All of lore.kernel.org
 help / color / mirror / Atom feed
From: Parav Pandit <parav@nvidia.com>
To: <virtualization@lists.linux-foundation.org>
Cc: elic@nvidia.com, mst@redhat.com
Subject: [PATCH linux-next v3 3/6] vdpa: Enable user to set mac and mtu of vdpa device
Date: Wed, 16 Jun 2021 22:11:52 +0300	[thread overview]
Message-ID: <20210616191155.102303-4-parav@nvidia.com> (raw)
In-Reply-To: <20210616191155.102303-1-parav@nvidia.com>

$ vdpa dev add name bar mgmtdev vdpasim_net

$ vdpa dev config set bar mac 00:11:22:33:44:55 mtu 9000

$ vdpa dev config show
bar: mac 00:11:22:33:44:55 link up link_announce false mtu 9000 speed 0 duplex 0

$ vdpa dev config show -jp
{
    "config": {
        "bar": {
            "mac": "00:11:22:33:44:55",
            "link ": "up",
            "link_announce ": false,
            "mtu": 9000,
            "speed": 0,
            "duplex": 0
        }
    }
}

Signed-off-by: Parav Pandit <parav@nvidia.com>
Reviewed-by: Eli Cohen <elic@nvidia.com>
---
changelog:
v2->v3:
 - using new setup_config callback to setup device params via mgmt tool
   to avoid mixing with existing set_config().
---
 drivers/vdpa/vdpa.c       | 91 ++++++++++++++++++++++++++++++++++++++-
 include/linux/vdpa.h      | 18 ++++++++
 include/uapi/linux/vdpa.h |  1 +
 3 files changed, 109 insertions(+), 1 deletion(-)

diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c
index 1295528244c3..40874bd92126 100644
--- a/drivers/vdpa/vdpa.c
+++ b/drivers/vdpa/vdpa.c
@@ -14,7 +14,6 @@
 #include <uapi/linux/vdpa.h>
 #include <net/genetlink.h>
 #include <linux/mod_devicetable.h>
-#include <linux/virtio_net.h>
 #include <linux/virtio_ids.h>
 
 static LIST_HEAD(mdev_head);
@@ -849,10 +848,94 @@ vdpa_nl_cmd_dev_config_get_dumpit(struct sk_buff *msg, struct netlink_callback *
 	return msg->len;
 }
 
+static int vdpa_dev_net_config_set(struct vdpa_device *vdev,
+				   struct sk_buff *skb, struct genl_info *info)
+{
+	struct nlattr **nl_attrs = info->attrs;
+	struct vdpa_dev_set_config config = {};
+	const u8 *macaddr;
+	int err;
+
+	if (!netlink_capable(skb, CAP_NET_ADMIN))
+		return -EPERM;
+
+	if (!vdev->config->setup_config)
+		return -EOPNOTSUPP;
+
+	if (nl_attrs[VDPA_ATTR_DEV_NET_CFG_MACADDR]) {
+		macaddr = nla_data(nl_attrs[VDPA_ATTR_DEV_NET_CFG_MACADDR]);
+		memcpy(config.net.mac, macaddr, sizeof(config.net.mac));
+		config.net_mask.mac_valid = true;
+	}
+	if (nl_attrs[VDPA_ATTR_DEV_NET_CFG_MTU]) {
+		config.net.mtu =
+			nla_get_u16(nl_attrs[VDPA_ATTR_DEV_NET_CFG_MTU]);
+		config.net_mask.mtu_valid = true;
+	}
+
+	mutex_lock(&vdev->cf_mutex);
+	err = vdev->config->setup_config(vdev, &config);
+	mutex_unlock(&vdev->cf_mutex);
+	return err;
+}
+
+static int vdpa_dev_config_set(struct vdpa_device *vdev, struct sk_buff *skb,
+			       struct genl_info *info)
+{
+	int err = -EOPNOTSUPP;
+	u32 device_id;
+
+	if (!vdev->mdev)
+		return -EOPNOTSUPP;
+
+	device_id = vdev->config->get_device_id(vdev);
+	switch (device_id) {
+	case VIRTIO_ID_NET:
+		err = vdpa_dev_net_config_set(vdev, skb, info);
+		break;
+	default:
+		break;
+	}
+	return err;
+}
+
+static int vdpa_nl_cmd_dev_config_set_doit(struct sk_buff *skb, struct genl_info *info)
+{
+	struct vdpa_device *vdev;
+	const char *devname;
+	struct device *dev;
+	int err;
+
+	if (!info->attrs[VDPA_ATTR_DEV_NAME])
+		return -EINVAL;
+	devname = nla_data(info->attrs[VDPA_ATTR_DEV_NAME]);
+
+	mutex_lock(&vdpa_dev_mutex);
+	dev = bus_find_device(&vdpa_bus, NULL, devname, vdpa_name_match);
+	if (!dev) {
+		mutex_unlock(&vdpa_dev_mutex);
+		NL_SET_ERR_MSG_MOD(info->extack, "device not found");
+		return -ENODEV;
+	}
+	vdev = container_of(dev, struct vdpa_device, dev);
+	if (!vdev->mdev) {
+		mutex_unlock(&vdpa_dev_mutex);
+		put_device(dev);
+		return -EINVAL;
+	}
+	err = vdpa_dev_config_set(vdev, skb, info);
+	put_device(dev);
+	mutex_unlock(&vdpa_dev_mutex);
+	return err;
+}
+
 static const struct nla_policy vdpa_nl_policy[VDPA_ATTR_MAX + 1] = {
 	[VDPA_ATTR_MGMTDEV_BUS_NAME] = { .type = NLA_NUL_STRING },
 	[VDPA_ATTR_MGMTDEV_DEV_NAME] = { .type = NLA_STRING },
 	[VDPA_ATTR_DEV_NAME] = { .type = NLA_STRING },
+	[VDPA_ATTR_DEV_NET_CFG_MACADDR] = NLA_POLICY_ETH_ADDR,
+	/* virtio spec 1.1 section 5.1.4.1 for valid MTU range */
+	[VDPA_ATTR_DEV_NET_CFG_MTU] = NLA_POLICY_MIN(NLA_U16, 68),
 };
 
 static const struct genl_ops vdpa_nl_ops[] = {
@@ -886,6 +969,12 @@ static const struct genl_ops vdpa_nl_ops[] = {
 		.doit = vdpa_nl_cmd_dev_config_get_doit,
 		.dumpit = vdpa_nl_cmd_dev_config_get_dumpit,
 	},
+	{
+		.cmd = VDPA_CMD_DEV_CONFIG_SET,
+		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
+		.doit = vdpa_nl_cmd_dev_config_set_doit,
+		.flags = GENL_ADMIN_PERM,
+	},
 };
 
 static struct genl_family vdpa_nl_family __ro_after_init = {
diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h
index bf104f9f461a..9b7238d5310e 100644
--- a/include/linux/vdpa.h
+++ b/include/linux/vdpa.h
@@ -6,6 +6,8 @@
 #include <linux/device.h>
 #include <linux/interrupt.h>
 #include <linux/vhost_iotlb.h>
+#include <linux/virtio_net.h>
+#include <linux/if_ether.h>
 
 /**
  * struct vdpa_calllback - vDPA callback definition.
@@ -70,6 +72,17 @@ struct vdpa_iova_range {
 	u64 last;
 };
 
+struct vdpa_dev_set_config {
+	struct {
+		u8 mac[ETH_ALEN];
+		u16 mtu;
+	} net;
+	struct {
+		u8 mac_valid: 1;
+		u8 mtu_valid: 1;
+	} net_mask;
+};
+
 /**
  * struct vdpa_config_ops - operations for configuring a vDPA device.
  * Note: vDPA device drivers are required to implement all of the
@@ -169,6 +182,9 @@ struct vdpa_iova_range {
  *				@buf: buffer used to write from
  *				@len: the length to write to
  *				configuration space
+ * @setup_config:		Setup configuration space
+ *				@vdev: vdpa device
+ *				#config: configuration to apply to device
  * @get_generation:		Get device config generation (optional)
  *				@vdev: vdpa device
  *				Returns u32: device generation
@@ -241,6 +257,8 @@ struct vdpa_config_ops {
 			   void *buf, unsigned int len);
 	void (*set_config)(struct vdpa_device *vdev, unsigned int offset,
 			   const void *buf, unsigned int len);
+	int (*setup_config)(struct vdpa_device *vdev,
+			    const struct vdpa_dev_set_config *config);
 	u32 (*get_generation)(struct vdpa_device *vdev);
 	struct vdpa_iova_range (*get_iova_range)(struct vdpa_device *vdev);
 
diff --git a/include/uapi/linux/vdpa.h b/include/uapi/linux/vdpa.h
index 5c31ecc3b956..ec349789b8d1 100644
--- a/include/uapi/linux/vdpa.h
+++ b/include/uapi/linux/vdpa.h
@@ -18,6 +18,7 @@ enum vdpa_command {
 	VDPA_CMD_DEV_DEL,
 	VDPA_CMD_DEV_GET,		/* can dump */
 	VDPA_CMD_DEV_CONFIG_GET,	/* can dump */
+	VDPA_CMD_DEV_CONFIG_SET,
 };
 
 enum vdpa_attr {
-- 
2.26.2

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

  parent reply	other threads:[~2021-06-16 19:12 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-16 19:11 [PATCH linux-next v3 0/6] vdpa: enable user to set mac, mtu Parav Pandit
2021-06-16 19:11 ` [PATCH linux-next v3 1/6] vdpa: Introduce and use vdpa device get, set config helpers Parav Pandit
2021-06-22  7:08   ` Jason Wang
2021-06-16 19:11 ` [PATCH linux-next v3 2/6] vdpa: Introduce query of device config layout Parav Pandit
2021-06-22  7:20   ` Jason Wang
2021-06-22 14:03     ` Parav Pandit
2021-06-23  4:08       ` Jason Wang
2021-06-23  4:22         ` Parav Pandit
2021-06-24  5:43           ` Jason Wang
2021-06-24  6:29             ` Parav Pandit
2021-06-24  7:05               ` Jason Wang
2021-06-24  7:59                 ` Parav Pandit
2021-06-25  3:28                   ` Jason Wang
2021-06-25  6:45                     ` Parav Pandit
2021-06-28  5:03                       ` Jason Wang
2021-06-28 10:56                         ` Parav Pandit
2021-06-29  3:52                           ` Jason Wang
2021-06-29  9:49                             ` Parav Pandit
2021-06-30  4:31                               ` Jason Wang
2021-06-30  6:03                                 ` Parav Pandit
2021-07-01  3:34                                   ` Jason Wang
2021-07-01  7:00                                     ` Parav Pandit
2021-07-01  7:43                                       ` Jason Wang
2021-07-02  6:04                                         ` Parav Pandit
2021-07-05  4:35                                           ` Jason Wang
2021-07-06 17:07                                             ` Parav Pandit
2021-07-07  4:03                                               ` Jason Wang
2021-06-28 22:39                         ` Michael S. Tsirkin
2021-06-29  3:41                           ` Jason Wang
2021-06-29 20:01                             ` Michael S. Tsirkin
2021-06-30  3:46                               ` Jason Wang
2021-06-16 19:11 ` Parav Pandit [this message]
2021-06-22  7:43   ` [PATCH linux-next v3 3/6] vdpa: Enable user to set mac and mtu of vdpa device Jason Wang
2021-06-22 14:09     ` Parav Pandit
2021-06-16 19:11 ` [PATCH linux-next v3 4/6] vdpa_sim_net: Enable user to set mac address and mtu Parav Pandit
2021-06-16 19:11 ` [PATCH linux-next v3 5/6] vdpa/mlx5: Support configuration of MAC Parav Pandit
2021-06-16 19:11 ` [PATCH linux-next v3 6/6] vdpa/mlx5: Forward only packets with allowed MAC address Parav Pandit
2021-08-05  9:57 ` [PATCH linux-next v3 0/6] vdpa: enable user to set mac, mtu Michael S. Tsirkin
2021-08-05 10:13   ` Parav Pandit via Virtualization
2021-08-05 12:05     ` Michael S. Tsirkin
2021-08-06  2:50   ` Jason Wang
2021-08-06  8:42     ` Michael S. Tsirkin
2021-08-06  8:55       ` Parav Pandit via Virtualization
2021-08-09  3:07         ` Jason Wang
2021-08-09  3:13           ` Parav Pandit via Virtualization
2021-08-09  3:29             ` Jason Wang
     [not found]           ` <20210809052121.GA209158@mtl-vdi-166.wap.labs.mlnx>
2021-08-09  5:42             ` Parav Pandit via Virtualization
     [not found]               ` <20210809055748.GA210406@mtl-vdi-166.wap.labs.mlnx>
2021-08-09  6:01                 ` Parav Pandit via Virtualization
     [not found]                   ` <20210809060746.GA210718@mtl-vdi-166.wap.labs.mlnx>
2021-08-09  6:10                     ` Parav Pandit via Virtualization
2021-08-09  7:05                       ` Jason Wang
2021-08-16 20:51                         ` Michael S. Tsirkin
2021-08-09  9:40         ` Michael S. Tsirkin
2021-08-09  9:51           ` Parav Pandit via Virtualization
2021-08-16 20:54             ` Michael S. Tsirkin
2021-08-18  3:14               ` Parav Pandit via Virtualization
2021-08-18  4:31                 ` Jason Wang
2021-08-18  4:36                   ` Parav Pandit via Virtualization
2021-08-19  4:18                     ` Jason Wang
2021-08-18 17:33                   ` Michael S. Tsirkin
2021-08-19  4:22                     ` Jason Wang
2021-08-19  5:23                       ` Parav Pandit via Virtualization
2021-08-19  7:15                         ` Jason Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210616191155.102303-4-parav@nvidia.com \
    --to=parav@nvidia.com \
    --cc=elic@nvidia.com \
    --cc=mst@redhat.com \
    --cc=virtualization@lists.linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.