From patchwork Sun Oct 13 12:14:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 3033251 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id F0024BF924 for ; Sun, 13 Oct 2013 12:18:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 00AFC20328 for ; Sun, 13 Oct 2013 12:18:10 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C3ACF20320 for ; Sun, 13 Oct 2013 12:18:08 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VVKbA-0003gX-Ex; Sun, 13 Oct 2013 12:16:41 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VVKam-0000zo-Jw; Sun, 13 Oct 2013 12:16:16 +0000 Received: from mail-wg0-f43.google.com ([74.125.82.43]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VVKaB-0000vD-HU for linux-arm-kernel@lists.infradead.org; Sun, 13 Oct 2013 12:15:42 +0000 Received: by mail-wg0-f43.google.com with SMTP id b13so2055542wgh.10 for ; Sun, 13 Oct 2013 05:15:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Fjfmh8XHWDy1yHDID9EYxCH+lC2LfZRh+/sKwVz9aL0=; b=kMFRzlu0RfHKVPW0IuS1Y+iY3qDwZMd4w77lh3irIHWka3wpkSje9NG9hJ8n11sNXG I/TT0x3/mO+Q3b1m05WhbGft2+kHxfACYsJidFss7FsVwjL1vhcbQF6SJDB1O8ZGQpCh eGJPZmeZO6EWYEYj4HaPfOyNS3YWlLqIcIGlXlD+1y2rznBBC4tq9Cd/u0+gM6ZzXnGi mvyaW0N5Ctdxlr8tAaWvGa0sQ95J7TpPEImzSOoCdIBiXrvfECbsn0C9d2dC9qf0S/2P nRjzLn4KINy0NzGgELLhaxWD1j8oxCWk9MPx/ZCmSQ3dGRQfXfBs3x5E1NgQBm3h5xEt B+qQ== X-Gm-Message-State: ALoCoQk0dMGr/ymx8lrzB6l2kyuecT5sVE52hybDwKA7IyuUTLGDFMKWkzvjrMcpduitlJkXcdJx X-Received: by 10.181.12.75 with SMTP id eo11mr10550499wid.24.1381666516681; Sun, 13 Oct 2013 05:15:16 -0700 (PDT) Received: from ards-mac-mini.local (cag06-7-83-153-85-71.fbx.proxad.net. [83.153.85.71]) by mx.google.com with ESMTPSA id bs15sm13032515wib.10.2013.10.13.05.15.15 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 13 Oct 2013 05:15:16 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [RFC v3 PATCH 3/7] ARM64: defer reloading a task's FPSIMD state to userland resume Date: Sun, 13 Oct 2013 14:14:59 +0200 Message-Id: <1381666503-23726-4-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1381666503-23726-1-git-send-email-ard.biesheuvel@linaro.org> References: <1381666503-23726-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131013_081539_739623_AD1779A2 X-CRM114-Status: GOOD ( 13.21 ) X-Spam-Score: -2.6 (--) Cc: catalin.marinas@arm.com, Ard Biesheuvel , linux@arm.linux.org.uk, nico@linaro.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Modify kernel_neon_begin() and kernel_neon_end() so subsequent calls don't need to preserve/restore the userland FPSIMD state if the task has not entered userland in the mean time. Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/thread_info.h | 4 +++- arch/arm64/kernel/entry.S | 2 +- arch/arm64/kernel/fpsimd.c | 7 ++----- arch/arm64/kernel/signal.c | 2 ++ 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/arch/arm64/include/asm/thread_info.h b/arch/arm64/include/asm/thread_info.h index 23a3c47..3bdeab6 100644 --- a/arch/arm64/include/asm/thread_info.h +++ b/arch/arm64/include/asm/thread_info.h @@ -106,6 +106,7 @@ static inline struct thread_info *current_thread_info(void) #define TIF_SIGPENDING 0 #define TIF_NEED_RESCHED 1 #define TIF_NOTIFY_RESUME 2 /* callback before returning to user */ +#define TIF_RELOAD_FPSTATE 3 /* user FPSIMD context saved to mem */ #define TIF_SYSCALL_TRACE 8 #define TIF_POLLING_NRFLAG 16 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */ @@ -118,10 +119,11 @@ static inline struct thread_info *current_thread_info(void) #define _TIF_SIGPENDING (1 << TIF_SIGPENDING) #define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED) #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME) +#define _TIF_RELOAD_FPSTATE (1 << TIF_RELOAD_FPSTATE) #define _TIF_32BIT (1 << TIF_32BIT) #define _TIF_WORK_MASK (_TIF_NEED_RESCHED | _TIF_SIGPENDING | \ - _TIF_NOTIFY_RESUME) + _TIF_NOTIFY_RESUME | _TIF_RELOAD_FPSTATE) #endif /* __KERNEL__ */ #endif /* __ASM_THREAD_INFO_H */ diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index 3881fd1..2c6c7fb 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -589,7 +589,7 @@ fast_work_pending: str x0, [sp, #S_X0] // returned x0 work_pending: tbnz x1, #TIF_NEED_RESCHED, work_resched - /* TIF_SIGPENDING or TIF_NOTIFY_RESUME case */ + /* TIF_SIGPENDING/TIF_NOTIFY_RESUME/TIF_RELOAD_FPSTATE case */ ldr x2, [sp, #S_PSTATE] mov x0, sp // 'regs' tst x2, #PSR_MODE_MASK // user mode regs? diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c index 1f2e4d5..a52affd 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -72,7 +72,7 @@ void do_fpsimd_exc(unsigned int esr, struct pt_regs *regs) void fpsimd_thread_switch(struct task_struct *next) { /* check if not kernel threads */ - if (current->mm) + if (current->mm && !test_and_clear_thread_flag(TIF_RELOAD_FPSTATE)) fpsimd_save_state(¤t->thread.fpsimd_state); if (next->mm) fpsimd_load_state(&next->thread.fpsimd_state); @@ -95,16 +95,13 @@ void kernel_neon_begin(void) BUG_ON(in_interrupt()); preempt_disable(); - if (current->mm) + if (current->mm && !test_and_set_thread_flag(TIF_RELOAD_FPSTATE)) fpsimd_save_state(¤t->thread.fpsimd_state); } EXPORT_SYMBOL(kernel_neon_begin); void kernel_neon_end(void) { - if (current->mm) - fpsimd_load_state(¤t->thread.fpsimd_state); - preempt_enable(); } EXPORT_SYMBOL(kernel_neon_end); diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c index 890a591..da3a433 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -416,4 +416,6 @@ asmlinkage void do_notify_resume(struct pt_regs *regs, clear_thread_flag(TIF_NOTIFY_RESUME); tracehook_notify_resume(regs); } + if (test_and_clear_thread_flag(TIF_RELOAD_FPSTATE)) + fpsimd_load_state(¤t->thread.fpsimd_state); }