From patchwork Wed Mar 18 19:11:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 451588 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id A2BD814011D for ; Thu, 19 Mar 2015 06:12:39 +1100 (AEDT) Received: from localhost ([::1]:35324 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYJOP-0003DW-8S for incoming@patchwork.ozlabs.org; Wed, 18 Mar 2015 15:12:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52853) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYJNs-0002Bm-Pi for qemu-devel@nongnu.org; Wed, 18 Mar 2015 15:12:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YYJNm-0005pK-Ql for qemu-devel@nongnu.org; Wed, 18 Mar 2015 15:12:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39510) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYJNm-0005p7-K4 for qemu-devel@nongnu.org; Wed, 18 Mar 2015 15:11:58 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t2IJBp8F031150 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 18 Mar 2015 15:11:51 -0400 Received: from apm-mustang-ev3-05.ml3.eng.bos.redhat.com (apm-mustang-ev3-05.ml3.eng.bos.redhat.com [10.19.176.136]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t2IJBm4k017778; Wed, 18 Mar 2015 15:11:50 -0400 From: Andrew Jones To: kvmarm@lists.cs.columbia.edu, qemu-devel@nongnu.org, ard.biesheuvel@linaro.org, christoffer.dall@linaro.org, marc.zyngier@arm.com, peter.maydell@linaro.org, pbonzini@redhat.com Date: Wed, 18 Mar 2015 15:11:45 -0400 Message-Id: <1426705908-2765-2-git-send-email-drjones@redhat.com> In-Reply-To: <1426705908-2765-1-git-send-email-drjones@redhat.com> References: <1426705700-2564-1-git-send-email-drjones@redhat.com> <1426705908-2765-1-git-send-email-drjones@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: catalin.marinas@arm.com, lersek@redhat.com, agraf@suse.de, m.smarduch@samsung.com Subject: [Qemu-devel] [RFC PATCH 1/4] kvm-all: put kvm_mem_flags to more work X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Currently kvm_mem_flags just translates bools to bits, let's make it also determine the bools first. This avoids its parameter list growing each time we add a flag. Signed-off-by: Andrew Jones --- kvm-all.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/kvm-all.c b/kvm-all.c index 55025cc366992..a1bc05a8d5c5c 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -295,10 +295,14 @@ err: * dirty pages logging control */ -static int kvm_mem_flags(KVMState *s, bool log_dirty, bool readonly) +static int kvm_mem_flags(MemoryRegion *mr) { + bool readonly = mr->readonly || memory_region_is_romd(mr); int flags = 0; - flags = log_dirty ? KVM_MEM_LOG_DIRTY_PAGES : 0; + + if (memory_region_is_logging(mr)) { + flags |= KVM_MEM_LOG_DIRTY_PAGES; + } if (readonly && kvm_readonly_mem_allowed) { flags |= KVM_MEM_READONLY; } @@ -313,7 +317,10 @@ static int kvm_slot_dirty_pages_log_change(KVMSlot *mem, bool log_dirty) old_flags = mem->flags; - flags = (mem->flags & ~mask) | kvm_mem_flags(s, log_dirty, false); + flags = mem->flags & ~mask; + if (log_dirty) { + flags |= KVM_MEM_LOG_DIRTY_PAGES; + } mem->flags = flags; /* If nothing changed effectively, no need to issue ioctl */ @@ -643,9 +650,7 @@ static void kvm_set_phys_mem(MemoryRegionSection *section, bool add) KVMSlot *mem, old; int err; MemoryRegion *mr = section->mr; - bool log_dirty = memory_region_is_logging(mr); bool writeable = !mr->readonly && !mr->rom_device; - bool readonly_flag = mr->readonly || memory_region_is_romd(mr); hwaddr start_addr = section->offset_within_address_space; ram_addr_t size = int128_get64(section->size); void *ram = NULL; @@ -689,7 +694,7 @@ static void kvm_set_phys_mem(MemoryRegionSection *section, bool add) (ram - start_addr == mem->ram - mem->start_addr)) { /* The new slot fits into the existing one and comes with * identical parameters - update flags and done. */ - kvm_slot_dirty_pages_log_change(mem, log_dirty); + kvm_slot_dirty_pages_log_change(mem, memory_region_is_logging(mr)); return; } @@ -722,7 +727,7 @@ static void kvm_set_phys_mem(MemoryRegionSection *section, bool add) mem->memory_size = old.memory_size; mem->start_addr = old.start_addr; mem->ram = old.ram; - mem->flags = kvm_mem_flags(s, log_dirty, readonly_flag); + mem->flags = kvm_mem_flags(mr); err = kvm_set_user_memory_region(s, mem); if (err) { @@ -743,7 +748,7 @@ static void kvm_set_phys_mem(MemoryRegionSection *section, bool add) mem->memory_size = start_addr - old.start_addr; mem->start_addr = old.start_addr; mem->ram = old.ram; - mem->flags = kvm_mem_flags(s, log_dirty, readonly_flag); + mem->flags = kvm_mem_flags(mr); err = kvm_set_user_memory_region(s, mem); if (err) { @@ -767,7 +772,7 @@ static void kvm_set_phys_mem(MemoryRegionSection *section, bool add) size_delta = mem->start_addr - old.start_addr; mem->memory_size = old.memory_size - size_delta; mem->ram = old.ram + size_delta; - mem->flags = kvm_mem_flags(s, log_dirty, readonly_flag); + mem->flags = kvm_mem_flags(mr); err = kvm_set_user_memory_region(s, mem); if (err) { @@ -789,7 +794,7 @@ static void kvm_set_phys_mem(MemoryRegionSection *section, bool add) mem->memory_size = size; mem->start_addr = start_addr; mem->ram = ram; - mem->flags = kvm_mem_flags(s, log_dirty, readonly_flag); + mem->flags = kvm_mem_flags(mr); err = kvm_set_user_memory_region(s, mem); if (err) {