From patchwork Mon Oct 2 23:14:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13406614 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 EFF28E776D4 for ; Mon, 2 Oct 2023 23:15:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 681F68D001D; Mon, 2 Oct 2023 19:15:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5E3998D0003; Mon, 2 Oct 2023 19:15:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4AC108D001D; Mon, 2 Oct 2023 19:15:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 32F518D0003 for ; Mon, 2 Oct 2023 19:15:05 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 04C05120108 for ; Mon, 2 Oct 2023 23:15:04 +0000 (UTC) X-FDA: 81302078970.16.C3DD649 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) by imf20.hostedemail.com (Postfix) with ESMTP id 31E061C0004 for ; Mon, 2 Oct 2023 23:15:02 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=CqtFSWLu; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf20.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.53 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=1696288503; 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=8CCf1YepfoJnZdTtxvEP7yh6ZYqHtmpLJthLBvRpqWQ=; b=1x8bORuIsMimrQoPR2HekviVBnSH2x8ORqulc7oKV1CrmWH52dXWfdiMxyvnUfdeWk2KT0 aqc8os6tZPrAH30yQl4vv79TcxmYtAvRSxEsAquBIojuxEKK/em3a8tO3JMzbBLPbKrFF6 N/0kxClhFUZ/7v9VUFTJk0CrGgf78js= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=CqtFSWLu; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf20.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.53 as permitted sender) smtp.mailfrom=lstoakes@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696288503; a=rsa-sha256; cv=none; b=WuHsiQD/tkNic3ncglgjtKCMLJfxJhGL30DlpA9Jos1NPSBLHPuYlpN+zUQvXIwmC4iFYL BDf91F703mCVWUFTn7g7IwvZMxeIS0PawrinOEQzkmxk2eAO+91gwuffusbzCT7VJNsrnT coVpi3rFVg8rqbM09GUGWSqIo7kl3+0= Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-31427ddd3fbso360937f8f.0 for ; Mon, 02 Oct 2023 16:15:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696288501; x=1696893301; 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=8CCf1YepfoJnZdTtxvEP7yh6ZYqHtmpLJthLBvRpqWQ=; b=CqtFSWLu4v/t363O9nTF5uTVSA2MVpxqgRzKPJZRsQ/C8BBGLhJjsfaAYAW9+Juc4+ cmNDzdH9fCjRc+xArkpIKAQB0uNWFcatO2FnF2AU27IoioW0GrzVaqfTW0suSqeP2Uf7 qfwyOCnkDd2QIsrusm8Wen68tB3tP3JszzScocFjKCrJt5tSNebBMtXI8YvysQ1ty9yS uWAVmeeTyICigXXESg6niMJhf5Jq4nrDJ/G54uwqoi+nKCF8ABvb4MvM99aKDB1oDlf3 NjTXG3TC0pD7QDx47DgF5rLQnOzCF7RZvbInC+TmLDUdRtdQvRCUuourY3Mei+ZmlMye WNlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696288501; x=1696893301; 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=8CCf1YepfoJnZdTtxvEP7yh6ZYqHtmpLJthLBvRpqWQ=; b=RwEIEOibmZgoEQ4Ptrfn0NsyaPLDvI2K+eifSGJV83xufio7Osb25G5GenOvSCLdDh 9a1ixd5azl6VcBufxRRu3d+Q/brZT2Lqdcchp7RjLgoFcD0xz6AKNWCFkB3nxaPCC05c R00g8asbleZjXA6/KFxnhCW6L4fsFYX1c/5nq/rGo+v89smjMC0CujSGhdGh+vDQfUJZ JO0i9JLP37722npKgmihfZpbXXi3h2Hhbjh24nvYGPXfV4P9Rn7dlroPC0mNPIc8/HrH ZCV5szvSSrR/sYmf2M1P6MXxArxzfcPT9g5j7XiD4U7wTcOK7Bnjj6qpqxlEXWHMsHsL +NlQ== X-Gm-Message-State: AOJu0Yws+geS2v9wVMKbj/cSu9kfJqSrhfft0abZW9VSFkFsTK3G2gbb f7VbRcXtTYn0F1RZpDoej+sc85aCITw= X-Google-Smtp-Source: AGHT+IHYriSecsmHZKvTmAjWX2tjh39AdJdHel618pmJyi/BsoVQvDJMPZheisgXAY/d1NQdCOZsLw== X-Received: by 2002:a5d:4dcc:0:b0:320:5f:c249 with SMTP id f12-20020a5d4dcc000000b00320005fc249mr11333408wru.30.1696288500995; Mon, 02 Oct 2023 16:15:00 -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.14.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 16:15:00 -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 , David Hildenbrand Subject: [PATCH v2 1/4] mm: make __access_remote_vm() static Date: Tue, 3 Oct 2023 00:14:51 +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: 31E061C0004 X-Stat-Signature: m4mu493zojkx9y9wszygyqc4133pifri X-Rspam-User: X-HE-Tag: 1696288502-128815 X-HE-Meta: U2FsdGVkX1/FbS2YFqDzRN2OL1We1LJirb7TyIcqee9QLIrCXd2LqKLHDZ+RhSpfOLuH7BpzhJuU+hHGY3TFva8X2Gca+p1ogwKA01y0np3asuCNGhIt3EwlpZyMcp29ZAOXIbyohQdy+bQzwRgfcCN6fdDsNiz++K8wZ0FdqEEGZAzWd9UsCUzinUvn54/EGq4Pt3R3ZHU+lLaPqzP5/eeigouELO98Gn6EGAOydg0pjw/7QXQTRoQi1BiR102GN+TinklnbhVD85tLcCtFwTyPpOYI2hupMLrbLYwfRA+5XT6aLRIf6o3i0bMnbDxTjU6fF+h2m+PqXzBFgaaGdugDNSaLDhblOs7f1BEX85rFmP0R2Rt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m9HqGiFSgZkeSJhFyq1Ic6IOQm8lpBww== 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: access_remote_vm() passes through parameters to __access_remote_vm() directly, so remove the __access_remote_vm() function from mm.h and use access_remote_vm() in the one caller that needs it (ptrace_access_vm()). This allows future adjustments to the GUP-internal __access_remote_vm() function while keeping the access_remote_vm() function stable. Reviewed-by: Arnd Bergmann Reviewed-by: David Hildenbrand Signed-off-by: Lorenzo Stoakes --- include/linux/mm.h | 2 -- kernel/ptrace.c | 2 +- mm/memory.c | 4 ++-- mm/nommu.c | 4 ++-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 52c40b3d0813..7b89f7bd420d 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2415,8 +2415,6 @@ extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, unsigned int gup_flags); extern int access_remote_vm(struct mm_struct *mm, unsigned long addr, void *buf, int len, unsigned int gup_flags); -extern int __access_remote_vm(struct mm_struct *mm, unsigned long addr, - void *buf, int len, unsigned int gup_flags); long get_user_pages_remote(struct mm_struct *mm, unsigned long start, unsigned long nr_pages, diff --git a/kernel/ptrace.c b/kernel/ptrace.c index 443057bee87c..d8b5e13a2229 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c @@ -59,7 +59,7 @@ int ptrace_access_vm(struct task_struct *tsk, unsigned long addr, return 0; } - ret = __access_remote_vm(mm, addr, buf, len, gup_flags); + ret = access_remote_vm(mm, addr, buf, len, gup_flags); mmput(mm); return ret; diff --git a/mm/memory.c b/mm/memory.c index d4820802b01b..e2743aa95b56 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5881,8 +5881,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys); /* * Access another process' address space as given in mm. */ -int __access_remote_vm(struct mm_struct *mm, unsigned long addr, void *buf, - int len, unsigned int gup_flags) +static int __access_remote_vm(struct mm_struct *mm, unsigned long addr, + void *buf, int len, unsigned int gup_flags) { void *old_buf = buf; int write = gup_flags & FOLL_WRITE; diff --git a/mm/nommu.c b/mm/nommu.c index 7f9e9e5a0e12..f9553579389b 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -1651,8 +1651,8 @@ vm_fault_t filemap_map_pages(struct vm_fault *vmf, } EXPORT_SYMBOL(filemap_map_pages); -int __access_remote_vm(struct mm_struct *mm, unsigned long addr, void *buf, - int len, unsigned int gup_flags) +static int __access_remote_vm(struct mm_struct *mm, unsigned long addr, + void *buf, int len, unsigned int gup_flags) { struct vm_area_struct *vma; int write = gup_flags & FOLL_WRITE; From patchwork Mon Oct 2 23:14:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13406613 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 76721E776D7 for ; Mon, 2 Oct 2023 23:15:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 795348D001F; Mon, 2 Oct 2023 19:15:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 71DA68D0003; Mon, 2 Oct 2023 19:15:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 522D58D001F; Mon, 2 Oct 2023 19:15:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 3E1718D0003 for ; Mon, 2 Oct 2023 19:15:06 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 10BDEC0124 for ; Mon, 2 Oct 2023 23:15:06 +0000 (UTC) X-FDA: 81302079012.11.2B403EC Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) by imf26.hostedemail.com (Postfix) with ESMTP id 40902140012 for ; Mon, 2 Oct 2023 23:15:03 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=c+xNpkU4; spf=pass (imf26.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.46 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696288504; 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=vQvCLVMfpl1rfMES4jKdwm82L8UOBjNuap0Ti+SzBhc=; b=bnkzVv0pGOR3jq+FYrRM2xdCuHrqTE3agJMa71rCyRue8YBokdDTsMQ2E5vvo8S800DcR9 UPVRkB9bwB0uZ3Pl7AwSY17dGz88n+MXtYNSKwJ6d1gFDartcuKc5cZ96zVPI2pF86x5+N jS4LXMPWtcSVjTNkqEyhvk/riCJbQO0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696288504; a=rsa-sha256; cv=none; b=SBod7NGG9fOOarjZYG2pO8PJlT63HxPSVpChvwZjoPACTAHDhBnOoJtxrmXAfc9waY1msG krz9+miu35eqsFxCdR5e2n2THa7T0RipYF+bhM+9jdt6kYIVUoTk9K1wA039/qa0An7cuK 4JWUGkGx74Rb0cW4MkyjpIVW/Stn4Q0= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=c+xNpkU4; spf=pass (imf26.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.46 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-405524e6768so3042595e9.2 for ; Mon, 02 Oct 2023 16:15:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696288502; x=1696893302; 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=vQvCLVMfpl1rfMES4jKdwm82L8UOBjNuap0Ti+SzBhc=; b=c+xNpkU4qymalFe1pMVGsJt5UOnbGLfvHj7f/8TkVzTgouSz7zsPLQNAOspABNXsuA PS/5Gvnua5wZhUiTvR7C2Rm6aXtgeee0lMbdgESRr7ty/u2mQEjG5GOj8uXX3TysaNIT xLrs256b0s7UhjB0GOjAXo7U4CzjJmQbj7p9NbDSpgZgIxBOjqGRrI8fc4f8Ma00m12X 2pD6T4cR8oaKvm/yr2BRIYDb9eP4aX6Vnu9ng85INuRGakDKSWfH4p76W8ff/6sXZFYT zF9qHnSByPWayguyeMkzKOR+9ZsJGf3L6kpFGiCLCFnQ7EThXA88RGbmxR+mjCP5dyRp Sfng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696288502; x=1696893302; 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=vQvCLVMfpl1rfMES4jKdwm82L8UOBjNuap0Ti+SzBhc=; b=MZyYWosjqVZnqzNq+k53LS08fppQTMXgLTZlXhz3JGA4zcihDPLFdhBz0h8Ets4C2e 16F9YCziN86Rdw3xdON4B0MB6atPJpVtr5LiZlJFt7FMlo/vaYzPmCFqMqQnPUTw3eHA f0G7eNUfsiNTovWgsJVCWN2JtVeXZR3NBaWBlr7R+YpClGScPgpj8VoX7lgo2pbcHL9P hUYJPd31ziCGVlH9tPzBC9WeFnGLGTJhxkjP5y47UG6lx7l2dT2CFCARcBg7bSdqYW0i Wj0EiejcSu/1W7ZqbHBjPuBjnEJsyXyTtM1XDNYSLsSy29EQLF56uuOerW6LQ+Y856ix /cFw== X-Gm-Message-State: AOJu0YxB4lqWB3HPUy6At2cwzCARHV9Vi0ffqXmoMzAWW4TQWon4c7w8 CxBRdeNY9uZVXs156ns14gSEeCpgxXc= X-Google-Smtp-Source: AGHT+IEtd7/2+KG5WHd0cByCIEOQATOBxdbRX+bfexS1IsqnxYU1Maj/cmH3p1/Wp7fgogXQxGevfg== X-Received: by 2002:adf:fc4c:0:b0:31a:d4e1:ea30 with SMTP id e12-20020adffc4c000000b0031ad4e1ea30mr11701566wrs.17.1696288502337; Mon, 02 Oct 2023 16:15:02 -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.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 16:15:01 -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 , David Hildenbrand Subject: [PATCH v2 2/4] mm/gup: explicitly define and check internal GUP flags, disallow FOLL_TOUCH Date: Tue, 3 Oct 2023 00:14:52 +0100 Message-ID: <971e013dfe20915612ea8b704e801d7aef9a66b6.1696288092.git.lstoakes@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: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7 zWoovPLI Wb2av/M0ab4jQ7bp3otRv9n8psOhUVU8RIAF9qOxcszP9Au6521WZVsx0SxXNhJ0IO04LD8fSg2VhcgQ3IIiFtis36pEquhrYkF+KZoNmUdPz5aWlTpwRpqitNDe71lQDuktKZKqnfW+hW3/3oN24+7tUyyKml4ZBS8fqgJ4/sRNlQ+hhMTKhj6B2VqZfzYkWQh35F8o/Q2IEIjHIVFIrXgbPgdvHYyeAwwjl0PwDsPZK9Fqsog+kGL08+RqHpw1x9shaed6ITYeOWH89N3/uBLQQme8+ymRr67Rk+MQRcU6ULP88f5uQZkOSN6iHQYG0puBDTtwvsGu8FMkFnjtU18+WQMxlgbmWe5b8rVhWbhlYumIfPrzCxEqEVKcfMLi8fC3a1nJY65y8TU9yURRYRkKg7AH9nlI9YU1I1NRAbHS0fNqaKg2NUUzC5HQMhcIQmNIBocD5ilOSv89cqFis5rKVPDBMruTlBjJQH6zTcJkbXmnVf0g5qsfRuQ== 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: Rather than open-coding a list of internal GUP flags in is_valid_gup_args(), define which ones are internal. In addition, explicitly check to see if the user passed in FOLL_TOUCH somehow, as this appears to have been accidentally excluded. Reviewed-by: Arnd Bergmann Reviewed-by: David Hildenbrand Signed-off-by: Lorenzo Stoakes --- mm/gup.c | 5 ++--- mm/internal.h | 3 +++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 2f8a2d89fde1..b21b33d1787e 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2227,12 +2227,11 @@ static bool is_valid_gup_args(struct page **pages, int *locked, /* * These flags not allowed to be specified externally to the gup * interfaces: - * - FOLL_PIN/FOLL_TRIED/FOLL_FAST_ONLY are internal only + * - FOLL_TOUCH/FOLL_PIN/FOLL_TRIED/FOLL_FAST_ONLY are internal only * - FOLL_REMOTE is internal only and used on follow_page() * - FOLL_UNLOCKABLE is internal only and used if locked is !NULL */ - if (WARN_ON_ONCE(gup_flags & (FOLL_PIN | FOLL_TRIED | FOLL_UNLOCKABLE | - FOLL_REMOTE | FOLL_FAST_ONLY))) + if (WARN_ON_ONCE(gup_flags & INTERNAL_GUP_FLAGS)) return false; gup_flags |= to_set; diff --git a/mm/internal.h b/mm/internal.h index 449891ad7fdb..499016c6b01d 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1018,6 +1018,9 @@ enum { FOLL_UNLOCKABLE = 1 << 21, }; +#define INTERNAL_GUP_FLAGS (FOLL_TOUCH | FOLL_TRIED | FOLL_REMOTE | FOLL_PIN | \ + FOLL_FAST_ONLY | FOLL_UNLOCKABLE) + /* * Indicates for which pages that are write-protected in the page table, * whether GUP has to trigger unsharing via FAULT_FLAG_UNSHARE such that the 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/wuLt5ohA6IUYbXB27CuTvj7YUc3twUZK0j+1Cx3qEiNxN/kXQ0v5vSmd9DHXMwZeRG1h/g0rU8BIP30fgcStrSnHhvEz0fj4Ae0nrpQCiXzo5ONmUHPEnyzDEWS6j9v/cTT5Wk1SCJ+mpoW6dC0+gZ6lR2p55SPL2OASRtspgcDIU37jYlNorLly5aJPBRYAKlVIUmkkBJBmaEYXTRB6dEwiV02ZEtYWqwf/oz7VV3UJoSBpEa4oenySx/XfnGllIlDyU7Frhp6u6wWevM3iB0wvjRGYeUjbdhbXPvqjFDJuGwK6zBwDdcT4cMZfg9HeSRQnD9qXS1arilJenjA3b8fJGWA3iyuPXQSQ7DS6EJiIHDuaRKEmcjXvUMubGvwuhBBSENOT2F6zSJ6Ht355QjRrCgWbAfAQr0kMJ1yCdZacjL4UHdhd/XSeic+lNWkD1lX5J9aK505ifwMaTuDcYrApdKZXvH9033xM38UqbqgrPAlMnORheYbSWWMfwKUKqrSZLpbtAPiRr18tgjw3zUjh7Wzs+t7Fk5BbHkfZlC1jI+W2xY0Dk0ewic4FrcHVBjR7MPrGONhT7DwEA4CScG0DvPAkZCPsmZuU/qzjpAPChyRj/2SwRySaZWzK6+0bBlEsDgX/ICihq+yjFpCjegPx1maOeiSH2TNeyoR4GSf2/dED4BrGFqigcs1hvQ4CKD+JnfZEJam+ ZGjD55uR R73Mh/8/e97VCLN6vB07IjqtTEajHxqw6EymhQ02V742/kx0i3BMHpDzEMBp7muiOVWFGZnIqKUO0ow+7MSavudGQa+v7+phzWEsLvmUeLqncMxFIMfQIDaJuLBjH12PLHR8y+6DGhpbtvHlQGXp5S3c0L3tLExvYiXfb3i6LxHnavcb5id6/uZOEufbq1H/DYbVGCP8chF+O+UHDQTEjSWORhc5ASVh08ihhwnBYMWBcYDn1s4y4WImutLJWnnf63F/rZC3QiM6ItrGVUNSq6U3YCAT0AFVc+uFdzB1QZobBqZlbGYF2lQj7Hel1cbUz9gqpO3kkoOrUwK3y+6BCglQojzrytIgeVSfytmMXXtPKOJu4G8S9vw+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; } From patchwork Mon Oct 2 23:14:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13406616 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 4E5BEE776D1 for ; Mon, 2 Oct 2023 23:15:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3019A8D004F; Mon, 2 Oct 2023 19:15:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 28C2E8D0003; Mon, 2 Oct 2023 19:15:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F0FB68D004F; Mon, 2 Oct 2023 19:15:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id D181C8D0003 for ; Mon, 2 Oct 2023 19:15:08 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id AC2AD80115 for ; Mon, 2 Oct 2023 23:15:08 +0000 (UTC) X-FDA: 81302079096.13.2DB78A9 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) by imf14.hostedemail.com (Postfix) with ESMTP id DA527100004 for ; Mon, 2 Oct 2023 23:15:06 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=L0FWOH1p; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf14.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.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=1696288507; 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=DSkssDhEiWfimKWDZskn49BRf30NYKZNHbeb9+/CySI=; b=wPch1ecjuxEboIiWqVxfhjYZBYb/ywwvwpi7DgzCSP1+6eYFF56+6cGDaw97culW+gNx/i 0Rpr6VSx633r/YPFWa875irxqYhkcUi0MX35cxja/eSrE7HrubSnSLsYypntfiV/FlZ+MH ZrmzH4OqS/ndo5/5MLl75fzD+DVtbGw= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=L0FWOH1p; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf14.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.45 as permitted sender) smtp.mailfrom=lstoakes@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696288507; a=rsa-sha256; cv=none; b=nAuAuhLtbH0AFD1yuD5uNqpaUeAi7ViTntOW5Inaw09urVGx8lHcX3OdPyP39OQZdfsTSj LFdlLdmCbv/MarDT6dge6Tb7154EI856+Oc9BQa1j1RuFK996BaCeNS5AecZPqQ8qe/XBJ 7EmyxIabwSESBrY4wuoSGm5rMB5ZGRg= Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4064876e8b8so3544135e9.0 for ; Mon, 02 Oct 2023 16:15:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696288505; x=1696893305; 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=DSkssDhEiWfimKWDZskn49BRf30NYKZNHbeb9+/CySI=; b=L0FWOH1pFl2RUSWtD3dpBuJjmzJZGvpSxepfd67sGuxZRY5Qqws/VgEc2SaUEKNw1m 12BJObsEHk5hhMD5rH6mitJuCx3uOhdXa5Q+lHMhU6OYZ7O57X7UX3y8DyOaEk/Wf0oX jU5G/EIZDUuHxlpZf/BsIVDB7IgtUlEJBbN7zB+vjHMPlshrlaY/ToS/UB7UOlBCSSg2 JkTaRGx26lW+tFqsgPLw8JS07JxZyDS1XE8EvPJwEKE4itm2tDzPFlZ5kIMsX0EBMTYk sPEzOynDTdSkGOk2kjc8d7S1qAEIoFy+i0IVCg/Hn9zLTPRj3IpmghV5LJbCRkaGzg3O EofA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696288505; x=1696893305; 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=DSkssDhEiWfimKWDZskn49BRf30NYKZNHbeb9+/CySI=; b=qkdb5TVNWGfZwPFopgiRjWYFrXjnmtb+kKoOpCWBeIj2UmwSuB16I75UX5mHfgfu8M 9XVhao0CvbzxGxB8djh0oHb7YBHrz4+XfktxoYudpXTv5Y1eof1cvHexK9JIZ0pJRjY3 TmoB525J2nLzgTYFmqasc05Ng2Rl1aQ+A4LfWYZNreZtiVKKFAC+thqy3fWWFIpyG3sg WZDcgGjY5ZQWDsdmOF1qtC1m/zbc9HOsllbktNCVuoUWdqwLZdIF7zy1t6oHAYg2qm+W r8sg4AuaGgBvCQQEFf2EUr9RixsIhZ/0dMR69mZ9H7ss+HvcsLFOYrvcAdfaiCN62QtD 1r7Q== X-Gm-Message-State: AOJu0Yzy5pu6XGp+XFS6zDVuKJrGQkdGvc0LbqDtv2fnLeCSZJhOzoNU EwMofzOcHrEJCE8Nr2VQ6LHe18VHHEk= X-Google-Smtp-Source: AGHT+IEGWuQdhMJNjpLTPPxmWTPQIgDGApVsDy6H+Wd+pJhPThR2GTKhSJQpOGnzKTM7ZLEyCa1p/g== X-Received: by 2002:a5d:4486:0:b0:321:6833:b930 with SMTP id j6-20020a5d4486000000b003216833b930mr12054922wrq.16.1696288505066; Mon, 02 Oct 2023 16:15:05 -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.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 16:15:04 -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 4/4] mm/gup: adapt get_user_page_vma_remote() to never return NULL Date: Tue, 3 Oct 2023 00:14:54 +0100 Message-ID: <00319ce292d27b3aae76a0eb220ce3f528187508.1696288092.git.lstoakes@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: DA527100004 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: c3bsgd9hecjtys1kwonet4g9ky8sin3u X-HE-Tag: 1696288506-681038 X-HE-Meta: U2FsdGVkX1/1tbdkdyRTWFIdjOVjCB99tjw2bDNG5gaKSplfPs9W50ZIeW2EQHZgEyY3xZp8uDS38nbyUlM21JhZQE4lXsUFxH40PEWGTqmKUoG7+sCahKIphiQhK+QjWHcd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vaYDDs0ne5DWmax6KkNtK9CaQvvv/SdV2paN1yjMu3RBxgm64r7HK8MN2n9k0DNX+ryAvuLyuph1vr370UQbK5h1a2DKl2Yc6nlwmbMyhn4ZdtRQPb1Tw5I/sQjOcvJI6NTsY7uRRIkquv5JScdmVk32jZB7ZvLZe6tSAY+8IELcdCklW6zqpSPQXw/Lsw5iSbCuTEkTLd0uto8EQ7NA3KyiE3P1VvUd/JguJ1xiX4v92gDv9NNj2XN6E7W+PUEBpO9uhtVIdzJHNjg4nN/SLy25NvaOp79Gox0GVQlDAoBItsYgGDxt0N3iHj/ABwmko5OiQ43NxeHY 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: 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 Reviewed-by: Arnd Bergmann Acked-by: Catalin Marinas Signed-off-by: Lorenzo Stoakes Reviewed-by: David Hildenbrand --- arch/arm64/kernel/mte.c | 4 ++-- include/linux/mm.h | 12 +++++++++--- kernel/events/uprobes.c | 4 ++-- mm/memory.c | 3 +-- 4 files changed, 14 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..fa608cba041f 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2425,6 +2425,9 @@ long pin_user_pages_remote(struct mm_struct *mm, unsigned int gup_flags, struct page **pages, int *locked); +/* + * Retrieves a single page alongside its VMA. Does not support FOLL_NOWAIT. + */ static inline struct page *get_user_page_vma_remote(struct mm_struct *mm, unsigned long addr, int gup_flags, @@ -2432,12 +2435,15 @@ 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 (WARN_ON_ONCE(unlikely(gup_flags & FOLL_NOWAIT))) + return ERR_PTR(-EINVAL); + + got = get_user_pages_remote(mm, addr, 1, gup_flags, &page, NULL); if (got < 0) return ERR_PTR(got); - if (got == 0) - return NULL; vma = vma_lookup(mm, addr); if (WARN_ON_ONCE(!vma)) { diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c index 3048589e2e85..435aac1d8c27 100644 --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c @@ -474,8 +474,8 @@ int uprobe_write_opcode(struct arch_uprobe *auprobe, struct mm_struct *mm, gup_flags |= FOLL_SPLIT_PMD; /* Read the page with vaddr into memory */ old_page = get_user_page_vma_remote(mm, vaddr, gup_flags, &vma); - if (IS_ERR_OR_NULL(old_page)) - return old_page ? PTR_ERR(old_page) : 0; + if (IS_ERR(old_page)) + return PTR_ERR(old_page); ret = verify_opcode(old_page, vaddr, &opcode); if (ret <= 0) diff --git a/mm/memory.c b/mm/memory.c index e2743aa95b56..f2eef3d1cf58 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5905,7 +5905,7 @@ static int __access_remote_vm(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)) { + if (IS_ERR(page)) { /* We might need to expand the stack to access it */ vma = vma_lookup(mm, addr); if (!vma) { @@ -5919,7 +5919,6 @@ static int __access_remote_vm(struct mm_struct *mm, unsigned long addr, continue; } - /* * Check if this is a VM_IO | VM_PFNMAP VMA, which * we can access using slightly different code.