From patchwork Tue Feb 7 06:15:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhenhua Huang X-Patchwork-Id: 13131090 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 21787C636CC for ; Tue, 7 Feb 2023 06:15:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7A4FC6B0088; Tue, 7 Feb 2023 01:15:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 753F76B0089; Tue, 7 Feb 2023 01:15:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 61C3D6B008A; Tue, 7 Feb 2023 01:15:48 -0500 (EST) 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 4F8826B0088 for ; Tue, 7 Feb 2023 01:15:48 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 1847940621 for ; Tue, 7 Feb 2023 06:15:48 +0000 (UTC) X-FDA: 80439484776.12.5CF1A7C Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf06.hostedemail.com (Postfix) with ESMTP id 0810E180016 for ; Tue, 7 Feb 2023 06:15:45 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=XelR0aUu; spf=pass (imf06.hostedemail.com: domain of quic_zhenhuah@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_zhenhuah@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=1675750546; 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: references:dkim-signature; bh=ahSOaZLW0WfU8QSzkAJl31MTwihbALzXfbI2inq+j3A=; b=fzKwOOvitYwa8BPdwJNxETqXtQoSAWtuRdc9gEq+nuHOKCSengMSaptv7PpfoZTAlSTzmm 3yVjustA5Ii85NCndyz2GWWHpEDu9u1c0X0W9o40zVN/kBoH5kT26k8D6mEhi2H9h9offK s+GSKVI0l7IxlabhtyGDhQjy6qrEf44= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=XelR0aUu; spf=pass (imf06.hostedemail.com: domain of quic_zhenhuah@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_zhenhuah@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675750546; a=rsa-sha256; cv=none; b=Uw8HRc7Y5E3IPaq45D8i+mj0riBgLJ7LfDGg1lpHv3ffRljX0WBeuYUN0jgbEESMBSc+ah bOHm1oIa9+5Bcv+gPWpzt2B8uX59zoc1h5T1e/MISWASusimnM4NbJu5U+JJxk0SFQDkgy rCu/eKAQVlZG4Y3un96c3ORVAmPecYY= Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3174MW8L030490; Tue, 7 Feb 2023 06:15:33 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=qcppdkim1; bh=ahSOaZLW0WfU8QSzkAJl31MTwihbALzXfbI2inq+j3A=; b=XelR0aUueAEKtNrod7Ke5F81Yro38CZqNMr7RUEAahGUflnScXtqQjr5/QsgXZZz0xgj VZ4r1Re64dYA/OfipinQ+g5hZ4271P1+EOpq8Oxot9uB9BxWhT/LOZSIY7a/xumDgpd/ Me9+UgRJMbabeXD9UM4kWubT0ro8KEW8AcE46ikeYeH8o8RX+wDGJ90XSCCbpqnWTimO VJ3f3Ie6Ueit+vwbczFS01pJP/jVsSs4e9H2GlqXKwRdAODMRTEeNqh/c9ud/iSoDfB7 0UD6fNpl4lzxKamxGjgxMW2lKGGr1AjURcpuLKCqT4HKeESxerKF2MHmyfS+9veiC8C3 Mg== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3nkdun8egw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 07 Feb 2023 06:15:33 +0000 Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3176FV64025738 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 7 Feb 2023 06:15:31 GMT Received: from zhenhuah-gv.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.36; Mon, 6 Feb 2023 22:15:29 -0800 From: Zhenhua Huang To: , , , , CC: Zhenhua Huang , , Subject: [PATCH] mm: kfence: export kfence_enabled as global variables Date: Tue, 7 Feb 2023 14:15:19 +0800 Message-ID: <1675750519-1064-1-git-send-email-quic_zhenhuah@quicinc.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 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: q0MtS_0qyqfiALi47NrsNb6hdL8Nu4pq X-Proofpoint-ORIG-GUID: q0MtS_0qyqfiALi47NrsNb6hdL8Nu4pq X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-02-06_07,2023-02-06_03,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 phishscore=0 priorityscore=1501 mlxlogscore=957 bulkscore=0 clxscore=1011 malwarescore=0 spamscore=0 adultscore=0 lowpriorityscore=0 impostorscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302070055 X-Stat-Signature: 5fb3j8xq1d8prcc9fjddibj14t6jjt8q X-Rspam-User: X-Rspamd-Queue-Id: 0810E180016 X-Rspamd-Server: rspam06 X-HE-Tag: 1675750545-161903 X-HE-Meta: U2FsdGVkX1+KR/XVUBR1cPTJVrXzy7RcfJGsG4cKt9fzec6IX2C2kusNaoP2kiEVzMUZTfsp/+v2P3itETVdKQvO7hUSZoAnf66GRvDga0QfTmqwpyPcETdHbHORTOAoRZbD3RU5xHD8ymAfnpguRQKmXLbb+L+GW03Dh++jntQeirrgQoG8VJdvu2bCN9cKnb3H5QCCs3rqg2ljcmsQr9dlnMrU8NyrZD9WLN4p5a+EpJd+7LDhfKZkNtQa1I4608iYfTidm9mvOc/SHqEGn60WzIY91Mq+GVSr+ZsSHBVTjcai9YNbJP296pUVtAHNI/DOTNG3YRFnQHSD6ZwvP3QtoWS3OWWyyK+ZMx3jnL6NNrJGL2w+x692THapS4K2SQdlWXq6x2wQEyNQiugpFCH0TFeEtoJJIOJyvyT8xlCmzlR2t+N30JGdKTGUc8pcCdUlexZ26KE1IExiPpJMX7n9nh0h0024txGa3ygSyK5AbxZSQ1FfX4Ijn+jjT8LsIuHniJPRC4gfmg2sWJDi1/JuYZ+2EG6LvurIWt2SJ90gwraAj0+VyMYcDyyykpT0mQ0i8hDd9DsNuP8zMHL62u241poXgLmePnfAglmONrbOLHSnhegTJt/AXCS4IqXe4uNlwtSO5+yYEwkXErtmjuRMCEQ3ARjX4TarQZSLPNf5ZwRlIKzj4fpPLlPTcpABcmA+8jnCTTYwt+3l1M9qJXaBRdujdhvVEPQyzc57qu0fhjSdVPBw6lfUQUw9Vxvs3ord1ezaCBfHfAMAfVd+amQBf6erSUcL8yvNyj6xsNJHKggh8kM2lwm4JqzlaQgmY+OcK0VcW/i1g3ylRD9pwJ3UlAxxfBzCw9P4p3ZuEqmaYFfjlyzpAukI+j1DFp8/6dwMAQNZfEhOJk95N3cvBJdGwGm5bJI9+vD2zT7FSwLyak74ITv8jCOTl89xMgY8bP//RsH0JfcSRoKrjNf 5wAmhrQo rmbI53mqqhUdgqnEBE5qJb+8hhlPLu8D1aM6Uq0zJPXhP3wn5k6WGZHuP20ND6L0MTmsUNBZg79KOjTT1FqKzSlMRcBKP95Qt3JnBn3p+Fx8I24v2PszMWtlxCj75uuN0/3o5Qxp+xNpDOAK/T9s200d8DVahgxFp0Xd2RrYPzEGophrxQCL3Qx2vQlaLsQQhdR9gnWVSDC+Llb6UX3la488Fs+BT8KzMKjG5vPNNpmnbbKinFocNwKQ4hV4Xw+K3SW5UuQrTnIs+GETK2bqEI+d7gMoceKZ8b9iiVAM4uIHM2vvyA0e6f9NjqTvLlidkZGYX 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: 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; } static int change_page_range(pte_t *ptep, unsigned long addr, void *data) diff --git a/include/linux/kfence.h b/include/linux/kfence.h index 726857a..9fac824 100644 --- a/include/linux/kfence.h +++ b/include/linux/kfence.h @@ -26,6 +26,7 @@ extern unsigned long kfence_sample_interval; */ #define KFENCE_POOL_SIZE ((CONFIG_KFENCE_NUM_OBJECTS + 1) * 2 * PAGE_SIZE) extern char *__kfence_pool; +extern bool kfence_enabled; DECLARE_STATIC_KEY_FALSE(kfence_allocation_key); extern atomic_t kfence_allocation_gate; @@ -222,6 +223,7 @@ bool __kfence_obj_info(struct kmem_obj_info *kpp, void *object, struct slab *sla #else /* CONFIG_KFENCE */ +#define kfence_enabled 0 static inline bool is_kfence_address(const void *addr) { return false; } static inline void kfence_alloc_pool(void) { } static inline void kfence_init(void) { } diff --git a/mm/kfence/core.c b/mm/kfence/core.c index 5349c37..e5bf93d 100644 --- a/mm/kfence/core.c +++ b/mm/kfence/core.c @@ -48,7 +48,7 @@ /* === Data ================================================================= */ -static bool kfence_enabled __read_mostly; +bool kfence_enabled __read_mostly; static bool disabled_by_warn __read_mostly; unsigned long kfence_sample_interval __read_mostly = CONFIG_KFENCE_SAMPLE_INTERVAL;