From mboxrd@z Thu Jan 1 00:00:00 1970 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 1C47EC4743E for ; Tue, 8 Jun 2021 14:49:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 074496124C for ; Tue, 8 Jun 2021 14:49:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233652AbhFHOvb (ORCPT ); Tue, 8 Jun 2021 10:51:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233615AbhFHOvY (ORCPT ); Tue, 8 Jun 2021 10:51:24 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A9C2C061787 for ; Tue, 8 Jun 2021 07:49:30 -0700 (PDT) Message-Id: <20210608144345.912645927@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1623163769; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: references:references; bh=4LgZtohgq2ySESHc02//du52iwoTx7HELfTV7M2CNOk=; b=DrBNLsLASRQA1MXui6Wz8ql7fIb+Xn7iAIE2pgTvQZR+Tkxo7VjttWsbyNOdUfrf2VIVxY t06nRKO0xpNG4I7W894ucQE5WB31QIEavEJF5eMPlIscT4N1/r0u2xJOR1ubeY/RgP/kdV mOZW9Xn4uJmuGtfGRoBvz8SDAIxy2sZxeEp2T1DnkO9maWdZ53VhTfnTNVcvgzWfeo7S1Q BpbEJeybhIwMFlQK0RD0DPTMbaVQKImtPHiMK2zcdKpb5Q9cv+XFwjryEetEy5bLQT5qxC t1SOuM+aNASTQENnSPaOr6AgLtaiaPoWjzjtUAsoA3pc1i3djXw2pCzM/6R+yA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1623163769; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: references:references; bh=4LgZtohgq2ySESHc02//du52iwoTx7HELfTV7M2CNOk=; b=R7AjCCNpSzRzMAYzkaVkBCKWz2MaLTk1KEAP5csC1RK6euycc4RmCJpULajQHi8+NQ3LKO 2WrHt5S+bbFdwHCA== Date: Tue, 08 Jun 2021 16:36:20 +0200 From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Andy Lutomirski , Dave Hansen , Fenghua Yu , Tony Luck , Yu-cheng Yu , Sebastian Andrzej Siewior , Rik van Riel , Borislav Petkov Subject: [patch V3 3/6] x86/process: Check PF_KTHREAD and not current->mm for kernel threads References: <20210608143617.565868844@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-transfer-encoding: 8-bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org switch_fpu_finish() checks current->mm as indicator for kernel threads. That's wrong because kernel threads can temporarily use a mm of a user process via kthread_use_mm(). Check the task flags for PF_KTHREAD instead. Fixes: 0cecca9d03c9 ("x86/fpu: Eager switch PKRU state") Signed-off-by: Thomas Gleixner Cc: Rik van Riel Cc: stable@vger.kernel.org --- arch/x86/include/asm/fpu/internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/arch/x86/include/asm/fpu/internal.h +++ b/arch/x86/include/asm/fpu/internal.h @@ -578,7 +578,7 @@ static inline void switch_fpu_finish(str * PKRU state is switched eagerly because it needs to be valid before we * return to userland e.g. for a copy_to_user() operation. */ - if (current->mm) { + if (!(current->flags & PF_KTHREAD)) { pk = get_xsave_addr(&new_fpu->state.xsave, XFEATURE_PKRU); if (pk) pkru_val = pk->pkru;