Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4910841rdb; Tue, 12 Dec 2023 12:52:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IEnvlAYGE43psuj4ZYjJKA6T4RJDrYT03MzYyzEbt2qaMOi3fD3RGhZNRTOiMjFIBWxlUvn X-Received: by 2002:a05:6e02:12eb:b0:35d:591f:861 with SMTP id l11-20020a056e0212eb00b0035d591f0861mr10951009iln.8.1702414320628; Tue, 12 Dec 2023 12:52:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702414320; cv=none; d=google.com; s=arc-20160816; b=kATWRjgauZi0+lbtHbwx5lDEohSC07E6YurMdDi8pjmgLVJ8ULvhXqW94N739uUlcG y+fswpXAHH8KumbNgctSwH0hoee69n/MeAtPy7TfVTelGQiEc/iMCYU/vkidI4HOmhC4 FB3cF2bi1A4cRXEh3VqFMbuR+nKyqiH/YW7BGIfogthGSsQo+LITcLzr22wPiyzRIf9Z Eit6lMsjusbG3vvVm9dIqty/OmTNZIkILqxTV4VnNX9CkYY55vtutYIfqEL7dUGHeY6A xli/MLOtiufIMgx4r7F/dCUSEYPTVqKWZLL8XHi3veaJ3ks4UW4I4uBTQdRmVnZvrSiw N8rw== 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=+IXZ/Kz3W3ByK8YMBqzR++sHVAa+56dFMX9xl5Pgrpw=; fh=Y5ua58y+ybdOPwRkMynUdu+Hv1LrozBumh8skcuOhBI=; b=1I/gA2lMG4+snPsBkImfFTV1cBhyQAS7AajvSgJzUHgwNcNO2QABaL5Ey+3g604cXR RsA1zL+lxSXdnzCUXIbFO6EQVJqSwlnB9CRg76leWvCrzlS3UthjFe9ygspP9OWN7Mkf 49i9nJ2Qs95fS2dDpKumCfdEfxJeluzLNyMukNFHDNfBaR61nXqrx2kSrlto8CrKZmFt 2uBaxxg2LYlpDAXnW+z76rmKjklikV6wmEpzzaaMb9QeEyUma3mk5uZ+3Z3Ma/doBV1m a12nPEjXbAfKlqlvvVArGR098ARPFWXoVfJxmW8dlcTtu+Ox367ZdELoe5VfzBM4rg7e 5Bsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=llnZxDvI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id b6-20020a6541c6000000b005893b7094easi8099443pgq.554.2023.12.12.12.52.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 12:52:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=llnZxDvI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 478928023722; Tue, 12 Dec 2023 12:51:55 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377407AbjLLUvk (ORCPT + 99 others); Tue, 12 Dec 2023 15:51:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235126AbjLLUv0 (ORCPT ); Tue, 12 Dec 2023 15:51:26 -0500 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99C551BFC for ; Tue, 12 Dec 2023 12:47:46 -0800 (PST) Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-1d341b6945dso4253375ad.0 for ; Tue, 12 Dec 2023 12:47:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1702414065; x=1703018865; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=+IXZ/Kz3W3ByK8YMBqzR++sHVAa+56dFMX9xl5Pgrpw=; b=llnZxDvI0hV3LkavGBpjWkB0VrsCb3nUAC3YQ8rNVzwUKOf2sWma5YGq2MEVO9yy02 zVbmoJwAwxem0JmXI/P80+1ZRdZ2Pneqotc2gt+95uAhdcxZyi3sukRPhQBIM53poJzn Exr0haV2PKVo/bQ+ydJTeZgnl96ileMcm7Hvg8M1aXpmSpFlUcsTQaNrVr47iAQ1ZwUH oroofogf8PmwTUV2acRuij0QVd0oHoomKRfxCbXxKpBUFXqGWInDUiSCKT9c7rncjbAd /9EUcmyeUQDPvQnTka1gpcU/i14m6WJHutOHf4tczp73vD/3qOci1qyRKCpaInX9SbtH 5k5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702414065; x=1703018865; 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=+IXZ/Kz3W3ByK8YMBqzR++sHVAa+56dFMX9xl5Pgrpw=; b=e/H+h7m7jV0EezDHw4cnQkWhfH9X8gchKOzjCkR7AaU7carioZC6jYxdrnjV7NU/1Y 2pMSC3Kju6DAJfYkTlBfs8NxuA93pYxjUwdfHNZ3qy/T7Hgx+ciXZFELq22neenB/POJ weLQnercr1F9Q0OH9ehVYo9TA+4uDE88Bh8OghDCwUTcYE6baK+1A9oZ2cgSt8V+lXWI G9hBALmekMU8Yz9da+R6qZvdlG3fA11E78nTsP4txntZNvlFW/AlLi5dVNmDK39I7Dn2 2qze5Og6kh6XRLOmxB/EI/IQreeUovtkQ7i86+rX9uo6woDivI4kLzXyvJjmz/4L6nTW cWzA== X-Gm-Message-State: AOJu0YzCmJcHAlgejEG21L4Xk1AAS6RKchyhl/h707kUWHGHtZ0oqJIa jg4xQVUOtyt6Mu7id2ZfRpzdYujD6w== X-Received: from sagi.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:241b]) (user=sagis job=sendgmr) by 2002:a17:903:22cd:b0:1d0:727b:8355 with SMTP id y13-20020a17090322cd00b001d0727b8355mr51732plg.1.1702414065371; Tue, 12 Dec 2023 12:47:45 -0800 (PST) Date: Tue, 12 Dec 2023 12:46:41 -0800 In-Reply-To: <20231212204647.2170650-1-sagis@google.com> Mime-Version: 1.0 References: <20231212204647.2170650-1-sagis@google.com> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Message-ID: <20231212204647.2170650-27-sagis@google.com> Subject: [RFC PATCH v5 26/29] KVM: selftests: TDX: Add support for TDG.VP.VEINFO.GET From: Sagi Shahar To: linux-kselftest@vger.kernel.org, Ackerley Tng , Ryan Afranji , Erdem Aktas , Sagi Shahar , Isaku Yamahata Cc: Sean Christopherson , Paolo Bonzini , Shuah Khan , Peter Gonda , Haibo Xu , Chao Peng , Vishal Annapurve , Roger Wang , Vipin Sharma , 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" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Tue, 12 Dec 2023 12:51:55 -0800 (PST) From: Ackerley Tng Signed-off-by: Ackerley Tng Signed-off-by: Ryan Afranji Signed-off-by: Sagi Shahar --- .../selftests/kvm/include/x86_64/tdx/tdx.h | 21 +++++++++++++++++++ .../selftests/kvm/lib/x86_64/tdx/tdx.c | 19 +++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/tools/testing/selftests/kvm/include/x86_64/tdx/tdx.h b/tools/testing/selftests/kvm/include/x86_64/tdx/tdx.h index b71bcea40b5c..12863a8beaae 100644 --- a/tools/testing/selftests/kvm/include/x86_64/tdx/tdx.h +++ b/tools/testing/selftests/kvm/include/x86_64/tdx/tdx.h @@ -6,6 +6,7 @@ #include "kvm_util_base.h" #define TDG_VP_INFO 1 +#define TDG_VP_VEINFO_GET 3 #define TDG_MEM_PAGE_ACCEPT 6 #define TDG_VP_VMCALL_GET_TD_VM_CALL_INFO 0x10000 @@ -41,4 +42,24 @@ uint64_t tdg_vp_info(uint64_t *rcx, uint64_t *rdx, uint64_t tdg_vp_vmcall_map_gpa(uint64_t address, uint64_t size, uint64_t *data_out); uint64_t tdg_mem_page_accept(uint64_t gpa, uint8_t level); +/* + * Used by the #VE exception handler to gather the #VE exception + * info from the TDX module. This is a software only structure + * and not part of the TDX module/VMM ABI. + * + * Adapted from arch/x86/include/asm/tdx.h + */ +struct ve_info { + uint64_t exit_reason; + uint64_t exit_qual; + /* Guest Linear (virtual) Address */ + uint64_t gla; + /* Guest Physical Address */ + uint64_t gpa; + uint32_t instr_len; + uint32_t instr_info; +}; + +uint64_t tdg_vp_veinfo_get(struct ve_info *ve); + #endif // SELFTEST_TDX_TDX_H diff --git a/tools/testing/selftests/kvm/lib/x86_64/tdx/tdx.c b/tools/testing/selftests/kvm/lib/x86_64/tdx/tdx.c index d8c4ab635c06..71d9f55007f7 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/tdx/tdx.c +++ b/tools/testing/selftests/kvm/lib/x86_64/tdx/tdx.c @@ -241,3 +241,22 @@ uint64_t tdg_mem_page_accept(uint64_t gpa, uint8_t level) { return __tdx_module_call(TDG_MEM_PAGE_ACCEPT, gpa | level, 0, 0, 0, NULL); } + +uint64_t tdg_vp_veinfo_get(struct ve_info *ve) +{ + uint64_t ret; + struct tdx_module_output out; + + memset(&out, 0, sizeof(struct tdx_module_output)); + + ret = __tdx_module_call(TDG_VP_VEINFO_GET, 0, 0, 0, 0, &out); + + ve->exit_reason = out.rcx; + ve->exit_qual = out.rdx; + ve->gla = out.r8; + ve->gpa = out.r9; + ve->instr_len = out.r10 & 0xffffffff; + ve->instr_info = out.r10 >> 32; + + return ret; +} -- 2.43.0.472.g3155946c3a-goog