From patchwork Mon Oct 2 23:14:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13406613 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76721E776D7 for ; Mon, 2 Oct 2023 23:15:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 795348D001F; Mon, 2 Oct 2023 19:15:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 71DA68D0003; Mon, 2 Oct 2023 19:15:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 522D58D001F; Mon, 2 Oct 2023 19:15:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 3E1718D0003 for ; Mon, 2 Oct 2023 19:15:06 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 10BDEC0124 for ; Mon, 2 Oct 2023 23:15:06 +0000 (UTC) X-FDA: 81302079012.11.2B403EC Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) by imf26.hostedemail.com (Postfix) with ESMTP id 40902140012 for ; Mon, 2 Oct 2023 23:15:03 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=c+xNpkU4; spf=pass (imf26.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.46 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696288504; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=vQvCLVMfpl1rfMES4jKdwm82L8UOBjNuap0Ti+SzBhc=; b=bnkzVv0pGOR3jq+FYrRM2xdCuHrqTE3agJMa71rCyRue8YBokdDTsMQ2E5vvo8S800DcR9 UPVRkB9bwB0uZ3Pl7AwSY17dGz88n+MXtYNSKwJ6d1gFDartcuKc5cZ96zVPI2pF86x5+N jS4LXMPWtcSVjTNkqEyhvk/riCJbQO0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696288504; a=rsa-sha256; cv=none; b=SBod7NGG9fOOarjZYG2pO8PJlT63HxPSVpChvwZjoPACTAHDhBnOoJtxrmXAfc9waY1msG krz9+miu35eqsFxCdR5e2n2THa7T0RipYF+bhM+9jdt6kYIVUoTk9K1wA039/qa0An7cuK 4JWUGkGx74Rb0cW4MkyjpIVW/Stn4Q0= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=c+xNpkU4; spf=pass (imf26.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.46 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-405524e6768so3042595e9.2 for ; Mon, 02 Oct 2023 16:15:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696288502; x=1696893302; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vQvCLVMfpl1rfMES4jKdwm82L8UOBjNuap0Ti+SzBhc=; b=c+xNpkU4qymalFe1pMVGsJt5UOnbGLfvHj7f/8TkVzTgouSz7zsPLQNAOspABNXsuA PS/5Gvnua5wZhUiTvR7C2Rm6aXtgeee0lMbdgESRr7ty/u2mQEjG5GOj8uXX3TysaNIT xLrs256b0s7UhjB0GOjAXo7U4CzjJmQbj7p9NbDSpgZgIxBOjqGRrI8fc4f8Ma00m12X 2pD6T4cR8oaKvm/yr2BRIYDb9eP4aX6Vnu9ng85INuRGakDKSWfH4p76W8ff/6sXZFYT zF9qHnSByPWayguyeMkzKOR+9ZsJGf3L6kpFGiCLCFnQ7EThXA88RGbmxR+mjCP5dyRp Sfng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696288502; x=1696893302; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vQvCLVMfpl1rfMES4jKdwm82L8UOBjNuap0Ti+SzBhc=; b=MZyYWosjqVZnqzNq+k53LS08fppQTMXgLTZlXhz3JGA4zcihDPLFdhBz0h8Ets4C2e 16F9YCziN86Rdw3xdON4B0MB6atPJpVtr5LiZlJFt7FMlo/vaYzPmCFqMqQnPUTw3eHA f0G7eNUfsiNTovWgsJVCWN2JtVeXZR3NBaWBlr7R+YpClGScPgpj8VoX7lgo2pbcHL9P hUYJPd31ziCGVlH9tPzBC9WeFnGLGTJhxkjP5y47UG6lx7l2dT2CFCARcBg7bSdqYW0i Wj0EiejcSu/1W7ZqbHBjPuBjnEJsyXyTtM1XDNYSLsSy29EQLF56uuOerW6LQ+Y856ix /cFw== X-Gm-Message-State: AOJu0YxB4lqWB3HPUy6At2cwzCARHV9Vi0ffqXmoMzAWW4TQWon4c7w8 CxBRdeNY9uZVXs156ns14gSEeCpgxXc= X-Google-Smtp-Source: AGHT+IEtd7/2+KG5WHd0cByCIEOQATOBxdbRX+bfexS1IsqnxYU1Maj/cmH3p1/Wp7fgogXQxGevfg== X-Received: by 2002:adf:fc4c:0:b0:31a:d4e1:ea30 with SMTP id e12-20020adffc4c000000b0031ad4e1ea30mr11701566wrs.17.1696288502337; Mon, 02 Oct 2023 16:15:02 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id e31-20020a5d595f000000b0031fbbe347e1sm63860wri.65.2023.10.02.16.15.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 16:15:01 -0700 (PDT) From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Catalin Marinas , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland Cc: Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Oleg Nesterov , Richard Cochran , Jason Gunthorpe , John Hubbard , Arnd Bergmann , Lorenzo Stoakes , David Hildenbrand Subject: [PATCH v2 2/4] mm/gup: explicitly define and check internal GUP flags, disallow FOLL_TOUCH Date: Tue, 3 Oct 2023 00:14:52 +0100 Message-ID: <971e013dfe20915612ea8b704e801d7aef9a66b6.1696288092.git.lstoakes@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: isr11uqzdqsrtc7mrgt8bt4p4oj78pqc X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 40902140012 X-Rspam-User: X-HE-Tag: 1696288503-220626 X-HE-Meta: U2FsdGVkX18h30ZQo0cRbJW3KSEHhcnu0y8eqXYrIDQkjNxzKcH7gNRG3qovgp5lwvbqUU6jg0KeETpcWhSnevEsjw9j42s73IrcLijAkyY8UmySSh6gKeMxThyW4VFAXxWxFcTDvIuJVE3Z3BxDRYxh76FVezE6S+9ECiIe4CkvlCBtsHaWUeGWQ4lXVzL/ZZZxP46QDsiEJDrJ08zXHefleJBodDXZoQBPMVGZnxKLGF6ZLToOkuHF73zjad6qA8DbPq62wQWadROvpu2/sKAoA4N9FH4giOpEW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fC3a1nJY65y8TU9yURRYRkKg7AH9nlI9YU1I1NRAbHS0fNqaKg2NUUzC5HQMhcIQmNIBocD5ilOSv89cqFis5rKVPDBMruTlBjJQH6zTcJkbXmnVf0g5qsfRuQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Rather than open-coding a list of internal GUP flags in is_valid_gup_args(), define which ones are internal. In addition, explicitly check to see if the user passed in FOLL_TOUCH somehow, as this appears to have been accidentally excluded. Reviewed-by: Arnd Bergmann Reviewed-by: David Hildenbrand Signed-off-by: Lorenzo Stoakes --- mm/gup.c | 5 ++--- mm/internal.h | 3 +++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 2f8a2d89fde1..b21b33d1787e 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2227,12 +2227,11 @@ static bool is_valid_gup_args(struct page **pages, int *locked, /* * These flags not allowed to be specified externally to the gup * interfaces: - * - FOLL_PIN/FOLL_TRIED/FOLL_FAST_ONLY are internal only + * - FOLL_TOUCH/FOLL_PIN/FOLL_TRIED/FOLL_FAST_ONLY are internal only * - FOLL_REMOTE is internal only and used on follow_page() * - FOLL_UNLOCKABLE is internal only and used if locked is !NULL */ - if (WARN_ON_ONCE(gup_flags & (FOLL_PIN | FOLL_TRIED | FOLL_UNLOCKABLE | - FOLL_REMOTE | FOLL_FAST_ONLY))) + if (WARN_ON_ONCE(gup_flags & INTERNAL_GUP_FLAGS)) return false; gup_flags |= to_set; diff --git a/mm/internal.h b/mm/internal.h index 449891ad7fdb..499016c6b01d 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1018,6 +1018,9 @@ enum { FOLL_UNLOCKABLE = 1 << 21, }; +#define INTERNAL_GUP_FLAGS (FOLL_TOUCH | FOLL_TRIED | FOLL_REMOTE | FOLL_PIN | \ + FOLL_FAST_ONLY | FOLL_UNLOCKABLE) + /* * Indicates for which pages that are write-protected in the page table, * whether GUP has to trigger unsharing via FAULT_FLAG_UNSHARE such that the