All of lore.kernel.org
 help / color / mirror / Atom feed
From: Keqian Zhu <zhukeqian1@huawei.com>
To: Peter Maydell <peter.maydell@linaro.org>,
	Paolo Bonzini <pbonzini@redhat.com>,
	"Dr . David Alan Gilbert" <dgilbert@redhat.com>,
	"Peter Xu" <peterx@redhat.com>
Cc: jiangkunkun@huawei.com, qemu-devel@nongnu.org,
	qemu-arm@nongnu.org, Zenghui Yu <yuzenghui@huawei.com>,
	wanghaibin.wang@huawei.com, Keqian Zhu <zhukeqian1@huawei.com>
Subject: [PATCH 2/2] accel: kvm: Add aligment check for kvm_log_clear_one_slot
Date: Tue, 15 Dec 2020 15:19:48 +0800	[thread overview]
Message-ID: <20201215071948.23940-3-zhukeqian1@huawei.com> (raw)
In-Reply-To: <20201215071948.23940-1-zhukeqian1@huawei.com>

The parameters start and size are transfered from QEMU memory
emulation layer. It can promise that they are TARGET_PAGE_SIZE
aligned. However, KVM needs they are qemu_real_page_size aligned.

Though no caller breaks this aligned requirement currently, we'd
better add an explicit check to avoid future breaking.

Signed-off-by: Keqian Zhu <zhukeqian1@huawei.com>
---
 accel/kvm/kvm-all.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index c5e06288eb..3d0e3aa872 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -701,6 +701,11 @@ static int kvm_log_clear_one_slot(KVMSlot *mem, int as_id, uint64_t start,
     unsigned long *bmap_clear = NULL, psize = qemu_real_host_page_size;
     int ret;
 
+    /* Make sure start and size are psize aligned */
+    if (!QEMU_IS_ALIGNED(start, psize) || !QEMU_IS_ALIGNED(size, psize)) {
+        return -EINVAL;
+    }
+
     /*
      * We need to extend either the start or the size or both to
      * satisfy the KVM interface requirement.  Firstly, do the start
-- 
2.23.0



  parent reply	other threads:[~2020-12-15  7:25 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-15  7:19 [PATCH 0/2] accel: kvm: Some bugfixes for kvm dirty log Keqian Zhu
2020-12-15  7:19 ` [PATCH 1/2] accel: kvm: Fix memory waste under mismatch page size Keqian Zhu
2020-12-15 11:20   ` Andrew Jones
2020-12-16  8:08     ` Keqian Zhu
2020-12-15 17:57   ` Peter Xu
2020-12-16  8:21     ` Keqian Zhu
2020-12-16 20:48       ` Peter Xu
2020-12-17  1:03         ` Keqian Zhu
2020-12-15  7:19 ` Keqian Zhu [this message]
2020-12-15 11:55   ` [PATCH 2/2] accel: kvm: Add aligment check for kvm_log_clear_one_slot Andrew Jones
2020-12-16  7:23     ` Andrew Jones
2020-12-16  8:17       ` Keqian Zhu
2020-12-16  8:11     ` Keqian Zhu

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=20201215071948.23940-3-zhukeqian1@huawei.com \
    --to=zhukeqian1@huawei.com \
    --cc=dgilbert@redhat.com \
    --cc=jiangkunkun@huawei.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=peterx@redhat.com \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=wanghaibin.wang@huawei.com \
    --cc=yuzenghui@huawei.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.