From patchwork Mon Feb 26 12:03:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13572037 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 5075FC48BF6 for ; Mon, 26 Feb 2024 12:03:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5A55E440149; Mon, 26 Feb 2024 07:03:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 55802440147; Mon, 26 Feb 2024 07:03:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3A928440149; Mon, 26 Feb 2024 07:03:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 213C7440147 for ; Mon, 26 Feb 2024 07:03:37 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id EE51A80845 for ; Mon, 26 Feb 2024 12:03:36 +0000 (UTC) X-FDA: 81833820432.30.FA4E7EE Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf27.hostedemail.com (Postfix) with ESMTP id 20A3E4002C for ; Mon, 26 Feb 2024 12:03:34 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf27.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=1708949015; 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=OdjdwRQXLMVJTKYMYLLNlR+fATmBCiXp0EKc+ys3wm0=; b=rq6JV0hm1Fdq51H0ByGGs59dpENtfT/MNh+clihLTDt3v3lnegj1cbCGAFSZfUHKP1c/8Y vSB7UBTjdF/9LJO2V3hQo76j++WJCep8fZw/3eaLXWFc/8VzXgFtq4PBebff7EXlU2UYn+ G89WX6g25NQGJfuVN/RvHOYwWdD4DtU= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf27.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=1708949015; a=rsa-sha256; cv=none; b=tz044Zc5kGlz55u+lCQZBPByYijOQf142NzC7ZbGi9WIGYSY9VbnTSumQ5tMZHqqIfnmNu U+MnLIlNuuyeijSDUyFvC4bYA66dhAWs90Q4DUM/cPA/6RUxhI7yKcYqjhK1bLhZRYAo0x Ya8551deFtPvP+GdE+7OfGGvQ+Ot0Tw= 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 A7EFF1042; Mon, 26 Feb 2024 04:04:12 -0800 (PST) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.27]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 081DC3F7C5; Mon, 26 Feb 2024 04:03:32 -0800 (PST) From: Ryan Roberts To: Andrew Morton , Catalin Marinas , Mark Rutland , John Hubbard Cc: Ryan Roberts , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org Subject: [PATCH 2/2] arm64/mm: Improve comment in contpte_ptep_get_lockless() Date: Mon, 26 Feb 2024 12:03:21 +0000 Message-Id: <20240226120321.1055731-3-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240226120321.1055731-1-ryan.roberts@arm.com> References: <20240226120321.1055731-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: sp9isbqk57hhzx1yt3fsx3ox9gyqbsmx X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 20A3E4002C X-HE-Tag: 1708949014-968537 X-HE-Meta: U2FsdGVkX18gDMxQM/iuQGrxVvlAGdre9U1GqDUWquJZyUN+TOW3kWWc4q1e3vdcB02CIdW9XSyYC7AF1USHn3TGYyeHjAA15735h9jTylmqUmQfvQfbTJtitVZ4fosQnDF4rafzl40FycQ+nj8mENzQDApt7fYdR2Kdc1bPmEojZ60Ooe2Oa1uJ1XuBzsBG0KIsrb2fy3ioqCKV9CPbJ7jWm9hNYqP0vEDpw+t3ukxTcNzZR5poPhFdumZkgeWxQaPw74zhwnjKDuZxZU3SYWp8omRUI6OLytVYW0BUxe03w6QRosXHX2piUJ0KXLFBJYGixWLx/xs8084S/aWmnOH9B/oTEP7n5qdZ3KcEqVyGwG/R4f7OM/vhotOyjO4lj5EWD7fBH18smeFWx1rTLLKGYCpxqoxnqRgrNayKUwjgGN+WBAVl6H8j9EK5NXd+1Hf0/37jSQQAAgdPuwKH8P2IQhZAq/+tcD5q87l983r+09umGjvKcbjFg72q/GjHoeMRTxcE05Eg9yhDQVtu+dMProy1yZ7wKzwImiQcStPJj2FAuoK6qYbjwRC7g2c6CfGFxY/2tn0+OaeWYfHjg9R35hUi0rHWUEWdoTEhQCBZ6DJnfPD72E/2U8NpcHJyFFb5jbDxGSer+SzgsNE661ZDt59MuomG3oOaMSJbTvetpltYXBI+zRGXkGV2QWeMupB7S/ZvZ55AdQjwZt/m2D08zAHVNMemMlaogpluxtdxyWwQSr1bPsqULY1/pXlunZByuVXCdpSsf363x81mL8kOYUICsH9FMraraALv3HWja3FM6TQ9oW3hL0PTymWjgHL98w7k56m9Hvh2IhjG0M9oThxuJcyKdXugsiCI/5QSiPCIyCv0Sz9de2Gm6UqB/jLM/QhwGfw= 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: 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 Reviewed-by: David Hildenbrand Reviewed-by: Catalin Marinas --- 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;