Skip to content

Commit e7d09cd

Browse files
siwliu-kernelmstsirkin
authored andcommitted
vdpa: validate provisioned device features against specified attribute
With device feature provisioning, there's a chance for misconfiguration that the vdpa feature attribute supplied in 'vdpa dev add' command doesn't get selected on the device_features to be provisioned. For instance, when a @mac attribute is specified, the corresponding feature bit _F_MAC in device_features should be set for consistency. If there's conflict on provisioned features against the attribute, it should be treated as an error to fail the ambiguous command. Noted the opposite is not necessarily true, for e.g. it's okay to have _F_MAC set in device_features without providing a corresponding @mac attribute, in which case the vdpa vendor driver could load certain default value for attribute that is not explicitly specified. Generalize this check in vdpa core so that there's no duplicate code in each vendor driver. Signed-off-by: Si-Wei Liu <si-wei.liu@oracle.com> Reviewed-by: Eli Cohen <elic@nvidia.com> Message-Id: <1675725124-7375-4-git-send-email-si-wei.liu@oracle.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent 6e6d398 commit e7d09cd

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

drivers/vdpa/vdpa.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,26 @@ static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff *skb, struct genl_info *i
606606
config.mask |= BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MAX_VQP);
607607
}
608608
if (nl_attrs[VDPA_ATTR_DEV_FEATURES]) {
609+
u64 missing = 0x0ULL;
610+
609611
config.device_features =
610612
nla_get_u64(nl_attrs[VDPA_ATTR_DEV_FEATURES]);
613+
if (nl_attrs[VDPA_ATTR_DEV_NET_CFG_MACADDR] &&
614+
!(config.device_features & BIT_ULL(VIRTIO_NET_F_MAC)))
615+
missing |= BIT_ULL(VIRTIO_NET_F_MAC);
616+
if (nl_attrs[VDPA_ATTR_DEV_NET_CFG_MTU] &&
617+
!(config.device_features & BIT_ULL(VIRTIO_NET_F_MTU)))
618+
missing |= BIT_ULL(VIRTIO_NET_F_MTU);
619+
if (nl_attrs[VDPA_ATTR_DEV_NET_CFG_MAX_VQP] &&
620+
config.net.max_vq_pairs > 1 &&
621+
!(config.device_features & BIT_ULL(VIRTIO_NET_F_MQ)))
622+
missing |= BIT_ULL(VIRTIO_NET_F_MQ);
623+
if (missing) {
624+
NL_SET_ERR_MSG_FMT_MOD(info->extack,
625+
"Missing features 0x%llx for provided attributes",
626+
missing);
627+
return -EINVAL;
628+
}
611629
config.mask |= BIT_ULL(VDPA_ATTR_DEV_FEATURES);
612630
}
613631

0 commit comments

Comments
 (0)