Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'x86_tdx_for_6.4' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull x86 tdx update from Dave Hansen:
"The original tdx hypercall assembly code took two flags in %RSI to
tweak its behavior at runtime. PeterZ recently axed one flag in commit
e80a48bade61 ("x86/tdx: Remove TDX_HCALL_ISSUE_STI").

Kill the other flag too and tweak the 'output' mode with an assembly
macro instead. This results in elimination of one push/pop pair and
overall easier to read assembly.

- Do conditional __tdx_hypercall() 'output' processing via an
assembly macro argument rather than a runtime register"

* tag 'x86_tdx_for_6.4' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
x86/tdx: Drop flags from __tdx_hypercall()

+51 -42
+2 -2
arch/x86/boot/compressed/tdx.c
··· 26 26 .r14 = port, 27 27 }; 28 28 29 - if (__tdx_hypercall(&args, TDX_HCALL_HAS_OUTPUT)) 29 + if (__tdx_hypercall_ret(&args)) 30 30 return UINT_MAX; 31 31 32 32 return args.r11; ··· 43 43 .r15 = value, 44 44 }; 45 45 46 - __tdx_hypercall(&args, 0); 46 + __tdx_hypercall(&args); 47 47 } 48 48 49 49 static inline u8 tdx_inb(u16 port)
+38 -28
arch/x86/coco/tdx/tdcall.S
··· 85 85 SYM_FUNC_END(__tdx_module_call) 86 86 87 87 /* 88 - * __tdx_hypercall() - Make hypercalls to a TDX VMM using TDVMCALL leaf 89 - * of TDCALL instruction 88 + * TDX_HYPERCALL - Make hypercalls to a TDX VMM using TDVMCALL leaf of TDCALL 89 + * instruction 90 90 * 91 91 * Transforms values in function call argument struct tdx_hypercall_args @args 92 92 * into the TDCALL register ABI. After TDCALL operation, VMM output is saved 93 - * back in @args. 93 + * back in @args, if \ret is 1. 94 94 * 95 95 *------------------------------------------------------------------------- 96 96 * TD VMCALL ABI: ··· 105 105 * specification. Non zero value indicates vendor 106 106 * specific ABI. 107 107 * R11 - VMCALL sub function number 108 - * RBX, RBP, RDI, RSI - Used to pass VMCALL sub function specific arguments. 108 + * RBX, RDX, RDI, RSI - Used to pass VMCALL sub function specific arguments. 109 109 * R8-R9, R12-R15 - Same as above. 110 110 * 111 111 * Output Registers: 112 112 * 113 113 * RAX - TDCALL instruction status (Not related to hypercall 114 114 * output). 115 - * R10 - Hypercall output error code. 116 - * R11-R15 - Hypercall sub function specific output values. 115 + * RBX, RDX, RDI, RSI - Hypercall sub function specific output values. 116 + * R8-R15 - Same as above. 117 117 * 118 - *------------------------------------------------------------------------- 119 - * 120 - * __tdx_hypercall() function ABI: 121 - * 122 - * @args (RDI) - struct tdx_hypercall_args for input and output 123 - * @flags (RSI) - TDX_HCALL_* flags 124 - * 125 - * On successful completion, return the hypercall error code. 126 118 */ 127 - SYM_FUNC_START(__tdx_hypercall) 119 + .macro TDX_HYPERCALL ret:req 128 120 FRAME_BEGIN 129 121 130 122 /* Save callee-saved GPRs as mandated by the x86_64 ABI */ ··· 126 134 push %r12 127 135 push %rbx 128 136 129 - /* Free RDI and RSI to be used as TDVMCALL arguments */ 137 + /* Free RDI to be used as TDVMCALL arguments */ 130 138 movq %rdi, %rax 131 - push %rsi 132 139 133 140 /* Copy hypercall registers from arg struct: */ 134 141 movq TDX_HYPERCALL_r8(%rax), %r8 ··· 162 171 * and are handled by callers. 163 172 */ 164 173 testq %rax, %rax 165 - jne .Lpanic 174 + jne .Lpanic\@ 166 175 167 176 pop %rax 168 177 169 - /* Copy hypercall result registers to arg struct if needed */ 170 - testq $TDX_HCALL_HAS_OUTPUT, (%rsp) 171 - jz .Lout 172 - 178 + .if \ret 173 179 movq %r8, TDX_HYPERCALL_r8(%rax) 174 180 movq %r9, TDX_HYPERCALL_r9(%rax) 175 181 movq %r10, TDX_HYPERCALL_r10(%rax) ··· 179 191 movq %rsi, TDX_HYPERCALL_rsi(%rax) 180 192 movq %rbx, TDX_HYPERCALL_rbx(%rax) 181 193 movq %rdx, TDX_HYPERCALL_rdx(%rax) 182 - .Lout: 194 + .endif 195 + 183 196 /* TDVMCALL leaf return code is in R10 */ 184 197 movq %r10, %rax 185 198 ··· 197 208 xor %rdi, %rdi 198 209 xor %rdx, %rdx 199 210 200 - /* Remove TDX_HCALL_* flags from the stack */ 201 - pop %rsi 202 - 203 211 /* Restore callee-saved GPRs as mandated by the x86_64 ABI */ 204 212 pop %rbx 205 213 pop %r12 ··· 207 221 FRAME_END 208 222 209 223 RET 210 - .Lpanic: 224 + .Lpanic\@: 211 225 call __tdx_hypercall_failed 212 226 /* __tdx_hypercall_failed never returns */ 213 227 REACHABLE 214 - jmp .Lpanic 228 + jmp .Lpanic\@ 229 + .endm 230 + 231 + /* 232 + * 233 + * __tdx_hypercall() function ABI: 234 + * 235 + * @args (RDI) - struct tdx_hypercall_args for input 236 + * 237 + * On successful completion, return the hypercall error code. 238 + */ 239 + SYM_FUNC_START(__tdx_hypercall) 240 + TDX_HYPERCALL ret=0 215 241 SYM_FUNC_END(__tdx_hypercall) 242 + 243 + /* 244 + * 245 + * __tdx_hypercall_ret() function ABI: 246 + * 247 + * @args (RDI) - struct tdx_hypercall_args for input and output 248 + * 249 + * On successful completion, return the hypercall error code. 250 + */ 251 + SYM_FUNC_START(__tdx_hypercall_ret) 252 + TDX_HYPERCALL ret=1 253 + SYM_FUNC_END(__tdx_hypercall_ret)
+9 -9
arch/x86/coco/tdx/tdx.c
··· 66 66 .r15 = r15, 67 67 }; 68 68 69 - return __tdx_hypercall(&args, 0); 69 + return __tdx_hypercall(&args); 70 70 } 71 71 72 72 /* Called from __tdx_hypercall() for unrecoverable failure */ ··· 99 99 .r14 = p4, 100 100 }; 101 101 102 - return __tdx_hypercall(&args, 0); 102 + return __tdx_hypercall(&args); 103 103 } 104 104 EXPORT_SYMBOL_GPL(tdx_kvm_hypercall); 105 105 #endif ··· 179 179 * happens to return. 180 180 */ 181 181 while (1) 182 - __tdx_hypercall(&args, 0); 182 + __tdx_hypercall(&args); 183 183 } 184 184 185 185 static void tdx_parse_tdinfo(u64 *cc_mask) ··· 289 289 * can keep the vCPU in virtual HLT, even if an IRQ is 290 290 * pending, without hanging/breaking the guest. 291 291 */ 292 - return __tdx_hypercall(&args, 0); 292 + return __tdx_hypercall(&args); 293 293 } 294 294 295 295 static int handle_halt(struct ve_info *ve) ··· 326 326 * can be found in TDX Guest-Host-Communication Interface 327 327 * (GHCI), section titled "TDG.VP.VMCALL<Instruction.RDMSR>". 328 328 */ 329 - if (__tdx_hypercall(&args, TDX_HCALL_HAS_OUTPUT)) 329 + if (__tdx_hypercall_ret(&args)) 330 330 return -EIO; 331 331 332 332 regs->ax = lower_32_bits(args.r11); ··· 348 348 * can be found in TDX Guest-Host-Communication Interface 349 349 * (GHCI) section titled "TDG.VP.VMCALL<Instruction.WRMSR>". 350 350 */ 351 - if (__tdx_hypercall(&args, 0)) 351 + if (__tdx_hypercall(&args)) 352 352 return -EIO; 353 353 354 354 return ve_instr_len(ve); ··· 380 380 * ABI can be found in TDX Guest-Host-Communication Interface 381 381 * (GHCI), section titled "VP.VMCALL<Instruction.CPUID>". 382 382 */ 383 - if (__tdx_hypercall(&args, TDX_HCALL_HAS_OUTPUT)) 383 + if (__tdx_hypercall_ret(&args)) 384 384 return -EIO; 385 385 386 386 /* ··· 407 407 .r15 = *val, 408 408 }; 409 409 410 - if (__tdx_hypercall(&args, TDX_HCALL_HAS_OUTPUT)) 410 + if (__tdx_hypercall_ret(&args)) 411 411 return false; 412 412 *val = args.r11; 413 413 return true; ··· 541 541 * in TDX Guest-Host-Communication Interface (GHCI) section titled 542 542 * "TDG.VP.VMCALL<Instruction.IO>". 543 543 */ 544 - success = !__tdx_hypercall(&args, TDX_HCALL_HAS_OUTPUT); 544 + success = !__tdx_hypercall_ret(&args); 545 545 546 546 /* Update part of the register affected by the emulated instruction */ 547 547 regs->ax &= ~mask;
+2 -3
arch/x86/include/asm/shared/tdx.h
··· 7 7 8 8 #define TDX_HYPERCALL_STANDARD 0 9 9 10 - #define TDX_HCALL_HAS_OUTPUT BIT(0) 11 - 12 10 #define TDX_CPUID_LEAF_ID 0x21 13 11 #define TDX_IDENT "IntelTDX " 14 12 ··· 34 36 }; 35 37 36 38 /* Used to request services from the VMM */ 37 - u64 __tdx_hypercall(struct tdx_hypercall_args *args, unsigned long flags); 39 + u64 __tdx_hypercall(struct tdx_hypercall_args *args); 40 + u64 __tdx_hypercall_ret(struct tdx_hypercall_args *args); 38 41 39 42 /* Called from __tdx_hypercall() for unrecoverable failure */ 40 43 void __tdx_hypercall_failed(void);