Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp674086img; Fri, 22 Mar 2019 06:21:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqzKZgnvZNgAOWzCFZgiqlarKWS4NiwEkgb5INf654YLVtmsfPBXI4w8Qy27LPfg1zxRUmuF X-Received: by 2002:a62:1a06:: with SMTP id a6mr9076054pfa.18.1553260862957; Fri, 22 Mar 2019 06:21:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553260862; cv=none; d=google.com; s=arc-20160816; b=Qo36KBK6e4yVAgJLKCTzURemamXeCSg2lCjyEkYkoHBEq5tDTD9DwWe1/RMfoF2YxT 652HFFwvaFOIHYk7+ecFcGm5dO1V0fYQIo8s3VpneD7pn4I0a46tKH60yoeUDV9oWhST PnxvpEnlxoNtGTvXd8Dx/dwEpHVBpy7uYqP5yMxzskKtrNyNa++5+vLyVNJ9uqaZTsXc cPiXmfJlu4AsvubIy6K9zu74sbrGySpjapKwQdmtT1gJec69LWnhY80BrM5JUqhWnkC7 Un5N122NNif5UFAT8/9jNnyA0kUXbtOT4aqSITYydMqXuv2pqsuo8oldqovevrJl2wfh N+1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=ZYou5Z6AAMCtFfpwiHA9X2K7cSO6/QC4OG3BtK+qRcw=; b=wzEk3N3mloSgY1pc/xO3e6s2uLoFroPuVqKLJUZqqtez//cpFMW/+8uT1rEjhnZVfS w7O0T5JknWLrXiotQh0WaTHSMuzpa4hkpde0fPz+7QXZvFe6bDldXmFSU7PiQs1XudFZ rhN4cHLhpXtPJ7oG73/4wNQE2hCqWmJKF5he9+uFTq99ALcPXrJ8Q5ht/TKCdM/AZ8/q sacs+s5tOguFCWZbXA/aYbluVYBiOcsMT3UkyAT+avzWZ6PVdQqJbBnbmzkC0kNRHNy8 50Gw05uzCvproP0lMY2bweCsMHsbx7KQP1Jst+F4dXzr/Ue+6bWFTT1pEQjU9PeCX0R1 1YoQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h12si5136218plt.69.2019.03.22.06.20.45; Fri, 22 Mar 2019 06:21:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728538AbfCVNUH (ORCPT + 99 others); Fri, 22 Mar 2019 09:20:07 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:40721 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728243AbfCVLWG (ORCPT ); Fri, 22 Mar 2019 07:22:06 -0400 Received: from [5.158.153.52] (helo=nanos.tec.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1h7IFI-0000dn-5U; Fri, 22 Mar 2019 12:21:56 +0100 Date: Fri, 22 Mar 2019 12:21:51 +0100 (CET) From: Thomas Gleixner To: "Jason A. Donenfeld" cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Samuel Neves , Andy Lutomirski , Greg KH , linux-arch@vger.kernel.org Subject: Re: [PATCH net-next v9 01/19] asm: simd context helper API In-Reply-To: <20190322071122.6677-2-Jason@zx2c4.com> Message-ID: References: <20190322071122.6677-1-Jason@zx2c4.com> <20190322071122.6677-2-Jason@zx2c4.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Jason, On Fri, 22 Mar 2019, Jason A. Donenfeld wrote: > index 000000000000..264ed84b41d8 > --- /dev/null > +++ b/arch/arm/include/asm/simd.h > @@ -0,0 +1,63 @@ > +/* SPDX-License-Identifier: GPL-2.0 The SPDX identifier has to be in a separate comment line. /* SPDX-License-Identifier: GPL-2.0 */ /* * Copyright (C) 2015-2018 Jason.... */ Yes, it looks odd, but it's defined that way. > +static __must_check inline bool simd_use(simd_context_t *ctx) > +{ > + if (!(*ctx & HAVE_FULL_SIMD)) > + return false; > + if (*ctx & HAVE_SIMD_IN_USE) > + return true; > + kernel_neon_begin(); > + *ctx |= HAVE_SIMD_IN_USE; > + return true; > +} > +static __must_check inline bool simd_use(simd_context_t *ctx) > +{ > + if (!(*ctx & HAVE_FULL_SIMD)) > + return false; > + if (*ctx & HAVE_SIMD_IN_USE) > + return true; > + kernel_neon_begin(); > + *ctx |= HAVE_SIMD_IN_USE; > + return true; > +} > +static __must_check inline bool simd_use(simd_context_t *ctx) > +{ > +#if !defined(CONFIG_UML) > + if (!(*ctx & HAVE_FULL_SIMD)) > + return false; > + if (*ctx & HAVE_SIMD_IN_USE) > + return true; > + kernel_fpu_begin(); > + *ctx |= HAVE_SIMD_IN_USE; > + return true; > +#else > + return false; > +#endif > +} So now we have 3 almost identical copies of the same thing and x86/UM handling it differently than the ARM(64) ones. That can be completely avoided. Untested patch below. Thanks, tglx 8<------------- --- /dev/null +++ b/arch/arm/include/asm/simd.h @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2015-2018 Jason A. Donenfeld . All Rights Reserved. + */ +#ifndef _ASM_SIMD_H +#define _ASM_SIMD_H + +#ifdef CONFIG_KERNEL_MODE_NEON +#include + +static __must_check inline bool may_use_simd(void) +{ + return !in_nmi() && !in_irq() && !in_serving_softirq(); +} + +static inline void arch_simd_end(void) +{ + kernel_neon_end(); +} + +static inline void arch_simd_begin(void) +{ + kernel_neon_begin(); +} + +#else +#include +#endif + +#endif /* _ASM_SIMD_H */ --- a/arch/arm64/include/asm/simd.h +++ b/arch/arm64/include/asm/simd.h @@ -1,11 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ /* * Copyright (C) 2017 Linaro Ltd. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 as published - * by the Free Software Foundation. + * Copyright (C) 2015-2018 Jason A. Donenfeld . All Rights Reserved. */ +#include #ifndef __ASM_SIMD_H #define __ASM_SIMD_H @@ -16,6 +15,8 @@ #include #ifdef CONFIG_KERNEL_MODE_NEON +#include +#include DECLARE_PER_CPU(bool, kernel_neon_busy); @@ -40,12 +41,18 @@ static __must_check inline bool may_use_ !this_cpu_read(kernel_neon_busy); } -#else /* ! CONFIG_KERNEL_MODE_NEON */ +static inline void arch_simd_end(void) +{ + kernel_neon_end(); +} -static __must_check inline bool may_use_simd(void) { - return false; +static inline void arch_simd_begin(void) +{ + kernel_neon_begin(); } -#endif /* ! CONFIG_KERNEL_MODE_NEON */ +#else +#include +#endif #endif --- a/arch/x86/include/asm/simd.h +++ b/arch/x86/include/asm/simd.h @@ -1,4 +1,12 @@ /* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2015-2018 Jason A. Donenfeld . All Rights Reserved. + */ + +#ifndef _ASM_SIMD_H +#define _ASM_SIMD_H + +#ifndef CONFIG_UML #include @@ -10,3 +18,21 @@ static __must_check inline bool may_use_ { return irq_fpu_usable(); } + +static inline void arch_simd_begin(void) +{ + kernel_fpu_begin(); +} + +static inline void arch_simd_end(void) +{ + kernel_fpu_end(); +} + +#else +#include +#endif + +#include + +#endif /* _ASM_SIMD_H */ --- a/include/asm-generic/simd.h +++ b/include/asm-generic/simd.h @@ -1,7 +1,12 @@ /* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_SIMD_H +#define _ASM_SIMD_H + #include +#define SIMD_GENERIC 1 + /* * may_use_simd - whether it is allowable at this time to issue SIMD * instructions or access the SIMD register file @@ -13,3 +18,10 @@ static __must_check inline bool may_use_ { return !in_interrupt(); } + +static inline void arch_simd_begin(void) { } +static inline void arch_simd_end(void) { } + +#include + +#endif /* _ASM_SIMD_H */ --- /dev/null +++ b/include/linux/simd.h @@ -0,0 +1,82 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2015-2018 Jason A. Donenfeld . All Rights Reserved. + */ + +#ifndef _SIMD_H +#define _SIMD_H + +typedef enum { + HAVE_NO_SIMD = 1 << 0, + HAVE_FULL_SIMD = 1 << 1, + HAVE_SIMD_IN_USE = 1 << 31 +} simd_context_t; + +#define DONT_USE_SIMD ((simd_context_t []){ HAVE_NO_SIMD }) + +#include + +#ifndef SIMD_GENERIC + +#include + +static inline bool simd_relax(simd_context_t *ctx) +{ +#ifdef CONFIG_PREEMPT + if ((*ctx & HAVE_SIMD_IN_USE) && need_resched()) { + simd_put(ctx); + simd_get(ctx); + return true; + } +#endif + return false; +} + +static inline void simd_get(simd_context_t *ctx) +{ + *ctx = may_use_simd() ? HAVE_FULL_SIMD : HAVE_NO_SIMD; +} + +static inline void simd_put(simd_context_t *ctx) +{ + if (*ctx & HAVE_SIMD_IN_USE) + arch_simd_end(); + + *ctx = HAVE_NO_SIMD; +} + +static __must_check inline bool simd_use(simd_context_t *ctx) +{ + if (!(*ctx & HAVE_FULL_SIMD)) + return false; + if (*ctx & HAVE_SIMD_IN_USE) + return true; + arch_simd_begin(); + *ctx |= HAVE_SIMD_IN_USE; + return true; +} + +#else /* !SIMD_GENERIC */ + +static inline bool simd_relax(simd_context_t *ctx) +{ + return false; +} + +static inline void simd_get(simd_context_t *ctx) +{ + *ctx = HAVE_NO_SIMD; +} + +static inline void simd_put(simd_context_t *ctx) +{ +} + +static __must_check inline bool simd_use(simd_context_t *ctx) +{ + return false; +} + +#endif /* SIMD_GENERIC */ + +#endif /* _SIMD_H */