Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1620630rdb; Mon, 2 Oct 2023 15:56:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEeaKFB0OmRB2LyeGZlImoMEdTGSucK1U0D+sKaHKgaOD9X4/On9AhR2EGDgE253s4JdYUc X-Received: by 2002:a17:903:2443:b0:1c7:22ae:4080 with SMTP id l3-20020a170903244300b001c722ae4080mr1811174pls.0.1696287406259; Mon, 02 Oct 2023 15:56:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696287406; cv=none; d=google.com; s=arc-20160816; b=QqZIRunS6C+uyG3dbLfwPArs3Zagw3pUFMRLiq9g+EimMcHvEQiJ1SIGLYbV84LClX XRo+90CAX3AiFYzBvBByNJZmD2h2jasH0pjJcVPWA2l/OJHfyN4i04SUzje9XL9Dclsi xfDUQRxb/K8LOWE52M1yF8zm+P4AxpfdJbLLq/HRfipaxO1vuWo5nj6iQTbnwaXx+kE2 yThSEOMMU8V8JB9KyRMc7Rid2iqAPRHuxc+g7VFU2mFwiGKwcSOFNmXgJb352cVzVtNh +cK0xRSKGJcowjgqVbx0yc1IJ2h9OufAspeqVr8C+bWZy5p7nI8h0XSySEgFu/G7Ln8m aBfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ImvWh+2gFsWJ7StqF/6mOZboIVtJA4miy8m0Nl6hNSk=; fh=l04N9FNvgf8DL4t+KIZynVbeKBRTfZE0LUiPok1Fnrc=; b=IJX6pTDfOcg8lOmKudIQU2l8Tdqb4WZp3uvlk3fDC+1No1TMU92i+ouxbrdOdPlAFJ 0CUteJr1AQBHZzlw9ENgborvbANHipCMEJwFwTbypKoIJLsgnTs5ne2RWyi1sWCfxE7n 4vBEpMgCkpxAjXuM3np+kWqc7caFY62B+H8EOKDGf7JCPmCwneZshUHEyqn1cRBota7o slfg8CppLLDVM5IE24wR7BIjsKzI7VhpOp0rn0ETJi52F1B1iO7LHMLXiGbHBprCzasB gDX13F6OfP2EA+mqcTnxtkxuv3CRJm7dGlI5DWuw7SLMNPdyZ57qeDuI9msmvdD3nAI9 H8bA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=E7xu8MxV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id b7-20020a170903228700b001c3c75842f1si21760027plh.14.2023.10.02.15.56.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 15:56:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=E7xu8MxV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 66784809E735; Mon, 2 Oct 2023 15:56:45 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230077AbjJBW4o (ORCPT + 99 others); Mon, 2 Oct 2023 18:56:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229823AbjJBW4o (ORCPT ); Mon, 2 Oct 2023 18:56:44 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B65509E for ; Mon, 2 Oct 2023 15:56:39 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-4053c6f0db8so3035025e9.3 for ; Mon, 02 Oct 2023 15:56:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696287398; x=1696892198; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=ImvWh+2gFsWJ7StqF/6mOZboIVtJA4miy8m0Nl6hNSk=; b=E7xu8MxVr6S0zAdLBKWVPuR1Z80KdlVTKSSx7boHTHumGSlYgpSSYsfVME1NV5F1/N 2nY+vJ8Dvoa3Gc3h/tqMqGKfgHNzs5STjg5cHA3RLBqgBbl4MNx5Fk4rIdlmsG0BQFZP QRKWobjccPwEa4s2QwW8jtYn9t3txhJ6Xw4/3cl8gDiFWUGu52tNKBCVH6sFTx4c/GMt 4RkujR2b6M6ypptxqSg6X6XS4AwLdR/+xZTI9PUGAJ5mrB5Mz1bWMzCMWuHxU3uyeOqN iyS8BmKDV3ksPH6wbL8UW/XrE/rV7qpXtNv2gRSsAexr9EhjFmRPZK+7dnE7LqPZgpcb d3iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696287398; x=1696892198; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ImvWh+2gFsWJ7StqF/6mOZboIVtJA4miy8m0Nl6hNSk=; b=n1nsNw8vHwhnZQM8HXOOmUHY0VDQpp9ap5QPtnSaEw6kt7M7ht5z6jz0i2I+/Ln+fN syzLrwcZ5X814N9BY5+IFcpzUPteE3ZyIFFpJr1XsW0w+yGBDEbcilzrB0gSf3jUvUs0 6l1OthGUn9OL1bCHuYC3mKud0J/oyNVaXqFxvb08EkQIU9GuslMW+MkjriC28BJ8/4DR 1Pc1TBDYRhipQBWRecjTxh+WaRjID1+/8mESJsDzO8UMYO5CK239EieciBgD+BKsjR/D J6g2QHZyfnQ3ylAxZ8zqzXLVCB9v1nO44I5WPzP/K0dio+QN4CRxN3WvlGQRJgVCP+U9 ly8g== X-Gm-Message-State: AOJu0Yw/cE93Bmv/CXPf9WDpc2IG6KzypobJMDKmvcORB+SuLdT9Gdhs K1NvtnfNZpvVvJoaZELOogv4HD820po= X-Received: by 2002:adf:eecd:0:b0:314:a3f:9c08 with SMTP id a13-20020adfeecd000000b003140a3f9c08mr10062481wrp.39.1696287397782; Mon, 02 Oct 2023 15:56:37 -0700 (PDT) Received: from localhost ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.gmail.com with ESMTPSA id s11-20020adff80b000000b0031ad2f9269dsm34796wrp.40.2023.10.02.15.56.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 15:56:37 -0700 (PDT) Date: Mon, 2 Oct 2023 23:56:36 +0100 From: Lorenzo Stoakes To: David Hildenbrand Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Catalin Marinas , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Oleg Nesterov , Richard Cochran , Jason Gunthorpe , John Hubbard , Arnd Bergmann Subject: Re: [PATCH 4/4] mm/gup: adapt get_user_page_vma_remote() to never return NULL Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 02 Oct 2023 15:56:45 -0700 (PDT) On Mon, Oct 02, 2023 at 01:08:41PM +0200, David Hildenbrand wrote: > 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 > > Signed-off-by: Lorenzo Stoakes > > --- > > 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? We have no callers who want to do that, will WARN_ON_ONCE() and update comment in v2. > > > + 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." Well you'd need to put it at all the other callers of __get_user_pages_locked() too :) so I think probably not worth doing that, at least in this patch series. In any case, we have explicitly added this check there to ensure that's not possible so I think we're good, will just strip in v2. > > -- > Cheers, > > David / dhildenb >