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 852DCC48260 for ; Tue, 13 Feb 2024 13:21:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D48EF6B009C; Tue, 13 Feb 2024 08:21:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CD1546B009D; Tue, 13 Feb 2024 08:21:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B72056B009E; Tue, 13 Feb 2024 08:21:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id A1C656B009C for ; Tue, 13 Feb 2024 08:21:02 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6E55A140BB4 for ; Tue, 13 Feb 2024 13:21:02 +0000 (UTC) X-FDA: 81786841164.11.A657B9F Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf29.hostedemail.com (Postfix) with ESMTP id A2921120023 for ; Tue, 13 Feb 2024 13:21:00 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf29.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=1707830460; a=rsa-sha256; cv=none; b=SauEx9QJvCGkRAE9k+jow98Orq4qwXpmBvxRt2a4R2QrrQuClpbdatTIUUSMlek3zT+XXC JlJ6FTYCv3GLUm+w/ViMG3HPgFhuw+mpYq0nMkNQetVFjIsDOns/C4crIapxalrMNgdTOq iOX2jbKTtm36pngZ2UgbDLp6Khc/Gno= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf29.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=1707830460; 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=8Fhg4tQxBXbadhl07KiA74KUc3LqRQ3zdnhXSy51HgY=; b=wNG6Q08m+Ngduejk32VU8UZp/OECguMo5g4zuKybKhkvrIeLLxj2ItKy4hUFV+ggV7A40z opjQpp2VqmHbm1nx6TKcCQgAQbgQwkDKvy5E2S6l5rYbix3ndFjstg2QO0m28PqUwdw6x4 fJxL210EuswAAAdN358VjVR6dQgFz6g= 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 1C4FADA7; Tue, 13 Feb 2024 05:21:41 -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 3E9C13F762; Tue, 13 Feb 2024 05:20:56 -0800 (PST) Message-ID: Date: Tue, 13 Feb 2024 13:20:55 +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> <1d302d7a-50ab-4ab4-b049-75ed4a71a87d@arm.com> <99e2a92c-f2a2-4e1e-8ce2-08caae2cb7e4@redhat.com> From: Ryan Roberts In-Reply-To: <99e2a92c-f2a2-4e1e-8ce2-08caae2cb7e4@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: A2921120023 X-Stat-Signature: ezyctxx5tw33ozinx4rsy3tf9jbexue6 X-Rspam-User: X-HE-Tag: 1707830460-673512 X-HE-Meta: U2FsdGVkX18Os7ZxZSxPmsYk2JeuT/6f0PJVmqgxUjwRD3m7zyLu7u97JSv6I/THA8AVPmF9+UK0bH5X0i4ZRDWa1EIurZvr9syVBiKecpSWgMRBn9rW5hvq8sOzgM2+XDTNTHWb7Uap7lyK6VZ+quhDfGR9O4uslrowIRMpajCjBUohqzNNjaeE0Jm4wUDpEVS8EQTyGMrBpBM2S9IivVBsJhFX2T46MaRO8VJJqkMxTVEkDSHGqHb1KDdpWTu3Dh4SsE9oOXHZP2V2whF6tNYEp0Ump4alC2m2I66q+dazLoAQTGoAnTD1Lrd63KxxY1I3oyv6s1VRYSFyFm0FtAlE0/v033B7n0gTklKJXh2G4vf/OMknafJvzrTnFTJDQleYi0KOSjtGf9ei43MWOse1KaLorFSTvoJb4B4ZqVuzUyZb/EQ29yzMsdzeAlC4lltq8LOa9uewiZk7xs6LBjOFmJj4YuRxVsFQE+dpz4bxgylFKd/zS8mAYZNabQZ23pNu/7b4GMOp/NyHOqaUwOReLHsL6PwFyvb/kSa3NTecMxJV8Ccbu+TZd0Wx0tZp5Fl4VzTsFyTBD44RHzPrXAKMbRbJVBcln6S/vdzWcfxEJ1phnGKk9hbTUZBEhcyo7x2uDqwmPQ/vY1OfJ9wBNg6hok+kk0RbFNwyAvddqvj8rUj4yI32/NrVYhyR6dKsQ61eb/5LDOJvpmS1wCPzvnP/6vtr1wRcvDw1pI+EMwLtXAEWAfOJkDm2FHnBSMxorNo3hTx4XueahfldqbfLjv/4rHkdwdETYiLwaiDnqTo4uc9BcsP5zJeonmv/hRQwQtygp2nZFr8CrNpjVsF1u/FD39doLpGo0V8J2Dwbdu6wlGrVCFcvEBb98rDAaZnxH6ddEWdzV+PlM1XxiwrjRxaNvcgAFreAYQyMaTOIfl3nlzxlJC8TgHszIrKqzhpeSET1UJ08mgSdhjDA0+R 8osSjWgR om0m2EN70qpz8WM6QC0Oe68Up1X5y/9ZWsOr26URlXNxQNIgId0+de/l5UJ63QB3tPq1DFDFbfeKkSxmfmniR8nOQPs5uqxRDsaVi+o+R/iz2TqpAvFB+XwA+OnEUzhIp5k+VOx8M43698xPRJLcnZZ+93++/akPhdZh2ETRPX8CCS+V9naINHR1UoZg33bj0ES69GXLUdrhsz3b0ZqnlwWzxM8RaCBHqcOrQAJwObWt2qC/HJm+eS5GAbouZ4x5q1Coqz4MH6FNuomk= 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 13:13, David Hildenbrand wrote: > On 13.02.24 14:06, Ryan Roberts wrote: >> 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. > > Just a thought, you could have a is_efi_mm() function that abstracts all that. > > diff --git a/include/linux/efi.h b/include/linux/efi.h > index c74f47711f0b..152f5fa66a2a 100644 > --- a/include/linux/efi.h > +++ b/include/linux/efi.h > @@ -692,6 +692,15 @@ extern struct efi { >   >  extern struct mm_struct efi_mm; >   > +static inline void is_efi_mm(struct mm_struct *mm) > +{ > +#ifdef CONFIG_EFI > +       return mm == &efi_mm; > +#else > +       return false; > +#endif > +} > + >  static inline int >  efi_guidcmp (efi_guid_t left, efi_guid_t right) >  { > > That would definitely work, but in that case, I might as well just check for it in mm_is_user() (and personally I would change the name to mm_is_efi()): static inline bool mm_is_user(struct mm_struct *mm) { return mm != &init_mm && !mm_is_efi(mm); } Any objections?