From: Alexey Makhalov <alexey.makhalov@broadcom.com>
To: kirill.shutemov@linux.intel.com
Cc: linux-kernel@vger.kernel.org, virtualization@lists.linux.dev,
bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com,
mingo@redhat.com, tglx@linutronix.de, x86@kernel.org,
netdev@vger.kernel.org, richardcochran@gmail.com,
linux-input@vger.kernel.org, dmitry.torokhov@gmail.com,
zackr@vmware.com, linux-graphics-maintainer@vmware.com,
pv-drivers@vmware.com, namit@vmware.com, timothym@vmware.com,
akaher@vmware.com, jsipek@vmware.com,
dri-devel@lists.freedesktop.org, daniel@ffwll.ch,
airlied@gmail.com, tzimmermann@suse.de, mripard@kernel.org,
maarten.lankhorst@linux.intel.com, horms@kernel.org
Subject: Re: [PATCH v3 6/6] x86/vmware: Add TDX hypercall support
Date: Tue, 19 Dec 2023 19:02:27 -0800 [thread overview]
Message-ID: <5169497a-e16c-402c-bbcd-4bdc7d063849@broadcom.com> (raw)
In-Reply-To: <20231220010000.y5ybey76xjckvh6y@box.shutemov.name>
On 12/19/23 5:00 PM, kirill.shutemov@linux.intel.com wrote:
> On Tue, Dec 19, 2023 at 04:27:51PM -0800, Alexey Makhalov wrote:
>>
>>
>> On 12/19/23 3:23 PM, kirill.shutemov@linux.intel.com wrote:
>>> On Tue, Dec 19, 2023 at 01:57:51PM -0800, Alexey Makhalov wrote:
>>>> diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c
>>>> index 3aa1adaed18f..ef07ab7a07e1 100644
>>>> --- a/arch/x86/kernel/cpu/vmware.c
>>>> +++ b/arch/x86/kernel/cpu/vmware.c
>>>> @@ -428,6 +428,30 @@ static bool __init vmware_legacy_x2apic_available(void)
>>>> (eax & BIT(VCPU_LEGACY_X2APIC));
>>>> }
>>>> +#ifdef CONFIG_INTEL_TDX_GUEST
>>>> +unsigned long vmware_tdx_hypercall(unsigned long cmd,
>>>> + struct tdx_module_args *args)
>>>> +{
>>>> + if (!hypervisor_is_type(X86_HYPER_VMWARE))
>>>> + return 0;
>
> BTW, don't you want to warn here to? We don't expect vmware hypercalls to
> be called by non-vmware guest, do we?
The answer is below...
>
>>>> +
>>>> + if (cmd & ~VMWARE_CMD_MASK) {
>>>> + pr_warn("Out of range command %x\n", cmd);
>>>> + return 0;
>>>
>>> Is zero success? Shouldn't it be an error?
>>
>> VMware hypercalls do not have a standard way of signalling an error.
>> To generalize expectations from the caller perspective of any existing
>> hypercalls: error (including hypercall is not supported or disabled) is when
>> return value is 0 and out1/2 are unchanged or equal to in1/in2.
>
> You are talking about signaling errors over hypercall transport. But if
> kernel can see that something is wrong why cannot it signal the issue
> clearly to caller. It is going to be in-kernel convention.These "return 0" blocks were introduced to protect against non-vmware
guest or arbitrary modules trying to use __tdx_hypercall via exported
vmware_tdx_hypercall function. In this case, it will be NOOP behavior
with no or minor side effects.
From valid vmware_hypercall callers point of view, there is no such
thing as a hypercall not available. Once guest detection code recognizes
VMWare hypervisor via cpuid, it will start using hypercalls in
accordance to per-call API.
Valid VMware guest code will never go into first return, no warning
required.
Second return can be hit in rare cases for example during development
phase, or, hypothetical case, when cmd was dynamically generated.
That's why we have a warning warning only for the second condition.
While speaking about it, I'm started to lean towards your
recommendation. Yes, we can return standard error code such as -EINVAL
or just -1 instead of "return 0" in this function. And it will be
algorithmically correct. As if Vmware guest caller provide out of range
cmd - it is not documented behavior.
Speaking of additional in-kernel convention for passing additional
parameter if error happens, it does not makes sense for me because:
1. existing caller codes analyze output argument to recognize error
error response from the hypervisor. Adding one additional check for
in-kernel errors just for TDX path which will be never hit by valid code
in production is an unnecessary overhead.
2. It will definitely add an overhead as an error code will require one
more output value, or out0 should be moved from return in-register value
to return by pointer function argument.
Summarizing, overloading vmware_tdx_hypercall return value by arg0 (from
the hypervisor) and kernel error (-1 or any other) seems like reasonable
change.
>
> And to very least, it has to be pr_warn_once().
>
Good catch! Will change it.
Thanks,
--Alexey
next prev parent reply other threads:[~2023-12-20 3:02 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-19 21:57 [PATCH v3 0/6] VMware hypercalls enhancements Alexey Makhalov
2023-12-19 21:57 ` [PATCH v3 1/6] x86/vmware: Move common macros to vmware.h Alexey Makhalov
2023-12-19 21:57 ` [PATCH v3 2/6] x86/vmware: Introduce vmware_hypercall API Alexey Makhalov
2023-12-19 23:20 ` kirill.shutemov
2023-12-20 0:17 ` Alexey Makhalov
2023-12-20 0:51 ` kirill.shutemov
2023-12-20 3:30 ` Alexey Makhalov
2023-12-19 21:57 ` [PATCH v3 3/6] ptp/vmware: Use " Alexey Makhalov
2023-12-19 21:57 ` [PATCH v3 4/6] input/vmmouse: " Alexey Makhalov
2023-12-19 21:57 ` [PATCH v3 5/6] drm/vmwgfx: " Alexey Makhalov
2023-12-19 21:57 ` [PATCH v3 6/6] x86/vmware: Add TDX hypercall support Alexey Makhalov
2023-12-19 23:23 ` kirill.shutemov
2023-12-20 0:27 ` Alexey Makhalov
2023-12-20 1:00 ` kirill.shutemov
2023-12-20 3:02 ` Alexey Makhalov [this message]
2023-12-20 13:09 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5169497a-e16c-402c-bbcd-4bdc7d063849@broadcom.com \
--to=alexey.makhalov@broadcom.com \
--cc=airlied@gmail.com \
--cc=akaher@vmware.com \
--cc=bp@alien8.de \
--cc=daniel@ffwll.ch \
--cc=dave.hansen@linux.intel.com \
--cc=dmitry.torokhov@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=horms@kernel.org \
--cc=hpa@zytor.com \
--cc=jsipek@vmware.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-graphics-maintainer@vmware.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mingo@redhat.com \
--cc=mripard@kernel.org \
--cc=namit@vmware.com \
--cc=netdev@vger.kernel.org \
--cc=pv-drivers@vmware.com \
--cc=richardcochran@gmail.com \
--cc=tglx@linutronix.de \
--cc=timothym@vmware.com \
--cc=tzimmermann@suse.de \
--cc=virtualization@lists.linux.dev \
--cc=x86@kernel.org \
--cc=zackr@vmware.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox