License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 15:07:57 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2010-05-07 16:57:28 -07:00
|
|
|
#ifndef _ASM_X86_MSHYPER_H
|
|
|
|
#define _ASM_X86_MSHYPER_H
|
2010-05-06 12:08:41 -07:00
|
|
|
|
2010-05-07 16:57:28 -07:00
|
|
|
#include <linux/types.h>
|
2017-08-02 18:09:17 +02:00
|
|
|
#include <linux/nmi.h>
|
2020-02-10 11:39:53 +08:00
|
|
|
#include <linux/msi.h>
|
2023-07-23 23:12:47 +00:00
|
|
|
#include <linux/io.h>
|
2018-01-11 21:46:30 +00:00
|
|
|
#include <asm/nospec-branch.h>
|
2020-08-09 18:29:51 -07:00
|
|
|
#include <asm/paravirt.h>
|
2025-04-30 22:42:41 -07:00
|
|
|
#include <asm/msr.h>
|
2024-11-25 15:24:43 -08:00
|
|
|
#include <hyperv/hvhdk.h>
|
2010-05-07 16:57:28 -07:00
|
|
|
|
x86/hyperv: Change vTOM handling to use standard coco mechanisms
Hyper-V guests on AMD SEV-SNP hardware have the option of using the
"virtual Top Of Memory" (vTOM) feature specified by the SEV-SNP
architecture. With vTOM, shared vs. private memory accesses are
controlled by splitting the guest physical address space into two
halves.
vTOM is the dividing line where the uppermost bit of the physical
address space is set; e.g., with 47 bits of guest physical address
space, vTOM is 0x400000000000 (bit 46 is set). Guest physical memory is
accessible at two parallel physical addresses -- one below vTOM and one
above vTOM. Accesses below vTOM are private (encrypted) while accesses
above vTOM are shared (decrypted). In this sense, vTOM is like the
GPA.SHARED bit in Intel TDX.
Support for Hyper-V guests using vTOM was added to the Linux kernel in
two patch sets[1][2]. This support treats the vTOM bit as part of
the physical address. For accessing shared (decrypted) memory, these
patch sets create a second kernel virtual mapping that maps to physical
addresses above vTOM.
A better approach is to treat the vTOM bit as a protection flag, not
as part of the physical address. This new approach is like the approach
for the GPA.SHARED bit in Intel TDX. Rather than creating a second kernel
virtual mapping, the existing mapping is updated using recently added
coco mechanisms.
When memory is changed between private and shared using
set_memory_decrypted() and set_memory_encrypted(), the PTEs for the
existing kernel mapping are changed to add or remove the vTOM bit in the
guest physical address, just as with TDX. The hypercalls to change the
memory status on the host side are made using the existing callback
mechanism. Everything just works, with a minor tweak to map the IO-APIC
to use private accesses.
To accomplish the switch in approach, the following must be done:
* Update Hyper-V initialization to set the cc_mask based on vTOM
and do other coco initialization.
* Update physical_mask so the vTOM bit is no longer treated as part
of the physical address
* Remove CC_VENDOR_HYPERV and merge the associated vTOM functionality
under CC_VENDOR_AMD. Update cc_mkenc() and cc_mkdec() to set/clear
the vTOM bit as a protection flag.
* Code already exists to make hypercalls to inform Hyper-V about pages
changing between shared and private. Update this code to run as a
callback from __set_memory_enc_pgtable().
* Remove the Hyper-V special case from __set_memory_enc_dec()
* Remove the Hyper-V specific call to swiotlb_update_mem_attributes()
since mem_encrypt_init() will now do it.
* Add a Hyper-V specific implementation of the is_private_mmio()
callback that returns true for the IO-APIC and vTPM MMIO addresses
[1] https://lore.kernel.org/all/20211025122116.264793-1-ltykernel@gmail.com/
[2] https://lore.kernel.org/all/20211213071407.314309-1-ltykernel@gmail.com/
[ bp: Touchups. ]
Signed-off-by: Michael Kelley <mikelley@microsoft.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://lore.kernel.org/r/1679838727-87310-7-git-send-email-mikelley@microsoft.com
2023-03-26 06:52:01 -07:00
|
|
|
/*
|
|
|
|
* Hyper-V always provides a single IO-APIC at this MMIO address.
|
|
|
|
* Ideally, the value should be looked up in ACPI tables, but it
|
|
|
|
* is needed for mapping the IO-APIC early in boot on Confidential
|
|
|
|
* VMs, before ACPI functions can be used.
|
|
|
|
*/
|
|
|
|
#define HV_IOAPIC_BASE_ADDRESS 0xfec00000
|
|
|
|
|
2023-04-10 22:55:32 -07:00
|
|
|
#define HV_VTL_NORMAL 0x0
|
|
|
|
#define HV_VTL_SECURE 0x1
|
|
|
|
#define HV_VTL_MGMT 0x2
|
|
|
|
|
2021-10-25 08:21:11 -04:00
|
|
|
union hv_ghcb;
|
|
|
|
|
2021-10-25 08:21:06 -04:00
|
|
|
DECLARE_STATIC_KEY_FALSE(isolation_type_snp);
|
2023-08-24 01:07:03 -07:00
|
|
|
DECLARE_STATIC_KEY_FALSE(isolation_type_tdx);
|
2021-10-25 08:21:06 -04:00
|
|
|
|
2018-12-06 21:21:05 +08:00
|
|
|
typedef int (*hyperv_fill_flush_list_func)(
|
|
|
|
struct hv_guest_mapping_flush_list *flush,
|
|
|
|
void *data);
|
|
|
|
|
2013-02-03 17:22:39 -08:00
|
|
|
void hyperv_vector_handler(struct pt_regs *regs);
|
2017-01-18 16:45:02 -07:00
|
|
|
|
2023-04-10 22:55:30 -07:00
|
|
|
static inline unsigned char hv_get_nmi_reason(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-01-18 16:45:02 -07:00
|
|
|
#if IS_ENABLED(CONFIG_HYPERV)
|
x86/hyperv: Introduce a global variable hyperv_paravisor_present
The new variable hyperv_paravisor_present is set only when the VM
is a SNP/TDX VM with the paravisor running: see ms_hyperv_init_platform().
We introduce hyperv_paravisor_present because we can not use
ms_hyperv.paravisor_present in arch/x86/include/asm/mshyperv.h:
struct ms_hyperv_info is defined in include/asm-generic/mshyperv.h, which
is included at the end of arch/x86/include/asm/mshyperv.h, but at the
beginning of arch/x86/include/asm/mshyperv.h, we would already need to use
struct ms_hyperv_info in hv_do_hypercall().
We use hyperv_paravisor_present only in include/asm-generic/mshyperv.h,
and use ms_hyperv.paravisor_present elsewhere. In the future, we'll
introduce a hypercall function structure for different VM types, and
at boot time, the right function pointers would be written into the
structure so that runtime testing of TDX vs. SNP vs. normal will be
avoided and hyperv_paravisor_present will no longer be needed.
Call hv_vtom_init() when it's a VBS VM or when ms_hyperv.paravisor_present
is true, i.e. the VM is a SNP VM or TDX VM with the paravisor.
Enhance hv_vtom_init() for a TDX VM with the paravisor.
In hv_common_cpu_init(), don't decrypt the hyperv_pcpu_input_arg
for a TDX VM with the paravisor, just like we don't decrypt the page
for a SNP VM with the paravisor.
Signed-off-by: Dexuan Cui <decui@microsoft.com>
Reviewed-by: Tianyu Lan <tiala@microsoft.com>
Reviewed-by: Michael Kelley <mikelley@microsoft.com>
Signed-off-by: Wei Liu <wei.liu@kernel.org>
Link: https://lore.kernel.org/r/20230824080712.30327-7-decui@microsoft.com
2023-08-24 01:07:08 -07:00
|
|
|
extern bool hyperv_paravisor_present;
|
2020-12-21 22:55:41 -08:00
|
|
|
|
2017-08-02 18:09:14 +02:00
|
|
|
extern void *hv_hypercall_pg;
|
|
|
|
|
2021-12-27 19:31:55 -08:00
|
|
|
extern union hv_ghcb * __percpu *hv_ghcb_pg;
|
2021-10-25 08:21:06 -04:00
|
|
|
|
2023-08-24 01:07:11 -07:00
|
|
|
bool hv_isolation_type_snp(void);
|
2023-08-24 01:07:03 -07:00
|
|
|
bool hv_isolation_type_tdx(void);
|
2023-08-24 01:07:04 -07:00
|
|
|
u64 hv_tdx_hypercall(u64 control, u64 param1, u64 param2);
|
2023-08-24 01:07:03 -07:00
|
|
|
|
2023-08-18 06:29:17 -04:00
|
|
|
/*
|
|
|
|
* DEFAULT INIT GPAT and SEGMENT LIMIT value in struct VMSA
|
|
|
|
* to start AP in enlightened SEV guest.
|
|
|
|
*/
|
|
|
|
#define HV_AP_INIT_GPAT_DEFAULT 0x0007040600070406ULL
|
|
|
|
#define HV_AP_SEGMENT_LIMIT 0xffffffff
|
2023-08-18 06:29:15 -04:00
|
|
|
|
2023-08-24 01:07:04 -07:00
|
|
|
/*
|
|
|
|
* If the hypercall involves no input or output parameters, the hypervisor
|
|
|
|
* ignores the corresponding GPA pointer.
|
|
|
|
*/
|
2017-08-02 18:09:14 +02:00
|
|
|
static inline u64 hv_do_hypercall(u64 control, void *input, void *output)
|
|
|
|
{
|
|
|
|
u64 input_address = input ? virt_to_phys(input) : 0;
|
|
|
|
u64 output_address = output ? virt_to_phys(output) : 0;
|
|
|
|
u64 hv_status;
|
|
|
|
|
|
|
|
#ifdef CONFIG_X86_64
|
x86/hyperv: Introduce a global variable hyperv_paravisor_present
The new variable hyperv_paravisor_present is set only when the VM
is a SNP/TDX VM with the paravisor running: see ms_hyperv_init_platform().
We introduce hyperv_paravisor_present because we can not use
ms_hyperv.paravisor_present in arch/x86/include/asm/mshyperv.h:
struct ms_hyperv_info is defined in include/asm-generic/mshyperv.h, which
is included at the end of arch/x86/include/asm/mshyperv.h, but at the
beginning of arch/x86/include/asm/mshyperv.h, we would already need to use
struct ms_hyperv_info in hv_do_hypercall().
We use hyperv_paravisor_present only in include/asm-generic/mshyperv.h,
and use ms_hyperv.paravisor_present elsewhere. In the future, we'll
introduce a hypercall function structure for different VM types, and
at boot time, the right function pointers would be written into the
structure so that runtime testing of TDX vs. SNP vs. normal will be
avoided and hyperv_paravisor_present will no longer be needed.
Call hv_vtom_init() when it's a VBS VM or when ms_hyperv.paravisor_present
is true, i.e. the VM is a SNP VM or TDX VM with the paravisor.
Enhance hv_vtom_init() for a TDX VM with the paravisor.
In hv_common_cpu_init(), don't decrypt the hyperv_pcpu_input_arg
for a TDX VM with the paravisor, just like we don't decrypt the page
for a SNP VM with the paravisor.
Signed-off-by: Dexuan Cui <decui@microsoft.com>
Reviewed-by: Tianyu Lan <tiala@microsoft.com>
Reviewed-by: Michael Kelley <mikelley@microsoft.com>
Signed-off-by: Wei Liu <wei.liu@kernel.org>
Link: https://lore.kernel.org/r/20230824080712.30327-7-decui@microsoft.com
2023-08-24 01:07:08 -07:00
|
|
|
if (hv_isolation_type_tdx() && !hyperv_paravisor_present)
|
2023-08-24 01:07:04 -07:00
|
|
|
return hv_tdx_hypercall(control, input_address, output_address);
|
|
|
|
|
2023-08-24 01:07:11 -07:00
|
|
|
if (hv_isolation_type_snp() && !hyperv_paravisor_present) {
|
2025-03-02 17:21:00 -08:00
|
|
|
__asm__ __volatile__("mov %[output_address], %%r8\n"
|
2023-08-18 06:29:15 -04:00
|
|
|
"vmmcall"
|
|
|
|
: "=a" (hv_status), ASM_CALL_CONSTRAINT,
|
|
|
|
"+c" (control), "+d" (input_address)
|
2025-03-02 17:21:00 -08:00
|
|
|
: [output_address] "r" (output_address)
|
2023-08-18 06:29:15 -04:00
|
|
|
: "cc", "memory", "r8", "r9", "r10", "r11");
|
|
|
|
return hv_status;
|
|
|
|
}
|
|
|
|
|
2017-08-02 18:09:14 +02:00
|
|
|
if (!hv_hypercall_pg)
|
|
|
|
return U64_MAX;
|
|
|
|
|
2025-03-02 17:21:00 -08:00
|
|
|
__asm__ __volatile__("mov %[output_address], %%r8\n"
|
2018-01-11 21:46:30 +00:00
|
|
|
CALL_NOSPEC
|
x86/asm: Fix inline asm call constraints for Clang
For inline asm statements which have a CALL instruction, we list the
stack pointer as a constraint to convince GCC to ensure the frame
pointer is set up first:
static inline void foo()
{
register void *__sp asm(_ASM_SP);
asm("call bar" : "+r" (__sp))
}
Unfortunately, that pattern causes Clang to corrupt the stack pointer.
The fix is easy: convert the stack pointer register variable to a global
variable.
It should be noted that the end result is different based on the GCC
version. With GCC 6.4, this patch has exactly the same result as
before:
defconfig defconfig-nofp distro distro-nofp
before 9820389 9491555 8816046 8516940
after 9820389 9491555 8816046 8516940
With GCC 7.2, however, GCC's behavior has changed. It now changes its
behavior based on the conversion of the register variable to a global.
That somehow convinces it to *always* set up the frame pointer before
inserting *any* inline asm. (Therefore, listing the variable as an
output constraint is a no-op and is no longer necessary.) It's a bit
overkill, but the performance impact should be negligible. And in fact,
there's a nice improvement with frame pointers disabled:
defconfig defconfig-nofp distro distro-nofp
before 9796316 9468236 9076191 8790305
after 9796957 9464267 9076381 8785949
So in summary, while listing the stack pointer as an output constraint
is no longer necessary for newer versions of GCC, it's still needed for
older versions.
Suggested-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Reported-by: Matthias Kaehlcke <mka@chromium.org>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Dmitriy Vyukov <dvyukov@google.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Miguel Bernal Marin <miguel.bernal.marin@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/3db862e970c432ae823cf515c52b54fec8270e0e.1505942196.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2017-09-20 16:24:33 -05:00
|
|
|
: "=a" (hv_status), ASM_CALL_CONSTRAINT,
|
2017-08-02 18:09:14 +02:00
|
|
|
"+c" (control), "+d" (input_address)
|
2025-03-02 17:21:00 -08:00
|
|
|
: [output_address] "r" (output_address),
|
|
|
|
THUNK_TARGET(hv_hypercall_pg)
|
2017-08-02 18:09:14 +02:00
|
|
|
: "cc", "memory", "r8", "r9", "r10", "r11");
|
|
|
|
#else
|
|
|
|
u32 input_address_hi = upper_32_bits(input_address);
|
|
|
|
u32 input_address_lo = lower_32_bits(input_address);
|
|
|
|
u32 output_address_hi = upper_32_bits(output_address);
|
|
|
|
u32 output_address_lo = lower_32_bits(output_address);
|
|
|
|
|
|
|
|
if (!hv_hypercall_pg)
|
|
|
|
return U64_MAX;
|
|
|
|
|
2018-01-11 21:46:30 +00:00
|
|
|
__asm__ __volatile__(CALL_NOSPEC
|
2017-08-02 18:09:14 +02:00
|
|
|
: "=A" (hv_status),
|
x86/asm: Fix inline asm call constraints for Clang
For inline asm statements which have a CALL instruction, we list the
stack pointer as a constraint to convince GCC to ensure the frame
pointer is set up first:
static inline void foo()
{
register void *__sp asm(_ASM_SP);
asm("call bar" : "+r" (__sp))
}
Unfortunately, that pattern causes Clang to corrupt the stack pointer.
The fix is easy: convert the stack pointer register variable to a global
variable.
It should be noted that the end result is different based on the GCC
version. With GCC 6.4, this patch has exactly the same result as
before:
defconfig defconfig-nofp distro distro-nofp
before 9820389 9491555 8816046 8516940
after 9820389 9491555 8816046 8516940
With GCC 7.2, however, GCC's behavior has changed. It now changes its
behavior based on the conversion of the register variable to a global.
That somehow convinces it to *always* set up the frame pointer before
inserting *any* inline asm. (Therefore, listing the variable as an
output constraint is a no-op and is no longer necessary.) It's a bit
overkill, but the performance impact should be negligible. And in fact,
there's a nice improvement with frame pointers disabled:
defconfig defconfig-nofp distro distro-nofp
before 9796316 9468236 9076191 8790305
after 9796957 9464267 9076381 8785949
So in summary, while listing the stack pointer as an output constraint
is no longer necessary for newer versions of GCC, it's still needed for
older versions.
Suggested-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Reported-by: Matthias Kaehlcke <mka@chromium.org>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Dmitriy Vyukov <dvyukov@google.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Miguel Bernal Marin <miguel.bernal.marin@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/3db862e970c432ae823cf515c52b54fec8270e0e.1505942196.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2017-09-20 16:24:33 -05:00
|
|
|
"+c" (input_address_lo), ASM_CALL_CONSTRAINT
|
2017-08-02 18:09:14 +02:00
|
|
|
: "A" (control),
|
|
|
|
"b" (input_address_hi),
|
|
|
|
"D"(output_address_hi), "S"(output_address_lo),
|
2018-01-11 21:46:30 +00:00
|
|
|
THUNK_TARGET(hv_hypercall_pg)
|
2017-08-02 18:09:14 +02:00
|
|
|
: "cc", "memory");
|
|
|
|
#endif /* !x86_64 */
|
|
|
|
return hv_status;
|
|
|
|
}
|
2017-02-04 09:57:13 -07:00
|
|
|
|
2017-08-02 18:09:15 +02:00
|
|
|
/* Fast hypercall with 8 bytes of input and no output */
|
2023-01-02 07:12:53 +00:00
|
|
|
static inline u64 _hv_do_fast_hypercall8(u64 control, u64 input1)
|
2017-08-02 18:09:15 +02:00
|
|
|
{
|
2023-01-02 07:12:53 +00:00
|
|
|
u64 hv_status;
|
2017-08-02 18:09:15 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_X86_64
|
x86/hyperv: Introduce a global variable hyperv_paravisor_present
The new variable hyperv_paravisor_present is set only when the VM
is a SNP/TDX VM with the paravisor running: see ms_hyperv_init_platform().
We introduce hyperv_paravisor_present because we can not use
ms_hyperv.paravisor_present in arch/x86/include/asm/mshyperv.h:
struct ms_hyperv_info is defined in include/asm-generic/mshyperv.h, which
is included at the end of arch/x86/include/asm/mshyperv.h, but at the
beginning of arch/x86/include/asm/mshyperv.h, we would already need to use
struct ms_hyperv_info in hv_do_hypercall().
We use hyperv_paravisor_present only in include/asm-generic/mshyperv.h,
and use ms_hyperv.paravisor_present elsewhere. In the future, we'll
introduce a hypercall function structure for different VM types, and
at boot time, the right function pointers would be written into the
structure so that runtime testing of TDX vs. SNP vs. normal will be
avoided and hyperv_paravisor_present will no longer be needed.
Call hv_vtom_init() when it's a VBS VM or when ms_hyperv.paravisor_present
is true, i.e. the VM is a SNP VM or TDX VM with the paravisor.
Enhance hv_vtom_init() for a TDX VM with the paravisor.
In hv_common_cpu_init(), don't decrypt the hyperv_pcpu_input_arg
for a TDX VM with the paravisor, just like we don't decrypt the page
for a SNP VM with the paravisor.
Signed-off-by: Dexuan Cui <decui@microsoft.com>
Reviewed-by: Tianyu Lan <tiala@microsoft.com>
Reviewed-by: Michael Kelley <mikelley@microsoft.com>
Signed-off-by: Wei Liu <wei.liu@kernel.org>
Link: https://lore.kernel.org/r/20230824080712.30327-7-decui@microsoft.com
2023-08-24 01:07:08 -07:00
|
|
|
if (hv_isolation_type_tdx() && !hyperv_paravisor_present)
|
2023-08-24 01:07:04 -07:00
|
|
|
return hv_tdx_hypercall(control, input1, 0);
|
|
|
|
|
2023-08-24 01:07:11 -07:00
|
|
|
if (hv_isolation_type_snp() && !hyperv_paravisor_present) {
|
2023-08-18 06:29:15 -04:00
|
|
|
__asm__ __volatile__(
|
|
|
|
"vmmcall"
|
|
|
|
: "=a" (hv_status), ASM_CALL_CONSTRAINT,
|
|
|
|
"+c" (control), "+d" (input1)
|
|
|
|
:: "cc", "r8", "r9", "r10", "r11");
|
|
|
|
} else {
|
2018-01-11 21:46:30 +00:00
|
|
|
__asm__ __volatile__(CALL_NOSPEC
|
x86/asm: Fix inline asm call constraints for Clang
For inline asm statements which have a CALL instruction, we list the
stack pointer as a constraint to convince GCC to ensure the frame
pointer is set up first:
static inline void foo()
{
register void *__sp asm(_ASM_SP);
asm("call bar" : "+r" (__sp))
}
Unfortunately, that pattern causes Clang to corrupt the stack pointer.
The fix is easy: convert the stack pointer register variable to a global
variable.
It should be noted that the end result is different based on the GCC
version. With GCC 6.4, this patch has exactly the same result as
before:
defconfig defconfig-nofp distro distro-nofp
before 9820389 9491555 8816046 8516940
after 9820389 9491555 8816046 8516940
With GCC 7.2, however, GCC's behavior has changed. It now changes its
behavior based on the conversion of the register variable to a global.
That somehow convinces it to *always* set up the frame pointer before
inserting *any* inline asm. (Therefore, listing the variable as an
output constraint is a no-op and is no longer necessary.) It's a bit
overkill, but the performance impact should be negligible. And in fact,
there's a nice improvement with frame pointers disabled:
defconfig defconfig-nofp distro distro-nofp
before 9796316 9468236 9076191 8790305
after 9796957 9464267 9076381 8785949
So in summary, while listing the stack pointer as an output constraint
is no longer necessary for newer versions of GCC, it's still needed for
older versions.
Suggested-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Reported-by: Matthias Kaehlcke <mka@chromium.org>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Dmitriy Vyukov <dvyukov@google.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Miguel Bernal Marin <miguel.bernal.marin@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/3db862e970c432ae823cf515c52b54fec8270e0e.1505942196.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2017-09-20 16:24:33 -05:00
|
|
|
: "=a" (hv_status), ASM_CALL_CONSTRAINT,
|
2017-08-02 18:09:15 +02:00
|
|
|
"+c" (control), "+d" (input1)
|
2018-01-11 21:46:30 +00:00
|
|
|
: THUNK_TARGET(hv_hypercall_pg)
|
2017-08-02 18:09:15 +02:00
|
|
|
: "cc", "r8", "r9", "r10", "r11");
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
{
|
|
|
|
u32 input1_hi = upper_32_bits(input1);
|
|
|
|
u32 input1_lo = lower_32_bits(input1);
|
|
|
|
|
2018-01-11 21:46:30 +00:00
|
|
|
__asm__ __volatile__ (CALL_NOSPEC
|
2017-08-02 18:09:15 +02:00
|
|
|
: "=A"(hv_status),
|
|
|
|
"+c"(input1_lo),
|
x86/asm: Fix inline asm call constraints for Clang
For inline asm statements which have a CALL instruction, we list the
stack pointer as a constraint to convince GCC to ensure the frame
pointer is set up first:
static inline void foo()
{
register void *__sp asm(_ASM_SP);
asm("call bar" : "+r" (__sp))
}
Unfortunately, that pattern causes Clang to corrupt the stack pointer.
The fix is easy: convert the stack pointer register variable to a global
variable.
It should be noted that the end result is different based on the GCC
version. With GCC 6.4, this patch has exactly the same result as
before:
defconfig defconfig-nofp distro distro-nofp
before 9820389 9491555 8816046 8516940
after 9820389 9491555 8816046 8516940
With GCC 7.2, however, GCC's behavior has changed. It now changes its
behavior based on the conversion of the register variable to a global.
That somehow convinces it to *always* set up the frame pointer before
inserting *any* inline asm. (Therefore, listing the variable as an
output constraint is a no-op and is no longer necessary.) It's a bit
overkill, but the performance impact should be negligible. And in fact,
there's a nice improvement with frame pointers disabled:
defconfig defconfig-nofp distro distro-nofp
before 9796316 9468236 9076191 8790305
after 9796957 9464267 9076381 8785949
So in summary, while listing the stack pointer as an output constraint
is no longer necessary for newer versions of GCC, it's still needed for
older versions.
Suggested-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Reported-by: Matthias Kaehlcke <mka@chromium.org>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Dmitriy Vyukov <dvyukov@google.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Miguel Bernal Marin <miguel.bernal.marin@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/3db862e970c432ae823cf515c52b54fec8270e0e.1505942196.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2017-09-20 16:24:33 -05:00
|
|
|
ASM_CALL_CONSTRAINT
|
2017-08-02 18:09:15 +02:00
|
|
|
: "A" (control),
|
|
|
|
"b" (input1_hi),
|
2018-01-11 21:46:30 +00:00
|
|
|
THUNK_TARGET(hv_hypercall_pg)
|
2017-08-02 18:09:15 +02:00
|
|
|
: "cc", "edi", "esi");
|
|
|
|
}
|
|
|
|
#endif
|
2025-03-21 22:40:14 +00:00
|
|
|
return hv_status;
|
2017-08-02 18:09:15 +02:00
|
|
|
}
|
|
|
|
|
2023-01-02 07:12:53 +00:00
|
|
|
static inline u64 hv_do_fast_hypercall8(u16 code, u64 input1)
|
|
|
|
{
|
|
|
|
u64 control = (u64)code | HV_HYPERCALL_FAST_BIT;
|
|
|
|
|
|
|
|
return _hv_do_fast_hypercall8(control, input1);
|
|
|
|
}
|
|
|
|
|
2018-06-22 19:06:22 +02:00
|
|
|
/* Fast hypercall with 16 bytes of input */
|
2023-01-02 07:12:53 +00:00
|
|
|
static inline u64 _hv_do_fast_hypercall16(u64 control, u64 input1, u64 input2)
|
2018-06-22 19:06:22 +02:00
|
|
|
{
|
2023-01-02 07:12:53 +00:00
|
|
|
u64 hv_status;
|
2018-06-22 19:06:22 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_X86_64
|
x86/hyperv: Introduce a global variable hyperv_paravisor_present
The new variable hyperv_paravisor_present is set only when the VM
is a SNP/TDX VM with the paravisor running: see ms_hyperv_init_platform().
We introduce hyperv_paravisor_present because we can not use
ms_hyperv.paravisor_present in arch/x86/include/asm/mshyperv.h:
struct ms_hyperv_info is defined in include/asm-generic/mshyperv.h, which
is included at the end of arch/x86/include/asm/mshyperv.h, but at the
beginning of arch/x86/include/asm/mshyperv.h, we would already need to use
struct ms_hyperv_info in hv_do_hypercall().
We use hyperv_paravisor_present only in include/asm-generic/mshyperv.h,
and use ms_hyperv.paravisor_present elsewhere. In the future, we'll
introduce a hypercall function structure for different VM types, and
at boot time, the right function pointers would be written into the
structure so that runtime testing of TDX vs. SNP vs. normal will be
avoided and hyperv_paravisor_present will no longer be needed.
Call hv_vtom_init() when it's a VBS VM or when ms_hyperv.paravisor_present
is true, i.e. the VM is a SNP VM or TDX VM with the paravisor.
Enhance hv_vtom_init() for a TDX VM with the paravisor.
In hv_common_cpu_init(), don't decrypt the hyperv_pcpu_input_arg
for a TDX VM with the paravisor, just like we don't decrypt the page
for a SNP VM with the paravisor.
Signed-off-by: Dexuan Cui <decui@microsoft.com>
Reviewed-by: Tianyu Lan <tiala@microsoft.com>
Reviewed-by: Michael Kelley <mikelley@microsoft.com>
Signed-off-by: Wei Liu <wei.liu@kernel.org>
Link: https://lore.kernel.org/r/20230824080712.30327-7-decui@microsoft.com
2023-08-24 01:07:08 -07:00
|
|
|
if (hv_isolation_type_tdx() && !hyperv_paravisor_present)
|
2023-08-24 01:07:04 -07:00
|
|
|
return hv_tdx_hypercall(control, input1, input2);
|
|
|
|
|
2023-08-24 01:07:11 -07:00
|
|
|
if (hv_isolation_type_snp() && !hyperv_paravisor_present) {
|
2025-03-02 17:21:00 -08:00
|
|
|
__asm__ __volatile__("mov %[input2], %%r8\n"
|
2023-08-18 06:29:15 -04:00
|
|
|
"vmmcall"
|
|
|
|
: "=a" (hv_status), ASM_CALL_CONSTRAINT,
|
|
|
|
"+c" (control), "+d" (input1)
|
2025-03-02 17:21:00 -08:00
|
|
|
: [input2] "r" (input2)
|
2023-08-18 06:29:15 -04:00
|
|
|
: "cc", "r8", "r9", "r10", "r11");
|
|
|
|
} else {
|
2025-03-02 17:21:00 -08:00
|
|
|
__asm__ __volatile__("mov %[input2], %%r8\n"
|
2018-06-22 19:06:22 +02:00
|
|
|
CALL_NOSPEC
|
|
|
|
: "=a" (hv_status), ASM_CALL_CONSTRAINT,
|
|
|
|
"+c" (control), "+d" (input1)
|
2025-03-02 17:21:00 -08:00
|
|
|
: [input2] "r" (input2),
|
2018-06-22 19:06:22 +02:00
|
|
|
THUNK_TARGET(hv_hypercall_pg)
|
|
|
|
: "cc", "r8", "r9", "r10", "r11");
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
{
|
|
|
|
u32 input1_hi = upper_32_bits(input1);
|
|
|
|
u32 input1_lo = lower_32_bits(input1);
|
|
|
|
u32 input2_hi = upper_32_bits(input2);
|
|
|
|
u32 input2_lo = lower_32_bits(input2);
|
|
|
|
|
|
|
|
__asm__ __volatile__ (CALL_NOSPEC
|
|
|
|
: "=A"(hv_status),
|
|
|
|
"+c"(input1_lo), ASM_CALL_CONSTRAINT
|
|
|
|
: "A" (control), "b" (input1_hi),
|
|
|
|
"D"(input2_hi), "S"(input2_lo),
|
|
|
|
THUNK_TARGET(hv_hypercall_pg)
|
|
|
|
: "cc");
|
|
|
|
}
|
|
|
|
#endif
|
2018-10-29 15:17:31 +08:00
|
|
|
return hv_status;
|
2018-06-22 19:06:22 +02:00
|
|
|
}
|
|
|
|
|
2023-01-02 07:12:53 +00:00
|
|
|
static inline u64 hv_do_fast_hypercall16(u16 code, u64 input1, u64 input2)
|
|
|
|
{
|
|
|
|
u64 control = (u64)code | HV_HYPERCALL_FAST_BIT;
|
|
|
|
|
|
|
|
return _hv_do_fast_hypercall16(control, input1, input2);
|
|
|
|
}
|
|
|
|
|
2018-03-20 15:02:08 +01:00
|
|
|
extern struct hv_vp_assist_page **hv_vp_assist_page;
|
|
|
|
|
|
|
|
static inline struct hv_vp_assist_page *hv_get_vp_assist_page(unsigned int cpu)
|
|
|
|
{
|
|
|
|
if (!hv_vp_assist_page)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return hv_vp_assist_page[cpu];
|
|
|
|
}
|
2017-08-02 18:09:18 +02:00
|
|
|
|
2018-05-16 14:53:30 -07:00
|
|
|
void __init hyperv_init(void);
|
2017-08-02 18:09:19 +02:00
|
|
|
void hyperv_setup_mmu_ops(void);
|
2018-01-24 14:23:33 +01:00
|
|
|
void set_hv_tscchange_cb(void (*cb)(void));
|
|
|
|
void clear_hv_tscchange_cb(void);
|
|
|
|
void hyperv_stop_tsc_emulation(void);
|
2018-07-19 08:40:06 +00:00
|
|
|
int hyperv_flush_guest_mapping(u64 as);
|
2018-12-06 21:21:05 +08:00
|
|
|
int hyperv_flush_guest_mapping_range(u64 as,
|
|
|
|
hyperv_fill_flush_list_func fill_func, void *data);
|
|
|
|
int hyperv_fill_flush_guest_mapping_list(
|
|
|
|
struct hv_guest_mapping_flush_list *flush,
|
|
|
|
u64 start_gfn, u64 end_gfn);
|
2018-05-19 21:22:48 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_X86_64
|
2018-05-16 14:53:30 -07:00
|
|
|
void hv_apic_init(void);
|
2018-10-08 16:29:34 +08:00
|
|
|
void __init hv_init_spinlocks(void);
|
|
|
|
bool hv_vcpu_is_preempted(int vcpu);
|
2018-05-19 21:22:48 +02:00
|
|
|
#else
|
|
|
|
static inline void hv_apic_init(void) {}
|
|
|
|
#endif
|
|
|
|
|
2021-02-03 15:04:34 +00:00
|
|
|
struct irq_domain *hv_create_pci_msi_domain(void);
|
|
|
|
|
2025-07-11 12:18:51 -07:00
|
|
|
int hv_map_msi_interrupt(struct irq_data *data,
|
|
|
|
struct hv_interrupt_entry *out_entry);
|
2021-02-03 15:04:35 +00:00
|
|
|
int hv_map_ioapic_interrupt(int ioapic_id, bool level, int vcpu, int vector,
|
|
|
|
struct hv_interrupt_entry *entry);
|
|
|
|
int hv_unmap_ioapic_interrupt(int ioapic_id, struct hv_interrupt_entry *entry);
|
2021-10-25 08:21:11 -04:00
|
|
|
|
|
|
|
#ifdef CONFIG_AMD_MEM_ENCRYPT
|
2022-06-13 21:45:53 -04:00
|
|
|
bool hv_ghcb_negotiate_protocol(void);
|
x86/hyperv: Mark hv_ghcb_terminate() as noreturn
Annotate the function prototype and definition as noreturn to prevent
objtool warnings like:
vmlinux.o: warning: objtool: hyperv_init+0x55c: unreachable instruction
Also, as per Josh's suggestion, add it to the global_noreturns list.
As a comparison, an objdump output without the annotation:
[...]
1b63: mov $0x1,%esi
1b68: xor %edi,%edi
1b6a: callq ffffffff8102f680 <hv_ghcb_terminate>
1b6f: jmpq ffffffff82f217ec <hyperv_init+0x9c> # unreachable
1b74: cmpq $0xffffffffffffffff,-0x702a24(%rip)
[...]
Now, after adding the __noreturn to the function prototype:
[...]
17df: callq ffffffff8102f6d0 <hv_ghcb_negotiate_protocol>
17e4: test %al,%al
17e6: je ffffffff82f21bb9 <hyperv_init+0x469>
[...] <many insns>
1bb9: mov $0x1,%esi
1bbe: xor %edi,%edi
1bc0: callq ffffffff8102f680 <hv_ghcb_terminate>
1bc5: nopw %cs:0x0(%rax,%rax,1) # end of function
Reported-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Michael Kelley <mikelley@microsoft.com>
Link: https://lore.kernel.org/r/32453a703dfcf0d007b473c9acbf70718222b74b.1681342859.git.jpoimboe@kernel.org
2023-04-12 16:49:41 -07:00
|
|
|
void __noreturn hv_ghcb_terminate(unsigned int set, unsigned int reason);
|
2025-05-07 11:22:26 -07:00
|
|
|
int hv_snp_boot_ap(u32 apic_id, unsigned long start_ip, unsigned int cpu);
|
2021-10-25 08:21:11 -04:00
|
|
|
#else
|
2022-06-13 21:45:53 -04:00
|
|
|
static inline bool hv_ghcb_negotiate_protocol(void) { return false; }
|
|
|
|
static inline void hv_ghcb_terminate(unsigned int set, unsigned int reason) {}
|
2025-05-07 11:22:26 -07:00
|
|
|
static inline int hv_snp_boot_ap(u32 apic_id, unsigned long start_ip,
|
|
|
|
unsigned int cpu) { return 0; }
|
2021-10-25 08:21:11 -04:00
|
|
|
#endif
|
|
|
|
|
x86/hyperv: Introduce a global variable hyperv_paravisor_present
The new variable hyperv_paravisor_present is set only when the VM
is a SNP/TDX VM with the paravisor running: see ms_hyperv_init_platform().
We introduce hyperv_paravisor_present because we can not use
ms_hyperv.paravisor_present in arch/x86/include/asm/mshyperv.h:
struct ms_hyperv_info is defined in include/asm-generic/mshyperv.h, which
is included at the end of arch/x86/include/asm/mshyperv.h, but at the
beginning of arch/x86/include/asm/mshyperv.h, we would already need to use
struct ms_hyperv_info in hv_do_hypercall().
We use hyperv_paravisor_present only in include/asm-generic/mshyperv.h,
and use ms_hyperv.paravisor_present elsewhere. In the future, we'll
introduce a hypercall function structure for different VM types, and
at boot time, the right function pointers would be written into the
structure so that runtime testing of TDX vs. SNP vs. normal will be
avoided and hyperv_paravisor_present will no longer be needed.
Call hv_vtom_init() when it's a VBS VM or when ms_hyperv.paravisor_present
is true, i.e. the VM is a SNP VM or TDX VM with the paravisor.
Enhance hv_vtom_init() for a TDX VM with the paravisor.
In hv_common_cpu_init(), don't decrypt the hyperv_pcpu_input_arg
for a TDX VM with the paravisor, just like we don't decrypt the page
for a SNP VM with the paravisor.
Signed-off-by: Dexuan Cui <decui@microsoft.com>
Reviewed-by: Tianyu Lan <tiala@microsoft.com>
Reviewed-by: Michael Kelley <mikelley@microsoft.com>
Signed-off-by: Wei Liu <wei.liu@kernel.org>
Link: https://lore.kernel.org/r/20230824080712.30327-7-decui@microsoft.com
2023-08-24 01:07:08 -07:00
|
|
|
#if defined(CONFIG_AMD_MEM_ENCRYPT) || defined(CONFIG_INTEL_TDX_GUEST)
|
|
|
|
void hv_vtom_init(void);
|
2023-08-24 01:07:10 -07:00
|
|
|
void hv_ivm_msr_write(u64 msr, u64 value);
|
|
|
|
void hv_ivm_msr_read(u64 msr, u64 *value);
|
x86/hyperv: Introduce a global variable hyperv_paravisor_present
The new variable hyperv_paravisor_present is set only when the VM
is a SNP/TDX VM with the paravisor running: see ms_hyperv_init_platform().
We introduce hyperv_paravisor_present because we can not use
ms_hyperv.paravisor_present in arch/x86/include/asm/mshyperv.h:
struct ms_hyperv_info is defined in include/asm-generic/mshyperv.h, which
is included at the end of arch/x86/include/asm/mshyperv.h, but at the
beginning of arch/x86/include/asm/mshyperv.h, we would already need to use
struct ms_hyperv_info in hv_do_hypercall().
We use hyperv_paravisor_present only in include/asm-generic/mshyperv.h,
and use ms_hyperv.paravisor_present elsewhere. In the future, we'll
introduce a hypercall function structure for different VM types, and
at boot time, the right function pointers would be written into the
structure so that runtime testing of TDX vs. SNP vs. normal will be
avoided and hyperv_paravisor_present will no longer be needed.
Call hv_vtom_init() when it's a VBS VM or when ms_hyperv.paravisor_present
is true, i.e. the VM is a SNP VM or TDX VM with the paravisor.
Enhance hv_vtom_init() for a TDX VM with the paravisor.
In hv_common_cpu_init(), don't decrypt the hyperv_pcpu_input_arg
for a TDX VM with the paravisor, just like we don't decrypt the page
for a SNP VM with the paravisor.
Signed-off-by: Dexuan Cui <decui@microsoft.com>
Reviewed-by: Tianyu Lan <tiala@microsoft.com>
Reviewed-by: Michael Kelley <mikelley@microsoft.com>
Signed-off-by: Wei Liu <wei.liu@kernel.org>
Link: https://lore.kernel.org/r/20230824080712.30327-7-decui@microsoft.com
2023-08-24 01:07:08 -07:00
|
|
|
#else
|
|
|
|
static inline void hv_vtom_init(void) {}
|
2023-08-24 01:07:10 -07:00
|
|
|
static inline void hv_ivm_msr_write(u64 msr, u64 value) {}
|
|
|
|
static inline void hv_ivm_msr_read(u64 msr, u64 *value) {}
|
x86/hyperv: Introduce a global variable hyperv_paravisor_present
The new variable hyperv_paravisor_present is set only when the VM
is a SNP/TDX VM with the paravisor running: see ms_hyperv_init_platform().
We introduce hyperv_paravisor_present because we can not use
ms_hyperv.paravisor_present in arch/x86/include/asm/mshyperv.h:
struct ms_hyperv_info is defined in include/asm-generic/mshyperv.h, which
is included at the end of arch/x86/include/asm/mshyperv.h, but at the
beginning of arch/x86/include/asm/mshyperv.h, we would already need to use
struct ms_hyperv_info in hv_do_hypercall().
We use hyperv_paravisor_present only in include/asm-generic/mshyperv.h,
and use ms_hyperv.paravisor_present elsewhere. In the future, we'll
introduce a hypercall function structure for different VM types, and
at boot time, the right function pointers would be written into the
structure so that runtime testing of TDX vs. SNP vs. normal will be
avoided and hyperv_paravisor_present will no longer be needed.
Call hv_vtom_init() when it's a VBS VM or when ms_hyperv.paravisor_present
is true, i.e. the VM is a SNP VM or TDX VM with the paravisor.
Enhance hv_vtom_init() for a TDX VM with the paravisor.
In hv_common_cpu_init(), don't decrypt the hyperv_pcpu_input_arg
for a TDX VM with the paravisor, just like we don't decrypt the page
for a SNP VM with the paravisor.
Signed-off-by: Dexuan Cui <decui@microsoft.com>
Reviewed-by: Tianyu Lan <tiala@microsoft.com>
Reviewed-by: Michael Kelley <mikelley@microsoft.com>
Signed-off-by: Wei Liu <wei.liu@kernel.org>
Link: https://lore.kernel.org/r/20230824080712.30327-7-decui@microsoft.com
2023-08-24 01:07:08 -07:00
|
|
|
#endif
|
2021-10-25 08:21:11 -04:00
|
|
|
|
hyperv-tlfs: Change prefix of generic HV_REGISTER_* MSRs to HV_MSR_*
The HV_REGISTER_ are used as arguments to hv_set/get_register(), which
delegate to arch-specific mechanisms for getting/setting synthetic
Hyper-V MSRs.
On arm64, HV_REGISTER_ defines are synthetic VP registers accessed via
the get/set vp registers hypercalls. The naming matches the TLFS
document, although these register names are not specific to arm64.
However, on x86 the prefix HV_REGISTER_ indicates Hyper-V MSRs accessed
via rdmsrl()/wrmsrl(). This is not consistent with the TLFS doc, where
HV_REGISTER_ is *only* used for used for VP register names used by
the get/set register hypercalls.
To fix this inconsistency and prevent future confusion, change the
arch-generic aliases used by callers of hv_set/get_register() to have
the prefix HV_MSR_ instead of HV_REGISTER_.
Use the prefix HV_X64_MSR_ for the x86-only Hyper-V MSRs. On x86, the
generic HV_MSR_'s point to the corresponding HV_X64_MSR_.
Move the arm64 HV_REGISTER_* defines to the asm-generic hyperv-tlfs.h,
since these are not specific to arm64. On arm64, the generic HV_MSR_'s
point to the corresponding HV_REGISTER_.
While at it, rename hv_get/set_registers() and related functions to
hv_get/set_msr(), hv_get/set_nested_msr(), etc. These are only used for
Hyper-V MSRs and this naming makes that clear.
Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
Reviewed-by: Wei Liu <wei.liu@kernel.org>
Reviewed-by: Michael Kelley <mhklinux@outlook.com>
Link: https://lore.kernel.org/r/1708440933-27125-1-git-send-email-nunodasneves@linux.microsoft.com
Signed-off-by: Wei Liu <wei.liu@kernel.org>
Message-ID: <1708440933-27125-1-git-send-email-nunodasneves@linux.microsoft.com>
2024-02-20 06:55:33 -08:00
|
|
|
static inline bool hv_is_synic_msr(unsigned int reg)
|
2021-10-25 08:21:11 -04:00
|
|
|
{
|
hyperv-tlfs: Change prefix of generic HV_REGISTER_* MSRs to HV_MSR_*
The HV_REGISTER_ are used as arguments to hv_set/get_register(), which
delegate to arch-specific mechanisms for getting/setting synthetic
Hyper-V MSRs.
On arm64, HV_REGISTER_ defines are synthetic VP registers accessed via
the get/set vp registers hypercalls. The naming matches the TLFS
document, although these register names are not specific to arm64.
However, on x86 the prefix HV_REGISTER_ indicates Hyper-V MSRs accessed
via rdmsrl()/wrmsrl(). This is not consistent with the TLFS doc, where
HV_REGISTER_ is *only* used for used for VP register names used by
the get/set register hypercalls.
To fix this inconsistency and prevent future confusion, change the
arch-generic aliases used by callers of hv_set/get_register() to have
the prefix HV_MSR_ instead of HV_REGISTER_.
Use the prefix HV_X64_MSR_ for the x86-only Hyper-V MSRs. On x86, the
generic HV_MSR_'s point to the corresponding HV_X64_MSR_.
Move the arm64 HV_REGISTER_* defines to the asm-generic hyperv-tlfs.h,
since these are not specific to arm64. On arm64, the generic HV_MSR_'s
point to the corresponding HV_REGISTER_.
While at it, rename hv_get/set_registers() and related functions to
hv_get/set_msr(), hv_get/set_nested_msr(), etc. These are only used for
Hyper-V MSRs and this naming makes that clear.
Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
Reviewed-by: Wei Liu <wei.liu@kernel.org>
Reviewed-by: Michael Kelley <mhklinux@outlook.com>
Link: https://lore.kernel.org/r/1708440933-27125-1-git-send-email-nunodasneves@linux.microsoft.com
Signed-off-by: Wei Liu <wei.liu@kernel.org>
Message-ID: <1708440933-27125-1-git-send-email-nunodasneves@linux.microsoft.com>
2024-02-20 06:55:33 -08:00
|
|
|
return (reg >= HV_X64_MSR_SCONTROL) &&
|
|
|
|
(reg <= HV_X64_MSR_SINT15);
|
2023-02-09 14:02:52 -08:00
|
|
|
}
|
|
|
|
|
hyperv-tlfs: Change prefix of generic HV_REGISTER_* MSRs to HV_MSR_*
The HV_REGISTER_ are used as arguments to hv_set/get_register(), which
delegate to arch-specific mechanisms for getting/setting synthetic
Hyper-V MSRs.
On arm64, HV_REGISTER_ defines are synthetic VP registers accessed via
the get/set vp registers hypercalls. The naming matches the TLFS
document, although these register names are not specific to arm64.
However, on x86 the prefix HV_REGISTER_ indicates Hyper-V MSRs accessed
via rdmsrl()/wrmsrl(). This is not consistent with the TLFS doc, where
HV_REGISTER_ is *only* used for used for VP register names used by
the get/set register hypercalls.
To fix this inconsistency and prevent future confusion, change the
arch-generic aliases used by callers of hv_set/get_register() to have
the prefix HV_MSR_ instead of HV_REGISTER_.
Use the prefix HV_X64_MSR_ for the x86-only Hyper-V MSRs. On x86, the
generic HV_MSR_'s point to the corresponding HV_X64_MSR_.
Move the arm64 HV_REGISTER_* defines to the asm-generic hyperv-tlfs.h,
since these are not specific to arm64. On arm64, the generic HV_MSR_'s
point to the corresponding HV_REGISTER_.
While at it, rename hv_get/set_registers() and related functions to
hv_get/set_msr(), hv_get/set_nested_msr(), etc. These are only used for
Hyper-V MSRs and this naming makes that clear.
Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
Reviewed-by: Wei Liu <wei.liu@kernel.org>
Reviewed-by: Michael Kelley <mhklinux@outlook.com>
Link: https://lore.kernel.org/r/1708440933-27125-1-git-send-email-nunodasneves@linux.microsoft.com
Signed-off-by: Wei Liu <wei.liu@kernel.org>
Message-ID: <1708440933-27125-1-git-send-email-nunodasneves@linux.microsoft.com>
2024-02-20 06:55:33 -08:00
|
|
|
static inline bool hv_is_sint_msr(unsigned int reg)
|
2023-02-09 14:02:52 -08:00
|
|
|
{
|
hyperv-tlfs: Change prefix of generic HV_REGISTER_* MSRs to HV_MSR_*
The HV_REGISTER_ are used as arguments to hv_set/get_register(), which
delegate to arch-specific mechanisms for getting/setting synthetic
Hyper-V MSRs.
On arm64, HV_REGISTER_ defines are synthetic VP registers accessed via
the get/set vp registers hypercalls. The naming matches the TLFS
document, although these register names are not specific to arm64.
However, on x86 the prefix HV_REGISTER_ indicates Hyper-V MSRs accessed
via rdmsrl()/wrmsrl(). This is not consistent with the TLFS doc, where
HV_REGISTER_ is *only* used for used for VP register names used by
the get/set register hypercalls.
To fix this inconsistency and prevent future confusion, change the
arch-generic aliases used by callers of hv_set/get_register() to have
the prefix HV_MSR_ instead of HV_REGISTER_.
Use the prefix HV_X64_MSR_ for the x86-only Hyper-V MSRs. On x86, the
generic HV_MSR_'s point to the corresponding HV_X64_MSR_.
Move the arm64 HV_REGISTER_* defines to the asm-generic hyperv-tlfs.h,
since these are not specific to arm64. On arm64, the generic HV_MSR_'s
point to the corresponding HV_REGISTER_.
While at it, rename hv_get/set_registers() and related functions to
hv_get/set_msr(), hv_get/set_nested_msr(), etc. These are only used for
Hyper-V MSRs and this naming makes that clear.
Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
Reviewed-by: Wei Liu <wei.liu@kernel.org>
Reviewed-by: Michael Kelley <mhklinux@outlook.com>
Link: https://lore.kernel.org/r/1708440933-27125-1-git-send-email-nunodasneves@linux.microsoft.com
Signed-off-by: Wei Liu <wei.liu@kernel.org>
Message-ID: <1708440933-27125-1-git-send-email-nunodasneves@linux.microsoft.com>
2024-02-20 06:55:33 -08:00
|
|
|
return (reg >= HV_X64_MSR_SINT0) &&
|
|
|
|
(reg <= HV_X64_MSR_SINT15);
|
2021-10-25 08:21:11 -04:00
|
|
|
}
|
|
|
|
|
hyperv-tlfs: Change prefix of generic HV_REGISTER_* MSRs to HV_MSR_*
The HV_REGISTER_ are used as arguments to hv_set/get_register(), which
delegate to arch-specific mechanisms for getting/setting synthetic
Hyper-V MSRs.
On arm64, HV_REGISTER_ defines are synthetic VP registers accessed via
the get/set vp registers hypercalls. The naming matches the TLFS
document, although these register names are not specific to arm64.
However, on x86 the prefix HV_REGISTER_ indicates Hyper-V MSRs accessed
via rdmsrl()/wrmsrl(). This is not consistent with the TLFS doc, where
HV_REGISTER_ is *only* used for used for VP register names used by
the get/set register hypercalls.
To fix this inconsistency and prevent future confusion, change the
arch-generic aliases used by callers of hv_set/get_register() to have
the prefix HV_MSR_ instead of HV_REGISTER_.
Use the prefix HV_X64_MSR_ for the x86-only Hyper-V MSRs. On x86, the
generic HV_MSR_'s point to the corresponding HV_X64_MSR_.
Move the arm64 HV_REGISTER_* defines to the asm-generic hyperv-tlfs.h,
since these are not specific to arm64. On arm64, the generic HV_MSR_'s
point to the corresponding HV_REGISTER_.
While at it, rename hv_get/set_registers() and related functions to
hv_get/set_msr(), hv_get/set_nested_msr(), etc. These are only used for
Hyper-V MSRs and this naming makes that clear.
Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
Reviewed-by: Wei Liu <wei.liu@kernel.org>
Reviewed-by: Michael Kelley <mhklinux@outlook.com>
Link: https://lore.kernel.org/r/1708440933-27125-1-git-send-email-nunodasneves@linux.microsoft.com
Signed-off-by: Wei Liu <wei.liu@kernel.org>
Message-ID: <1708440933-27125-1-git-send-email-nunodasneves@linux.microsoft.com>
2024-02-20 06:55:33 -08:00
|
|
|
u64 hv_get_msr(unsigned int reg);
|
|
|
|
void hv_set_msr(unsigned int reg, u64 value);
|
|
|
|
u64 hv_get_non_nested_msr(unsigned int reg);
|
|
|
|
void hv_set_non_nested_msr(unsigned int reg, u64 value);
|
2021-10-25 08:21:11 -04:00
|
|
|
|
hyperv-tlfs: Change prefix of generic HV_REGISTER_* MSRs to HV_MSR_*
The HV_REGISTER_ are used as arguments to hv_set/get_register(), which
delegate to arch-specific mechanisms for getting/setting synthetic
Hyper-V MSRs.
On arm64, HV_REGISTER_ defines are synthetic VP registers accessed via
the get/set vp registers hypercalls. The naming matches the TLFS
document, although these register names are not specific to arm64.
However, on x86 the prefix HV_REGISTER_ indicates Hyper-V MSRs accessed
via rdmsrl()/wrmsrl(). This is not consistent with the TLFS doc, where
HV_REGISTER_ is *only* used for used for VP register names used by
the get/set register hypercalls.
To fix this inconsistency and prevent future confusion, change the
arch-generic aliases used by callers of hv_set/get_register() to have
the prefix HV_MSR_ instead of HV_REGISTER_.
Use the prefix HV_X64_MSR_ for the x86-only Hyper-V MSRs. On x86, the
generic HV_MSR_'s point to the corresponding HV_X64_MSR_.
Move the arm64 HV_REGISTER_* defines to the asm-generic hyperv-tlfs.h,
since these are not specific to arm64. On arm64, the generic HV_MSR_'s
point to the corresponding HV_REGISTER_.
While at it, rename hv_get/set_registers() and related functions to
hv_get/set_msr(), hv_get/set_nested_msr(), etc. These are only used for
Hyper-V MSRs and this naming makes that clear.
Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
Reviewed-by: Wei Liu <wei.liu@kernel.org>
Reviewed-by: Michael Kelley <mhklinux@outlook.com>
Link: https://lore.kernel.org/r/1708440933-27125-1-git-send-email-nunodasneves@linux.microsoft.com
Signed-off-by: Wei Liu <wei.liu@kernel.org>
Message-ID: <1708440933-27125-1-git-send-email-nunodasneves@linux.microsoft.com>
2024-02-20 06:55:33 -08:00
|
|
|
static __always_inline u64 hv_raw_get_msr(unsigned int reg)
|
2023-05-19 12:21:08 +02:00
|
|
|
{
|
x86/msr: Convert __rdmsr() uses to native_rdmsrq() uses
__rdmsr() is the lowest level MSR write API, with native_rdmsr()
and native_rdmsrq() serving as higher-level wrappers around it.
#define native_rdmsr(msr, val1, val2) \
do { \
u64 __val = __rdmsr((msr)); \
(void)((val1) = (u32)__val); \
(void)((val2) = (u32)(__val >> 32)); \
} while (0)
static __always_inline u64 native_rdmsrq(u32 msr)
{
return __rdmsr(msr);
}
However, __rdmsr() continues to be utilized in various locations.
MSR APIs are designed for different scenarios, such as native or
pvops, with or without trace, and safe or non-safe. Unfortunately,
the current MSR API names do not adequately reflect these factors,
making it challenging to select the most appropriate API for
various situations.
To pave the way for improving MSR API names, convert __rdmsr()
uses to native_rdmsrq() to ensure consistent usage. Later, these
APIs can be renamed to better reflect their implications, such as
native or pvops, with or without trace, and safe or non-safe.
No functional change intended.
Signed-off-by: Xin Li (Intel) <xin@zytor.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>
Cc: Uros Bizjak <ubizjak@gmail.com>
Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
Link: https://lore.kernel.org/r/20250427092027.1598740-10-xin@zytor.com
2025-04-27 02:20:21 -07:00
|
|
|
return native_rdmsrq(reg);
|
2023-05-19 12:21:08 +02:00
|
|
|
}
|
2025-05-07 11:22:25 -07:00
|
|
|
int hv_apicid_to_vp_index(u32 apic_id);
|
2023-05-19 12:21:08 +02:00
|
|
|
|
2017-08-02 18:09:13 +02:00
|
|
|
#else /* CONFIG_HYPERV */
|
|
|
|
static inline void hyperv_init(void) {}
|
2017-08-02 18:09:19 +02:00
|
|
|
static inline void hyperv_setup_mmu_ops(void) {}
|
2018-01-24 14:23:33 +01:00
|
|
|
static inline void set_hv_tscchange_cb(void (*cb)(void)) {}
|
|
|
|
static inline void clear_hv_tscchange_cb(void) {}
|
|
|
|
static inline void hyperv_stop_tsc_emulation(void) {};
|
2018-03-20 15:02:08 +01:00
|
|
|
static inline struct hv_vp_assist_page *hv_get_vp_assist_page(unsigned int cpu)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-07-19 08:40:06 +00:00
|
|
|
static inline int hyperv_flush_guest_mapping(u64 as) { return -1; }
|
2018-12-06 21:21:05 +08:00
|
|
|
static inline int hyperv_flush_guest_mapping_range(u64 as,
|
|
|
|
hyperv_fill_flush_list_func fill_func, void *data)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
hyperv-tlfs: Change prefix of generic HV_REGISTER_* MSRs to HV_MSR_*
The HV_REGISTER_ are used as arguments to hv_set/get_register(), which
delegate to arch-specific mechanisms for getting/setting synthetic
Hyper-V MSRs.
On arm64, HV_REGISTER_ defines are synthetic VP registers accessed via
the get/set vp registers hypercalls. The naming matches the TLFS
document, although these register names are not specific to arm64.
However, on x86 the prefix HV_REGISTER_ indicates Hyper-V MSRs accessed
via rdmsrl()/wrmsrl(). This is not consistent with the TLFS doc, where
HV_REGISTER_ is *only* used for used for VP register names used by
the get/set register hypercalls.
To fix this inconsistency and prevent future confusion, change the
arch-generic aliases used by callers of hv_set/get_register() to have
the prefix HV_MSR_ instead of HV_REGISTER_.
Use the prefix HV_X64_MSR_ for the x86-only Hyper-V MSRs. On x86, the
generic HV_MSR_'s point to the corresponding HV_X64_MSR_.
Move the arm64 HV_REGISTER_* defines to the asm-generic hyperv-tlfs.h,
since these are not specific to arm64. On arm64, the generic HV_MSR_'s
point to the corresponding HV_REGISTER_.
While at it, rename hv_get/set_registers() and related functions to
hv_get/set_msr(), hv_get/set_nested_msr(), etc. These are only used for
Hyper-V MSRs and this naming makes that clear.
Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
Reviewed-by: Wei Liu <wei.liu@kernel.org>
Reviewed-by: Michael Kelley <mhklinux@outlook.com>
Link: https://lore.kernel.org/r/1708440933-27125-1-git-send-email-nunodasneves@linux.microsoft.com
Signed-off-by: Wei Liu <wei.liu@kernel.org>
Message-ID: <1708440933-27125-1-git-send-email-nunodasneves@linux.microsoft.com>
2024-02-20 06:55:33 -08:00
|
|
|
static inline void hv_set_msr(unsigned int reg, u64 value) { }
|
|
|
|
static inline u64 hv_get_msr(unsigned int reg) { return 0; }
|
|
|
|
static inline void hv_set_non_nested_msr(unsigned int reg, u64 value) { }
|
|
|
|
static inline u64 hv_get_non_nested_msr(unsigned int reg) { return 0; }
|
2025-05-07 11:22:25 -07:00
|
|
|
static inline int hv_apicid_to_vp_index(u32 apic_id) { return -EINVAL; }
|
2017-08-02 18:09:13 +02:00
|
|
|
#endif /* CONFIG_HYPERV */
|
|
|
|
|
2019-05-30 00:14:00 +00:00
|
|
|
|
2023-04-10 22:55:32 -07:00
|
|
|
#ifdef CONFIG_HYPERV_VTL_MODE
|
|
|
|
void __init hv_vtl_init_platform(void);
|
2023-09-21 21:58:40 -07:00
|
|
|
int __init hv_vtl_early_init(void);
|
2023-04-10 22:55:32 -07:00
|
|
|
#else
|
|
|
|
static inline void __init hv_vtl_init_platform(void) {}
|
2023-09-21 21:58:40 -07:00
|
|
|
static inline int __init hv_vtl_early_init(void) { return 0; }
|
2023-04-10 22:55:32 -07:00
|
|
|
#endif
|
|
|
|
|
2019-05-30 00:14:00 +00:00
|
|
|
#include <asm-generic/mshyperv.h>
|
|
|
|
|
2010-05-06 12:08:41 -07:00
|
|
|
#endif
|