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