From patchwork Mon Oct 17 13:47:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 3465 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1458283wrs; Mon, 17 Oct 2022 06:50:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5/fzZ860do26Zw5fU0mz/zCztwqmNHWXJjZRcrDb/j1zoJWJsKfxh5PxHyhaoZL/vtQbzF X-Received: by 2002:a63:1f5c:0:b0:469:d0e6:dac0 with SMTP id q28-20020a631f5c000000b00469d0e6dac0mr10532235pgm.427.1666014622151; Mon, 17 Oct 2022 06:50:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666014622; cv=none; d=google.com; s=arc-20160816; b=xmT3wxPjEmobwOJDvqQlgv0F+haTF5yFLRF8OFESjFt5FveNj+iC6oPMdzEEE3gW9F fMFP6k4a8t9jYgFCGs1ikdrE0eiuHWek5sXhFmHeFY1N47FmvKTb7NXCcZ5W/HqEitIl deQOgs1w2pIqDOPHZk41CJiynhhj/+bhVkkU8GpPxvwxXzgHf/6Ml8YUDw1akTT7FIXO Me/gr8NvVcqPdxxQs3dKtJl3Noj9TJn47GcmR4sntg9fOkURjYk7ZD7BPVlw1y8TM8Ju oAqB52+FdbEvvuewyLEYDx5LzeQzy4hCwBE+YA+nqwVjC0lV34F+k8LOqrfYk+l+YCl/ i6eQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=tqBa9Ui0a5BzY8tHtFFmljjsK0hmX5eiFPxQJ7f2bbc=; b=wdLrBNpCF8fa+MfgQTTddUavSP2zA7Cxxwf958U3W8zPpIeCV5OItZf0DFz4JdTuwr +OuBS+ZXwlWf/LlJ+1vwVoFGVviChO1CDQHJOcziRzCsOBUfhFeZ5jtzRDFNdcjNJz+h ND4WNXr8Dtpt1CGuL8CX95CnJAtjIHsE+Ti2v8rBdD9G2NKx8mP053II32BX2UNT+/T8 Ia6Da6cTzW3ypXGDe8mxsxlhlbksw55YK2Y18aMdfTcXQEMnsATqyqnxSbIGW5jvjRvE enlhC06tnd9O7gfkVtgu8mYHzGN7IU/GhNgQqsQ6vYppmviBAspFHYWtUTC4uryZAUPZ +xfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=LRNjp5if; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b6-20020a170902d50600b00182b78df2f8si14187709plg.495.2022.10.17.06.50.08; Mon, 17 Oct 2022 06:50:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=LRNjp5if; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229980AbiJQNri (ORCPT + 99 others); Mon, 17 Oct 2022 09:47:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229894AbiJQNrf (ORCPT ); Mon, 17 Oct 2022 09:47:35 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3415952825; Mon, 17 Oct 2022 06:47:34 -0700 (PDT) Date: Mon, 17 Oct 2022 13:47:30 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666014451; h=from:from:sender:sender:reply-to: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: in-reply-to:in-reply-to:references:references; bh=tqBa9Ui0a5BzY8tHtFFmljjsK0hmX5eiFPxQJ7f2bbc=; b=LRNjp5ifONGe7zYMKC/22iEY1mmXz8lpRQbCXrx4lfR8KxaG/O71MzNH7kSDFTU874lx9n LnKPROcNMoOCBjcnyCxhdePwiEInAp2kpyUbGrxI3y8lmyrEBAOkNCLkBSIzGoGJTSGky4 zDUMPeFuVnwwPxan8cPq3FSdZu15K+9anxZhvx2oR1PME2/kaIouepOlHcLdvkU1xBA25f cW/wExufSMJWqYPQXMFhdulPJgPGr+ja/jPUe5BRzgRjxxdw5XuXkeB9fhT/r5c1PMQ8xF 0+uQPro8dMJRnlanetOo8x5H4tFosf2wBlbSrI5YHA7OQew87yH2tdOkkD+cAw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666014451; h=from:from:sender:sender:reply-to: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: in-reply-to:in-reply-to:references:references; bh=tqBa9Ui0a5BzY8tHtFFmljjsK0hmX5eiFPxQJ7f2bbc=; b=kJ2iDCSuCKuNl1CPwReaMyDg8XpthNf9ioNYKP7udbZaVZZRD7d4AEGrYAuPEqOCr12f2M ZsjaqO3c99ji2XBw== From: "tip-bot2 for Chang S. Bae" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/urgent] x86/fpu: Exclude dynamic states from init_fpstate Cc: Lin X Wang , "Chang S. Bae" , Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20220824191223.1248-4-chang.seok.bae@intel.com> References: <20220824191223.1248-4-chang.seok.bae@intel.com> MIME-Version: 1.0 Message-ID: <166601445015.401.6980293789787013355.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746942948403558670?= X-GMAIL-MSGID: =?utf-8?q?1746942948403558670?= The following commit has been merged into the x86/urgent branch of tip: Commit-ID: a401f45e38754953c9d402f8b3bc965707eecc91 Gitweb: https://git.kernel.org/tip/a401f45e38754953c9d402f8b3bc965707eecc91 Author: Chang S. Bae AuthorDate: Wed, 24 Aug 2022 12:12:23 -07:00 Committer: Thomas Gleixner CommitterDate: Mon, 17 Oct 2022 15:44:25 +02:00 x86/fpu: Exclude dynamic states from init_fpstate == Background == The XSTATE init code initializes all enabled and supported components. Then, the init states are saved in the init_fpstate buffer that is statically allocated in about one page. The AMX TILE_DATA state is large (8KB) but its init state is zero. And the feature comes only with the compacted format with these established dependencies: AMX->XFD->XSAVES. So this state is excludable from init_fpstate. == Problem == But the buffer is formatted to include that large state. Then, this can be the cause of a noisy splat like the below. This came from XRSTORS for the task with init_fpstate in its XSAVE buffer. It is reproducible on AMX systems when the running kernel is built with CONFIG_DEBUG_PAGEALLOC=y and CONFIG_DEBUG_PAGEALLOC_ENABLE_DEFAULT=y: Bad FPU state detected at restore_fpregs_from_fpstate+0x57/0xd0, reinitializing FPU registers. ... RIP: 0010:restore_fpregs_from_fpstate+0x57/0xd0 ? restore_fpregs_from_fpstate+0x45/0xd0 switch_fpu_return+0x4e/0xe0 exit_to_user_mode_prepare+0x17b/0x1b0 syscall_exit_to_user_mode+0x29/0x40 do_syscall_64+0x67/0x80 ? do_syscall_64+0x67/0x80 ? exc_page_fault+0x86/0x180 entry_SYSCALL_64_after_hwframe+0x63/0xcd == Solution == Adjust init_fpstate to exclude dynamic states. XRSTORS from init_fpstate still initializes those states when their bits are set in the requested-feature bitmap. Fixes: 2308ee57d93d ("x86/fpu/amx: Enable the AMX feature in 64-bit mode") Reported-by: Lin X Wang Signed-off-by: Chang S. Bae Signed-off-by: Thomas Gleixner Tested-by: Lin X Wang Link: https://lore.kernel.org/r/20220824191223.1248-4-chang.seok.bae@intel.com --- arch/x86/kernel/fpu/xstate.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index f5ef786..e77cabf 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -857,9 +857,12 @@ void __init fpu__init_system_xstate(unsigned int legacy_size) update_regset_xstate_info(fpu_user_cfg.max_size, fpu_user_cfg.max_features); - /* Bring init_fpstate size and features up to date */ - init_fpstate.size = fpu_kernel_cfg.max_size; - init_fpstate.xfeatures = fpu_kernel_cfg.max_features; + /* + * init_fpstate excludes dynamic states as they are large but init + * state is zero. + */ + init_fpstate.size = fpu_kernel_cfg.default_size; + init_fpstate.xfeatures = fpu_kernel_cfg.default_features; if (init_fpstate.size > sizeof(init_fpstate.regs)) { pr_warn("x86/fpu: init_fpstate buffer too small (%zu < %d), disabling XSAVE\n",