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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7DA84C3DA4A for ; Thu, 1 Aug 2024 12:49:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=g/b3QtdK9bSJYO7mGqn8rOV9eQSMsaqWOJw7en2Fe2g=; b=avtLFWMf6SkfCvJcWg8IU1n9in XcZOumf/QjaDYNBp4Q7GZROAWh+AkqxBph6LpKOCTIRoYS0mAbt1c8iSmjbkZw/NMz96qKjUlzImy xyygSroZE/JKe9ZUF+W05T6/LcnZx/FL/dl7HLp1ng4UQbzHxA7IZM+PBwLiDAK7+tmW3LE1PoP2i DMearG8c4Z26gEmAD+aikEvxSBoyFqbB4KLTodkOt78JKjci1gEg/1N59Y0MeqfcpDJ3Rhg3e4W5Z JY6/K1bFDI9iYH7QhNtstv2xOibK8ZZqQYf0GYZjzpUZHtFhmbSGU0bh7swizVq+sibVuuSpYU6Wr IpUM5naw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZVEg-00000005GEk-1DKe; Thu, 01 Aug 2024 12:48:50 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZVEC-00000005G7k-1HcY for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2024 12:48:21 +0000 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 203AB15A1; Thu, 1 Aug 2024 05:48:45 -0700 (PDT) Received: from [10.1.28.152] (XHFQ2J9959.cambridge.arm.com [10.1.28.152]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id ABA6D3F766; Thu, 1 Aug 2024 05:48:18 -0700 (PDT) Message-ID: Date: Thu, 1 Aug 2024 13:48:17 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] arm64/mm: Avoid direct referencing page table enties in map_range() Content-Language: en-GB To: Will Deacon Cc: Anshuman Khandual , linux-arm-kernel@lists.infradead.org, Catalin Marinas , linux-kernel@vger.kernel.org References: <20240725091052.314750-1-anshuman.khandual@arm.com> <3e82687a-0183-42f3-b32c-6d99dbd4fe49@arm.com> <20240801113440.GB4476@willie-the-truck> From: Ryan Roberts In-Reply-To: <20240801113440.GB4476@willie-the-truck> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240801_054820_471609_F8B5ACB7 X-CRM114-Status: GOOD ( 14.28 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 01/08/2024 12:34, Will Deacon wrote: > On Thu, Jul 25, 2024 at 11:36:56AM +0100, Ryan Roberts wrote: >> On 25/07/2024 10:10, Anshuman Khandual wrote: >>> Like else where in arm64 platform, use WRITE_ONCE() in map_range() while >>> creating page table entries. This avoids referencing page table entries >>> directly. >> >> I could be wrong, but I don't think this code is ever operating on live >> pgtables? So there is never a potential to race with the HW walker and therefore >> no need to guarrantee copy atomicity? As long as the correct barriers are placed >> at the point where you load the pgdir into the TTBRx there should be no problem? >> >> If my assertion is correct, I don't think there is any need for this change. > > Agreed. I think I need to row back on this. It looks like map_range() does act on live pgtables; see map_kernel() where twopass == true. init_pg_dir is populated then installed in TTBR1, then permissions are modified with 3 [un]map_segment() calls, which call through to map_range(). So on that basis, I think the WRITE_ONCE() calls are warranted. And to be consistent, I'd additionally recommend adding a READ_ONCE() around the: if (pte_none(*tbl)) { Thanks, Ryan > > Will