linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mike Kravetz <mike.kravetz@oracle.com>
To: Axel Rasmussen <axelrasmussen@google.com>
Cc: "Alexander Viro" <viro@zeniv.linux.org.uk>,
	"Alexey Dobriyan" <adobriyan@gmail.com>,
	"Andrea Arcangeli" <aarcange@redhat.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Anshuman Khandual" <anshuman.khandual@arm.com>,
	"Catalin Marinas" <catalin.marinas@arm.com>,
	"Chinwen Chang" <chinwen.chang@mediatek.com>,
	"Huang Ying" <ying.huang@intel.com>,
	"Ingo Molnar" <mingo@redhat.com>, "Jann Horn" <jannh@google.com>,
	"Jerome Glisse" <jglisse@redhat.com>,
	"Lokesh Gidra" <lokeshgidra@google.com>,
	"Matthew Wilcox (Oracle)" <willy@infradead.org>,
	"Michael Ellerman" <mpe@ellerman.id.au>,
	"Michal Koutný" <mkoutny@suse.com>,
	"Michel Lespinasse" <walken@google.com>,
	"Mike Rapoport" <rppt@linux.vnet.ibm.com>,
	"Nicholas Piggin" <npiggin@gmail.com>,
	"Peter Xu" <peterx@redhat.com>, "Shaohua Li" <shli@fb.com>,
	"Shawn Anastasio" <shawn@anastas.io>,
	"Steven Rostedt" <rostedt@goodmis.org>,
	"Steven Price" <steven.price@arm.com>,
	"Vlastimil Babka" <vbabka@suse.cz>,
	LKML <linux-kernel@vger.kernel.org>,
	linux-fsdevel@vger.kernel.org, "Linux MM" <linux-mm@kvack.org>,
	"Adam Ruprecht" <ruprecht@google.com>,
	"Cannon Matthews" <cannonmatthews@google.com>,
	"Dr . David Alan Gilbert" <dgilbert@redhat.com>,
	"David Rientjes" <rientjes@google.com>,
	"Mina Almasry" <almasrymina@google.com>,
	"Oliver Upton" <oupton@google.com>
Subject: Re: [PATCH v7 1/6] userfaultfd: add minor fault registration mode
Date: Thu, 25 Feb 2021 10:48:04 -0800	[thread overview]
Message-ID: <0c0c8e86-cf60-12d1-2260-2a7215493fd5@oracle.com> (raw)
In-Reply-To: <CAJHvVch4iweAW274Ub5Q_oKgZaTHvEkGnE4=jo6SfxOs1qCf6A@mail.gmail.com>

On 2/25/21 9:49 AM, Axel Rasmussen wrote:
> On Wed, Feb 24, 2021 at 4:26 PM Mike Kravetz <mike.kravetz@oracle.com> wrote:
>>
>> On 2/18/21 4:48 PM, Axel Rasmussen wrote:
>> <snip>
>>> @@ -401,8 +398,10 @@ vm_fault_t handle_userfault(struct vm_fault *vmf, unsigned long reason)
>>>
>>>       BUG_ON(ctx->mm != mm);
>>>
>>> -     VM_BUG_ON(reason & ~(VM_UFFD_MISSING|VM_UFFD_WP));
>>> -     VM_BUG_ON(!(reason & VM_UFFD_MISSING) ^ !!(reason & VM_UFFD_WP));
>>> +     /* Any unrecognized flag is a bug. */
>>> +     VM_BUG_ON(reason & ~__VM_UFFD_FLAGS);
>>> +     /* 0 or > 1 flags set is a bug; we expect exactly 1. */
>>> +     VM_BUG_ON(!reason || !!(reason & (reason - 1)));
>>
>> I may be confused, but that seems to be checking for a flag value of 1
>> as opposed to one flag being set?
> 
> (Assuming I implemented it correctly!) It's the logical negation of
> this trick: https://graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2
> So, it's "VM_BUG_ON(reason is *not* a power of 2)".
> 
> Maybe the double negation makes it overly confusing? It ought to be
> equivalent if we remove it and just say:
> VM_BUG_ON(!reason || (reason & (reason - 1)));

Sorry, my bad.  In my mind I was thinking,

	VM_BUG_ON(!reason || !!(reason && (reason - 1)));

-- 
Mike Kravetz

  reply	other threads:[~2021-02-25 18:50 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-19  0:48 [PATCH v7 0/6] userfaultfd: add minor fault handling Axel Rasmussen
2021-02-19  0:48 ` [PATCH v7 1/6] userfaultfd: add minor fault registration mode Axel Rasmussen
2021-02-23 15:20   ` Peter Xu
2021-02-25  0:24   ` Mike Kravetz
2021-02-25 17:49     ` Axel Rasmussen
2021-02-25 18:48       ` Mike Kravetz [this message]
2021-02-19  0:48 ` [PATCH v7 2/6] userfaultfd: disable huge PMD sharing for MINOR registered VMAs Axel Rasmussen
2021-02-25  0:33   ` Mike Kravetz
2021-02-19  0:48 ` [PATCH v7 3/6] userfaultfd: hugetlbfs: only compile UFFD helpers if config enabled Axel Rasmussen
2021-02-19  0:48 ` [PATCH v7 4/6] userfaultfd: add UFFDIO_CONTINUE ioctl Axel Rasmussen
2021-02-23 15:38   ` Peter Xu
2021-02-23 18:05     ` Axel Rasmussen
2021-02-23 18:28       ` Peter Xu
2021-02-19  0:48 ` [PATCH v7 5/6] userfaultfd: update documentation to describe minor fault handling Axel Rasmussen
2021-02-19  0:48 ` [PATCH v7 6/6] userfaultfd/selftests: add test exercising " Axel Rasmussen

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=0c0c8e86-cf60-12d1-2260-2a7215493fd5@oracle.com \
    --to=mike.kravetz@oracle.com \
    --cc=aarcange@redhat.com \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=almasrymina@google.com \
    --cc=anshuman.khandual@arm.com \
    --cc=axelrasmussen@google.com \
    --cc=cannonmatthews@google.com \
    --cc=catalin.marinas@arm.com \
    --cc=chinwen.chang@mediatek.com \
    --cc=dgilbert@redhat.com \
    --cc=jannh@google.com \
    --cc=jglisse@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lokeshgidra@google.com \
    --cc=mingo@redhat.com \
    --cc=mkoutny@suse.com \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@gmail.com \
    --cc=oupton@google.com \
    --cc=peterx@redhat.com \
    --cc=rientjes@google.com \
    --cc=rostedt@goodmis.org \
    --cc=rppt@linux.vnet.ibm.com \
    --cc=ruprecht@google.com \
    --cc=shawn@anastas.io \
    --cc=shli@fb.com \
    --cc=steven.price@arm.com \
    --cc=vbabka@suse.cz \
    --cc=viro@zeniv.linux.org.uk \
    --cc=walken@google.com \
    --cc=willy@infradead.org \
    --cc=ying.huang@intel.com \
    /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;
as well as URLs for NNTP newsgroup(s).