Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9164950pxu; Mon, 28 Dec 2020 08:11:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJxpcxd2EUjN7k6StB/0qxxd0wOwbWpJpYNrlhcZOwl9eMQlOQSJd4zQLmXoBe/drtfbQvpu X-Received: by 2002:a17:906:5182:: with SMTP id y2mr43195609ejk.92.1609171911537; Mon, 28 Dec 2020 08:11:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609171911; cv=none; d=google.com; s=arc-20160816; b=h/om7us0BmC1Z/T/d5Q4SigMS06zgAXNxpikdVS7w92EQdKRDTMjfPWSH6hW0QiZcd xBTHQ+sVJoBSAtHjjPaNl6sCzSerglmRXJuwenqJbOHZ2rJKQ0T+5RWbIboTbiKR9V6U BhOCLiSRzvPFC9tgdvWlQZ1rTdQ/Gq0RGRoPXRlz2kODPHTqIhR2ev1PNm20Zgu54rJG UuyWdwsYJon3TM67fMw+mOXVyoEna+xqlGvCTcUdSApdhJ0LMXQwkCspkIYjmCEiZ3aj QdF/8IkGZFfhcl0AFgJQQG5lCeUqP6pP2ZKJCUtXC94OjaLsgMwtEnqjQDd8+axpyMOr Rs3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=I65qXEtGw76GDnQflwBz9Eqfd8lEXU8eaKaYDGKJvz0=; b=j/N80vVnZgEPiGLJ8dalmB5LqaeFpvyzxV6ETD/ltXhrhpmdvFjNBtxbPeEkyw7xJM NeAXebqDjCGfEreSqvrqBonOMO74jhGT9H50CiZqUlXTiBCstM7nxoVhn3AJXQ+Zxb7Q 0nu5oIRS5gWTzfG0J9G7WOvA8ufPdVzKv1qOp9rzOowEkAJsdE7mTBuGrpN2AjbnwXX9 Udo2VyKNzAkuahisCMHaa1HuxlP8+eJct8epu49IbGVz5Lgz4Upsi0Vvg1c+/V8LHR8z aXPK9aXmwht2XbVTQ0s+xZ0m+bWs5KLCLqSu1cKCJ9IdWJCZyx11LiJY7xjDgikNeSbJ RkvQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=podlesie.net Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i24si18632604eja.372.2020.12.28.08.11.28; Mon, 28 Dec 2020 08:11:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=podlesie.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393541AbgL1QJ1 (ORCPT + 99 others); Mon, 28 Dec 2020 11:09:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2393535AbgL1QJY (ORCPT ); Mon, 28 Dec 2020 11:09:24 -0500 X-Greylist: delayed 121 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 28 Dec 2020 08:08:43 PST Received: from shrek.podlesie.net (shrek-3s.podlesie.net [IPv6:2a00:13a0:3010::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9F08FC061794; Mon, 28 Dec 2020 08:08:43 -0800 (PST) Received: from geronimo.kostuchna.emnet (unknown [127.0.0.1]) by shrek.podlesie.net (Postfix) with ESMTP id 9119E1636; Mon, 28 Dec 2020 16:06:40 +0000 (UTC) From: Krzysztof Mazur To: Thomas Gleixner , Ingo Molnar , Borislav Petkov Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Krzysztof Mazur , stable@vger.kernel.org Subject: [PATCH] x86/lib: don't use MMX before FPU initialization Date: Mon, 28 Dec 2020 17:06:31 +0100 Message-Id: <20201228160631.32732-1-krzysiek@podlesie.net> X-Mailer: git-send-email 2.27.0.rc1.207.gb85828341f MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When enabled, the MMX 3DNow! optimized memcpy() is used very early, even before FPU is initialized. It worked fine, but commit 7ad816762f9bf89e940e618ea40c43138b479e10 ("x86/fpu: Reset MXCSR to default in kernel_fpu_begin()") broke that. After that commit the kernel crashes just after "Booting the kernel." message. It affects all kernels with CONFIG_X86_USE_3DNOW=y (enabled when some AMD/Cyrix processors are selected). So, enable MMX 3DNow! optimized memcpy() later. Cc: # 5.8+ Signed-off-by: Krzysztof Mazur --- Hi, this patch fixes a kernel crash during boot observed on AMD Athlon XP (with CONFIG_MK7=y). The static key adds 5 byte NOP in the "fast" path. The 3DNow! usage can be enabled earlier, but arch_initcall should be ok. The static_cpu_has() does not work because the kernel with CONFIG_X86_USE_3DNOW=y assumes that 3DNOW! is available, so a static key is used instead. "Alternatives" should also work, as long they not assume that required features (REQUIRED_MASK*) are available early. Similar bugs are possible. For easier debugging, maybe kernel_fpu_begin() should catch such cases and print something? Thanks, Krzysiek arch/x86/lib/mmx_32.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c index 4321fa02e18d..375bf0798993 100644 --- a/arch/x86/lib/mmx_32.c +++ b/arch/x86/lib/mmx_32.c @@ -26,12 +26,14 @@ #include #include +static __ro_after_init DEFINE_STATIC_KEY_FALSE(use_mmx); + void *_mmx_memcpy(void *to, const void *from, size_t len) { void *p; int i; - if (unlikely(in_interrupt())) + if (unlikely(in_interrupt()) || !static_branch_likely(&use_mmx)) return __memcpy(to, from, len); p = to; @@ -376,3 +378,11 @@ void mmx_copy_page(void *to, void *from) fast_copy_page(to, from); } EXPORT_SYMBOL(mmx_copy_page); + +static int __init mmx_32_init(void) +{ + static_branch_enable(&use_mmx); + return 0; +} + +arch_initcall(mmx_32_init); -- 2.27.0.rc1.207.gb85828341f