Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp901390rdb; Sun, 1 Oct 2023 10:07:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IExt2A0kYd0RkzUUd1L3fguyNUAl3v3e9VI8TTq5dUTMjrXY9tihVsC9ipCVTgrgGq6qjJF X-Received: by 2002:aca:f1a:0:b0:3a7:55f2:552d with SMTP id 26-20020aca0f1a000000b003a755f2552dmr8980191oip.58.1696180024048; Sun, 01 Oct 2023 10:07:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696180024; cv=none; d=google.com; s=arc-20160816; b=iwiLcZJSsfSFnwogBgri2L4QMtewoqYAHo8F++J0hMXpAMTwOHKCzhrFS8NIyd49jp WK2LOcjXzR9t1ErvgLGDwe6uZwHuCKKl3xREtzfo6AUBMiuYSj5RB304e1eDeravL4RM +ygtP7BZ6v52CgUURMJZg8APJvMxyFqVz9S9K2MIJj0gz532Q7hZFA2B6SQ8TwYhwW5X 4wqXnSkdmcTjOxw+JiX47DhARNctIebeYFr26E4oE8vnaiGa/sn4PesONV2gjzCM/gnu REh1FMFcWyEWCzwNKnO2Ex9fhCuiAcpERzxtsyLSxRQy+YfwTFtVqD4aBePsMC6bZYry uB5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1xEwOtL01+HmLCODlG5jDnboU50nYLcrpSFuPs0VWD8=; fh=mNvOpR73OaUnRrr53gRvslddDUjaIrpQi7RNpkp0Veo=; b=sjqNA4xxeL87bhTnNUDEnS5YnRFYDTmg/c4s8H2+AUv3NhqpqSVK2NcGWkhvGbQEmQ 4EGgQBCSFgStnK37HJjxw+scNxwNmE9qyyFLy3CgrweDPqnAUvd1EVSHmmZ2KM0UcRBN eMC23aBWoRakig2Yp/QDczJxD02WoFYTt99BMbMfiAL49+01sx4GVHxGjupM8yeLPvhT Yx6Hb2FeC/z7PgffsbsWpymmH1JlXwOmYSWCeYt7EKJxehfK5jzZcMWxKehcLNoxP54u vrG73P6ZeTaCzlzf7aAkP8NXBWn9vOC0PaMqcZQ9ikg5ixerl7A752dgNAD+DkIZTvaK earg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=hFnRHMmA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id mu11-20020a17090b388b00b00274e2ba0ca6si6455264pjb.134.2023.10.01.10.07.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Oct 2023 10:07:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=hFnRHMmA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 66C258067B54; Sun, 1 Oct 2023 09:00:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235213AbjJAQAZ (ORCPT + 99 others); Sun, 1 Oct 2023 12:00:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235192AbjJAQAR (ORCPT ); Sun, 1 Oct 2023 12:00:17 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12817DA for ; Sun, 1 Oct 2023 09:00:15 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-4066241289bso17466035e9.0 for ; Sun, 01 Oct 2023 09:00:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696176013; x=1696780813; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1xEwOtL01+HmLCODlG5jDnboU50nYLcrpSFuPs0VWD8=; b=hFnRHMmA4lo/2w3tKnAYh6JXvlNSDY4KQCmh/Tj9yi79eMbL0j0ysTNz9uh2PRMfb2 mg80XnivtwqN5F4Wp+d6RIzGD8eXpq6X6V9o/e9oYYDJ0ES+wsce6/0qHMZ6Rg4G6soe MlJKbxZzzdxActTVwKf9r6Y2k9BacE+6wdzjshE6szpq6VyY+7HXO3VKSZJ6w3IGQoBc QZkXfVphMGrb8J4RMtzY+cIWy6QsN08VVUAUGnFmfHLRrIQK+xIU0X8EX91hOx0uRY0d SxBhubrp5oo8i2Lc1wo8BlxaqXTeT8LyEN2zrytq6Mw8tKiEZH8CHZh1vpFzxPk5hxId BaFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696176013; x=1696780813; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1xEwOtL01+HmLCODlG5jDnboU50nYLcrpSFuPs0VWD8=; b=rUCFtHkrGWLfBbXdQOGVBbqpDk0I+IBJalkcRETJzWJ9DhgHRY9Z1h139LlFXpN8Ed /em/spHd/1eQlGwhs1UWR1Yr3Vsg55IzeoyUwhBng8jKdE1AoanpCnFW9/w+LBORGavO kxJbHPgk4FidwRcCtQIXbQ05CNYCA5kbAQvAQjUBzpRLO9iVR2k35rWgVz7BBlIaB/8O G0dckJK1iiYeG3MrOpEYtiRrUOToN0T/3cGuxujEyK5R+p7/PZs86VnhSdi6u6nYadll oGbA/vOY5U8qMgQwAkTJitk/JM791ceNVX9gGH/SfBeZ35hVF4xO9QwcQL3BJT7+zO2p qX/A== X-Gm-Message-State: AOJu0YxDpPk02ehq68fwh/1uBEdWUhlgu3dp3UIc8hv/6XCCX9BS7dcl 06AsEV0RFwMSEwekV4NssbQ= X-Received: by 2002:a1c:7407:0:b0:3fe:d1b9:7ea9 with SMTP id p7-20020a1c7407000000b003fed1b97ea9mr7951514wmc.36.1696176013401; Sun, 01 Oct 2023 09:00:13 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id s16-20020a05600c045000b0040536dcec17sm5487695wmb.27.2023.10.01.09.00.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Oct 2023 09:00:12 -0700 (PDT) From: Lorenzo Stoakes To: 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 , Lorenzo Stoakes Subject: [PATCH 3/4] mm/gup: make failure to pin an error if FOLL_NOWAIT not specified Date: Sun, 1 Oct 2023 17:00:04 +0100 Message-ID: X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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_NONE,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 (howler.vger.email [0.0.0.0]); Sun, 01 Oct 2023 09:00:44 -0700 (PDT) There really should be no circumstances under which a non-FOLL_NOWAIT GUP operation fails to return any pages, so make this an error. To catch the trivial case, simply exit early if nr_pages == 0. This brings __get_user_pages_locked() in line with the behaviour of its nommu variant. Signed-off-by: Lorenzo Stoakes --- mm/gup.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mm/gup.c b/mm/gup.c index b21b33d1787e..fb2218d74ca5 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1471,6 +1471,9 @@ static __always_inline long __get_user_pages_locked(struct mm_struct *mm, long ret, pages_done; bool must_unlock = false; + if (!nr_pages) + return 0; + /* * The internal caller expects GUP to manage the lock internally and the * lock must be released when this returns. @@ -1595,6 +1598,14 @@ static __always_inline long __get_user_pages_locked(struct mm_struct *mm, mmap_read_unlock(mm); *locked = 0; } + + /* + * Failing to pin anything implies something has gone wrong except when + * FOLL_NOWAIT is specified, so explicitly make this an error. + */ + if (pages_done == 0 && !(flags & FOLL_NOWAIT)) + return -EFAULT; + return pages_done; } -- 2.42.0