Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp168853rwe; Wed, 31 Aug 2022 18:59:35 -0700 (PDT) X-Google-Smtp-Source: AA6agR67DjCFTFPS0fQ093rbyshgmRXT+++iU5ollv937eSwVPB60gXclrgJDRfLL/EXcHZ1PzUQ X-Received: by 2002:a17:906:5a68:b0:73d:d354:f2c8 with SMTP id my40-20020a1709065a6800b0073dd354f2c8mr21971881ejc.509.1661997575104; Wed, 31 Aug 2022 18:59:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661997575; cv=none; d=google.com; s=arc-20160816; b=RJ3taUS+WcitmFlfPq9CkpQjOj8aG6vkKPUbBePV3n0rh0ptlnHTp1Fv6FlGE7dj4W qYI0z278xY5JgPqVDOJRlSFtsd+PVqDYOuGNTA7DVA3w002CAgQTmXY5R1zpqXNiwz6y IdNI2FZL5X/5UlDermsqczBtxl7i3g6t9pOcqRVFDrIBfgSUx1u7nBUGM4jVTd1JJbc+ zzfzCuzbUG7HZ5BLi6PO/oBG3+DgL2MaUn1JQasa1cH69YhzWW9Dvzr6niZm4CRwzQlq yHi3kYrAhROY0KUOgQi1Osjr+XHZIwep2uItke99XNZ1BjzX22Dvw2LQ8lm3OUGPSMKM Gsiw== 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=j6hcngYlpvs5vhfu0mW47DQwHIYzAccUtyEnKVrv4bk=; b=SsNmZ8h5VSlTfAzURPqz2BlZKB9BEFpBvs2lpq2hQmB3r3wrJ2X0YlWjNxs09ZlreT ZyHV3XMD+C8SiOZo7ScOvgYd3SEmUYvQx7KHqOdKG5nmFF9b75DdDAF0CTjiRGXgHPCy kZjqF1kfahfCzl/3JP0jVMbiJLEB4A5AiKRu84aaZ0x0biyOP4xFexjnVNPejf72atc6 8I6lvFAdHo9X4KQahdS61oAMUBPW8iBin3K+WvjUA3ZIxo3vAgRlQN5BvAC178AnJoxN 6Z52YtYSMbRigizGgfGXsur97JM7nqIlazoTHT7ayb1jSzr+HRFycM+Ako5go1Ouv/Hy Sg0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Ig9Jz4jF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lb5-20020a170907784500b0072b3b8d31f8si11737081ejc.63.2022.08.31.18.58.59; Wed, 31 Aug 2022 18:59:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Ig9Jz4jF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232467AbiIABUk (ORCPT + 99 others); Wed, 31 Aug 2022 21:20:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232329AbiIABUi (ORCPT ); Wed, 31 Aug 2022 21:20:38 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64C6181690; Wed, 31 Aug 2022 18:20:37 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id 76so16103646pfy.3; Wed, 31 Aug 2022 18:20:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc; bh=j6hcngYlpvs5vhfu0mW47DQwHIYzAccUtyEnKVrv4bk=; b=Ig9Jz4jFpQYi8elhuz6NJZGp+7tykwAd+nejNRkApGgSCIGRxS9VSxgP40TfiKEoXH jVEGavejFbJKhMGtTtw6DgNifjj4+qZMIN+G/LNuLMf1grvfxCFz1bTjy8ZV3vyowdSv fhR+7g4wulbwNCcPK6RUiqXS0MdUJ6QoA27l8UJMy+5Wi4rexR/yDBcz/IrUcBkrZlvq oP1iDMKbU4KCvvmfrcrqwQ7rAraaU48gkzG0opBzFQSdzWGSaAhTFyTY4yAam+v6dZ+o xpYxDlTtusVBFCqjMWkOAZDTgaQjYjsJVqxQjWUzfGnHhEtXc52amf6gQHHeISjvtulj 7GIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc; bh=j6hcngYlpvs5vhfu0mW47DQwHIYzAccUtyEnKVrv4bk=; b=o84xAQ4vEnEUQecRTIk9Zlt2avPO0QxbiYBqLXr+H3FcM9Wl8Vo+4beMLTd2irWFs2 O1zCNP/iwHUZapvfAgG1f7BwxBXp6kwpMQvG87MDH9752RYRRfrc0QAwGOfGKW/ECRRp P+raAAyQ4oRTicEOZ4nKyb/1E2I9FFdSx9RWPPyBrS1h36UyjORQ8+CMt58Kjushhezu 9RXOYaaNvG0bNTpZ/HkNuXyfdfn2Ux/VAR7vJv2P05YFmLwnIUhVGfF9KN509a6IUtiD m1DeInJBBV1mtH3nWIwOPbUWHthjgHLBG7ZjFvpuVYWaUO9hfoKnq28Ptn7HjZ0xeFSA AD4A== X-Gm-Message-State: ACgBeo2bbs3hs2SCNKyIsin3e6t3xxlkoX8gEjS8HG8h2LqCkMmF79Mf CrKvxG3GCgJebQDw1rwAqUE= X-Received: by 2002:a63:1043:0:b0:429:fd41:b7cb with SMTP id 3-20020a631043000000b00429fd41b7cbmr23574082pgq.442.1661995236799; Wed, 31 Aug 2022 18:20:36 -0700 (PDT) Received: from localhost ([192.55.55.51]) by smtp.gmail.com with ESMTPSA id y11-20020a17090322cb00b00172dd10f64fsm6473650plg.263.2022.08.31.18.20.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 18:20:36 -0700 (PDT) Date: Wed, 31 Aug 2022 18:20:34 -0700 From: Isaku Yamahata To: Sagi Shahar Cc: linux-kselftest@vger.kernel.org, Paolo Bonzini , Sean Christopherson , Isaku Yamahata , Erdem Aktas , Ryan Afranji , Roger Wang , Shuah Khan , Andrew Jones , Marc Zyngier , Ben Gardon , Jim Mattson , David Matlack , Peter Xu , Oliver Upton , Ricardo Koller , Yang Zhong , Wei Wang , Xiaoyao Li , Peter Gonda , Marc Orr , Emanuele Giuseppe Esposito , Christian Borntraeger , Eric Auger , Yanan Wang , Aaron Lewis , Vitaly Kuznetsov , Peter Shier , Axel Rasmussen , Zhenzhong Duan , "Maciej S . Szmigiero" , Like Xu , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, isaku.yamahata@gmail.com Subject: Re: [RFC PATCH v2 02/17] KVM: selftest: Add helper functions to create TDX VMs Message-ID: <20220901012034.GD2711697@ls.amr.corp.intel.com> References: <20220830222000.709028-1-sagis@google.com> <20220830222000.709028-3-sagis@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220830222000.709028-3-sagis@google.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 30, 2022 at 10:19:45PM +0000, Sagi Shahar wrote: > diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c > index f35626df1dea..2a6e28c769f2 100644 > --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c > +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c > @@ -8,6 +8,7 @@ > #include "test_util.h" > #include "kvm_util.h" > #include "processor.h" > +#include "tdx.h" > > #ifndef NUM_INTERRUPTS > #define NUM_INTERRUPTS 256 > @@ -641,6 +642,32 @@ struct kvm_vcpu *vm_arch_vcpu_add(struct kvm_vm *vm, uint32_t vcpu_id, > return vcpu; > } > > +/* > + * Adds a vCPU to a TD (Trusted Domain) with minimum defaults. It will not set > + * up any general purpose registers as they will be initialized by the TDX. In > + * TDX, vCPUs RIP is set to 0xFFFFFFF0. See Intel TDX EAS Section "Initial State > + * of Guest GPRs" for more information on vCPUs initial register values when > + * entering the TD first time. > + * > + * Input Args: > + * vm - Virtual Machine > + * vcpuid - The id of the VCPU to add to the VM. > + */ > +struct kvm_vcpu *vm_vcpu_add_tdx(struct kvm_vm *vm, uint32_t vcpu_id) > +{ > + struct kvm_mp_state mp_state; > + struct kvm_vcpu *vcpu; > + > + vcpu = __vm_vcpu_add(vm, vcpu_id); > + initialize_td_vcpu(vcpu); > + > + /* Setup the MP state */ > + mp_state.mp_state = 0; > + vcpu_mp_state_set(vcpu, &mp_state); > + > + return vcpu; > +} > + It's better to use symbolic value. I know this is copied from vmx version, though. diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c index 3bb7dc5a55ea..4009bc926e33 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -636,7 +636,7 @@ struct kvm_vcpu *vm_arch_vcpu_add(struct kvm_vm *vm, uint32_t vcpu_id, vcpu_regs_set(vcpu, ®s); /* Setup the MP state */ - mp_state.mp_state = 0; + mp_state.mp_state = KVM_MP_STATE_RUNNABLE; vcpu_mp_state_set(vcpu, &mp_state); return vcpu; @@ -662,7 +662,7 @@ struct kvm_vcpu *vm_vcpu_add_tdx(struct kvm_vm *vm, uint32_t vcpu_id) initialize_td_vcpu(vcpu); /* Setup the MP state */ - mp_state.mp_state = 0; + mp_state.mp_state = KVM_MP_STATE_RUNNABLE; vcpu_mp_state_set(vcpu, &mp_state); return vcpu; -- Isaku Yamahata