From patchwork Wed Dec 13 20:29:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13491848 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D10F5C4332F for ; Wed, 13 Dec 2023 20:31:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 35D716B0331; Wed, 13 Dec 2023 15:31:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 294A06B0347; Wed, 13 Dec 2023 15:31:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 04ACE6B0331; Wed, 13 Dec 2023 15:31:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id E0DA26B032E for ; Wed, 13 Dec 2023 15:31:21 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A7567C0355 for ; Wed, 13 Dec 2023 20:31:21 +0000 (UTC) X-FDA: 81562939962.17.9D4FC93 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) by imf09.hostedemail.com (Postfix) with ESMTP id C40D414000F for ; Wed, 13 Dec 2023 20:31:19 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=LVlTaZQT; spf=pass (imf09.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.221.50 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702499479; a=rsa-sha256; cv=none; b=v3YZUbrb1/zjd//9JeJ4FgVPnm3uoJGAFkQ8KQoMtrmzDheqqnD8XSQjbbcvoZOOQY44vl h4/if5i2dSCOXGbBfQTj75ZzEQtAz/FK4Q4Eyu/t/VKRvatKzFrA1Yr+IauMJp9EwOrNeo yeCyLU2PS7TM767aOXTQyWFJBHXHMN4= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=LVlTaZQT; spf=pass (imf09.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.221.50 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702499479; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=E15RwjGwh0jg6//BOgBWUm8VeEPhhxkhRr12JTaACPU=; b=THealNykb0lmpFvJrcO6Av6A1MyHzdkDxmkT5a1W9gAe7zBC+7LAZTAF5iumkEyUFuOw/a dPfZxHcUz1a069BXPf+YzlFIqv5JcDjNvgD60o8lXftUCcTpD/YbWX/iwkhWJGM1UHTy0G 8o5Of1IvQgs4IhypdRWopD8jsa2N2qs= Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-336420a244dso655305f8f.0 for ; Wed, 13 Dec 2023 12:31:19 -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=kvack.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=LVlTaZQTr959rXEqpZmVPcy4WN+NXilxUvNDcB7FtfgWjtJshNN9tA6EyTpfjjO+Q8 4z+Yh1Ennfj5bLShvoDWl1ZYJQt3XIaKbaQsxfcV7L7SItEuoJdRv54ZUu6DvOOcZBO8 rnlq0VijEA5Fzh3IyB48ovQiPAzFzncy61bR/3XCMlXB0Bi3C9Nk7MLGE7s0dPWAJtyD 8nhuDlkJtDMV0abVlbaNzILMypNm7b/e0Hw6iXtBPCD2CBVqwlIZJXC/3XQX2DHFE7hn Z9gjpxpzdl1VpWmOiRfYa0sHyeE1QjnpV+UNKtDVpf3mZ5+CkbptbD0KiAOXqgwuSJPN a0nA== 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=w9VULYA+dxWEJsl5G7cc1ODjMAC/UsCppyl1F4WUp9PIABA1ZLKcrMyfFfcKh6ZCJX Vltu+B0YO9Dics24tHVYwtU6r/fY+FUKcx3yskjU//CXLQiuGT9mkCk4LpZ4bbk+kssK 3u2N6AlxgUJsFGgG6BgQ1as0H4ZpG/g1bjKNZDWkgMQ2JhWJuuDAmTjMlRbiEMqKKYkH OCiSY8ayGEUgwbdVusxjHreQTRq4Ayjy0sEg2gXSWV1NmpIaa43m6j8xps6/YRup+M+2 0ARU6N+kZpncSXWoCyaMORgxk1N8YnOIVLb3f+OHPrPRUz5vNToWZfCaw+9NezpDOvHp DZrA== X-Gm-Message-State: AOJu0YyaKA71d2ty4avMFtCjylxGDj6nXa/T1mQTZx5hdtR9kwG42HR6 rZA+lNKQ9Izy5i44A14FXh8NSA== X-Google-Smtp-Source: AGHT+IHJ9RU792w4DCZZx9hZPdAspSn4SI/uXWC5g1BlHgB2r11Rp2Nl7fP233w9pzamiUzq2saHcQ== 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 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: C40D414000F X-Stat-Signature: se3utf3qd5ztew6agwgp3ttk6jcgy66w X-Rspam-User: X-HE-Tag: 1702499479-216084 X-HE-Meta: U2FsdGVkX1/fQm/LkhtKbcoZBMYRRUu6h2CILEMVYST0j28asYLhYUEK2/Vxy5G8CzrCO9jtwVE/RiJOPC8612wtAnVFju7JPlHO8DyateWNCVq675qliAAo8S9b6I9eIp+Gn7ASExv/YIX2OqTb35YKppi7SEl1qi0LMz14U+WEYq55nLb8w7duIKKdfbghsfJU20q2y4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YymtChDhwLqfKtMi6bhppkB3F305BsWYnnmSUtMC0reNS14KKXxSWtTEX7YeK4/zhocEkQij2NTutZW3pwwFHmFn+UTLYldgSIAV8hYJUvJJP7TmGJ3W0Q4l3avnrcBmMzCvSyCwvNbZcxTknXbH4Uvf33FsXlKkdjhucMP2dUYTL6NM6RR0ZTSzQc9IusqotMENlHmn49nRlTD22CgicOPvadI8U3y/DiG0khr9f4CI2s6xje8qB4AyqCk+WbfcPTHaCKcToW0g== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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);