From patchwork Fri Feb 16 18:39:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 10225353 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 DCDE5601E7 for ; Fri, 16 Feb 2018 18:40:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CBC3A29374 for ; Fri, 16 Feb 2018 18:40:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BFC3229665; Fri, 16 Feb 2018 18:40:49 +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 [198.137.202.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 077D829374 for ; Fri, 16 Feb 2018 18:40:49 +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=wPz+pRQmWm6Y3Gf4EahcmMAjodDLSzgKY5YxB+ib450=; b=DLU+HEPwDFdq0UgBLfwZtSTOfn JDsnQavcZhAHmndjQo/3IQ7jegnkI5FKKFLh6NNuqmTtCWy32PMrViLzbFAQFon2v9hc0FSObPZWj Vo2xtNpwQI5zesOFFwUsA4TDxp7MF71e7yukaxCogZTpnPi+Rp8yDRQ3JPG19U5jhxXVd/qX8tBQg 1NjMGBWmo8ZcOJJn3Ril+77OvLg35RrpNXywOHlwnS2OPtydEZ4cvCcQlnHjoVeJjqkCF4+ibfQhs nSB8J1s6KJf/BuWu22EbBBLD/dJTuaoZv0sBinR0PJHPkcZEBGiPJIkHEewKx8F+S6SPDSPWwdlZn 1sILOfqg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1emkw0-0006cu-JF; Fri, 16 Feb 2018 18:40:36 +0000 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70] helo=foss.arm.com) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1emkvE-00054H-95 for linux-arm-kernel@lists.infradead.org; Fri, 16 Feb 2018 18:39:58 +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 8D98D80D; Fri, 16 Feb 2018 10:39:37 -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 A0A8D3F487; Fri, 16 Feb 2018 10:39:36 -0800 (PST) From: Dave Martin To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 0.9/2] arm64: fpsimd: Expose CPU / FPSIMD state association helpers Date: Fri, 16 Feb 2018 18:39:30 +0000 Message-Id: <1518806370-15697-1-git-send-email-Dave.Martin@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1518805771-15346-1-git-send-email-Dave.Martin@arm.com> References: <1518805771-15346-1-git-send-email-Dave.Martin@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180216_103948_590953_E4490510 X-CRM114-Status: GOOD ( 12.48 ) 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: Marc Zyngier , Christoffer Dall , linux-arm-kernel@lists.infradead.org, Ard Biesheuvel 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 Oops, forgot to post this patch that goes before patch 1 in the series. --8<-- Expose an interface for associating an FPSIMD context with a CPU and checking the association, for use by KVM. Signed-off-by: Dave Martin --- arch/arm64/include/asm/fpsimd.h | 5 +++++ arch/arm64/kernel/fpsimd.c | 42 +++++++++++++++++++++++++++++------------ 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/arch/arm64/include/asm/fpsimd.h b/arch/arm64/include/asm/fpsimd.h index 8857a0f..f4ce4d6 100644 --- a/arch/arm64/include/asm/fpsimd.h +++ b/arch/arm64/include/asm/fpsimd.h @@ -23,6 +23,7 @@ #include #include +#include /* * FP/SIMD storage area has: @@ -62,6 +63,8 @@ struct fpsimd_state { struct task_struct; +extern bool fpsimd_foreign_fpstate(struct fpsimd_state const *state); + extern void fpsimd_save_state(struct fpsimd_state *state); extern void fpsimd_load_state(struct fpsimd_state *state); @@ -76,6 +79,8 @@ extern void fpsimd_update_current_state(struct user_fpsimd_state const *state); extern void fpsimd_flush_task_state(struct task_struct *target); extern void sve_flush_cpu_state(void); +extern void fpsimd_bind_state_to_cpu(struct fpsimd_state *state); + /* Maximum VL that SVE VL-agnostic software can transparently support */ #define SVE_VL_ARCH_MAX 0x100 diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c index e7226c4..138efaf 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -121,6 +122,14 @@ struct fpsimd_last_state_struct { static DEFINE_PER_CPU(struct fpsimd_last_state_struct, fpsimd_last_state); +bool fpsimd_foreign_fpstate(struct fpsimd_state const *st) +{ + WARN_ON(!in_softirq() && !irqs_disabled()); + + return st->cpu != smp_processor_id() || + st != __this_cpu_read(fpsimd_last_state.st); +} + /* Default VL for tasks that don't set it explicitly: */ static int sve_default_vl = -1; @@ -908,13 +917,10 @@ void fpsimd_thread_switch(struct task_struct *next) * the TIF_FOREIGN_FPSTATE flag so the state will be loaded * upon the next return to userland. */ - struct fpsimd_state *st = &next->thread.fpsimd_state; - - if (__this_cpu_read(fpsimd_last_state.st) == st - && st->cpu == smp_processor_id()) - clear_tsk_thread_flag(next, TIF_FOREIGN_FPSTATE); - else + if (fpsimd_foreign_fpstate(¤t->thread.fpsimd_state)) set_tsk_thread_flag(next, TIF_FOREIGN_FPSTATE); + else + clear_tsk_thread_flag(next, TIF_FOREIGN_FPSTATE); } } @@ -996,19 +1002,31 @@ void fpsimd_signal_preserve_current_state(void) sve_to_fpsimd(current); } +static void __fpsimd_bind_to_cpu(struct fpsimd_last_state_struct *last, + struct fpsimd_state *st) +{ + WARN_ON(!in_softirq() || !irqs_disabled()); + + last->st = st; + st->cpu = smp_processor_id(); +} + +void fpsimd_bind_state_to_cpu(struct fpsimd_state *st) +{ + __fpsimd_bind_to_cpu(this_cpu_ptr(&fpsimd_last_state), st); +} + /* * Associate current's FPSIMD context with this cpu * Preemption must be disabled when calling this function. */ -static void fpsimd_bind_to_cpu(void) +static void fpsimd_bind_task_to_cpu(void) { struct fpsimd_last_state_struct *last = this_cpu_ptr(&fpsimd_last_state); - struct fpsimd_state *st = ¤t->thread.fpsimd_state; - last->st = st; + __fpsimd_bind_to_cpu(last, ¤t->thread.fpsimd_state); last->sve_in_use = test_thread_flag(TIF_SVE); - st->cpu = smp_processor_id(); } /* @@ -1025,7 +1043,7 @@ void fpsimd_restore_current_state(void) if (test_and_clear_thread_flag(TIF_FOREIGN_FPSTATE)) { task_fpsimd_load(); - fpsimd_bind_to_cpu(); + fpsimd_bind_task_to_cpu(); } local_bh_enable(); @@ -1050,7 +1068,7 @@ void fpsimd_update_current_state(struct user_fpsimd_state const *state) task_fpsimd_load(); if (test_and_clear_thread_flag(TIF_FOREIGN_FPSTATE)) - fpsimd_bind_to_cpu(); + fpsimd_bind_task_to_cpu(); local_bh_enable(); }