From patchwork Wed Nov 8 07:59:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13449665 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 9D0C0C4332F for ; Wed, 8 Nov 2023 07:59:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0048E8D00A3; Wed, 8 Nov 2023 02:59:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EF6648D00A2; Wed, 8 Nov 2023 02:59:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DBE008D00A3; Wed, 8 Nov 2023 02:59:50 -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 CC4228D00A2 for ; Wed, 8 Nov 2023 02:59:50 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 937C71CB788 for ; Wed, 8 Nov 2023 07:59:50 +0000 (UTC) X-FDA: 81434038140.28.6404D65 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) by imf04.hostedemail.com (Postfix) with ESMTP id BE4954000C for ; Wed, 8 Nov 2023 07:59:48 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=Zqhp0HTF; spf=pass (imf04.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.128.54 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=1699430388; 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=0JwSBQVb6gzPPp96ouDbhllQ0NgXknpa4e1qtpF4Lng=; b=AXqaDQjn5cGpEq4uM9LgSpVmKh+7QRVlfvMpBtb8du+QPo6D5R2+uULnHH+sz//dJ48Ud1 5RG2yc6DdgehjJa/O4DXiwSjxWGQjX3S3zFHXIw9qszQlJS0nvDb15xErG+GbpOUqjSOl7 82jYMaQKCoDPMFpUbxQ+7+iv01nliGk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699430388; a=rsa-sha256; cv=none; b=nXXN0VtpMD7OUIxOAz+2cJ6PeDRPRpXg+zDAX+x71fNGamKTEtJKwymX8f7t1oMWArWKj+ goSwl6ZFy4Er4RYOVA45Bz1NYI3EFvsUIQOstejod5UtOLjjsXvYZckq90Zxr9/Po9BtZ6 SY50vQRF1mJ4B64wwvDN5d/Ky1e01Ic= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=Zqhp0HTF; spf=pass (imf04.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.128.54 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-4083cd3917eso49957735e9.3 for ; Tue, 07 Nov 2023 23:59:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1699430387; x=1700035187; 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=0JwSBQVb6gzPPp96ouDbhllQ0NgXknpa4e1qtpF4Lng=; b=Zqhp0HTFInj4H0MieiOig87qdhvpJRolIH3vodMGgYGSJaEEU2WTd2AJqSwidDGv1d onddJoXsssVBcHucZivGnLRCcTk3MYgm2ezJcjx8f8Nm5tY7ZSoFm2u/SxSGXfODRHBV Kur4pYu8qcUZiQDad7uLxHtmzPJwuD1Q/r2cwWeJrTFCfK10Lx+7hLHeRWymej7xFASq +j7onJx72Me/xhhOVPUaJw3h5pzDztbBHMIqrMjVbW8N2+LeDGngasildmM84TBqTSRv 3Lpaex/76k8Gf4ItkCgx2kkJNzCO/bDPZ5TgGExvZqlpcCTQBj6O348amJheD4hf8sID w5Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699430387; x=1700035187; 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=0JwSBQVb6gzPPp96ouDbhllQ0NgXknpa4e1qtpF4Lng=; b=dXsA3HiZJYISLnxvIEVyPoCN+sgAOnHou13DpBS3gdU9wgn6AWkt9lzHZsmhJE1Tv0 t3w2VKOsNcnCgXkPPiQqXLhHxMtOyE08GiP7ut5dVqZD+qEEBnH/ZO+lgx5m8DSGi/u/ Ypu//aEMQlhn8jW1f8ItDu+9mFsfPNuKfPfZVUASBpCjrIubC13pxQ/Ee9L53GHSUlsr HwTj/yMynxcJzQ4SSkx0qwYXxd9r25maSgOdXjY/0PR3JoU1FjAgMxv+Muu0p9Hq2Jw5 b9kJ0B/KlqlSH2XS0UgjR7HUm6hZtQ+qLWncBV6pg3cLLLMyW8LgUGeHNHDofXGXqTdN q5Iw== X-Gm-Message-State: AOJu0YxFZoGntW00eVC0zD3FUsddol7xj12FHvUryYfg2TKbm9wIRnAV UfWT3l1o3v/BsKgjOSaPvJfLtg== X-Google-Smtp-Source: AGHT+IHZGNMDI0jyKZiSY6MKCJvZxFw8O9s4wGNsKWif0l8pMDZ26/WOd6aVZ9FdKc8rFEMYh9ddTw== X-Received: by 2002:a05:600c:358a:b0:409:67bd:6fa1 with SMTP id p10-20020a05600c358a00b0040967bd6fa1mr1096777wmq.18.1699430387245; Tue, 07 Nov 2023 23:59:47 -0800 (PST) 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 j19-20020a05600c1c1300b004060f0a0fd5sm18375687wms.13.2023.11.07.23.59.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Nov 2023 23:59:46 -0800 (PST) From: Alexandre Ghiti To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Mike Rapoport , linux-mm@kvack.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Alexandre Ghiti Subject: [PATCH RESEND v2 0/2] riscv: Fix set_memory_XX() and set_direct_map_XX() Date: Wed, 8 Nov 2023 08:59:28 +0100 Message-Id: <20231108075930.7157-1-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Rspamd-Queue-Id: BE4954000C X-Rspam-User: X-Stat-Signature: 1snqsskdo9yyzwmg7j9eqtf1pn3b9dqk X-Rspamd-Server: rspam03 X-HE-Tag: 1699430388-158064 X-HE-Meta: U2FsdGVkX18PL1/g9RTuNBR9bKb/Gi3ngMb32mNzip9u7A1Dio07awd6+ziYAw9aUcRhM7hY735nYwyPLiq5OG73uV7PAIVSqIouvkwpDUBCgy2dbVjJR8uwg5rBGQs3PaHNVED7dFPNlZyo1uUZfGMSuVgH/cD+OKbb4VzVwkb/vNNMx0BMzno/x1VUelKcitnZsSb9GeOsZ27DnhbHOWFqjZRgGJKfVZGG9UUor2s7wsE8lSeZ8NIZI4AmOsMnmPE3eqnbgbLPcQCJz8AznWSjO8UWl10t3BzFlct0w9qD7YyMVJQMr3mW5cXhTsEu/dv4VStYy/n+PAk2jsdUIjCeAdo4ULVUbs5xTDG0moS/Z95/ptgRYOZeyDRS6JzTZ+XLYDXfaYriUvFNSN7gjv1HwSP+IuKa/2UNznO5Ts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2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Those 2 patches fix the set_memory_XX() and set_direct_map_XX() APIs, which in turn fix STRICT_KERNEL_RWX and memfd_secret(). Those were broken since the permission changes were not applied to the linear mapping because the linear mapping is mapped using hugepages and walk_page_range_novma() does not split such mappings. To fix that, patch 1 disables PGD mappings in the linear mapping as it is hard to propagate changes at this level in *all* the page tables, this has the downside of disabling PMD mapping for sv32 and PUD (1GB) mapping for sv39 in the linear mapping (for specific kernels, we could add a Kconfig to enable ARCH_HAS_SET_DIRECT_MAP and STRICT_KERNEL_RWX if needed, I'm pretty sure we'll discuss that). patch 2 implements the split of the huge linear mappings so that walk_page_range_novma() can properly apply the permissions. The whole split is protected with mmap_sem in write mode, but I'm wondering if that's enough, any opinion on that is appreciated. Changes in v2: - Fix rv32 build - Rebase on top of 6.6-rc6 - Move the flush_tlb_all outside the mmap_lock Alexandre Ghiti (2): riscv: Don't use PGD entries for the linear mapping riscv: Fix set_memory_XX() and set_direct_map_XX() by splitting huge linear mappings arch/riscv/mm/init.c | 12 +- arch/riscv/mm/pageattr.c | 270 +++++++++++++++++++++++++++++++++------ 2 files changed, 236 insertions(+), 46 deletions(-)