From patchwork Mon Aug 21 06:47:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengen Du X-Patchwork-Id: 1823551 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=sMsUhOEp; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RTjj06zz5z1ygk for ; Mon, 21 Aug 2023 16:47:47 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1qXyhP-0004D5-7i; Mon, 21 Aug 2023 06:47:39 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1qXyhM-0004CT-OA for kernel-team@lists.ubuntu.com; Mon, 21 Aug 2023 06:47:36 +0000 Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 961E93FAA1 for ; Mon, 21 Aug 2023 06:47:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1692600456; bh=i2V6Pz1Rtd523sDqwuqkVOiZ+5cEVFmxSZRvsEN/bjo=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=sMsUhOEp0+VNlz/XUrw5JI/b5AJsw/SsXFsQTpwFAQp3FGPmfinxmUsxUqUl/UrG7 JKseyvYZT7Kwg4O7UT4ZXvWxSxBNAQP3cyQQ5WpUbdU6h9C57mkpTwh0W+G7uaKN2K VBRbZdetORpzucNtU8+pRGIO0hlUFtzU8IOVUFUU2wrKRTDC4hsUKYEUKtoB+Bg3qj DqDWZX34WHxFMzOMUUkBBnjWK8rf8O8J2PyoFVrn30Pu9vgk6bAjxOhA/hIFqwXhB1 1JZAT061bqyp8kKQxarB4tB4HxmQHYxWuA8NXoumd3u+rSRzCZERNjbz3IytNxOH+j +/SbiOY0W/YmQ== Received: by mail-pj1-f72.google.com with SMTP id 98e67ed59e1d1-267f00f6876so3141590a91.3 for ; Sun, 20 Aug 2023 23:47:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692600455; x=1693205255; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=i2V6Pz1Rtd523sDqwuqkVOiZ+5cEVFmxSZRvsEN/bjo=; b=UK6QWDFnHoxm6Y/T6UQe8/zkag/mkuLIlsogD8Gjp7ZQOChlYFDcgCw6g3oggfoPUc IgYOIuQ5A1pk6vY4lR6x0Z3iOeBYOf8k7m3TbCOnJPjC/lG80jPob0f2SadeC3jLHrlE iZwyKucoEc2krWPFeWu2M06GJYf0rQ/yoUay47Xh4p4WL0dlPEm6fxkehMyGqfDnAIi5 vOHrYbexQhHM7DkyavqQKc9CeyNSd3KNEDJxpp9oD2NNY3GV9jDGmo/nNO+P8qRxJO6r tn2ajDnmV+5uvpPZflwRh68zdf51TH3mRCHqfFUytok8UKISNsjazoQM+0sOOQyisb65 BGVQ== X-Gm-Message-State: AOJu0YyJEH0qmB39oWBhpim+R9WcLy37bH8nbePhe8/wzNACM59FRC+D sYMyECaGPwUwKuo3SswNj9N4zLMkqJoJUo+y/TXOhUY0U8/Ax2JHP+3luqva4q5kBz66Zq6Fi9K 8ZvLlF1hmH7Xrz/FEcIc2j2tew/Jl+lwDVQFFpkF81IbN24UGjA== X-Received: by 2002:a17:90a:ce17:b0:262:f579:41db with SMTP id f23-20020a17090ace1700b00262f57941dbmr2853661pju.6.1692600454950; Sun, 20 Aug 2023 23:47:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGk8uT/PWWjfRTxxsSh5DKa/dEtI/kPDn20fN+ypD53dUpQhmVi0GtRrGcBCSLmwlP0/y3HQA== X-Received: by 2002:a17:90a:ce17:b0:262:f579:41db with SMTP id f23-20020a17090ace1700b00262f57941dbmr2853655pju.6.1692600454627; Sun, 20 Aug 2023 23:47:34 -0700 (PDT) Received: from chengendu.. (111-248-116-169.dynamic-ip.hinet.net. [111.248.116.169]) by smtp.gmail.com with ESMTPSA id l11-20020a17090a598b00b00267b38f5e13sm5275515pji.2.2023.08.20.23.47.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Aug 2023 23:47:34 -0700 (PDT) From: Chengen Du To: kernel-team@lists.ubuntu.com Subject: [SRU][J][PATCH 2/2] KVM: x86: Always enable legacy FP/SSE in allowed user XFEATURES Date: Mon, 21 Aug 2023 14:47:28 +0800 Message-Id: <20230821064728.38227-3-chengen.du@canonical.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230821064728.38227-1-chengen.du@canonical.com> References: <20230821064728.38227-1-chengen.du@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: "Dr. David Alan Gilbert" Allow FP and SSE state to be saved and restored via KVM_{G,SET}_XSAVE on XSAVE-capable hosts even if their bits are not exposed to the guest via XCR0. Failing to allow FP+SSE first showed up as a QEMU live migration failure, where migrating a VM from a pre-XSAVE host, e.g. Nehalem, to an XSAVE host failed due to KVM rejecting KVM_SET_XSAVE. However, the bug also causes problems even when migrating between XSAVE-capable hosts as KVM_GET_SAVE won't set any bits in user_xfeatures if XSAVE isn't exposed to the guest, i.e. KVM will fail to actually migrate FP+SSE. Because KVM_{G,S}ET_XSAVE are designed to allowing migrating between hosts with and without XSAVE, KVM_GET_XSAVE on a non-XSAVE (by way of fpu_copy_guest_fpstate_to_uabi()) always sets the FP+SSE bits in the header so that KVM_SET_XSAVE will work even if the new host supports XSAVE. Fixes: ad856280ddea ("x86/kvm/fpu: Limit guest user_xfeatures to supported bits of XCR0") bz: https://bugzilla.redhat.com/show_bug.cgi?id=2079311 Cc: stable@vger.kernel.org Cc: Leonardo Bras Signed-off-by: Dr. David Alan Gilbert [sean: add comment, massage changelog] Signed-off-by: Sean Christopherson Message-Id: <20220824033057.3576315-3-seanjc@google.com> Signed-off-by: Paolo Bonzini (cherry picked from commit a1020a25e69755a8a1a37735d674b91d6f02939f) Signed-off-by: Chengen Du --- arch/x86/kvm/cpuid.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 8e24e2b22948..d9cd49305c84 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -187,7 +187,13 @@ static void kvm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu) best->ecx |= XFEATURE_MASK_FPSSE; } - vcpu->arch.guest_fpu.fpstate->user_xfeatures = vcpu->arch.guest_supported_xcr0; + /* + * FP+SSE can always be saved/restored via KVM_{G,S}ET_XSAVE, even if + * XSAVE/XCRO are not exposed to the guest, and even if XSAVE isn't + * supported by the host. + */ + vcpu->arch.guest_fpu.fpstate->user_xfeatures = vcpu->arch.guest_supported_xcr0 | + XFEATURE_MASK_FPSSE; kvm_update_pv_runtime(vcpu);