Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1197698rdb; Mon, 19 Feb 2024 07:18:48 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUrEugWpNoy0/dzlSEKzKjT7epHrB+nfxOq0kh7aRfjQNgFZCewQ1DsnXJB98R45YeM0+kezGv6ZHvTQI3+Bw9vqlLrIsoSKo/pi43GRw== X-Google-Smtp-Source: AGHT+IFroiS+ahPI4SPUe+kc2UkNqsBYIi/sLx98I+NiZ8VMTHWmgXKo8l8wzLAXAOnYYhchh2jO X-Received: by 2002:a17:906:3499:b0:a3e:d7fe:4c4d with SMTP id g25-20020a170906349900b00a3ed7fe4c4dmr634068ejb.57.1708355928618; Mon, 19 Feb 2024 07:18:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708355928; cv=pass; d=google.com; s=arc-20160816; b=J4XkhtrqIrqWAjMO++Mf+C0IddK7c8ScR08n7e6edW50EV2Zh6h8fB2JbxTwnVXJ/x HL+LfJc/KHGoOfsDwF1FAH3HjUqrvUNz1usDkwSEiIupMvC50fCMZAQ6ThmabeRbmYog 4wAHgRdkLeUYSpDPMsdFrTqG1dvPv+Qc/ZupWUIs02ZhC8Z3Ayz5jsd1FGQbUpeYOxYw lLBRWI04iMAvjuUVJ6N4pk0S7jW6bswJrubfy5O+LPsMmA/zrpQoMWt2m6tyR3H6uX0j P14bKunG/0hacm06jxvPTDwvt7Og+Bfv/JyCHs3j6hQM6T9ykdoxri/HMQLHRsvXKMM3 D76Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=Roq0vh187tFs1nNPc72IO5rTUB9JixlfKY0u0BhH5ao=; fh=r8G2JENgcRo/RTe4xvZO7IzPLZ7yvHykzgF2Da/HHrw=; b=UPpralHLc0SHXNEHj6mw1gMBMDU95CWsdlBxFdqe+2VZTLYMCc+8yjb6vdnSUt5ee0 idlujsS5j4yn3H9rooGwfFX1YX11DGMvRlBRHR87VY+dacexYlX0GvwIqGaJPJsqu2b/ IhKWPK5D6RGZNzhtu6Br+WQd0ussvG0K0pYuVNdyPZVKff0+zHx6/u1dtrzU5lmh9VfT ch9Lr3WccEI0zjy389/fI2XBLw3ASLPu84LiGvplbkuhiRhqYxPEfnzyLgQPtTG1KMxr uIv/OnOELNl3i3YLzdogsGGFkvQqX0jo4ozU5DZAd2hteNbhfhSdKlsS7xuIihZi/SnP PP5w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-71574-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71574-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id m13-20020a1709062acd00b00a3e4094408dsi1967512eje.356.2024.02.19.07.18.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 07:18:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71574-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-71574-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71574-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 6302D1F242DA for ; Mon, 19 Feb 2024 15:18:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 80482383A2; Mon, 19 Feb 2024 15:18:41 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D43038389 for ; Mon, 19 Feb 2024 15:18:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708355921; cv=none; b=YZ82zDMQJtdlVtN15zw4pRg2kN0GwXrevef9Exdu5GPR/T0Bjkck+z9C3TRd68WW+DG5GFM8xWvgz5xHJCplcsQkaTUs2V1tf0qgmE/jPc0LDFhdXrJ2WYzFuK4MoGCtlnE5yzvuDpqdhSjxDC/JKUkiFGtfprVak1su5gJATS4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708355921; c=relaxed/simple; bh=e+73T9SMCi27PyDmGbKHMRdyG/AztmAZjvgCjhDl5fw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XrMaLBwHp2OpE3EHTJOV1Gne3xvb8497n0FTtfuwkKosVmb4LY0CAOyoXzCWuAODU6gAmwsjVB/aVCcRfCdNkweMAjk4q6/m2KRES3u43lE1yLODRXUwQPTiDnJjPLoi27qLaRKLQWWRR0T3AIpaczLjcdCshj5obiruA2UPmxg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 179F3C433F1; Mon, 19 Feb 2024 15:18:35 +0000 (UTC) Date: Mon, 19 Feb 2024 15:18:33 +0000 From: Catalin Marinas To: Ryan Roberts Cc: Will Deacon , Ard Biesheuvel , Marc Zyngier , James Morse , Andrey Ryabinin , Andrew Morton , Matthew Wilcox , Mark Rutland , David Hildenbrand , Kefeng Wang , John Hubbard , Zi Yan , Barry Song <21cnbao@gmail.com>, Alistair Popple , Yang Shi , 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 Subject: Re: [PATCH v6 12/18] arm64/mm: Wire up PTE_CONT for user mappings Message-ID: References: <20240215103205.2607016-1-ryan.roberts@arm.com> <20240215103205.2607016-13-ryan.roberts@arm.com> <892caa6a-e4fe-4009-aa33-0570526961c5@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <892caa6a-e4fe-4009-aa33-0570526961c5@arm.com> On Fri, Feb 16, 2024 at 12:53:43PM +0000, Ryan Roberts wrote: > On 16/02/2024 12:25, Catalin Marinas wrote: > > On Thu, Feb 15, 2024 at 10:31:59AM +0000, Ryan Roberts wrote: > >> +pte_t contpte_ptep_get_lockless(pte_t *orig_ptep) > >> +{ > >> + /* > >> + * Gather access/dirty bits, which may be populated in any of the ptes > >> + * of the contig range. We may not be holding the PTL, so any contiguous > >> + * range may be unfolded/modified/refolded under our feet. Therefore we > >> + * ensure we read a _consistent_ contpte range by checking that all ptes > >> + * in the range are valid and have CONT_PTE set, that all pfns are > >> + * contiguous and that all pgprots are the same (ignoring access/dirty). > >> + * If we find a pte that is not consistent, then we must be racing with > >> + * an update so start again. If the target pte does not have CONT_PTE > >> + * set then that is considered consistent on its own because it is not > >> + * part of a contpte range. > >> +*/ [...] > > After writing the comments above, I think I figured out that the whole > > point of this loop is to check that the ptes in the contig range are > > still consistent and the only variation allowed is the dirty/young > > state to be passed to the orig_pte returned. The original pte may have > > been updated by the time this loop finishes but I don't think it > > matters, it wouldn't be any different than reading a single pte and > > returning it while it is being updated. > > Correct. The pte can be updated at any time, before after or during the reads. > That was always the case. But now we have to cope with a whole contpte block > being repainted while we are reading it. So we are just checking to make sure > that all the ptes that we read from the contpte block are consistent with > eachother and therefore we can trust that the access/dirty bits we gathered are > consistent. I've been thinking a bit more about this - do any of the callers of ptep_get_lockless() check the dirty/access bits? The only one that seems to care is ptdump but in that case I'd rather see the raw bits for debugging rather than propagating the dirty/access bits to the rest in the contig range. So with some clearer documentation on the requirements, I think we don't need an arm64-specific ptep_get_lockless() (unless I missed something). -- Catalin