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: brnhsqswfm4xs7c7ernzd1fza6qc78ma X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 0C78DA0021 X-Rspam-User: X-HE-Tag: 1696176013-645053 X-HE-Meta: U2FsdGVkX1+qlY1Fol1LLCex2m7lbHfC64bkktOFFqOXpB3X3I2lfiZWf08brJmdRs31ksmw1nlmP7QBFsz1ghtF7EVYwK3pXa4OZTh7a5hpv9XMfZrUADT+VojRVEo2ot13JfRko3NEJbX7q+c3GNW5YgcrjcIjNkiB2nspPkej6XbVnsAMNCyMY13P1qDsK5CgEXnxqsE7kY7wP6ub7BLthVoJp+Ep2yTXctKELuGZWYQQP0omOaSOe+yw/kkl2sbCS7GMIkHuxh+JBG3n/4qpXXkxFG6l0PUUsfxhs+neVR9kACoD43LfHTZoPfbXkBaPn2aBWUwy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wGM27H15jxzf4wP4qEAAEBnkDK0iBZRUyxxMxHqjt1CXlq 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