Skip to contentSkip to conversation

KVM: arm64: Don't WARN on SMCCC filter reserved range allocation failure

PATCH Applied Fuad Tabba 4 participants 4 messages Oct 13 – Oct 26

Subsystems (2)
lore
Share & tools
lore

Fuad Tabba

author reviewer
#0 lore raw

PATCH v2 1/1 KVM: arm64: Don't WARN on SMCCC filter reserved range allocation failure

The first time userspace sets an SMCCC filter, kvm_smccc_set_filter() inserts the reserved architecture ranges into the maple tree and WARNs if that fails. The insertion allocates with GFP_KERNEL_ACCOUNT, so a tight memory cgroup limit is enough for userspace to hit the WARN, even though the -ENOMEM is also returned to it. The WARN dates back to when the ranges were inserted at VM creation.

Leave -ENOMEM out of the WARN and keep it for every other error. The two reserved ranges are fixed and disjoint and go into an empty tree under config_lock, so any other error is a KVM bug.

Fixes fb88707dd39bd ("KVM: arm64: Use a maple tree to represent the SMCCC filter")

---
Changes since v1 [1]:
- Keep the WARN for any error other than -ENOMEM. (Oliver)
- Split out of v1 as its own patch. (Marc)

Based on Linux 7.3-rc3 (fd73f4a665989).

[1] https://lore.kernel.org/all/[email protected]/

 arch/arm64/kvm/hypercalls.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/arm64/kvm/hypercalls.c +3 -1
index b11b8821c9fbc..c9d488c586e5f 100644
@@ -197,8 +197,10 @@ static int kvm_smccc_set_filter(struct kvm *kvm, struct kvm_smccc_filter __user
 
 	if (!kvm_smccc_filter_configured(kvm)) {
 		r = kvm_smccc_filter_insert_reserved(kvm);
-		if (WARN_ON_ONCE(r))
+		if (r) {
+			WARN_ON_ONCE(r != -ENOMEM);
 			goto out_unlock;
+		}
 	}
 
 	r = mtree_insert_range(&kvm->arch.smccc_filter, start, end,

base-commit: fd73f4a6659897191fa0d40695fe370925dd3780

Signature · 1 line
2.39.5
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 11 lines · Fuad Tabba

The first time userspace sets an SMCCC filter, kvm_smccc_set_filter() inserts the reserved architecture ranges into the maple tree and WARNs if that fails. The insertion allocates with GFP_KERNEL_ACCOUNT, so a tight memory cgroup limit is enough for userspace to hit the WARN, even though the -ENOMEM is also returned to it. The WARN dates back to when the ranges were inserted at VM creation.

Leave -ENOMEM out of the WARN and keep it for every other error. The two reserved ranges are fixed and disjoint and go into an empty tree under config_lock, so any other error is a KVM bug.

Quoted 5 lines
Fixes fb88707dd39bd ("KVM: arm64: Use a maple tree to represent the SMCCC filter")

Thanks,
Oliver

Quoted 34 lines

---
Changes since v1 [1]:
- Keep the WARN for any error other than -ENOMEM. (Oliver)
- Split out of v1 as its own patch. (Marc)

Based on Linux 7.3-rc3 (fd73f4a665989).

[1] https://lore.kernel.org/all/[email protected]/

 arch/arm64/kvm/hypercalls.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/arm64/kvm/hypercalls.c +3 -1
index b11b8821c9fbc..c9d488c586e5f 100644
@@ -197,8 +197,10 @@ static int kvm_smccc_set_filter(struct kvm *kvm, struct kvm_smccc_filter __user
 
 	if (!kvm_smccc_filter_configured(kvm)) {
 		r = kvm_smccc_filter_insert_reserved(kvm);
-		if (WARN_ON_ONCE(r))
+		if (r) {
+			WARN_ON_ONCE(r != -ENOMEM);
 			goto out_unlock;
+		}
 	}
 
 	r = mtree_insert_range(&kvm->arch.smccc_filter, start, end,

base-commit: fd73f4a6659897191fa0d40695fe370925dd3780

Signature · 1 line
2.39.5
reviewer Reviewed-by on v2 1/1
#2 lore raw
In reply to Fuad Tabba
Quoted 11 lines · Fuad Tabba

The first time userspace sets an SMCCC filter, kvm_smccc_set_filter() inserts the reserved architecture ranges into the maple tree and WARNs if that fails. The insertion allocates with GFP_KERNEL_ACCOUNT, so a tight memory cgroup limit is enough for userspace to hit the WARN, even though the -ENOMEM is also returned to it. The WARN dates back to when the ranges were inserted at VM creation.

Leave -ENOMEM out of the WARN and keep it for every other error. The two reserved ranges are fixed and disjoint and go into an empty tree under config_lock, so any other error is a KVM bug.

Quoted 5 lines
Fixes fb88707dd39bd ("KVM: arm64: Use a maple tree to represent the SMCCC filter")
Quoted 30 lines

---
Changes since v1 [1]:
- Keep the WARN for any error other than -ENOMEM. (Oliver)
- Split out of v1 as its own patch. (Marc)

Based on Linux 7.3-rc3 (fd73f4a665989).

[1] https://lore.kernel.org/all/[email protected]/

  arch/arm64/kvm/hypercalls.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
arch/arm64/kvm/hypercalls.c +3 -1
index b11b8821c9fbc..c9d488c586e5f 100644
@@ -197,8 +197,10 @@ static int kvm_smccc_set_filter(struct kvm *kvm, struct kvm_smccc_filter __user
 
  	if (!kvm_smccc_filter_configured(kvm)) {
  		r = kvm_smccc_filter_insert_reserved(kvm);
-		if (WARN_ON_ONCE(r))
+		if (r) {
+			WARN_ON_ONCE(r != -ENOMEM);
  			goto out_unlock;
+		}
  	}
 
  	r = mtree_insert_range(&kvm->arch.smccc_filter, start, end,

base-commit: fd73f4a6659897191fa0d40695fe370925dd3780

maintainer Applied
#3 lore raw
In reply to Fuad Tabba
Quoted 8 lines · Fuad Tabba

The first time userspace sets an SMCCC filter, kvm_smccc_set_filter() inserts the reserved architecture ranges into the maple tree and WARNs if that fails. The insertion allocates with GFP_KERNEL_ACCOUNT, so a tight memory cgroup limit is enough for userspace to hit the WARN, even though the -ENOMEM is also returned to it. The WARN dates back to when the ranges were inserted at VM creation.

[...]

Applied to fixes, thanks!

[1/1] KVM: arm64: Don't WARN on SMCCC filter reserved range allocation failure

      commit: 09d5e940500c2e51b697a0522c54132c1ef078ef

Cheers,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.