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 D624CC636CC for ; Tue, 7 Feb 2023 10:48:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4D92D6B0073; Tue, 7 Feb 2023 05:48:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 489706B0085; Tue, 7 Feb 2023 05:48:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 379036B0087; Tue, 7 Feb 2023 05:48:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 285B66B0073 for ; Tue, 7 Feb 2023 05:48:30 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id F225B1A0C09 for ; Tue, 7 Feb 2023 10:48:29 +0000 (UTC) X-FDA: 80440171938.30.40715F9 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf16.hostedemail.com (Postfix) with ESMTP id E3C6218001A for ; Tue, 7 Feb 2023 10:48:27 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf16.hostedemail.com: domain of mark.rutland@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=mark.rutland@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675766908; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Yei3eyebblIbWDsrxlCyvivDcJzN0GAOgTqClknaJkk=; b=8DnHFWCzmMrE5nzPjnpGx/abjjDB7G9a6cFD893xsP04548sjJX6MJt4FkTaPT6dQsvfNh hGXOwaApVZCqSMECG43ofaxw9aYLNzDNzVF9geL1RhhCdlvLxbsSYWm1eF+MIG59qrdt2P vO1KbhJlcD754fFyVvKlBfJg7gerhJY= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf16.hostedemail.com: domain of mark.rutland@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=mark.rutland@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675766908; a=rsa-sha256; cv=none; b=jQ74pReJleIp+rwtBlODu7lEyoPUvsNf3prbEcgXbgAHWxelsByE981sqTq96MdfoanieI GYs8R1sfrVzujfN7hJzeiy4SELj9VW8SskncQL2dm88QbXgKKwQ2cGKHHh3PsLjSjU8qKa NQV76nwbt1jzRQsTwQSIhK2Cl+u8U6g= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2A287106F; Tue, 7 Feb 2023 02:49:09 -0800 (PST) Received: from FVFF77S0Q05N (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5DA043F703; Tue, 7 Feb 2023 02:48:25 -0800 (PST) Date: Tue, 7 Feb 2023 10:48:22 +0000 From: Mark Rutland To: Zhenhua Huang Cc: Marco Elver , catalin.marinas@arm.com, will@kernel.org, glider@google.com, akpm@linux-foundation.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org Subject: Re: [PATCH] mm: kfence: export kfence_enabled as global variables Message-ID: References: <1675750519-1064-1-git-send-email-quic_zhenhuah@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue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z3eoWEfuj5JI3NDxeWzb5nvxVf5wEH+4+L3oEN8Jku4LFQENLUSJf7HQjni8dzOodpEqYDmYlFQFI+bOB+uMP7FGPVz2or14/QkU7XySa9KSrDfYbcO/TSzLpIV+Mzqs2enHZTxnq2lgWosOIutwT/VX+O9qXubXALmYg/gYvX8UwnK+Zme+pgn4mNXaMPxozvD0WyskGGx4kMDV9qxmZjSjHtkViEz/S7VjYL9o5+ePRRIPJjmnFIw/YbgtHsY= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Feb 07, 2023 at 03:46:53PM +0800, Zhenhua Huang wrote: > Thanks Marco! > > On 2023/2/7 15:19, Marco Elver wrote: > > On Tue, 7 Feb 2023 at 07:15, Zhenhua Huang wrote: > > > > > > Export the variable to ease the judgement of whether kfence enabled > > > at runtime. It should be more precise than through kernel config > > > "CONFIG_KFENCE". > > > > > > For example We can disable kfence at runtime using bootargs > > > "kfence.sample_interval=0" but CONFIG_KFENCE enabled. > > > It was false positive. > > > > > > Signed-off-by: Zhenhua Huang > > > --- > > > arch/arm64/mm/pageattr.c | 3 ++- > > > include/linux/kfence.h | 2 ++ > > > mm/kfence/core.c | 2 +- > > > 3 files changed, 5 insertions(+), 2 deletions(-) > > > > > > diff --git a/arch/arm64/mm/pageattr.c b/arch/arm64/mm/pageattr.c > > > index 79dd201..208d780 100644 > > > --- a/arch/arm64/mm/pageattr.c > > > +++ b/arch/arm64/mm/pageattr.c > > > @@ -7,6 +7,7 @@ > > > #include > > > #include > > > #include > > > +#include > > > > > > #include > > > #include > > > @@ -27,7 +28,7 @@ bool can_set_direct_map(void) > > > * protect/unprotect single pages. > > > */ > > > return (rodata_enabled && rodata_full) || debug_pagealloc_enabled() || > > > - IS_ENABLED(CONFIG_KFENCE); > > > + kfence_enabled; > > > > Unfortunately this won't work, because it's possible to enable KFENCE > > after the kernel has booted with e.g.: echo 100 > > > /sys/module/kfence/parameters/sample_interval > Yeah, got it. Thanks for catching it. > > > > What is the problem you have encountered? Is the page-granular direct > > map causing issues? > We're working on a low memory target, page-granular mapping costed more (2M > per 1GB) memory. Due to GKI constraints, it is not easy to disable > CONFIG_KFENCE. So my intention was to move the judgement to runtime > configurable w/ CONFIG_KFENCE on... > > Do you have any further suggestion/proposal on this? Many Thanks! Just to check, the cost is because we're mapping *all* of memory at page granulatrity, right? If we were to just map the KFENCE region a page granularity, would that be a sufficient saving? We didn't do that so far because it was simpler to just map everything at page granularity (and that's also required by rodata_full, which I though android used?). If it's really important (and rodata_full isn't being used), we could try to do that. To do that we'd need to choose the KFENCE region *before* arm64 creates the fine-grain translation tables, which probable needs an arch_ hook. Thanks, Mark.