From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtpbgeu2.qq.com (smtpbgeu2.qq.com [18.194.254.142]) (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 7DE1C69D29; Tue, 2 Apr 2024 10:57:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=18.194.254.142 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712055460; cv=none; b=uUnCHmC6aTNEhsLX5tUrpNf9KYZlfvnmjFHRuXeQC4B47iiPrNEg6KMtpCmNXwvxRZTxzNgmZRsRrUqSu8zdfu5qH1DS2K6J1OxQdDZ1rQ1ERFR+pDcXz3ZnLtovTKYGyFoVECg1vmjblAegqswwAtvd8Ffqpi1SO51XnTLX0r0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712055460; c=relaxed/simple; bh=ZRYL0tm66PlUF17wSgS7t8Otxaj80Ds/bGY0ik9xez0=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=XTvdUiASRAOq2GgqjZk69B4YI/VXBud+a4Z85DfyuF8qwo7/a2yjlwN5IbGDv2pYtukNm4yVRcHj8Lh8p6aNfNy0OftExtv59dOGxPOfrjyuFrvuEGW9ukzHUEG+TOR28K+P0FQYOEwZXqWrzO1Pk1QXNOMa9S3TdfPShX8D4GM= 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=18.194.254.142 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: bizesmtpsz8t1712055389tx1i9do X-QQ-Originating-IP: npMTgiYLrAXZVfH9UzuoxN0WWf6arlNvluh0QgiuEPM= Received: from localhost ( [112.0.147.175]) by bizesmtp.qq.com (ESMTP) with id ; Tue, 02 Apr 2024 18:56:27 +0800 (CST) X-QQ-SSF: 01400000000000704000000A0000000 X-QQ-FEAT: U4uNK7LTfdrLsqLmQfZRWmU4TTRkTMv9/wdPfBCemXIxmWjsfkg+yE23RLl3O yWmO4DknxnZb8FXBxhPsu+CxpuKghtgmdZ/+TJh6K9lHe2TQubcT4IShhqebXjQGM4q3Hrj zOc1wfOasA6I5o/rp9VAxtkYDeVIfvj2UmXRBDh+Nr9d9Cp7C57Bq6dFKn0Gu4TWBFuWcYi ire/ACUxmnnxV+hEysx2faHEQDe+0cpPtVYQBYsnB7E5Yzg1ORvgFWqUvMYXw0xDajbWtPp dgRKhs7VVA0IrpYjQyFzNuVhDufUh4cU+tqhKr5jBMyFSnclf/lrBOBQf7hi+SbnlO6NFs1 BrGVJ/2WLsuWjm2WgFV1AujEFu1qVc4TvZCZzkAAEHeXXshTcix1WGHgb7bRz5/0CCacN9I X-QQ-GoodBg: 2 X-BIZMAIL-ID: 13364674971117449586 From: Dawei Li To: will@kernel.org, mark.rutland@arm.com 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 0/9] perf: Avoid explicit cpumask var allocation from stack Date: Tue, 2 Apr 2024 18:56:01 +0800 Message-Id: <20240402105610.1695644-1-dawei.li@shingroup.cn> X-Mailer: git-send-email 2.27.0 Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtpsz:shingroup.cn:qybglogicsvrgz:qybglogicsvrgz5a-1 Hi, This series try to eliminate direct cpumask var allocation from stack for perf subsystem. Direct/explicit allocation of cpumask on stack could be dangerous since it can lead to stack overflow for systems with big NR_CPUS or CONFIG_CPUMASK_OFFSTACK=y. For arm64, it's more urgent since commit 3fbd56f0e7c1 ("ARM64: Dynamically allocate cpumasks and increase supported CPUs to 512"). It's sort of a pattern that almost every cpumask var in perf subystem occurs in teardown callback of cpuhp. In which case, if dynamic allocation failed(which is unlikely), we choose return 0 rather than -ENOMEM to caller cuz: @teardown is not supposed to fail and if it does, system crashes: static int cpuhp_issue_call(int cpu, enum cpuhp_state state, bool bringup, struct hlist_node *node) { struct cpuhp_step *sp = cpuhp_get_step(state); int ret; /* * If there's nothing to do, we done. * Relies on the union for multi_instance. */ if (cpuhp_step_empty(bringup, sp)) return 0; /* * The non AP bound callbacks can fail on bringup. On teardown * e.g. module removal we crash for now. */ #ifdef CONFIG_SMP if (cpuhp_is_ap_state(state)) ret = cpuhp_invoke_ap_callback(cpu, state, bringup, node); else ret = cpuhp_invoke_callback(cpu, state, bringup, node, NULL); #else ret = cpuhp_invoke_callback(cpu, state, bringup, node, NULL); #endif BUG_ON(ret && !bringup); return ret; } Dawei Li (9): perf/alibaba_uncore_drw: Avoid explicit cpumask var allocation from stack perf/arm-cmn: Avoid explicit cpumask var allocation from stack perf/arm_cspmu: Avoid explicit cpumask var allocation from stack perf/arm_dsu: Avoid explicit cpumask var allocation from stack perf/dwc_pcie: Avoid explicit cpumask var allocation from stack perf/hisi_pcie: Avoid explicit cpumask var allocation from stack perf/hisi_uncore: Avoid explicit cpumask var allocation from stack perf/qcom_l2: Avoid explicit cpumask var allocation from stack perf/thunder_x2: Avoid explicit cpumask var allocation from stack drivers/perf/alibaba_uncore_drw_pmu.c | 13 +++++++++---- drivers/perf/arm-cmn.c | 13 +++++++++---- drivers/perf/arm_cspmu/arm_cspmu.c | 13 +++++++++---- drivers/perf/arm_dsu_pmu.c | 18 +++++++++++++----- drivers/perf/dwc_pcie_pmu.c | 17 +++++++++++------ drivers/perf/hisilicon/hisi_pcie_pmu.c | 15 ++++++++++----- drivers/perf/hisilicon/hisi_uncore_pmu.c | 13 +++++++++---- drivers/perf/qcom_l2_pmu.c | 15 ++++++++++----- drivers/perf/thunderx2_pmu.c | 20 ++++++++++++-------- 9 files changed, 92 insertions(+), 45 deletions(-) Thanks, Dawei -- 2.27.0 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 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 58AACCD1284 for ; Tue, 2 Apr 2024 10:57:49 +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=7f5GkNDf6in4gwTKUP9lyZ+NyvAS+X1nXLvHXvPc1Ns=; b=JDMDsqPbHMh6oJ Qdu2xP7dDTOJ1Tz+yFyx+hK9O59PoXk1NKijwbNGDDqyiWctHqROUwYqW5yU7Xig/KJ7VCS3Xth8D 5kZZ7AF4RZepwOxizJXXX2q8HtA2Ptjp+bIzK5V5zEAvdxYnY7Qwx8moz7pH7Lf+piiFLPFMJPBQ1 6UtSjrWxK858zwrnnvYDX+s2/2mBuRIPIl6Fpygk8hG6yrqpqasJwACWHsOmsqTe5lcRX37fXFaN8 wL24CpAZxWYD+IDfnZyDtDJLyw2dCtWQtx0FJlqEtrQdrilA/WhfRftd+93KNsJ+kGrcwVBCwmUIT d8gkRSl8ptv5dqf660uQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rrbpa-0000000Aksg-1Q0Q; Tue, 02 Apr 2024 10:57:30 +0000 Received: from smtpbg150.qq.com ([18.132.163.193]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rrbpV-0000000Akmf-4B3E for linux-arm-kernel@lists.infradead.org; Tue, 02 Apr 2024 10:57:28 +0000 X-QQ-mid: bizesmtpsz8t1712055389tx1i9do X-QQ-Originating-IP: npMTgiYLrAXZVfH9UzuoxN0WWf6arlNvluh0QgiuEPM= Received: from localhost ( [112.0.147.175]) by bizesmtp.qq.com (ESMTP) with id ; Tue, 02 Apr 2024 18:56:27 +0800 (CST) X-QQ-SSF: 01400000000000704000000A0000000 X-QQ-FEAT: U4uNK7LTfdrLsqLmQfZRWmU4TTRkTMv9/wdPfBCemXIxmWjsfkg+yE23RLl3O yWmO4DknxnZb8FXBxhPsu+CxpuKghtgmdZ/+TJh6K9lHe2TQubcT4IShhqebXjQGM4q3Hrj zOc1wfOasA6I5o/rp9VAxtkYDeVIfvj2UmXRBDh+Nr9d9Cp7C57Bq6dFKn0Gu4TWBFuWcYi ire/ACUxmnnxV+hEysx2faHEQDe+0cpPtVYQBYsnB7E5Yzg1ORvgFWqUvMYXw0xDajbWtPp dgRKhs7VVA0IrpYjQyFzNuVhDufUh4cU+tqhKr5jBMyFSnclf/lrBOBQf7hi+SbnlO6NFs1 BrGVJ/2WLsuWjm2WgFV1AujEFu1qVc4TvZCZzkAAEHeXXshTcix1WGHgb7bRz5/0CCacN9I X-QQ-GoodBg: 2 X-BIZMAIL-ID: 13364674971117449586 From: Dawei Li To: will@kernel.org, mark.rutland@arm.com 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 0/9] perf: Avoid explicit cpumask var allocation from stack Date: Tue, 2 Apr 2024 18:56:01 +0800 Message-Id: <20240402105610.1695644-1-dawei.li@shingroup.cn> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtpsz:shingroup.cn:qybglogicsvrgz:qybglogicsvrgz5a-1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240402_035726_682144_0C8DA1DB X-CRM114-Status: UNSURE ( 8.77 ) X-CRM114-Notice: Please train this message. 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi, This series try to eliminate direct cpumask var allocation from stack for perf subsystem. Direct/explicit allocation of cpumask on stack could be dangerous since it can lead to stack overflow for systems with big NR_CPUS or CONFIG_CPUMASK_OFFSTACK=y. For arm64, it's more urgent since commit 3fbd56f0e7c1 ("ARM64: Dynamically allocate cpumasks and increase supported CPUs to 512"). It's sort of a pattern that almost every cpumask var in perf subystem occurs in teardown callback of cpuhp. In which case, if dynamic allocation failed(which is unlikely), we choose return 0 rather than -ENOMEM to caller cuz: @teardown is not supposed to fail and if it does, system crashes: static int cpuhp_issue_call(int cpu, enum cpuhp_state state, bool bringup, struct hlist_node *node) { struct cpuhp_step *sp = cpuhp_get_step(state); int ret; /* * If there's nothing to do, we done. * Relies on the union for multi_instance. */ if (cpuhp_step_empty(bringup, sp)) return 0; /* * The non AP bound callbacks can fail on bringup. On teardown * e.g. module removal we crash for now. */ #ifdef CONFIG_SMP if (cpuhp_is_ap_state(state)) ret = cpuhp_invoke_ap_callback(cpu, state, bringup, node); else ret = cpuhp_invoke_callback(cpu, state, bringup, node, NULL); #else ret = cpuhp_invoke_callback(cpu, state, bringup, node, NULL); #endif BUG_ON(ret && !bringup); return ret; } Dawei Li (9): perf/alibaba_uncore_drw: Avoid explicit cpumask var allocation from stack perf/arm-cmn: Avoid explicit cpumask var allocation from stack perf/arm_cspmu: Avoid explicit cpumask var allocation from stack perf/arm_dsu: Avoid explicit cpumask var allocation from stack perf/dwc_pcie: Avoid explicit cpumask var allocation from stack perf/hisi_pcie: Avoid explicit cpumask var allocation from stack perf/hisi_uncore: Avoid explicit cpumask var allocation from stack perf/qcom_l2: Avoid explicit cpumask var allocation from stack perf/thunder_x2: Avoid explicit cpumask var allocation from stack drivers/perf/alibaba_uncore_drw_pmu.c | 13 +++++++++---- drivers/perf/arm-cmn.c | 13 +++++++++---- drivers/perf/arm_cspmu/arm_cspmu.c | 13 +++++++++---- drivers/perf/arm_dsu_pmu.c | 18 +++++++++++++----- drivers/perf/dwc_pcie_pmu.c | 17 +++++++++++------ drivers/perf/hisilicon/hisi_pcie_pmu.c | 15 ++++++++++----- drivers/perf/hisilicon/hisi_uncore_pmu.c | 13 +++++++++---- drivers/perf/qcom_l2_pmu.c | 15 ++++++++++----- drivers/perf/thunderx2_pmu.c | 20 ++++++++++++-------- 9 files changed, 92 insertions(+), 45 deletions(-) Thanks, Dawei -- 2.27.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel