From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id E88F85A026A for ; Mon, 27 Feb 2023 01:00:40 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4PQ0xx3V7sz4x91; Mon, 27 Feb 2023 11:00:37 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1677456037; bh=iVbrS6TlWh0VCOGVX1KcpKFImYUq/OUSP5OCt999W1s=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=QQChxvwIaVvRzLPRk0qmQijeyDszuw/P+RmZMIsxSwPRz4DdorWfqaPdeS91Fo60t kvNm097WMP5mlzLSzG9yVEHvAXU5uLTRP9IR+pn/uk5E1sc4uH7dMPxgKZ+h2m8uVY Mrns4Ex9mdcWEdjiWBv5/vtGf9SxzZXGSPh4mSp8= Date: Mon, 27 Feb 2023 10:58:35 +1100 From: David Gibson To: Andrea Bolognani Subject: Re: [PATCH 4/5] qrap: Introduce machine-specific PCI address base Message-ID: References: <20230224184949.518615-1-abologna@redhat.com> <20230224184949.518615-5-abologna@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="tRFqzsRKBWWEdkMj" Content-Disposition: inline In-Reply-To: <20230224184949.518615-5-abologna@redhat.com> Message-ID-Hash: SHZAEJAD3T2ARPDQ6DSN5C7KDZ5RBLSU X-Message-ID-Hash: SHZAEJAD3T2ARPDQ6DSN5C7KDZ5RBLSU X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --tRFqzsRKBWWEdkMj Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Feb 24, 2023 at 07:49:48PM +0100, Andrea Bolognani wrote: 11;rgb:ffff/ffff/ffff> For pc machines, devices are placed directly on pci.= 0 with > addresses like >=20 > bus=3Dpci.0,addr=3D0xa >=20 > and in this case the existing code works correctly. >=20 > For q35 machines, however, a separate PCI bus is created for > each devices using a pcie-root-port, and the resulting > addresses look like >=20 > bus=3Dpci.9,addr=3D0x0 >=20 > In this case, we need to treat PCI addresses as decimal, not > hexadecimal, both when parsing and generating them. >=20 > This issue has gone unnoticed for a long time because it only > shows up when enough PCI devices are present: for small > numbers, decimal and hexadecimal overlap, masking the issue. >=20 > Reported-by: Alona Paz > Fixes: 5307faa05997 ("qrap: Strip network devices from command line, set = them up according to machine") > Signed-off-by: Andrea Bolognani Clunky, but, whatever, it's qrap. Reviewed-by: David Gibson > --- > qrap.c | 34 ++++++++++++++++++++++++---------- > 1 file changed, 24 insertions(+), 10 deletions(-) >=20 > diff --git a/qrap.c b/qrap.c > index 3077944..27c12ed 100644 > --- a/qrap.c > +++ b/qrap.c > @@ -77,6 +77,7 @@ static const struct drop_arg { > * @template_post: Suffix for device specification (last part of address) > * @template_json: Device prefix for when JSON is used > * @template_json_post: Device suffix for when JSON is used > + * @base: Base used for PCI addresses > * @first: First usable PCI address > * @last: Last usable PCI address > */ > @@ -87,6 +88,7 @@ static const struct pci_dev { > char *template_post; > char *template_json; > char *template_json_post; > + int base; > int first; > int last; > } pci_devs[] =3D { > @@ -94,19 +96,19 @@ static const struct pci_dev { > "pc-q35", "virtio-net-pci", > "bus=3Dpci.", ",addr=3D0x0", > "\"bus\":\"pci.", ",\"addr\":\"0x0\"", > - 3, /* 2: hotplug bus */ 31 > + 10, 3, /* 2: hotplug bus */ 31 > }, > { > "pc-", "virtio-net-pci", > "bus=3Dpci.0,addr=3D0x", "", > "\"bus\":\"pci.0\",\"addr\":\"0x", "", > - 2, /* 1: ISA bridge */ 31 > + 16, 2, /* 1: ISA bridge */ 31 > }, > { > "s390-ccw", "virtio-net-ccw", > "devno=3Dfe.0.", "", > "\"devno\":\"fe.0.", "", > - 1, 16 > + 16, 1, 16 > }, > { 0 }, > }; > @@ -264,7 +266,7 @@ int main(int argc, char **argv) > if (template) { > long n; > =20 > - n =3D strtol(p + strlen(template), NULL, 16); > + n =3D strtol(p + strlen(template), NULL, dev->base); > if (!errno) > addr_map |=3D (1 << n); > } > @@ -285,13 +287,25 @@ int main(int argc, char **argv) > if (has_dev) { > qemu_argv[qemu_argc++] =3D "-device"; > if (!has_json) { > - snprintf(dev_str, ARG_MAX, > - "%s,%s%x%s,netdev=3Dhostnet0,x-txburst=3D4096", > - dev->name, dev->template, i, dev->template_post); > + if (dev->base =3D=3D 16) { > + snprintf(dev_str, ARG_MAX, > + "%s,%s%x%s,netdev=3Dhostnet0,x-txburst=3D4096", > + dev->name, dev->template, i, dev->template_post); > + } else if (dev->base =3D=3D 10) { > + snprintf(dev_str, ARG_MAX, > + "%s,%s%d%s,netdev=3Dhostnet0,x-txburst=3D4096", > + dev->name, dev->template, i, dev->template_post); > + } > } else { > - snprintf(dev_str, ARG_MAX, > - "{\"driver\":\"%s\",%s%x\"%s,\"netdev\":\"hostnet0\",\"x-txb= urst\":4096}", > - dev->name, dev->template_json, i, dev->template_json_post); > + if (dev->base =3D=3D 16) { > + snprintf(dev_str, ARG_MAX, > + "{\"driver\":\"%s\",%s%x\"%s,\"netdev\":\"hostnet0\",\"x-tx= burst\":4096}", > + dev->name, dev->template_json, i, dev->template_json_post); > + } else if (dev->base =3D=3D 10) { > + snprintf(dev_str, ARG_MAX, > + "{\"driver\":\"%s\",%s%d\"%s,\"netdev\":\"hostnet0\",\"x-tx= burst\":4096}", > + dev->name, dev->template_json, i, dev->template_json_post); > + } > } > qemu_argv[qemu_argc++] =3D dev_str; > } --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --tRFqzsRKBWWEdkMj Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmP78iUACgkQzQJF27ox 2Gdb9A/+Mo/dEdp8inMWAIt7qgypDK2p/lXZKb36YGiGJ0jzTqT/0j/Nw5GHWsxf qRwtFhaRgZWbVzyD2WSp8e81NtQcV1Y32OZB0fI97x/FCTHJnk0r6H1yjG5I58U1 95ndrfRE00t8h1zaeZk4UTTNLeK9OMH4hCxDRdo3dBo9E0lPSzSuqS7lM4FimbtC AnMfGdJEfUQqFO9mr5V4ukAkiOo4gK/ruZwORdnr+yIUZaOZBF/AgCpeJFZ1H8Pz Cjk4mzwcG8y0JGjVEJE7eIhnsheK9N9bTt4rF9Km6vFewEVTi3E9JQfovIGGZ2/I FT50zU1zi2MrYqSUmXtugoInrziNhERgAVN8Z3GxUyiowRkNw57OernVVdnPBnHC 8Jrx3hGayFBHzMWfAa9tfgSstgn3rsLZ8qZQHkx4mKbT0Sht0SjumYdAKtiLqW0/ fmLs9U7RuGCSH1TB9K78pcUMJv2wtpwW6zc7k67LID4eg3CnIo1tiw9ekgONoR8H aoXNjuM6LrwegNrUpYgoyuvojgANuovass1c+tKp5TjI6JMN4iNYPpnFIklmWKMv PoxidFfWsZWWxqxeHlSM37zxfXAQe6NsSa6VeQjhBrSF/xVUuZQdTrMf5RlU2Ujs raa4cNBsIalcw2Gyxbl4yKyb87XNJIAAPkG2TxpXvyWqQd2Un4g= =eu1j -----END PGP SIGNATURE----- --tRFqzsRKBWWEdkMj--