Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp1203863rdh; Fri, 27 Oct 2023 07:33:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEvf2Z8rj2ATO/Kt9///5L4/ve5xMTywOS97ZZLzqg3rCEntIKCdfgYxSjWNliyYClYzqs7 X-Received: by 2002:a81:79c6:0:b0:5a7:be3f:c451 with SMTP id u189-20020a8179c6000000b005a7be3fc451mr5222375ywc.3.1698417225876; Fri, 27 Oct 2023 07:33:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698417225; cv=none; d=google.com; s=arc-20160816; b=qC/XbYrNPbB42KnDqruQMLyom+omNSdhOwrU4rxObmPw7h2TRZ/bHN3RG4rg1csX3h akgLbBNZJAQaRAlgJu+LTKBsn7y+fTtuqxhtqK2/GEC9kluskvlDCILkZK/3SHMdaDoS B+az6NWueDANnG918BKUC0QXORvIjl31Aers2QOpUdx05FoPMDEhAf6bCJWPA0t91Ypa 1ZYu4WyoRMbZg5+QkqHTtA0mclX8dJj6SaLnfndCtLtG1/gkAAKEDWG/F2GvhYfKtJnP iG17/DjYRdibWEOPV54gNvDI7naQSYI7/CI1ioGoGXdhzaaCMHTSjIn0Knjf77IWXcX7 NqWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=0JwSBQVb6gzPPp96ouDbhllQ0NgXknpa4e1qtpF4Lng=; fh=0YNXORI2f1g3k8QaEEzBwjs/kwDlkOiTK/vvbTQGF20=; b=yxedIZJsvNHpyjU8mqQDsbSQbWeBqzs/Wg+AkHv2Udcyy77znHB43IQ2pJlFfP3lGt ZojWKWkwKvTnsEn91wascvgmtjdPenfo7W3Z1/9Y1sYyoSy9gmxOLiQqFaREzE7qhUmz ljiSIsLiqEZ7KP64bdF5nxz6YJHtVY6AOFo8B30Mb4xaEos5TMfr1evKXGobha82bejg +sCv50DX6BZf7YYaQj03WQ5pNdg2gQP9AdTBYqVP9HCuCujWiGgP50R/VyblxuC5Xtgr kIJyLI8AS0tvtJLRZH4huMfAuhFPORAzoHd5/dwH9sbPBoGNOZnNKUkqBhEoxnrAexcl VzIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=z7mRtw1t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id w67-20020a816246000000b0059f4eb8ecbcsi3100797ywb.52.2023.10.27.07.33.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 07:33:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=z7mRtw1t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 1ED34809B447; Fri, 27 Oct 2023 07:33:42 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346049AbjJ0Odc (ORCPT + 99 others); Fri, 27 Oct 2023 10:33:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346012AbjJ0Oda (ORCPT ); Fri, 27 Oct 2023 10:33:30 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 187D8C0 for ; Fri, 27 Oct 2023 07:33:28 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-40836ea8cbaso16272715e9.0 for ; Fri, 27 Oct 2023 07:33:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1698417206; x=1699022006; darn=vger.kernel.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=z7mRtw1t52QVAYRFB+GQHZHXeqmoE2MfBBcH71XQtlT+P9rHFEVuAys+EGebU2P3fR dz3ElIcF76EksC4Ib689dRotfKH1xTKMin3Iz5hJbhMK1JomR+6t9FlAtyQ5g8Q5C2uT 3hIx3hwDEUOg3/zqb2d1pAKJPcPH7tN3fFTBgazPqnibS9ukO8BxpKhma7kQoxLrPH2i 2QQKV56ZQViXnkXUxMb9eXXvHs5urUjBpnUieOxmy4pszMPKURUcb7xz4bvzj+O29GMw j0L47Lyd/lX+eIhaOJpe2xTiHSGd0HutJEdf5p5GJF+TSMfcDHSwt8g5jmze1ZdzfDKq vqpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698417206; x=1699022006; 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=bjWQqBC/wfk58d0oDlIhj6fFeD8oSm3y/nRE2JingKZ0u5w/0nzDgQpo1Df2dvmPSn CW+wVb0RiwP+31mccLwng9g9EDUovXai968lwoWJzb8B7p7sNek/mLLvKnY4d8wAEQ/C +UlLVzOlE7TczmJe6yOlf9gREuefV7GbwJMi4WCmKsrdPwy609aEctw/8r6+xNFgWdln cdlu7ghwql9pvqrcOEq2zlPLCxGf6+skvbUi2ucHjcTN3PkFedP1ChBhVOUAqN0SS7q3 5Qcq2+JhHPGL25q4rRB5rgjZN9oozrwha8hvqno4dAycfcnK5RUwgxjTxaH9c/QoFo+G C3BQ== X-Gm-Message-State: AOJu0Yw23P6S1zL2hRR/SiAxvNxuPGAHGzN+WdLYh6J+AdD2D/X7ik/2 bQHKWufwGfPY8LyH078XNj9Zqw== X-Received: by 2002:a5d:6da8:0:b0:32f:710c:6d92 with SMTP id u8-20020a5d6da8000000b0032f710c6d92mr1459732wrs.21.1698417206391; Fri, 27 Oct 2023 07:33:26 -0700 (PDT) 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 c8-20020adfef48000000b0031fd849e797sm1867433wrp.105.2023.10.27.07.33.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 07:33:26 -0700 (PDT) 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 v2 0/2] riscv: Fix set_memory_XX() and set_direct_map_XX() Date: Fri, 27 Oct 2023 16:32:20 +0200 Message-Id: <20231027143222.115588-1-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Fri, 27 Oct 2023 07:33:42 -0700 (PDT) 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(-) -- 2.39.2