Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3082982rwb; Mon, 15 Aug 2022 17:42:39 -0700 (PDT) X-Google-Smtp-Source: AA6agR6kva0QrKFl5qRG1RtPrTvlnOVWlH9UbGkp0LMJElmie+jHR0J4eADOuBkyEmsTSkXldhBF X-Received: by 2002:aa7:d354:0:b0:43d:7c64:3383 with SMTP id m20-20020aa7d354000000b0043d7c643383mr17048504edr.148.1660610559319; Mon, 15 Aug 2022 17:42:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660610559; cv=none; d=google.com; s=arc-20160816; b=mR7btHdhAsz1vfuIb8vHCdyHaVCfsbrwbDkdIGfkkUuEWjEa5dcrM3ZTYXh1XSdDhI CVroEeqZSRsSguGZ0hugMqwOjMzgb77uTPd4jOAGsyuSHVBzPrTm7gdmTV1r+acbz+dp Po1tTIMfAL+uyUb7XZB4MxsVoj/ohNEi4mLc+E2XE76EonVFwzREsFfEO6c93ZH2SIny Ah/mlmMKW3L9HyfYYS2/NJFL2mN1Rtfk/QGFATzu2vx3DHTuz/lpU1ed3gXi5WkYIfiv MWKsR7DQUrj+wwpdyed+E+DyewvKBWS/39BGbGVRGjlRYR3Tg6ir/8AGEoN1H6E+vmyP 83xw== 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=gglRmIyz5HImtf0y+YBAd2EGNIpJL3xhktjMbeGLlhUHJESAllp18+mMIeWrfdbr5V WarY9kjJbpIiD5x2DaMQ4jHGVjZWUgIUsIhjt3O0BErmX4iLtzoGleXt5ef4lh//TNWT PpMxyvq8FuEjQ118fTuQhSZEYq1L+LKYhKPpWTnG2p+/UykL5slVBmvVpnSrPNKzk7ad vYX5Ms+XrBjkA7oDEzT9wVjpUYRyg4f+aIYMECZAYjq38paBjrNp1bwPAcH5L87ZIqMp ip++BQDv0jO2KJOwOxppJeCiK+XMfX4aIb/IJPQWm0xVRY7mVkyl00wZyg7BEc9rT3Kc mH6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Y9FMMkVs; 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 nb38-20020a1709071ca600b00711efd98320si10337848ejc.241.2022.08.15.17.42.14; Mon, 15 Aug 2022 17:42:39 -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=Y9FMMkVs; 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 S1351916AbiHOWwY (ORCPT + 99 others); Mon, 15 Aug 2022 18:52:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351956AbiHOWuJ (ORCPT ); Mon, 15 Aug 2022 18:50:09 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46A3A13728B; Mon, 15 Aug 2022 12:53:53 -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 ED54EB80EB1; Mon, 15 Aug 2022 19:53:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55FF6C433C1; Mon, 15 Aug 2022 19:53:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660593230; bh=hjKaXMlf/qIWQalHOBKYAOOd5KyNV3mEb9Uy2J+LTrM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y9FMMkVsQ2hrqsXJOVlmzx3JhJEUCVhGyv/Lt7y17Gvfeq+qDV2wi0b45VrJvXNWP scvU2ze3K6HJbpCVezCGrlXk8hq346b2TldX7B/eH5aO/+3u1aq2vSIZuhb/FEuk2E 2gXhCoq3A7KXH1n5cpQLsyTQ5A4LtyR7CYtZ18eQ= 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.18 0915/1095] powerpc/32: Call mmu_mark_initmem_nx() regardless of data block mapping. Date: Mon, 15 Aug 2022 20:05:14 +0200 Message-Id: <20220815180507.134696584@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@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