From patchwork Fri Feb 22 15:06:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 10826387 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7D0C21805 for ; Fri, 22 Feb 2019 15:07:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6B0B1313CD for ; Fri, 22 Feb 2019 15:07:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E8C23143F; Fri, 22 Feb 2019 15:07:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C7EB5313CD for ; Fri, 22 Feb 2019 15:07:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727260AbfBVPHn (ORCPT ); Fri, 22 Feb 2019 10:07:43 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:44756 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726531AbfBVPHn (ORCPT ); Fri, 22 Feb 2019 10:07:43 -0500 Received: by mail-pl1-f196.google.com with SMTP id c4so1205697pls.11; Fri, 22 Feb 2019 07:07:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=CpN/0CU4PssPimucBDW3qrQE8gB87OVfmQk4MBzKcb0=; b=sZn34zh121esQ9rHu7OfdWYgI567kymvyPtthBEFuNmOfJWc+SL6SiHZRqxvpLi/DS 5j/HkSPzuvMHTcnA3dFymxGR4aVkky9kxKZwNg/3Y/dwfBbb5Au9iqewX8XYNPB1VdL0 6k+2hIADWR2i5LzFzyDDyL7AG59h18992mECk/VkD80umCmdi5UmrWr9Px/rOmt7JwN9 Zaxl2vdv628qNQ5yrIMbynBoCupTr5SOdm9HZF35o07h8qIZNoYKY+FGD0/1lErJMkiS Qrm986aMPblJDFt1pQK+S/V7cGMf2wMl/qZYusz1PX9Ia+wGbYclVCX4a2J/up3pieyZ ugpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=CpN/0CU4PssPimucBDW3qrQE8gB87OVfmQk4MBzKcb0=; b=ICQ/w297UVxnfATQjBDlVP4lGXYXvtnnGZvyYA6pTCPkW1DfzL59IMva9uWZvUQM0R okg2rxDbud4VqocuHe2zsTFoUtiScmyjbt0Bj43r1FIZfmCk6H8MJqxDrr208IBhMxSe xe7cRvHui+mv8XH3Bl95ci4EirpMKesyQ6TE9tB4lPdAwVuxp3RZkRwyAqeDiAM5YEIS uuzEHOd2L2usFf0rJ64DjthuNSM4pj6rlLStOgr3o87QpQRtuAqk9afQFbXMEpvHAvG2 8cBVZi5UT/FWfcOo1IEmlxsW03wgebbZTQ+OLxetNwnOvA6mzEoDxbboZ7aykieBI5ak QTFA== X-Gm-Message-State: AHQUAubXhpZkzqqufflqKsUPzaPPKXP3azJoiKrCwnUv/VOmVh7UUMqY zMmz64WNeS5M/yC9b1jyu/g= X-Google-Smtp-Source: AHgI3IYMepLojh2DFE0IB9ZwxY853xtXspAtLpEVzZyrdb9ij0IMu6tFRllJJBjnpjslRP6pU0AOLQ== X-Received: by 2002:a17:902:bd97:: with SMTP id q23mr4685513pls.210.1550848062453; Fri, 22 Feb 2019 07:07:42 -0800 (PST) Received: from localhost.corp.microsoft.com ([167.220.255.67]) by smtp.googlemail.com with ESMTPSA id a4sm6151780pga.52.2019.02.22.07.07.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 Feb 2019 07:07:41 -0800 (PST) From: lantianyu1986@gmail.com X-Google-Original-From: Tianyu.Lan@microsoft.com Cc: Lan Tianyu , christoffer.dall@arm.com, marc.zyngier@arm.com, linux@armlinux.org.uk, catalin.marinas@arm.com, will.deacon@arm.com, jhogan@kernel.org, ralf@linux-mips.org, paul.burton@mips.com, paulus@ozlabs.org, benh@kernel.crashing.org, mpe@ellerman.id.au, pbonzini@redhat.com, rkrcmar@redhat.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, x86@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, kvm-ppc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, michael.h.kelley@microsoft.com, kys@microsoft.com, vkuznets@redhat.com Subject: [PATCH V3 6/10] KVM: Add kvm_get_memslot() to get memslot via slot id Date: Fri, 22 Feb 2019 23:06:33 +0800 Message-Id: <20190222150637.2337-7-Tianyu.Lan@microsoft.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20190222150637.2337-1-Tianyu.Lan@microsoft.com> References: <20190222150637.2337-1-Tianyu.Lan@microsoft.com> To: unlisted-recipients:; (no To-header on input) Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Lan Tianyu 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 --- 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)