From: Janosch Frank <frankja@linux.ibm.com>
To: pbonzini@redhat.com
Cc: kvm@vger.kernel.org, frankja@linux.ibm.com, david@redhat.com,
borntraeger@linux.ibm.com, linux-s390@vger.kernel.org,
imbrenda@linux.ibm.com, nrb@linux.ibm.com, pmorel@linux.ibm.com
Subject: [GIT PULL 01/11] KVM: s390: fix KVM_S390_GET_CMMA_BITS for GFNs in memslot holes
Date: Wed, 21 Jun 2023 17:29:07 +0200 [thread overview]
Message-ID: <20230621153227.57250-2-frankja@linux.ibm.com> (raw)
In-Reply-To: <20230621153227.57250-1-frankja@linux.ibm.com>
From: Nico Boehr <nrb@linux.ibm.com>
The KVM_S390_GET_CMMA_BITS ioctl may return incorrect values when userspace
specifies a start_gfn outside of memslots.
This can occur when a VM has multiple memslots with a hole in between:
+-----+----------+--------+--------+
| ... | Slot N-1 | <hole> | Slot N |
+-----+----------+--------+--------+
^ ^ ^ ^
| | | |
GFN A A+B | |
A+B+C |
A+B+C+D
When userspace specifies a GFN in [A+B, A+B+C), it would expect to get the
CMMA values of the first dirty page in Slot N. However, userspace may get a
start_gfn of A+B+C+D with a count of 0, hence completely skipping over any
dirty pages in slot N.
The error is in kvm_s390_next_dirty_cmma(), which assumes
gfn_to_memslot_approx() will return the memslot _below_ the specified GFN
when the specified GFN lies outside a memslot. In reality it may return
either the memslot below or above the specified GFN.
When a memslot above the specified GFN is returned this happens:
- ofs is calculated, but since the memslot's base_gfn is larger than the
specified cur_gfn, ofs will underflow to a huge number.
- ofs is passed to find_next_bit(). Since ofs will exceed the memslot's
number of pages, the number of pages in the memslot is returned,
completely skipping over all bits in the memslot userspace would be
interested in.
Fix this by resetting ofs to zero when a memslot _above_ cur_gfn is
returned (cur_gfn < ms->base_gfn).
Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Fixes: afdad61615cc ("KVM: s390: Fix storage attributes migration with memory slots")
Message-Id: <20230324145424.293889-2-nrb@linux.ibm.com>
Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
---
arch/s390/kvm/kvm-s390.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 17b81659cdb2..670019696464 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -2156,6 +2156,10 @@ static unsigned long kvm_s390_next_dirty_cmma(struct kvm_memslots *slots,
ms = container_of(mnode, struct kvm_memory_slot, gfn_node[slots->node_idx]);
ofs = 0;
}
+
+ if (cur_gfn < ms->base_gfn)
+ ofs = 0;
+
ofs = find_next_bit(kvm_second_dirty_bitmap(ms), ms->npages, ofs);
while (ofs >= ms->npages && (mnode = rb_next(mnode))) {
ms = container_of(mnode, struct kvm_memory_slot, gfn_node[slots->node_idx]);
--
2.41.0
next prev parent reply other threads:[~2023-06-21 15:35 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-21 15:29 [GIT PULL 00/11] kvm: s390: Changes for 6.5 Janosch Frank
2023-06-21 15:29 ` Janosch Frank [this message]
2023-06-21 15:29 ` [GIT PULL 02/11] KVM: s390: selftests: add selftest for CMMA migration Janosch Frank
2023-06-21 15:29 ` [GIT PULL 03/11] KVM: s390: vsie: fix the length of APCB bitmap Janosch Frank
2023-06-21 15:29 ` [GIT PULL 04/11] KVM: s390/diag: fix racy access of physical cpu number in diag 9c handler Janosch Frank
2023-06-21 15:29 ` [GIT PULL 05/11] s390/uv: Always export uv_info Janosch Frank
2023-06-21 15:29 ` [GIT PULL 06/11] s390/uvdevice: Add info IOCTL Janosch Frank
2023-06-21 15:29 ` [GIT PULL 07/11] s390/uvdevice: Add 'Add Secret' UVC Janosch Frank
2023-06-21 15:29 ` [GIT PULL 08/11] s390/uvdevice: Add 'List Secrets' UVC Janosch Frank
2023-06-21 15:29 ` [GIT PULL 09/11] s390/uvdevice: Add 'Lock Secret Store' UVC Janosch Frank
2023-06-21 15:29 ` [GIT PULL 10/11] s390/uv: replace scnprintf with sysfs_emit Janosch Frank
2023-06-21 15:29 ` [GIT PULL 11/11] s390/uv: Update query for secret-UVCs Janosch Frank
2023-07-01 11:01 ` [GIT PULL 00/11] kvm: s390: Changes for 6.5 Paolo Bonzini
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=20230621153227.57250-2-frankja@linux.ibm.com \
--to=frankja@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=david@redhat.com \
--cc=imbrenda@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=nrb@linux.ibm.com \
--cc=pbonzini@redhat.com \
--cc=pmorel@linux.ibm.com \
/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