Skip to contentSkip to conversation

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

RFC PATCH Superseded Philippe Mathieu-Daudé 3 participants 10 messages Jan 18, 2021 – Jan 20, 2021 SCSI

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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 "Illegal Request - parameter not supported".

Philippe Mathieu-Daud=C3=A9 (2):
scsi/utils: Add INVALID_PARAM_VALUE sense code definition hw/usb/dev-uas: Report command additional adb length as unsupported

 include/scsi/utils.h |  2 ++
 hw/usb/dev-uas.c     | 12 +++++++++++-
 scsi/utils.c         |  5 +++++
 3 files changed, 18 insertions(+), 1 deletion(-)

--=20
2.26.2

#1 lore raw

RFC PATCH 1/2 scsi/utils: Add INVALID_PARAM_VALUE sense code definition

---
 include/scsi/utils.h | 2 ++
 scsi/utils.c         | 5 +++++
 2 files changed, 7 insertions(+)
include/scsi/utils.h +2 -0
index fbc55882799..096489c6cd1 100644
@@ -57,6 +57,8 @@ extern const struct SCSISense sense_code_LBA_OUT_OF_RANGE;
 extern const struct SCSISense sense_code_INVALID_FIELD;
 /* Illegal request, Invalid field in parameter list */
 extern const struct SCSISense sense_code_INVALID_PARAM;
+/* Illegal request, Invalid value in parameter list */
+extern const struct SCSISense sense_code_INVALID_PARAM_VALUE;
 /* Illegal request, Parameter list length error */
 extern const struct SCSISense sense_code_INVALID_PARAM_LEN;
 /* Illegal request, LUN not supported */
scsi/utils.c +5 -0
index b37c2830148..793c3a6b9c9 100644
@@ -197,6 +197,11 @@ const struct SCSISense sense_code_INVALID_PARAM = {
     .key = ILLEGAL_REQUEST, .asc = 0x26, .ascq = 0x00
 };
 
+/* Illegal request, Invalid value in parameter list */
+const struct SCSISense sense_code_INVALID_PARAM_VALUE = {
+    .key = ILLEGAL_REQUEST, .asc = 0x26, .ascq = 0x01
+};
+
 /* Illegal 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
Reviewed-by on v1 1/2
#2 lore raw

Re: [RFC PATCH 1/2] scsi/utils: Add INVALID_PARAM_VALUE sense code definition

Quoted 11 lines · Philippe Mathieu-Daudé
---
 include/scsi/utils.h | 2 ++
 scsi/utils.c         | 5 +++++
 2 files changed, 7 insertions(+)
include/scsi/utils.h +0 -0
index fbc55882799..096489c6cd1 100644

include/scsi/utils.h extern const struct SCSISense sense_code_LBA_OUT_OF_RANGE; · line 64

Quoted 8 lines
include/scsi/utils.h +2 -0
@@ -57,6 +57,8 @@ extern const struct SCSISense sense_code_LBA_OUT_OF_RANGE;
 extern const struct SCSISense sense_code_INVALID_FIELD;
 /* Illegal request, Invalid field in parameter list */
 extern const struct SCSISense sense_code_INVALID_PARAM;
+/* Illegal request, Invalid value in parameter list */
+extern const struct SCSISense sense_code_INVALID_PARAM_VALUE;
 /* Illegal request, Parameter list length error */
 extern const struct SCSISense sense_code_INVALID_PARAM_LEN;
 /* Illegal request, LUN not supported */

Pre-existing: the term 'illegal' is suspect in computer science (the code isn't breaking any laws); I prefer 'invalid'. But that's a pet peeve of mine, and not something you need to change here.

Quoted 7 lines
scsi/utils.c +0 -0
index b37c2830148..793c3a6b9c9 100644
@@ -197,6 +197,11 @@ const struct SCSISense sense_code_INVALID_PARAM = {
     .key = ILLEGAL_REQUEST, .asc = 0x26, .ascq = 0x00

scsi/utils.c const struct SCSISense sense_code_INVALID_PARAM = { · line 207

Quoted 10 lines
scsi/utils.c +5 -0
 };
 
+/* Illegal request, Invalid value in parameter list */
+const struct SCSISense sense_code_INVALID_PARAM_VALUE = {
+    .key = ILLEGAL_REQUEST, .asc = 0x26, .ascq = 0x01
+};
+
 /* Illegal request, Parameter list length error */
 const struct SCSISense sense_code_INVALID_PARAM_LEN = {
     .key = ILLEGAL_REQUEST, .asc = 0x1a, .ascq = 0x00
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#3 lore raw

Re: [RFC PATCH 1/2] scsi/utils: Add INVALID_PARAM_VALUE sense code definition

Hi,

Quoted 5 lines

include/scsi/utils.h extern const struct SCSISense sense_code_LBA_OUT_OF_RANGE; · line 61

Quoted 2 lines
include/scsi/utils.h +2 -0
+/* Illegal request, Invalid value in parameter list */
+extern const struct SCSISense sense_code_INVALID_PARAM_VALUE;

Pre-existing: the term 'illegal' is suspect in computer science (the code isn't breaking any laws);

Indeed. It's named that way in the scsi specs though, and being consistent with that is a reasonable thing too ...

take care,
Gerd

#4 lore raw

Re: [RFC PATCH 1/2] scsi/utils: Add INVALID_PARAM_VALUE sense code definition

Quoted 10 lines · Gerd Hoffmann

Hi,

Quoted 5 lines

include/scsi/utils.h extern const struct SCSISense sense_code_LBA_OUT_OF_RANGE; · line 61

Quoted 2 lines
include/scsi/utils.h +2 -0
+/* Illegal request, Invalid value in parameter list */
+extern const struct SCSISense sense_code_INVALID_PARAM_VALUE;

Pre-existing: the term 'illegal' is suspect in computer science (the code isn't breaking any laws);

Indeed. It's named that way in the scsi specs though, and being consistent with that is a reasonable thing too ...

In v2 I renamed 'illegal' in the description comments but not in the #definitions (which match the specs).

Regards,

Phil.

#5 lore raw

RFC PATCH 2/2 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 send a packet with such additional data, report the command parameter as not supported.

We can then explicit there is nothing in this additional buffer, by fixing its size to zero.

This fixes an error when building with Clang 11:

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: Ed Maste <[email protected]>
Cc: Han Han <[email protected]>
Cc: Marc-André Lureau <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Gustavo A. R. Silva <[email protected]>

---
 hw/usb/dev-uas.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
hw/usb/dev-uas.c +11 -1
index cec071d96c4..b6434ad4b9c 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[0];      /* 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
#6 lore raw

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

Quoted 8 lines · Philippe Mathieu-Daudé

We are not ready to handle additional CDB data.

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

We can then explicit there is nothing in this additional buffer, by fixing its size to zero.

Quoted 7 lines

This fixes an error when building with Clang 11:

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;
                                ^

TBH this should be (chronological order):

Quoted 56 lines

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

---
 hw/usb/dev-uas.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
hw/usb/dev-uas.c +11 -1
index cec071d96c4..b6434ad4b9c 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[0];      /* 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;
Reviewed-by on v1 2/2
#7 lore raw

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

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

We are not ready to handle additional CDB data.

If a guest send a packet with such additional data,

sends

Quoted 3 lines

report the command parameter as not supported.

We can then explicit there is nothing in this additional

then be explicit that there

Quoted 33 lines

buffer, by fixing its size to zero.

This fixes an error when building with Clang 11:

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: Ed Maste <[email protected]>
Cc: Han Han <[email protected]>
Cc: Marc-André Lureau <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Gustavo A. R. Silva <[email protected]>

---
 hw/usb/dev-uas.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
hw/usb/dev-uas.c +1 -0
index cec071d96c4..b6434ad4b9c 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"

hw/usb/dev-uas.c typedef struct { · line 75

Quoted 6 lines
hw/usb/dev-uas.c +1 -1
@@ -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[0];      /* not supported by QEMU */
 } QEMU_PACKED  uas_iu_command;

Technically, a zero-sized array is also a gcc/clang extension, and may bite us later if that extension starts triggering compiler complaints in one of the two compilers, just as our current use of an extension is causing grief in clang 11. But in the short term, it works, and gets rid of the more problematic extension of a dynamically-sized type preventing the determination of a packed union containing that type.

Quoted 16 lines
hw/usb/dev-uas.c +5 -0
 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;
     }

hw/usb/dev-uas.c static void usb_uas_command(UASDevice *uas, uas_iu *iu) · line 750

Quoted 10 lines
hw/usb/dev-uas.c +4 -0
@@ -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 · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#8 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 9 lines · Philippe Mathieu-Daudé

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 "Illegal Request - parameter not supported".

Why rfc? looks good to me as-is ;)

thanks,
Gerd

#9 lore raw
Quoted 11 lines · Gerd Hoffmann
Quoted 9 lines · Philippe Mathieu-Daudé

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 "Illegal Request - parameter not supported".

Quoted 1 line

Why rfc? looks good to me as-is ;)

Sorry I forgot to explain. RFC because I don't know enough SCSI to be sure than the device returning sense_code_INVALID_PARAM_VALUE on the bus is appropriate. This is the best fit I could find.

Quoted 4 lines

thanks,
Gerd