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 556A7C3DA64 for ; Thu, 1 Aug 2024 13:24:12 +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:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=BOEdhEpVViZAesXQhIxEgzuTq7b2mfvHwv4X8T81f2g=; b=Z0Yh0zUkJAP0//QQKJFpEOBH9/ GgpoUfaVILL7ZnRM2xsMweva66ruac9nX4eNFvvNLUYFIoRsTA5XtoaoClXyznaAmismtfBtcdXYE JaWdPJuY8c7eMJYa6Sh+v7yfa9H7XkKX9h1iUzXtjB+bH+O/MfIaJH/8XOH/+F7CesMoVasR4TqXB +YihwecXBFUbdt95lnxOjZlVUzVj9ZeSlYkKfnZy2TOoBpYTIUnr82FOIv0Afv49t1rm2LyNlDooZ biJXqa5yrwE5GxDw6VOqnR11IRdhIBNlXxw107V0R/RrqjA2421JY20MoHbTkx0YSUU0AyZ57ym2z HWccvZ2w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZVml-00000005Uzd-0q7Z; Thu, 01 Aug 2024 13:24:03 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZVmG-00000005UqS-2nVK for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2024 13:23:33 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id F0BF0628BB; Thu, 1 Aug 2024 13:23:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8DF64C4AF0A; Thu, 1 Aug 2024 13:23:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722518611; bh=rX7rb9hXMhlm2xmHKvLXykMAxNBBTXGZ3WbXhR4Q1zY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=eHZ6ODzMEz6vXABGsnmbdiF4B5FK05z6tLlhyOkPeYDrBYaxUVCwUcPEq6Xx84A3A 7JcrH6c4x+CDR36JQ1fI+1WXLKUOCP3UgD2jI4zyyRylqnkQHLJn1oyVTidVAQs9OU BtB4P00y6LevFsPyiFKVmeWBitOy8b5hqaLe7CRHixO7+/TZHT5A8Ubrchgm5L8AfY X/MBL7zrEPhw8JScqyYq1g2pBIVR7aFFlj5MvYbWEtJCvqZqp93Iu3XUr02JYqBTcj SqyxHBN0aWNAkTjuk+/6gqAe6t+qbhoHW6kKPhMVVQSl4OpszSPdZTuSajjGSnqlHx 2D3xZItiFI7WQ== Date: Thu, 1 Aug 2024 14:23:27 +0100 From: Will Deacon To: Ryan Roberts Cc: Anshuman Khandual , linux-arm-kernel@lists.infradead.org, Catalin Marinas , linux-kernel@vger.kernel.org Subject: Re: [PATCH] arm64/mm: Avoid direct referencing page table enties in map_range() Message-ID: <20240801132326.GA4794@willie-the-truck> References: <20240725091052.314750-1-anshuman.khandual@arm.com> <3e82687a-0183-42f3-b32c-6d99dbd4fe49@arm.com> <20240801113440.GB4476@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240801_062332_795002_3558FCB2 X-CRM114-Status: GOOD ( 21.78 ) 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 Thu, Aug 01, 2024 at 01:48:17PM +0100, Ryan Roberts wrote: > 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(). I think the permission part is fine, but I hadn't spotted that unmap_segment() uses map_range() to zap the ptes mapping the text. That *does* need single-copy atomicity, so should probably use __set_pte_nosync(). > 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)) { Why? I don't think we need that. Will