From patchwork Mon Oct 2 23:14:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13406615 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 6237AE776DA for ; Mon, 2 Oct 2023 23:15:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AFE2B8D004E; Mon, 2 Oct 2023 19:15:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A2F448D0003; Mon, 2 Oct 2023 19:15:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 82EDD8D004E; Mon, 2 Oct 2023 19:15:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 6300A8D0003 for ; Mon, 2 Oct 2023 19:15:07 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 3CA9C16011E for ; Mon, 2 Oct 2023 23:15:07 +0000 (UTC) X-FDA: 81302079054.27.8641B46 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) by imf07.hostedemail.com (Postfix) with ESMTP id 6B39E4001C for ; Mon, 2 Oct 2023 23:15:05 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=E0dkRDiP; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf07.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.45 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=1696288505; 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=XG4wWkmLCo1BkRFV+SZ7pD22xcplU2FkjQ1ykcSCzlA=; b=4gCO8pm5K5n36z0IP+bbAznCrsAL5NX23UdLde2oFwum7JA0oxpl1i0jqAxYQx2KVo1Ygx jsbzOXNYQwIgw5G55GzpuDt58j8WvE8cJnkbDQxFqgJO4fXEmNf02cuMhJyUaNgLJdBoC4 cDDoSlQFO1fCsqOdRpfdXGhyRetRKmM= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=E0dkRDiP; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf07.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.45 as permitted sender) smtp.mailfrom=lstoakes@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696288505; a=rsa-sha256; cv=none; b=AlawDk8LUxwZb+6IfNC3FVrRAnc5qgKmkxjAUbFDJ9pkcvvi9YVaVMC7FCgg8MKmCiSzRC wUDEUSZqoIex80N/LMGUexjhtZUNdu9hKih/ZSXo7tUhVZz6HjDHj885+RQB54XoN1mNb7 jpqxBNO+1NR5f97TW103y0J49GDLOv0= Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-32325534cfaso326088f8f.3 for ; Mon, 02 Oct 2023 16:15:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696288504; x=1696893304; 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=XG4wWkmLCo1BkRFV+SZ7pD22xcplU2FkjQ1ykcSCzlA=; b=E0dkRDiPIm4EziwYaW4SDahK50/FY+soQdDs1fxeYKEANWu8NSWj/9plnE/lvPem00 lp0EqnhuoAN1UUYAsgYwAJ0+ABR1YSQqjp2CPNZ4q+Utftck/kJakt31gnZQSkQ2dFeT v2b+8sjXjcSQ/Y4UBTUi2l05z9G2+J8RBdHsfnLLbfR9IF7vg2xrYMolEPIQZCNRsZFE kY2wYgvVa0S4tmmm7JeCW5fOVRf1pJNaa8zc0YNFlAt7e2iiDifsyNWl1hxnmHUmCHa1 FAcmei+M9XjzODfCwn3glXRza8Gdtq45P2qwNSnJWixvER+T93iBgsdHHDCsWOK1/6j/ cq9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696288504; x=1696893304; 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=XG4wWkmLCo1BkRFV+SZ7pD22xcplU2FkjQ1ykcSCzlA=; b=Eq2j9JI3yOWW5vXBdikdtdZ4d7lTDz+G66Q9FiA499Q+FWjgOnBs8GYFLU7nCSUych rv+W20OTCYqRsXKnoutyfXt0WSDBOYEfFm/av4eTL/tB70Me/b7V5YFkkW2UmyZ/HctH T85ePGSqdj7zzX4bQsVLUIrMS8u0TXzR7R32O025dH8oNEhjfFh/l3TAdOaTT6lNyMaj ffdujtNSUr4py2xb8CNi17Y/RPhQEnXuH56uSc/KeaWH1O2mp4Pe9T8TOCsFpE3n9y+Y rPSSxctbXh6/Z9xdq5bIxVVZXdeZzVg/NPU5bar0HyYSF+a7C1NUgRMLxXBEvfsue6Dy 9UYA== X-Gm-Message-State: AOJu0Yyp3AgJLH/Ao6MyGFO3tTxL9HvHpusSFpM3RQHPgvnwMXR9dVsB KzNG7vNXLDfRPFnOqblTsCBAPq/NZkc= X-Google-Smtp-Source: AGHT+IHPD0YW6W2NKg8MPeJMMqQ8iaJpIr7CxgDjPL+crfsBudmp0EpxGqIbkwK6ssWkl/HoqBh5Gw== X-Received: by 2002:adf:ea8f:0:b0:320:1c6:628c with SMTP id s15-20020adfea8f000000b0032001c6628cmr12351480wrm.65.1696288503641; Mon, 02 Oct 2023 16:15:03 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id e31-20020a5d595f000000b0031fbbe347e1sm63860wri.65.2023.10.02.16.15.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 16:15:02 -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 v2 3/4] mm/gup: make failure to pin an error if FOLL_NOWAIT not specified Date: Tue, 3 Oct 2023 00:14:53 +0100 Message-ID: <2a42d96dd1e37163f90a0019a541163dafb7e4c3.1696288092.git.lstoakes@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 6B39E4001C X-Stat-Signature: ps8jg889z9o8nxc97jzoai9atwep1kzj X-Rspam-User: X-HE-Tag: 1696288505-873278 X-HE-Meta: U2FsdGVkX1/iToG56S2Qf5DVMDWWB982/LCk5OC/tSmkrZU61LIZG4qbs7pzMpRLGpQEUTt/q1IJS5VrdccT9bm6Cj7gHenJ9uIlF6kOshIEgMYuPJ6U3LUEfNCY6SV78dH/sp1ywRsAS1DUY2KQT03EJ00hPNFO/3EFEH+ZCZfabS+nuCgeKyiroGNDx+uXsDeuhceQkiha2QKJ6IBGyafRbIGGlUNuYL8M7B+nrGw1EhDUK8YQql7BvPvfXVJxl8r7uN/wuLt5ohA6IUY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u4G8S9vw+OsuWm8sdo7ickADnEbFeSv+nztOJlvKgkeLd+VKp5i/xlp7KhRvJj3CYE+8I2YDbvIY2CmqE1ejUZm1/5VGoDVriyTpNxEEvdpfR9L/dAx3cM 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 and warn on it. 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. Reviewed-by: Arnd Bergmann Signed-off-by: Lorenzo Stoakes Reviewed-by: David Hildenbrand --- mm/gup.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mm/gup.c b/mm/gup.c index b21b33d1787e..231711efa390 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). + */ + if (WARN_ON_ONCE(pages_done == 0 && !(flags & FOLL_NOWAIT))) + return -EFAULT; + return pages_done; }