Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp172159imd; Wed, 31 Oct 2018 16:46:21 -0700 (PDT) X-Google-Smtp-Source: AJdET5ebbQ37WTy6sFN02x6e6SsGQr46E2m9OXYSNiCBTXOkBn7bSVx4wae7ajuGUG9vBTSwRl1B X-Received: by 2002:a17:902:f096:: with SMTP id go22mr5440707plb.235.1541029581827; Wed, 31 Oct 2018 16:46:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541029581; cv=none; d=google.com; s=arc-20160816; b=DT8omOOi5G8h8V/odJcDAX1VNBkE/kTA225WuGmOPonD/yg5qoAvtUlH0TmOc+ydaO vLs0eiZgHTVlHsPH8H22e4JXEEADV4rM48H2EuGy9M+cqhtI3+6zeFxYKjiM0MQTw/AX dafPgql5G434dHLEu/iu+0EbEuNNTr3F9+pINEpMOCl5B8J1TEKrxEDaKVXHc7WsrLLo GTlLnHiHjpehy/CzDAmAry59UOMAC6OHDUH0dgOcsYG9epT7FDyBswoo6IffAQf3TRgZ t8aYy6Qc+CaHcP1G9zQSLNNkLQkEL4QAj0O/ILhSwTRPcqOis+wG2peDuDHuwtJHC0xz OF1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=roxl6aXBjs6x364iA21AR/2LxmUF7ZEAl2oGiwhFIHc=; b=ErFXSwmPzQOXUaAs7esB1lVsvZXLBPXKwddrtd/t8OkrlypwDosZJdg00lxb9F2WKm VxdG2nQF14owfjNs403u9illQ/2Ko0/ZkZruDX/+HIj7sGFgTEKu5xWgP6Jnr/wEyKS1 +fauXL23noI+5jy+1frQU7yNTiEDgchGJm5rEJAh7eO+wM9bdOh1rIAyCzI7PvkrIJT3 so+mP/sHrbl1rewRHRzQb+QsrigIaWoR1hfgH8sD2LinnFxsuZeSR0Se1tE78qPmEsrO +6h4AUBNVLv/6sMCyLC0Hr1K4FC9A5zKuX1/GLifI57mxVLcGgHxIlhWnrzRZp3PWJfg 2Cgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Y1UXnOJH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o22-v6si17376092pfk.50.2018.10.31.16.46.07; Wed, 31 Oct 2018 16:46:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Y1UXnOJH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728832AbeKAIHX (ORCPT + 99 others); Thu, 1 Nov 2018 04:07:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:55056 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728646AbeKAIHV (ORCPT ); Thu, 1 Nov 2018 04:07:21 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B027F20664; Wed, 31 Oct 2018 23:07:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541027230; bh=iIBFHOFdm1uol+cnicz6GG1J/Q+oGi6a5JTQyVLqpv4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y1UXnOJHqKOUryA63O5cssspLW+W/XenPdjPSjOuCZqcp3MB4cLt7e3Hhl5VuycX6 kDgfCn5o3UY9hY16wnchXTg3tR4tOPzqUECiLLfto/JW548LniolCJSW2zRbFgduj+ pldt2+IyQg3mBnwLs3sUhRhoPOlJUBa/dWgreEEE= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Parav Pandit , Leon Romanovsky , Doug Ledford , Sasha Levin Subject: [PATCH AUTOSEL 4.19 097/146] RDMA/core: Do not expose unsupported counters Date: Wed, 31 Oct 2018 19:04:52 -0400 Message-Id: <20181031230541.28822-97-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031230541.28822-1-sashal@kernel.org> References: <20181031230541.28822-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Parav Pandit [ Upstream commit 0f6ef65d1c6ec8deb5d0f11f86631ec4cfe8f22e ] If the provider driver (such as rdma_rxe) doesn't support pma counters, avoid exposing its directory similar to optional hw_counters directory. If core fails to read the PMA counter, return an error so that user can retry later if needed. Fixes: 35c4cbb17811 ("IB/core: Create get_perf_mad function in sysfs.c") Reported-by: Holger Hoffstätte Tested-by: Holger Hoffstätte Signed-off-by: Parav Pandit Signed-off-by: Leon Romanovsky Signed-off-by: Doug Ledford Signed-off-by: Sasha Levin --- drivers/infiniband/core/sysfs.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c index 7fd14ead7b37..ace40bb98624 100644 --- a/drivers/infiniband/core/sysfs.c +++ b/drivers/infiniband/core/sysfs.c @@ -512,7 +512,7 @@ static ssize_t show_pma_counter(struct ib_port *p, struct port_attribute *attr, ret = get_perf_mad(p->ibdev, p->port_num, tab_attr->attr_id, &data, 40 + offset / 8, sizeof(data)); if (ret < 0) - return sprintf(buf, "N/A (no PMA)\n"); + return ret; switch (width) { case 4: @@ -1057,10 +1057,12 @@ static int add_port(struct ib_device *device, int port_num, goto err_put; } - p->pma_table = get_counter_table(device, port_num); - ret = sysfs_create_group(&p->kobj, p->pma_table); - if (ret) - goto err_put_gid_attrs; + if (device->process_mad) { + p->pma_table = get_counter_table(device, port_num); + ret = sysfs_create_group(&p->kobj, p->pma_table); + if (ret) + goto err_put_gid_attrs; + } p->gid_group.name = "gids"; p->gid_group.attrs = alloc_group_attrs(show_port_gid, attr.gid_tbl_len); @@ -1173,7 +1175,8 @@ static int add_port(struct ib_device *device, int port_num, p->gid_group.attrs = NULL; err_remove_pma: - sysfs_remove_group(&p->kobj, p->pma_table); + if (p->pma_table) + sysfs_remove_group(&p->kobj, p->pma_table); err_put_gid_attrs: kobject_put(&p->gid_attr_group->kobj); @@ -1285,7 +1288,9 @@ static void free_port_list_attributes(struct ib_device *device) kfree(port->hw_stats); free_hsag(&port->kobj, port->hw_stats_ag); } - sysfs_remove_group(p, port->pma_table); + + if (port->pma_table) + sysfs_remove_group(p, port->pma_table); sysfs_remove_group(p, &port->pkey_group); sysfs_remove_group(p, &port->gid_group); sysfs_remove_group(&port->gid_attr_group->kobj, -- 2.17.1