Skip to contentSkip to conversation

hw/usb/dev-uas: Fix Clang 11 -Wgnu-variable-sized-type-not-at-end error

PATCH Applied Philippe Mathieu-Daudé 3 participants 9 messages Jan 20, 2021 – Jan 21, 2021 SCSI

lore
Share & tools
lore
#0 lore raw

v2 cover hw/usb/dev-uas: Fix Clang 11 -Wgnu-variable-sized-type-not-at-end error

Another attempt to fix the following Clang 11 warning:

usb/dev-uas.c:157:31: error: field 'status' with variable sized type 'uas_i=
u' not at the end of a struct or class is a GNU extension [-Werror,-Wgnu-vari= able-sized-type-not-at-end]

      uas_iu                    status;
                                ^

If a guest send a packet with additional data, respond with "Invalid Request - parameter not supported".

v2: Include Eric feedbacks

Philippe Mathieu-Daud=C3=A9 (3):
scsi/utils: Rename 'illegal request' -> 'invalid request' scsi/utils: Add INVALID_PARAM_VALUE sense code definition hw/usb/dev-uas: Report command additional adb length as unsupported

 include/scsi/utils.h | 22 ++++++++++++----------
 hw/usb/dev-uas.c     | 12 +++++++++++-
 scsi/utils.c         | 25 +++++++++++++++----------
 3 files changed, 38 insertions(+), 21 deletions(-)

--=20
2.26.2

#1 lore raw

PATCH v2 1/3 scsi/utils: Rename 'illegal request' -> 'invalid request'

While these requests are invalid, they are not breaking any laws :) Rename 'illegal request' as 'invalid request'.

---
 include/scsi/utils.h | 20 ++++++++++----------
 scsi/utils.c         | 20 ++++++++++----------
 2 files changed, 20 insertions(+), 20 deletions(-)
include/scsi/utils.h +10 -10
index fbc55882799..725769be3cb 100644
@@ -49,25 +49,25 @@ extern const struct SCSISense sense_code_NO_MEDIUM;
 extern const struct SCSISense sense_code_NOT_READY_REMOVAL_PREVENTED;
 /* Hardware error, internal target failure */
 extern const struct SCSISense sense_code_TARGET_FAILURE;
-/* Illegal request, invalid command operation code */
+/* Invalid request, invalid command operation code */
 extern const struct SCSISense sense_code_INVALID_OPCODE;
-/* Illegal request, LBA out of range */
+/* Invalid request, LBA out of range */
 extern const struct SCSISense sense_code_LBA_OUT_OF_RANGE;
-/* Illegal request, Invalid field in CDB */
+/* Invalid request, Invalid field in CDB */
 extern const struct SCSISense sense_code_INVALID_FIELD;
-/* Illegal request, Invalid field in parameter list */
+/* Invalid request, Invalid field in parameter list */
 extern const struct SCSISense sense_code_INVALID_PARAM;
-/* Illegal request, Parameter list length error */
+/* Invalid request, Parameter list length error */
 extern const struct SCSISense sense_code_INVALID_PARAM_LEN;
-/* Illegal request, LUN not supported */
+/* Invalid request, LUN not supported */
 extern const struct SCSISense sense_code_LUN_NOT_SUPPORTED;
-/* Illegal request, Saving parameters not supported */
+/* Invalid request, Saving parameters not supported */
 extern const struct SCSISense sense_code_SAVING_PARAMS_NOT_SUPPORTED;
-/* Illegal request, Incompatible format */
+/* Invalid request, Incompatible format */
 extern const struct SCSISense sense_code_INCOMPATIBLE_FORMAT;
-/* Illegal request, medium removal prevented */
+/* Invalid request, medium removal prevented */
 extern const struct SCSISense sense_code_ILLEGAL_REQ_REMOVAL_PREVENTED;
-/* Illegal request, Invalid Transfer Tag */
+/* Invalid request, Invalid Transfer Tag */
 extern const struct SCSISense sense_code_INVALID_TAG;
 /* Command aborted, I/O process terminated */
 extern const struct SCSISense sense_code_IO_ERROR;
scsi/utils.c +10 -10
index b37c2830148..41ad49459ca 100644
@@ -177,52 +177,52 @@ const struct SCSISense sense_code_TARGET_FAILURE = {
     .key = HARDWARE_ERROR, .asc = 0x44, .ascq = 0x00
 };
 
-/* Illegal request, invalid command operation code */
+/* Invalid request, invalid command operation code */
 const struct SCSISense sense_code_INVALID_OPCODE = {
     .key = ILLEGAL_REQUEST, .asc = 0x20, .ascq = 0x00
 };
 
-/* Illegal request, LBA out of range */
+/* Invalid request, LBA out of range */
 const struct SCSISense sense_code_LBA_OUT_OF_RANGE = {
     .key = ILLEGAL_REQUEST, .asc = 0x21, .ascq = 0x00
 };
 
-/* Illegal request, Invalid field in CDB */
+/* Invalid request, Invalid field in CDB */
 const struct SCSISense sense_code_INVALID_FIELD = {
     .key = ILLEGAL_REQUEST, .asc = 0x24, .ascq = 0x00
 };
 
-/* Illegal request, Invalid field in parameter list */
+/* Invalid request, Invalid field in parameter list */
 const struct SCSISense sense_code_INVALID_PARAM = {
     .key = ILLEGAL_REQUEST, .asc = 0x26, .ascq = 0x00
 };
 
-/* Illegal request, Parameter list length error */
+/* Invalid request, Parameter list length error */
 const struct SCSISense sense_code_INVALID_PARAM_LEN = {
     .key = ILLEGAL_REQUEST, .asc = 0x1a, .ascq = 0x00
 };
 
-/* Illegal request, LUN not supported */
+/* Invalid request, LUN not supported */
 const struct SCSISense sense_code_LUN_NOT_SUPPORTED = {
     .key = ILLEGAL_REQUEST, .asc = 0x25, .ascq = 0x00
 };
 
-/* Illegal request, Saving parameters not supported */
+/* Invalid request, Saving parameters not supported */
 const struct SCSISense sense_code_SAVING_PARAMS_NOT_SUPPORTED = {
     .key = ILLEGAL_REQUEST, .asc = 0x39, .ascq = 0x00
 };
 
-/* Illegal request, Incompatible medium installed */
+/* Invalid request, Incompatible medium installed */
 const struct SCSISense sense_code_INCOMPATIBLE_FORMAT = {
     .key = ILLEGAL_REQUEST, .asc = 0x30, .ascq = 0x00
 };
 
-/* Illegal request, medium removal prevented */
+/* Invalid request, medium removal prevented */
 const struct SCSISense sense_code_ILLEGAL_REQ_REMOVAL_PREVENTED = {
     .key = ILLEGAL_REQUEST, .asc = 0x53, .ascq = 0x02
 };
 
-/* Illegal request, Invalid Transfer Tag */
+/* Invalid request, Invalid Transfer Tag */
 const struct SCSISense sense_code_INVALID_TAG = {
     .key = ILLEGAL_REQUEST, .asc = 0x4b, .ascq = 0x01
 };
Signature · 1 line
2.26.2
Reviewed-by on v2 1/3
#2 lore raw

Re: [PATCH v2 1/3] scsi/utils: Rename 'illegal request' -> 'invalid request'

Quoted 9 lines · Philippe Mathieu-Daudé

While these requests are invalid, they are not breaking any laws :) Rename 'illegal request' as 'invalid request'.

---
 include/scsi/utils.h | 20 ++++++++++----------
 scsi/utils.c         | 20 ++++++++++----------
 2 files changed, 20 insertions(+), 20 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#3 lore raw

Re: [PATCH v2 1/3] scsi/utils: Rename 'illegal request' -> 'invalid request'

In reply to Philippe Mathieu-Daudé
Quoted 2 lines · Philippe Mathieu-Daudé

While these requests are invalid, they are not breaking any laws :) Rename 'illegal request' as 'invalid request'.

Given the scsi spec calls this "illegal request" I think it makes sense to *not* change this and stay consistent with the spec for better grep-ability. Note the variables are already renamed, I expect the comments have been left as-is intentionally ...

take care,
Gerd

#4 lore raw

Re: [PATCH v2 1/3] scsi/utils: Rename 'illegal request' -> 'invalid request'

Quoted 8 lines · Gerd Hoffmann
Quoted 2 lines · Philippe Mathieu-Daudé

While these requests are invalid, they are not breaking any laws :) Rename 'illegal request' as 'invalid request'.

Given the scsi spec calls this "illegal request" I think it makes sense to *not* change this and stay consistent with the spec for better grep-ability. Note the variables are already renamed, I expect the comments have been left as-is intentionally ...

Consistency with the spec and grep-ability takes precedence over any pet peeves of mine. I'm fine if we disregard this patch.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#5 lore raw

PATCH v2 2/3 scsi/utils: Add INVALID_PARAM_VALUE sense code definition

In reply to Philippe Mathieu-Daudé
---
 include/scsi/utils.h | 2 ++
 scsi/utils.c         | 5 +++++
 2 files changed, 7 insertions(+)
include/scsi/utils.h +2 -0
index 725769be3cb..504cde1cc9b 100644
@@ -57,6 +57,8 @@ extern const struct SCSISense sense_code_LBA_OUT_OF_RANGE;
 extern const struct SCSISense sense_code_INVALID_FIELD;
 /* Invalid request, Invalid field in parameter list */
 extern const struct SCSISense sense_code_INVALID_PARAM;
+/* Invalid request, Invalid value in parameter list */
+extern const struct SCSISense sense_code_INVALID_PARAM_VALUE;
 /* Invalid request, Parameter list length error */
 extern const struct SCSISense sense_code_INVALID_PARAM_LEN;
 /* Invalid request, LUN not supported */
scsi/utils.c +5 -0
index 41ad49459ca..e9082da7420 100644
@@ -197,6 +197,11 @@ const struct SCSISense sense_code_INVALID_PARAM = {
     .key = ILLEGAL_REQUEST, .asc = 0x26, .ascq = 0x00
 };
 
+/* Invalid request, Invalid value in parameter list */
+const struct SCSISense sense_code_INVALID_PARAM_VALUE = {
+    .key = ILLEGAL_REQUEST, .asc = 0x26, .ascq = 0x01
+};
+
 /* Invalid request, Parameter list length error */
 const struct SCSISense sense_code_INVALID_PARAM_LEN = {
     .key = ILLEGAL_REQUEST, .asc = 0x1a, .ascq = 0x00
Signature · 1 line
2.26.2
#6 lore raw

PATCH v2 3/3 hw/usb/dev-uas: Report command additional adb length as unsupported

In reply to Philippe Mathieu-Daudé

We are not ready to handle additional CDB data.

If a guest sends a packet with such additional data, report the command parameter as not supported.

Specify a size (of 1 byte) for the add_cdb member we are not using, to fix the following warning:

usb/dev-uas.c:157:31: error: field 'status' with variable sized type 'uas_iu' not at the end of a struct or class is a GNU extension [-Werror,-Wgnu-variable-sized-type-not-at-end]

      uas_iu                    status;
                                ^

---
Cc: Marc-André Lureau <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Gustavo A. R. Silva <[email protected]>

v2: include Eric feedbacks

---
 hw/usb/dev-uas.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
hw/usb/dev-uas.c +11 -1
index cec071d96c4..a51402bc0bf 100644
@@ -16,6 +16,7 @@
 #include "qemu/error-report.h"
 #include "qemu/main-loop.h"
 #include "qemu/module.h"
+#include "qemu/log.h"
 
 #include "hw/usb.h"
 #include "migration/vmstate.h"
@@ -70,7 +71,7 @@ typedef struct {
     uint8_t    reserved_2;
     uint64_t   lun;
     uint8_t    cdb[16];
-    uint8_t    add_cdb[];
+    uint8_t    add_cdb[1];      /* not supported by QEMU */
 } QEMU_PACKED  uas_iu_command;
 
 typedef struct {
@@ -700,6 +701,11 @@ static void usb_uas_command(UASDevice *uas, uas_iu *iu)
     uint32_t len;
     uint16_t tag = be16_to_cpu(iu->hdr.tag);
 
+    if (iu->command.add_cdb_length > 0) {
+        qemu_log_mask(LOG_UNIMP, "additional adb length not yet supported\n");
+        goto unsupported_len;
+    }
+
     if (uas_using_streams(uas) && tag > UAS_MAX_STREAMS) {
         goto invalid_tag;
     }
@@ -735,6 +741,10 @@ static void usb_uas_command(UASDevice *uas, uas_iu *iu)
     }
     return;
 
+unsupported_len:
+    usb_uas_queue_fake_sense(uas, tag, sense_code_INVALID_PARAM_VALUE);
+    return;
+
 invalid_tag:
     usb_uas_queue_fake_sense(uas, tag, sense_code_INVALID_TAG);
     return;
Signature · 1 line
2.26.2
#7 lore raw

Re: [PATCH v2 3/3] hw/usb/dev-uas: Report command additional adb length as unsupported

Quoted 17 lines · Philippe Mathieu-Daudé

We are not ready to handle additional CDB data.

If a guest sends a packet with such additional data, report the command parameter as not supported.

Specify a size (of 1 byte) for the add_cdb member we are not using, to fix the following warning:

usb/dev-uas.c:157:31: error: field 'status' with variable sized type 'uas_iu' not at the end of a struct or class is a GNU extension [-Werror,-Wgnu-variable-sized-type-not-at-end]

      uas_iu                    status;
                                ^
Quoted 6 lines

---
Cc: Marc-André Lureau <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Gustavo A. R. Silva <[email protected]>

v2: include Eric feedbacks

Queued 2+3, fixup #2 conflicts due to dropping #1.

thanks,
Gerd

#8 lore raw

Re: [PATCH v2 3/3] hw/usb/dev-uas: Report command additional adb length as unsupported

Quoted 23 lines · Gerd Hoffmann
Quoted 22 lines · Philippe Mathieu-Daudé

We are not ready to handle additional CDB data.

If a guest sends a packet with such additional data, report the command parameter as not supported.

Specify a size (of 1 byte) for the add_cdb member we are not using, to fix the following warning:

usb/dev-uas.c:157:31: error: field 'status' with variable sized type 'uas_iu' not at the end of a struct or class is a GNU extension [-Werror,-Wgnu-variable-sized-type-not-at-end]

      uas_iu                    status;
                                ^

---
Cc: Marc-André Lureau <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Gustavo A. R. Silva <[email protected]>

Quoted 3 lines
Quoted 1 line

v2: include Eric feedbacks

Queued 2+3, fixup #2 conflicts due to dropping #1.

Thank you!