Lines Matching +full:0 +full:x40000000 +full:- +full:0 +full:x4fffffff

1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2021-2022 Intel Corporation */
16 #include <asm/insn-eval.h>
22 #define EPT_READ 0
26 #define PORT_READ 0
31 #define VE_GET_IO_SIZE(e) (((e) & GENMASK(2, 0)) + 1)
37 #define TDCALL_INVALID_OPERAND 0xc0000100
39 #define TDREPORT_SUBTYPE_0 0
78 /* Read TD-scoped metadata */
92 /* Write TD-scoped metadata */
105 * tdx_mcall_get_report0() - Wrapper to get TDREPORT0 (a.k.a. TDREPORT
106 * subtype 0) using TDG.MR.REPORT TDCALL.
107 * @reportdata: Address of the input buffer which contains user-defined
112 * v1.0 specification for more information on TDG.MR.REPORT TDCALL.
115 * Return 0 on success, -EINVAL for invalid operands, or -EIO on
130 return -EINVAL;
131 return -EIO;
134 return 0;
139 * tdx_hcall_get_quote() - Wrapper to request TD Quote using GetQuote
144 * @size: size of the tdquote buffer (4KB-aligned).
147 * v1.0 specification for more information on GetQuote hypercall.
150 * Return 0 on success or error code on failure.
155 return _tdx_hypercall(TDVMCALL_GET_QUOTE, cc_mkdec(virt_to_phys(buf)), size, 0, 0);
164 .r12 = 0, /* Error code: 0 is Panic */
173 /* VMM assumes '\0' in byte 65, if the message took all 64 bytes */
174 strtomem_pad(message.str, msg, '\0');
196 * that no #VE will be delivered for accesses to TD-private memory.
249 * TDX 1.0 generates a #VE when accessing topology-related CPUID leafs (0xB and
250 * 0x1F) and the X2APIC_APICID MSR. The kernel returns all zeros on CPUID #VEs.
255 * Enabling the feature eliminates topology-related #VEs: the TDX module
298 * Guest-Host-Communication Interface (GHCI), section 2.4.2 TDCALL
310 gpa_width = args.rcx & GENMASK(5, 0);
311 *cc_mask = BIT_ULL(gpa_width - 1);
316 tdg_vm_wr(TDCS_NOTIFY_ENABLES, 0, -1ULL);
327 * - Emulation of the architectural #VE injection on EPT violation;
329 * - As a result of guest TD execution of a disallowed instruction,
332 * - A notification to the guest TD about anomalous behavior;
334 * The last one is opt-in and is not used by the kernel.
346 switch (ve->exit_reason) {
352 /* It is safe to use ve->instr_len for #VE due instructions */
353 return ve->instr_len;
356 * For EPT violations, ve->insn_len is not defined. For those,
360 WARN_ONCE(1, "ve->instr_len is not defined for EPT violations");
361 return 0;
363 WARN_ONCE(1, "Unexpected #VE-type: %lld\n", ve->exit_reason);
364 return ve->instr_len;
378 * can be found in TDX Guest-Host-Communication Interface
396 return -EIO;
417 .r12 = regs->cx,
422 * can be found in TDX Guest-Host-Communication Interface
426 return -EIO;
428 regs->ax = lower_32_bits(args.r11);
429 regs->dx = upper_32_bits(args.r11);
438 .r12 = regs->cx,
439 .r13 = (u64)regs->dx << 32 | regs->ax,
444 * can be found in TDX Guest-Host-Communication Interface
448 return -EIO;
458 .r12 = regs->ax,
459 .r13 = regs->cx,
466 * Return all-zeros for any CPUID outside the range. It matches CPU
467 * behaviour for non-supported leaf.
469 if (regs->ax < 0x40000000 || regs->ax > 0x4FFFFFFF) {
470 regs->ax = regs->bx = regs->cx = regs->dx = 0;
476 * ABI can be found in TDX Guest-Host-Communication Interface
480 return -EIO;
483 * As per TDX GHCI CPUID ABI, r12-r15 registers contain contents of
487 regs->ax = args.r12;
488 regs->bx = args.r13;
489 regs->cx = args.r14;
490 regs->dx = args.r15;
525 u8 extend_val = 0;
527 /* Only in-kernel MMIO is supported */
529 return -EFAULT;
531 if (copy_from_kernel_nofault(buffer, (void *)regs->ip, MAX_INSN_SIZE))
532 return -EFAULT;
535 return -EINVAL;
539 return -EINVAL;
544 return -EINVAL;
547 if (!fault_in_kernel_space(ve->gla)) {
549 return -EINVAL;
562 if (vaddr / PAGE_SIZE != (vaddr + size - 1) / PAGE_SIZE)
563 return -EFAULT;
569 if (!mmio_write(size, ve->gpa, val))
570 return -EIO;
574 if (!mmio_write(size, ve->gpa, val))
575 return -EIO;
589 return -EINVAL;
592 return -EINVAL;
596 if (!mmio_read(size, ve->gpa, &val))
597 return -EIO;
601 /* Zero-extend for 32-bit operation */
602 extend_size = size == 4 ? sizeof(*reg) : 0;
612 extend_val = 0xFF;
614 extend_val = 0xFF;
619 return -EINVAL;
637 u64 mask = GENMASK(BITS_PER_BYTE * size, 0);
642 * in TDX Guest-Host-Communication Interface (GHCI) section titled
648 regs->ax &= ~mask;
650 regs->ax |= args.r11 & mask;
657 u64 mask = GENMASK(BITS_PER_BYTE * size, 0);
661 * in TDX Guest-Host-Communication Interface (GHCI) section titled
665 PORT_WRITE, port, regs->ax & mask);
678 u32 exit_qual = ve->exit_qual;
683 return -EIO;
695 return -EIO;
715 if (insn_len < 0)
718 regs->ip += insn_len;
744 ve->exit_reason = args.rcx;
745 ve->exit_qual = args.rdx;
746 ve->gla = args.r8;
747 ve->gpa = args.r9;
748 ve->instr_len = lower_32_bits(args.r10);
749 ve->instr_info = upper_32_bits(args.r10);
755 * On success, returns the number of bytes RIP should be incremented (>=0)
756 * or -errno on error.
760 switch (ve->exit_reason) {
764 pr_warn("Unexpected #VE: %lld\n", ve->exit_reason);
765 return -EIO;
777 * On success, returns the number of bytes RIP should be incremented (>=0)
778 * or -errno on error.
782 switch (ve->exit_reason) {
792 if (is_private_gpa(ve->gpa))
793 panic("Unexpected EPT-violation on private memory.");
798 pr_warn("Unexpected #VE: %lld\n", ve->exit_reason);
799 return -EIO;
811 if (insn_len < 0)
815 regs->ip += insn_len;
823 * TDX guest is responsible for flushing TLB on private->shared
824 * transition. VMM is responsible for flushing on shared->private.
851 * can be found in TDX Guest-Host-Communication Interface (GHCI),
858 int retry_count = 0;
862 start |= cc_mkdec(0);
863 end |= cc_mkdec(0);
871 .r13 = end - start };
894 retry_count = 0;
913 /* shared->private conversion requires memory to be accepted before use */
924 * Only handle shared->private conversion here.
928 return -EIO;
930 return 0;
937 * Only handle private->shared conversion here.
941 return -EIO;
948 return 0;
951 /* Stop new private<->shared conversions */
964 pr_warn("Failed to stop shared<->private conversions\n");
971 long found = 0, shared;
999 set_pte(pte, __pte(0));
1011 * a pre-reserved memory range that is always private.
1021 pr_err("Failed to unshare range %#lx-%#lx\n",
1059 cpuid_count(TDX_CPUID_LEAF_ID, 0, &eax, &sig[0], &sig[2], &sig[1]);
1082 physical_mask &= cc_mask - 1;
1090 * - Private mapping => Shared Page == Guest shutdown
1091 * - Shared mapping => Private Page == Recoverable #VE
1117 * Intel-TDX has a secure RDMSR hypercall, but that needs to be