From patchwork Wed Dec 13 20:29:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13491847 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 15885C4332F for ; Wed, 13 Dec 2023 20:30:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 99B7B8D0059; Wed, 13 Dec 2023 15:30:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8FD318D0049; Wed, 13 Dec 2023 15:30:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7286A8D0059; Wed, 13 Dec 2023 15:30:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 560458D0049 for ; Wed, 13 Dec 2023 15:30:21 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 9BDD212036B for ; Wed, 13 Dec 2023 20:30:20 +0000 (UTC) X-FDA: 81562937400.26.9CAD020 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) by imf24.hostedemail.com (Postfix) with ESMTP id B140418000D for ; Wed, 13 Dec 2023 20:30:18 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=DS3ZGmfJ; dmarc=none; spf=pass (imf24.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.221.41 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702499418; a=rsa-sha256; cv=none; b=8VJx+ibur8pw4iMCfi9YXv8k1IzZ56IKAnS211V9hFzZ1H/KbfCVEE9F+LcAZ/gJUSkYu4 EehgQf8XENMiKHkFSb1dlOIJoVSjOK8KIGkf/86Ddj34pXlZJKACT/shTgfKSuw+DVlqkT ACaRXjYjVFyQ1QTBJuSVQKjTFoSIFxY= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=DS3ZGmfJ; dmarc=none; spf=pass (imf24.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.221.41 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=1702499418; 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=i+467Loz3LrvYEdXAV5s12LMqcUY9odwCyEv1IdVOvU=; b=Kbaqxcf5q+XI5+jqxLeo2CHo+r6IdYQf6ZP0xBDbInc+XT2joTzhYH+JkQminJU7WHWolf Z1hs7YGDtxigUepTI9WwLE0Cc1FYHnggfV8rOxHmDiavk7w7SlSLJwKjcXXiHmdwxMRyeY p/n4SctJQ3Vrkw1cNpTbS6Vqd6nOejw= Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-33621d443a7so3699689f8f.3 for ; Wed, 13 Dec 2023 12:30:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1702499417; x=1703104217; 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=i+467Loz3LrvYEdXAV5s12LMqcUY9odwCyEv1IdVOvU=; b=DS3ZGmfJ9pf2bAjeYk4/rUZ693LvGVXh+PRikpAwIn7/KLOLzXuFRDC3Ew2ZeDPGcx VgotECzsCXXiaBXliO3Ui+jjb8Nl/cXuMcIyYeWEe29cMCatL66pRkCYSU9bldgyCirG p+PGmeay7z6tlKCUNzoPGa+cW8g0vqv1+kz+awBa+qrrqrxpjhbNBH5qGCLbAL5yUiYV FgzJg/ATaIkd5RDkEGkgxzy96ZuAkS6KEE2lVx5zKmJnV4xOZt8YzXyw0dun9mMXZ/Fm 2QnlOuNymkAWfy+F2xparUaVrN0BqnvVjbPO5/+k0M6/agnwsVT0zPlXhZt/CluPiI9g 1OgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702499417; x=1703104217; 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=i+467Loz3LrvYEdXAV5s12LMqcUY9odwCyEv1IdVOvU=; b=X4z/FGN/QWidcC7DuSp3P1gA8J4nqr3FyDlCd35b9X5GWopkFA1yQC3rJon3OSR2wI Xaj/S7oafNOqWRkYRivLXV7rJSQR8xdUmlylnPjY0RH9HwgTSOk3H20mhbuNNNN2N8Jd MS/NNPS7h0U+5tCfHY7PcErVq5be5tIvEXLtRIwGj9ORuILwSJTjxFK04UlaNeuC0o8G 5j7vigpGKS2eBk0IQbyKegsihQrzELjGMFN0gkzU5ppNnqB7mDSJXQEiiPrTJI7RcASH f8GplS4dglchXmYO6G+cnoxunzReZwQhjZGSY4uG5ZigZaoi0NsHVG6HxM5USYMPlnkg XFTw== X-Gm-Message-State: AOJu0YwxNDMVOJo8dEbGqKLpmo73LVjHCVroLLA9fpOVl9h/eoAl+qWE UwluutOYlnwqk9S9QRoFT2GFng== X-Google-Smtp-Source: AGHT+IGBLga6z9pG2jLj7Eh24QZCKuh/cAtflhfd+Zgtj1tOF9StAT24MMOv0TqcLPwKldvFFyI7jA== X-Received: by 2002:a05:6000:10c1:b0:336:38ef:1e91 with SMTP id b1-20020a05600010c100b0033638ef1e91mr917003wrx.128.1702499416911; Wed, 13 Dec 2023 12:30:16 -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 x10-20020a5d444a000000b00336371fafe6sm2945256wrr.16.2023.12.13.12.30.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 12:30:16 -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 0/4] riscv: Use READ_ONCE()/WRITE_ONCE() for pte accesses Date: Wed, 13 Dec 2023 21:29:57 +0100 Message-Id: <20231213203001.179237-1-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: B140418000D X-Stat-Signature: 7qkx8465wgjstzysgnqfg7zqdef39mi8 X-HE-Tag: 1702499418-951174 X-HE-Meta: U2FsdGVkX18yCITsrHNqnAgWrb6YGRxxN6nYIBO19gr3yE8Z8AqDqjlhXcORnB3rI28/FgTpHEsiNqjWk/p4rO0nLRSvHMs4Os0Jczjpyt+xU77dahK+7n6/4I4LbETnouCrClPZrCPpRop0X6SQW6RASaVKZ/AGe+FeRbPgCmiqOzVe7sq/DwOT4kulQVqTk1Bh4+B0oVnI765N0SXn4LEwVlFYPOyO6oIRZq1t7ZRB//wqPuY8uQO2K6ObmD3jW6cZsM6JzrA9wNRb8NlDUpC6S3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zgXIg0AejOP+L65Ixr/1re6DsuSDsNgH6Mo+NT6OyvW+MGB1xjakWifU2rNb72ZSduZi3KxKnCYq8eK+GEIppWoeikePIk5udWDZ1jOXMsvgaiqSYJS65SijdTLv1Aey2kin19ABM4W7AXlZve5LhRrdnq1wpuqUrjViQZlCeD130mUDpQVw6GlAXVn7y04z7tNYgD5PqX95ZRJanTX1HU0xjPwGgNy2eM6D+nSEbPpPVad6sF5vxhoScoU9P5ZT/Xt3tsBQhYqA== 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: 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/ Changes in v2: - Fix the kernel test report on arm32 - Remove the pte suffix patch - Fix pud_offset/p4d_offset which were missing the use of accessors - Rebase on top of 6.7-rc4 Alexandre Ghiti (4): 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: Use accessors to page table entries instead of direct dereference arch/arm/include/asm/pgtable.h | 2 ++ arch/riscv/include/asm/kfence.h | 4 +-- arch/riscv/include/asm/pgtable-64.h | 22 +++---------- arch/riscv/include/asm/pgtable.h | 33 +++++-------------- arch/riscv/kernel/efi.c | 2 +- arch/riscv/kvm/mmu.c | 22 ++++++------- arch/riscv/mm/Makefile | 3 +- arch/riscv/mm/fault.c | 16 ++++----- arch/riscv/mm/hugetlbpage.c | 12 +++---- arch/riscv/mm/kasan_init.c | 45 +++++++++++++------------ arch/riscv/mm/pageattr.c | 44 ++++++++++++------------- arch/riscv/mm/pgtable.c | 51 ++++++++++++++++++++++++++--- include/linux/pgtable.h | 21 ++++++++++++ 13 files changed, 157 insertions(+), 120 deletions(-)