From: Alex Williamson Subject: Re: [PATCH] iommu/vt-d: Fix shift overflow in qi_flush_dev_iotlb Date: Wed, 13 Dec 2017 10:15:18 -0700 Message-ID: <20171213101518.7807ae4b@t450s.home> References: <20171212224250.22173.74201.stgit@gimli.home> <20171213071355.GD7780@xz-mi> <20171213085847.3d3245c6@t450s.home> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: iommu-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org Errors-To: iommu-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org To: "Hook, Gary" Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org, dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, tursulin-9sj9WOxYP5jR7s880joybQ@public.gmane.org List-Id: iommu@lists.linux-foundation.org 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 Thanks, Alex