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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A911C43334 for ; Mon, 18 Jul 2022 22:37:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235268AbiGRWhu (ORCPT ); Mon, 18 Jul 2022 18:37:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230369AbiGRWht (ORCPT ); Mon, 18 Jul 2022 18:37:49 -0400 Received: from mail-yb1-xb34.google.com (mail-yb1-xb34.google.com [IPv6:2607:f8b0:4864:20::b34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A4D924F1F for ; Mon, 18 Jul 2022 15:37:48 -0700 (PDT) Received: by mail-yb1-xb34.google.com with SMTP id 7so5941632ybw.0 for ; Mon, 18 Jul 2022 15:37:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=1BNdWsaF3uahy5xNZXMoCLMmRQWlXmWwGVzk7t0GH80=; b=joRzGhYq+1nJo3rrtfk3XF7T69GtjNsF0UwsJyiQQMCjUQofTOPho/uMz2rroFejVa xbOSrEbrXEhg728DZ/iz0B0lI80WGdZO0VVivd+aYCllfIGdf/FY3zcxn9lxZb2apsup 7tdZD/eJEa5i7cKRhq4iSpBit4SFWuLcX+MOji/pb1rgk1ecGxlH6q1QiAE4D9Ik+sU6 EnZvJ1nm73KqCXEz+JNVwFyLJYbyTtR8b0NucNkY1TXXHWJGqqkQOkGYBdePxpzH6+6X eVY5tgoVGslnyQxoabJfzRYpxlBcMglFyNKoX0g0Mzg5k+47JIUqUIYvI/9wjuY7He8H /16Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=1BNdWsaF3uahy5xNZXMoCLMmRQWlXmWwGVzk7t0GH80=; b=Axb30dyJQcbKvlGMiFIz/ayWj5uBcXNFUJX/VFboQn654byOHI7SrMXq1ExxJ057Rn AfCPoutlslVOYLuGgnDrYQdQbxlC/rxJaRxr9ue4krSoBbQ0J3H/QSReYtI3avJMikHZ cjJL3oBaXX5mjyaLqHFCJ0FL7COgCA67UUbn+EuEJfhZ/c5zi/ZoEBFF92T8u7f+Gt+Y eZTQJEiKsF2Vpa/fB45tCMoUyfFGNdkqSpnI+Je6n3PVRwZIH1fC4fvvRwb2pF/rBvQ1 h9ZifNF6qflQ47tQSuZrmUrYuKCa4bFSAfEMK/1JpMJoOd7zsC87gbGynQCa5Iy07MkT JWHg== X-Gm-Message-State: AJIora/STziprcckTNWiFaCQpPdPXexKI5EjzIu/imKuEEdm2/A7nyxl OWXH7XghbFFh11kNT3OeVPwo8y4c2TFV61PgpTcCRA== X-Google-Smtp-Source: AGRyM1sYwn5En0zgTpktu7I/Hg6nJ8yQa4ZMwZHQNIF/QCoG6aD+McW8mOoEyev33/Zzw4fsuJSlsMK4QvpJiV9of5w= X-Received: by 2002:a5b:3ce:0:b0:66f:4692:27a2 with SMTP id t14-20020a5b03ce000000b0066f469227a2mr29642799ybp.167.1658183867383; Mon, 18 Jul 2022 15:37:47 -0700 (PDT) MIME-Version: 1.0 References: <98939c0ec83a109c8f49045e82096d6cdd5dafa3.1651774251.git.isaku.yamahata@intel.com> <20220629101356.GA882746@ls.amr.corp.intel.com> In-Reply-To: <20220629101356.GA882746@ls.amr.corp.intel.com> From: Sagi Shahar Date: Mon, 18 Jul 2022 15:37:35 -0700 Message-ID: Subject: Re: [RFC PATCH v6 090/104] KVM: TDX: Handle TDX PV CPUID hypercall To: Isaku Yamahata Cc: "Yamahata, Isaku" , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Paolo Bonzini , Erdem Aktas , Sean Christopherson Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 29, 2022 at 3:14 AM Isaku Yamahata wrote: > > On Tue, Jun 14, 2022 at 11:15:00AM -0700, > Sagi Shahar wrote: > > > On Thu, May 5, 2022 at 11:16 AM wrote: > > > > > > From: Isaku Yamahata > > > > > > Wire up TDX PV CPUID hypercall to the KVM backend function. > > > > > > Signed-off-by: Isaku Yamahata > > > --- > > > arch/x86/kvm/vmx/tdx.c | 22 ++++++++++++++++++++++ > > > 1 file changed, 22 insertions(+) > > > > > > diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c > > > index 9c712f661a7c..c7cdfee397ec 100644 > > > --- a/arch/x86/kvm/vmx/tdx.c > > > +++ b/arch/x86/kvm/vmx/tdx.c > > > @@ -946,12 +946,34 @@ static int tdx_emulate_vmcall(struct kvm_vcpu *vcpu) > > > return 1; > > > } > > > > > > +static int tdx_emulate_cpuid(struct kvm_vcpu *vcpu) > > > +{ > > > + u32 eax, ebx, ecx, edx; > > > + > > > + /* EAX and ECX for cpuid is stored in R12 and R13. */ > > > + eax = tdvmcall_a0_read(vcpu); > > > + ecx = tdvmcall_a1_read(vcpu); > > > + > > > + kvm_cpuid(vcpu, &eax, &ebx, &ecx, &edx, true); > > > > According to the GHCI spec section 3.6 > > (TDG.VP.VMCALL) we should return > > VMCALL_INVALID_OPERAND if an invalid CPUID is requested. > > > > kvm_cpuid already returns false in this case so we should use that > > return value to set the tdvmcall return code in case of invalid leaf. > > Based on CPUID instruction, cpuid results in #UD when lock prefix is used or > earlier CPU that doesn't support cpuid instruction. > So I'm not sure what CPUID input result in INVALID_OPERAND error. > Does the following make sense for you? > > --- a/arch/x86/kvm/vmx/tdx.c > +++ b/arch/x86/kvm/vmx/tdx.c > @@ -1347,7 +1347,7 @@ static int tdx_emulate_cpuid(struct kvm_vcpu *vcpu) > eax = tdvmcall_a0_read(vcpu); > ecx = tdvmcall_a1_read(vcpu); > > - kvm_cpuid(vcpu, &eax, &ebx, &ecx, &edx, true); > + kvm_cpuid(vcpu, &eax, &ebx, &ecx, &edx, false); > > tdvmcall_a0_write(vcpu, eax); > tdvmcall_a1_write(vcpu, ebx); > > thanks, If any CPUID request is considered valid, then perhaps the spec itself needs to be updated. Right now it clearly states that TDG.VP.VMCALL_INVALID_OPERAND is returned if "Invalid CPUID requested" which I understood as a non-existing leaf. But if you say that a non-existing leaf is still a valid CPUID request than I'm not sure what "Invalid CPUID requested" means in the spec itself. > > -- > Isaku Yamahata