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: 17651 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vb0-f72.google.com (mail-vb0-f72.google.com [209.85.212.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7ED0020F47 for ; Thu, 6 Jun 2013 15:03:35 +0000 (UTC) Received: by mail-vb0-f72.google.com with SMTP id p12sf1852434vbe.3 for ; Thu, 06 Jun 2013 08:03:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-beenthere:x-forwarded-to:x-forwarded-for :delivered-to:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe; bh=zOxebZeppTPU+cnqvEUMNHXR2Pt8SVICuLpgDW8AybA=; b=IoOVsKqt2E1qpLLfzYMtxckrOETFqYx426WGmscwvHfesWpHvcuWzw+/8IUGZ+JCoX zjqPT5A0Asvz3Gs8yKC+41MLdJU+qYsITntz4n9GN6cFHh6baCcfBPVXQlMAY8jNMpGu OPBjFIWxKwtyiXqfisNR5AvKYlub4g9lhPplPxxmTPdUtRlKkZXh657zYEHjtiej28B4 0saiuLp8wsR1lYjOWgt0rmnJIW4jGGCQeD/j3u902FNkg4CzXubqIJRGBeHgYfrS81z7 3fc5ruGtnDcIt1rnBvMHiTTfq3p7U2QkFPu5Uz71IEHe+aI7+cdFJ80wr+sMXx/SuyYs /QOA== X-Received: by 10.52.185.234 with SMTP id ff10mr9109090vdc.0.1370531015234; Thu, 06 Jun 2013 08:03:35 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.108.201 with SMTP id hm9ls1401365qeb.65.gmail; Thu, 06 Jun 2013 08:03:34 -0700 (PDT) X-Received: by 10.52.94.48 with SMTP id cz16mr18563184vdb.60.1370531014865; Thu, 06 Jun 2013 08:03:34 -0700 (PDT) Received: from mail-vb0-x22d.google.com (mail-vb0-x22d.google.com [2607:f8b0:400c:c02::22d]) by mx.google.com with ESMTPS id zp6si41582333vdb.145.2013.06.06.08.03.34 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 06 Jun 2013 08:03:34 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c02::22d is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=2607:f8b0:400c:c02::22d; Received: by mail-vb0-f45.google.com with SMTP id 12so2015390vbf.18 for ; Thu, 06 Jun 2013 08:03:34 -0700 (PDT) X-Received: by 10.58.116.211 with SMTP id jy19mr1578075veb.7.1370531014780; Thu, 06 Jun 2013 08:03:34 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.221.10.206 with SMTP id pb14csp70245vcb; Thu, 6 Jun 2013 08:03:34 -0700 (PDT) X-Received: by 10.180.205.200 with SMTP id li8mr10098259wic.15.1370531013915; Thu, 06 Jun 2013 08:03:33 -0700 (PDT) Received: from mail-we0-x229.google.com (mail-we0-x229.google.com [2a00:1450:400c:c03::229]) by mx.google.com with ESMTPS id f16si28502424wjn.92.2013.06.06.08.03.33 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 06 Jun 2013 08:03:33 -0700 (PDT) Received-SPF: neutral (google.com: 2a00:1450:400c:c03::229 is neither permitted nor denied by best guess record for domain of ard.biesheuvel@linaro.org) client-ip=2a00:1450:400c:c03::229; Received: by mail-we0-f169.google.com with SMTP id n57so2180618wev.28 for ; Thu, 06 Jun 2013 08:03:33 -0700 (PDT) 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 Cc: nico@linaro.org, rob.herring@calxeda.com, linux@arm.linux.org.uk, patches@linaro.org, Ard Biesheuvel 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: ALoCoQlDSNu9/oZATGep3ABOD6Sg2+kwKg5G9ow4ATJpLk1NNon/myWuWuGUcuVQk+nriIDxkjIO X-Original-Sender: ard.biesheuvel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c02::22d is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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. */