Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp660855pxy; Fri, 30 Apr 2021 13:29:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9adCWzbwBQU1Bx9HNEvJbaKSo1mkTA2hNph9o6VmwlFVu4v4K+/wrewNl8x73oLUe3+RY X-Received: by 2002:a17:906:7842:: with SMTP id p2mr6585377ejm.87.1619814555055; Fri, 30 Apr 2021 13:29:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619814555; cv=none; d=google.com; s=arc-20160816; b=aBA124v6VZ4nvUjw1eNkGiYgRjIy+dtzWoTLveo9LpuEzkSKtngH6GPsPtqkTbm6Fh +MJxF0CuO3cgHL93rCtixzGc3nf541QjmtiT/z3RwcN7UPOZ7QOh3vvZ60cJbIBCCPhU zRdQ9/fxC4hVSXOBwGjKB5ofskvC+eYi/E3T1W26gxDDcXx6Icivju8Hz6x84OPCI2Ls fefQTc1DMyIkio8NCJWtP/DyIslcIYuez1jUE2+YrGiUkxhGddCfwphClxY44Aomnyxs Gk+BmVkJnetwBNkYj8vNcX7PEnEUk+BCcBoPZlCkyocC29StDPB4UqbK5rlImtv+ZmSz At4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=y5hqDeZNhe8SoddKxv/ncGGJkjFlgN/Vvr4BayVVCMY=; b=obE76fyZ4Lv4T3tZEL4WT/Moz/OD7smoWpjpKj/2qOymNEsJKzGEsFw78sL0wZ5VGG CPnUA2pKnbZwiog+Tw01mMMUfoHrhc05KaJSIlHHzjVoMs+dBbgAWJx32YmH1FYZMkB3 BraMXU7kBthq/GGkKQ3Gl87HZGY7XrFQQtS1YZ380wiRpRHeJJ58nDHKUx8tFp20wQ1h fT2B6ZxNWVSyDzDYo/6aY3+Z7O+GPfNzz/dBLkg2wVO4X2XWXv6iwGhaPE+AiesX+B+p FUli8fNFRL5zGx9oF1pJ5INnIRdQE9SW73fqoIjWVHI8Dn07Ajmw7T3kehzSXRxxLsfB uofw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=KuHqqWrj; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x16si2930040edd.387.2021.04.30.13.28.51; Fri, 30 Apr 2021 13:29:15 -0700 (PDT) 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=@google.com header.s=20161025 header.b=KuHqqWrj; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235557AbhD3ULy (ORCPT + 99 others); Fri, 30 Apr 2021 16:11:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235412AbhD3ULq (ORCPT ); Fri, 30 Apr 2021 16:11:46 -0400 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 482DAC06138D for ; Fri, 30 Apr 2021 13:10:58 -0700 (PDT) Received: by mail-pg1-x530.google.com with SMTP id q10so50146753pgj.2 for ; Fri, 30 Apr 2021 13:10:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=y5hqDeZNhe8SoddKxv/ncGGJkjFlgN/Vvr4BayVVCMY=; b=KuHqqWrjKa2m55Q/rYXy8NdBn6FOdROzDmCHjWsY9JynRSJG0cewtOzEeU0vh4SZfL 8MgNSxiia93hm5iqJxTYx2oNGp3J6RWfv+/uo9ghdK/gJz7saJ2p5VjEMiLdOYNr0rdD eGtgn36hh46T0c23mmszl4+hJ+mqknyV3t/KIvT4dWRXs8lc1+L9vqDIBIER0VvjHKZU LIcUVNXB4qqAlk+Rxh6US0RqrRnDFdBA2uVDoCBWwVTyGfC61FAyb13mtVILtNSjW/xb FXUBbwfiAGviWnMqFzBEOAxTdtkTDITPeKT4hh5ZwzhlTRo4vqvpa+OiyeLsntQTutge qsgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=y5hqDeZNhe8SoddKxv/ncGGJkjFlgN/Vvr4BayVVCMY=; b=gjwOZbf2aYfbCAZWf8I6nxV1yFaXMshp40NHYY/gG8yYmCnXXwCw78FnWToXZiiuNe Q6SWBnj8WHjRCiCpIaU/jGpdGu5NVGrmQvO3yVLl4fa7eBqiZ70jmBQDB8IC1sjlpHPQ zM5Hfh1FsfP7TCHvceIW7ANlTuz5xHXGyj+vQeMRiFtFUmZjf+A9gV9z2lyJf5jf9zDC 7ZASNDl5zhacGLJ9L4dcARlnB5BIWx+hgWiaLvxonMnRMAiLUE3FsnPsBrwcEVqjkQeH uD4ofqhoA8BAHGnv4J+37gspQq2/v7zTHnRmaflf0Ka50jEmRK/ZgWzQzMnSpMeg/XK4 ftaQ== X-Gm-Message-State: AOAM532kkPl2yz8Dqhj9PVgkLv+rYUFaXywYzSI8xGiyVbSCUMoEu1ya bAT/6GR2jVDxhpy1bdjXzEOBHw== X-Received: by 2002:a63:2143:: with SMTP id s3mr6326413pgm.429.1619813457493; Fri, 30 Apr 2021 13:10:57 -0700 (PDT) Received: from google.com (240.111.247.35.bc.googleusercontent.com. [35.247.111.240]) by smtp.gmail.com with ESMTPSA id i9sm2922341pji.41.2021.04.30.13.10.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Apr 2021 13:10:56 -0700 (PDT) Date: Fri, 30 Apr 2021 20:10:53 +0000 From: Sean Christopherson To: Paolo Bonzini Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, srutherford@google.com, joro@8bytes.org, brijesh.singh@amd.com, thomas.lendacky@amd.com, ashish.kalra@amd.com, Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Borislav Petkov , x86@kernel.org Subject: Re: [PATCH v3 2/2] KVM: X86: Introduce KVM_HC_PAGE_ENC_STATUS hypercall Message-ID: References: <20210429104707.203055-1-pbonzini@redhat.com> <20210429104707.203055-3-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210429104707.203055-3-pbonzini@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 29, 2021, Paolo Bonzini wrote: > diff --git a/Documentation/virt/kvm/msr.rst b/Documentation/virt/kvm/msr.rst > index 57fc4090031a..cf1b0b2099b0 100644 > --- a/Documentation/virt/kvm/msr.rst > +++ b/Documentation/virt/kvm/msr.rst > @@ -383,5 +383,10 @@ MSR_KVM_MIGRATION_CONTROL: > data: > This MSR is available if KVM_FEATURE_MIGRATION_CONTROL is present in > CPUID. Bit 0 represents whether live migration of the guest is allowed. > + > When a guest is started, bit 0 will be 1 if the guest has encrypted > - memory and 0 if the guest does not have encrypted memory. > + memory and 0 if the guest does not have encrypted memory. If the > + guest is communicating page encryption status to the host using the > + ``KVM_HC_PAGE_ENC_STATUS`` hypercall, it can set bit 0 in this MSR to > + allow live migration of the guest. The MSR is read-only if > + ``KVM_FEATURE_HC_PAGE_STATUS`` is not advertised to the guest. I still don't get the desire to tie MSR_KVM_MIGRATION_CONTROL to PAGE_ENC_STATUS in any way shape or form. I can understand making it read-only or dropping writes if it's not intercepted by userspace, but making it read-only for non-encrypted guests makes it useful only for encrypted guests, which defeats the purpose of genericizing the MSR. > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index e9c40be9235c..0c2524bbaa84 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -3279,6 +3279,12 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) > if (!guest_pv_has(vcpu, KVM_FEATURE_MIGRATION_CONTROL)) > return 1; > > + /* > + * This implementation is only good if userspace has *not* > + * enabled KVM_FEATURE_HC_PAGE_ENC_STATUS. If userspace > + * enables KVM_FEATURE_HC_PAGE_ENC_STATUS it must set up an > + * MSR filter in order to accept writes that change bit 0. > + */ > if (data != !static_call(kvm_x86_has_encrypted_memory)(vcpu->kvm)) > return 1; This behavior doesn't match the documentation. a. The MSR is not read-only for legacy guests since they can write '0'. b. The MSR is not read-only if KVM_FEATURE_HC_PAGE_STATUS isn't advertised, a guest with encrypted memory can write '1' regardless of whether userspace has enabled KVM_FEATURE_HC_PAGE_STATUS. c. The MSR is never fully writable, e.g. a guest with encrypted memory can set bit 0, but not clear it. This doesn't seem intentional? Why not simply drop writes? E.g. if (data & ~KVM_MIGRATION_READY) return 1; break; And then do "msr->data = 0;" in the read path. That's just as effective as making the MSR read-only to force userspace to intercept the MSR if it wants to do anything useful with the information, and it's easy to document. > break;