From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E0C6C63798 for ; Thu, 19 Nov 2020 15:02:40 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CAEBB246D1 for ; Thu, 19 Nov 2020 15:02:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="VP3vVEi6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CAEBB246D1 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.30889.61077 (Exim 4.92) (envelope-from ) id 1kflS4-00071S-By; Thu, 19 Nov 2020 15:02:24 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 30889.61077; Thu, 19 Nov 2020 15:02:24 +0000 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" Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kflS4-00071L-8O; Thu, 19 Nov 2020 15:02:24 +0000 Received: by outflank-mailman (input) for mailman id 30889; Thu, 19 Nov 2020 15:02:23 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kflS3-00071G-HV for xen-devel@lists.xenproject.org; Thu, 19 Nov 2020 15:02:23 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 9198f529-1b12-41de-84cd-0ceaa10b0ffc; Thu, 19 Nov 2020 15:02:22 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id ED54EABD6; Thu, 19 Nov 2020 15:02:21 +0000 (UTC) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kflS3-00071G-HV for xen-devel@lists.xenproject.org; Thu, 19 Nov 2020 15:02:23 +0000 X-Inumbo-ID: 9198f529-1b12-41de-84cd-0ceaa10b0ffc Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 9198f529-1b12-41de-84cd-0ceaa10b0ffc; Thu, 19 Nov 2020 15:02:22 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1605798142; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kcL9z9jC7iEJLcAtPdDO0JaXD92KDhIUbO9txRAzG28=; b=VP3vVEi6t/Ncea3SRMsFMig3iscpmhvsTvXoukVL5UhVgEiFCnqezJBK0r5Uat6avniSaX u6uuwo+qu1EcOQosWNLXLpn50VDI6Uqsfz4zaoFu5Y0n1NKVFrbmmlF3VrmPzF8QZ90Ej6 jSJm59a9sDZZkJQM+4CssLaP0vZZNWY= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id ED54EABD6; Thu, 19 Nov 2020 15:02:21 +0000 (UTC) Subject: Re: [PATCH] xen/iommu: vtd: Fix undefined behavior pci_vtd_quirks() To: Julien Grall Cc: Julien Grall , Kevin Tian , xen-devel@lists.xenproject.org References: <20201119145216.29280-1-julien@xen.org> From: Jan Beulich Message-ID: Date: Thu, 19 Nov 2020 16:02:21 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.4.3 MIME-Version: 1.0 In-Reply-To: <20201119145216.29280-1-julien@xen.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 19.11.2020 15:52, Julien Grall wrote: > From: Julien Grall > > When booting Xen with CONFIG_USBAN=y on Sandy Bridge, UBSAN will throw > the following splat: > > (XEN) ================================================================================ > (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=y 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 Reviewed-by: Jan Beulich > --- 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 = pci_conf_read32(pdev->sbdf, 0x1AC); > - pci_conf_write32(pdev->sbdf, 0x1AC, val | (1 << 31)); > + pci_conf_write32(pdev->sbdf, 0x1AC, val | (1U << 31)); I can see a couple of similar uses in arm/ipmmu-vmsa.c and arm/smmu.c. These are all #define-s though, so would be an issue only if these #define-s actually get used anywhere. Jan