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: 147172 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1103110vqb; Sun, 1 Oct 2023 16:46:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFIGoiTZJUH6sb4cvqndALJR/CZb8r166XWgGIXfAb/kJR9B1ZwdEOdF6DlGH8ylFIowiKx X-Received: by 2002:aca:2415:0:b0:3ae:156f:d319 with SMTP id n21-20020aca2415000000b003ae156fd319mr9706092oic.45.1696204006755; Sun, 01 Oct 2023 16:46:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696204006; cv=none; d=google.com; s=arc-20160816; b=C4+Ep8mDfC/LsEEM2t5jGb9txikOUfN4jF9DJLkRVXbpfyH+CuiMWEOIZiCrlG5nE9 fJws5iN9eoC4CdcHkEXroM/9TsFIUv8y/9KdMYKtlf7MH7WzY3NWKpTMh1U91r3w1WtZ LpmAGeeADA9ed+pxyoAdw4mHNUki/zpLJjXE66W+yUO8fA/0K2z3aJ+sU6nEgSRoIsIs nSs1+h/fVivNtqpk4GJPouCqBobgP4PLVCS9ii35OeriI80po5rJxJemMlAiIdh3lW59 eUce0L2O8+EVRUxE3GpQTFecp7cZoxKo+HnOUdvEzx0NUFfV8z6LcvX8LYv7hPptjDRV 440w== 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=pfhqMS4SBWNsRFumL7f2VoNpk2TCo8ZgiAHTNGqiqHs=; fh=mNvOpR73OaUnRrr53gRvslddDUjaIrpQi7RNpkp0Veo=; b=pXTmy6agokigxDnkLzcPNi0exVWDKzVwdBBfoUqgUeNsH832pRrdOaUW97v2qmkHzQ Eml+ykFGdEI4jUCQKeXKcC92/OfNd5yXoUmjtx9XLz+mHSTq39rIx1rIrhfveOn545qr 8J4jCzEyEbMT4rr1Jj8VtlJY9w2YuUIYtv72JOddf2wn31Cp4Gc0iaRLLSXASp7nhNAZ U5xTYBKFK5qjhp/F3zjNjkmU66yap+bPyxut59pV8NA0wgFeAKOGAQQNNAB75lhDVYXH 6JsZdqnw1K7H5NRjT4y4XrHh75mnI3MBL3DxMDB7JmagPEYr/EvWPjZ3rvvqsYFQ5tfM Nc5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=OL9jdxRb; 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id my11-20020a17090b4c8b00b002777d51e89dsi7123882pjb.128.2023.10.01.16.46.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Oct 2023 16:46:46 -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=OL9jdxRb; 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 7BB00806FB51; Sun, 1 Oct 2023 09:00:24 -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 S235184AbjJAQAR (ORCPT + 18 others); Sun, 1 Oct 2023 12:00:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235186AbjJAQAO (ORCPT ); Sun, 1 Oct 2023 12:00:14 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 471B5E3 for ; Sun, 1 Oct 2023 09:00:12 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-406618d0992so18458715e9.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=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=pfhqMS4SBWNsRFumL7f2VoNpk2TCo8ZgiAHTNGqiqHs=; b=OL9jdxRbNe4765piky1C++UOFN5BOfkLGtMtaUCnY05qx7TND1M+mmB3wInOdtdTxm dIYYB9JZI3uQpKMnzC7NrMJJtRIGF768eq9z5bT1QKwgZHokRcCfNIYmFQsZvrGRmVif aR+qF0sn0LknzKCaOiFfqAR0r8v/ybbj4YfTSA3/3J+i4B6eYSi+ekEUFooEyOOfG2m1 vLwUSZ3w92QTxt/8U3rpqVfO2e6h0JF6+bq4UqGwbv1J3u62Ew4gRNP42RiG2s9goLB/ 2HJrRilNNXjTHCvJ5+A2D3rDBFXdJzIre2NQ4YRomx9/2JJAml301z2HdYMceG6l1/W0 Vo3g== 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=Qp4/cpL3+UmQtrnb4MREl2w32RGLVuP4RiOZuPIh7Ht9KPoqrstjSfaCRKujcsXx6k a/rArB7wSi4EUamQ37QsAHGRprNlOTXUuAX9NkKpmpPfwV48jMjN+Tkyxs14WA49y3mO OAlhCy2m1gHBbmGfIVOjI5fKm3YZQ7610T/it+AIFrpf1qSisyHeGJwAuZ5LL1ZDdNGf 2dMjYE73yyJrSSP8Hggl2NE3IAJO3PryGLVrW+K4YqF1GcU7zgQXqR0Xgw2SGe6xG3Hi J7kWfgFglhcbZRAnKcEWgWSuW5CJkvkmmS3G+g27oLffmzBOawKR1vXftyH+1ayl2tPv HPXg== X-Gm-Message-State: AOJu0YwqR7Sau8PcJmL1rSafyCWD/a7mQ4HIGSWgkawKh/NDw/VYFReh GkRfT9DeX557J1BowmUj5mg= 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-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:24 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778598812339444499 X-GMAIL-MSGID: 1778598812339444499 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: 147128 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp943092vqb; Sun, 1 Oct 2023 09:03:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF17L45fzOHR8WREC0xKtxjYQ44b6wgsX2hRSk4+VJlJ+Qh7ocmSfBqpEyWinku39gpy7nR X-Received: by 2002:a05:6a00:2e84:b0:68e:36b1:3d7f with SMTP id fd4-20020a056a002e8400b0068e36b13d7fmr9823249pfb.18.1696176207837; Sun, 01 Oct 2023 09:03:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696176207; cv=none; d=google.com; s=arc-20160816; b=Qmrlg6/SP8a5XfrkukO8Qjjl5zhN0g5WziDWKjAHmikj+F1QRfDmv4Ldyopi7zaVaA vQFIISd+ZAZEya7sUk1j0QsYd9H+O2irGLorQ0Py2IeEziZEeEgwnmAf0vP1uGgJrfkX ruFTryzcHUtd3OxukytvjWkQ/52PsdDxy1nAeE2CcV366kZk1d0GAmDnDsFa6CSXexxy u9ewrUbDoPk9Ytzg/vmD0z4/RWgh3bibpJld39xKWHIwcGYpeIxpx/3Dj5KgDFjSESpy uF2pmyKM50Qxr78WJ3hPNYIcE28QThiKHBJs/Atcqwk21WHhl8nt8u3/57UBiu0WDIoK cl5A== 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=YKun88ibkbujMSV7ziw9uIyf2WbEOY54JUL6u/KwN9Y=; fh=mNvOpR73OaUnRrr53gRvslddDUjaIrpQi7RNpkp0Veo=; b=Y0wtr8lpBrXqdN53gro8GFWvSLfWDC+YbOKMTEBQFBRZ4yjE/lMh+h5UIt/2275s2a iU2RUuVTtqJa4V4ilbBUaXlFJrPOc13H2LQKORZbI9xkxjnLonUVLMgjRaj5HPsQ+CV5 WSwtLtcKqWi6LPdc+QwXZwyRLC9BWZxRkY4/Bw8F0nrj+lE27L9yFqIOY9ULV4+gX0Dh CIsdGUucZPerQY2fOCcbE1I0kTpAX/W562GKUCmb4v5tD0+tn5DrHV3ROgdSn938LuQN 4sulMNlaOoy6/DImYh7mckLrux3Zx10Y2oXYWh6ufesCCwyM15XqB+kinUl5e2HiqleF Z//w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ikurUGbA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id j5-20020a056a00174500b006933e7dcb09si11402889pfc.87.2023.10.01.09.03.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Oct 2023 09:03:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ikurUGbA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 D573380756EA; Sun, 1 Oct 2023 09:00:31 -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 S235199AbjJAQAT (ORCPT + 18 others); Sun, 1 Oct 2023 12:00:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235188AbjJAQAQ (ORCPT ); Sun, 1 Oct 2023 12:00:16 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D43A8D3 for ; Sun, 1 Oct 2023 09:00:13 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-4066241289bso17465955e9.0 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=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=YKun88ibkbujMSV7ziw9uIyf2WbEOY54JUL6u/KwN9Y=; b=ikurUGbAkTec8UM6M/cK8aM22hqVN3YesBMi2a+t0fqgMn/G+hx7FQ5Kz592kakc83 PqxmeO8rHY7GttX0Ebmm5yHee1HKE63oLKmMZl9pNb3UMFqqs4HvJTqYYo7wMONriHCi d0j+txlH0BgefD6d4Sq3h9dv/LaDkDzx/UcyojVzvouJ/fcU8En+B6znwnFZmmd06h26 bW57zJjt1GdWuxPtRrTAyUSPZTfuUFDrMqTSycN9ekNNZxlbikV2rlzQLrLMXWCVzN3o SuJ8DyVjFk9RcqIZ1eTUZhQ7iO5yOTiTA7uyoPdg/iVm7fX1YZp2/lldLlmt1AzlyLNO mXog== 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=B/STIgu5zlIvpC4Sc0TCRMfZyUnGis+NTKYa1dIz9oC+WX1SknReli9OHpg+sYa2tm o1e955/spSkVbQRomgwiSGYIphuuPr8acatGZhWM7erb0fHYjhqaskJeBgt1epndhCBh TuEfZop52peyPS+FA+J5nZpHBt+AlvSzS2bUUYq96cQpk8YMFvqAMBuD9X7A3jI9IK7e ZVnXn5zFYoW9qWA6kKXQHbYAJemCHv2NAktBnuoMcxpLW5fRzSil0pGOiV9NpSVSxRJ4 WnIsrd7aQ7+o7BN/yn1rEN6TBZY+eUpBcMyG0/lwvmBa26nA31wK6e1xRSFAlJMJNPj2 1eyQ== X-Gm-Message-State: AOJu0Yyy1VjNZmzUEz8S6vImfliW0IDiRvLcc7Al1CUFaxIMF/le3/YH WLK+iBqU/xuNw01D/KMasHA= 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-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:31 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778569662978744991 X-GMAIL-MSGID: 1778569662978744991 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: 147163 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1060440vqb; Sun, 1 Oct 2023 14:26:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFpqobR5h4fecD8Enk1Oughttrr1rYfq+APSbBjhqLf7gdEmtyirwMt+3yvjaKQs+euMAVM X-Received: by 2002:a17:903:181:b0:1c1:f27e:a55a with SMTP id z1-20020a170903018100b001c1f27ea55amr9880725plg.46.1696195596481; Sun, 01 Oct 2023 14:26:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696195596; cv=none; d=google.com; s=arc-20160816; b=ffIHHgyAlnegOoUy03r0DpLRpd3SATuNqeuz8z946OefPqr3BvHwhRImoUytLG+GxF 1tT8SiiiZA3LbPAQT++MrSj5Ef/vNaNV7Aga6kXMefJ3Lb+Vmae5Ki5l3z5VoTYJFm4c XiSYlYCnW4j3LNzTHagjSO7yOhmVvQgNMZv5SZ3TS3agIwiQGtIEXO0ep8d+wlWiiOne VouIMzqZQSKqVBphToZhtlQAq4Umf7I6zTxtY7P6IbjwRksu0BCvTrNf9rCO6NfCyoM+ RN8CXOkJpPKipu9l4jEj4VhYcvqrsmO7bsiI29Ajm1YTyCSlKctaIfoyWlrGUsnrC5A5 km4g== 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 Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id j4-20020a170903028400b001b9c992945fsi26473915plr.555.2023.10.01.14.26.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Oct 2023 14:26:36 -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 AC62B8074526; Sun, 1 Oct 2023 09:00:41 -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 S235188AbjJAQAZ (ORCPT + 18 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 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:41 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778589993769695489 X-GMAIL-MSGID: 1778589993769695489 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: 147190 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1210396vqb; Sun, 1 Oct 2023 22:36:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEDF1pculdTJbb2rKwhhC/ANGUIIRcIHLhiEEz+hmS5t8kmmI7lueYuscs3hRp3VrWRU1O0 X-Received: by 2002:a17:902:d4c2:b0:1c3:90c7:b99d with SMTP id o2-20020a170902d4c200b001c390c7b99dmr12720546plg.41.1696225007190; Sun, 01 Oct 2023 22:36:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696225007; cv=none; d=google.com; s=arc-20160816; b=WXVmO8pPUH6Uc5Cfe3TmLuNs4kGDAIwwOnNBp/C19N8GaxuOkUVaHdnaIfQH3SGZ6o aYl7YADRhC26YyStiMmtleJZOjzxoRWyEe/HO985mflLU/R6P0UrC4vyM74lfjaglW25 uX3/KzgoMtfTkvIoGRilVvZ5o7JKIg+Lzu1csHyttvHmF8cs8xEpFTS2aI0Qb9Yw/T9c YCBZy0flAW7IChS5FUPe3XMRZFJyB22JeHhcyigXNJMtvySpMdBJEtCslMyC1MSWxOC1 0KUtnIxbmme2Z9tBRXba7/CBMnsEfVZ3iBLj98lx15gyg5yXkKrn1UwuS1T+ZIrLl7b/ Zh+A== 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=k884TE7KNx/WnBRBjm/8oTv2AQyhCRgzdEjEHuml8kg=; fh=mNvOpR73OaUnRrr53gRvslddDUjaIrpQi7RNpkp0Veo=; b=G55mZ6RTqsghuxINmoyyckNA3aSoxocBg5saqccZIonEWcJ690Y8lrkp9GYomrWJGI Fcg1Z5HUIZgyXtg/vFuExLBxgSloO45NECxo838VkxRdVXAhVIIgOVfzcoQysQM4Hagw gZwCyZZx8asPIIIrfn27jMX/g7rjWm9y2zTnoXGBYpbBv3KTvdozoDQZzP7LUIGNbqhc WKHWAcU9kqYbjP+AWyaNoHX0okQeVGb2c2Svd4gssKawyHRjh6vUPG0Fs64iROINyoho 9/xEqyWdsJUPB4Ay7FtgNjHzcf/k+uTsssFTN5jmzvj6swOspxcVVcuAyji34aaARk4o lVcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=eC9v2aDJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id a17-20020a170902ecd100b001c5616520cfsi18104817plh.204.2023.10.01.22.36.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Oct 2023 22:36:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=eC9v2aDJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 A68D78091C5D; Sun, 1 Oct 2023 09:00:48 -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 S235220AbjJAQA2 (ORCPT + 18 others); Sun, 1 Oct 2023 12:00:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235155AbjJAQAY (ORCPT ); Sun, 1 Oct 2023 12:00:24 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBF87E1 for ; Sun, 1 Oct 2023 09:00:16 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-32157c8e4c7so15624050f8f.1 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=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=k884TE7KNx/WnBRBjm/8oTv2AQyhCRgzdEjEHuml8kg=; b=eC9v2aDJav36tUfYswA4Ze3QQ6KNhS2sPi3X+0XZvGEt6RiOGnHEFN7ks5WJKS5GVK 8RD9V2mf2jzuPrCFcosWNXr2/J3xsXoKC62g/7LHBWYPoFF0CN4/rGKNwD6f5bbSLWOm Hd8EKWgLBo124NZERmoyUeVzdsWMsqZI2N6ggQPptylgZ0mqqn1eey6aH+kqcBpFDQ77 0DttRbbNSUNaflltsL/j3ukJEaQ085f4JCF3tgTMvA2XQI02BOVBy2iUF9dzKLlNhObp 3FjPgeAqz3UoRHKdyKVpK0X30L8lpFxA8BEiH5Ms5b9EB3apVrK20scqaWg/1iBRg2V9 /W7w== 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=Cc37zSFpMSfPlBb8aNtT9fH391un6/U6bggvzUvkKNFZIfEN6DDMg9QsWu623nDyM4 qClonr+xPwd6Y8H9PRdSkJrY5efhAZy8Ftz/MxQ9Fdf24VOm4sObHbFDtjbVh9Sn5f1+ 3VQbFSPLydJTNU/0Ua1M19vHqn64ZIbw57M7fhaAP2DOCzf9mKqnRckQUzPh4tmuZlF8 B9jGLkmX11YnB/FdqXrsCvclaKnxIkJf4oEdHRxYw5qJELpLDD4DD/9HhX8lJGj827Sy nhtTdWYR9uIQn37uRgvIn2p3c3iYgU6UCc+DBmAcJ/WUj05kkS4ICZzNvEUuTk/Z2rx/ xB1Q== X-Gm-Message-State: AOJu0YwHxlnjgIqzoR5MMZwViK2mewEQ+7uT+cUrgOpNNgIVA7v+aCA4 Q8DGBIZ/ME0SgnVSyME9kxI= 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-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:48 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778620833187275900 X-GMAIL-MSGID: 1778620833187275900 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.