From mboxrd@z Thu Jan 1 00:00:00 1970 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 6EE6AC77B73 for ; Wed, 24 May 2023 19:11:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DAF4A6B007B; Wed, 24 May 2023 15:11:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D5DEE900003; Wed, 24 May 2023 15:11:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C4D34900002; Wed, 24 May 2023 15:11:45 -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 B7E436B007B for ; Wed, 24 May 2023 15:11:45 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8C231C0C62 for ; Wed, 24 May 2023 19:11:45 +0000 (UTC) X-FDA: 80826092970.19.CB02B96 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf11.hostedemail.com (Postfix) with ESMTP id 7574D40005 for ; Wed, 24 May 2023 19:11:43 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf11.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684955503; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MW19HOC7A2F54hQk6U06jOt8a+EpvvmJRg4eHzFwppE=; b=7QGaj9dPt2E7o9b+kUz8l2u/YTjgawoB+vHSlGe5HALMOku89Uxdnu4pTG1XMaFiUCsq8C pWePuMfx2o/O8T8gv8o/8623v3J5VYlytRPm2gJXQf7bFZBpwAUWHNmpBYvmRzc5m3hMVJ /ojUEgudEYKLjJXz7AZxBml1vqjjTJY= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf11.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684955503; a=rsa-sha256; cv=none; b=VJBX7+7RHZnk/rczR59U3Q3pGBDlIMDD7C8jNAqIcs+CbqswSIx2XMoyJ9PMcVdHxXW4Yw sRew/U7GO9EUtZWv9Euh+6agExPAJ/bVX/u+gf5WkQbwQ2dqDJkJHJQzNlOFNW3Edj7giK OLMtm/W2eQXwEy6iXenGncSN5tckK80= 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 60FBF1042; Wed, 24 May 2023 12:12:27 -0700 (PDT) Received: from [10.57.74.16] (unknown [10.57.74.16]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 517853F762; Wed, 24 May 2023 12:11:40 -0700 (PDT) Message-ID: Date: Wed, 24 May 2023 20:11:38 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH v2 4/5] mm: Add new ptep_deref() helper to fully encapsulate pte_t To: Mike Rapoport Cc: Andrew Morton , SeongJae Park , Christoph Hellwig , "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 References: <20230518110727.2106156-1-ryan.roberts@arm.com> <20230518110727.2106156-5-ryan.roberts@arm.com> <20230524190618.GR4967@kernel.org> From: Ryan Roberts In-Reply-To: <20230524190618.GR4967@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 7574D40005 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: rnmiy91sw3tfjx9urdfjnsak8ur1hu5b X-HE-Tag: 1684955503-930040 X-HE-Meta: U2FsdGVkX18PMca6A7TWR4TR35lxsfi1EbldyxKgbdQ6Sa1WhVYKXifLpuX2O3tVv25vDRUaC4L9+JFaaKa/Y7SKrkE33GtTro7sLVTr+lpyg4KFOQrJbIBiTOT7makSr0SiCvdjJiUcN9X98bXxh6ryXRlDJ90ZnZcSR63c3gzkjfUQoq588myle96wgSwnxhm0Lu8adyiWyj6eYENdU7lK4inp1hc/4dImS6r0LWnIuG6/HwwoP/hDiOuYeFx8IJjH5KdrN5Aemz2CF7AIeFOmO4DVcCo7F2qv6ZR7tb7Iv+Uy/OYshYn417xZL5yibRZYviiVScdwSHcu3LAIC+kFRF43h4p8micBJbnk/dzKmZdyaxKuktmJgdh7X5phK6eq6csh/L02Dsn8WvK4Q4BHOHfCasr3llbK4sbtKl/nowUitoi28W0dkSFoyx9feqhaGms6DjMrfk7Wkk0EO1Qt14rfMjak9/TgcaMSCR4C3spcT6alPtvMLX4/frLesNglJP3+/3wadVcoaav7NruQGoZ1zW6mnJpfTtR/rMMEcEhLpjJrrw65zxgJ5Ped1mQo/pA9I/Z2kRSWcK3WbXXXHq19T84NyaRUJFq7KgtqivtUqK6cKSkZnKmabkv5CPEboMpE3+HErqysXsRNVSP/T0deSI+mRes3qGxJ5sOeMEHZ0FtRmyj3T2iLENtS1QQAqTm5An22XS0KefNbmXL6LDS7o5+QKL8x/iIYwpQOGQRhGFoh/GopbeJhEficsiBRQIlgeKaPbFT6/u2bRFRS08Q72x6EtwtOHGOba/pkCUlyXvgLMjwa5j/ZDhSo/uu5cINWtqhfVi7SxS01HbvfnbHW1WH9pqAvsUQPg4mQY5tqsO+VlFWT8CoG/j+nME5NY2dHROiZb1a1W7BFliH3Mg3MNVZSztp6SkpV1HjHgHwnKzYrWgejDIkoRwH3jNottrumq7Modj0NEjN Hdc1IMMc lsan4Pa5bSFWSJGoCRIS7lcOI6FLqewBDTIwDQEjhGHg59nZ++o8T00CmZ5nh5RCouauA7fWA7pzJyp8U3aT+mv+ZUqrXvhS0oRtsyXsRLscO9j27R7FbCRoze94B/M3CaEJO30yBBJ3gjLOvkS73l9ZUs9ywUB6VMfK6oDIAO9rkwpdP0MadpFw5Z4gWFUxI1M4zzRA4FfJ3d2M0muMW4ZWx4w== 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: On 24/05/2023 20:06, Mike Rapoport wrote: > On Thu, May 18, 2023 at 12:07:26PM +0100, Ryan Roberts wrote: >> 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; > > Why do you need the casting here? I don't - good spot. Will fix for v3. This is some residue from one of the approaches I took to finding all the call sites, where I globally did s/pte_t */pte_handle_t/ and typedef'ed pte_handle_t as a void*. Then the compiler would error on any attempted dereferences, but I had to explicitly cast in the places that could legitimately dereference. Thanks for the reviews. > >> +} >> +#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, >> -- >> 2.25.1 >> >> >