From owner-svn-src-all@FreeBSD.ORG Sat Oct 4 19:34:00 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id F1F1496F; Sat, 4 Oct 2014 19:33:59 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id DD82DBEB; Sat, 4 Oct 2014 19:33:59 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s94JXxl7032243; Sat, 4 Oct 2014 19:33:59 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s94JXxGa032241; Sat, 4 Oct 2014 19:33:59 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201410041933.s94JXxGa032241@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Sat, 4 Oct 2014 19:33:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r272540 - stable/10/sys/amd64/amd64 X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 04 Oct 2014 19:34:00 -0000 Author: kib Date: Sat Oct 4 19:33:58 2014 New Revision: 272540 URL: https://svnweb.freebsd.org/changeset/base/272540 Log: MFC r271747: - Use NULL instead of 0 for fpcurthread. - Note the quirk with the interrupt enabled state of the dna handler. - Use just panic() instead of printf() and panic(). Print tid instead of pid, the fpu state is per-thread. MFC r271924: Update and clarify comments. Remove the useless counter for impossible, but seen in wild situation (on buggy hypervisors). Modified: stable/10/sys/amd64/amd64/fpu.c stable/10/sys/amd64/amd64/trap.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/amd64/amd64/fpu.c ============================================================================== --- stable/10/sys/amd64/amd64/fpu.c Sat Oct 4 19:32:46 2014 (r272539) +++ stable/10/sys/amd64/amd64/fpu.c Sat Oct 4 19:33:58 2014 (r272540) @@ -362,7 +362,7 @@ fpuexit(struct thread *td) stop_emulating(); fpusave(curpcb->pcb_save); start_emulating(); - PCPU_SET(fpcurthread, 0); + PCPU_SET(fpcurthread, NULL); } critical_exit(); } @@ -603,33 +603,37 @@ fputrap_sse(void) } /* - * Implement device not available (DNA) exception + * Device Not Available (DNA, #NM) exception handler. * - * It would be better to switch FP context here (if curthread != fpcurthread) - * and not necessarily for every context switch, but it is too hard to - * access foreign pcb's. + * It would be better to switch FP context here (if curthread != + * fpcurthread) and not necessarily for every context switch, but it + * is too hard to access foreign pcb's. */ - -static int err_count = 0; - void fpudna(void) { + /* + * This handler is entered with interrupts enabled, so context + * switches may occur before critical_enter() is executed. If + * a context switch occurs, then when we regain control, our + * state will have been completely restored. The CPU may + * change underneath us, but the only part of our context that + * lives in the CPU is CR0.TS and that will be "restored" by + * setting it on the new CPU. + */ critical_enter(); + if (PCPU_GET(fpcurthread) == curthread) { - printf("fpudna: fpcurthread == curthread %d times\n", - ++err_count); + printf("fpudna: fpcurthread == curthread\n"); stop_emulating(); critical_exit(); return; } if (PCPU_GET(fpcurthread) != NULL) { - printf("fpudna: fpcurthread = %p (%d), curthread = %p (%d)\n", - PCPU_GET(fpcurthread), - PCPU_GET(fpcurthread)->td_proc->p_pid, - curthread, curthread->td_proc->p_pid); - panic("fpudna"); + panic("fpudna: fpcurthread = %p (%d), curthread = %p (%d)\n", + PCPU_GET(fpcurthread), PCPU_GET(fpcurthread)->td_tid, + curthread, curthread->td_tid); } stop_emulating(); /* Modified: stable/10/sys/amd64/amd64/trap.c ============================================================================== --- stable/10/sys/amd64/amd64/trap.c Sat Oct 4 19:32:46 2014 (r272539) +++ stable/10/sys/amd64/amd64/trap.c Sat Oct 4 19:33:58 2014 (r272540) @@ -450,8 +450,8 @@ trap(struct trapframe *frame) case T_XMMFLT: /* SIMD floating-point exception */ case T_FPOPFLT: /* FPU operand fetch fault */ /* - * XXXKIB for now disable any FPU traps in kernel - * handler registration seems to be overkill + * For now, supporting kernel handler + * registration for FPU traps is overkill. */ trap_fatal(frame, 0); goto out;