[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20190222150637.2337-7-Tianyu.Lan@microsoft.com>
Date: Fri, 22 Feb 2019 23:06:33 +0800
From: lantianyu1986@...il.com
To: unlisted-recipients:; (no To-header on input)
Cc: Lan Tianyu <Tianyu.Lan@...rosoft.com>, christoffer.dall@....com,
marc.zyngier@....com, linux@...linux.org.uk,
catalin.marinas@....com, will.deacon@....com, jhogan@...nel.org,
ralf@...ux-mips.org, paul.burton@...s.com, paulus@...abs.org,
benh@...nel.crashing.org, mpe@...erman.id.au, pbonzini@...hat.com,
rkrcmar@...hat.com, tglx@...utronix.de, mingo@...hat.com,
bp@...en8.de, hpa@...or.com, x86@...nel.org,
linux-arm-kernel@...ts.infradead.org, kvmarm@...ts.cs.columbia.edu,
linux-kernel@...r.kernel.org, linux-mips@...r.kernel.org,
kvm-ppc@...r.kernel.org, linuxppc-dev@...ts.ozlabs.org,
kvm@...r.kernel.org, michael.h.kelley@...rosoft.com,
kys@...rosoft.com, vkuznets@...hat.com
Subject: [PATCH V3 6/10] KVM: Add kvm_get_memslot() to get memslot via slot id
From: Lan Tianyu <Tianyu.Lan@...rosoft.com>
This patch is to add kvm_get_memslot() to get struct kvm_memory_slot
via slot it and remove redundant codes. The function will also be used
in the following changes.
Signed-off-by: Lan Tianyu <Tianyu.Lan@...rosoft.com>
---
include/linux/kvm_host.h | 1 +
virt/kvm/kvm_main.c | 45 +++++++++++++++++++--------------------------
2 files changed, 20 insertions(+), 26 deletions(-)
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 9d55c63db09b..87e665069f6d 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -779,6 +779,7 @@ int kvm_get_dirty_log_protect(struct kvm *kvm,
struct kvm_dirty_log *log, bool *flush);
int kvm_clear_dirty_log_protect(struct kvm *kvm,
struct kvm_clear_dirty_log *log, bool *flush);
+struct kvm_memory_slot *kvm_get_memslot(struct kvm *kvm, u32 slot);
void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm,
struct kvm_memory_slot *slot,
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 276af92ace6c..61ddc3f0425c 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -1099,22 +1099,30 @@ static int kvm_vm_ioctl_set_memory_region(struct kvm *kvm,
return kvm_set_memory_region(kvm, mem);
}
+struct kvm_memory_slot *kvm_get_memslot(struct kvm *kvm, u32 slot)
+{
+ struct kvm_memslots *slots;
+ int as_id, id;
+
+ as_id = slot >> 16;
+ id = (u16)slot;
+ if (as_id >= KVM_ADDRESS_SPACE_NUM || id >= KVM_USER_MEM_SLOTS)
+ return NULL;
+
+ slots = __kvm_memslots(kvm, as_id);
+ return id_to_memslot(slots, id);
+}
+
int kvm_get_dirty_log(struct kvm *kvm,
struct kvm_dirty_log *log, int *is_dirty)
{
- struct kvm_memslots *slots;
struct kvm_memory_slot *memslot;
- int i, as_id, id;
unsigned long n;
unsigned long any = 0;
+ int i;
- as_id = log->slot >> 16;
- id = (u16)log->slot;
- if (as_id >= KVM_ADDRESS_SPACE_NUM || id >= KVM_USER_MEM_SLOTS)
- return -EINVAL;
+ memslot = kvm_get_memslot(kvm, log->slot);
- slots = __kvm_memslots(kvm, as_id);
- memslot = id_to_memslot(slots, id);
if (!memslot->dirty_bitmap)
return -ENOENT;
@@ -1158,20 +1166,13 @@ EXPORT_SYMBOL_GPL(kvm_get_dirty_log);
int kvm_get_dirty_log_protect(struct kvm *kvm,
struct kvm_dirty_log *log, bool *flush)
{
- struct kvm_memslots *slots;
struct kvm_memory_slot *memslot;
- int i, as_id, id;
unsigned long n;
unsigned long *dirty_bitmap;
unsigned long *dirty_bitmap_buffer;
+ int i;
- as_id = log->slot >> 16;
- id = (u16)log->slot;
- if (as_id >= KVM_ADDRESS_SPACE_NUM || id >= KVM_USER_MEM_SLOTS)
- return -EINVAL;
-
- slots = __kvm_memslots(kvm, as_id);
- memslot = id_to_memslot(slots, id);
+ memslot = kvm_get_memslot(kvm, log->slot);
dirty_bitmap = memslot->dirty_bitmap;
if (!dirty_bitmap)
@@ -1227,24 +1228,16 @@ EXPORT_SYMBOL_GPL(kvm_get_dirty_log_protect);
int kvm_clear_dirty_log_protect(struct kvm *kvm,
struct kvm_clear_dirty_log *log, bool *flush)
{
- struct kvm_memslots *slots;
struct kvm_memory_slot *memslot;
- int as_id, id;
gfn_t offset;
unsigned long i, n;
unsigned long *dirty_bitmap;
unsigned long *dirty_bitmap_buffer;
- as_id = log->slot >> 16;
- id = (u16)log->slot;
- if (as_id >= KVM_ADDRESS_SPACE_NUM || id >= KVM_USER_MEM_SLOTS)
- return -EINVAL;
-
if ((log->first_page & 63) || (log->num_pages & 63))
return -EINVAL;
- slots = __kvm_memslots(kvm, as_id);
- memslot = id_to_memslot(slots, id);
+ memslot = kvm_get_memslot(kvm, log->slot);
dirty_bitmap = memslot->dirty_bitmap;
if (!dirty_bitmap)
--
2.14.4
Powered by blists - more mailing lists