From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF2CBC25B74 for ; Thu, 16 May 2024 17:23:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D1E746B007B; Thu, 16 May 2024 13:23:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CF5086B0082; Thu, 16 May 2024 13:23:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BBCF86B0083; Thu, 16 May 2024 13:23:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 95BEE6B007B for ; Thu, 16 May 2024 13:23:54 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 4FD93A1A69 for ; Thu, 16 May 2024 17:23:54 +0000 (UTC) X-FDA: 82124931588.21.1FD612A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf29.hostedemail.com (Postfix) with ESMTP id 473A4120007 for ; Thu, 16 May 2024 17:23:51 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NKhWMF4n; spf=pass (imf29.hostedemail.com: domain of pbonzini@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=pbonzini@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715880231; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=19E7GPCN1ivTDhWTuCbZE7KnAa8A5iElKF7+ifU05tY=; b=P44A/GJegfcKW/x6hnzLO9OXeQcs43A9kTOLLOfl/MQOtis1S5IAlFaqm1+jS+M8z7+wX6 COFD46v+2N6wX54iLKmLCcqf3ShFpC67Bg9z6d8Tw0yNQkQDyzc8xFe/E64rUyBBxKv3n+ gSJv6bXsjhiSEqaJKSKZhkB2cU0xCxo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715880231; a=rsa-sha256; cv=none; b=WblBhbwckxCFHhmkdkzXaGUxTkhk5GHXz4Jx5moj3FhCfQ+fd5QI8daUvdd3NOl2BJXZG0 XGkd6MRwnMM1H50YPmNR192Vd+vb5NodfXisI68D2cALOw2U7l/kEKLl69tepA3BeN/5Jz DzgMzftJCNiKtSLpjSvN1mjN8k6z8cs= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NKhWMF4n; spf=pass (imf29.hostedemail.com: domain of pbonzini@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=pbonzini@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715880230; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=19E7GPCN1ivTDhWTuCbZE7KnAa8A5iElKF7+ifU05tY=; b=NKhWMF4nw42o4kzrADMRjLnJH6EC4oZTBjhB4awxUyZGALktlflffhzdjNevuQbiw2sKy9 Th28oT7K2H6cwo06OELFOL9ZQiUtFkmBMg75Pv1RE1rQ4FJziAKPC49TIOZiJddVlndItz OgSfFHDjzk2XuoaBm0Yi/VX0WYYxuOU= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-557-cjhZ--P1N8Wa3QoHUGxTgA-1; Thu, 16 May 2024 13:23:49 -0400 X-MC-Unique: cjhZ--P1N8Wa3QoHUGxTgA-1 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-351baf27b00so3051310f8f.0 for ; Thu, 16 May 2024 10:23:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715880228; x=1716485028; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=19E7GPCN1ivTDhWTuCbZE7KnAa8A5iElKF7+ifU05tY=; b=ItDzGO/bbrKyJMeADHqhg5K1xmA7+WIn9nnavrtIbb3LDnxmAbLy0LLuI/vplV8gZb 3COlqyVtGF1r1r02L4ySN17MX5qyPRxTSvQxIuVLauYX3IsdHTN8fCtvXGlYUmDyuI8o UlqkXINQf3/UMyjzlrqUtd5+tGCiqELbRfinvrf/eH9hHn19EQfDehyYOt2xchV5jhIc bLPvzYjzj+nMwv3SQGGHwjCz4O0nE5VOWgJaoX0wk8cXF/kOd8nYd+GR9e+LAKOtJsYR jIJks5LtCz23/wpl+dJvXWiaobWT6jjnmoc/JIaaJsOOaVVqziquVGWbExo5s7Yf30Pr tgbg== X-Forwarded-Encrypted: i=1; AJvYcCWI+YeU1NtBF2WET+dT36NA+CVwQuCXIcc/vdIH/pwr67jvne5ZYYkwv6UfKfvnqykJjmh66B0oViDuthtTiotxlT4= X-Gm-Message-State: AOJu0Yx8AEUraw3fOFbp9mcyuL/Q1yFkJV7ywz8J+HeIDcYJwuxU9IsR tqefJn5WGaS6XKJY8xlzQC7jp88WYHB/gO0BslGlBQbKv5Na6cTq58IT8yBGxcat2w1dFbepWEz 92dV7DCZWzCbDoK0xGQ8BAg1MI3x3sEpr4+9MZReJyify2mykM/JeqAtFz63J0xmLXeahbDGeKY QPla+4BtmvWqTZh7t1qF8EI4c= X-Received: by 2002:adf:ff92:0:b0:34c:9b4d:a7ee with SMTP id ffacd0b85a97d-3504aa66822mr15744061f8f.67.1715880228133; Thu, 16 May 2024 10:23:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHTVOF6tCwOyYT/m1XvAI/L4WEGf+ijDm6MmFZ5m37aa8PPPlxqPrapghhXVBONg9RhqurSX3MAN+Jlfejb4GQ= X-Received: by 2002:adf:ff92:0:b0:34c:9b4d:a7ee with SMTP id ffacd0b85a97d-3504aa66822mr15744026f8f.67.1715880227699; Thu, 16 May 2024 10:23:47 -0700 (PDT) MIME-Version: 1.0 References: <20240501085210.2213060-1-michael.roth@amd.com> <20240501085210.2213060-10-michael.roth@amd.com> <84e8460d-f8e7-46d7-a274-90ea7aec2203@linux.intel.com> In-Reply-To: <84e8460d-f8e7-46d7-a274-90ea7aec2203@linux.intel.com> From: Paolo Bonzini Date: Thu, 16 May 2024 19:23:35 +0200 Message-ID: Subject: Re: [PATCH v15 09/20] KVM: SEV: Add support to handle MSR based Page State Change VMGEXIT To: Binbin Wu Cc: Michael Roth , kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-mm@kvack.org, linux-crypto@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, tglx@linutronix.de, mingo@redhat.com, jroedel@suse.de, thomas.lendacky@amd.com, hpa@zytor.com, ardb@kernel.org, seanjc@google.com, vkuznets@redhat.com, jmattson@google.com, luto@kernel.org, dave.hansen@linux.intel.com, slp@redhat.com, pgonda@google.com, peterz@infradead.org, srinivas.pandruvada@linux.intel.com, rientjes@google.com, dovmurik@linux.ibm.com, tobin@ibm.com, bp@alien8.de, vbabka@suse.cz, kirill@shutemov.name, ak@linux.intel.com, tony.luck@intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, alpergun@google.com, jarkko@kernel.org, ashish.kalra@amd.com, nikunj.dadhania@amd.com, pankaj.gupta@amd.com, liam.merwick@oracle.com, Brijesh Singh , "Yamahata, Isaku" X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Stat-Signature: 8b19kseiiako4hi9qkz9m4au8ktqgore X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 473A4120007 X-HE-Tag: 1715880231-196712 X-HE-Meta: U2FsdGVkX182SSB3cXXkCtKdJIQC6eg4AJ5lcyUcDieVfmVoX3I9dT6ZqTj52ALhxRGMqimATCBnJY4vuNsnJDQIzoiAE2RFAUdZwAvpab5dwnQWbNN8Y9HbvDYNWZvEnwiUp39PVcwPER2a8GpG29ViBY/SfjyGjf+AjpD5oV0oWOzkOkkGJwgmZ1vYodSvISnA0FuhmCR+hN5rx/BLds1tG7SE23TKRqZGIaxdojaK9LonIW0z4aZh2eMVp2RwgDIZEa0osPHMtrl9mwgjUyWHypFhh2yiJp5roBd7FIjisnzbmoSss/Psgxi1rt6is385XAtbZEEtci21UkaVH0xb0aNXAnA9E0jaOa3QHBuRQQc+pvuXBstklorSk82dgYeZyRIPWX5L135i9oqGX4+IOQQ6P3r7AGj/mkooqVLZHyo6FKQ+TJBlwmctOs7pX5oRbScUueZcFxNDAMOk06A1cNZdw4QxYhCVyN0jDegEV5fOrgH0xi4jsMHyQuNCoWC7AVdc2NKg7hUVuhcghIq392m5a6+cHTQW8BnFfyKPHVR7hAu20puZh3jX5eyX3g52rQnSIh/8TJ3UMru8njr69WtS6qC5kL/4K/M6rP2rxrVsmhMG1iT2DSJ9YJ2AOsO9nqOVLTQX9zCxoL2Tti6Yjv+0yQ4Xpw0RY2FfdTbx2EzsTqEJDg+rIrYPifNIuZ7Z5eUsFguEO6lda+87HwIHF7TPPbVKr+nh7kjjh12tIh+cyipyGB0u5Y5gLqRpB53RBdtN8GFSrmw6pz/6L6k8nzpC1tUH9WlC1zTye1KwXcSDmGWQ5djC78skc9U3sc47JlBAo8oq+TkW8fEp0XLYbJPUtsWaoa52PbaP/2DQ5/0iwpIHd152KMGb9ljKMfIJ8+Z4tx28vAPjJgXju7Wu8C0YeMMoiK9uWzbrpxM6mrlCkHWGD03WNT+j3oBopQK6h1ibd+mrG26POCf xMwW6N/1 avN5IUduBkWRQXhbwgI22PxDAp38sv1EdN9WmAbLbTxUAsZ8HdGY+PFut5mnOKHFKKjOiYhW+mRnKyKCwi0q7BByftWE34CU9If0hS0psr8vjPohynDvIaVOt8HU9tMoRGF7jYWzyYvRrDmIosHHyTRgiFtyw20bzvD2Nd+nrNJh6lukn1ScPZq0arAJD9LpztN00X/BK2U3Xd/s3w0hIUyFTIcRFWegE4SfjKyD9qwMuZM45SWeg/gNyw3MpPh1H80EkMKNxTG9EfIK2cSEzLDJLnAkEFbf7Rz5xb2E232NXvPdEamvCyHhvkd3KNOpQEJJfaSnJXuYJeogd0/9yZsMoO/09WwHhHUWB6eLSHFP/IMs8G/U/qOaUuyjISQfg/DiKv+5xl1nxq4k= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Thu, May 16, 2024 at 10:29=E2=80=AFAM Binbin Wu wrote: > > > > On 5/1/2024 4:51 PM, Michael Roth wrote: > > SEV-SNP VMs can ask the hypervisor to change the page state in the RMP > > table to be private or shared using the Page State Change MSR protocol > > as defined in the GHCB specification. > > > > When using gmem, private/shared memory is allocated through separate > > pools, and KVM relies on userspace issuing a KVM_SET_MEMORY_ATTRIBUTES > > KVM ioctl to tell the KVM MMU whether or not a particular GFN should be > > backed by private memory or not. > > > > Forward these page state change requests to userspace so that it can > > issue the expected KVM ioctls. The KVM MMU will handle updating the RMP > > entries when it is ready to map a private page into a guest. > > > > Use the existing KVM_HC_MAP_GPA_RANGE hypercall format to deliver these > > requests to userspace via KVM_EXIT_HYPERCALL. > > > > Signed-off-by: Michael Roth > > Co-developed-by: Brijesh Singh > > Signed-off-by: Brijesh Singh > > Signed-off-by: Ashish Kalra > > --- > > arch/x86/include/asm/sev-common.h | 6 ++++ > > arch/x86/kvm/svm/sev.c | 48 ++++++++++++++++++++++++++++++= + > > 2 files changed, 54 insertions(+) > > > > diff --git a/arch/x86/include/asm/sev-common.h b/arch/x86/include/asm/s= ev-common.h > > index 1006bfffe07a..6d68db812de1 100644 > > --- a/arch/x86/include/asm/sev-common.h > > +++ b/arch/x86/include/asm/sev-common.h > > @@ -101,11 +101,17 @@ enum psc_op { > > /* GHCBData[11:0] */ \ > > GHCB_MSR_PSC_REQ) > > > > +#define GHCB_MSR_PSC_REQ_TO_GFN(msr) (((msr) & GENMASK_ULL(51, 12)) >>= 12) > > +#define GHCB_MSR_PSC_REQ_TO_OP(msr) (((msr) & GENMASK_ULL(55, 52)) >> = 52) > > + > > #define GHCB_MSR_PSC_RESP 0x015 > > #define GHCB_MSR_PSC_RESP_VAL(val) \ > > /* GHCBData[63:32] */ \ > > (((u64)(val) & GENMASK_ULL(63, 32)) >> 32) > > > > +/* Set highest bit as a generic error response */ > > +#define GHCB_MSR_PSC_RESP_ERROR (BIT_ULL(63) | GHCB_MSR_PSC_RESP) > > + > > /* GHCB Hypervisor Feature Request/Response */ > > #define GHCB_MSR_HV_FT_REQ 0x080 > > #define GHCB_MSR_HV_FT_RESP 0x081 > > diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c > > index e1ac5af4cb74..720775c9d0b8 100644 > > --- a/arch/x86/kvm/svm/sev.c > > +++ b/arch/x86/kvm/svm/sev.c > > @@ -3461,6 +3461,48 @@ static void set_ghcb_msr(struct vcpu_svm *svm, u= 64 value) > > svm->vmcb->control.ghcb_gpa =3D value; > > } > > > > +static int snp_complete_psc_msr(struct kvm_vcpu *vcpu) > > +{ > > + struct vcpu_svm *svm =3D to_svm(vcpu); > > + > > + if (vcpu->run->hypercall.ret) > > Do we have definition of ret? I didn't find clear documentation about it. > According to the code, 0 means succssful. Is there any other error codes > need to or can be interpreted? They are defined in include/uapi/linux/kvm_para.h #define KVM_ENOSYS 1000 #define KVM_EFAULT EFAULT /* 14 */ #define KVM_EINVAL EINVAL /* 22 */ #define KVM_E2BIG E2BIG /* 7 */ #define KVM_EPERM EPERM /* 1*/ #define KVM_EOPNOTSUPP 95 Linux however does not expect the hypercall to fail for SEV/SEV-ES; and it will terminate the guest if the PSC operation fails for SEV-SNP. So it's best for userspace if the hypercall always succeeds. :) > For TDX, it may also want to use KVM_HC_MAP_GPA_RANGE hypercall to > userspace via KVM_EXIT_HYPERCALL. Yes, definitely. Paolo