From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E0531B6CE9 for ; Thu, 23 Apr 2026 13:11:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776949885; cv=none; b=X7Y9bCutqHaRg4YdgKhCPAlQOgiE9o0Ur/uBpPqTvFr1LtkMkBOeGjRzgTmPCzrBfEHh92vA2TCr0LyF9QPGPHBiIYe1HxU0T88Yz6zONlaeTf6CYCjW8z9jIRtK+lQ1jB+HuR1rq9oAcVhPxEGhJpm5uEM0aakpm2Uz18Z7jY0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776949885; c=relaxed/simple; bh=NgNx5Wx9WFx543DniRV0daakH/1Qxo617y5uaLhM+y8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=t9uyh7TfjtlEK6ErYLAHK2fgqJ+4abyDWTURqyur0Hmb+3mbKK+sTH1DEnNbFkMrIW3FuSVHH9qgB/OuazyBKHay1NDJfKp32m4nQ9YFRLqtrgVRXIyntfi3NM1Eqv4hZtzDwcV6B3DglMcmfOx+FrdchtLcndbTG7T/7rOru4U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=zr9ltmpH; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="zr9ltmpH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CBFDDC2BCAF; Thu, 23 Apr 2026 13:11:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1776949885; bh=NgNx5Wx9WFx543DniRV0daakH/1Qxo617y5uaLhM+y8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=zr9ltmpHiAFJSCjm6cVQGCv0pX9x8gQffjtVQwifkogwK5JxYx3eNqkRPpxbQEs8P 6R9NJSkoG9+IG3I38q0VHX1936NLu37nkbwumAltDTIWATIRcEVutZOlkXIVYPswH1 xC6rVI06nA11QuCwzYng7C/BhoxhszjB5LxyHeUI= Date: Thu, 23 Apr 2026 15:11:22 +0200 From: Greg Kroah-Hartman To: "David Hildenbrand (Arm)" Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Jason Gunthorpe , John Hubbard , Peter Xu Subject: Re: [PATCH] mm/gup: honour FOLL_PIN in NOMMU __get_user_pages_locked() Message-ID: <2026042357-elderly-mute-6cae@gregkh> References: <2026042334-acutely-unadorned-e05c@gregkh> <2026042314-traffic-riverbank-d9a1@gregkh> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Thu, Apr 23, 2026 at 03:04:56PM +0200, David Hildenbrand (Arm) wrote: > > >> It just follows what we do everywhere else (e.g., follow_page_pte()). > >> > >> > >>> + if (try_grab_folio(page_folio(pages[i]), 1, > >>> + foll_flags)) { > >>> + pages[i] = NULL; > >>> + break; > >>> + } > >>> + } > >> > >> If it fails on the first iteration, we return -EFAULT instead of -ENOMEM. > >> > >> I know, I know, nobody cares. But if we touch it, we might just want to return > >> the error we get from try_grab_folio(). > > > > So just abort here and return it? No, that will not work, there's a > > lock we would jump around. How about something like this horrid thing, > > adding back in the relevant unlikely() to match the other calls like > > this: > > > > > > diff --git a/mm/gup.c b/mm/gup.c > > index ad9ded39609c..8fa5b37be8b7 100644 > > --- a/mm/gup.c > > +++ b/mm/gup.c > > @@ -1983,6 +1983,7 @@ static long __get_user_pages_locked(struct mm_struct *mm, unsigned long start, > > struct vm_area_struct *vma; > > bool must_unlock = false; > > vm_flags_t vm_flags; > > + int ret; > > long i; > > > > if (!nr_pages) > > @@ -2019,8 +2020,15 @@ static long __get_user_pages_locked(struct mm_struct *mm, unsigned long start, > > > > if (pages) { > > pages[i] = virt_to_page((void *)start); > > - if (pages[i]) > > - get_page(pages[i]); > > + if (pages[i]) { > > + ret = try_grab_folio(page_folio(pages[i]), 1, > > + foll_flags); > > + if (unlikely(ret)) { > > + pages[i] = NULL; > > + i = ret; > > + break; > > So, we have to report the old i in case of an error. > > Assuming we want to also return -EFAULT on !pages[i] -- which i think we want, > maybe the following (uncompiled and untested)? > > diff --git a/mm/gup.c b/mm/gup.c > index ad9ded39609c..d00ff8d988fa 100644 > --- a/mm/gup.c > +++ b/mm/gup.c > @@ -1983,6 +1983,7 @@ static long __get_user_pages_locked(struct mm_struct *mm, unsigned long start, > struct vm_area_struct *vma; > bool must_unlock = false; > vm_flags_t vm_flags; > + int ret, err = -EFAULT; > long i; > > if (!nr_pages) > @@ -2019,8 +2020,14 @@ static long __get_user_pages_locked(struct mm_struct *mm, unsigned long start, > > if (pages) { > pages[i] = virt_to_page((void *)start); > - if (pages[i]) > - get_page(pages[i]); > + if (!pages[i]) > + break; > + ret = try_grab_folio(page_folio(pages[i]), 1, foll_flags); > + if (ret) { > + pages[i] = NULL; > + err = ret; > + break > + } > } > > start = (start + PAGE_SIZE) & PAGE_MASK; > @@ -2031,7 +2038,7 @@ static long __get_user_pages_locked(struct mm_struct *mm, unsigned long start, > *locked = 0; > } > > - return i ? : -EFAULT; > + return i ? : err; > } > #endif /* !CONFIG_MMU */ Cool, let me through this at my reproducer and see how it goes! Ugh, nommu...