Re: [PATCHv2 08/29] x86/tdx: Handle in-kernel MMIO

From: Dave Hansen
Date: Mon Jan 24 2022 - 18:37:58 EST


+static bool tdx_mmio(int size, bool write, unsigned long addr,
+ unsigned long *val)
+{
+ struct tdx_hypercall_output out;
+ u64 err;
+
+ err = _tdx_hypercall(EXIT_REASON_EPT_VIOLATION, size, write,
+ addr, *val, &out);
+ if (err)
+ return true;
+
+ *val = out.r11;
+ return false;
+}
+
+static bool tdx_mmio_read(int size, unsigned long addr, unsigned long *val)
+{
+ return tdx_mmio(size, false, addr, val);
+}
+
+static bool tdx_mmio_write(int size, unsigned long addr, unsigned long *val)
+{
+ return tdx_mmio(size, true, addr, val);
+}
+
+static int tdx_handle_mmio(struct pt_regs *regs, struct ve_info *ve)
+{
...
+ bool err;

I'll agree with Josh on one point: "bool err" _is_ weird.

Things tend to either return int with 0 for success or bool with true for success.

The tdx_handle*() ones seem OK to me. It's pretty normal to have a literal "handler" return true if things were handled.

I'd probably just make tdx_mmio() return an int. It seems to only able to return -EFAULT anyway, so changing the return from bool->int and doing:

- return false;
+ return -EFAULT;

isn't exactly a heavy lift.