From: "Jan Beulich" Subject: [PATCH] x86/boot: re-arrange how/when we do disk I/O Date: Mon, 12 Jun 2017 09:11:57 -0600 Message-ID: <593ECB5D0200007800162126@prv-mh.provo.novell.com> References: <593ECB5D0200007800162126@prv-mh.provo.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part8DB5E72D.2__=" Return-path: Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dKR0d-00013o-Pv for xen-devel@lists.xenproject.org; Mon, 12 Jun 2017 15:12:03 +0000 List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" To: xen-devel Cc: Andrew Cooper , Julien Grall , Paul Durrant List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part8DB5E72D.2__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline We place the trampoline no lower than at 256k, so we have ample space to read the MBRs of BIOS disks into an aligned buffer right below the trampoline (not doing so has been found to be a problem on a buggy BIOS coming with a Skull Canyon NUC). To facilitate that move MBR reading past EDD info retrieval. Also add a wrap check to the EDD info retrieval loop, to match that in the MBR reading one. Reported-by: Paul Durrant Signed-off-by: Jan Beulich Tested-by: Paul Durrant --- Using 512-byte sector size as default right now - perhaps worth considering to use 4k instead. I'm also not sure whether we shouldn't sanity check the sector size some more. --- a/xen/arch/x86/boot/edd.S +++ b/xen/arch/x86/boot/edd.S @@ -26,46 +26,6 @@ get_edd: cmpb $2, bootsym(opt_edd) # edd=3Doff ? je edd_done - cmpb $1, bootsym(opt_edd) # edd=3Dskipmbr ? - je edd_start - -# Read the first sector of each BIOS disk device and store the 4-byte = signature -edd_mbr_sig_start: - movb $0x80, %dl # from device 80 - movw $bootsym(boot_mbr_signature),%bx # store buffer ptr in bx -edd_mbr_sig_read: - pushw %bx - movb $0x02, %ah # 0x02 Read Sectors - movb $1, %al # read 1 sector - movb $0, %dh # at head 0 - movw $1, %cx # cylinder 0, sector 0 - pushw %es - pushw %ds - popw %es - movw $bootsym(boot_edd_info), %bx # disk's data goes into = info - pushw %dx # work around buggy BIOSes - stc # work around buggy BIOSes - int $0x13 - sti # work around buggy BIOSes - popw %dx - popw %es - popw %bx - jc edd_mbr_sig_done # on failure, we're done. - cmpb $0, %ah # some BIOSes do not set = CF - jne edd_mbr_sig_done # on failure, we're done. - cmpw $0xaa55, bootsym(boot_edd_info)+0x1fe - jne .Ledd_mbr_sig_next - movl bootsym(boot_edd_info)+EDD_MBR_SIG_OFFSET,%eax - movb %dl, (%bx) # store BIOS drive number - movl %eax, 4(%bx) # store signature from = MBR - incb bootsym(boot_mbr_signature_nr) # note that we stored = something - addw $8, %bx # increment sig buffer = ptr -.Ledd_mbr_sig_next: - incb %dl # increment to next = device - jz edd_mbr_sig_done - cmpb $EDD_MBR_SIG_MAX,bootsym(boot_mbr_signature_nr) - jb edd_mbr_sig_read -edd_mbr_sig_done: =20 # Do the BIOS Enhanced Disk Drive calls # This consists of two calls: @@ -136,10 +96,71 @@ edd_legacy_done: =20 edd_next: incb %dl # increment to next = device + jz edd_done cmpb $EDD_INFO_MAX,bootsym(boot_edd_info_nr) jb edd_check_ext =20 edd_done: + cmpb $1, bootsym(opt_edd) # edd=3Dskipmbr ? + je .Ledd_mbr_sig_skip + +# Read the first sector of each BIOS disk device and store the 4-byte = signature +.Ledd_mbr_sig_start: + pushw %es + movb $0x80, %dl # from device 80 + movw $bootsym(boot_mbr_signature), %bx # store buffer ptr in = bx +.Ledd_mbr_sig_read: + pushw %bx + movw $bootsym(boot_edd_info), %bx + movzbw bootsym(boot_edd_info_nr), %cx + jcxz .Ledd_mbr_sig_default +.Ledd_mbr_sig_find_info: + cmpb %dl, (%bx) + ja .Ledd_mbr_sig_default + je .Ledd_mbr_sig_get_size + add $EDDEXTSIZE+EDDPARMSIZE, %bx + loop .Ledd_mbr_sig_find_info +.Ledd_mbr_sig_default: + movw $(512 >> 4), %bx + jmp .Ledd_mbr_sig_set_buf +.Ledd_mbr_sig_get_size: + movw EDDEXTSIZE+0x18(%bx), %bx # sector size + shr $4, %bx # convert to paragraphs + jz .Ledd_mbr_sig_default +.Ledd_mbr_sig_set_buf: + movw %ds, %ax + subw %bx, %ax # disk's data goes right = ahead + movw %ax, %es # of trampoline + xorw %bx, %bx + movw %bx, %es:0x1fe(%bx) # clear BIOS magic just = in case + pushw %dx # work around buggy = BIOSes + stc # work around buggy = BIOSes + movw $0x0201, %ax # read 1 sector + movb $0, %dh # at head 0 + movw $1, %cx # cylinder 0, sector 0 + int $0x13 + sti # work around buggy = BIOSes + popw %dx + movw %es:0x1fe(%bx), %si + movl %es:EDD_MBR_SIG_OFFSET(%bx), %ecx + popw %bx + jc .Ledd_mbr_sig_done # on failure, we're done. + testb %ah, %ah # some BIOSes do not set = CF + jnz .Ledd_mbr_sig_done # on failure, we're done. + cmpw $0xaa55, %si + jne .Ledd_mbr_sig_next + movb %dl, (%bx) # store BIOS drive number + movl %ecx, 4(%bx) # store signature from = MBR + incb bootsym(boot_mbr_signature_nr) # note that we stored = something + addw $8, %bx # increment sig buffer = ptr +.Ledd_mbr_sig_next: + incb %dl # increment to next = device + jz .Ledd_mbr_sig_done + cmpb $EDD_MBR_SIG_MAX, bootsym(boot_mbr_signature_nr) + jb .Ledd_mbr_sig_read +.Ledd_mbr_sig_done: + popw %es +.Ledd_mbr_sig_skip: ret =20 GLOBAL(boot_edd_info_nr) @@ -149,4 +170,4 @@ GLOBAL(boot_mbr_signature_nr) GLOBAL(boot_mbr_signature) .fill EDD_MBR_SIG_MAX*8,1,0 GLOBAL(boot_edd_info) - .fill 512,1,0 # big enough for a disc = sector + .fill EDD_INFO_MAX * (EDDEXTSIZE + EDDPARMSIZE), 1, 0 --=__Part8DB5E72D.2__= Content-Type: text/plain; name="x86-MBR-below-trampoline.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-MBR-below-trampoline.patch" x86/boot: re-arrange how/when we do disk I/O=0A=0AWe place the trampoline = no lower than at 256k, so we have ample space=0Ato read the MBRs of BIOS = disks into an aligned buffer right below the=0Atrampoline (not doing so = has been found to be a problem on a buggy BIOS=0Acoming with a Skull = Canyon NUC). To facilitate that move MBR reading=0Apast EDD info retrieval.= =0A=0AAlso add a wrap check to the EDD info retrieval loop, to match that = in=0Athe MBR reading one.=0A=0AReported-by: Paul Durrant =0ASigned-off-by: Jan Beulich =0ATested-by: Paul = Durrant =0A---=0AUsing 512-byte sector size as = default right now - perhaps worth=0Aconsidering to use 4k instead. I'm = also not sure whether we shouldn't=0Asanity check the sector size some = more.=0A=0A--- a/xen/arch/x86/boot/edd.S=0A+++ b/xen/arch/x86/boot/edd.S=0A= @@ -26,46 +26,6 @@=0A get_edd:=0A cmpb $2, bootsym(opt_edd) = # edd=3Doff ?=0A je edd_done=0A- cmpb $1, = bootsym(opt_edd) # edd=3Dskipmbr ?=0A- je = edd_start=0A-=0A-# Read the first sector of each BIOS disk device and = store the 4-byte signature=0A-edd_mbr_sig_start:=0A- movb $0x80, = %dl # from device 80=0A- movw $bootsym(boot_= mbr_signature),%bx # store buffer ptr in bx=0A-edd_mbr_sig_read:=0A- = pushw %bx=0A- movb $0x02, %ah # 0x02 = Read Sectors=0A- movb $1, %al # read 1 = sector=0A- movb $0, %dh # at head 0=0A- = movw $1, %cx # cylinder 0, sector 0=0A- = pushw %es=0A- pushw %ds=0A- popw %es=0A- = movw $bootsym(boot_edd_info), %bx # disk's data goes into info=0A- = pushw %dx # work around buggy BIOSes=0A- stc = # work around buggy BIOSes=0A- int $0x13=0A- = sti # work around buggy BIOSes=0A- popw = %dx=0A- popw %es=0A- popw %bx=0A- jc = edd_mbr_sig_done # on failure, we're done.=0A- cmpb = $0, %ah # some BIOSes do not set CF=0A- = jne edd_mbr_sig_done # on failure, we're done.=0A- = cmpw $0xaa55, bootsym(boot_edd_info)+0x1fe=0A- jne = .Ledd_mbr_sig_next=0A- movl bootsym(boot_edd_info)+EDD_MBR_SIG_OF= FSET,%eax=0A- movb %dl, (%bx) # store BIOS = drive number=0A- movl %eax, 4(%bx) # store = signature from MBR=0A- incb bootsym(boot_mbr_signature_nr) # = note that we stored something=0A- addw $8, %bx = # increment sig buffer ptr=0A-.Ledd_mbr_sig_next:=0A- incb = %dl # increment to next device=0A- jz = edd_mbr_sig_done=0A- cmpb $EDD_MBR_SIG_MAX,bootsym(boot_mbr_si= gnature_nr)=0A- jb edd_mbr_sig_read=0A-edd_mbr_sig_done:=0A = =0A # Do the BIOS Enhanced Disk Drive calls=0A # This consists of two = calls:=0A@@ -136,10 +96,71 @@ edd_legacy_done:=0A =0A edd_next:=0A = incb %dl # increment to next device=0A+ = jz edd_done=0A cmpb $EDD_INFO_MAX,bootsym(boot_edd_info_= nr)=0A jb edd_check_ext=0A =0A edd_done:=0A+ cmpb = $1, bootsym(opt_edd) # edd=3Dskipmbr ?=0A+ je = .Ledd_mbr_sig_skip=0A+=0A+# Read the first sector of each BIOS disk device = and store the 4-byte signature=0A+.Ledd_mbr_sig_start:=0A+ pushw = %es=0A+ movb $0x80, %dl # from device = 80=0A+ movw $bootsym(boot_mbr_signature), %bx # store buffer ptr = in bx=0A+.Ledd_mbr_sig_read:=0A+ pushw %bx=0A+ movw = $bootsym(boot_edd_info), %bx=0A+ movzbw bootsym(boot_edd_info_nr), = %cx=0A+ jcxz .Ledd_mbr_sig_default=0A+.Ledd_mbr_sig_find_info:=0A= + cmpb %dl, (%bx)=0A+ ja .Ledd_mbr_sig_default=0A+ = je .Ledd_mbr_sig_get_size=0A+ add $EDDEXTSIZE+EDDPARMS= IZE, %bx=0A+ loop .Ledd_mbr_sig_find_info=0A+.Ledd_mbr_sig_defaul= t:=0A+ movw $(512 >> 4), %bx=0A+ jmp .Ledd_mbr_sig_set= _buf=0A+.Ledd_mbr_sig_get_size:=0A+ movw EDDEXTSIZE+0x18(%bx), = %bx # sector size=0A+ shr $4, %bx = # convert to paragraphs=0A+ jz .Ledd_mbr_sig_default=0A+.Ledd_m= br_sig_set_buf:=0A+ movw %ds, %ax=0A+ subw %bx, %ax = # disk's data goes right ahead=0A+ movw %ax, = %es # of trampoline=0A+ xorw %bx, %bx=0A+ = movw %bx, %es:0x1fe(%bx) # clear BIOS magic just in = case=0A+ pushw %dx # work around = buggy BIOSes=0A+ stc # work = around buggy BIOSes=0A+ movw $0x0201, %ax # = read 1 sector=0A+ movb $0, %dh # at head = 0=0A+ movw $1, %cx # cylinder 0, sector = 0=0A+ int $0x13=0A+ sti = # work around buggy BIOSes=0A+ popw %dx=0A+ movw = %es:0x1fe(%bx), %si=0A+ movl %es:EDD_MBR_SIG_OFFSET(%bx), = %ecx=0A+ popw %bx=0A+ jc .Ledd_mbr_sig_done = # on failure, we're done.=0A+ testb %ah, %ah = # some BIOSes do not set CF=0A+ jnz .Ledd_mbr_sig_done = # on failure, we're done.=0A+ cmpw $0xaa55, %si=0A+ = jne .Ledd_mbr_sig_next=0A+ movb %dl, (%bx) = # store BIOS drive number=0A+ movl %ecx, 4(%bx) = # store signature from MBR=0A+ incb bootsym(boot_mbr_sig= nature_nr) # note that we stored something=0A+ addw $8, %bx = # increment sig buffer ptr=0A+.Ledd_mbr_sig_next:=0A+ = incb %dl # increment to next = device=0A+ jz .Ledd_mbr_sig_done=0A+ cmpb $EDD_MBR_SI= G_MAX, bootsym(boot_mbr_signature_nr)=0A+ jb .Ledd_mbr_sig_read= =0A+.Ledd_mbr_sig_done:=0A+ popw %es=0A+.Ledd_mbr_sig_skip:=0A = ret=0A =0A GLOBAL(boot_edd_info_nr)=0A@@ -149,4 +170,4 @@ GLOBAL(boot= _mbr_signature_nr)=0A GLOBAL(boot_mbr_signature)=0A .fill = EDD_MBR_SIG_MAX*8,1,0=0A GLOBAL(boot_edd_info)=0A- .fill 512,1,0 = # big enough for a disc sector=0A+ .fill = EDD_INFO_MAX * (EDDEXTSIZE + EDDPARMSIZE), 1, 0=0A --=__Part8DB5E72D.2__= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KWGVuLWRldmVs IG1haWxpbmcgbGlzdApYZW4tZGV2ZWxAbGlzdHMueGVuLm9yZwpodHRwczovL2xpc3RzLnhlbi5v cmcveGVuLWRldmVsCg== --=__Part8DB5E72D.2__=--