mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Jan Beulich" <JBeulich@novell.com>
To: "Peter Zijlstra" <a.p.zijlstra@chello.nl>,
	"Xiaowei Yang" <xiaowei.yang@huawei.com>
Cc: <fanhenglong@huawei.com>, "Kaushik Barde" <kbarde@huawei.com>,
	"Kenneth Lee" <liguozhu@huawei.com>,
	"linqaingmin" <linqiangmin@huawei.com>, <wangzhenguo@huawei.com>,
	"Wu Fengguang" <fengguang.wu@intel.com>,
	"Nick Piggin" <npiggin@kernel.dk>, <linux-kernel@vger.kernel.org>
Subject: Re: One (possible) x86 get_user_pages bug
Date: Thu, 27 Jan 2011 14:30:21 +0000	[thread overview]
Message-ID: <4D418F8D020000780002EC8F@vpn.id2.novell.com> (raw)
In-Reply-To: <1296136618.15234.187.camel@laptop>

>>> On 27.01.11 at 14:56, Peter Zijlstra <a.p.zijlstra@chello.nl> wrote:
> On Thu, 2011-01-27 at 21:05 +0800, Xiaowei Yang wrote:
>> 
>> However, from the comments embedded in gup.c, it seems deliberate to 
>> avoid the lock in the fast path. The question is: if so, how to avoid 
>> the above scenario? 
> 
> Something like the below comes to mind... but I must say I haven't fully
> considered the problem yet..

That doesn't seem to account for the possible case of the page
even managing to get allocated again to something else.

And I think you would need to drop out of gup_pte_range() in
that case.

I would think this needs to be get_page_unless_zero()
followed by re-checking of the page table entry (probably
not even requiring a second gup_get_pte()); I'm not sure
yet what the correct action would be for change in only the
accessed/dirty bits.

Jan

> ---
>  arch/x86/mm/gup.c |    9 +++++----
>  1 files changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
> index dbe34b9..6527933 100644
> --- a/arch/x86/mm/gup.c
> +++ b/arch/x86/mm/gup.c
> @@ -89,10 +89,11 @@ static noinline int gup_pte_range(pmd_t pmd, unsigned 
> long addr,
>  		}
>  		VM_BUG_ON(!pfn_valid(pte_pfn(pte)));
>  		page = pte_page(pte);
> -		get_page(page);
> -		SetPageReferenced(page);
> -		pages[*nr] = page;
> -		(*nr)++;
> +		if (get_page_unless_zero(page)) {
> +			SetPageReferenced(page);
> +			pages[*nr] = page;
> +			(*nr)++;
> +		}
>  
>  	} while (ptep++, addr += PAGE_SIZE, addr != end);
>  	pte_unmap(ptep - 1);




  reply	other threads:[~2011-01-27 14:30 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-27 13:05 Xiaowei Yang
2011-01-27 13:56 ` Peter Zijlstra
2011-01-27 14:30   ` Jan Beulich [this message]
2011-01-28 10:51     ` Peter Zijlstra
2011-01-27 14:49 ` Jan Beulich
2011-01-27 15:01   ` Peter Zijlstra
2011-01-27 18:27   ` Jeremy Fitzhardinge
2011-01-27 19:27     ` Peter Zijlstra
2011-01-30 13:01     ` Avi Kivity
2011-01-30 22:21       ` Kaushik Barde
2011-01-31 18:04         ` Jeremy Fitzhardinge
2011-01-31 20:10           ` Kaushik Barde
2011-01-31 22:10             ` Jeremy Fitzhardinge
2011-01-27 16:07 ` Jan Beulich
2011-01-27 16:25   ` Peter Zijlstra
2011-01-27 16:41     ` Jan Beulich
2011-01-27 16:56   ` Peter Zijlstra
2011-01-27 21:24   ` Nick Piggin
2011-01-28  7:17     ` Xiaowei Yang

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=4D418F8D020000780002EC8F@vpn.id2.novell.com \
    --to=jbeulich@novell.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=fanhenglong@huawei.com \
    --cc=fengguang.wu@intel.com \
    --cc=kbarde@huawei.com \
    --cc=liguozhu@huawei.com \
    --cc=linqiangmin@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=npiggin@kernel.dk \
    --cc=wangzhenguo@huawei.com \
    --cc=xiaowei.yang@huawei.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

Powered by JetHome