Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4586005ybl; Mon, 13 Jan 2020 16:36:00 -0800 (PST) X-Google-Smtp-Source: APXvYqyIQND+1XLekod/XrLsCsSM34GCluZ0340cLSydqwBJ6I5w2YBvvbIlemv++XewcX596hJ9 X-Received: by 2002:a9d:6f82:: with SMTP id h2mr14837405otq.69.1578962160591; Mon, 13 Jan 2020 16:36:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578962160; cv=none; d=google.com; s=arc-20160816; b=YfEHlhAfPsfFLN57rw8wv2dZVvLQIGFerItJ13+kJXgijgVAAV9SDUlHv5Xi4H32eH 2VAliALeEsa2BECEqIO4VHt2PuUAVqY05B6QWHMrqw4Vspj8wGrOjQ4OS7ANKhlLO2zY FDq0ivb6THPBlpcEtX3pjlm090TTkwDadDgSumAfDw7u3R13ZeuwjNULFt/z5W8Z6Iy3 Nv+J/fHQTdMACJXGOpYurDjpor/cFa4UG4PfK+Xc18Dgh9IiiOfRbz26CiSfsGVNVUvM /Pup18d/DCczdNX6uKtQJ9miVrtkZ9S8OuCR8cXAdletUKjEV7Qe9jm7m5hkqMsqXtO9 FGfg== 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=0ZeQ5BT8swF1+nv4epHv2xXxQjP1Qix5a0QrYJTvzgE=; b=QyVpBmta/vhmZiTPQP+mWD3MUdAA1sN4WXWYjdKwZYBVNX+pGtBwW9Z/u7+OLLIfRP 08rlpIAMVPlkFHDOO3JA0HSLPLRJ4x+YDpoIrL6pL8aIu8Vv2jH1d/nFvbe7tp/11VtF HGtTJsBQOwMZLZGZGgYHs5rMA+TY1rlULRdxFeAX2r1p/4yI8OfSQL4+PerxH3c15j9z X1c4QQOGvNVzcOlPV4lfG1QsYD6dRYAEAPg+XVjyRdIOX0OlTDmXQb3GpIHa0iS0Zzqn urDba1r5eNypbIQG0lXGGAu9tc+BNHmM7AWOnW1LWno+5eI81qZJ1QgG3hQzuIGW9dcu NqMA== 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 p22si7359348ota.43.2020.01.13.16.35.47; Mon, 13 Jan 2020 16:36:00 -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 S1729163AbgAMXbN (ORCPT + 99 others); Mon, 13 Jan 2020 18:31:13 -0500 Received: from foss.arm.com ([217.140.110.172]:45652 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727282AbgAMXbN (ORCPT ); Mon, 13 Jan 2020 18:31:13 -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 D953F11B3; Mon, 13 Jan 2020 15:31:12 -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 BFBF73F68E; Mon, 13 Jan 2020 15:31:11 -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, catalin.marinas@arm.com, ard.biesheuvel@linaro.org, mark.rutland@arm.com, Suzuki K Poulose Subject: [PATCH v3 2/7] arm64: fpsimd: Make sure SVE setup is complete before SIMD is used Date: Mon, 13 Jan 2020 23:30:18 +0000 Message-Id: <20200113233023.928028-3-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200113233023.928028-1-suzuki.poulose@arm.com> References: <20200113233023.928028-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- Changes since v2: - Add WARN_ON() in may_use_simd() if invoked before caps are finalized() --- arch/arm64/include/asm/simd.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/simd.h b/arch/arm64/include/asm/simd.h index 7434844036d3..89cba2622b79 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 !WARN_ON(!system_capabilities_finalized()) && + system_supports_fpsimd() && + !in_irq() && !irqs_disabled() && !in_nmi() && + !this_cpu_read(fpsimd_context_busy); } #else /* ! CONFIG_KERNEL_MODE_NEON */ -- 2.24.1