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 0A4B5C74A44 for ; Tue, 14 Mar 2023 11:15:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 82C166B0072; Tue, 14 Mar 2023 07:15:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7DCEC8E0002; Tue, 14 Mar 2023 07:15:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 67D908E0001; Tue, 14 Mar 2023 07:15:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 591DE6B0072 for ; Tue, 14 Mar 2023 07:15:03 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 347C1C02DB for ; Tue, 14 Mar 2023 11:15:03 +0000 (UTC) X-FDA: 80567246886.14.ABB79AB Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by imf02.hostedemail.com (Postfix) with ESMTP id EC89B8001C for ; Tue, 14 Mar 2023 11:14:59 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=i8Huf3pr; spf=pass (imf02.hostedemail.com: domain of quic_pkondeti@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_pkondeti@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678792500; 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:dkim-signature; bh=VujrT43HB6fJ6xXNFPnzBFZqIlXJL3kJIrIgS+iVKd8=; b=lpCFGtzKDzfNfWINeJDeYdni/5iPvDxKFxQoXcDEjBgx3i/INVxDFEWvBKWVu665yVCHMC Ex2sGR2a/y40zepkK65jDkXpoFjieOUKIKZOaxwRcZCF8RzSh3VAnm/TfsN2FwLpDgeWsh E874MWqqMNg0/XHHfPOpdAVtFMXztEo= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=i8Huf3pr; spf=pass (imf02.hostedemail.com: domain of quic_pkondeti@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_pkondeti@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678792500; a=rsa-sha256; cv=none; b=qbCAqDsNPEoerZHMY9eTAkh39ON07kkL9zzK5wRb1ZNB5cCwAdC9+9/sW/nJGe1fObIIet MRjl7dR+xlZmE6MNBFPjPLhok3icMtLA8xSXH62iqi1xXac9QQwLnUhczK/m9d/d4s0EYZ uESTOnc7czHt05cEV0bPKoEKpo0LxB8= Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32EASMjl010812; Tue, 14 Mar 2023 11:14:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=qcppdkim1; bh=VujrT43HB6fJ6xXNFPnzBFZqIlXJL3kJIrIgS+iVKd8=; b=i8Huf3prJJaFSkJuKkDf1Cjh/qd+PeN/9+iFq3sTL/zcN40vLm4HLoehVl0C1kBDsDhF BQyiyPVmF//aDaT31/C7TY2PvPZia8APFrlDSlYgb/kB7LkOPLlSVwJ8eJXFUMa67In+ 5vk/zGP5cTublvZejGk56fsM/2Sm0sgMXiiWS3gwLdLFK3wOLxyU+UJNzhIFhqm2qyI3 wbg9XhMdctfuaeEGNA+QHo3u6vmFH5thh6uuNdZnQF+l/Oe/V4Y2yKJzn8P9yOjfOlgo 3nXwY9LqpP7LVKQszyxB1rdai/MftaRAhDSkcJF6s1UanNPpCjO1HE7w5b/NZpq6mJjv Ig== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3p9yew3y90-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 14 Mar 2023 11:14:41 +0000 Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 32EBEW4T024149 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 14 Mar 2023 11:14:32 GMT Received: from hu-pkondeti-hyd.qualcomm.com (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Tue, 14 Mar 2023 04:14:26 -0700 Date: Tue, 14 Mar 2023 16:44:22 +0530 From: Pavan Kondeti To: Zhenhua Huang CC: Pavan Kondeti , , , , , , , , , , , , , , , , , Subject: Re: [PATCH v8] mm,kfence: decouple kfence from page granularity mapping judgement Message-ID: <20230314111422.GB556474@hu-pkondeti-hyd.qualcomm.com> References: <1678777502-6933-1-git-send-email-quic_zhenhuah@quicinc.com> <20230314083645.GA556474@hu-pkondeti-hyd.qualcomm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01a.na.qualcomm.com (10.47.209.196) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: zQqQQnlnQ1G2CzVEoY1uaOXmMFItH-8s X-Proofpoint-ORIG-GUID: zQqQQnlnQ1G2CzVEoY1uaOXmMFItH-8s X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-14_05,2023-03-14_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 adultscore=0 priorityscore=1501 bulkscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 clxscore=1015 mlxscore=0 suspectscore=0 malwarescore=0 mlxlogscore=878 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2303140096 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: 8n99irdau1idzazf5nkmbyajtehqw6f3 X-Rspamd-Queue-Id: EC89B8001C X-HE-Tag: 1678792499-127115 X-HE-Meta: U2FsdGVkX1806bmP8ry+m7W/FXuPGPo2qxCGYO2qMGqYdcFYrh+RBKFh2p8zbjpabDOXkqqGjzUXZETeqxfiCCpdtIbgDMllNC55ihrt6No61hYC5I+VHo/nHnalI6CnZTRyXq9VfeArlKGPW/KtkGJ2B5sfgNmyEBBI1cJIKNU+fSCCZt24McDGkfJ7bubaMWpuXAa8b5CC0lXlekCzF9ybp1FikLOOMS0byAl5ufpYaV8XEjxnTC53euc8cUa7/9HXInWINdsgua9LjjeaXJtBrFi69+PorTRaqW/dkJZuX2LoyZd+C/wfK/FozHTV7t/HrEqRxv+FDBH1OJYPDVL5GVdmgdQYxQlhnDm+dBFdxgNCoQXoFfe0rQPYYdjARTYVWm0wVhszMuckgipUGsqMlxZPozLFdKJvMHniKNE1Xp1rFbEdNFmCTa6tqEYe9CwdVa1yob2H/6w1S5JZOke5BH4WTtcvTYQ2H0yzdYv/QMkLqHiJteNf0pFPf5s2AewGdg6AWKZC5zT6/IOH8ttM7KzOmiSmFwEaRcV+CV3RYOvkMWUrnsDqLa13jrrtHiqntLInMO1/Gl6qNR4DuhZzzDrRZqWVZ+1x7pzZBljdGrHBpa+7S6TwFpbKvwj15PJmWFwdlkbhyoMHwuzLd9S6GYwo2t7WRGQyANi8WlgEHpM/XU07f6TxiRbBxvNb5b1Gg5V5AfpvmF44u9O76QCVEuDqHdczHuNsyhgUBFQP/3XgAmZX2GhJCiJVKKR0yjIOWE3qOrqA+OpGNzZnQNpd5W6R0kmPOD2R51HOAaLq83CPNnA+C3+hS2VYJEA0uGppkbHx/OoKHNLgdV/EM/8pTP4C4jOArgPcu2IYRjDX6HNbRNV3qpSXfCYbmQeZ2XGzc/DySTi2MYLSnCQSHjBMHMlzxYfYG+avprxLEDZJypO08VHh5tb87aAwEF9Kh7TkoNBrOTli0GEFXLr 7JrX0mFJ e79ICOfIQcx9NNqWKnioGfUFW30pUiqJEMxovpPendDJ5PogLGaG02cZ9dtJHodZqy7tBcchqvf8zuFvmm0E+S4XIm5i83F9EYymRgr2a1JH1QL1GbmuVNehXk1/Xf1jGy7X4rLKFlwtP6jb7TuaT1P+BJODbHuln4ciJ4E6bo/w+uShWdIUPQwDNBmwxyd63E4SkQxQxd6Kve2l4u/s/DP7GgUx/HAe7//921a2iNu8Oswm6k6MylVbzYlISMga40EyIVMBxOoPykYqdH3jBCq3f4xcmSiMAwgJ8YUkdwX2XuJ4rP1KZUC/NhVoE4VZqUIGNxGcosfFs9kdWgChUB0E4qv/Zw4mcq3x9B0WNVkVvXPPKRpUNx+LSDE3fdXj753u7R/2yUhUgX1pZVjD0b5nWNQ== 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, Mar 14, 2023 at 06:08:07PM +0800, Zhenhua Huang wrote: > > > On 2023/3/14 16:36, Pavan Kondeti wrote: > > On Tue, Mar 14, 2023 at 03:05:02PM +0800, Zhenhua Huang wrote: > > > Kfence only needs its pool to be mapped as page granularity, if it is > > > inited early. Previous judgement was a bit over protected. From [1], Mark > > > suggested to "just map the KFENCE region a page granularity". So I > > > decouple it from judgement and do page granularity mapping for kfence > > > pool only. Need to be noticed that late init of kfence pool still requires > > > page granularity mapping. > > > > > > Page granularity mapping in theory cost more(2M per 1GB) memory on arm64 > > > platform. Like what I've tested on QEMU(emulated 1GB RAM) with > > > gki_defconfig, also turning off rodata protection: > > > Before: > > > [root@liebao ]# cat /proc/meminfo > > > MemTotal: 999484 kB > > > After: > > > [root@liebao ]# cat /proc/meminfo > > > MemTotal: 1001480 kB > > > > > > To implement this, also relocate the kfence pool allocation before the > > > linear mapping setting up, arm64_kfence_alloc_pool is to allocate phys > > > addr, __kfence_pool is to be set after linear mapping set up. > > > > > > LINK: [1] https://lore.kernel.org/linux-arm-kernel/Y+IsdrvDNILA59UN@FVFF77S0Q05N/ > > > Suggested-by: Mark Rutland > > > Signed-off-by: Zhenhua Huang > > > --- > > > arch/arm64/include/asm/kfence.h | 2 ++ > > > arch/arm64/mm/mmu.c | 44 +++++++++++++++++++++++++++++++++++++++++ > > > arch/arm64/mm/pageattr.c | 9 +++++++-- > > > include/linux/kfence.h | 8 ++++++++ > > > mm/kfence/core.c | 9 +++++++++ > > > 5 files changed, 70 insertions(+), 2 deletions(-) > > > > > > diff --git a/arch/arm64/include/asm/kfence.h b/arch/arm64/include/asm/kfence.h > > > index aa855c6..f1f9ca2d 100644 > > > --- a/arch/arm64/include/asm/kfence.h > > > +++ b/arch/arm64/include/asm/kfence.h > > > @@ -10,6 +10,8 @@ > > > #include > > > +extern phys_addr_t early_kfence_pool; > > > + > > > static inline bool arch_kfence_init_pool(void) { return true; } > > > static inline bool kfence_protect_page(unsigned long addr, bool protect) > > > diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c > > > index 6f9d889..7fbf2ed 100644 > > > --- a/arch/arm64/mm/mmu.c > > > +++ b/arch/arm64/mm/mmu.c > > > @@ -24,6 +24,7 @@ > > > #include > > > #include > > > #include > > > +#include > > > #include > > > #include > > > @@ -38,6 +39,7 @@ > > > #include > > > #include > > > #include > > > +#include > > > #define NO_BLOCK_MAPPINGS BIT(0) > > > #define NO_CONT_MAPPINGS BIT(1) > > > @@ -525,6 +527,33 @@ static int __init enable_crash_mem_map(char *arg) > > > } > > > early_param("crashkernel", enable_crash_mem_map); > > > +#ifdef CONFIG_KFENCE > > > + > > > +static phys_addr_t arm64_kfence_alloc_pool(void) > > > +{ > > > + phys_addr_t kfence_pool; > > > + > > > + if (!kfence_sample_interval) > > > + return 0; > > > + > > > > Are you sure that kernel commandline param are processed this early? > > AFAICS, start_kernel()->parse_args() process the kernel arguments. We > > are here before that. without your patch, mm_init() which takes care of > > allocating kfence memory is called after parse_args(). > > > > Can you check your patch with kfence.sample_interval=0 appended to > > kernel commandline? > > > > Thanks Pavan. I have tried and you're correct. Previously I thought it's > parsed by the way: > setup_arch()->parse_early_param(earlier)->parse_early_options-> > do_early_param > Unfortunately seems not take effect. > > Then the only way left is we always allocate the kfence pool early? as we > can't get sample_invertal at this early stage. > That would mean, we would allocate the kfence pool memory even when it is disabled from commandline. That does not sound good to me. Is it possible to free this early allocated memory later in mm_init()->kfence_alloc_pool()? if that is not possible, can we think of adding early param for kfence? > > > + kfence_pool = memblock_phys_alloc(KFENCE_POOL_SIZE, PAGE_SIZE); > > > + if (!kfence_pool) > > > + pr_err("failed to allocate kfence pool\n"); > > > + > > For whatever reason, if this allocation fails, what should be done? We > > end up not calling kfence_set_pool(). kfence_alloc_pool() is going to > > attempt allocation again but we did not setup page granularity. That > > means, we are enabling KFENCE without meeting pre-conditions. Can you > > check this? > > In this scenario, early_kfence_pool should be false(0) and we will end up > using page granularity mapping? should be fine IMO. > Right, I missed that hunk in can_set_direct_map(). Thanks, Pavan