Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1286800rdb; Mon, 2 Oct 2023 05:20:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFL4+tR2m2BehjdqUboA/9K6JEuIe0onRq3KrUxIbycJqb+iVzEcnw027kvNBdd0B8FLyct X-Received: by 2002:a05:6870:440d:b0:1d4:dce5:332e with SMTP id u13-20020a056870440d00b001d4dce5332emr14310890oah.51.1696249201538; Mon, 02 Oct 2023 05:20:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696249201; cv=none; d=google.com; s=arc-20160816; b=EC8zl5tuNVo2K4W4at8lrKVWO8YpaI2MF2FGnmWvmuFeeU+aHcrj0BuMKy2bDLMGiJ EAQNwptGkSfij2LyJDMgtmbkpr1gucKU4jMvujCYbjxXVn8wQlFT55SJ9Y32+0uoVm7M 2Ofp0TjiPFIuRdryZ7QMFEl99VdZL6RFCyylPZv+tZzTv8ngD0SHiIzofv3OmaJDh6rS NulxUj0lQFKKeAwV+fQbYWuASYSBloX8zMTxInoop1c8OESoQ/7y7VAkD4CVpPVUuANQ +E32DGcxu8cBZtvaCXiOxyDvHBPP5bC5hkUjvXSghtEJmNPSgSuSSlXiaNuwXeTzIEgd TYnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=Gtgcf+hFLMW3q0sfoiNdr0OOcMu3cpe/tcYTwFuRDbE=; fh=JJ8aRrpI7BiSqERYEJ/uCOnbMrZPXb+v6eLQfglDdgw=; b=VhrOrNq3baGZlFUTI9euIjkIGsJcH1CYWqeDsUzu4WTrrFu9MAp/xHrA21bNdLph4r ETf5vz5oAVHmqQDRNLBXcZr/gzhOt2H7HJRTPsnYkQ4gGzmW5BWnnK4J6kz7ufE/rJ7L 3Wu4nzRdxavC6RicyEgVna6jk07TcaZXqz/fX16mPTrn3X+RP3NNTL49klQuiMHDItuS N4Pt54BM87e9zJ9qXx7MvdRkOZlHj3klp9evrKgbJFFtd0STJyGH03PLQVY/SZ5imNRv RH8MCo5gP7fsBvVF3D0bZOGwpdf73M+t9uWbtbJ+Gi5C6aa3VIY9To4HiOQkZF4oY/6w 2vgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fTUhKWz2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id v10-20020a63610a000000b005853066063csi13935008pgb.857.2023.10.02.05.20.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 05:20:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fTUhKWz2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 05F2F80C2E02; Mon, 2 Oct 2023 04:10:00 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236626AbjJBLJv (ORCPT + 99 others); Mon, 2 Oct 2023 07:09:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236589AbjJBLJu (ORCPT ); Mon, 2 Oct 2023 07:09:50 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94671BF for ; Mon, 2 Oct 2023 04:09:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696244941; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Gtgcf+hFLMW3q0sfoiNdr0OOcMu3cpe/tcYTwFuRDbE=; b=fTUhKWz2Hf9CLaigVkLY3/m5cOpLVaQNOOAbqq0MwMqc5p865egc4a4m/aX3rII3/XuhWn KfWeN7sNYXiBb/ELhyXX3PxB9GBlqxf6JUIxsnSvzrF2YokPoe1FyhggSu1SxeXS8SLOSF Atwi0EfCbIOLVV3AAIGDoBiGPm2hXAw= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-605-LgO5wN2SN22YmALPnfL5eQ-1; Mon, 02 Oct 2023 07:08:54 -0400 X-MC-Unique: LgO5wN2SN22YmALPnfL5eQ-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4055ce1e8c4so12653255e9.0 for ; Mon, 02 Oct 2023 04:08:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696244923; x=1696849723; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Gtgcf+hFLMW3q0sfoiNdr0OOcMu3cpe/tcYTwFuRDbE=; b=gKJPDQeZ/4BCUgf7LC5iTTvkP2XBUhWcj7DiKaQ+HlBim/sOlom8ic45xljySFvDGl vLiWzpvDEF9osfbJqrn21ZjwxJHsoXOJ4Ws0/GOh2B3R8tBZY6oXCWyXFC9gSln+cDq1 8HQiKjLh4lPzMYMzMV7urakmlq2/Pre/rngC1dNKpjo3W1c/bRNJTRxiciiW+SQzpPhq xGprcWLrcUWE4YoykC+rwPBCdvZSmNjlKLwcxyT+Gj9U/VTzA9xxWo3EDRZP6NiRivq/ mceHNcrIyGv5A9WbeJEmpcvKUa9BFbiHeFOqh7/59EdGsU8Iupo8cToEpcA6pxov7JKC kqHg== X-Gm-Message-State: AOJu0Yytz1yckXD91dqP2HxH6mZ7lx/BEiXrPpqnlZRdOA+KNYHwscgA bQ6dyuki0dNAmWORm5BAkbmZHhh7BJIIjPPGcQT7seSxuS5+MHzqvEQKi4/dRWnAzkToRYRK/Sk k7NHcnrs7fWGNqvF+R5D17Sw/ X-Received: by 2002:a5d:6e53:0:b0:323:2c2b:baf0 with SMTP id j19-20020a5d6e53000000b003232c2bbaf0mr9621451wrz.15.1696244923523; Mon, 02 Oct 2023 04:08:43 -0700 (PDT) X-Received: by 2002:a5d:6e53:0:b0:323:2c2b:baf0 with SMTP id j19-20020a5d6e53000000b003232c2bbaf0mr9621435wrz.15.1696244923114; Mon, 02 Oct 2023 04:08:43 -0700 (PDT) Received: from ?IPV6:2003:cb:c735:f200:cb49:cb8f:88fc:9446? (p200300cbc735f200cb49cb8f88fc9446.dip0.t-ipconnect.de. [2003:cb:c735:f200:cb49:cb8f:88fc:9446]) by smtp.gmail.com with ESMTPSA id g16-20020adfa490000000b003232380ffd5sm19920471wrb.106.2023.10.02.04.08.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 02 Oct 2023 04:08:42 -0700 (PDT) Message-ID: Date: Mon, 2 Oct 2023 13:08:41 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH 4/4] mm/gup: adapt get_user_page_vma_remote() to never return NULL Content-Language: en-US To: Lorenzo Stoakes , 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 Cc: Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Oleg Nesterov , Richard Cochran , Jason Gunthorpe , John Hubbard , Arnd Bergmann References: From: David Hildenbrand Organization: Red Hat In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email 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 (groat.vger.email [0.0.0.0]); Mon, 02 Oct 2023 04:10:00 -0700 (PDT) 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? > + 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