Skip to contentSkip to conversation

vdpa: Warn if MTU configured is too low

PATCH In review Eli Cohen 3 participants 5 messages May 11, 2022 – May 12, 2022 virtio core

lore
Share & tools
lore

Eli Cohen

author
#0 lore raw

PATCH 1/1 vdpa: Warn if MTU configured is too low

Following the recommendation in virio spec 1.1, a device offering VIRTIO_NET_F_MTU should set the mtu to at least 1280 bytes.

Print a warning if this recommendation is not met.

---
v0 -> v1:
chage pr_warn to netlink warning to userspace

 drivers/vdpa/vdpa.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/vdpa/vdpa.c +8 -1
index 91f4c13c7c7c..0fb4a615f267 100644
@@ -583,6 +583,9 @@ vdpa_nl_cmd_mgmtdev_get_dumpit(struct sk_buff *msg, struct netlink_callback *cb)
 				 BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MTU)     | \
 				 BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MAX_VQP))
 
+/* Recommended virtio spec 1.1 section 5.1.4.1 */
+#define VIRTIO_MIN_PREFERRED_MTU 1280
+
 static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff *skb, struct genl_info *info)
 {
 	struct vdpa_dev_set_config config = {};
@@ -634,6 +637,10 @@ static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff *skb, struct genl_info *i
 		err = PTR_ERR(mdev);
 		goto err;
 	}
+	if ((mdev->supported_features & BIT_ULL(VIRTIO_NET_F_MTU)) &&
+	    (config.mask & BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MTU) &&
+	    config.net.mtu < VIRTIO_MIN_PREFERRED_MTU))
+		NL_SET_ERR_MSG_MOD(info->extack, "MTU is below recommended value\n");
 	if ((config.mask & mdev->config_attr_mask) != config.mask) {
 		NL_SET_ERR_MSG_MOD(info->extack,
 				   "All provided attributes are not supported");
@@ -1135,7 +1142,7 @@ static const struct nla_policy vdpa_nl_policy[VDPA_ATTR_MAX + 1] = {
 	[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),
+	[VDPA_ATTR_DEV_NET_CFG_MTU] = NLA_POLICY_MIN(NLA_U16, ETH_MIN_MTU),
 };
 
 static const struct genl_ops vdpa_nl_ops[] = {
Signature · 1 line
2.35.1
#1 lore raw
Quoted 29 lines · Eli Cohen

Following the recommendation in virio spec 1.1, a device offering VIRTIO_NET_F_MTU should set the mtu to at least 1280 bytes.

Print a warning if this recommendation is not met.

---
v0 -> v1:
chage pr_warn to netlink warning to userspace

 drivers/vdpa/vdpa.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/vdpa/vdpa.c +3 -0
index 91f4c13c7c7c..0fb4a615f267 100644
@@ -583,6 +583,9 @@ vdpa_nl_cmd_mgmtdev_get_dumpit(struct sk_buff *msg, struct netlink_callback *cb)
                                 BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MTU)     | \
                                 BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MAX_VQP))
 
+/* Recommended virtio spec 1.1 section 5.1.4.1 */
+#define VIRTIO_MIN_PREFERRED_MTU 1280
+
 static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff *skb, struct genl_info *info)
 {
        struct vdpa_dev_set_config config = {};

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff *skb, struct genl_info *i · line 643

Quoted 7 lines
drivers/vdpa/vdpa.c +4 -0
@@ -634,6 +637,10 @@ static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff *skb, struct genl_info *i
                err = PTR_ERR(mdev);
                goto err;
        }
+       if ((mdev->supported_features & BIT_ULL(VIRTIO_NET_F_MTU)) &&
+           (config.mask & BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MTU) &&
+           config.net.mtu < VIRTIO_MIN_PREFERRED_MTU))
+               NL_SET_ERR_MSG_MOD(info->extack, "MTU is below recommended value\n");

Can this function be used for warning? I have a quick cscope that tells me it's probably used only for error.

Will it be better if we fail only when the device supports VERSION_1?

Thanks

Quoted 13 lines
drivers/vdpa/vdpa.c +1 -2
        if ((config.mask & mdev->config_attr_mask) != config.mask) {
                NL_SET_ERR_MSG_MOD(info->extack,
                                   "All provided attributes are not supported");
@@ -1135,7 +1142,7 @@ static const struct nla_policy vdpa_nl_policy[VDPA_ATTR_MAX + 1] = {
        [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),
+       [VDPA_ATTR_DEV_NET_CFG_MTU] = NLA_POLICY_MIN(NLA_U16, ETH_MIN_MTU),
 };
 
 static const struct genl_ops vdpa_nl_ops[] = {
--
Quoted 2 lines

2.35.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

author
#2 lore raw
Quoted 40 lines

-----Original Message-----
From: Jason Wang <[email protected]>
Sent: Thursday, May 12, 2022 7:17 AM
To: Eli Cohen <[email protected]>
Cc: mst <[email protected]>; virtualization <[email protected]>; linux-kernel <[email protected]>; Si- Wei Liu <[email protected]>
Subject: Re: [PATCH v1] vdpa: Warn if MTU configured is too low

Quoted 31 lines · Eli Cohen

Following the recommendation in virio spec 1.1, a device offering VIRTIO_NET_F_MTU should set the mtu to at least 1280 bytes.

Print a warning if this recommendation is not met.

---
v0 -> v1:
chage pr_warn to netlink warning to userspace

 drivers/vdpa/vdpa.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/vdpa/vdpa.c +3 -0
index 91f4c13c7c7c..0fb4a615f267 100644
@@ -583,6 +583,9 @@ vdpa_nl_cmd_mgmtdev_get_dumpit(struct sk_buff *msg, struct netlink_callback *cb)
                                 BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MTU)     | \
                                 BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MAX_VQP))
 
+/* Recommended virtio spec 1.1 section 5.1.4.1 */
+#define VIRTIO_MIN_PREFERRED_MTU 1280
+
 static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff *skb, struct genl_info *info)
 {
        struct vdpa_dev_set_config config = {};
@@ -634,6 +637,10 @@ static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff *skb, struct genl_info *i
                err = PTR_ERR(mdev);
                goto err;
Quoted 8 lines

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff *skb, struct genl_info *i · line 643

Quoted 5 lines
drivers/vdpa/vdpa.c +4 -0
        }
+       if ((mdev->supported_features & BIT_ULL(VIRTIO_NET_F_MTU)) &&
+           (config.mask & BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MTU) &&
+           config.net.mtu < VIRTIO_MIN_PREFERRED_MTU))
+               NL_SET_ERR_MSG_MOD(info->extack, "MTU is below recommended value\n");

Can this function be used for warning? I have a quick cscope that tells me it's probably used only for error.

Here's what I get:

# vdpa dev add name vdpa-a mgmtdev auxiliary/mlx5_core.sf.1 mtu 1279
Warning: vdpa: MTU is below recommended value

The vdpa device is created fine.

Quoted 3 lines

Will it be better if we fail only when the device supports VERSION_1?

Why?

Quoted 17 lines

Thanks

Quoted 15 lines
drivers/vdpa/vdpa.c +1 -2
        if ((config.mask & mdev->config_attr_mask) != config.mask) {
                NL_SET_ERR_MSG_MOD(info->extack,
                                   "All provided attributes are not supported");
@@ -1135,7 +1142,7 @@ static const struct nla_policy vdpa_nl_policy[VDPA_ATTR_MAX + 1] = {
        [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),
+       [VDPA_ATTR_DEV_NET_CFG_MTU] = NLA_POLICY_MIN(NLA_U16, ETH_MIN_MTU),
 };
 
 static const struct genl_ops vdpa_nl_ops[] = {
--

2.35.1

#3 lore raw
In reply to Eli Cohen
Quoted 18 lines · Eli Cohen

Following the recommendation in virio spec 1.1, a device offering VIRTIO_NET_F_MTU should set the mtu to at least 1280 bytes.

Print a warning if this recommendation is not met.

---
v0 -> v1:
chage pr_warn to netlink warning to userspace

 drivers/vdpa/vdpa.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/vdpa/vdpa.c +0 -0
index 91f4c13c7c7c..0fb4a615f267 100644

drivers/vdpa/vdpa.c vdpa_nl_cmd_mgmtdev_get_dumpit(struct sk_buff *msg, struct netlink_callback *cb) · line 586

Quoted 4 lines
drivers/vdpa/vdpa.c +1 -0
@@ -583,6 +583,9 @@ vdpa_nl_cmd_mgmtdev_get_dumpit(struct sk_buff *msg, struct netlink_callback *cb)
 				 BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MTU)     | \
 				 BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MAX_VQP))
 
+/* Recommended virtio spec 1.1 section 5.1.4.1 */

I'd add name of section here too.

drivers/vdpa/vdpa.c vdpa_nl_cmd_mgmtdev_get_dumpit(struct sk_buff *msg, struct netlink_callback *cb) · line 588

Quoted 2 lines
drivers/vdpa/vdpa.c +2 -0
+#define VIRTIO_MIN_PREFERRED_MTU 1280
+

Preferred is kind of confusing here. I guess you are trying to say it's not mandatory but I don't think this conveys this information.

Recommended (matching text below)?

Quoted 4 lines
drivers/vdpa/vdpa.c +0 -0
 static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff *skb, struct genl_info *info)
 {
 	struct vdpa_dev_set_config config = {};

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff *skb, struct genl_info *i · line 646

Quoted 10 lines
drivers/vdpa/vdpa.c +4 -0
@@ -634,6 +637,10 @@ static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff *skb, struct genl_info *i
 		err = PTR_ERR(mdev);
 		goto err;
 	}
+	if ((mdev->supported_features & BIT_ULL(VIRTIO_NET_F_MTU)) &&
+	    (config.mask & BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MTU) &&
+	    config.net.mtu < VIRTIO_MIN_PREFERRED_MTU))
+		NL_SET_ERR_MSG_MOD(info->extack, "MTU is below recommended value\n");
 	if ((config.mask & mdev->config_attr_mask) != config.mask) {
 		NL_SET_ERR_MSG_MOD(info->extack,
 				   "All provided attributes are not supported");

Pity we can't include the actual value here, but oh well. At least let's include the recommended value, we can do that:
"MTU is below recommended value of " __stringify(VIRTIO_MIN_PREFERRED_MTU) "\n"

Quoted 11 lines
drivers/vdpa/vdpa.c +1 -1
@@ -1135,7 +1142,7 @@ static const struct nla_policy vdpa_nl_policy[VDPA_ATTR_MAX + 1] = {
 	[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),
+	[VDPA_ATTR_DEV_NET_CFG_MTU] = NLA_POLICY_MIN(NLA_U16, ETH_MIN_MTU),
 };
 
 static const struct genl_ops vdpa_nl_ops[] = {
Signature · 1 line
2.35.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

author
#4 lore raw
Quoted 29 lines

-----Original Message-----
From: Michael S. Tsirkin <[email protected]>
Sent: Thursday, May 12, 2022 8:57 AM
To: Eli Cohen <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v1] vdpa: Warn if MTU configured is too low

Quoted 21 lines · Eli Cohen

Following the recommendation in virio spec 1.1, a device offering VIRTIO_NET_F_MTU should set the mtu to at least 1280 bytes.

Print a warning if this recommendation is not met.

---
v0 -> v1:
chage pr_warn to netlink warning to userspace

 drivers/vdpa/vdpa.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/vdpa/vdpa.c +0 -0
index 91f4c13c7c7c..0fb4a615f267 100644
@@ -583,6 +583,9 @@ vdpa_nl_cmd_mgmtdev_get_dumpit(struct sk_buff *msg, struct netlink_callback *cb)
 				 BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MTU)     | \
 				 BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MAX_VQP))
 
Quoted 3 lines

drivers/vdpa/vdpa.c vdpa_nl_cmd_mgmtdev_get_dumpit(struct sk_buff *msg, struct netlink_callback *cb) · line 586

Quoted 1 line
drivers/vdpa/vdpa.c +1 -0
+/* Recommended virtio spec 1.1 section 5.1.4.1 */

I'd add name of section here too.

Sure

Quoted 8 lines

drivers/vdpa/vdpa.c vdpa_nl_cmd_mgmtdev_get_dumpit(struct sk_buff *msg, struct netlink_callback *cb) · line 588

Quoted 3 lines
drivers/vdpa/vdpa.c +2 -0
+#define VIRTIO_MIN_PREFERRED_MTU 1280
+

Preferred is kind of confusing here. I guess you are trying to say it's not mandatory but I don't think this conveys this information.

Recommended (matching text below)?

Will modify

Quoted 13 lines
Quoted 13 lines
drivers/vdpa/vdpa.c +4 -0
 static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff *skb, struct genl_info *info)
 {
 	struct vdpa_dev_set_config config = {};
@@ -634,6 +637,10 @@ static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff *skb, struct genl_info *i
 		err = PTR_ERR(mdev);
 		goto err;
 	}
+	if ((mdev->supported_features & BIT_ULL(VIRTIO_NET_F_MTU)) &&
+	    (config.mask & BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MTU) &&
+	    config.net.mtu < VIRTIO_MIN_PREFERRED_MTU))
+		NL_SET_ERR_MSG_MOD(info->extack, "MTU is below recommended value\n");
Quoted 9 lines

drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff *skb, struct genl_info *i · line 646

Quoted 3 lines
drivers/vdpa/vdpa.c +0 -0
 	if ((config.mask & mdev->config_attr_mask) != config.mask) {
 		NL_SET_ERR_MSG_MOD(info->extack,
 				   "All provided attributes are not supported");

Pity we can't include the actual value here, but oh well. At least let's include the recommended value, we can do that:
"MTU is below recommended value of " __stringify(VIRTIO_MIN_PREFERRED_MTU) "\n"

Will change

Quoted 12 lines
Quoted 12 lines
drivers/vdpa/vdpa.c +1 -2
@@ -1135,7 +1142,7 @@ static const struct nla_policy vdpa_nl_policy[VDPA_ATTR_MAX + 1] = {
 	[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),
+	[VDPA_ATTR_DEV_NET_CFG_MTU] = NLA_POLICY_MIN(NLA_U16, ETH_MIN_MTU),
 };
 
 static const struct genl_ops vdpa_nl_ops[] = {
--

2.35.1