From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41052) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WxEnx-0005Gb-1d for qemu-devel@nongnu.org; Wed, 18 Jun 2014 08:17:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WxEnn-0003Jr-QQ for qemu-devel@nongnu.org; Wed, 18 Jun 2014 08:17:28 -0400 Received: from e06smtp13.uk.ibm.com ([195.75.94.109]:57440) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WxEnn-0003Jf-Ie for qemu-devel@nongnu.org; Wed, 18 Jun 2014 08:17:19 -0400 Received: from /spool/local by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 18 Jun 2014 13:17:18 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id 8E92E17D8059 for ; Wed, 18 Jun 2014 13:18:38 +0100 (BST) Received: from d06av01.portsmouth.uk.ibm.com (d06av01.portsmouth.uk.ibm.com [9.149.37.212]) by b06cxnps4074.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s5ICHE6322478878 for ; Wed, 18 Jun 2014 12:17:14 GMT Received: from d06av01.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av01.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s5ICHCKQ029091 for ; Wed, 18 Jun 2014 06:17:13 -0600 From: Jens Freimann Date: Wed, 18 Jun 2014 14:16:46 +0200 Message-Id: <1403093807-32836-4-git-send-email-jfrei@linux.vnet.ibm.com> In-Reply-To: <1403093807-32836-1-git-send-email-jfrei@linux.vnet.ibm.com> References: <1403093807-32836-1-git-send-email-jfrei@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 3/4] pc-bios/s390-ccw: fix for fragmented SCSI bootmap List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Christian Borntraeger , Alexander Graf , Cornelia Huck Cc: "Eugene (jno) Dvurechenski" , Jens Freimann , qemu-devel@nongnu.org From: "Eugene (jno) Dvurechenski" We need to interpret the last entry of the bootmap with zero block count as "continuation pointer". The "last entry" is being detected by pre-filling of the scratch space with known values and respective look-ahead. Signed-off-by: Eugene (jno) Dvurechenski Signed-off-by: Jens Freimann Tested-by: Christian Borntraeger Reviewed-by: David Hildenbrand Reviewed-by: Cornelia Huck --- pc-bios/s390-ccw/bootmap.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/pc-bios/s390-ccw/bootmap.c b/pc-bios/s390-ccw/bootmap.c index c07553b..5ee3fcb 100644 --- a/pc-bios/s390-ccw/bootmap.c +++ b/pc-bios/s390-ccw/bootmap.c @@ -118,10 +118,26 @@ static int zipl_magic(uint8_t *ptr) return 1; } +#define FREE_SPACE_FILLER '\xAA' + +static inline bool unused_space(const void *p, unsigned int size) +{ + int i; + const unsigned char *m = p; + + for (i = 0; i < size; i++) { + if (m[i] != FREE_SPACE_FILLER) { + return false; + } + } + return true; +} + static int zipl_load_segment(struct component_entry *entry) { const int max_entries = (SECTOR_SIZE / sizeof(struct scsi_blockptr)); struct scsi_blockptr *bprs = (void*)sec; + const int bprs_size = sizeof(sec); uint64_t blockno; long address; int i; @@ -133,6 +149,7 @@ static int zipl_load_segment(struct component_entry *entry) debug_print_int("addr", address); do { + memset(bprs, FREE_SPACE_FILLER, bprs_size); if (virtio_read(blockno, (uint8_t *)bprs)) { debug_print_int("failed reading bprs at", blockno); goto fail; @@ -150,6 +167,16 @@ static int zipl_load_segment(struct component_entry *entry) if (i == (max_entries - 1)) break; + if (bprs[i].blockct == 0 && unused_space(&bprs[i + 1], + sizeof(struct scsi_blockptr))) { + /* This is a "continue" pointer. + * This ptr is the last one in the current script section. + * I.e. the next ptr must point to the unused memory area. + * The blockno is not zero, so the upper loop must continue + * reading next section of BPRS. + */ + break; + } address = virtio_load_direct(cur_desc[0], cur_desc[1], 0, (void*)address); if (address == -1) -- 1.8.5.5