Thread (20 messages) 20 messages, 4 authors, 2025-02-21

Re: [PATCH v2 1/3] hyperv: Convert hypercall statuses to linux error codes

From: Nuno Das Neves <hidden>
Date: 2025-02-20 21:59:18
Also in: linux-arch, linux-arm-kernel, linux-iommu, lkml

On 2/20/2025 10:49 AM, Easwar Hariharan wrote:
On 2/20/2025 10:33 AM, Nuno Das Neves wrote:
quoted
Return linux-friendly error codes from hypercall helper functions,
which allows them to be used more flexibly.

Introduce hv_result_to_errno() for this purpose, which also handles
the special value U64_MAX returned from hv_do_hypercall().

Signed-off-by: Nuno Das Neves <redacted>
---
 drivers/hv/hv_common.c         | 34 ++++++++++++++++++++++++++++++++++
 drivers/hv/hv_proc.c           |  6 +++---
 include/asm-generic/mshyperv.h |  1 +
 3 files changed, 38 insertions(+), 3 deletions(-)
diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
index ee3083937b4f..2120aead98d9 100644
--- a/drivers/hv/hv_common.c
+++ b/drivers/hv/hv_common.c
@@ -683,3 +683,37 @@ u64 __weak hv_tdx_hypercall(u64 control, u64 param1, u64 param2)
 	return HV_STATUS_INVALID_PARAMETER;
 }
 EXPORT_SYMBOL_GPL(hv_tdx_hypercall);
+
+/* Convert a hypercall result into a linux-friendly error code. */
+int hv_result_to_errno(u64 status)
+{
+	/* hv_do_hypercall() may return U64_MAX, hypercalls aren't possible */
+	if (unlikely(status == U64_MAX))
+		return -EOPNOTSUPP;
+	/*
+	 * A failed hypercall is usually only recoverable (or loggable) near
+	 * the call site where the HV_STATUS_* code is known. So the errno
+	 * it gets converted to is not too useful further up the stack.
+	 * Provice a few mappings that could be useful, and revert to -EIO
Typo: Provide
Yep, looks like there will be a v3, I'll fix it there.
Thanks for the review!
Otherwise, looks good to me.

Reviewed-by: Easwar Hariharan <redacted>

Thanks,
Easwar (he/him)
  
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help