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 1485AC54E49 for ; Mon, 26 Feb 2024 12:37:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A20BF440150; Mon, 26 Feb 2024 07:37:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9D07D440147; Mon, 26 Feb 2024 07:37:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 89854440150; Mon, 26 Feb 2024 07:37:36 -0500 (EST) 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 76D29440147 for ; Mon, 26 Feb 2024 07:37:36 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 239A28085C for ; Mon, 26 Feb 2024 12:37:36 +0000 (UTC) X-FDA: 81833906112.13.E51684D Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf16.hostedemail.com (Postfix) with ESMTP id 57709180013 for ; Mon, 26 Feb 2024 12:37:33 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; spf=pass (imf16.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=1708951053; 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=ytWgS3EtBTT6JM0Rrexj/EmASbnILdrV/ENZhT+bkMw=; b=RzHLdZ17XJr5ICIr064gat+PjqaLhobBntZLrpejutiS123knFpyoEuPAiLdV3g5i+LJFf ijaK7HSeyyD5Tm5D7ee9uukQLwd5dHpJMwBto7s2Dg2AKpPDz9QkdM5ZjyPnGEenaRZpfv hPZcpcZc4/qzEQQ+9FyNN4xVDNzBBcM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708951053; a=rsa-sha256; cv=none; b=lKw0TWgQlNJMvmOEguOZSgpx9/vyQwLpE9PyNIlhWRPzrQ5L7W9ch99mi27Fqjr+dOU852 2PFjP/xQswbeqiDGlj0DxidUKZnoYr07Cruv8DwzYIZuItGdFUFS1vm5jKjrj7TuRfMvwZ 9hcLYPAvrERtfedLymcVWX28PPbZEf0= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; spf=pass (imf16.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 00E4CDA7; Mon, 26 Feb 2024 04:38:11 -0800 (PST) Received: from [10.57.67.4] (unknown [10.57.67.4]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 072C53F73F; Mon, 26 Feb 2024 04:37:30 -0800 (PST) Message-ID: <8cda557a-cbf0-4926-be19-454cefdb4fdb@arm.com> Date: Mon, 26 Feb 2024 12:37:29 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/2] arm64/mm: Improve comment in contpte_ptep_get_lockless() Content-Language: en-GB To: David Hildenbrand , Andrew Morton , Catalin Marinas , Mark Rutland , John Hubbard Cc: linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org References: <20240226120321.1055731-1-ryan.roberts@arm.com> <20240226120321.1055731-3-ryan.roberts@arm.com> <4f215e3f-3395-4fab-b938-07a6d9e0a662@redhat.com> From: Ryan Roberts In-Reply-To: <4f215e3f-3395-4fab-b938-07a6d9e0a662@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 57709180013 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: uahaqyiw9ucemwn3jeiarhutpq9xmmur X-HE-Tag: 1708951053-323908 X-HE-Meta: U2FsdGVkX1/OS2FrZpjLCiYVLJcuHmuT1/c+3Q+NLwNXtV0eWDR2nmlJUGXlflgsNCneHw9BiINc8mNxibAFIYdWon4gIRu2H32KJxwDt0OpjGTxohTcaoLVVq01boOcReodVA1DsXvYzjAlMqEfnispHfJ5z/7wE0Ww3vVYCKUPilaMVKSPu8m5C3HqRjHulT2Mtc5WNqcPCRhLcy4qcK7XLjp/iF0yEG5u9owiPclvOHw8R5xm+eM6HkBp+Rl9mKOmG6RDlXFIRfFwDCDDjfdC/q5xrKx+Su0LMsQECLQSfATvGWU2f82262Hw8KDNfM0QCvL5NIeRgtsHllWaKca0tmcdI3f4zYRsLikGbOz3MpDLjnQA3m4IO8AWDQUZw9xtKW0MW57xI7TjRjO/3o67aBCfcBz5Jz2CVvfF7vMQZBBrnBer6CTH7WIrriJPEaGyOV/70YTItdHWq9pTHPwueOgrj/U4cadCS8MYm6LXoEGbQY0ONdFF9mmmJCtqsysClhu7iAG/tB5UzEcQRn6TXpGMqv6Zy0TNqssMbuRm0hlgMpvETxbOYO4raN+XQZP5R02RixH4TZqQMO1UJ8r3tZmmEuhmUxfTiYfau8LBCbHuum3+IPdsuhJffkTCp0M1G870q3AhCoocjtlW47EFZfPsfh9UUAS0WQyMWxR2Hp/heyLlR4rDBMuWuTVBmWwq6GxZPxjLVJeT7bj3g/U+Yz3QPCDjJIclvglkSRjsT03f69JIjVreKVPw73QJfIJP1jSYyBh6NQhti//WwT3ii1jNPk2jRLZfWwwYLeo6aHdyqwyOeh5WVrvgwNVLx+73zEsVf0CcMVEK6bKKcJ7GVvY/XcRc/sPZ7WCuZIeC/BodcDvByOXSaXXHlYNvT4klEda1oG3G4U4BQ9m35dDGupNNRS4FM89ow6rXSz9LK9HnxCZRdeEntyDjbk2Zx3mL8X6j+ccNZoPZw29 jtdYdDK1 lK1psNpHBrjUKSeCRA86N2jvlMhNIsTMgSZuhHKS1B/Xt0xqwI/uj7p1D+xqMKEG9Dtzc1d4EjcjUbian0llbM17Z/tP2WN9d3R+EIjHkNeskP92rTx4zbt81oK64ADorHH8m3b6y2Rhs+9r2rrLE+H1lXx0WbFtEsOw8SDeS6KjIbRwFYx7zNMzBbhLepr5EnbzGczrB1etpgS3XJx/QSWjV/2vB7NrYCFoGKuBAw8qNIOLYr+J+ZhFqwZsx50HAoNQ15xMNlpgAC13+MtikNj2E2lvF95/l2WoVqDA7nhyVHOi5km+ENyoLEoZc0b/swSfHRcBxjQT9UJZQlaawLj6+h0e7JYHVkGEgEIzdZPuft1s= 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: List-Subscribe: List-Unsubscribe: On 26/02/2024 12:30, David Hildenbrand wrote: > On 26.02.24 13:03, Ryan Roberts wrote: >> Make clear the atmicity/consistency requirements of the API and how we >> achieve them. >> >> Link: https://lore.kernel.org/linux-mm/Zc-Tqqfksho3BHmU@arm.com/ >> Signed-off-by: Ryan Roberts >> --- >>   arch/arm64/mm/contpte.c | 24 ++++++++++++++---------- >>   1 file changed, 14 insertions(+), 10 deletions(-) >> >> diff --git a/arch/arm64/mm/contpte.c b/arch/arm64/mm/contpte.c >> index be0a226c4ff9..1b64b4c3f8bf 100644 >> --- a/arch/arm64/mm/contpte.c >> +++ b/arch/arm64/mm/contpte.c >> @@ -183,16 +183,20 @@ EXPORT_SYMBOL_GPL(contpte_ptep_get); >>   pte_t contpte_ptep_get_lockless(pte_t *orig_ptep) >>   { >>       /* >> -     * Gather access/dirty bits, which may be populated in any of the ptes >> -     * of the contig range. We may not be holding the PTL, so any contiguous >> -     * range may be unfolded/modified/refolded under our feet. Therefore we >> -     * ensure we read a _consistent_ contpte range by checking that all ptes >> -     * in the range are valid and have CONT_PTE set, that all pfns are >> -     * contiguous and that all pgprots are the same (ignoring access/dirty). >> -     * If we find a pte that is not consistent, then we must be racing with >> -     * an update so start again. If the target pte does not have CONT_PTE >> -     * set then that is considered consistent on its own because it is not >> -     * part of a contpte range. >> +     * The ptep_get_lockless() API requires us to read and return *orig_ptep >> +     * so that it is self-consistent, without the PTL held, so we may be >> +     * racing with other threads modifying the pte. Usually a READ_ONCE() >> +     * would suffice, but for the contpte case, we also need to gather the >> +     * access and dirty bits from across all ptes in the contiguous block, >> +     * and we can't read all of those neighbouring ptes atomically, so any >> +     * contiguous range may be unfolded/modified/refolded under our feet. >> +     * Therefore we ensure we read a _consistent_ contpte range by checking >> +     * that all ptes in the range are valid and have CONT_PTE set, that all >> +     * pfns are contiguous and that all pgprots are the same (ignoring >> +     * access/dirty). If we find a pte that is not consistent, then we must >> +     * be racing with an update so start again. If the target pte does not >> +     * have CONT_PTE set then that is considered consistent on its own >> +     * because it is not part of a contpte range. >>        */ >>         pgprot_t orig_prot; > > Reviewed-by: David Hildenbrand Thanks! > > In an ideal world, we'd really not rely on any accessed/dirty on the lockless > path and remove contpte_ptep_get_lockless() completely :) Not sure if you saw my RFC to do exactly that? (well, it doesn't actually remove [contpte_]ptep_get_lockless() but it does remove all the callers). If you have any feedback, we could get this moving... https://lore.kernel.org/linux-mm/20240215121756.2734131-1-ryan.roberts@arm.com/ Thanks, Ryan