Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp360536rdf; Fri, 3 Nov 2023 03:02:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEmhcWhpU5yPk2qURpXKLbYHCgmT9Pb8yhyPFSdPPSp4UYLe70NGRWVhUIYPSnZIziTMIsZ X-Received: by 2002:a05:6a21:328e:b0:174:2d20:5404 with SMTP id yt14-20020a056a21328e00b001742d205404mr25167085pzb.37.1699005775336; Fri, 03 Nov 2023 03:02:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699005775; cv=none; d=google.com; s=arc-20160816; b=ehNVSMrMbp7GGA+p/WvWzYNCPsO4dkEdAEaQYUQRQucSe8px7X/fHtoWdcHRFE/8wv mzp5JkYykR8URonkq+RdEIG55uyH6pyu88jOjJRp0unpgCR4tj2m0q2DO6H5xpEVGgkA lWPsduiVrWj467whBo2Sy0YohhSmTDGA77jYcr0NKvNQ/6ICpGUUjkrD43P4LwshTnme eSyUjyHj7EhGsyNJDNcvOhjk0+RAF4w7xf2uME72MM94FuV+GydrmIQDkM9BUQN/8fM7 Y4opFG2TBmQMZCMd8vPfLwp/EpalGxtBGtS/W6txCpzxy+kkM0jpmjfnlVrJDNo1cOYl e3lQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:to:content-language:subject:user-agent:mime-version:date :message-id; bh=avrLbhc66aOWbl2UxFZsRV2HSEPF39CktXd9Udgjp5Y=; fh=UyoHsMrPkU6Z/SC8BXHKyCAXNDb0dLG3w5QMkpyWI7E=; b=sBa1eEsIbZKEA0XweSMVOb6H+M5QuPxrCoKjIMy1nkQ2AHI4NrRp2IG4F9hitlw37t rX91wGJeMc2B0H1V4nCXOUXNvb029H7h50XNH0B9J0bUYArAGN2LHTEdYhTDcJxI4PU2 aoK9ahA9zh+h7NHmFjdXKXOK1hBQgItpLQjXSpTeMD0aKwfY8pLw9KXfZdGOPq6zUAfA i5fk5sIa3G3ad1twAAR/IuCBfx7SbVqrObUYWCkBbmhPi9VgSJrVQbfqxouVX+udg8BK RANgO0jByASgbxH+uL4AO0b+rSq15NzwLLUaA9xhIFJ+8lQz9kAsHu2Ofx0ZlJhKOfSq 1qIQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id d22-20020a056a0024d600b0068e3f55075esi1288767pfv.134.2023.11.03.03.02.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 03:02:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 1B6D5807602F; Fri, 3 Nov 2023 03:02:53 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347626AbjKCKCt (ORCPT + 99 others); Fri, 3 Nov 2023 06:02:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347416AbjKCKCs (ORCPT ); Fri, 3 Nov 2023 06:02:48 -0400 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D672ABD for ; Fri, 3 Nov 2023 03:02:41 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id 9E11EC0002; Fri, 3 Nov 2023 10:02:36 +0000 (UTC) Message-ID: <7fa25a76-4e4e-49c3-b0d1-fc34ed73a19a@ghiti.fr> Date: Fri, 3 Nov 2023 11:02:36 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 0/2] riscv: Fix set_memory_XX() and set_direct_map_XX() Content-Language: en-US To: Alexandre Ghiti , Paul Walmsley , Palmer Dabbelt , Albert Ou , Mike Rapoport , linux-mm@kvack.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org References: <20231027143222.115588-1-alexghiti@rivosinc.com> From: Alexandre Ghiti In-Reply-To: <20231027143222.115588-1-alexghiti@rivosinc.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-GND-Sasl: alex@ghiti.fr X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Fri, 03 Nov 2023 03:02:53 -0700 (PDT) On 27/10/2023 16:32, Alexandre Ghiti wrote: > 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(-) > Any feedback from anyone? That's a fix I'd like to see merged in 6.7, if no objection, I'll ask for Palmer to take it. Thanks, Alex