Received: by 2002:ab2:7407:0:b0:1f4:b336:87c4 with SMTP id e7csp236714lqn; Thu, 11 Apr 2024 22:35:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVduwpNhYJaX1S85xU1bjD81XZG/OAqFP7Txk9N9goeUFTHBgvmIq765ngNiB8xDi91sHhanC+A7G1/CAImNS1gczeBZ0JnyhkkIIP9Dg== X-Google-Smtp-Source: AGHT+IFBdkAaylt8HyRY3t1abu2FvWtUD7PdJemXZlkdFlaLm8X6vmofA26CwkQu7EWR7tZ9QLMO X-Received: by 2002:a17:902:cf10:b0:1e4:6938:6fe2 with SMTP id i16-20020a170902cf1000b001e469386fe2mr1970706plg.57.1712900109767; Thu, 11 Apr 2024 22:35:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712900109; cv=pass; d=google.com; s=arc-20160816; b=y9AB5pBC9vKElvgjQV0332FsLzW7VqMC8DYnxd5mxNGPtmgy0eo/8AD86WfPEvw/sM X++mgf7zLIZvced2+h/xqWgKkFHXQiG4tNFDfCo8XAoIxytODxTbmqCuOuH1m0lD/7FM 0QUQHYo5BeTKEzcsHbJho+xQEpsnolfJzMuKvsv71Pmvb1GayQlrw4Rph0VaFmg2cBSp I4PV+rr2ecfKqGDEqn3OHRWnJPea1xB1Y+FiL6niY5Zh7KW1YvmGhdmoPef11DmZK0K8 nhnEwu15vjF1jmaViro4dmRiXMUn6nY/qQ0MnPHEusShrBN+Ur/RoB0AML6Z0N0xRgB3 gjzw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:in-reply-to:date:dkim-signature; bh=40CL73wib6boENITVkOBpqP4qrDROFAeF098K7rCEZo=; fh=kLIoUZyeLwDrlsXnrh9D54cVborZRKlbGoLr2rBMO7w=; b=kHz/Fv9tZ3/OgeVHSlRmxSAeLmZ1HI+MWNzbnAmMBQ4jgnwaUFHUtTdU3GKtGv2Fp2 Y5T2/k+HM+BctLdGl+jgYRAbvpQgzl1pJK6NEv6rW25W6cMkQN0B5Cq+ZeRgU1VObkae W9TYO7nW47dLy58AkVs1XVWDtwviqv4Wbx88n1iI4z+HaKm9qnVGSGR/v82ETHX6iqt6 6qQlvy30kNHbEgZCuta0knQlCEj1Vro3M1KWujkUao5aLDKbfeTTpGsBokDCkBZa2o0V hORs/+49nm0AiugoLArtGK1RuJbQ/lcKV3yGwTd4my85O5x3M5394I3Hul8eWcssdMyb uNig==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Eq9dsrct; arc=pass (i=1 spf=pass spfdomain=flex--ackerleytng.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-141985-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141985-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id f10-20020a170902f38a00b001e4945829basi2465231ple.514.2024.04.11.22.35.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 22:35:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-141985-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Eq9dsrct; arc=pass (i=1 spf=pass spfdomain=flex--ackerleytng.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-141985-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141985-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 71DD7284D41 for ; Fri, 12 Apr 2024 05:35:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B0CE21BC4E; Fri, 12 Apr 2024 05:35:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Eq9dsrct" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B4E21B95B for ; Fri, 12 Apr 2024 05:34:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712900100; cv=none; b=ubhh98AFGAIku3mP2UZcJUhhBFdLawVMIMMJBh6apQecpdCLE19r3Vkwq4ytWiT3VmGTYkHwrmtvTsKd/VK8gxp5+oDvc59UNbIUAdkO39xnShs0A9HQdQ4jKDzNFnJMQQpZl//TZwCNeSOqqOHEfTZuGc/HWOi1NXtgY29gfNg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712900100; c=relaxed/simple; bh=mekwCTMyUIHf0Fvc6QFOxa55PFHUFQeuRMLlo60az0o=; h=Date:In-Reply-To:Mime-Version:Message-ID:Subject:From:To:Cc: Content-Type; b=EEUCyrtAB5JxLRZw8xlstX0auLXNLKgAdwzltvt1Z1NaZ9/WFbB7GB9uP5N/mYCQ6GpQlgi2RQca8numkXms8nt3To6Eo4Vo+6ovSqcSB8+0IBf+8t+5Cx4ZwcYQguXIX1yWDchoH2+YhN/7OGdnjKHp/TvettoydSaWH2kAf1Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ackerleytng.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Eq9dsrct; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ackerleytng.bounces.google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dd1395fd1bfso1047378276.0 for ; Thu, 11 Apr 2024 22:34:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712900099; x=1713504899; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:in-reply-to:date:from:to :cc:subject:date:message-id:reply-to; bh=40CL73wib6boENITVkOBpqP4qrDROFAeF098K7rCEZo=; b=Eq9dsrctp+oeiCMUetYY+mx5187uUTmAAILjPVRkuM/efzVXCL+moLjt3HW46gaFJF mIt1K4bqnJPZhfCkbxP3YGzx7H1oDfr24z4inSkNYaHBlT7OVEHLv6KSuC1iG1EP5SE9 b5ugjNlYD/Bl/gK9y1OUKfxr2rdXutn23ND5+yJbT5D8O1VlhzU2moboODm70h0NZKvi tAJvW+8Gc1saTFTD5qk2xFjCdsQQOkndgHKfMllBOjsfK8DYWOa8fSXpuHNLC1Rmitiy tF1Hfk3aMKdL2dYncCWa2wItjV4ueOypd5+kyXR0xi5ESg0Jdw04f2QST0Lm1iOQEhSc 2kgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712900099; x=1713504899; h=cc:to:from:subject:message-id:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=40CL73wib6boENITVkOBpqP4qrDROFAeF098K7rCEZo=; b=KfWasHxmX5BBYCy0D7eWJPx8BH+Te/snbQ5bn9WKj6tUThmqLZfNFjmFPGNMv7Hnoh xEHg1KVr2EKWSiCK1l13VUmar4IJQTNjx6csqua1I/PDKhnxwWvQ3e/OO9GdJME43Nxs acp33gt+l4ojTvcHeRtBuq+xekqefrExYyTsG92AMW3Evv6Iq2JjzLYiFWBx7w1NiM5E WBFMnmkL3dzHxR3sqrhrdRUg0UonLWQgnFEwZCPifePN1YFiClrsw+H1kk2VSIOZ6oMa IbS1J0pv8s8p/iniWkLQpA4n4c+PY5G18BIuktzA6fReDR0+z59MeoXeh2YdTH8sw4q2 3VZQ== X-Forwarded-Encrypted: i=1; AJvYcCXItxVFsHcHawOg3W2CWehYaGpnj654b7bEl92Vj0dL5D7eJkb5tF+L9Yjh1vdSS3hizQwCTAaLDNrcdnwLL0AQuXIu6++4rjs1sOhN X-Gm-Message-State: AOJu0YwilXVYpDS0qriO4EgVwxegCcYc5XpA9OXADwjv8Xc70d7/gzWM Ctq6nw9vaalwbPc+9RYVHutc9sIRArpuBYWarPzgwbbbknboyNHIvB1J9MGbe1Ta7fLp5RFym0F 9KGEViLbxT3QT5SXAkhnKUA== X-Received: from ctop-sg.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:1223]) (user=ackerleytng job=sendgmr) by 2002:a05:6902:1002:b0:dc6:e5d3:5f03 with SMTP id w2-20020a056902100200b00dc6e5d35f03mr510040ybt.4.1712900098616; Thu, 11 Apr 2024 22:34:58 -0700 (PDT) Date: Fri, 12 Apr 2024 05:34:54 +0000 In-Reply-To: <3d69b44a-8542-4a11-b233-16487e980d54@intel.com> (dongsheng.x.zhang@intel.com) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Message-ID: Subject: Re: [RFC PATCH v5 05/29] KVM: selftests: Add helper functions to create TDX VMs From: Ackerley Tng To: dongsheng.x.zhang@intel.com Cc: sagis@google.com, linux-kselftest@vger.kernel.org, afranji@google.com, erdemaktas@google.com, isaku.yamahata@intel.com, seanjc@google.com, pbonzini@redhat.com, shuah@kernel.org, pgonda@google.com, haibo1.xu@intel.com, chao.p.peng@linux.intel.com, vannapurve@google.com, runanwang@google.com, vipinsh@google.com, jmattson@google.com, dmatlack@google.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" Thank you for your other comments! >> >> +static void load_td_per_vcpu_parameters(struct td_boot_parameters *params, >> + struct kvm_sregs *sregs, >> + struct kvm_vcpu *vcpu, >> + void *guest_code) >> +{ >> + /* Store vcpu_index to match what the TDX module would store internally */ >> + static uint32_t vcpu_index; >> + >> + struct td_per_vcpu_parameters *vcpu_params = ¶ms->per_vcpu[vcpu_index]; > > I think we can use vcpu->id in place of vcpu_index in this function, thus removing vcpu_index > td_per_vcpu_parameters is used in the selftest setup code (see tools/testing/selftests/kvm/lib/x86_64/tdx/td_boot.S), (read via ESI) to access the set of parameters belonging to the vcpu running the selftest code, based on vcpu_index. ESI is used because according to the TDX base spec, RSI contains the vcpu index, which starts "from 0 and allocated sequentially on each successful TDH.VP.INIT". Hence, vcpu_index is set up to be static and is incremented once every time load_td_per_vcpu_parameters() is called, which is once every time td_vcpu_add() is called, which is aligned with the TDX base spec. vcpu->id can be specified by the user when vm_vcpu_add() is called, but that may not be the same as vcpu_index. >> + >> + TEST_ASSERT(vcpu->initial_stack_addr != 0, >> + "initial stack address should not be 0"); >> + TEST_ASSERT(vcpu->initial_stack_addr <= 0xffffffff, >> + "initial stack address must fit in 32 bits"); >> + TEST_ASSERT((uint64_t)guest_code <= 0xffffffff, >> + "guest_code must fit in 32 bits"); >> + TEST_ASSERT(sregs->cs.selector != 0, "cs.selector should not be 0"); >> + >> + vcpu_params->esp_gva = (uint32_t)(uint64_t)vcpu->initial_stack_addr; >> + vcpu_params->ljmp_target.eip_gva = (uint32_t)(uint64_t)guest_code; >> + vcpu_params->ljmp_target.code64_sel = sregs->cs.selector; >> + >> + vcpu_index++; >> +} >>