From nobody Fri Apr 19 19:03:04 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1605797565; cv=none; d=zohomail.com; s=zohoarc; b=eTG0Gf8TW3bRfXyrDx+53G8mMwkObIap+bWcrPUIc1Bv6lMB/L28OdbLajh6bF0w+c1uOIMhBW05jC18yce3g1DCwGUD3ToEWzJoZQe3sniuAGSEw81MB2no6bCSKWyME9BWyRkUNLfAOwZrNLecDStRZ1YaUz4Gerl/tjndQXo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605797565; h=Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:To; bh=VezKhLTcskDqjf5vN3pACojitNeVXOtWXoGo9wlVx5c=; b=UHU6/YwmS3ExRbaYB4WKv/NuBxTUuimfrHtP6OjYBGszG3mdCZLItFSlDkL4dDtdTnAG3aJS9g1g+vmAegvu68Y8UaHWyUATTrhYR0xvRWbQ25YFGgmHEIgOLYwKpr2kjkO8wez+L3KQKjVjKYhifFBXIgQ0Ofzg0XEMNaSCdt8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1605797565356321.6343318371012; Thu, 19 Nov 2020 06:52:45 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.30858.61024 (Exim 4.92) (envelope-from ) id 1kflIM-0005SZ-ED; Thu, 19 Nov 2020 14:52:22 +0000 Received: by outflank-mailman (output) from mailman id 30858.61024; Thu, 19 Nov 2020 14:52:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kflIM-0005SS-B8; Thu, 19 Nov 2020 14:52:22 +0000 Received: by outflank-mailman (input) for mailman id 30858; Thu, 19 Nov 2020 14:52:21 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kflIL-0005SN-2a for xen-devel@lists.xenproject.org; Thu, 19 Nov 2020 14:52:21 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kflIJ-0005st-5I; Thu, 19 Nov 2020 14:52:19 +0000 Received: from 54-240-197-235.amazon.com ([54.240.197.235] helo=ufe34d9ed68d054.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kflII-00039y-RC; Thu, 19 Nov 2020 14:52:19 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kflIL-0005SN-2a for xen-devel@lists.xenproject.org; Thu, 19 Nov 2020 14:52:21 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kflIJ-0005st-5I; Thu, 19 Nov 2020 14:52:19 +0000 Received: from 54-240-197-235.amazon.com ([54.240.197.235] helo=ufe34d9ed68d054.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kflII-00039y-RC; Thu, 19 Nov 2020 14:52:19 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Message-Id:Date:Subject:Cc:To:From; bh=VezKhLTcskDqjf5vN3pACojitNeVXOtWXoGo9wlVx5c=; b=hsqdXZaKgU+knug2crcBbr40TO TBzlwjmquQBv/36tjN8I6IzQxRbv/RH15d1raerlWXAaiaiK9WhKHMCqi/KJJuJoEMEYiJcH+uvNS a+KfOPwT05QZOE+bpKD5kRAe0k/zofQG6wzoG9fUC3joVEc+iuVUw2CsGOvkKwvE1epE=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Kevin Tian Subject: [PATCH] xen/iommu: vtd: Fix undefined behavior pci_vtd_quirks() Date: Thu, 19 Nov 2020 14:52:16 +0000 Message-Id: <20201119145216.29280-1-julien@xen.org> X-Mailer: git-send-email 2.17.1 X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Julien Grall When booting Xen with CONFIG_USBAN=3Dy on Sandy Bridge, UBSAN will throw the following splat: (XEN) =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D (XEN) UBSAN: Undefined behaviour in quirks.c:449:63 (XEN) left shift of 1 by 31 places cannot be represented in type 'int' (XEN) ----[ Xen-4.11.4 x86_64 debug=3Dy Not tainted ]---- [...] (XEN) Xen call trace: (XEN) [] ubsan.c#ubsan_epilogue+0xa/0xad (XEN) [] __ubsan_handle_shift_out_of_bounds+0xb4/0x145 (XEN) [] pci_vtd_quirk+0x3d3/0x74f (XEN) [] iommu.c#domain_context_mapping+0x45b/0x46f (XEN) [] iommu.c#setup_hwdom_device+0x22/0x3a (XEN) [] pci.c#setup_one_hwdom_device+0x8c/0x124 (XEN) [] pci.c#_setup_hwdom_pci_devices+0xbb/0x2f7 (XEN) [] pci.c#pci_segments_iterate+0x4c/0x8c (XEN) [] setup_hwdom_pci_devices+0x25/0x2c (XEN) [] iommu.c#intel_iommu_hwdom_init+0x52/0x2f3 (XEN) [] iommu_hwdom_init+0x4e/0xa4 (XEN) [] dom0_construct_pv+0x23c8/0x2476 (XEN) [] construct_dom0+0x6c/0xa3 (XEN) [] __start_xen+0x4651/0x4b55 (XEN) [] __high_start+0x53/0x55 Note that splat is from 4.11.4 and not staging. Although, the problem is still present. This can be solved by making the first operand unsigned int. Signed-off-by: Julien Grall CR: https://code.amazon.com/reviews/CR-38873112 Reviewed-by: Jan Beulich Reviewed-by: Kevin Tian --- xen/drivers/passthrough/vtd/quirks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xen/drivers/passthrough/vtd/quirks.c b/xen/drivers/passthrough= /vtd/quirks.c index a8330f17bc0c..8a81d9c9308b 100644 --- a/xen/drivers/passthrough/vtd/quirks.c +++ b/xen/drivers/passthrough/vtd/quirks.c @@ -435,7 +435,7 @@ void pci_vtd_quirk(const struct pci_dev *pdev) case 0x3728: /* Xeon C5500/C3500 (JasperForest) */ case 0x3c28: /* Sandybridge */ val =3D pci_conf_read32(pdev->sbdf, 0x1AC); - pci_conf_write32(pdev->sbdf, 0x1AC, val | (1 << 31)); + pci_conf_write32(pdev->sbdf, 0x1AC, val | (1U << 31)); printk(XENLOG_INFO "Masked VT-d error signaling on %pp\n", &pdev->= sbdf); break; =20 --=20 2.17.1