[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251219114238.3797364-7-clopez@suse.de>
Date: Fri, 19 Dec 2025 12:42:01 +0100
From: Carlos López <clopez@...e.de>
To: kvm@...r.kernel.org,
seanjc@...gle.com,
pbonzini@...hat.com
Cc: tglx@...utronix.de,
mingo@...hat.com,
bp@...en8.de,
dave.hansen@...ux.intel.com,
x86@...nel.org,
hpa@...or.com,
linux-kernel@...r.kernel.org,
Carlos López <clopez@...e.de>
Subject: [PATCH 6/6] KVM: SEV: use scoped mutex guard in sev_asid_new()
Simplify the lock management in sev_asid_new() by using a mutex guard,
automatically releasing the mutex when following the goto.
Signed-off-by: Carlos López <clopez@...e.de>
---
arch/x86/kvm/svm/sev.c | 24 ++++++++++--------------
1 file changed, 10 insertions(+), 14 deletions(-)
diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index 5f46b7f073b0..95430d456a6f 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -232,24 +232,20 @@ static int sev_asid_new(struct kvm_sev_info *sev, unsigned long vm_type)
return ret;
}
- mutex_lock(&sev_bitmap_lock);
-
+ scoped_guard(mutex, &sev_bitmap_lock) {
again:
- asid = find_next_zero_bit(sev_asid_bitmap, max_asid + 1, min_asid);
- if (asid > max_asid) {
- if (retry && __sev_recycle_asids(min_asid, max_asid)) {
- retry = false;
- goto again;
+ asid = find_next_zero_bit(sev_asid_bitmap, max_asid + 1, min_asid);
+ if (asid > max_asid) {
+ if (retry && __sev_recycle_asids(min_asid, max_asid)) {
+ retry = false;
+ goto again;
+ }
+ ret = -EBUSY;
+ goto e_uncharge;
}
- mutex_unlock(&sev_bitmap_lock);
- ret = -EBUSY;
- goto e_uncharge;
+ __set_bit(asid, sev_asid_bitmap);
}
- __set_bit(asid, sev_asid_bitmap);
-
- mutex_unlock(&sev_bitmap_lock);
-
sev->asid = asid;
return 0;
e_uncharge:
--
2.51.0
Powered by blists - more mailing lists