From patchwork Wed Oct 5 13:45:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 9362949 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AE7406077E for ; Wed, 5 Oct 2016 13:55:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9DE2B28763 for ; Wed, 5 Oct 2016 13:55:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F06728956; Wed, 5 Oct 2016 13:55:26 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3408928763 for ; Wed, 5 Oct 2016 13:55:26 +0000 (UTC) Received: from localhost ([::1]:49298 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1brmfN-00040Q-Aj for patchwork-qemu-devel@patchwork.kernel.org; Wed, 05 Oct 2016 09:55:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49825) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1brmVu-0004gb-IM for qemu-devel@nongnu.org; Wed, 05 Oct 2016 09:45:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1brmVp-0000e6-BY for qemu-devel@nongnu.org; Wed, 05 Oct 2016 09:45:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49256) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1brmVo-0000dm-Ti for qemu-devel@nongnu.org; Wed, 05 Oct 2016 09:45:33 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 08585C05ACAC for ; Wed, 5 Oct 2016 13:45:32 +0000 (UTC) Received: from emacs.mitica (ovpn-116-91.ams2.redhat.com [10.36.116.91]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u95DjCfS031257; Wed, 5 Oct 2016 09:45:30 -0400 From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 5 Oct 2016 15:45:05 +0200 Message-Id: <1475675109-8105-12-git-send-email-quintela@redhat.com> In-Reply-To: <1475675109-8105-1-git-send-email-quintela@redhat.com> References: <1475675109-8105-1-git-send-email-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 05 Oct 2016 13:45:32 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 11/15] RAMBlocks: Store page size X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: amit.shah@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Dr. David Alan Gilbert" Store the page size in each RAMBlock, we need it later. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- exec.c | 19 ++++++++++++------- include/exec/cpu-common.h | 1 + include/exec/ram_addr.h | 1 + 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/exec.c b/exec.c index c8389f9..9c457bc 100644 --- a/exec.c +++ b/exec.c @@ -1201,7 +1201,6 @@ static void *file_ram_alloc(RAMBlock *block, char *c; void *area = MAP_FAILED; int fd = -1; - int64_t page_size; if (kvm_enabled() && !kvm_has_sync_mmu()) { error_setg(errp, @@ -1256,17 +1255,17 @@ static void *file_ram_alloc(RAMBlock *block, */ } - page_size = qemu_fd_getpagesize(fd); - block->mr->align = MAX(page_size, QEMU_VMALLOC_ALIGN); + block->page_size = qemu_fd_getpagesize(fd); + block->mr->align = MAX(block->page_size, QEMU_VMALLOC_ALIGN); - if (memory < page_size) { + if (memory < block->page_size) { error_setg(errp, "memory size 0x" RAM_ADDR_FMT " must be equal to " - "or larger than page size 0x%" PRIx64, - memory, page_size); + "or larger than page size 0x%zx", + memory, block->page_size); goto error; } - memory = ROUND_UP(memory, page_size); + memory = ROUND_UP(memory, block->page_size); /* * ftruncate is not supported by hugetlbfs in older @@ -1421,6 +1420,11 @@ void qemu_ram_unset_idstr(RAMBlock *block) } } +size_t qemu_ram_pagesize(RAMBlock *rb) +{ + return rb->page_size; +} + static int memory_try_enable_merging(void *addr, size_t len) { if (!machine_mem_merge(current_machine)) { @@ -1660,6 +1664,7 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size, new_block->max_length = max_size; assert(max_size >= size); new_block->fd = -1; + new_block->page_size = getpagesize(); new_block->host = host; if (host) { new_block->flags |= RAM_PREALLOC; diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index 869ba41..cffdc13 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -63,6 +63,7 @@ RAMBlock *qemu_ram_block_from_host(void *ptr, bool round_offset, void qemu_ram_set_idstr(RAMBlock *block, const char *name, DeviceState *dev); void qemu_ram_unset_idstr(RAMBlock *block); const char *qemu_ram_get_idstr(RAMBlock *rb); +size_t qemu_ram_pagesize(RAMBlock *block); void cpu_physical_memory_rw(hwaddr addr, uint8_t *buf, int len, int is_write); diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index 2a9465d..54d7108 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -36,6 +36,7 @@ struct RAMBlock { /* RCU-enabled, writes protected by the ramlist lock */ QLIST_ENTRY(RAMBlock) next; int fd; + size_t page_size; }; static inline bool offset_in_ramblock(RAMBlock *b, ram_addr_t offset)