Received: by 2002:ab2:7407:0:b0:1f4:b336:87c4 with SMTP id e7csp224653lqn; Thu, 11 Apr 2024 21:56:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWOEUxiovue6c40NeH57rkiUTyoIue8EzZHqSyRfmoNiLynTzJLVDwEtCFz+CS+jVy5t6Ab5hkyTE8FCHUA/eXt8r04G7JsC5rtelwo9A== X-Google-Smtp-Source: AGHT+IEqBsphXXn0CYO9IHsCzthhr/gQZjIXcyvtappXk8kx8NoXibCaNq9Ej12CjWwl1RrH0Chn X-Received: by 2002:a05:6a20:9145:b0:1a8:58c5:4b58 with SMTP id x5-20020a056a20914500b001a858c54b58mr2228888pzc.5.1712897818481; Thu, 11 Apr 2024 21:56:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712897818; cv=pass; d=google.com; s=arc-20160816; b=UfBmtvoH3LmPDTMLd3vORIVeY8ZFqDHjVuog7E1a4favjbHxGkOCtf7BwP8ugW6t1P EESSDznZ25FEPd4VAxYKhKuqZ/nbriv0y4sCRjVEAIhjqJD2FcLW1akhRSIXm7O9vCyu cMS7heUuX/WZg0sdloH6ohsbtmDND6EvFrzXaCcL2nmecZjOuAg3vXyyzE/Yuq7dzs3b +oXfpu3jYNfF2aj/bvamvfo0maRcU5Q3rPTEpm/fYMx2ze0aK9h3jAikyj7XIuEiQLpW 8jExjV0UNgxMjy0SMOUwseKv1CDWuRBTIwK3vxKcfSQocx9Qd3iFRnGKWlW+dnzpVxp/ tCww== 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=cqWwq/YjmJyQ4CvXHHLBMD+DqXASBJiMvQ6ZfNbBSk8=; fh=cfQYs7NBWWzS3pEORTB8TDGarNiFBeCsUbze6oEcqQI=; b=PrrCb5IAlYM+jDiLQvot7IQeNc0AMj6CqNv+HJ/BY8NdUjpMcejl9I+igLmk8+rkxK 3nvtj9MuzsbMo3Hqz87Q4KjaNPF7+YUW9nEtpjM5VKW1NlLJSLCYnPgVOQxI+DANArNv k4umMA1HcC9hyPIaDfkYtZ04YDE1rAYh+CvYCSuqIC3zrnCVvZ8YWVD07dVyTqTbMGSS /XDYWZMoeiKHtdzz/EK0mkFW6kN0xXqa8kyX5/4LJirV+P1HsnTjESk1cV6X8qGwDB1Y e5HKJhS8EmappEOxqBNegsaUViE+MhACOB5TNyOk097juptCs1AtgnoRkjTHYhj6ht93 OutA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=HzZEmtbc; 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-141945-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141945-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 u15-20020a17090a4bcf00b002a6efd18800si524508pjl.113.2024.04.11.21.56.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 21:56:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-141945-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=HzZEmtbc; 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-141945-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141945-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 043B42865C5 for ; Fri, 12 Apr 2024 04:56:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9BE4218B1B; Fri, 12 Apr 2024 04:56:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="HzZEmtbc" Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 067791B946 for ; Fri, 12 Apr 2024 04:56:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712897804; cv=none; b=or2kZHGzwrSOw1vUxNvPBpQCDpcs+2s3MrAOE3hSdf5E+Xlp+jnBItPbukf6r5jRvKXXHYX/PpYu/3KA36rMenHFkLAyTR3kiDGbAeMDxH4TXOaxzIykjlxs7+RKneTSJnPXDA62NbEtmSRT7+k+SB8Gfef7rv6uX971i6u3RU8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712897804; c=relaxed/simple; bh=3BVECkjKWPbyqchU1j/oKY0/VzfucM7JP8zNKfPqr64=; h=Date:In-Reply-To:Mime-Version:Message-ID:Subject:From:To:Cc: Content-Type; b=prNVaL8Bnv62QzCZJdKPo6GvkdlnBz6JTO78s98w9pRET4MFUOa0lJNmZI35xB+SWt/Tguz4zQI1xKchokuzZmmCH8VAl0bvWvsfHOywfX+mzFXhHUXgApVQokd2DDD0r9wEaIV9o8y2ncF+U8aF0O71WF+YSwNRdBj01opG/1g= 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=HzZEmtbc; arc=none smtp.client-ip=209.85.128.201 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-yw1-f201.google.com with SMTP id 00721157ae682-615372710c4so8939827b3.1 for ; Thu, 11 Apr 2024 21:56:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712897801; x=1713502601; 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=cqWwq/YjmJyQ4CvXHHLBMD+DqXASBJiMvQ6ZfNbBSk8=; b=HzZEmtbcqm1oka6OUPSmcQSMMsGYdK6fRKMHQBoIrJfJiGaTpqxILgZ1nGwGT+QgrT 6Wl68yKtzZRRi0JASQDooMl525+30GOZmtckRGKqwfNHoI/X0hw0vQzTilaPdgA8dVOb Akzeqjy8xWPyp0v4hQSpH+Kh1r8K1fqnvNZgZOoUIno6/jjkutEqYYt4B7NrofRfKRia mf+DWFAZ/EDO71tw8W4T1Msw6Gk7pnq373g1NY2yFUR08pm8s1Nu7IxobOALa5IYg9en Fq5GxMVvMy+5MG8UANtdUNJfbMOCTZM7DAGFfdveIGpj/EjIgaEGaonDnJuTJwRSIHy1 iLgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712897801; x=1713502601; 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=cqWwq/YjmJyQ4CvXHHLBMD+DqXASBJiMvQ6ZfNbBSk8=; b=EPyn9dJ+MtPqDnlKiJ8J/BdZsAcafaTGYvi2oKgvHnW9kCNw7CCeicRqlMjtKHa+g8 J+D4IMDjf3oj/J4Ag+f9YmIOz8ClwIgQnwa0aW3IlyBx7notC48P/1VdsfHlwlsO9tnC +/MZUVR5Xz06m1GJdg85gvIv4vKZp96YfpVwe62pjdI3wyfcIsn9UDlgDPZCtLlpLTlB TsUZbPkLncZ5JPUnoHIZBI63S2B6NTPxRTCmrJ5bDo4Y++icNpmKzEoFcRUsmzXiqY0A gm0wBWUDPagsu6O6ywpvFURXI4gloG840h9gaGP9T/NJf3RP4w/yFGHeNxjxisf200Y0 o7Ew== X-Forwarded-Encrypted: i=1; AJvYcCVNYzb97ANl9M73IVPOnjb/Zvz9cjBIas6XapPAannE/nYJv3W3N/s+qdha/lFBK78SjFAc3e1N8Z+Kr+hYMCSjg3dLAjw2mFAbWu/t X-Gm-Message-State: AOJu0Ywij7HrHN1n33UUCr7/BW7qUUbCnCT5JwEJK9KVjcQTFB47gFsp rF0qL4uGiP3Tqk9901zc/jKj/7GlibQ+ATkRMeKu3Asd4BCyYuH7GmKOrK/KIr572Q2UDKvE7CC v26CtEAhy+xMqt368MUte+Q== X-Received: from ctop-sg.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:1223]) (user=ackerleytng job=sendgmr) by 2002:a5b:c49:0:b0:dcd:3a37:65 with SMTP id d9-20020a5b0c49000000b00dcd3a370065mr159815ybr.7.1712897801099; Thu, 11 Apr 2024 21:56:41 -0700 (PDT) Date: Fri, 12 Apr 2024 04:56:36 +0000 In-Reply-To: (message from Yan Zhao on Fri, 1 Mar 2024 20:09:58 +0800) 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 09/29] KVM: selftests: TDX: Add report_fatal_error test From: Ackerley Tng To: Yan Zhao 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" Yan Zhao writes: > ... >> diff --git a/tools/testing/selftests/kvm/include/x86_64/tdx/test_util.h b/tools/testing/selftests/kvm/include/x86_64/tdx/test_util.h >> index b570b6d978ff..6d69921136bd 100644 >> --- a/tools/testing/selftests/kvm/include/x86_64/tdx/test_util.h >> +++ b/tools/testing/selftests/kvm/include/x86_64/tdx/test_util.h >> @@ -49,4 +49,23 @@ bool is_tdx_enabled(void); >> */ >> void tdx_test_success(void); >> >> +/** >> + * Report an error with @error_code to userspace. >> + * >> + * Return value from tdg_vp_vmcall_report_fatal_error is ignored since execution >> + * is not expected to continue beyond this point. >> + */ >> +void tdx_test_fatal(uint64_t error_code); >> + >> +/** >> + * Report an error with @error_code to userspace. >> + * >> + * @data_gpa may point to an optional shared guest memory holding the error >> + * string. >> + * >> + * Return value from tdg_vp_vmcall_report_fatal_error is ignored since execution >> + * is not expected to continue beyond this point. >> + */ >> +void tdx_test_fatal_with_data(uint64_t error_code, uint64_t data_gpa); > I found nowhere is using "data_gpa" as a gpa, even in patch 23, it's > usage is to pass a line number ("tdx_test_fatal_with_data(ret, __LINE__)"). > > This function tdx_test_fatal_with_data() is meant to provide a generic interface for TDX tests to use TDG.VP.VMCALL, and so the parameters of tdx_test_fatal_with_data() generically allow error_code and data_gpa to be specified. The tests just happen to use the data_gpa parameter to pass __LINE__ to the host VMM, but other tests in future that use the tdx_test_fatal_with_data() function in the TDX testing library could actually pass a GPA through using data_gpa. >> #endif // SELFTEST_TDX_TEST_UTIL_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 c2414523487a..b854c3aa34ff 100644 >> --- a/tools/testing/selftests/kvm/lib/x86_64/tdx/tdx.c >> +++ b/tools/testing/selftests/kvm/lib/x86_64/tdx/tdx.c >> @@ -1,8 +1,31 @@ >> // SPDX-License-Identifier: GPL-2.0-only >> >> +#include >> + >> #include "tdx/tdcall.h" >> #include "tdx/tdx.h" >> >> +void handle_userspace_tdg_vp_vmcall_exit(struct kvm_vcpu *vcpu) >> +{ >> + struct kvm_tdx_vmcall *vmcall_info = &vcpu->run->tdx.u.vmcall; >> + uint64_t vmcall_subfunction = vmcall_info->subfunction; >> + >> + switch (vmcall_subfunction) { >> + case TDG_VP_VMCALL_REPORT_FATAL_ERROR: >> + vcpu->run->exit_reason = KVM_EXIT_SYSTEM_EVENT; >> + vcpu->run->system_event.ndata = 3; >> + vcpu->run->system_event.data[0] = >> + TDG_VP_VMCALL_REPORT_FATAL_ERROR; >> + vcpu->run->system_event.data[1] = vmcall_info->in_r12; >> + vcpu->run->system_event.data[2] = vmcall_info->in_r13; >> + vmcall_info->status_code = 0; >> + break; >> + default: >> + TEST_FAIL("TD VMCALL subfunction %lu is unsupported.\n", >> + vmcall_subfunction); >> + } >> +} >> + >> uint64_t tdg_vp_vmcall_instruction_io(uint64_t port, uint64_t size, >> uint64_t write, uint64_t *data) >> { >> @@ -25,3 +48,19 @@ uint64_t tdg_vp_vmcall_instruction_io(uint64_t port, uint64_t size, >> >> return ret; >> } >> + >> +void tdg_vp_vmcall_report_fatal_error(uint64_t error_code, uint64_t data_gpa) >> +{ >> + struct tdx_hypercall_args args; >> + >> + memset(&args, 0, sizeof(struct tdx_hypercall_args)); >> + >> + if (data_gpa) >> + error_code |= 0x8000000000000000; >> > So, why this error_code needs to set bit 63? > > The Intel GHCI Spec says in R12, bit 63 is set if the GPA is valid. As a generic TDX testing library function, this check allows the user to use tdg_vp_vmcall_report_fatal_error() with error_code and data_gpa and not worry about setting bit 63 before calling tdg_vp_vmcall_report_fatal_error(), though if the user set bit 63 before that, there is no issue. >> + args.r11 = TDG_VP_VMCALL_REPORT_FATAL_ERROR; >> + args.r12 = error_code; >> + args.r13 = data_gpa; >> + >> + __tdx_hypercall(&args, 0); >> +} >>