From patchwork Mon Feb 24 14:26:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 25194 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f198.google.com (mail-ie0-f198.google.com [209.85.223.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 33EB12066C for ; Mon, 24 Feb 2014 14:26:22 +0000 (UTC) Received: by mail-ie0-f198.google.com with SMTP id at1sf22556108iec.1 for ; Mon, 24 Feb 2014 06:26:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=Ct2MyaUCCBVt/NnIlw+ejz2u3QWRUOMngHrI/7yTZ7I=; b=E4jwTfavnraP3YzneNrlMSI/TZ9NdAZoULWo4ltAblpZYS1ZxDhD03Zg58O9ImA/Ct kCPFmzIQEiJAVWIDjoa7LU/zzvKoZIPZqJLDiDd46bmgViIlPTLw0DL57fHGkK+IKv7O 3OU7O1J9V4Y7rrIZcLsbj4okqNHV4TIvYiHU7WEp4RK3lVAwCaM49zJhLwWCY5GCXGYL SCXDXbjdnBWpLwl3d8O0cF0Vjl0mbBSJD6GSuJX08EzLjIY923MKoyzLdYVCsMCn9cxI pXygKUHU/4MjlujtNKz+HehOdI1t6/2tFbuZXik7B7rcd3tSHbHvmmPuDjn45Z+yL8ka Be9w== X-Gm-Message-State: ALoCoQmIvJV8zD6GOIJSiu3PL3euS7KwMu1fJ2VWtGPCOmG1vyrnc9b9VDeQ8fwhTIlyEv6d1Jw3 X-Received: by 10.50.78.231 with SMTP id e7mr9460519igx.5.1393251981672; Mon, 24 Feb 2014 06:26:21 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.84.103 with SMTP id k94ls1961329qgd.39.gmail; Mon, 24 Feb 2014 06:26:21 -0800 (PST) X-Received: by 10.52.116.171 with SMTP id jx11mr55918vdb.88.1393251981493; Mon, 24 Feb 2014 06:26:21 -0800 (PST) Received: from mail-ve0-f176.google.com (mail-ve0-f176.google.com [209.85.128.176]) by mx.google.com with ESMTPS id t20si5859445vek.117.2014.02.24.06.26.21 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 24 Feb 2014 06:26:21 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.176 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.176; Received: by mail-ve0-f176.google.com with SMTP id pa12so490376veb.35 for ; Mon, 24 Feb 2014 06:26:21 -0800 (PST) X-Received: by 10.220.191.134 with SMTP id dm6mr12933634vcb.16.1393251981404; Mon, 24 Feb 2014 06:26:21 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp64840vcz; Mon, 24 Feb 2014 06:26:20 -0800 (PST) X-Received: by 10.180.101.166 with SMTP id fh6mr14547225wib.2.1393251979982; Mon, 24 Feb 2014 06:26:19 -0800 (PST) Received: from mail-wi0-f175.google.com (mail-wi0-f175.google.com [209.85.212.175]) by mx.google.com with ESMTPS id ba4si15442067wjb.78.2014.02.24.06.26.19 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 24 Feb 2014 06:26:19 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.175 is neither permitted nor denied by best guess record for domain of ard.biesheuvel@linaro.org) client-ip=209.85.212.175; Received: by mail-wi0-f175.google.com with SMTP id hm4so3124176wib.2 for ; Mon, 24 Feb 2014 06:26:19 -0800 (PST) X-Received: by 10.180.106.40 with SMTP id gr8mr14430051wib.31.1393251979504; Mon, 24 Feb 2014 06:26:19 -0800 (PST) Received: from ards-macbook-pro.local (cag06-7-83-153-85-71.fbx.proxad.net. [83.153.85.71]) by mx.google.com with ESMTPSA id ga20sm24784170wic.0.2014.02.24.06.26.18 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 24 Feb 2014 06:26:19 -0800 (PST) From: Ard Biesheuvel To: will.deacon@arm.com, catalin.marinas@arm.com, linux-arm-kernel@lists.infradead.org Cc: patches@linaro.org, Ard Biesheuvel Subject: [PATCH v3 1/4] arm64: add abstractions for FPSIMD state manipulation Date: Mon, 24 Feb 2014 15:26:27 +0100 Message-Id: <1393251990-19614-2-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1393251990-19614-1-git-send-email-ard.biesheuvel@linaro.org> References: <1393251990-19614-1-git-send-email-ard.biesheuvel@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.176 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , There are two tacit assumptions in the FPSIMD handling code that will no longer hold after the next patch that optimizes away some FPSIMD state restores: . the FPSIMD registers of this CPU contain the userland FPSIMD state of task 'current'; . when switching to a task, its FPSIMD state will always be restored from memory. This patch adds the following functions to abstract away from straight FPSIMD register file saves and restores: - fpsimd_preserve_current_state -> ensure current's FPSIMD state is saved - fpsimd_restore_current_state -> ensure current's FPSIMD state is loaded - fpsimd_update_current_state -> replace current's FPSIMD state - fpsimd_flush_task_state -> invalidate live copies of a task's FPSIMD state Where necessary, the ptrace, signal handling and fork code are updated to use the above wrappers instead of poking into the FPSIMD registers directly. Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/fpsimd.h | 6 ++++++ arch/arm64/kernel/fpsimd.c | 31 +++++++++++++++++++++++++++++++ arch/arm64/kernel/process.c | 2 +- arch/arm64/kernel/ptrace.c | 2 ++ arch/arm64/kernel/signal.c | 4 ++-- arch/arm64/kernel/signal32.c | 4 ++-- 6 files changed, 44 insertions(+), 5 deletions(-) diff --git a/arch/arm64/include/asm/fpsimd.h b/arch/arm64/include/asm/fpsimd.h index c43b4ac13008..9f9b8e438546 100644 --- a/arch/arm64/include/asm/fpsimd.h +++ b/arch/arm64/include/asm/fpsimd.h @@ -58,6 +58,12 @@ extern void fpsimd_load_state(struct fpsimd_state *state); extern void fpsimd_thread_switch(struct task_struct *next); extern void fpsimd_flush_thread(void); +extern void fpsimd_preserve_current_state(void); +extern void fpsimd_restore_current_state(void); +extern void fpsimd_update_current_state(struct fpsimd_state *state); + +extern void fpsimd_flush_task_state(struct task_struct *target); + #endif #endif diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c index 4aef42a04bdc..612328d91318 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -87,6 +87,37 @@ void fpsimd_flush_thread(void) preempt_enable(); } +/* + * Save the userland FPSIMD state of 'current' to memory + */ +void fpsimd_preserve_current_state(void) +{ + fpsimd_save_state(¤t->thread.fpsimd_state); +} + +/* + * Load the userland FPSIMD state of 'current' from memory + */ +void fpsimd_restore_current_state(void) +{ + fpsimd_load_state(¤t->thread.fpsimd_state); +} + +/* + * Load an updated userland FPSIMD state for 'current' from memory + */ +void fpsimd_update_current_state(struct fpsimd_state *state) +{ + fpsimd_load_state(state); +} + +/* + * Invalidate live CPU copies of task t's FPSIMD state + */ +void fpsimd_flush_task_state(struct task_struct *t) +{ +} + #ifdef CONFIG_KERNEL_MODE_NEON /* diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c index 1c0a9be2ffa8..6074e0a4418d 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -199,7 +199,7 @@ void release_thread(struct task_struct *dead_task) int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src) { - fpsimd_save_state(¤t->thread.fpsimd_state); + fpsimd_preserve_current_state(); *dst = *src; return 0; } diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index 6a8928bba03c..f8700eca24e7 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -517,6 +517,7 @@ static int fpr_set(struct task_struct *target, const struct user_regset *regset, return ret; target->thread.fpsimd_state.user_fpsimd = newstate; + fpsimd_flush_task_state(target); return ret; } @@ -764,6 +765,7 @@ static int compat_vfp_set(struct task_struct *target, uregs->fpcr = fpscr & VFP_FPSCR_CTRL_MASK; } + fpsimd_flush_task_state(target); return ret; } diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c index 890a591f75dd..ee30afd846f0 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -51,7 +51,7 @@ static int preserve_fpsimd_context(struct fpsimd_context __user *ctx) int err; /* dump the hardware registers to the fpsimd_state structure */ - fpsimd_save_state(fpsimd); + fpsimd_preserve_current_state(); /* copy the FP and status/control registers */ err = __copy_to_user(ctx->vregs, fpsimd->vregs, sizeof(fpsimd->vregs)); @@ -88,7 +88,7 @@ static int restore_fpsimd_context(struct fpsimd_context __user *ctx) /* load the hardware registers from the fpsimd_state structure */ if (!err) { preempt_disable(); - fpsimd_load_state(&fpsimd); + fpsimd_update_current_state(&fpsimd); preempt_enable(); } diff --git a/arch/arm64/kernel/signal32.c b/arch/arm64/kernel/signal32.c index b3fc9f5ec6d3..78e169c8214c 100644 --- a/arch/arm64/kernel/signal32.c +++ b/arch/arm64/kernel/signal32.c @@ -219,7 +219,7 @@ static int compat_preserve_vfp_context(struct compat_vfp_sigframe __user *frame) * Note that this also saves V16-31, which aren't visible * in AArch32. */ - fpsimd_save_state(fpsimd); + fpsimd_preserve_current_state(); /* Place structure header on the stack */ __put_user_error(magic, &frame->magic, err); @@ -284,7 +284,7 @@ static int compat_restore_vfp_context(struct compat_vfp_sigframe __user *frame) */ if (!err) { preempt_disable(); - fpsimd_load_state(&fpsimd); + fpsimd_update_current_state(&fpsimd); preempt_enable(); }