All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@mellanox.com>
To: Christoph Hellwig <hch@lst.de>
Cc: Jerome Glisse <jglisse@redhat.com>,
	Ralph Campbell <rcampbell@nvidia.com>,
	Felix.Kuehling@amd.com, linux-mm@kvack.org,
	John Hubbard <jhubbard@nvidia.com>,
	dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org,
	Philip Yang <Philip.Yang@amd.com>
Subject: Re: [PATCH hmm 2/6] mm/hmm: return the fault type from hmm_pte_need_fault()
Date: Mon, 23 Mar 2020 17:14:06 -0300	[thread overview]
Message-ID: <20200323201406.GD13183@mellanox.com> (raw)
In-Reply-To: <20200321083726.GB28695@lst.de>

On Sat, Mar 21, 2020 at 09:37:26AM +0100, Christoph Hellwig wrote:
> On Fri, Mar 20, 2020 at 01:49:01PM -0300, Jason Gunthorpe wrote:
> > +enum {
> > +	NEED_FAULT = 1 << 0,
> > +	NEED_WRITE_FAULT = 1 << 1,
> > +};
> 
> Maybe add a HMM_ prefix?

Yes, OK, the existing names are pretty generic
 
> >  	for (i = 0; i < npages; ++i) {
> > +		required_fault |=
> > +			hmm_pte_need_fault(hmm_vma_walk, pfns[i], cpu_flags);
> > +		if (required_fault == (NEED_FAULT | NEED_WRITE_FAULT))
> > +			return required_fault;
> 
> No need for the inner braces.

Techincally yes, but gcc demands them:

mm/hmm.c:146:22: warning: suggest parentheses around comparison in operand of '|' [-Wparentheses]
   if (required_fault == NEED_FAULT | NEED_WRITE_FAULT)
       ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~

Probably because | vs || is a common confusion?

Actually this whole NEED_FAULT | WRITE_FAULT thing is silly, I'm going
to define NEED_WRITE_FAULT == NEED_FAULT | (1<<1) and add a
NEED_ALL_BITS to make this clear what this test is for (early loop
exit once there is no possible change to required_fault).

> > @@ -532,17 +515,15 @@ static int hmm_vma_walk_test(unsigned long start, unsigned long end,
> >  	 */
> >  	if ((vma->vm_flags & (VM_IO | VM_PFNMAP | VM_MIXEDMAP)) ||
> >  	    !(vma->vm_flags & VM_READ)) {
> > -		bool fault, write_fault;
> > -
> 
> No that there is no need for local variables I'd invert the test and
> return early:

This is more readable, I reworked the comment too

Jason


WARNING: multiple messages have this Message-ID (diff)
From: Jason Gunthorpe <jgg@mellanox.com>
To: Christoph Hellwig <hch@lst.de>
Cc: Philip Yang <Philip.Yang@amd.com>,
	Ralph Campbell <rcampbell@nvidia.com>,
	John Hubbard <jhubbard@nvidia.com>,
	Felix.Kuehling@amd.com, dri-devel@lists.freedesktop.org,
	linux-mm@kvack.org, Jerome Glisse <jglisse@redhat.com>,
	amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH hmm 2/6] mm/hmm: return the fault type from hmm_pte_need_fault()
Date: Mon, 23 Mar 2020 17:14:06 -0300	[thread overview]
Message-ID: <20200323201406.GD13183@mellanox.com> (raw)
In-Reply-To: <20200321083726.GB28695@lst.de>

On Sat, Mar 21, 2020 at 09:37:26AM +0100, Christoph Hellwig wrote:
> On Fri, Mar 20, 2020 at 01:49:01PM -0300, Jason Gunthorpe wrote:
> > +enum {
> > +	NEED_FAULT = 1 << 0,
> > +	NEED_WRITE_FAULT = 1 << 1,
> > +};
> 
> Maybe add a HMM_ prefix?

Yes, OK, the existing names are pretty generic
 
> >  	for (i = 0; i < npages; ++i) {
> > +		required_fault |=
> > +			hmm_pte_need_fault(hmm_vma_walk, pfns[i], cpu_flags);
> > +		if (required_fault == (NEED_FAULT | NEED_WRITE_FAULT))
> > +			return required_fault;
> 
> No need for the inner braces.

Techincally yes, but gcc demands them:

mm/hmm.c:146:22: warning: suggest parentheses around comparison in operand of '|' [-Wparentheses]
   if (required_fault == NEED_FAULT | NEED_WRITE_FAULT)
       ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~

Probably because | vs || is a common confusion?

Actually this whole NEED_FAULT | WRITE_FAULT thing is silly, I'm going
to define NEED_WRITE_FAULT == NEED_FAULT | (1<<1) and add a
NEED_ALL_BITS to make this clear what this test is for (early loop
exit once there is no possible change to required_fault).

> > @@ -532,17 +515,15 @@ static int hmm_vma_walk_test(unsigned long start, unsigned long end,
> >  	 */
> >  	if ((vma->vm_flags & (VM_IO | VM_PFNMAP | VM_MIXEDMAP)) ||
> >  	    !(vma->vm_flags & VM_READ)) {
> > -		bool fault, write_fault;
> > -
> 
> No that there is no need for local variables I'd invert the test and
> return early:

This is more readable, I reworked the comment too

Jason
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

WARNING: multiple messages have this Message-ID (diff)
From: Jason Gunthorpe <jgg@mellanox.com>
To: Christoph Hellwig <hch@lst.de>
Cc: Philip Yang <Philip.Yang@amd.com>,
	Ralph Campbell <rcampbell@nvidia.com>,
	John Hubbard <jhubbard@nvidia.com>,
	Felix.Kuehling@amd.com, dri-devel@lists.freedesktop.org,
	linux-mm@kvack.org, Jerome Glisse <jglisse@redhat.com>,
	amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH hmm 2/6] mm/hmm: return the fault type from hmm_pte_need_fault()
Date: Mon, 23 Mar 2020 17:14:06 -0300	[thread overview]
Message-ID: <20200323201406.GD13183@mellanox.com> (raw)
In-Reply-To: <20200321083726.GB28695@lst.de>

On Sat, Mar 21, 2020 at 09:37:26AM +0100, Christoph Hellwig wrote:
> On Fri, Mar 20, 2020 at 01:49:01PM -0300, Jason Gunthorpe wrote:
> > +enum {
> > +	NEED_FAULT = 1 << 0,
> > +	NEED_WRITE_FAULT = 1 << 1,
> > +};
> 
> Maybe add a HMM_ prefix?

Yes, OK, the existing names are pretty generic
 
> >  	for (i = 0; i < npages; ++i) {
> > +		required_fault |=
> > +			hmm_pte_need_fault(hmm_vma_walk, pfns[i], cpu_flags);
> > +		if (required_fault == (NEED_FAULT | NEED_WRITE_FAULT))
> > +			return required_fault;
> 
> No need for the inner braces.

Techincally yes, but gcc demands them:

mm/hmm.c:146:22: warning: suggest parentheses around comparison in operand of '|' [-Wparentheses]
   if (required_fault == NEED_FAULT | NEED_WRITE_FAULT)
       ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~

Probably because | vs || is a common confusion?

Actually this whole NEED_FAULT | WRITE_FAULT thing is silly, I'm going
to define NEED_WRITE_FAULT == NEED_FAULT | (1<<1) and add a
NEED_ALL_BITS to make this clear what this test is for (early loop
exit once there is no possible change to required_fault).

> > @@ -532,17 +515,15 @@ static int hmm_vma_walk_test(unsigned long start, unsigned long end,
> >  	 */
> >  	if ((vma->vm_flags & (VM_IO | VM_PFNMAP | VM_MIXEDMAP)) ||
> >  	    !(vma->vm_flags & VM_READ)) {
> > -		bool fault, write_fault;
> > -
> 
> No that there is no need for local variables I'd invert the test and
> return early:

This is more readable, I reworked the comment too

Jason
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  reply	other threads:[~2020-03-23 20:14 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-20 16:48 [PATCH hmm 0/6] Small hmm_range_fault() cleanups Jason Gunthorpe
2020-03-20 16:48 ` Jason Gunthorpe
2020-03-20 16:48 ` Jason Gunthorpe
2020-03-20 16:49 ` [PATCH hmm 1/6] mm/hmm: remove pgmap checking for devmap pages Jason Gunthorpe
2020-03-20 16:49   ` Jason Gunthorpe
2020-03-20 16:49   ` Jason Gunthorpe
2020-03-21  8:24   ` Christoph Hellwig
2020-03-21  8:24     ` Christoph Hellwig
2020-03-20 16:49 ` [PATCH hmm 2/6] mm/hmm: return the fault type from hmm_pte_need_fault() Jason Gunthorpe
2020-03-20 16:49   ` Jason Gunthorpe
2020-03-20 16:49   ` Jason Gunthorpe
2020-03-21  8:37   ` Christoph Hellwig
2020-03-21  8:37     ` Christoph Hellwig
2020-03-23 20:14     ` Jason Gunthorpe [this message]
2020-03-23 20:14       ` Jason Gunthorpe
2020-03-23 20:14       ` Jason Gunthorpe
2020-03-20 16:49 ` [PATCH hmm 3/6] mm/hmm: remove unused code and tidy comments Jason Gunthorpe
2020-03-20 16:49   ` Jason Gunthorpe
2020-03-20 16:49   ` Jason Gunthorpe
2020-03-20 21:46   ` Ralph Campbell
2020-03-20 21:46     ` Ralph Campbell
2020-03-20 21:46     ` Ralph Campbell
2020-03-23 17:24     ` Jason Gunthorpe
2020-03-23 17:24       ` Jason Gunthorpe
2020-03-23 17:24       ` Jason Gunthorpe
2020-03-21  8:39   ` Christoph Hellwig
2020-03-21  8:39     ` Christoph Hellwig
2020-03-23 17:24     ` Jason Gunthorpe
2020-03-23 17:24       ` Jason Gunthorpe
2020-03-23 17:24       ` Jason Gunthorpe
2020-03-23 17:27       ` Christoph Hellwig
2020-03-23 17:27         ` Christoph Hellwig
2020-03-20 16:49 ` [PATCH hmm 4/6] mm/hmm: remove HMM_FAULT_SNAPSHOT Jason Gunthorpe
2020-03-20 16:49   ` Jason Gunthorpe
2020-03-20 16:49   ` Jason Gunthorpe
2020-03-21  8:40   ` Christoph Hellwig
2020-03-21  8:40     ` Christoph Hellwig
2020-03-20 16:49 ` [PATCH hmm 5/6] mm/hmm: remove the CONFIG_TRANSPARENT_HUGEPAGE #ifdef Jason Gunthorpe
2020-03-20 16:49   ` Jason Gunthorpe
2020-03-20 16:49   ` Jason Gunthorpe
2020-03-21  8:43   ` Christoph Hellwig
2020-03-21  8:43     ` Christoph Hellwig
2020-03-23 17:33     ` Jason Gunthorpe
2020-03-23 17:33       ` Jason Gunthorpe
2020-03-23 17:33       ` Jason Gunthorpe
2020-03-20 16:49 ` [PATCH hmm 6/6] mm/hmm: use device_private_entry_to_pfn() Jason Gunthorpe
2020-03-20 16:49   ` Jason Gunthorpe
2020-03-20 16:49   ` Jason Gunthorpe
2020-03-21  8:43   ` Christoph Hellwig
2020-03-21  8:43     ` Christoph Hellwig
2020-03-23 17:44     ` Jason Gunthorpe
2020-03-23 17:44       ` Jason Gunthorpe
2020-03-23 17:44       ` Jason Gunthorpe
2020-03-20 18:51 ` [PATCH hmm 0/6] Small hmm_range_fault() cleanups Ralph Campbell
2020-03-20 18:51   ` Ralph Campbell
2020-03-20 18:51   ` Ralph Campbell
2020-03-20 18:55   ` Jason Gunthorpe
2020-03-20 18:55     ` Jason Gunthorpe
2020-03-20 18:55     ` Jason Gunthorpe
2020-03-20 21:47 ` Ralph Campbell
2020-03-20 21:47   ` Ralph Campbell
2020-03-20 21:47   ` Ralph Campbell

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=20200323201406.GD13183@mellanox.com \
    --to=jgg@mellanox.com \
    --cc=Felix.Kuehling@amd.com \
    --cc=Philip.Yang@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hch@lst.de \
    --cc=jglisse@redhat.com \
    --cc=jhubbard@nvidia.com \
    --cc=linux-mm@kvack.org \
    --cc=rcampbell@nvidia.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.