From patchwork Tue Dec 31 13:04:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Mammedov X-Patchwork-Id: 1216755 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="FmeXAg/l"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47nG7k48K5z9sPV for ; Wed, 1 Jan 2020 00:57:06 +1100 (AEDT) Received: from localhost ([::1]:42856 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1imI18-0006Xc-U2 for incoming@patchwork.ozlabs.org; Tue, 31 Dec 2019 08:57:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:57760) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1imHCl-0006I6-Py for qemu-devel@nongnu.org; Tue, 31 Dec 2019 08:05:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1imHCj-0005QB-W7 for qemu-devel@nongnu.org; Tue, 31 Dec 2019 08:04:59 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:33980 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1imHCj-0005Nm-Qg for qemu-devel@nongnu.org; Tue, 31 Dec 2019 08:04:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1577797497; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Xs8LnIRA2zAde8kFfiq4bXuPMiGndHHSXAMiLjjJMKY=; b=FmeXAg/lgN7YqDelYuFX8foAiOS90+cjH5U/nNDY4a5meJcQ3mM69UrRYthYEwGeexwhae BYBMYeIUHakApPRfj+ib20M6f4Kdm8CXflQVRU+9a9vjihQSdaCPd1XDJpaYyuiq094Es7 PCihgL4XLpo/EjK/pcOqZwjBR6391RY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-340-gjlngfIsOVel5on-7ngsoA-1; Tue, 31 Dec 2019 08:04:55 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CDF71800EB8 for ; Tue, 31 Dec 2019 13:04:54 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.37.153.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 558F678E96 for ; Tue, 31 Dec 2019 13:04:54 +0000 (UTC) From: Igor Mammedov To: qemu-devel@nongnu.org Subject: [PATCH 81/86] hostmem: fix strict bind policy Date: Tue, 31 Dec 2019 14:04:05 +0100 Message-Id: <1577797450-88458-82-git-send-email-imammedo@redhat.com> In-Reply-To: <1577797450-88458-1-git-send-email-imammedo@redhat.com> References: <1577797450-88458-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: gjlngfIsOVel5on-7ngsoA-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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" When option -mem-prealloc is used with one or more memory-backend objects, created backends may not obey configured bind policy or creation may fail after kernel attempts to move pages according to bind policy. Reason is in file_ram_alloc(), which will pre-allocate any descriptor based RAM if global mem_prealloc != 0 and that happens way before bind policy is applied to memory range. One way to fix it would be to extend memory_region_foo() API and add more invariants that could broken later due implicit dependencies that's hard to track. Another approach is to drop adhoc main RAM allocation and consolidate it around memory-backend. That allows to have single place that allocates guest RAM (main and memdev) in the same way and then global mem_prealloc could be replaced by backend's property[s] that will affect created memory-backend objects but only in correct order this time. With main RAM now converted to hostmem backends, there is no point in keeping global mem_prealloc around, so alias -mem-prealloc to "memory-backend.prealloc=on" machine compat[*] property and make mem_prealloc a local variable to only stir registration of compat property. *) currently user accessible -global works only with DEVICE based objects and extra work is needed to make it work with hostmem backends. But that is convenience option and out of scope of this already huge refactoring. Hence machine compat properties were used. Signed-off-by: Igor Mammedov --- include/sysemu/hostmem.h | 2 +- include/sysemu/sysemu.h | 1 - backends/hostmem-file.c | 1 - backends/hostmem-memfd.c | 1 - backends/hostmem.c | 12 +----------- exec.c | 11 ----------- vl.c | 3 ++- 7 files changed, 4 insertions(+), 27 deletions(-) diff --git a/include/sysemu/hostmem.h b/include/sysemu/hostmem.h index bdf8666..8276e53 100644 --- a/include/sysemu/hostmem.h +++ b/include/sysemu/hostmem.h @@ -70,7 +70,7 @@ struct HostMemoryBackend { /* protected */ uint64_t size; bool merge, dump, use_canonical_path; - bool prealloc, force_prealloc, is_mapped, share; + bool prealloc, is_mapped, share; uint32_t prealloc_threads; DECLARE_BITMAP(host_nodes, MAX_NODES + 1); HostMemPolicy policy; diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 8de9065..b72c773 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -53,7 +53,6 @@ extern uint8_t *boot_splash_filedata; extern bool enable_mlock; extern bool enable_cpu_pm; extern QEMUClockType rtc_clock; -extern int mem_prealloc; #define MAX_OPTION_ROMS 16 typedef struct QEMUOptionRom { diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c index cb319a9..c8c355f 100644 --- a/backends/hostmem-file.c +++ b/backends/hostmem-file.c @@ -51,7 +51,6 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) return; } - backend->force_prealloc = mem_prealloc; name = host_memory_backend_get_name(backend); memory_region_init_ram_from_file(&backend->mr, OBJECT(backend), name, diff --git a/backends/hostmem-memfd.c b/backends/hostmem-memfd.c index 26070b4..74ba987 100644 --- a/backends/hostmem-memfd.c +++ b/backends/hostmem-memfd.c @@ -45,7 +45,6 @@ memfd_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) return; } - backend->force_prealloc = mem_prealloc; fd = qemu_memfd_create(TYPE_MEMORY_BACKEND_MEMFD, backend->size, m->hugetlb, m->hugetlbsize, m->seal ? F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_SEAL : 0, diff --git a/backends/hostmem.c b/backends/hostmem.c index 4c23c77..1f09ade 100644 --- a/backends/hostmem.c +++ b/backends/hostmem.c @@ -215,7 +215,7 @@ static bool host_memory_backend_get_prealloc(Object *obj, Error **errp) { HostMemoryBackend *backend = MEMORY_BACKEND(obj); - return backend->prealloc || backend->force_prealloc; + return backend->prealloc; } static void host_memory_backend_set_prealloc(Object *obj, bool value, @@ -224,14 +224,6 @@ static void host_memory_backend_set_prealloc(Object *obj, bool value, Error *local_err = NULL; HostMemoryBackend *backend = MEMORY_BACKEND(obj); - if (backend->force_prealloc) { - if (value) { - error_setg(errp, - "remove -mem-prealloc to use the prealloc property"); - return; - } - } - if (!host_memory_backend_mr_inited(backend)) { backend->prealloc = value; return; @@ -288,8 +280,6 @@ static void host_memory_backend_init(Object *obj) /* TODO: convert this compat properties */ backend->merge = machine_mem_merge(machine); backend->dump = machine_dump_guest_core(machine); - backend->prealloc = mem_prealloc; - backend->prealloc_threads = 1; } static void host_memory_backend_post_init(Object *obj) diff --git a/exec.c b/exec.c index d0a7e7e..cbe5bc5 100644 --- a/exec.c +++ b/exec.c @@ -1802,8 +1802,6 @@ static void *file_ram_alloc(RAMBlock *block, bool truncate, Error **errp) { - Error *err = NULL; - MachineState *ms = MACHINE(qdev_get_machine()); void *area; block->page_size = qemu_fd_getpagesize(fd); @@ -1859,15 +1857,6 @@ static void *file_ram_alloc(RAMBlock *block, return NULL; } - if (mem_prealloc) { - os_mem_prealloc(fd, area, memory, ms->smp.cpus, &err); - if (err) { - error_propagate(errp, err); - qemu_ram_munmap(fd, area, memory); - return NULL; - } - } - block->fd = fd; return area; } diff --git a/vl.c b/vl.c index 61501cc..e0ec743 100644 --- a/vl.c +++ b/vl.c @@ -140,7 +140,6 @@ enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB; int display_opengl; const char* keyboard_layout = NULL; ram_addr_t ram_size; -int mem_prealloc = 0; /* force preallocation of physical target memory */ bool enable_mlock = false; bool enable_cpu_pm = false; int nb_nics; @@ -2868,6 +2867,7 @@ int main(int argc, char **argv, char **envp) const char *mem_path = NULL; BlockdevOptionsQueue bdo_queue = QSIMPLEQ_HEAD_INITIALIZER(bdo_queue); QemuPluginList plugin_list = QTAILQ_HEAD_INITIALIZER(plugin_list); + int mem_prealloc = 0; /* force preallocation of physical target memory */ os_set_line_buffering(); @@ -3968,6 +3968,7 @@ int main(int argc, char **argv, char **envp) if (mem_prealloc) { static GlobalProperty p[] = { {"memory-backend", "prealloc-threads", NULL}, + {"memory-backend", "prealloc", "on"}, }; p[0].value = g_strdup_printf("%d", current_machine->smp.cpus);