From patchwork Thu May 11 13:21:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 92592 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp4376974vqo; Thu, 11 May 2023 06:36:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7x9JfAA65YgGA0ojZ9A2KY5QYPOG1N3yDROpVkgXFZRC18lzmrknixnXn/1SY2Pyy3ktTC X-Received: by 2002:a17:902:e549:b0:1a6:bb04:a020 with SMTP id n9-20020a170902e54900b001a6bb04a020mr29325138plf.46.1683812177919; Thu, 11 May 2023 06:36:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683812177; cv=none; d=google.com; s=arc-20160816; b=P1GXai91NBkqhwhTRzlChQl92ri5so8yZm7uyYDAmG193O34xWG9FZTTHM7zoUie+P isplXZVyh882mi/tC3auCKEafq1+OS4gsYb1ma61+l+Jlz0KzLDlxMZAIFEu2qV7sciC wKP7DooQAj1WoehPnyACTPFAZOC/wByPG2zkkIG0uCFAbZBjfTQLgt+9mkqMt7HN0t2i B8SUYvdIlMG9xv/lg8BSVFA0i17PZS458Joxg1+H1Q+I//8B8Bqsrx2rm88EN8RQS5vQ R4pmqkfsEtOI0I30wKkLP7gr1I9NvubnlFY6z5kluSRx2uhPy+eeWPkjUqYHXTf+Eh5N 00sA== 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; bh=/52sUb9+9WPQZmxdyTfX0GVTpGvmb9ShLbs41ARbI6k=; b=J4SI2+Fk8PzQJPlNQIO8wBJhdonnklBCNTU+WVNJIsoyJoJ8oEUFVxrkraGI3xx+h7 pGNfaFTMG2LJ0PRHdW8ZHuM1nawsT+/WH7V2dkQr1NpPH36ocoCMz4XT3PUCejKrx1rP QsgBS4TmyVeFcc3/UqQoG2B+aKLnyMqnBXlYwDXi1OS2c8/TR449VhMzxksWEB4EpVfx KeghTX+n+T6PrZXLHg9qsEbXiQJ9u1EE/DJY7Xxruv8CEKmciPlatMOQ0q8OV5zVh67f zi5dbT90HeiJFEvPRDiWQiBnwLrGB2aho4RAXZ+o8As25czEm7snUjt+iK1rz5tQrbA2 W0zw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mw14-20020a17090b4d0e00b002467eaf62e0si20263944pjb.178.2023.05.11.06.36.05; Thu, 11 May 2023 06:36:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238308AbjEKNXu (ORCPT + 99 others); Thu, 11 May 2023 09:23:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238165AbjEKNXU (ORCPT ); Thu, 11 May 2023 09:23:20 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4BE2C11547 for ; Thu, 11 May 2023 06:21:42 -0700 (PDT) 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 AB6621688; Thu, 11 May 2023 06:22:12 -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 10AA33F5A1; Thu, 11 May 2023 06:21:26 -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: [RESEND PATCH v1 4/5] mm: Add new ptep_deref() helper to fully encapsulate pte_t Date: Thu, 11 May 2023 14:21:12 +0100 Message-Id: <20230511132113.80196-5-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230511132113.80196-1-ryan.roberts@arm.com> References: <20230511132113.80196-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765605038133757426?= X-GMAIL-MSGID: =?utf-8?q?1765605038133757426?= 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(+) -- 2.25.1 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,