Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp234398rwb; Tue, 25 Jul 2023 15:04:39 -0700 (PDT) X-Google-Smtp-Source: APBJJlE+gM9F7VxNWPjez/8MoofcWtAVoDHZn4XNE7r5pR71NGAON539rz69ZR8CEODnFBeQOflp X-Received: by 2002:a05:6a00:a06:b0:64c:4f2f:a235 with SMTP id p6-20020a056a000a0600b0064c4f2fa235mr602355pfh.30.1690322679288; Tue, 25 Jul 2023 15:04:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690322679; cv=none; d=google.com; s=arc-20160816; b=khBLPazJC8avSw9SdxkfdlJm7xUeX2HozGGRVyykuqGahWr7jHJfr8Zzsklln4HTvJ JGjrxXGT/nbjvBCNGeHUNKlMK+Dkyk68AGYXSRBSb+hDk1Zdbqn3dV3U8ppYerfZuF2K Ya8taunk+yUfuA2BoX0n+jsvvIMIydxsgG3BhIbQ5drBJ1yE3fE1dXrWm5s28C5nzqH0 1fq2yHbQiLUW/FYYfVik5/6nWyeE6gmB5x5YKAeG6bYK7tw2xFy44eVJGxq0XlHgHQEK Ic+OLEiZqn2xQ7G6v+NJdCJT66n4z1J5ThkOOnp2V3ykVUfoL7O9KA4UQtsV6mzqppxE zA2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=2LFI4LFbO9Za9GYdKLk7QvU7CpMUS45By27lNDC3GjA=; fh=1/sgOwi5AuU8IZymeFKs1Rjnf4QELnrK+C7GntqU2hA=; b=WXo6Zrm/3iz0hc/IRviuEgCpf9xcx5sgNLyg+1a+AtFmbahHYvBe7Vw/qfjPwOXVwP 5mkxNmyKXvBQZB0uPFMpB6EBGuXOiFj0oO8R6Y34A4pHGBdU31XvR4FVi8l8lAVlhHQ5 H9PV6VQY2zD+SS//4nn+htVV/HXNodBeQbbac3j/yoAkgGTvF/rLG0VVUY/dv7qOr7h4 WqkOcORMlEGH1eAvzDZOnNXUXGlEtJjaMoWuioOK96NO+0eDBiw4Jw/V1d5HSlVoeSQg B+fE/P52qQJjLMqHV+eBTqxIYxK6n/PF2g0VNTLSLeMlf97laEGMtuNhI7nNmkTehOCV VPiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=uciYcUsc; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id eg10-20020a056a00800a00b006796dca10d3si11726030pfb.100.2023.07.25.15.04.25; Tue, 25 Jul 2023 15:04:39 -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=@google.com header.s=20221208 header.b=uciYcUsc; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231852AbjGYWCv (ORCPT + 99 others); Tue, 25 Jul 2023 18:02:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231697AbjGYWC3 (ORCPT ); Tue, 25 Jul 2023 18:02:29 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B357426AE for ; Tue, 25 Jul 2023 15:01:59 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id 41be03b00d2f7-56336f5dc6cso2586600a12.0 for ; Tue, 25 Jul 2023 15:01:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690322512; x=1690927312; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=2LFI4LFbO9Za9GYdKLk7QvU7CpMUS45By27lNDC3GjA=; b=uciYcUscCG6H+67Jcmkbc5V2n9+VZ93bLtIW814gvYmube9sijgHq2d2+fhAFg6N1t Dw4e/msB58FhRlaEDW6If1180OsASchae1hL8RG8Jlem0+vo7hC/bEDYlzLHbT5J7xru CI3Y9RFVPoG/mQEzEtMXSmWvBfZBr9P5M/FCdiUrv9f7yKBdMi1yE2lbKEebb/8QZrY3 Sd/n6X4t+tTakMnoxsxynC3E0aJNnw2nV7YVVD5gYjxSjF/Cxreuub5mjDYW8pyYp/4t lw849iyeLf7Y7QA9iS63UcnFz3R7IDBAOt0z3hD2XdzVMNzbYny5txH8dWGWJQ7IIJKN rWBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690322512; x=1690927312; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2LFI4LFbO9Za9GYdKLk7QvU7CpMUS45By27lNDC3GjA=; b=FCJmrvWt7Ra9dETK2k9D1fZrO2sbK4Xx54qoKU+/wabfTNnX8VLvjOyqNyNLFg97Ta hfb3/UDgaf+fvSUAuy6MhN/c0tYlMLJNQUBm74rT/EIz47qIcAxvx/5djWkWyjjU8xuC JLn8Q1mi0i5vA6M4NB8JxN8XqMN58k8bnZbUu7vYEXsl6OoyIh+zBuXEAckBx8hf2HvU GGWBoza5iDjDDOuBPi9xDE2q3UH3ZnE+KsTRDwgIPbSa6NY7i5ZnBElMhryg30isRGgt i51JZIoenel7BLBOrDo8tAIsLuLRiKbJMFdwlupbR2VR2Om6RZySZwJW43BE0ov+jiO/ G6aA== X-Gm-Message-State: ABy/qLZaTx3HAdout/3HettMibITIHi328vY24E0X0zXxGFF4dkyCft8 q7vi2edMjfx+1d6If8oCBhdGKioqrx5s X-Received: from afranji.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:47f1]) (user=afranji job=sendgmr) by 2002:a63:3e82:0:b0:563:9e04:52b with SMTP id l124-20020a633e82000000b005639e04052bmr2658pga.6.1690322512106; Tue, 25 Jul 2023 15:01:52 -0700 (PDT) Date: Tue, 25 Jul 2023 22:00:56 +0000 In-Reply-To: <20230725220132.2310657-1-afranji@google.com> Mime-Version: 1.0 References: <20230725220132.2310657-1-afranji@google.com> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog Message-ID: <20230725220132.2310657-4-afranji@google.com> Subject: [PATCH v4 03/28] KVM: selftests: Store initial stack address in struct kvm_vcpu From: Ryan Afranji To: linux-kselftest@vger.kernel.org Cc: pbonzini@redhat.com, seanjc@google.com, isaku.yamahata@intel.com, sagis@google.com, erdemaktas@google.com, afranji@google.com, runanwang@google.com, shuah@kernel.org, drjones@redhat.com, maz@kernel.org, bgardon@google.com, jmattson@google.com, dmatlack@google.com, peterx@redhat.com, oupton@google.com, ricarkol@google.com, yang.zhong@intel.com, wei.w.wang@intel.com, xiaoyao.li@intel.com, pgonda@google.com, eesposit@redhat.com, borntraeger@de.ibm.com, eric.auger@redhat.com, wangyanan55@huawei.com, aaronlewis@google.com, vkuznets@redhat.com, pshier@google.com, axelrasmussen@google.com, zhenzhong.duan@intel.com, maciej.szmigiero@oracle.com, like.xu@linux.intel.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, ackerleytng@google.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED, USER_IN_DEF_DKIM_WL 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 From: Ackerley Tng TDX guests' registers cannot be initialized directly using vcpu_regs_set(), hence the stack pointer needs to be initialized by the guest itself, running boot code beginning at the reset vector. We store the stack address as part of struct kvm_vcpu so that it can be accessible later to be passed to the boot code for rsp initialization. Signed-off-by: Ackerley Tng Change-Id: I54e7bde72c5c21e7d8944415ac5818d9443e2b70 Signed-off-by: Ryan Afranji --- tools/testing/selftests/kvm/include/kvm_util_base.h | 1 + tools/testing/selftests/kvm/lib/x86_64/processor.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h index a07ce5f5244a..12524d94a4eb 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -67,6 +67,7 @@ struct kvm_vcpu { int fd; struct kvm_vm *vm; struct kvm_run *run; + vm_vaddr_t initial_stack_addr; #ifdef __x86_64__ struct kvm_cpuid2 *cpuid; #endif diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c index e3a9366d4f80..78dd918b9a92 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -607,10 +607,12 @@ struct kvm_vcpu *vm_arch_vcpu_add(struct kvm_vm *vm, uint32_t vcpu_id, vcpu_init_cpuid(vcpu, kvm_get_supported_cpuid()); vcpu_setup(vm, vcpu); + vcpu->initial_stack_addr = stack_vaddr; + /* Setup guest general purpose registers */ vcpu_regs_get(vcpu, ®s); regs.rflags = regs.rflags | 0x2; - regs.rsp = stack_vaddr; + regs.rsp = vcpu->initial_stack_addr; regs.rip = (unsigned long) guest_code; vcpu_regs_set(vcpu, ®s); -- 2.41.0.487.g6d72f3e995-goog