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 B2553C021A4 for ; Mon, 24 Feb 2025 12:26:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2ED376B007B; Mon, 24 Feb 2025 07:26:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 29D4E6B0083; Mon, 24 Feb 2025 07:26:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 165896B0085; Mon, 24 Feb 2025 07:26:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E1F886B007B for ; Mon, 24 Feb 2025 07:26:29 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 8D09E1A1348 for ; Mon, 24 Feb 2025 12:26:29 +0000 (UTC) X-FDA: 83154761298.04.D297B98 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf18.hostedemail.com (Postfix) with ESMTP id 7F94D1C0012 for ; Mon, 24 Feb 2025 12:26:27 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf18.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=1740399987; 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=KtNByZl9qAP9GjlXryzLItO1F76DSdCbtTtd89ojuxM=; b=fqC1oy/zRRaqpjWQreaHYxS1qEB7Ucm7hz5R9OVa5DXkc1ht4PACkXfs7JmPL8g9Xw8cXD rIdGUUoq4DCveR/3QV1YNjBX9RwNXqLL45hSld0TIJKv7SeAw0ZRHhOYEPCvp9qhKE0veP V0wqbWTdQk0HANWkR/MWQI+p8MS5aOk= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf18.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=1740399987; a=rsa-sha256; cv=none; b=sDghFu76Cm866UM2pbblGEzFwde8YN0DbLE5lFymMx1UcGEgF/NQ8pP7jhmSRKTRqZ7gfo rn2CC/Avh5ajeo1QaM0z+qMTikWmyzAlNFZHjIeN9g/74Ei4iaidloWK8kmWQKNGKUu6Wc bnT+k2jJn4kpFWSwzigNHVN6lqDQaWU= 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 61DC01756; Mon, 24 Feb 2025 04:26:43 -0800 (PST) Received: from [10.1.27.150] (XHFQ2J9959.cambridge.arm.com [10.1.27.150]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 842BD3F6A8; Mon, 24 Feb 2025 04:26:24 -0800 (PST) Message-ID: <90195b91-e9b3-41aa-bb39-45f6a49b171b@arm.com> Date: Mon, 24 Feb 2025 12:26:23 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 07/14] arm64/mm: Avoid barriers for invalid or userspace mappings Content-Language: en-GB To: Kevin Brodsky , Catalin Marinas , Will Deacon , Pasha Tatashin , Andrew Morton , Uladzislau Rezki , Christoph Hellwig , David Hildenbrand , "Matthew Wilcox (Oracle)" , Mark Rutland , Anshuman Khandual , Alexandre Ghiti Cc: linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20250217140809.1702789-1-ryan.roberts@arm.com> <20250217140809.1702789-8-ryan.roberts@arm.com> From: Ryan Roberts In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspam-User: X-Stat-Signature: d5o4rmmcf5txb6sywn53hgstneeaokba X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 7F94D1C0012 X-HE-Tag: 1740399987-697689 X-HE-Meta: U2FsdGVkX1/8RNm/pAaSz9A7Vmb1HttHcHq2EUM6kIVFV0zMCoXKAQ+7DrCW87KTg6HyMn11Rg84NG20onkHXbxjg8Sqip7IASp04vF/ZY776vebgPfuR6wLng5kHtZhqlDHSfeJN/SGugv18dHqG9wHS3h5zFWX4ZOg7ZvBBJJT8gIQVnTVR8z6b6wyBwN7FSsG2dKrB7Gq901DH5FGWZhKTkv2SMm1pc/H2PnsydbaOZHoGsC/HsmmUGnfcfjhipihG9x+yxv1Prc02auqGCPN5NjVZhy7JMHDbR50pXctU3UmBbWrDVSG2y4gHMoES49GU481NvQ9dCuTO78NSFV5ff/5P1hyLrMmsDEtbIUpE5mT9ozg4xCKaqGEkz7pnAbzF0YRMS2HDFzKWn9h+m7tUSi6ZSaqiR5URgEMDLIAuPkMtcuUSs8+1ZkRZESiv5Q+3LY+vNP85DSQddeiXRYcJo9ADEcemst2tLErTn67L1oLGxZ9EQH+N9RZmc9UPegRvrJX26YyhqV7v74GBefFkxxbmmHTsr5kj+f8Fo3P9pEJ9pHtr5GzBWnwuL0jgSYAmA0KHx2iLWUiQqxomLtmbqZ4ozJV3nc5Q/SIu3E28qdCoGQVA9RDvYQPOIwCZd+HuzjOPmzppNhz0nQj0QupM6YuPnHIYOH+jNv1bewbYli+tdR0Jcyw+kZoAvBSKHGkJxCqVjtHUMl4vAYFoxafygf4AS+H5kj7vUbzCVGrB5qpzhNdxtdvhK3lc/kKcinOLGYjsxV60ErBshvwBfdtErKZfnaG0zFzKMTCxH5RQEdxlGhqvAkXTydG6vJXToVvtjLxB25qELPmJdJGGNEEv/LsdhlZHo7ZXT0KQaNE3tvEZur1Rc8e8r6/9Jy3AmJ3ZHs1Y7Bc6nPusxvye2aoz6DqfXckLG2dI97iygWRZ7MMlbnLQ8OC2F6ZflNnuzgX+a7zqzJ3CstyfOU 0PDCHBM+ XmIejyrT13g54JXCyknEo93B37xfTaqmFvNDg7aJcPNvxeAZV2iYg6eho5I+gtrUD1az8mXfIgRdHdR0A+2wAYLL6PQq7rNfFqf6rNPEOSuwiR3q86DyWC21M+BZoACZnP1to7fHt405tgT2dbn7xGZSVmQ== 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 20/02/2025 16:54, Kevin Brodsky wrote: > On 17/02/2025 15:07, Ryan Roberts wrote: >> __set_pte_complete(), set_pmd(), set_pud(), set_p4d() and set_pgd() are > > Nit: it would be more accurate to say __set_pte() instead of > __set_pte_complete(), as it is the former that actually writes the PTE > (and then issues barriers). Yeah, fair enough. Will fix in the next version. > >> used to write entries into pgtables. And they issue barriers (currently >> dsb and isb) to ensure that the written values are observed by the table >> walker prior to any program-order-future memory access to the mapped >> location. >> >> Over the years some of these functions have received optimizations: In >> particular, commit 7f0b1bf04511 ("arm64: Fix barriers used for page >> table modifications") made it so that the barriers were only emitted for >> valid-kernel mappings for set_pte() (now __set_pte_complete()). And >> commit 0795edaf3f1f ("arm64: pgtable: Implement p[mu]d_valid() and check >> in set_p[mu]d()") made it so that set_pmd()/set_pud() only emitted the >> barriers for valid mappings. set_p4d()/set_pgd() continue to emit the >> barriers unconditionally. >> >> This is all very confusing to the casual observer; surely the rules >> should be invariant to the level? Let's change this so that every level >> consistently emits the barriers only when setting valid, non-user >> entries (both table and leaf). >> >> It seems obvious that if it is ok to elide barriers all but valid kernel >> mappings at pte level, it must also be ok to do this for leaf entries at >> other levels: If setting an entry to invalid, a tlb maintenance >> operation must surely follow to synchronise the TLB and this contains >> the required barriers. If setting a valid user mapping, the previous >> mapping must have been invalid and there must have been a TLB >> maintenance operation (complete with barriers) to honour >> break-before-make. So the worst that can happen is we take an extra >> fault (which will imply the DSB + ISB) and conclude that there is >> nothing to do. These are the arguments for doing this optimization at >> pte level and they also apply to leaf mappings at other levels. >> >> For table entries, the same arguments hold: If unsetting a table entry, >> a TLB is required and this will emit the required barriers. If setting a > > s/TLB/TLB maintenance/ > >> table entry, the previous value must have been invalid and the table >> walker must already be able to observe that. Additionally the contents >> of the pgtable being pointed to in the newly set entry must be visible >> before the entry is written and this is enforced via smp_wmb() (dmb) in >> the pgtable allocation functions and in __split_huge_pmd_locked(). But >> this last part could never have been enforced by the barriers in >> set_pXd() because they occur after updating the entry. So ultimately, >> the wost that can happen by eliding these barriers for user table > > s/wost/worst/ > > - Kevin > >> entries is an extra fault. >> >> [...] >