From patchwork Thu May 11 12:58:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13237873 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 A4A7FC7EE22 for ; Thu, 11 May 2023 12:59:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C38B96B0081; Thu, 11 May 2023 08:59:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B99436B0082; Thu, 11 May 2023 08:59:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A3AC56B0083; Thu, 11 May 2023 08:59:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 965636B0081 for ; Thu, 11 May 2023 08:59:15 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 5C2DA160A3A for ; Thu, 11 May 2023 12:59:15 +0000 (UTC) X-FDA: 80777979870.10.F001B61 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf09.hostedemail.com (Postfix) with ESMTP id 97D0114000E for ; Thu, 11 May 2023 12:59:13 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1683809953; 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; bh=/52sUb9+9WPQZmxdyTfX0GVTpGvmb9ShLbs41ARbI6k=; b=PtAbgDHPbCzJx4EC6NaEwR8oMr3ThJV6FF3OfEfmklkkL7ENo76CfkyBoMCNt6wyFVUjHI W09L23TSrqpoBOXZSPYo+0/w84tgNw789bybXbvdI4zuRaSWWOuq/SQ5AyA9BURs1CPgBm sywjcyR5wv37zyGPI6IiebLadCWWXks= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1683809953; a=rsa-sha256; cv=none; b=HHKVxhpBUpkQkTYTEx9YlFf533hf6OL09HznZjHZUlibnDw8EHEzDrETWB85p4xfOLN3q1 sDhUiuycPzlUtmGV+xijtCANhLynRILpqPm8S/rH8MxYJ3/rDIO5JNRoDkue1scI1GHDjp McWae2BHWq6oG55HQ95+a+vH44l+Lag= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5AE531688; Thu, 11 May 2023 05:59:57 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B46B23F5A1; Thu, 11 May 2023 05:59:11 -0700 (PDT) From: Ryan Roberts To: Andrew Morton , "Matthew Wilcox (Oracle)" , "Kirill A. Shutemov" , SeongJae Park Cc: Ryan Roberts , linux-kernel@vger.kernel.org, linux-mm@kvack.org, damon@lists.linux.dev Subject: [PATCH v1 4/5] mm: Add new ptep_deref() helper to fully encapsulate pte_t Date: Thu, 11 May 2023 13:58:47 +0100 Message-Id: <20230511125848.78621-5-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230511125848.78621-1-ryan.roberts@arm.com> References: <20230511125848.78621-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 97D0114000E X-Stat-Signature: 1frktawu4i6ti9dhgkr8hmfqorsx4gi1 X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1683809953-360899 X-HE-Meta: U2FsdGVkX18sCGP4UIXXMuhasAqINeHUQZQS/m1CBgnivBkSraXtkfUwvYO30tLFXjoXFdvouv6LjrCSg7HabbMissE0Dl5Ngsw45VE8SRxZI8pwbxOfTiDYbVzEa7Ptz4IoLw1AWWqX0T4rrAX+FnfBg4axsmJwRrGSFbtoiWSi5+cdgOAbLfA6H14mptjf5pr3dTbL+Wuxm0bfCS08SWmXrb275eqm9U403t/yEMUnMnUeVUWTjKUbmwRiAqs3IkRwAQFzQZ1WtLcK6eJZ34gadIqBxQMEOV9mo1C+T6qDS3ahCIq4BdlQAOeC0xnS32GAFpf1IHVpS4cJ4uL6IpA8tnJ6FaOMbJF5Us+Up3fYFgzrNVvpohrpuLf5xoMjEYADBiSNBXmmWDIXjws3aRLDQEaApM/d75T/5trGqcO28ntbkv87DK3OfL87jDECdqxGVrkOzzBavG2iJVDnDv0fFFTqGd/otkHUXqwYmR8efONLH3RRcVYaW3Au0pOZ1My90+E3t+TVEwTf2uO11eXg+a0zWgtZU4l9CwRl1wXw7v5Y/qcPn4KW/1XcbzJsgzCXktgEpQ39xaeF5hnXzDozNSZqjxV/Rc3sZrrnDcxHtx+5BOaH3VZukpzLQ1Ice+qVakV0NE4SF0HSBM3DxL7GNiQI8ASghKKMbj3UcKS6cB3NuuO1udMcuf02Q21FMj5yyuZRK4np41fP3tMRcuTqoH83v4r3aLKCqxONYfRmvvay1OsLKsTQrxhUDtS3ks64xcce8RH57daDVc++3yyyg7KTZ9N1wdc2pIMnqaCEhn5Etcx0rQxvw9dD3AeMBFkqk/9UTM+LAqjJzMByKm/dn/rIPpiX5eJ4IqWYU0NAP1ZchMPPSW3/CiClvwh6oCn+9zkbQ/y79nlqr3kbpa+0KDXUbbuZlZIxiQqcc4POW6GtH76eluqe0TyNysw7GU0KTusuZHpKdpfX50s xrWTPBjA /uuMxrhmzGP0ZCEtduh2sJmCAuCHoT+gOF9qwWANOCeWRfDF/CsOyuMgcKQbYyYxfl85z6vkVIJjqaheMlfc6Va19XnOybf7GyuFF17eE4/4ErfXCKr0OoyuXlolPrZiueaRikr+7Mlyz/1N0SEgOyhN6vuwPQizbLLXXcDoVwGDooUKmZIS9u71j2eAvAIJffTJNr7Ql97W+5Mw= 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: There are many call sites that directly dereference a pte_t pointer. This makes it very difficult to properly encapsulate a page table in the arch code without having to allocate shadow page tables. ptep_deref() aims to solve this by replacing all direct dereferences with a call to this function. The default implementation continues to just dereference the pointer (*ptep), so generated code should be exactly the same. However, it is possible for the architecture to override the default with their own implementation, that can (e.g.) hide certain bits from the core code, or determine young/dirty status by mixing in state from another source. While ptep_get() and ptep_get_lockless() already exist, these are implemented as atomic accesses (e.g. READ_ONCE() in the default case). So rather than using ptep_get() and risking performance regressions, introduce an new variant. Call sites will be converted to use the accessor in future commits. Signed-off-by: Ryan Roberts --- include/linux/pgtable.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index c5a51481bbb9..1161beab2492 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -204,6 +204,13 @@ static inline int pudp_set_access_flags(struct vm_area_struct *vma, #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ #endif +#ifndef ptep_deref +static inline pte_t ptep_deref(pte_t *ptep) +{ + return *(pte_t *)ptep; +} +#endif + #ifndef __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG static inline int ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long address,