mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Juergen Gross <jgross@suse.com>
To: linux-kernel@vger.kernel.org, x86@kernel.org, kvm@vger.kernel.org
Cc: Juergen Gross <jgross@suse.com>,
	Vitaly Kuznetsov <vkuznets@redhat.com>,
	Sean Christopherson <seanjc@google.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
	Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	"H. Peter Anvin" <hpa@zytor.com>
Subject: [PATCH v2 3/6] KVM/x86: Return -errno instead of "1" for Hyper-V related MSR emulation
Date: Thu, 28 May 2026 13:36:02 +0200	[thread overview]
Message-ID: <20260528113605.267111-4-jgross@suse.com> (raw)
In-Reply-To: <20260528113605.267111-1-jgross@suse.com>

Instead of a literal "1" for signalling an error, use a negative errno
value in the emulation code of Hyper-V related MSR registers.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
V2:
- use -errno instead of KVM_MSR_RET_ERR
---
 arch/x86/kvm/hyperv.c | 72 +++++++++++++++++++++----------------------
 1 file changed, 36 insertions(+), 36 deletions(-)

diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index 4438ecac9a89..809752a6d0ac 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -167,7 +167,7 @@ static int synic_set_sint(struct kvm_vcpu_hv_synic *synic, int sint,
 	 * allow zero-initing the register from host as well.
 	 */
 	if (vector < HV_SYNIC_FIRST_VALID_VECTOR && !host && !masked)
-		return 1;
+		return -EINVAL;
 	/*
 	 * Guest may configure multiple SINTs to use the same vector, so
 	 * we maintain a bitmap of vectors handled by synic, and a
@@ -263,7 +263,7 @@ static int synic_set_msr(struct kvm_vcpu_hv_synic *synic,
 	int ret;
 
 	if (!synic->active && (!host || data))
-		return 1;
+		return -EINVAL;
 
 	trace_kvm_hv_synic_set_msr(vcpu->vcpu_id, msr, data, host);
 
@@ -276,7 +276,7 @@ static int synic_set_msr(struct kvm_vcpu_hv_synic *synic,
 		break;
 	case HV_X64_MSR_SVERSION:
 		if (!host) {
-			ret = 1;
+			ret = -EINVAL;
 			break;
 		}
 		synic->version = data;
@@ -286,7 +286,7 @@ static int synic_set_msr(struct kvm_vcpu_hv_synic *synic,
 		    !synic->dont_zero_synic_pages)
 			if (kvm_clear_guest(vcpu->kvm,
 					    data & PAGE_MASK, PAGE_SIZE)) {
-				ret = 1;
+				ret = -EFAULT;
 				break;
 			}
 		synic->evt_page = data;
@@ -298,7 +298,7 @@ static int synic_set_msr(struct kvm_vcpu_hv_synic *synic,
 		    !synic->dont_zero_synic_pages)
 			if (kvm_clear_guest(vcpu->kvm,
 					    data & PAGE_MASK, PAGE_SIZE)) {
-				ret = 1;
+				ret = -EFAULT;
 				break;
 			}
 		synic->msg_page = data;
@@ -319,7 +319,7 @@ static int synic_set_msr(struct kvm_vcpu_hv_synic *synic,
 		ret = synic_set_sint(synic, msr - HV_X64_MSR_SINT0, data, host);
 		break;
 	default:
-		ret = 1;
+		ret = -EINVAL;
 		break;
 	}
 	return ret;
@@ -365,7 +365,7 @@ static int syndbg_set_msr(struct kvm_vcpu *vcpu, u32 msr, u64 data, bool host)
 	struct kvm_hv_syndbg *syndbg = to_hv_syndbg(vcpu);
 
 	if (!kvm_hv_is_syndbg_enabled(vcpu) && !host)
-		return 1;
+		return -EINVAL;
 
 	trace_kvm_hv_syndbg_set_msr(vcpu->vcpu_id,
 				    to_hv_vcpu(vcpu)->vp_index, msr, data);
@@ -404,7 +404,7 @@ static int syndbg_get_msr(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata, bool host)
 	struct kvm_hv_syndbg *syndbg = to_hv_syndbg(vcpu);
 
 	if (!kvm_hv_is_syndbg_enabled(vcpu) && !host)
-		return 1;
+		return -EINVAL;
 
 	switch (msr) {
 	case HV_X64_MSR_SYNDBG_CONTROL:
@@ -440,7 +440,7 @@ static int synic_get_msr(struct kvm_vcpu_hv_synic *synic, u32 msr, u64 *pdata,
 	int ret;
 
 	if (!synic->active && !host)
-		return 1;
+		return -EINVAL;
 
 	ret = 0;
 	switch (msr) {
@@ -463,7 +463,7 @@ static int synic_get_msr(struct kvm_vcpu_hv_synic *synic, u32 msr, u64 *pdata,
 		*pdata = atomic64_read(&synic->sint[msr - HV_X64_MSR_SINT0]);
 		break;
 	default:
-		ret = 1;
+		ret = -EINVAL;
 		break;
 	}
 	return ret;
@@ -695,12 +695,12 @@ static int stimer_set_config(struct kvm_vcpu_hv_stimer *stimer, u64 config,
 	struct kvm_vcpu_hv_synic *synic = to_hv_synic(vcpu);
 
 	if (!synic->active && (!host || config))
-		return 1;
+		return -EINVAL;
 
 	if (unlikely(!host && hv_vcpu->enforce_cpuid && new_config.direct_mode &&
 		     !(hv_vcpu->cpuid_cache.features_edx &
 		       HV_STIMER_DIRECT_MODE_AVAILABLE)))
-		return 1;
+		return -EINVAL;
 
 	trace_kvm_hv_stimer_set_config(hv_stimer_to_vcpu(stimer)->vcpu_id,
 				       stimer->index, config, host);
@@ -724,7 +724,7 @@ static int stimer_set_count(struct kvm_vcpu_hv_stimer *stimer, u64 count,
 	struct kvm_vcpu_hv_synic *synic = to_hv_synic(vcpu);
 
 	if (!synic->active && (!host || count))
-		return 1;
+		return -EINVAL;
 
 	trace_kvm_hv_stimer_set_count(hv_stimer_to_vcpu(stimer)->vcpu_id,
 				      stimer->index, count, host);
@@ -1380,7 +1380,7 @@ static int kvm_hv_set_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data,
 	struct kvm_hv *hv = to_kvm_hv(kvm);
 
 	if (unlikely(!host && !hv_check_msr_access(to_hv_vcpu(vcpu), msr)))
-		return 1;
+		return -EINVAL;
 
 	switch (msr) {
 	case HV_X64_MSR_GUEST_OS_ID:
@@ -1476,23 +1476,23 @@ static int kvm_hv_set_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data,
 		break;
 	case HV_X64_MSR_TSC_EMULATION_STATUS:
 		if (data && !host)
-			return 1;
+			return -EINVAL;
 
 		hv->hv_tsc_emulation_status = data;
 		break;
 	case HV_X64_MSR_TIME_REF_COUNT:
 		/* read-only, but still ignore it if host-initiated */
 		if (!host)
-			return 1;
+			return -EINVAL;
 		break;
 	case HV_X64_MSR_TSC_INVARIANT_CONTROL:
 		/* Only bit 0 is supported */
 		if (data & ~HV_EXPOSE_INVARIANT_TSC)
-			return 1;
+			return -EINVAL;
 
 		/* The feature can't be disabled from the guest */
 		if (!host && hv->hv_invtsc_control && !data)
-			return 1;
+			return -EINVAL;
 
 		hv->hv_invtsc_control = data;
 		break;
@@ -1501,7 +1501,7 @@ static int kvm_hv_set_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data,
 		return syndbg_set_msr(vcpu, msr, data, host);
 	default:
 		kvm_pr_unimpl_wrmsr(vcpu, msr, data);
-		return 1;
+		return -EINVAL;
 	}
 	return 0;
 }
@@ -1521,7 +1521,7 @@ static int kvm_hv_set_msr(struct kvm_vcpu *vcpu, u32 msr, u64 data, bool host)
 	struct kvm_vcpu_hv *hv_vcpu = to_hv_vcpu(vcpu);
 
 	if (unlikely(!host && !hv_check_msr_access(hv_vcpu, msr)))
-		return 1;
+		return -EINVAL;
 
 	switch (msr) {
 	case HV_X64_MSR_VP_INDEX: {
@@ -1529,7 +1529,7 @@ static int kvm_hv_set_msr(struct kvm_vcpu *vcpu, u32 msr, u64 data, bool host)
 		u32 new_vp_index = (u32)data;
 
 		if (!host || new_vp_index >= KVM_MAX_VCPUS)
-			return 1;
+			return -EINVAL;
 
 		if (new_vp_index == hv_vcpu->vp_index)
 			return 0;
@@ -1555,13 +1555,13 @@ static int kvm_hv_set_msr(struct kvm_vcpu *vcpu, u32 msr, u64 data, bool host)
 		if (!(data & HV_X64_MSR_VP_ASSIST_PAGE_ENABLE)) {
 			hv_vcpu->hv_vapic = data;
 			if (kvm_lapic_set_pv_eoi(vcpu, 0, 0))
-				return 1;
+				return -EINVAL;
 			break;
 		}
 		gfn = data >> HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_SHIFT;
 		addr = kvm_vcpu_gfn_to_hva(vcpu, gfn);
 		if (kvm_is_error_hva(addr))
-			return 1;
+			return -EINVAL;
 
 		/*
 		 * Clear apic_assist portion of struct hv_vp_assist_page
@@ -1569,13 +1569,13 @@ static int kvm_hv_set_msr(struct kvm_vcpu *vcpu, u32 msr, u64 data, bool host)
 		 * to be preserved e.g. on migration.
 		 */
 		if (put_user(0, (u32 __user *)addr))
-			return 1;
+			return -EFAULT;
 		hv_vcpu->hv_vapic = data;
 		kvm_vcpu_mark_page_dirty(vcpu, gfn);
 		if (kvm_lapic_set_pv_eoi(vcpu,
 					    gfn_to_gpa(gfn) | KVM_MSR_ENABLED,
 					    sizeof(struct hv_vp_assist_page)))
-			return 1;
+			return -EINVAL;
 		break;
 	}
 	case HV_X64_MSR_EOI:
@@ -1586,7 +1586,7 @@ static int kvm_hv_set_msr(struct kvm_vcpu *vcpu, u32 msr, u64 data, bool host)
 		return kvm_hv_vapic_msr_write(vcpu, APIC_TASKPRI, data);
 	case HV_X64_MSR_VP_RUNTIME:
 		if (!host)
-			return 1;
+			return -EINVAL;
 		hv_vcpu->runtime_offset = data - current_task_runtime_100ns();
 		break;
 	case HV_X64_MSR_SCONTROL:
@@ -1618,11 +1618,11 @@ static int kvm_hv_set_msr(struct kvm_vcpu *vcpu, u32 msr, u64 data, bool host)
 	case HV_X64_MSR_APIC_FREQUENCY:
 		/* read-only, but still ignore it if host-initiated */
 		if (!host)
-			return 1;
+			return -EINVAL;
 		break;
 	default:
 		kvm_pr_unimpl_wrmsr(vcpu, msr, data);
-		return 1;
+		return -EINVAL;
 	}
 
 	return 0;
@@ -1636,7 +1636,7 @@ static int kvm_hv_get_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata,
 	struct kvm_hv *hv = to_kvm_hv(kvm);
 
 	if (unlikely(!host && !hv_check_msr_access(to_hv_vcpu(vcpu), msr)))
-		return 1;
+		return -EINVAL;
 
 	switch (msr) {
 	case HV_X64_MSR_GUEST_OS_ID:
@@ -1677,7 +1677,7 @@ static int kvm_hv_get_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata,
 		return syndbg_get_msr(vcpu, msr, pdata, host);
 	default:
 		kvm_pr_unimpl_rdmsr(vcpu, msr);
-		return 1;
+		return -EINVAL;
 	}
 
 	*pdata = data;
@@ -1691,7 +1691,7 @@ static int kvm_hv_get_msr(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata,
 	struct kvm_vcpu_hv *hv_vcpu = to_hv_vcpu(vcpu);
 
 	if (unlikely(!host && !hv_check_msr_access(hv_vcpu, msr)))
-		return 1;
+		return -EINVAL;
 
 	switch (msr) {
 	case HV_X64_MSR_VP_INDEX:
@@ -1743,7 +1743,7 @@ static int kvm_hv_get_msr(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata,
 		break;
 	default:
 		kvm_pr_unimpl_rdmsr(vcpu, msr);
-		return 1;
+		return -EINVAL;
 	}
 	*pdata = data;
 	return 0;
@@ -1754,10 +1754,10 @@ int kvm_hv_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data, bool host)
 	struct kvm_hv *hv = to_kvm_hv(vcpu->kvm);
 
 	if (!host && !vcpu->arch.hyperv_enabled)
-		return 1;
+		return -EINVAL;
 
 	if (kvm_hv_vcpu_init(vcpu))
-		return 1;
+		return -EINVAL;
 
 	if (kvm_hv_msr_partition_wide(msr)) {
 		int r;
@@ -1775,10 +1775,10 @@ int kvm_hv_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata, bool host)
 	struct kvm_hv *hv = to_kvm_hv(vcpu->kvm);
 
 	if (!host && !vcpu->arch.hyperv_enabled)
-		return 1;
+		return -EINVAL;
 
 	if (kvm_hv_vcpu_init(vcpu))
-		return 1;
+		return -EINVAL;
 
 	if (kvm_hv_msr_partition_wide(msr)) {
 		int r;
-- 
2.54.0


  parent reply	other threads:[~2026-05-28 11:36 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-28 11:35 [PATCH v2 0/6] KVM/x86: Drop "1" as MSR emulation return value Juergen Gross
2026-05-28 11:36 ` [PATCH v2 1/6] KVM/x86: Change comment before KVM_MSR_RET_* defines Juergen Gross
2026-05-28 11:36 ` [PATCH v2 2/6] KVM/x86: Return -errno instead of "1" for APIC related MSR emulation Juergen Gross
2026-05-28 11:36 ` Juergen Gross [this message]
2026-05-28 11:36 ` [PATCH v2 4/6] KVM/x86: Return -errno instead of "1" for VMX " Juergen Gross
2026-05-28 11:36 ` [PATCH v2 5/6] KVM/x86: Return -errno instead of "1" for SVM " Juergen Gross
2026-05-28 11:36 ` [PATCH v2 6/6] KVM/x86: Return -errno instead of "1" for common " Juergen Gross
2026-05-28 11:58 ` [PATCH v2 0/6] KVM/x86: Drop "1" as MSR emulation return value Juergen Gross
2026-05-28 13:09   ` Sean Christopherson
2026-05-28 13:18     ` Jürgen Groß
2026-05-28 13:21       ` Sean Christopherson
2026-05-28 14:01         ` Jürgen Groß
2026-05-28 14:33         ` Jürgen Groß
2026-05-28 15:32           ` David Woodhouse
2026-05-28 15:36             ` Jürgen Groß
2026-05-28 15:50         ` Jürgen Groß
2026-05-29  9:31           ` Juergen Gross

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260528113605.267111-4-jgross@suse.com \
    --to=jgross@suse.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=tglx@kernel.org \
    --cc=vkuznets@redhat.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®