[4/5] net/virtio: add GET_STATUS support to virtio-user

Message ID 20200715171828.95887-5-amorenoz@redhat.com (mailing list archive)
State Superseded, archived
Delegated to: Maxime Coquelin
Headers
Series Add support for GET/SET_STATUS on virtio-user pmd |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Intel-compilation success Compilation OK

Commit Message

Adrian Moreno July 15, 2020, 5:18 p.m. UTC
  This patch adds support for VHOST_USER_GET_STATUS request.

Only vhost-user backed is supported for now

Signed-off-by: Adrian Moreno <amorenoz@redhat.com>
---
 drivers/net/virtio/virtio_user/vhost_user.c   |  2 +
 .../net/virtio/virtio_user/virtio_user_dev.c  | 39 +++++++++++++++++++
 .../net/virtio/virtio_user/virtio_user_dev.h  |  1 +
 drivers/net/virtio/virtio_user_ethdev.c       |  2 +
 4 files changed, 44 insertions(+)
  

Comments

Chenbo Xia July 16, 2020, 3:31 a.m. UTC | #1
Hi Adrian,

> -----Original Message-----
> From: Adrian Moreno <amorenoz@redhat.com>
> Sent: Thursday, July 16, 2020 1:18 AM
> To: dev@dpdk.org
> Cc: maxime.coquelin@redhat.com; Wang, Zhihong <zhihong.wang@intel.com>;
> amorenoz@redhat.com; Xia, Chenbo <chenbo.xia@intel.com>
> Subject: [PATCH 4/5] net/virtio: add GET_STATUS support to virtio-user
> 
> This patch adds support for VHOST_USER_GET_STATUS request.
> 
> Only vhost-user backed is supported for now
> 
> Signed-off-by: Adrian Moreno <amorenoz@redhat.com>
> ---
>  drivers/net/virtio/virtio_user/vhost_user.c   |  2 +
>  .../net/virtio/virtio_user/virtio_user_dev.c  | 39
> +++++++++++++++++++  .../net/virtio/virtio_user/virtio_user_dev.h  |  1 +
>  drivers/net/virtio/virtio_user_ethdev.c       |  2 +
>  4 files changed, 44 insertions(+)
> 
> diff --git a/drivers/net/virtio/virtio_user/vhost_user.c
> b/drivers/net/virtio/virtio_user/vhost_user.c
> index 2332e01d1..43c630e47 100644
> --- a/drivers/net/virtio/virtio_user/vhost_user.c
> +++ b/drivers/net/virtio/virtio_user/vhost_user.c
> @@ -279,6 +279,7 @@ vhost_user_sock(struct virtio_user_dev *dev,
>  	switch (req) {
>  	case VHOST_USER_GET_FEATURES:
>  	case VHOST_USER_GET_PROTOCOL_FEATURES:
> +	case VHOST_USER_GET_STATUS:
>  		need_reply = 1;
>  		break;
> 
> @@ -373,6 +374,7 @@ vhost_user_sock(struct virtio_user_dev *dev,
> 
>  		switch (req) {
>  		case VHOST_USER_GET_FEATURES:
> +		case VHOST_USER_GET_STATUS:
>  		case VHOST_USER_GET_PROTOCOL_FEATURES:
>  			if (msg.size != sizeof(m.payload.u64)) {
>  				PMD_DRV_LOG(ERR, "Received bad msg size");
> diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c
> b/drivers/net/virtio/virtio_user/virtio_user_dev.c
> index 2c400a448..613caef56 100644
> --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
> +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
> @@ -804,3 +804,42 @@ virtio_user_send_status_update(struct virtio_user_dev
> *dev, uint8_t status)
> 
>  	return 0;
>  }
> +
> +int
> +virtio_user_update_status(struct virtio_user_dev *dev) {
> +	uint64_t ret;
> +
> +	/* Vhost-user only for now */
> +	if (!is_vhost_user_by_type(dev->path))
> +		return 0;
> +
> +	if (!(dev->protocol_features & (1UL <<
> VHOST_USER_PROTOCOL_F_STATUS)))
> +		return 0;
> +
> +	if (dev->ops->send_request(dev, VHOST_USER_GET_STATUS, &ret) < 0) {
> +		PMD_INIT_LOG(ERR, "GET_STATUS failed: %s", strerror(errno));
> +		return -1;
> +	}
> +	if (ret > UINT8_MAX) {
> +		PMD_INIT_LOG(ERR, "Invalid VHOST_USER_GET_STATUS
> response 0x%" PRIx64 "\n", ret);

There's a coding style issue here:
CHECK:CAMELCASE: Avoid CamelCase: <PRIx64>
Could you fix this?

Btw, in case you don't know, there's a script in dpdk for check these issues:
devtools/checkpatches.sh. 😊

Thanks!
Chenbo

> +		return -1;
> +	}
> +
> +	dev->status = ret;
> +	PMD_INIT_LOG(DEBUG, "Updated Device Status(0x%08x):\n"
> +			"\t-ACKNOWLEDGE: %u\n"
> +			"\t-DRIVER: %u\n"
> +			"\t-DRIVER_OK: %u\n"
> +			"\t-FEATURES_OK: %u\n"
> +			"\t-DEVICE_NEED_RESET: %u\n"
> +			"\t-FAILED: %u\n",
> +			dev->status,
> +			!!(dev->status & VIRTIO_CONFIG_STATUS_ACK),
> +			!!(dev->status & VIRTIO_CONFIG_STATUS_DRIVER),
> +			!!(dev->status & VIRTIO_CONFIG_STATUS_DRIVER_OK),
> +			!!(dev->status &
> VIRTIO_CONFIG_STATUS_FEATURES_OK),
> +			!!(dev->status &
> VIRTIO_CONFIG_STATUS_DEV_NEED_RESET),
> +			!!(dev->status & VIRTIO_CONFIG_STATUS_FAILED));
> +	return 0;
> +}
> diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.h
> b/drivers/net/virtio/virtio_user/virtio_user_dev.h
> index a76d7cfaf..1a045af6f 100644
> --- a/drivers/net/virtio/virtio_user/virtio_user_dev.h
> +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h
> @@ -75,4 +75,5 @@ void virtio_user_handle_cq_packed(struct virtio_user_dev
> *dev,
>  				  uint16_t queue_idx);
>  uint8_t virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs);
> int virtio_user_send_status_update(struct virtio_user_dev *dev, uint8_t status);
> +int virtio_user_update_status(struct virtio_user_dev *dev);
>  #endif
> diff --git a/drivers/net/virtio/virtio_user_ethdev.c
> b/drivers/net/virtio/virtio_user_ethdev.c
> index e52f11341..40330deed 100644
> --- a/drivers/net/virtio/virtio_user_ethdev.c
> +++ b/drivers/net/virtio/virtio_user_ethdev.c
> @@ -281,6 +281,8 @@ virtio_user_get_status(struct virtio_hw *hw)  {
>  	struct virtio_user_dev *dev = virtio_user_get_dev(hw);
> 
> +	virtio_user_update_status(dev);
> +
>  	return dev->status;
>  }
> 
> --
> 2.26.2
  
Adrian Moreno July 16, 2020, 7:53 a.m. UTC | #2
On 7/16/20 5:31 AM, Xia, Chenbo wrote:
> Hi Adrian,
> 
>> -----Original Message-----
>> From: Adrian Moreno <amorenoz@redhat.com>
>> Sent: Thursday, July 16, 2020 1:18 AM
>> To: dev@dpdk.org
>> Cc: maxime.coquelin@redhat.com; Wang, Zhihong <zhihong.wang@intel.com>;
>> amorenoz@redhat.com; Xia, Chenbo <chenbo.xia@intel.com>
>> Subject: [PATCH 4/5] net/virtio: add GET_STATUS support to virtio-user
>>
>> This patch adds support for VHOST_USER_GET_STATUS request.
>>
>> Only vhost-user backed is supported for now
>>
>> Signed-off-by: Adrian Moreno <amorenoz@redhat.com>
>> ---
>>  drivers/net/virtio/virtio_user/vhost_user.c   |  2 +
>>  .../net/virtio/virtio_user/virtio_user_dev.c  | 39
>> +++++++++++++++++++  .../net/virtio/virtio_user/virtio_user_dev.h  |  1 +
>>  drivers/net/virtio/virtio_user_ethdev.c       |  2 +
>>  4 files changed, 44 insertions(+)
>>
>> diff --git a/drivers/net/virtio/virtio_user/vhost_user.c
>> b/drivers/net/virtio/virtio_user/vhost_user.c
>> index 2332e01d1..43c630e47 100644
>> --- a/drivers/net/virtio/virtio_user/vhost_user.c
>> +++ b/drivers/net/virtio/virtio_user/vhost_user.c
>> @@ -279,6 +279,7 @@ vhost_user_sock(struct virtio_user_dev *dev,
>>  	switch (req) {
>>  	case VHOST_USER_GET_FEATURES:
>>  	case VHOST_USER_GET_PROTOCOL_FEATURES:
>> +	case VHOST_USER_GET_STATUS:
>>  		need_reply = 1;
>>  		break;
>>
>> @@ -373,6 +374,7 @@ vhost_user_sock(struct virtio_user_dev *dev,
>>
>>  		switch (req) {
>>  		case VHOST_USER_GET_FEATURES:
>> +		case VHOST_USER_GET_STATUS:
>>  		case VHOST_USER_GET_PROTOCOL_FEATURES:
>>  			if (msg.size != sizeof(m.payload.u64)) {
>>  				PMD_DRV_LOG(ERR, "Received bad msg size");
>> diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c
>> b/drivers/net/virtio/virtio_user/virtio_user_dev.c
>> index 2c400a448..613caef56 100644
>> --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
>> +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
>> @@ -804,3 +804,42 @@ virtio_user_send_status_update(struct virtio_user_dev
>> *dev, uint8_t status)
>>
>>  	return 0;
>>  }
>> +
>> +int
>> +virtio_user_update_status(struct virtio_user_dev *dev) {
>> +	uint64_t ret;
>> +
>> +	/* Vhost-user only for now */
>> +	if (!is_vhost_user_by_type(dev->path))
>> +		return 0;
>> +
>> +	if (!(dev->protocol_features & (1UL <<
>> VHOST_USER_PROTOCOL_F_STATUS)))
>> +		return 0;
>> +
>> +	if (dev->ops->send_request(dev, VHOST_USER_GET_STATUS, &ret) < 0) {
>> +		PMD_INIT_LOG(ERR, "GET_STATUS failed: %s", strerror(errno));
>> +		return -1;
>> +	}
>> +	if (ret > UINT8_MAX) {
>> +		PMD_INIT_LOG(ERR, "Invalid VHOST_USER_GET_STATUS
>> response 0x%" PRIx64 "\n", ret);
> 
> There's a coding style issue here:
> CHECK:CAMELCASE: Avoid CamelCase: <PRIx64>
> Could you fix this?

I did see this one as well. It also seems new because PRIx64 is widely used in DPDK.

find -iname *.c | xargs grep -i "PRIx64" | wc -l
520

So, ether we have to modify the script to ignore this one or change all 520
cases, right?

+ David, what do you think?

> 
> Btw, in case you don't know, there's a script in dpdk for check these issues:
> devtools/checkpatches.sh. 😊
> 
> Thanks!
> Chenbo
> 
>> +		return -1;
>> +	}
>> +
>> +	dev->status = ret;
>> +	PMD_INIT_LOG(DEBUG, "Updated Device Status(0x%08x):\n"
>> +			"\t-ACKNOWLEDGE: %u\n"
>> +			"\t-DRIVER: %u\n"
>> +			"\t-DRIVER_OK: %u\n"
>> +			"\t-FEATURES_OK: %u\n"
>> +			"\t-DEVICE_NEED_RESET: %u\n"
>> +			"\t-FAILED: %u\n",
>> +			dev->status,
>> +			!!(dev->status & VIRTIO_CONFIG_STATUS_ACK),
>> +			!!(dev->status & VIRTIO_CONFIG_STATUS_DRIVER),
>> +			!!(dev->status & VIRTIO_CONFIG_STATUS_DRIVER_OK),
>> +			!!(dev->status &
>> VIRTIO_CONFIG_STATUS_FEATURES_OK),
>> +			!!(dev->status &
>> VIRTIO_CONFIG_STATUS_DEV_NEED_RESET),
>> +			!!(dev->status & VIRTIO_CONFIG_STATUS_FAILED));
>> +	return 0;
>> +}
>> diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.h
>> b/drivers/net/virtio/virtio_user/virtio_user_dev.h
>> index a76d7cfaf..1a045af6f 100644
>> --- a/drivers/net/virtio/virtio_user/virtio_user_dev.h
>> +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h
>> @@ -75,4 +75,5 @@ void virtio_user_handle_cq_packed(struct virtio_user_dev
>> *dev,
>>  				  uint16_t queue_idx);
>>  uint8_t virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs);
>> int virtio_user_send_status_update(struct virtio_user_dev *dev, uint8_t status);
>> +int virtio_user_update_status(struct virtio_user_dev *dev);
>>  #endif
>> diff --git a/drivers/net/virtio/virtio_user_ethdev.c
>> b/drivers/net/virtio/virtio_user_ethdev.c
>> index e52f11341..40330deed 100644
>> --- a/drivers/net/virtio/virtio_user_ethdev.c
>> +++ b/drivers/net/virtio/virtio_user_ethdev.c
>> @@ -281,6 +281,8 @@ virtio_user_get_status(struct virtio_hw *hw)  {
>>  	struct virtio_user_dev *dev = virtio_user_get_dev(hw);
>>
>> +	virtio_user_update_status(dev);
>> +
>>  	return dev->status;
>>  }
>>
>> --
>> 2.26.2
>
  
David Marchand July 16, 2020, 8:18 a.m. UTC | #3
On Thu, Jul 16, 2020 at 9:53 AM Adrian Moreno <amorenoz@redhat.com> wrote:
> >> +    if (ret > UINT8_MAX) {
> >> +            PMD_INIT_LOG(ERR, "Invalid VHOST_USER_GET_STATUS
> >> response 0x%" PRIx64 "\n", ret);
> >
> > There's a coding style issue here:
> > CHECK:CAMELCASE: Avoid CamelCase: <PRIx64>
> > Could you fix this?
>
> I did see this one as well. It also seems new because PRIx64 is widely used in DPDK.
>
> find -iname *.c | xargs grep -i "PRIx64" | wc -l
> 520
>
> So, ether we have to modify the script to ignore this one or change all 520
> cases, right?

This is a false positive.
We won't drop use of this standard macro because checkpatch is not
happy with it.

I don't see how to silence this warning but I can see that the kernel
uses this macro: so I guess people are simply ignoring this one.
  
Adrian Moreno July 16, 2020, 8:28 a.m. UTC | #4
On 7/16/20 10:18 AM, David Marchand wrote:
> On Thu, Jul 16, 2020 at 9:53 AM Adrian Moreno <amorenoz@redhat.com> wrote:
>>>> +    if (ret > UINT8_MAX) {
>>>> +            PMD_INIT_LOG(ERR, "Invalid VHOST_USER_GET_STATUS
>>>> response 0x%" PRIx64 "\n", ret);
>>>
>>> There's a coding style issue here:
>>> CHECK:CAMELCASE: Avoid CamelCase: <PRIx64>
>>> Could you fix this?
>>
>> I did see this one as well. It also seems new because PRIx64 is widely used in DPDK.
>>
>> find -iname *.c | xargs grep -i "PRIx64" | wc -l
>> 520
>>
>> So, ether we have to modify the script to ignore this one or change all 520
>> cases, right?
> 
> This is a false positive.
> We won't drop use of this standard macro because checkpatch is not
> happy with it.
> 
> I don't see how to silence this warning but I can see that the kernel
> uses this macro: so I guess people are simply ignoring this one.
> 
> 

Thanks David!
  

Patch

diff --git a/drivers/net/virtio/virtio_user/vhost_user.c b/drivers/net/virtio/virtio_user/vhost_user.c
index 2332e01d1..43c630e47 100644
--- a/drivers/net/virtio/virtio_user/vhost_user.c
+++ b/drivers/net/virtio/virtio_user/vhost_user.c
@@ -279,6 +279,7 @@  vhost_user_sock(struct virtio_user_dev *dev,
 	switch (req) {
 	case VHOST_USER_GET_FEATURES:
 	case VHOST_USER_GET_PROTOCOL_FEATURES:
+	case VHOST_USER_GET_STATUS:
 		need_reply = 1;
 		break;
 
@@ -373,6 +374,7 @@  vhost_user_sock(struct virtio_user_dev *dev,
 
 		switch (req) {
 		case VHOST_USER_GET_FEATURES:
+		case VHOST_USER_GET_STATUS:
 		case VHOST_USER_GET_PROTOCOL_FEATURES:
 			if (msg.size != sizeof(m.payload.u64)) {
 				PMD_DRV_LOG(ERR, "Received bad msg size");
diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c
index 2c400a448..613caef56 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
@@ -804,3 +804,42 @@  virtio_user_send_status_update(struct virtio_user_dev *dev, uint8_t status)
 
 	return 0;
 }
+
+int
+virtio_user_update_status(struct virtio_user_dev *dev)
+{
+	uint64_t ret;
+
+	/* Vhost-user only for now */
+	if (!is_vhost_user_by_type(dev->path))
+		return 0;
+
+	if (!(dev->protocol_features & (1UL << VHOST_USER_PROTOCOL_F_STATUS)))
+		return 0;
+
+	if (dev->ops->send_request(dev, VHOST_USER_GET_STATUS, &ret) < 0) {
+		PMD_INIT_LOG(ERR, "GET_STATUS failed: %s", strerror(errno));
+		return -1;
+	}
+	if (ret > UINT8_MAX) {
+		PMD_INIT_LOG(ERR, "Invalid VHOST_USER_GET_STATUS response 0x%" PRIx64 "\n", ret);
+		return -1;
+	}
+
+	dev->status = ret;
+	PMD_INIT_LOG(DEBUG, "Updated Device Status(0x%08x):\n"
+			"\t-ACKNOWLEDGE: %u\n"
+			"\t-DRIVER: %u\n"
+			"\t-DRIVER_OK: %u\n"
+			"\t-FEATURES_OK: %u\n"
+			"\t-DEVICE_NEED_RESET: %u\n"
+			"\t-FAILED: %u\n",
+			dev->status,
+			!!(dev->status & VIRTIO_CONFIG_STATUS_ACK),
+			!!(dev->status & VIRTIO_CONFIG_STATUS_DRIVER),
+			!!(dev->status & VIRTIO_CONFIG_STATUS_DRIVER_OK),
+			!!(dev->status & VIRTIO_CONFIG_STATUS_FEATURES_OK),
+			!!(dev->status & VIRTIO_CONFIG_STATUS_DEV_NEED_RESET),
+			!!(dev->status & VIRTIO_CONFIG_STATUS_FAILED));
+	return 0;
+}
diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.h b/drivers/net/virtio/virtio_user/virtio_user_dev.h
index a76d7cfaf..1a045af6f 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.h
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h
@@ -75,4 +75,5 @@  void virtio_user_handle_cq_packed(struct virtio_user_dev *dev,
 				  uint16_t queue_idx);
 uint8_t virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs);
 int virtio_user_send_status_update(struct virtio_user_dev *dev, uint8_t status);
+int virtio_user_update_status(struct virtio_user_dev *dev);
 #endif
diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c
index e52f11341..40330deed 100644
--- a/drivers/net/virtio/virtio_user_ethdev.c
+++ b/drivers/net/virtio/virtio_user_ethdev.c
@@ -281,6 +281,8 @@  virtio_user_get_status(struct virtio_hw *hw)
 {
 	struct virtio_user_dev *dev = virtio_user_get_dev(hw);
 
+	virtio_user_update_status(dev);
+
 	return dev->status;
 }