Lines Matching +full:ia32 +full:- +full:3 +full:a

1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2021-2022 Intel Corporation */
14 #include <asm/ia32.h>
16 #include <asm/insn-eval.h>
31 #define VE_IS_IO_IN(e) ((e) & BIT(3))
37 #define TDCALL_RETURN_CODE(a) ((a) >> 32) argument
80 /* Read TD-scoped metadata */
94 /* Write TD-scoped metadata */
107 * tdx_mcall_get_report0() - Wrapper to get TDREPORT0 (a.k.a. TDREPORT
109 * @reportdata: Address of the input buffer which contains user-defined
118 * Return 0 on success, -ENXIO for invalid operands, -EBUSY for busy operation,
119 * or -EIO on other TDCALL failures.
133 return -ENXIO; in tdx_mcall_get_report0()
135 return -EBUSY; in tdx_mcall_get_report0()
136 return -EIO; in tdx_mcall_get_report0()
144 * tdx_mcall_extend_rtmr() - Wrapper to extend RTMR registers using
155 * Return 0 on success, -ENXIO for invalid operands, -EBUSY for busy operation,
156 * or -EIO on other TDCALL failures.
169 return -ENXIO; in tdx_mcall_extend_rtmr()
171 return -EBUSY; in tdx_mcall_extend_rtmr()
172 return -EIO; in tdx_mcall_extend_rtmr()
180 * tdx_hcall_get_quote() - Wrapper to request TD Quote using GetQuote
185 * @size: size of the tdquote buffer (4KB-aligned).
195 /* Since buf is a shared memory, set the shared (decrypted) bits */ in tdx_hcall_get_quote()
237 * that no #VE will be delivered for accesses to TD-private memory.
290 * TDX 1.0 generates a #VE when accessing topology-related CPUID leafs (0xB and
292 * In practice, this means that the kernel can only boot with a plain topology.
296 * Enabling the feature eliminates topology-related #VEs: the TDX module
305 /* Has the VMM provided a valid topology configuration? */ in enable_cpu_topology_enumeration()
339 * Guest-Host-Communication Interface (GHCI), section 2.4.2 TDCALL in tdx_setup()
345 * The highest bit of a guest physical address is the "sharing" bit. in tdx_setup()
352 *cc_mask = BIT_ULL(gpa_width - 1); in tdx_setup()
357 tdg_vm_wr(TDCS_NOTIFY_ENABLES, 0, -1ULL); in tdx_setup()
365 * The TDX module spec states that #VE may be injected for a limited set of
368 * - Emulation of the architectural #VE injection on EPT violation;
370 * - As a result of guest TD execution of a disallowed instruction,
371 * a disallowed MSR access, or CPUID virtualization;
373 * - A notification to the guest TD about anomalous behavior;
375 * The last one is opt-in and is not used by the kernel.
387 switch (ve->exit_reason) { in ve_instr_len()
393 /* It is safe to use ve->instr_len for #VE due instructions */ in ve_instr_len()
394 return ve->instr_len; in ve_instr_len()
397 * For EPT violations, ve->insn_len is not defined. For those, in ve_instr_len()
401 WARN_ONCE(1, "ve->instr_len is not defined for EPT violations"); in ve_instr_len()
404 WARN_ONCE(1, "Unexpected #VE-type: %lld\n", ve->exit_reason); in ve_instr_len()
405 return ve->instr_len; in ve_instr_len()
419 * can be found in TDX Guest-Host-Communication Interface in __halt()
437 * HLT with IRQs enabled is unsafe, as an IRQ that is intended to be a in handle_halt()
442 return -EIO; in handle_halt()
445 return -EIO; in handle_halt()
476 .r12 = regs->cx, in read_msr()
481 * can be found in TDX Guest-Host-Communication Interface in read_msr()
485 return -EIO; in read_msr()
487 regs->ax = lower_32_bits(args.r11); in read_msr()
488 regs->dx = upper_32_bits(args.r11); in read_msr()
497 .r12 = regs->cx, in write_msr()
498 .r13 = (u64)regs->dx << 32 | regs->ax, in write_msr()
503 * can be found in TDX Guest-Host-Communication Interface in write_msr()
507 return -EIO; in write_msr()
517 .r12 = regs->ax, in handle_cpuid()
518 .r13 = regs->cx, in handle_cpuid()
525 * Return all-zeros for any CPUID outside the range. It matches CPU in handle_cpuid()
526 * behaviour for non-supported leaf. in handle_cpuid()
528 if (regs->ax < 0x40000000 || regs->ax > 0x4FFFFFFF) { in handle_cpuid()
529 regs->ax = regs->bx = regs->cx = regs->dx = 0; in handle_cpuid()
534 * Emulate the CPUID instruction via a hypercall. More info about in handle_cpuid()
535 * ABI can be found in TDX Guest-Host-Communication Interface in handle_cpuid()
539 return -EIO; in handle_cpuid()
542 * As per TDX GHCI CPUID ABI, r12-r15 registers contain contents of in handle_cpuid()
546 regs->ax = args.r12; in handle_cpuid()
547 regs->bx = args.r13; in handle_cpuid()
548 regs->cx = args.r14; in handle_cpuid()
549 regs->dx = args.r15; in handle_cpuid()
586 /* Only in-kernel MMIO is supported */ in handle_mmio()
588 return -EFAULT; in handle_mmio()
590 if (copy_from_kernel_nofault(buffer, (void *)regs->ip, MAX_INSN_SIZE)) in handle_mmio()
591 return -EFAULT; in handle_mmio()
594 return -EINVAL; in handle_mmio()
598 return -EINVAL; in handle_mmio()
603 return -EINVAL; in handle_mmio()
606 if (!fault_in_kernel_space(ve->gla)) { in handle_mmio()
608 return -EINVAL; in handle_mmio()
616 * a bug or a load_unaligned_zeropad() that stepped into an MMIO page. in handle_mmio()
621 if (vaddr / PAGE_SIZE != (vaddr + size - 1) / PAGE_SIZE) in handle_mmio()
622 return -EFAULT; in handle_mmio()
628 if (!mmio_write(size, ve->gpa, val)) in handle_mmio()
629 return -EIO; in handle_mmio()
633 if (!mmio_write(size, ve->gpa, val)) in handle_mmio()
634 return -EIO; in handle_mmio()
648 return -EINVAL; in handle_mmio()
651 return -EINVAL; in handle_mmio()
655 if (!mmio_read(size, ve->gpa, &val)) in handle_mmio()
656 return -EIO; in handle_mmio()
660 /* Zero-extend for 32-bit operation */ in handle_mmio()
678 return -EINVAL; in handle_mmio()
701 * in TDX Guest-Host-Communication Interface (GHCI) section titled in handle_in()
707 regs->ax &= ~mask; in handle_in()
709 regs->ax |= args.r11 & mask; in handle_in()
720 * in TDX Guest-Host-Communication Interface (GHCI) section titled in handle_out()
724 PORT_WRITE, port, regs->ax & mask); in handle_out()
737 u32 exit_qual = ve->exit_qual; in handle_io()
742 return -EIO; in handle_io()
754 return -EIO; in handle_io()
760 * Early #VE exception handler. Only handles a subset of port I/O.
777 regs->ip += insn_len; in tdx_early_handle_ve()
789 * This has to be called early in #VE handling. A "nested" #VE which in tdx_get_ve_info()
790 * occurs before this will raise a #DF and is not recoverable. in tdx_get_ve_info()
798 * valid flag is set. It means that NMI=>#VE will not result in a #DF. in tdx_get_ve_info()
803 ve->exit_reason = args.rcx; in tdx_get_ve_info()
804 ve->exit_qual = args.rdx; in tdx_get_ve_info()
805 ve->gla = args.r8; in tdx_get_ve_info()
806 ve->gpa = args.r9; in tdx_get_ve_info()
807 ve->instr_len = lower_32_bits(args.r10); in tdx_get_ve_info()
808 ve->instr_info = upper_32_bits(args.r10); in tdx_get_ve_info()
815 * or -errno on error.
819 switch (ve->exit_reason) { in virt_exception_user()
823 pr_warn("Unexpected #VE: %lld\n", ve->exit_reason); in virt_exception_user()
824 return -EIO; in virt_exception_user()
837 * or -errno on error.
841 switch (ve->exit_reason) { in virt_exception_kernel()
851 if (is_private_gpa(ve->gpa)) in virt_exception_kernel()
852 panic("Unexpected EPT-violation on private memory."); in virt_exception_kernel()
857 pr_warn("Unexpected #VE: %lld\n", ve->exit_reason); in virt_exception_kernel()
858 return -EIO; in virt_exception_kernel()
874 regs->ip += insn_len; in tdx_handle_virt_exception()
882 * TDX guest is responsible for flushing TLB on private->shared in tdx_tlb_flush_required()
883 * transition. VMM is responsible for flushing on shared->private. in tdx_tlb_flush_required()
891 * flush to avoid integrity failures in the face of a buggy or in tdx_tlb_flush_required()
910 * can be found in TDX Guest-Host-Communication Interface (GHCI),
915 /* Retrying the hypercall a second time should succeed; use 3 just in case */ in tdx_map_gpa()
916 const int max_retries_per_page = 3; in tdx_map_gpa()
930 .r13 = end - start }; in tdx_map_gpa()
946 /* "Consume" a retry without forward progress */ in tdx_map_gpa()
972 /* shared->private conversion requires memory to be accepted before use */ in tdx_enc_status_changed()
983 * Only handle shared->private conversion here. in tdx_enc_status_change_prepare()
987 return -EIO; in tdx_enc_status_change_prepare()
996 * Only handle private->shared conversion here. in tdx_enc_status_change_finish()
1000 return -EIO; in tdx_enc_status_change_finish()
1010 /* Stop new private<->shared conversions */
1023 pr_warn("Failed to stop shared<->private conversions\n"); in tdx_kexec_begin()
1066 * *next* kernel through a private mapping will result in tdx_kexec_finish()
1070 * a pre-reserved memory range that is always private. in tdx_kexec_finish()
1072 * a crash if it accesses unconverted memory through in tdx_kexec_finish()
1073 * a private mapping which is possible when accessing in tdx_kexec_finish()
1080 pr_err("Failed to unshare range %#lx-%#lx\n", in tdx_kexec_finish()
1116 u32 eax, sig[3]; in tdx_early_init()
1141 physical_mask &= cc_mask - 1; in tdx_early_init()
1149 * - Private mapping => Shared Page == Guest shutdown in tdx_early_init()
1150 * - Shared mapping => Private Page == Recoverable #VE in tdx_early_init()
1158 * In both cases there is a temporary shared mapping to a private page, in tdx_early_init()
1159 * which can result in a #VE. But, there is never a private mapping to in tdx_early_init()
1160 * a shared page. in tdx_early_init()
1172 * Avoid "sti;hlt" execution in TDX guests as HLT induces a #VE that in tdx_early_init()
1174 * in STI-shadow, possibly resulting in missed wakeup events. in tdx_early_init()
1179 * in addition to having a reliable halt logic execution. in tdx_early_init()
1189 * Intel-TDX has a secure RDMSR hypercall, but that needs to be in tdx_early_init()