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 D7133C4829A for ; Tue, 13 Feb 2024 13:06:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4B1EF6B0099; Tue, 13 Feb 2024 08:06:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 46B596B009A; Tue, 13 Feb 2024 08:06:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 328986B009B; Tue, 13 Feb 2024 08:06:42 -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 1D6E26B0099 for ; Tue, 13 Feb 2024 08:06:42 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C8CFD1C0897 for ; Tue, 13 Feb 2024 13:06:41 +0000 (UTC) X-FDA: 81786805002.19.12922F3 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf13.hostedemail.com (Postfix) with ESMTP id 0677220014 for ; Tue, 13 Feb 2024 13:06:39 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; spf=pass (imf13.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=1707829600; 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=289HidDA0PT0UR0Lh4pHC3erO1U0mLUVLPKDtXBiAi4=; b=Bd8HuQSbVcktLnVuPP1iHNSiyCQ/wALJ6SbKHqoZL2VnGwrLFiUWLyscLZfxzccUUobH8t vwgZcbgZ0RbZHUhuhUIvUkC9nl3F1B8rQmUU/GKQXt4E5g55GsmEmqW8zVShM9xYVMqmCR 9AXa0g2PZk9paoYp+WojZndHiXQ20CE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707829600; a=rsa-sha256; cv=none; b=x8DYbd0ICckS8R69aco/EJPm0kekhwg7xMpzYsEpt6UcBQ7qeujU3etry0LDh58ubOGZKW zcxuyLg/OXPDbUnglALJdpNFPWEOt7qA0VDFr4wW+frYPs5ibkvrh5MMV7KwNGKJJA90EM buM2sF65UP/kDtMXRly3ACVhHYbEbHc= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; spf=pass (imf13.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 652A7DA7; Tue, 13 Feb 2024 05:07:20 -0800 (PST) Received: from [10.1.36.184] (XHFQ2J9959.cambridge.arm.com [10.1.36.184]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 93AE23F762; Tue, 13 Feb 2024 05:06:35 -0800 (PST) Message-ID: <1d302d7a-50ab-4ab4-b049-75ed4a71a87d@arm.com> Date: Tue, 13 Feb 2024 13:06:34 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 19/25] arm64/mm: Wire up PTE_CONT for user mappings Content-Language: en-GB To: David Hildenbrand , Mark Rutland Cc: Catalin Marinas , Will Deacon , Ard Biesheuvel , Marc Zyngier , James Morse , Andrey Ryabinin , Andrew Morton , Matthew Wilcox , Kefeng Wang , John Hubbard , Zi Yan , Barry Song <21cnbao@gmail.com>, Alistair Popple , Yang Shi , Nicholas Piggin , Christophe Leroy , "Aneesh Kumar K.V" , "Naveen N. Rao" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , linux-arm-kernel@lists.infradead.org, x86@kernel.org, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20240202080756.1453939-1-ryan.roberts@arm.com> <20240202080756.1453939-20-ryan.roberts@arm.com> <64395ae4-3a7d-45dd-8f1d-ea6b232829c5@arm.com> <41499621-482f-455b-9f68-b43ea8052557@redhat.com> From: Ryan Roberts In-Reply-To: <41499621-482f-455b-9f68-b43ea8052557@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 0677220014 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 46pe14t1psa1cunregaf8mwpos7kkxdy X-HE-Tag: 1707829599-193231 X-HE-Meta: U2FsdGVkX18Hzu7+q3jg8+azrsW0Yb12tRaaL2H1Xt0fGZVNHUhiKKqkMLAcpE+RDX1YJ2UkW4IaMoD5W/rcZ3kHGvp4QAh9m0d0fshs6KMNz7OXGGKh5CN/by1ok7q0kN84rzUFYIv6UNkh+0P2whIses7L5lEbnp4M6UMJZ9S9sbjgktTE58dPRWw9HEfY2AfthM+DbPjKTwg0x2lklXR/6MkennfeEf68r1MrCxDhpuVCnm0sC4uLulPla8p1IXlBr3bq813av0u9hN5XcpyyjFqO25Vwl4BT57AzAW1D10nLm/x/LszyqxwfLzm0lNF+Fdj6nDT45hoolpNC5+Vip2x1Z3BHyS6oARFMT2Hd38ly7X71TDNOrdRdRAMyOJ5099Iu9dVYttCtMn+awUD7TrAqxzjC65sNafwpOavgnZiSTBRq0GOrEd97pckM2dqepswUn+hqMxHRRxxhOBsgwD07zrLVS7R9XK6+3t4NpdYeHCIw7y6uNgvbhvfn82TN0QZxH/cUPoVyEmiyvf+Q2XFWXMEKLv2ycJ0Euqdw9YpZa29gME5fJ9wLx5/D/eEDxcV7qpMJRecT56M6HCUpMWavZPCVTwlH3x45pPjEDrgw8Zgg1zP7HMsR5bsQrPDN7U2L6teESIsnYSIYFsZIFvds2O0vAmXuYeWyRAocyQikOB7OVo7vZSPx2CDRPjyPdxUcpxgyBa8BfPUUkSlB8V/lXaKFUCzukiIBDXUU5N31pFy9ESyya9tpWkTp+45UTq5K51sEl9fZ6/o3ZfmMq31sNXtV/0Z8kTPxOFkHSfM/7Ih2PpT2X9Cbd1L7Q5Q0zJ87gzm1ApB0VO/MnbHS5Wso2p2nm/vJKttICMVA83b4i2M23DUbnvFvpwZ7gv8/Q9ThIalkleeCbxsEyMYiytlwFUu6jQI/oXjJRtltmKBkvNrNKiObmtXQAeeYEQUB/10l2cq4NZRqNGI OcIiUq7O AaVHYB4JKMZrtbYBseeEe3etAwTmUdBYcbXuUH/+0Jqhan7wplPNns9waBw041XJzWc1NaFbyYyswBh4hD9coMHPQ9zgfLJPLjScb2wpg9SlqI89dG5q4CSqqNDhdgx1GM0Tjeehp/IfwU8cOGg3XUcXpOY1S7SUphcnMJPe7QnKaR0tosVhfANwnSDiFCaMr/VO1Zmijn3KF0eY9p5IgMewOYRj+x2zAw9DpDw+r4SGXuLSNF8OcYfmg8zJllskaxaIRK30i3OrF0Ec= 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 13/02/2024 12:19, David Hildenbrand wrote: > On 13.02.24 13:06, Ryan Roberts wrote: >> On 12/02/2024 20:38, Ryan Roberts wrote: >>> [...] >>> >>>>>>> +static inline bool mm_is_user(struct mm_struct *mm) >>>>>>> +{ >>>>>>> +    /* >>>>>>> +     * Don't attempt to apply the contig bit to kernel mappings, because >>>>>>> +     * dynamically adding/removing the contig bit can cause page faults. >>>>>>> +     * These racing faults are ok for user space, since they get serialized >>>>>>> +     * on the PTL. But kernel mappings can't tolerate faults. >>>>>>> +     */ >>>>>>> +    return mm != &init_mm; >>>>>>> +} >>>>>> >>>>>> We also have the efi_mm as a non-user mm, though I don't think we manipulate >>>>>> that while it is live, and I'm not sure if that needs any special handling. >>>>> >>>>> Well we never need this function in the hot (order-0 folio) path, so I think I >>>>> could add a check for efi_mm here with performance implication. It's probably >>>>> safest to explicitly exclude it? What do you think? >>>> >>>> Oops: This should have read "I think I could add a check for efi_mm here >>>> *without* performance implication" >>> >>> It turns out that efi_mm is only defined when CONFIG_EFI is enabled. I can do >>> this: >>> >>> return mm != &init_mm && (!IS_ENABLED(CONFIG_EFI) || mm != &efi_mm); >>> >>> Is that acceptable? This is my preference, but nothing else outside of efi >>> references this symbol currently. >>> >>> Or perhaps I can convince myself that its safe to treat efi_mm like userspace. >>> There are a couple of things that need to be garanteed for it to be safe: >>> >>>    - The PFNs of present ptes either need to have an associated struct page or >>>      need to have the PTE_SPECIAL bit set (either pte_mkspecial() or >>>      pte_mkdevmap()) >>> >>>    - Live mappings must either be static (no changes that could cause >>> fold/unfold >>>      while live) or the system must be able to tolerate a temporary fault >>> >>> Mark suggests efi_mm is not manipulated while live, so that meets the latter >>> requirement, but I'm not sure about the former? >> >> I've gone through all the efi code, and conclude that, as Mark suggests, the >> mappings are indeed static. And additionally, the ptes are populated using only >> the _private_ ptep API, so there is no issue here. As just discussed with Mark, >> my prefereence is to not make any changes to code, and just add a comment >> describing why efi_mm is safe. >> >> Details: >> >> * Registered with ptdump >>      * ptep_get_lockless() >> * efi_create_mapping -> create_pgd_mapping … -> init_pte: >>      * __ptep_get() >>      * __set_pte() >> * efi_memattr_apply_permissions -> efi_set_mapping_permissions … -> >> set_permissions >>      * __ptep_get() >>      * __set_pte() > > Sound good. We could add some VM_WARN_ON if we ever get the efi_mm via the > "official" APIs. We could, but that would lead to the same linkage issue, which I'm trying to avoid in the first place: VM_WARN_ON(IS_ENABLED(CONFIG_EFI) && mm == efi_mm); This creates new source code dependencies, which I would rather avoid if possible.