Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753498AbdLMQl6 (ORCPT ); Wed, 13 Dec 2017 11:41:58 -0500 Received: from mail-by2nam01on0045.outbound.protection.outlook.com ([104.47.34.45]:8608 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753336AbdLMQlx (ORCPT ); Wed, 13 Dec 2017 11:41:53 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Gary.Hook@amd.com; Subject: Re: [PATCH] iommu/vt-d: Fix shift overflow in qi_flush_dev_iotlb To: Alex Williamson , Peter Xu Cc: iommu@lists.linux-foundation.org, dwmw2@infradead.org, linux-kernel@vger.kernel.org, tursulin@ursulin.net References: <20171212224250.22173.74201.stgit@gimli.home> <20171213071355.GD7780@xz-mi> <20171213085847.3d3245c6@t450s.home> From: "Hook, Gary" Message-ID: Date: Wed, 13 Dec 2017 10:41:47 -0600 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <20171213085847.3d3245c6@t450s.home> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BN6PR1001CA0006.namprd10.prod.outlook.com (10.174.84.19) To DM5PR12MB1212.namprd12.prod.outlook.com (10.168.237.15) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: f3c8d766-ec1b-4d23-db88-08d54248694e X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(48565401081)(5600026)(4604075)(2017052603307);SRVR:DM5PR12MB1212; X-Microsoft-Exchange-Diagnostics: 1;DM5PR12MB1212;3:L/PpuY4Zw8zXfgq5NbkBodUAXB+DP98thZm1lxy6IDE53sYc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ErqBXOFCcGRwKL+8N8YO0TdnyXGUtq39QvLH/FXOjnvfriKiWSjve0ABHEVSg9D/4S/Hn7yb/NrAGvgWYgi/dXHvhJo+IHCr8eiGUso7VMTQMPOI310YCToXpeJOEBAfDIsL71giTagw1kgCqHDnEAC16gKKlEVQ9ZU77sVVTTocvqcFqCUCDpsuJNUJcoHEPPAwVjmGk8oXXEn0JDarH9Tm8mzuPEK6NBEvMgJ60lcxj/SqCrKxxiYr8bqUCnD8DwYcjdQFoKP2uZVrcLApDnVGaIbTWvx;4:5OtY0jbm2iE0aZbGL9L9ci/IksSSX4bVb2NjG8YAKFHCZ6xGS3CVOkuvSqOcBU2m8cTbaUoVtqJxq4uSIRbbQfXX8pDdQ3ovq6RMe7m6VZY5KV3gQTKlDX/Upu+4vH49Uu1ViHbVjrPkbmGVbxwTekCm9g9631fadJrKeqqGA9bUZJOdaDykQu6Tw090UVKOu2MJFlPuzvKblHyYAXXQo0YNcJbqke8GwOz7ijB4WFEhjH3VTXC3JGVnbdv8MmraY+r6CpaUYXQOc/sESegvtQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040450)(2401047)(8121501046)(5005006)(3231023)(3002001)(10201501046)(93006095)(93001095)(6055026)(6041248)(20161123555025)(20161123562025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(20161123558100)(6072148)(201708071742011);SRVR:DM5PR12MB1212;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:DM5PR12MB1212; X-Forefront-PRVS: 052017CAF1 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6049001)(376002)(346002)(39860400002)(366004)(24454002)(199004)(189003)(36756003)(77096006)(64126003)(305945005)(16576012)(8936002)(31686004)(90366009)(65826007)(97736004)(230700001)(5660300001)(561944003)(386003)(53546011)(6486002)(76176011)(53936002)(50466002)(16526018)(478600001)(105586002)(58126008)(72206003)(2486003)(7736002)(106356001)(6116002)(47776003)(3846002)(52116002)(8676002)(81166006)(229853002)(81156014)(6666003)(2950100002)(83506002)(23676004)(67846002)(31696002)(52146003)(316002)(4326008)(25786009)(65956001)(6246003)(3260700006)(68736007)(2906002)(66066001)(65806001)(110136005);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR12MB1212;H:[10.236.18.126];FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtETTVQUjEyTUIxMjEyOzIzOlMvbHY1WVYrdVJyNnZ5OXQyQnNlZEp1SWcx?= =?utf-8?B?K2dibEdtK1NuN2kzSTk5NUN3ZWlXZWZIV1JQMkhFZ1BDM1ZZRDNRRTJBcTZR?= =?utf-8?B?RFBtQ3RSUmV6TTZ0cTVWcStMOXp0azBvLzR6UHljSzBOSWEyalBpRlNSc3Iv?= =?utf-8?B?MTRWRzZVbXo0ZlBQUDR3em9qVHpBc0ZSbnFqd29MUDIxM3QzWWQyMEFNa3FN?= =?utf-8?B?TWp2d09ZRjRJRzIzYjdMcnhiM3ExalRTNm5rcUR5cUxBNVhSUHBqSDdiNFlW?= =?utf-8?B?azc3Wjh6NnVPcXdkRnpKT2FXa3hZY211SDVWV1FwdUdJZXlkQU1MNWdQbU0x?= =?utf-8?B?WnRKbjByT2c4OGxxclZsWFlFUWRKeUw0azVxREZzYjhqVkIwY0VCdzhSTlRF?= =?utf-8?B?bVBSYjYvNUhSeVVoLzFObjJMblNtNkVpdFVIVDI4cW1nMGdDT1B5dVZlRlIz?= =?utf-8?B?N0FWNmhOS0xoakJwVThyazZ2MCs4TnNmZjM4QzB6VlQ5bFZ3Q1g1dytTaDF0?= =?utf-8?B?MzRlb2xva01zUFNLV1FOOTlPSmFEY0NycWwxOEVwM1o0QUxSUFVKWmpRb0Z4?= =?utf-8?B?YVFISzI0S2dZMGRKUkpZNXB2K1hrSjBrM2JrWS9mc1BKKzRLMmZRa3Vi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90tT26qHPVUJ6idfQxJxpjN760V1W8eZOYBs0wKDWZg=;7:6RktJTQjdhA0wd6HVvze+a5g3U/vocAMU/aYmOq+T35M0X8WgqDpJ2UJD0kom879CZU+7pslUveaFo7RwHPNbdarsHcsZb9h6PuqMwpRrRJfo1MLn+0vsohZ2BltxEeMAP1FGYoggL3xb2m9VDfdaxubi+rwILlX862CYfrizCdDppuyRLuit9dn/+U7h3FYaPlpm0SH9R8Hjr6ImId4qMOgj0zzZZmlSW4wbZpSsEuW5Nookv2d2N/jb3Y7UOKg SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;DM5PR12MB1212;20:5sUxuPDuJjYXxLvYVEayf8DBupwAfknG7OPTO2UIy4a0wyCuu5qKJVEvy1cVowoqiFDZDKbwLzxMUzcHU3VXXyk53bbBgEpg09YwBpBljIdyYInVJOyA/kzC6aPEfH6Ncuv0+WWaS2t/LUDs4GlfYLWe2WW2jp4Acs+sG7E7J/VpoO1CEYnORK+15NKr4oCZE6yu7e4YjEA4wDH8DSEY5lUsHnveK8ricXt8/KfRUaz0pUNhMiKYU+cAhnr2nE4t X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Dec 2017 16:41:50.8084 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f3c8d766-ec1b-4d23-db88-08d54248694e X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1212 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1569 Lines: 45 On 12/13/2017 9:58 AM, Alex Williamson wrote: > On Wed, 13 Dec 2017 15:13:55 +0800 > Peter Xu wrote: > >> On Tue, Dec 12, 2017 at 03:43:08PM -0700, Alex Williamson wrote: >> >> [...] >> >>> diff --git a/drivers/iommu/dmar.c b/drivers/iommu/dmar.c >>> index 9a7ffd13c7f0..87888b102057 100644 >>> --- a/drivers/iommu/dmar.c >>> +++ b/drivers/iommu/dmar.c >>> @@ -1345,7 +1345,9 @@ void qi_flush_dev_iotlb(struct intel_iommu *iommu, u16 sid, u16 qdep, >>> struct qi_desc desc; >>> >>> if (mask) { >>> - BUG_ON(addr & ((1 << (VTD_PAGE_SHIFT + mask)) - 1)); >>> + BUG_ON((mask > MAX_AGAW_PFN_WIDTH) || >>> + ((mask == MAX_AGAW_PFN_WIDTH) && addr) || >>> + (addr & ((1 << (VTD_PAGE_SHIFT + mask)) - 1))); >> >> Could it work if we just use 1ULL instead of 1 here? Thanks, > > In either case we're talking about shifting off the end of the > variable, which I understand to be undefined. Right? Thanks, How so? Bits fall off the left (MSB) end, zeroes fill in the right (LSB) end. I believe that behavior is pretty set. The only problem here is that the promotion of integral types is (at the very least) unclear in this statement. As for the proposal, do we know that 1ULL is always going to be the same size as addr? I would suggest, as pedantic as it sounds, creating a local u64 variable, initialized to 1, and using that in the BUG_ON: u64 ubit = 1; ... if (mask) { BUG_ON(addr & ((ubit << (VTD_PAGE_SHIFT + mask)) - 1)); I believe this forces everything to be appropriately wide, and the same size?