Bug 182740

Summary: BTX halted on Jetway NF81 motherboard when RAID is enabled
Product: Base System Reporter: Julian Pidancet <julian.pidancet>
Component: amd64Assignee: John Baldwin <jhb>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   

Description Julian Pidancet 2013-10-06 12:30:00 UTC
Just got this brand new motherboard with an AMD APU and an AMD chipset.

Whenever I try to boot FreeBSD and AHCI or RAID is enabled in the BIOS, I am getting this message:

BTX loader 1.00  BTX version is 1.02
int=0000000a  err=00000000  efl=00006402  eip=000093e0
eax=534d4150  ebx=00000001  ecx=00000014  edx=534d4150
esi=00000000  edi=00000004  ebp=00000000  esp=0000004e
cs=0008  ds=0033  es=0033    fs=0033  gs=0033  ss=0010
cs:eip=cf 83 f8 01 75 1a 16 87-86 1f 1e 0f a1 0f a0 0f
       a9 b8 00 a0 00 00 03 44-24 0c 8d 60 04 58 ff d0
ss:esp=00 f0 39 e7 00 f0 e3 21-80 ce 2e e8 00 f0 d2 ef
       00 f0 00 e0 00 f0 f2 e6-00 f0 6e fe 00 f0 53 ff
BTX halted

It looks like to me the BTX is taking an "Invalid TSS" exception while executing an iret instruction.

Fix: 

Selecting "Legacy IDE" mode in the BIOS configuration instead of AHCI/RAID.
How-To-Repeat: I tried: - Booting from the install cdrom
         - Booting from an USB install disk
         - Booting from boot/pxeboot in PXE mode

All exhibit the same issue.
Comment 1 John Baldwin freebsd_committer freebsd_triage 2013-10-07 16:47:32 UTC
On Sunday, October 06, 2013 7:28:31 am Julian Pidancet wrote:
> 
> >Number:         182740
> >Category:       amd64
> >Synopsis:       BTX halted on Jetway NF81 motherboard when RAID is enabled
> >Confidential:   no
> >Severity:       non-critical
> >Priority:       low
> >Responsible:    freebsd-amd64
> >State:          open
> >Quarter:        
> >Keywords:       
> >Date-Required:
> >Class:          sw-bug
> >Submitter-Id:   current-users
> >Arrival-Date:   Sun Oct 06 11:30:00 UTC 2013
> >Closed-Date:
> >Last-Modified:
> >Originator:     Julian Pidancet
> >Release:        8.2
> >Organization:
> >Environment:
> >Description:
> Just got this brand new motherboard with an AMD APU and an AMD chipset.
> 
> Whenever I try to boot FreeBSD and AHCI or RAID is enabled in the BIOS, I am 
getting this message:
> 
> BTX loader 1.00  BTX version is 1.02
> int=0000000a  err=00000000  efl=00006402  eip=000093e0
> eax=534d4150  ebx=00000001  ecx=00000014  edx=534d4150
> esi=00000000  edi=00000004  ebp=00000000  esp=0000004e
> cs=0008  ds=0033  es=0033    fs=0033  gs=0033  ss=0010
> cs:eip=cf 83 f8 01 75 1a 16 87-86 1f 1e 0f a1 0f a0 0f
>        a9 b8 00 a0 00 00 03 44-24 0c 8d 60 04 58 ff d0
> ss:esp=00 f0 39 e7 00 f0 e3 21-80 ce 2e e8 00 f0 d2 ef
>        00 f0 00 e0 00 f0 f2 e6-00 f0 6e fe 00 f0 53 ff
> BTX halted
> 
> It looks like to me the BTX is taking an "Invalid TSS" exception while 
executing an iret instruction.
> >How-To-Repeat:
> I tried: - Booting from the install cdrom
>          - Booting from an USB install disk
>          - Booting from boot/pxeboot in PXE mode
> 
> All exhibit the same issue.
> >Fix:
> Selecting "Legacy IDE" mode in the BIOS configuration instead of AHCI/RAID.

Ok, can you take this patch and use it to build an updated pxeboot and test
if it fixes disk access with AHCI enabled?

Index: boot/i386/btx/btx/btx.S
===================================================================
--- boot/i386/btx/btx/btx.S	(revision 247010)
+++ boot/i386/btx/btx/btx.S	(working copy)
@@ -41,6 +41,8 @@
 		.set PSL_RESERVED_DEFAULT,0x00000002
 		.set PSL_T,0x00000100		# Trap flag
 		.set PSL_I,0x00000200		# Interrupt enable flag
+		.set PSL_D,0x00000400		# String instruction direction
+		.set PSL_NT,0x00004000		# Nested task flag
 		.set PSL_VM,0x00020000		# Virtual 8086 mode flag
 		.set PSL_AC,0x00040000		# Alignment check flag
 /*
@@ -611,8 +613,8 @@
 		pushl %ds			#  regs
 		pushl %es
 		pushfl				# Save %eflags
-		cli				# Disable interrupts
-		std				# String ops dec
+		pushl $PSL_RESERVED_DEFAULT|PSL_D # Use clean %eflags with
+		popfl				#  string ops dec
 		xorw %ax,%ax			# Reset seg 
 		movw %ax,%ds			#  regs
 		movw %ax,%es			#  (%ss is already 0)
@@ -675,6 +677,7 @@
 		testl $V86F_FLAGS,%edx		# User wants flags?
 		jz rret_tramp.3			# No
 		movl MEM_ESPR-0x3c,%eax		# Read real mode flags
+		andl $~(PSL_T|PSL_NT),%eax	# Clear unsafe flags
 		movw %ax,-0x08(%esi)		# Update user flags (low 16)
 /*
  * Return to the user task

-- 
John Baldwin
Comment 2 Julian Pidancet 2013-10-09 10:21:05 UTC
On 7 October 2013 16:47, John Baldwin <jhb@freebsd.org> wrote:

>
> Ok, can you take this patch and use it to build an updated pxeboot and test
> if it fixes disk access with AHCI enabled?
>
>

That seems to have fixed the issue, thanks.

-- 
Julian
Comment 3 John Baldwin freebsd_committer freebsd_triage 2013-10-10 16:20:40 UTC
On Wednesday, October 09, 2013 5:21:05 am Julian Pidancet wrote:
> On 7 October 2013 16:47, John Baldwin <jhb@freebsd.org> wrote:
> 
> >
> > Ok, can you take this patch and use it to build an updated pxeboot and 
test
> > if it fixes disk access with AHCI enabled?
> >
> >
> 
> That seems to have fixed the issue, thanks.

Great, thanks!

-- 
John Baldwin
Comment 4 dfilter service freebsd_committer freebsd_triage 2013-10-10 20:51:45 UTC
Author: jhb
Date: Thu Oct 10 19:51:38 2013
New Revision: 256293
URL: http://svnweb.freebsd.org/changeset/base/256293

Log:
  Sanitize the %eflags returned by BIOS routines.  Some BIOS routines enter
  protected mode and may leave protected-mode-specific flags like PSL_NT set
  when they return to real mode.  This can cause a fault when BTX re-enters
  protected mode after the BIOS mode returns.
  
  PR:		amd64/182740
  Reported by:	Julian Pidancet <julian.pidancet@gmail.com>
  Approved by:	re (gjb)
  MFC after:	1 week

Modified:
  head/sys/boot/i386/btx/btx/btx.S

Modified: head/sys/boot/i386/btx/btx/btx.S
==============================================================================
--- head/sys/boot/i386/btx/btx/btx.S	Thu Oct 10 19:48:43 2013	(r256292)
+++ head/sys/boot/i386/btx/btx/btx.S	Thu Oct 10 19:51:38 2013	(r256293)
@@ -41,6 +41,8 @@
 		.set PSL_RESERVED_DEFAULT,0x00000002
 		.set PSL_T,0x00000100		# Trap flag
 		.set PSL_I,0x00000200		# Interrupt enable flag
+		.set PSL_D,0x00000400		# String instruction direction
+		.set PSL_NT,0x00004000		# Nested task flag
 		.set PSL_VM,0x00020000		# Virtual 8086 mode flag
 		.set PSL_AC,0x00040000		# Alignment check flag
 /*
@@ -611,8 +613,8 @@ rret_tramp:	movw $MEM_ESPR-0x08,%sp		# R
 		pushl %ds			#  regs
 		pushl %es
 		pushfl				# Save %eflags
-		cli				# Disable interrupts
-		std				# String ops dec
+		pushl $PSL_RESERVED_DEFAULT|PSL_D # Use clean %eflags with
+		popfl				#  string ops dec
 		xorw %ax,%ax			# Reset seg 
 		movw %ax,%ds			#  regs
 		movw %ax,%es			#  (%ss is already 0)
@@ -675,6 +677,7 @@ rret_tramp.1:	xorl %ecx,%ecx			# Zero
 		testl $V86F_FLAGS,%edx		# User wants flags?
 		jz rret_tramp.3			# No
 		movl MEM_ESPR-0x3c,%eax		# Read real mode flags
+		andl $~(PSL_T|PSL_NT),%eax	# Clear unsafe flags
 		movw %ax,-0x08(%esi)		# Update user flags (low 16)
 /*
  * Return to the user task
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
Comment 5 John Baldwin freebsd_committer freebsd_triage 2013-10-10 21:07:02 UTC
State Changed
From-To: open->patched

Fix committed to HEAD. 


Comment 6 John Baldwin freebsd_committer freebsd_triage 2013-10-10 21:07:02 UTC
Responsible Changed
From-To: freebsd-amd64->jhb

Fix committed to HEAD.
Comment 7 dfilter service freebsd_committer freebsd_triage 2013-11-15 15:09:00 UTC
Author: jhb
Date: Fri Nov 15 15:08:53 2013
New Revision: 258171
URL: http://svnweb.freebsd.org/changeset/base/258171

Log:
  MFC 256293:
  Sanitize the %eflags returned by BIOS routines.  Some BIOS routines enter
  protected mode and may leave protected-mode-specific flags like PSL_NT set
  when they return to real mode.  This can cause a fault when BTX re-enters
  protected mode after the BIOS mode returns.
  
  PR:		amd64/182740

Modified:
  stable/9/sys/boot/i386/btx/btx/btx.S
Directory Properties:
  stable/9/sys/   (props changed)
  stable/9/sys/boot/   (props changed)

Modified: stable/9/sys/boot/i386/btx/btx/btx.S
==============================================================================
--- stable/9/sys/boot/i386/btx/btx/btx.S	Fri Nov 15 13:55:55 2013	(r258170)
+++ stable/9/sys/boot/i386/btx/btx/btx.S	Fri Nov 15 15:08:53 2013	(r258171)
@@ -41,6 +41,8 @@
 		.set PSL_RESERVED_DEFAULT,0x00000002
 		.set PSL_T,0x00000100		# Trap flag
 		.set PSL_I,0x00000200		# Interrupt enable flag
+		.set PSL_D,0x00000400		# String instruction direction
+		.set PSL_NT,0x00004000		# Nested task flag
 		.set PSL_VM,0x00020000		# Virtual 8086 mode flag
 		.set PSL_AC,0x00040000		# Alignment check flag
 /*
@@ -611,8 +613,8 @@ rret_tramp:	movw $MEM_ESPR-0x08,%sp		# R
 		pushl %ds			#  regs
 		pushl %es
 		pushfl				# Save %eflags
-		cli				# Disable interrupts
-		std				# String ops dec
+		pushl $PSL_RESERVED_DEFAULT|PSL_D # Use clean %eflags with
+		popfl				#  string ops dec
 		xorw %ax,%ax			# Reset seg 
 		movw %ax,%ds			#  regs
 		movw %ax,%es			#  (%ss is already 0)
@@ -675,6 +677,7 @@ rret_tramp.1:	xorl %ecx,%ecx			# Zero
 		testl $V86F_FLAGS,%edx		# User wants flags?
 		jz rret_tramp.3			# No
 		movl MEM_ESPR-0x3c,%eax		# Read real mode flags
+		andl $~(PSL_T|PSL_NT),%eax	# Clear unsafe flags
 		movw %ax,-0x08(%esi)		# Update user flags (low 16)
 /*
  * Return to the user task
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
Comment 8 John Baldwin freebsd_committer freebsd_triage 2013-11-15 15:09:04 UTC
State Changed
From-To: patched->closed

Fix merged to 8 and 9.
Comment 9 dfilter service freebsd_committer freebsd_triage 2013-11-15 15:09:07 UTC
Author: jhb
Date: Fri Nov 15 15:08:58 2013
New Revision: 258172
URL: http://svnweb.freebsd.org/changeset/base/258172

Log:
  MFC 256293:
  Sanitize the %eflags returned by BIOS routines.  Some BIOS routines enter
  protected mode and may leave protected-mode-specific flags like PSL_NT set
  when they return to real mode.  This can cause a fault when BTX re-enters
  protected mode after the BIOS mode returns.
  
  PR:		amd64/182740

Modified:
  stable/8/sys/boot/i386/btx/btx/btx.S
Directory Properties:
  stable/8/sys/   (props changed)
  stable/8/sys/boot/   (props changed)

Modified: stable/8/sys/boot/i386/btx/btx/btx.S
==============================================================================
--- stable/8/sys/boot/i386/btx/btx/btx.S	Fri Nov 15 15:08:53 2013	(r258171)
+++ stable/8/sys/boot/i386/btx/btx/btx.S	Fri Nov 15 15:08:58 2013	(r258172)
@@ -41,6 +41,8 @@
 		.set PSL_RESERVED_DEFAULT,0x00000002
 		.set PSL_T,0x00000100		# Trap flag
 		.set PSL_I,0x00000200		# Interrupt enable flag
+		.set PSL_D,0x00000400		# String instruction direction
+		.set PSL_NT,0x00004000		# Nested task flag
 		.set PSL_VM,0x00020000		# Virtual 8086 mode flag
 		.set PSL_AC,0x00040000		# Alignment check flag
 /*
@@ -611,8 +613,8 @@ rret_tramp:	movw $MEM_ESPR-0x08,%sp		# R
 		pushl %ds			#  regs
 		pushl %es
 		pushfl				# Save %eflags
-		cli				# Disable interrupts
-		std				# String ops dec
+		pushl $PSL_RESERVED_DEFAULT|PSL_D # Use clean %eflags with
+		popfl				#  string ops dec
 		xorw %ax,%ax			# Reset seg 
 		movw %ax,%ds			#  regs
 		movw %ax,%es			#  (%ss is already 0)
@@ -675,6 +677,7 @@ rret_tramp.1:	xorl %ecx,%ecx			# Zero
 		testl $V86F_FLAGS,%edx		# User wants flags?
 		jz rret_tramp.3			# No
 		movl MEM_ESPR-0x3c,%eax		# Read real mode flags
+		andl $~(PSL_T|PSL_NT),%eax	# Clear unsafe flags
 		movw %ax,-0x08(%esi)		# Update user flags (low 16)
 /*
  * Return to the user task
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"