Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp754712pxb; Wed, 20 Jan 2021 21:21:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJzDt47i0UXCCSTeya1fm5XGGgy4jHM+YkNugbbrejxC8MrXefmDzZO49jgz7Gcqhoz3A7J4 X-Received: by 2002:aa7:d78e:: with SMTP id s14mr9773058edq.329.1611206497228; Wed, 20 Jan 2021 21:21:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611206497; cv=none; d=google.com; s=arc-20160816; b=KVwzHNvH/M97xQsR/o//rMEhjcGSF4WjwyN3PAxGNtk9cZ9R/ai0ykHTDgHHEE+xRu Hme9ilYYiJ+pRJbnXVyuigTfOj1EhqcVj+HgyVL9PtG9lC0JuQx23Pt/l4vt/R6oH0cP MPJ9JO8/r/RC2EUsodynQn/9T3/yZLw+Da0NN4FW5JJxMI2Yq5RkA5Cxmd6+HJM+zsjw FDvK9i/nN6tJ4QXVB8WbaoNldLG56gJrblRglsPSV6Y07xHYLGPmCyrNqCR5wc895nkv x8iIpOhvcXXZ4uy6ImvFxfxIDFIMgPtZFCcZMZhM/gEun8Ht08U3rY6lixKrKxuvw28K WgTw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=NdjdJeOfsuYWD9WS2vumIeHEPxpIHBmXRV6f/R9H0pg=; b=Tp166nDDVIjFQKLZP//6c6b7rmhw4TVaF8Ve6iDGOMvXj9IyS/ugksY9I0HX41fwXi X+xkRIGiku+CshWjUNYdCj03ALTcU4R7P+MyF9ZVDS7zSdsEvsBIiwUBlwAzMRQ3yMqE aCS+prZaBreTgi9I/F3rn3N3Jq5+DGbsrfS4E7DEoX+NXVpIrueFPYV8AWpfOOUf4f7Z 0bGNfyw6EFpqagL5KSfx20RZxQ7/l2Zt2lFCPpQgR7iWv0D1I6k2kPC7SqTxM36y91z9 S1ghaxNBL4mHzWee9a8SNeQDuH1nRL+neWqDFkEp9S07ckZcVXxSlS6j8TW0leENd7Rq vf1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tnylOiFr; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x17si1760616edq.154.2021.01.20.21.21.14; Wed, 20 Jan 2021 21:21:37 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tnylOiFr; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727342AbhAUFRn (ORCPT + 99 others); Thu, 21 Jan 2021 00:17:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:46856 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725829AbhAUFKf (ORCPT ); Thu, 21 Jan 2021 00:10:35 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 82A66238EE; Thu, 21 Jan 2021 05:09:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611205794; bh=7DNRp6WNtdeilktzFhBTnZxvvhrAqZFiRFv1t5H9vSU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tnylOiFr8w6hafHWQ24ixd1sGaIIF+W+WI8k4G9lOH9xGHk2vAm6reHp/IyB2L+wr +sCyoVNPPGmi+PSoM/yEshqdiNlRtiNxRLltdnvJybLHI7jwUx5bnvJeo9CHZp7hue WHIVpwGAcf9kSOxDLoAQATzUtStvmR522esE2XNmrRdCJaDOLyjD+xyna8WhZj9n1R YjAIECbqjYQ5fy7DG/3bj3KBsUFHfIy3HB4AWcQjPdpuNQNpMeLLzDEeAkPeNroN0K 5lLYuoAmJv2x8NipNa3WOLP8GLaYGRNN3lkD/vGl3Mkvmctl4ovvJVuzJQcwmkNbE5 LZ1o7lQKFEhaQ== From: Andy Lutomirski To: x86@kernel.org Cc: LKML , Krzysztof Mazur , =?UTF-8?q?Krzysztof=20Ol=C4=99dzki?= , Arnd Bergmann , Andy Lutomirski , stable@vger.kernel.org Subject: [PATCH v3 2/4] x86/mmx: Use KFPU_387 for MMX string operations Date: Wed, 20 Jan 2021 21:09:49 -0800 Message-Id: X-Mailer: git-send-email 2.29.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The default kernel_fpu_begin() doesn't work on systems that support XMM but haven't yet enabled CR4.OSFXSR. This causes crashes when _mmx_memcpy() is called too early because LDMXCSR generates #UD when the aforementioned bit is clear. Fix it by using kernel_fpu_begin_mask(KFPU_387) explicitly. Fixes: 7ad816762f9b ("x86/fpu: Reset MXCSR to default in kernel_fpu_begin()") Cc: Reported-by: Krzysztof Mazur Signed-off-by: Andy Lutomirski --- arch/x86/lib/mmx_32.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c index 4321fa02e18d..ad1dabce931e 100644 --- a/arch/x86/lib/mmx_32.c +++ b/arch/x86/lib/mmx_32.c @@ -26,6 +26,16 @@ #include #include +/* + * Use KFPU_387. MMX instructions are not affected by MXCSR, + * but both AMD and Intel documentation states that even integer MMX + * operations will result in #MF if an exception is pending in FCW. + * + * EMMS is not needed afterwards because, after we call kernel_fpu_end(), + * any subsequent user of the 387 stack will reinitialize it using + * KFPU_387. + */ + void *_mmx_memcpy(void *to, const void *from, size_t len) { void *p; @@ -37,7 +47,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len) p = to; i = len >> 6; /* len/64 */ - kernel_fpu_begin(); + kernel_fpu_begin_mask(KFPU_387); __asm__ __volatile__ ( "1: prefetch (%0)\n" /* This set is 28 bytes */ @@ -127,7 +137,7 @@ static void fast_clear_page(void *page) { int i; - kernel_fpu_begin(); + kernel_fpu_begin_mask(KFPU_387); __asm__ __volatile__ ( " pxor %%mm0, %%mm0\n" : : @@ -160,7 +170,7 @@ static void fast_copy_page(void *to, void *from) { int i; - kernel_fpu_begin(); + kernel_fpu_begin_mask(KFPU_387); /* * maybe the prefetch stuff can go before the expensive fnsave... @@ -247,7 +257,7 @@ static void fast_clear_page(void *page) { int i; - kernel_fpu_begin(); + kernel_fpu_begin_mask(KFPU_387); __asm__ __volatile__ ( " pxor %%mm0, %%mm0\n" : : @@ -282,7 +292,7 @@ static void fast_copy_page(void *to, void *from) { int i; - kernel_fpu_begin(); + kernel_fpu_begin_mask(KFPU_387); __asm__ __volatile__ ( "1: prefetch (%0)\n" -- 2.29.2