From patchwork Tue Dec 17 18:33:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 181900 Delivered-To: patch@linaro.org Received: by 2002:ac9:44c4:0:0:0:0:0 with SMTP id t4csp6068947och; Tue, 17 Dec 2019 10:34:25 -0800 (PST) X-Google-Smtp-Source: APXvYqxArQReia5RVJLeCeNap5dso98yROFSESpcI8+hgZYY2IyVGPdRbVD5y2ilaq6fLtEu9V3Q X-Received: by 2002:a9d:4c88:: with SMTP id m8mr38413051otf.12.1576607665863; Tue, 17 Dec 2019 10:34:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576607665; cv=none; d=google.com; s=arc-20160816; b=bnGkeJyPKEvYKemfY4r5L4v7fCwXtA+dPAKjwBZe6fa7nmysQ99lW+kUlPZLOqCZHN hURlEuhChaLDwLtDUl0vk2P/QSL8kTHMN0JHqzMJOQRsmv3jUch2/lXK+EiJqnk+IXeL f3doXeHrRmLNnzlldTc8898TvLRPjaTGhJA0oMlDhVsoVvlgRr08EdPxkcHlhJqwBGkY E0hzkEIXnqFnpapISRvnP6CR+QaBHteJi9WivvAz9CURnG5inLm4asbQ9RFPmAipu5jw MBn+YkGsf5bvlLJgDytGhxYbBh8Iit2HLdv/Th+yLbohLt1HTVS8fGi+X92XMelUYzre 94GA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=z8p3TCNHWLurQKBMbuTIJ0Ly3grFmdC1W7NGYx5hYtQ=; b=h2RS9YPxhQkcSz0J6aqWl3s8tcsUAk29t74V0q0mZR/fleJl+f46J9ZyWF9LGHRqt5 rcV57enUZ1Zs5/wDjcx1rqrCBRwNg28hxtHnDiO/0x2cMcncaDnh5Ow6V/1AAiUzURwz T5rEOQOav46ZRz6QU3+v6LSFhK7r7Lnd0j0Cp6e4dPlJCv7lAQXIxKs/sr2K7GQ4IEp/ /JxOXj/d9G4CleuKofoIknxfC6XRRYz6eHEJSYaSm7yKMbmq1UVyV3/5tdFPzFlfLBFW GK1L9pLoxLO4GkJydddxl9KVIKlvV1+Ci3xPsalE+tqDUB3jJ3ZCUZIiWRzMZAWIAzMF 9PSA== 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 t1si1639859otq.322.2019.12.17.10.34.25; Tue, 17 Dec 2019 10:34:25 -0800 (PST) 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 S1728281AbfLQSeY (ORCPT + 27 others); Tue, 17 Dec 2019 13:34:24 -0500 Received: from foss.arm.com ([217.140.110.172]:44770 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728181AbfLQSeU (ORCPT ); Tue, 17 Dec 2019 13:34:20 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F384330E; Tue, 17 Dec 2019 10:34:19 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 8A6283F67D; Tue, 17 Dec 2019 10:34:18 -0800 (PST) From: Suzuki K Poulose To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, will@kernel.org, maz@kernel.org, mark.rutland@arm.com, dave.martin@arm.com, catalin.marinas@arm.com, ard.biesheuvel@linaro.org, christoffer.dall@arm.com, Suzuki K Poulose , Will Deacon Subject: [PATCH v2 2/7] arm64: fpsimd: Make sure SVE setup is complete before SIMD is used Date: Tue, 17 Dec 2019 18:33:57 +0000 Message-Id: <20191217183402.2259904-3-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191217183402.2259904-1-suzuki.poulose@arm.com> References: <20191217183402.2259904-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In-kernel users of NEON rely on may_use_simd() to check if the SIMD can be used. However, we must initialize the SVE before SIMD can be used. Add a sanity check to make sure that we have completed the SVE setup before anyone uses the SIMD. Cc: Ard Biesheuvel Cc: Mark Rutland Cc: Will Deacon Cc: Catalin Marinas Signed-off-by: Suzuki K Poulose --- Discussion here : https://lkml.kernel.org/r/20191014145204.GS27757@arm.com --- arch/arm64/include/asm/simd.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) -- 2.23.0 diff --git a/arch/arm64/include/asm/simd.h b/arch/arm64/include/asm/simd.h index 7434844036d3..afce6409be51 100644 --- a/arch/arm64/include/asm/simd.h +++ b/arch/arm64/include/asm/simd.h @@ -26,6 +26,8 @@ DECLARE_PER_CPU(bool, fpsimd_context_busy); static __must_check inline bool may_use_simd(void) { /* + * We must make sure that the SVE has been initialized properly + * before using the SIMD in kernel. * fpsimd_context_busy is only set while preemption is disabled, * and is clear whenever preemption is enabled. Since * this_cpu_read() is atomic w.r.t. preemption, fpsimd_context_busy @@ -33,8 +35,10 @@ static __must_check inline bool may_use_simd(void) * migrated, and if it's clear we cannot be migrated to a CPU * where it is set. */ - return !in_irq() && !irqs_disabled() && !in_nmi() && - !this_cpu_read(fpsimd_context_busy); + return system_capabilities_finalized() && + system_supports_fpsimd() && + !in_irq() && !irqs_disabled() && !in_nmi() && + !this_cpu_read(fpsimd_context_busy); } #else /* ! CONFIG_KERNEL_MODE_NEON */