From: "Hook, Gary" <ghook@amd.com>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: Peter Xu <peterx@redhat.com>,
iommu@lists.linux-foundation.org, dwmw2@infradead.org,
linux-kernel@vger.kernel.org, tursulin@ursulin.net
Subject: Re: [PATCH] iommu/vt-d: Fix shift overflow in qi_flush_dev_iotlb
Date: Wed, 13 Dec 2017 11:31:02 -0600 [thread overview]
Message-ID: <b8d7c8fd-8370-a0f0-e5db-f211423d7b9b@amd.com> (raw)
In-Reply-To: <20171213101518.7807ae4b@t450s.home>
On 12/13/2017 11:15 AM, Alex Williamson wrote:
> On Wed, 13 Dec 2017 10:41:47 -0600
> "Hook, Gary" <ghook@amd.com> wrote:
>
>> On 12/13/2017 9:58 AM, Alex Williamson wrote:
>>> On Wed, 13 Dec 2017 15:13:55 +0800
>>> Peter Xu <peterx@redhat.com> 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.
next prev parent reply other threads:[~2017-12-13 17:31 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-12 22:43 Alex Williamson
2017-12-13 7:13 ` Peter Xu
2017-12-13 15:58 ` Alex Williamson
2017-12-13 16:41 ` Hook, Gary
2017-12-13 17:15 ` Alex Williamson
2017-12-13 17:31 ` Hook, Gary [this message]
2017-12-15 7:29 ` Peter Xu
2017-12-15 3:12 ` kbuild test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b8d7c8fd-8370-a0f0-e5db-f211423d7b9b@amd.com \
--to=ghook@amd.com \
--cc=alex.williamson@redhat.com \
--cc=dwmw2@infradead.org \
--cc=iommu@lists.linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterx@redhat.com \
--cc=tursulin@ursulin.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®