Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5570497rdb; Wed, 13 Dec 2023 12:31:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IEm0J+Roj2cZWVoZ5/ZZZr0cABOSLcjs3ZXUUCtYXOvyLzKYK9NGtmBjPm2CEdd0X5pgYKi X-Received: by 2002:a05:6a00:c91:b0:6ce:5fbf:3cd8 with SMTP id a17-20020a056a000c9100b006ce5fbf3cd8mr5353291pfv.21.1702499493297; Wed, 13 Dec 2023 12:31:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702499493; cv=none; d=google.com; s=arc-20160816; b=ja0q4E4WidsmJBhi84vDIWvjKRpp+ltObt9iwm+X8XxDjh6xJ1iySJB4m48hm4/Swc ppqfymnrIfiyon2M9eKN1Tn3ZRGVYt9RmHlpUatTDWQ0Dq5Q8D8xcT4GenK1kBQ+ez8f frTcpbQ6pjmqpW+Q/CHzS56gMjwpYs2w6T5rRsXqWpUAObdpi2l4awMyc+B1wXqmzYBu 6fRpn76qp6t7kk3QStm3CgSY3RU8EfzDhkHXO6Y1g+9QMMXKcic0miD4I2uctQ4NTeIm u5A0szz0Eejy1F6Mx7x9Vj/rBUUUPi4jv5Yrb1gxx2keM/sIZdAOr47RTMsbwrttn6rx tOjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=E15RwjGwh0jg6//BOgBWUm8VeEPhhxkhRr12JTaACPU=; fh=IGropsY/f620dSTjnkF1U3l/yVuB1Ulli/O+nFZzzpw=; b=od3hN8NEy172KNRJNRbpzkTgj2NA7QSS7KNSZ3BCx6xM3IgKSwR+Q+vNw/Dxwb8mSc G50vl36/T0nXKwhuEyEoJfcx5pfykHzn7NSDee0QTOZZum2EyvbPqvD96i9a9bVPV7bC UK7NG9e/cAHQLvOQWqmjXIwnqHaKkK6DHqh9aeF33NGqgpOxwvRDLKr4fKdSejI85HKM TA+5tVviCNvRAJMM5DeS/J22RaotmNc+SiX+YlNSCb717h0R2Ly9u6mmiR9Zqabw/lja jXWILVMxnTMRWk3hM7xNVyUdlSRTVkYlVsXRzaXe9RhLYVs0AQbBWRzwLrE/K3pWiRbC pGsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=OF+hrUMD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id s36-20020a056a0017a400b006cea00de0f4si10152997pfg.105.2023.12.13.12.31.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 12:31:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=OF+hrUMD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id BD7DE808BE70; Wed, 13 Dec 2023 12:31:30 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442598AbjLMUbQ (ORCPT + 99 others); Wed, 13 Dec 2023 15:31:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233770AbjLMUbO (ORCPT ); Wed, 13 Dec 2023 15:31:14 -0500 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14313E4 for ; Wed, 13 Dec 2023 12:31:20 -0800 (PST) Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-334af3b3ddfso6614153f8f.3 for ; Wed, 13 Dec 2023 12:31:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1702499478; x=1703104278; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=E15RwjGwh0jg6//BOgBWUm8VeEPhhxkhRr12JTaACPU=; b=OF+hrUMDO1WDgo25gRINqm8tt4IJOo30AwXe7ElgLxjc8MhNhG5j+NLC1fcPU0USNE 6IzGOWwIjEN6XNZu/K2eJFANsI14nVKWUJloCCVP/vUxv6jVMujvSmj8+TK4ACfFbzz0 aFJUGMNCrpIc8agIsfaosP43snv9/Piozb5A/aWKppcriqqgnkBa4WgUPlKcMNMfkvk+ vbetLn8AXoQ/5Jx5ey6Zlgvh5ZFC1sOc76EGmtlPykOVi6YDST0QcPRclh1UuCTpvoYS Csj3G5/1NHSKgVXB73+Trjhutx4Iea/0MAc/bNH3L9X7RS6B2Zq+vU6BHZe4yQvQsWOV jwjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702499478; x=1703104278; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=E15RwjGwh0jg6//BOgBWUm8VeEPhhxkhRr12JTaACPU=; b=Ao22TimBwfup+KA3fNopF8ORJkcN+J8IEbx+vByjdFhlxrHN+h+1QUQ3wBUfuPyrMz FDov9BU7uWsxrjQzbtkW6v/7JqRYxG4JorTbyu+0b633Nm+2LEp5NyrRQ4siI65gCT18 /Pk0nDvA1sLBiUM87s4/zZBYi61h4dkQFjCRBHlvrntRQRVAFZCvgQQ1o8yM3fD64JwV frmoPXmelVhmmssIRW4raYIXa0DMtJR4/yFLEaWrpPlzIaLOgCyHyXHWDgWJ6ved9//K qSmGJTNAOxtSR/72Nc9NrCxA2M1I1nR8qJXFSxziAJMN++epGikDhwHiY08V/O+7xvoH dguQ== X-Gm-Message-State: AOJu0YxS3+z9da5QhUfcaGDLZRuFwrWhPoWjMKCuczWC7JAt1TegFuaw +0AhZGBxfXPq63mf7e6EThqbgA== X-Received: by 2002:a5d:5742:0:b0:336:370d:4c4f with SMTP id q2-20020a5d5742000000b00336370d4c4fmr973590wrw.60.1702499478475; Wed, 13 Dec 2023 12:31:18 -0800 (PST) Received: from alex-rivos.ba.rivosinc.com (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id h3-20020a5d4303000000b0033629538fa2sm5560888wrq.18.2023.12.13.12.31.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 12:31:18 -0800 (PST) From: Alexandre Ghiti To: Russell King , Ryan Roberts , Alexander Potapenko , Marco Elver , Dmitry Vyukov , Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Atish Patra , Ard Biesheuvel , Andrey Ryabinin , Andrey Konovalov , Vincenzo Frascino , kasan-dev@googlegroups.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-efi@vger.kernel.org, linux-mm@kvack.org Cc: Alexandre Ghiti Subject: [PATCH v2 1/4] riscv: Use WRITE_ONCE() when setting page table entries Date: Wed, 13 Dec 2023 21:29:58 +0100 Message-Id: <20231213203001.179237-2-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231213203001.179237-1-alexghiti@rivosinc.com> References: <20231213203001.179237-1-alexghiti@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Wed, 13 Dec 2023 12:31:30 -0800 (PST) To avoid any compiler "weirdness" when accessing page table entries which are concurrently modified by the HW, let's use WRITE_ONCE() macro (commit 20a004e7b017 ("arm64: mm: Use READ_ONCE/WRITE_ONCE when accessing page tables") gives a great explanation with more details). Signed-off-by: Alexandre Ghiti --- arch/riscv/include/asm/pgtable-64.h | 6 +++--- arch/riscv/include/asm/pgtable.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/riscv/include/asm/pgtable-64.h b/arch/riscv/include/asm/pgtable-64.h index 9a2c780a11e9..5d8431a390dd 100644 --- a/arch/riscv/include/asm/pgtable-64.h +++ b/arch/riscv/include/asm/pgtable-64.h @@ -202,7 +202,7 @@ static inline int pud_user(pud_t pud) static inline void set_pud(pud_t *pudp, pud_t pud) { - *pudp = pud; + WRITE_ONCE(*pudp, pud); } static inline void pud_clear(pud_t *pudp) @@ -278,7 +278,7 @@ static inline unsigned long _pmd_pfn(pmd_t pmd) static inline void set_p4d(p4d_t *p4dp, p4d_t p4d) { if (pgtable_l4_enabled) - *p4dp = p4d; + WRITE_ONCE(*p4dp, p4d); else set_pud((pud_t *)p4dp, (pud_t){ p4d_val(p4d) }); } @@ -351,7 +351,7 @@ static inline pud_t *pud_offset(p4d_t *p4d, unsigned long address) static inline void set_pgd(pgd_t *pgdp, pgd_t pgd) { if (pgtable_l5_enabled) - *pgdp = pgd; + WRITE_ONCE(*pgdp, pgd); else set_p4d((p4d_t *)pgdp, (p4d_t){ pgd_val(pgd) }); } diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index 294044429e8e..c9f4b250b4ee 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -248,7 +248,7 @@ static inline int pmd_leaf(pmd_t pmd) static inline void set_pmd(pmd_t *pmdp, pmd_t pmd) { - *pmdp = pmd; + WRITE_ONCE(*pmdp, pmd); } static inline void pmd_clear(pmd_t *pmdp) @@ -510,7 +510,7 @@ static inline int pte_same(pte_t pte_a, pte_t pte_b) */ static inline void set_pte(pte_t *ptep, pte_t pteval) { - *ptep = pteval; + WRITE_ONCE(*ptep, pteval); } void flush_icache_pte(pte_t pte); -- 2.39.2