From patchwork Thu Jun 6 15:03:03 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 2681351 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) by patchwork2.kernel.org (Postfix) with ESMTP id A370CDF23A for ; Thu, 6 Jun 2013 15:07:04 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UkbkP-000373-CD; Thu, 06 Jun 2013 15:05:07 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ukbjt-0003Er-7e; Thu, 06 Jun 2013 15:04:33 +0000 Received: from mail-wi0-x22f.google.com ([2a00:1450:400c:c05::22f]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UkbjK-0003AE-8t for linux-arm-kernel@lists.infradead.org; Thu, 06 Jun 2013 15:04:00 +0000 Received: by mail-wi0-f175.google.com with SMTP id hn14so451447wib.8 for ; Thu, 06 Jun 2013 08:03:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=zOxebZeppTPU+cnqvEUMNHXR2Pt8SVICuLpgDW8AybA=; b=ZhNuvmlVB6A1ebNbueTPndNisBmw8svzQGjYexF0MxFGWOiPuusllXQTqrtpt1nW/g oVFgFeLUUIKk9iN51gh5PUGFrHy7tmDRfmxeZgNpj8VSLD54ZE9Pav8g69jdNT8x1Cto HZxuM+nrvNPrCzoggiNn81tbczZLB1r5uVypCirDDr4kl7WSVhVKnHUp7SlYDtS06e37 +IsscOBzuETplFqdnXckWD9x0uu+YtheWxduYKjOTLB+eFzfEp8BJI9CsP1Jw6TP7kNE sIbUD0i9kyO8crKeYhGeBRHZJ+QjlrzGf/5d7uHh+U+St/OzNrTv9v+K06z8Byy+LOED 7tWQ== X-Received: by 10.194.119.2 with SMTP id kq2mr1282763wjb.88.1370531013310; Thu, 06 Jun 2013 08:03:33 -0700 (PDT) Received: from ards-mac-mini.local (cag06-7-83-153-85-71.fbx.proxad.net. [83.153.85.71]) by mx.google.com with ESMTPSA id cw8sm16357697wib.7.2013.06.06.08.03.32 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 06 Jun 2013 08:03:32 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 3/5] ARM: be strict about FP exceptions in kernel mode Date: Thu, 6 Jun 2013 17:03:03 +0200 Message-Id: <1370530985-20619-4-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1370530985-20619-1-git-send-email-ard.biesheuvel@linaro.org> References: <1370530985-20619-1-git-send-email-ard.biesheuvel@linaro.org> X-Gm-Message-State: ALoCoQlgQhV7Q97OzLxS3v1xbAaFg26dLxjREB17tpPdJJEnVff3/prILkc68XpKIIJx7CVv3D1e X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130606_110358_650562_5EB6805D X-CRM114-Status: GOOD ( 12.44 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Ard Biesheuvel , patches@linaro.org, linux@arm.linux.org.uk, rob.herring@calxeda.com, nico@linaro.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org The support code in vfp_support_entry does not care whether the exception that caused it to be invoked occurred in kernel mode or in user mode. However, neither condition that could trigger this exception (lazy restore and VFP bounce to support code) is currently allowable in kernel mode. In the former case, we can just handle it as an undefined instruction. In the latter case, we should flag it as a bug, as it implies that the FP unit has been enabled and an attempt has been made to execute FP instructions that are dependent on the support code, and this is not supported in kernel mode. Signed-off-by: Ard Biesheuvel Acked-by: Nicolas Pitre --- arch/arm/vfp/vfphw.S | 5 +++++ arch/arm/vfp/vfpmodule.c | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/arch/arm/vfp/vfphw.S b/arch/arm/vfp/vfphw.S index 8d10dc8..3e5d311 100644 --- a/arch/arm/vfp/vfphw.S +++ b/arch/arm/vfp/vfphw.S @@ -78,6 +78,11 @@ ENTRY(vfp_support_entry) DBGSTR3 "instr %08x pc %08x state %p", r0, r2, r10 + ldr r3, [sp, #S_PSR] @ Neither lazy restore nor FP exceptions + and r3, r3, #MODE_MASK @ are supported in kernel mode + teq r3, #USR_MODE + bne vfp_kmode_exception @ Returns through lr + VFPFMRX r1, FPEXC @ Is the VFP enabled? DBGSTR1 "fpexc %08x", r1 tst r1, #FPEXC_EN diff --git a/arch/arm/vfp/vfpmodule.c b/arch/arm/vfp/vfpmodule.c index 4c39f91..bd2f7a2 100644 --- a/arch/arm/vfp/vfpmodule.c +++ b/arch/arm/vfp/vfpmodule.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "vfpinstr.h" #include "vfp.h" @@ -691,6 +692,16 @@ EXPORT_SYMBOL(kernel_neon_end); #endif /* CONFIG_KERNEL_MODE_NEON */ +void vfp_kmode_exception(void) +{ + /* + * Taking an FP exception in kernel mode is always a bug, because + * none of the FP instructions currently supported in kernel mode + * (i.e., NEON) should ever be bounced back to the support code. + */ + BUG_ON(fmrx(FPEXC) & FPEXC_EN); +} + /* * VFP support code initialisation. */