From patchwork Thu Jul 29 10:52:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 12408345 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CCBA8C4338F for ; Thu, 29 Jul 2021 10:54:35 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9803660C40 for ; Thu, 29 Jul 2021 10:54:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9803660C40 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linutronix.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=w18FmRiCLFiKRokSNg6Lt6jHn2z2u4cIinC3Jmh4dn8=; b=FbO5uvH/kNnaQs 1jaxYWfyeX2Vc9UfKNEGDObqYWDnCr9eMl7z4HsJsuoldYUhmzS1kLO1gFgcU2ir6GCCuPdFqZCjC itoYK/Aeb+rF2Hxd4Vp0If0IpQbihAWM5cSZLXohpXkpTYxFV3qn4ehSMotddgxVVxgulyZodnNl5 6Ckhxq31K+9HOJsxa5hrYINpZtXzJj6rzu363vX8CBhGwOm8+pFSnFSxYTIREsZ++Fv5BYvVQotME 4zeRbOCJ5yiBq9yo4A2wMH7q9XQzpj4N7tBeFjpGHkoyX0nm5LgjU+lIlTLrOKF4pi/+ZCjbJoS1n x31YyqpEwCVePDxD6NsA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m93en-003tQW-Cc; Thu, 29 Jul 2021 10:52:53 +0000 Received: from galois.linutronix.de ([193.142.43.55]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m93eQ-003tM7-1p for linux-arm-kernel@lists.infradead.org; Thu, 29 Jul 2021 10:52:31 +0000 From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1627555948; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+eUsa3+rIdfqWZPM+w+ab0fqtmkGhqwS4RQHkBHiN1Q=; b=aas1lbczFM0dAE7UKJzWU1DTp1twUvrPrqhJp3wf4pkab2oUmOKEOMvZwRJDpBzKUZW34A /DNjOq2DW0yKRJSB7d0mbRqBiQ8gWNiOCbRUY0HV2KZvQr6onyV+qUZlAg0+hcML6vJFDf Aw4TK1ckrbDv02BVVS69bNnW/5ZDZ2GWGn6xTEx8XN1VWranXXbUxjSwX1CZ7yQe2O4tNC ZaeENAYBW5z+LdKMwtrcptwj1VPQ12Y7qLiDJG0M8sILVDArcVPPd8PawhDJYnVVaFIqDr ltP9KU+YHjv4kOu2dbBsp8pLf3J9fisTpn/oW+L8ySi166ChHnHc+3rXOOZ8zA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1627555948; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+eUsa3+rIdfqWZPM+w+ab0fqtmkGhqwS4RQHkBHiN1Q=; b=auOupncCOMhXRHIgFmcyW9nHZaC5NnBIuWK59Fs5zlmV9T2wxox+iCj7IaWFAFXAH/CrQS xIpAG7Bvx+z/TyAg== To: linux-arm-kernel@lists.infradead.org Cc: Catalin Marinas , Will Deacon , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH] arm64/sve: Make kernel FPU protection RT friendly Date: Thu, 29 Jul 2021 12:52:15 +0200 Message-Id: <20210729105215.2222338-3-bigeasy@linutronix.de> In-Reply-To: <20210729105215.2222338-1-bigeasy@linutronix.de> References: <20210729105215.2222338-1-bigeasy@linutronix.de> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210729_035230_305727_70A646A7 X-CRM114-Status: UNSURE ( 9.64 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Non RT kernels need to protect FPU against preemption and bottom half processing. This is achieved by disabling bottom halves via local_bh_disable() which implictly disables preemption. On RT kernels this protection mechanism is not sufficient because local_bh_disable() does not disable preemption. It serializes bottom half related processing via a CPU local lock. As bottom halves are running always in thread context on RT kernels disabling preemption is the proper choice as it implicitly prevents bottom half processing. Signed-off-by: Sebastian Andrzej Siewior Reviewed-by: Mark Brown --- arch/arm64/kernel/fpsimd.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c index e098f6c67b1de..a208514bd69a9 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -177,10 +177,19 @@ static void __get_cpu_fpsimd_context(void) * * The double-underscore version must only be called if you know the task * can't be preempted. + * + * On RT kernels local_bh_disable() is not sufficient because it only + * serializes soft interrupt related sections via a local lock, but stays + * preemptible. Disabling preemption is the right choice here as bottom + * half processing is always in thread context on RT kernels so it + * implicitly prevents bottom half processing as well. */ static void get_cpu_fpsimd_context(void) { - local_bh_disable(); + if (!IS_ENABLED(CONFIG_PREEMPT_RT)) + local_bh_disable(); + else + preempt_disable(); __get_cpu_fpsimd_context(); } @@ -201,7 +210,10 @@ static void __put_cpu_fpsimd_context(void) static void put_cpu_fpsimd_context(void) { __put_cpu_fpsimd_context(); - local_bh_enable(); + if (!IS_ENABLED(CONFIG_PREEMPT_RT)) + local_bh_enable(); + else + preempt_enable(); } static bool have_cpu_fpsimd_context(void)