From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTP id 64D305A026C for ; Fri, 24 Feb 2023 19:49:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677264596; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GWt2Jvic5upicZ+V6CF07q9954+jbr/dRxkhjhpXznE=; b=anb9sjwSvxuLeqrtxT8fKEYcpUrBLmcEA6r9PQfGcEuqiA1ysN6ePpslqS82JShOfO0cJt W8Ekis3O1BW61cywRTGr4SF9KonGmDS8nTkeVcT1dLjWd4kwj//DTuA90alrjkhIWKbjw+ QiEBb0GjEnYJ3cg61THuTJ7GioTTrqQ= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-269-eqJLEi31NXyU7SARc8uU_Q-1; Fri, 24 Feb 2023 13:49:54 -0500 X-MC-Unique: eqJLEi31NXyU7SARc8uU_Q-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5F9A729DD995 for ; Fri, 24 Feb 2023 18:49:54 +0000 (UTC) Received: from harajuku.usersys.redhat.com.homenet.telecomitalia.it (unknown [10.45.224.52]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E48F7140EBF6 for ; Fri, 24 Feb 2023 18:49:53 +0000 (UTC) From: Andrea Bolognani To: passt-dev@passt.top Subject: [PATCH 4/5] qrap: Introduce machine-specific PCI address base Date: Fri, 24 Feb 2023 19:49:48 +0100 Message-Id: <20230224184949.518615-5-abologna@redhat.com> In-Reply-To: <20230224184949.518615-1-abologna@redhat.com> References: <20230224184949.518615-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: JNPQ6LWEZTYWUTVSVZGCLSVHYBG2QDJT X-Message-ID-Hash: JNPQ6LWEZTYWUTVSVZGCLSVHYBG2QDJT X-MailFrom: abologna@redhat.com 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 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: For pc machines, devices are placed directly on pci.0 with addresses like bus=pci.0,addr=0xa and in this case the existing code works correctly. For q35 machines, however, a separate PCI bus is created for each devices using a pcie-root-port, and the resulting addresses look like bus=pci.9,addr=0x0 In this case, we need to treat PCI addresses as decimal, not hexadecimal, both when parsing and generating them. 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. Reported-by: Alona Paz Fixes: 5307faa05997 ("qrap: Strip network devices from command line, set them up according to machine") Signed-off-by: Andrea Bolognani --- qrap.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) 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[] = { @@ -94,19 +96,19 @@ static const struct pci_dev { "pc-q35", "virtio-net-pci", "bus=pci.", ",addr=0x0", "\"bus\":\"pci.", ",\"addr\":\"0x0\"", - 3, /* 2: hotplug bus */ 31 + 10, 3, /* 2: hotplug bus */ 31 }, { "pc-", "virtio-net-pci", "bus=pci.0,addr=0x", "", "\"bus\":\"pci.0\",\"addr\":\"0x", "", - 2, /* 1: ISA bridge */ 31 + 16, 2, /* 1: ISA bridge */ 31 }, { "s390-ccw", "virtio-net-ccw", "devno=fe.0.", "", "\"devno\":\"fe.0.", "", - 1, 16 + 16, 1, 16 }, { 0 }, }; @@ -264,7 +266,7 @@ int main(int argc, char **argv) if (template) { long n; - n = strtol(p + strlen(template), NULL, 16); + n = strtol(p + strlen(template), NULL, dev->base); if (!errno) addr_map |= (1 << n); } @@ -285,13 +287,25 @@ int main(int argc, char **argv) if (has_dev) { qemu_argv[qemu_argc++] = "-device"; if (!has_json) { - snprintf(dev_str, ARG_MAX, - "%s,%s%x%s,netdev=hostnet0,x-txburst=4096", - dev->name, dev->template, i, dev->template_post); + if (dev->base == 16) { + snprintf(dev_str, ARG_MAX, + "%s,%s%x%s,netdev=hostnet0,x-txburst=4096", + dev->name, dev->template, i, dev->template_post); + } else if (dev->base == 10) { + snprintf(dev_str, ARG_MAX, + "%s,%s%d%s,netdev=hostnet0,x-txburst=4096", + dev->name, dev->template, i, dev->template_post); + } } else { - snprintf(dev_str, ARG_MAX, - "{\"driver\":\"%s\",%s%x\"%s,\"netdev\":\"hostnet0\",\"x-txburst\":4096}", - dev->name, dev->template_json, i, dev->template_json_post); + if (dev->base == 16) { + snprintf(dev_str, ARG_MAX, + "{\"driver\":\"%s\",%s%x\"%s,\"netdev\":\"hostnet0\",\"x-txburst\":4096}", + dev->name, dev->template_json, i, dev->template_json_post); + } else if (dev->base == 10) { + snprintf(dev_str, ARG_MAX, + "{\"driver\":\"%s\",%s%d\"%s,\"netdev\":\"hostnet0\",\"x-txburst\":4096}", + dev->name, dev->template_json, i, dev->template_json_post); + } } qemu_argv[qemu_argc++] = dev_str; } -- 2.39.2