lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 11 Nov 2022 22:27:22 +0800
From:   "Longpeng(Mike)" <longpeng2@...wei.com>
To:     <bhelgaas@...gle.com>
CC:     <linux-pci@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
        <jianjay.zhou@...wei.com>, <zhuangshengen@...wei.com>,
        <arei.gonglei@...wei.com>, <yechuan@...wei.com>,
        <huangzhichao@...wei.com>, <xiehong@...wei.com>,
        Longpeng <longpeng2@...wei.com>
Subject: [RFC 4/4] pci/sriov: add sriov_scan_vf_id interface

From: Longpeng <longpeng2@...wei.com>

The users can add a specific VF through the sriov_scan_vf_id interface.

For example:
 echo 4 > /sys/bus/pci/devices/0000\:65\:00.0/sriov_scan_vf_id
 ( Add VF4 into the system. )

Signed-off-by: Longpeng <longpeng2@...wei.com>
---
 drivers/pci/iov.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index cb24d4b60e0d..2b585b3a9ad8 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -553,6 +553,51 @@ static ssize_t sriov_numvfs_no_scan_show(struct device *dev,
 	return sriov_numvfs_show(dev, attr, buf);
 }
 
+static ssize_t sriov_scan_vf_id_store(struct device *dev,
+				      struct device_attribute *attr,
+				      const char *buf, size_t count)
+{
+	struct pci_dev *pdev = to_pci_dev(dev);
+	u16 vf_id;
+	ssize_t ret;
+
+	if (kstrtou16(buf, 0, &vf_id) < 0)
+		return -EINVAL;
+
+	device_lock(&pdev->dev);
+
+	if (!pdev->sriov->num_VFs) {
+		ret = -ENOENT;
+		goto exit;
+	}
+
+	if (vf_id >= pdev->sriov->num_VFs) {
+		ret = -ENODEV;
+		goto exit;
+	}
+
+	if (test_bit(vf_id, pdev->sriov->vf_bitmap)) {
+		ret = -EEXIST;
+		goto exit;
+	}
+
+	device_unlock(&pdev->dev);
+
+	/* Already scanned VF0 when enabling VFs */
+	if (vf_id == 0)
+		return count;
+
+	ret = pci_iov_add_virtfn(pdev, vf_id);
+	if (ret < 0)
+		return ret;
+
+	return count;
+
+exit:
+	device_unlock(&pdev->dev);
+	return ret;
+}
+
 static ssize_t sriov_offset_show(struct device *dev,
 				 struct device_attribute *attr,
 				 char *buf)
@@ -607,6 +652,7 @@ static ssize_t sriov_drivers_autoprobe_store(struct device *dev,
 static DEVICE_ATTR_RO(sriov_totalvfs);
 static DEVICE_ATTR_RW(sriov_numvfs);
 static DEVICE_ATTR_RW(sriov_numvfs_no_scan);
+static DEVICE_ATTR_WO(sriov_scan_vf_id);
 static DEVICE_ATTR_RO(sriov_offset);
 static DEVICE_ATTR_RO(sriov_stride);
 static DEVICE_ATTR_RO(sriov_vf_device);
@@ -616,6 +662,7 @@ static struct attribute *sriov_pf_dev_attrs[] = {
 	&dev_attr_sriov_totalvfs.attr,
 	&dev_attr_sriov_numvfs.attr,
 	&dev_attr_sriov_numvfs_no_scan.attr,
+	&dev_attr_sriov_scan_vf_id.attr,
 	&dev_attr_sriov_offset.attr,
 	&dev_attr_sriov_stride.attr,
 	&dev_attr_sriov_vf_device.attr,
-- 
2.23.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ