Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3239527rwb; Mon, 15 Aug 2022 22:02:19 -0700 (PDT) X-Google-Smtp-Source: AA6agR7hUo+XnstBNqO6+F1FK1+n1XwxbwGsI4G0/3VzaAzRdbnKWIE0aDQpSGni/lir7M7UtCxZ X-Received: by 2002:a05:6402:350b:b0:43e:f4be:c447 with SMTP id b11-20020a056402350b00b0043ef4bec447mr17638830edd.427.1660626139655; Mon, 15 Aug 2022 22:02:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660626139; cv=none; d=google.com; s=arc-20160816; b=UHcrxa5f1UTwoWMXbaabQ0TEVOPa85B3F9TiR9EBg4opAdjH+JXhfJZdv7uj7FkA9L UcbZeS5KichmeM3Aw5wf3MAdGJLNQmOePH/kQ54PsBmKk8+A26880t7SMH3qxoIFTLC2 fRVxenpq5bZYpfDo+iB/4LujDw+GTnd7S1EwDfR7tWBKFMNDAZgyhiz/yZ12hgzxnqTQ Y5jn4nYMDAMKxk6I+siXKD6VuzgofDhvHZmF6mlu2E7p+CczMewcUSBwUMhG6pInusZe vxBWmGenjevzyfG8rDjeLc+8+rDfYsUEUBuBALlgokbZdCwB+tcKJQdvPUsWeYLZY8q5 oQ8A== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=SEmStose4tTiT5FFbTaUYOBjiP8Z/bUBilR1BG+sYzs=; b=R22/VpCDULACXE3G5xBvkPwA6Se+KkzIynbsozcKNPl1FN7UjDJUm1V6fwzF/rVtFH BtgrlY8jTuvgd4Mm2PVDWcToMUHZfTYXLddEJAg/xLj04habD4b1hvejmnRhv1gLjrT8 lit5O7/UVVry1gaDXy8cET2J8ReS/gm1EZmKpBPQYZ++KIZyWLlZhBZ9uQB/jcihmdN1 SBWUeqIXN32sYlD6FRLF2n6cHbbom3mfJ85RiA5msE7639RGePKPGdGyDcwdBAcf7//w ZjJuZgN9ZJLm00oWMXPRQPi0tuM48RGSCB+rF7TseMOL4Et4O6VwzyP3yslKC68D620M gHIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="wmQonE/w"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y6-20020a056402270600b0043e72fe84bdsi10839155edd.44.2022.08.15.22.01.53; Mon, 15 Aug 2022 22:02:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="wmQonE/w"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232876AbiHPEtl (ORCPT + 99 others); Tue, 16 Aug 2022 00:49:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232966AbiHPEqR (ORCPT ); Tue, 16 Aug 2022 00:46:17 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C94BC135; Mon, 15 Aug 2022 13:42:47 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 86AB7B80EAD; Mon, 15 Aug 2022 20:42:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7338C433C1; Mon, 15 Aug 2022 20:42:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660596165; bh=hjKaXMlf/qIWQalHOBKYAOOd5KyNV3mEb9Uy2J+LTrM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wmQonE/wEyBv0mi49IW8ecY0dxSteQ+DLIUx0CGAS1Jl5j4sKB8dtn2q1yUw0MPsP YG61hhC97A55T/Tp1llyxbMzWPGN6t/3RSfP6Pjc6ZdQRqMD5RCW26IorlR3iMKAba OMIuw7sVxryhCs2kEywy4gz8quP7pavGwJDkua2U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christophe Leroy , Michael Ellerman , Sasha Levin Subject: [PATCH 5.19 0993/1157] powerpc/32: Call mmu_mark_initmem_nx() regardless of data block mapping. Date: Mon, 15 Aug 2022 20:05:49 +0200 Message-Id: <20220815180519.444327738@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christophe Leroy [ Upstream commit 980bbf7ca72012d317617fcdbfabe8708e4cef29 ] mark_initmem_nx() calls either mmu_mark_initmem_nx() or set_memory_attr() based on return from v_block_mapped() of _sinittext. But we can now handle text and data independently, so that text may be mapped by block even when data is mapped by pages. On the 8xx for instance, at startup 32Mbytes of memory are pinned in TLB. So the pinned entries need to go away for sinittext. In next patch a BAT will be set to also covers sinittext on book3s/32. So it will also be needed to call mmu_mark_initmem_nx() even when data above sinittext is not mapped with BATs. As this is highly dependent on the platform, call mmu_mark_initmem_nx() regardless of data block mapping. Then the platform will know what to do. Modify 8xx mmu_mark_initmem_nx() so that inittext mapping is modified only when pagealloc debug and kfence are not active, otherwise inittext is mapped with standard pages. And don't do anything on kernel text which is already mapped with PAGE_KERNEL_TEXT. Fixes: da1adea07576 ("powerpc/8xx: Allow STRICT_KERNEL_RwX with pinned TLB") Signed-off-by: Christophe Leroy Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/db3fc14f3bfa6215b0786ef58a6e2bc1e1f964d7.1655202804.git.christophe.leroy@csgroup.eu Signed-off-by: Sasha Levin --- arch/powerpc/mm/nohash/8xx.c | 4 ++-- arch/powerpc/mm/pgtable_32.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/mm/nohash/8xx.c b/arch/powerpc/mm/nohash/8xx.c index 27f9186ae374..1ee08c3efe5b 100644 --- a/arch/powerpc/mm/nohash/8xx.c +++ b/arch/powerpc/mm/nohash/8xx.c @@ -179,8 +179,8 @@ void mmu_mark_initmem_nx(void) unsigned long boundary = strict_kernel_rwx_enabled() ? sinittext : etext8; unsigned long einittext8 = ALIGN(__pa(_einittext), SZ_8M); - mmu_mapin_ram_chunk(0, boundary, PAGE_KERNEL_TEXT, false); - mmu_mapin_ram_chunk(boundary, einittext8, PAGE_KERNEL, false); + if (!debug_pagealloc_enabled_or_kfence()) + mmu_mapin_ram_chunk(boundary, einittext8, PAGE_KERNEL, false); mmu_pin_tlb(block_mapped_ram, false); } diff --git a/arch/powerpc/mm/pgtable_32.c b/arch/powerpc/mm/pgtable_32.c index a56ade39dc68..3ac73f9fb5d5 100644 --- a/arch/powerpc/mm/pgtable_32.c +++ b/arch/powerpc/mm/pgtable_32.c @@ -135,9 +135,9 @@ void mark_initmem_nx(void) unsigned long numpages = PFN_UP((unsigned long)_einittext) - PFN_DOWN((unsigned long)_sinittext); - if (v_block_mapped((unsigned long)_sinittext)) { - mmu_mark_initmem_nx(); - } else { + mmu_mark_initmem_nx(); + + if (!v_block_mapped((unsigned long)_sinittext)) { set_memory_nx((unsigned long)_sinittext, numpages); set_memory_rw((unsigned long)_sinittext, numpages); } -- 2.35.1