From patchwork Thu Jul 25 09:10:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anshuman Khandual X-Patchwork-Id: 13741656 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 A5602C3DA49 for ; Thu, 25 Jul 2024 09:11:37 +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: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=39iq2fRAwh52C60Z4whou4qDH6s5D8nD9r+blT3IvD0=; b=1vdrej3ifAkCLp+vV7QZzQJeNt 3tyYqWkPQ4fP5RH2T8/iJ3Rcc9MVRLa9E4ulVv0nPNYPrTDfvnGTAV0+3i8zp8PYPAvV6ScF8kSwj oiT+1PXON6WFbtKPscI1A8GZyGzNXpKWK0k7c0acQjpJp7MWzah22hSMZYYH6Btv3GjWDPE8uWbPq s+2rOZRhER22EBUlXS3L5+VuENI2meZ+fwn0E7AycFkbaUS8RT3lRBGUT20rMTnhDtoqJdYfa1QZR 3/OR1ZMO0LDOrlnPeijCOB8NfGCUOCzs+hwCMTTTCqSd3wmqGZswCY6GWMRYbwfb7Yac0mz07aKsu GrVILs2A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sWuVR-00000000QUO-0JUz; Thu, 25 Jul 2024 09:11:25 +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 1sWuV2-00000000QPr-3kpW for linux-arm-kernel@lists.infradead.org; Thu, 25 Jul 2024 09:11:02 +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 775781007; Thu, 25 Jul 2024 02:11:25 -0700 (PDT) Received: from a077893.blr.arm.com (a077893.blr.arm.com [10.162.40.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E9C233F5A1; Thu, 25 Jul 2024 02:10:57 -0700 (PDT) From: Anshuman Khandual To: linux-arm-kernel@lists.infradead.org Cc: Anshuman Khandual , Catalin Marinas , Will Deacon , Ryan Roberts , linux-kernel@vger.kernel.org Subject: [PATCH] arm64/mm: Avoid direct referencing page table enties in map_range() Date: Thu, 25 Jul 2024 14:40:52 +0530 Message-Id: <20240725091052.314750-1-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240725_021101_001691_61D91098 X-CRM114-Status: UNSURE ( 9.25 ) X-CRM114-Notice: Please train this message. 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 Like else where in arm64 platform, use WRITE_ONCE() in map_range() while creating page table entries. This avoids referencing page table entries directly. Cc: Catalin Marinas Cc: Will Deacon Cc: Ryan Roberts Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Anshuman Khandual --- arch/arm64/kernel/pi/map_range.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kernel/pi/map_range.c b/arch/arm64/kernel/pi/map_range.c index 5410b2cac590..b93b70cdfb62 100644 --- a/arch/arm64/kernel/pi/map_range.c +++ b/arch/arm64/kernel/pi/map_range.c @@ -56,8 +56,8 @@ void __init map_range(u64 *pte, u64 start, u64 end, u64 pa, pgprot_t prot, * table mapping if necessary and recurse. */ if (pte_none(*tbl)) { - *tbl = __pte(__phys_to_pte_val(*pte) | - PMD_TYPE_TABLE | PMD_TABLE_UXN); + WRITE_ONCE(*tbl, __pte(__phys_to_pte_val(*pte) | + PMD_TYPE_TABLE | PMD_TABLE_UXN)); *pte += PTRS_PER_PTE * sizeof(pte_t); } map_range(pte, start, next, pa, prot, level + 1, @@ -79,7 +79,7 @@ void __init map_range(u64 *pte, u64 start, u64 end, u64 pa, pgprot_t prot, protval &= ~PTE_CONT; /* Put down a block or page mapping */ - *tbl = __pte(__phys_to_pte_val(pa) | protval); + WRITE_ONCE(*tbl, __pte(__phys_to_pte_val(pa) | protval)); } pa += next - start; start = next;