Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp279206pxb; Thu, 21 Jan 2021 07:01:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJzp3Ti5VMGlIf1+FR+J3FA1w8pntzhr77g9EJpzF+pGlcpoVAlKlAg+xhdA73LOosFgdvZZ X-Received: by 2002:a17:907:948d:: with SMTP id dm13mr9137825ejc.545.1611241274864; Thu, 21 Jan 2021 07:01:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611241274; cv=none; d=google.com; s=arc-20160816; b=U37yslrxyNLMK4c/Z/jbqTe8lKahH8PLL83vbg22BltrtB1LUeIPwIMLVThtYqkZCd 5t5PuqQjD1029Ykmvep8EEtqEdZKNoqXaWuPJDA2Uzx8DnXeRV+qreOAh25VDdUH72qG LomT089HTQrbNXV8004QuUrCy25OpcmXwllzOB288IRFOOaVxLF9uVnavuLKolkzF/sd CIsjNnnDjq9z/oyM7Vb+zH7m9UQnMm4uvl+R0PUdo5uf8wjRZAsmoQEeyHOYHzkUV6UA gJNhgt0fgNM69Ycme3mEZnTunt646CQYhNQvmrBMTGTwZO5F1jYg4GxEmMe4Sa71lLm8 Hq8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=8nCcl62e6GfJVT0Q+3a0+mnSZi/+Kdfk1t5E0aKT7a0=; b=oQ1MRzVsBmtJQwO5yiMp8tq088DZ9UNt5E/R6MXvZvCJqrqYZfZcGDk4tgtM3PMg8N efduvzMmh5gN/QmVTnmsRd8JKcS+bBbvzZq4WpJPg8IKox0oQGqUGfR8icQ14iJB3KRK 1/2ZEfU8bp3OYEWt4UOX+iycWeBtBxJqHh/RGVuVVbvWD+Nbt/oKDGCwJ8Yzzn4g6Rnm IxVLW/sVAgvgmBLh/GbJQHXPH3hV73fW4uawjqOzrRWlieTGqdl1w1hx2Ew8uyXazMLX pCtz7hCYcCrWrknm3Yt3sXx39REzbt7w0Ut4B2cAHlYnYZD/G37T5IN/fkGjb/SMUUrv GQlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GlUfMQQO; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id mm6si1840378ejb.395.2021.01.21.07.00.43; Thu, 21 Jan 2021 07:01:14 -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=@redhat.com header.s=mimecast20190719 header.b=GlUfMQQO; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732352AbhAUO6r (ORCPT + 99 others); Thu, 21 Jan 2021 09:58:47 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:24885 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732023AbhAUO6B (ORCPT ); Thu, 21 Jan 2021 09:58:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611240994; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=8nCcl62e6GfJVT0Q+3a0+mnSZi/+Kdfk1t5E0aKT7a0=; b=GlUfMQQONHqnNJ67L+AYjYDXXtTav9UrmZ0KgFs17pGWbQqp0vzRWbLmjC073a14MPf91W Anzk61XbcFoWoPyGSK/ZGg7nZ0YNNCFDDdHUaVyZJVgzj9K7acK+iFmBoC90xLasPkFFy5 jlPXKEKSas18sCHooH4hmu7GYEvQokQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-334-z2uOodC7PMq_brP9sYullA-1; Thu, 21 Jan 2021 09:56:33 -0500 X-MC-Unique: z2uOodC7PMq_brP9sYullA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 58BEA10151EC; Thu, 21 Jan 2021 14:56:31 +0000 (UTC) Received: from work-vm (ovpn-115-101.ams2.redhat.com [10.36.115.101]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 05C066E51B; Thu, 21 Jan 2021 14:56:24 +0000 (UTC) Date: Thu, 21 Jan 2021 14:56:22 +0000 From: "Dr. David Alan Gilbert" To: Wei Huang Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, pbonzini@redhat.com, vkuznets@redhat.com, mlevitsk@redhat.com, seanjc@google.com, joro@8bytes.org, bp@alien8.de, tglx@linutronix.de, mingo@redhat.com, x86@kernel.org, jmattson@google.com, wanpengli@tencent.com, bsd@redhat.com, luto@amacapital.net Subject: Re: [PATCH v2 4/4] KVM: SVM: Support #GP handling for the case of nested on nested Message-ID: <20210121145622.GH3072@work-vm> References: <20210121065508.1169585-1-wei.huang2@amd.com> <20210121065508.1169585-5-wei.huang2@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210121065508.1169585-5-wei.huang2@amd.com> User-Agent: Mutt/1.14.6 (2020-07-11) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Wei Huang (wei.huang2@amd.com) wrote: > Under the case of nested on nested (e.g. L0->L1->L2->L3), #GP triggered > by SVM instructions can be hided from L1. Instead the hypervisor can > inject the proper #VMEXIT to inform L1 of what is happening. Thus L1 > can avoid invoking the #GP workaround. For this reason we turns on > guest VM's X86_FEATURE_SVME_ADDR_CHK bit for KVM running inside VM to > receive the notification and change behavior. Doesn't this mean a VM migrated between levels (hmm L2 to L1???) would see different behaviour? (I've never tried such a migration, but I thought in principal it should work). Dave > Co-developed-by: Bandan Das > Signed-off-by: Bandan Das > Signed-off-by: Wei Huang > --- > arch/x86/kvm/svm/svm.c | 19 ++++++++++++++++++- > 1 file changed, 18 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c > index 2a12870ac71a..89512c0e7663 100644 > --- a/arch/x86/kvm/svm/svm.c > +++ b/arch/x86/kvm/svm/svm.c > @@ -2196,6 +2196,11 @@ static int svm_instr_opcode(struct kvm_vcpu *vcpu) > > static int emulate_svm_instr(struct kvm_vcpu *vcpu, int opcode) > { > + const int guest_mode_exit_codes[] = { > + [SVM_INSTR_VMRUN] = SVM_EXIT_VMRUN, > + [SVM_INSTR_VMLOAD] = SVM_EXIT_VMLOAD, > + [SVM_INSTR_VMSAVE] = SVM_EXIT_VMSAVE, > + }; > int (*const svm_instr_handlers[])(struct vcpu_svm *svm) = { > [SVM_INSTR_VMRUN] = vmrun_interception, > [SVM_INSTR_VMLOAD] = vmload_interception, > @@ -2203,7 +2208,14 @@ static int emulate_svm_instr(struct kvm_vcpu *vcpu, int opcode) > }; > struct vcpu_svm *svm = to_svm(vcpu); > > - return svm_instr_handlers[opcode](svm); > + if (is_guest_mode(vcpu)) { > + svm->vmcb->control.exit_code = guest_mode_exit_codes[opcode]; > + svm->vmcb->control.exit_info_1 = 0; > + svm->vmcb->control.exit_info_2 = 0; > + > + return nested_svm_vmexit(svm); > + } else > + return svm_instr_handlers[opcode](svm); > } > > /* > @@ -4034,6 +4046,11 @@ static void svm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu) > /* Check again if INVPCID interception if required */ > svm_check_invpcid(svm); > > + if (nested && guest_cpuid_has(vcpu, X86_FEATURE_SVM)) { > + best = kvm_find_cpuid_entry(vcpu, 0x8000000A, 0); > + best->edx |= (1 << 28); > + } > + > /* For sev guests, the memory encryption bit is not reserved in CR3. */ > if (sev_guest(vcpu->kvm)) { > best = kvm_find_cpuid_entry(vcpu, 0x8000001F, 0); > -- > 2.27.0 > -- Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK