From nobody Wed Feb 11 01:32:53 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1733958351; cv=none; d=zohomail.com; s=zohoarc; b=jasbO88ZG06t2YS5uxkbuVpxAoU2T3EiF39y2j+zqlfIydZWbI8NoQfDw1Tmj8Ap1mQwpCLcfbZ+IeA1jlvzfeaxEGYY1SyVh5MEAn8zTt9KFjyaq4uNF+hB1NEeJyZp5s6RHW6T/8GDrhISl+GsCgDUwtqYCOE2kx4jyzQVJa8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733958351; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Vid9eybyfHkBbtn2DvtJa1fgolplJfizmxOi8mOdV4s=; b=Z1zqC0KaPu4+Mjq9w4LhVFqUirQcw43H/OcXdeQsgaFTS9OfPm8OK/mwXcBrwH9AzNZ5rTf2Ydbi/xVewI4V9iW+ddyriaEUvbxGyMJOJSo5vL/KGCUeVUKhn3KTmRQ2YXc0YXZu+a68+r6DMHUG0cWjoMDkbuacoWNHV1k3FMo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1733958350882783.3230197299993; Wed, 11 Dec 2024 15:05:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLVlP-0003cH-CB; Wed, 11 Dec 2024 18:05:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLVlM-0003au-Nn for qemu-devel@nongnu.org; Wed, 11 Dec 2024 18:05:01 -0500 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLVlK-0002Oc-Vb for qemu-devel@nongnu.org; Wed, 11 Dec 2024 18:05:00 -0500 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:5829:0:640:f281:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id A05E96145B; Thu, 12 Dec 2024 02:04:57 +0300 (MSK) Received: from d-tatianin-lin.yandex-team.ru (unknown [2a02:6b8:b081:1227::1:8]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id b4xnrS4GamI0-aTQBHnXU; Thu, 12 Dec 2024 02:04:57 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1733958297; bh=Vid9eybyfHkBbtn2DvtJa1fgolplJfizmxOi8mOdV4s=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=VUaXkpQuwgitdxYTmK62r2fe/46rjucr3JbG2UgPUm+jpAKYWZcT/faFRRNxsIusT qPWYMgIjTt3hQ7X6CppdOB34UiIEyHkddz1tnrGQhnfXSTCfcBpCYVbtnrTb0J8/HW C7Pht/9qfThgX35D5XA6xtDlLVpXbP1MVDY2BPmk= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Daniil Tatianin To: Paolo Bonzini Cc: Daniil Tatianin , Stefan Weil , Peter Xu , Fabiano Rosas , qemu-devel@nongnu.org Subject: [PATCH v3 3/4] sysemu: introduce a new MlockState enum Date: Thu, 12 Dec 2024 02:04:32 +0300 Message-Id: <20241211230433.1371327-4-d-tatianin@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241211230433.1371327-1-d-tatianin@yandex-team.ru> References: <20241211230433.1371327-1-d-tatianin@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=d-tatianin@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1733958355711116600 Content-Type: text/plain; charset="utf-8" Replace the boolean value enable_mlock with an enum and add a helper to decide whether we should be calling os_mlock. This is a stepping stone towards introducing a new mlock mode, which will be the third possible state of this enum. Signed-off-by: Daniil Tatianin Reviewed-by: Peter Xu Reviewed-by: Vladimir Sementsov-Ogievskiy --- hw/virtio/virtio-mem.c | 2 +- include/sysemu/sysemu.h | 10 +++++++++- migration/postcopy-ram.c | 2 +- system/globals.c | 7 ++++++- system/vl.c | 9 +++++++-- 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c index 80ada89551..78d27eb141 100644 --- a/hw/virtio/virtio-mem.c +++ b/hw/virtio/virtio-mem.c @@ -988,7 +988,7 @@ static void virtio_mem_device_realize(DeviceState *dev,= Error **errp) return; } =20 - if (enable_mlock) { + if (should_mlock(mlock_state)) { error_setg(errp, "Incompatible with mlock"); return; } diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 7ec419ce13..f1c9895057 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -43,10 +43,18 @@ extern int display_opengl; extern const char *keyboard_layout; extern int old_param; extern uint8_t *boot_splash_filedata; -extern bool enable_mlock; extern bool enable_cpu_pm; extern QEMUClockType rtc_clock; =20 +typedef enum { + MLOCK_OFF =3D 0, + MLOCK_ON, +} MlockState; + +bool should_mlock(MlockState); + +extern MlockState mlock_state; + #define MAX_OPTION_ROMS 16 typedef struct QEMUOptionRom { const char *name; diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 36ec6a3d75..a6a26a9cbb 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -651,7 +651,7 @@ int postcopy_ram_incoming_cleanup(MigrationIncomingStat= e *mis) mis->have_fault_thread =3D false; } =20 - if (enable_mlock) { + if (should_mlock(mlock_state)) { if (os_mlock(false) < 0) { error_report("mlock: %s", strerror(errno)); /* diff --git a/system/globals.c b/system/globals.c index 84ce943ac9..c6452d4a0d 100644 --- a/system/globals.c +++ b/system/globals.c @@ -31,10 +31,15 @@ #include "sysemu/cpus.h" #include "sysemu/sysemu.h" =20 +bool should_mlock(MlockState state) +{ + return state =3D=3D MLOCK_ON; +} + enum vga_retrace_method vga_retrace_method =3D VGA_RETRACE_DUMB; int display_opengl; const char* keyboard_layout; -bool enable_mlock; +MlockState mlock_state; bool enable_cpu_pm; int autostart =3D 1; int vga_interface_type =3D VGA_NONE; diff --git a/system/vl.c b/system/vl.c index f0b3ad0df7..a41306ac84 100644 --- a/system/vl.c +++ b/system/vl.c @@ -792,7 +792,7 @@ static QemuOptsList qemu_run_with_opts =3D { =20 static void realtime_init(void) { - if (enable_mlock) { + if (should_mlock(mlock_state)) { if (os_mlock(false) < 0) { error_report("locking memory failed"); exit(1); @@ -1858,13 +1858,18 @@ static void object_option_parse(const char *str) static void overcommit_parse(const char *str) { QemuOpts *opts; + bool enable_mlock; =20 opts =3D qemu_opts_parse_noisily(qemu_find_opts("overcommit"), str, false); if (!opts) { exit(1); } - enable_mlock =3D qemu_opt_get_bool(opts, "mem-lock", enable_mlock); + + enable_mlock =3D qemu_opt_get_bool(opts, "mem-lock", + should_mlock(mlock_state)); + mlock_state =3D enable_mlock ? MLOCK_ON : MLOCK_OFF; + enable_cpu_pm =3D qemu_opt_get_bool(opts, "cpu-pm", enable_cpu_pm); } =20 --=20 2.34.1