From patchwork Wed May 31 12:57:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 9756939 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 B875960360 for ; Wed, 31 May 2017 12:57:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A9BAC27FC0 for ; Wed, 31 May 2017 12:57:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9C98F2836F; Wed, 31 May 2017 12:57:38 +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 0511527FC0 for ; Wed, 31 May 2017 12:57:38 +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: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:In-Reply-To: References:List-Owner; bh=iztJ8BrmE/BT0mnJ9fc/dRHQSxC8b8G+mDEv/ohUPkE=; b=MAu TPfmul637Ajl1EwG0GIDHf3P5iHwizoIYg1Ip0QHUiuiSM1S4p0Z4UIEE34WWPnzb3jX2bJgVnKLz R8wB7Zgeyp3s6PRUfdUCi9zWntEb7StYsOimlO2jMtqS3w+O4XaTwjGxO/krW9kHz4LrsR0NiGgjK QeV9RgYDl3MY7GpaFjwLynkQNtyUD+jAik5piVtv5FbdPG25wQTt1BwKe4bOThEnQOXmm5RKd6mx9 sZuGQ1fOoeoc89nrFoa9hFs79k6VNmySJRJpNAERR2VchYZVldRLnaUb0I+VluBxFbpV7Utc8w8HR 2LXu9mf2zBakj+hgH4KC/CDjvvZY2Vw==; 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 1dG3Bw-0001Uj-12; Wed, 31 May 2017 12:57:36 +0000 Received: from mail-wm0-x22f.google.com ([2a00:1450:400c:c09::22f]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dG3Bs-0001TV-4P for linux-arm-kernel@lists.infradead.org; Wed, 31 May 2017 12:57:34 +0000 Received: by mail-wm0-x22f.google.com with SMTP id b84so118128055wmh.0 for ; Wed, 31 May 2017 05:57:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=CAnbUxBPv8Ng8Oo9aEAaYUDAAWAyX1UGnemffHf/7CU=; b=XYwGcsKXWL8dtY4hs3JN0Ik08otjq8dnYCl1vUSSU0wd8yu3ReaHg5Izpc2qMdieLW N7msOcjNJJ5GP5Vd3pLw7SN9N+UrIQ/J/FxyyBK9FMpl08mWWkYrfODS0nTSw0nuWo5T +MtAZE9ryKy835EBhZCwZF4yg4WB13EdOu6TE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=CAnbUxBPv8Ng8Oo9aEAaYUDAAWAyX1UGnemffHf/7CU=; b=lNrPZFgHmXvYYv/2qnpZOwgrdLVxPbkE73KV7Q9kPjUG2Ht61eybcxskWmU4czWlOB R4GB1VJFM40gvYFokZDciJyySEO2plyX8gkuT2dCkQqf1CXWWflYqjAK76OxpL65Vr0B lQHDfyjyjHZAi7ZN3pbq1QJyXYAh4ukyNwEhVgM9nT6NWC1UIumaHEpH6olpewPhQsc4 gfY06bAbwUmRCHlLg6cbmKnoxwj8EmPUntUxSzSV/V2urCofgs2xXaSC8E82PZsJjiuY 2nVnBDfpHbCxqjw+JInIOlnwdqatxs33iM6QADSG43iKiwk/s1GKzp0mdZrlIaAQ9ZgX A39w== X-Gm-Message-State: AODbwcBbGAC4f/DuDJSpTWqMJ+BhQKUcXddZtYrgvEDLdh6BFaL9nE5x x3z2WZatoedONvIi X-Received: by 10.28.26.82 with SMTP id a79mr5531670wma.119.1496235428802; Wed, 31 May 2017 05:57:08 -0700 (PDT) Received: from localhost.localdomain ([154.144.49.177]) by smtp.gmail.com with ESMTPSA id 185sm17896653wmp.1.2017.05.31.05.57.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 May 2017 05:57:07 -0700 (PDT) From: Ard Biesheuvel To: linux-arch@vger.kernel.org Subject: [PATCH] asm-generic: simd: allow SIMD in process context with BH disabled Date: Wed, 31 May 2017 12:57:01 +0000 Message-Id: <20170531125701.20717-1-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.9.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170531_055732_355785_6D9ED5E0 X-CRM114-Status: GOOD ( 16.70 ) 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: Jason@zx2c4.com, Ard Biesheuvel , linux-arm-kernel@lists.infradead.org, arnd@arndb.de, dave.martin@arm.com 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 asm-generic supplies a header asm/simd.h which exports a single function may_use_simd(), which conveys whether the current context allows the SIMD register file or instructions to be used. This header is included by crypto code shared between x86 and ARM/arm64, and which offloads SIMD processing to process context if required. The generic asm/simd.h is shared between ARM and arm64 at the moment, while x86 has its own implementation. On arm64, we currently mostly ignore may_use_simd(), because arm64 allows kernel mode NEON in any context. However, this is due to change shortly when support for SVE is merged, at which point we will introduce an arm64 specific implementation of asm/simd.h as well. That leaves ARM, which only allows kernel mode NEON in process context, which makes the current generic implementation of may_use_simd() seem appropriate. However, given that in_interrupt() will return true when running in process context with bottom halves disabled, we may end up falling back to less optimized code unnecessarily, given that kernel mode NEON is perfectly usable in that case. So redefine may_use_simd() to disallow SIMD only when running in hardirq or softirq context. While we're at it, add some missing header file decorations such as a license header and include guards. Reported-by: "Jason A. Donenfeld" Signed-off-by: Ard Biesheuvel --- include/asm-generic/simd.h | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/include/asm-generic/simd.h b/include/asm-generic/simd.h index f57eb7b5c23b..a3e5ebe6b2b2 100644 --- a/include/asm-generic/simd.h +++ b/include/asm-generic/simd.h @@ -1,14 +1,31 @@ +/* + * Copyright (C) 2013 - 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. + */ -#include +#ifndef __ASM_SIMD_H +#define __ASM_SIMD_H + +#include +#include /* * may_use_simd - whether it is allowable at this time to issue SIMD * instructions or access the SIMD register file * * As architectures typically don't preserve the SIMD register file when - * taking an interrupt, !in_interrupt() should be a reasonable default. + * taking an interrupt, it is reasonable to define the default behavior + * of 'may_use_simd()' to be 'SIMD is only allowed when not handling an + * IRQ or softIRQ'. Since 'in_interrupt()' will also return true when + * running in process context with bottom halves disabled, we have to + * spell out that condition as shown. */ static __must_check inline bool may_use_simd(void) { - return !in_interrupt(); + return !in_irq() && !in_serving_softirq(); } + +#endif