From patchwork Fri Oct 21 22:25:18 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: 7020 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp930796wrr; Fri, 21 Oct 2022 15:30:35 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7aLP6CEkvhvR6n3XEtc+t3H/T4bfbm2Cm5oTEmoZoFyh7hIFhO4XwuNm+d2d8vlzGeOFeE X-Received: by 2002:a17:902:724b:b0:185:4639:69b1 with SMTP id c11-20020a170902724b00b00185463969b1mr20628649pll.142.1666391435483; Fri, 21 Oct 2022 15:30:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666391435; cv=none; d=google.com; s=arc-20160816; b=GQpTOHeVk32EE5HQh/wiihFjpiheRRxVgTpRz2b+fvuHGPmYUi/mp0woIAyb1Tp1C8 6X+yDZW1LkDSifxtkaqnI/7mxoO1ESwnGPPyp/INF4oBZSBd6p5gXxtBrKEKT6L5xWSO l2tGKNE7QUOWXeTiSDR6XF3QN8gkUZ0ccKV2eD1SjTMH4eRcFrXgrgHHWkQs2soitujz 6V+zwGD+kuOS3cBZhQ0Phu1gifzxy4DKGq6jECrA2DJQ2gKHK2NjV1XoHY/9EhoKdgAI W3Auy4vjmsNp207QPovUVJHGlJJbI2gbFVgeYFQ0iIw0BdJwMpOrR+/TVfD3LW5WywQw 7+Dw== 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=mC43962uVKGAlF97kVQ/2Yk+2veweV1Yl78IBTeen9U=; b=VU1MaJGupbr0IbKPTm2+9XmycKsRdrmrC02svjDetb99J+uhHpya39EDXIuPAU8R1/ fpmn0+1WEu+xFM8a6XcmVBYd5WdVb0Pqptezx94XciTJtVvL37+vBN8QJYN21ZGu33M5 b9yBsbCC+eb5kMLus2LUwIphCSHXvuIL3aNRC8NovGQT/kGM4niGFGaYd0XdHtwBKsGv ZSxVym18p7HeHcbPy27xinA3+BSU9oa9bNEJDRz5Qj6JzS1fKpUy22HdFlHTd4olPD0z h2kscBRs7H5xxzS+7i5hT8i76csL2U7Y+e64RJC8pviIb2JSwAhGAqIBgpAGMAxE+NvD uaJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=f6WkOOu7; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=GEPauoEc; 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 m1-20020a170902db0100b00184306292a5si26779582plx.229.2022.10.21.15.30.23; Fri, 21 Oct 2022 15:30:35 -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=f6WkOOu7; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=GEPauoEc; 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 S229741AbiJUWZb (ORCPT + 99 others); Fri, 21 Oct 2022 18:25:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229515AbiJUWZ3 (ORCPT ); Fri, 21 Oct 2022 18:25:29 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DDD1140E68; Fri, 21 Oct 2022 15:25:23 -0700 (PDT) Date: Fri, 21 Oct 2022 22:25:18 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666391120; 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=mC43962uVKGAlF97kVQ/2Yk+2veweV1Yl78IBTeen9U=; b=f6WkOOu7gGMTSYbG3IiWWK8UBoeaSVZiAX6nlhBzUy0h40cuay6eAwnNNwqjHB/Tgt54X6 HdCr+LKPCxZqxyvPsOUuCJP7l+DNVq/eC4f21CqWX6or33FpHhtBVI5wn1u4BsoVg3u8Nn N5c/fMvwvErjZUKSpii2snPTyjxIhGVIcWKDI7e9CBlXAlEYxnxgEl3rCwkC+9StxSeh/J tXYbjJwch7Of2dscXIp0K4sfCMjMi8+2qoDHlS4hrms5ErMH5mRWDeXsDAQsO2EDAPqGKI x1SKSsV+u3cLMJbQfokvM8ZYZ4SaesW2ujwkgjz8zaWUBEaCGI4t9eBCsITdqg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666391120; 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=mC43962uVKGAlF97kVQ/2Yk+2veweV1Yl78IBTeen9U=; b=GEPauoEcTc61qc8UBuJyq8IU7IIRYJ5lwjpk58pdOPMj34hS3BWQx32cU6gNy6UB2AxQFv qaR3SwJkLsyIzsAQ== 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: Fix copy_xstate_to_uabi() to copy init states correctly Cc: Yuan Yao , Dave Hansen , "Chang S. Bae" , Dave Hansen , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20221021185844.13472-1-chang.seok.bae@intel.com> References: <20221021185844.13472-1-chang.seok.bae@intel.com> MIME-Version: 1.0 Message-ID: <166639111821.401.9381657733834636095.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,URIBL_BLOCKED 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?1747065964259797394?= X-GMAIL-MSGID: =?utf-8?q?1747338065877978712?= The following commit has been merged into the x86/urgent branch of tip: Commit-ID: 471f0aa7fa64e23766a1473b32d9ec3f0718895a Gitweb: https://git.kernel.org/tip/471f0aa7fa64e23766a1473b32d9ec3f0718895a Author: Chang S. Bae AuthorDate: Fri, 21 Oct 2022 11:58:44 -07:00 Committer: Dave Hansen CommitterDate: Fri, 21 Oct 2022 15:22:09 -07:00 x86/fpu: Fix copy_xstate_to_uabi() to copy init states correctly When an extended state component is not present in fpstate, but in init state, the function copies from init_fpstate via copy_feature(). But, dynamic states are not present in init_fpstate because of all-zeros init states. Then retrieving them from init_fpstate will explode like this: BUG: kernel NULL pointer dereference, address: 0000000000000000 ... RIP: 0010:memcpy_erms+0x6/0x10 ? __copy_xstate_to_uabi_buf+0x381/0x870 fpu_copy_guest_fpstate_to_uabi+0x28/0x80 kvm_arch_vcpu_ioctl+0x14c/0x1460 [kvm] ? __this_cpu_preempt_check+0x13/0x20 ? vmx_vcpu_put+0x2e/0x260 [kvm_intel] kvm_vcpu_ioctl+0xea/0x6b0 [kvm] ? kvm_vcpu_ioctl+0xea/0x6b0 [kvm] ? __fget_light+0xd4/0x130 __x64_sys_ioctl+0xe3/0x910 ? debug_smp_processor_id+0x17/0x20 ? fpregs_assert_state_consistent+0x27/0x50 do_syscall_64+0x3f/0x90 entry_SYSCALL_64_after_hwframe+0x63/0xcd Adjust the 'mask' to zero out the userspace buffer for the features that are not available both from fpstate and from init_fpstate. The dynamic features depend on the compacted XSAVE format. Ensure it is enabled before reading XCOMP_BV in init_fpstate. Fixes: 2308ee57d93d ("x86/fpu/amx: Enable the AMX feature in 64-bit mode") Reported-by: Yuan Yao Suggested-by: Dave Hansen Signed-off-by: Chang S. Bae Signed-off-by: Dave Hansen Tested-by: Yuan Yao Link: https://lore.kernel.org/lkml/BYAPR11MB3717EDEF2351C958F2C86EED95259@BYAPR11MB3717.namprd11.prod.outlook.com/ Link: https://lkml.kernel.org/r/20221021185844.13472-1-chang.seok.bae@intel.com --- arch/x86/kernel/fpu/xstate.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index e77cabf..59e543b 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -1125,6 +1125,15 @@ void __copy_xstate_to_uabi_buf(struct membuf to, struct fpstate *fpstate, */ mask = fpstate->user_xfeatures; + /* + * Dynamic features are not present in init_fpstate. When they are + * in an all zeros init state, remove those from 'mask' to zero + * those features in the user buffer instead of retrieving them + * from init_fpstate. + */ + if (fpu_state_size_dynamic()) + mask &= (header.xfeatures | xinit->header.xcomp_bv); + for_each_extended_xfeature(i, mask) { /* * If there was a feature or alignment gap, zero the space