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: 13131091 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3908EC636CD for ; Tue, 7 Feb 2023 06:16:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:CC :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=dxHEqjIWaz2Mio/r6JYdZWfYoycxGAoehi6kkABPkqU=; b=MbD/cik1/Ie2lT 7ZdlM3gTWNIaWr5f8lPhVbYOaMB5tX09o8PLNjuFoD5HPMK4o6RpNRuPdPfR54qMYhVvZCI67n13u rzcJAVLWtSxMLWpQ5BbjCWOij1dx+2E+lQLpErGaOtGRFYTYgnmAQoyAYn5D7JsdgUuHJ7ylr1ICA k5vTYPJu/Kuz4rc1ovyBwOUs37Rm7iIJKGPF/woh9ynHdaJvTpnMaooaG4jtw/r9/ZLUra4D0huml BKbEZgPMVa/0y00q/0gSkF9Vp91MrebFxZJi0BhAHpTvX+EYgGogRM/yQ1vb4qiyhE36pBSwCRru6 StJ+S4wwUuvRqccFCbVw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pPHGo-00AxGp-Gr; Tue, 07 Feb 2023 06:15:58 +0000 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pPHGh-00AxDf-Ee for linux-arm-kernel@lists.infradead.org; Tue, 07 Feb 2023 06:15:53 +0000 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230206_221551_639888_F4A72EC0 X-CRM114-Status: GOOD ( 19.18 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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;