From owner-svn-src-head@freebsd.org Wed Jul 8 19:26:37 2015 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 9448D9967BC; Wed, 8 Jul 2015 19:26:37 +0000 (UTC) (envelope-from jmg@FreeBSD.org) Received: from repo.freebsd.org (repo.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 7DD30127E; Wed, 8 Jul 2015 19:26:37 +0000 (UTC) (envelope-from jmg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.14.9/8.14.9) with ESMTP id t68JQbJG095649; Wed, 8 Jul 2015 19:26:37 GMT (envelope-from jmg@FreeBSD.org) Received: (from jmg@localhost) by repo.freebsd.org (8.14.9/8.14.9/Submit) id t68JQai3095647; Wed, 8 Jul 2015 19:26:36 GMT (envelope-from jmg@FreeBSD.org) Message-Id: <201507081926.t68JQai3095647@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jmg set sender to jmg@FreeBSD.org using -f From: John-Mark Gurney Date: Wed, 8 Jul 2015 19:26:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r285290 - in head/sys: amd64/amd64 i386/isa X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Jul 2015 19:26:37 -0000 Author: jmg Date: Wed Jul 8 19:26:36 2015 New Revision: 285290 URL: https://svnweb.freebsd.org/changeset/base/285290 Log: Now that aesni won't reuse fpu contexts (D3016), add seatbelts to the fpu code to prevent other reuse of the contexts in the future... Differential Revision: https://reviews.freebsd.org/D3015 Reviewed by: kib, gnn Modified: head/sys/amd64/amd64/fpu.c head/sys/i386/isa/npx.c Modified: head/sys/amd64/amd64/fpu.c ============================================================================== --- head/sys/amd64/amd64/fpu.c Wed Jul 8 19:15:29 2015 (r285289) +++ head/sys/amd64/amd64/fpu.c Wed Jul 8 19:26:36 2015 (r285290) @@ -916,6 +916,7 @@ static MALLOC_DEFINE(M_FPUKERN_CTX, "fpu #define FPU_KERN_CTX_FPUINITDONE 0x01 #define FPU_KERN_CTX_DUMMY 0x02 /* avoided save for the kern thread */ +#define FPU_KERN_CTX_INUSE 0x04 struct fpu_kern_ctx { struct savefpu *prev; @@ -940,6 +941,7 @@ void fpu_kern_free_ctx(struct fpu_kern_ctx *ctx) { + KASSERT((ctx->flags & FPU_KERN_CTX_INUSE) == 0, ("free'ing inuse ctx")); /* XXXKIB clear the memory ? */ free(ctx, M_FPUKERN_CTX); } @@ -959,14 +961,16 @@ fpu_kern_enter(struct thread *td, struct { struct pcb *pcb; + KASSERT((ctx->flags & FPU_KERN_CTX_INUSE) == 0, ("using inuse ctx")); + if ((flags & FPU_KERN_KTHR) != 0 && is_fpu_kern_thread(0)) { - ctx->flags = FPU_KERN_CTX_DUMMY; + ctx->flags = FPU_KERN_CTX_DUMMY | FPU_KERN_CTX_INUSE; return (0); } pcb = td->td_pcb; KASSERT(!PCB_USER_FPU(pcb) || pcb->pcb_save == get_pcb_user_save_pcb(pcb), ("mangled pcb_save")); - ctx->flags = 0; + ctx->flags = FPU_KERN_CTX_INUSE; if ((pcb->pcb_flags & PCB_FPUINITDONE) != 0) ctx->flags |= FPU_KERN_CTX_FPUINITDONE; fpuexit(td); @@ -982,6 +986,10 @@ fpu_kern_leave(struct thread *td, struct { struct pcb *pcb; + KASSERT((ctx->flags & FPU_KERN_CTX_INUSE) != 0, + ("leaving not inuse ctx")); + ctx->flags &= ~FPU_KERN_CTX_INUSE; + if (is_fpu_kern_thread(0) && (ctx->flags & FPU_KERN_CTX_DUMMY) != 0) return (0); KASSERT((ctx->flags & FPU_KERN_CTX_DUMMY) == 0, ("dummy ctx")); Modified: head/sys/i386/isa/npx.c ============================================================================== --- head/sys/i386/isa/npx.c Wed Jul 8 19:15:29 2015 (r285289) +++ head/sys/i386/isa/npx.c Wed Jul 8 19:26:36 2015 (r285290) @@ -1359,6 +1359,7 @@ static MALLOC_DEFINE(M_FPUKERN_CTX, "fpu #define FPU_KERN_CTX_NPXINITDONE 0x01 #define FPU_KERN_CTX_DUMMY 0x02 +#define FPU_KERN_CTX_INUSE 0x04 struct fpu_kern_ctx { union savefpu *prev; @@ -1383,6 +1384,7 @@ void fpu_kern_free_ctx(struct fpu_kern_ctx *ctx) { + KASSERT((ctx->flags & FPU_KERN_CTX_INUSE) == 0, ("free'ing inuse ctx")); /* XXXKIB clear the memory ? */ free(ctx, M_FPUKERN_CTX); } @@ -1402,14 +1404,16 @@ fpu_kern_enter(struct thread *td, struct { struct pcb *pcb; + KASSERT((ctx->flags & FPU_KERN_CTX_INUSE) == 0, ("using inuse ctx")); + if ((flags & FPU_KERN_KTHR) != 0 && is_fpu_kern_thread(0)) { - ctx->flags = FPU_KERN_CTX_DUMMY; + ctx->flags = FPU_KERN_CTX_DUMMY | FPU_KERN_CTX_INUSE; return (0); } pcb = td->td_pcb; KASSERT(!PCB_USER_FPU(pcb) || pcb->pcb_save == get_pcb_user_save_pcb(pcb), ("mangled pcb_save")); - ctx->flags = 0; + ctx->flags = FPU_KERN_CTX_INUSE; if ((pcb->pcb_flags & PCB_NPXINITDONE) != 0) ctx->flags |= FPU_KERN_CTX_NPXINITDONE; npxexit(td); @@ -1425,6 +1429,10 @@ fpu_kern_leave(struct thread *td, struct { struct pcb *pcb; + KASSERT((ctx->flags & FPU_KERN_CTX_INUSE) != 0, + ("leaving not inuse ctx")); + ctx->flags &= ~FPU_KERN_CTX_INUSE; + if (is_fpu_kern_thread(0) && (ctx->flags & FPU_KERN_CTX_DUMMY) != 0) return (0); pcb = td->td_pcb;