From nobody Sat Apr 27 16:15:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1597101312; cv=none; d=zohomail.com; s=zohoarc; b=PGYOgyMCQuFlAyeMxk4I8YL7JQ+4K82W5JH59piI6xp9ApYhbvL+7zRE2zw59gXfeXLP0QKHKt8n9sfz1CgsXpDZCv0DQ/fR1PExJMBc0vmycY1Jw66iixIhEZqywsS6tjHAjO9aVj9ydXeqJyLkI53AaOyEdpAZRVzuf2RARUA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597101312; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=g/Vi6ic1+pD6wPNHivyLLGiLhJgSPX1F70eL2IDh9qo=; b=Mjrxax/M8AawSMlG0fAhWR8F5lAMVKYuiMOUvD8DXvNbxJBZxtJSqOXX+R/zolkd+OQJWT9uK3Me2n2orNaHTN6uGrfiohrV4xZFS6CwWNUVP/+/ggokiWkbonpmoeRxoskX1gcUIWrh2779R9WA/sz6SI5Ry5Mv72Vr4hE8bT0= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1597101312576537.847419722303; Mon, 10 Aug 2020 16:15:12 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-194-L0gUO-2ENGiDDQLBOYEDsg-1; Mon, 10 Aug 2020 19:15:08 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3B8B359; Mon, 10 Aug 2020 23:15:01 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 086301000320; Mon, 10 Aug 2020 23:14:57 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 6CB581809554; Mon, 10 Aug 2020 23:14:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 07ANEpgZ004216 for ; Mon, 10 Aug 2020 19:14:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id A653BF41CB; Mon, 10 Aug 2020 23:14:51 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A14D7EAFA8 for ; Mon, 10 Aug 2020 23:14:48 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D4B88185A797 for ; Mon, 10 Aug 2020 23:14:48 +0000 (UTC) Received: from de-smtp-delivery-102.mimecast.com (de-smtp-delivery-102.mimecast.com [51.163.158.102]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-330-67gxZ_FgOLSUg3o-iKYyhA-1; Mon, 10 Aug 2020 19:14:46 -0400 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04lp2052.outbound.protection.outlook.com [104.47.12.52]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-23-wkwTrzPvNku6pgt3K17QoA-1; Tue, 11 Aug 2020 01:14:44 +0200 Received: from VI1PR0401MB2429.eurprd04.prod.outlook.com (2603:10a6:800:2c::13) by VI1PR04MB3037.eurprd04.prod.outlook.com (2603:10a6:802:9::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Mon, 10 Aug 2020 23:14:41 +0000 Received: from VI1PR0401MB2429.eurprd04.prod.outlook.com ([fe80::7cc0:b0a4:b951:90e2]) by VI1PR0401MB2429.eurprd04.prod.outlook.com ([fe80::7cc0:b0a4:b951:90e2%11]) with mapi id 15.20.3261.024; Mon, 10 Aug 2020 23:14:40 +0000 Received: from linux-tbji.devlab.prv.suse.com (192.150.153.236) by AM0PR08CA0014.eurprd08.prod.outlook.com (2603:10a6:208:d2::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.16 via Frontend Transport; Mon, 10 Aug 2020 23:14:38 +0000 X-MC-Unique: L0gUO-2ENGiDDQLBOYEDsg-1 X-MC-Unique: 67gxZ_FgOLSUg3o-iKYyhA-1 X-MC-Unique: wkwTrzPvNku6pgt3K17QoA-1 From: Jim Fehlig To: libvir-list@redhat.com Subject: [PATCH] Xen: Improve parsing of PCI addresses in config converter Date: Mon, 10 Aug 2020 17:14:16 -0600 Message-ID: <20200810231416.10141-1-jfehlig@suse.com> X-ClientProxiedBy: AM0PR08CA0014.eurprd08.prod.outlook.com (2603:10a6:208:d2::27) To VI1PR0401MB2429.eurprd04.prod.outlook.com (2603:10a6:800:2c::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Originating-IP: [192.150.153.236] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a62c543c-ae50-40e1-af99-08d83d832858 X-MS-TrafficTypeDiagnostic: VI1PR04MB3037: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:459; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fNoEgLv6jggqiMlxl75rMkZI/Dm/SA1A9qQ1VJMAVpsw3Evnn0f9fKXpkKHhIzo32uRP+lS/fz7tyt3yv7JCKhWt3PoNp7D4ccNMZafNfLNK2OtE19xtj4dBgjK5S5woBWriQ/WtqAnXuZLT6dcBmBZCEW52RrjiuFuhjT+fdoqHoxkFjm8z1PDflMLezkSxUXMMoERF3JYZe458DxkWJeU/QBcuWs0Py+/9T3Ifngrn/dY8t3zxFXK4WsBiQGtb4Vq521EV/JgIdl+zfrMX+7GBSiBILKqOFz//MjQM1yRdlF/ZT7F4XJ1G0FMlg4hvDESOyYX5yHoe4voLe0tzcLYrzOfUg+dasHHT8OiNEA1i5Djaied+q2f7ySRQaXcwM+kLTOTXBDOYVUXxPSNhYw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR0401MB2429.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(396003)(39860400002)(366004)(346002)(376002)(136003)(6486002)(86362001)(2906002)(316002)(2616005)(956004)(7696005)(52116002)(83380400001)(66946007)(8936002)(36756003)(66476007)(66556008)(6666004)(966005)(8676002)(478600001)(26005)(186003)(16526019)(107886003)(4326008)(6916009)(1076003)(5660300002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 5bEp/bhKNWWbpyxFhEAynGxjHeIPFqHbDEpRhi3uhCP3NYd3JAOrCLCdj7pVwkfuM44zCoa7j4OqBVNdzxC+36M4cC5WLfbM6lot8gA6EhoWs0uZKp2bTMhm7h968vptWhMuuTYRILfBgbWXCWAOEmIdh5SgmIaO/haHZ4QEFEOcG6xpya5CIp2vmm5mbX7r3oYbJ7JMkrcBCZDdxue3tAsqz3bw3hGmFXnIYqpttWsgWUgY054NVYTHVo/dGU9H8SL/gTBMDr6pmxos7jXov0D8wcRjv0SdpFz+3XwNyIkJ9pha6zyRzR24jnx9ygTIp+mCYWohk3IDd1Sw+BLJMYiUpCMnQz5EM7k6CcP+QnjQI8sERjFcgSPooS1a5JYxBLaNRXF3pkDEpa6BC8oTGD6mRv6H9B6IhRHUnuOFs+prLxExCYMfpUizSa8bQVtjYSa8cRA6gBpAkebW3fS50EktniTXnLArU0iZfIVOxDBPQN/6kzGKfuKZpvuARM99CaPakGvGmQJnPGAa8RfHESg+lbOkkEQV8VR9mpwevYNbf0cnf+3CTGaz40uouvmmBTfF9lRoHsnfbFfzJJC2mntGmKTChzXZf5XyN9K4UE/97PsVKH2/S7EoeVC19YTGGDYMLUl9x9VWbO+vwOrj/g== X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: a62c543c-ae50-40e1-af99-08d83d832858 X-MS-Exchange-CrossTenant-AuthSource: VI1PR0401MB2429.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Aug 2020 23:14:40.6603 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Z7VvyV6sVzyKZaLuQ79KPy05IUKdIaPd0dNWgxtj8sWuGQxjYruTjWk01JY7BsiC2TwLJUx5HZvOd0CjAiOOXA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB3037 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false; X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 07ANEpgZ004216 X-loop: libvir-list@redhat.com Cc: mangel@gmx.de X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" There was a report on libvirt-users [1] about the domxml to/from native converter in the Xen driver not handling PCI addresses without a domain specification. This patch improves parsing of PCI addresses in the converter and allows PCI addresses with only bb:ss.f. xl.cfg(5) also allows either the dddd:bb:ss.f or bb:ss.f format. A test has been added to check the conversion from xl.cfg to domXML. [1] https://www.redhat.com/archives/libvirt-users/2020-August/msg00040.html Signed-off-by: Jim Fehlig Reviewed-by: Daniel Henrique Barboza --- src/libxl/xen_common.c | 81 +++++++++------------- tests/xmconfigdata/test-pci-dev-syntax.cfg | 26 +++++++ tests/xmconfigdata/test-pci-dev-syntax.xml | 71 +++++++++++++++++++ tests/xmconfigtest.c | 1 + 4 files changed, 129 insertions(+), 50 deletions(-) diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c index 75fe7e0644..73ce412fe7 100644 --- a/src/libxl/xen_common.c +++ b/src/libxl/xen_common.c @@ -372,63 +372,44 @@ static virDomainHostdevDefPtr xenParsePCI(char *entry) { virDomainHostdevDefPtr hostdev =3D NULL; - char domain[5]; - char bus[3]; - char slot[3]; - char func[2]; - char *key, *nextkey; - int domainID; - int busID; - int slotID; - int funcID; + VIR_AUTOSTRINGLIST tokens =3D NULL; + size_t ntokens =3D 0; + size_t nexttoken =3D 0; + char *slotstr; + char *funcstr; + int domain =3D 0x0; + int bus; + int slot; + int func; =20 - domain[0] =3D bus[0] =3D slot[0] =3D func[0] =3D '\0'; - - /* pci=3D['0000:00:1b.0','0000:00:13.0'] */ - if (!(key =3D entry)) - return NULL; - if (!(nextkey =3D strchr(key, ':'))) - return NULL; - if (virStrncpy(domain, key, (nextkey - key), sizeof(domain)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Domain %s too big for destination"), key); + /* pci=3D['00:1b.0','0000:00:13.0'] */ + if (!(tokens =3D virStringSplitCount(entry, ":", 3, &ntokens))) return NULL; - } =20 - key =3D nextkey + 1; - if (!(nextkey =3D strchr(key, ':'))) - return NULL; - if (virStrncpy(bus, key, (nextkey - key), sizeof(bus)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Bus %s too big for destination"), key); - return NULL; + /* domain */ + if (ntokens =3D=3D 3) { + if (virStrToLong_i(tokens[nexttoken], NULL, 16, &domain) < 0) + return NULL; + nexttoken++; } =20 - key =3D nextkey + 1; - if (!(nextkey =3D strchr(key, '.'))) + /* bus */ + if (virStrToLong_i(tokens[nexttoken], NULL, 16, &bus) < 0) return NULL; - if (virStrncpy(slot, key, (nextkey - key), sizeof(slot)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Slot %s too big for destination"), key); - return NULL; - } + nexttoken++; =20 - key =3D nextkey + 1; - if (strlen(key) !=3D 1) - return NULL; - if (virStrncpy(func, key, 1, sizeof(func)) < 0) { + /* slot and function */ + slotstr =3D tokens[nexttoken]; + if (!(funcstr =3D strchr(slotstr, '.'))) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Function %s too big for destination"), key); + _("Malformed PCI address %s"), slotstr); return NULL; } - - if (virStrToLong_i(domain, NULL, 16, &domainID) < 0) - return NULL; - if (virStrToLong_i(bus, NULL, 16, &busID) < 0) - return NULL; - if (virStrToLong_i(slot, NULL, 16, &slotID) < 0) + *funcstr =3D '\0'; + funcstr++; + if (virStrToLong_i(slotstr, NULL, 16, &slot) < 0) return NULL; - if (virStrToLong_i(func, NULL, 16, &funcID) < 0) + if (virStrToLong_i(funcstr, NULL, 16, &func) < 0) return NULL; =20 if (!(hostdev =3D virDomainHostdevDefNew())) @@ -436,10 +417,10 @@ xenParsePCI(char *entry) =20 hostdev->managed =3D false; hostdev->source.subsys.type =3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI; - hostdev->source.subsys.u.pci.addr.domain =3D domainID; - hostdev->source.subsys.u.pci.addr.bus =3D busID; - hostdev->source.subsys.u.pci.addr.slot =3D slotID; - hostdev->source.subsys.u.pci.addr.function =3D funcID; + hostdev->source.subsys.u.pci.addr.domain =3D domain; + hostdev->source.subsys.u.pci.addr.bus =3D bus; + hostdev->source.subsys.u.pci.addr.slot =3D slot; + hostdev->source.subsys.u.pci.addr.function =3D func; =20 return hostdev; } diff --git a/tests/xmconfigdata/test-pci-dev-syntax.cfg b/tests/xmconfigdat= a/test-pci-dev-syntax.cfg new file mode 100644 index 0000000000..e0f00d9bd7 --- /dev/null +++ b/tests/xmconfigdata/test-pci-dev-syntax.cfg @@ -0,0 +1,26 @@ +name =3D "test" +uuid =3D "cc2315e7-d26a-307a-438c-6d188ec4c09c" +maxmem =3D 382 +memory =3D 350 +vcpus =3D 1 +pae =3D 1 +acpi =3D 1 +apic =3D 1 +viridian =3D 0 +rtc_timeoffset =3D 0 +localtime =3D 0 +on_poweroff =3D "destroy" +on_reboot =3D "destroy" +on_crash =3D "destroy" +device_model =3D "/usr/lib/xen/bin/qemu-system-i386" +sdl =3D 0 +vnc =3D 1 +vncunused =3D 1 +vif =3D [ "mac=3D00:16:3e:0a:7b:39,bridge=3Dxenbr0,script=3Dvif-bridge,mod= el=3De1000" ] +pci =3D [ "0001:0c:1b.2", "01:13.0" ] +parallel =3D "none" +serial =3D "pty" +builder =3D "hvm" +kernel =3D "/usr/lib/xen/boot/hvmloader" +boot =3D "c" +disk =3D [ "phy:/dev/sda8,hda,w", ",hdc:cdrom,r" ] diff --git a/tests/xmconfigdata/test-pci-dev-syntax.xml b/tests/xmconfigdat= a/test-pci-dev-syntax.xml new file mode 100644 index 0000000000..5d5d29c61c --- /dev/null +++ b/tests/xmconfigdata/test-pci-dev-syntax.xml @@ -0,0 +1,71 @@ + + test + cc2315e7-d26a-307a-438c-6d188ec4c09c + 391168 + 358400 + 1 + + hvm + /usr/lib/xen/boot/hvmloader + + + + + + + + + destroy + destroy + destroy + + /usr/lib/xen/bin/qemu-system-i386 + + + + +
+ + + + + +
+ + + + + + +