Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp431356pxm; Wed, 2 Mar 2022 19:16:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJyuFhxP+nB8XDi5Oq0pQBuBrm6h6qx66OsCIaNIqYmsSudjz7txxXRmROh+NX1RZ/TIlEp8 X-Received: by 2002:a63:8741:0:b0:37c:4e26:f6fe with SMTP id i62-20020a638741000000b0037c4e26f6femr2243680pge.128.1646277380276; Wed, 02 Mar 2022 19:16:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646277380; cv=none; d=google.com; s=arc-20160816; b=0DFOb9qh9aQvmwWp+g+lNU3SgMy2H3frPepBVnYeBrPa49NjYfaF2mwo5dAxA0kfw9 PENHkAwZGX1LFqC5z7OmiPmFeSBrf7/agxFxQ8DE60cNEyUaRq1H40hZ/qJdFfmUStvO 3CKU3tFptSLDxsKBdbJAftUcqbRMFGAaQH+Ck6HLaCDmvtLzgNsHoKLy4a7NkaN7rLiw rxQ+KR4tqgvU6PAZa+hGx5SwcYLjSgPiwQCdfpr3nmaxNrfoxlWj4mvmY+AOiVu4W3uK KAu9nV7vTLQ8bPwjsts0TmztWIZzhwAO/ycpbEpp54oSJkD0HfN7bcVxPx+27ZPHqRDh Qr5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=/ijYYutsxUojOe1tELAQp7k0K7hU/iWlgmSloY8X9h4=; b=T/0SSw5izcz3gfiFR+wT2W5K7a/CpvlJNtOagD+SBJyJ6GK/6mfmgehOCIuarLLcCZ 34XSNXz0tktJJgJz61OgprXRbgo0nQ9bzddIdvFay3o163Lx+el7H/Rqjw+9Jm8Ux/8b uhY+Fc5iT2LOt26bGtn4MXdQStKL+fG9q3fXI7zq2ov8ZWnI8mCpFRrXUBximaMEovJ/ DagwLoSZjua4wSk9lZ4zkOX5vA/m5F9Qb8fnYxwHFFwMLxM0I1y0WfDgng7Olx8qFiHh 51JwbINcP+SvEEWy8iaOe7bV5lDurFRizRQ5IGCMoODMmil41eYJQ4SDoF8aPjSarLbX /Zdw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id z4-20020a656644000000b0037392422940si821302pgv.746.2022.03.02.19.16.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 19:16:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B7819F65ED; Wed, 2 Mar 2022 19:15:55 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232013AbiCCDQT (ORCPT + 99 others); Wed, 2 Mar 2022 22:16:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231966AbiCCDQH (ORCPT ); Wed, 2 Mar 2022 22:16:07 -0500 Received: from out30-44.freemail.mail.aliyun.com (out30-44.freemail.mail.aliyun.com [115.124.30.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1F2DF70CD for ; Wed, 2 Mar 2022 19:15:17 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R101e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04394;MF=dtcccc@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0V650kGS_1646277314; Received: from localhost.localdomain(mailfrom:dtcccc@linux.alibaba.com fp:SMTPD_---0V650kGS_1646277314) by smtp.aliyun-inc.com(127.0.0.1); Thu, 03 Mar 2022 11:15:15 +0800 From: Tianchen Ding To: Alexander Potapenko , Marco Elver , Dmitry Vyukov , Andrew Morton Cc: kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 1/2] kfence: Allow re-enabling KFENCE after system startup Date: Thu, 3 Mar 2022 11:15:04 +0800 Message-Id: <20220303031505.28495-2-dtcccc@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220303031505.28495-1-dtcccc@linux.alibaba.com> References: <20220303031505.28495-1-dtcccc@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If once KFENCE is disabled by: echo 0 > /sys/module/kfence/parameters/sample_interval KFENCE could never be re-enabled until next rebooting. Allow re-enabling it by writing a positive num to sample_interval. Signed-off-by: Tianchen Ding --- mm/kfence/core.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/mm/kfence/core.c b/mm/kfence/core.c index 13128fa13062..19eb123c0bba 100644 --- a/mm/kfence/core.c +++ b/mm/kfence/core.c @@ -55,6 +55,7 @@ EXPORT_SYMBOL_GPL(kfence_sample_interval); /* Export for test modules. */ #endif #define MODULE_PARAM_PREFIX "kfence." +static int kfence_enable_late(void); static int param_set_sample_interval(const char *val, const struct kernel_param *kp) { unsigned long num; @@ -65,10 +66,11 @@ static int param_set_sample_interval(const char *val, const struct kernel_param if (!num) /* Using 0 to indicate KFENCE is disabled. */ WRITE_ONCE(kfence_enabled, false); - else if (!READ_ONCE(kfence_enabled) && system_state != SYSTEM_BOOTING) - return -EINVAL; /* Cannot (re-)enable KFENCE on-the-fly. */ *((unsigned long *)kp->arg) = num; + + if (num && !READ_ONCE(kfence_enabled) && system_state != SYSTEM_BOOTING) + return kfence_enable_late(); return 0; } @@ -787,6 +789,16 @@ void __init kfence_init(void) (void *)(__kfence_pool + KFENCE_POOL_SIZE)); } +static int kfence_enable_late(void) +{ + if (!__kfence_pool) + return -EINVAL; + + WRITE_ONCE(kfence_enabled, true); + queue_delayed_work(system_unbound_wq, &kfence_timer, 0); + return 0; +} + void kfence_shutdown_cache(struct kmem_cache *s) { unsigned long flags; -- 2.27.0