Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753658AbdLMRbL (ORCPT ); Wed, 13 Dec 2017 12:31:11 -0500 Received: from mail-cys01nam02on0062.outbound.protection.outlook.com ([104.47.37.62]:2209 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753356AbdLMRbI (ORCPT ); Wed, 13 Dec 2017 12:31:08 -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 Cc: Peter Xu , 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> <20171213101518.7807ae4b@t450s.home> From: "Hook, Gary" Message-ID: Date: Wed, 13 Dec 2017 11:31:02 -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: <20171213101518.7807ae4b@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: MWHPR22CA0052.namprd22.prod.outlook.com (10.171.142.14) To DM5PR12MB1209.namprd12.prod.outlook.com (10.168.237.12) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 077ad861-132f-439b-4376-08d5424f4af7 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(48565401081)(5600026)(4604075)(2017052603307);SRVR:DM5PR12MB1209; X-Microsoft-Exchange-Diagnostics: 1;DM5PR12MB1209;3:3v3DIw2GUt58WZhDRaoukCwbjwSvR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1VY+iDHGGOQVVkhKixUaftyvjrplWPahGIIURHdvJX24UnEI1UVJ8r/1sciCd6dF0ae3oHNDtLBnd/Ek0T0Rmbkf0QU1nAWK5brJ2a9w3RJl1xevDedlfInb2NO+/3f5LAqbA0br3tPFOLBXLSlixuWlxXrevlmBpKXztk/vLnl/kHpS7sDjnV71qa3hRDIQ6ECepUEAN6VnbkHFzZkRDq9q3dVmaJbBo0NR4Dnds6G+IKywLxRMe68potkc4MPT8T4B3dKZs47B2Uic/IsXZtY3UShqoOv9mncbjn1/tNct6DPsMrHVt5ZJhNntYq1CzCdaqX33;4:yHZEoczfC35OL7bL4N7b+uG9FuV1Wli7Menva0NUbe4tjK5zZV0F1zxhshJUbdpWw4TgO3NyqJB7VEbPg6faUhE3Tw3GchYO/SoannxgxZmSigIOsHl3gbqOL92Lgdarwn5JdMYfTqLCRsSZCtuNxbaECDsssHa6Xv1EGyD2fsojLiO4uIK6JMAYE62lF8v3DwhaZtlZS8yqtcr5MwzOEtBshVJr5C1GbmZeK6g6cIZagGdTckVRqGRDCNu4bQBO2EGXh98ghNnlbH1H1V8HGDIEp27HPITfQU2aRzu8FI67UO6sBHXAQy8lCDsVZdTZ48upqm7qyy+5oEEH6DVROg== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110)(185212123834332); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040450)(2401047)(5005006)(8121501046)(3002001)(10201501046)(3231023)(93006095)(93001095)(6055026)(6041248)(20161123564025)(20161123555025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(20161123562025)(6072148)(201708071742011);SRVR:DM5PR12MB1209;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:DM5PR12MB1209; X-Forefront-PRVS: 052017CAF1 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6049001)(366004)(39860400002)(346002)(376002)(199004)(24454002)(189003)(76176011)(97736004)(52116002)(8936002)(6246003)(23676004)(52146003)(2486003)(8676002)(25786009)(67846002)(3260700006)(58126008)(68736007)(72206003)(478600001)(83506002)(53546011)(106356001)(16576012)(316002)(966005)(6306002)(53936002)(105586002)(65956001)(36756003)(7736002)(31686004)(66066001)(65826007)(50466002)(93886005)(6916009)(47776003)(305945005)(4326008)(16526018)(81156014)(6666003)(5660300001)(6486002)(3846002)(230700001)(64126003)(81166006)(6116002)(77096006)(31696002)(229853002)(2950100002)(386003)(90366009)(2906002)(65806001);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR12MB1209;H:[10.236.18.126];FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtETTVQUjEyTUIxMjA5OzIzOmlnWWhFcnk0b0NRVkNOZkdmVCtVK2lNMnRH?= =?utf-8?B?NWNjUnpoaUZaNUYwTTNucEFWRDZJVXZTa2V4SGhlQzNWTCtpQnZ2YzMzbXQx?= =?utf-8?B?Nm9NdFlaZWpFZmFhUEllTEJDcEF0YzRsWUJlV3VMalNZbnJHQ2J6ZlVxTlVU?= =?utf-8?B?VEtkTURvTjdONFlUTUxjUkVWN2c2b3VlenZhNjVYVzlRalR3ekN2M3RTM0xn?= =?utf-8?B?aXpwUHlyeGlFc3VwY1BPQWFSTlVmRGpMaWdXMVRWTDBnclc3ZXYvZXZLWDBh?= =?utf-8?B?SGROdldFenNTRi9nbW1xclZYTlJwRHJZdkV3d1lHVXBQcDF5KzVlREFueVlB?= =?utf-8?B?MHczaEd2elFmRW9sVzBlZ2JId2p4NnlKait1Rkc5eEhPUWczTkZma2xZOFpU?= =?utf-8?B?R0NZUzB4M3VhK3k4VGRUZGJySm5pZXEyUWRtRit0K3hrMlc2OHFtYm9Gd3BH?= =?utf-8?B?SGJGWDZWT3lwVkRvSmJ5MzZSb1JRSTdZMk9wek5LM3NuSjBaV09VZHZ3Q1Fp?= =?utf-8?B?QTFCRFYrQzZxMEhROWdwYVI3Z0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qNYADY3DkXEboispQQvLsocNhwWjo6fUyYSsCBu+4jVK5Rru9tEiXGcyiq/fyijYyjg7/+UI2vs1BamfCmNnspGZIIcrffrMGRoVQnp+Ppyt3g=;24:obfEnAMKzHQcH1QV+KIGUkLcjLKozgTF9khejjOx+IUqPytSUoLymrv2koDd+l1qrbyf+IDRvvtc1U2Tz2qcGiPoKmJM2ZAk2W4j+lHW7xY=;7:R728ealyfeh7ETI4mon0Ccsoe6FiwmjEHsTgbJSqjY3akIYwbnWvA5tMWJHoV5LuZDoqRQ2Gwi+NhKl8gdkAtWnmcLCSI3RcqSRYpYb7OVV1TfbYkwN9TJtvamiBTpdk5cWR/aNhA5sp9N1w9BFM4hpeSK+t9a6CuGh9FnwwY8PP2mAYxuDrLMt+iPJ6SBdkvLSykvuCTj/kCzduwd6D4tAD1/74N41C+b7z6H/pxbsVGAsuwgfYxzxbniAthNKI SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;DM5PR12MB1209;20:ZoJD9CCKt0G8MKl9cJ3UmycKzNLNtual8iqIrtG4XKSMcsO8C/H/OCnwM6mr1go+Zv/kTerEsccujHH0GohGmbhNzNiBBoOd4O7vqh3UR34dyLnR5sbAEu4/BgqE5OZxHmoBcY2//dolE44LO8HQTdoagAH1xBZsmO8PuhHAzJE4hhITnX7oiZglECN3i9ByUKolpO2R1G23DyUV+ZevT7snQV9zdKv+yw5LqAp+N+XVBJgTNIGvvrVUxPjUmEFo X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Dec 2017 17:31:06.2080 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 077ad861-132f-439b-4376-08d5424f4af7 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1209 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1796 Lines: 45 On 12/13/2017 11:15 AM, Alex Williamson wrote: > On Wed, 13 Dec 2017 10:41:47 -0600 > "Hook, Gary" wrote: > >> 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. > > Maybe I'm relying too much on stackoverflow, but: > > https://stackoverflow.com/questions/11270492/what-does-the-c-standard-say-about-bitshifting-more-bits-than-the-width-of-type No, probably not. I don't have my copy of c99 handy, so can't check it. But it is beyond me why any compiler implementation would choose to use a rotate instead of a shift... probably a performance issue. So, yeah, when you have silly parameters, you get what you get. I'll stick to my suggestion. Which seems unambiguous... but I could be wrong.