lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20201105004412.GA24605@linux.intel.com>
Date:   Wed, 4 Nov 2020 16:44:12 -0800
From:   Sean Christopherson <sean.j.christopherson@...el.com>
To:     Paolo Bonzini <pbonzini@...hat.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 Thu, Oct 29, 2020 at 08:08:48AM +0100, Paolo Bonzini wrote:
> 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))
> 
> ?

Hmm, not awful?  What about OFFSET instead of INDEX, to pair with page offset?
I don't particularly love either one, but I can't think of anything better.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ