Skip to content

Commit abdf31b

Browse files
emuslnmstsirkin
authored andcommitted
pds_vdpa: always allow offering VIRTIO_NET_F_MAC
Our driver sets a mac if the HW is 00:..:00 so we need to be sure to advertise VIRTIO_NET_F_MAC even if the HW doesn't. We also need to be sure that virtio_net sees the VIRTIO_NET_F_MAC and doesn't rewrite the mac address that a user may have set with the vdpa utility. After reading the hw_feature bits, add the VIRTIO_NET_F_MAC to the driver's supported_features and use that for reporting what is available. If the HW is not advertising it, be sure to strip the VIRTIO_NET_F_MAC before finishing the feature negotiation. If the user specifies a device_features bitpattern in the vdpa utility without the VIRTIO_NET_F_MAC set, then don't set the mac. Fixes: 151cc83 ("pds_vdpa: add support for vdpa and vdpamgmt interfaces") Signed-off-by: Shannon Nelson <shannon.nelson@amd.com> Message-Id: <20230711042437.69381-3-shannon.nelson@amd.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Acked-by: Jason Wang <jasowang@redhat.com>
1 parent 0cd2c13 commit abdf31b

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

drivers/vdpa/pds/debugfs.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,6 @@ static int config_show(struct seq_file *seq, void *v)
224224
seq_printf(seq, "dev_status: %#x\n", status);
225225
print_status_bits(seq, status);
226226

227-
seq_printf(seq, "req_features: %#llx\n", pdsv->req_features);
228-
print_feature_bits_all(seq, pdsv->req_features);
229227
driver_features = vp_modern_get_driver_features(&pdsv->vdpa_aux->vd_mdev);
230228
seq_printf(seq, "driver_features: %#llx\n", driver_features);
231229
print_feature_bits_all(seq, driver_features);

drivers/vdpa/pds/vdpa_dev.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -318,28 +318,34 @@ static int pds_vdpa_set_driver_features(struct vdpa_device *vdpa_dev, u64 featur
318318
struct device *dev = &pdsv->vdpa_dev.dev;
319319
u64 driver_features;
320320
u64 nego_features;
321+
u64 hw_features;
321322
u64 missing;
322323

323324
if (!(features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)) && features) {
324325
dev_err(dev, "VIRTIO_F_ACCESS_PLATFORM is not negotiated\n");
325326
return -EOPNOTSUPP;
326327
}
327328

328-
pdsv->req_features = features;
329-
330329
/* Check for valid feature bits */
331-
nego_features = features & le64_to_cpu(pdsv->vdpa_aux->ident.hw_features);
332-
missing = pdsv->req_features & ~nego_features;
330+
nego_features = features & pdsv->supported_features;
331+
missing = features & ~nego_features;
333332
if (missing) {
334333
dev_err(dev, "Can't support all requested features in %#llx, missing %#llx features\n",
335-
pdsv->req_features, missing);
334+
features, missing);
336335
return -EOPNOTSUPP;
337336
}
338337

338+
pdsv->negotiated_features = nego_features;
339+
339340
driver_features = pds_vdpa_get_driver_features(vdpa_dev);
340341
dev_dbg(dev, "%s: %#llx => %#llx\n",
341342
__func__, driver_features, nego_features);
342343

344+
/* if we're faking the F_MAC, strip it before writing to device */
345+
hw_features = le64_to_cpu(pdsv->vdpa_aux->ident.hw_features);
346+
if (!(hw_features & BIT_ULL(VIRTIO_NET_F_MAC)))
347+
nego_features &= ~BIT_ULL(VIRTIO_NET_F_MAC);
348+
343349
if (driver_features == nego_features)
344350
return 0;
345351

@@ -352,7 +358,7 @@ static u64 pds_vdpa_get_driver_features(struct vdpa_device *vdpa_dev)
352358
{
353359
struct pds_vdpa_device *pdsv = vdpa_to_pdsv(vdpa_dev);
354360

355-
return vp_modern_get_driver_features(&pdsv->vdpa_aux->vd_mdev);
361+
return pdsv->negotiated_features;
356362
}
357363

358364
static void pds_vdpa_set_config_cb(struct vdpa_device *vdpa_dev,
@@ -564,7 +570,7 @@ static int pds_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
564570

565571
if (add_config->mask & BIT_ULL(VDPA_ATTR_DEV_FEATURES)) {
566572
u64 unsupp_features =
567-
add_config->device_features & ~mgmt->supported_features;
573+
add_config->device_features & ~pdsv->supported_features;
568574

569575
if (unsupp_features) {
570576
dev_err(dev, "Unsupported features: %#llx\n", unsupp_features);
@@ -615,7 +621,8 @@ static int pds_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
615621
}
616622

617623
/* Set a mac, either from the user config if provided
618-
* or set a random mac if default is 00:..:00
624+
* or use the device's mac if not 00:..:00
625+
* or set a random mac
619626
*/
620627
if (add_config->mask & BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MACADDR)) {
621628
ether_addr_copy(pdsv->mac, add_config->net.mac);
@@ -624,7 +631,8 @@ static int pds_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
624631

625632
vc = pdsv->vdpa_aux->vd_mdev.device;
626633
memcpy_fromio(pdsv->mac, vc->mac, sizeof(pdsv->mac));
627-
if (is_zero_ether_addr(pdsv->mac)) {
634+
if (is_zero_ether_addr(pdsv->mac) &&
635+
(pdsv->supported_features & BIT_ULL(VIRTIO_NET_F_MAC))) {
628636
eth_random_addr(pdsv->mac);
629637
dev_info(dev, "setting random mac %pM\n", pdsv->mac);
630638
}
@@ -752,6 +760,10 @@ int pds_vdpa_get_mgmt_info(struct pds_vdpa_aux *vdpa_aux)
752760
mgmt->id_table = pds_vdpa_id_table;
753761
mgmt->device = dev;
754762
mgmt->supported_features = le64_to_cpu(vdpa_aux->ident.hw_features);
763+
764+
/* advertise F_MAC even if the device doesn't */
765+
mgmt->supported_features |= BIT_ULL(VIRTIO_NET_F_MAC);
766+
755767
mgmt->config_attr_mask = BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MACADDR);
756768
mgmt->config_attr_mask |= BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MAX_VQP);
757769
mgmt->config_attr_mask |= BIT_ULL(VDPA_ATTR_DEV_FEATURES);

drivers/vdpa/pds/vdpa_dev.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ struct pds_vdpa_device {
3535
struct pds_vdpa_aux *vdpa_aux;
3636

3737
struct pds_vdpa_vq_info vqs[PDS_VDPA_MAX_QUEUES];
38-
u64 supported_features; /* specified device features */
39-
u64 req_features; /* features requested by vdpa */
38+
u64 supported_features; /* supported device features */
39+
u64 negotiated_features; /* negotiated features */
4040
u8 vdpa_index; /* rsvd for future subdevice use */
4141
u8 num_vqs; /* num vqs in use */
4242
u8 mac[ETH_ALEN]; /* mac selected when the device was added */

0 commit comments

Comments
 (0)