yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
ae23c9
From 3fcc45e3b9a204454910832f2c9a7fcfc28a0d07 Mon Sep 17 00:00:00 2001
ae23c9
From: Paolo Bonzini <pbonzini@redhat.com>
ae23c9
Date: Thu, 20 Dec 2018 12:31:00 +0000
ae23c9
Subject: [PATCH 5/8] scsi-generic: keep VPD page list sorted
ae23c9
ae23c9
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
ae23c9
Message-id: <20181220123103.29579-6-pbonzini@redhat.com>
ae23c9
Patchwork-id: 83714
ae23c9
O-Subject: [PATCH 5/8] scsi-generic: keep VPD page list sorted
ae23c9
Bugzilla: 1639957
ae23c9
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
ae23c9
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
ae23c9
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
ae23c9
ae23c9
Block limits emulation is just placing 0xb0 as the final byte of the
ae23c9
VPD pages list.  However, VPD page numbers must be sorted, so change
ae23c9
that to an in-place insert.  Since I couldn't find any disk that triggered
ae23c9
the loop more than once, this was tested by adding manually 0xb1
ae23c9
at the end of the list and checking that 0xb0 was added before.
ae23c9
ae23c9
Reported-by: Max Reitz <mreitz@redhat.com>
ae23c9
Reviewed-by: Max Reitz <mreitz@redhat.com>
ae23c9
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
ae23c9
(cherry picked from commit 6c219fc8a112fc69b29f59ea2c7865717ff6e3e0)
ae23c9
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ae23c9
---
ae23c9
 hw/scsi/scsi-generic.c | 19 +++++++++++++++----
ae23c9
 1 file changed, 15 insertions(+), 4 deletions(-)
ae23c9
ae23c9
diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c
ae23c9
index 4266003..98c6a34 100644
ae23c9
--- a/hw/scsi/scsi-generic.c
ae23c9
+++ b/hw/scsi/scsi-generic.c
ae23c9
@@ -145,7 +145,7 @@ static int execute_command(BlockBackend *blk,
ae23c9
 
ae23c9
 static void scsi_handle_inquiry_reply(SCSIGenericReq *r, SCSIDevice *s)
ae23c9
 {
ae23c9
-    uint8_t page, page_len;
ae23c9
+    uint8_t page, page_idx;
ae23c9
 
ae23c9
     /*
ae23c9
      *  EVPD set to zero returns the standard INQUIRY data.
ae23c9
@@ -191,10 +191,21 @@ static void scsi_handle_inquiry_reply(SCSIGenericReq *r, SCSIDevice *s)
ae23c9
              *
ae23c9
              * This way, the guest kernel will be aware of the support
ae23c9
              * and will use it to proper setup the SCSI device.
ae23c9
+             *
ae23c9
+             * VPD page numbers must be sorted, so insert 0xb0 at the
ae23c9
+             * right place with an in-place insert.  After the initialization
ae23c9
+             * part of the for loop is executed, the device response is
ae23c9
+             * at r[0] to r[page_idx - 1].
ae23c9
              */
ae23c9
-            page_len = r->buf[3];
ae23c9
-            r->buf[page_len + 4] = 0xb0;
ae23c9
-            r->buf[3] = ++page_len;
ae23c9
+            for (page_idx = lduw_be_p(r->buf + 2) + 4;
ae23c9
+                 page_idx > 4 && r->buf[page_idx - 1] >= 0xb0;
ae23c9
+                 page_idx--) {
ae23c9
+                if (page_idx < r->buflen) {
ae23c9
+                    r->buf[page_idx] = r->buf[page_idx - 1];
ae23c9
+                }
ae23c9
+            }
ae23c9
+            r->buf[page_idx] = 0xb0;
ae23c9
+            stw_be_p(r->buf + 2, lduw_be_p(r->buf + 2) + 1);
ae23c9
         }
ae23c9
     }
ae23c9
 }
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9