From patchwork Mon Oct 2 15:10:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13406330 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 2D299E784BD for ; Mon, 2 Oct 2023 15:10:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AFFBB8D0028; Mon, 2 Oct 2023 11:10:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AB0498D000E; Mon, 2 Oct 2023 11:10:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 951EE8D0028; Mon, 2 Oct 2023 11:10:39 -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 871CC8D000E for ; Mon, 2 Oct 2023 11:10:39 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 611E61402E7 for ; Mon, 2 Oct 2023 15:10:39 +0000 (UTC) X-FDA: 81300858198.15.E53AA53 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) by imf15.hostedemail.com (Postfix) with ESMTP id 956C1A0030 for ; Mon, 2 Oct 2023 15:10:37 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=HVcMTZYg; dmarc=none; spf=pass (imf15.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.221.45 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696259437; 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:references:dkim-signature; bh=BviuOqu94hunsSO/3Ul5WhMTTjDvZpGvaCCYOAqyBa0=; b=d52D7QRLQzjC0BCANpqGQm65jfzOkdancaccCLOdUdlKE5CcO3DxHNi1mgaIo1FcVPTUQW LyhNp0nwwFPQ8G6+naHzLmqzU9FqtaWgiyKBKe4cHFvX/QAKIJbmqaHBsBDMLvMPC06lom QLtk92yV40vg9HTDDELvX14qSk2HfVg= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=HVcMTZYg; dmarc=none; spf=pass (imf15.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.221.45 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696259437; a=rsa-sha256; cv=none; b=ZqCdkRhAz8ADYju+tVuyil77S/z5y6lBSjDBQ1OxTGEmQSDeFGUck/8wHUIOh4cSfLOltU IM08XUey2OgV696PVEswVNGpTfGuvDioPDEGd1ACnt7gSKqWVjsHgAwViL1FbLl9iyxTY0 uj0bsQUwdnDfoeo5FWspp+nte9RSFD4= Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-3231d6504e1so12623632f8f.2 for ; Mon, 02 Oct 2023 08:10:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1696259436; x=1696864236; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=BviuOqu94hunsSO/3Ul5WhMTTjDvZpGvaCCYOAqyBa0=; b=HVcMTZYgV6uO+JQacKGBf9O3ujGlAuOMjvJi+BXmklN1HWf4UCPODz75fxPRRuo90q rBthHc3S576fbw+JPALC3M+73C/tbyHH224P6VulXLFGEG+WluSG1XhR25F46e/nB3CB 8NjC8mvnIlnpNx3iGWlx2YfxsxDiYPVzvcL/GGw4Nlv6TXFt6JUbJy5TDjmVAS/TrPME PXeFedm0smlfJ1Ned8/YoN0Xxcsis1hOXPX49lY4ShKaU85pdNYc+YUPH9yEs7SvQzn4 yTrpWzBZU9ZHgTIcPK3ZwUEbNm7+qerCaofC1dFaCLOf6pbvWm9EKtZ2NZ8/sA0oWYKc py8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696259436; x=1696864236; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=BviuOqu94hunsSO/3Ul5WhMTTjDvZpGvaCCYOAqyBa0=; b=iXlcITYaxJw0+GSKgGO6lntClGSaoq++v48rNENUJlsedkpUpLMWc1mfLOEg1tIikr YErjPy8927WOs9HqIlrulbtf3SWnxQFBki2p+p13EDRn0Xvcez918XP4OKtuyMnEjWRZ NuQ2OqrEiBgHpJzoDnu5pyRo4UjBBqqVKj22+ZIVO4BQQsVbYzhI2zQbvt6D/YkSFqEE C2tJQ1Lek8BJxpkwbe4nyI4k/2PXF5pzz5CzWYlbwfA42KQMmF6ERUDeckA0+WSNfiTY jUHeXe2UBsfCwWL8/JdOxcZPdQrAUQbHdP3YPEtUAygG3ipxns0aerXjnymDW4M3Ed4I Xz+g== X-Gm-Message-State: AOJu0YwobT9L1T1KCNwkhG+HFvS00M71RrnKOidah5ZxM6JkiHmmt5CP ud+n0i1j0gjmLgnPTZVG+Gw8tA== X-Google-Smtp-Source: AGHT+IFAtgaoRF40XzBvtOGWfYM9G4XzLkYMHt7t11y/gj67JLtREpQrgnLizsD6s7v4+vCjcvL7tw== X-Received: by 2002:adf:ea8f:0:b0:320:1c6:628c with SMTP id s15-20020adfea8f000000b0032001c6628cmr11378844wrm.65.1696259436015; Mon, 02 Oct 2023 08:10:36 -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 b16-20020a5d4d90000000b0031fba0a746bsm8493981wru.9.2023.10.02.08.10.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 08:10:35 -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 0/5] riscv: Use READ_ONCE()/WRITE_ONCE() for pte accesses Date: Mon, 2 Oct 2023 17:10:26 +0200 Message-Id: <20231002151031.110551-1-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: pqtquxuwymonk93afh54h3bq17tmy6hr X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 956C1A0030 X-HE-Tag: 1696259437-902123 X-HE-Meta: U2FsdGVkX1+VM834lwNU6bppUgPP6zqUhuZhqMAwaK3d2QIZ4LRFogeccHH2w8SwsMIWGhSYnkX5LyM+VhcJGgS1Vb4TDPrJLNltRG6sJ//bP4StR1FifHfU+NV0ffV+LmZTM/Mew3WaY4EbD3rgQeB8uI3awMszxlihbfX2m1XYJzo7oWj8ukoxoIjqVukVxsPTQtpclcS1Ori4ioTEHlIxaFq7hytEZ+lF2R8YHWdi0mZKeT/CTi1pTATozUx05mb8dZb7DWz9WmIA81gEvOJgc7vCRtG5GyMBkfRVPQFDSQpQXJcd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XeUIhb49O3VP70eSR+5JzNQNTAHMxqMTj7J8AjR+jj+X6il2GDo1rqxozGxAja6JoH9oM1cbRBqWgBz/uF+qFpboo3f/uD9weSoman0+jup/5girZt4wB9MxXpRCSky/GNEcffwCE4a6Q5QsjKwEmCDURZkzpmR37ANdR/jS+NBKcrvMImfObjwzu7d0Km+aQtSju1VWqP934zveMGLYZuJJ+8z14aVl+324e44oqDWKFBFqw== 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: This series is a follow-up for riscv of a recent series from Ryan [1] which converts all direct dereferences of pte_t into a ptet_get() access. The goal here for riscv is to use READ_ONCE()/WRITE_ONCE() for all page table entries accesses to avoid any compiler transformation when the hardware can concurrently modify the page tables entries (A/D bits for example). I went a bit further and added pud/p4d/pgd_get() helpers as such concurrent modifications can happen too at those levels. [1] https://lore.kernel.org/all/20230612151545.3317766-1-ryan.roberts@arm.com/ Alexandre Ghiti (5): riscv: Use WRITE_ONCE() when setting page table entries mm: Introduce pudp/p4dp/pgdp_get() functions riscv: mm: Only compile pgtable.c if MMU riscv: Suffix all page table entry pointers with 'p' riscv: Use accessors to page table entries instead of direct dereference arch/riscv/include/asm/kfence.h | 6 +- arch/riscv/include/asm/kvm_host.h | 2 +- arch/riscv/include/asm/pgalloc.h | 86 ++++++++++---------- arch/riscv/include/asm/pgtable-64.h | 26 +++--- arch/riscv/include/asm/pgtable.h | 33 ++------ arch/riscv/kernel/efi.c | 2 +- arch/riscv/kvm/mmu.c | 44 +++++----- arch/riscv/mm/Makefile | 3 +- arch/riscv/mm/fault.c | 38 ++++----- arch/riscv/mm/hugetlbpage.c | 80 +++++++++---------- arch/riscv/mm/init.c | 30 +++---- arch/riscv/mm/kasan_init.c | 119 ++++++++++++++-------------- arch/riscv/mm/pageattr.c | 74 +++++++++-------- arch/riscv/mm/pgtable.c | 71 +++++++++++------ include/linux/pgtable.h | 21 +++++ 15 files changed, 334 insertions(+), 301 deletions(-)