From patchwork Wed Mar 22 14:50:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 9639251 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3F038602CB for ; Wed, 22 Mar 2017 15:46:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F92928451 for ; Wed, 22 Mar 2017 15:46:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 22AAD28460; Wed, 22 Mar 2017 15:46:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A2EAF28451 for ; Wed, 22 Mar 2017 15:46:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=vx4lvrnuuwbgISTeQohAgMbLDO5zPx+Xiz6PwL6GY0I=; b=ipOcCh0ax3oJM/ovqExfWoN0q6 DYjYPBPmIP88u2sF/ZBpHs0cJOOce21ILZHkmcWqoCNKrPJ4YMTpcH38XcBwgVlE8nOoE3H+BxmIc XtWdVB/LMQW5N/ErR1H1no08TAZYWSVWzBvDSIYwLSZpyrzCyhFBQP+iBSONIPk4V0DzDEQAuhEHn LvMm/75Nf9iWb6I+EOnodAaEDkpllPq6j5h8i+JFTI+6XzpChcbjh9pg439c3F6GeQFJqzfUKybXq mON/CkkUWbUwiGetmN+t+/QM/CLd/Wy683OHZJm/+VgwhAdAnJq9wLSZsOqh2T4z0K8p/XnrYRrQE 1suPLDbQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cqiTA-0007TW-0k; Wed, 22 Mar 2017 15:46:40 +0000 Received: from merlin.infradead.org ([2001:4978:20e::2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cqhxl-00018w-6s for linux-arm-kernel@bombadil.infradead.org; Wed, 22 Mar 2017 15:14:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=6b+zeMSs28UE3EWh/6rwGid8ARRNQAnWKZsQZCIZntk=; b=YKO/4UCMNTLr1mg6TzfwPZEGv Vit7ULnNOVNEHlPqjQ55Opbh+ZbEEyGhClDv6dFS3Vz/rNZFzw01U8XdM2u1j/wHWU8vFEy0wpQA/ 3/6DH9lmHxbb6H3OTny0jWXRcyj2vJnwY7dYXtbngvMcRK/r6b9yoBryUsSQMS0zNy90KwQQNyog0 yWtLOhnp/uzgaBjwczBsFft3SRMTq3iRTwacrUMlMUbesNuwgs3q3w/g/j/hiBDXNjz0nw9wTbg6q SPdaiOp3JzZ+lDCHyjq9kbcZLT8tLO99whqFzYGzxX3M9Qu5rELtgeMcy2Er1QVPbrTzlLF5qNkxO N1jKhvOcg==; Received: from foss.arm.com ([217.140.101.70]) by merlin.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cqhdn-0006jz-El for linux-arm-kernel@lists.infradead.org; Wed, 22 Mar 2017 14:53:38 +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 8E0EF1597; Wed, 22 Mar 2017 07:53:19 -0700 (PDT) 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 E1E503F575; Wed, 22 Mar 2017 07:53:17 -0700 (PDT) From: Dave Martin To: linux-arm-kernel@lists.infradead.org Subject: [RFC PATCH v2 24/41] arm64/sve: Discard SVE state on system call Date: Wed, 22 Mar 2017 14:50:54 +0000 Message-Id: <1490194274-30569-25-git-send-email-Dave.Martin@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1490194274-30569-1-git-send-email-Dave.Martin@arm.com> References: <1490194274-30569-1-git-send-email-Dave.Martin@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170322_105335_632811_DC35EBB8 X-CRM114-Status: UNSURE ( 8.47 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Florian Weimer , Ard Biesheuvel , Marc Zyngier , Catalin Marinas , Will Deacon , Szabolcs Nagy , Joseph Myers MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 5fb5585..8c18384 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -250,6 +250,23 @@ static void task_fpsimd_save(struct task_struct *task) BUG_ON(task != current); 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(sve_pffr(task), &task->thread.fpsimd_state.fpsr);