* [PATCH v1 0/4] KVM: s390: vsie: vsie page handling fixes + rework
@ 2025-01-07 15:43 David Hildenbrand
2025-01-07 15:43 ` [PATCH v1 1/4] KVM: s390: vsie: fix some corner-cases when grabbing vsie pages David Hildenbrand
` (5 more replies)
0 siblings, 6 replies; 10+ messages in thread
From: David Hildenbrand @ 2025-01-07 15:43 UTC (permalink / raw)
To: linux-kernel
Cc: kvm, linux-s390, David Hildenbrand, Christian Borntraeger,
Janosch Frank, Claudio Imbrenda, Heiko Carstens, Vasily Gorbik,
Alexander Gordeev, Sven Schnelle, Thomas Huth,
Matthew Wilcox (Oracle)
We want to get rid of page->index, so let's make vsie code stop using it
for the vsie page.
While at it, also remove the usage of page refcount, so we can stop messing
with "struct page" completely.
... of course, looking at this code after quite some years, I found some
corner cases that should be fixed.
Briefly sanity tested with kvm-unit-tests running inside a KVM VM, and
nothing blew up.
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Janosch Frank <frankja@linux.ibm.com>
Cc: Claudio Imbrenda <imbrenda@linux.ibm.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Thomas Huth <thuth@redhat.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
David Hildenbrand (4):
KVM: s390: vsie: fix some corner-cases when grabbing vsie pages
KVM: s390: vsie: stop using page->index
KVM: s390: vsie: stop messing with page refcount
KVM: s390: vsie: stop using "struct page" for vsie page
arch/s390/include/asm/kvm_host.h | 4 +-
arch/s390/kvm/vsie.c | 104 ++++++++++++++++++++-----------
2 files changed, 69 insertions(+), 39 deletions(-)
base-commit: fbfd64d25c7af3b8695201ebc85efe90be28c5a3
--
2.47.1
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v1 1/4] KVM: s390: vsie: fix some corner-cases when grabbing vsie pages
2025-01-07 15:43 [PATCH v1 0/4] KVM: s390: vsie: vsie page handling fixes + rework David Hildenbrand
@ 2025-01-07 15:43 ` David Hildenbrand
2025-01-07 15:43 ` [PATCH v1 2/4] KVM: s390: vsie: stop using page->index David Hildenbrand
` (4 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: David Hildenbrand @ 2025-01-07 15:43 UTC (permalink / raw)
To: linux-kernel
Cc: kvm, linux-s390, David Hildenbrand, Christian Borntraeger,
Janosch Frank, Claudio Imbrenda, Heiko Carstens, Vasily Gorbik,
Alexander Gordeev, Sven Schnelle, Thomas Huth,
Matthew Wilcox (Oracle), stable
We try to reuse the same vsie page when re-executing the vsie with a
given SCB address. The result is that we use the same shadow SCB --
residing in the vsie page -- and can avoid flushing the TLB when
re-running the vsie on a CPU.
So, when we allocate a fresh vsie page, or when we reuse a vsie page for
a different SCB address -- reusing the shadow SCB in different context --
we set ihcpu=0xffff to trigger the flush.
However, after we looked up the SCB address in the radix tree, but before
we grabbed the vsie page by raising the refcount to 2, someone could reuse
the vsie page for a different SCB address, adjusting page->index and the
radix tree. In that case, we would be reusing the vsie page with a
wrong page->index.
Another corner case is that we might set the SCB address for a vsie
page, but fail the insertion into the radix tree. Whoever would reuse
that page would remove the corresponding radix tree entry -- which might
now be a valid entry pointing at another page, resulting in the wrong
vsie page getting removed from the radix tree.
Let's handle such races better, by validating that the SCB address of a
vsie page didn't change after we grabbed it (not reuse for a different
SCB; the alternative would be performing another tree lookup), and by
setting the SCB address to invalid until the insertion in the tree
succeeded (SCB addresses are aligned to 512, so ULONG_MAX is invalid).
These scenarios are rare, the effects a bit unclear, and these issues were
only found by code inspection. Let's CC stable to be safe.
Fixes: a3508fbe9dc6 ("KVM: s390: vsie: initial support for nested virtualization")
Cc: stable@vger.kernel.org
Signed-off-by: David Hildenbrand <david@redhat.com>
---
arch/s390/kvm/vsie.c | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
diff --git a/arch/s390/kvm/vsie.c b/arch/s390/kvm/vsie.c
index 150b9387860ad..0fb527b33734c 100644
--- a/arch/s390/kvm/vsie.c
+++ b/arch/s390/kvm/vsie.c
@@ -1362,8 +1362,14 @@ static struct vsie_page *get_vsie_page(struct kvm *kvm, unsigned long addr)
page = radix_tree_lookup(&kvm->arch.vsie.addr_to_page, addr >> 9);
rcu_read_unlock();
if (page) {
- if (page_ref_inc_return(page) == 2)
- return page_to_virt(page);
+ if (page_ref_inc_return(page) == 2) {
+ if (page->index == addr)
+ return page_to_virt(page);
+ /*
+ * We raced with someone reusing + putting this vsie
+ * page before we grabbed it.
+ */
+ }
page_ref_dec(page);
}
@@ -1393,15 +1399,20 @@ static struct vsie_page *get_vsie_page(struct kvm *kvm, unsigned long addr)
kvm->arch.vsie.next++;
kvm->arch.vsie.next %= nr_vcpus;
}
- radix_tree_delete(&kvm->arch.vsie.addr_to_page, page->index >> 9);
+ if (page->index != ULONG_MAX)
+ radix_tree_delete(&kvm->arch.vsie.addr_to_page,
+ page->index >> 9);
}
- page->index = addr;
- /* double use of the same address */
+ /* Mark it as invalid until it resides in the tree. */
+ page->index = ULONG_MAX;
+
+ /* Double use of the same address or allocation failure. */
if (radix_tree_insert(&kvm->arch.vsie.addr_to_page, addr >> 9, page)) {
page_ref_dec(page);
mutex_unlock(&kvm->arch.vsie.mutex);
return NULL;
}
+ page->index = addr;
mutex_unlock(&kvm->arch.vsie.mutex);
vsie_page = page_to_virt(page);
@@ -1496,7 +1507,9 @@ void kvm_s390_vsie_destroy(struct kvm *kvm)
vsie_page = page_to_virt(page);
release_gmap_shadow(vsie_page);
/* free the radix tree entry */
- radix_tree_delete(&kvm->arch.vsie.addr_to_page, page->index >> 9);
+ if (page->index != ULONG_MAX)
+ radix_tree_delete(&kvm->arch.vsie.addr_to_page,
+ page->index >> 9);
__free_page(page);
}
kvm->arch.vsie.page_count = 0;
--
2.47.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v1 2/4] KVM: s390: vsie: stop using page->index
2025-01-07 15:43 [PATCH v1 0/4] KVM: s390: vsie: vsie page handling fixes + rework David Hildenbrand
2025-01-07 15:43 ` [PATCH v1 1/4] KVM: s390: vsie: fix some corner-cases when grabbing vsie pages David Hildenbrand
@ 2025-01-07 15:43 ` David Hildenbrand
2025-01-07 15:43 ` [PATCH v1 3/4] KVM: s390: vsie: stop messing with page refcount David Hildenbrand
` (3 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: David Hildenbrand @ 2025-01-07 15:43 UTC (permalink / raw)
To: linux-kernel
Cc: kvm, linux-s390, David Hildenbrand, Christian Borntraeger,
Janosch Frank, Claudio Imbrenda, Heiko Carstens, Vasily Gorbik,
Alexander Gordeev, Sven Schnelle, Thomas Huth,
Matthew Wilcox (Oracle)
Let's stop using page->index, and instead use a field inside "struct
vsie_page" to hold that value. We have plenty of space left in there.
This is one part of stopping using "struct page" when working with vsie
pages. We place the "page_to_virt(page)" strategically, so the next
cleanups requires less churn.
Signed-off-by: David Hildenbrand <david@redhat.com>
---
arch/s390/kvm/vsie.c | 28 ++++++++++++++++++----------
1 file changed, 18 insertions(+), 10 deletions(-)
diff --git a/arch/s390/kvm/vsie.c b/arch/s390/kvm/vsie.c
index 0fb527b33734c..00cd9a27fd8fc 100644
--- a/arch/s390/kvm/vsie.c
+++ b/arch/s390/kvm/vsie.c
@@ -46,7 +46,13 @@ struct vsie_page {
gpa_t gvrd_gpa; /* 0x0240 */
gpa_t riccbd_gpa; /* 0x0248 */
gpa_t sdnx_gpa; /* 0x0250 */
- __u8 reserved[0x0700 - 0x0258]; /* 0x0258 */
+ /*
+ * guest address of the original SCB. Remains set for free vsie
+ * pages, so we can properly look them up in our addr_to_page
+ * radix tree.
+ */
+ gpa_t scb_gpa; /* 0x0258 */
+ __u8 reserved[0x0700 - 0x0260]; /* 0x0260 */
struct kvm_s390_crypto_cb crycb; /* 0x0700 */
__u8 fac[S390_ARCH_FAC_LIST_SIZE_BYTE]; /* 0x0800 */
};
@@ -1362,9 +1368,10 @@ static struct vsie_page *get_vsie_page(struct kvm *kvm, unsigned long addr)
page = radix_tree_lookup(&kvm->arch.vsie.addr_to_page, addr >> 9);
rcu_read_unlock();
if (page) {
+ vsie_page = page_to_virt(page);
if (page_ref_inc_return(page) == 2) {
- if (page->index == addr)
- return page_to_virt(page);
+ if (vsie_page->scb_gpa == addr)
+ return vsie_page;
/*
* We raced with someone reusing + putting this vsie
* page before we grabbed it.
@@ -1386,6 +1393,7 @@ static struct vsie_page *get_vsie_page(struct kvm *kvm, unsigned long addr)
mutex_unlock(&kvm->arch.vsie.mutex);
return ERR_PTR(-ENOMEM);
}
+ vsie_page = page_to_virt(page);
page_ref_inc(page);
kvm->arch.vsie.pages[kvm->arch.vsie.page_count] = page;
kvm->arch.vsie.page_count++;
@@ -1393,18 +1401,19 @@ static struct vsie_page *get_vsie_page(struct kvm *kvm, unsigned long addr)
/* reuse an existing entry that belongs to nobody */
while (true) {
page = kvm->arch.vsie.pages[kvm->arch.vsie.next];
+ vsie_page = page_to_virt(page);
if (page_ref_inc_return(page) == 2)
break;
page_ref_dec(page);
kvm->arch.vsie.next++;
kvm->arch.vsie.next %= nr_vcpus;
}
- if (page->index != ULONG_MAX)
+ if (vsie_page->scb_gpa != ULONG_MAX)
radix_tree_delete(&kvm->arch.vsie.addr_to_page,
- page->index >> 9);
+ vsie_page->scb_gpa >> 9);
}
/* Mark it as invalid until it resides in the tree. */
- page->index = ULONG_MAX;
+ vsie_page->scb_gpa = ULONG_MAX;
/* Double use of the same address or allocation failure. */
if (radix_tree_insert(&kvm->arch.vsie.addr_to_page, addr >> 9, page)) {
@@ -1412,10 +1421,9 @@ static struct vsie_page *get_vsie_page(struct kvm *kvm, unsigned long addr)
mutex_unlock(&kvm->arch.vsie.mutex);
return NULL;
}
- page->index = addr;
+ vsie_page->scb_gpa = addr;
mutex_unlock(&kvm->arch.vsie.mutex);
- vsie_page = page_to_virt(page);
memset(&vsie_page->scb_s, 0, sizeof(struct kvm_s390_sie_block));
release_gmap_shadow(vsie_page);
vsie_page->fault_addr = 0;
@@ -1507,9 +1515,9 @@ void kvm_s390_vsie_destroy(struct kvm *kvm)
vsie_page = page_to_virt(page);
release_gmap_shadow(vsie_page);
/* free the radix tree entry */
- if (page->index != ULONG_MAX)
+ if (vsie_page->scb_gpa != ULONG_MAX)
radix_tree_delete(&kvm->arch.vsie.addr_to_page,
- page->index >> 9);
+ vsie_page->scb_gpa >> 9);
__free_page(page);
}
kvm->arch.vsie.page_count = 0;
--
2.47.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v1 3/4] KVM: s390: vsie: stop messing with page refcount
2025-01-07 15:43 [PATCH v1 0/4] KVM: s390: vsie: vsie page handling fixes + rework David Hildenbrand
2025-01-07 15:43 ` [PATCH v1 1/4] KVM: s390: vsie: fix some corner-cases when grabbing vsie pages David Hildenbrand
2025-01-07 15:43 ` [PATCH v1 2/4] KVM: s390: vsie: stop using page->index David Hildenbrand
@ 2025-01-07 15:43 ` David Hildenbrand
2025-01-07 15:43 ` [PATCH v1 4/4] KVM: s390: vsie: stop using "struct page" for vsie page David Hildenbrand
` (2 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: David Hildenbrand @ 2025-01-07 15:43 UTC (permalink / raw)
To: linux-kernel
Cc: kvm, linux-s390, David Hildenbrand, Christian Borntraeger,
Janosch Frank, Claudio Imbrenda, Heiko Carstens, Vasily Gorbik,
Alexander Gordeev, Sven Schnelle, Thomas Huth,
Matthew Wilcox (Oracle)
Let's stop messing with the page refcount, and use a flag that is set /
cleared atomically to remember whether a vsie page is currently in use.
Note that we could use a page flag, or a lower bit of the scb_gpa. Let's
keep it simple for now, we have sufficient space.
While at it, stop passing "struct kvm *" to put_vsie_page(), it's
unused.
Signed-off-by: David Hildenbrand <david@redhat.com>
---
arch/s390/kvm/vsie.c | 46 +++++++++++++++++++++++++++++---------------
1 file changed, 30 insertions(+), 16 deletions(-)
diff --git a/arch/s390/kvm/vsie.c b/arch/s390/kvm/vsie.c
index 00cd9a27fd8fc..29fdffeab635d 100644
--- a/arch/s390/kvm/vsie.c
+++ b/arch/s390/kvm/vsie.c
@@ -23,6 +23,10 @@
#include "kvm-s390.h"
#include "gaccess.h"
+enum vsie_page_flags {
+ VSIE_PAGE_IN_USE = 0,
+};
+
struct vsie_page {
struct kvm_s390_sie_block scb_s; /* 0x0000 */
/*
@@ -52,7 +56,12 @@ struct vsie_page {
* radix tree.
*/
gpa_t scb_gpa; /* 0x0258 */
- __u8 reserved[0x0700 - 0x0260]; /* 0x0260 */
+ /*
+ * Flags: must be set/cleared atomically after the vsie page can be
+ * looked up by other CPUs.
+ */
+ unsigned long flags; /* 0x0260 */
+ __u8 reserved[0x0700 - 0x0268]; /* 0x0268 */
struct kvm_s390_crypto_cb crycb; /* 0x0700 */
__u8 fac[S390_ARCH_FAC_LIST_SIZE_BYTE]; /* 0x0800 */
};
@@ -1351,6 +1360,20 @@ static int vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
return rc;
}
+/* Try getting a given vsie page, returning "true" on success. */
+static inline bool try_get_vsie_page(struct vsie_page *vsie_page)
+{
+ if (test_bit(VSIE_PAGE_IN_USE, &vsie_page->flags))
+ return false;
+ return !test_and_set_bit(VSIE_PAGE_IN_USE, &vsie_page->flags);
+}
+
+/* Put a vsie page acquired through get_vsie_page / try_get_vsie_page. */
+static void put_vsie_page(struct vsie_page *vsie_page)
+{
+ clear_bit(VSIE_PAGE_IN_USE, &vsie_page->flags);
+}
+
/*
* Get or create a vsie page for a scb address.
*
@@ -1369,15 +1392,15 @@ static struct vsie_page *get_vsie_page(struct kvm *kvm, unsigned long addr)
rcu_read_unlock();
if (page) {
vsie_page = page_to_virt(page);
- if (page_ref_inc_return(page) == 2) {
+ if (try_get_vsie_page(vsie_page)) {
if (vsie_page->scb_gpa == addr)
return vsie_page;
/*
* We raced with someone reusing + putting this vsie
* page before we grabbed it.
*/
+ put_vsie_page(vsie_page);
}
- page_ref_dec(page);
}
/*
@@ -1394,7 +1417,7 @@ static struct vsie_page *get_vsie_page(struct kvm *kvm, unsigned long addr)
return ERR_PTR(-ENOMEM);
}
vsie_page = page_to_virt(page);
- page_ref_inc(page);
+ __set_bit(VSIE_PAGE_IN_USE, &vsie_page->flags);
kvm->arch.vsie.pages[kvm->arch.vsie.page_count] = page;
kvm->arch.vsie.page_count++;
} else {
@@ -1402,9 +1425,8 @@ static struct vsie_page *get_vsie_page(struct kvm *kvm, unsigned long addr)
while (true) {
page = kvm->arch.vsie.pages[kvm->arch.vsie.next];
vsie_page = page_to_virt(page);
- if (page_ref_inc_return(page) == 2)
+ if (try_get_vsie_page(vsie_page))
break;
- page_ref_dec(page);
kvm->arch.vsie.next++;
kvm->arch.vsie.next %= nr_vcpus;
}
@@ -1417,7 +1439,7 @@ static struct vsie_page *get_vsie_page(struct kvm *kvm, unsigned long addr)
/* Double use of the same address or allocation failure. */
if (radix_tree_insert(&kvm->arch.vsie.addr_to_page, addr >> 9, page)) {
- page_ref_dec(page);
+ put_vsie_page(vsie_page);
mutex_unlock(&kvm->arch.vsie.mutex);
return NULL;
}
@@ -1431,14 +1453,6 @@ static struct vsie_page *get_vsie_page(struct kvm *kvm, unsigned long addr)
return vsie_page;
}
-/* put a vsie page acquired via get_vsie_page */
-static void put_vsie_page(struct kvm *kvm, struct vsie_page *vsie_page)
-{
- struct page *page = pfn_to_page(__pa(vsie_page) >> PAGE_SHIFT);
-
- page_ref_dec(page);
-}
-
int kvm_s390_handle_vsie(struct kvm_vcpu *vcpu)
{
struct vsie_page *vsie_page;
@@ -1489,7 +1503,7 @@ int kvm_s390_handle_vsie(struct kvm_vcpu *vcpu)
out_unpin_scb:
unpin_scb(vcpu, vsie_page, scb_addr);
out_put:
- put_vsie_page(vcpu->kvm, vsie_page);
+ put_vsie_page(vsie_page);
return rc < 0 ? rc : 0;
}
--
2.47.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v1 4/4] KVM: s390: vsie: stop using "struct page" for vsie page
2025-01-07 15:43 [PATCH v1 0/4] KVM: s390: vsie: vsie page handling fixes + rework David Hildenbrand
` (2 preceding siblings ...)
2025-01-07 15:43 ` [PATCH v1 3/4] KVM: s390: vsie: stop messing with page refcount David Hildenbrand
@ 2025-01-07 15:43 ` David Hildenbrand
2025-01-08 18:17 ` Claudio Imbrenda
2025-01-08 18:21 ` [PATCH v1 0/4] KVM: s390: vsie: vsie page handling fixes + rework Claudio Imbrenda
2025-01-14 9:18 ` Christoph Schlameuss
5 siblings, 1 reply; 10+ messages in thread
From: David Hildenbrand @ 2025-01-07 15:43 UTC (permalink / raw)
To: linux-kernel
Cc: kvm, linux-s390, David Hildenbrand, Christian Borntraeger,
Janosch Frank, Claudio Imbrenda, Heiko Carstens, Vasily Gorbik,
Alexander Gordeev, Sven Schnelle, Thomas Huth,
Matthew Wilcox (Oracle)
Now that we no longer use page->index and the page refcount explicitly,
let's avoid messing with "struct page" completely.
Signed-off-by: David Hildenbrand <david@redhat.com>
---
arch/s390/include/asm/kvm_host.h | 4 +++-
arch/s390/kvm/vsie.c | 31 ++++++++++++-------------------
2 files changed, 15 insertions(+), 20 deletions(-)
diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
index 97c7c81275434..4581388411b71 100644
--- a/arch/s390/include/asm/kvm_host.h
+++ b/arch/s390/include/asm/kvm_host.h
@@ -931,12 +931,14 @@ struct sie_page2 {
u8 reserved928[0x1000 - 0x928]; /* 0x0928 */
};
+struct vsie_page;
+
struct kvm_s390_vsie {
struct mutex mutex;
struct radix_tree_root addr_to_page;
int page_count;
int next;
- struct page *pages[KVM_MAX_VCPUS];
+ struct vsie_page *pages[KVM_MAX_VCPUS];
};
struct kvm_s390_gisa_iam {
diff --git a/arch/s390/kvm/vsie.c b/arch/s390/kvm/vsie.c
index 29fdffeab635d..22643f4ae4455 100644
--- a/arch/s390/kvm/vsie.c
+++ b/arch/s390/kvm/vsie.c
@@ -599,7 +599,6 @@ void kvm_s390_vsie_gmap_notifier(struct gmap *gmap, unsigned long start,
struct kvm *kvm = gmap->private;
struct vsie_page *cur;
unsigned long prefix;
- struct page *page;
int i;
if (!gmap_is_shadow(gmap))
@@ -609,10 +608,9 @@ void kvm_s390_vsie_gmap_notifier(struct gmap *gmap, unsigned long start,
* therefore we can safely reference them all the time.
*/
for (i = 0; i < kvm->arch.vsie.page_count; i++) {
- page = READ_ONCE(kvm->arch.vsie.pages[i]);
- if (!page)
+ cur = READ_ONCE(kvm->arch.vsie.pages[i]);
+ if (!cur)
continue;
- cur = page_to_virt(page);
if (READ_ONCE(cur->gmap) != gmap)
continue;
prefix = cur->scb_s.prefix << GUEST_PREFIX_SHIFT;
@@ -1384,14 +1382,12 @@ static void put_vsie_page(struct vsie_page *vsie_page)
static struct vsie_page *get_vsie_page(struct kvm *kvm, unsigned long addr)
{
struct vsie_page *vsie_page;
- struct page *page;
int nr_vcpus;
rcu_read_lock();
- page = radix_tree_lookup(&kvm->arch.vsie.addr_to_page, addr >> 9);
+ vsie_page = radix_tree_lookup(&kvm->arch.vsie.addr_to_page, addr >> 9);
rcu_read_unlock();
- if (page) {
- vsie_page = page_to_virt(page);
+ if (vsie_page) {
if (try_get_vsie_page(vsie_page)) {
if (vsie_page->scb_gpa == addr)
return vsie_page;
@@ -1411,20 +1407,18 @@ static struct vsie_page *get_vsie_page(struct kvm *kvm, unsigned long addr)
mutex_lock(&kvm->arch.vsie.mutex);
if (kvm->arch.vsie.page_count < nr_vcpus) {
- page = alloc_page(GFP_KERNEL_ACCOUNT | __GFP_ZERO | GFP_DMA);
- if (!page) {
+ vsie_page = (void *)__get_free_page(GFP_KERNEL_ACCOUNT | __GFP_ZERO | GFP_DMA);
+ if (!vsie_page) {
mutex_unlock(&kvm->arch.vsie.mutex);
return ERR_PTR(-ENOMEM);
}
- vsie_page = page_to_virt(page);
__set_bit(VSIE_PAGE_IN_USE, &vsie_page->flags);
- kvm->arch.vsie.pages[kvm->arch.vsie.page_count] = page;
+ kvm->arch.vsie.pages[kvm->arch.vsie.page_count] = vsie_page;
kvm->arch.vsie.page_count++;
} else {
/* reuse an existing entry that belongs to nobody */
while (true) {
- page = kvm->arch.vsie.pages[kvm->arch.vsie.next];
- vsie_page = page_to_virt(page);
+ vsie_page = kvm->arch.vsie.pages[kvm->arch.vsie.next];
if (try_get_vsie_page(vsie_page))
break;
kvm->arch.vsie.next++;
@@ -1438,7 +1432,8 @@ static struct vsie_page *get_vsie_page(struct kvm *kvm, unsigned long addr)
vsie_page->scb_gpa = ULONG_MAX;
/* Double use of the same address or allocation failure. */
- if (radix_tree_insert(&kvm->arch.vsie.addr_to_page, addr >> 9, page)) {
+ if (radix_tree_insert(&kvm->arch.vsie.addr_to_page, addr >> 9,
+ vsie_page)) {
put_vsie_page(vsie_page);
mutex_unlock(&kvm->arch.vsie.mutex);
return NULL;
@@ -1519,20 +1514,18 @@ void kvm_s390_vsie_init(struct kvm *kvm)
void kvm_s390_vsie_destroy(struct kvm *kvm)
{
struct vsie_page *vsie_page;
- struct page *page;
int i;
mutex_lock(&kvm->arch.vsie.mutex);
for (i = 0; i < kvm->arch.vsie.page_count; i++) {
- page = kvm->arch.vsie.pages[i];
+ vsie_page = kvm->arch.vsie.pages[i];
kvm->arch.vsie.pages[i] = NULL;
- vsie_page = page_to_virt(page);
release_gmap_shadow(vsie_page);
/* free the radix tree entry */
if (vsie_page->scb_gpa != ULONG_MAX)
radix_tree_delete(&kvm->arch.vsie.addr_to_page,
vsie_page->scb_gpa >> 9);
- __free_page(page);
+ free_page((unsigned long)vsie_page);
}
kvm->arch.vsie.page_count = 0;
mutex_unlock(&kvm->arch.vsie.mutex);
--
2.47.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v1 4/4] KVM: s390: vsie: stop using "struct page" for vsie page
2025-01-07 15:43 ` [PATCH v1 4/4] KVM: s390: vsie: stop using "struct page" for vsie page David Hildenbrand
@ 2025-01-08 18:17 ` Claudio Imbrenda
0 siblings, 0 replies; 10+ messages in thread
From: Claudio Imbrenda @ 2025-01-08 18:17 UTC (permalink / raw)
To: David Hildenbrand
Cc: linux-kernel, kvm, linux-s390, Christian Borntraeger,
Janosch Frank, Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
Sven Schnelle, Thomas Huth, Matthew Wilcox (Oracle)
On Tue, 7 Jan 2025 16:43:44 +0100
David Hildenbrand <david@redhat.com> wrote:
[...]
> @@ -1438,7 +1432,8 @@ static struct vsie_page *get_vsie_page(struct kvm *kvm, unsigned long addr)
> vsie_page->scb_gpa = ULONG_MAX;
>
> /* Double use of the same address or allocation failure. */
> - if (radix_tree_insert(&kvm->arch.vsie.addr_to_page, addr >> 9, page)) {
> + if (radix_tree_insert(&kvm->arch.vsie.addr_to_page, addr >> 9,
> + vsie_page)) {
this is less than 100 columns, could have staid on one line
> put_vsie_page(vsie_page);
> mutex_unlock(&kvm->arch.vsie.mutex);
> return NULL;
> @@ -1519,20 +1514,18 @@ void kvm_s390_vsie_init(struct kvm *kvm)
> void kvm_s390_vsie_destroy(struct kvm *kvm)
> {
> struct vsie_page *vsie_page;
> - struct page *page;
> int i;
>
> mutex_lock(&kvm->arch.vsie.mutex);
> for (i = 0; i < kvm->arch.vsie.page_count; i++) {
> - page = kvm->arch.vsie.pages[i];
> + vsie_page = kvm->arch.vsie.pages[i];
> kvm->arch.vsie.pages[i] = NULL;
> - vsie_page = page_to_virt(page);
> release_gmap_shadow(vsie_page);
> /* free the radix tree entry */
> if (vsie_page->scb_gpa != ULONG_MAX)
> radix_tree_delete(&kvm->arch.vsie.addr_to_page,
> vsie_page->scb_gpa >> 9);
> - __free_page(page);
> + free_page((unsigned long)vsie_page);
> }
> kvm->arch.vsie.page_count = 0;
> mutex_unlock(&kvm->arch.vsie.mutex);
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v1 0/4] KVM: s390: vsie: vsie page handling fixes + rework
2025-01-07 15:43 [PATCH v1 0/4] KVM: s390: vsie: vsie page handling fixes + rework David Hildenbrand
` (3 preceding siblings ...)
2025-01-07 15:43 ` [PATCH v1 4/4] KVM: s390: vsie: stop using "struct page" for vsie page David Hildenbrand
@ 2025-01-08 18:21 ` Claudio Imbrenda
2025-01-08 20:42 ` David Hildenbrand
2025-01-14 9:18 ` Christoph Schlameuss
5 siblings, 1 reply; 10+ messages in thread
From: Claudio Imbrenda @ 2025-01-08 18:21 UTC (permalink / raw)
To: David Hildenbrand
Cc: linux-kernel, kvm, linux-s390, Christian Borntraeger,
Janosch Frank, Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
Sven Schnelle, Thomas Huth, Matthew Wilcox (Oracle)
On Tue, 7 Jan 2025 16:43:40 +0100
David Hildenbrand <david@redhat.com> wrote:
> We want to get rid of page->index, so let's make vsie code stop using it
> for the vsie page.
>
> While at it, also remove the usage of page refcount, so we can stop messing
> with "struct page" completely.
>
> ... of course, looking at this code after quite some years, I found some
> corner cases that should be fixed.
>
> Briefly sanity tested with kvm-unit-tests running inside a KVM VM, and
> nothing blew up.
I like this! (aside from a very tiny nit in patch 4)
if a v2 is not needed, I'll put the split line in patch 4 back together
myself when picking, no need to send a v2 just for that.
whole series:
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
>
> Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
> Cc: Janosch Frank <frankja@linux.ibm.com>
> Cc: Claudio Imbrenda <imbrenda@linux.ibm.com>
> Cc: Heiko Carstens <hca@linux.ibm.com>
> Cc: Vasily Gorbik <gor@linux.ibm.com>
> Cc: Alexander Gordeev <agordeev@linux.ibm.com>
> Cc: Sven Schnelle <svens@linux.ibm.com>
> Cc: Thomas Huth <thuth@redhat.com>
> Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
>
> David Hildenbrand (4):
> KVM: s390: vsie: fix some corner-cases when grabbing vsie pages
> KVM: s390: vsie: stop using page->index
> KVM: s390: vsie: stop messing with page refcount
> KVM: s390: vsie: stop using "struct page" for vsie page
>
> arch/s390/include/asm/kvm_host.h | 4 +-
> arch/s390/kvm/vsie.c | 104 ++++++++++++++++++++-----------
> 2 files changed, 69 insertions(+), 39 deletions(-)
>
>
> base-commit: fbfd64d25c7af3b8695201ebc85efe90be28c5a3
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v1 0/4] KVM: s390: vsie: vsie page handling fixes + rework
2025-01-08 18:21 ` [PATCH v1 0/4] KVM: s390: vsie: vsie page handling fixes + rework Claudio Imbrenda
@ 2025-01-08 20:42 ` David Hildenbrand
0 siblings, 0 replies; 10+ messages in thread
From: David Hildenbrand @ 2025-01-08 20:42 UTC (permalink / raw)
To: Claudio Imbrenda
Cc: linux-kernel, kvm, linux-s390, Christian Borntraeger,
Janosch Frank, Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
Sven Schnelle, Thomas Huth, Matthew Wilcox (Oracle)
On 08.01.25 19:21, Claudio Imbrenda wrote:
> On Tue, 7 Jan 2025 16:43:40 +0100
> David Hildenbrand <david@redhat.com> wrote:
>
>> We want to get rid of page->index, so let's make vsie code stop using it
>> for the vsie page.
>>
>> While at it, also remove the usage of page refcount, so we can stop messing
>> with "struct page" completely.
>>
>> ... of course, looking at this code after quite some years, I found some
>> corner cases that should be fixed.
>>
>> Briefly sanity tested with kvm-unit-tests running inside a KVM VM, and
>> nothing blew up.
>
> I like this! (aside from a very tiny nit in patch 4)
Thanks for the review!
>
> if a v2 is not needed, I'll put the split line in patch 4 back together
> myself when picking, no need to send a v2 just for that.
Yeah, that might be a case where "significantly increases readability"
might still apply.
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v1 0/4] KVM: s390: vsie: vsie page handling fixes + rework
2025-01-07 15:43 [PATCH v1 0/4] KVM: s390: vsie: vsie page handling fixes + rework David Hildenbrand
` (4 preceding siblings ...)
2025-01-08 18:21 ` [PATCH v1 0/4] KVM: s390: vsie: vsie page handling fixes + rework Claudio Imbrenda
@ 2025-01-14 9:18 ` Christoph Schlameuss
2025-01-14 9:37 ` David Hildenbrand
5 siblings, 1 reply; 10+ messages in thread
From: Christoph Schlameuss @ 2025-01-14 9:18 UTC (permalink / raw)
To: David Hildenbrand, linux-kernel
Cc: kvm, linux-s390, Christian Borntraeger, Janosch Frank,
Claudio Imbrenda, Heiko Carstens, Vasily Gorbik,
Alexander Gordeev, Sven Schnelle, Thomas Huth,
Matthew Wilcox (Oracle)
On Tue Jan 7, 2025 at 4:43 PM CET, David Hildenbrand wrote:
> We want to get rid of page->index, so let's make vsie code stop using it
> for the vsie page.
>
> While at it, also remove the usage of page refcount, so we can stop messing
> with "struct page" completely.
>
> ... of course, looking at this code after quite some years, I found some
> corner cases that should be fixed.
>
> Briefly sanity tested with kvm-unit-tests running inside a KVM VM, and
> nothing blew up.
Reviewed and tested the whole series.
Reviewed-by: Christoph Schlameuss <schlameuss@linux.ibm.com>
Tested-by: Christoph Schlameuss <schlameuss@linux.ibm.com>
>
> Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
> Cc: Janosch Frank <frankja@linux.ibm.com>
> Cc: Claudio Imbrenda <imbrenda@linux.ibm.com>
> Cc: Heiko Carstens <hca@linux.ibm.com>
> Cc: Vasily Gorbik <gor@linux.ibm.com>
> Cc: Alexander Gordeev <agordeev@linux.ibm.com>
> Cc: Sven Schnelle <svens@linux.ibm.com>
> Cc: Thomas Huth <thuth@redhat.com>
> Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
>
> David Hildenbrand (4):
> KVM: s390: vsie: fix some corner-cases when grabbing vsie pages
> KVM: s390: vsie: stop using page->index
> KVM: s390: vsie: stop messing with page refcount
> KVM: s390: vsie: stop using "struct page" for vsie page
>
> arch/s390/include/asm/kvm_host.h | 4 +-
> arch/s390/kvm/vsie.c | 104 ++++++++++++++++++++-----------
> 2 files changed, 69 insertions(+), 39 deletions(-)
>
>
> base-commit: fbfd64d25c7af3b8695201ebc85efe90be28c5a3
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v1 0/4] KVM: s390: vsie: vsie page handling fixes + rework
2025-01-14 9:18 ` Christoph Schlameuss
@ 2025-01-14 9:37 ` David Hildenbrand
0 siblings, 0 replies; 10+ messages in thread
From: David Hildenbrand @ 2025-01-14 9:37 UTC (permalink / raw)
To: Christoph Schlameuss, linux-kernel
Cc: kvm, linux-s390, Christian Borntraeger, Janosch Frank,
Claudio Imbrenda, Heiko Carstens, Vasily Gorbik,
Alexander Gordeev, Sven Schnelle, Thomas Huth,
Matthew Wilcox (Oracle)
On 14.01.25 10:18, Christoph Schlameuss wrote:
> On Tue Jan 7, 2025 at 4:43 PM CET, David Hildenbrand wrote:
>> We want to get rid of page->index, so let's make vsie code stop using it
>> for the vsie page.
>>
>> While at it, also remove the usage of page refcount, so we can stop messing
>> with "struct page" completely.
>>
>> ... of course, looking at this code after quite some years, I found some
>> corner cases that should be fixed.
>>
>> Briefly sanity tested with kvm-unit-tests running inside a KVM VM, and
>> nothing blew up.
>
> Reviewed and tested the whole series.
Thanks a bunch!
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2025-01-14 9:37 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-07 15:43 [PATCH v1 0/4] KVM: s390: vsie: vsie page handling fixes + rework David Hildenbrand
2025-01-07 15:43 ` [PATCH v1 1/4] KVM: s390: vsie: fix some corner-cases when grabbing vsie pages David Hildenbrand
2025-01-07 15:43 ` [PATCH v1 2/4] KVM: s390: vsie: stop using page->index David Hildenbrand
2025-01-07 15:43 ` [PATCH v1 3/4] KVM: s390: vsie: stop messing with page refcount David Hildenbrand
2025-01-07 15:43 ` [PATCH v1 4/4] KVM: s390: vsie: stop using "struct page" for vsie page David Hildenbrand
2025-01-08 18:17 ` Claudio Imbrenda
2025-01-08 18:21 ` [PATCH v1 0/4] KVM: s390: vsie: vsie page handling fixes + rework Claudio Imbrenda
2025-01-08 20:42 ` David Hildenbrand
2025-01-14 9:18 ` Christoph Schlameuss
2025-01-14 9:37 ` David Hildenbrand
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox