From patchwork Sun Oct 1 16:00:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13405430 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 48FA8E748F5 for ; Sun, 1 Oct 2023 16:00:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BF60A6B018E; Sun, 1 Oct 2023 12:00:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B7F3D6B018F; Sun, 1 Oct 2023 12:00:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9F99E6B0190; Sun, 1 Oct 2023 12:00:14 -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 9024E6B018E for ; Sun, 1 Oct 2023 12:00:14 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 573EF140154 for ; Sun, 1 Oct 2023 16:00:14 +0000 (UTC) X-FDA: 81297354348.02.9C84A0A Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) by imf12.hostedemail.com (Postfix) with ESMTP id 5B32A40020 for ; Sun, 1 Oct 2023 16:00:12 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=kHtaxQYm; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.41 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=1696176012; 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=pfhqMS4SBWNsRFumL7f2VoNpk2TCo8ZgiAHTNGqiqHs=; b=Pc76vCnxX8mFxTStH02KWTLnYy7d/IcV8n4rvsiXVYXvdZE/594Yzc+iKWtqvJxkpEXzZ/ YKEu30KIQqP2qamM2WvJH5o7TnuZ0POjiH9C6WRd370r3Ouw1/V6as3MYv3TYCM47yc7zS d7aKZ2ltZusyl4sSVnVfpVkZnMA7UHc= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=kHtaxQYm; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.41 as permitted sender) smtp.mailfrom=lstoakes@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696176012; a=rsa-sha256; cv=none; b=AdGxBK89bj2VFy9p/slroLVeX3CRmOYRMEd6MA3j4lLh/u876QI1aZzQt3NGDAKqAGHWYQ Ia97u0eKaZzMF/sAZfL/ltshr7PN06OWQUrS0+zC6+IveVfJRStpoUpZESCbRhYKZJDho2 nb+DToMtdFP49HSnn18HRWwBy8fJ7rQ= Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-406618d0992so18458745e9.0 for ; Sun, 01 Oct 2023 09:00:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696176011; x=1696780811; 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=pfhqMS4SBWNsRFumL7f2VoNpk2TCo8ZgiAHTNGqiqHs=; b=kHtaxQYmXZ+UwtFHooV9y0l869tnVPa3p7/C6SgG6befJLWRGJ9FMLPGvEh0AcFkng 1E9hvFtq2HTxpGXN4cSj9bRHjHaan/kd4f8sy2zh2VEEwWbfgDr+HCygVi1hqGsFHujT bnaJqWeOrCpxTmzIKSoqvc3hv1s32vG7HPL++ya2dgsNi4Ekakinwf2PXbc0xlFQhRg+ NpX9dImGIatZDzsnq0dRN41fBwnaY6gtfDrSuPjy60F284/9AxV1vOcgJalA0jL9cLYi W3xlXn6BwmUtbfzg7JLTp3g2z17K/AlX0dnSS8nJI5Pd9cyxuagm5sx1Pnw6N3UoD4Ar nIaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696176011; x=1696780811; 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=pfhqMS4SBWNsRFumL7f2VoNpk2TCo8ZgiAHTNGqiqHs=; b=m4pRinuexNU28dEu+SNqd5kC6EvYv0xj98qPYYgCblov9q4MAjBEokUCKN4+J+J1eW 5Hqk1F2aH19VKxb5pW8h1JLbvyivKUs0NMbDSqI3TQ0XVtQR1Qo945Box4C9JUKe77Vx ZPsQUGg0bUJ7KJ2EAn6RnclT/2fReIrYrlJ4LPeonAV6ysFfGmR/yk/NH1LK0rDmZ5Yi mJGwJcXsWYoaLlge+eMLwfpDeScaSeShDbCooIa8rEbUSnUbCS9TS3eGGbfHIYqZBRol oXFYU7bk1Qk3ObBgYb6W7M2/ZRuWcKUs7U7upHQAILhFKaN329BFKzajr/7aDUX5B80x Oz/w== X-Gm-Message-State: AOJu0YzJx6lJNll3ZPhi9KtlXI7CTW9leY2PXQv0skAMTZ2vWYYQdoU7 +ZpGnjBmKsOI6kAazoRhQc1yDZFqgbk= X-Google-Smtp-Source: AGHT+IEII6JdFJg8xpbvXnmUnQWjv6hpexCp5q2DqxZ8O7FssanDUSfov88XVS8L+47c6qXHvBvGoQ== X-Received: by 2002:a7b:cd15:0:b0:401:c52c:5ed9 with SMTP id f21-20020a7bcd15000000b00401c52c5ed9mr8350531wmj.32.1696176010384; Sun, 01 Oct 2023 09:00:10 -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.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Oct 2023 09:00:09 -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 1/4] mm: make __access_remote_vm() static Date: Sun, 1 Oct 2023 17:00:02 +0100 Message-ID: <70436dcf596565770e604a4fc4e8f27a14c85166.1696174961.git.lstoakes@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 5B32A40020 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 9e6ryxom394qkysudht99qu1h8ohpxjb X-HE-Tag: 1696176012-219874 X-HE-Meta: U2FsdGVkX18Y2EqOemu0IZuKWtPS5IYKZbYztHfZDxVxLaF7mR2N3NZf9keyp9kFt/sCmhp1wy8Kl/ev4LW1hkRPSqME2rYLAtX8g+yLyob606ewmgJOgsKO/izx61d1jW8pxoq88DBP4Liq8fgk2nrDK1bMY7scRKTU4Liyw1I/jKLw9fc+Jl3hwIZtfKET/wp2MsrY5z73fGKqtcSUJb/6mW06BYjOaG5nMFDheMKQZkadKsjknFUG5s0KoBWpEwCnXUp1U74se7W2vOdljAZ03cTUau4uVABn3KGA4Zpgp78G0ed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zf+Xi17rKw9A6vuKKGFhCKp2Iw5v7mNUL7TCukWn/adoU/Seb+y4bnzFbvGO2ms63mKz 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 aand 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. Signed-off-by: Lorenzo Stoakes Reviewed-by: David Hildenbrand Reviewed-by: Jason Gunthorpe --- 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 Sun Oct 1 16:00:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13405431 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 653FAE748EE for ; Sun, 1 Oct 2023 16:00:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 42D8A6B018F; Sun, 1 Oct 2023 12:00:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3DD786B0190; Sun, 1 Oct 2023 12:00:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 256E46B0191; Sun, 1 Oct 2023 12:00:16 -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 167146B018F for ; Sun, 1 Oct 2023 12:00:16 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id ED4331C9C5E for ; Sun, 1 Oct 2023 16:00:15 +0000 (UTC) X-FDA: 81297354390.11.51465DB Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) by imf25.hostedemail.com (Postfix) with ESMTP id 0C78DA0021 for ; Sun, 1 Oct 2023 16:00:13 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=AgxXlV50; spf=pass (imf25.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=1696176014; 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=YKun88ibkbujMSV7ziw9uIyf2WbEOY54JUL6u/KwN9Y=; b=hIhMLea9hyClwsCAFng84sxH4knQAWgHZYkojl4qvlRyqLMRBOUU+NEoLK3FKBRG/x9FqC wfechbYYErXuBwdIR1LOBHvH2TNAeEVFgHUluYWPHRpyVbt0ilVWM9BIFKN/a+qoHDXk1v JGTWzXrjH6+JOjFJGDzS23e6AyWlgLs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696176014; a=rsa-sha256; cv=none; b=eIIFcsV7zplCJPmBKxIhBuz6hYBzaiT4UHnfGcThwmJ78YYZuZULWkYeYguGfzP/pIcJN3 cYb9P0MmNpG97jz6Zt4sFKkjld7YQBoYr7TMnx5OwGCkJZGTSuFL+laRDeYw2rKb42aHes sTFoAqY6qlOFx0iRjEJzU0m6YVWF6PM= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=AgxXlV50; spf=pass (imf25.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-406402933edso73933515e9.2 for ; Sun, 01 Oct 2023 09:00:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696176012; x=1696780812; 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=YKun88ibkbujMSV7ziw9uIyf2WbEOY54JUL6u/KwN9Y=; b=AgxXlV50SDl542YrOXwOhMEt5+o365ZWniIKeLGhhb/5SOrtF8g94iEj//ibHbKqAc aWRfLVtnumB83njlc9xmCDt5C5UWRqrPpOHbZD17wLM37DLXRy2wmlbC9/aAppzHcc4K uNELTWh4SEph0h3ZKh6DTz7P170ur8PIpMlIGPn/mMhypXJIelmDrDSmd1Eer/fRYvKA rdCX8somilymG3otXkRY7U1wzv8xez+/9eBkixFmwqO2L6asA4iuizSWRJmv066wG1e8 iahWMgN1VudYkOE4L/aGm+HKb1Xhbb/SKhxtmunL0gpv6Ncj4I0TgA4tp8C0zUuyELeR RBtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696176012; x=1696780812; 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=YKun88ibkbujMSV7ziw9uIyf2WbEOY54JUL6u/KwN9Y=; b=Pf+EMAZ8Uznq4P1xWZra4eJ6NB39auKMoRKN8IJNKByW7fv1YlHyJJUNOKHlycOLEL 63BMQziebMqTcEv5bdu7E3KkISJsKEmhZFAPFanZOiVx4Zr47OL9pq+la6E3NLy0Jk4p G8G7D4hO6la3whKoO3PAMpNVnaAlDBd0qI+947OMoWO9sjXxYk5+UHiB2kf4glVbIUDI fpuVPMM2lbDb4jxm39Y+5z7tgQcGr/1YFT9q30hiteUwT4+JNMZWP4uxYvKsy5rxDtDT Jranf23HDaoUc4yx5XVOBmVkfvlp0tEvNPCZEr0wSJNnJVgJVc1hvj2+GeYyP9ejc7Mz A7qA== X-Gm-Message-State: AOJu0Yy1pERvOSU/un4v3RKhjM5cinX15y7ZVuHyFA3+5k0w9CUMbM2R pOcJEUqsbBlU/POz07ueMtBQ+PZpWFY= X-Google-Smtp-Source: AGHT+IFnnsWiobuODClQVC5VSivppI1POmujPR7WElSjDMqnAnbl/lbUpE8dWdav5pBbnzl7mmgOrg== X-Received: by 2002:a05:600c:293:b0:401:1b58:72f7 with SMTP id 19-20020a05600c029300b004011b5872f7mr8926916wmk.38.1696176011866; Sun, 01 Oct 2023 09:00:11 -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.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Oct 2023 09:00:11 -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 2/4] mm/gup: explicitly define and check internal GUP flags, disallow FOLL_TOUCH Date: Sun, 1 Oct 2023 17:00:03 +0100 Message-ID: <5b20f3cda7cd841555c2626f98d23aa25a039828.1696174961.git.lstoakes@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: brnhs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uCnMo3ZZUfLCEJWHxUS61iPynwVybbAflt40bnA9RJa1sym3zto3RAoqk7odg5amv5NnuY6GGQagcEjVdYvox8SjlNTd9lzkrla/BLCaZvvRVCYbjV+8wwcuF3Ps4OHrFqP6YRdoKSmaxOfTgpS06Hjo6glklNq+EWQbIBWLA91ADyileZ7yqipCyciqcyxOz/6fmJpz5aGMT1z/q9GkiHgzJxqxFDSCWk7+17l1rZ95gqKaOqzl5cXqYMdGwubNeWEVk/XMd98vqIAoDIeY1euAtcSouTwkuVK4SQa7ZghijvaoCWsDrSpOjhVMPqgU+U5I4IUKnMMkNu/PTpFXsI4CEsNFvYxExBB4oHfbBCXmxhRVMrbTRCVuVVUrjbcqxjQrGree4jsfXtLnhXC+tyAEl/X8Za6yAxmpumCCIrjvMdgigLm4gz0wGM27H15jxzf4wP4qEAAEBnkDK0iBZRUyxxMxHqjt1CXlq 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, we were not explicitly checking to see if the user passed in FOLL_TOUCH somehow, this patch fixes that. Signed-off-by: Lorenzo Stoakes Reviewed-by: David Hildenbrand Reviewed-by: Jason Gunthorpe --- 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 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: f5k6eygyf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ZuyNuOrGxRhMJ6HL71wYGvxMzZ1EQCg/GQ2QI4yAwClmnFAoDtm20GS0T/uJfwgk82OR7wT3T7yVx0V23IlWsz8HqP6YI5JUDd0jnd0DGP+w3xSDGh4AKwt8x+/YihWBbsPwkR68utn7JTmfOqhtiz8JkFbEK73uoF1uu7I3bokwqKAihJIiQ7VkQq2TM5cGAKyVZbKwZ1rCqqdzcAl+/WqCkjpRqmUjqvuPJ+e8dZPTuirgTm8wIQcCrUMAjkIjLJipV9Q1H7mcqWwOR4KuNEVzRWQhb3j8USxH6+K2RREMmAZ4FVY/3JvmZqwA0mc72O46Jbtdf9Urk0W20/axEyrCqDzf7d+eIyM7U5dDy1sfpzB46devgHABjU/yzj11WUoRl9nBus8ABEPUJYxs9rxRaHWX+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; } From patchwork Sun Oct 1 16:00:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13405433 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 61FC3E748E9 for ; Sun, 1 Oct 2023 16:00:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AE5A96B0192; Sun, 1 Oct 2023 12:00:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A93CD6B0194; Sun, 1 Oct 2023 12:00:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 90EEB6B0195; Sun, 1 Oct 2023 12:00:19 -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 7EF186B0192 for ; Sun, 1 Oct 2023 12:00:19 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 3DFCAB35F4 for ; Sun, 1 Oct 2023 16:00:19 +0000 (UTC) X-FDA: 81297354558.14.910FE44 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) by imf11.hostedemail.com (Postfix) with ESMTP id 4D7B540013 for ; Sun, 1 Oct 2023 16:00:17 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=FdkoEOJK; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf11.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=1696176017; 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=k884TE7KNx/WnBRBjm/8oTv2AQyhCRgzdEjEHuml8kg=; b=UXEd+7ZulPxBX3ff5H+yJCiAA7/2IQydyDXCBaV4ehMNMd90QZchMQjO/52VlakCmQu7dB aCbj8jzI5ga2WFXiHredFHMNEam9RDmGyrSi6REPpJNTYgeImWSXZbE4dgty9/mEKsAcx7 b+qQZffo/t0It3p8F8QnjnwVl71fST4= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=FdkoEOJK; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf11.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=1696176017; a=rsa-sha256; cv=none; b=AV2dNC+cfd37l3jozIvJkHJFj3XHykqQi9XCqaEhDnmPlQ5WUEowEfHoJce5wS5gLgZnDz 5lqjfieuiXb63e4popfenDTCBWyt/oVbpU++G/QfZEVxnlT5I6hgG6vK5nQjR2dLtcJ12m cE/z6MTdSNtgGoY91rzCR2CRB830EK8= Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-3215f19a13aso15619665f8f.3 for ; Sun, 01 Oct 2023 09:00:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696176015; x=1696780815; 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=k884TE7KNx/WnBRBjm/8oTv2AQyhCRgzdEjEHuml8kg=; b=FdkoEOJKygWJUkHWHN7kvekbcHXcPpVm1lGTWafGbdOQGNCnq6qb1Tcbbg8oGkifxq LafuzSdja5ZUcC+f47tb+vr26Ikey2Hfl08wDtyyZY02NKf1KFdMdgdMroNicuK1oW3x j8kUYF/GLx1cCkpKadTwRXbUBEwO8ND7ImLnZw2DOKAEDCrK/q8Gt1/QyQ+ZgY0E+aqH Rh2aVWBKLmqtSgptz8JOEDbD164Mtz1ZqHN8rpOEDHtkzUjcYSZGGE83+CniuEDo6tkO M3fpP4ylc7o0sRTyial7kgm4wSJNgGTiGYPGE0+aAATstmtK9vkJW3gSNup/7Vuz3a5V h7IQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696176015; x=1696780815; 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=k884TE7KNx/WnBRBjm/8oTv2AQyhCRgzdEjEHuml8kg=; b=N+F3VOQHYNu6q6VN96zhbS3qRZnlEZgfGTn4+yQOAAH0QjlyLdKZcp4ieFZYCI9v1D kXX9j9rVkXHPboUMbW+REYTc4r3/afud/EU3bI13UBqhfHnDOWOklFZ6cLkp/ybeHsve G33PZGguV4D5dDti04phpdSdp68rAxcXPXNbAmrROP2eokdkNF4FB44YVKBKMp4YexcK wq8HR1ChvxiQymcVd1aAF9Hw6hfGvQwIWPVMhR19rm0duMuqiQy5/h8QHWy+aV2ytkNg JOcWlUC2FhpeO6Ssn9w/KNlkQUT4y0xPoQPec1cd+GyKGCptOrs/L0kboOfFOaHHgfAo //hg== X-Gm-Message-State: AOJu0YyM+IOuZHeE/RdYelerRWNrdnjVc9yM5OHwrxxCURKYJLMqQ+y2 oZcjxeUMvsQRPXxsrxveaXNTS8MGvgU= X-Google-Smtp-Source: AGHT+IFz6TUSlKf+sA6AqE1HJa6bCLgZ7TQdxdFdV0t++vM23Tcc6lgRka6dafHVYFayTJul4FVAXw== X-Received: by 2002:a5d:6e53:0:b0:321:5971:23a5 with SMTP id j19-20020a5d6e53000000b00321597123a5mr7951114wrz.20.1696176014911; Sun, 01 Oct 2023 09:00:14 -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.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Oct 2023 09:00:14 -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 4/4] mm/gup: adapt get_user_page_vma_remote() to never return NULL Date: Sun, 1 Oct 2023 17:00:05 +0100 Message-ID: X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: 1ufm6i7jjffxuek9ghe9w83x4iqyyx9j X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 4D7B540013 X-HE-Tag: 1696176017-811020 X-HE-Meta: U2FsdGVkX1/mhpSNIQTnd/FSoY44avpAxDvJyS7L/LwxqsRvbcPDDcfDmIndH1u1cnHbxK5foByaWkbmUmSvq0NiGGZ3rPF50lVkzXKFlY8YcIuqdb4AdqY7ja16G5ANuGABMqHVBXOQgEkLdIpP4kuHwCfrnsHSasg4uSHPNBkX9z317siI2qxT6Eety2oIJQEkGcSiPrXMdzKBZG8gADtnrSN5AxxWshjpT/w8Av4Es+6Wlhi6N3ogaRKoeMnXseSTviRV7pWBiWOvnMYXhR60TDvnyz3hwRrj4AtzMlM46INchCaTvjhyxP+pPSe4o6Wz2hdcc9Hykf5DJXoMCbwlZ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YnVYtFJY5kJiRTWGpTmD7eVNY//GIRRNK1XQ0H4+lvgufxp6 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 Signed-off-by: Lorenzo Stoakes Acked-by: Catalin Marinas Reviewed-by: Jason Gunthorpe --- 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); + + 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); 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.