Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4225893pxj; Tue, 25 May 2021 03:14:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwdgZMbQArdE6bUEwnXUXy+aYW+RcM2NzI0ExYNb6UxzPOOE+M8LjUJspBcnZz2Wm0a/tzZ X-Received: by 2002:a6b:4105:: with SMTP id n5mr18456786ioa.148.1621937639850; Tue, 25 May 2021 03:13:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621937639; cv=none; d=google.com; s=arc-20160816; b=oKcvymFuMKTFP0KAQlNvETswDwvSDq2dBpWpR121VT+JvDJVwTJCChBUaRZgjVjU/j /y2KCIypr0EbamVPW9MPR4KNxdYVLsbXWA9MZtzyVbi8o2wJ3E9Qc4WUYHfme56YNJGW cx8D91pI2uu6LQoin9XnGG6bcKof3rczwz4wY/kxKGx0aF2kcudEJOWoBzRIs2MMKkRS Fxq3Lk2s8031Z25Ft1EF+Z3uXDPhxfUhUJ0aqdOb7weSJalTQsRpT4HdYNqK3GZbo33o aQobkPBuJh7RDC71K93Im48eyXRmiMnvoCLeZ4FsM0Hk72sHKw0kx/WmlDmvTWeLpUZM m5ZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=ToFLxqOf83HeFVD2xsbBx9SMeRlXjpSYMbMVCYxyS/Q=; b=rmRi7Jae2pboaTD5eaupl3tBuPG22IUt3MXyM2P6mwpAuzJhu2jeaUl6RLZ8jrat4r v2qyz91ptDxPLiO1hJ3H5tb3M1JnUCvztuOCdbfmXEnzPjDgOMUN28O6qKGLq4oQTZRx XOAzx8fozFp4aeJRllCxug9dFWD5ZZhp/V+FSY47XYfMUYI4751DZsE3DWqGSg8HRohW /xjsOAndLByRPPX3QV1H9yAGKzAOi1ldOey/JD7BjIZeMSapYklkoMnXfatl9Z6fOwC5 hx04+xJHDy8+mt1jeJ6ZGDdeUoN79Y0duJ6RUQwpw6lUc3t1gd32bT9d0TFOmeNoKNzC sN5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=QEJnHdSK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f10si19300845ilu.68.2021.05.25.03.13.23; Tue, 25 May 2021 03:13:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=QEJnHdSK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231391AbhEYIx1 (ORCPT + 99 others); Tue, 25 May 2021 04:53:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231260AbhEYIx0 (ORCPT ); Tue, 25 May 2021 04:53:26 -0400 Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C663C061756 for ; Tue, 25 May 2021 01:51:57 -0700 (PDT) Received: by mail-oi1-x22e.google.com with SMTP id z3so29583836oib.5 for ; Tue, 25 May 2021 01:51:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ToFLxqOf83HeFVD2xsbBx9SMeRlXjpSYMbMVCYxyS/Q=; b=QEJnHdSK0xfzOCCWTk8svsTkGjqYPrBMkTCQDLtL+AnA6ZhDiO3B266diZ/SZGNjRz 45hnmWSkJF4oVGdxhhAdn1VJ16OM2z/quxKoRFzBMLeycOQjjxalbUxeRDT12Wxi/lI6 qLdTg4KY/pfvGFFmzA6syNOFB534frebeFZPeQbNGpvUimgmdX4KHuT+KNeFJuDPTql9 vZS4KLLUdg/GrsMi8xmdny+ATt+usvZ3m5PMiDL5f7YeOLlN8t8Sd2214buXT0pXtXiu kn3anWfcT7VU6Fe7nTxNHuc5fIX/OkFQg3K3kx6xAJpv0nOoTZiD66KrNflPlAV2ii/i SEvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ToFLxqOf83HeFVD2xsbBx9SMeRlXjpSYMbMVCYxyS/Q=; b=hoNA46xT0WSpSCCnMjPtmuvHgeObhXG/xnseTXzKprzHDGuHkQLdm0yO2c/6ChQkc/ /xO0odCCymU77AEuZjHv8zBNhnxyT7a/TqZlcs+m3AA9MeFDx3kUvYvxY/lTpmEPdRBm j+yZTXdECic+VV7qziAP3xJypB44zBCpEB6LP4/fkq8vw/JWhjTILPeyxTHTGAU23oZX uCgUFjY3aEBrjdyDKeyw1qRrpWTKzUUaarTiosdmm/dfqzPmuclitGpvYrUKEF6/PMhr bK4s1jayggxkrtYKWk17D/speEcZyZLHpXXUMD6Ou/AQSksay31j67pW8A+dG4uJnsnI hYCA== X-Gm-Message-State: AOAM530Qok2RpI+d8EpzwTIXlMd8hlO/Vs2BfWAJVR07pdPEhyLmJZP9 m3zZKoWGEZpRTyvkunRnBsqm3CTx4cFbfE3ZEuLOBA== X-Received: by 2002:a05:6808:144f:: with SMTP id x15mr13374298oiv.172.1621932716817; Tue, 25 May 2021 01:51:56 -0700 (PDT) MIME-Version: 1.0 References: <20210525104551.2ec37f77@xhacker.debian> In-Reply-To: <20210525104551.2ec37f77@xhacker.debian> From: Marco Elver Date: Tue, 25 May 2021 10:51:45 +0200 Message-ID: Subject: Re: [PATCH v2] arm64: mm: don't use CON and BLK mapping if KFENCE is enabled To: Jisheng Zhang Cc: Catalin Marinas , Will Deacon , Mark Rutland , Alexander Potapenko , Linux ARM , LKML , stable Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 25 May 2021 at 04:46, Jisheng Zhang wrote: > When we added KFENCE support for arm64, we intended that it would > force the entire linear map to be mapped at page granularity, but we > only enforced this in arch_add_memory() and not in map_mem(), so > memory mapped at boot time can be mapped at a larger granularity. > > When booting a kernel with KFENCE=y and RODATA_FULL=n, this results in > the following WARNING at boot: > > [ 0.000000] ------------[ cut here ]------------ > [ 0.000000] WARNING: CPU: 0 PID: 0 at mm/memory.c:2462 apply_to_pmd_range+0xec/0x190 > [ 0.000000] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.13.0-rc1+ #10 > [ 0.000000] Hardware name: linux,dummy-virt (DT) > [ 0.000000] pstate: 600000c5 (nZCv daIF -PAN -UAO -TCO BTYPE=--) > [ 0.000000] pc : apply_to_pmd_range+0xec/0x190 > [ 0.000000] lr : __apply_to_page_range+0x94/0x170 > [ 0.000000] sp : ffffffc010573e20 > [ 0.000000] x29: ffffffc010573e20 x28: ffffff801f400000 x27: ffffff801f401000 > [ 0.000000] x26: 0000000000000001 x25: ffffff801f400fff x24: ffffffc010573f28 > [ 0.000000] x23: ffffffc01002b710 x22: ffffffc0105fa450 x21: ffffffc010573ee4 > [ 0.000000] x20: ffffff801fffb7d0 x19: ffffff801f401000 x18: 00000000fffffffe > [ 0.000000] x17: 000000000000003f x16: 000000000000000a x15: ffffffc01060b940 > [ 0.000000] x14: 0000000000000000 x13: 0098968000000000 x12: 0000000098968000 > [ 0.000000] x11: 0000000000000000 x10: 0000000098968000 x9 : 0000000000000001 > [ 0.000000] x8 : 0000000000000000 x7 : ffffffc010573ee4 x6 : 0000000000000001 > [ 0.000000] x5 : ffffffc010573f28 x4 : ffffffc01002b710 x3 : 0000000040000000 > [ 0.000000] x2 : ffffff801f5fffff x1 : 0000000000000001 x0 : 007800005f400705 > [ 0.000000] Call trace: > [ 0.000000] apply_to_pmd_range+0xec/0x190 > [ 0.000000] __apply_to_page_range+0x94/0x170 > [ 0.000000] apply_to_page_range+0x10/0x20 > [ 0.000000] __change_memory_common+0x50/0xdc > [ 0.000000] set_memory_valid+0x30/0x40 > [ 0.000000] kfence_init_pool+0x9c/0x16c > [ 0.000000] kfence_init+0x20/0x98 > [ 0.000000] start_kernel+0x284/0x3f8 > > Fixes: 840b23986344 ("arm64, kfence: enable KFENCE for ARM64") > Cc: # 5.12.x > Signed-off-by: Jisheng Zhang > Acked-by: Mark Rutland > Acked-by: Marco Elver Tested-by: Marco Elver Thank you. > --- > Since v1: > - improve commit msg as Mark suggested > - add "Cc: stable@vger.kernel.org" > - collect Mark and Marco's Acks > > arch/arm64/mm/mmu.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c > index 6dd9369e3ea0..89b66ef43a0f 100644 > --- a/arch/arm64/mm/mmu.c > +++ b/arch/arm64/mm/mmu.c > @@ -515,7 +515,8 @@ static void __init map_mem(pgd_t *pgdp) > */ > BUILD_BUG_ON(pgd_index(direct_map_end - 1) == pgd_index(direct_map_end)); > > - if (rodata_full || crash_mem_map || debug_pagealloc_enabled()) > + if (rodata_full || crash_mem_map || debug_pagealloc_enabled() || > + IS_ENABLED(CONFIG_KFENCE)) > flags |= NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS; > > /* > -- > 2.31.0 >