Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1952616rdb; Tue, 20 Feb 2024 11:59:07 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXinCp5bd6WVc5Iv7/umgt3O741GueI7UqI7+mldf58FlWRTSUf2947BQrEJufGvB/W9+ldjSTQl7qTtP0EygxqEn6PNEKrLkRuLGFMBQ== X-Google-Smtp-Source: AGHT+IGjl5N40ra8iXf2iPILYU/CBizfv8qXaJxeRh8o5h+EAb/csokX9BNMLYDVSPy2Pfl2Trjz X-Received: by 2002:a05:6402:b07:b0:564:a5c1:6ec5 with SMTP id bm7-20020a0564020b0700b00564a5c16ec5mr3586325edb.35.1708459147059; Tue, 20 Feb 2024 11:59:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708459147; cv=pass; d=google.com; s=arc-20160816; b=wCcASpTNvnKMqu/wVHYqpM54DM9cU33z9Qv9hgWermegEwmkvcyOm3HM1woTrzuZjq awxbtVNjc2LLUboZbP520hEIMhD/C3h5BRsMOaMaofU1h8SqPN9dlT9J79+EnkTjpx4C czwGmHG/CPev0y6ofPjMcGzq1FsPtGSwgkYMtm8S75l5imaOjg6Dh27ex6vEi5AKNyqn UxPnogrO06OE+pOdA/X5CtyIh9Ag9pMZZZLiUxJ5zhxiXrujGJkIiysQRzR7wIVMAOAS X0Ja9/ong3Lc7hzvEWeW4V6gDoXCB1ef1yPZtT1g/fr2brWYesb8jAyNxdyddB0IjGVj /rTA== 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=aCGG1n3K1/8qYFXNdvddX+moUXK+HNNXWmX+SD9OaDI=; fh=c/03A4aPz1gk/+3F0++83wBLTcimRvi6MJMJ4yXDK9I=; b=W8kQRPfii+VjMJaHxv3q5vxLBx8O4n324p1zg1cnn3Cuc7/OwXQMKtvTYLLWPKcp68 YwEFprZiymkeD/kKgbOEb8yQsLb/cds3Zn4bWi9fA3axo3Pj2+izsUmNRq/mloF5igum 5dzpYJWXsWhiimPFkD8NB/gVlq0ZzAuYaMnfiAPZXVICQRVekLcptEUwyDz3sGpq8zLm p6gSE4qXsE1sTpLDDZli9hRxW20i8WAcIk0BhNgkVG4sDJ7T/b1cDXNo6QfLtfv431nz v4K7ZOkaDGZSELuQXR6UsscmJnqyBrCOtr0d+WWMldEQzQECk0BP5doP5j9966OQeAc6 8Pww==; 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-73630-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73630-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 q6-20020a056402518600b005649f9ea4c2si1662184edd.507.2024.02.20.11.59.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 11:59:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-73630-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 spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-73630-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73630-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 CDD2A1F2195F for ; Tue, 20 Feb 2024 19:59:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5019E14A4C3; Tue, 20 Feb 2024 19:59:00 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0C08F14A4D8 for ; Tue, 20 Feb 2024 19:58:57 +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=1708459139; cv=none; b=r61wrCjXaSPQLhQ/ijEfQD3NC8rAnn9dv1PuWikI9rHlHnD577NH1APw9ZuHSzMiANDkKERqyAusLUWS7dLsE5wnpElcMCLJ9AACAACIE9ITw4OfgVjr7w3HRGNHm6RUYI08J9D9/YcGuTax9T/ik0Uh6w2MJBFaVPKRR8BXWpE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708459139; c=relaxed/simple; bh=+i8JjHVQkwYG6aYw9uGp8s+ZPKM0ZgZC8abIOEX9pzM=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=kULGkSV7KeF5ABU6q1WpCbxvUS+QcTeCXvnC6Jp7kGqtI6GZ3VtWws0N+M/eQss85XSlJ85QJF4+yBysBviGmJxsxfpx5uzf4p+BSnETQyslSPEqX3UgD37mmPRa3p2yKBy3nK0JM8+smrVODmUf1Bti/GsVydHv8tC+BK9eqxE= 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 1C06FFEC; Tue, 20 Feb 2024 11:59:36 -0800 (PST) Received: from [172.20.10.9] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A9C333F73F; Tue, 20 Feb 2024 11:58:51 -0800 (PST) Message-ID: <9cb2b8c6-aac8-4130-8558-6646817689e0@arm.com> Date: Tue, 20 Feb 2024 20:58:49 +0100 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 v6 12/18] arm64/mm: Wire up PTE_CONT for user mappings Content-Language: en-GB To: Catalin Marinas 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 References: <20240215103205.2607016-1-ryan.roberts@arm.com> <20240215103205.2607016-13-ryan.roberts@arm.com> <892caa6a-e4fe-4009-aa33-0570526961c5@arm.com> From: Ryan Roberts In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 19/02/2024 15:18, Catalin Marinas wrote: > 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). We've discussed similar at [1]. And I've posted an RFC series to convert all ptep_get_lockless() to ptep_get_lockless_norecency() at [2]. The current spec for ptep_get_lockless() is that it includes the access and dirty bits. So we can't just read the single pte - if there is a tlb eviction followed by re-population for the block, the access/dirty bits could move and that will break pte_same() comparisons which are used in places. So the previous conclusion was that we are ok to put this arm64-specific ptep_get_lockless() in for now, but look to simplify by migrating to ptep_get_lockless_norecency() in future. Are you ok with that approach? [1] https://lore.kernel.org/linux-mm/a91cfe1c-289e-4828-8cfc-be34eb69a71b@redhat.com/ [2] https://lore.kernel.org/linux-mm/20240215121756.2734131-1-ryan.roberts@arm.com/ Thanks, Ryan