From patchwork Wed Mar 15 09:43:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yicong Yang X-Patchwork-Id: 13175539 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4982C6FD1D for ; Wed, 15 Mar 2023 09:44:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231701AbjCOJoH (ORCPT ); Wed, 15 Mar 2023 05:44:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232088AbjCOJn7 (ORCPT ); Wed, 15 Mar 2023 05:43:59 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42C5D60D65; Wed, 15 Mar 2023 02:43:47 -0700 (PDT) Received: from canpemm500009.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Pc56M2svSzrT4m; Wed, 15 Mar 2023 17:42:51 +0800 (CST) Received: from localhost.localdomain (10.50.163.32) by canpemm500009.china.huawei.com (7.192.105.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Wed, 15 Mar 2023 17:43:44 +0800 From: Yicong Yang To: , , , , , CC: , , , , Subject: [PATCH 1/4] hwtracing: hisi_ptt: Make cpumask only present online CPUs Date: Wed, 15 Mar 2023 17:43:13 +0800 Message-ID: <20230315094316.26772-2-yangyicong@huawei.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20230315094316.26772-1-yangyicong@huawei.com> References: <20230315094316.26772-1-yangyicong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.50.163.32] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To canpemm500009.china.huawei.com (7.192.105.203) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Yicong Yang perf will try to start PTT trace on every CPU presented in cpumask sysfs attribute and it will fail to start on offline CPUs(see the comments in perf_event_open()). But the driver is using cpumask_of_node() to export the available cpumask which may include offline CPUs and may fail the perf unintendedly. Fix this by only export the online CPUs of the node. Fixes: ff0de066b463 ("hwtracing: hisi_ptt: Add trace function support for HiSilicon PCIe Tune and Trace device") Signed-off-by: Yicong Yang --- drivers/hwtracing/ptt/hisi_ptt.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/hwtracing/ptt/hisi_ptt.c b/drivers/hwtracing/ptt/hisi_ptt.c index 30f1525639b5..0a10c7ec46ad 100644 --- a/drivers/hwtracing/ptt/hisi_ptt.c +++ b/drivers/hwtracing/ptt/hisi_ptt.c @@ -487,9 +487,18 @@ static ssize_t cpumask_show(struct device *dev, struct device_attribute *attr, char *buf) { struct hisi_ptt *hisi_ptt = to_hisi_ptt(dev_get_drvdata(dev)); - const cpumask_t *cpumask = cpumask_of_node(dev_to_node(&hisi_ptt->pdev->dev)); + cpumask_var_t mask; + ssize_t n; - return cpumap_print_to_pagebuf(true, buf, cpumask); + if (!alloc_cpumask_var(&mask, GFP_KERNEL)) + return 0; + + cpumask_and(mask, cpumask_of_node(dev_to_node(&hisi_ptt->pdev->dev)), + cpu_online_mask); + n = cpumap_print_to_pagebuf(true, buf, mask); + free_cpumask_var(mask); + + return n; } static DEVICE_ATTR_RO(cpumask);