From mboxrd@z Thu Jan 1 00:00:00 1970 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 BDE53C4332F for ; Fri, 3 Nov 2023 10:02:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3832B280018; Fri, 3 Nov 2023 06:02:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 332B028000F; Fri, 3 Nov 2023 06:02:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1FA26280018; Fri, 3 Nov 2023 06:02:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 0D01B28000F for ; Fri, 3 Nov 2023 06:02:45 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id D724840379 for ; Fri, 3 Nov 2023 10:02:44 +0000 (UTC) X-FDA: 81416203848.18.9955570 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by imf25.hostedemail.com (Postfix) with ESMTP id 1B8C3A0019 for ; Fri, 3 Nov 2023 10:02:41 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; spf=pass (imf25.hostedemail.com: domain of alex@ghiti.fr designates 217.70.183.198 as permitted sender) smtp.mailfrom=alex@ghiti.fr; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1699005762; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=avrLbhc66aOWbl2UxFZsRV2HSEPF39CktXd9Udgjp5Y=; b=GF8/yWk3DYZaHFp2IDIQTmzZ6g0dMey1G97xD5nNtQJShviktRCiEjWC4+jOwzrIobibW7 9kb5+GFF8AQuaS721OWPQC2VJyCBCF2XqlX5ZcTaCjBk/oAnmHH2YGBtqSgTd6MorOkK7a DZD2KRx6udTYER6J95vcLIlzEOdBz7E= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699005762; a=rsa-sha256; cv=none; b=gYCGaOmTBzCmvqJ/POKp6AqTrncwMYdVb9V/1n6RAOzELfKGZc4Pds9vIqQA1QBB+T6Ld3 y+0Yaeieus/IyGNUvbst1+PYugOOD2n7MQWMYx7wEtZRZ8Xmutoj533fD9p8J/MEbfydyf v40TjDkz/FFHMBSD0gaiKPe42RoHcJU= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; spf=pass (imf25.hostedemail.com: domain of alex@ghiti.fr designates 217.70.183.198 as permitted sender) smtp.mailfrom=alex@ghiti.fr; dmarc=none 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-Stat-Signature: rwxe9j7h1s8q3nbdcpbdit93fohtcp4e X-Rspamd-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wn7wqfWeY7uRseUSlujBZp0d5zZNchL/d4h6gr+HzPEy/TPgXiShlnZ/Myhg6e2Ue3BCwHZiaP4WeeKVW/wnwUnNF9HGbMtLj1CU6X4W X-Bogosity: Ham, tests=bogofilter, spamicity=0.000171, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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