From patchwork Thu May 5 16:32:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 12839779 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id AD1F9C433F5 for ; Thu, 5 May 2022 16:33:49 +0000 (UTC) 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=DioUzQqJBqM9gSWmKRf/jUfIcfoT2kvx4ZkpNRCztrM=; b=z5MyOv7kWZEWDJ p7f5oI56JVu36BHQd2nXgNbu+u+Uaqvx97vxYuOEVj5fCeGFwUt+bPqoA9QNHaDJHsjEKaG38JMyP AYnMSSqRXowEMhb+HEkq58NbuhwUTL2GY2jC5Smz0qiH7AAA9QqeutwLw6HIdK+xzwx4QJR5ws4VI LW3I4kDQUXp83gQdCTY3B1IGtswDBjp4wSIUZlY4Ufm5jZXDavPz5Wyxxr08Y2LOcMEtta2Oifdcl q+dj1ZSsphWZvYeG8NIZtb3lZR3SNML/26U7LU/uOpb2VhjPGhlkgjr61CJm9Xc2jCPfqllGBaLN0 PFcTGW5WoiidKpdgKfng==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nmePJ-00GsMy-Ff; Thu, 05 May 2022 16:32:49 +0000 Received: from galois.linutronix.de ([2a0a:51c0:0:12e:550::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nmeOs-00Gs8v-3y for linux-arm-kernel@lists.infradead.org; Thu, 05 May 2022 16:32:24 +0000 From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1651768333; 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=UhvugnrnSVEkgaTr6vuGdh+1uO5Ehoz84DBvH9ORve8=; b=PZFj7i9Ulvdr4aGFnlBRyKAAPZm70H6UgKaL2HxcnsLqwttlVKT6I2AjRCd3DNWW6mm7lK x3bMMG3PMWQovnj5rXAnPk9nrYBgA0fw4I8HgK3Ex8EcWtNl3JEZ7K4YK9UXMb9SqPIjwY oG1aAd+U3dB+IoeSarzq9EqqKUaJCIuDvJWcGBnr6GFeVt+YtTPdPN/Wa7GC1YAKEMe7ra 9HgMK5VFkRyw5TRB+aRn8iHOV1roshPhbVWlnBZFGR0F0iJ40QjMsXbsMurwP8ynYjy5Rk 4VFQ2K3KZZ/u5jmdW/lponTuRHtbpWbzPy3CV+bYJ7QWo94GPh9xFnrGlf+/gw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1651768333; 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=UhvugnrnSVEkgaTr6vuGdh+1uO5Ehoz84DBvH9ORve8=; b=3c4ySyon0VMhDIYu04AVi+cZD8babqI6cESs+L77rihRfNPcAILV22DXIZFtlCsShHUBhl tEaIIxc61D6dFcCw== To: linux-arm-kernel@lists.infradead.org Cc: Catalin Marinas , Will Deacon , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH 1/3] arm64/sve: Delay freeing memory in fpsimd_flush_thread() Date: Thu, 5 May 2022 18:32:05 +0200 Message-Id: <20220505163207.85751-2-bigeasy@linutronix.de> In-Reply-To: <20220505163207.85751-1-bigeasy@linutronix.de> References: <20220505163207.85751-1-bigeasy@linutronix.de> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220505_093222_321683_BC9877A2 X-CRM114-Status: GOOD ( 10.11 ) 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 fpsimd_flush_thread() invokes kfree() via sve_free()+sme_free() within a preempt disabled section which is not working on -RT. Delay freeing of memory until preemption is enabled again. Signed-off-by: Sebastian Andrzej Siewior Reviewed-by: Mark Brown --- arch/arm64/kernel/fpsimd.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c index 95a733d3b2538..475939beb0167 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -1562,6 +1562,9 @@ static void fpsimd_flush_thread_vl(enum vec_type type) void fpsimd_flush_thread(void) { + void *sve_state = NULL; + void *za_state = NULL; + if (!system_supports_fpsimd()) return; @@ -1573,18 +1576,28 @@ void fpsimd_flush_thread(void) if (system_supports_sve()) { clear_thread_flag(TIF_SVE); - sve_free(current); + + /* Defer kfree() while in atomic context */ + sve_state = current->thread.sve_state; + current->thread.sve_state = NULL; + fpsimd_flush_thread_vl(ARM64_VEC_SVE); } if (system_supports_sme()) { clear_thread_flag(TIF_SME); - sme_free(current); + + /* Defer kfree() while in atomic context */ + za_state = current->thread.za_state; + current->thread.za_state = NULL; + fpsimd_flush_thread_vl(ARM64_VEC_SME); current->thread.svcr = 0; } put_cpu_fpsimd_context(); + kfree(sve_state); + kfree(za_state); } /* From patchwork Thu May 5 16:32:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 12839778 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id B68BDC433F5 for ; Thu, 5 May 2022 16:33:40 +0000 (UTC) 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=Uy11VzhVhuES2RYlIQOwAIgU1fS4vUDcVcbm55ew7Ag=; b=fYtcPH8PXyDOtP MOg6yBuodkp6LycwJB+dwc4VUH93H/FiOzvi4EWzM15ZvhFPmZtJSGqVF8nwcvpOiHz+XS/ijdZCs qUry49IMA37yOaesNNVyFcrS2ayPdSmDvSmgeIaFgiCLYNG3hYIBHUqVH4lHkwVYqgOWyxKsEEaxW 2EIVKSS7yD6O0jVuzY0ebnUL6BzYZi0H6ftQdwyGBcmRzETIDNiJzeYaiIIYTUqUXASiv6vrOKYz0 BpYPYp+vlW4rBnGLkWpIL6+r88NLZ4krkxCj8yNR42MitDkPclDxnm7lEEMKerXk7+XxQFiuTRHqh FPPp0kjsw3ht8P+/wJJQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nmeP7-00GsIE-Px; Thu, 05 May 2022 16:32:37 +0000 Received: from galois.linutronix.de ([2a0a:51c0:0:12e:550::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nmeOs-00Gs8w-4B for linux-arm-kernel@lists.infradead.org; Thu, 05 May 2022 16:32:23 +0000 From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1651768333; 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=IJvShu7gr0khpxTgyZyp96OVeMnXvb3D1pvN4Rr8j4Y=; b=k5HuLeGOt70xdjdv5NA878FQV6B+366+NRpjb9xg4cqkEAbLp4QaKSCQZyeYFYZnvsF5Hk iTFA8ps8Py+7Nv5kazqPs6dEBePwpA0CIwkkKb1bnJj+/a64cpf/Yfohw8ybQlzlkxVdfN MoxlJ+1bs+WdZPNEOKoNuZUQRfISrOMIufaYvgpdf5dyA6nTggMo6LnEd2nLM1wLMxlQ+M yB2/IVQ5p6/DsiJkTbun6Sr1tQ1fO2GXXGcVm9cBwbKqMrsJvgDymzmj0LHsUkSGb0V8pJ Gthy8IJubKKbkouNLjsaWnrRRO4eyRN0A1Si9gJg9hWavdwyTfd1s/qVysyelg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1651768333; 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=IJvShu7gr0khpxTgyZyp96OVeMnXvb3D1pvN4Rr8j4Y=; b=j6+oNW75kAYrlmqJK6MmRvlXYMVwZ0d/5ZoD39SAup31X6J7jgRBucch7myiGewugHQuV/ nS0It2FSSLjXZaBQ== To: linux-arm-kernel@lists.infradead.org Cc: Catalin Marinas , Will Deacon , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH 2/3] arm64/sve: Make kernel FPU protection RT friendly Date: Thu, 5 May 2022 18:32:06 +0200 Message-Id: <20220505163207.85751-3-bigeasy@linutronix.de> In-Reply-To: <20220505163207.85751-1-bigeasy@linutronix.de> References: <20220505163207.85751-1-bigeasy@linutronix.de> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220505_093222_348127_99AE84B9 X-CRM114-Status: UNSURE ( 9.61 ) 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 Acked-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 475939beb0167..ce4ee36b1da88 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -237,10 +237,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(); } @@ -261,7 +270,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) From patchwork Thu May 5 16:32:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 12839780 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id CDA40C433FE for ; Thu, 5 May 2022 16:34:00 +0000 (UTC) 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=DQbNAVGjQFERamDc6EPVvKtyQlpgK269PVNOpNQMnGg=; b=PWTWaY4wyHmaHr gzH8UkCjsZiyi3EIf8lnC1Qq6SWdaMrzcp5JBs25Ar3KiIyrcMGu1d+QKkOLcOEjrDTWTy93aeQom mS+gIyxPYZOfU2Z9oxyIa5UnZYg+dCjwgYU9kSrXwUxa8Kq5NngjDF6ycUe5c2Tjt3/ZaEqjxdmUx E03Vjl3uF4fQ39r4Lvz1p3dhnVxTSG4voKpsgLnLaZmD06miT9cQw9ykQrpKgEh/0u3K4ZbqigmK+ 1wvvP0odbltsBBtvSeIDxCir/j3XOagc9gbAQTxb7GZcNu2FVK9pjsibdi2DGofM4DK6zD7W7ZCkj oHVLmRxWgnC9e4RxQ3rw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nmePV-00GsRo-K6; Thu, 05 May 2022 16:33:01 +0000 Received: from galois.linutronix.de ([2a0a:51c0:0:12e:550::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nmeOs-00Gs91-4f for linux-arm-kernel@lists.infradead.org; Thu, 05 May 2022 16:32:25 +0000 From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1651768334; 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=LKm9AqbXcXRNKE2mxGijV7TPIG3gvdmtoC0y/ykq+0g=; b=eoU1GdPieDsNfZLaqVV4ics+xIMfGrnmT94xmAgYAhUrcvVmLPkgq12DfgR+5eYUvyW7yS 2yfdfVEPpqQ1ibpjY9H4TnETO9PsnuHSxzn3JnV9sUz5eyJT4L53r9ZfMx+BhbLTUPQ/jJ 8wu9s3PTIwESnkXV2WBkwpPFdPQHzTO1MVjsS14bDa3vOuUIcAQRQ++DjdhTFK325CvFL8 xR7i4ThhL4vSPy6IeuBtEMmc1BGb3Ll2eP5PPV5O+/qcK++TrOkQNt/Jh8JR9x4kpAsBCS t44ZAl0rXkvD0jHi8xifkVkKHLEIvx1Q58wCmSYuoKylNWwCT+NAjDE7JfnMwg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1651768334; 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=LKm9AqbXcXRNKE2mxGijV7TPIG3gvdmtoC0y/ykq+0g=; b=lj6so2GEhXyvry3v++TaUJnebl76rudhXO9HGhB/NmTEIswfkZ1mg000RHKfzkr0POsU31 uLRZqOG810ecEMDQ== To: linux-arm-kernel@lists.infradead.org Cc: Catalin Marinas , Will Deacon , Thomas Gleixner , Valentin Schneider , Valentin Schneider , Sebastian Andrzej Siewior Subject: [PATCH 3/3] arm64: mm: Make arch_faults_on_old_pte() check for migratability Date: Thu, 5 May 2022 18:32:07 +0200 Message-Id: <20220505163207.85751-4-bigeasy@linutronix.de> In-Reply-To: <20220505163207.85751-1-bigeasy@linutronix.de> References: <20220505163207.85751-1-bigeasy@linutronix.de> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220505_093222_368627_4E08F7AF X-CRM114-Status: UNSURE ( 9.29 ) 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 From: Valentin Schneider arch_faults_on_old_pte() relies on the calling context being non-preemptible. CONFIG_PREEMPT_RT turns the PTE lock into a sleepable spinlock, which doesn't disable preemption once acquired, triggering the warning in arch_faults_on_old_pte(). It does however disable migration, ensuring the task remains on the same CPU during the entirety of the critical section, making the read of cpu_has_hw_af() safe and stable. Make arch_faults_on_old_pte() check cant_migrate() instead of preemptible(). Cc: Valentin Schneider Suggested-by: Sebastian Andrzej Siewior Signed-off-by: Valentin Schneider Link: https://lore.kernel.org/r/20220127192437.1192957-1-valentin.schneider@arm.com Acked-by: Catalin Marinas --- arch/arm64/include/asm/pgtable.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index 8ebf1cec5d901..5a53558578ab3 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -1018,7 +1018,8 @@ static inline void update_mmu_cache(struct vm_area_struct *vma, */ static inline bool arch_faults_on_old_pte(void) { - WARN_ON(preemptible()); + /* The register read below requires a stable CPU to make any sense */ + cant_migrate(); return !cpu_has_hw_af(); }