[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <e3d68b2b-2af6-04ce-c5f6-47786d9a15bb@redhat.com>
Date: Thu, 29 Oct 2020 08:08:48 +0100
From: Paolo Bonzini <pbonzini@...hat.com>
To: Sean Christopherson <sean.j.christopherson@...el.com>
Cc: Vitaly Kuznetsov <vkuznets@...hat.com>,
Wanpeng Li <wanpengli@...cent.com>,
Jim Mattson <jmattson@...gle.com>,
Joerg Roedel <joro@...tes.org>, kvm@...r.kernel.org,
linux-kernel@...r.kernel.org, Ben Gardon <bgardon@...gle.com>
Subject: Re: [PATCH 0/3] KVM: x86/mmu: Add macro for hugepage GFN mask
On 28/10/20 16:29, Sean Christopherson wrote:
> The naming and usage also aligns with the kernel, which defines PAGE, PMD and
> PUD masks, and has near identical usage patterns.
>
> #define PAGE_SIZE (_AC(1,UL) << PAGE_SHIFT)
> #define PAGE_MASK (~(PAGE_SIZE-1))
>
> #define PMD_PAGE_SIZE (_AC(1, UL) << PMD_SHIFT)
> #define PMD_PAGE_MASK (~(PMD_PAGE_SIZE-1))
>
> #define PUD_PAGE_SIZE (_AC(1, UL) << PUD_SHIFT)
> #define PUD_PAGE_MASK (~(PUD_PAGE_SIZE-1))
Well, PAGE_MASK is also one of my pet peeves for Linux. At least I am
consistent. :)
>> and of course if you're debugging it you have to
>> look closer and check if it's really "x & -y" or "x & ~y", but at least
>> in normal cursory code reading that's how it works for me.
>
> IMO, "x & -y" has a higher barrier to entry, especially when the kernel's page
> masks uses "x & ~(y - 1))". But, my opinion is definitely colored by my
> inability to read two's-complement on the fly.
Fair enough. What about having instead
#define KVM_HPAGE_GFN_BASE(gfn, level) \
(x & ~(KVM_PAGES_PER_HPAGE(gfn) - 1))
#define KVM_HPAGE_GFN_INDEX(gfn, level) \
(x & (KVM_PAGES_PER_HPAGE(gfn) - 1))
?
Paolo
Powered by blists - more mailing lists