Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1766571rda; Tue, 24 Oct 2023 02:36:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGZJomrQ80IQY8HujhudCG2mG2AIQpxwclGiUGCm3cZGsc+5YO4YEZIZ5eWTeMxvbopeYCH X-Received: by 2002:a05:6808:10a:b0:3b2:e6a4:e177 with SMTP id b10-20020a056808010a00b003b2e6a4e177mr11765523oie.51.1698140207154; Tue, 24 Oct 2023 02:36:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698140207; cv=none; d=google.com; s=arc-20160816; b=dE3yTR+UqYSNPurKNQg9m17kgHE5S0/ceKP4kgZbF5lwlLoSx8FSxvygJoeVGLDKnk tpeibc6EwgbQaLcg2KQmqtVfdQIYhoiINBNWIfmIckvkC43JfCNzY1XKPYTwCuqG8Sp9 sAG/8WeJT5yKq6SQ2Ijn4LH+5xuk9eTDkjoi4WO81tmXgioZhywyC873sOux/KlmwwFK PxOm3bttvHzMf72vS+FmVpFq4NSkHsQBS3VseD4AeKAKvqg9eVgq2e7IPnwtglc0H2ld oX4PCGsLGCjP8+cysp7di9pnbvbdHppRGiOBX43ZdUK2deLz7R4I2V+jBzMH2f8PblFK Ryaw== 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=RGli7CCvlqgP2fK5DCKcVOhZByYxsLySSqOycW6TIoI=; fh=xoaP1/qmyEPzq9R51vMaZS6yh5pwCixcbcGH9XObUYE=; b=pMRM5Di7n7UcGIor0m6BeXN4Kj3APkoGKFBESh0qG7URXCRn+U38patYmVpOH9Dmze LzQRP6WpL9L3nL4z90+1BBK30fjr+JAAbaZ1uAB4J+asLP+gi1UrHdDeR8jYJiHSnaap 7CfXK+qV/FXZjo3pmPkwefsdx1glzXIAx1nOqQq7/mnMAWTNBt6cUnlzSnLX7QlAGVob ks7sZJ4LoX0VxoTP0qxHB8BaqTXEy6RuT7uwxhU+Zr/hclWD0lynxGIwEC9FPXvk8Ibp qlGJ+8qguFP5zie+dD4NZ8PRrEi3+yoIqrtqe4DIu7mnAbvMyPNjPe41kgJBhotN7W16 1xHQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id y7-20020a636407000000b005ae4b3f4343si7980562pgb.126.2023.10.24.02.36.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 02:36:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 11027807FD70; Tue, 24 Oct 2023 02:36:41 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234132AbjJXJee (ORCPT + 99 others); Tue, 24 Oct 2023 05:34:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234231AbjJXJdu (ORCPT ); Tue, 24 Oct 2023 05:33:50 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDE2510F1 for ; Tue, 24 Oct 2023 02:32:56 -0700 (PDT) Received: from canpemm500009.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4SF6Gg2nmRz15Nlw; Tue, 24 Oct 2023 17:30:03 +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.31; Tue, 24 Oct 2023 17:32:53 +0800 From: Yicong Yang To: , , , , CC: , , , Subject: [PATCH 1/2] drivers/perf: hisi_pcie: Check the type first in pmu::event_init() Date: Tue, 24 Oct 2023 17:29:53 +0800 Message-ID: <20231024092954.42297-2-yangyicong@huawei.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20231024092954.42297-1-yangyicong@huawei.com> References: <20231024092954.42297-1-yangyicong@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.50.163.32] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500009.china.huawei.com (7.192.105.203) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Tue, 24 Oct 2023 02:36:41 -0700 (PDT) From: Yicong Yang Check whether the event type matches the PMU type firstly in pmu::event_init() before touching the event. Otherwise we'll change the events of others and lead to incorrect results. Since in perf_init_event() we may call every pmu's event_init() in a certain case, we should not modify the event if it's not ours. Fixes: 8404b0fbc7fb ("drivers/perf: hisi: Add driver for HiSilicon PCIe PMU") Signed-off-by: Yicong Yang --- drivers/perf/hisilicon/hisi_pcie_pmu.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/perf/hisilicon/hisi_pcie_pmu.c b/drivers/perf/hisilicon/hisi_pcie_pmu.c index 5a00adb2de8c..051efffc44c8 100644 --- a/drivers/perf/hisilicon/hisi_pcie_pmu.c +++ b/drivers/perf/hisilicon/hisi_pcie_pmu.c @@ -353,6 +353,10 @@ static int hisi_pcie_pmu_event_init(struct perf_event *event) struct hisi_pcie_pmu *pcie_pmu = to_pcie_pmu(event->pmu); struct hw_perf_event *hwc = &event->hw; + /* Check the type first before going on, otherwise it's not our event */ + if (event->attr.type != event->pmu->type) + return -ENOENT; + event->cpu = pcie_pmu->on_cpu; if (EXT_COUNTER_IS_USED(hisi_pcie_get_event(event))) @@ -360,9 +364,6 @@ static int hisi_pcie_pmu_event_init(struct perf_event *event) else hwc->event_base = HISI_PCIE_CNT; - if (event->attr.type != event->pmu->type) - return -ENOENT; - /* Sampling is not supported. */ if (is_sampling_event(event) || event->attach_state & PERF_ATTACH_TASK) return -EOPNOTSUPP; -- 2.24.0