From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11386 invoked by alias); 25 Nov 2016 19:41:59 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 11304 invoked by uid 89); 25 Nov 2016 19:41:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 spammy=frequently, tracking, bic, rarely X-Spam-User: qpsmtpd, 2 recipients X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 25 Nov 2016 19:41:48 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4126FC14; Fri, 25 Nov 2016 11:41:47 -0800 (PST) Received: from e103592.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id A312A3F318; Fri, 25 Nov 2016 11:41:46 -0800 (PST) From: Dave Martin To: linux-arm-kernel@lists.infradead.org Cc: libc-alpha@sourceware.org, gdb@sourceware.org Subject: [RFC PATCH 24/29] arm64/sve: Discard SVE state on system call Date: Fri, 25 Nov 2016 19:41:00 -0000 Message-Id: <1480102762-23647-25-git-send-email-Dave.Martin@arm.com> In-Reply-To: <1480102762-23647-1-git-send-email-Dave.Martin@arm.com> References: <1480102762-23647-1-git-send-email-Dave.Martin@arm.com> X-SW-Source: 2016-11/txt/msg00059.txt.bz2 The base procedure call standard for the Scalable Vector Extension defines all of the SVE programmer's model state (Z0-31, P0-15, FFR) as caller-save, except for that subset of the state that aliases FPSIMD state. System calls from userspace will almost always be made through C library wrappers -- as a consequence of the PCS there will thus rarely if ever be any live SVE state at syscall entry in practice. This gives us an opportinity to make SVE explicitly caller-save around SVC and so stop carrying around the SVE state for tasks that use SVE only occasionally (say, by calling a library). Note that FPSIMD state will still be preserved around SVC. As a crude heuristic to avoid pathological cases where a thread that uses SVE frequently has to fault back into the kernel again to re-enable SVE after a syscall, we switch the thread back to FPSIMD-only context tracking only if the context is actually switched out before returning to userspace. Signed-off-by: Dave Martin --- arch/arm64/kernel/fpsimd.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c index 5834f81..2e1056e 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -203,6 +203,23 @@ static void task_fpsimd_load(struct task_struct *task) static void task_fpsimd_save(struct task_struct *task) { if (IS_ENABLED(CONFIG_ARM64_SVE) && + task_pt_regs(task)->syscallno != ~0UL && + test_tsk_thread_flag(task, TIF_SVE)) { + unsigned long tmp; + + clear_tsk_thread_flag(task, TIF_SVE); + + /* Trap if the task tries to use SVE again: */ + asm volatile ( + "mrs %[tmp], cpacr_el1\n\t" + "bic %[tmp], %[tmp], %[mask]\n\t" + "msr cpacr_el1, %[tmp]" + : [tmp] "=r" (tmp) + : [mask] "i" (CPACR_EL1_ZEN_EL0EN) + ); + } + + if (IS_ENABLED(CONFIG_ARM64_SVE) && test_tsk_thread_flag(task, TIF_SVE)) sve_save_state(__task_pffr(task), &task->thread.fpsimd_state.fpsr); -- 2.1.4