kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ashish Kalra <ashish.kalra@amd.com>
To: Sean Christopherson <seanjc@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
	srutherford@google.com, joro@8bytes.org, brijesh.singh@amd.com,
	thomas.lendacky@amd.com, venu.busireddy@oracle.com,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	Borislav Petkov <bp@suse.de>,
	x86@kernel.org
Subject: Re: [PATCH 0/3] KVM: x86: guest interface for SEV live migration
Date: Tue, 20 Apr 2021 18:11:24 +0000	[thread overview]
Message-ID: <20210420181124.GA12798@ashkalra_ubuntu_server> (raw)
In-Reply-To: <YH8P26OibEfxvJAu@google.com>

On Tue, Apr 20, 2021 at 05:31:07PM +0000, Sean Christopherson wrote:
> On Tue, Apr 20, 2021, Paolo Bonzini wrote:
> > From ef78673f78e3f2eedc498c1fbf9271146caa83cb Mon Sep 17 00:00:00 2001
> > From: Ashish Kalra <ashish.kalra@amd.com>
> > Date: Thu, 15 Apr 2021 15:57:02 +0000
> > Subject: [PATCH 2/3] KVM: X86: Introduce KVM_HC_PAGE_ENC_STATUS hypercall
> > 
> > This hypercall is used by the SEV guest to notify a change in the page
> > encryption status to the hypervisor. The hypercall should be invoked
> > only when the encryption attribute is changed from encrypted -> decrypted
> > and vice versa. By default all guest pages are considered encrypted.
> > 
> > The hypercall exits to userspace to manage the guest shared regions and
> > integrate with the userspace VMM's migration code.
> 
> ...
> 
> > diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
> > index fd4a84911355..2bc353d1f356 100644
> > --- a/Documentation/virt/kvm/api.rst
> > +++ b/Documentation/virt/kvm/api.rst
> > @@ -6766,3 +6766,14 @@ they will get passed on to user space. So user space still has to have
> >  an implementation for these despite the in kernel acceleration.
> >  
> >  This capability is always enabled.
> > +
> > +8.32 KVM_CAP_EXIT_HYPERCALL
> > +---------------------------
> > +
> > +:Capability: KVM_CAP_EXIT_HYPERCALL
> > +:Architectures: x86
> > +:Type: vm
> > +
> > +This capability, if enabled, will cause KVM to exit to userspace
> > +with KVM_EXIT_HYPERCALL exit reason to process some hypercalls.
> > +Right now, the only such hypercall is KVM_HC_PAGE_ENC_STATUS.
> > diff --git a/Documentation/virt/kvm/cpuid.rst b/Documentation/virt/kvm/cpuid.rst
> > index cf62162d4be2..c9378d163b5a 100644
> > --- a/Documentation/virt/kvm/cpuid.rst
> > +++ b/Documentation/virt/kvm/cpuid.rst
> > @@ -96,6 +96,11 @@ KVM_FEATURE_MSI_EXT_DEST_ID        15          guest checks this feature bit
> >                                                 before using extended destination
> >                                                 ID bits in MSI address bits 11-5.
> >  
> > +KVM_FEATURE_HC_PAGE_ENC_STATUS     16          guest checks this feature bit before
> > +                                               using the page encryption state
> > +                                               hypercall to notify the page state
> > +                                               change
> 
> ...
> 
> >  int kvm_emulate_hypercall(struct kvm_vcpu *vcpu)
> >  {
> >  	unsigned long nr, a0, a1, a2, a3, ret;
> > @@ -8334,6 +8346,28 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu)
> >  		kvm_sched_yield(vcpu, a0);
> >  		ret = 0;
> >  		break;
> > +	case KVM_HC_PAGE_ENC_STATUS: {
> > +		u64 gpa = a0, npages = a1, enc = a2;
> > +
> > +		ret = -KVM_ENOSYS;
> > +		if (!vcpu->kvm->arch.hypercall_exit_enabled)
> 
> I don't follow, why does the hypercall need to be gated by a capability?  What
> would break if this were changed to?
> 
> 		if (!guest_pv_has(vcpu, KVM_FEATURE_HC_PAGE_ENC_STATUS))
> 

But, the above indicates host support for page_enc_status_hc, so we want
to ensure that host supports and has enabled support for the hypercall
exit, i.e., hypercall has been enabled.

Thanks,
Ashish

> > +			break;
> > +
> > +		if (!PAGE_ALIGNED(gpa) || !npages ||
> > +		    gpa_to_gfn(gpa) + npages <= gpa_to_gfn(gpa)) {
> > +			ret = -EINVAL;
> > +			break;
> > +		}
> > +
> > +		vcpu->run->exit_reason        = KVM_EXIT_HYPERCALL;
> > +		vcpu->run->hypercall.nr       = KVM_HC_PAGE_ENC_STATUS;
> > +		vcpu->run->hypercall.args[0]  = gpa;
> > +		vcpu->run->hypercall.args[1]  = npages;
> > +		vcpu->run->hypercall.args[2]  = enc;
> > +		vcpu->run->hypercall.longmode = op_64_bit;
> > +		vcpu->arch.complete_userspace_io = complete_hypercall_exit;
> > +		return 0;
> > +	}
> >  	default:
> >  		ret = -KVM_ENOSYS;
> >  		break;
> 
> ...
> 
> > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> > index 590cc811c99a..d696a9f13e33 100644
> > --- a/arch/x86/kvm/x86.c
> > +++ b/arch/x86/kvm/x86.c
> > @@ -3258,6 +3258,14 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
> >  		vcpu->arch.msr_kvm_poll_control = data;
> >  		break;
> >  
> > +	case MSR_KVM_MIGRATION_CONTROL:
> > +		if (data & ~KVM_PAGE_ENC_STATUS_UPTODATE)
> > +			return 1;
> > +
> > +		if (data && !guest_pv_has(vcpu, KVM_FEATURE_HC_PAGE_ENC_STATUS))
> 
> Why let the guest write '0'?  Letting the guest do WRMSR but not RDMSR is
> bizarre.
> 
> > +			return 1;
> > +		break;
> > +
> >  	case MSR_IA32_MCG_CTL:
> >  	case MSR_IA32_MCG_STATUS:
> >  	case MSR_IA32_MC0_CTL ... MSR_IA32_MCx_CTL(KVM_MAX_MCE_BANKS) - 1:
> > @@ -3549,6 +3557,12 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
> >  		if (!guest_pv_has(vcpu, KVM_FEATURE_ASYNC_PF))
> >  			return 1;
> >  
> > +		msr_info->data = 0;
> > +		break;
> > +	case MSR_KVM_MIGRATION_CONTROL:
> > +		if (!guest_pv_has(vcpu, KVM_FEATURE_HC_PAGE_ENC_STATUS))
> > +			return 1;
> > +
> >  		msr_info->data = 0;
> >  		break;
> >  	case MSR_KVM_STEAL_TIME:
> > -- 
> > 2.26.2
> > 

  reply	other threads:[~2021-04-20 18:11 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-20 11:20 [PATCH 0/3] KVM: x86: guest interface for SEV live migration Paolo Bonzini
2021-04-20 15:15 ` Sean Christopherson
2021-04-20 18:27   ` Paolo Bonzini
2021-04-20 17:31 ` Sean Christopherson
2021-04-20 18:11   ` Ashish Kalra [this message]
2021-04-20 18:40     ` Sean Christopherson
2021-04-20 18:58       ` Sean Christopherson
2021-04-20 18:39   ` Paolo Bonzini
2021-04-20 19:02     ` Sean Christopherson
2021-04-20 20:16       ` Sean Christopherson
2021-04-20 20:58         ` Paolo Bonzini
2021-04-20 22:49           ` Sean Christopherson
2021-04-20 23:20             ` Sean Christopherson
2021-04-21 12:03               ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210420181124.GA12798@ashkalra_ubuntu_server \
    --to=ashish.kalra@amd.com \
    --cc=bp@suse.de \
    --cc=brijesh.singh@amd.com \
    --cc=hpa@zytor.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=srutherford@google.com \
    --cc=tglx@linutronix.de \
    --cc=thomas.lendacky@amd.com \
    --cc=venu.busireddy@oracle.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).