linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Lorenzo Stoakes <lstoakes@gmail.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
	Ian Rogers <irogers@google.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Oleg Nesterov <oleg@redhat.com>,
	Richard Cochran <richardcochran@gmail.com>,
	Jason Gunthorpe <jgg@nvidia.com>,
	John Hubbard <jhubbard@nvidia.com>, Arnd Bergmann <arnd@arndb.de>
Subject: Re: [PATCH 4/4] mm/gup: adapt get_user_page_vma_remote() to never return NULL
Date: Mon, 2 Oct 2023 13:08:41 +0200	[thread overview]
Message-ID: <f29e6a5d-39db-8f11-2182-1f13c97882c9@redhat.com> (raw)
In-Reply-To: <b57d5f6618818f2f781a664039ace025c932074c.1696174961.git.lstoakes@gmail.com>

On 01.10.23 18:00, Lorenzo Stoakes wrote:
> get_user_pages_remote() will never return 0 except in the case of
> FOLL_NOWAIT being specified, which we explicitly disallow.
> 
> This simplifies error handling for the caller and avoids the awkwardness of
> dealing with both errors and failing to pin. Failing to pin here is an
> error.
> 
> Suggested-by: Arnd Bergmann <arnd@arndb.de>
> Signed-off-by: Lorenzo Stoakes <lstoakes@gmail.com>
> ---
>   arch/arm64/kernel/mte.c |  4 ++--
>   include/linux/mm.h      | 16 +++++++++++++---
>   kernel/events/uprobes.c |  4 ++--
>   mm/memory.c             |  3 +--
>   4 files changed, 18 insertions(+), 9 deletions(-)
> 
> diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c
> index 4edecaac8f91..8878b392df58 100644
> --- a/arch/arm64/kernel/mte.c
> +++ b/arch/arm64/kernel/mte.c
> @@ -411,8 +411,8 @@ static int __access_remote_tags(struct mm_struct *mm, unsigned long addr,
>   		struct page *page = get_user_page_vma_remote(mm, addr,
>   							     gup_flags, &vma);
>   
> -		if (IS_ERR_OR_NULL(page)) {
> -			err = page == NULL ? -EIO : PTR_ERR(page);
> +		if (IS_ERR(page)) {
> +			err = PTR_ERR(page);
>   			break;
>   		}
>   
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 7b89f7bd420d..da9631683d38 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -2425,6 +2425,7 @@ long pin_user_pages_remote(struct mm_struct *mm,
>   			   unsigned int gup_flags, struct page **pages,
>   			   int *locked);
>   
> +/* Either retrieve a single VMA and page, or an error. */
>   static inline struct page *get_user_page_vma_remote(struct mm_struct *mm,
>   						    unsigned long addr,
>   						    int gup_flags,
> @@ -2432,12 +2433,21 @@ static inline struct page *get_user_page_vma_remote(struct mm_struct *mm,
>   {
>   	struct page *page;
>   	struct vm_area_struct *vma;
> -	int got = get_user_pages_remote(mm, addr, 1, gup_flags, &page, NULL);
> +	int got;
> +
> +	if (unlikely(gup_flags & FOLL_NOWAIT))
> +		return ERR_PTR(-EINVAL);
> +

Do we have any callers or do we want to make that official (document it) 
and use WARN_ON_ONCE() instead?

> +	got = get_user_pages_remote(mm, addr, 1, gup_flags, &page, NULL);
>   
>   	if (got < 0)
>   		return ERR_PTR(got);
> -	if (got == 0)
> -		return NULL;
> +
> +	/*
> +	 * get_user_pages_remote() is guaranteed to not return 0 for
> +	 * non-FOLL_NOWAIT contexts, so this should never happen.
> +	 */
> +	VM_WARN_ON(got == 0);

You should probably just drop that. Not worth the comment + code and its 
better checked inside get_user_pages_remote().

Ideally, just document that behavior for get_user_pages_remote() "Will 
never return 0 without FOLL_NOWAIT."

-- 
Cheers,

David / dhildenb



  parent reply	other threads:[~2023-10-02 11:09 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-01 16:00 [PATCH 0/4] various improvements to the GUP interface Lorenzo Stoakes
2023-10-01 16:00 ` [PATCH 1/4] mm: make __access_remote_vm() static Lorenzo Stoakes
2023-10-02 10:59   ` David Hildenbrand
2023-10-09 22:16   ` Jason Gunthorpe
2023-10-01 16:00 ` [PATCH 2/4] mm/gup: explicitly define and check internal GUP flags, disallow FOLL_TOUCH Lorenzo Stoakes
2023-10-02 11:00   ` David Hildenbrand
2023-10-09 22:19   ` Jason Gunthorpe
2023-10-01 16:00 ` [PATCH 3/4] mm/gup: make failure to pin an error if FOLL_NOWAIT not specified Lorenzo Stoakes
2023-10-02 11:04   ` David Hildenbrand
2023-10-02 22:51     ` Lorenzo Stoakes
2023-10-09 22:22       ` Jason Gunthorpe
2023-10-01 16:00 ` [PATCH 4/4] mm/gup: adapt get_user_page_vma_remote() to never return NULL Lorenzo Stoakes
2023-10-02 10:16   ` Catalin Marinas
2023-10-02 11:08   ` David Hildenbrand [this message]
2023-10-02 22:56     ` Lorenzo Stoakes
2023-10-09 22:24   ` Jason Gunthorpe
2023-10-01 17:39 ` [PATCH 0/4] various improvements to the GUP interface Arnd Bergmann

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=f29e6a5d-39db-8f11-2182-1f13c97882c9@redhat.com \
    --to=david@redhat.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=arnd@arndb.de \
    --cc=catalin.marinas@arm.com \
    --cc=irogers@google.com \
    --cc=jgg@nvidia.com \
    --cc=jhubbard@nvidia.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lstoakes@gmail.com \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=oleg@redhat.com \
    --cc=peterz@infradead.org \
    --cc=richardcochran@gmail.com \
    --cc=will@kernel.org \
    /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