Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp3032051rdb; Tue, 13 Feb 2024 05:06:49 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXCeZTV2B2GNzW02xdjCSOc/pxavlplfTY39wDjZrj8dF+j5FcKRwhc/jAatvosl6DVU/gzfbI8UeYEhySx2/hhxATkgFHLVpxcgP0OdA== X-Google-Smtp-Source: AGHT+IFgbwa11aEEIXh1JiwzFZt2/zA/uN/91MUtMG9oybi9y9xAXFSFESi2sD5yF7EbMh3J7GmL X-Received: by 2002:a17:902:d4c4:b0:1da:1fde:8411 with SMTP id o4-20020a170902d4c400b001da1fde8411mr3621628plg.34.1707829609368; Tue, 13 Feb 2024 05:06:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707829609; cv=pass; d=google.com; s=arc-20160816; b=xagi2nmHdnxLlSdh/pt2ym/Fjij2N3sUdFuWKe4b+kowTSm7d9xxsZm+tXIkj3kXeT Ckvl5djOVpQ79Ehs5LSmQRuCgj+5Wm7RkA70hwW2J8pd1ir0KcGqNXmmxK0cJz4gFFny dzuiQ7jy4ne6WKbs2V1Nr5WEnmA/bpLNvpt7C5mOsksF6j6IVW6yFkmvCOnoIw+QxFE4 rnn+eTZcHgjrw/5rAq1XIFanUPWLEpp2xfjUIg2RQUeLYJF/IGT7SIbvyum4h6vTqxED KOQOEyXipNO3orXYPY+nyyiU4CeBNphGBubJzOgOm9Dld8/bWDSP8BCqDdvG1uhbDQpt SNUQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=289HidDA0PT0UR0Lh4pHC3erO1U0mLUVLPKDtXBiAi4=; fh=+wPqhJGF3/sHJ8wlvYvLi9qJmmOiRwxzsRQ+dnRFZ9c=; b=UizHIvoihVPWXQdPpgpVtgYPPrb8yXon93eIpFeslL0q8dxiPSwB0TboVa7pNVNlJK SmpV7sC6e1W8+ngVXlYgOmWq4bg+H0F17Y6j7eqN725tRq3Gef+Srn3W/h9cpXf5BDSg F4FZ7cC9zZyi13/QrHerdWuJujAvewM4xyQSNDSQU5p1SCaWd+0BBTC7UkqdKZUeEw8w VtT3lIiFI9oXtApd7SWCJupK7HvJiXGS+M8ZRv6BF1kVt3aRMYLAJXYNccJyIXgd52qH rBueowE1gbyL6v8v4Kj7SXpGgvqIiZuO9BjSQjeMlphmiXpWd/pIZRyQXApp9AX2hRGI 5dwg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-63559-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63559-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCVjh5texhqcY5y6U3B8zO0q/i0L3YNC+kxVxt+HF8PDEXntcJkM1xr+nhx10QdNDFA+zWFuw/nUxxRT3O8My+S600Nv4VLqmRHtnHckvQ== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id v7-20020a170902b7c700b001d71de11ca5si1998899plz.493.2024.02.13.05.06.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 05:06:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-63559-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-63559-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63559-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 0D272281C0E for ; Tue, 13 Feb 2024 13:06:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 93B6E4EB35; Tue, 13 Feb 2024 13:06:42 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F1EFD2AE71 for ; Tue, 13 Feb 2024 13:06:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707829602; cv=none; b=faIn6K+C5HbPNo6HTLh0lQ7dk9kTLmpnhiyT9q8urbefR0UuVYqPS5QJJRPG9IJ2fuxOwhsKxdsThEJ94cT9UHPNGJn6DfKTm8JWKVe9bpzwxYgo1bejS0Y3u9zquRKOk5+uHT05Phcs47pZ/J2LzzWYPbZ+rRXdbrwz6O4Q+3s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707829602; c=relaxed/simple; bh=Htw2aaS4vp9qzL3/6H+N0QGH90wafRbRew7ZPnrXhg4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=XzTt+QQ5wLvmxxhFb+1cFyE33pnuFev7qeEsarZfEx/WPjk9hrXY/mOtP5X7ejHgLrU70BsJj042n13Tc7fzj6gUudeOJM4VF3A2WAlBkBujMSfFhyVU3AJHY1KVlQgo3Le+nl4cOHlLL54ikqp17DrrjcY4pNmFBtS3JsFkW4g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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.