Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp105459ybe; Sun, 1 Sep 2019 21:28:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqw+GZm4iZXnl8jHvQUtQ3KjJGW+8agtmqcKO98tWKTXS5Xsx5bOdOJlRv4qphT6ombxBis/ X-Received: by 2002:a65:62d7:: with SMTP id m23mr23505917pgv.358.1567398530135; Sun, 01 Sep 2019 21:28:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567398530; cv=none; d=google.com; s=arc-20160816; b=kHkB7+i318xz0kLUv8/fpeHtJh14/tTLiP7KQ1AWRJVCBWdkZxz7Upkbe89+TMoFMd 3RzH0jkN0E3VMMN4ZkI9kHSiwwKmH9+i3UA1y0PHDB0vZnQZlfg3P55ulL/F/aEXhD0/ x5judcghZuLgFu1xRw8cJVLo8lvVVcfRwaqLfoRzl0r4yu49dEIYsCYPDtT0vJBm6A0o 8uiPIXDRqGjVZZxK0D0F3P2/RmV+FItqj9DlguHyMgCQntZ8Yz7Ct17jX+Urm7cOkZ+M mdWK+56Oh5/AmKABVs+AZuAkhYRYWPX0zFrSVDGe43leeyUj2eT2twOFrPInqQKN5tXj Sceg== 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; bh=ka60UnKNtBObMl9gmMXpfn2ERhi/m9QEyHc0Ju5QkWo=; b=hDZ9o58qKzbxIxRvSSjGTmJKZN3eKV6GahCIe3GFDzgRTH9BDJczh9MjWkEk92w2xg QKEsUmIiW23D/jGCQtXH6PiaI6YzE5T3m5+viiPN3mNqr3i4e775bzkUxCcFTPpuZDbF GJsy2fUb1+Mv2o/E7Vc3GetXlTdBVYuhdMuTnWyB/7tLejFM6/bGV96W5i/5KosmgKQ3 PepBle1Iwe2wYHcOYPymOUiF67pwzUyT+k2j2IoRH56JXk0ewcAdEy/quF5eUCb5L6Bc WvwGGnRQyB7MJHuS6iyFTsodHDpzpwsB4W0QTi3Txw16OgAgkenpwqWr2r3xEaMkVusv Ko5w== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mellanox.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v41si1141669plg.65.2019.09.01.21.28.35; Sun, 01 Sep 2019 21:28:50 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mellanox.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729618AbfIBEZU (ORCPT + 99 others); Mon, 2 Sep 2019 00:25:20 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:35679 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729511AbfIBEYv (ORCPT ); Mon, 2 Sep 2019 00:24:51 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from parav@mellanox.com) with ESMTPS (AES256-SHA encrypted); 2 Sep 2019 07:24:49 +0300 Received: from sw-mtx-036.mtx.labs.mlnx (sw-mtx-036.mtx.labs.mlnx [10.12.150.149]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id x824OeRN001225; Mon, 2 Sep 2019 07:24:47 +0300 From: Parav Pandit To: alex.williamson@redhat.com, jiri@mellanox.com, kwankhede@nvidia.com, cohuck@redhat.com, davem@davemloft.net Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Parav Pandit Subject: [PATCH v3 3/5] mdev: Expose mdev alias in sysfs tree Date: Sun, 1 Sep 2019 23:24:34 -0500 Message-Id: <20190902042436.23294-4-parav@mellanox.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190902042436.23294-1-parav@mellanox.com> References: <20190826204119.54386-1-parav@mellanox.com> <20190902042436.23294-1-parav@mellanox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Expose the optional alias for an mdev device as a sysfs attribute. This way, userspace tools such as udev may make use of the alias, for example to create a netdevice name for the mdev. Updated documentation for optional read only sysfs attribute. Signed-off-by: Parav Pandit --- Changelog: v2->v3: - Merged sysfs documentation patch with sysfs addition - Added more description for alias return value v0->v1: - Addressed comments from Cornelia Huck - Updated commit description --- Documentation/driver-api/vfio-mediated-device.rst | 9 +++++++++ drivers/vfio/mdev/mdev_sysfs.c | 13 +++++++++++++ 2 files changed, 22 insertions(+) diff --git a/Documentation/driver-api/vfio-mediated-device.rst b/Documentation/driver-api/vfio-mediated-device.rst index 25eb7d5b834b..0b7d2bf843b6 100644 --- a/Documentation/driver-api/vfio-mediated-device.rst +++ b/Documentation/driver-api/vfio-mediated-device.rst @@ -270,6 +270,7 @@ Directories and Files Under the sysfs for Each mdev Device |--- remove |--- mdev_type {link to its type} |--- vendor-specific-attributes [optional] + |--- alias * remove (write only) @@ -281,6 +282,14 @@ Example:: # echo 1 > /sys/bus/mdev/devices/$mdev_UUID/remove +* alias (read only, optional) +Whenever a parent requested to generate an alias, each mdev device of such +parent is assigned unique alias by the mdev core. +This file shows the alias of the mdev device. + +Reading file either returns valid alias when assigned or returns error code +-EOPNOTSUPP when unsupported. + Mediated device Hot plug ------------------------ diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c index 43afe0e80b76..59f4e3cc5233 100644 --- a/drivers/vfio/mdev/mdev_sysfs.c +++ b/drivers/vfio/mdev/mdev_sysfs.c @@ -246,7 +246,20 @@ static ssize_t remove_store(struct device *dev, struct device_attribute *attr, static DEVICE_ATTR_WO(remove); +static ssize_t alias_show(struct device *device, + struct device_attribute *attr, char *buf) +{ + struct mdev_device *dev = mdev_from_dev(device); + + if (!dev->alias) + return -EOPNOTSUPP; + + return sprintf(buf, "%s\n", dev->alias); +} +static DEVICE_ATTR_RO(alias); + static const struct attribute *mdev_device_attrs[] = { + &dev_attr_alias.attr, &dev_attr_remove.attr, NULL, }; -- 2.19.2