From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A87C6C4345F for ; Mon, 15 Apr 2024 08:05:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 04CDD6B0085; Mon, 15 Apr 2024 04:05:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F3FC86B0087; Mon, 15 Apr 2024 04:05:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E07BB6B0088; Mon, 15 Apr 2024 04:05:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id C28156B0085 for ; Mon, 15 Apr 2024 04:05:56 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 8B8E4404BC for ; Mon, 15 Apr 2024 08:05:56 +0000 (UTC) X-FDA: 82011032712.05.F0F480C Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf22.hostedemail.com (Postfix) with ESMTP id DA941C0015 for ; Mon, 15 Apr 2024 08:05:54 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=FkMyRh9h; spf=pass (imf22.hostedemail.com: domain of 34d8cZgsKCEwoqys5zsC71uu22uzs.q20zw18B-00y9oqy.25u@flex--ackerleytng.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=34d8cZgsKCEwoqys5zsC71uu22uzs.q20zw18B-00y9oqy.25u@flex--ackerleytng.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713168354; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:dkim-signature; bh=s+QzKS/TBsR0oqS/yx5/asjaA5pGnOo8W0mMCO+D7xM=; b=6duz6h8vL+htJNvIUJ/l4RuNuHJVcJ9cNPgGt2/0wh27xRx4pFcuhoG1raq2gpweeOTqcb Ssbcdbk5NANq01w2LNNWLh+MZTjoRe8AM9IOpQO1biM2bJGzyHR0yxH3gy934MG29Sc6Pg 0nya3jDffIHV0n5ayxhHwk3H0oAsztk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713168354; a=rsa-sha256; cv=none; b=oBdbS2WqCVgrXpnwdDcHRh11z1FqNZm149yuSJsN5wT4VFmdys4WrzO4fD20quY8cSjU/f G3EdeEwbokE57lHoxi12fRGXNzPMSylyWs1HneNHTWlyzBBOEPCeC1pLAzWtbSlkngqSSO FP7WTKljzWkKA0Gl/ZetWt/KvLaEfk8= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=FkMyRh9h; spf=pass (imf22.hostedemail.com: domain of 34d8cZgsKCEwoqys5zsC71uu22uzs.q20zw18B-00y9oqy.25u@flex--ackerleytng.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=34d8cZgsKCEwoqys5zsC71uu22uzs.q20zw18B-00y9oqy.25u@flex--ackerleytng.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-61891efba06so35291437b3.0 for ; Mon, 15 Apr 2024 01:05:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713168354; x=1713773154; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:in-reply-to:date:from:to :cc:subject:date:message-id:reply-to; bh=s+QzKS/TBsR0oqS/yx5/asjaA5pGnOo8W0mMCO+D7xM=; b=FkMyRh9hX/pKloTkkae8i1bZzTrdV/AkXeZW00KENvacEEqMZrHih9azvbIwAgTWUg ypoy3xch4UgCmmmpDR4+Cw3z/QSnDiuGZ9pHAOqLxhSF7BlK3i/ePX377Cz7l3I6JtEx I3SM2vvI8VN3PeCEFNUSrtZnDV5S79bHtGnzVSyCd9ALwKGYiMR05w2LZ6Oy96k1kcSR YInu1S8Xz3gtd+BX04EH55tWkHcL/46KrgVd6h7vRnk0XFa+ug3Iqrhd7DkKsGATi61a 4uHQrRGN9nLB0TwzZoZOl7FIcg+2EVXUSHJOtVQy8r5VmTa+kEvCc9Sm9ejA3gOzT3LK aIXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713168354; x=1713773154; 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=s+QzKS/TBsR0oqS/yx5/asjaA5pGnOo8W0mMCO+D7xM=; b=QIC3kiLr0PDIoIGKwt5A4GI3O+7bouavTpRa7WPL6X6La5OMEJ7W8IrhrlcyHBgp6z tpr2ZcMcnJj3Fg9h6de1VURtq7nZAeTJO9Wwqt5mVwovI9VwLUwwee3IWa1N9B3xiKcu fJ9xnIa+vm6aPev/Br9tgc5ZIdf39JPTNMgt9zGnDQUEnmILy/ccbPA+AZcJZWUJUnRW WzGm1uqEg/Ntg5PgPx1wd82jEi2pz6YHQUHhm50wMVxoyNxrRPPWXPd+Pftwk/fGnT2/ D/hAyJnnt3yAOR0YS/ZnOAKJxjSMjCq2898ES7W0zroWHSWK0KMNyX+kKfDuh/YxXilI 5fhw== X-Forwarded-Encrypted: i=1; AJvYcCWDCmrrpcm2lFQMZy5a0B2GXr84rwyM7xfdUWyN9WOmqC7bC3/F+DTVi7bXTI60FvAOW4cWaKGlpmzubDOtKuMWYy4= X-Gm-Message-State: AOJu0Yzd0ayCILMTEbjXk7eDQ+1j8uFHr8PezO7R++0whdnyg6rd3DzP FYOq2THn7eRmnn4FXNuFThx4YE217g4YXaWj9sa+I6ovvIfW6bmUzoAjQsAywp9X+t6/7BVAU7U x4WWHpwQvGjVN0jAscFCrpQ== X-Google-Smtp-Source: AGHT+IHMikC/U+kmGrGiTb25wJ2Cco4+xgMYwFQUfHjLotNG/XKGpj3Obvk5i4rsrXv7eys5ilLKnnIaps2TET0qpQ== X-Received: from ctop-sg.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:1223]) (user=ackerleytng job=sendgmr) by 2002:a0d:d183:0:b0:61a:d41d:f969 with SMTP id t125-20020a0dd183000000b0061ad41df969mr320681ywd.3.1713168353903; Mon, 15 Apr 2024 01:05:53 -0700 (PDT) Date: Mon, 15 Apr 2024 08:05:49 +0000 In-Reply-To: (message from Yan Zhao on Fri, 12 Apr 2024 19:57:50 +0800) 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" X-Rspamd-Queue-Id: DA941C0015 X-Rspam-User: X-Stat-Signature: uhbibhmupkfpa9kbbzn987udkhgbtdf3 X-Rspamd-Server: rspam03 X-HE-Tag: 1713168354-522581 X-HE-Meta: U2FsdGVkX1/NiiOVrzVoWw4+83FX1xHw9dOm43l2BKc9Rq0BDActQz+Paxrch0FFLo01N6FXcxFNBQbN3FB1Dv5wpKth9Enm7h9jIkwIU4PVWb0jP+TcF3snqskJCQF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2nEikDLfRN0pRKtMp5LjQEvp0kYRQknfe56ZEx8UUPjW/onASiF1W+KFRbotnjG7EW3AjzgeFOc3TX3i7d5xmiuz7fsICdX0MFlPzA6Kmv/XcGpg+UsgJep/jA/s1a4tlnWxdFOm9AunPIIYBmVCAe22I/NalnzP6f832FEhL9vUGf6vKXnB7QoKYhH/g4PgG71BlHWbjXE1OE+G4rfEFtgnSmka33gkvXS+4PSAmgoEliN6MDeLSL8eyd5l13+xN83S043jplZePcMgYlmx3fGzlZ5cLp2eKSJTWGxK4MrG8Ph96t8cXBdBSG6DRMomq5U8ShOzi3CcQPVCtDKWX+GGtzpnAcqDO0yCPLYOCSURbwNCRV344lgKF7Sm9Z576xN5j78lwlo3rbsLCB1JdMjxuNKI4cp/yo5KwKLIHSwws8A93efY= X-Bogosity: Ham, tests=bogofilter, spamicity=0.003109, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Yan Zhao writes: > On Fri, Apr 12, 2024 at 04:56:36AM +0000, Ackerley Tng wrote: >> 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 > But above "__LINE__" is obviously not a valid GPA. > > Do you think it's better to check "data_gpa" is with shared bit on and > aligned in 4K before setting bit 63? > I read "valid" in the spec to mean that the value in R13 "should be considered as useful" or "should be passed on to the host VMM via the TDX module", and not so much as in "validated". We could validate the data_gpa as you suggested to check alignment and shared bit, but perhaps that could be a higher-level function that calls tdg_vp_vmcall_report_fatal_error()? If it helps, shall we rename "data_gpa" to "data" for this lower-level, generic helper function and remove these two lines if (data_gpa) error_code |= 0x8000000000000000; A higher-level function could perhaps do the validation as you suggested and then set bit 63. Are you objecting to the use of R13 to hold extra test information, such as __LINE__? I feel that R13 is just another register that could be used to hold error information, and in the case of this test, we can use it to send __LINE__ to aid in debugging selftests. On the host side of the selftest we can printf() :). >> 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); >> >> +} >> >> >> >>