From patchwork Thu May 18 11:07:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13246486 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 6D760C7EE24 for ; Thu, 18 May 2023 11:07:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0A945900009; Thu, 18 May 2023 07:07:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 05A0A900003; Thu, 18 May 2023 07:07:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E13D6900009; Thu, 18 May 2023 07:07:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id D4267900003 for ; Thu, 18 May 2023 07:07:47 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 9BFC38024F for ; Thu, 18 May 2023 11:07:47 +0000 (UTC) X-FDA: 80803100574.29.21475F8 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf15.hostedemail.com (Postfix) with ESMTP id E86F9A0011 for ; Thu, 18 May 2023 11:07:45 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; spf=pass (imf15.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684408066; a=rsa-sha256; cv=none; b=ZzOWi3Cz7NTl+lCg7x+E+R2MeCNR9UECOUk4HAav6FHzyYZv4UbI8Mu7XZEfIls81hv07c yDVd4KqU/bFpPURp/bv3+w2ahNfTxbyDECa6hI2NG2YpVybZUtfvuik9tcK/Ggs1zIHJ2m m22WBzYnlrmCmRxA5KxVHT8b2cyqeVQ= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; spf=pass (imf15.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=1684408066; 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=GN7c8kEEsV7jATC2Jm7ArlDjEY3G84kw8AsOXLh8zKq5cEnkFnwNG/v9UReWTH0yPGSGRE tVoftHxg08WQVqOEdHUeuvVc7xZrveDZlN8wajTScasHcNcqGnsG/Hb8oZvlrVOOWmMjxx j5zhQnRdcbqXQKKQZ6L9lGrYQFlK5E0= 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 311D91595; Thu, 18 May 2023 04:08:30 -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 CB3943F793; Thu, 18 May 2023 04:07:43 -0700 (PDT) From: Ryan Roberts To: Andrew Morton , SeongJae Park , Christoph Hellwig Cc: Ryan Roberts , "Matthew Wilcox (Oracle)" , "Kirill A. Shutemov" , Lorenzo Stoakes , Uladzislau Rezki , Zi Yan , linux-kernel@vger.kernel.org, linux-mm@kvack.org, damon@lists.linux.dev Subject: [PATCH v2 4/5] mm: Add new ptep_deref() helper to fully encapsulate pte_t Date: Thu, 18 May 2023 12:07:26 +0100 Message-Id: <20230518110727.2106156-5-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230518110727.2106156-1-ryan.roberts@arm.com> References: <20230518110727.2106156-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: tdqprxq1jfd6qe5bgo9x49xtmbddf4z3 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: E86F9A0011 X-HE-Tag: 1684408065-739638 X-HE-Meta: U2FsdGVkX1/sliovpd2QetLyotc22NS3nSASjvaS7Oy8hOaPX5cbOofG6Gq2VmOlll8y/M+iSrXdhsIvLOq2IH4D0qeqy+VLuec8+sBCHxCmH6Gx3KwIyczRKqxSehrgPSQb/xsgc49scugs+i265KI00ez3JZX8jh0BN97j5p2KZ2uJvsz0DYuFQeuN9YWAx9pPI3xjC8h/ePlT3ZxEAR81BVDkq+uaiRUK0zuiULrmXjHQAcIcBrGZQVR5UJtOQM/m1HulPgH9ZilKvyns3IPwIO6LbRsyltOObJq7TUb7XjpxduAMFPWLHWFdZz9kH7V4ZG6pWhrU1/m8qvjiKRKpg40c0LFkHUJpdg8CElMoByA6IE7dic1h9MRSfr5wLAiIA1wW7pw+Lf1Twvclk85+EUzrva10T5PwrC8NCiGrWhND5GZrKaXeZhvt+qltJNvloIYrDq87jW0hwIwgqkl+YTXSWOtM5kxFaFyMZPMCfBO5gSjM4LG4ZcJ0T5ChgNyKRuE3JWP9K/UcIMExm2MKu1relC5SFYj4i58sC5yTsqIdvOyxA70hiCT6ECmkDRoGHLGvQo6PiyT/nfroRyttvrljmR9VANuXKSYpYl8kIBkiyghzSR/2Rh0I0UuhuEAZ2wFrOtTD3ccRQcaWBP4PVIUwVpiYmgeeu4NbPpfsudgwWExKTAEQ2xdz8HrnrwXG4pNMSp7oZpVrMtEGc8boujAOlYtVAR9ns9IzEY8dWC5RpJbNRnrCp/QbgrWErCAdGIoF06OBHwS+HOQRMvsAw7NdnZT5tZgNvHY4WwpRkCux+cy1qp/wswverJ/kMoRRxj3hkSQ7OwfJFt+ulSq4tnqNpzCjKSS0wu/YOiyq82E2YB/8cWDsFGv9OP5/KoKROGCGm8L9FMgHYevIBFv71CM3qfN+PvbpnA/lYPt6Ld1dgvIZJft6yZBJGqEnPYydYYYGPtzSY1PqF1b bbrxI4/q XAgKlVtBT5gb+8xqDCsFBdgeB6W02xee1FQziXxpMcJKuP+GnAr9IRtkXUec0Ar73o47LQtPm/NYY7lxPxz8Jseogni6pS8vQfmSJdNaXmvALssirByVGOdkvF2Mlb7DoKLZKWAKn+n5GeaIaGhPIXVCjTXLJNBDSHTZ0EGo2ZkfCNz49c7qKqEUmQYbdrbnaTnRSgMGiMdf59DQ= 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,