Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4722882rwl; Tue, 28 Mar 2023 10:22:50 -0700 (PDT) X-Google-Smtp-Source: AKy350a9XcbP+xgegeooAXz3WoGdAeNPN0WKCt3Cfi1tKZEhdT/mW6TAKaoQpPcRM+nflwmTi2Jx X-Received: by 2002:a17:902:c943:b0:19f:1e3e:a84d with SMTP id i3-20020a170902c94300b0019f1e3ea84dmr18108960pla.64.1680024170729; Tue, 28 Mar 2023 10:22:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680024170; cv=none; d=google.com; s=arc-20160816; b=jRQzhjL5nzQBTO5nM/zN1JlVHdb/CJ+11lpN3fW/vRUY6MBwoaq8PAvJjcHA6zr+Jf uUbP32l+96pWcRI9ZzuoU80GbVBcNcv9Nk4ARZPG+jUewWvHLDOQAw278O1hmcheMMyM HGIPmatVnIVGWYIBi43R744ZYT+H4Mgy0bY0CZ9yxuJIQ0SjhucCnV1Pe+VZ0nhE7HdY D/yhD0xDJEbrBkXKID2jor7ke2/B2hb7e8wzkvcvoRxQ38uMY73T5s9WRRftLUq0lUQv L+YkIJq1diyfU4/Qwz3Msc/DkP+0Tut5W5RsPBh1iRIIbDt2lH6Rv6U74aUPXyjM8ga3 NZsQ== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=0jtm3osp22NgNELskHkUb2vE87RrTJrqJxYPTVVzvjI=; b=pbx4wWbAgu0J0S1tUpR9dtBc6SS7lOj7DSEJQL1fc2/vWa2QyjQX4B0s5x80rh5v// 7LjXpbOQ/n0gDtm9VxLbcu3vwtp9gXsTauG4h+fTxBvNJ8jqsiUBrElJu7pD7xi3Uvsh jbPzTba0aE3MD7gxzd/qYRpthnXqkoRa633rk3MzXlzoE36dWWwe6TJ4xayxL4AtcEzJ gxhf9V1vHvNg6YY3blEJ9UGhoap1KN9CHogmBYTHbnlH0mSp3FRNiGjtyDBmy84Z2Dn5 Tr0+rPvgYHb3aheEdbYF9HHWo7MmZlrSSMGtILockGUU2we9Yes83F8Lb3lnP82RPbZD 4rQQ== 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:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x5-20020a654145000000b00503005a4f2fsi28694276pgp.857.2023.03.28.10.22.14; Tue, 28 Mar 2023 10:22:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232277AbjC1RCk (ORCPT + 99 others); Tue, 28 Mar 2023 13:02:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229806AbjC1RCj (ORCPT ); Tue, 28 Mar 2023 13:02:39 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECBA0BDF2; Tue, 28 Mar 2023 10:02:37 -0700 (PDT) Received: from lhrpeml500005.china.huawei.com (unknown [172.18.147.201]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4PmGCw2Rtfz6J7dG; Wed, 29 Mar 2023 01:01:00 +0800 (CST) Received: from localhost (10.195.244.179) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Tue, 28 Mar 2023 18:02:35 +0100 Date: Tue, 28 Mar 2023 18:02:34 +0100 From: Jonathan Cameron To: Yicong Yang CC: , , , , , , , , , Subject: Re: [PATCH 3/4] hwtracing: hisi_ptt: Export available filters through sysfs Message-ID: <20230328180234.00003421@Huawei.com> In-Reply-To: <20230315094316.26772-4-yangyicong@huawei.com> References: <20230315094316.26772-1-yangyicong@huawei.com> <20230315094316.26772-4-yangyicong@huawei.com> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.195.244.179] X-ClientProxiedBy: lhrpeml100001.china.huawei.com (7.191.160.183) To lhrpeml500005.china.huawei.com (7.191.163.240) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 15 Mar 2023 17:43:15 +0800 Yicong Yang wrote: > From: Yicong Yang > > The PTT can only filter the traced TLP headers by the Root Ports or the > Requester ID of the Endpoint, which are located on the same core of the > PTT device. The filter value used is derived from the BDF number of the > supported Root Port or the Endpoint. It's not friendly enough for the > users since it requires the user to be familiar enough with the platform > and calculate the filter value manually. > > This patch export the available filters through sysfs. Each available > filters is presented as an individual file with the name of the BDF > number of the related PCIe device. The files are created under > $(PTT PMU dir)/available_root_port_filters and > $(PTT PMU dir)/available_requester_filters respectively. The filter > value can be known by reading the related file. > > Then the users can easily know the available filters for trace and get > the filter values without calculating. > > Signed-off-by: Yicong Yang Trivial comments only inline. With those answered / tidied up. Reviewed-by: Jonathan Cameron > diff --git a/drivers/hwtracing/ptt/hisi_ptt.c b/drivers/hwtracing/ptt/hisi_ptt.c > index 010cdbc3c172..a5cd87edb813 100644 > --- a/drivers/hwtracing/ptt/hisi_ptt.c > +++ b/drivers/hwtracing/ptt/hisi_ptt.c > > + > +static int hisi_ptt_init_filter_attributes(struct hisi_ptt *hisi_ptt) > +{ > + struct hisi_ptt_filter_desc *filter; > + int ret; > + > + mutex_lock(&hisi_ptt->filter_lock); > + > + list_for_each_entry(filter, &hisi_ptt->port_filters, list) { > + ret = hisi_ptt_create_filter_attr(hisi_ptt, filter); > + if (ret) > + goto err; > + } > + > + list_for_each_entry(filter, &hisi_ptt->req_filters, list) { > + ret = hisi_ptt_create_filter_attr(hisi_ptt, filter); > + if (ret) > + goto err; > + } > + > + ret = devm_add_action_or_reset(&hisi_ptt->pdev->dev, > + hisi_ptt_remove_all_filter_attributes, > + hisi_ptt); > + if (ret) > + goto err; > + > + hisi_ptt->sysfs_inited = true; err: > + mutex_unlock(&hisi_ptt->filter_lock); return ret; No need for separate exit block when nothing to do but unlock. > + return 0; > +err: > + mutex_unlock(&hisi_ptt->filter_lock); > + return ret; > +} > + > static void hisi_ptt_update_filters(struct work_struct *work) > { > struct delayed_work *delayed_work = to_delayed_work(work); > @@ -384,8 +517,28 @@ static void hisi_ptt_update_filters(struct work_struct *work) > continue; > } > > + filter->name = kstrdup(pci_name(info.pdev), GFP_KERNEL); > + if (!filter->name) { > + pci_err(hisi_ptt->pdev, "failed to add filter %s\n", > + pci_name(info.pdev)); > + kfree(filter); > + continue; > + } > + > filter->devid = devid; > filter->is_port = is_port; > + > + /* > + * If filters' sysfs entries hasn't been initialized, then > + * we're still at probe stage and leave it to handled by > + * others. > + */ > + if (hisi_ptt->sysfs_inited && Can we move this sysfs_inited check earlier? Seems silly to leave a simple check like that so late. > + hisi_ptt_create_filter_attr(hisi_ptt, filter)) { > + kfree(filter); > + continue; > + } > + > list_add_tail(&filter->list, target_list); > > if (is_port) > @@ -394,6 +547,11 @@ static void hisi_ptt_update_filters(struct work_struct *work) > list_for_each_entry(filter, target_list, list) > if (filter->devid == devid) { > list_del(&filter->list); > + > + if (hisi_ptt->sysfs_inited) > + hisi_ptt_remove_filter_attr(hisi_ptt, filter); > + > + kfree(filter->name); > kfree(filter); > break; > } > @@ -486,10 +644,12 @@ static int hisi_ptt_init_filters(struct pci_dev *pdev, void *data) > * through the log. Other functions of PTT device are still available. > */ > filter = kzalloc(sizeof(*filter), GFP_KERNEL); > - if (!filter) { > - pci_err(hisi_ptt->pdev, "failed to add filter %s\n", pci_name(pdev)); > - return -ENOMEM; > - } > + if (!filter) > + goto err_mem; > + > + filter->name = kstrdup(pci_name(pdev), GFP_KERNEL); > + if (!filter->name) > + goto err_name; > > filter->devid = PCI_DEVID(pdev->bus->number, pdev->devfn); > > @@ -504,6 +664,11 @@ static int hisi_ptt_init_filters(struct pci_dev *pdev, void *data) > } > > return 0; > +err_name: > + kfree(filter); > +err_mem: > + pci_err(hisi_ptt->pdev, "failed to add filter %s\n", pci_name(pdev)); I'd rather see a message for each of the error paths so we have some information on why. Original message wasn't great for this obviously and perhaps given they are both allocation errors it's not worth splitting them up. > + return -ENOMEM; > }