From patchwork Mon Oct 2 15:10:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13406331 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 4C307E784BC for ; Mon, 2 Oct 2023 15:11:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E0F1F8D0029; Mon, 2 Oct 2023 11:11:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DBEAA8D000E; Mon, 2 Oct 2023 11:11:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C5FDE8D0029; Mon, 2 Oct 2023 11:11:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id B2FB98D000E for ; Mon, 2 Oct 2023 11:11:40 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 97113160322 for ; Mon, 2 Oct 2023 15:11:40 +0000 (UTC) X-FDA: 81300860760.17.303995F Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) by imf01.hostedemail.com (Postfix) with ESMTP id BF6FA40014 for ; Mon, 2 Oct 2023 15:11:38 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=GnYs8dyE; spf=pass (imf01.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.128.45 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=1696259498; 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=CH5x2RpAAFVf+XEG+0f6TamSE9fPT169LwjSjxAPY4U=; b=IPVquCvr2MjgAtVrcrZrDDhuqU7QeNmsFkDqlNKo/isfd/eOpJgrqHX94VQYVIwq8Pi+2D 5NJk1OC+B062IcrAbzd9nG47LVqGmLNrUXwDH0sidPlcsTEWVrt9uvYAoP0jOpOB7MEOfV b2HBvglvYWTj/QRvC9RzBQ6XWTSHh/0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696259498; a=rsa-sha256; cv=none; b=KCkvILeI22KAd77f6c9daxhVa6CJNsJ0q4mHsncxnc3cTiU408PmnPe3s+D6lQxrqF20C+ T2yMyDHepqa3iVYaMApzM0r4fBVc3tO9SxhVVqp2CCEDabNR2xQvwYmauv0VIBiUnNVWRS AipePqo6Om20dq2sqjj700dI5Sv8+fg= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=GnYs8dyE; spf=pass (imf01.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.128.45 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4060b623e64so19752985e9.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=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=CH5x2RpAAFVf+XEG+0f6TamSE9fPT169LwjSjxAPY4U=; b=GnYs8dyECQNxaLgFbts5gpWnEuinONDK/6qoAXiADg4EgnCtyjmRjG1k87fRpQVmyu 38QKl5Az65ArDw7sTJ3StU+xjJ3OfjWYtFAhqj9MfAavDNGkff7qW+1TzNrYpLaziBGA lOj4QygrJaMhmnD26CvNr3sDX8s8JcUYD6ASwquiP+bynxmRDrvmeGQKf3VeSc/vzJ4p j2RqxJ/ZAOo6fTOtNNq+FnevmKnQT5zuq75ISNjydNpvO55z6Nl+V20X36qMtVLAAnVM Dhhg2r4RdfX81rGFgk+ufySz4uxOYnoiEF+KD6eUNBLCNgb6qqnqqQpLPRTzKMrmuSdS b2OQ== 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=Asz0GfO5fiMIenqiCg+rmxi39u5h8OXvGAsWEZXLqckr7Off7KA9imvCoWDnJC213P 2oqB16eHJVxAKO7/MPPByNEMERk7Rbf0we2Apb/u9FgIIbGN54WApgIAksq4iyeFu3/Q SxBlbAxlQ9F97xmnXsMVAEv5ewMh0NSJSjODEn0CHfBq3x4VR3uRY/oOSzmqPLeAL+j6 Zjx4sygev65Qfax1U3e2hKlR1PriK9laE+yl/KB0i43gD1/31BpdAxpuVA9JiYKhGWW3 +cNaa9EEPolpwTBEormFXMF/974N0Zu3PtY2tuYizSrd7NgEhWjNaVxVEa8njfjuwneX zjvQ== X-Gm-Message-State: AOJu0YzoMIpBQq8TiHfo0IYois8Ud9aVfHTb/eIl0QTzZw1r630nZJfg zlHDE6f0Py2PP12zpkwlNO7wuQ== X-Google-Smtp-Source: AGHT+IE3cvPQyM2FMWspPhPjMKub5vjeWt6/Vb1fFmHzwxugTPglcumTh9TgVZ+QYgvakVdrqaJiiQ== 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 X-Rspamd-Queue-Id: BF6FA40014 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: oiz9j7dektbffpytifb5gotbbq18we6g X-HE-Tag: 1696259498-219804 X-HE-Meta: U2FsdGVkX19FCU04KFKndL6zwdxerAtkPYcA6XyesMShizDOuAjHGBRPkjO+ZLghrQew7nqOItfokAJNnZCDnaeKKC5l33JurFX1YX3/yz8AIF0+uZ3wQ2IF92LTjbtjPJae5XLCnFdQHzGdUI623CY6Hh3gxozlawlxE/hJHwpy4+SfF3y4WUBbQTzUWF9gWMCStLk5sHx2Z3FvL0xVNKeJ/g+y3C1L19tb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d504nEBcIcCWBmgxaya7/CXoMiRlW/ENMz8GIJcIaSYjGtrrpYaEcnK3uHC044vbyi0WbZJzGCgh67ZY4TCAIjIGdYivu9p/PgsPqCwb852ffKtT/TApu8jgBRgzyEuaueCF0ujHzGuwOOUmSzVm08rbJIzurcIbBt3rHn7/dMrmOoRERhq8cN0BsGa4o6VL/VesToIMOA5UooHjP0mRkwWdB4VS/yD7vKpcLB56txzjN6XessjN9A== 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: 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);