From patchwork Mon Apr 29 15:55:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 13647317 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id C0CE5C4345F for ; Mon, 29 Apr 2024 15:56:57 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1TMF-0004X3-J5; Mon, 29 Apr 2024 11:55:59 -0400 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 1s1TM6-0004TS-5l for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:55:50 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s1TM0-0005De-9K for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:55:46 -0400 Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43TFmlHi021730; Mon, 29 Apr 2024 15:55:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2023-11-20; bh=APXR9kXyXmqqAjJjI1A0Ctj4zR+Lv7xd+zkmXLq6AjI=; b=XA4RY79X18QR8yX0r0vv1vY4JGRhMXR0CqzLsbktzzcYSIMGtJeBOGsMmNDtiEkhj/kH 1zt3sleRsHAB8aJNzVbwsG6lbKXOpGnycFEe5oRw+VvLrvA0rqHPOYXKHIpno8B6n2hT +t/RaRaelO1tFo5z9ZlZW34WsRZrXqnU0xScYTM8MH7+zFQikssKkY6evv0u+nfI+JQa pt6eA17GaTZ69RzuGsiRF0Nm1S9bAOmWfqOOs+Fp+qP9w/14oiBGBnKtTWPK+aDPKVA6 Z59cowPP1eQeblIn+mJRD247R234GXlZ0LQ9xavHxDx5lzSma/djyu0axr/4oJ9huLOs cQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrr54axse-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:38 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43TEgWMX011336; Mon, 29 Apr 2024 15:55:37 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt6j619-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:37 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43TFtaGU034442; Mon, 29 Apr 2024 15:55:36 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3xrqt6j5ys-2; Mon, 29 Apr 2024 15:55:36 +0000 From: Steve Sistare To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , David Hildenbrand , Igor Mammedov , Eduardo Habkost , Marcel Apfelbaum , Philippe Mathieu-Daude , Paolo Bonzini , "Daniel P. Berrange" , Markus Armbruster , Steve Sistare Subject: [PATCH V1 01/26] oslib: qemu_clear_cloexec Date: Mon, 29 Apr 2024 08:55:10 -0700 Message-Id: <1714406135-451286-2-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> References: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-29_14,2024-04-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404290101 X-Proofpoint-ORIG-GUID: eg93MLnPdshm7l52FbHOTNVga8e6GdBq X-Proofpoint-GUID: eg93MLnPdshm7l52FbHOTNVga8e6GdBq Received-SPF: pass client-ip=205.220.177.32; envelope-from=steven.sistare@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Define qemu_clear_cloexec, analogous to qemu_set_cloexec. Signed-off-by: Steve Sistare Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Marc-André Lureau Reviewed-by: Fabiano Rosas --- include/qemu/osdep.h | 9 +++++++++ util/oslib-posix.c | 9 +++++++++ util/oslib-win32.c | 4 ++++ 3 files changed, 22 insertions(+) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index c7053cd..b58f312 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -660,6 +660,15 @@ ssize_t qemu_write_full(int fd, const void *buf, size_t count) void qemu_set_cloexec(int fd); +/* + * Clear FD_CLOEXEC for a descriptor. + * + * The caller must guarantee that no other fork+exec's occur before the + * exec that is intended to inherit this descriptor, eg by suspending CPUs + * and blocking monitor commands. + */ +void qemu_clear_cloexec(int fd); + /* Return a dynamically allocated directory path that is appropriate for storing * local state. * diff --git a/util/oslib-posix.c b/util/oslib-posix.c index e764416..614c3e5 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -272,6 +272,15 @@ int qemu_socketpair(int domain, int type, int protocol, int sv[2]) return ret; } +void qemu_clear_cloexec(int fd) +{ + int f; + f = fcntl(fd, F_GETFD); + assert(f != -1); + f = fcntl(fd, F_SETFD, f & ~FD_CLOEXEC); + assert(f != -1); +} + char * qemu_get_local_state_dir(void) { diff --git a/util/oslib-win32.c b/util/oslib-win32.c index b623830..c3e969a 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -222,6 +222,10 @@ void qemu_set_cloexec(int fd) { } +void qemu_clear_cloexec(int fd) +{ +} + int qemu_get_thread_id(void) { return GetCurrentThreadId(); From patchwork Mon Apr 29 15:55:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 13647312 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 5C993C4345F for ; Mon, 29 Apr 2024 15:56:28 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1TMD-0004Wn-Kh; Mon, 29 Apr 2024 11:55:57 -0400 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 1s1TM6-0004TQ-5A for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:55:50 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s1TM0-0005Dr-E2 for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:55:47 -0400 Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43TFmk5h006740; Mon, 29 Apr 2024 15:55:39 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=juAJZ9JJdV6p90qNLNXdU3rK88VMPL7lXoIHnJjCa8U=; b=EamvT5bY6OBU9AkYgTdKoO37IT9QjAeMuLycTjTG9/+GvxE85ZqTSVirWP7Nnh85lTxB 8sUmKawgWqDoAZB5n6C5KHx04r+4Hg8iGWo4fCq6tY5VJauRTyoDaKAwD6KoFCACN+U2 XaROH4KsSfh/840sFwZh4YXZQxRDCgmqD/KZa7ad+NPWouECQZS+ESygUvSB9s1rgONk vPpgjdG6BdUAS/yrEVwM/QnyCUqm5rot9WyQQxo5Y7azKALJW7qsspC7RV4uuG90xXGP EwZx07iBgxj/x/eBHkb18XdXDbMiCZoSfs4PtJqtGGcWfrPpamNhCnsw+6VxQdy0yslN Eg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrsdejwmf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:39 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43TEt9HQ011467; Mon, 29 Apr 2024 15:55:38 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt6j628-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:38 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43TFtaGW034442; Mon, 29 Apr 2024 15:55:37 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3xrqt6j5ys-3; Mon, 29 Apr 2024 15:55:37 +0000 From: Steve Sistare To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , David Hildenbrand , Igor Mammedov , Eduardo Habkost , Marcel Apfelbaum , Philippe Mathieu-Daude , Paolo Bonzini , "Daniel P. Berrange" , Markus Armbruster , Steve Sistare Subject: [PATCH V1 02/26] vl: helper to request re-exec Date: Mon, 29 Apr 2024 08:55:11 -0700 Message-Id: <1714406135-451286-3-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> References: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-29_14,2024-04-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404290101 X-Proofpoint-GUID: k_u3yKebWxJVSnA80RC6bZybAo6nXIAD X-Proofpoint-ORIG-GUID: k_u3yKebWxJVSnA80RC6bZybAo6nXIAD Received-SPF: pass client-ip=205.220.177.32; envelope-from=steven.sistare@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Add a qemu_system_exec_request() hook that causes the main loop to exit and re-exec qemu using the specified arguments. Signed-off-by: Steve Sistare --- include/sysemu/runstate.h | 3 +++ system/runstate.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/include/sysemu/runstate.h b/include/sysemu/runstate.h index 0117d24..cb669cf 100644 --- a/include/sysemu/runstate.h +++ b/include/sysemu/runstate.h @@ -80,6 +80,8 @@ typedef enum WakeupReason { QEMU_WAKEUP_REASON_OTHER, } WakeupReason; +typedef void (*qemu_exec_func)(char **exec_argv); + void qemu_system_reset_request(ShutdownCause reason); void qemu_system_suspend_request(void); void qemu_register_suspend_notifier(Notifier *notifier); @@ -91,6 +93,7 @@ void qemu_register_wakeup_support(void); void qemu_system_shutdown_request_with_code(ShutdownCause reason, int exit_code); void qemu_system_shutdown_request(ShutdownCause reason); +void qemu_system_exec_request(qemu_exec_func func, const strList *args); void qemu_system_powerdown_request(void); void qemu_register_powerdown_notifier(Notifier *notifier); void qemu_register_shutdown_notifier(Notifier *notifier); diff --git a/system/runstate.c b/system/runstate.c index cb4905a..0de0c6e 100644 --- a/system/runstate.c +++ b/system/runstate.c @@ -40,6 +40,7 @@ #include "qapi/error.h" #include "qapi/qapi-commands-run-state.h" #include "qapi/qapi-events-run-state.h" +#include "qapi/type-helpers.h" #include "qemu/accel.h" #include "qemu/error-report.h" #include "qemu/job.h" @@ -401,6 +402,8 @@ static NotifierList wakeup_notifiers = static NotifierList shutdown_notifiers = NOTIFIER_LIST_INITIALIZER(shutdown_notifiers); static uint32_t wakeup_reason_mask = ~(1 << QEMU_WAKEUP_REASON_NONE); +qemu_exec_func exec_func; +static char **exec_argv; ShutdownCause qemu_shutdown_requested_get(void) { @@ -417,6 +420,11 @@ static int qemu_shutdown_requested(void) return qatomic_xchg(&shutdown_requested, SHUTDOWN_CAUSE_NONE); } +static int qemu_exec_requested(void) +{ + return exec_argv != NULL; +} + static void qemu_kill_report(void) { if (!qtest_driver() && shutdown_signal) { @@ -694,6 +702,23 @@ void qemu_system_shutdown_request(ShutdownCause reason) qemu_notify_event(); } +static void qemu_system_exec(void) +{ + exec_func(exec_argv); + + /* exec failed */ + g_strfreev(exec_argv); + exec_argv = NULL; + exec_func = NULL; +} + +void qemu_system_exec_request(qemu_exec_func func, const strList *args) +{ + exec_func = func; + exec_argv = strv_from_str_list(args); + qemu_notify_event(); +} + static void qemu_system_powerdown(void) { qapi_event_send_powerdown(); @@ -740,6 +765,10 @@ static bool main_loop_should_exit(int *status) if (qemu_suspend_requested()) { qemu_system_suspend(); } + if (qemu_exec_requested()) { + qemu_system_exec(); + return false; + } request = qemu_shutdown_requested(); if (request) { qemu_kill_report(); From patchwork Mon Apr 29 15:55:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 13647332 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id DB71DC4345F for ; Mon, 29 Apr 2024 16:01:37 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1TMH-0004Xw-Eb; Mon, 29 Apr 2024 11:56:01 -0400 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 1s1TMB-0004Vr-7s for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:55:56 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s1TM4-0005Ea-75 for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:55:53 -0400 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43TFmsuB024847; Mon, 29 Apr 2024 15:55:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=DxeHxy1bq5kO0rBm8da1QGgj35Yav5ReaUbTJuUkAjA=; b=ObyA7MC7BP6AojsHELxfJbKKq9q9NfcQUo9dTwLiWtj7Z2ezazbFB/kj6MY/wjTe37pU W+l6MDSyxbaCQQnQAEQ7knNrzYZ5kQyNfyOQ+UWz0Wy+Bh7UFmMJ0xUvbiuGr3KrojNr 4mBJOOqbpJ2yE1MQcIxDZ94bv2sfWO5sKCDs88FWQDr/sB0a57aKfc/wJL5OJNhsW5mj UcM11T9J7XCL3xFBHCxpGkPEmhOJjJ6HDye6eEWl/mb03a/+3csApVBx+Wphoo2D6NZq /804KKAQDTWRXZUATACoYcdk3vPBeWnGox/JQlA1bzBdMB2B7D6X7QyhaAVI+JYMHkNz Cw== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrqsetx3a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:40 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43TEuHws011355; Mon, 29 Apr 2024 15:55:39 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt6j634-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:39 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43TFtaGY034442; Mon, 29 Apr 2024 15:55:38 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3xrqt6j5ys-4; Mon, 29 Apr 2024 15:55:38 +0000 From: Steve Sistare To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , David Hildenbrand , Igor Mammedov , Eduardo Habkost , Marcel Apfelbaum , Philippe Mathieu-Daude , Paolo Bonzini , "Daniel P. Berrange" , Markus Armbruster , Steve Sistare Subject: [PATCH V1 03/26] migration: SAVEVM_FOREACH Date: Mon, 29 Apr 2024 08:55:12 -0700 Message-Id: <1714406135-451286-4-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> References: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-29_14,2024-04-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404290101 X-Proofpoint-ORIG-GUID: siASKqHzQ5DYvLwFrORQhU0nLO1ACnbl X-Proofpoint-GUID: siASKqHzQ5DYvLwFrORQhU0nLO1ACnbl Received-SPF: pass client-ip=205.220.177.32; envelope-from=steven.sistare@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Define an abstraction SAVEVM_FOREACH to loop over all savevm state handlers, and replace QTAILQ_FOREACH. Define variants for ALL so we can loop over all handlers vs a subset of handlers in a subsequent patch, but at this time there is no distinction between the two. No functional change. Signed-off-by: Steve Sistare --- migration/savevm.c | 55 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/migration/savevm.c b/migration/savevm.c index 4509482..6829ba3 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -237,6 +237,15 @@ static SaveState savevm_state = { .global_section_id = 0, }; +#define SAVEVM_FOREACH(se, entry) \ + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) \ + +#define SAVEVM_FOREACH_ALL(se, entry) \ + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) + +#define SAVEVM_FOREACH_SAFE_ALL(se, entry, new_se) \ + QTAILQ_FOREACH_SAFE(se, &savevm_state.handlers, entry, new_se) + static SaveStateEntry *find_se(const char *idstr, uint32_t instance_id); static bool should_validate_capability(int capability) @@ -674,7 +683,7 @@ static uint32_t calculate_new_instance_id(const char *idstr) SaveStateEntry *se; uint32_t instance_id = 0; - QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + SAVEVM_FOREACH_ALL(se, entry) { if (strcmp(idstr, se->idstr) == 0 && instance_id <= se->instance_id) { instance_id = se->instance_id + 1; @@ -690,7 +699,7 @@ static int calculate_compat_instance_id(const char *idstr) SaveStateEntry *se; int instance_id = 0; - QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + SAVEVM_FOREACH(se, entry) { if (!se->compat) { continue; } @@ -816,7 +825,7 @@ void unregister_savevm(VMStateIf *obj, const char *idstr, void *opaque) } pstrcat(id, sizeof(id), idstr); - QTAILQ_FOREACH_SAFE(se, &savevm_state.handlers, entry, new_se) { + SAVEVM_FOREACH_SAFE_ALL(se, entry, new_se) { if (strcmp(se->idstr, id) == 0 && se->opaque == opaque) { savevm_state_handler_remove(se); g_free(se->compat); @@ -939,7 +948,7 @@ void vmstate_unregister(VMStateIf *obj, const VMStateDescription *vmsd, { SaveStateEntry *se, *new_se; - QTAILQ_FOREACH_SAFE(se, &savevm_state.handlers, entry, new_se) { + SAVEVM_FOREACH_SAFE_ALL(se, entry, new_se) { if (se->vmsd == vmsd && se->opaque == opaque) { savevm_state_handler_remove(se); g_free(se->compat); @@ -1223,7 +1232,7 @@ bool qemu_savevm_state_blocked(Error **errp) { SaveStateEntry *se; - QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + SAVEVM_FOREACH(se, entry) { if (se->vmsd && se->vmsd->unmigratable) { error_setg(errp, "State blocked by non-migratable device '%s'", se->idstr); @@ -1237,7 +1246,7 @@ void qemu_savevm_non_migratable_list(strList **reasons) { SaveStateEntry *se; - QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + SAVEVM_FOREACH(se, entry) { if (se->vmsd && se->vmsd->unmigratable) { QAPI_LIST_PREPEND(*reasons, g_strdup_printf("non-migratable device: %s", @@ -1276,7 +1285,7 @@ bool qemu_savevm_state_guest_unplug_pending(void) { SaveStateEntry *se; - QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + SAVEVM_FOREACH(se, entry) { if (se->vmsd && se->vmsd->dev_unplug_pending && se->vmsd->dev_unplug_pending(se->opaque)) { return true; @@ -1291,7 +1300,7 @@ int qemu_savevm_state_prepare(Error **errp) SaveStateEntry *se; int ret; - QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + SAVEVM_FOREACH(se, entry) { if (!se->ops || !se->ops->save_prepare) { continue; } @@ -1321,7 +1330,7 @@ int qemu_savevm_state_setup(QEMUFile *f, Error **errp) json_writer_start_array(ms->vmdesc, "devices"); trace_savevm_state_setup(); - QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + SAVEVM_FOREACH(se, entry) { if (se->vmsd && se->vmsd->early_setup) { ret = vmstate_save(f, se, ms->vmdesc, errp); if (ret) { @@ -1365,7 +1374,7 @@ int qemu_savevm_state_resume_prepare(MigrationState *s) trace_savevm_state_resume_prepare(); - QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + SAVEVM_FOREACH(se, entry) { if (!se->ops || !se->ops->resume_prepare) { continue; } @@ -1396,7 +1405,7 @@ int qemu_savevm_state_iterate(QEMUFile *f, bool postcopy) int ret; trace_savevm_state_iterate(); - QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + SAVEVM_FOREACH(se, entry) { if (!se->ops || !se->ops->save_live_iterate) { continue; } @@ -1461,7 +1470,7 @@ void qemu_savevm_state_complete_postcopy(QEMUFile *f) SaveStateEntry *se; int ret; - QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + SAVEVM_FOREACH(se, entry) { if (!se->ops || !se->ops->save_live_complete_postcopy) { continue; } @@ -1495,7 +1504,7 @@ int qemu_savevm_state_complete_precopy_iterable(QEMUFile *f, bool in_postcopy) SaveStateEntry *se; int ret; - QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + SAVEVM_FOREACH(se, entry) { if (!se->ops || (in_postcopy && se->ops->has_postcopy && se->ops->has_postcopy(se->opaque)) || @@ -1543,7 +1552,7 @@ int qemu_savevm_state_complete_precopy_non_iterable(QEMUFile *f, Error *local_err = NULL; int ret; - QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + SAVEVM_FOREACH(se, entry) { if (se->vmsd && se->vmsd->early_setup) { /* Already saved during qemu_savevm_state_setup(). */ continue; @@ -1649,7 +1658,7 @@ void qemu_savevm_state_pending_estimate(uint64_t *must_precopy, *must_precopy = 0; *can_postcopy = 0; - QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + SAVEVM_FOREACH(se, entry) { if (!se->ops || !se->ops->state_pending_estimate) { continue; } @@ -1670,7 +1679,7 @@ void qemu_savevm_state_pending_exact(uint64_t *must_precopy, *must_precopy = 0; *can_postcopy = 0; - QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + SAVEVM_FOREACH(se, entry) { if (!se->ops || !se->ops->state_pending_exact) { continue; } @@ -1693,7 +1702,7 @@ void qemu_savevm_state_cleanup(void) } trace_savevm_state_cleanup(); - QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + SAVEVM_FOREACH(se, entry) { if (se->ops && se->ops->save_cleanup) { se->ops->save_cleanup(se->opaque); } @@ -1778,7 +1787,7 @@ int qemu_save_device_state(QEMUFile *f) } cpu_synchronize_all_states(); - QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + SAVEVM_FOREACH(se, entry) { int ret; if (se->is_ram) { @@ -1801,7 +1810,7 @@ static SaveStateEntry *find_se(const char *idstr, uint32_t instance_id) { SaveStateEntry *se; - QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + SAVEVM_FOREACH_ALL(se, entry) { if (!strcmp(se->idstr, idstr) && (instance_id == se->instance_id || instance_id == se->alias_id)) @@ -2680,7 +2689,7 @@ qemu_loadvm_section_part_end(QEMUFile *f, MigrationIncomingState *mis, } trace_qemu_loadvm_state_section_partend(section_id); - QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + SAVEVM_FOREACH(se, entry) { if (se->load_section_id == section_id) { break; } @@ -2755,7 +2764,7 @@ static void qemu_loadvm_state_switchover_ack_needed(MigrationIncomingState *mis) { SaveStateEntry *se; - QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + SAVEVM_FOREACH(se, entry) { if (!se->ops || !se->ops->switchover_ack_needed) { continue; } @@ -2775,7 +2784,7 @@ static int qemu_loadvm_state_setup(QEMUFile *f, Error **errp) int ret; trace_loadvm_state_setup(); - QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + SAVEVM_FOREACH(se, entry) { if (!se->ops || !se->ops->load_setup) { continue; } @@ -2801,7 +2810,7 @@ void qemu_loadvm_state_cleanup(void) SaveStateEntry *se; trace_loadvm_state_cleanup(); - QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + SAVEVM_FOREACH(se, entry) { if (se->ops && se->ops->load_cleanup) { se->ops->load_cleanup(se->opaque); } From patchwork Mon Apr 29 15:55:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 13647331 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id B6AA7C4345F for ; Mon, 29 Apr 2024 16:01:29 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1TMG-0004XF-H9; Mon, 29 Apr 2024 11:56:00 -0400 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 1s1TMB-0004Vo-3F for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:55:55 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s1TM4-0005Eg-79 for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:55:51 -0400 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43TFmsRI024843; Mon, 29 Apr 2024 15:55:41 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=KtpyFr+SdtUHtFMbtC13x2YcjcWEc2j37inbhMEUMPY=; b=QCpg//PfQjbmslzOi4fksKAlMFBrDiLfnyU+yPkbrOSmbC9JI7GhzzcemdcI+vY+qiM2 onpnPXEhzwx6qdtmBM5isyuwKyhJ4MkSJsooKzuCYt6W1rxTFvbK9kA2EPZelkt28iDB azbILbN47Pnj569Grz+xUPDfe4YheT9W7orX06ZmTowL/n16KI71NYR/h0X3Sq19uF7C GlwmNk/BfdBLHD/2YLB17kKpYQ+s+xbe7croKFPl2SeyAFBpY1JepCRqMKT5qXUFNy2l 1MXIKhvwwDelo2G746JyMbx4ufINv61BV6E5vi1A46lQEEzIrlhO5oxvi0xsDku86HjL TA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrqsetx3b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:40 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43TEgWMc011336; Mon, 29 Apr 2024 15:55:39 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt6j63r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:39 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43TFtaGa034442; Mon, 29 Apr 2024 15:55:39 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3xrqt6j5ys-5; Mon, 29 Apr 2024 15:55:39 +0000 From: Steve Sistare To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , David Hildenbrand , Igor Mammedov , Eduardo Habkost , Marcel Apfelbaum , Philippe Mathieu-Daude , Paolo Bonzini , "Daniel P. Berrange" , Markus Armbruster , Steve Sistare Subject: [PATCH V1 04/26] migration: delete unused parameter mis Date: Mon, 29 Apr 2024 08:55:13 -0700 Message-Id: <1714406135-451286-5-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> References: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-29_14,2024-04-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404290101 X-Proofpoint-ORIG-GUID: p0BjRbropzKbemkh0Zryts-gVxjw-hYa X-Proofpoint-GUID: p0BjRbropzKbemkh0Zryts-gVxjw-hYa Received-SPF: pass client-ip=205.220.177.32; envelope-from=steven.sistare@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Steve Sistare Reviewed-by: Fabiano Rosas Reviewed-by: Peter Xu --- migration/savevm.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/migration/savevm.c b/migration/savevm.c index 6829ba3..9789823 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2591,8 +2591,7 @@ static bool check_section_footer(QEMUFile *f, SaveStateEntry *se) } static int -qemu_loadvm_section_start_full(QEMUFile *f, MigrationIncomingState *mis, - uint8_t type) +qemu_loadvm_section_start_full(QEMUFile *f, uint8_t type) { bool trace_downtime = (type == QEMU_VM_SECTION_FULL); uint32_t instance_id, version_id, section_id; @@ -2670,8 +2669,7 @@ qemu_loadvm_section_start_full(QEMUFile *f, MigrationIncomingState *mis, } static int -qemu_loadvm_section_part_end(QEMUFile *f, MigrationIncomingState *mis, - uint8_t type) +qemu_loadvm_section_part_end(QEMUFile *f, uint8_t type) { bool trace_downtime = (type == QEMU_VM_SECTION_END); int64_t start_ts, end_ts; @@ -2906,14 +2904,14 @@ retry: switch (section_type) { case QEMU_VM_SECTION_START: case QEMU_VM_SECTION_FULL: - ret = qemu_loadvm_section_start_full(f, mis, section_type); + ret = qemu_loadvm_section_start_full(f, section_type); if (ret < 0) { goto out; } break; case QEMU_VM_SECTION_PART: case QEMU_VM_SECTION_END: - ret = qemu_loadvm_section_part_end(f, mis, section_type); + ret = qemu_loadvm_section_part_end(f, section_type); if (ret < 0) { goto out; } From patchwork Mon Apr 29 15:55:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 13647316 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id B8DBDC19F53 for ; Mon, 29 Apr 2024 15:56:45 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1TMJ-0004Zy-Qd; Mon, 29 Apr 2024 11:56:04 -0400 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 1s1TMB-0004Vx-MS for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:55:56 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s1TM4-0005F1-LW for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:55:55 -0400 Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43TFmjb4006712; Mon, 29 Apr 2024 15:55:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=yo0i2IaEWoAUYk4MxRQWxqRVVF0sXL4SczE0OahgkO0=; b=PE63jmzQDU+UPeEli2ouHIbpcnZHEi7eNt0oCzknb9JGodR6oxkyq4I/JrVdnzhlOKR9 OZzHGFakyJ6iFcmdcO5dkJOAM7E8kc+iToR2ZMP2L4cZnZbEQUYugXxGDA1RDqGjxq8i GA+EraQ3UuP2DuyZBLGAEV+R7R0GL6IwGD5zI43NAoFv1BYDxo06wi2n3ebSr71Lr+bX 0QOR3+XpikRCMCxARntfu7tMxmiEZYtfqrsoslH9Go/6W492OQlYl9cv5JqMCXkLOuWj d+JRtNT75M0EntxfYQTzB7VJppRBXpw1Wz7Hhaui31Qu1dw0VaWp1zJOeuUUgtKRmZXv DA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrsdejwmp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:41 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43TEgWMd011336; Mon, 29 Apr 2024 15:55:40 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt6j64f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:40 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43TFtaGc034442; Mon, 29 Apr 2024 15:55:39 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3xrqt6j5ys-6; Mon, 29 Apr 2024 15:55:39 +0000 From: Steve Sistare To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , David Hildenbrand , Igor Mammedov , Eduardo Habkost , Marcel Apfelbaum , Philippe Mathieu-Daude , Paolo Bonzini , "Daniel P. Berrange" , Markus Armbruster , Steve Sistare Subject: [PATCH V1 05/26] migration: precreate vmstate Date: Mon, 29 Apr 2024 08:55:14 -0700 Message-Id: <1714406135-451286-6-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> References: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-29_14,2024-04-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404290101 X-Proofpoint-GUID: gMELQzHGA4M0LMoXiVrIZatgWVcZtksl X-Proofpoint-ORIG-GUID: gMELQzHGA4M0LMoXiVrIZatgWVcZtksl Received-SPF: pass client-ip=205.220.177.32; envelope-from=steven.sistare@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Provide the VMStateDescription precreate field to mark objects that must be loaded on the incoming side before devices have been created, because they provide properties that will be needed at creation time. They will be saved to and loaded from their own QEMUFile, via qemu_savevm_precreate_save and qemu_savevm_precreate_load, but these functions are not yet called in this patch. Allow them to be called before or after normal migration is active, when current_migration and current_incoming are not valid. Signed-off-by: Steve Sistare Reviewed-by: Fabiano Rosas --- include/migration/vmstate.h | 6 ++++ migration/savevm.c | 69 +++++++++++++++++++++++++++++++++++++++++---- migration/savevm.h | 3 ++ 3 files changed, 73 insertions(+), 5 deletions(-) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 294d2d8..4691334 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -198,6 +198,12 @@ struct VMStateDescription { * a QEMU_VM_SECTION_START section. */ bool early_setup; + + /* + * Send/receive this object in the precreate migration stream. + */ + bool precreate; + int version_id; int minimum_version_id; MigrationPriority priority; diff --git a/migration/savevm.c b/migration/savevm.c index 9789823..a30bcd9 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -239,6 +239,7 @@ static SaveState savevm_state = { #define SAVEVM_FOREACH(se, entry) \ QTAILQ_FOREACH(se, &savevm_state.handlers, entry) \ + if (!se->vmsd || !se->vmsd->precreate) #define SAVEVM_FOREACH_ALL(se, entry) \ QTAILQ_FOREACH(se, &savevm_state.handlers, entry) @@ -1006,13 +1007,19 @@ static void save_section_header(QEMUFile *f, SaveStateEntry *se, } } +static bool send_section_footer(SaveStateEntry *se) +{ + return (se->vmsd && se->vmsd->precreate) || + migrate_get_current()->send_section_footer; +} + /* * Write a footer onto device sections that catches cases misformatted device * sections. */ static void save_section_footer(QEMUFile *f, SaveStateEntry *se) { - if (migrate_get_current()->send_section_footer) { + if (send_section_footer(se)) { qemu_put_byte(f, QEMU_VM_SECTION_FOOTER); qemu_put_be32(f, se->section_id); } @@ -1319,6 +1326,52 @@ int qemu_savevm_state_prepare(Error **errp) return 0; } +int qemu_savevm_precreate_save(QEMUFile *f, Error **errp) +{ + int ret; + SaveStateEntry *se; + + qemu_put_be32(f, QEMU_VM_FILE_MAGIC); + qemu_put_be32(f, QEMU_VM_FILE_VERSION); + + SAVEVM_FOREACH_ALL(se, entry) { + if (se->vmsd && se->vmsd->precreate) { + ret = vmstate_save(f, se, NULL, errp); + if (ret) { + qemu_file_set_error(f, ret); + return ret; + } + } + } + qemu_fflush(f); + return 0; +} + +int qemu_savevm_precreate_load(QEMUFile *f, Error **errp) +{ + unsigned int v; + int ret; + + v = qemu_get_be32(f); + if (v != QEMU_VM_FILE_MAGIC) { + error_setg(errp, "Not a migration stream"); + return -EINVAL; + } + + v = qemu_get_be32(f); + if (v != QEMU_VM_FILE_VERSION) { + error_setg(errp, "Unsupported migration stream version"); + return -ENOTSUP; + } + + ret = qemu_loadvm_state_main(f, NULL); + if (ret) { + error_setg_errno(errp, -ret, "qemu_savevm_precreate_load"); + } + + return ret; +} + int qemu_savevm_state_setup(QEMUFile *f, Error **errp) { ERRP_GUARD(); @@ -2559,7 +2612,7 @@ static bool check_section_footer(QEMUFile *f, SaveStateEntry *se) uint8_t read_mark; uint32_t read_section_id; - if (!migrate_get_current()->send_section_footer) { + if (!send_section_footer(se)) { /* No footer to check */ return true; } @@ -2895,9 +2948,12 @@ retry: while (true) { section_type = qemu_get_byte(f); - ret = qemu_file_get_error_obj_any(f, mis->postcopy_qemufile_dst, NULL); - if (ret) { - break; + if (mis) { + ret = qemu_file_get_error_obj_any(f, mis->postcopy_qemufile_dst, + NULL); + if (ret) { + break; + } } trace_qemu_loadvm_state_section(section_type); @@ -2936,6 +2992,9 @@ retry: out: if (ret < 0) { qemu_file_set_error(f, ret); + if (!mis) { + return ret; + } /* Cancel bitmaps incoming regardless of recovery */ dirty_bitmap_mig_cancel_incoming(); diff --git a/migration/savevm.h b/migration/savevm.h index 9ec96a9..6f207b5 100644 --- a/migration/savevm.h +++ b/migration/savevm.h @@ -70,4 +70,7 @@ int qemu_loadvm_approve_switchover(void); int qemu_savevm_state_complete_precopy_non_iterable(QEMUFile *f, bool in_postcopy, bool inactivate_disks); +int qemu_savevm_precreate_save(QEMUFile *f, Error **errp); +int qemu_savevm_precreate_load(QEMUFile *f, Error **errp); + #endif From patchwork Mon Apr 29 15:55:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 13647320 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 75C2EC4345F for ; Mon, 29 Apr 2024 15:57:31 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1TMF-0004X4-JA; Mon, 29 Apr 2024 11:55:59 -0400 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 1s1TMB-0004Vq-4q for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:55:55 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s1TM4-0005Et-79 for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:55:52 -0400 Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43TFmjvP006702; Mon, 29 Apr 2024 15:55:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=AsixATSRLpV+Yop01dX+ts3i0CYeTOgvTvdYJbJ4OQY=; b=lFrt4iZog+GLRgFaBt6eZ6O0H41PuUQZnVNR7uONQCyoY4aETxwNFrT81CuljVEBbMTe eu219Xy3pPOrGZeqlZa46aV8VUHfcXHkJ0RCMYlbB/XO4+JdiwfLq3rNF+wOIGNxrdkj IV8i4/5P4KsLPE5y80umIgsSNm/CSTILyRKuJn3QPxMmVhAcTkcYyX564BqNnr7F/FwY LN3vwGDvVbtpkBVJkh6zMzH6LX890vO644EAdsgCoJMBNEQKUOYXMnRpRarlEgPZJUpP OLKLht07B4DCMxH+tgRFNlVSDcYwgckS/QxnM+lOlr2MvcSFcXrO89/BWY2HSaXAV2AR 2Q== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrsdejwmr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:42 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43TEheo5011366; Mon, 29 Apr 2024 15:55:41 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt6j64y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:41 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43TFtaGe034442; Mon, 29 Apr 2024 15:55:40 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3xrqt6j5ys-7; Mon, 29 Apr 2024 15:55:40 +0000 From: Steve Sistare To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , David Hildenbrand , Igor Mammedov , Eduardo Habkost , Marcel Apfelbaum , Philippe Mathieu-Daude , Paolo Bonzini , "Daniel P. Berrange" , Markus Armbruster , Steve Sistare Subject: [PATCH V1 06/26] migration: precreate vmstate for exec Date: Mon, 29 Apr 2024 08:55:15 -0700 Message-Id: <1714406135-451286-7-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> References: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-29_14,2024-04-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404290101 X-Proofpoint-GUID: ZbprD0pcIER2DImXWwmIew0YnfdbXrb_ X-Proofpoint-ORIG-GUID: ZbprD0pcIER2DImXWwmIew0YnfdbXrb_ Received-SPF: pass client-ip=205.220.177.32; envelope-from=steven.sistare@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Provide migration_precreate_save for saving precreate vmstate across exec. Create a memfd, save its value in the environment, and serialize state to it. Reverse the process in migration_precreate_load. Signed-off-by: Steve Sistare Reviewed-by: Fabiano Rosas --- include/migration/misc.h | 5 ++ migration/meson.build | 1 + migration/precreate.c | 139 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 145 insertions(+) create mode 100644 migration/precreate.c diff --git a/include/migration/misc.h b/include/migration/misc.h index c9e200f..cf30351 100644 --- a/include/migration/misc.h +++ b/include/migration/misc.h @@ -56,6 +56,11 @@ AnnounceParameters *migrate_announce_params(void); void dump_vmstate_json_to_file(FILE *out_fp); +/* migration/precreate.c */ +int migration_precreate_save(Error **errp); +void migration_precreate_unsave(void); +int migration_precreate_load(Error **errp); + /* migration/migration.c */ void migration_object_init(void); void migration_shutdown(void); diff --git a/migration/meson.build b/migration/meson.build index f76b1ba..50e7cb2 100644 --- a/migration/meson.build +++ b/migration/meson.build @@ -26,6 +26,7 @@ system_ss.add(files( 'ram-compress.c', 'options.c', 'postcopy-ram.c', + 'precreate.c', 'savevm.c', 'socket.c', 'tls.c', diff --git a/migration/precreate.c b/migration/precreate.c new file mode 100644 index 0000000..0bf5e1f --- /dev/null +++ b/migration/precreate.c @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2022, 2024 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qemu/cutils.h" +#include "qemu/memfd.h" +#include "qapi/error.h" +#include "io/channel-file.h" +#include "migration/misc.h" +#include "migration/qemu-file.h" +#include "migration/savevm.h" + +#define PRECREATE_STATE_NAME "QEMU_PRECREATE_STATE" + +static QEMUFile *qemu_file_new_fd_input(int fd, const char *name) +{ + g_autoptr(QIOChannelFile) fioc = qio_channel_file_new_fd(fd); + QIOChannel *ioc = QIO_CHANNEL(fioc); + qio_channel_set_name(ioc, name); + return qemu_file_new_input(ioc); +} + +static QEMUFile *qemu_file_new_fd_output(int fd, const char *name) +{ + g_autoptr(QIOChannelFile) fioc = qio_channel_file_new_fd(fd); + QIOChannel *ioc = QIO_CHANNEL(fioc); + qio_channel_set_name(ioc, name); + return qemu_file_new_output(ioc); +} + +static int memfd_create_named(const char *name, Error **errp) +{ + int mfd; + char val[16]; + + mfd = memfd_create(name, 0); + if (mfd < 0) { + error_setg_errno(errp, errno, "memfd_create failed"); + return -1; + } + + /* Remember mfd in environment for post-exec load */ + qemu_clear_cloexec(mfd); + snprintf(val, sizeof(val), "%d", mfd); + g_setenv(name, val, 1); + + return mfd; +} + +static int memfd_find_named(const char *name, int *mfd_p, Error **errp) +{ + const char *val = g_getenv(name); + + if (!val) { + *mfd_p = -1; + return 0; /* No memfd was created, not an error */ + } + g_unsetenv(name); + if (qemu_strtoi(val, NULL, 10, mfd_p)) { + error_setg(errp, "Bad %s env value %s", PRECREATE_STATE_NAME, val); + return -1; + } + lseek(*mfd_p, 0, SEEK_SET); + return 0; +} + +static void memfd_delete_named(const char *name) +{ + int mfd; + const char *val = g_getenv(name); + + if (val) { + g_unsetenv(name); + if (!qemu_strtoi(val, NULL, 10, &mfd)) { + close(mfd); + } + } +} + +static QEMUFile *qemu_file_new_memfd_output(const char *name, Error **errp) +{ + int mfd = memfd_create_named(name, errp); + + if (mfd < 0) { + return NULL; + } + + return qemu_file_new_fd_output(mfd, name); +} + +static QEMUFile *qemu_file_new_memfd_input(const char *name, Error **errp) +{ + int ret, mfd; + + ret = memfd_find_named(name, &mfd, errp); + if (ret || mfd < 0) { + return NULL; + } + + return qemu_file_new_fd_input(mfd, name); +} + +int migration_precreate_save(Error **errp) +{ + QEMUFile *f = qemu_file_new_memfd_output(PRECREATE_STATE_NAME, errp); + + if (!f) { + return -1; + } else if (qemu_savevm_precreate_save(f, errp)) { + memfd_delete_named(PRECREATE_STATE_NAME); + return -1; + } else { + /* Do not close f, as mfd must remain open. */ + return 0; + } +} + +void migration_precreate_unsave(void) +{ + memfd_delete_named(PRECREATE_STATE_NAME); +} + +int migration_precreate_load(Error **errp) +{ + int ret; + QEMUFile *f = qemu_file_new_memfd_input(PRECREATE_STATE_NAME, errp); + + if (!f) { + return -1; + } + ret = qemu_savevm_precreate_load(f, errp); + qemu_fclose(f); + g_unsetenv(PRECREATE_STATE_NAME); + return ret; +} From patchwork Mon Apr 29 15:55:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 13647318 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id C7EADC4345F for ; Mon, 29 Apr 2024 15:57:09 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1TMU-0004ib-KU; Mon, 29 Apr 2024 11:56:14 -0400 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 1s1TMJ-0004Zp-Dd for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:56:03 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s1TMF-0005Ex-VM for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:56:03 -0400 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43TFmn2D023135; Mon, 29 Apr 2024 15:55:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=HZrv1nFWtE6Nl7XyPOcCaiN32/YoQ6R+20VVNPwSEUk=; b=bEDLS/LKXmi+P8SBtrIEujkndt551tLiCoCsXxydsfYwtLWU7VTv8wDNvdBOM60lUFJ9 8jwYArAlqMB26iURylTQ7C30+XLkuq09hjWc5BM+AsfE7S6QWr5vL1/e/h9rHEBr3Kid 8L9aJHHf8HhmWaVCbF4ksKMsurVji5oiiWzv780SqMfTQOpWeC5M+ARDtC91o59EPICG UA32KpeT2aidKhOFR3e2eYAIJrwZr6KIo7bgSrzdUVLo+sdWz8LU85w3ccYA70+16KQv lrF7CBHe8I+iXnxtgLiuozrvrm9GeoAQtkgurgccb7nBmepFqy5nbGH51srPRsKLm+go 3A== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrryv2wbj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:42 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43TFVc5C011501; Mon, 29 Apr 2024 15:55:42 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt6j65t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:41 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43TFtaGg034442; Mon, 29 Apr 2024 15:55:41 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3xrqt6j5ys-8; Mon, 29 Apr 2024 15:55:41 +0000 From: Steve Sistare To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , David Hildenbrand , Igor Mammedov , Eduardo Habkost , Marcel Apfelbaum , Philippe Mathieu-Daude , Paolo Bonzini , "Daniel P. Berrange" , Markus Armbruster , Steve Sistare Subject: [PATCH V1 07/26] migration: VMStateId Date: Mon, 29 Apr 2024 08:55:16 -0700 Message-Id: <1714406135-451286-8-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> References: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-29_14,2024-04-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404290101 X-Proofpoint-GUID: pEkksVTdrNfiyxDXjEK5ht38loEMuz1S X-Proofpoint-ORIG-GUID: pEkksVTdrNfiyxDXjEK5ht38loEMuz1S Received-SPF: pass client-ip=205.220.177.32; envelope-from=steven.sistare@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Define a type for the 256 byte id string to guarantee the same length is used and enforced everywhere. Signed-off-by: Steve Sistare Reviewed-by: Fabiano Rosas --- include/exec/ramblock.h | 3 ++- include/migration/vmstate.h | 2 ++ migration/savevm.c | 8 ++++---- migration/vmstate.c | 3 ++- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/include/exec/ramblock.h b/include/exec/ramblock.h index 0babd10..61deefe 100644 --- a/include/exec/ramblock.h +++ b/include/exec/ramblock.h @@ -23,6 +23,7 @@ #include "cpu-common.h" #include "qemu/rcu.h" #include "exec/ramlist.h" +#include "migration/vmstate.h" struct RAMBlock { struct rcu_head rcu; @@ -35,7 +36,7 @@ struct RAMBlock { void (*resized)(const char*, uint64_t length, void *host); uint32_t flags; /* Protected by the BQL. */ - char idstr[256]; + VMStateId idstr; /* RCU-enabled, writes protected by the ramlist lock */ QLIST_ENTRY(RAMBlock) next; QLIST_HEAD(, RAMBlockNotifier) ramblock_notifiers; diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 4691334..a39c0e6 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -1210,6 +1210,8 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd, bool vmstate_section_needed(const VMStateDescription *vmsd, void *opaque); +typedef char (VMStateId)[256]; + #define VMSTATE_INSTANCE_ID_ANY -1 /* Returns: 0 on success, -1 on failure */ diff --git a/migration/savevm.c b/migration/savevm.c index a30bcd9..9b1a335 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -197,13 +197,13 @@ const VMStateInfo vmstate_info_timer = { typedef struct CompatEntry { - char idstr[256]; + VMStateId idstr; int instance_id; } CompatEntry; typedef struct SaveStateEntry { QTAILQ_ENTRY(SaveStateEntry) entry; - char idstr[256]; + VMStateId idstr; uint32_t instance_id; int alias_id; int version_id; @@ -814,7 +814,7 @@ int register_savevm_live(const char *idstr, void unregister_savevm(VMStateIf *obj, const char *idstr, void *opaque) { SaveStateEntry *se, *new_se; - char id[256] = ""; + VMStateId id = ""; if (obj) { char *oid = vmstate_if_get_id(obj); @@ -2650,7 +2650,7 @@ qemu_loadvm_section_start_full(QEMUFile *f, uint8_t type) uint32_t instance_id, version_id, section_id; int64_t start_ts, end_ts; SaveStateEntry *se; - char idstr[256]; + VMStateId idstr; int ret; /* Read section start */ diff --git a/migration/vmstate.c b/migration/vmstate.c index ef26f26..437f156 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -471,7 +471,8 @@ static int vmstate_subsection_load(QEMUFile *f, const VMStateDescription *vmsd, trace_vmstate_subsection_load(vmsd->name); while (qemu_peek_byte(f, 0) == QEMU_VM_SUBSECTION) { - char idstr[256], *idstr_ret; + VMStateId idstr; + char *idstr_ret; int ret; uint8_t version_id, len, size; const VMStateDescription *sub_vmsd; From patchwork Mon Apr 29 15:55:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 13647337 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 8E544C41513 for ; Mon, 29 Apr 2024 16:06:11 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1TMV-0004oN-4s; Mon, 29 Apr 2024 11:56:15 -0400 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 1s1TMH-0004Y1-Vi for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:56:01 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s1TMF-0005FB-Ux for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:56:01 -0400 Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43TFmlZq021746; Mon, 29 Apr 2024 15:55:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=mfUEBur7xmKrlLkLi6qOQJ8fPpHhzHrrtYVn+a6Puyk=; b=i1ifYD+4Amn7wTHZUK7DSc8ql/ht70BhjC1LRoGFGM9qjco5vJOIkXW6ClJZ3SoFDpYK hPQUUqr1dwA/1WS1J+7ur6OF9/hY+uFVPSGEWnU2aS1jh5BAzvpl27saWew6+23UjuXF pawTTRZQudhu2L0Ftr1B5ucK0xzjEAV3LSv2Dm1AsNk+EHXqwqmDTbNJ3PtUKoEegmbE bjob9sODzDM82woWxubH+DKB+Qya5FPtA8VxBT+QnanCHRCJOlH4rZItdpJ5ImyCvvm6 +TFRJTX9ukQGpA1h/VJi49idWxqOqoImL3LiQAAmu7s4+2GoJU8IAZuWKLuIP0egFKMs IA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrr54axsu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:43 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43TFGqtP011343; Mon, 29 Apr 2024 15:55:42 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt6j66j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:42 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43TFtaGi034442; Mon, 29 Apr 2024 15:55:42 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3xrqt6j5ys-9; Mon, 29 Apr 2024 15:55:41 +0000 From: Steve Sistare To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , David Hildenbrand , Igor Mammedov , Eduardo Habkost , Marcel Apfelbaum , Philippe Mathieu-Daude , Paolo Bonzini , "Daniel P. Berrange" , Markus Armbruster , Steve Sistare Subject: [PATCH V1 08/26] migration: vmstate_info_void_ptr Date: Mon, 29 Apr 2024 08:55:17 -0700 Message-Id: <1714406135-451286-9-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> References: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-29_14,2024-04-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404290101 X-Proofpoint-ORIG-GUID: DVn4SmJXNGnbMp5mluxbY-_8LL3x95ta X-Proofpoint-GUID: DVn4SmJXNGnbMp5mluxbY-_8LL3x95ta Received-SPF: pass client-ip=205.220.177.32; envelope-from=steven.sistare@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Define VMSTATE_VOID_PTR so the value of a pointer (but not its target) can be saved in the migration stream. This will be needed for CPR. Signed-off-by: Steve Sistare Reviewed-by: Fabiano Rosas --- include/migration/vmstate.h | 15 +++++++++++++++ migration/vmstate-types.c | 24 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index a39c0e6..bb885d9 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -236,6 +236,7 @@ extern const VMStateInfo vmstate_info_uint8; extern const VMStateInfo vmstate_info_uint16; extern const VMStateInfo vmstate_info_uint32; extern const VMStateInfo vmstate_info_uint64; +extern const VMStateInfo vmstate_info_void_ptr; /** Put this in the stream when migrating a null pointer.*/ #define VMS_NULLPTR_MARKER (0x30U) /* '0' */ @@ -326,6 +327,17 @@ extern const VMStateInfo vmstate_info_qlist; .offset = vmstate_offset_value(_state, _field, _type), \ } +#define VMSTATE_SINGLE_TEST_NO_CHECK(_field, _state, _test, \ + _version, _info, _type) { \ + .name = (stringify(_field)), \ + .version_id = (_version), \ + .field_exists = (_test), \ + .size = sizeof(_type), \ + .info = &(_info), \ + .flags = VMS_SINGLE, \ + .offset = offsetof(_state, _field) \ +} + #define VMSTATE_SINGLE_FULL(_field, _state, _test, _version, _info, \ _type, _err_hint) { \ .name = (stringify(_field)), \ @@ -952,6 +964,9 @@ extern const VMStateInfo vmstate_info_qlist; #define VMSTATE_UINT64(_f, _s) \ VMSTATE_UINT64_V(_f, _s, 0) +#define VMSTATE_VOID_PTR(_f, _s) \ + VMSTATE_SINGLE_TEST_NO_CHECK(_f, _s, NULL, 0, vmstate_info_void_ptr, void *) + #ifdef CONFIG_LINUX #define VMSTATE_U8(_f, _s) \ diff --git a/migration/vmstate-types.c b/migration/vmstate-types.c index e83bfcc..097ecad 100644 --- a/migration/vmstate-types.c +++ b/migration/vmstate-types.c @@ -314,6 +314,30 @@ const VMStateInfo vmstate_info_uint64 = { .put = put_uint64, }; +/* 64 bit pointer */ + +static int get_void_ptr(QEMUFile *f, void *pv, size_t size, + const VMStateField *field) +{ + void **v = pv; + qemu_get_be64s(f, (uint64_t *)v); + return 0; +} + +static int put_void_ptr(QEMUFile *f, void *pv, size_t size, + const VMStateField *field, JSONWriter *vmdesc) +{ + void **v = pv; + qemu_put_be64s(f, (uint64_t *)v); + return 0; +} + +const VMStateInfo vmstate_info_void_ptr = { + .name = "void_ptr", + .get = get_void_ptr, + .put = put_void_ptr, +}; + static int get_nullptr(QEMUFile *f, void *pv, size_t size, const VMStateField *field) From patchwork Mon Apr 29 15:55:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 13647314 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id D092EC4345F for ; Mon, 29 Apr 2024 15:56:44 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1TMN-0004cI-QA; Mon, 29 Apr 2024 11:56:07 -0400 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 1s1TMI-0004Ya-9Z for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:56:02 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s1TMF-0005FH-V6 for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:56:02 -0400 Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43TFmjb6006712; Mon, 29 Apr 2024 15:55:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=tY/XgqmbfugZCppNeWrHSHTrYbFcI73pMuTKk9NtCoo=; b=og8uEnDik4o9IunnbXEIkAo0ddegTvIJDL1SPrX/fudCdjknuQgfNpTf0UY4xZTkU/o0 fU4X0ips4EGve5OnlC+GKZVSqss5K8eULOj5wd75fVMkQmeTnmXikcVbQg09at9QEiYz p7p0NWiumeaUo0Fyb4jhwEuZih3+0c/262uf2BcK1ax4zqAkCzEaIlaC1k6x4zGtH0qf Tp+3wSJ4PptbvvJPKx6Q5oSHy7q1yvITpIWD+HSsdVGise7UF9MrCUFtNIZffxLj79XW ojVIYrXG3RQbyaChmhBQWObiNAPrRVbKcGnA7bmkSh6O9d1yPCvbFB+bEDWF3fv5KuKs iA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrsdejwmv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:44 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43TEdOSa011469; Mon, 29 Apr 2024 15:55:43 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt6j67k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:43 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43TFtaGk034442; Mon, 29 Apr 2024 15:55:42 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3xrqt6j5ys-10; Mon, 29 Apr 2024 15:55:42 +0000 From: Steve Sistare To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , David Hildenbrand , Igor Mammedov , Eduardo Habkost , Marcel Apfelbaum , Philippe Mathieu-Daude , Paolo Bonzini , "Daniel P. Berrange" , Markus Armbruster , Steve Sistare Subject: [PATCH V1 09/26] migration: vmstate_register_named Date: Mon, 29 Apr 2024 08:55:18 -0700 Message-Id: <1714406135-451286-10-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> References: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-29_14,2024-04-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404290101 X-Proofpoint-GUID: WEZZNIVNuHiWFwWOzeazeRuLu8RgV6TC X-Proofpoint-ORIG-GUID: WEZZNIVNuHiWFwWOzeazeRuLu8RgV6TC Received-SPF: pass client-ip=205.220.177.32; envelope-from=steven.sistare@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Define vmstate_register_named which takes the instance name as its first parameter, instead of generating the name from VMStateIf of the Object. This will be needed to register objects that are not Objects. Pass the new name parameter to vmstate_register_with_alias_id. Signed-off-by: Steve Sistare Reviewed-by: Fabiano Rosas --- hw/core/qdev.c | 1 + hw/intc/apic_common.c | 2 +- include/migration/vmstate.h | 19 +++++++++++++++++-- migration/savevm.c | 35 ++++++++++++++++++++++++----------- migration/trace-events | 1 + stubs/vmstate.c | 1 + 6 files changed, 45 insertions(+), 14 deletions(-) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 00efaf1..b352e8a 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -535,6 +535,7 @@ static void device_set_realized(Object *obj, bool value, Error **errp) qdev_get_vmsd(dev), dev, dev->instance_id_alias, dev->alias_required_for_version, + NULL, &local_err) < 0) { goto post_realize_fail; } diff --git a/hw/intc/apic_common.c b/hw/intc/apic_common.c index d8fc1e2..d6cd293 100644 --- a/hw/intc/apic_common.c +++ b/hw/intc/apic_common.c @@ -298,7 +298,7 @@ static void apic_common_realize(DeviceState *dev, Error **errp) instance_id = VMSTATE_INSTANCE_ID_ANY; } vmstate_register_with_alias_id(NULL, instance_id, &vmstate_apic_common, - s, -1, 0, NULL); + s, -1, 0, NULL, NULL); /* APIC LDR in x2APIC mode */ s->extended_log_dest = ((s->initial_apic_id >> 4) << 16) | diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index bb885d9..22aa3c6 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -1234,6 +1234,7 @@ int vmstate_register_with_alias_id(VMStateIf *obj, uint32_t instance_id, const VMStateDescription *vmsd, void *base, int alias_id, int required_for_version, + const char *instance_name, Error **errp); /** @@ -1250,7 +1251,7 @@ static inline int vmstate_register(VMStateIf *obj, int instance_id, void *opaque) { return vmstate_register_with_alias_id(obj, instance_id, vmsd, - opaque, -1, 0, NULL); + opaque, -1, 0, NULL, NULL); } /** @@ -1278,7 +1279,21 @@ static inline int vmstate_register_any(VMStateIf *obj, void *opaque) { return vmstate_register_with_alias_id(obj, VMSTATE_INSTANCE_ID_ANY, vmsd, - opaque, -1, 0, NULL); + opaque, -1, 0, NULL, NULL); +} + +/** + * vmstate_register_named() - pass an instance_name explicitly instead of + * implicitly via VMStateIf get_id(). Needed to register a instance-specific + * VMSD for objects that are not Objects. + */ +static inline int vmstate_register_named(const char *instance_name, + int instance_id, + const VMStateDescription *vmsd, + void *opaque) +{ + return vmstate_register_with_alias_id(NULL, instance_id, vmsd, opaque, + -1, 0, instance_name, NULL); } void vmstate_unregister(VMStateIf *obj, const VMStateDescription *vmsd, diff --git a/migration/savevm.c b/migration/savevm.c index 9b1a335..86b4c87 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -889,10 +889,20 @@ int vmstate_replace_hack_for_ppc(VMStateIf *obj, int instance_id, return vmstate_register(obj, instance_id, vmsd, opaque); } +static bool make_new_idstr(VMStateId idstr, const char *id, Error **errp) +{ + if (snprintf(idstr, sizeof(VMStateId), "%s/", id) >= sizeof(VMStateId)) { + error_setg(errp, "Path too long for VMState (%s)", id); + return false; + } + return true; +} + int vmstate_register_with_alias_id(VMStateIf *obj, uint32_t instance_id, const VMStateDescription *vmsd, void *opaque, int alias_id, int required_for_version, + const char *instance_name, Error **errp) { SaveStateEntry *se; @@ -907,19 +917,17 @@ int vmstate_register_with_alias_id(VMStateIf *obj, uint32_t instance_id, se->vmsd = vmsd; se->alias_id = alias_id; - if (obj) { - char *id = vmstate_if_get_id(obj); + if (instance_name) { + if (!make_new_idstr(se->idstr, instance_name, errp)) { + goto err; + } + + } else if (obj) { + g_autofree char *id = vmstate_if_get_id(obj); if (id) { - if (snprintf(se->idstr, sizeof(se->idstr), "%s/", id) >= - sizeof(se->idstr)) { - error_setg(errp, "Path too long for VMState (%s)", id); - g_free(id); - g_free(se); - - return -1; + if (!make_new_idstr(se->idstr, id, errp)) { + goto err; } - g_free(id); - se->compat = g_new0(CompatEntry, 1); pstrcpy(se->compat->idstr, sizeof(se->compat->idstr), vmsd->name); se->compat->instance_id = instance_id == VMSTATE_INSTANCE_ID_ANY ? @@ -941,7 +949,12 @@ int vmstate_register_with_alias_id(VMStateIf *obj, uint32_t instance_id, } assert(!se->compat || se->instance_id == 0); savevm_state_handler_insert(se); + trace_vmstate_register(se->idstr, se->instance_id, (void *)vmsd, opaque); return 0; + +err: + g_free(se); + return -1; } void vmstate_unregister(VMStateIf *obj, const VMStateDescription *vmsd, diff --git a/migration/trace-events b/migration/trace-events index f0e1cb8..8647147 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -53,6 +53,7 @@ vmstate_downtime_checkpoint(const char *checkpoint) "%s" postcopy_pause_incoming(void) "" postcopy_pause_incoming_continued(void) "" postcopy_page_req_sync(void *host_addr) "sync page req %p" +vmstate_register(const char *idstr, int id, void *vmsd, void *opaque) "%s, %d, vmsd %p, opaque %p" # vmstate.c vmstate_load_field_error(const char *field, int ret) "field \"%s\" load failed, ret = %d" diff --git a/stubs/vmstate.c b/stubs/vmstate.c index 8513d92..d67506e 100644 --- a/stubs/vmstate.c +++ b/stubs/vmstate.c @@ -6,6 +6,7 @@ int vmstate_register_with_alias_id(VMStateIf *obj, const VMStateDescription *vmsd, void *base, int alias_id, int required_for_version, + const char *instance_name, Error **errp) { return 0; From patchwork Mon Apr 29 15:55:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 13647330 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 9B62EC19F53 for ; Mon, 29 Apr 2024 16:01:11 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1TMI-0004YK-7e; Mon, 29 Apr 2024 11:56:02 -0400 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 1s1TMB-0004Vt-5M for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:55:55 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s1TM5-0005FQ-UR for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:55:53 -0400 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43TFmtke024859; Mon, 29 Apr 2024 15:55:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=1iyEuKHKhjkeO1rjz/LH8X1Di+OzUJZsFON4pYrDrmQ=; b=bVY32c4lgfahy4gdY4NuLsYkqiWiJ710CAtCJyg2oBcVtVAXwad1Ik/oE0ccS0yrlyyn KtpO4RsrZ3KOwSIZDzYnR77tnLq6MgRQfP0wUpTx/wH6YnNecpIJrzbAq/vyn9QBDPKs 0mYKN2vvXhxg4u9TPB9Y/dzlMSKK/Q8RhqrCqKwqfeBVVzhRmN+MXDaBTouZ1ylDjTFv p/fww9fmJ1frOHE4P14EUr6c2oLh5cFFXVWPMMPWk6vddFM3/J5ZLOg6G1WD6E8dMOqC B6q1+bbIN60+EBc6HuotKoOj8W2mL4iKZzaaChYsl6kfD1LYkYi2KQtANp5H14gX3jzX nw== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrqsetx3m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:45 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43TEgWMf011336; Mon, 29 Apr 2024 15:55:44 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt6j68u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:44 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43TFtaGm034442; Mon, 29 Apr 2024 15:55:43 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3xrqt6j5ys-11; Mon, 29 Apr 2024 15:55:43 +0000 From: Steve Sistare To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , David Hildenbrand , Igor Mammedov , Eduardo Habkost , Marcel Apfelbaum , Philippe Mathieu-Daude , Paolo Bonzini , "Daniel P. Berrange" , Markus Armbruster , Steve Sistare Subject: [PATCH V1 10/26] migration: vmstate_unregister_named Date: Mon, 29 Apr 2024 08:55:19 -0700 Message-Id: <1714406135-451286-11-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> References: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-29_14,2024-04-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404290101 X-Proofpoint-ORIG-GUID: BuDJYYtSpP_O1DFjifLULu__09e91xiN X-Proofpoint-GUID: BuDJYYtSpP_O1DFjifLULu__09e91xiN Received-SPF: pass client-ip=205.220.177.32; envelope-from=steven.sistare@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Define an accessor to find vmstate state handler by name and id and unregister it. This is needed to unregister a specific instance of an object that is not an Object, since it lacks the VMStateIf get_id hook. Signed-off-by: Steve Sistare --- include/migration/vmstate.h | 9 +++++++++ migration/savevm.c | 27 +++++++++++++++++++++++++++ migration/trace-events | 1 + stubs/vmstate.c | 6 ++++++ 4 files changed, 43 insertions(+) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 22aa3c6..3d71b34 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -1299,6 +1299,15 @@ static inline int vmstate_register_named(const char *instance_name, void vmstate_unregister(VMStateIf *obj, const VMStateDescription *vmsd, void *opaque); +/** + * Delete the VMSD handler for the object with name "vmsd_name/instance_name" + * and matching instance_id. If instance_id is VMSTATE_INSTANCE_ID_ANY, + * delete all instances matching name. + */ +void vmstate_unregister_named(const char *vmsd_name, + const char *instance_name, + int instance_id); + void vmstate_register_ram(struct MemoryRegion *memory, DeviceState *dev); void vmstate_unregister_ram(struct MemoryRegion *memory, DeviceState *dev); void vmstate_register_ram_global(struct MemoryRegion *memory); diff --git a/migration/savevm.c b/migration/savevm.c index 86b4c87..cd2eabe 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -964,6 +964,8 @@ void vmstate_unregister(VMStateIf *obj, const VMStateDescription *vmsd, SAVEVM_FOREACH_SAFE_ALL(se, entry, new_se) { if (se->vmsd == vmsd && se->opaque == opaque) { + trace_vmstate_unregister(se->idstr, se->instance_id, (void *)vmsd, + opaque); savevm_state_handler_remove(se); g_free(se->compat); g_free(se); @@ -971,6 +973,31 @@ void vmstate_unregister(VMStateIf *obj, const VMStateDescription *vmsd, } } +void vmstate_unregister_named(const char *vmsd_name, + const char *instance_name, + int instance_id) +{ + SaveStateEntry *se, *new_se; + VMStateId idstr; + + snprintf(idstr, sizeof(idstr), "%s/%s", vmsd_name, instance_name); + + SAVEVM_FOREACH_SAFE_ALL(se, entry, new_se) { + if (!strcmp(se->idstr, idstr) && + (instance_id == VMSTATE_INSTANCE_ID_ANY || + se->instance_id == instance_id)) { + trace_vmstate_unregister(idstr, se->instance_id, (void *)se->vmsd, + se->opaque); + savevm_state_handler_remove(se); + g_free(se->compat); + g_free(se); + if (instance_id != VMSTATE_INSTANCE_ID_ANY) { + return; + } + } + } +} + static int vmstate_load(QEMUFile *f, SaveStateEntry *se) { trace_vmstate_load(se->idstr, se->vmsd ? se->vmsd->name : "(old)"); diff --git a/migration/trace-events b/migration/trace-events index 8647147..1e23238 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -54,6 +54,7 @@ postcopy_pause_incoming(void) "" postcopy_pause_incoming_continued(void) "" postcopy_page_req_sync(void *host_addr) "sync page req %p" vmstate_register(const char *idstr, int id, void *vmsd, void *opaque) "%s, %d, vmsd %p, opaque %p" +vmstate_unregister(const char *idstr, int id, void *vmsd, void *opaque) "%s, %d, vmsd %p, opaque %p" # vmstate.c vmstate_load_field_error(const char *field, int ret) "field \"%s\" load failed, ret = %d" diff --git a/stubs/vmstate.c b/stubs/vmstate.c index d67506e..eff8be4 100644 --- a/stubs/vmstate.c +++ b/stubs/vmstate.c @@ -18,6 +18,12 @@ void vmstate_unregister(VMStateIf *obj, { } +void vmstate_unregister_named(const char *vmsd_name, + const char *instance_name, + int instance_id) +{ +} + bool vmstate_check_only_migratable(const VMStateDescription *vmsd) { return true; From patchwork Mon Apr 29 15:55:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 13647319 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id A1A91C4345F for ; Mon, 29 Apr 2024 15:57:15 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1TMF-0004X5-Mi; Mon, 29 Apr 2024 11:55:59 -0400 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 1s1TMB-0004Vs-7U for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:55:55 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s1TM5-0005Fb-RE for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:55:53 -0400 Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43TFml1T021753; Mon, 29 Apr 2024 15:55:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=LzcEoTaqq99sN03X9qX31cStr9peqSwOasAJUDXCZM8=; b=kI51nE349QCVJ4sWJyq4jeYPzaVdsQcW09dpM9ZSN6iFj5WNaUhjCLXNIL6qkAG+pMuV pEMWqutrIVYh1ZYocwSMATQZe6KEbNbOiWh6JPSNmZUOLd+Gy4gQI2/esQGEnFs/S2Ja 7rKs1/zQCNVaZdViaj+buEGcBP8QQgHxCTFl8bDonLjLcGA+Of+KyRPJN0HJRhlz3SB3 VQ1C/OsXKKgK0IBTGRCPh7M3LaTiUx5mZYlQ/MyZOFzZyE+yXpEgvtGpp751Vivukjhw 6h7ttHLl+Q/YP/BUp+wWsQKms7UGTQ9TnLTvxRzMHF5Mwjom7quyQwpp0VhbkoiVfjg+ XA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrr54axsx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:46 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43TFp3V3011441; Mon, 29 Apr 2024 15:55:45 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt6j69q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:45 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43TFtaGo034442; Mon, 29 Apr 2024 15:55:44 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3xrqt6j5ys-12; Mon, 29 Apr 2024 15:55:44 +0000 From: Steve Sistare To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , David Hildenbrand , Igor Mammedov , Eduardo Habkost , Marcel Apfelbaum , Philippe Mathieu-Daude , Paolo Bonzini , "Daniel P. Berrange" , Markus Armbruster , Steve Sistare Subject: [PATCH V1 11/26] migration: vmstate_register at init time Date: Mon, 29 Apr 2024 08:55:20 -0700 Message-Id: <1714406135-451286-12-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> References: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-29_14,2024-04-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404290101 X-Proofpoint-ORIG-GUID: ohXr_sM7tsS6uc2XKKMImGShsoBvCqMc X-Proofpoint-GUID: ohXr_sM7tsS6uc2XKKMImGShsoBvCqMc Received-SPF: pass client-ip=205.220.177.32; envelope-from=steven.sistare@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Define vmstate_register_init to statically declare that a vmstate object should be registered during qemu initialization, specifically, in the call to vmstate_register_init_all. This is needed to register objects that are not Objects (and hence cannot use the DeviceClass vmsd hook), without requiring that qemu call an object-specific initialization function. Signed-off-by: Steve Sistare --- include/migration/vmstate.h | 18 ++++++++++++++++++ migration/savevm.c | 32 ++++++++++++++++++++++++++++++++ system/vl.c | 3 +++ 3 files changed, 53 insertions(+) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 3d71b34..8cb3d2b 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -1255,6 +1255,24 @@ static inline int vmstate_register(VMStateIf *obj, int instance_id, } /** + * vmstate_register_init() - statically declare a VMSD to be registered when + * QEMU calls vmstate_register_init_all. This is useful for registering + * objects that are not Objects (and hence cannot use the DeviceClass vmsd + * hook). + */ +#define vmstate_register_init(_obj, _id, _vmsd, _opaque) \ +static void __attribute__((constructor)) vmstate_register_ ## _vmsd(void) \ +{ \ + vmstate_register_init_add(_obj, _id, &_vmsd, _opaque); \ +} + +void vmstate_register_init_add(VMStateIf *obj, int instance_id, + const VMStateDescription *vmsd, void *opaque); + +void vmstate_register_init_all(void); + + +/** * vmstate_replace_hack_for_ppc() - ppc used to abuse vmstate_register * * Don't even think about using this function in new code. diff --git a/migration/savevm.c b/migration/savevm.c index cd2eabe..ec48da9 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -957,6 +957,38 @@ err: return -1; } +typedef struct VMStateInit { + VMStateIf *obj; + int instance_id; + const VMStateDescription *vmsd; + void *opaque; + QLIST_ENTRY(VMStateInit) next; +} VMStateInit; + +static QLIST_HEAD(, VMStateInit) vmstate_inits; + +void vmstate_register_init_add(VMStateIf *obj, int instance_id, + const VMStateDescription *vmsd, void *opaque) +{ + VMStateInit *v = g_new0(VMStateInit, 1); + + v->obj = obj; + v->instance_id = instance_id; + v->vmsd = vmsd; + v->opaque = opaque; + QLIST_INSERT_HEAD(&vmstate_inits, v, next); +} + +void vmstate_register_init_all(void) +{ + VMStateInit *v, *tmp; + + QLIST_FOREACH_SAFE(v, &vmstate_inits, next, tmp) { + vmstate_register(v->obj, v->instance_id, v->vmsd, v->opaque); + QLIST_REMOVE(v, next); + } +} + void vmstate_unregister(VMStateIf *obj, const VMStateDescription *vmsd, void *opaque) { diff --git a/system/vl.c b/system/vl.c index c644222..7797206 100644 --- a/system/vl.c +++ b/system/vl.c @@ -78,6 +78,7 @@ #include "hw/i386/pc.h" #include "migration/misc.h" #include "migration/snapshot.h" +#include "migration/vmstate.h" #include "sysemu/tpm.h" #include "sysemu/dma.h" #include "hw/audio/soundhw.h" @@ -3663,6 +3664,8 @@ void qemu_init(int argc, char **argv) qemu_create_machine(machine_opts_dict); + vmstate_register_init_all(); + suspend_mux_open(); qemu_disable_default_devices(); From patchwork Mon Apr 29 15:55:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 13647333 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 1D522C4345F for ; Mon, 29 Apr 2024 16:02:38 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1TMH-0004Xv-Es; Mon, 29 Apr 2024 11:56:01 -0400 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 1s1TMB-0004Vu-7U for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:55:56 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s1TM5-0005Fo-U3 for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:55:53 -0400 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43TFmnhD023131; Mon, 29 Apr 2024 15:55:47 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=TtzXAOMSJ+mFPsS060bW1BIYuL+1IqosMX6aAuhUFBc=; b=dEFIgmEMytoW7mzIPB9s9NsSaGxgiAVN5FiK6H0awX0hdVZYcIZsIzxpNJyl53UVt8h9 MZN7isdagMCZldWq6LGYIwd+w6oQW0tsqfq/9QEOeN3XmMePtrlelIxiSXP95KEZTqdG CKsUp2WuRB4qUgkmei2hsBMfpAqJvoBvs8wwY7zGcKInC/oreMTrggEGFHgSr3WRw4U7 dOFyQQO60HfdeARirSPiBPeCSDryvnO94DXP2sI01XKC4rlU6L4xVTkmh1yFb8iY5nLA qLJFkSvPIeX4dq8qAkcbjICS5+tr5npwpdZ4J4d/4Jr4jgBfrhTKITDPfr7tbwtm1BsI Yw== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrryv2wbt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:47 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43TEheoD011366; Mon, 29 Apr 2024 15:55:46 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt6j6ap-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:46 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43TFtaGq034442; Mon, 29 Apr 2024 15:55:45 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3xrqt6j5ys-13; Mon, 29 Apr 2024 15:55:45 +0000 From: Steve Sistare To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , David Hildenbrand , Igor Mammedov , Eduardo Habkost , Marcel Apfelbaum , Philippe Mathieu-Daude , Paolo Bonzini , "Daniel P. Berrange" , Markus Armbruster , Steve Sistare Subject: [PATCH V1 12/26] migration: vmstate factory object Date: Mon, 29 Apr 2024 08:55:21 -0700 Message-Id: <1714406135-451286-13-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> References: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-29_14,2024-04-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404290101 X-Proofpoint-GUID: jCwUEuM3k0csDSnwJbllX2OWoYHJqr47 X-Proofpoint-ORIG-GUID: jCwUEuM3k0csDSnwJbllX2OWoYHJqr47 Received-SPF: pass client-ip=205.220.177.32; envelope-from=steven.sistare@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org During the precreate phase, we will load migration state that will be used to create objects, but those objects have not been created and have not registered a vmstate handler yet. We don't know how many objects will be created, or what their names and ids will be, so we don't know what vmstate handlers to register. To solve this problem, define the factory object. A factory object is added to the outgoing migration stream as usual, by registering a vmsd and opaque pointer. During incoming migration, it is allocated on demand, without relying on a pre-registered object's opaque address. Instead, register a factory that knows the object's size. loadvm receives an idstr which contains a factory name, finds the factory, allocates the object, then loads the fields as usual. The object is added to a factory_objects list, tagged by name and id, to be found and claimed later by object-specific code. A factory is a registered VMStateDescription with factory=true and instance_id VMSTATE_INSTANCE_ID_FACTORY. A factory object is registered using the same VMStateDescription, but with its own instance_name and instance_id. Signed-off-by: Steve Sistare --- include/migration/vmstate.h | 66 +++++++++++++++++++++++++++++++++++++- migration/meson.build | 1 + migration/savevm.c | 66 ++++++++++++++++++++++++++++++++++++-- migration/trace-events | 5 +++ migration/vmstate-factory.c | 78 +++++++++++++++++++++++++++++++++++++++++++++ stubs/vmstate.c | 6 ++++ 6 files changed, 218 insertions(+), 4 deletions(-) create mode 100644 migration/vmstate-factory.c diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 8cb3d2b..00ad864 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -204,6 +204,11 @@ struct VMStateDescription { */ bool precreate; + /* + * This VMSD is a factory or a factory object. + */ + bool factory; + int version_id; int minimum_version_id; MigrationPriority priority; @@ -1228,6 +1233,17 @@ bool vmstate_section_needed(const VMStateDescription *vmsd, void *opaque); typedef char (VMStateId)[256]; #define VMSTATE_INSTANCE_ID_ANY -1 +#define VMSTATE_INSTANCE_ID_FACTORY -2 + +#include "qemu/queue.h" + +typedef struct FactoryObject { + char *factory_name; + char *instance_name; + int instance_id; + void *opaque; + QLIST_ENTRY(FactoryObject) next; +} FactoryObject; /* Returns: 0 on success, -1 on failure */ int vmstate_register_with_alias_id(VMStateIf *obj, uint32_t instance_id, @@ -1266,6 +1282,10 @@ static void __attribute__((constructor)) vmstate_register_ ## _vmsd(void) \ vmstate_register_init_add(_obj, _id, &_vmsd, _opaque); \ } +#define vmstate_register_init_factory(_vmsd, _type) \ + vmstate_register_init(NULL, VMSTATE_INSTANCE_ID_FACTORY, \ + _vmsd, (void *)sizeof(_type)) + void vmstate_register_init_add(VMStateIf *obj, int instance_id, const VMStateDescription *vmsd, void *opaque); @@ -1301,8 +1321,20 @@ static inline int vmstate_register_any(VMStateIf *obj, } /** + * vmstate_register_factory() - register a factory name and size, needed to + * recognize incoming factory objects. + */ +static inline int vmstate_register_factory(const VMStateDescription *vmsd, + long size) +{ + return vmstate_register_with_alias_id(NULL, VMSTATE_INSTANCE_ID_FACTORY, + vmsd, (void *)size, -1, 0, NULL, + NULL); +} + +/** * vmstate_register_named() - pass an instance_name explicitly instead of - * implicitly via VMStateIf get_id(). Needed to register a instance-specific + * implicitly via VMStateIf get_id(). Needed to register an instance-specific * VMSD for objects that are not Objects. */ static inline int vmstate_register_named(const char *instance_name, @@ -1332,4 +1364,36 @@ void vmstate_register_ram_global(struct MemoryRegion *memory); bool vmstate_check_only_migratable(const VMStateDescription *vmsd); +/* + * Add to the factory object list, called during loadvm. + */ +void vmstate_add_factory_object(const char *factory_name, + const char *instance_name, + int instance_id, + void *opaque); + +/* + * Search for and return a factory object. + */ +void *vmstate_find_factory_object(const char *factory_name, + const char *instance_name, + int instance_id); + +/* + * Search for and return a factory object, removing it from the list. + */ +void *vmstate_claim_factory_object(const char *factory_name, + const char *instance_name, + int instance_id); + +typedef int (*vmstate_walk_factory_cb)(FactoryObject *obj, void *opaque); + +/* + * Search for registered factory objects (ie, outgoing) + * and call cb passing opaque. + */ +int vmstate_walk_factory_outgoing(const char *factory_name, + vmstate_walk_factory_cb cb, + void *opaque); + #endif diff --git a/migration/meson.build b/migration/meson.build index 50e7cb2..e667b40 100644 --- a/migration/meson.build +++ b/migration/meson.build @@ -5,6 +5,7 @@ migration_files = files( 'xbzrle.c', 'vmstate-types.c', 'vmstate.c', + 'vmstate-factory.c', 'qemu-file.c', 'yank_functions.c', ) diff --git a/migration/savevm.c b/migration/savevm.c index ec48da9..01ed78c 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1407,7 +1407,8 @@ int qemu_savevm_precreate_save(QEMUFile *f, Error **errp) qemu_put_be32(f, QEMU_VM_FILE_VERSION); SAVEVM_FOREACH_ALL(se, entry) { - if (se->vmsd && se->vmsd->precreate) { + if (se->vmsd && se->vmsd->precreate && + se->instance_id != VMSTATE_INSTANCE_ID_FACTORY) { ret = vmstate_save(f, se, NULL, errp); if (ret) { qemu_file_set_error(f, ret); @@ -1951,6 +1952,45 @@ static SaveStateEntry *find_se(const char *idstr, uint32_t instance_id) return NULL; } +int vmstate_walk_factory_outgoing(const char *factory_name, + vmstate_walk_factory_cb cb, void *cb_data) +{ + SaveStateEntry *se, *new_se; + int ret, instance_len; + FactoryObject obj; + VMStateId idstr; + char *se_factory_name; + + SAVEVM_FOREACH_SAFE_ALL(se, entry, new_se) { + if (!se->vmsd || !se->vmsd->factory) { + continue; + } + if (se->instance_id == VMSTATE_INSTANCE_ID_FACTORY) { + /* This is the factory itself, not a generated instance */ + continue; + } + + se_factory_name = strrchr(se->idstr, '/'); + if (factory_name && strcmp(se_factory_name + 1, factory_name)) { + continue; + } + + strcpy(idstr, se->idstr); + instance_len = se_factory_name - se->idstr; + idstr[instance_len] = 0; + obj.factory_name = idstr + instance_len + 1; + obj.instance_name = idstr; + obj.instance_id = se->instance_id; + obj.opaque = se->opaque; + + ret = cb(&obj, cb_data); + if (ret) { + return ret; + } + } + return 0; +} + enum LoadVMExitCodes { /* Allow a command to quit all layers of nested loadvm loops */ LOADVM_QUIT = 1, @@ -2721,8 +2761,9 @@ qemu_loadvm_section_start_full(QEMUFile *f, uint8_t type) bool trace_downtime = (type == QEMU_VM_SECTION_FULL); uint32_t instance_id, version_id, section_id; int64_t start_ts, end_ts; - SaveStateEntry *se; - VMStateId idstr; + SaveStateEntry *se, new_se; + VMStateId idstr, instance_name; + char *factory_name = NULL; int ret; /* Read section start */ @@ -2744,8 +2785,22 @@ qemu_loadvm_section_start_full(QEMUFile *f, uint8_t type) trace_qemu_loadvm_state_section_startfull(section_id, idstr, instance_id, version_id); + /* Find savevm section */ se = find_se(idstr, instance_id); + + if (se == NULL) { + pstrcpy(instance_name, sizeof(idstr), idstr); + factory_name = strrchr(instance_name, '/'); + if (factory_name) { + *factory_name++ = 0; + se = find_se(factory_name, VMSTATE_INSTANCE_ID_FACTORY); + new_se = *se; + new_se.opaque = g_malloc((long)se->opaque); + se = &new_se; + } + } + if (se == NULL) { error_report("Unknown savevm section or instance '%s' %"PRIu32". " "Make sure that your current VM setup matches your " @@ -2780,6 +2835,11 @@ qemu_loadvm_section_start_full(QEMUFile *f, uint8_t type) return ret; } + if (factory_name) { + vmstate_add_factory_object(factory_name, instance_name, instance_id, + se->opaque); + } + if (trace_downtime) { end_ts = qemu_clock_get_us(QEMU_CLOCK_REALTIME); trace_vmstate_downtime_load("non-iterable", se->idstr, diff --git a/migration/trace-events b/migration/trace-events index 1e23238..3b9c292 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -72,6 +72,11 @@ vmstate_subsection_save_loop(const char *name, const char *sub) "%s/%s" vmstate_subsection_save_top(const char *idstr) "%s" vmstate_field_exists(const char *vmsd, const char *name, int field_version, int version, int result) "%s:%s field_version %d version %d result %d" +# vmstate-factory.c +vmstate_add_factory_object(const char *factory_name, const char *idstr, int instance_id, void *opaque) " %s, %s, %d, %p" +vmstate_find_factory_object(const char *factory_name, const char *instance_name, int instance_id, void *opaque) "%s, %s, %d -> %p" +vmstate_claim_factory_object(const char *factory_name, const char *instance_name, int instance_id, void *opaque) "%s, %s, %d -> %p" + # vmstate-types.c get_qtailq(const char *name, int version_id) "%s v%d" get_qtailq_end(const char *name, const char *reason, int val) "%s %s/%d" diff --git a/migration/vmstate-factory.c b/migration/vmstate-factory.c new file mode 100644 index 0000000..e425666 --- /dev/null +++ b/migration/vmstate-factory.c @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ +#include "qemu/osdep.h" +#include "migration/vmstate.h" +#include "trace.h" + +static QLIST_HEAD(, FactoryObject) factory_objects; + +void vmstate_add_factory_object(const char *factory_name, + const char *instance_name, + int instance_id, + void *opaque) +{ + FactoryObject *obj = g_new0(FactoryObject, 1); + + obj->opaque = opaque; + obj->factory_name = g_strdup(factory_name); + obj->instance_name = g_strdup(instance_name); + obj->instance_id = instance_id; + QLIST_INSERT_HEAD(&factory_objects, obj, next); + trace_vmstate_add_factory_object(factory_name, instance_name, instance_id, + opaque); + +} + +#define object_match(obj, _factory_name, _instance_name, _instance_id) \ + (!strcmp(obj->factory_name, _factory_name) && \ + !strcmp(obj->instance_name, _instance_name) && \ + obj->instance_id == _instance_id) + +static FactoryObject *find_object(const char *factory_name, + const char *instance_name, + int instance_id) +{ + FactoryObject *obj; + + QLIST_FOREACH(obj, &factory_objects, next) { + if (object_match(obj, factory_name, instance_name, instance_id)) { + return obj; + } + } + + return NULL; +} + +void *vmstate_find_factory_object(const char *factory_name, + const char *instance_name, + int instance_id) +{ + FactoryObject *obj = find_object(factory_name, instance_name, instance_id); + void *opaque = obj ? obj->opaque : NULL; + + trace_vmstate_find_factory_object(factory_name, instance_name, instance_id, + opaque); + return opaque; +} + +void *vmstate_claim_factory_object(const char *factory_name, + const char *instance_name, + int instance_id) +{ + FactoryObject *obj = find_object(factory_name, instance_name, instance_id); + void *opaque = obj ? obj->opaque : NULL; + + if (obj) { + g_free(obj->factory_name); + g_free(obj->instance_name); + QLIST_REMOVE(obj, next); + } + + trace_vmstate_claim_factory_object(factory_name, instance_name, instance_id, + opaque); + return opaque; +} diff --git a/stubs/vmstate.c b/stubs/vmstate.c index eff8be4..0e977e2 100644 --- a/stubs/vmstate.c +++ b/stubs/vmstate.c @@ -24,6 +24,12 @@ void vmstate_unregister_named(const char *vmsd_name, { } +int vmstate_walk_factory_outgoing(const char *factory_name, + vmstate_walk_factory_cb cb, void *cb_data) +{ + return 1; +} + bool vmstate_check_only_migratable(const VMStateDescription *vmsd) { return true; From patchwork Mon Apr 29 15:55:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 13647336 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id DBBB3C04FFE for ; Mon, 29 Apr 2024 16:06:10 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1TMW-0004rn-2k; Mon, 29 Apr 2024 11:56:16 -0400 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 1s1TMI-0004YO-6M for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:56:02 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s1TMF-0005Fq-V6 for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:56:01 -0400 Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43TFmjvS006702; Mon, 29 Apr 2024 15:55:47 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=on/dHn8yh7blYwmWHlzbl2iCCZvcPBO2UbSOSMfAHcA=; b=oWbd01wxZhY6xNw9wFmx+eC0UImOeKSeyNplXNmhZSjkzlT84bY7OvowHaTBtAs3TrrE KzR107f/gBiMh3OfmfxElfqWo6kzBTixjUsxklZOTRt38DalCKbodlKyi9e2eG8fp+iH Zh0hh6QrZIH5XG8SNAnatPQEvKE1mNiSztR2r9WUx7Owq8L0p/lu4ckp3X4q2CVfnluJ kkoIkj1LnpXuoB6M+LeIwcQdQddvm6L9l0ISS4csrCNphrAJ6OrWkNLTse+Cycrx+Dvq RRksrnyWROV472UeXbOHQf/o8omzSIL37oOrZ01L7UJNq1tU0nq0VBet8zxn392eujeS NQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrsdejwn3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:47 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43TEj25e011398; Mon, 29 Apr 2024 15:55:46 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt6j6bf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:46 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43TFtaGs034442; Mon, 29 Apr 2024 15:55:45 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3xrqt6j5ys-14; Mon, 29 Apr 2024 15:55:45 +0000 From: Steve Sistare To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , David Hildenbrand , Igor Mammedov , Eduardo Habkost , Marcel Apfelbaum , Philippe Mathieu-Daude , Paolo Bonzini , "Daniel P. Berrange" , Markus Armbruster , Steve Sistare Subject: [PATCH V1 13/26] physmem: ram_block_create Date: Mon, 29 Apr 2024 08:55:22 -0700 Message-Id: <1714406135-451286-14-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> References: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-29_14,2024-04-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404290101 X-Proofpoint-GUID: D80zV2ykTrJXFl01qh9wWugF3uyURfRn X-Proofpoint-ORIG-GUID: D80zV2ykTrJXFl01qh9wWugF3uyURfRn Received-SPF: pass client-ip=205.220.177.32; envelope-from=steven.sistare@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Create a common subroutine to allocate a RAMBlock, de-duping the code to populate its common fields. Add a trace point for good measure. No functional change. Signed-off-by: Steve Sistare --- system/physmem.c | 47 ++++++++++++++++++++++++++--------------------- system/trace-events | 3 +++ 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/system/physmem.c b/system/physmem.c index c3d04ca..6216b14 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -52,6 +52,7 @@ #include "sysemu/hw_accel.h" #include "sysemu/xen-mapcache.h" #include "trace/trace-root.h" +#include "trace.h" #ifdef CONFIG_FALLOCATE_PUNCH_HOLE #include @@ -1918,11 +1919,29 @@ out_free: } } +static RAMBlock *ram_block_create(MemoryRegion *mr, ram_addr_t size, + ram_addr_t max_size, uint32_t ram_flags) +{ + RAMBlock *rb = g_malloc0(sizeof(*rb)); + + rb->used_length = size; + rb->max_length = max_size; + rb->fd = -1; + rb->flags = ram_flags; + rb->page_size = qemu_real_host_page_size(); + rb->mr = mr; + rb->guest_memfd = -1; + trace_ram_block_create(rb->idstr, rb->flags, rb->fd, rb->used_length, + rb->max_length, mr->align); + return rb; +} + #ifdef CONFIG_POSIX RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, uint32_t ram_flags, int fd, off_t offset, Error **errp) { + void *host; RAMBlock *new_block; Error *local_err = NULL; int64_t file_size, file_align; @@ -1962,19 +1981,14 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, return NULL; } - new_block = g_malloc0(sizeof(*new_block)); - new_block->mr = mr; - new_block->used_length = size; - new_block->max_length = size; - new_block->flags = ram_flags; - new_block->guest_memfd = -1; - new_block->host = file_ram_alloc(new_block, size, fd, !file_size, offset, - errp); - if (!new_block->host) { + new_block = ram_block_create(mr, size, size, ram_flags); + host = file_ram_alloc(new_block, size, fd, !file_size, offset, errp); + if (!host) { g_free(new_block); return NULL; } + new_block->host = host; ram_block_add(new_block, &local_err); if (local_err) { g_free(new_block); @@ -1982,7 +1996,6 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, return NULL; } return new_block; - } @@ -2054,18 +2067,10 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size, align = MAX(align, TARGET_PAGE_SIZE); size = ROUND_UP(size, align); max_size = ROUND_UP(max_size, align); - - new_block = g_malloc0(sizeof(*new_block)); - new_block->mr = mr; - new_block->resized = resized; - new_block->used_length = size; - new_block->max_length = max_size; assert(max_size >= size); - new_block->fd = -1; - new_block->guest_memfd = -1; - new_block->page_size = qemu_real_host_page_size(); - new_block->host = host; - new_block->flags = ram_flags; + new_block = ram_block_create(mr, size, max_size, ram_flags); + new_block->resized = resized; + ram_block_add(new_block, &local_err); if (local_err) { g_free(new_block); diff --git a/system/trace-events b/system/trace-events index 69c9044..f0a80ba 100644 --- a/system/trace-events +++ b/system/trace-events @@ -38,3 +38,6 @@ dirtylimit_state_finalize(void) dirtylimit_throttle_pct(int cpu_index, uint64_t pct, int64_t time_us) "CPU[%d] throttle percent: %" PRIu64 ", throttle adjust time %"PRIi64 " us" dirtylimit_set_vcpu(int cpu_index, uint64_t quota) "CPU[%d] set dirty page rate limit %"PRIu64 dirtylimit_vcpu_execute(int cpu_index, int64_t sleep_time_us) "CPU[%d] sleep %"PRIi64 " us" + +# physmem.c +ram_block_create(const char *name, uint32_t flags, int fd, size_t used_length, size_t max_length, size_t align) "%s, flags %u, fd %d, len %lu, maxlen %lu, align %lu" From patchwork Mon Apr 29 15:55:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 13647327 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 47B71C41513 for ; Mon, 29 Apr 2024 15:59:46 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1TMm-0005Gp-1c; Mon, 29 Apr 2024 11:56:32 -0400 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 1s1TML-0004bE-J2 for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:56:06 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s1TMI-0005G8-JD for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:56:04 -0400 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43TFmnrW023173; Mon, 29 Apr 2024 15:55:48 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=36mCyWFnknwNhH0B4xYEyn7ewW0hY0bHUl96xUN213U=; b=dXyKY1ylWEmMxTC2H6sppI4Zoq1D6T1QQYUEOj47gwcMB/oTEmdYM9YMp7yxpKlMyxsB ZR5e5xt1NsYX4X7flNuKO0+hlzX3sjcLEhQwKOg8QVWPIw6vk6igDutN8znyAHfNHtoT pewsHh4DH+fxCqHmn2TGDh/Vxc4p/LSgFul5t4XSGuUYI8iBzFxDKJLjEENGbcRDl+e0 Nivh0C+TNNieLaO79LWo8+iXoHQsLh6X4pBFUvsxKo/onVIgy9TfYziACx+GSkBMUFcx FpeIpQCyEi+nRx7REh+9J+G+Di4EAUQFDR7L42bGgyTUVkDlPYAjGdDNDO7k6weDZYek wg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrryv2wby-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:48 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43TFAtv5011379; Mon, 29 Apr 2024 15:55:47 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt6j6cj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:47 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43TFtaGu034442; Mon, 29 Apr 2024 15:55:46 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3xrqt6j5ys-15; Mon, 29 Apr 2024 15:55:46 +0000 From: Steve Sistare To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , David Hildenbrand , Igor Mammedov , Eduardo Habkost , Marcel Apfelbaum , Philippe Mathieu-Daude , Paolo Bonzini , "Daniel P. Berrange" , Markus Armbruster , Steve Sistare Subject: [PATCH V1 14/26] physmem: hoist guest_memfd creation Date: Mon, 29 Apr 2024 08:55:23 -0700 Message-Id: <1714406135-451286-15-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> References: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-29_14,2024-04-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404290101 X-Proofpoint-GUID: UYhh70tNoRJsC3TSXG4YZQ9ZOG27g5_V X-Proofpoint-ORIG-GUID: UYhh70tNoRJsC3TSXG4YZQ9ZOG27g5_V Received-SPF: pass client-ip=205.220.177.32; envelope-from=steven.sistare@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Do not modify RAMBlocks in ram_block_add. The block should be fully formed before calling ram_block_add to add it to the block list. This will simplify error handling and be more modular. Start by hoisting guest_memfd creation to the call sites. No functional change. Signed-off-by: Steve Sistare --- system/physmem.c | 85 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 37 deletions(-) diff --git a/system/physmem.c b/system/physmem.c index 6216b14..ffcf012 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -1803,13 +1803,34 @@ static void dirty_memory_extend(ram_addr_t old_ram_size, } } +static int ram_block_create_guest_memfd(RAMBlock *rb, Error **errp) +{ + assert(kvm_enabled()); + + if (ram_block_discard_require(true) < 0) { + error_setg_errno(errp, errno, + "cannot set up private guest memory: discard currently blocked"); + error_append_hint(errp, "Are you using assigned devices?\n"); + return -1; + } + + return kvm_create_guest_memfd(rb->max_length, 0, errp); +} + +static void ram_block_destroy_guest_memfd(RAMBlock *rb) +{ + if (rb->guest_memfd >= 0) { + close(rb->guest_memfd); + ram_block_discard_require(false); + } +} + static void ram_block_add(RAMBlock *new_block, Error **errp) { const bool noreserve = qemu_ram_is_noreserve(new_block); const bool shared = qemu_ram_is_shared(new_block); RAMBlock *block; RAMBlock *last_block = NULL; - bool free_on_error = false; ram_addr_t old_ram_size, new_ram_size; Error *err = NULL; @@ -1839,26 +1860,6 @@ static void ram_block_add(RAMBlock *new_block, Error **errp) return; } memory_try_enable_merging(new_block->host, new_block->max_length); - free_on_error = true; - } - } - - if (new_block->flags & RAM_GUEST_MEMFD) { - assert(kvm_enabled()); - assert(new_block->guest_memfd < 0); - - if (ram_block_discard_require(true) < 0) { - error_setg_errno(errp, errno, - "cannot set up private guest memory: discard currently blocked"); - error_append_hint(errp, "Are you using assigned devices?\n"); - goto out_free; - } - - new_block->guest_memfd = kvm_create_guest_memfd(new_block->max_length, - 0, errp); - if (new_block->guest_memfd < 0) { - qemu_mutex_unlock_ramlist(); - goto out_free; } } @@ -1910,17 +1911,11 @@ static void ram_block_add(RAMBlock *new_block, Error **errp) ram_block_notify_add(new_block->host, new_block->used_length, new_block->max_length); } - return; - -out_free: - if (free_on_error) { - qemu_anon_ram_free(new_block->host, new_block->max_length); - new_block->host = NULL; - } } static RAMBlock *ram_block_create(MemoryRegion *mr, ram_addr_t size, - ram_addr_t max_size, uint32_t ram_flags) + ram_addr_t max_size, uint32_t ram_flags, + Error **errp) { RAMBlock *rb = g_malloc0(sizeof(*rb)); @@ -1930,7 +1925,17 @@ static RAMBlock *ram_block_create(MemoryRegion *mr, ram_addr_t size, rb->flags = ram_flags; rb->page_size = qemu_real_host_page_size(); rb->mr = mr; - rb->guest_memfd = -1; + + if (ram_flags & RAM_GUEST_MEMFD) { + rb->guest_memfd = ram_block_create_guest_memfd(rb, errp); + if (rb->guest_memfd < 0) { + g_free(rb); + return NULL; + } + } else { + rb->guest_memfd = -1; + } + trace_ram_block_create(rb->idstr, rb->flags, rb->fd, rb->used_length, rb->max_length, mr->align); return rb; @@ -1981,9 +1986,14 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, return NULL; } - new_block = ram_block_create(mr, size, size, ram_flags); + new_block = ram_block_create(mr, size, size, ram_flags, errp); + if (!new_block) { + return NULL; + } + host = file_ram_alloc(new_block, size, fd, !file_size, offset, errp); if (!host) { + ram_block_destroy_guest_memfd(new_block); g_free(new_block); return NULL; } @@ -2068,11 +2078,16 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size, size = ROUND_UP(size, align); max_size = ROUND_UP(max_size, align); assert(max_size >= size); - new_block = ram_block_create(mr, size, max_size, ram_flags); + new_block = ram_block_create(mr, size, max_size, ram_flags, errp); + if (!new_block) { + return NULL; + } new_block->resized = resized; + new_block->host = host; ram_block_add(new_block, &local_err); if (local_err) { + ram_block_destroy_guest_memfd(new_block); g_free(new_block); error_propagate(errp, local_err); return NULL; @@ -2119,11 +2134,7 @@ static void reclaim_ramblock(RAMBlock *block) qemu_anon_ram_free(block->host, block->max_length); } - if (block->guest_memfd >= 0) { - close(block->guest_memfd); - ram_block_discard_require(false); - } - + ram_block_destroy_guest_memfd(block); g_free(block); } From patchwork Mon Apr 29 15:55:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 13647334 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id E9396C4345F for ; Mon, 29 Apr 2024 16:03:45 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1TMZ-0004zT-I4; Mon, 29 Apr 2024 11:56:19 -0400 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 1s1TMJ-0004aH-Ru for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:56:04 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s1TMI-0005Gh-2g for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:56:03 -0400 Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43TFmoK9021820; Mon, 29 Apr 2024 15:55:49 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=5W3Uqi4pt3zRyBqCA3ANso+QnzCYfMdNqiQwmSxIPBU=; b=aPwa47nHVSwmydqNUpY5aAlBcaUI93HussR2INpO4QLt1OMnNVXlylVzYL3p4VwzMAr3 2JGdfEIlN0sddOlTqidc2ger5xjbpXam+L+n1h+IKb1+bxl+PGbBAXTOW1zMpsFzecrm /RZkqjs+k2i+S+XX3r2xc34FSFx8P+/A0AMFqwUwp3LqL8JCBNU4f4JhoCPhg19c7r5C 0x0GWbPkmNNcpecSr57PX4hWWfnCcajqsN32Oe59HbdR0Y0Fi8QtPMX40v+/IEBFpFVO ZjjdeGGZmh3ga59SK7norNg2R8DpSJq1orZ3brI7A84zcDwbceoRM5fd7hbpAgkqioVX cA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrr54axt8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:49 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43TEuHx5011355; Mon, 29 Apr 2024 15:55:48 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt6j6d8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:47 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43TFtaGw034442; Mon, 29 Apr 2024 15:55:47 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3xrqt6j5ys-16; Mon, 29 Apr 2024 15:55:47 +0000 From: Steve Sistare To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , David Hildenbrand , Igor Mammedov , Eduardo Habkost , Marcel Apfelbaum , Philippe Mathieu-Daude , Paolo Bonzini , "Daniel P. Berrange" , Markus Armbruster , Steve Sistare Subject: [PATCH V1 15/26] physmem: hoist host memory allocation Date: Mon, 29 Apr 2024 08:55:24 -0700 Message-Id: <1714406135-451286-16-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> References: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-29_14,2024-04-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404290101 X-Proofpoint-ORIG-GUID: pMtKRFgkojj0wtNbTsvLIjG0hCQLLpL5 X-Proofpoint-GUID: pMtKRFgkojj0wtNbTsvLIjG0hCQLLpL5 Received-SPF: pass client-ip=205.220.177.32; envelope-from=steven.sistare@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Hoist host memory allocation from ram_block_add. No functional change. Signed-off-by: Steve Sistare --- system/physmem.c | 80 +++++++++++++++++++++++++------------------------------- 1 file changed, 36 insertions(+), 44 deletions(-) diff --git a/system/physmem.c b/system/physmem.c index ffcf012..b57462d 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -1825,44 +1825,40 @@ static void ram_block_destroy_guest_memfd(RAMBlock *rb) } } -static void ram_block_add(RAMBlock *new_block, Error **errp) +static void *ram_block_alloc_host(RAMBlock *rb, Error **errp) +{ + struct MemoryRegion *mr = rb->mr; + uint8_t *host = NULL; + + if (xen_enabled()) { + xen_ram_alloc(rb->offset, rb->max_length, mr, errp); + + } else { + host = qemu_anon_ram_alloc(rb->max_length, &mr->align, + qemu_ram_is_shared(rb), + qemu_ram_is_noreserve(rb)); + if (!host) { + error_setg_errno(errp, errno, "cannot set up guest memory '%s'", + rb->idstr); + } + } + + if (host) { + memory_try_enable_merging(host, rb->max_length); + } + return host; +} + +static void ram_block_add(RAMBlock *new_block) { - const bool noreserve = qemu_ram_is_noreserve(new_block); - const bool shared = qemu_ram_is_shared(new_block); RAMBlock *block; RAMBlock *last_block = NULL; ram_addr_t old_ram_size, new_ram_size; - Error *err = NULL; - old_ram_size = last_ram_page(); qemu_mutex_lock_ramlist(); new_block->offset = find_ram_offset(new_block->max_length); - if (!new_block->host) { - if (xen_enabled()) { - xen_ram_alloc(new_block->offset, new_block->max_length, - new_block->mr, &err); - if (err) { - error_propagate(errp, err); - qemu_mutex_unlock_ramlist(); - return; - } - } else { - new_block->host = qemu_anon_ram_alloc(new_block->max_length, - &new_block->mr->align, - shared, noreserve); - if (!new_block->host) { - error_setg_errno(errp, errno, - "cannot set up guest memory '%s'", - memory_region_name(new_block->mr)); - qemu_mutex_unlock_ramlist(); - return; - } - memory_try_enable_merging(new_block->host, new_block->max_length); - } - } - new_ram_size = MAX(old_ram_size, (new_block->offset + new_block->max_length) >> TARGET_PAGE_BITS); if (new_ram_size > old_ram_size) { @@ -1948,7 +1944,6 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, { void *host; RAMBlock *new_block; - Error *local_err = NULL; int64_t file_size, file_align; /* Just support these ram flags by now. */ @@ -1999,12 +1994,7 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, } new_block->host = host; - ram_block_add(new_block, &local_err); - if (local_err) { - g_free(new_block); - error_propagate(errp, local_err); - return NULL; - } + ram_block_add(new_block); return new_block; } @@ -2066,7 +2056,6 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size, MemoryRegion *mr, Error **errp) { RAMBlock *new_block; - Error *local_err = NULL; int align; assert((ram_flags & ~(RAM_SHARED | RAM_RESIZEABLE | RAM_PREALLOC | @@ -2084,14 +2073,17 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size, } new_block->resized = resized; - new_block->host = host; - ram_block_add(new_block, &local_err); - if (local_err) { - ram_block_destroy_guest_memfd(new_block); - g_free(new_block); - error_propagate(errp, local_err); - return NULL; + if (!host) { + host = ram_block_alloc_host(new_block, errp); + if (!host) { + ram_block_destroy_guest_memfd(new_block); + g_free(new_block); + return NULL; + } } + + new_block->host = host; + ram_block_add(new_block); return new_block; } From patchwork Mon Apr 29 15:55:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 13647321 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id CF833C4345F for ; Mon, 29 Apr 2024 15:57:53 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1TMm-0005OV-UY; Mon, 29 Apr 2024 11:56:32 -0400 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 1s1TML-0004bI-Uk for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:56:06 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s1TMJ-0005IG-Ra for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:56:05 -0400 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43TFmsuF024847; Mon, 29 Apr 2024 15:55:50 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=OyrHtB4q6XpnHj4/tkIq+24vCmQ0KEnKiUVp8HEQSEg=; b=RZFbV41TtymB0DJSa0KNlb8BXdfbfII7YxBXcGZrzPHbek5f1QIz0gA1IoZ08bE9hjre kARwfpzvsZSchwkaUgxxB6dFmfnUaPTMLsvgmefo+L3IVFIh4KC6Z8cXe0NorO60oTzu LrbeNVU+t+wrU9M0ylR+8uxQweKRXtD6nD91FBSER2VG+gc04ZV1+QSVIMEjgcB1N4Uj bOorxr3jbu1f+eObQM5D2fN/5Xw0dlhwyHr5Cknv8SRrReC2MtCfejdFA9l0K7gcqmJ6 +3HSvAyuDdb2jA4TzJVYKbe/Sm8U3xlLJDb9Ku47XzPwmvzRGB3MTgFTViPFpFR56ftq ww== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrqsetx43-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:49 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43TEcwOZ011335; Mon, 29 Apr 2024 15:55:48 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt6j6em-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:48 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43TFtaH0034442; Mon, 29 Apr 2024 15:55:48 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3xrqt6j5ys-17; Mon, 29 Apr 2024 15:55:48 +0000 From: Steve Sistare To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , David Hildenbrand , Igor Mammedov , Eduardo Habkost , Marcel Apfelbaum , Philippe Mathieu-Daude , Paolo Bonzini , "Daniel P. Berrange" , Markus Armbruster , Steve Sistare Subject: [PATCH V1 16/26] physmem: set ram block idstr earlier Date: Mon, 29 Apr 2024 08:55:25 -0700 Message-Id: <1714406135-451286-17-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> References: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-29_14,2024-04-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404290101 X-Proofpoint-ORIG-GUID: ezm-HSnNG4XBA-we7_0HH0YveZ9ZQI8i X-Proofpoint-GUID: ezm-HSnNG4XBA-we7_0HH0YveZ9ZQI8i Received-SPF: pass client-ip=205.220.177.32; envelope-from=steven.sistare@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Set the idstr for a ram block earlier, prior to calling ram_block_add, so it can be used in a subsequent patch to find CPR attributes for the block before it is created. The id depends on the block's device path and its mr. As as sanity check, verify that the id has not changed (due to these dependencies changing) by the time vmstate_register_ram is called (where the id was previously assigned). Signed-off-by: Steve Sistare --- include/exec/cpu-common.h | 3 +-- migration/savevm.c | 4 +--- system/physmem.c | 46 +++++++++++++++++++++++----------------------- 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index 6d53188..ffab5d9 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -82,8 +82,7 @@ RAMBlock *qemu_ram_block_by_name(const char *name); RAMBlock *qemu_ram_block_from_host(void *ptr, bool round_offset, ram_addr_t *offset); ram_addr_t qemu_ram_block_host_offset(RAMBlock *rb, void *host); -void qemu_ram_set_idstr(RAMBlock *block, const char *name, DeviceState *dev); -void qemu_ram_unset_idstr(RAMBlock *block); +void qemu_ram_verify_idstr(RAMBlock *block, DeviceState *dev); const char *qemu_ram_get_idstr(RAMBlock *rb); void *qemu_ram_get_host_addr(RAMBlock *rb); ram_addr_t qemu_ram_get_offset(RAMBlock *rb); diff --git a/migration/savevm.c b/migration/savevm.c index 01ed78c..8463ddf 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -3566,14 +3566,12 @@ bool delete_snapshot(const char *name, bool has_devices, void vmstate_register_ram(MemoryRegion *mr, DeviceState *dev) { - qemu_ram_set_idstr(mr->ram_block, - memory_region_name(mr), dev); + qemu_ram_verify_idstr(mr->ram_block, dev); qemu_ram_set_migratable(mr->ram_block); } void vmstate_unregister_ram(MemoryRegion *mr, DeviceState *dev) { - qemu_ram_unset_idstr(mr->ram_block); qemu_ram_unset_migratable(mr->ram_block); } diff --git a/system/physmem.c b/system/physmem.c index b57462d..c736af5 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -1597,35 +1597,20 @@ int qemu_ram_get_fd(RAMBlock *rb) } /* Called with the BQL held. */ -void qemu_ram_set_idstr(RAMBlock *new_block, const char *name, DeviceState *dev) +static void qemu_ram_set_idstr(char *idstr, MemoryRegion *mr, DeviceState *dev) { - RAMBlock *block; + const char *name = memory_region_name(mr); + g_autofree char *id = dev ? qdev_get_dev_path(dev) : NULL; - assert(new_block); - assert(!new_block->idstr[0]); - - if (dev) { - char *id = qdev_get_dev_path(dev); - if (id) { - snprintf(new_block->idstr, sizeof(new_block->idstr), "%s/", id); - g_free(id); - } - } - pstrcat(new_block->idstr, sizeof(new_block->idstr), name); - - RCU_READ_LOCK_GUARD(); - RAMBLOCK_FOREACH(block) { - if (block != new_block && - !strcmp(block->idstr, new_block->idstr)) { - fprintf(stderr, "RAMBlock \"%s\" already registered, abort!\n", - new_block->idstr); - abort(); - } + if (id) { + snprintf(idstr, sizeof(VMStateId), "%s/%s", id, name); + } else { + pstrcpy(idstr, sizeof(VMStateId), name); } } /* Called with the BQL held. */ -void qemu_ram_unset_idstr(RAMBlock *block) +static void qemu_ram_unset_idstr(RAMBlock *block) { /* FIXME: arch_init.c assumes that this is not called throughout * migration. Ignore the problem since hot-unplug during migration @@ -1636,6 +1621,13 @@ void qemu_ram_unset_idstr(RAMBlock *block) } } +void qemu_ram_verify_idstr(RAMBlock *new_block, DeviceState *dev) +{ + VMStateId idstr; + qemu_ram_set_idstr(idstr, new_block->mr, dev); + assert(!strcmp(new_block->idstr, idstr)); +} + size_t qemu_ram_pagesize(RAMBlock *rb) { return rb->page_size; @@ -1869,6 +1861,12 @@ static void ram_block_add(RAMBlock *new_block) * tail, so save the last element in last_block. */ RAMBLOCK_FOREACH(block) { + if (!strcmp(block->idstr, new_block->idstr)) { + fprintf(stderr, "RAMBlock \"%s\" already added, abort!\n", + new_block->idstr); + abort(); + } + last_block = block; if (block->max_length < new_block->max_length) { break; @@ -1915,6 +1913,7 @@ static RAMBlock *ram_block_create(MemoryRegion *mr, ram_addr_t size, { RAMBlock *rb = g_malloc0(sizeof(*rb)); + qemu_ram_set_idstr(rb->idstr, mr, mr->dev); rb->used_length = size; rb->max_length = max_size; rb->fd = -1; @@ -2142,6 +2141,7 @@ void qemu_ram_free(RAMBlock *block) } qemu_mutex_lock_ramlist(); + qemu_ram_unset_idstr(block); QLIST_REMOVE_RCU(block, next); ram_list.mru_block = NULL; /* Write list before version */ From patchwork Mon Apr 29 15:55:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 13647313 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id E19DBC04FFE for ; Mon, 29 Apr 2024 15:56:30 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1TMS-0004hB-8t; Mon, 29 Apr 2024 11:56:13 -0400 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 1s1TML-0004bH-Ut for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:56:06 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s1TMJ-0005IS-S7 for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:56:05 -0400 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43TFmtkg024859; Mon, 29 Apr 2024 15:55:50 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=OdRX+jRtvCW98UOUiTtcK+L9U7QTWnTC0birZ0CkFpo=; b=Pul2sqwYCFTihXbG5RSDBsfveEpdnEeGYu9jy+wXEjw7uw5f67hgvevBmeaXRyXzaxuG NGCPSBk8m9kVJHlaHXN8dgU2laXkgqxCP7aK5aOSs2Vfk+97i57ya8uQ1CTSMVMAhk4A iy+/OjE79LPaF4i4zUBowBojuBM4qoeGiyKzbR0mZd9u81qyQY8KvkfMp5pqXFAvzswA 1iH+Cg5ftu5eXG4CAVXgIIoi2leREabqzp9tJZvUzKQ+uaK02e+w0BhWy497jGdby4Tk r20aJJ7ycFDUBRdRHf38f6MKtBHfxxKd8+Vyk5zfE+i4e01bUQ1VrNeSjF9TFNnKvTae Cw== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrqsetx45-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:50 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43TFAtvA011379; Mon, 29 Apr 2024 15:55:49 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt6j6fq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:49 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43TFtaH2034442; Mon, 29 Apr 2024 15:55:48 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3xrqt6j5ys-18; Mon, 29 Apr 2024 15:55:48 +0000 From: Steve Sistare To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , David Hildenbrand , Igor Mammedov , Eduardo Habkost , Marcel Apfelbaum , Philippe Mathieu-Daude , Paolo Bonzini , "Daniel P. Berrange" , Markus Armbruster , Steve Sistare Subject: [PATCH V1 17/26] machine: memfd-alloc option Date: Mon, 29 Apr 2024 08:55:26 -0700 Message-Id: <1714406135-451286-18-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> References: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-29_14,2024-04-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404290101 X-Proofpoint-ORIG-GUID: XsjXw9QE5dA8AOJ-8O-ijpBV7uylLDNE X-Proofpoint-GUID: XsjXw9QE5dA8AOJ-8O-ijpBV7uylLDNE Received-SPF: pass client-ip=205.220.177.32; envelope-from=steven.sistare@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Allocate anonymous memory using memfd_create if the memfd-alloc machine option is set. Signed-off-by: Steve Sistare --- hw/core/machine.c | 22 ++++++++++++++++++++++ include/hw/boards.h | 1 + qemu-options.hx | 6 ++++++ system/memory.c | 9 ++++++--- system/physmem.c | 18 +++++++++++++++++- system/trace-events | 1 + 6 files changed, 53 insertions(+), 4 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 582c2df..9567b97 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -443,6 +443,20 @@ static void machine_set_mem_merge(Object *obj, bool value, Error **errp) ms->mem_merge = value; } +static bool machine_get_memfd_alloc(Object *obj, Error **errp) +{ + MachineState *ms = MACHINE(obj); + + return ms->memfd_alloc; +} + +static void machine_set_memfd_alloc(Object *obj, bool value, Error **errp) +{ + MachineState *ms = MACHINE(obj); + + ms->memfd_alloc = value; +} + static bool machine_get_usb(Object *obj, Error **errp) { MachineState *ms = MACHINE(obj); @@ -1044,6 +1058,11 @@ static void machine_class_init(ObjectClass *oc, void *data) object_class_property_set_description(oc, "mem-merge", "Enable/disable memory merge support"); + object_class_property_add_bool(oc, "memfd-alloc", + machine_get_memfd_alloc, machine_set_memfd_alloc); + object_class_property_set_description(oc, "memfd-alloc", + "Enable/disable allocating anonymous memory using memfd_create"); + object_class_property_add_bool(oc, "usb", machine_get_usb, machine_set_usb); object_class_property_set_description(oc, "usb", @@ -1387,6 +1406,9 @@ static bool create_default_memdev(MachineState *ms, const char *path, Error **er if (!object_property_set_int(obj, "size", ms->ram_size, errp)) { goto out; } + if (!object_property_set_bool(obj, "share", ms->memfd_alloc, errp)) { + goto out; + } object_property_add_child(object_get_objects_root(), mc->default_ram_id, obj); /* Ensure backend's memory region name is equal to mc->default_ram_id */ diff --git a/include/hw/boards.h b/include/hw/boards.h index 69c1ba4..96259c3 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -372,6 +372,7 @@ struct MachineState { bool dump_guest_core; bool mem_merge; bool require_guest_memfd; + bool memfd_alloc; bool usb; bool usb_disabled; char *firmware; diff --git a/qemu-options.hx b/qemu-options.hx index cf61f6b..f0dfda5 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -32,6 +32,7 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ " vmport=on|off|auto controls emulation of vmport (default: auto)\n" " dump-guest-core=on|off include guest memory in a core dump (default=on)\n" " mem-merge=on|off controls memory merge support (default: on)\n" + " memfd-alloc=on|off controls allocating anonymous guest RAM using memfd_create (default: off)\n" " aes-key-wrap=on|off controls support for AES key wrapping (default=on)\n" " dea-key-wrap=on|off controls support for DEA key wrapping (default=on)\n" " suppress-vmdesc=on|off disables self-describing migration (default=off)\n" @@ -79,6 +80,11 @@ SRST supported by the host, de-duplicates identical memory pages among VMs instances (enabled by default). + ``memfd-alloc=on|off`` + Enables or disables allocation of anonymous guest RAM using + memfd_create. Any associated memory-backend objects are created with + share=on. The memfd-alloc default is off. + ``aes-key-wrap=on|off`` Enables or disables AES key wrapping support on s390-ccw hosts. This feature controls whether AES wrapping keys will be created diff --git a/system/memory.c b/system/memory.c index 49f1cb2..ca04a0e 100644 --- a/system/memory.c +++ b/system/memory.c @@ -1552,8 +1552,9 @@ bool memory_region_init_ram_nomigrate(MemoryRegion *mr, uint64_t size, Error **errp) { + uint32_t flags = current_machine->memfd_alloc ? RAM_SHARED : 0; return memory_region_init_ram_flags_nomigrate(mr, owner, name, - size, 0, errp); + size, flags, errp); } bool memory_region_init_ram_flags_nomigrate(MemoryRegion *mr, @@ -1713,8 +1714,9 @@ bool memory_region_init_rom_nomigrate(MemoryRegion *mr, uint64_t size, Error **errp) { + uint32_t flags = current_machine->memfd_alloc ? RAM_SHARED : 0; if (!memory_region_init_ram_flags_nomigrate(mr, owner, name, - size, 0, errp)) { + size, flags, errp)) { return false; } mr->readonly = true; @@ -1731,6 +1733,7 @@ bool memory_region_init_rom_device_nomigrate(MemoryRegion *mr, Error **errp) { Error *err = NULL; + uint32_t flags = current_machine->memfd_alloc ? RAM_SHARED : 0; assert(ops); memory_region_init(mr, owner, name, size); mr->ops = ops; @@ -1738,7 +1741,7 @@ bool memory_region_init_rom_device_nomigrate(MemoryRegion *mr, mr->terminates = true; mr->rom_device = true; mr->destructor = memory_region_destructor_ram; - mr->ram_block = qemu_ram_alloc(size, 0, mr, &err); + mr->ram_block = qemu_ram_alloc(size, flags, mr, &err); if (err) { mr->size = int128_zero(); object_unparent(OBJECT(mr)); diff --git a/system/physmem.c b/system/physmem.c index c736af5..36d97ec 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -45,6 +45,7 @@ #include "qemu/qemu-print.h" #include "qemu/log.h" #include "qemu/memalign.h" +#include "qemu/memfd.h" #include "exec/memory.h" #include "exec/ioport.h" #include "sysemu/dma.h" @@ -1825,6 +1826,19 @@ static void *ram_block_alloc_host(RAMBlock *rb, Error **errp) if (xen_enabled()) { xen_ram_alloc(rb->offset, rb->max_length, mr, errp); + } else if (rb->flags & RAM_SHARED) { + if (rb->fd == -1) { + mr->align = QEMU_VMALLOC_ALIGN; + rb->fd = qemu_memfd_create(rb->idstr, rb->max_length + mr->align, + 0, 0, 0, errp); + } + if (rb->fd >= 0) { + int mfd = rb->fd; + qemu_set_cloexec(mfd); + host = file_ram_alloc(rb, rb->max_length, mfd, false, 0, errp); + trace_qemu_anon_memfd_alloc(rb->idstr, rb->max_length, mfd, host); + } + } else { host = qemu_anon_ram_alloc(rb->max_length, &mr->align, qemu_ram_is_shared(rb), @@ -2106,8 +2120,10 @@ RAMBlock *qemu_ram_alloc_resizeable(ram_addr_t size, ram_addr_t maxsz, void *host), MemoryRegion *mr, Error **errp) { + uint32_t flags = current_machine->memfd_alloc ? RAM_SHARED : 0; + flags |= RAM_RESIZEABLE; return qemu_ram_alloc_internal(size, maxsz, resized, NULL, - RAM_RESIZEABLE, mr, errp); + flags, mr, errp); } static void reclaim_ramblock(RAMBlock *block) diff --git a/system/trace-events b/system/trace-events index f0a80ba..0092734 100644 --- a/system/trace-events +++ b/system/trace-events @@ -41,3 +41,4 @@ dirtylimit_vcpu_execute(int cpu_index, int64_t sleep_time_us) "CPU[%d] sleep %"P # physmem.c ram_block_create(const char *name, uint32_t flags, int fd, size_t used_length, size_t max_length, size_t align) "%s, flags %u, fd %d, len %lu, maxlen %lu, align %lu" +qemu_anon_memfd_alloc(const char *name, size_t size, int fd, void *ptr) "%s size %zu fd %d -> %p" From patchwork Mon Apr 29 15:55:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 13647325 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id D2AB5C4345F for ; Mon, 29 Apr 2024 15:59:38 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1TMa-00052h-CY; Mon, 29 Apr 2024 11:56:20 -0400 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 1s1TMN-0004c0-60 for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:56:07 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s1TML-0005Ig-1C for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:56:06 -0400 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43TFmu7n024919; Mon, 29 Apr 2024 15:55:51 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=dFAAqcGLASWY0fwkl8wcUig8RTCMMJh3CTyJCKkbWEA=; b=YIelEe8WLbHOe2XpwaK3/if7mmGszxLh8Xjk7WViTNxijjHYDSVrTdGzpcPG/ink+3WA JPxDweByoRf/2oUh54cGOJHy7+Qn0KMgng7oPKlBJyRgkEbB8twi71dmzcn6UluwXhBz aEthyRV46gQrLV3UUY+2/V29jUXaw8AZE1fC/fWypo2m6WYJx9yFp51fBiKahaOehm0y WAHuFliypWhamSadAbTLrm7mwEWSqClHiSRECaonx6E8M0t00Dy5Lo4hHjtFKZA5xnqd o51I+PwvVZfdEdMNEdw1QE2yHyCKuWF3TFDVxS4qyYTR3BakHreFaqcnQ6e9dgWQU13q Fw== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrqsetx49-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:51 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43TFgaep011393; Mon, 29 Apr 2024 15:55:50 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt6j6gq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:50 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43TFtaH4034442; Mon, 29 Apr 2024 15:55:49 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3xrqt6j5ys-19; Mon, 29 Apr 2024 15:55:49 +0000 From: Steve Sistare To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , David Hildenbrand , Igor Mammedov , Eduardo Habkost , Marcel Apfelbaum , Philippe Mathieu-Daude , Paolo Bonzini , "Daniel P. Berrange" , Markus Armbruster , Steve Sistare Subject: [PATCH V1 18/26] migration: cpr-exec-args parameter Date: Mon, 29 Apr 2024 08:55:27 -0700 Message-Id: <1714406135-451286-19-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> References: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-29_14,2024-04-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404290101 X-Proofpoint-ORIG-GUID: _rEh2WqBWliGLL0O96WpdRoKN7qOMHQz X-Proofpoint-GUID: _rEh2WqBWliGLL0O96WpdRoKN7qOMHQz Received-SPF: pass client-ip=205.220.177.32; envelope-from=steven.sistare@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Create the cpr-exec-args migration parameter, defined as a list of strings. It will be used for cpr-exec migration mode in a subsequent patch. No functional change, except that cpr-exec-args is shown by the 'info migrate' command. Signed-off-by: Steve Sistare --- hmp-commands.hx | 2 +- migration/migration-hmp-cmds.c | 24 ++++++++++++++++++++++++ migration/options.c | 13 +++++++++++++ qapi/migration.json | 18 +++++++++++++++--- 4 files changed, 53 insertions(+), 4 deletions(-) diff --git a/hmp-commands.hx b/hmp-commands.hx index 2e2a3bc..39954ae 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1012,7 +1012,7 @@ ERST { .name = "migrate_set_parameter", - .args_type = "parameter:s,value:s", + .args_type = "parameter:s,value:S", .params = "parameter value", .help = "Set the parameter for migration", .cmd = hmp_migrate_set_parameter, diff --git a/migration/migration-hmp-cmds.c b/migration/migration-hmp-cmds.c index 7e96ae6..414c7e8 100644 --- a/migration/migration-hmp-cmds.c +++ b/migration/migration-hmp-cmds.c @@ -255,6 +255,18 @@ void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict) qapi_free_MigrationCapabilityStatusList(caps); } +static void monitor_print_cpr_exec_args(Monitor *mon, strList *args) +{ + monitor_printf(mon, "%s:", + MigrationParameter_str(MIGRATION_PARAMETER_CPR_EXEC_ARGS)); + + while (args) { + monitor_printf(mon, " %s", args->value); + args = args->next; + } + monitor_printf(mon, "\n"); +} + void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict) { MigrationParameters *params; @@ -397,6 +409,8 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict) monitor_printf(mon, "%s: %s\n", MigrationParameter_str(MIGRATION_PARAMETER_MODE), qapi_enum_lookup(&MigMode_lookup, params->mode)); + assert(params->has_cpr_exec_args); + monitor_print_cpr_exec_args(mon, params->cpr_exec_args); } qapi_free_MigrationParameters(params); @@ -690,6 +704,16 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) p->has_mode = true; visit_type_MigMode(v, param, &p->mode, &err); break; + case MIGRATION_PARAMETER_CPR_EXEC_ARGS: { + g_autofree char **strv = g_strsplit(valuestr ?: "", " ", -1); + strList **tail = &p->cpr_exec_args; + + for (int i = 0; strv[i]; i++) { + QAPI_LIST_APPEND(tail, strv[i]); + } + p->has_cpr_exec_args = true; + break; + } default: assert(0); } diff --git a/migration/options.c b/migration/options.c index 239f5ec..89082cc 100644 --- a/migration/options.c +++ b/migration/options.c @@ -1060,6 +1060,8 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp) params->mode = s->parameters.mode; params->has_zero_page_detection = true; params->zero_page_detection = s->parameters.zero_page_detection; + params->has_cpr_exec_args = true; + params->cpr_exec_args = QAPI_CLONE(strList, s->parameters.cpr_exec_args); return params; } @@ -1097,6 +1099,7 @@ void migrate_params_init(MigrationParameters *params) params->has_vcpu_dirty_limit = true; params->has_mode = true; params->has_zero_page_detection = true; + params->has_cpr_exec_args = true; } /* @@ -1416,6 +1419,10 @@ static void migrate_params_test_apply(MigrateSetParameters *params, if (params->has_zero_page_detection) { dest->zero_page_detection = params->zero_page_detection; } + + if (params->has_cpr_exec_args) { + dest->cpr_exec_args = params->cpr_exec_args; + } } static void migrate_params_apply(MigrateSetParameters *params, Error **errp) @@ -1570,6 +1577,12 @@ static void migrate_params_apply(MigrateSetParameters *params, Error **errp) if (params->has_zero_page_detection) { s->parameters.zero_page_detection = params->zero_page_detection; } + + if (params->has_cpr_exec_args) { + qapi_free_strList(s->parameters.cpr_exec_args); + s->parameters.cpr_exec_args = + QAPI_CLONE(strList, params->cpr_exec_args); + } } void qmp_migrate_set_parameters(MigrateSetParameters *params, Error **errp) diff --git a/qapi/migration.json b/qapi/migration.json index 8c65b90..49710e7 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -914,6 +914,9 @@ # See description in @ZeroPageDetection. Default is 'multifd'. # (since 9.0) # +# @cpr-exec-args: Arguments passed to new QEMU for @cpr-exec mode. +# See @cpr-exec for details. (Since 9.1) +# # Features: # # @deprecated: Member @block-incremental is deprecated. Use @@ -948,7 +951,8 @@ { 'name': 'x-vcpu-dirty-limit-period', 'features': ['unstable'] }, 'vcpu-dirty-limit', 'mode', - 'zero-page-detection'] } + 'zero-page-detection', + 'cpr-exec-args'] } ## # @MigrateSetParameters: @@ -1122,6 +1126,9 @@ # See description in @ZeroPageDetection. Default is 'multifd'. # (since 9.0) # +# @cpr-exec-args: Arguments passed to new QEMU for @cpr-exec mode. +# See @cpr-exec for details. (Since 9.1) +# # Features: # # @deprecated: Member @block-incremental is deprecated. Use @@ -1176,7 +1183,8 @@ 'features': [ 'unstable' ] }, '*vcpu-dirty-limit': 'uint64', '*mode': 'MigMode', - '*zero-page-detection': 'ZeroPageDetection'} } + '*zero-page-detection': 'ZeroPageDetection', + '*cpr-exec-args': [ 'str' ]} } ## # @migrate-set-parameters: @@ -1354,6 +1362,9 @@ # See description in @ZeroPageDetection. Default is 'multifd'. # (since 9.0) # +# @cpr-exec-args: Arguments passed to new QEMU for @cpr-exec mode. +# See @cpr-exec for details. (Since 9.1) +# # Features: # # @deprecated: Member @block-incremental is deprecated. Use @@ -1405,7 +1416,8 @@ 'features': [ 'unstable' ] }, '*vcpu-dirty-limit': 'uint64', '*mode': 'MigMode', - '*zero-page-detection': 'ZeroPageDetection'} } + '*zero-page-detection': 'ZeroPageDetection', + '*cpr-exec-args': [ 'str' ]} } ## # @query-migrate-parameters: From patchwork Mon Apr 29 15:55:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 13647335 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id A8E3BC4345F for ; Mon, 29 Apr 2024 16:06:10 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1TMV-0004oZ-5B; Mon, 29 Apr 2024 11:56:15 -0400 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 1s1TMN-0004c5-Dg for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:56:07 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s1TML-0005Io-Bk for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:56:07 -0400 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43TFmuqt024941; Mon, 29 Apr 2024 15:55:52 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=fLoc8RsqqC4/VvEU3N//EHt3MAKOJS/axPmHtsZ0S2I=; b=LKS6ViAh+M0O36nGKTlxhC4JVUgjUzJEamKT++giIj4LCE+kykzjXSZpxKZIHq0A/c4l cxuS0YHwaRaURMsuTT9x/VzpQl/RS6g4ymyiMLYbm1s2t1mdyRmFJgLFa0ETLlBOn/WV MuQOFIem3p3sRzdTreGuKJDntHuzTPFe7WiuccruIwtg0fw9crBZYKPGy/J4syuhk7yV n8C0+gRx8fiusjYhom7SRZm3NfvFP+vGMo84tZZT+R6tfFcJdoxBFiTWludtJu1W7Uq+ UJuwhHy9sE7/kAUYNFKOR8FKdtGzgPBKIohlwh3DQDwzCyZf2YKbhwlni08WregQCYoD jQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrqsetx4d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:52 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43TF0rU7011374; Mon, 29 Apr 2024 15:55:51 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt6j6hj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:51 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43TFtaH6034442; Mon, 29 Apr 2024 15:55:50 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3xrqt6j5ys-20; Mon, 29 Apr 2024 15:55:50 +0000 From: Steve Sistare To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , David Hildenbrand , Igor Mammedov , Eduardo Habkost , Marcel Apfelbaum , Philippe Mathieu-Daude , Paolo Bonzini , "Daniel P. Berrange" , Markus Armbruster , Steve Sistare Subject: [PATCH V1 19/26] physmem: preserve ram blocks for cpr Date: Mon, 29 Apr 2024 08:55:28 -0700 Message-Id: <1714406135-451286-20-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> References: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-29_14,2024-04-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404290101 X-Proofpoint-ORIG-GUID: w77k14UptVokYNFo1CGRDQLveHdVRrra X-Proofpoint-GUID: w77k14UptVokYNFo1CGRDQLveHdVRrra Received-SPF: pass client-ip=205.220.177.32; envelope-from=steven.sistare@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Preserve fields of RAMBlocks that allocate their host memory during CPR so the RAM allocation can be recovered. Mirror the mr->align field in the RAMBlock to simplify the vmstate. Preserve the old host address, even though it is immediately discarded, as it will be needed in the future for CPR with iommufd. Preserve guest_memfd, even though CPR does not yet support it, to maintain vmstate compatibility when it becomes supported. Signed-off-by: Steve Sistare --- include/exec/ramblock.h | 6 ++++++ system/physmem.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/include/exec/ramblock.h b/include/exec/ramblock.h index 61deefe..b492d89 100644 --- a/include/exec/ramblock.h +++ b/include/exec/ramblock.h @@ -44,6 +44,7 @@ struct RAMBlock { uint64_t fd_offset; int guest_memfd; size_t page_size; + uint64_t align; /* dirty bitmap used during migration */ unsigned long *bmap; @@ -91,5 +92,10 @@ struct RAMBlock { */ ram_addr_t postcopy_length; }; + +#define RAM_BLOCK "RAMBlock" + +extern const VMStateDescription vmstate_ram_block; + #endif #endif diff --git a/system/physmem.c b/system/physmem.c index 36d97ec..3019284 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -1398,6 +1398,7 @@ static void *file_ram_alloc(RAMBlock *block, block->mr->align = MAX(block->mr->align, QEMU_VMALLOC_ALIGN); } #endif + block->align = block->mr->align; if (memory < block->page_size) { error_setg(errp, "memory size 0x" RAM_ADDR_FMT " must be equal to " @@ -1848,6 +1849,7 @@ static void *ram_block_alloc_host(RAMBlock *rb, Error **errp) rb->idstr); } } + rb->align = mr->align; if (host) { memory_try_enable_merging(host, rb->max_length); @@ -1934,6 +1936,7 @@ static RAMBlock *ram_block_create(MemoryRegion *mr, ram_addr_t size, rb->flags = ram_flags; rb->page_size = qemu_real_host_page_size(); rb->mr = mr; + rb->align = mr->align; if (ram_flags & RAM_GUEST_MEMFD) { rb->guest_memfd = ram_block_create_guest_memfd(rb, errp); @@ -2060,6 +2063,26 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, } #endif +const VMStateDescription vmstate_ram_block = { + .name = RAM_BLOCK, + .version_id = 1, + .minimum_version_id = 1, + .precreate = true, + .factory = true, + .fields = (VMStateField[]) { + VMSTATE_UINT64(align, RAMBlock), + VMSTATE_VOID_PTR(host, RAMBlock), + VMSTATE_INT32(fd, RAMBlock), + VMSTATE_INT32(guest_memfd, RAMBlock), + VMSTATE_UINT32(flags, RAMBlock), + VMSTATE_UINT64(used_length, RAMBlock), + VMSTATE_UINT64(max_length, RAMBlock), + VMSTATE_END_OF_LIST() + } +}; + +vmstate_register_init_factory(vmstate_ram_block, RAMBlock); + static RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size, void (*resized)(const char*, @@ -2070,6 +2093,7 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size, { RAMBlock *new_block; int align; + g_autofree RAMBlock *preserved = NULL; assert((ram_flags & ~(RAM_SHARED | RAM_RESIZEABLE | RAM_PREALLOC | RAM_NORESERVE | RAM_GUEST_MEMFD)) == 0); @@ -2086,6 +2110,17 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size, } new_block->resized = resized; + preserved = vmstate_claim_factory_object(RAM_BLOCK, new_block->idstr, 0); + if (preserved) { + assert(mr->align <= preserved->align); + mr->align = mr->align ?: preserved->align; + new_block->align = preserved->align; + new_block->fd = preserved->fd; + new_block->flags = preserved->flags; + new_block->used_length = preserved->used_length; + new_block->max_length = preserved->max_length; + } + if (!host) { host = ram_block_alloc_host(new_block, errp); if (!host) { @@ -2093,6 +2128,10 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size, g_free(new_block); return NULL; } + if (!(ram_flags & RAM_GUEST_MEMFD)) { + vmstate_register_named(new_block->idstr, 0, &vmstate_ram_block, + new_block); + } } new_block->host = host; @@ -2157,6 +2196,7 @@ void qemu_ram_free(RAMBlock *block) } qemu_mutex_lock_ramlist(); + vmstate_unregister_named(RAM_BLOCK, block->idstr, 0); qemu_ram_unset_idstr(block); QLIST_REMOVE_RCU(block, next); ram_list.mru_block = NULL; From patchwork Mon Apr 29 15:55:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 13647322 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 85F2EC04FFE for ; Mon, 29 Apr 2024 15:57:56 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1TMn-0005Tf-UL; Mon, 29 Apr 2024 11:56:33 -0400 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 1s1TMT-0004iM-Bv for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:56:13 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s1TML-0005JH-9v for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:56:13 -0400 Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43TFmj9M006699; Mon, 29 Apr 2024 15:55:53 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=GpsDXkwU42jBrI4A7QnchPbVZI0PhZ5nHsXDpLdTUlY=; b=m72lAlHbkrT4D8LD6/lkKWjIetDsJxPlS7sqjbKdbwTYRpw1U+Jr8XuqEymR0Fxm6xoh jkHjdvOxdp/X1Yg7tFOC+hEBbTbdyBPDqWdUae/uts2nxVRt1nVXKwIgXy8NLI9dP3Tq DyxOpFgubNcCE6gleR0q5IMO25wezmQbO/qh6gOo/pEJ/MU/hmyOkFKfcR8zN+Pdycnw zCODXVDwSK4ESTIY8n56PdO7SzfAAbmaB28F+pfk6aQV3lZVG2PP091lOYezqEb0B/3d KgBzXE7VpG6/FKCihEUv77qlN1QgB4ndzl/9knCI+uaneyiwgwbhjDtpUj5DBGwTRGWf tQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrsdejwnn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:52 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43TFgaer011393; Mon, 29 Apr 2024 15:55:51 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt6j6j9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:51 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43TFtaH8034442; Mon, 29 Apr 2024 15:55:51 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3xrqt6j5ys-21; Mon, 29 Apr 2024 15:55:51 +0000 From: Steve Sistare To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , David Hildenbrand , Igor Mammedov , Eduardo Habkost , Marcel Apfelbaum , Philippe Mathieu-Daude , Paolo Bonzini , "Daniel P. Berrange" , Markus Armbruster , Steve Sistare Subject: [PATCH V1 20/26] migration: cpr-exec mode Date: Mon, 29 Apr 2024 08:55:29 -0700 Message-Id: <1714406135-451286-21-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> References: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-29_14,2024-04-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404290101 X-Proofpoint-GUID: F7RgHGRfLXEparyz_Qa0jv4G3uuqoDYv X-Proofpoint-ORIG-GUID: F7RgHGRfLXEparyz_Qa0jv4G3uuqoDYv Received-SPF: pass client-ip=205.220.177.32; envelope-from=steven.sistare@oracle.com; helo=mx0b-00069f02.pphosted.com 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, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Add the cpr-exec migration mode. Usage: qemu-system-$arch -machine memfd-alloc=on ... migrate_set_parameter mode cpr-exec migrate_set_parameter cpr-exec-args \ ... -incoming migrate -d The migrate command stops the VM, saves state to the URI, directly exec's a new version of QEMU on the same host, replacing the original process while retaining its PID, and loads state from the URI. Guest RAM is preserved in place, albeit with new virtual addresses. Arguments for the new QEMU process are taken from the @cpr-exec-args parameter. The first argument should be the path of a new QEMU binary, or a prefix command that exec's the new QEMU binary. Because old QEMU terminates when new QEMU starts, one cannot stream data between the two, so the URI must be a type, such as a file, that reads all data before old QEMU exits. Memory backend objects must have the share=on attribute, and must be mmap'able in the new QEMU process. For example, memory-backend-file is acceptable, but memory-backend-ram is not. The VM must be started with the '-machine memfd-alloc=on' option. This causes implicit ram blocks (those not explicitly described by a memory-backend object) to be allocated by mmap'ing a memfd. Examples include VGA, ROM, and even guest RAM when it is specified without a memory-backend object. The implementation saves precreate vmstate at the end of normal migration in migrate_fd_cleanup, and tells the main loop to call cpr_exec. Incoming qemu loads preceate state early, before objects are created. The memfds are kept open across exec by clearing the close-on-exec flag, their values are saved in precreate vmstate, and they are mmap'd in new qemu. Note that the memfd-alloc option is not related to memory-backend-memfd. Later patches add support for memory-backend-memfd, and for additional devices, including vfio, chardev, and more. Signed-off-by: Steve Sistare --- include/migration/cpr.h | 14 +++++ include/migration/misc.h | 3 ++ migration/cpr.c | 131 +++++++++++++++++++++++++++++++++++++++++++++++ migration/meson.build | 1 + migration/migration.c | 21 ++++++++ migration/migration.h | 5 +- migration/ram.c | 1 + qapi/migration.json | 30 ++++++++++- system/physmem.c | 2 + system/vl.c | 4 ++ 10 files changed, 210 insertions(+), 2 deletions(-) create mode 100644 include/migration/cpr.h create mode 100644 migration/cpr.c diff --git a/include/migration/cpr.h b/include/migration/cpr.h new file mode 100644 index 0000000..aa8316d --- /dev/null +++ b/include/migration/cpr.h @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2021, 2024 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#ifndef MIGRATION_CPR_H +#define MIGRATION_CPR_H + +bool cpr_needed_for_exec(void *opaque); +void cpr_unpreserve_fds(void); + +#endif diff --git a/include/migration/misc.h b/include/migration/misc.h index cf30351..5b963ba 100644 --- a/include/migration/misc.h +++ b/include/migration/misc.h @@ -122,4 +122,7 @@ bool migration_in_bg_snapshot(void); /* migration/block-dirty-bitmap.c */ void dirty_bitmap_mig_init(void); +/* migration/cpr.c */ +void cpr_exec(char **argv); + #endif diff --git a/migration/cpr.c b/migration/cpr.c new file mode 100644 index 0000000..d4703e1 --- /dev/null +++ b/migration/cpr.c @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2021-2024 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "exec/ramblock.h" +#include "migration/cpr.h" +#include "migration/migration.h" +#include "migration/misc.h" +#include "migration/vmstate.h" +#include "sysemu/runstate.h" +#include "trace.h" + +/*************************************************************************/ +#define CPR_STATE "CprState" + +typedef struct CprState { + MigMode mode; +} CprState; + +static CprState cpr_state = { + .mode = MIG_MODE_NORMAL, +}; + +static int cpr_state_presave(void *opaque) +{ + cpr_state.mode = migrate_mode(); + return 0; +} + +bool cpr_needed_for_exec(void *opaque) +{ + return migrate_mode() == MIG_MODE_CPR_EXEC; +} + +static const VMStateDescription vmstate_cpr_state = { + .name = CPR_STATE, + .version_id = 1, + .minimum_version_id = 1, + .needed = cpr_needed_for_exec, + .pre_save = cpr_state_presave, + .precreate = true, + .fields = (VMStateField[]) { + VMSTATE_UINT32(mode, CprState), + VMSTATE_END_OF_LIST() + } +}; + +vmstate_register_init(NULL, 0, vmstate_cpr_state, &cpr_state); + +/*************************************************************************/ + +typedef int (*cpr_walk_fd_cb)(int fd); + +static int walk_ramblock(FactoryObject *obj, void *opaque) +{ + RAMBlock *rb = obj->opaque; + cpr_walk_fd_cb cb = opaque; + return cb(rb->fd); +} + +static int cpr_walk_fd(cpr_walk_fd_cb cb) +{ + int ret = vmstate_walk_factory_outgoing(RAM_BLOCK, walk_ramblock, cb); + return ret; +} + +static int preserve_fd(int fd) +{ + qemu_clear_cloexec(fd); + return 0; +} + +static int unpreserve_fd(int fd) +{ + qemu_set_cloexec(fd); + return 0; +} + +static void cpr_preserve_fds(void) +{ + cpr_walk_fd(preserve_fd); +} + +void cpr_unpreserve_fds(void) +{ + cpr_walk_fd(unpreserve_fd); +} + +static int cpr_fd_notifier_func(NotifierWithReturn *notifier, + MigrationEvent *e, Error **errp) +{ + if (migrate_mode() == MIG_MODE_CPR_EXEC && + e->type == MIG_EVENT_PRECOPY_FAILED) { + cpr_unpreserve_fds(); + } + return 0; +} + +void cpr_mig_init(void) +{ + static NotifierWithReturn cpr_fd_notifier; + + migrate_get_current()->parameters.mode = cpr_state.mode; + migration_add_notifier(&cpr_fd_notifier, cpr_fd_notifier_func); +} + +void cpr_exec(char **argv) +{ + MigrationState *s = migrate_get_current(); + Error *err = NULL; + + /* + * Clear the close-on-exec flag for all preserved fd's. We cannot do so + * earlier because they should not persist across miscellaneous fork and + * exec calls that are performed during normal operation. + */ + cpr_preserve_fds(); + + execvp(argv[0], argv); + + error_setg_errno(&err, errno, "execvp %s failed", argv[0]); + error_report_err(err); + migrate_set_state(&s->state, s->state, MIGRATION_STATUS_FAILED); + migrate_set_error(s, err); + migration_precreate_unsave(); +} diff --git a/migration/meson.build b/migration/meson.build index e667b40..d9e9c60 100644 --- a/migration/meson.build +++ b/migration/meson.build @@ -14,6 +14,7 @@ system_ss.add(files( 'block-dirty-bitmap.c', 'channel.c', 'channel-block.c', + 'cpr.c', 'dirtyrate.c', 'exec.c', 'fd.c', diff --git a/migration/migration.c b/migration/migration.c index b5af6b5..0d91531 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -239,6 +239,7 @@ void migration_object_init(void) blk_mig_init(); ram_mig_init(); dirty_bitmap_mig_init(); + cpr_mig_init(); } typedef struct { @@ -1395,6 +1396,15 @@ static void migrate_fd_cleanup(MigrationState *s) qemu_fclose(tmp); } + if (migrate_mode() == MIG_MODE_CPR_EXEC) { + Error *err = NULL; + if (migration_precreate_save(&err)) { + migrate_set_error(s, err); + error_report_err(err); + migrate_set_state(&s->state, s->state, MIGRATION_STATUS_FAILED); + } + } + assert(!migration_is_active()); if (s->state == MIGRATION_STATUS_CANCELLING) { @@ -1410,6 +1420,11 @@ static void migrate_fd_cleanup(MigrationState *s) MIG_EVENT_PRECOPY_DONE; migration_call_notifiers(s, type, NULL); block_cleanup_parameters(); + + if (migrate_mode() == MIG_MODE_CPR_EXEC && !migration_has_failed(s)) { + assert(s->state == MIGRATION_STATUS_COMPLETED); + qemu_system_exec_request(cpr_exec, s->parameters.cpr_exec_args); + } yank_unregister_instance(MIGRATION_YANK_INSTANCE); } @@ -1977,6 +1992,12 @@ static bool migrate_prepare(MigrationState *s, bool blk, bool blk_inc, return false; } + if (migrate_mode() == MIG_MODE_CPR_EXEC && + !s->parameters.has_cpr_exec_args) { + error_setg(errp, "cpr-exec mode requires setting cpr-exec-args"); + return false; + } + if (migration_is_blocked(errp)) { return false; } diff --git a/migration/migration.h b/migration/migration.h index 8045e39..2ad2163 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -490,7 +490,6 @@ bool migration_in_postcopy(void); bool migration_postcopy_is_alive(int state); MigrationState *migrate_get_current(void); bool migration_has_failed(MigrationState *); -bool migrate_mode_is_cpr(MigrationState *); uint64_t ram_get_total_transferred_pages(void); @@ -544,4 +543,8 @@ int migration_rp_wait(MigrationState *s); */ void migration_rp_kick(MigrationState *s); +/* CPR */ +bool migrate_mode_is_cpr(MigrationState *); +void cpr_mig_init(void); + #endif diff --git a/migration/ram.c b/migration/ram.c index a975c5a..add285b 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -219,6 +219,7 @@ static bool postcopy_preempt_active(void) bool migrate_ram_is_ignored(RAMBlock *block) { return !qemu_ram_is_migratable(block) || + migrate_mode() == MIG_MODE_CPR_EXEC || (migrate_ignore_shared() && qemu_ram_is_shared(block) && qemu_ram_is_named_file(block)); } diff --git a/qapi/migration.json b/qapi/migration.json index 49710e7..7c5f45f 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -665,9 +665,37 @@ # or COLO. # # (since 8.2) +# +# @cpr-exec: The migrate command stops the VM, saves state to the URI, +# directly exec's a new version of QEMU on the same host, +# replacing the original process while retaining its PID, and +# loads state from the URI. Guest RAM is preserved in place, +# albeit with new virtual addresses. +# +# Arguments for the new QEMU process are taken from the +# @cpr-exec-args parameter. The first argument should be the +# path of a new QEMU binary, or a prefix command that exec's the +# new QEMU binary. +# +# Because old QEMU terminates when new QEMU starts, one cannot +# stream data between the two, so the URI must be a type, such as +# a file, that reads all data before old QEMU exits. +# +# Memory backend objects must have the share=on attribute, and +# must be mmap'able in the new QEMU process. For example, +# memory-backend-file is acceptable, but memory-backend-ram is +# not. +# +# The VM must be started with the '-machine memfd-alloc=on' +# option. This causes implicit ram blocks -- those not explicitly +# described by a memory-backend object -- to be allocated by +# mmap'ing a memfd. Examples include VGA, ROM, and even guest +# RAM when it is specified without a memory-backend object. +# +# (since 9.1) ## { 'enum': 'MigMode', - 'data': [ 'normal', 'cpr-reboot' ] } + 'data': [ 'normal', 'cpr-reboot', 'cpr-exec' ] } ## # @ZeroPageDetection: diff --git a/system/physmem.c b/system/physmem.c index 3019284..87ad441 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -69,6 +69,7 @@ #include "qemu/pmem.h" +#include "migration/cpr.h" #include "migration/vmstate.h" #include "qemu/range.h" @@ -2069,6 +2070,7 @@ const VMStateDescription vmstate_ram_block = { .minimum_version_id = 1, .precreate = true, .factory = true, + .needed = cpr_needed_for_exec, .fields = (VMStateField[]) { VMSTATE_UINT64(align, RAMBlock), VMSTATE_VOID_PTR(host, RAMBlock), diff --git a/system/vl.c b/system/vl.c index 7797206..7252100 100644 --- a/system/vl.c +++ b/system/vl.c @@ -76,6 +76,7 @@ #include "hw/block/block.h" #include "hw/i386/x86.h" #include "hw/i386/pc.h" +#include "migration/cpr.h" #include "migration/misc.h" #include "migration/snapshot.h" #include "migration/vmstate.h" @@ -3665,6 +3666,9 @@ void qemu_init(int argc, char **argv) qemu_create_machine(machine_opts_dict); vmstate_register_init_all(); + migration_precreate_load(&error_fatal); + /* Set cloexec to prevent fd leaks from fork until the next cpr-exec */ + cpr_unpreserve_fds(); suspend_mux_open(); From patchwork Mon Apr 29 15:55:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 13647338 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 7BE35C19F53 for ; Mon, 29 Apr 2024 16:06:11 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1TMW-0004ra-0p; Mon, 29 Apr 2024 11:56:16 -0400 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 1s1TMO-0004cz-NW for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:56:08 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s1TMN-0005Jt-3K for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:56:08 -0400 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43TFmsuG024847; Mon, 29 Apr 2024 15:55:54 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=AI42jKlapaNWs243JK/hObQrllWrnyUcajeE/W738TA=; b=FcJS/OuKbUH3kfJcEpWklLhtGQ6m3F1aWB+Fjr2vFGR/kfGL4WF64BH8W1PJo+IIiZS/ wB9JnBCnkSlaCGCLg3eeL4e2C7aNiZ5m8MUc7+ZOS1t7etRtkuNEMdw1VK2BJbT2AwEI ZPEGQbbmJDUD5YH2BAjLmDX7MPT/zSU33FiweNH4pk3UMhdKck+48B8OQxwmU4IqYoaZ zxKX+3aSN3VlQ2FM2YcydPAUjBgyAhVcNRhrUNoosaWKj5pG1vuOXAhUDxd5hYaP4coa hhNfwF/PHEXUaN7JEF50zMVoUOb1hgRWL8ThQ27u6v/tporiV24YPss5uBemxUzrQ/5c vw== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrqsetx4g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:53 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43TF0EUY011367; Mon, 29 Apr 2024 15:55:52 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt6j6kd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:52 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43TFtaHA034442; Mon, 29 Apr 2024 15:55:52 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3xrqt6j5ys-22; Mon, 29 Apr 2024 15:55:51 +0000 From: Steve Sistare To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , David Hildenbrand , Igor Mammedov , Eduardo Habkost , Marcel Apfelbaum , Philippe Mathieu-Daude , Paolo Bonzini , "Daniel P. Berrange" , Markus Armbruster , Steve Sistare Subject: [PATCH V1 21/26] migration: migrate_add_blocker_mode Date: Mon, 29 Apr 2024 08:55:30 -0700 Message-Id: <1714406135-451286-22-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> References: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-29_14,2024-04-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404290101 X-Proofpoint-ORIG-GUID: EIKLcuWjtaMHIii8TcXTb450Qi-Ljg7- X-Proofpoint-GUID: EIKLcuWjtaMHIii8TcXTb450Qi-Ljg7- Received-SPF: pass client-ip=205.220.177.32; envelope-from=steven.sistare@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Define a convenience function to add a migration blocker for a single mode. Signed-off-by: Steve Sistare Reviewed-by: Fabiano Rosas --- include/migration/blocker.h | 7 +++++++ migration/migration.c | 5 +++++ stubs/migr-blocker.c | 5 +++++ 3 files changed, 17 insertions(+) diff --git a/include/migration/blocker.h b/include/migration/blocker.h index a687ac0..5c2e5d4 100644 --- a/include/migration/blocker.h +++ b/include/migration/blocker.h @@ -94,4 +94,11 @@ int migrate_add_blocker_normal(Error **reasonp, Error **errp); */ int migrate_add_blocker_modes(Error **reasonp, Error **errp, MigMode mode, ...); +/** + * @migrate_add_blocker_mode - prevent a mode of migration from proceeding + * + * Like migrate_add_blocker_modes, but for a single mode. + */ +int migrate_add_blocker_mode(Error **reasonp, MigMode mode, Error **errp); + #endif diff --git a/migration/migration.c b/migration/migration.c index 0d91531..4984dee 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1769,6 +1769,11 @@ int migrate_add_blocker_normal(Error **reasonp, Error **errp) return migrate_add_blocker_modes(reasonp, errp, MIG_MODE_NORMAL, -1); } +int migrate_add_blocker_mode(Error **reasonp, MigMode mode, Error **errp) +{ + return migrate_add_blocker_modes(reasonp, errp, mode, -1); +} + int migrate_add_blocker_modes(Error **reasonp, Error **errp, MigMode mode, ...) { int modes; diff --git a/stubs/migr-blocker.c b/stubs/migr-blocker.c index 11cbff2..150eb62 100644 --- a/stubs/migr-blocker.c +++ b/stubs/migr-blocker.c @@ -16,6 +16,11 @@ int migrate_add_blocker_modes(Error **reasonp, Error **errp, MigMode mode, ...) return 0; } +int migrate_add_blocker_mode(Error **reasonp, MigMode mode, Error **errp) +{ + return 0; +} + void migrate_del_blocker(Error **reasonp) { } From patchwork Mon Apr 29 15:55:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 13647323 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 7C906C04FFE for ; Mon, 29 Apr 2024 15:58:48 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1TMM-0004bw-ME; Mon, 29 Apr 2024 11:56:06 -0400 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 1s1TMG-0004XK-IV for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:56:00 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s1TME-0005KG-Ma for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:56:00 -0400 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43TFnZ1C028117; Mon, 29 Apr 2024 15:55:54 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=JnHkPIVQqTLNiTwWrVL5qrGRdbPYqitNd1sfXn89xic=; b=BcUp/ltegDdnTi8MOxY7B4v81QbQO00rQU8z0N/e0kLQj4C6HshcMcXWyP0ufHAIe5S8 SU5wupBROE6nvltCAMPLp6llG/XVb7HreR06NcOP4kW2MVuh2i0aRtxBMtJTs3Y9Gy+U Ne0mrDf9PQR9dw93SXtAMJ4Fo/scoXkelQPlv4O4w8LUkuAuc5a9CdjWDpK9w3xqXQFB orJSDD4miq/PhrXKJcuc2B0u1gVohg85pxSpuAC7Y55hYUy5SR2AZTTRRVE+e1tbYiNe WwT9W0FLluRpBYH1XI+7jC+9dnnlTNnK7Y33/BnN6JHaeZXwH4ceByeq3lxfEhrXzdYl uQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrswvjxs6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:54 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43TEgDmZ011440; Mon, 29 Apr 2024 15:55:53 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt6j6ku-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:53 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43TFtaHC034442; Mon, 29 Apr 2024 15:55:52 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3xrqt6j5ys-23; Mon, 29 Apr 2024 15:55:52 +0000 From: Steve Sistare To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , David Hildenbrand , Igor Mammedov , Eduardo Habkost , Marcel Apfelbaum , Philippe Mathieu-Daude , Paolo Bonzini , "Daniel P. Berrange" , Markus Armbruster , Steve Sistare Subject: [PATCH V1 22/26] migration: ram block cpr-exec blockers Date: Mon, 29 Apr 2024 08:55:31 -0700 Message-Id: <1714406135-451286-23-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> References: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-29_14,2024-04-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404290101 X-Proofpoint-GUID: j9AmfYAvp19a7BCtisg125IWA-jMyWpt X-Proofpoint-ORIG-GUID: j9AmfYAvp19a7BCtisg125IWA-jMyWpt Received-SPF: pass client-ip=205.220.165.32; envelope-from=steven.sistare@oracle.com; helo=mx0a-00069f02.pphosted.com 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, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Unlike cpr-reboot mode, cpr-exec mode cannot save volatile ram blocks in the migration stream file and recreate them later, because the physical memory for the blocks is pinned and registered for vfio. Add an exec-mode blocker for volatile ram blocks. Also add a blocker for RAM_GUEST_MEMFD. Preserving guest_memfd may be sufficient for cpr-exec, but it has not been tested yet. - Steve Signed-off-by: Steve Sistare Reviewed-by: Fabiano Rosas --- include/exec/memory.h | 3 +++ include/exec/ramblock.h | 1 + migration/savevm.c | 2 ++ system/physmem.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index dbb1bad..d337737 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -3182,6 +3182,9 @@ bool ram_block_discard_is_disabled(void); */ bool ram_block_discard_is_required(void); +void ram_block_add_cpr_blocker(RAMBlock *rb, Error **errp); +void ram_block_del_cpr_blocker(RAMBlock *rb); + #endif #endif diff --git a/include/exec/ramblock.h b/include/exec/ramblock.h index b492d89..b70ec0c 100644 --- a/include/exec/ramblock.h +++ b/include/exec/ramblock.h @@ -40,6 +40,7 @@ struct RAMBlock { /* RCU-enabled, writes protected by the ramlist lock */ QLIST_ENTRY(RAMBlock) next; QLIST_HEAD(, RAMBlockNotifier) ramblock_notifiers; + Error *cpr_blocker; int fd; uint64_t fd_offset; int guest_memfd; diff --git a/migration/savevm.c b/migration/savevm.c index 8463ddf..6087c3a 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -3568,11 +3568,13 @@ void vmstate_register_ram(MemoryRegion *mr, DeviceState *dev) { qemu_ram_verify_idstr(mr->ram_block, dev); qemu_ram_set_migratable(mr->ram_block); + ram_block_add_cpr_blocker(mr->ram_block, &error_fatal); } void vmstate_unregister_ram(MemoryRegion *mr, DeviceState *dev) { qemu_ram_unset_migratable(mr->ram_block); + ram_block_del_cpr_blocker(mr->ram_block); } void vmstate_register_ram_global(MemoryRegion *mr) diff --git a/system/physmem.c b/system/physmem.c index 87ad441..9d44b41 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -69,6 +69,7 @@ #include "qemu/pmem.h" +#include "migration/blocker.h" #include "migration/cpr.h" #include "migration/vmstate.h" @@ -2130,7 +2131,14 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size, g_free(new_block); return NULL; } - if (!(ram_flags & RAM_GUEST_MEMFD)) { + if (ram_flags & RAM_GUEST_MEMFD) { + error_setg(&new_block->cpr_blocker, + "Memory region %s uses guest_memfd, " + "which is not supported with CPR.", + memory_region_name(mr)); + migrate_add_blocker_mode(&new_block->cpr_blocker, MIG_MODE_CPR_EXEC, + errp); + } else { vmstate_register_named(new_block->idstr, 0, &vmstate_ram_block, new_block); } @@ -3997,3 +4005,45 @@ bool ram_block_discard_is_required(void) return qatomic_read(&ram_block_discard_required_cnt) || qatomic_read(&ram_block_coordinated_discard_required_cnt); } + +/* + * Return true if ram contents would be lost during cpr for MIG_MODE_CPR_EXEC. + * Return false for ram_device because it is remapped after exec. Do not + * exclude rom, even though it is readonly, because the rom file could change + * in the new qemu. Return false for non-migratable blocks. They are either + * re-created after exec, or are handled specially, or are covered by a + * device-level cpr blocker. Return false for an fd, because it is visible and + * can be remapped in the new process. + */ +static bool ram_is_volatile(RAMBlock *rb) +{ + MemoryRegion *mr = rb->mr; + + return mr && + memory_region_is_ram(mr) && + !memory_region_is_ram_device(mr) && + (!qemu_ram_is_shared(rb) || !qemu_ram_is_named_file(rb)) && + qemu_ram_is_migratable(rb) && + rb->fd < 0; +} + +/* + * Add a MIG_MODE_CPR_EXEC blocker for each volatile ram block. + */ +void ram_block_add_cpr_blocker(RAMBlock *rb, Error **errp) +{ + if (!ram_is_volatile(rb)) { + return; + } + + error_setg(&rb->cpr_blocker, + "Memory region %s is volatile. A memory-backend-memfd or " + "memory-backend-file with share=on is required.", + memory_region_name(rb->mr)); + migrate_add_blocker_mode(&rb->cpr_blocker, MIG_MODE_CPR_EXEC, errp); +} + +void ram_block_del_cpr_blocker(RAMBlock *rb) +{ + migrate_del_blocker(&rb->cpr_blocker); +} From patchwork Mon Apr 29 15:55:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 13647324 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 43948C4345F for ; Mon, 29 Apr 2024 15:59:31 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1TMb-00055E-F1; Mon, 29 Apr 2024 11:56:24 -0400 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 1s1TMI-0004Y7-2G for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:56:02 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s1TME-0005KM-WD for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:56:01 -0400 Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43TFnpqi003604; Mon, 29 Apr 2024 15:55:55 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=0z80vD9gJHUUN6VSjk6F74K/JUahJKBy+uwGOPFalAc=; b=JmWtfTCsB4t31pozNc6Du5FyR2NY10OE22AO8tKVZnxOxXqiJ1m8ISTZmC51peEbRniq WL1y4nXU+ECeXJoBjsJRIaii2H7XMg55vH6yoy5tc28tCY8WZBAeqwCdg39Ogu9Zv3yq Z4NJ+hkST6eJ33Z650E/HxcfznRaYPG4QahVo8fdBM0Vy521M1MAsKImBrsWK0jhvlq+ D2NZ7G3Rdv01FHCEgnw1t1b240Oaga4HUSA+QFtBqq2DmE4ZemkBJlEqzwgzAN3c2X6I EgPMEuVkbqoQSq+JZfpJaca++iFefxKYfDBPyF1Aw0b574G0EamFrQy7O8Q4KMQu9jb5 qQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrr9ck10x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:54 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43TF1T3C011502; Mon, 29 Apr 2024 15:55:54 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt6j6mg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:53 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43TFtaHE034442; Mon, 29 Apr 2024 15:55:53 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3xrqt6j5ys-24; Mon, 29 Apr 2024 15:55:53 +0000 From: Steve Sistare To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , David Hildenbrand , Igor Mammedov , Eduardo Habkost , Marcel Apfelbaum , Philippe Mathieu-Daude , Paolo Bonzini , "Daniel P. Berrange" , Markus Armbruster , Steve Sistare Subject: [PATCH V1 23/26] migration: misc cpr-exec blockers Date: Mon, 29 Apr 2024 08:55:32 -0700 Message-Id: <1714406135-451286-24-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> References: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-29_14,2024-04-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404290101 X-Proofpoint-GUID: UARJ5-I5Ju3WsUQCfewP7UeGh73cvy83 X-Proofpoint-ORIG-GUID: UARJ5-I5Ju3WsUQCfewP7UeGh73cvy83 Received-SPF: pass client-ip=205.220.165.32; envelope-from=steven.sistare@oracle.com; helo=mx0a-00069f02.pphosted.com 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, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Add blockers for cpr-exec migration mode for devices and options that do not support it. Signed-off-by: Steve Sistare Reviewed-by: Fabiano Rosas --- accel/xen/xen-all.c | 5 +++++ backends/hostmem-epc.c | 12 ++++++++++-- hw/vfio/migration.c | 3 ++- replay/replay.c | 6 ++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/accel/xen/xen-all.c b/accel/xen/xen-all.c index 0bdefce..9a7ed0f 100644 --- a/accel/xen/xen-all.c +++ b/accel/xen/xen-all.c @@ -78,6 +78,7 @@ static void xen_setup_post(MachineState *ms, AccelState *accel) static int xen_init(MachineState *ms) { MachineClass *mc = MACHINE_GET_CLASS(ms); + Error *blocker = NULL; xen_xc = xc_interface_open(0, 0, 0); if (xen_xc == NULL) { @@ -112,6 +113,10 @@ static int xen_init(MachineState *ms) mc->default_ram_id = NULL; xen_mode = XEN_ATTACH; + + error_setg(&blocker, "xen does not support cpr exec"); + migrate_add_blocker_mode(&blocker, MIG_MODE_CPR_EXEC, &error_fatal); + return 0; } diff --git a/backends/hostmem-epc.c b/backends/hostmem-epc.c index 735e2e1..837300f 100644 --- a/backends/hostmem-epc.c +++ b/backends/hostmem-epc.c @@ -15,6 +15,7 @@ #include "qom/object_interfaces.h" #include "qapi/error.h" #include "sysemu/hostmem.h" +#include "migration/blocker.h" #include "hw/i386/hostmem-epc.h" static bool @@ -23,6 +24,7 @@ sgx_epc_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) g_autofree char *name = NULL; uint32_t ram_flags; int fd; + Error *blocker = NULL; if (!backend->size) { error_setg(errp, "can't create backend with size 0"); @@ -38,8 +40,14 @@ sgx_epc_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) name = object_get_canonical_path(OBJECT(backend)); ram_flags = (backend->share ? RAM_SHARED : 0) | RAM_PROTECTED; - return memory_region_init_ram_from_fd(&backend->mr, OBJECT(backend), name, - backend->size, ram_flags, fd, 0, errp); + if (!memory_region_init_ram_from_fd(&backend->mr, OBJECT(backend), + name, backend->size, ram_flags, + fd, 0, errp)) { + return false; + } + error_setg(&blocker, "memory-backend-epc does not support cpr exec"); + migrate_add_blocker_mode(&blocker, MIG_MODE_CPR_EXEC, &error_fatal); + return true; } static void sgx_epc_backend_instance_init(Object *obj) diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index 06ae409..b9cd783 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -898,7 +898,8 @@ static int vfio_block_migration(VFIODevice *vbasedev, Error *err, Error **errp) vbasedev->migration_blocker = error_copy(err); error_free(err); - return migrate_add_blocker_normal(&vbasedev->migration_blocker, errp); + return migrate_add_blocker_modes(&vbasedev->migration_blocker, errp, + MIG_MODE_NORMAL, MIG_MODE_CPR_EXEC, -1); } /* ---------------------------------------------------------------------- */ diff --git a/replay/replay.c b/replay/replay.c index a2c576c..1bf3f38 100644 --- a/replay/replay.c +++ b/replay/replay.c @@ -19,6 +19,7 @@ #include "qemu/option.h" #include "sysemu/cpus.h" #include "qemu/error-report.h" +#include "migration/blocker.h" /* Current version of the replay mechanism. Increase it when file format changes. */ @@ -339,6 +340,11 @@ G_NORETURN void replay_sync_error(const char *error) static void replay_enable(const char *fname, int mode) { const char *fmode = NULL; + Error *blocker = NULL; + + error_setg(&blocker, "replay is not compatible with cpr"); + migrate_add_blocker_mode(&blocker, MIG_MODE_CPR_EXEC, &error_fatal); + assert(!replay_file); switch (mode) { From patchwork Mon Apr 29 15:55:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 13647328 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 0B1F6C4345F for ; Mon, 29 Apr 2024 16:00:41 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1TMO-0004cT-5Z; Mon, 29 Apr 2024 11:56:08 -0400 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 1s1TMI-0004Y4-2S for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:56:02 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s1TMF-0005KS-D8 for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:56:01 -0400 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43TFnaSJ028140; Mon, 29 Apr 2024 15:55:55 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=fw5vl/gUrGf8tdC1SZLnUmsT4rLdaGW9sQv+fRKn54c=; b=Xm601FTQxdGx5a1MU96jZyMrjHsSJOr2BmCwl42Vscvn5khy98rCS6hEDnjP2Uo27liJ AedR8f0SmOH8aAMGMDx6Q9Ww0HreoV+dykYweGi9ElhLac2mrg7r1CFydmJzfgxR7tRt GyvdlAe0q7XUDhh2QJkb6ObUaPYlcsRqDuW9X4yTs81S0b87qE232Bn7eH8gEYOpmUYh D/k5QMDZvHCWu3/bWkb4/UKjwPqSTttv1T6httpt5zfXGWD/YswD3ZPlZs/17y3TdpWj 8C0j0dtmMAISFxe5oiH0X4b1NP7rPRcSODWlMT9OJUd6arPctKTAETKlMwE255Po1wVK 8Q== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrswvjxsa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:55 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43TFtTbm011394; Mon, 29 Apr 2024 15:55:54 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt6j6n7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:54 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43TFtaHG034442; Mon, 29 Apr 2024 15:55:54 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3xrqt6j5ys-25; Mon, 29 Apr 2024 15:55:54 +0000 From: Steve Sistare To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , David Hildenbrand , Igor Mammedov , Eduardo Habkost , Marcel Apfelbaum , Philippe Mathieu-Daude , Paolo Bonzini , "Daniel P. Berrange" , Markus Armbruster , Steve Sistare Subject: [PATCH V1 24/26] seccomp: cpr-exec blocker Date: Mon, 29 Apr 2024 08:55:33 -0700 Message-Id: <1714406135-451286-25-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> References: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-29_14,2024-04-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404290101 X-Proofpoint-GUID: Eyz1nINE8TlboDT8f6RUbRVTAFCt2zH7 X-Proofpoint-ORIG-GUID: Eyz1nINE8TlboDT8f6RUbRVTAFCt2zH7 Received-SPF: pass client-ip=205.220.165.32; envelope-from=steven.sistare@oracle.com; helo=mx0a-00069f02.pphosted.com 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, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org cpr-exec mode needs permission to exec. Block it if permission is denied. Signed-off-by: Steve Sistare Reviewed-by: Fabiano Rosas --- include/sysemu/seccomp.h | 1 + system/qemu-seccomp.c | 10 ++++++++-- system/vl.c | 6 ++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/include/sysemu/seccomp.h b/include/sysemu/seccomp.h index fe85989..023c0a1 100644 --- a/include/sysemu/seccomp.h +++ b/include/sysemu/seccomp.h @@ -22,5 +22,6 @@ #define QEMU_SECCOMP_SET_RESOURCECTL (1 << 4) int parse_sandbox(void *opaque, QemuOpts *opts, Error **errp); +uint32_t qemu_seccomp_get_opts(void); #endif diff --git a/system/qemu-seccomp.c b/system/qemu-seccomp.c index 5c20ac0..0d2a561 100644 --- a/system/qemu-seccomp.c +++ b/system/qemu-seccomp.c @@ -360,12 +360,18 @@ static int seccomp_start(uint32_t seccomp_opts, Error **errp) return rc < 0 ? -1 : 0; } +static uint32_t seccomp_opts; + +uint32_t qemu_seccomp_get_opts(void) +{ + return seccomp_opts; +} + int parse_sandbox(void *opaque, QemuOpts *opts, Error **errp) { if (qemu_opt_get_bool(opts, "enable", false)) { - uint32_t seccomp_opts = QEMU_SECCOMP_SET_DEFAULT - | QEMU_SECCOMP_SET_OBSOLETE; const char *value = NULL; + seccomp_opts = QEMU_SECCOMP_SET_DEFAULT | QEMU_SECCOMP_SET_OBSOLETE; value = qemu_opt_get(opts, "obsolete"); if (value) { diff --git a/system/vl.c b/system/vl.c index 7252100..b76881e 100644 --- a/system/vl.c +++ b/system/vl.c @@ -76,6 +76,7 @@ #include "hw/block/block.h" #include "hw/i386/x86.h" #include "hw/i386/pc.h" +#include "migration/blocker.h" #include "migration/cpr.h" #include "migration/misc.h" #include "migration/snapshot.h" @@ -2493,6 +2494,11 @@ static void qemu_process_early_options(void) QemuOptsList *olist = qemu_find_opts_err("sandbox", NULL); if (olist) { qemu_opts_foreach(olist, parse_sandbox, NULL, &error_fatal); + if (qemu_seccomp_get_opts() & QEMU_SECCOMP_SET_SPAWN) { + Error *blocker = NULL; + error_setg(&blocker, "-sandbox denies exec for cpr-exec"); + migrate_add_blocker_mode(&blocker, MIG_MODE_CPR_EXEC, &error_fatal); + } } #endif From patchwork Mon Apr 29 15:55:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 13647315 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 9E914C04FFE for ; Mon, 29 Apr 2024 15:56:45 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1TMQ-0004d3-Ii; Mon, 29 Apr 2024 11:56:10 -0400 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 1s1TMJ-0004aF-Ra for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:56:04 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s1TMG-0005Kc-4W for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:56:03 -0400 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43TFnajp028150; Mon, 29 Apr 2024 15:55:56 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=VUgeGOjkH5xIbS4LS0QSaGY+st+ceFJUGTwLpgJtyIk=; b=ZmamR6ZdtEuYc2LtZ0Bap9lt2OKIpRknZoBFjuIoUXyhXQdJYuLey21cvWkrEX/8dM+G tGCRVvb91nOH+j0GbseR5lVpTmlKYpG22/M2eBi54Wk6i/Gd7ow/hSQsixDGQtCeiZq3 WnX18WSL55V4bpuEjJqiVzndg67TMFpRLzek5uDDEr2QmCJ7717bx1R4AwFp6UUHlHkl 45uP+YKBkLWRvzt9EizBP1G93q06Mq4VcVWF/8Xy5CyqL5zl1CqFkw0jXEju4VtEP0FK RarNd3FSGmmJdq/+MDWyfH6W1anFjioJwlBhHyHkbku1ezovxDiw3PYg4sxdBNt5KQau 2w== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrswvjxse-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:56 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43TEt9Hk011467; Mon, 29 Apr 2024 15:55:55 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt6j6nt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:55 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43TFtaHI034442; Mon, 29 Apr 2024 15:55:54 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3xrqt6j5ys-26; Mon, 29 Apr 2024 15:55:54 +0000 From: Steve Sistare To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , David Hildenbrand , Igor Mammedov , Eduardo Habkost , Marcel Apfelbaum , Philippe Mathieu-Daude , Paolo Bonzini , "Daniel P. Berrange" , Markus Armbruster , Steve Sistare Subject: [PATCH V1 25/26] migration: fix mismatched GPAs during cpr-exec Date: Mon, 29 Apr 2024 08:55:34 -0700 Message-Id: <1714406135-451286-26-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> References: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-29_14,2024-04-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404290101 X-Proofpoint-GUID: 2M02lCBcA8F4cIOqPH-NyC-H1zDq86Gl X-Proofpoint-ORIG-GUID: 2M02lCBcA8F4cIOqPH-NyC-H1zDq86Gl Received-SPF: pass client-ip=205.220.165.32; envelope-from=steven.sistare@oracle.com; helo=mx0a-00069f02.pphosted.com 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, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org For cpr-exec mode, ramblock_is_ignored is always true, and the address of each migrated memory region must match the address of the statically initialized region on the target. However, for a PCI rom block, the region address is set when the guest writes to a BAR on the source, which does not occur on the target, causing a "Mismatched GPAs" error during cpr-exec migration. To fix, unconditionally set the target's address to the source's address if the region does not have an address yet. Signed-off-by: Steve Sistare Reviewed-by: Fabiano Rosas --- include/exec/memory.h | 12 ++++++++++++ migration/ram.c | 15 +++++++++------ system/memory.c | 10 ++++++++-- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index d337737..4f654b0 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -801,6 +801,7 @@ struct MemoryRegion { bool unmergeable; uint8_t dirty_log_mask; bool is_iommu; + bool has_addr; RAMBlock *ram_block; Object *owner; /* owner as TYPE_DEVICE. Used for re-entrancy checks in MR access hotpath */ @@ -2402,6 +2403,17 @@ void memory_region_set_enabled(MemoryRegion *mr, bool enabled); void memory_region_set_address(MemoryRegion *mr, hwaddr addr); /* + * memory_region_set_address_only: set the address of a region. + * + * Same as memory_region_set_address, but without causing transaction side + * effects. + * + * @mr: the region to be updated + * @addr: new address, relative to container region + */ +void memory_region_set_address_only(MemoryRegion *mr, hwaddr addr); + +/* * memory_region_set_size: dynamically update the size of a region. * * Dynamically updates the size of a region. diff --git a/migration/ram.c b/migration/ram.c index add285b..7b8d7f6 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -4196,12 +4196,15 @@ static int parse_ramblock(QEMUFile *f, RAMBlock *block, ram_addr_t length) } if (migrate_ignore_shared()) { hwaddr addr = qemu_get_be64(f); - if (migrate_ram_is_ignored(block) && - block->mr->addr != addr) { - error_report("Mismatched GPAs for block %s " - "%" PRId64 "!= %" PRId64, block->idstr, - (uint64_t)addr, (uint64_t)block->mr->addr); - return -EINVAL; + if (migrate_ram_is_ignored(block)) { + if (!block->mr->has_addr) { + memory_region_set_address_only(block->mr, addr); + } else if (block->mr->addr != addr) { + error_report("Mismatched GPAs for block %s " + "%" PRId64 "!= %" PRId64, block->idstr, + (uint64_t)addr, (uint64_t)block->mr->addr); + return -EINVAL; + } } } ret = rdma_block_notification_handle(f, block->idstr); diff --git a/system/memory.c b/system/memory.c index ca04a0e..3c72504 100644 --- a/system/memory.c +++ b/system/memory.c @@ -2665,7 +2665,7 @@ static void memory_region_add_subregion_common(MemoryRegion *mr, for (alias = subregion->alias; alias; alias = alias->alias) { alias->mapped_via_alias++; } - subregion->addr = offset; + memory_region_set_address_only(subregion, offset); memory_region_update_container_subregions(subregion); } @@ -2745,10 +2745,16 @@ static void memory_region_readd_subregion(MemoryRegion *mr) } } +void memory_region_set_address_only(MemoryRegion *mr, hwaddr addr) +{ + mr->addr = addr; + mr->has_addr = true; +} + void memory_region_set_address(MemoryRegion *mr, hwaddr addr) { if (addr != mr->addr) { - mr->addr = addr; + memory_region_set_address_only(mr, addr); memory_region_readd_subregion(mr); } } From patchwork Mon Apr 29 15:55:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 13647326 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 136C3C19F53 for ; Mon, 29 Apr 2024 15:59:46 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1TMX-0004wL-Rx; Mon, 29 Apr 2024 11:56:17 -0400 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 1s1TMJ-0004aG-Rk for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:56:04 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s1TMG-0005Kk-UR for qemu-devel@nongnu.org; Mon, 29 Apr 2024 11:56:03 -0400 Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43TFncI6017546; Mon, 29 Apr 2024 15:55:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=6/yzYvmrOyiE45IoO54xQG76mwyvh+VmExAEkFTHCAM=; b=D42+6OfjTW27SCvs0i8gK3pIeD63IlspjayYtIZvjo2YHIPWIVLBGxLyehdP65wx7PR1 jQ22ZNnPyU7Ij4UsOHcErHWKfFgUvxePPYSsaAzaGvURFjh2c0qLMYafr/AFnIu/Nfc4 l2QGw4olRVo5xg1hy7Z4N0PK8HV/kRgrp/1j71ejPKaTERMFlZ+qqYeEuLJ53FCouKwb GTuO70f/O3gakCpErqalYFoDU/I7nxB9GlONbw3zUXxn7dN44wUbvvBAToPF7Pu91qwb zBaPG/w0JHAAdGd/n+lze4YErHTY/aoBf+mhzRJnNPpmWr73qVrb1txG/ooTHDXaU6Pl /A== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrs8cjxdn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:56 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43TEheoP011366; Mon, 29 Apr 2024 15:55:56 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt6j6pc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 15:55:56 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43TFtaHK034442; Mon, 29 Apr 2024 15:55:55 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3xrqt6j5ys-27; Mon, 29 Apr 2024 15:55:55 +0000 From: Steve Sistare To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , David Hildenbrand , Igor Mammedov , Eduardo Habkost , Marcel Apfelbaum , Philippe Mathieu-Daude , Paolo Bonzini , "Daniel P. Berrange" , Markus Armbruster , Steve Sistare Subject: [PATCH V1 26/26] migration: only-migratable-modes Date: Mon, 29 Apr 2024 08:55:35 -0700 Message-Id: <1714406135-451286-27-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> References: <1714406135-451286-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-29_14,2024-04-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404290101 X-Proofpoint-GUID: oF8VrummWUdED35UQ2I_pgZRACaZ_gmF X-Proofpoint-ORIG-GUID: oF8VrummWUdED35UQ2I_pgZRACaZ_gmF Received-SPF: pass client-ip=205.220.165.32; envelope-from=steven.sistare@oracle.com; helo=mx0a-00069f02.pphosted.com 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, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Add the only-migratable-modes option as a generalization of only-migratable. Only devices that support all requested modes are allowed. Signed-off-by: Steve Sistare --- include/migration/misc.h | 3 +++ include/sysemu/sysemu.h | 1 - migration/migration-hmp-cmds.c | 26 +++++++++++++++++++++++++- migration/migration.c | 22 +++++++++++++++++----- migration/savevm.c | 2 +- qemu-options.hx | 16 ++++++++++++++-- system/globals.c | 1 - system/vl.c | 13 ++++++++++++- target/s390x/cpu_models.c | 4 +++- 9 files changed, 75 insertions(+), 13 deletions(-) diff --git a/include/migration/misc.h b/include/migration/misc.h index 5b963ba..3ad2cd9 100644 --- a/include/migration/misc.h +++ b/include/migration/misc.h @@ -119,6 +119,9 @@ bool migration_incoming_postcopy_advised(void); /* True if background snapshot is active */ bool migration_in_bg_snapshot(void); +void migration_set_required_mode(MigMode mode); +bool migration_mode_required(MigMode mode); + /* migration/block-dirty-bitmap.c */ void dirty_bitmap_mig_init(void); diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 5b4397e..0a9c4b4 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -8,7 +8,6 @@ /* vl.c */ -extern int only_migratable; extern const char *qemu_name; extern QemuUUID qemu_uuid; extern bool qemu_uuid_set; diff --git a/migration/migration-hmp-cmds.c b/migration/migration-hmp-cmds.c index 414c7e8..ca913b7 100644 --- a/migration/migration-hmp-cmds.c +++ b/migration/migration-hmp-cmds.c @@ -16,6 +16,7 @@ #include "qemu/osdep.h" #include "block/qapi.h" #include "migration/snapshot.h" +#include "migration/misc.h" #include "monitor/hmp.h" #include "monitor/monitor.h" #include "qapi/error.h" @@ -33,6 +34,28 @@ #include "options.h" #include "migration.h" +static void migration_dump_modes(Monitor *mon) +{ + int mode, n = 0; + + monitor_printf(mon, "only-migratable-modes: "); + + for (mode = 0; mode < MIG_MODE__MAX; mode++) { + if (migration_mode_required(mode)) { + if (n++) { + monitor_printf(mon, ","); + } + monitor_printf(mon, "%s", MigMode_str(mode)); + } + } + + if (!n) { + monitor_printf(mon, "none\n"); + } else { + monitor_printf(mon, "\n"); + } +} + static void migration_global_dump(Monitor *mon) { MigrationState *ms = migrate_get_current(); @@ -41,7 +64,7 @@ static void migration_global_dump(Monitor *mon) monitor_printf(mon, "store-global-state: %s\n", ms->store_global_state ? "on" : "off"); monitor_printf(mon, "only-migratable: %s\n", - only_migratable ? "on" : "off"); + migration_mode_required(MIG_MODE_NORMAL) ? "on" : "off"); monitor_printf(mon, "send-configuration: %s\n", ms->send_configuration ? "on" : "off"); monitor_printf(mon, "send-section-footer: %s\n", @@ -50,6 +73,7 @@ static void migration_global_dump(Monitor *mon) ms->decompress_error_check ? "on" : "off"); monitor_printf(mon, "clear-bitmap-shift: %u\n", ms->clear_bitmap_shift); + migration_dump_modes(mon); } void hmp_info_migrate(Monitor *mon, const QDict *qdict) diff --git a/migration/migration.c b/migration/migration.c index 4984dee..5535b84 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1719,17 +1719,29 @@ static bool is_busy(Error **reasonp, Error **errp) return false; } -static bool is_only_migratable(Error **reasonp, Error **errp, int modes) +static int migration_modes_required; + +void migration_set_required_mode(MigMode mode) +{ + migration_modes_required |= BIT(mode); +} + +bool migration_mode_required(MigMode mode) +{ + return !!(migration_modes_required & BIT(mode)); +} + +static bool modes_are_required(Error **reasonp, Error **errp, int modes) { ERRP_GUARD(); - if (only_migratable && (modes & BIT(MIG_MODE_NORMAL))) { + if (migration_modes_required & modes) { error_propagate_prepend(errp, *reasonp, - "disallowing migration blocker " - "(--only-migratable) for: "); + "-only-migratable{-modes} specified, but: "); *reasonp = NULL; return true; } + return false; } @@ -1783,7 +1795,7 @@ int migrate_add_blocker_modes(Error **reasonp, Error **errp, MigMode mode, ...) modes = get_modes(mode, ap); va_end(ap); - if (is_only_migratable(reasonp, errp, modes)) { + if (modes_are_required(reasonp, errp, modes)) { return -EACCES; } else if (is_busy(reasonp, errp)) { return -EBUSY; diff --git a/migration/savevm.c b/migration/savevm.c index 6087c3a..e53ac84 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -3585,7 +3585,7 @@ void vmstate_register_ram_global(MemoryRegion *mr) bool vmstate_check_only_migratable(const VMStateDescription *vmsd) { /* check needed if --only-migratable is specified */ - if (!only_migratable) { + if (!migration_mode_required(MIG_MODE_NORMAL)) { return true; } diff --git a/qemu-options.hx b/qemu-options.hx index f0dfda5..946d731 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4807,8 +4807,20 @@ DEF("only-migratable", 0, QEMU_OPTION_only_migratable, \ "-only-migratable allow only migratable devices\n", QEMU_ARCH_ALL) SRST ``-only-migratable`` - Only allow migratable devices. Devices will not be allowed to enter - an unmigratable state. + Only allow devices that can migrate using normal mode. Devices will not + be allowed to enter an unmigratable state. +ERST + +DEF("only-migratable-modes", HAS_ARG, QEMU_OPTION_only_migratable_modes, \ + "-only-migratable-modes mode1[,...]\n" + " allow only devices that are migratable using mode(s)\n", + QEMU_ARCH_ALL) +SRST +``-only-migratable-modes mode1[,...]`` + Only allow devices which are migratable using all modes in the list, + which guarantees that migration will not fail due to a blocker. + If both only-migratable-modes and only-migratable are specified, + or are specified multiple times, then the required modes accumulate. ERST DEF("nodefaults", 0, QEMU_OPTION_nodefaults, \ diff --git a/system/globals.c b/system/globals.c index e353584..fdc263e 100644 --- a/system/globals.c +++ b/system/globals.c @@ -48,7 +48,6 @@ const char *qemu_name; unsigned int nb_prom_envs; const char *prom_envs[MAX_PROM_ENVS]; uint8_t *boot_splash_filedata; -int only_migratable; /* turn it off unless user states otherwise */ int icount_align_option; /* The bytes in qemu_uuid are in the order specified by RFC4122, _not_ in the diff --git a/system/vl.c b/system/vl.c index b76881e..7e73be9 100644 --- a/system/vl.c +++ b/system/vl.c @@ -3458,7 +3458,18 @@ void qemu_init(int argc, char **argv) incoming = optarg; break; case QEMU_OPTION_only_migratable: - only_migratable = 1; + migration_set_required_mode(MIG_MODE_NORMAL); + break; + case QEMU_OPTION_only_migratable_modes: + { + int i, mode; + g_autofree char **words = g_strsplit(optarg, ",", -1); + for (i = 0; words[i]; i++) { + mode = qapi_enum_parse(&MigMode_lookup, words[i], -1, + &error_fatal); + migration_set_required_mode(mode); + } + } break; case QEMU_OPTION_nodefaults: has_defaults = 0; diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c index 8ed3bb6..42ad160 100644 --- a/target/s390x/cpu_models.c +++ b/target/s390x/cpu_models.c @@ -16,6 +16,7 @@ #include "kvm/kvm_s390x.h" #include "sysemu/kvm.h" #include "sysemu/tcg.h" +#include "migration/misc.h" #include "qapi/error.h" #include "qemu/error-report.h" #include "qapi/visitor.h" @@ -526,7 +527,8 @@ static void check_compatibility(const S390CPUModel *max_model, } #ifndef CONFIG_USER_ONLY - if (only_migratable && test_bit(S390_FEAT_UNPACK, model->features)) { + if (migration_mode_required(MIG_MODE_NORMAL) && + test_bit(S390_FEAT_UNPACK, model->features)) { error_setg(errp, "The unpack facility is not compatible with " "the --only-migratable option. You must remove either " "the 'unpack' facility or the --only-migratable option");