From patchwork Tue Oct 25 12:47:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 10776 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp991435wru; Tue, 25 Oct 2022 06:02:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6rYetXbeafHHbVb8bUJgpvizZXTFCAGCmtz/BxzHA49B9AvPxsbD7qcGEhn/ckp1Hnbvui X-Received: by 2002:a17:902:b092:b0:186:9dc3:dc44 with SMTP id p18-20020a170902b09200b001869dc3dc44mr13244573plr.112.1666702963140; Tue, 25 Oct 2022 06:02:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666702963; cv=none; d=google.com; s=arc-20160816; b=D+FoNXxno9q3ug6CU8I1Mm47qgfiGxk354aZpX4vna/8uRyc2QvYi458OiY2N+bW0B KqvQO8Miz3UfMaG28lTPfBcFVnF9R4l7+D1hJTk4WfedPlRLsc9pMifo4tfNKjACqSJE NsVzpQ8148UATVMTwMQDc1KvzA9bOAb8gIrHXn91xWw10YcLBBa0CGQLRHT4eshRAQt1 xYAI78uBJCmruKuUwf/ECxlJqzJxrPLsQ57oMOsqFchj9TFbJn9HKfi3Qh2a/dl3CXTN 36nV1aF/e4mLEm5LG1WUp1omtqQbVFT2++24RxpyIjE1WfqjFMJaO3dpzvUa91p/riDc mawQ== 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=mCA4Do0tiMgEdMpQsmntRao/qg+7vUX+Fj7hqfX+/kI=; b=nyksI1yZH129ZTkFQlCDm3ocKLTasaRpnQt+NwMvCu/x00UxUxeHqJTRFNDIcav5dm KpsphlgUrMwpqoajZH9yW3KR4nmRxlGYzxijtZuV3maEf4AhI/Z+k1+pKVVc/LK9/FQH Wm7tzxyoThjq/x53IXM76RfFQOdYIR+nqWbqSoSJH0wc2xvlwcbkj6PiKqJfLK/ZfDW+ Ny5fmbJiBUmU/2eHbuQx7JOYZY7IDUGGHzbxY6Bg4LfaLfceDhKiT7biGBm0/Hw8K+j5 GCWl7JrzjTcmmee4CAcxo79XLw6kwltvTyPyqNG7AcQIy5cdBD5Kal8AF8zDXpNZWnQi rj2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QR9NgiDA; 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=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m2-20020a656a02000000b0046b173cdb6esi3504185pgu.352.2022.10.25.06.02.18; Tue, 25 Oct 2022 06:02:43 -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=@redhat.com header.s=mimecast20190719 header.b=QR9NgiDA; 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=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232679AbiJYMxK (ORCPT + 99 others); Tue, 25 Oct 2022 08:53:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232155AbiJYMwC (ORCPT ); Tue, 25 Oct 2022 08:52:02 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B61F026FE for ; Tue, 25 Oct 2022 05:49:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666702156; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mCA4Do0tiMgEdMpQsmntRao/qg+7vUX+Fj7hqfX+/kI=; b=QR9NgiDAwGFYmB9rqT93i1WZLEcflEu8m3kiYQd+wWch6M5aWcZF60pbcxbnQH1+WqkO1E r5Pl5bZLnSgEu9Q1a5Z4/FIpgXOeAJ0j+gX7auykONxEyXtOOLzG8f2qeKP8Nxtx7xMCCU jjIHwJY3ZvK5AhnTMRV6PNj7ei3hbRA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-212-zqzZbjGpOrGulRdIimA3DQ-1; Tue, 25 Oct 2022 08:49:13 -0400 X-MC-Unique: zqzZbjGpOrGulRdIimA3DQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 600AD802527; Tue, 25 Oct 2022 12:49:12 +0000 (UTC) Received: from amdlaptop.tlv.redhat.com (dhcp-4-238.tlv.redhat.com [10.35.4.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0CE8640C6E13; Tue, 25 Oct 2022 12:49:08 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Thomas Gleixner , Yang Zhong , x86@kernel.org, Jim Mattson , Vitaly Kuznetsov , Paolo Bonzini , Sean Christopherson , Wanpeng Li , Shuah Khan , Guang Zeng , Joerg Roedel , Maxim Levitsky , linux-kernel@vger.kernel.org, Dave Hansen , Ingo Molnar , linux-kselftest@vger.kernel.org, Kees Cook , "H. Peter Anvin" , Wei Wang , Borislav Petkov Subject: [PATCH RESEND v4 22/23] KVM: x86: SVM: don't save SVM state to SMRAM when VM is not long mode capable Date: Tue, 25 Oct 2022 15:47:40 +0300 Message-Id: <20221025124741.228045-23-mlevitsk@redhat.com> In-Reply-To: <20221025124741.228045-1-mlevitsk@redhat.com> References: <20221025124741.228045-1-mlevitsk@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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?1747664726032700714?= X-GMAIL-MSGID: =?utf-8?q?1747664726032700714?= When the guest CPUID doesn't have support for long mode, 32 bit SMRAM layout is used and it has no support for preserving EFER and/or SVM state. Note that this isn't relevant to running 32 bit guests on VM which is long mode capable - such VM can still run 32 bit guests in compatibility mode. Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/svm.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 3004a5ff3fbf79..d22a809d923339 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4445,6 +4445,14 @@ static int svm_enter_smm(struct kvm_vcpu *vcpu, union kvm_smram *smram) if (!is_guest_mode(vcpu)) return 0; + /* + * 32-bit SMRAM format doesn't preserve EFER and SVM state. Userspace is + * responsible for ensuring nested SVM and SMIs are mutually exclusive. + */ + + if (!guest_cpuid_has(vcpu, X86_FEATURE_LM)) + return 1; + smram->smram64.svm_guest_flag = 1; smram->smram64.svm_guest_vmcb_gpa = svm->nested.vmcb12_gpa;