libvirtio: Mark struct virtio_scsi_req_cmd as packed

Message ID 1509652882-7144-1-git-send-email-thuth@redhat.com
State Accepted
Headers show
Series
  • libvirtio: Mark struct virtio_scsi_req_cmd as packed
Related show

Commit Message

Thomas Huth Nov. 2, 2017, 8:01 p.m.
The struct contains an uneven amount of bytes, so we should use
the "packed" attribute to avoid padding problems here. So far the
problems did not show up yet since the struct is filled by Forth
code only and QEMU seems to be quite forgiving about the length of
the descriptor, but anyway, let's better be safe than sorry here.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 lib/libvirtio/virtio-scsi.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Thomas Huth Dec. 6, 2017, 8:08 a.m. | #1
On 02.11.2017 21:01, Thomas Huth wrote:
> The struct contains an uneven amount of bytes, so we should use
> the "packed" attribute to avoid padding problems here. So far the
> problems did not show up yet since the struct is filled by Forth
> code only and QEMU seems to be quite forgiving about the length of
> the descriptor, but anyway, let's better be safe than sorry here.
> 
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>  lib/libvirtio/virtio-scsi.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/libvirtio/virtio-scsi.h b/lib/libvirtio/virtio-scsi.h
> index 451ba4d..d598dea 100644
> --- a/lib/libvirtio/virtio-scsi.h
> +++ b/lib/libvirtio/virtio-scsi.h
> @@ -47,7 +47,7 @@ struct virtio_scsi_req_cmd {
>      uint8_t prio;
>      uint8_t crn;
>      char cdb[VIRTIO_SCSI_CDB_SIZE];
> -};
> +} __attribute__((packed));
>  
>  /* This is the first element of the "in" scatter-gather list. */
>  struct virtio_scsi_resp_cmd {
> 

Ping?
Nikunj A Dadhania Dec. 6, 2017, 8:42 a.m. | #2
Thomas Huth <thuth@redhat.com> writes:

> The struct contains an uneven amount of bytes, so we should use
> the "packed" attribute to avoid padding problems here. So far the
> problems did not show up yet since the struct is filled by Forth
> code only and QEMU seems to be quite forgiving about the length of
> the descriptor, but anyway, let's better be safe than sorry here.
>
> Signed-off-by: Thomas Huth <thuth@redhat.com>

Reviewed-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
 
> ---
>  lib/libvirtio/virtio-scsi.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/libvirtio/virtio-scsi.h b/lib/libvirtio/virtio-scsi.h
> index 451ba4d..d598dea 100644
> --- a/lib/libvirtio/virtio-scsi.h
> +++ b/lib/libvirtio/virtio-scsi.h
> @@ -47,7 +47,7 @@ struct virtio_scsi_req_cmd {
>      uint8_t prio;
>      uint8_t crn;
>      char cdb[VIRTIO_SCSI_CDB_SIZE];
> -};
> +} __attribute__((packed));
>  
>  /* This is the first element of the "in" scatter-gather list. */
>  struct virtio_scsi_resp_cmd {
> -- 
> 1.8.3.1
>
> _______________________________________________
> SLOF mailing list
> SLOF@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/slof
Alexey Kardashevskiy Dec. 11, 2017, 4:36 a.m. | #3
On 06/12/17 19:08, Thomas Huth wrote:
> On 02.11.2017 21:01, Thomas Huth wrote:
>> The struct contains an uneven amount of bytes, so we should use
>> the "packed" attribute to avoid padding problems here. So far the
>> problems did not show up yet since the struct is filled by Forth
>> code only and QEMU seems to be quite forgiving about the length of
>> the descriptor, but anyway, let's better be safe than sorry here.
>>
>> Signed-off-by: Thomas Huth <thuth@redhat.com>
>> ---
>>  lib/libvirtio/virtio-scsi.h | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/lib/libvirtio/virtio-scsi.h b/lib/libvirtio/virtio-scsi.h
>> index 451ba4d..d598dea 100644
>> --- a/lib/libvirtio/virtio-scsi.h
>> +++ b/lib/libvirtio/virtio-scsi.h
>> @@ -47,7 +47,7 @@ struct virtio_scsi_req_cmd {
>>      uint8_t prio;
>>      uint8_t crn;
>>      char cdb[VIRTIO_SCSI_CDB_SIZE];
>> -};
>> +} __attribute__((packed));
>>  
>>  /* This is the first element of the "in" scatter-gather list. */
>>  struct virtio_scsi_resp_cmd {
>>
> 
> Ping?


Thanks, applied.

Patch

diff --git a/lib/libvirtio/virtio-scsi.h b/lib/libvirtio/virtio-scsi.h
index 451ba4d..d598dea 100644
--- a/lib/libvirtio/virtio-scsi.h
+++ b/lib/libvirtio/virtio-scsi.h
@@ -47,7 +47,7 @@  struct virtio_scsi_req_cmd {
     uint8_t prio;
     uint8_t crn;
     char cdb[VIRTIO_SCSI_CDB_SIZE];
-};
+} __attribute__((packed));
 
 /* This is the first element of the "in" scatter-gather list. */
 struct virtio_scsi_resp_cmd {