[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <54923be8-8ab0-4b55-b599-5f20c999e60f@redhat.com>
Date: Wed, 18 Jun 2025 10:31:37 +0200
From: Paolo Abeni <pabeni@...hat.com>
To: Jason Wang <jasowang@...hat.com>
Cc: netdev@...r.kernel.org, Willem de Bruijn
<willemdebruijn.kernel@...il.com>, Andrew Lunn <andrew+netdev@...n.ch>,
"David S. Miller" <davem@...emloft.net>, Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>, "Michael S. Tsirkin" <mst@...hat.com>,
Xuan Zhuo <xuanzhuo@...ux.alibaba.com>, Eugenio Pérez
<eperezma@...hat.com>, Yuri Benditovich <yuri.benditovich@...nix.com>,
Akihiko Odaki <akihiko.odaki@...nix.com>
Subject: Re: [PATCH v4 net-next 1/8] virtio: introduce extended features
On 6/18/25 3:51 AM, Jason Wang wrote:
> On Wed, Jun 18, 2025 at 12:12 AM Paolo Abeni <pabeni@...hat.com> wrote:
>>
>> The virtio specifications allows for up to 128 bits for the
>> device features. Soon we are going to use some of the 'extended'
>> bits features (above 64) for the virtio_net driver.
>>
>> Introduce extended features as a fixed size array of u64. To minimize
>> the diffstat allows legacy driver to access the low 64 bits via a
>> transparent union.
>>
>> Introduce an extended get_extended_features configuration callback
>> that devices supporting the extended features range must implement in
>> place of the traditional one.
>>
>> Note that legacy and transport features don't need any change, as
>> they are always in the low 64 bit range.
>>
>> Signed-off-by: Paolo Abeni <pabeni@...hat.com>
>> ---
>> v3 -> v4:
>> - moved bit sanity check in virtio_features_*
>> - replaced BUG_ON with WARN_ON_ONCE
>> - *_and_not -> _andnot
>> - short circuit features comparison
>> v2 -> v3:
>> - uint128_t -> u64[2];
>> v1 -> v2:
>> - let u64 VIRTIO_BIT() cope with higher bit values
>> - add .get_features128 instead of changing .get_features signature
>> ---
>> drivers/virtio/virtio.c | 43 +++++++++-------
>> drivers/virtio/virtio_debug.c | 27 +++++-----
>> include/linux/virtio.h | 5 +-
>> include/linux/virtio_config.h | 41 +++++++--------
>> include/linux/virtio_features.h | 88 +++++++++++++++++++++++++++++++++
>> 5 files changed, 151 insertions(+), 53 deletions(-)
>> create mode 100644 include/linux/virtio_features.h
>>
>> diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
>> index 95d5d7993e5b..5c48788cdbec 100644
>> --- a/drivers/virtio/virtio.c
>> +++ b/drivers/virtio/virtio.c
>> @@ -53,7 +53,7 @@ static ssize_t features_show(struct device *_d,
>>
>> /* We actually represent this as a bitstring, as it could be
>> * arbitrary length in future. */
>> - for (i = 0; i < sizeof(dev->features)*8; i++)
>> + for (i = 0; i < VIRTIO_FEATURES_MAX; i++)
>> len += sysfs_emit_at(buf, len, "%c",
>> __virtio_test_bit(dev, i) ? '1' : '0');
>> len += sysfs_emit_at(buf, len, "\n");
>> @@ -272,22 +272,22 @@ static int virtio_dev_probe(struct device *_d)
>> int err, i;
>> struct virtio_device *dev = dev_to_virtio(_d);
>> struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
>> - u64 device_features;
>> - u64 driver_features;
>> + u64 device_features[VIRTIO_FEATURES_DWORDS];
>> + u64 driver_features[VIRTIO_FEATURES_DWORDS];
>> u64 driver_features_legacy;
>>
>> /* We have a driver! */
>> virtio_add_status(dev, VIRTIO_CONFIG_S_DRIVER);
>>
>> /* Figure out what features the device supports. */
>> - device_features = dev->config->get_features(dev);
>> + virtio_get_features(dev, device_features);
>>
>> /* Figure out what features the driver supports. */
>> - driver_features = 0;
>> + virtio_features_zero(driver_features);
>> for (i = 0; i < drv->feature_table_size; i++) {
>> unsigned int f = drv->feature_table[i];
>> - BUG_ON(f >= 64);
>> - driver_features |= (1ULL << f);
>> + if (!WARN_ON_ONCE(f >= VIRTIO_FEATURES_MAX))
>
> Nit: Any reason why switching to use WARN_ON_ONCE()?
BUG_ON() are strongly discouraged. Since I touched the nearby code
checkpatch urged me to take action ;)
/P
Powered by blists - more mailing lists