From patchwork Wed Jun 26 11:12:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 2786901 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 96C289F3A0 for ; Wed, 26 Jun 2013 16:10:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 611CD20542 for ; Wed, 26 Jun 2013 16:10:28 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 64B362053E for ; Wed, 26 Jun 2013 16:10:26 +0000 (UTC) Received: from merlin.infradead.org ([205.233.59.134]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UrsHK-0005LG-Tq; Wed, 26 Jun 2013 16:09: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 1UrsHB-0006k4-A3; Wed, 26 Jun 2013 16:08:57 +0000 Received: from bombadil.infradead.org ([2001:1868:205::9]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Urs1g-0005IC-DB for linux-arm-kernel@merlin.infradead.org; Wed, 26 Jun 2013 15:52:56 +0000 Received: from mail-wg0-x233.google.com ([2a00:1450:400c:c00::233]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UrnfL-0004mz-UG for linux-arm-kernel@lists.infradead.org; Wed, 26 Jun 2013 11:13:37 +0000 Received: by mail-wg0-f51.google.com with SMTP id e11so10385295wgh.30 for ; Wed, 26 Jun 2013 04:12:50 -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:x-gm-message-state; bh=nvsVOVDeDkijK525rtN9n9F2FyXUbQjjvSqh5+d9fss=; b=iQxZ8y85s6px5jFpOHclIqa+bsXsL/7n9jwiS+8IUqdSLgsmZVwlUXXBAvuzAHZ/Dt r0ZN+7C8k0ZCcUpYZFbtpauTOS0JO2iVhp88zFUMQOycGVD6oVeDsaovylcOZ809T64M nmbCDt5tO59ooAPFrEEtR9PP3C4ngQ6HhRUFxJK2ORWwsORuTt/RlzkyJLs84F1E21on FlO9zeqwE+Q/A1LHRDFgYbDGdMrJ1QwzgdIEntK3Gj0uwR7fHBKHELb1fyokcQnB3Vi8 0rvwkFQHifE82ysSfTuAp2D4aSHOYuQStUjc+7N3xT0xDXRhtNnKu7rFk0EMOz8wU/kn /z7w== X-Received: by 10.180.206.70 with SMTP id lm6mr12205113wic.50.1372245170723; Wed, 26 Jun 2013 04:12:50 -0700 (PDT) Received: from ards-mac-mini.fritz.box (cust-03-55bf5db2.adsl.scarlet.nl. [85.191.93.178]) by mx.google.com with ESMTPSA id o14sm10115814wiv.3.2013.06.26.04.12.48 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 26 Jun 2013 04:12:48 -0700 (PDT) From: Ard Biesheuvel To: catalin.marinas@arm.com Subject: [PATCH] arm64: add support for kernel mode NEON Date: Wed, 26 Jun 2013 13:12:46 +0200 Message-Id: <1372245166-31924-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.1.2 X-Gm-Message-State: ALoCoQm+Nlmew22FCgTCUJFw42syG68vEW/Yf9y299x9wZQ/RNS8R7KEHxqH8MzsQbOh9Gdn5y6k X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130626_041336_986658_AFA2CC02 X-CRM114-Status: GOOD ( 12.89 ) X-Spam-Score: 0.0 (/) Cc: linux-arm-kernel@lists.infradead.org, Ard Biesheuvel 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 X-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add containing kernel_neon_begin/kernel_neon_end function declarations and corresponding definitions in fpsimd.c These are needed to wrap uses of NEON in kernel mode. The names are identical to the ones used in arm/ so code using intrinsics or vectorized by GCC can be shared between arm and arm64. Signed-off-by: Ard Biesheuvel --- Catalin, You were right about the might_sleep(), it prevents kernel_neon_begin() from being called if preemption is already disabled, which is a perfectly acceptable use case. I used BUG_ON(in_interrupt()) instead. diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 56b3f6d..46ba680 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -95,6 +95,9 @@ config SWIOTLB config IOMMU_HELPER def_bool SWIOTLB +config KERNEL_MODE_NEON + def_bool y + source "init/Kconfig" source "kernel/Kconfig.freezer" diff --git a/arch/arm64/include/asm/neon.h b/arch/arm64/include/asm/neon.h new file mode 100644 index 0000000..b0cc58a9 --- /dev/null +++ b/arch/arm64/include/asm/neon.h @@ -0,0 +1,14 @@ +/* + * linux/arch/arm64/include/asm/neon.h + * + * Copyright (C) 2013 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. + */ + +#define cpu_has_neon() (1) + +void kernel_neon_begin(void); +void kernel_neon_end(void); diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c index e8b8357..040aec2 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -83,6 +84,46 @@ void fpsimd_flush_thread(void) fpsimd_load_state(¤t->thread.fpsimd_state); } +#ifdef CONFIG_KERNEL_MODE_NEON + +/* + * Kernel-side NEON support functions + */ +void kernel_neon_begin(void) +{ + /* + * Kernel mode NEON is only allowed outside of interrupt context + * with preemption disabled. This will make sure that the kernel + * mode NEON register contents never need to be preserved. + * + * Use inc_preempt_count() directly on builds that have kernel + * preemption disabled so sleeping complains noisily even on those. + */ + BUG_ON(in_interrupt()); +#ifndef CONFIG_PREEMPT_COUNT + inc_preempt_count(); +#endif + preempt_disable(); + + if (current->mm) + fpsimd_save_state(¤t->thread.fpsimd_state); +} +EXPORT_SYMBOL(kernel_neon_begin); + +void kernel_neon_end(void) +{ + if (current->mm) + fpsimd_load_state(¤t->thread.fpsimd_state); + + preempt_enable(); +#ifndef CONFIG_PREEMPT_COUNT + dec_preempt_count(); +#endif +} +EXPORT_SYMBOL(kernel_neon_end); + +#endif /* CONFIG_KERNEL_MODE_NEON */ + /* * FP/SIMD support code initialisation. */