Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2687812lqz; Wed, 3 Apr 2024 06:02:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXVB73R/0phSbRd2ExL9pPgxQwL3J6rPCz76R5WMv/95CmBtqjAMTEOQz2gp8bEHDkI1gBY8wRSxmRAGIPK3MFf/hk5rVROqRI2NNLGGA== X-Google-Smtp-Source: AGHT+IHP+LE/Dov5Ofs/d/03StvwKmwhqnyHWSa+IADrOs4hx14MXAV/MdfXrGJMczM1s1yEj5Pe X-Received: by 2002:a05:6402:2794:b0:56b:d9b0:f1c3 with SMTP id b20-20020a056402279400b0056bd9b0f1c3mr2347052ede.39.1712149356311; Wed, 03 Apr 2024 06:02:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712149356; cv=pass; d=google.com; s=arc-20160816; b=RpbJSY/B6pNK5dZfsHoBPITKmjpPvFuRoNb5fmED72R1T9f4p06EMndn04ZZyAYoYo nbiPYVovcpDDe5UjwjgfUIlUJy+YbeAX9UkzPpn4xvXdxxQvQfclm9KGUjbs5LyBOPFc aWIK8VYT+Gz1RkWctH+Ji4rkXJnbpFx1l/1ZlqkmoSVChFEz+O+uTMbC/yeDIP70hagS 6bAInSTYnqh005lt70L7Jx1tS8hRRIjnOY55XbnLa2YPcH5fz6w/bWP7HE+8hLpmeBmD sMDA7Rm7pa+eFENBW5fj/1BqKCcGVYWKI0uZKD6W8yjBqOwPHqO9wLol193kkBE7gcNR H+4g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=feedback-id:content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=edj1rFrGCwWnAEc/RTjjyPVbQtJjaOY+zxBS7BPSBgc=; fh=K1EjY/iDKwuQSBahFsPqCvcaIzvvxPUGKK+WBDBIaaQ=; b=bITiDNGs9sYiy2l3j+hfmpQXmm4H/7oCOcg7Hmxck9Qo5asIY1OAXuPRXO1ZE9nRED 2Q0LBrsKgamW+u1CJebJKXBkC3CE2nCUu1i4+4ltU63MRgKsU+pPERl3QK0qvDMbjcbk byA2HEDiBvHqI00tXikfGhprMoJdMc67w+VlAQwCuda1KK7z9Ee8n5Id4oYYirj7MYE1 AP6qUknv7qyLpYM5jjpquN6nYtIl48XQ2J5geD8tuSF+HCgOV5gUuvxRc2j/eZZwr611 ic2Q+sEkY8QrSsyYw0ASpBrFGGNRkacjinomVqLLKiicZoG/W/H7DIwDHt0N9XAp9i7Z EaWA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=shingroup.cn dmarc=pass fromdomain=shingroup.cn); spf=pass (google.com: domain of linux-kernel+bounces-129759-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-129759-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=shingroup.cn Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id b7-20020a056402278700b0056c181add45si6737174ede.489.2024.04.03.06.02.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 06:02:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-129759-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=shingroup.cn dmarc=pass fromdomain=shingroup.cn); spf=pass (google.com: domain of linux-kernel+bounces-129759-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-129759-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=shingroup.cn Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 470F71F287C7 for ; Wed, 3 Apr 2024 12:56:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AE531146D4A; Wed, 3 Apr 2024 12:54:38 +0000 (UTC) Received: from smtpbgau2.qq.com (smtpbgau2.qq.com [54.206.34.216]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F667148841; Wed, 3 Apr 2024 12:54:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=54.206.34.216 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712148878; cv=none; b=DPGm7ed+xBgVUMAWKb2LS+axm7uTaRZILNajLawIi4VbIj+/a7xhtuwPrnFZLI7eIh5p17FNiKpaLthzeVUUqN10dCnID7shnLBct/TuYgJOYv8cxs9Ll7PLxsIMAN1J1MggVzd7cCtYgP+pG08URx8zRTv3H2sLv0awMtatQpA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712148878; c=relaxed/simple; bh=YPbYnG00R6gzJY3wQosCsmzl+ZE2k9Rcp+wAlH+Q/vQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KqCC14rph7n3a/navJUIStgHlsyCRizq3WyV3sDU+RRYvZHvZ2sXDUWQ1GZpUc4DDmfIpdiGFnNl+JXgZSBqcmWd2dEFCBoVZ3gtI4hZ8PLsA63obxnG94TnIzrShmI4HPYUmj0PVQ9bj/Td0Ey7v5JG9fOrA0x439TwEjNnIhk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=shingroup.cn; spf=pass smtp.mailfrom=shingroup.cn; arc=none smtp.client-ip=54.206.34.216 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=shingroup.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=shingroup.cn X-QQ-mid: bizesmtp79t1712148775teye1u3j X-QQ-Originating-IP: xdXNA6zp8ZSrFbbqKwC7auWvxA+9gSLqEpXCtDjvsc8= Received: from localhost ( [112.0.147.175]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 03 Apr 2024 20:52:54 +0800 (CST) X-QQ-SSF: 01400000000000704000000A0000000 X-QQ-FEAT: RmQi6iQXyoPI3227xPNYQoydQAD/PwEqenSojQohu5757FSm3x7ceIiKbAVGu 412DzCp1YWMrlYllY6gv9ImMEfEWAD5DsWbtLmD1KDWtDGmFg2aMGLi0Zj5JQVC+1aXtngL u2nerBQMgjZ1JaIt5LAA20jmq5u0EV9XnXuTDItDmDBcZMz4dhmUgaEr7djBrbtW95ZRsN6 2f4bQNLDOB527dcnzaBSi5y/7qjTjHKvftRFlJ8z/GdorcYD1HH7QedXtJNW2Neb7QNAhuz 0hoK/CAOWuZzThYCMs1Hl3aalSKlRTobx5IxOE3giObFjp5Pno08NUN7R6YKJ/M7KoeAmOe m83vrEBDYEwqYIdXMIB/n5acoCF4TyirSZKmSVzR45oKz6Tff4ZyjojIOaUh6Mu1e8xgmpb 27ARI95bBrMpObXtXUtTNG3idfP/MYs+ X-QQ-GoodBg: 2 X-BIZMAIL-ID: 4365670256005717423 From: Dawei Li To: will@kernel.org, mark.rutland@arm.com, yury.norov@gmail.com, linux@rasmusvillemoes.dk Cc: xueshuai@linux.alibaba.com, renyu.zj@linux.alibaba.com, yangyicong@hisilicon.com, jonathan.cameron@huawei.com, andersson@kernel.org, konrad.dybcio@linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Dawei Li Subject: [PATCH v2 09/10] perf/qcom_l2: Avoid placing cpumask var on stack Date: Wed, 3 Apr 2024 20:51:08 +0800 Message-Id: <20240403125109.2054881-10-dawei.li@shingroup.cn> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240403125109.2054881-1-dawei.li@shingroup.cn> References: <20240403125109.2054881-1-dawei.li@shingroup.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:shingroup.cn:qybglogicsvrgz:qybglogicsvrgz5a-1 For CONFIG_CPUMASK_OFFSTACK=y kernel, explicit allocation of cpumask variable on stack is not recommended since it can cause potential stack overflow. Instead, kernel code should always use *cpumask_var API(s) to allocate cpumask var in config-neutral way, leaving allocation strategy to CONFIG_CPUMASK_OFFSTACK. But dynamic allocation in cpuhp's teardown callback is somewhat problematic for if allocation fails(which is unlikely but still possible): - If -ENOMEM is returned to caller, kernel crashes for non-bringup teardown; - If callback pretends nothing happened and returns 0 to caller, it may trap system into an in-consisitent/compromised state; Use newly-introduced cpumask_any_and_but() to address all issues above. It eliminates usage of temporary cpumask var in generic way, no matter how the cpumask var is allocated. Suggested-by: Mark Rutland Signed-off-by: Dawei Li --- drivers/perf/qcom_l2_pmu.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/perf/qcom_l2_pmu.c b/drivers/perf/qcom_l2_pmu.c index 148df5ae8ef8..b5a44dc1dc3a 100644 --- a/drivers/perf/qcom_l2_pmu.c +++ b/drivers/perf/qcom_l2_pmu.c @@ -801,9 +801,8 @@ static int l2cache_pmu_online_cpu(unsigned int cpu, struct hlist_node *node) static int l2cache_pmu_offline_cpu(unsigned int cpu, struct hlist_node *node) { - struct cluster_pmu *cluster; struct l2cache_pmu *l2cache_pmu; - cpumask_t cluster_online_cpus; + struct cluster_pmu *cluster; unsigned int target; l2cache_pmu = hlist_entry_safe(node, struct l2cache_pmu, node); @@ -820,9 +819,8 @@ static int l2cache_pmu_offline_cpu(unsigned int cpu, struct hlist_node *node) cluster->on_cpu = -1; /* Any other CPU for this cluster which is still online */ - cpumask_and(&cluster_online_cpus, &cluster->cluster_cpus, - cpu_online_mask); - target = cpumask_any_but(&cluster_online_cpus, cpu); + target = cpumask_any_and_but(&cluster->cluster_cpus, + cpu_online_mask, cpu); if (target >= nr_cpu_ids) { disable_irq(cluster->irq); return 0; -- 2.27.0