From patchwork Sun Oct 1 16:00:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13405432 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9AABE748E9 for ; Sun, 1 Oct 2023 16:00:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A22B16B0191; Sun, 1 Oct 2023 12:00:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9D0EE6B0192; Sun, 1 Oct 2023 12:00:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7AEA26B0194; Sun, 1 Oct 2023 12:00:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 653876B0191 for ; Sun, 1 Oct 2023 12:00:17 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 1682DB3600 for ; Sun, 1 Oct 2023 16:00:17 +0000 (UTC) X-FDA: 81297354474.19.16BF5BE Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) by imf01.hostedemail.com (Postfix) with ESMTP id 389BF40014 for ; Sun, 1 Oct 2023 16:00:14 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Wjps9GGb; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf01.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.54 as permitted sender) smtp.mailfrom=lstoakes@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696176015; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=1xEwOtL01+HmLCODlG5jDnboU50nYLcrpSFuPs0VWD8=; b=tsTEkJfj1RHLnpc8kRjkYD3ZmclJJM/KyfcluPxx2y6+3PQTfT4xFGzAlhydYmZj3QqVB7 LQSE2peUpUvQL5wDZVXHbPFLIteqAN6sbUTQmHfGoCkAh4QZj3gmWlUFiLs7bfcH1MW2lq NPnWPgZJWMmDXeQaPILTFcE3e7p1tU8= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Wjps9GGb; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf01.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.54 as permitted sender) smtp.mailfrom=lstoakes@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696176015; a=rsa-sha256; cv=none; b=A72jrFjOgDXliAgXZ90ylZ9hK6fFeJljFMA80wRzx/3FrkWITDvDn53/AT5JVKV7QYRx7U nr56VMhXVCdJZYfBpMGdKwyzofAvgiGTqaYnb0vPlAhvr901RcyOaygwS5yiWNQntagK4C oBTDvrbnd0KmeLNUoBY56IFTg42hHrs= Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-406402933edso73933655e9.2 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=kvack.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=Wjps9GGbvE58kEtIxZ1+GigJmQN3w+DvesON3fTyOYzwGXbExElj8ajqWysItxxJUJ 2EoDzaC8WfXPuvIfpzxVy3arXZPRCuwv3LOJ0kW5o7RwrulQVg4U++T5n3gnD8m6s+oK 6q246vQtcHwX8TTdNZHCgsJ/p/3XOueRHzQ4jvGnbjms9ZszD4LcXq7Zo2OFbxoPyhyu 3toQgz5QJEDmq/Xbs3tBIMNp7dLo27IkS2Dq4AXDKobUAOvSa34BZP037O3BQyBvBNhK kQy4IlkMZ7ykl+D0peWxHAyU/8YKiz0Ro3oAcOXzwtul6pkWuBrSdVdxY/MFeg3QozJr B3Eg== 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=j1wxIAeu60eH8gM+23P58qlDKfTgRmAIahV1ZfNjmP85ZQXeapZ41qNEfZxbhEQnKk 8bq/cE2vSIZCN/ZE361bcEwKFwrsHnSvZsWP1MuS2KPEdrI8AjcRZi/CSlLE7InIXczZ GsY7a+202yPUHAeXRCvMQsjgUWuRmN7QafKFsl7/UgHkl89LKZaB5IluheFUPTSC1ii5 GFRpySlxJQkSisevDnr/g8ufH6E7x22UIAU1JoOChDFIO8t7oLKlPig2BJesWaVQzxo+ IQJUxdJ1ebg1fySshZlWP+0nhBwwtR7YWJ/LaKALxFN2l5bJ5QRpMQKkrYFWwB42eryI fORA== X-Gm-Message-State: AOJu0Yxs1jDYpVfXJIl/qcqPDnB4dh3gn0cl+us1jW+eL/YfB8i74dVI urdIODK6qNia9OWWcaav3U3LJN93CbA= X-Google-Smtp-Source: AGHT+IGxL3BxWt0viNQ4gBrwqwGyLTXnXg+le9Rifz61iOn5svjkixg7oOtLo9NMLPoFe6fGC0eUhA== 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 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 389BF40014 X-Stat-Signature: f5k6eygyfodgzqf5cqnz6rjk4rzrpbhf X-Rspam-User: X-HE-Tag: 1696176014-962882 X-HE-Meta: U2FsdGVkX1+2rjXBCuROASfkpT/6XAMfhV2dMg7Ea92NZ9vJDyv0TJWcIDbSwrh+GH2nBCmxL6qnE/w91McCv8hKg+y5y0+djdxNopLPOPLwXQE0D13Gc3DRgjV8rvVihtwao0g73cCEGbKcUXqkms/z2kBWcymeaW1vu7g4N2YTmtQ5IkMRGBUn6qONQ7fjwBjstoOorZs72nMlBVL4TAudMI6s2yAhKbJieMkN4XtdonU5bzASKBWxhrOWHmqklCB9F/BfYVXIWEGLFMiFjQuIppKUYPHpJ+dXUtfDTIbQjJ5QLavcmzTwfkTD6Fv2UmfQgWDIW2HRF9RC8ykCkOrLj/gPEmTt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WX+xA/oD6ilMKIjQidl3b0ePJH0l4tvgdkDaXXeu6AK/ClW7x X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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; }