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 76E68C282C5 for ; Mon, 3 Mar 2025 10:22:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 13C6C280007; Mon, 3 Mar 2025 05:22:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0EC45280004; Mon, 3 Mar 2025 05:22:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 002C1280007; Mon, 3 Mar 2025 05:22:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id D551F280004 for ; Mon, 3 Mar 2025 05:22:12 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 81FA41A05F7 for ; Mon, 3 Mar 2025 10:22:12 +0000 (UTC) X-FDA: 83179849704.09.4157638 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf01.hostedemail.com (Postfix) with ESMTP id BA7AB40007 for ; Mon, 3 Mar 2025 10:22:10 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf01.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=1740997330; 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=zx2ACXorL7pUvFqYSFbdW0p63+XczN01SUH9wlN7gm4=; b=QAQEcDDAQA/EqWKoVReJ5Nqh13uKhMhf01jmgIOXEuRmqi9Pnwk70rA91f/dpsqxx4ok+u CLTIGFbK2CE2N9H9JTIg+5ZhNNtBDD5fyGzI2XG5FlQhEbwyEmXj2tCuQZixZSpIOXaNLI +/a2FiHgueTyaJ652icxvBIuZ/F9eM4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1740997330; a=rsa-sha256; cv=none; b=ZqyvYiOWodBZrdhtM0hvE/Jj3VMIki/hbWreF3B1yNtpmGEHphGNlVc3CZXtEaoTbY6GXY eM25zhtiw6eq5hDR0RDt+kzUvO0Rvr97aklmxy/+0cEoVziR5obIu3U5nxY/ZJAI7NR5lu sGk2uv2haQ8PjNDapYQtsNrSTK0gW+M= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf01.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@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 F08EC12FC; Mon, 3 Mar 2025 02:22:23 -0800 (PST) Received: from [10.1.26.155] (XHFQ2J9959.cambridge.arm.com [10.1.26.155]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7EC963F66E; Mon, 3 Mar 2025 02:22:07 -0800 (PST) Message-ID: <1ff509c7-187b-4e43-b266-db8ada33b9a2@arm.com> Date: Mon, 3 Mar 2025 10:22:05 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 1/4] mm: Fix lazy mmu docs and usage Content-Language: en-GB To: David Hildenbrand , Andrew Morton , "David S. Miller" , Andreas Larsson , Juergen Gross , Boris Ostrovsky , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , "Matthew Wilcox (Oracle)" , Catalin Marinas Cc: linux-mm@kvack.org, sparclinux@vger.kernel.org, xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org References: <20250302145555.3236789-1-ryan.roberts@arm.com> <20250302145555.3236789-2-ryan.roberts@arm.com> <5418a661-dbd0-46e9-8ef7-b1c5a34acce3@redhat.com> From: Ryan Roberts In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam02 X-Stat-Signature: ss9i37zzj68iyfpymbaexy81ycjknqgh X-Rspamd-Queue-Id: BA7AB40007 X-Rspam-User: X-HE-Tag: 1740997330-171566 X-HE-Meta: U2FsdGVkX18kKlohhLTBS38BTEhNYZ335tOpa1gdYGN1JklfTYW95TIg8zoNQx2ypwFi20NWZbB/GkoUAPQYIi/uLukGrUmDox0J8xnxKan4nyOGts7cqMBwHox0bCLKKXt+MROMI3XScsGWRFhVzfVkRMbNfiNZSjn/MhaDeO18Zb9A/azAT8PDRoaB62Cce7+D5Wndc+9AH2xP3IES95uVq1cNJz2OjptHuXoXyOAXp4uONB8mkBD3dF8tt/YCs4r9/cz9ygxTnyGuRWO15OuFfRz3ebkPblhAKYyPJu8Jc2PN6gOugy4J4Qr5/+3KL07h+UIH0Dp6115jb+L6txB1j+/bufMMyCmFqv8b7UEWZLMB1ynjaJUrBDfZbtAykM8ESMzudCuvoq56cy+KYKlOm/JJwZKiPaX2yAXbUHmV48quwB4djIkuR79JUQhViA7pb+WeanZ9dZ813fCr77y0RZQsqRWbA/Fj1EboBb4cyzrmhnW2GvSxlGKMj4cN7wleaKb/SmPWNmPgKZVwW1TDGMIObtnOJCJH7sXo0jL7MmuLIjsHt7/bRknDPBQ005jftGomhQ6ZebceDTq2wpbjnrsUT/Vd+Y1b4DVaJTI6eAe4+uxFC+Epu417MfF00oHVzRmNvYkoXu4NLffbdwrtKyTP1CwT0aj1YpaZJJRlbCDerdG2lDyVbK3K2D3fXtiPFu0f+SeWKp5VX/uSRtkCaglKS3/wLxQkDOPydBCjm6RrqW6h0e2bHoyq3v8d2AKGy3iO20SCAzeRZfTjEwziWS9Ll4/OVNmK7ff1wM12ZmqWUGq8W1YHY3JWzejHbgSHnnvv52y6fSOMYcXc3DZfKGSquipTEOj7JqoZuBObcDiPVD06Th7MQKZ0KHipjFLvITTb2j+0HXcFpn5leIORsFrDeEHT0Krk1WPCjkNjO2W5YjbO/1gWh9NtofTAu9WHll51j2DXnjfwJMZ dnGfj8g2 gW7coVjZoomk9Dg3NNq/lCxy3tvqLxQcbwJsbAF8CYawYmE6Omo2ByTKrreffyMTqCpUGI082jzhiREGzRaJEqVaXNcM7jIyV4F22YDGbty6w3xokYDwp2kUZVCMPXiBqFf+nGcgQtjxkSe0ANu8uhRzsQwWLv0NP+vxs76JaMO0l5Xw= 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 03/03/2025 08:52, David Hildenbrand wrote: > On 03.03.25 09:49, David Hildenbrand wrote: >> On 02.03.25 15:55, Ryan Roberts wrote: >>> The docs, implementations and use of arch_[enter|leave]_lazy_mmu_mode() >>> is a bit of a mess (to put it politely). There are a number of issues >>> related to nesting of lazy mmu regions and confusion over whether the >>> task, when in a lazy mmu region, is preemptible or not. Fix all the >>> issues relating to the core-mm. Follow up commits will fix the >>> arch-specific implementations. 3 arches implement lazy mmu; powerpc, >>> sparc and x86. >>> >>> When arch_[enter|leave]_lazy_mmu_mode() was first introduced by commit >>> 6606c3e0da53 ("[PATCH] paravirt: lazy mmu mode hooks.patch"), it was >>> expected that lazy mmu regions would never nest and that the appropriate >>> page table lock(s) would be held while in the region, thus ensuring the >>> region is non-preemptible. Additionally lazy mmu regions were only used >>> during manipulation of user mappings. >>> >>> Commit 38e0edb15bd0 ("mm/apply_to_range: call pte function with lazy >>> updates") started invoking the lazy mmu mode in apply_to_pte_range(), >>> which is used for both user and kernel mappings. For kernel mappings the >>> region is no longer protected by any lock so there is no longer any >>> guarantee about non-preemptibility. Additionally, for RT configs, the >>> holding the PTL only implies no CPU migration, it doesn't prevent >>> preemption. >>> >>> Commit bcc6cc832573 ("mm: add default definition of set_ptes()") added >>> arch_[enter|leave]_lazy_mmu_mode() to the default implementation of >>> set_ptes(), used by x86. So after this commit, lazy mmu regions can be >>> nested. Additionally commit 1a10a44dfc1d ("sparc64: implement the new >>> page table range API") and commit 9fee28baa601 ("powerpc: implement the >>> new page table range API") did the same for the sparc and powerpc >>> set_ptes() overrides. >>> >>> powerpc couldn't deal with preemption so avoids it in commit >>> b9ef323ea168 ("powerpc/64s: Disable preemption in hash lazy mmu mode"), >>> which explicitly disables preemption for the whole region in its >>> implementation. x86 can support preemption (or at least it could until >>> it tried to add support nesting; more on this below). Sparc looks to be >>> totally broken in the face of preemption, as far as I can tell. >>> >>> powewrpc can't deal with nesting, so avoids it in commit 47b8def9358c >>> ("powerpc/mm: Avoid calling arch_enter/leave_lazy_mmu() in set_ptes"), >>> which removes the lazy mmu calls from its implementation of set_ptes(). >>> x86 attempted to support nesting in commit 49147beb0ccb ("x86/xen: allow >>> nesting of same lazy mode") but as far as I can tell, this breaks its >>> support for preemption. >>> >>> In short, it's all a mess; the semantics for >>> arch_[enter|leave]_lazy_mmu_mode() are not clearly defined and as a >>> result the implementations all have different expectations, sticking >>> plasters and bugs. >>> >>> arm64 is aiming to start using these hooks, so let's clean everything up >>> before adding an arm64 implementation. Update the documentation to state >>> that lazy mmu regions can never be nested, must not be called in >>> interrupt context and preemption may or may not be enabled for the >>> duration of the region. >>> >>> Additionally, update the way arch_[enter|leave]_lazy_mmu_mode() is >>> called in pagemap_scan_pmd_entry() to follow the normal pattern of >>> holding the ptl for user space mappings. As a result the scope is >>> reduced to only the pte table, but that's where most of the performance >>> win is. While I believe there wasn't technically a bug here, the >>> original scope made it easier to accidentally nest or, worse, >>> accidentally call something like kmap() which would expect an immediate >>> mode pte modification but it would end up deferred. >>> >>> arch-specific fixes to conform to the new spec will proceed this one. >>> >>> These issues were spotted by code review and I have no evidence of >>> issues being reported in the wild. >>> >> >> All looking good to me! >> >> Acked-by: David Hildenbrand >> > > ... but I do wonder if the set_ptes change should be split from the pagemap change. So set_ptes + docs changes in one patch, and pagemap change in another? I can do that. I didn't actually cc stable on these, I'm wondering if I should do that? Perhaps for all patches except the pagemap change? Thanks for the quick review!