From nobody@FreeBSD.org  Mon Jul  9 11:35:07 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 748BB106566C
	for <freebsd-gnats-submit@FreeBSD.org>; Mon,  9 Jul 2012 11:35:07 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 5EFA88FC12
	for <freebsd-gnats-submit@FreeBSD.org>; Mon,  9 Jul 2012 11:35:07 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id q69BZ6KP029931
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 9 Jul 2012 11:35:06 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id q69BZ62v029923;
	Mon, 9 Jul 2012 11:35:06 GMT
	(envelope-from nobody)
Message-Id: <201207091135.q69BZ62v029923@red.freebsd.org>
Date: Mon, 9 Jul 2012 11:35:06 GMT
From: Dmitrij Tejblum <tejblum@yandex-team.ru>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] libc/i386/gen/getcontextx.c::__getcontextx_size() is broken
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         169730
>Category:       i386
>Synopsis:       [patch] libc/i386/gen/getcontextx.c::__getcontextx_size() is broken
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    freebsd-i386
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jul 09 11:40:05 UTC 2012
>Closed-Date:    Mon Jul 16 02:37:38 UTC 2012
>Last-Modified:  Tue Jul 17 02:10:09 UTC 2012
>Originator:     Dmitrij Tejblum
>Release:        FreeBSD 9.0-STABLE
>Organization:
>Environment:
>Description:
__getcontextx_size() compute size of "extended" cpu state, depending on the CPU features. To do it, it should check if the bit CPUID2_OSXSAVE present in the "features2" field. But actually it checks some junk instead of the "features2" bitfield. 

To get features2 field, one should execure the "cpuid" instruction with EAX==1, but the code use EAX==0. See also the amd64 counterpart (libc/amd64/gen/getcontextx.c) for the correct (I believe) code.

>How-To-Repeat:

>Fix:


Patch attached with submission follows:

--- lib/libc/i386/gen/getcontextx.c.00	2012-02-22 01:18:59.000000000 +0400
+++ lib/libc/i386/gen/getcontextx.c	2012-07-06 21:45:04.000000000 +0400
@@ -64,15 +64,15 @@
 		if (cpuid_supported) {
 			__asm __volatile(
 			    "	pushl	%%ebx\n"
 			    "	cpuid\n"
 			    "	movl	%%ebx,%1\n"
 			    "	popl	%%ebx\n"
 			    : "=a" (p[0]), "=r" (p[1]), "=c" (p[2]), "=d" (p[3])
-			    :  "0" (0x0));
+			    :  "0" (1));
 			if ((p[2] & CPUID2_OSXSAVE) != 0) {
 				__asm __volatile(
 				    "	pushl	%%ebx\n"
 				    "	cpuid\n"
 				    "	movl	%%ebx,%1\n"
 				    "	popl	%%ebx\n"
 				    : "=a" (p[0]), "=r" (p[1]), "=c" (p[2]),


>Release-Note:
>Audit-Trail:

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: i386/169730: commit references a PR
Date: Tue, 10 Jul 2012 01:47:23 +0000 (UTC)

 Author: davidxu
 Date: Tue Jul 10 01:47:11 2012
 New Revision: 238328
 URL: http://svn.freebsd.org/changeset/base/238328
 
 Log:
   Executing CPUID with EAX set to 1 to actually get feature flags.
   PR:	169730
 
 Modified:
   head/lib/libc/i386/gen/getcontextx.c
 
 Modified: head/lib/libc/i386/gen/getcontextx.c
 ==============================================================================
 --- head/lib/libc/i386/gen/getcontextx.c	Tue Jul 10 01:32:52 2012	(r238327)
 +++ head/lib/libc/i386/gen/getcontextx.c	Tue Jul 10 01:47:11 2012	(r238328)
 @@ -68,7 +68,7 @@ __getcontextx_size(void)
  			    "	movl	%%ebx,%1\n"
  			    "	popl	%%ebx\n"
  			    : "=a" (p[0]), "=r" (p[1]), "=c" (p[2]), "=d" (p[3])
 -			    :  "0" (0x0));
 +			    :  "0" (0x1));
  			if ((p[2] & CPUID2_OSXSAVE) != 0) {
  				__asm __volatile(
  				    "	pushl	%%ebx\n"
 _______________________________________________
 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"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: i386/169730: commit references a PR
Date: Mon, 16 Jul 2012 02:10:37 +0000 (UTC)

 Author: davidxu
 Date: Mon Jul 16 02:10:26 2012
 New Revision: 238513
 URL: http://svn.freebsd.org/changeset/base/238513
 
 Log:
   MFC r238328:
   
   Executing CPUID with EAX set to 1 to actually get feature flags.
   PR:     169730
   Approved by:    re (kib)
 
 Modified:
   stable/9/lib/libc/i386/gen/getcontextx.c
 Directory Properties:
   stable/9/lib/libc/   (props changed)
 
 Modified: stable/9/lib/libc/i386/gen/getcontextx.c
 ==============================================================================
 --- stable/9/lib/libc/i386/gen/getcontextx.c	Mon Jul 16 00:21:05 2012	(r238512)
 +++ stable/9/lib/libc/i386/gen/getcontextx.c	Mon Jul 16 02:10:26 2012	(r238513)
 @@ -68,7 +68,7 @@ __getcontextx_size(void)
  			    "	movl	%%ebx,%1\n"
  			    "	popl	%%ebx\n"
  			    : "=a" (p[0]), "=r" (p[1]), "=c" (p[2]), "=d" (p[3])
 -			    :  "0" (0x0));
 +			    :  "0" (0x1));
  			if ((p[2] & CPUID2_OSXSAVE) != 0) {
  				__asm __volatile(
  				    "	pushl	%%ebx\n"
 _______________________________________________
 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"
 
State-Changed-From-To: open->closed 
State-Changed-By: davidxu 
State-Changed-When: Mon Jul 16 02:37:02 UTC 2012 
State-Changed-Why:  
Fixed. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=169730 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: i386/169730: commit references a PR
Date: Tue, 17 Jul 2012 02:02:52 +0000 (UTC)

 Author: davidxu
 Date: Tue Jul 17 02:02:40 2012
 New Revision: 238541
 URL: http://svn.freebsd.org/changeset/base/238541
 
 Log:
   MFC r238328:
   
   Executing CPUID with EAX set to 1 to actually get feature flags.
   PR:	169730
 
 Modified:
   stable/8/lib/libc/i386/gen/getcontextx.c
 Directory Properties:
   stable/8/lib/libc/   (props changed)
 
 Modified: stable/8/lib/libc/i386/gen/getcontextx.c
 ==============================================================================
 --- stable/8/lib/libc/i386/gen/getcontextx.c	Mon Jul 16 22:15:30 2012	(r238540)
 +++ stable/8/lib/libc/i386/gen/getcontextx.c	Tue Jul 17 02:02:40 2012	(r238541)
 @@ -68,7 +68,7 @@ __getcontextx_size(void)
  			    "	movl	%%ebx,%1\n"
  			    "	popl	%%ebx\n"
  			    : "=a" (p[0]), "=r" (p[1]), "=c" (p[2]), "=d" (p[3])
 -			    :  "0" (0x0));
 +			    :  "0" (0x1));
  			if ((p[2] & CPUID2_OSXSAVE) != 0) {
  				__asm __volatile(
  				    "	pushl	%%ebx\n"
 _______________________________________________
 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"
 
>Unformatted:
