Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1621915rdb; Mon, 2 Oct 2023 16:00:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGkCv+5ISd1NtZ9smtuSmJx6xcIgyLNzEcrIntpujDadNsNYKe6ZvUiLt4X9EVBW/HIWRa6 X-Received: by 2002:a05:6808:1409:b0:3ae:5f15:8bd6 with SMTP id w9-20020a056808140900b003ae5f158bd6mr14533264oiv.35.1696287641267; Mon, 02 Oct 2023 16:00:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696287641; cv=none; d=google.com; s=arc-20160816; b=deYEnVybVCbIfJDTli04juiIJoES5kKsizsHElgiwTCfEvZCsGVpYUWbJCcYHk+d5k dI8v/cjdJMCvZoer1D0xxiGIdFU2ILPVRoFGgxqmDN/Di0EKjp+N1PXSolhAyvYucE3m hk4dHHGxyuaJvfd03c+lmIMV+dWvd5EXCk6ExBmIpyzCO7wDmD4uhJd3cxL1KFWcfbp8 77XPF4wuf2fnMwGFuVZGk+uvHS11RCV46XFJpG1NA8eHAT94aGJU99qPonmgP84SC8oT lG3RV2ETGJQ/45Z1ARw73lGnLKY/pc9YTJltzSxgSJgzLDbvmci30kT8jO5QZf2ALbII ebUA== 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=CH5x2RpAAFVf+XEG+0f6TamSE9fPT169LwjSjxAPY4U=; fh=uXvJMJMnIF8WaKRrdgquas9RQiOXXOyuQb5203rEpB4=; b=CYvdpHppmP18ZwnG6l9RzirPSu8H2gjVqojGx8ysu5KZMuBMvX7oBbkdZ3gUBIcdTK SqlnxcMBAqthy6tk8ERtMzPg/TfKQexu7AVJFmdMHHWm2SaGBVZUiku5w36uKGNjfgyp l13fRzrDQf+RdyQT6eTrhFcXIUDpjj7zgYHObZpq7FR6efiLEN64Wl/IotS9MAzDe4vB X6M7bdigDUl7tu27HaJnLCspK7dNLeVPc1WWZPHDHNQEqgl08sWSFm7vP7QIfbIwtV5Z +OmthcevNS1P6lf22t/Gbuy6t72jinGi8GYjyPJS1Zn4U5r16mmGRLhTAvIhZyVKhzme DmKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=sZYLZdW1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id a6-20020a17090a8c0600b00278ee2b717fsi8442619pjo.85.2023.10.02.16.00.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 16:00:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=sZYLZdW1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id A49CC8089866; Mon, 2 Oct 2023 08:12:01 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237998AbjJBPLn (ORCPT + 99 others); Mon, 2 Oct 2023 11:11:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237935AbjJBPLm (ORCPT ); Mon, 2 Oct 2023 11:11:42 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38D5EE6 for ; Mon, 2 Oct 2023 08:11:39 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-405505b07dfso18811105e9.0 for ; Mon, 02 Oct 2023 08:11:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1696259497; x=1696864297; 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=CH5x2RpAAFVf+XEG+0f6TamSE9fPT169LwjSjxAPY4U=; b=sZYLZdW1sqyhuGnlVwuGihDYW6v5O4P88fRBV5P0IldYQjc9PTJ7jtDmFdUYLz2uf1 vVOe8Ks/EjlyPz2IcPzxF+RjHEbn4kU6KcnsE99CT+IYCStO5QY0sm0C1oOPHc9arvnd LSg3kshb4uk4e4idEjZNWSqUwGo+3b2L0J3TWvu+Nm0KMm+GwJpqNwEelW7aaCs3CSsS G9l5JBOi9wPPKHHpTbFHolpiBf2lOGS1WakzP9iYL7FzUM6pmO1SGofuim14BH/bOO5b dxrppG0t6v/x8a+hieXfqNWUANAbRRJTVrLNV8/V4UmNJRnqSDVTVvkd+VB1KKZOhSXi Erlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696259497; x=1696864297; 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=CH5x2RpAAFVf+XEG+0f6TamSE9fPT169LwjSjxAPY4U=; b=YMTlT539BSAcGRc9bNjLM3A1WPjERSLLGzeGTcpkqzRfYBYbnDwhF8Fap0tpJOFLeF kyp7Wg8qCtnQcWJugSCoX+AJ+jihuRPJTdS+t6VaNdBG2vFHB1sTJvlcSsYLTItLMshp MmFRyYYvpH10+ypo6fiLSWZyUXmMcelYvdh3zozJ/Fq2iZEmqZ4pdogk2E/KJCdzLA4S eymb+g/iGGX8Gw7MPJJgclRER+STY2ZA4Ev7ul5UQRmD3n7J+XccXlL//UJYZnF7tCS8 kDLQh59ZFuLCEZTZ6q0+l4UGihZRsSax3eRkYmoNuExakevYXQrhP8JtVmlurpmf+rBn yFRw== X-Gm-Message-State: AOJu0Yw0qx/IsBEqelUqMDoe8761VkPI0voElMjHsrHdwdrnJRRp6kf4 bqwIsgF9emA4HP2adrq30OYjdQ== X-Received: by 2002:a05:600c:1c9d:b0:401:609f:7f9a with SMTP id k29-20020a05600c1c9d00b00401609f7f9amr10681875wms.8.1696259497220; Mon, 02 Oct 2023 08:11:37 -0700 (PDT) Received: from alex-rivos.home (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id o14-20020a05600c4fce00b004065d67c3c9sm7473193wmq.8.2023.10.02.08.11.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 08:11:36 -0700 (PDT) From: Alexandre Ghiti To: 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 1/5] riscv: Use WRITE_ONCE() when setting page table entries Date: Mon, 2 Oct 2023 17:10:27 +0200 Message-Id: <20231002151031.110551-2-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231002151031.110551-1-alexghiti@rivosinc.com> References: <20231002151031.110551-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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Mon, 02 Oct 2023 08:12:02 -0700 (PDT) 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 7a5097202e15..a65a352dcfbf 100644 --- a/arch/riscv/include/asm/pgtable-64.h +++ b/arch/riscv/include/asm/pgtable-64.h @@ -198,7 +198,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) @@ -274,7 +274,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) }); } @@ -347,7 +347,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 b2ba3f79cfe9..b820775f4973 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) @@ -509,7 +509,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