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: 147570 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1745521vqb; Mon, 2 Oct 2023 16:15:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGtc0yq5bW9inVGjCO3adOnuStpz8XNgRp2YvkxCJ48/3LokNEqX2/uqeZCp/1GKAlBqxwg X-Received: by 2002:a05:6a00:1a90:b0:693:3e7d:cb4c with SMTP id e16-20020a056a001a9000b006933e7dcb4cmr12719752pfv.16.1696288513787; Mon, 02 Oct 2023 16:15:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696288513; cv=none; d=google.com; s=arc-20160816; b=1IRt8YIx4u1XPNwB//6zPxntZCWM43n5tzqexC++MV+dApZWSDJ65EWUWq8jsfKtQb wOtK7h9GNS0oBvNorG7EhzEv01sNQxaoXW6yIPulxQgwUbb87c5iz08vpPy6smT+fmXo XpCWui7HhVDsxZtrCIS6HukMz71Vx1qAscpQtPU4RtaGrk+CfsG9MWQ7/Kmv3fLj/BMd 9U2B3vN2UtrnyxCZuKJuOy0E036XEDKs2PkwAhOFfEPKL8D0dpp2CQbwjdaDGv+e1t88 6RdBce1LuzBVMiFlNWTpaTkBctiz/OwUYh7aBV8DP14nNPHea8wWu4RoAPvbTiXSmi3G LaLg== 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=8CCf1YepfoJnZdTtxvEP7yh6ZYqHtmpLJthLBvRpqWQ=; fh=vfaXzLBSn2OPHxthf1M6cY+yoPZVfBDCnuDRbM5tXwU=; b=Qt5tDzi9YK71suq7gn6FsZWyhqQDmsAYWVVSg3kqLIz4laA8TJo6nGHwPThNeXhwfw 2VFPWqL2S185ZrJtgxXXRMeg3Z52QThpmf2elMj+EGNC3SgICIU+p2xLodHZggqgaAKr 2Ki9HN8XYf6nzfDGQEQHJmsxM96CIq/d+lu8hyPe6hSEDdbi3682PtWFtZdmqxS4lJWe vv0HlX37l2reY66nU0zJq5kYEELN/s/iKMslsa0VE4bmq9XW6vmMVaQprczg3RqYloLb Quf3VrWqzaPuJqYhHEG9RbMFuYV1KXT0t9tp4iMY+Chl5xz+VKVIJIIiWuQt58UxOfBS gzaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ItCKK958; 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 q10-20020a056a00150a00b0069342cee02esi59985pfu.298.2023.10.02.16.15.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 16:15:13 -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=ItCKK958; 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 1ABB2822898C; Mon, 2 Oct 2023 16:15:13 -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 S237213AbjJBXPH (ORCPT + 18 others); Mon, 2 Oct 2023 19:15:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237135AbjJBXPF (ORCPT ); Mon, 2 Oct 2023 19:15:05 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0ADB9AD for ; Mon, 2 Oct 2023 16:15:02 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-3226b8de467so339922f8f.3 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=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=8CCf1YepfoJnZdTtxvEP7yh6ZYqHtmpLJthLBvRpqWQ=; b=ItCKK958uPcvOnGUWxDaFvxf/iSAE1qQORYwYqcO/d3Q895BvgA3irUvfNEi4b23vr IjQM0Oyph9oKqRxDy6wIWk2v/2q6lpy++mRS8S2PnzGDOCWcEttk67NVbY1eNt3lQVnP vEckMqkx7XbiGVxmli6x67+8dBodqFYqbI3AYPzjVRDXyfqxWoImKtbo1QyG4Hub3vri Yw+xZxzDdp5NjiVOafChucoQKWuIJumr/OK2/717M/ZMSwmCDFvks1SkrNaWofiR/eFy eN58f/dgbFmv2NVohc+YkYWacuwQp52jPpnu4wHpMJ5eKxKW8u7qog9ER5bPfvDK3lwC ka/w== 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=tZLl4Ut6sXKlqpFODBaNHcXsUX+i0f1V4gTOFdCeMQuT7wT1YG8IIc/8zcyEXbw/1W hF+3imZoQFg20GTeXZ+jr9TehkGRysV+pJ0NvHghWNj9ivLdYT+ZzVuQVHSu+vhkXcco boKVTO88EzNzdM44S5K6Asx218Q1wUUTNh3NMQnwdP7x7NPAr8mA/0QKqHypzpH/Gdgu 81RHHErHYlvJGIVBb2GoI8jYyRH1EU9Uryf6IvxkRqoyrww2F6KMgTa+ouhlXRZ5gV0q DhlzAo4J5s5/uGgMh4PsGokZY3cVIja+eXLTOcud/AHgpiu8b05HvZ74+73ljfMs3zTe k6sg== X-Gm-Message-State: AOJu0Yxl8XfUAKh25KSX/O2kdaQ6X0Qtrih/5l9RT/ehR5WjUt8gYjZL RHvraqffyHFh0hopMC3WpVE= 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-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_BLOCKED,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]); Mon, 02 Oct 2023 16:15:13 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778687424412453616 X-GMAIL-MSGID: 1778687424412453616 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: 147571 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1745644vqb; Mon, 2 Oct 2023 16:15:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHkyuuq18vpEVKDtjraDbWC7pUACZu8tzOf6bJHOdAYbljNW9GWbRDch11oyI9Etn6PorjH X-Received: by 2002:a05:6808:1983:b0:3a7:330d:93da with SMTP id bj3-20020a056808198300b003a7330d93damr17137767oib.19.1696288532875; Mon, 02 Oct 2023 16:15:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696288532; cv=none; d=google.com; s=arc-20160816; b=rILT/Kp2xYFvZJevDln1mdQCYgPPzde+pYu0vdAXvkDF2GWsM9rFABXiQvuOaeJcwR 5u8s3bV2C73g1Vubfpyz8W6cGBMzNHMEZ1kUQTlfBss4/kvxSv1m5j/I0w2vR511ljXw DnRspEIlLk/65ZpBntAKPafXl8N15pgw/LMA6x4/kTzbGvW9nT/fqQBkrOVFYsyKU/TH i2AkCBTfJOfm2skv7OLORSoHI6qNq3Py44KHvUSTn/TXormVzWx0a8HEHKgUvU0uqMOu flFI43JN3t2dn050/9lbxGHWGdekCyC8Xfnx43weMY24ubNNFT+WoKfbdsT8VoX6Nsy7 fdqA== 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=vQvCLVMfpl1rfMES4jKdwm82L8UOBjNuap0Ti+SzBhc=; fh=vfaXzLBSn2OPHxthf1M6cY+yoPZVfBDCnuDRbM5tXwU=; b=J0fIzYlmorwC24vlgjhGHUPxVdDfkuCgG+ZggDZYr/JLk66VSZhLTu9g65cR5mYHY9 f4NJnM9/KeP1adQJKadvpy0NDU22uTmme7gzAnEnVIV52FvxeB3whxe1lkgSxUbU3uU4 9/MH5EIb6l7T/56RdZhXrJrl1Ywimh+zEtiJrcrb+bRg9z9SeWSzXk8NE3sKSrUFcAXy ic3i5WyKFVIOXU+dgwhDPvBpX8tEMF7jRrsTyhg0bXUtGseBlF6sKgNJJNqjwCkWD1ER QsIQztGmRSNgOBRnnVrkr//I6ysV7bdzW/34/RJUFGoqS/EdvauEwOxbH3cI6+4Jp8rz SRng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=M+CLVVRy; 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 g9-20020a17090a128900b0026d40e6a7d0si16572pja.56.2023.10.02.16.15.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 16:15:32 -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=M+CLVVRy; 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 8D31D8065C84; Mon, 2 Oct 2023 16:15:16 -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 S237274AbjJBXPJ (ORCPT + 18 others); Mon, 2 Oct 2023 19:15:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237204AbjJBXPG (ORCPT ); Mon, 2 Oct 2023 19:15:06 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 228B6AD for ; Mon, 2 Oct 2023 16:15:04 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-317c3ac7339so355260f8f.0 for ; Mon, 02 Oct 2023 16:15:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696288502; x=1696893302; 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=vQvCLVMfpl1rfMES4jKdwm82L8UOBjNuap0Ti+SzBhc=; b=M+CLVVRy5HwsqvwlOokevjgvepUgwThG5qiKvLLjgD6DgeE0lvwqnB3Uwnbn04and0 5FwsF0wShTTx273cd96s8GM5ipKSoQNtSSWLleeCVEi+nkNqXAS5+Skcbte8QM65fri7 CozNyc2DCzNxLYZC2uztoUiriVNctcjbqvUEIPQSF8LrQiVpZD/grqAQaBMVlZ8pkcYa VMbDr9bjJpGKhPJui+9bnSEhAD/CRyHtYHvTgJxCVZq+6//ibb2+RZHErvAkBnvdDDpM OsUvgL92PtYNz963pxwdEIybG9/0Q6M8vXsx9KiGD04R9j+8vvMmaHeZfIW3pbIOP23U U0Cg== 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=Wz91v5mZdLiPfpjUaMQ6OO3YcLFO1BBx+q276hxhSVcJ3ayBLOFG4gRZ63uNAE9UTR 1IMbZIhkk6Ngb/XEKYfrsRxDl19VZ0Ssa2+YB531BppAlHzyrCZ+yJk4Sb6MikgmKvgD qoURXuWHQUFamsz+kbhMqvGHbRLuYld8JybKuvAoVjjqnWlZ0VYgAbv6v+UonAE2aaAM gM3Tn/TUaXd0l54rgmo45ZG0qjJ4X+qC3dGTXlXumIoU3VmJ4jn5Vm7+NhP6DHspBXuj 6SaO8xRzYsLZ9m+w6UCGSnvZFJDn2Ou8MSfUS9RQtNN6wwtZiKsWggVOtPrfVMmabC2q QtMQ== X-Gm-Message-State: AOJu0YwTAQD5Ljb1yb48RliWmioVD9xG4yfLfxsYg2rUnIVteh3tUM5f vLvr++qE9AZOvQIYkk0gSH0= 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-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_BLOCKED,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]); Mon, 02 Oct 2023 16:15:16 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778687444268292648 X-GMAIL-MSGID: 1778687444268292648 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: 147572 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1745748vqb; Mon, 2 Oct 2023 16:15:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGQRUF2lbBCIH5Sbq+Sf1+Xq6rbh2XJgagSNHO/PRbqsZUkon/3vdnGGVERSb5BGE1k9lC0 X-Received: by 2002:a05:6870:a9a0:b0:1c8:bbd0:2fd1 with SMTP id ep32-20020a056870a9a000b001c8bbd02fd1mr14425174oab.41.1696288546157; Mon, 02 Oct 2023 16:15:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696288546; cv=none; d=google.com; s=arc-20160816; b=T7lnHobdrk+o5ZaP2lTF5D6WI0lg+W6jbC2Rp5BbFjlFw66ICdeAtqy2cH4zeYlvwT M7JVGxmfZCgXmHMeVKqhmBBZHCt1jMLS2qITFZyOHgMszf1U+3zXqDajaJmbxMwaHUdr mQn8aAPGTvG6ryGxuekEzkWr6ksANsobl+0233RY5jCJtOE+mRNNrQAYyi+0dx3MaJw9 6QVaECYLbc6XK8/1VgtKqtN5n53fDRallqPAP8immKgjKsKAzXNLcAPSLepwgVmb3uQ4 Q9floYu1kFy76eu+sXvpZ0hmI1MEOWa66itFla0NfYSTxTdUmCpp1TLry4QkPnRxVDBA NuQg== 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=XG4wWkmLCo1BkRFV+SZ7pD22xcplU2FkjQ1ykcSCzlA=; fh=mNvOpR73OaUnRrr53gRvslddDUjaIrpQi7RNpkp0Veo=; b=GO5NXB/k+p+l02nC48p9WT6mssSBnQjQ3qFd4oJDYuBvSPSi0zAV3W74pg7xXB9Ci+ a7s7cQq/iYysJeLtelWVEqsyxZjpXOdFqX754Xn0TWn5eQZSV/1g/zlT4CnzFmR7/kgI fo+cRXAVDyWuFE6jf2syDG53qKC3D1Fa9sPzPJKAHiC6rzcQVpJUo7ojhJvkAbIKcEuk nqTv9GNPq7zsxpsTrTYOHDzjgd1BC0gYfOJkLkbIlgAAXZzldKgaw0EkkKaHSCe45nPA c2c4jEHdu/EB3NAliWWOryJDBM0dMZyX1XBgCv0lZPs/5iByrSTl5zuu35kjjAjsktp9 uQ3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=nC2uPqKa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id g10-20020a65580a000000b00563d9ff5157si7964pgr.547.2023.10.02.16.15.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 16:15:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=nC2uPqKa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 6939780978AE; Mon, 2 Oct 2023 16:15:25 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237630AbjJBXPP (ORCPT + 18 others); Mon, 2 Oct 2023 19:15:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237247AbjJBXPJ (ORCPT ); Mon, 2 Oct 2023 19:15:09 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BBDBB8 for ; Mon, 2 Oct 2023 16:15:05 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-3231d6504e1so326819f8f.2 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=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=XG4wWkmLCo1BkRFV+SZ7pD22xcplU2FkjQ1ykcSCzlA=; b=nC2uPqKaHv+ZGud73irvViL69+e70oLHG/gE2GX5iioSIZDUkiEo98cvpWWRs1rQcv RfcE+uhXBrltGQtEpvz5V0Ax9Vnw2nM7lX0JoKEjmQrRg0E7591VUPJbjcstCmwofFqt q97vZQz+EFQTogxvoFm9ej8w8yjOU9/jGQiZ1G78g12HaTPIJCgnOYheji9YzxAH6hFv RkHR4NlcMwukPC/Z3H7sjjA4aD2VAyvsFFohdkgrlQg3CIGne/Vsx/wnikP4/SdmeoGJ otRHdMIZjHFKOPMVYH/oYiP7q01NGT3do9AuZPdKboGKT9dEGHO59C6F0sjg6a890Eh4 xhWA== 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=NY/aBdgqAVPDE/MwiT/8tomrmf562qNV3S1OotbuNXsyRf/RtMZjeyFVkrmxicOq4h iB5QL4KHsOgsmyjCWIXF2RqOpcggBYhItPzMORWYeWX0aFabqjX4CP9sUZioLwv6+cz0 EVmdAr4ZYlJtsbjQlo3tqDPG0uUm1+tPH2oa2o0uBLrVI4mxNAuXrvlpwYjcj17jzOiG k3CHohqoewDsnQKOECjtHhDEjzpgHxbg40/unthwpdrFcacAa8+hihxC2B3aBeG+C+rx qjgkMvQRFPU/8Uwph1mWPnlGDUYxuuig2zrBMdZBn+AFoOi8bQVGzbo7L38X/rbxcU1U okcQ== X-Gm-Message-State: AOJu0Yx2+QcmQP1Eutl/q3VMefQ1wF0fF8Q9fSasj3cBaMMYNkGtbE4z ZdUwgoDLE6JzrNcSz4FlZvs= 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-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_BLOCKED,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 (snail.vger.email [0.0.0.0]); Mon, 02 Oct 2023 16:15:25 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778687458476735211 X-GMAIL-MSGID: 1778687458476735211 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: 147573 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1745845vqb; Mon, 2 Oct 2023 16:15:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFJHKdMUajDmwPasIj3b5I7p96tqddc+bX6ppBMaHo33PbD3Mp4EthifSXTvg/CABSJEnEF X-Received: by 2002:a05:6830:1407:b0:6bd:be5:daa2 with SMTP id v7-20020a056830140700b006bd0be5daa2mr12746268otp.33.1696288558713; Mon, 02 Oct 2023 16:15:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696288558; cv=none; d=google.com; s=arc-20160816; b=RQY/DB+qbC6nP99CxgzhD7gSI9miXT+CL6OTgQqT4UeaPmh1Xf49NQ7i8WTlNkoyOb 3iUKih0jpAxzsMkMooxbC4PgqQ1Am0gudDErAd6TeuKHfcCIw+E3rfhy6pzFGhrr0hS2 yg/kHuxKlbVkwBI0Z3geKHA075cjMUzN6DQyzsMmDPjj/rAkwo0+PMKOJuei0Y993u7U M8u0Woch/QxUHJvh8f+wSQKXNvpXqWSwrb+P9/lklSFZTUkBBC5E3GkXHQxfizckvdzV x7qmftwHEzOTm+ql7vyk5i+arFgD6ocNPFSL0Avnzs5bQluMcBsQocfFBdg12K2+/Zw6 hwDg== 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=DSkssDhEiWfimKWDZskn49BRf30NYKZNHbeb9+/CySI=; fh=mNvOpR73OaUnRrr53gRvslddDUjaIrpQi7RNpkp0Veo=; b=WW+EtOkgl6bdkoc8f2woJD2Q7IxF+tWkuckKUV1XPiLFiBCRi+GalYttX7sI1mGOX3 GrUfkGVCV5DaVSNymIF3H6H+8Mu2mG10d3LWjWBhE5q3ZM2mNPnOKMNX9JKuvE6Xad6c WLqGo6iKdCwYeyJbD57zJ84JrKDFvoy1UlgEzMURI2pmVqj/hpwG8sreIj9GDtwqZDBH bMM8A2BqmOKFoAvN1ghITjTJSi8D7g9dT9lw0fvdU/qtmrmjVv3NoVVcLqDmKWfaMtBY IQthoHLf3CYWRa+yct7CPnB9y2Xdfk3bwMut13RFn7SxhAuVhukoXqnTA5J3BLcMLp30 kS7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=I6SJWj6m; 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 a35-20020a631a63000000b00578b40703bcsi27624524pgm.885.2023.10.02.16.15.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 16:15:58 -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=I6SJWj6m; 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 86EBB8042857; Mon, 2 Oct 2023 16:15:28 -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 S237660AbjJBXPS (ORCPT + 18 others); Mon, 2 Oct 2023 19:15:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237295AbjJBXPK (ORCPT ); Mon, 2 Oct 2023 19:15:10 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C110BCC for ; Mon, 2 Oct 2023 16:15:06 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-40652e5718cso3311145e9.3 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=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=DSkssDhEiWfimKWDZskn49BRf30NYKZNHbeb9+/CySI=; b=I6SJWj6mhap6/PZcry5n1JUgyCiOpf+0xKdAMTHsCd+raNERvnu4oIP3OMJy8bfqtU 0nUSXRKrVZ3NxYmfN4lKpDJ7jPXmWaO2sdPGAx3tLdZvCQnjn/eFv1l/wgqbb0rN6gtg KmlpLRDti5PLjUaQgUnTisNB1y02i/H4OhPapjX/L4rtBGDc4QP0+b4GEr4r2mXcwes/ wYPUB/RXN9irphtXN9yjk4mXq/EfAYFQq2Mdy+MgU3wxmlQRXJHQRKCC9Pjotp35Qn3r qMDGzm15bhYh6mDzAmDYXuhOjNaD7yGZakajvmyD/AzWeKGY/s3D6iqEqp1C4vLchhHK YtTQ== 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=gz/HFCbl7n/EREttfiubOGRv+Z6HBJCrEwwEY6WIRjiIuBKW0+MrpRBUJLPLpdCbFW dtHrI9OBzdS2uLMvzN9Td17GjEwvSgUy8WTnUb8dG+w0F8O6MmpjFF8hXxfc75Kklr8o 86XFEg1aMhIA8vRDwZKGXuCGFEp94SZonEBLqgcM6G42UJPvTtNKE4aLIRbeiy0sOHzl MbasQcf+xRuXtU+LzQR1lZ3exoo4VpGOF1zEGxS0QJOOKt3sS94lxQLVE+OHEIGZH98E shOzXzEOO4+/8yCJWTsco3haRFz5UDymbykCfbUvdlfToc6Hn9AS2jnvs/D04idosq/r qZPA== X-Gm-Message-State: AOJu0YxfJVBw6xBynXv3Skv+1q/gk091nPfrBLcfmXNHQiFr28+Fb4Ro wEFpYXrFIVysbbHuDS31DHs= 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-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_BLOCKED,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]); Mon, 02 Oct 2023 16:15:28 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778687471675812315 X-GMAIL-MSGID: 1778687471675812315 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.