From patchwork Thu Jul 30 15:14:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 277253 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0A07C433E0 for ; Thu, 30 Jul 2020 15:39:58 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id AC8A32082E for ; Thu, 30 Jul 2020 15:39:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="hPC9FlqW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AC8A32082E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:59594 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k1Aez-0000N4-RX for qemu-devel@archiver.kernel.org; Thu, 30 Jul 2020 11:39:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53736) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1Ad8-00074l-Tt for qemu-devel@nongnu.org; Thu, 30 Jul 2020 11:38:02 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:36882) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1Ad6-00024X-CL for qemu-devel@nongnu.org; Thu, 30 Jul 2020 11:38:02 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06UFXgGG156161; Thu, 30 Jul 2020 15:37: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-2020-01-29; bh=dijgsEynUNDBNs0kElXjXPqxdC+9Litu30NacqUmQDQ=; b=hPC9FlqWro9zSXaKvl7HVagYvZ0cfce99DJvlCCTEXKsJgPIiQaqM4n/KqpK/Dq5HmPS nD5u0ZWrFqno7CIMd8apHQR1n/sPo3oJT1H+4JIFnO9HLAlONxtMPg3hoo3UcHRxlSow o3QxfeagyGranhO4S/ikXIacg614mrkGznQLLwBv96vwWVhLHkFbcE8wMPWB4x1VYnsp jGfGQEyG2s0THtc5Ys6c6+cVZOIe263YMTX5ktyE+wc14674Vm+DvD/M5lRxhKHlaI02 7FRj47BjxD7etHr+ruTwMctIsR7F1hafaClGHSJwHyjfzD3PBO4JY5ikVUW3eH2L5Bi6 iQ== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 32hu1jmebr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 30 Jul 2020 15:37:56 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06UFXSkf130680; Thu, 30 Jul 2020 15:37:55 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3030.oracle.com with ESMTP id 32hu5wwgj4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 30 Jul 2020 15:37:55 +0000 Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 06UFbr9c020268; Thu, 30 Jul 2020 15:37:53 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Jul 2020 08:37:53 -0700 From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V1 01/32] savevm: add vmstate handler iterators Date: Thu, 30 Jul 2020 08:14:05 -0700 Message-Id: <1596122076-341293-2-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1596122076-341293-1-git-send-email-steven.sistare@oracle.com> References: <1596122076-341293-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9698 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxlogscore=999 mlxscore=0 suspectscore=3 bulkscore=0 malwarescore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007300111 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9698 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 mlxlogscore=999 lowpriorityscore=0 malwarescore=0 clxscore=1015 mlxscore=0 impostorscore=0 phishscore=0 adultscore=0 suspectscore=3 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007300111 Received-SPF: pass client-ip=141.146.126.78; envelope-from=steven.sistare@oracle.com; helo=aserp2120.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/30 11:37:57 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -63 X-Spam_score: -6.4 X-Spam_bar: ------ X-Spam_report: (-6.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Daniel P. Berrange" , "Michael S. Tsirkin" , =?utf-8?q?Alex_Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Provide the SAVEVM_FOREACH and SAVEVM_FORALL macros to loop over all save VM state handlers. The former will filter handlers based on the operation in the later patch "savevm: VM handlers mode mask". The latter loops over all handlers. No functional change. Signed-off-by: Steve Sistare --- migration/savevm.c | 57 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/migration/savevm.c b/migration/savevm.c index 45c9dd9..a07fcad 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -266,6 +266,25 @@ static SaveState savevm_state = { .global_section_id = 0, }; +/* + * The FOREACH macros will filter handlers based on the current operation when + * additional conditions are added in a subsequent patch. + */ + +#define SAVEVM_FOREACH(se, entry) \ + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) \ + +#define SAVEVM_FOREACH_SAFE(se, entry, new_se) \ + QTAILQ_FOREACH_SAFE(se, &savevm_state.handlers, entry, new_se) \ + +/* The FORALL macros unconditionally loop over all handlers. */ + +#define SAVEVM_FORALL(se, entry) \ + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) + +#define SAVEVM_FORALL_SAFE(se, entry, new_se) \ + QTAILQ_FOREACH_SAFE(se, &savevm_state.handlers, entry, new_se) + static bool should_validate_capability(int capability) { assert(capability >= 0 && capability < MIGRATION_CAPABILITY__MAX); @@ -673,7 +692,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_FORALL(se, entry) { if (strcmp(idstr, se->idstr) == 0 && instance_id <= se->instance_id) { instance_id = se->instance_id + 1; @@ -689,7 +708,7 @@ static int calculate_compat_instance_id(const char *idstr) SaveStateEntry *se; int instance_id = 0; - QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + SAVEVM_FORALL(se, entry) { if (!se->compat) { continue; } @@ -803,7 +822,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_FORALL_SAFE(se, entry, new_se) { if (strcmp(se->idstr, id) == 0 && se->opaque == opaque) { savevm_state_handler_remove(se); g_free(se->compat); @@ -867,7 +886,7 @@ void vmstate_unregister(VMStateIf *obj, const VMStateDescription *vmsd, { SaveStateEntry *se, *new_se; - QTAILQ_FOREACH_SAFE(se, &savevm_state.handlers, entry, new_se) { + SAVEVM_FORALL_SAFE(se, entry, new_se) { if (se->vmsd == vmsd && se->opaque == opaque) { savevm_state_handler_remove(se); g_free(se->compat); @@ -1119,7 +1138,7 @@ bool qemu_savevm_state_blocked(Error **errp) { SaveStateEntry *se; - QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + SAVEVM_FORALL(se, entry) { if (se->vmsd && se->vmsd->unmigratable) { error_setg(errp, "State blocked by non-migratable device '%s'", se->idstr); @@ -1145,7 +1164,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; @@ -1162,7 +1181,7 @@ void qemu_savevm_state_setup(QEMUFile *f) int ret; trace_savevm_state_setup(); - QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + SAVEVM_FOREACH(se, entry) { if (!se->ops || !se->ops->save_setup) { continue; } @@ -1193,7 +1212,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; } @@ -1223,7 +1242,7 @@ int qemu_savevm_state_iterate(QEMUFile *f, bool postcopy) int ret = 1; trace_savevm_state_iterate(); - QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + SAVEVM_FOREACH(se, entry) { if (!se->ops || !se->ops->save_live_iterate) { continue; } @@ -1291,7 +1310,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; } @@ -1324,7 +1343,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)) || @@ -1366,7 +1385,7 @@ int qemu_savevm_state_complete_precopy_non_iterable(QEMUFile *f, vmdesc = qjson_new(); json_prop_int(vmdesc, "page_size", qemu_target_page_size()); json_start_array(vmdesc, "devices"); - QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + SAVEVM_FOREACH(se, entry) { if ((!se->ops || !se->ops->save_state) && !se->vmsd) { continue; @@ -1476,7 +1495,7 @@ void qemu_savevm_state_pending(QEMUFile *f, uint64_t threshold_size, *res_postcopy_only = 0; - QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + SAVEVM_FOREACH(se, entry) { if (!se->ops || !se->ops->save_live_pending) { continue; } @@ -1501,7 +1520,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); } @@ -1580,7 +1599,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) { @@ -1612,7 +1631,7 @@ static SaveStateEntry *find_se(const char *idstr, uint32_t instance_id) { SaveStateEntry *se; - QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + SAVEVM_FORALL(se, entry) { if (!strcmp(se->idstr, idstr) && (instance_id == se->instance_id || instance_id == se->alias_id)) @@ -2334,7 +2353,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; } @@ -2400,7 +2419,7 @@ static int qemu_loadvm_state_setup(QEMUFile *f) 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; } @@ -2425,7 +2444,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 Thu Jul 30 15:14:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 277240 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65FD3C433DF for ; Thu, 30 Jul 2020 15:57:29 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 1DDCD206F5 for ; Thu, 30 Jul 2020 15:57:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="T/1swMwa" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1DDCD206F5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:34078 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k1Avw-0000fJ-Ei for qemu-devel@archiver.kernel.org; Thu, 30 Jul 2020 11:57:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54548) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1Af4-00019k-Oh for qemu-devel@nongnu.org; Thu, 30 Jul 2020 11:40:02 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:51750) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1Af1-0002Tl-5w for qemu-devel@nongnu.org; Thu, 30 Jul 2020 11:40:02 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06UFXUoj007564; Thu, 30 Jul 2020 15:39: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-2020-01-29; bh=9yU3uF0G2s5qWsK/B3S+9s+ZnpI5bYaEDMA1bh3ly1A=; b=T/1swMwaDReppaREZ3DKXzoBsMTAo1crVZqkF5LvNqHCS3M/jzVpmronv4WUuwMZg16t EdhcrK1PTjRQToUEYZGVuTz2qlS4ooCSdqPXHk2bZZigUnT81pyllFNSj6RqVJsvrTUa hOkoCvn3Z6nprqMS06sq7Twvy10y8gG+/MXcD/kGVhHykr8klbjBsUx4/58pt5tzEeWx FRe2aAmqOcIlby767KqTLDWpgKdsQVES0/BdumyV85WrqaVyEaiq1EAIxoxVhhr6VLBK nrbIo0cfd6GZ3owxgow117wVItCvM2jeC7taVIswtN2CN3lHxY11k0xM2yJ2GBhBbiod 3Q== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 32hu1jmfsw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 30 Jul 2020 15:39:56 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06UFXSVk130767; Thu, 30 Jul 2020 15:37:55 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 32hu5wwgjp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 30 Jul 2020 15:37:55 +0000 Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 06UFbsQp001804; Thu, 30 Jul 2020 15:37:54 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Jul 2020 08:37:54 -0700 From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V1 02/32] savevm: VM handlers mode mask Date: Thu, 30 Jul 2020 08:14:06 -0700 Message-Id: <1596122076-341293-3-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1596122076-341293-1-git-send-email-steven.sistare@oracle.com> References: <1596122076-341293-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9698 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxlogscore=999 mlxscore=0 suspectscore=1 bulkscore=0 malwarescore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007300111 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9698 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 clxscore=1015 malwarescore=0 spamscore=0 suspectscore=1 bulkscore=0 priorityscore=1501 phishscore=0 mlxlogscore=999 lowpriorityscore=0 impostorscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007300111 Received-SPF: pass client-ip=156.151.31.86; envelope-from=steven.sistare@oracle.com; helo=userp2130.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/30 11:37:58 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -63 X-Spam_score: -6.4 X-Spam_bar: ------ X-Spam_report: (-6.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Daniel P. Berrange" , "Michael S. Tsirkin" , =?utf-8?q?Alex_Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Add a new mode argument to qemu_savevm_state() and qemu_loadvm_state() that can customize the operation. Define the VMS_MIGRATE and VMS_SNAPSHOT modes for the existing live migration and snapshot capabilities. Provide a mode mask for vmstate handlers. A handler is only processed by SAVEVM_FOREACH if its mask includes the savevm_state.mode. Unmodified handler declarations have a zero mask field, which implicitly enables the handler for all modes. No functional change for the VMS_MIGRATE and VMS_SNAPSHOT modes. Signed-off-by: Steve Sistare --- include/migration/register.h | 3 +++ include/migration/vmstate.h | 9 ++++++++ migration/migration.c | 4 ++-- migration/savevm.c | 51 +++++++++++++++++++++++++++++++++++--------- migration/savevm.h | 4 +++- 5 files changed, 58 insertions(+), 13 deletions(-) diff --git a/include/migration/register.h b/include/migration/register.h index c1dcff0..c030a10 100644 --- a/include/migration/register.h +++ b/include/migration/register.h @@ -17,6 +17,9 @@ #include "hw/vmstate-if.h" typedef struct SaveVMHandlers { + /* Mask of VMStateMode's that should use this handler */ + unsigned mode_mask; + /* This runs inside the iothread lock. */ SaveStateHandler *save_state; diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index f68ed7d..fa575f9 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -158,6 +158,12 @@ typedef enum { MIG_PRI_MAX, } MigrationPriority; +typedef enum { + VMS_MIGRATE = (1U << 1), + VMS_SNAPSHOT = (1U << 2), + VMS_MODE_ALL = ~0U +} VMStateMode; + struct VMStateField { const char *name; const char *err_hint; @@ -182,6 +188,7 @@ struct VMStateDescription { int minimum_version_id; int minimum_version_id_old; MigrationPriority priority; + unsigned mode_mask; LoadStateHandler *load_state_old; int (*pre_load)(void *opaque); int (*post_load)(void *opaque, int version_id); @@ -1215,4 +1222,6 @@ void vmstate_register_ram_global(struct MemoryRegion *memory); bool vmstate_check_only_migratable(const VMStateDescription *vmsd); +void savevm_set_mode(VMStateMode mode); + #endif diff --git a/migration/migration.c b/migration/migration.c index 2ed9923..e3d0899 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -465,7 +465,7 @@ static void process_incoming_migration_co(void *opaque) postcopy_state_set(POSTCOPY_INCOMING_NONE); migrate_set_state(&mis->state, MIGRATION_STATUS_NONE, MIGRATION_STATUS_ACTIVE); - ret = qemu_loadvm_state(mis->from_src_file); + ret = qemu_loadvm_state(mis->from_src_file, VMS_MIGRATE); ps = postcopy_state_get(); trace_process_incoming_migration_co_end(ret, ps); @@ -3414,7 +3414,7 @@ static void *migration_thread(void *opaque) object_ref(OBJECT(s)); update_iteration_initial_status(s); - + savevm_set_mode(VMS_MIGRATE); qemu_savevm_state_header(s->to_dst_file); /* diff --git a/migration/savevm.c b/migration/savevm.c index a07fcad..ce02b6b 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -256,6 +256,7 @@ typedef struct SaveState { const char *name; uint32_t target_page_bits; uint32_t caps_count; + VMStateMode mode; MigrationCapability *capabilities; QemuUUID uuid; } SaveState; @@ -266,16 +267,15 @@ static SaveState savevm_state = { .global_section_id = 0, }; -/* - * The FOREACH macros will filter handlers based on the current operation when - * additional conditions are added in a subsequent patch. - */ +/* The FOREACH macros filter handlers based on the current operation. */ #define SAVEVM_FOREACH(se, entry) \ QTAILQ_FOREACH(se, &savevm_state.handlers, entry) \ + if (savevm_state.mode & mode_mask(se)) #define SAVEVM_FOREACH_SAFE(se, entry, new_se) \ QTAILQ_FOREACH_SAFE(se, &savevm_state.handlers, entry, new_se) \ + if (savevm_state.mode & mode_mask(se)) /* The FORALL macros unconditionally loop over all handlers. */ @@ -285,6 +285,33 @@ static SaveState savevm_state = { #define SAVEVM_FORALL_SAFE(se, entry, new_se) \ QTAILQ_FOREACH_SAFE(se, &savevm_state.handlers, entry, new_se) +/* + * Set the current mode to be used for filtering savevm handlers in + * SAVEVM_FOREACH. + */ +void savevm_set_mode(VMStateMode mode) +{ + savevm_state.mode = mode; +} + +/* + * A savevm handler is selected in SAVEVM_FOREACH if its mask overlaps the + * current mode. The mask is defined by either the new vmsd interface or the + * legacy ops interface. If the mask is zero, it implicily includes all modes. + */ +static inline unsigned mode_mask(SaveStateEntry *se) +{ + const VMStateDescription *vmsd = se->vmsd; + unsigned mask = 0; + + if (vmsd) { + mask = vmsd->mode_mask; + } else if (se->ops) { + mask = se->ops->mode_mask; + } + return mask ? mask : VMS_MODE_ALL; +} + static bool should_validate_capability(int capability) { assert(capability >= 0 && capability < MIGRATION_CAPABILITY__MAX); @@ -1527,12 +1554,14 @@ void qemu_savevm_state_cleanup(void) } } -static int qemu_savevm_state(QEMUFile *f, Error **errp) +static int qemu_savevm_state(QEMUFile *f, VMStateMode mode, Error **errp) { int ret; MigrationState *ms = migrate_get_current(); MigrationStatus status; + savevm_set_mode(mode); + if (migration_is_running(ms->state)) { error_setg(errp, QERR_MIGRATION_ACTIVE); return -EINVAL; @@ -2557,13 +2586,14 @@ out: return ret; } -int qemu_loadvm_state(QEMUFile *f) +int qemu_loadvm_state(QEMUFile *f, VMStateMode mode) { MigrationIncomingState *mis = migration_incoming_get_current(); Error *local_err = NULL; int ret; - if (qemu_savevm_state_blocked(&local_err)) { + if ((mode & (VMS_SNAPSHOT | VMS_MIGRATE)) && + qemu_savevm_state_blocked(&local_err)) { error_report_err(local_err); return -EINVAL; } @@ -2736,7 +2766,7 @@ int save_snapshot(const char *name, Error **errp) error_setg(errp, "Could not open VM state file"); goto the_end; } - ret = qemu_savevm_state(f, errp); + ret = qemu_savevm_state(f, VMS_SNAPSHOT, errp); vm_state_size = qemu_ftell(f); ret2 = qemu_fclose(f); if (ret < 0) { @@ -2785,6 +2815,7 @@ void qmp_xen_save_devices_state(const char *filename, bool has_live, bool live, int saved_vm_running; int ret; + savevm_set_mode(VMS_MIGRATE); if (!has_live) { /* live default to true so old version of Xen tool stack can have a * successfull live migration */ @@ -2850,7 +2881,7 @@ void qmp_xen_load_devices_state(const char *filename, Error **errp) f = qemu_fopen_channel_input(QIO_CHANNEL(ioc)); object_unref(OBJECT(ioc)); - ret = qemu_loadvm_state(f); + ret = qemu_loadvm_state(f, VMS_MIGRATE); qemu_fclose(f); if (ret < 0) { error_setg(errp, QERR_IO_ERROR); @@ -2928,7 +2959,7 @@ int load_snapshot(const char *name, Error **errp) mis->from_src_file = f; aio_context_acquire(aio_context); - ret = qemu_loadvm_state(f); + ret = qemu_loadvm_state(f, VMS_SNAPSHOT); migration_incoming_state_destroy(); aio_context_release(aio_context); diff --git a/migration/savevm.h b/migration/savevm.h index ba64a7e..4b7ce91 100644 --- a/migration/savevm.h +++ b/migration/savevm.h @@ -14,6 +14,8 @@ #ifndef MIGRATION_SAVEVM_H #define MIGRATION_SAVEVM_H +#include "migration/vmstate.h" + #define QEMU_VM_FILE_MAGIC 0x5145564d #define QEMU_VM_FILE_VERSION_COMPAT 0x00000002 #define QEMU_VM_FILE_VERSION 0x00000003 @@ -60,7 +62,7 @@ void qemu_savevm_send_colo_enable(QEMUFile *f); void qemu_savevm_live_state(QEMUFile *f); int qemu_save_device_state(QEMUFile *f); -int qemu_loadvm_state(QEMUFile *f); +int qemu_loadvm_state(QEMUFile *f, VMStateMode mode); void qemu_loadvm_state_cleanup(void); int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis); int qemu_load_device_state(QEMUFile *f); From patchwork Thu Jul 30 15:14:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 277252 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10A4CC433E0 for ; Thu, 30 Jul 2020 15:40:02 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id D23112082E for ; Thu, 30 Jul 2020 15:40:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="YVoVl/dT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D23112082E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:59812 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k1Af2-0000Tb-TY for qemu-devel@archiver.kernel.org; Thu, 30 Jul 2020 11:40:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53816) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1AdC-000770-Gs for qemu-devel@nongnu.org; Thu, 30 Jul 2020 11:38:06 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:49920) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1Ad7-00025A-Tr for qemu-devel@nongnu.org; Thu, 30 Jul 2020 11:38:06 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06UFXaIp007640; Thu, 30 Jul 2020 15:37: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-2020-01-29; bh=NTT/O6BWx9NAiOeWb7X9irO+Oulxu74/KXA7hp5V6/k=; b=YVoVl/dTQMeSJSbSxIGf3e3TL5B9sj+n4Zdn/AdhPcwQWYz7e5yTW1DfX8+U2GeMV+YQ p3pVpCiY6tfapoxdyM3Hx/ReUdZA5SLlIwFehQYLN0TIFCwBywxW5/drg3LjvsR18TN/ 1JWa8jn0wsaXTU8qqX8AVERAXxEBjgxIkgI18wqvrIwqoMP51ktCMCnV1HXVtdOP4y+X MlK/VEGfdtJ1gY4Y1I7Fd2GoXIiAgPKJ0Tfhp5nkreoeyDTH+CHjW0qj+wGP6+jxF5Wk KZMfuY6ismCxZWOchu0R6JiUNxFQuteLkMpA8EyD4bc41Nvl457pM2NMA9Zq3p4sMsrN 7A== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 32hu1jmfda-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 30 Jul 2020 15:37:57 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06UFWpt3188405; Thu, 30 Jul 2020 15:37:56 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3030.oracle.com with ESMTP id 32hu5xj9n9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 30 Jul 2020 15:37:56 +0000 Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 06UFbtAJ001812; Thu, 30 Jul 2020 15:37:55 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Jul 2020 08:37:55 -0700 From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V1 03/32] savevm: QMP command for cprsave Date: Thu, 30 Jul 2020 08:14:07 -0700 Message-Id: <1596122076-341293-4-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1596122076-341293-1-git-send-email-steven.sistare@oracle.com> References: <1596122076-341293-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9698 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 mlxscore=0 adultscore=0 spamscore=0 phishscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007300111 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9698 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 clxscore=1015 malwarescore=0 spamscore=0 suspectscore=1 bulkscore=0 priorityscore=1501 phishscore=0 mlxlogscore=999 lowpriorityscore=0 impostorscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007300111 Received-SPF: pass client-ip=156.151.31.86; envelope-from=steven.sistare@oracle.com; helo=userp2130.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/30 11:37:58 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -63 X-Spam_score: -6.4 X-Spam_bar: ------ X-Spam_report: (-6.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Daniel P. Berrange" , "Michael S. Tsirkin" , =?utf-8?q?Alex_Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" To enable live reboot, provide the cprsave QMP command and the VMS_REBOOT vmstate-saving operation, which saves the state of the virtual machine in a simple file. Syntax: {'command':'cprsave', 'data':{'file':'str', 'mode':'str'}} The mode argument must be 'reboot'. Additional modes will be defined in the future. Unlike the savevm command, cprsave supports any type of guest image and block device. cprsave stops the VM so that guest ram and block devices are not modified after state is saved. Guest ram must be mapped to a persistent memory file such as /dev/dax0.0. The ram object vmstate handler and block device handler do not apply to VMS_REBOOT, so restrict them to VMS_MIGRATE or VMS_SNAPSHOT. After cprsave completes successfully, qemu exits. After issuing cprsave, the caller may update qemu, update the host kernel, reboot, start qemu using the same arguments as the original process, and issue the cprload command to restore the guest. cprload is added by subsequent patches. If the caller suspends the guest instead of stopping the VM, such as by issuing guest-suspend-ram to the qemu guest agent, then cprsave and cprload support guests with vfio devices. The guest drivers suspend methods flush outstanding requests and re-initialize the devices, and thus there is no device state to save and restore. Signed-off-by: Steve Sistare Signed-off-by: Maran Wilson --- include/migration/vmstate.h | 1 + include/sysemu/sysemu.h | 2 ++ migration/block.c | 1 + migration/ram.c | 1 + migration/savevm.c | 59 +++++++++++++++++++++++++++++++++++++++++++++ monitor/qmp-cmds.c | 6 +++++ qapi/migration.json | 14 +++++++++++ 7 files changed, 84 insertions(+) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index fa575f9..c58551a 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -161,6 +161,7 @@ typedef enum { typedef enum { VMS_MIGRATE = (1U << 1), VMS_SNAPSHOT = (1U << 2), + VMS_REBOOT = (1U << 3), VMS_MODE_ALL = ~0U } VMStateMode; diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 4b6a5c4..6fe86e6 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -24,6 +24,8 @@ extern bool machine_init_done; void qemu_add_machine_init_done_notifier(Notifier *notify); void qemu_remove_machine_init_done_notifier(Notifier *notify); +void save_cpr_snapshot(const char *file, const char *mode, Error **errp); + extern int autostart; typedef enum { diff --git a/migration/block.c b/migration/block.c index 737b649..a69accb 100644 --- a/migration/block.c +++ b/migration/block.c @@ -1023,6 +1023,7 @@ static SaveVMHandlers savevm_block_handlers = { .load_state = block_load, .save_cleanup = block_migration_cleanup, .is_active = block_is_active, + .mode_mask = VMS_MIGRATE | VMS_SNAPSHOT, }; void blk_mig_init(void) diff --git a/migration/ram.c b/migration/ram.c index 76d4fee..f0d5d9f 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3795,6 +3795,7 @@ static SaveVMHandlers savevm_ram_handlers = { .load_setup = ram_load_setup, .load_cleanup = ram_load_cleanup, .resume_prepare = ram_resume_prepare, + .mode_mask = VMS_MIGRATE | VMS_SNAPSHOT, }; void ram_mig_init(void) diff --git a/migration/savevm.c b/migration/savevm.c index ce02b6b..ff1a46e 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2680,6 +2680,65 @@ int qemu_load_device_state(QEMUFile *f) return 0; } +static QEMUFile *qf_file_open(const char *filename, int flags, int mode, + Error **errp) +{ + QIOChannel *ioc; + int fd = qemu_open(filename, flags, mode); + + if (fd < 0) { + error_setg_errno(errp, errno, "%s(%s)", __func__, filename); + return NULL; + } + + ioc = QIO_CHANNEL(qio_channel_file_new_fd(fd)); + + if (flags & O_WRONLY) { + return qemu_fopen_channel_output(ioc); + } + + return qemu_fopen_channel_input(ioc); +} + +void save_cpr_snapshot(const char *file, const char *mode, Error **errp) +{ + int ret = 0; + QEMUFile *f; + VMStateMode op; + + if (!strcmp(mode, "reboot")) { + op = VMS_REBOOT; + } else { + error_setg(errp, "cprsave: bad mode %s", mode); + return; + } + + f = qf_file_open(file, O_CREAT | O_WRONLY | O_TRUNC, 0600, errp); + if (!f) { + return; + } + + ret = global_state_store(); + if (ret) { + error_setg(errp, "Error saving global state"); + qemu_fclose(f); + return; + } + + vm_stop(RUN_STATE_SAVE_VM); + + ret = qemu_savevm_state(f, op, errp); + if ((ret < 0) && !*errp) { + error_setg(errp, "qemu_savevm_state failed"); + } + qemu_fclose(f); + + if (op == VMS_REBOOT) { + no_shutdown = 0; + qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); + } +} + int save_snapshot(const char *name, Error **errp) { BlockDriverState *bs, *bs1; diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c index 864cbfa..9ec7b88 100644 --- a/monitor/qmp-cmds.c +++ b/monitor/qmp-cmds.c @@ -35,6 +35,7 @@ #include "qapi/qapi-commands-machine.h" #include "qapi/qapi-commands-misc.h" #include "qapi/qapi-commands-ui.h" +#include "qapi/qapi-commands-migration.h" #include "qapi/qmp/qerror.h" #include "hw/mem/memory-device.h" #include "hw/acpi/acpi_dev_interface.h" @@ -161,6 +162,11 @@ void qmp_cont(Error **errp) } } +void qmp_cprsave(const char *file, const char *mode, Error **errp) +{ + save_cpr_snapshot(file, mode, errp); +} + void qmp_system_wakeup(Error **errp) { if (!qemu_wakeup_suspend_enabled()) { diff --git a/qapi/migration.json b/qapi/migration.json index d500055..b61df1d 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -1621,3 +1621,17 @@ ## { 'event': 'UNPLUG_PRIMARY', 'data': { 'device-id': 'str' } } + +## +# @cprsave: +# +# Create a checkpoint of the virtual machine device state in @file. +# Guest RAM and guest block device blocks are not saved. +# +# @file: name of checkpoint file +# @mode: 'reboot' : checkpoint can be cprload'ed after a host kexec reboot. +# +# Since 5.0 +## +{ 'command': 'cprsave', 'data': { 'file': 'str', 'mode': 'str' } } + From patchwork Thu Jul 30 15:14:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 277245 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5962C433E0 for ; Thu, 30 Jul 2020 15:50:28 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id ADF84206F5 for ; Thu, 30 Jul 2020 15:50:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="Emg4Uuw5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ADF84206F5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:39562 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k1Ap9-0007dv-QK for qemu-devel@archiver.kernel.org; Thu, 30 Jul 2020 11:50:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54558) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1Af6-0001CJ-0o for qemu-devel@nongnu.org; Thu, 30 Jul 2020 11:40:04 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:47832) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1Af3-0002U1-Qz for qemu-devel@nongnu.org; Thu, 30 Jul 2020 11:40:03 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06UFXTG9152212; Thu, 30 Jul 2020 15:39:58 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-2020-01-29; bh=d1OT3ty10GFpJwdnOpO08ryOwyf2KWtChB0Ypajkg9M=; b=Emg4Uuw5rZONqvucdJs1QRfhNS/VSGS6ktxi6Fl0eaas4SWyKxs2/jXtQCYKSec9hn5R UdxaVYHTqAdFjL3djkWKp613Q3pT3XqMTxBzROxjajnw6bXWIBM9bt/aexroVagum4t3 OngfikS4/GMsMqMLfy5k6gWhv9rEXLbetxFz0R00Pf2HkER+sEJysMP9iohPbvArq5p9 TOUHZvQS4jvr7wsAjhOvrf/parVwHgdKVFVWAljc4Wb4EgfMvskxQ2TjRJsLzHKga7y0 jxq8E87vYQcKVYcf5X95e/bHdMGI1lnAnbsn2qASgaO3caSzn6i5ckMZgwgO7NtHlFaf QQ== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 32hu1jveb2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 30 Jul 2020 15:39:58 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06UFXSO3130733; Thu, 30 Jul 2020 15:37:58 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 32hu5wwgn1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 30 Jul 2020 15:37:58 +0000 Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 06UFbuT0001829; Thu, 30 Jul 2020 15:37:56 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Jul 2020 08:37:56 -0700 From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V1 05/32] savevm: QMP command for cprload Date: Thu, 30 Jul 2020 08:14:09 -0700 Message-Id: <1596122076-341293-6-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1596122076-341293-1-git-send-email-steven.sistare@oracle.com> References: <1596122076-341293-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9698 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxlogscore=999 mlxscore=0 suspectscore=1 bulkscore=0 malwarescore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007300111 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9698 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1015 mlxlogscore=999 malwarescore=0 impostorscore=0 priorityscore=1501 spamscore=0 phishscore=0 suspectscore=1 bulkscore=0 mlxscore=0 lowpriorityscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007300111 Received-SPF: pass client-ip=156.151.31.85; envelope-from=steven.sistare@oracle.com; helo=userp2120.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/30 11:38:02 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -53 X-Spam_score: -5.4 X-Spam_bar: ----- X-Spam_report: (-5.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Daniel P. Berrange" , "Michael S. Tsirkin" , =?utf-8?q?Alex_Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Provide the cprload QMP command. The VM is created from the file produced by the cprsave command. Guest RAM is restored in-place from the shared memory backend file, and guest block devices are used as is. The contents of such devices must not be modified between the cprsave and cprload operations. If the VM was running at cprsave time, then VM execution resumes. Syntax: {'command':'cprload', 'data':{'file':'str'}} Signed-off-by: Steve Sistare Signed-off-by: Maran Wilson --- include/sysemu/sysemu.h | 2 ++ migration/savevm.c | 34 ++++++++++++++++++++++++++++++++++ monitor/qmp-cmds.c | 5 +++++ qapi/migration.json | 11 +++++++++++ softmmu/vl.c | 15 ++++++++++++++- 5 files changed, 66 insertions(+), 1 deletion(-) diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 6fe86e6..5360da5 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -25,6 +25,7 @@ void qemu_add_machine_init_done_notifier(Notifier *notify); void qemu_remove_machine_init_done_notifier(Notifier *notify); void save_cpr_snapshot(const char *file, const char *mode, Error **errp); +void load_cpr_snapshot(const char *file, Error **errp); extern int autostart; @@ -53,6 +54,7 @@ extern uint8_t *boot_splash_filedata; extern bool enable_mlock; extern bool enable_cpu_pm; extern QEMUClockType rtc_clock; +extern int start_on_wake; #define MAX_OPTION_ROMS 16 typedef struct QEMUOptionRom { diff --git a/migration/savevm.c b/migration/savevm.c index ff1a46e..1509173 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2948,6 +2948,40 @@ void qmp_xen_load_devices_state(const char *filename, Error **errp) migration_incoming_state_destroy(); } +void load_cpr_snapshot(const char *file, Error **errp) +{ + QEMUFile *f; + int ret; + RunState state; + + if (runstate_is_running()) { + error_setg(errp, "cprload called for a running VM"); + return; + } + + f = qf_file_open(file, O_RDONLY, 0, errp); + if (!f) { + return; + } + + ret = qemu_loadvm_state(f, VMS_REBOOT); + qemu_fclose(f); + if (ret < 0) { + error_setg(errp, "Error %d while loading VM state", ret); + return; + } + + state = global_state_get_runstate(); + if (state == RUN_STATE_RUNNING) { + vm_start(); + } else { + runstate_set(state); + if (runstate_check(RUN_STATE_SUSPENDED)) { + start_on_wake = 1; + } + } +} + int load_snapshot(const char *name, Error **errp) { BlockDriverState *bs, *bs_vm_state; diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c index 9ec7b88..81e6feb 100644 --- a/monitor/qmp-cmds.c +++ b/monitor/qmp-cmds.c @@ -167,6 +167,11 @@ void qmp_cprsave(const char *file, const char *mode, Error **errp) save_cpr_snapshot(file, mode, errp); } +void qmp_cprload(const char *file, Error **errp) +{ + load_cpr_snapshot(file, errp); +} + void qmp_system_wakeup(Error **errp) { if (!qemu_wakeup_suspend_enabled()) { diff --git a/qapi/migration.json b/qapi/migration.json index b61df1d..ce4d32b 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -1635,3 +1635,14 @@ ## { 'command': 'cprsave', 'data': { 'file': 'str', 'mode': 'str' } } +## +# @cprload: +# +# Start virtual machine from checkpoint file that was created earlier using +# the cprsave command. +# +# @file: name of checkpoint file +# +# Since 5.0 +## +{ 'command': 'cprload', 'data': { 'file': 'str' } } diff --git a/softmmu/vl.c b/softmmu/vl.c index 660537a..8478778 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -137,6 +137,7 @@ static time_t rtc_ref_start_datetime; static int rtc_realtime_clock_offset; /* used only with QEMU_CLOCK_REALTIME */ static int rtc_host_datetime_offset = -1; /* valid & used only with RTC_BASE_DATETIME */ +int start_on_wake; QEMUClockType rtc_clock; int vga_interface_type = VGA_NONE; static DisplayOptions dpy; @@ -602,6 +603,8 @@ static const RunStateTransition runstate_transitions_def[] = { { RUN_STATE_PRELAUNCH, RUN_STATE_RUNNING }, { RUN_STATE_PRELAUNCH, RUN_STATE_FINISH_MIGRATE }, { RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE }, + { RUN_STATE_PRELAUNCH, RUN_STATE_SUSPENDED }, + { RUN_STATE_PRELAUNCH, RUN_STATE_PAUSED }, { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING }, { RUN_STATE_FINISH_MIGRATE, RUN_STATE_PAUSED }, @@ -1519,7 +1522,17 @@ void qemu_system_wakeup_request(WakeupReason reason, Error **errp) if (!(wakeup_reason_mask & (1 << reason))) { return; } - runstate_set(RUN_STATE_RUNNING); + + /* + * Must call vm_start if it has never been called, to invoke the state + * change callbacks for the first time. + */ + if (start_on_wake) { + start_on_wake = 0; + vm_start(); + } else { + runstate_set(RUN_STATE_RUNNING); + } wakeup_reason = reason; qemu_notify_event(); } From patchwork Thu Jul 30 15:14:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 277250 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75270C433E3 for ; Thu, 30 Jul 2020 15:42:46 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 3F0E02082E for ; Thu, 30 Jul 2020 15:42:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="0ZuMsycl" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3F0E02082E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:40150 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k1Ahh-0004IL-Fu for qemu-devel@archiver.kernel.org; Thu, 30 Jul 2020 11:42:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54588) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1Af9-0001Gg-0U for qemu-devel@nongnu.org; Thu, 30 Jul 2020 11:40:11 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:51862) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1Af6-0002UV-JE for qemu-devel@nongnu.org; Thu, 30 Jul 2020 11:40:06 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06UFXoQC008019; Thu, 30 Jul 2020 15:40:01 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-2020-01-29; bh=Q6iOoNWsJ7EJZ/SrWzpci9KqugByM0dkae4gvLigMYc=; b=0ZuMsyclxLoMaOJsBoTuEX47Rbk4rqe/Sf42FnCb55kX3MJDI7mFIC/mfQ46UScl4vFy jdzniQunw7hLOpIhK29xhzDFYe8W3Zz/VUWB0fA8fL0pAaCAwHVc2md9q91HWmIDsvch P7QE2dd8JbHtG2NsvDR3rAmA4MRWRG/mm3MFDAmWKu+00oJuvJ1AwUp1rVIpv2srp/3J vwyiSlQqyrMApoJD4T7oYmT15LyNfMosKMQbn6TS9iHckl2mtFrcnlSz2pEpoOG0lpww 9Mh2TiCcE3p5hIy889/ihUmXeFRepKlj6cj/vylASixogMHGGi0mTGOMswN+uXfTPeS1 UA== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 32hu1jmftp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 30 Jul 2020 15:40:01 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06UFXToC130863; Thu, 30 Jul 2020 15:38:01 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3030.oracle.com with ESMTP id 32hu5wwgqe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 30 Jul 2020 15:38:01 +0000 Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 06UFc0rN020352; Thu, 30 Jul 2020 15:38:00 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Jul 2020 08:37:59 -0700 From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V1 09/32] savevm: prevent cprsave if memory is volatile Date: Thu, 30 Jul 2020 08:14:13 -0700 Message-Id: <1596122076-341293-10-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1596122076-341293-1-git-send-email-steven.sistare@oracle.com> References: <1596122076-341293-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9698 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxlogscore=999 mlxscore=0 suspectscore=1 bulkscore=0 malwarescore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007300111 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9698 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 clxscore=1015 malwarescore=0 spamscore=0 suspectscore=1 bulkscore=0 priorityscore=1501 phishscore=0 mlxlogscore=999 lowpriorityscore=0 impostorscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007300111 Received-SPF: pass client-ip=156.151.31.86; envelope-from=steven.sistare@oracle.com; helo=userp2130.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/30 11:37:58 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -63 X-Spam_score: -6.4 X-Spam_bar: ------ X-Spam_report: (-6.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Daniel P. Berrange" , "Michael S. Tsirkin" , =?utf-8?q?Alex_Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" cprsave and cprload require that guest ram be backed by an externally visible shared file. Check that in cprsave. Signed-off-by: Steve Sistare --- exec.c | 32 ++++++++++++++++++++++++++++++++ include/exec/memory.h | 2 ++ migration/savevm.c | 4 ++++ 3 files changed, 38 insertions(+) diff --git a/exec.c b/exec.c index 6f381f9..02160e0 100644 --- a/exec.c +++ b/exec.c @@ -2726,6 +2726,38 @@ ram_addr_t qemu_ram_addr_from_host(void *ptr) return block->offset + offset; } +/* + * Return true if any memory regions are writable and not backed by shared + * memory. Exclude x86 option rom shadow "pc.rom" by name, even though it is + * writable. + */ +bool qemu_ram_volatile(Error **errp) +{ + RAMBlock *block; + MemoryRegion *mr; + bool ret = false; + + rcu_read_lock(); + QLIST_FOREACH_RCU(block, &ram_list.blocks, next) { + mr = block->mr; + if (mr && + memory_region_is_ram(mr) && + !memory_region_is_ram_device(mr) && + !memory_region_is_rom(mr) && + (!mr->name || strcmp(mr->name, "pc.rom")) && + (block->fd == -1 || !qemu_ram_is_shared(block))) { + + error_setg(errp, "Memory region %s is volatile", + memory_region_name(mr)); + ret = true; + break; + } + } + + rcu_read_unlock(); + return ret; +} + /* Generate a debug exception if a watchpoint has been hit. */ void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len, MemTxAttrs attrs, int flags, uintptr_t ra) diff --git a/include/exec/memory.h b/include/exec/memory.h index 307e527..6aafbb0 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -2519,6 +2519,8 @@ bool ram_block_discard_is_disabled(void); */ bool ram_block_discard_is_required(void); +bool qemu_ram_volatile(Error **errp); + #endif #endif diff --git a/migration/savevm.c b/migration/savevm.c index 1509173..f101039 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2713,6 +2713,10 @@ void save_cpr_snapshot(const char *file, const char *mode, Error **errp) return; } + if (op == VMS_REBOOT && qemu_ram_volatile(errp)) { + return; + } + f = qf_file_open(file, O_CREAT | O_WRONLY | O_TRUNC, 0600, errp); if (!f) { return; From patchwork Thu Jul 30 15:14:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 277251 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B03F0C433DF for ; Thu, 30 Jul 2020 15:42:45 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 76E662082E for ; Thu, 30 Jul 2020 15:42:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="QW1mNHZL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 76E662082E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:40148 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k1Ahg-0004IC-Nd for qemu-devel@archiver.kernel.org; Thu, 30 Jul 2020 11:42:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53822) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1AdD-00077X-4t for qemu-devel@nongnu.org; Thu, 30 Jul 2020 11:38:07 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:46092) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1AdB-00026T-9R for qemu-devel@nongnu.org; Thu, 30 Jul 2020 11:38:06 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06UFXQQp152168; Thu, 30 Jul 2020 15:38:02 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-2020-01-29; bh=b9FFmQWTlGqrcBgCjwNHHJqNdI4vPeyPId0JJEpNZUw=; b=QW1mNHZLrKDI/TyJrxY+XfKmOOCm/o670xc2IK+Uk4v6pGxinNIgtDDfEUu5JbPsVewe u5v1pkp1N5LmEQXSSaGRJKPa2SEoRkUDtMbISHOsufdivMrOZ79nGWzbPcF9DBw1moDO e8589BC9YDDXt9AcsPJcDdhgPCOYcDT87IogVuLQKZts437c6sB2tWEsEclB8rtcxzj6 5icyMQMR9dMGwO3WCSuHEOLd+sIlIBU1NQFQdvJDG65F/CL1KWwLOJS8v3U7+JamxpJQ sZsGzZIPDUv3+ep1lJx78rrK7ivnOg+Uj/+FRfEESvNeOASDyJG6yf+VVfoNab/a6gb8 hg== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 32hu1jvdy0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 30 Jul 2020 15:38:02 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06UFYjGo172130; Thu, 30 Jul 2020 15:38:02 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3020.oracle.com with ESMTP id 32hu5x0w82-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 30 Jul 2020 15:38:02 +0000 Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 06UFc04Q020369; Thu, 30 Jul 2020 15:38:00 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Jul 2020 08:38:00 -0700 From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V1 10/32] kvmclock: restore paused KVM clock Date: Thu, 30 Jul 2020 08:14:14 -0700 Message-Id: <1596122076-341293-11-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1596122076-341293-1-git-send-email-steven.sistare@oracle.com> References: <1596122076-341293-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9698 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 bulkscore=0 malwarescore=0 suspectscore=1 spamscore=0 mlxlogscore=999 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007300111 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9698 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1015 mlxlogscore=999 malwarescore=0 impostorscore=0 priorityscore=1501 spamscore=0 phishscore=0 suspectscore=1 bulkscore=0 mlxscore=0 lowpriorityscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007300111 Received-SPF: pass client-ip=156.151.31.85; envelope-from=steven.sistare@oracle.com; helo=userp2120.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/30 11:38:02 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -53 X-Spam_score: -5.4 X-Spam_bar: ----- X-Spam_report: (-5.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Daniel P. Berrange" , "Michael S. Tsirkin" , =?utf-8?q?Alex_Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" If the VM is paused when the KVM clock is serialized to a file, record that the clock is valid, so the value will be reused rather than overwritten after cprload with a new call to KVM_GET_CLOCK here: kvmclock_vm_state_change() if (running) ... else if (s->clock_valid) return; <-- instead, return here kvm_update_clock() kvm_vm_ioctl(kvm_state, KVM_GET_CLOCK, &data) <-- overwritten Signed-off-by: Steve Sistare --- hw/i386/kvm/clock.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hw/i386/kvm/clock.c b/hw/i386/kvm/clock.c index 6428335..161991a 100644 --- a/hw/i386/kvm/clock.c +++ b/hw/i386/kvm/clock.c @@ -285,18 +285,22 @@ static int kvmclock_pre_save(void *opaque) if (!s->runstate_paused) { kvm_update_clock(s); } + if (!runstate_is_running()) { + s->clock_valid = true; + } return 0; } static const VMStateDescription kvmclock_vmsd = { .name = "kvmclock", - .version_id = 1, + .version_id = 2, .minimum_version_id = 1, .pre_load = kvmclock_pre_load, .pre_save = kvmclock_pre_save, .fields = (VMStateField[]) { VMSTATE_UINT64(clock, KVMClockState), + VMSTATE_BOOL_V(clock_valid, KVMClockState, 2), VMSTATE_END_OF_LIST() }, .subsections = (const VMStateDescription * []) { From patchwork Thu Jul 30 15:14:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 277249 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88B2BC433E0 for ; Thu, 30 Jul 2020 15:44:53 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 51FC22082E for ; Thu, 30 Jul 2020 15:44:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="cGYDjR1G" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 51FC22082E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:48434 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k1Ajk-0007on-Hp for qemu-devel@archiver.kernel.org; Thu, 30 Jul 2020 11:44:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53852) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1AdF-0007AK-1v for qemu-devel@nongnu.org; Thu, 30 Jul 2020 11:38:09 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:46116) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1AdD-00026o-1Q for qemu-devel@nongnu.org; Thu, 30 Jul 2020 11:38:08 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06UFXSVG152193; Thu, 30 Jul 2020 15:38:04 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-2020-01-29; bh=pBOdcc2CBeYUKc86FdzgZ3jsx9sNsQgOjultivuhWfI=; b=cGYDjR1GRjZh/vQl/QWcM8tVySYpzykPsAVYJnYc2EuRyDUJYbwcJrMMvvMimy/k/ptf dmzMdCEaSVMy6dYZOZULIYSlgAlajX4Y7ZG2cjDpG9LTGXy99CFZaPYc2KoW60ogYzS9 OUVVE8Uy7gb5nN7DuUXCXMS/lJ5tpuFPF6ZCZ5c+BttNM8PcVQGBH2d1Lj/YnLbIH5I2 /KspMc+8CTs4yl8B9rts6rwtYYMoZSuOw4ssrFMFDK8FuxiQjDXeUr05EkXlIvumgZpY DkuiTpqb5uZapYBgP58IN4vyqhnDKg+vvmUr+nU/SAIIGXuNMyeaJtPACi9Q5cWmnq6B Ig== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 32hu1jvdyb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 30 Jul 2020 15:38:04 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06UFYjDR172050; Thu, 30 Jul 2020 15:38:03 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3020.oracle.com with ESMTP id 32hu5x0wat-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 30 Jul 2020 15:38:03 +0000 Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 06UFc2t8014453; Thu, 30 Jul 2020 15:38:02 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Jul 2020 08:38:02 -0700 From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V1 12/32] vl: pause option Date: Thu, 30 Jul 2020 08:14:16 -0700 Message-Id: <1596122076-341293-13-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1596122076-341293-1-git-send-email-steven.sistare@oracle.com> References: <1596122076-341293-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9698 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 bulkscore=0 malwarescore=0 suspectscore=1 spamscore=0 mlxlogscore=999 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007300111 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9698 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1015 mlxlogscore=999 malwarescore=0 impostorscore=0 priorityscore=1501 spamscore=0 phishscore=0 suspectscore=1 bulkscore=0 mlxscore=0 lowpriorityscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007300111 Received-SPF: pass client-ip=156.151.31.85; envelope-from=steven.sistare@oracle.com; helo=userp2120.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/30 11:38:02 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -53 X-Spam_score: -5.4 X-Spam_bar: ----- X-Spam_report: (-5.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Daniel P. Berrange" , "Michael S. Tsirkin" , =?utf-8?q?Alex_Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Provide the -pause command-line parameter and the QEMU_PAUSE environment variable to briefly pause QEMU in main and allow a developer to attach gdb. Useful when the developer does not invoke QEMU directly, such as when using libvirt. Usage: qemu -pause or export QEMU_PAUSE= Signed-off-by: Steve Sistare --- qemu-options.hx | 9 +++++++++ softmmu/vl.c | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/qemu-options.hx b/qemu-options.hx index 708583b..8505cf2 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3668,6 +3668,15 @@ SRST option is experimental. ERST +DEF("pause", HAS_ARG, QEMU_OPTION_pause, \ + "-pause secs Pause for secs seconds on entry to main.\n", QEMU_ARCH_ALL) + +SRST +``--pause secs`` + Pause for a number of seconds on entry to main. Useful for attaching + a debugger after QEMU has been launched by some other entity. +ERST + DEF("S", 0, QEMU_OPTION_S, \ "-S freeze CPU at startup (use 'c' to start execution)\n", QEMU_ARCH_ALL) diff --git a/softmmu/vl.c b/softmmu/vl.c index 8478778..951994f 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -2844,7 +2844,7 @@ static void create_default_memdev(MachineState *ms, const char *path) void qemu_init(int argc, char **argv, char **envp) { - int i; + int i, seconds; int snapshot, linux_boot; const char *initrd_filename; const char *kernel_filename, *kernel_cmdline; @@ -2882,6 +2882,13 @@ void qemu_init(int argc, char **argv, char **envp) QemuPluginList plugin_list = QTAILQ_HEAD_INITIALIZER(plugin_list); int mem_prealloc = 0; /* force preallocation of physical target memory */ + if (getenv("QEMU_PAUSE")) { + seconds = atoi(getenv("QEMU_PAUSE")); + printf("Pausing %d seconds for debugger. QEMU PID is %d\n", + seconds, getpid()); + sleep(seconds); + } + os_set_line_buffering(); error_init(argv[0]); @@ -3204,6 +3211,12 @@ void qemu_init(int argc, char **argv, char **envp) case QEMU_OPTION_gdb: add_device_config(DEV_GDB, optarg); break; + case QEMU_OPTION_pause: + seconds = atoi(optarg); + printf("Pausing %d seconds for debugger. QEMU PID is %d\n", + seconds, getpid()); + sleep(seconds); + break; case QEMU_OPTION_L: if (is_help_option(optarg)) { list_data_dirs = true; From patchwork Thu Jul 30 15:14:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 277239 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4EA67C433DF for ; Thu, 30 Jul 2020 15:59:19 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 17D2E206F5 for ; Thu, 30 Jul 2020 15:59:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="HATlcllz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 17D2E206F5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:39448 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k1Axi-00033n-7p for qemu-devel@archiver.kernel.org; Thu, 30 Jul 2020 11:59:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54746) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1AfQ-0001U9-6N for qemu-devel@nongnu.org; Thu, 30 Jul 2020 11:40:24 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:51922) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1AfD-0002Uz-Dm for qemu-devel@nongnu.org; Thu, 30 Jul 2020 11:40:23 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06UFXSrw007533; Thu, 30 Jul 2020 15:40:06 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-2020-01-29; bh=J39U91hwUcfjz6AYWlnaWvznYzeNFQTfjjlfc4yEwTc=; b=HATlcllz2geWSo0JhUch8jXfS1fmtj7O9TyiHsJYjFPaRVDZCeD9Tz5HgwVNuurK+n6o cXnAY0V139k71HxrTw9/UJoRxGXpspBaYq2SzfP2oeHxSnZDDjqh6jP+tr1EpiVJ/VDI pgg6nhMLZ9VaJY/y2A+qnoFYI8yLnxqtd1AiHCYLddNqnbufpztgHOc2QsngkAKx6fiY 0zPtXwz106C/Af2PXxoPgz2GpouL6XZHkRpNAN3qBs5fvTOJwkLYMcww5QK4M5rcQ7Z1 VTm2ybj3k2PWjTx8v0Mi3zjCEsyHCV56QouTqUqVaQvOq9DOjB8KZgfYFw6yhprbmfrA yw== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 32hu1jmfu8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 30 Jul 2020 15:40:05 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06UFWZQ9176243; Thu, 30 Jul 2020 15:38:04 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 32hu61a1dc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 30 Jul 2020 15:38:04 +0000 Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 06UFc3LM007477; Thu, 30 Jul 2020 15:38:03 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Jul 2020 08:38:02 -0700 From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V1 13/32] gdbstub: gdb support for suspended state Date: Thu, 30 Jul 2020 08:14:17 -0700 Message-Id: <1596122076-341293-14-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1596122076-341293-1-git-send-email-steven.sistare@oracle.com> References: <1596122076-341293-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9698 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 adultscore=0 bulkscore=0 malwarescore=0 mlxscore=0 spamscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007300111 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9698 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 clxscore=1015 malwarescore=0 spamscore=0 suspectscore=1 bulkscore=0 priorityscore=1501 phishscore=0 mlxlogscore=999 lowpriorityscore=0 impostorscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007300111 Received-SPF: pass client-ip=156.151.31.86; envelope-from=steven.sistare@oracle.com; helo=userp2130.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/30 11:37:58 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -63 X-Spam_score: -6.4 X-Spam_bar: ------ X-Spam_report: (-6.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Daniel P. Berrange" , "Michael S. Tsirkin" , =?utf-8?q?Alex_Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Modify the gdb server so a continue command appears to resume execution when in RUN_STATE_SUSPENDED. Do not print the next gdb prompt, but do not actually resume instruction fetch. While in this "fake" running mode, a ctrl-C returns the user to the gdb prompt. Signed-off-by: Steve Sistare --- gdbstub.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index f3a318c..2f0d9ff 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -461,7 +461,9 @@ static inline void gdb_continue(void) #else if (!runstate_needs_reset()) { trace_gdbstub_op_continue(); - vm_start(); + if (!runstate_check(RUN_STATE_SUSPENDED)) { + vm_start(); + } } #endif } @@ -490,7 +492,7 @@ static int gdb_continue_partial(char *newstates) int flag = 0; if (!runstate_needs_reset()) { - if (vm_prepare_start()) { + if (!runstate_check(RUN_STATE_SUSPENDED) && vm_prepare_start()) { return 0; } @@ -2835,6 +2837,9 @@ static void gdb_read_byte(uint8_t ch) /* when the CPU is running, we cannot do anything except stop it when receiving a char */ vm_stop(RUN_STATE_PAUSED); + } else if (runstate_check(RUN_STATE_SUSPENDED) && ch == 3) { + /* Received ctrl-c from gdb */ + gdb_vm_state_change(0, 0, RUN_STATE_PAUSED); } else #endif { @@ -3282,6 +3287,8 @@ static void gdb_sigterm_handler(int signal) { if (runstate_is_running()) { vm_stop(RUN_STATE_PAUSED); + } else if (runstate_check(RUN_STATE_SUSPENDED)) { + gdb_vm_state_change(0, 0, RUN_STATE_PAUSED); } } #endif From patchwork Thu Jul 30 15:14:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 277247 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87C96C433E0 for ; Thu, 30 Jul 2020 15:47:06 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 528892082E for ; Thu, 30 Jul 2020 15:47:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="yKTS0uk+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 528892082E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:56924 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k1Alt-00031m-Gu for qemu-devel@archiver.kernel.org; Thu, 30 Jul 2020 11:47:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53888) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1AdH-0007FW-4w for qemu-devel@nongnu.org; Thu, 30 Jul 2020 11:38:11 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:46140) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1AdF-00027Q-5K for qemu-devel@nongnu.org; Thu, 30 Jul 2020 11:38:10 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06UFXPHJ152152; Thu, 30 Jul 2020 15:38:06 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-2020-01-29; bh=fYdkKNzUmAEAASFvyVOY1gxPGlabooBwhMTDAwC7ovs=; b=yKTS0uk+3YFIJUctgZKyXWdl0SWovuzz/3cS88Uzl3kN83L/nLd9SDoijiapmDdL7BrE OUw1fRC3ZN78h3pOMSwFX8CuuBHJf4GTcLPAWg8jAnPcXVSlIpryuNbj9unJ4ajaSqzK FGeZ8ID4vmYXYc0Y5BBOCzu9xiNtZZT7Lzc/Y0/VbKCGQO8k7T9tN765LnqQjdidqdqB vzcO72BrUIE/g61TzXeLmTO748Z4+ihv6FQNSS8xP3RaS7ZcJkgjiJFEXP1yVsvmgBda hL/2nh6mJ5xFX2uMYbCqLGhzeXTCzLdQqqMEhNFxLvieEVoXWlq9MO9Ry578BPE0XSYQ 4g== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 32hu1jvdyg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 30 Jul 2020 15:38:06 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06UFWZoc176171; Thu, 30 Jul 2020 15:38:05 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 32hu61a1em-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 30 Jul 2020 15:38:05 +0000 Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 06UFc4IN020459; Thu, 30 Jul 2020 15:38:04 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Jul 2020 08:38:04 -0700 From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V1 15/32] vl: QEMU_START_FREEZE env var Date: Thu, 30 Jul 2020 08:14:19 -0700 Message-Id: <1596122076-341293-16-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1596122076-341293-1-git-send-email-steven.sistare@oracle.com> References: <1596122076-341293-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9698 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 adultscore=0 bulkscore=0 malwarescore=0 mlxscore=0 spamscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007300111 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9698 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1015 mlxlogscore=999 malwarescore=0 impostorscore=0 priorityscore=1501 spamscore=0 phishscore=0 suspectscore=1 bulkscore=0 mlxscore=0 lowpriorityscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007300111 Received-SPF: pass client-ip=156.151.31.85; envelope-from=steven.sistare@oracle.com; helo=userp2120.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/30 11:38:02 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -53 X-Spam_score: -5.4 X-Spam_bar: ----- X-Spam_report: (-5.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Daniel P. Berrange" , "Michael S. Tsirkin" , =?utf-8?q?Alex_Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" For qemu upgrade and restart, we will re-exec() qemu with the same argv. However, qemu must start in a paused state and wait for the cprload command, and the original argv might not contain the -S option. To avoid modifying argv, provide the QEMU_START_FREEZE environment variable. If QEMU_START_FREEZE is set, then set autostart=0, like the -S option. Signed-off-by: Steve Sistare --- softmmu/vl.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/softmmu/vl.c b/softmmu/vl.c index 951994f..7016e39 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -4501,6 +4501,11 @@ void qemu_init(int argc, char **argv, char **envp) exit(0); } + if (getenv("QEMU_START_FREEZE")) { + unsetenv("QEMU_START_FREEZE"); + autostart = 0; + } + if (incoming) { Error *local_err = NULL; qemu_start_incoming_migration(incoming, &local_err); From patchwork Thu Jul 30 15:14:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 277246 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, UNWANTED_LANGUAGE_BODY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6611C433E0 for ; Thu, 30 Jul 2020 15:49:24 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 916522082E for ; Thu, 30 Jul 2020 15:49:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="x2cFeCgr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 916522082E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:37138 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k1Ao7-0006e7-Qi for qemu-devel@archiver.kernel.org; Thu, 30 Jul 2020 11:49:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53916) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1AdJ-0007Kh-Bu for qemu-devel@nongnu.org; Thu, 30 Jul 2020 11:38:13 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:46170) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1AdH-00028y-5e for qemu-devel@nongnu.org; Thu, 30 Jul 2020 11:38:12 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06UFXcEf152601; Thu, 30 Jul 2020 15:38:08 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-2020-01-29; bh=OOANDamxT/8UjVbukusZVM3EHUd5XIA23EDjTuSw9PA=; b=x2cFeCgrSHq5pOZc51DK+4PxT5AyGmJa1UYZI4GZodfMOVbP/3yQi7y1zdgMjw5V5GY9 DJY4TjNOpceEDJ9WBZ6o12fvW3MsGZfSJirah7kD6RysIrBZYfRzNHpGCYBSASDEHZS0 gTuRco46r+9tGku9RH4Q+ILsi8tse3Y/M/cI5T4OjAl7Fv1nhT/yLoZXZX6/DS5130j3 xGQNOcg/LhFziRfoVW5p9c5RR6ACBCPdiD4OiBQVagmgqrpyrA92q5JOk659eaIMLgE1 r8F2vP+Nf0moGMJsi0nRCv9Nyq3lIbUb2qgTZqO2BRm1rqWqjiSyASC/CCeiKzMV8mqw 8Q== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 32hu1jvdyk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 30 Jul 2020 15:38:08 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06UFWYbh176052; Thu, 30 Jul 2020 15:38:07 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 32hu61a1h0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 30 Jul 2020 15:38:07 +0000 Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 06UFc60G020470; Thu, 30 Jul 2020 15:38:06 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Jul 2020 08:38:05 -0700 From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V1 17/32] util: env var helpers Date: Thu, 30 Jul 2020 08:14:21 -0700 Message-Id: <1596122076-341293-18-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1596122076-341293-1-git-send-email-steven.sistare@oracle.com> References: <1596122076-341293-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9698 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 adultscore=0 bulkscore=0 malwarescore=0 mlxscore=0 spamscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007300111 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9698 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1015 mlxlogscore=999 malwarescore=0 impostorscore=0 priorityscore=1501 spamscore=0 phishscore=0 suspectscore=1 bulkscore=0 mlxscore=0 lowpriorityscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007300111 Received-SPF: pass client-ip=156.151.31.85; envelope-from=steven.sistare@oracle.com; helo=userp2120.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/30 11:38:02 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -53 X-Spam_score: -5.4 X-Spam_bar: ----- X-Spam_report: (-5.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Daniel P. Berrange" , "Michael S. Tsirkin" , =?utf-8?q?Alex_Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Add functions for saving fd's and ram extents in the environment via setenv, and for reading them back via getenv. Signed-off-by: Steve Sistare Signed-off-by: Mark Kanda --- MAINTAINERS | 7 +++ include/qemu/cutils.h | 1 + include/qemu/env.h | 31 ++++++++++++ util/Makefile.objs | 2 +- util/env.c | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 include/qemu/env.h create mode 100644 util/env.c diff --git a/MAINTAINERS b/MAINTAINERS index 3395abd..8d377a7 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3115,3 +3115,10 @@ Performance Tools and Tests M: Ahmed Karaman S: Maintained F: scripts/performance/ + +Environment variable helpers +M: Steve Sistare +M: Mark Kanda +S: Maintained +F: include/qemu/env.h +F: util/env.c diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h index eb59852..d4c7d70 100644 --- a/include/qemu/cutils.h +++ b/include/qemu/cutils.h @@ -1,6 +1,7 @@ #ifndef QEMU_CUTILS_H #define QEMU_CUTILS_H +#include "qemu/env.h" /** * pstrcpy: * @buf: buffer to copy string into diff --git a/include/qemu/env.h b/include/qemu/env.h new file mode 100644 index 0000000..53cc121 --- /dev/null +++ b/include/qemu/env.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef QEMU_ENV_H +#define QEMU_ENV_H + +#define FD_PREFIX "QEMU_FD_" +#define ADDR_PREFIX "QEMU_ADDR_" +#define LEN_PREFIX "QEMU_LEN_" +#define BOOL_PREFIX "QEMU_BOOL_" + +typedef int (*walkenv_cb)(const char *name, const char *val, void *handle); + +bool getenv_ram(const char *name, void **addrp, size_t *lenp); +void setenv_ram(const char *name, void *addr, size_t len); +void unsetenv_ram(const char *name); +int getenv_fd(const char *name); +void setenv_fd(const char *name, int fd); +void unsetenv_fd(const char *name); +bool getenv_bool(const char *name); +void setenv_bool(const char *name, bool val); +void unsetenv_bool(const char *name); +int walkenv(const char *prefix, walkenv_cb cb, void *handle); +void printenv(void); + +#endif diff --git a/util/Makefile.objs b/util/Makefile.objs index cc5e371..d357932 100644 --- a/util/Makefile.objs +++ b/util/Makefile.objs @@ -1,4 +1,4 @@ -util-obj-y = osdep.o cutils.o unicode.o qemu-timer-common.o +util-obj-y = osdep.o cutils.o unicode.o qemu-timer-common.o env.o util-obj-$(call lnot,$(CONFIG_ATOMIC64)) += atomic64.o util-obj-$(CONFIG_POSIX) += aio-posix.o util-obj-$(CONFIG_POSIX) += fdmon-poll.o diff --git a/util/env.c b/util/env.c new file mode 100644 index 0000000..0cc4a9f --- /dev/null +++ b/util/env.c @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "qemu/env.h" + +static uint64_t getenv_ulong(const char *prefix, const char *name, bool *found) +{ + char var[80], *val; + uint64_t res; + + snprintf(var, sizeof(var), "%s%s", prefix, name); + val = getenv(var); + if (val) { + *found = true; + res = strtol(val, 0, 10); + } else { + *found = false; + res = 0; + } + return res; +} + +static void setenv_ulong(const char *prefix, const char *name, uint64_t val) +{ + char var[80], val_str[80]; + snprintf(var, sizeof(var), "%s%s", prefix, name); + snprintf(val_str, sizeof(val_str), "%"PRIu64, val); + setenv(var, val_str, 1); +} + +static void unsetenv_ulong(const char *prefix, const char *name) +{ + char var[80]; + snprintf(var, sizeof(var), "%s%s", prefix, name); + unsetenv(var); +} + +bool getenv_ram(const char *name, void **addrp, size_t *lenp) +{ + bool found1, found2; + *addrp = (void *) getenv_ulong(ADDR_PREFIX, name, &found1); + *lenp = getenv_ulong(LEN_PREFIX, name, &found2); + assert(found1 == found2); + return found1; +} + +void setenv_ram(const char *name, void *addr, size_t len) +{ + setenv_ulong(ADDR_PREFIX, name, (uint64_t)addr); + setenv_ulong(LEN_PREFIX, name, len); +} + +void unsetenv_ram(const char *name) +{ + unsetenv_ulong(ADDR_PREFIX, name); + unsetenv_ulong(LEN_PREFIX, name); +} + +int getenv_fd(const char *name) +{ + bool found; + int fd = getenv_ulong(FD_PREFIX, name, &found); + if (!found) { + fd = -1; + } + return fd; +} + +void setenv_fd(const char *name, int fd) +{ + setenv_ulong(FD_PREFIX, name, fd); +} + +void unsetenv_fd(const char *name) +{ + unsetenv_ulong(FD_PREFIX, name); +} + +bool getenv_bool(const char *name) +{ + bool found; + bool val = getenv_ulong(BOOL_PREFIX, name, &found); + if (!found) { + val = -1; + } + return val; +} + +void setenv_bool(const char *name, bool val) +{ + setenv_ulong(BOOL_PREFIX, name, val); +} + +void unsetenv_bool(const char *name) +{ + unsetenv_ulong(BOOL_PREFIX, name); +} + +int walkenv(const char *prefix, walkenv_cb cb, void *handle) +{ + char *str, name[128]; + char **envp = environ; + size_t prefix_len = strlen(prefix); + + while (*envp) { + str = *envp++; + if (!strncmp(str, prefix, prefix_len)) { + char *val = strchr(str, '='); + str += prefix_len; + strncpy(name, str, val - str); + name[val - str] = 0; + if (cb(name, val + 1, handle)) { + return 1; + } + } + } + return 0; +} + +void printenv(void) +{ + char **ptr = environ; + while (*ptr) { + puts(*ptr++); + } +} From patchwork Thu Jul 30 15:14:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 277242 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2252C433E0 for ; Thu, 30 Jul 2020 15:54:28 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 6B18F20838 for ; Thu, 30 Jul 2020 15:54:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="fVDW8D3N" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6B18F20838 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:52256 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k1Asz-0004fV-Te for qemu-devel@archiver.kernel.org; Thu, 30 Jul 2020 11:54:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54718) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1AfP-0001SK-D3 for qemu-devel@nongnu.org; Thu, 30 Jul 2020 11:40:23 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:48040) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1AfH-0002VO-Rj for qemu-devel@nongnu.org; Thu, 30 Jul 2020 11:40:23 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06UFXjA1152650; Thu, 30 Jul 2020 15:40:12 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-2020-01-29; bh=micmSlORAvpi9yB3dc5wSQuxzyCBVgja6SS0xcqR81Y=; b=fVDW8D3NpBMq4/wzeoNpQ+NCTkZMkzsIs3oZ4PdsOoqqZ4/NaHt09iGxxqf5eNCHiGgf 4Acypv1qVUOEk1zWJeu46GgBHxMeWOD++EZz1IaedzaQhCDwhPfemElpRAzNzDoFS3zE 4AwgWj+nZpwFoC/0NvhS5We9JuU+RrjTR3zDrhXpuPc6fOBBdSS6OCHl3egFzrs3ai6a p4frav4DeCDKGmtHtyPxDrcy2U09ThmYnlwe+v8pFViKt3NK98pCplTArsvmOQffxKDQ qzJGfcr1HpV4OuTN39/4JzLrA9YXz8dBYDexKcA7rZm4irJjzv5YmhmJMPMWrq+BAavP /A== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2120.oracle.com with ESMTP id 32hu1jvecx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 30 Jul 2020 15:40:12 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06UFWp4K188370; Thu, 30 Jul 2020 15:38:11 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3030.oracle.com with ESMTP id 32hu5xja3d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 30 Jul 2020 15:38:11 +0000 Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 06UFcA0c001907; Thu, 30 Jul 2020 15:38:10 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Jul 2020 08:38:10 -0700 From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V1 21/32] exec, memory: exec(3) to restart Date: Thu, 30 Jul 2020 08:14:25 -0700 Message-Id: <1596122076-341293-22-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1596122076-341293-1-git-send-email-steven.sistare@oracle.com> References: <1596122076-341293-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9698 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 malwarescore=0 mlxscore=0 adultscore=0 spamscore=0 phishscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007300111 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9698 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1015 mlxlogscore=999 malwarescore=0 impostorscore=0 priorityscore=1501 spamscore=0 phishscore=0 suspectscore=3 bulkscore=0 mlxscore=0 lowpriorityscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007300111 Received-SPF: pass client-ip=156.151.31.85; envelope-from=steven.sistare@oracle.com; helo=userp2120.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/30 11:38:02 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -53 X-Spam_score: -5.4 X-Spam_bar: ----- X-Spam_report: (-5.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Daniel P. Berrange" , "Michael S. Tsirkin" , =?utf-8?q?Alex_Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Use exec() to restart qemu to a potentially new version, while preserving guest RAM. The guest pauses briefly. cprsave saves the address and length of RAM blocks to the environment via setenv, tags the RAM with the new madvise(MADV_DOEXEC) option to preserve it across exec, then exec()'s the (typically updated) qemu binary with the original argv. On qemu restart, ram_block_add() finds the env vars that describe preserved RAM segments and does not reallocate them. Signed-off-by: Steve Sistare --- exec.c | 36 ++++++++++++++++++++++++++++++++++-- include/exec/memory.h | 2 ++ migration/savevm.c | 16 ++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/exec.c b/exec.c index 359e437..5473c09 100644 --- a/exec.c +++ b/exec.c @@ -2235,7 +2235,7 @@ static void ram_block_add(RAMBlock *new_block, Error **errp, bool shared) Error *err = NULL; const char *name; void *addr; - size_t maxlen; + size_t len, maxlen; old_ram_size = last_ram_page(); @@ -2253,7 +2253,12 @@ static void ram_block_add(RAMBlock *new_block, Error **errp, bool shared) } } else { name = memory_region_name(new_block->mr); - addr = phys_mem_alloc(maxlen, &new_block->mr->align, shared); + if (getenv_ram(name, &addr, &len)) { + assert(len == maxlen); + } else { + addr = phys_mem_alloc(maxlen, &new_block->mr->align, shared); + setenv_ram(name, addr, maxlen); + } if (!addr) { error_setg_errno(errp, errno, @@ -2499,6 +2504,8 @@ void qemu_ram_free(RAMBlock *block) return; } + unsetenv_ram(memory_region_name(block->mr)); + if (block->host) { ram_block_notify_remove(block->host, block->max_length); } @@ -2763,6 +2770,31 @@ bool qemu_ram_volatile(Error **errp) return ret; } +static int preserve_ram(const char *name, const char *val, void *handle) +{ + void *addr; + size_t len; + Error **errp = handle; + + getenv_ram(name, &addr, &len); + if (qemu_madvise(addr, len, QEMU_MADV_DOEXEC)) { + error_setg_errno(errp, errno, + "MADV_DOEXEC failed on memory region %s", name); + return 1; + } + return 0; +} + + +int qemu_preserve_ram(Error **errp) +{ + int ret; + qemu_mutex_lock_ramlist(); + ret = walkenv(ADDR_PREFIX, preserve_ram, errp); + qemu_mutex_unlock_ramlist(); + return ret; +} + /* Generate a debug exception if a watchpoint has been hit. */ void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len, MemTxAttrs attrs, int flags, uintptr_t ra) diff --git a/include/exec/memory.h b/include/exec/memory.h index 6aafbb0..e2d297d 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -2521,6 +2521,8 @@ bool ram_block_discard_is_required(void); bool qemu_ram_volatile(Error **errp); +int qemu_preserve_ram(Error **errp); + #endif #endif diff --git a/migration/savevm.c b/migration/savevm.c index 38cc63a..2902006 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2719,6 +2719,16 @@ void save_cpr_snapshot(const char *file, const char *mode, Error **errp) return; } + if (op == VMS_RESTART && QEMU_MADV_DOEXEC == QEMU_MADV_INVALID) { + error_setg(errp, "kernel does not support MADV_DOEXEC."); + return; + } + + if (op == VMS_RESTART && xen_enabled()) { + error_setg(errp, "xen does not support cprsave restart"); + return; + } + f = qf_file_open(file, O_CREAT | O_WRONLY | O_TRUNC, 0600, errp); if (!f) { return; @@ -2747,6 +2757,12 @@ void save_cpr_snapshot(const char *file, const char *mode, Error **errp) if (op == VMS_REBOOT) { no_shutdown = 0; qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); + } else if (op == VMS_RESTART) { + if (qemu_preserve_ram(errp)) { + return; + } + qemu_system_exec_request(); + putenv((char *)"QEMU_START_FREEZE="); } } From patchwork Thu Jul 30 15:14:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 277244 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65163C433E1 for ; Thu, 30 Jul 2020 15:51:38 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 33ACD206F5 for ; Thu, 30 Jul 2020 15:51:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="jLeRnvBK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 33ACD206F5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:43592 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k1AqH-0000zY-H1 for qemu-devel@archiver.kernel.org; Thu, 30 Jul 2020 11:51:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53974) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1AdO-0007Wf-GE for qemu-devel@nongnu.org; Thu, 30 Jul 2020 11:38:18 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:50186) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1AdM-0002Au-8i for qemu-devel@nongnu.org; Thu, 30 Jul 2020 11:38:18 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06UFXbZP007647; Thu, 30 Jul 2020 15:38:13 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-2020-01-29; bh=yiR9ky1zjTylsw8BvTXwpDDI6qX/bEvwcYOs2wTpK2g=; b=jLeRnvBKmk3fqCsGN5XETuObcAsvUR0IfiKA5km8vUp+JKn0cppTODFVSB6dYeYthEdt SCMz+3CUnzDWohYmt7wHJJarex5WvRYBqy/7A5M2jFN/86Lq87gG/Tp7T0K8bdb8AmtJ VvcTchZ+6rLpqhY8svvt5b7/rLKiR43l6xPQfJFvH5vYm7t7WmgGNdtJffntuOO2uJuM 1gtL3AZLjAnUXBhtJPN2uJtMCthTNIEbvrFCoL7iq/8mx0ShHUL3WqPc6tsP7O2nYbsL UC0UCbKotxXIJQaQSFSHyfaRVwbecRUUo3xuFHyf12gHZbTjVYGBGiOqs+ytzIDadvER QA== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 32hu1jmffm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 30 Jul 2020 15:38:13 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06UFYkbK172237; Thu, 30 Jul 2020 15:38:12 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3020.oracle.com with ESMTP id 32hu5x0wnr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 30 Jul 2020 15:38:12 +0000 Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 06UFcBVv014547; Thu, 30 Jul 2020 15:38:11 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Jul 2020 08:38:11 -0700 From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V1 22/32] char: qio_channel_socket_accept reuse fd Date: Thu, 30 Jul 2020 08:14:26 -0700 Message-Id: <1596122076-341293-23-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1596122076-341293-1-git-send-email-steven.sistare@oracle.com> References: <1596122076-341293-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9698 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 bulkscore=0 malwarescore=0 suspectscore=1 spamscore=0 mlxlogscore=999 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007300111 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9698 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 clxscore=1015 malwarescore=0 spamscore=0 suspectscore=1 bulkscore=0 priorityscore=1501 phishscore=0 mlxlogscore=999 lowpriorityscore=0 impostorscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007300111 Received-SPF: pass client-ip=156.151.31.86; envelope-from=steven.sistare@oracle.com; helo=userp2130.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/30 11:37:58 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -63 X-Spam_score: -6.4 X-Spam_bar: ------ X-Spam_report: (-6.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Daniel P. Berrange" , "Michael S. Tsirkin" , =?utf-8?q?Alex_Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Mark Kanda Add an fd argument to qio_channel_socket_accept. If not -1, the channel uses that fd instead of accepting a new socket connection. All callers pass -1 in this patch, so no functional change. Signed-off-by: Mark Kanda Signed-off-by: Steve Sistare --- include/io/channel-socket.h | 3 ++- io/channel-socket.c | 12 +++++++++--- io/net-listener.c | 4 ++-- scsi/qemu-pr-helper.c | 2 +- tests/qtest/tpm-emu.c | 2 +- tests/test-char.c | 2 +- tests/test-io-channel-socket.c | 4 ++-- 7 files changed, 18 insertions(+), 11 deletions(-) diff --git a/include/io/channel-socket.h b/include/io/channel-socket.h index 777ff59..0ffc560 100644 --- a/include/io/channel-socket.h +++ b/include/io/channel-socket.h @@ -248,6 +248,7 @@ qio_channel_socket_get_remote_address(QIOChannelSocket *ioc, /** * qio_channel_socket_accept: * @ioc: the socket channel object + * @reuse_fd: fd to reuse; -1 otherwise * @errp: pointer to a NULL-initialized error object * * If the socket represents a server, then this accepts @@ -258,7 +259,7 @@ qio_channel_socket_get_remote_address(QIOChannelSocket *ioc, */ QIOChannelSocket * qio_channel_socket_accept(QIOChannelSocket *ioc, - Error **errp); + int reuse_fd, Error **errp); #endif /* QIO_CHANNEL_SOCKET_H */ diff --git a/io/channel-socket.c b/io/channel-socket.c index e1b4667..dde12bf 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -352,7 +352,7 @@ void qio_channel_socket_dgram_async(QIOChannelSocket *ioc, QIOChannelSocket * qio_channel_socket_accept(QIOChannelSocket *ioc, - Error **errp) + int reuse_fd, Error **errp) { QIOChannelSocket *cioc; @@ -362,8 +362,14 @@ qio_channel_socket_accept(QIOChannelSocket *ioc, retry: trace_qio_channel_socket_accept(ioc); - cioc->fd = qemu_accept(ioc->fd, (struct sockaddr *)&cioc->remoteAddr, - &cioc->remoteAddrLen); + + if (reuse_fd != -1) { + cioc->fd = reuse_fd; + } else { + cioc->fd = qemu_accept(ioc->fd, (struct sockaddr *)&cioc->remoteAddr, + &cioc->remoteAddrLen); + } + if (cioc->fd < 0) { if (errno == EINTR) { goto retry; diff --git a/io/net-listener.c b/io/net-listener.c index 5d8a226..bbdea1e 100644 --- a/io/net-listener.c +++ b/io/net-listener.c @@ -45,7 +45,7 @@ static gboolean qio_net_listener_channel_func(QIOChannel *ioc, QIOChannelSocket *sioc; sioc = qio_channel_socket_accept(QIO_CHANNEL_SOCKET(ioc), - NULL); + -1, NULL); if (!sioc) { return TRUE; } @@ -194,7 +194,7 @@ static gboolean qio_net_listener_wait_client_func(QIOChannel *ioc, QIOChannelSocket *sioc; sioc = qio_channel_socket_accept(QIO_CHANNEL_SOCKET(ioc), - NULL); + -1, NULL); if (!sioc) { return TRUE; } diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c index 57ad830..0e6d683 100644 --- a/scsi/qemu-pr-helper.c +++ b/scsi/qemu-pr-helper.c @@ -800,7 +800,7 @@ static gboolean accept_client(QIOChannel *ioc, GIOCondition cond, gpointer opaqu PRHelperClient *prh; cioc = qio_channel_socket_accept(QIO_CHANNEL_SOCKET(ioc), - NULL); + -1, NULL); if (!cioc) { return TRUE; } diff --git a/tests/qtest/tpm-emu.c b/tests/qtest/tpm-emu.c index 2e8eb7b..19e5dab 100644 --- a/tests/qtest/tpm-emu.c +++ b/tests/qtest/tpm-emu.c @@ -83,7 +83,7 @@ void *tpm_emu_ctrl_thread(void *data) g_cond_signal(&s->data_cond); qio_channel_wait(QIO_CHANNEL(lioc), G_IO_IN); - ioc = QIO_CHANNEL(qio_channel_socket_accept(lioc, &error_abort)); + ioc = QIO_CHANNEL(qio_channel_socket_accept(lioc, -1, &error_abort)); g_assert(ioc); { diff --git a/tests/test-char.c b/tests/test-char.c index 614bdac..1bb6ae0 100644 --- a/tests/test-char.c +++ b/tests/test-char.c @@ -884,7 +884,7 @@ char_socket_client_server_thread(gpointer data) QIOChannelSocket *cioc; retry: - cioc = qio_channel_socket_accept(ioc, &error_abort); + cioc = qio_channel_socket_accept(ioc, -1, &error_abort); g_assert_nonnull(cioc); if (char_socket_ping_pong(QIO_CHANNEL(cioc), NULL) != 0) { diff --git a/tests/test-io-channel-socket.c b/tests/test-io-channel-socket.c index d43083a..0d410cf 100644 --- a/tests/test-io-channel-socket.c +++ b/tests/test-io-channel-socket.c @@ -75,7 +75,7 @@ static void test_io_channel_setup_sync(SocketAddress *listen_addr, qio_channel_set_delay(*src, false); qio_channel_wait(QIO_CHANNEL(lioc), G_IO_IN); - *dst = QIO_CHANNEL(qio_channel_socket_accept(lioc, &error_abort)); + *dst = QIO_CHANNEL(qio_channel_socket_accept(lioc, -1, &error_abort)); g_assert(*dst); test_io_channel_set_socket_bufs(*src, *dst); @@ -143,7 +143,7 @@ static void test_io_channel_setup_async(SocketAddress *listen_addr, g_assert(!data.err); qio_channel_wait(QIO_CHANNEL(lioc), G_IO_IN); - *dst = QIO_CHANNEL(qio_channel_socket_accept(lioc, &error_abort)); + *dst = QIO_CHANNEL(qio_channel_socket_accept(lioc, -1, &error_abort)); g_assert(*dst); qio_channel_set_delay(*src, false); From patchwork Thu Jul 30 15:14:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 277237 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F1C1C433E0 for ; Thu, 30 Jul 2020 16:02:34 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 15FFD206F5 for ; Thu, 30 Jul 2020 16:02:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="lpsd5iZB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 15FFD206F5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:47136 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k1B0r-0006iN-4n for qemu-devel@archiver.kernel.org; Thu, 30 Jul 2020 12:02:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54768) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1AfQ-0001Vv-Uk for qemu-devel@nongnu.org; Thu, 30 Jul 2020 11:40:24 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:52020) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1AfJ-0002Va-NE for qemu-devel@nongnu.org; Thu, 30 Jul 2020 11:40:24 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06UFXPL6007495; Thu, 30 Jul 2020 15:40:14 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-2020-01-29; bh=Nv/b2PUDoqsO8F4DqZ6z7ZSgREh1Dj6LffZizWf6DgQ=; b=lpsd5iZB4zS7RfTSXqVLdGdu12hG/QHJ21uZjJif1qyYI7ULZ0ZRPwOmyB6no+Cp3XxQ HM+58KDyZ310qMlS7xdz+r11iDR47qaMcGYqvX39GsIea/V7BfrImKqMGPG+3zdSdm71 TSJJFkM823g5vejzOEzMkrQIMUUWTgGzC758EvTicU/XT9l32yDWQ5Xaeag569S8Hg3v JJRtmOsJ1ZDUzfCF2CPn2aZgbZl97NJSCl2LQtKlwAa/6UKKkysdt44xVDkDqSjpFbp/ FhLlkREJG+iOCocyyPrVetiAxt8tprwG9Y9DttZfxS7muDzDnf+k+NF7QxRFvfy4JNCc iw== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 32hu1jmfv3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 30 Jul 2020 15:40:13 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06UFXSM4130705; Thu, 30 Jul 2020 15:38:13 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 32hu5wwh1a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 30 Jul 2020 15:38:13 +0000 Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 06UFcCfo001915; Thu, 30 Jul 2020 15:38:12 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Jul 2020 08:38:12 -0700 From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V1 23/32] char: save/restore chardev socket fds Date: Thu, 30 Jul 2020 08:14:27 -0700 Message-Id: <1596122076-341293-24-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1596122076-341293-1-git-send-email-steven.sistare@oracle.com> References: <1596122076-341293-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9698 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxlogscore=999 mlxscore=0 suspectscore=3 bulkscore=0 malwarescore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007300111 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9698 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 clxscore=1015 malwarescore=0 spamscore=0 suspectscore=3 bulkscore=0 priorityscore=1501 phishscore=0 mlxlogscore=999 lowpriorityscore=0 impostorscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007300111 Received-SPF: pass client-ip=156.151.31.86; envelope-from=steven.sistare@oracle.com; helo=userp2130.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/30 11:37:58 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -63 X-Spam_score: -6.4 X-Spam_bar: ------ X-Spam_report: (-6.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Daniel P. Berrange" , "Michael S. Tsirkin" , =?utf-8?q?Alex_Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Mark Kanda Iterate through the character devices and save/restore the socket fds. Signed-off-by: Mark Kanda Signed-off-by: Steve Sistare --- chardev/char-socket.c | 35 +++++++++++++++++++++++++++++++++++ chardev/char.c | 14 ++++++++++++++ include/chardev/char.h | 5 +++++ include/sysemu/sysemu.h | 1 + migration/savevm.c | 8 ++++++++ 5 files changed, 63 insertions(+) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index ef62dbf..e08e7e1 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -36,6 +36,8 @@ #include "qapi/qapi-visit-sockets.h" #include "chardev/char-io.h" +#include "sysemu/sysemu.h" +#include "qemu/cutils.h" /***********************************************************/ /* TCP Net console */ @@ -400,6 +402,7 @@ static void tcp_chr_free_connection(Chardev *chr) SocketChardev *s = SOCKET_CHARDEV(chr); int i; + unsetenv_fd(chr->label); if (s->read_msgfds_num) { for (i = 0; i < s->read_msgfds_num; i++) { close(s->read_msgfds[i]); @@ -1375,6 +1378,9 @@ static void qmp_chardev_open_socket(Chardev *chr, return; } } + + load_char_socket_fd(chr); + } static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend, @@ -1517,3 +1523,32 @@ static void register_types(void) } type_init(register_types); + +void save_char_socket_fd(Chardev *chr) +{ + SocketChardev *sockchar = SOCKET_CHARDEV(chr); + + if (sockchar->sioc) { + setenv_fd(chr->label, sockchar->sioc->fd); + } +} + +void load_char_socket_fd(Chardev *chr) +{ + SocketChardev *sockchar; + QIOChannelSocket *sioc; + + int fd = getenv_fd(chr->label); + + if (fd != -1) { + unsetenv_fd(chr->label); + sockchar = SOCKET_CHARDEV(chr); + sioc = qio_channel_socket_accept(*sockchar->listener->sioc, fd, NULL); + if (sioc) { + tcp_chr_accept(sockchar->listener, sioc, chr); + } else { + error_printf("error: could not restore socket for %s\n", + chr->label); + } + } +} diff --git a/chardev/char.c b/chardev/char.c index 77e7ec8..8fd54cc 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -34,6 +34,7 @@ #include "qapi/qapi-commands-char.h" #include "qapi/qmp/qerror.h" #include "sysemu/replay.h" +#include "sysemu/sysemu.h" #include "qemu/help_option.h" #include "qemu/module.h" #include "qemu/option.h" @@ -1174,3 +1175,16 @@ static void register_types(void) } type_init(register_types); + +static int chardev_is_socket(Object *child, void *opaque) +{ + if (CHARDEV_IS_SOCKET(child)) { + save_char_socket_fd((Chardev *) child); + } + return 0; +} + +void save_chardev_fds(void) +{ + object_child_foreach(get_chardevs_root(), chardev_is_socket, NULL); +} diff --git a/include/chardev/char.h b/include/chardev/char.h index 00589a6..80a9cf8 100644 --- a/include/chardev/char.h +++ b/include/chardev/char.h @@ -250,6 +250,8 @@ int qemu_chr_wait_connected(Chardev *chr, Error **errp); object_dynamic_cast(OBJECT(chr), TYPE_CHARDEV_RINGBUF) #define CHARDEV_IS_PTY(chr) \ object_dynamic_cast(OBJECT(chr), TYPE_CHARDEV_PTY) +#define CHARDEV_IS_SOCKET(chr) \ + object_dynamic_cast(OBJECT(chr), TYPE_CHARDEV_SOCKET) typedef struct ChardevClass { ObjectClass parent_class; @@ -290,4 +292,7 @@ GSource *qemu_chr_timeout_add_ms(Chardev *chr, guint ms, /* console.c */ void qemu_chr_parse_vc(QemuOpts *opts, ChardevBackend *backend, Error **errp); +void save_char_socket_fd(Chardev *); +void load_char_socket_fd(Chardev *); + #endif diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 4dfc4ca..fa1a5c3 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -27,6 +27,7 @@ void qemu_remove_machine_init_done_notifier(Notifier *notify); void save_cpr_snapshot(const char *file, const char *mode, Error **errp); void load_cpr_snapshot(const char *file, Error **errp); +void save_chardev_fds(void); extern int autostart; diff --git a/migration/savevm.c b/migration/savevm.c index 2902006..81f38c4 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2700,6 +2700,12 @@ static QEMUFile *qf_file_open(const char *filename, int flags, int mode, return qemu_fopen_channel_input(ioc); } +static int preserve_fd(const char *name, const char *val, void *handle) +{ + qemu_clr_cloexec(atoi(val)); + return 0; +} + void save_cpr_snapshot(const char *file, const char *mode, Error **errp) { int ret = 0; @@ -2761,6 +2767,8 @@ void save_cpr_snapshot(const char *file, const char *mode, Error **errp) if (qemu_preserve_ram(errp)) { return; } + save_chardev_fds(); + walkenv(FD_PREFIX, preserve_fd, 0); qemu_system_exec_request(); putenv((char *)"QEMU_START_FREEZE="); } From patchwork Thu Jul 30 15:14:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 277243 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC6D6C433DF for ; Thu, 30 Jul 2020 15:53:47 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 87CD4206F5 for ; Thu, 30 Jul 2020 15:53:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="BVT1abTq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 87CD4206F5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:49846 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k1AsM-0003dC-RT for qemu-devel@archiver.kernel.org; Thu, 30 Jul 2020 11:53:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54000) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1AdS-0007bR-5f for qemu-devel@nongnu.org; Thu, 30 Jul 2020 11:38:25 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:37176) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1AdN-0002C2-CJ for qemu-devel@nongnu.org; Thu, 30 Jul 2020 11:38:20 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06UFXXd3155787; Thu, 30 Jul 2020 15:38:15 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-2020-01-29; bh=gA4smmTDr4yV2TFqL9n5pgGRpocaWBZlXIn3Szu+0+M=; b=BVT1abTqjT8zlDGDu6rO+Dg2O4Nk18XH/O7Q2rr5r0KGQg849IeHfSQZ/DeAApQNwV+1 E/Q1bdCmAYFM2dgXFl+xJAF+eOlwk9rdA0+kQV1DYpzPvgQLvS8Lnmdlk5Ul4Yth6XpT MV370a/eE65P5ggWX/kavm9os1e2JXSSxaPnOvxWcUIHD9/Ns1KjmO0niJzVYIt3+P/H 8Nr6fThMIRzJ+VIkn3MTlupW9Bc8JeMlk9f7fQ06o+v14lHBtPFQhq0uw87GxbJZvY8g dDTAJaO+lFDZv+piwlaOpKQ8HHXZHsrtLXCsd0/XexF8jt+6D6mgfnlfkFy6P4BgiWXA 7g== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 32hu1jmee8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 30 Jul 2020 15:38:15 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06UFXShC130702; Thu, 30 Jul 2020 15:38:14 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 32hu5wwh23-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 30 Jul 2020 15:38:14 +0000 Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 06UFcDJV001920; Thu, 30 Jul 2020 15:38:13 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Jul 2020 08:38:12 -0700 From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V1 24/32] ui: save/restore vnc socket fds Date: Thu, 30 Jul 2020 08:14:28 -0700 Message-Id: <1596122076-341293-25-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1596122076-341293-1-git-send-email-steven.sistare@oracle.com> References: <1596122076-341293-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9698 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxlogscore=999 mlxscore=0 suspectscore=1 bulkscore=0 malwarescore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007300111 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9698 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 mlxlogscore=999 lowpriorityscore=0 malwarescore=0 clxscore=1015 mlxscore=0 impostorscore=0 phishscore=0 adultscore=0 suspectscore=1 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007300111 Received-SPF: pass client-ip=141.146.126.78; envelope-from=steven.sistare@oracle.com; helo=aserp2120.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/30 11:37:57 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -63 X-Spam_score: -6.4 X-Spam_bar: ------ X-Spam_report: (-6.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Daniel P. Berrange" , "Michael S. Tsirkin" , =?utf-8?q?Alex_Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Mark Kanda Iterate through the VNC displays and save/restore the socket fds. Signed-off-by: Mark Kanda Signed-off-by: Steve Sistare --- include/sysemu/sysemu.h | 2 + migration/savevm.c | 3 + ui/vnc.c | 153 +++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 130 insertions(+), 28 deletions(-) diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index fa1a5c3..3e7bfee 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -28,6 +28,8 @@ void qemu_remove_machine_init_done_notifier(Notifier *notify); void save_cpr_snapshot(const char *file, const char *mode, Error **errp); void load_cpr_snapshot(const char *file, Error **errp); void save_chardev_fds(void); +void save_vnc_fds(void); +void load_vnc_fds(void); extern int autostart; diff --git a/migration/savevm.c b/migration/savevm.c index 81f38c4..35fafb7 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2768,6 +2768,7 @@ void save_cpr_snapshot(const char *file, const char *mode, Error **errp) return; } save_chardev_fds(); + save_vnc_fds(); walkenv(FD_PREFIX, preserve_fd, 0); qemu_system_exec_request(); putenv((char *)"QEMU_START_FREEZE="); @@ -3015,6 +3016,8 @@ void load_cpr_snapshot(const char *file, Error **errp) start_on_wake = 1; } } + + load_vnc_fds(); } int load_snapshot(const char *name, Error **errp) diff --git a/ui/vnc.c b/ui/vnc.c index f006aa1..947ddf5 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -50,6 +50,7 @@ #include "qom/object_interfaces.h" #include "qemu/cutils.h" #include "io/dns-resolver.h" +#include "sysemu/sysemu.h" #define VNC_REFRESH_INTERVAL_BASE GUI_REFRESH_INTERVAL_DEFAULT #define VNC_REFRESH_INTERVAL_INC 50 @@ -2214,28 +2215,34 @@ static void set_pixel_format(VncState *vs, int bits_per_pixel, graphic_hw_update(vs->vd->dcl.con); } -static void pixel_format_message (VncState *vs) { +/* + * reuse - true if we are using an existing (already initialized) + * connection to a vnc client + */ +static void pixel_format_message(VncState *vs, bool reuse) +{ char pad[3] = { 0, 0, 0 }; vs->client_pf = qemu_default_pixelformat(32); - vnc_write_u8(vs, vs->client_pf.bits_per_pixel); /* bits-per-pixel */ - vnc_write_u8(vs, vs->client_pf.depth); /* depth */ + if (!reuse) { + vnc_write_u8(vs, vs->client_pf.bits_per_pixel); /* bits-per-pixel */ + vnc_write_u8(vs, vs->client_pf.depth); /* depth */ #ifdef HOST_WORDS_BIGENDIAN - vnc_write_u8(vs, 1); /* big-endian-flag */ + vnc_write_u8(vs, 1); /* big-endian-flag */ #else - vnc_write_u8(vs, 0); /* big-endian-flag */ + vnc_write_u8(vs, 0); /* big-endian-flag */ #endif - vnc_write_u8(vs, 1); /* true-color-flag */ - vnc_write_u16(vs, vs->client_pf.rmax); /* red-max */ - vnc_write_u16(vs, vs->client_pf.gmax); /* green-max */ - vnc_write_u16(vs, vs->client_pf.bmax); /* blue-max */ - vnc_write_u8(vs, vs->client_pf.rshift); /* red-shift */ - vnc_write_u8(vs, vs->client_pf.gshift); /* green-shift */ - vnc_write_u8(vs, vs->client_pf.bshift); /* blue-shift */ - vnc_write(vs, pad, 3); /* padding */ - + vnc_write_u8(vs, 1); /* true-color-flag */ + vnc_write_u16(vs, vs->client_pf.rmax); /* red-max */ + vnc_write_u16(vs, vs->client_pf.gmax); /* green-max */ + vnc_write_u16(vs, vs->client_pf.bmax); /* blue-max */ + vnc_write_u8(vs, vs->client_pf.rshift); /* red-shift */ + vnc_write_u8(vs, vs->client_pf.gshift); /* green-shift */ + vnc_write_u8(vs, vs->client_pf.bshift); /* blue-shift */ + vnc_write(vs, pad, 3); /* padding */ + } vnc_hextile_set_pixel_conversion(vs, 0); vs->write_pixels = vnc_write_pixels_copy; } @@ -2252,7 +2259,7 @@ static void vnc_colordepth(VncState *vs) pixman_image_get_width(vs->vd->server), pixman_image_get_height(vs->vd->server), VNC_ENCODING_WMVi); - pixel_format_message(vs); + pixel_format_message(vs, false); vnc_unlock_output(vs); vnc_flush(vs); } else { @@ -2420,7 +2427,8 @@ static int protocol_client_msg(VncState *vs, uint8_t *data, size_t len) return 0; } -static int protocol_client_init(VncState *vs, uint8_t *data, size_t len) +static int protocol_client_init_base(VncState *vs, uint8_t *data, size_t len, + bool reuse) { char buf[1024]; VncShareMode mode; @@ -2495,10 +2503,11 @@ static int protocol_client_init(VncState *vs, uint8_t *data, size_t len) pixman_image_get_height(vs->vd->server) >= 0); vs->client_width = pixman_image_get_width(vs->vd->server); vs->client_height = pixman_image_get_height(vs->vd->server); - vnc_write_u16(vs, vs->client_width); - vnc_write_u16(vs, vs->client_height); - - pixel_format_message(vs); + if (!reuse) { + vnc_write_u16(vs, vs->client_width); + vnc_write_u16(vs, vs->client_height); + } + pixel_format_message(vs, reuse); if (qemu_name) { size = snprintf(buf, sizeof(buf), "QEMU (%s)", qemu_name); @@ -2509,9 +2518,11 @@ static int protocol_client_init(VncState *vs, uint8_t *data, size_t len) size = snprintf(buf, sizeof(buf), "QEMU"); } - vnc_write_u32(vs, size); - vnc_write(vs, buf, size); - vnc_flush(vs); + if (!reuse) { + vnc_write_u32(vs, size); + vnc_write(vs, buf, size); + vnc_flush(vs); + } vnc_client_cache_auth(vs); vnc_qmp_event(vs, QAPI_EVENT_VNC_INITIALIZED); @@ -2521,6 +2532,11 @@ static int protocol_client_init(VncState *vs, uint8_t *data, size_t len) return 0; } +static int protocol_client_init(VncState *vs, uint8_t *data, size_t len) +{ + return protocol_client_init_base(vs, data, len, false); +} + void start_client_init(VncState *vs) { vnc_read_when(vs, protocol_client_init, 1); @@ -3012,8 +3028,12 @@ static void vnc_refresh(DisplayChangeListener *dcl) } } +/* + * reuse - true if we are using an existing (already initialized) + * connection to a vnc client + */ static void vnc_connect(VncDisplay *vd, QIOChannelSocket *sioc, - bool skipauth, bool websocket) + bool skipauth, bool websocket, bool reuse) { VncState *vs = g_new0(VncState, 1); bool first_client = QTAILQ_EMPTY(&vd->clients); @@ -3109,10 +3129,15 @@ static void vnc_connect(VncDisplay *vd, QIOChannelSocket *sioc, graphic_hw_update(vd->dcl.con); - if (!vs->websocket) { + if ((!vs->websocket) && !reuse) { vnc_start_protocol(vs); } + if (reuse) { + uint8_t data[1] = {0}; + (void) protocol_client_init_base(vs, data, sizeof(data), true); + } + if (vd->num_connecting > vd->connections_limit) { QTAILQ_FOREACH(vs, &vd->clients, next) { if (vs->share_mode == VNC_SHARE_MODE_CONNECTING) { @@ -3143,7 +3168,7 @@ static void vnc_listen_io(QIONetListener *listener, qio_channel_set_name(QIO_CHANNEL(cioc), isWebsock ? "vnc-ws-server" : "vnc-server"); qio_channel_set_delay(QIO_CHANNEL(cioc), false); - vnc_connect(vd, cioc, false, isWebsock); + vnc_connect(vd, cioc, false, isWebsock, false); } static const DisplayChangeListenerOps dcl_ops = { @@ -3733,7 +3758,7 @@ static int vnc_display_connect(VncDisplay *vd, if (qio_channel_socket_connect_sync(sioc, saddr[0], errp) < 0) { return -1; } - vnc_connect(vd, sioc, false, false); + vnc_connect(vd, sioc, false, false, false); object_unref(OBJECT(sioc)); return 0; } @@ -4057,7 +4082,7 @@ void vnc_display_add_client(const char *id, int csock, bool skipauth) sioc = qio_channel_socket_new_fd(csock, NULL); if (sioc) { qio_channel_set_name(QIO_CHANNEL(sioc), "vnc-server"); - vnc_connect(vd, sioc, skipauth, false); + vnc_connect(vd, sioc, skipauth, false, false); object_unref(OBJECT(sioc)); } } @@ -4117,3 +4142,75 @@ static void vnc_register_config(void) qemu_add_opts(&qemu_vnc_opts); } opts_init(vnc_register_config); + +void save_vnc_fds(void) +{ + VncDisplay *vd; + VncState *vs; + int disp_num = 0; + char name[40]; + + QTAILQ_FOREACH(vd, &vnc_displays, next) { + QTAILQ_FOREACH(vs, &vd->clients, next) { + if (vs->sioc) { + snprintf(name, sizeof(name), "%s_%d", vs->sioc->parent.name, + disp_num); + setenv_fd(name, vs->sioc->fd); + break; + } + } + disp_num++; + } +} + +static void set_vnc_fd(char *name, QIOChannelSocket *cioc, VncDisplay *vd, + bool isWebsock) +{ + VncState *vs; + QIOChannelSocket *sioc; + + int fd = getenv_fd(name); + if (fd != -1) { + sioc = qio_channel_socket_accept(cioc, fd, NULL); + if (sioc) { + unsetenv_fd(name); + qio_channel_set_name(QIO_CHANNEL(sioc), + isWebsock ? "vnc-ws-server" : "vnc-server"); + + qio_channel_set_delay(QIO_CHANNEL(sioc), false); + vnc_connect(vd, sioc, false, isWebsock, true); + object_unref(OBJECT(sioc)); + + /* force update on all clients */ + QTAILQ_FOREACH(vs, &vd->clients, next) { + vs->update = VNC_STATE_UPDATE_FORCE; + } + } else { + error_printf("Could not restore vnc channel %s; " + "client must reconnect.\n", name); + } + } +} + +void load_vnc_fds(void) +{ + VncDisplay *vd; + QIOChannelSocket *cioc = NULL; + int disp_num = 0; + char name[40]; + + QTAILQ_FOREACH(vd, &vnc_displays, next) { + if (vd->listener) { + cioc = *vd->listener->sioc; + snprintf(name, sizeof(name), "vnc-server_%d", disp_num); + set_vnc_fd(name, cioc, vd, false); + } + + if (vd->wslistener) { + cioc = *vd->wslistener->sioc; + snprintf(name, sizeof(name), "vnc-ws-server_%d", disp_num); + set_vnc_fd(name, cioc, vd, true); + } + disp_num++; + } +} From patchwork Thu Jul 30 15:14:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 277241 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA91FC433E0 for ; Thu, 30 Jul 2020 15:55:49 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 90606206F5 for ; Thu, 30 Jul 2020 15:55:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="QM4weoki" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 90606206F5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:56176 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k1AuK-0006OL-S7 for qemu-devel@archiver.kernel.org; Thu, 30 Jul 2020 11:55:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54044) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1AdY-0007eQ-Jp for qemu-devel@nongnu.org; Thu, 30 Jul 2020 11:38:28 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:46366) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1AdV-0002CO-Tv for qemu-devel@nongnu.org; Thu, 30 Jul 2020 11:38:28 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06UFXPlV152146; Thu, 30 Jul 2020 15:38:18 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-2020-01-29; bh=FPPMSivcUUtl0hRkdAFGBRzCLwr8+PkkoZfhLsJyqGs=; b=QM4weokiqiLhDvpSqxMTqdt9/TGQT+Ou7MoBsLCGSgokxwBFmQhmIqisJbHEBmQ7B+oA wrn7ouDQNMEgIf1lNz7s98J3ycDk68G3XDQAp0dy2gb++M4uHrM5ls/WAIPYO6ucNbi4 +/TR+rPPjAIszj52BkxvW/cooNs5NIIcO7cTL9+YLpesp2so6ezMVha22wRXSewrrOjk e0sBy0YeViPbxKJvaYsZBppNsdd2dYHF1qRnN+zze1BibThoAlNRhG7i9QXpkUth4mDG eLyaZPtsRsjTJlQZHlLVdJ0V3/03rbqzRSaopYlKjFuZ7xPmClm2hlkkO6eVRIWZRw+u pw== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 32hu1jve10-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 30 Jul 2020 15:38:18 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06UFWZrB176081; Thu, 30 Jul 2020 15:38:17 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 32hu61a20m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 30 Jul 2020 15:38:17 +0000 Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 06UFcGWZ007542; Thu, 30 Jul 2020 15:38:16 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Jul 2020 08:38:15 -0700 From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V1 28/32] char: restore terminal on restart Date: Thu, 30 Jul 2020 08:14:32 -0700 Message-Id: <1596122076-341293-29-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1596122076-341293-1-git-send-email-steven.sistare@oracle.com> References: <1596122076-341293-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9698 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 adultscore=0 bulkscore=0 malwarescore=0 mlxscore=0 spamscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007300111 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9698 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1015 mlxlogscore=999 malwarescore=0 impostorscore=0 priorityscore=1501 spamscore=0 phishscore=0 suspectscore=1 bulkscore=0 mlxscore=0 lowpriorityscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007300111 Received-SPF: pass client-ip=156.151.31.85; envelope-from=steven.sistare@oracle.com; helo=userp2120.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/30 11:38:02 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -53 X-Spam_score: -5.4 X-Spam_bar: ----- X-Spam_report: (-5.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Daniel P. Berrange" , "Michael S. Tsirkin" , =?utf-8?q?Alex_Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" If stdin is is a char backend device, then restore original stdin terminal settings in before re-exec'ing. Otherwise, the new qemu sees the modified settings as initial settings, and does not restore the true initial settings when it exits. Signed-off-by: Steve Sistare --- chardev/char-stdio.c | 7 +++++++ include/chardev/char.h | 2 ++ migration/savevm.c | 2 ++ 3 files changed, 11 insertions(+) diff --git a/chardev/char-stdio.c b/chardev/char-stdio.c index 82eaebc..6481d08 100644 --- a/chardev/char-stdio.c +++ b/chardev/char-stdio.c @@ -119,6 +119,13 @@ static void qemu_chr_open_stdio(Chardev *chr, } #endif +void qemu_term_exit(void) +{ +#ifndef _WIN32 + term_exit(); +#endif +} + static void qemu_chr_parse_stdio(QemuOpts *opts, ChardevBackend *backend, Error **errp) { diff --git a/include/chardev/char.h b/include/chardev/char.h index c18bda8..5fd3ecc 100644 --- a/include/chardev/char.h +++ b/include/chardev/char.h @@ -296,4 +296,6 @@ void save_char_socket_fd(Chardev *); void load_char_socket_fd(Chardev *); void save_char_pty_fd(Chardev *); +void qemu_term_exit(void); + #endif diff --git a/migration/savevm.c b/migration/savevm.c index 732dfb5..881dc13 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -32,6 +32,7 @@ #include "migration.h" #include "migration/snapshot.h" #include "migration/vmstate.h" +#include "chardev/char.h" #include "migration/misc.h" #include "migration/register.h" #include "migration/global_state.h" @@ -2772,6 +2773,7 @@ void save_cpr_snapshot(const char *file, const char *mode, Error **errp) walkenv(FD_PREFIX, preserve_fd, 0); reset_vhost_devices(); save_qmp_negotiation_status(); + qemu_term_exit(); qemu_system_exec_request(); putenv((char *)"QEMU_START_FREEZE="); } From patchwork Thu Jul 30 15:14:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 277248 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5247C433DF for ; Thu, 30 Jul 2020 15:44:59 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id A01302082E for ; Thu, 30 Jul 2020 15:44:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="JbtPvXPs" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A01302082E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:48922 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k1Ajq-00081C-TI for qemu-devel@archiver.kernel.org; Thu, 30 Jul 2020 11:44:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54820) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1AfT-0001cS-NT for qemu-devel@nongnu.org; Thu, 30 Jul 2020 11:40:27 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:38998) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1AfP-0002WW-9S for qemu-devel@nongnu.org; Thu, 30 Jul 2020 11:40:27 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06UFXPB2155707; Thu, 30 Jul 2020 15:40:21 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-2020-01-29; bh=2Avxi1QWe6cUG3l1LSMFbAq/69tVDOToYh40OrsqGe4=; b=JbtPvXPsB7YTbRvXEQcezDf1/hl6eo4YAYQOf/3R88VzkPO1trOzEzr3w/Zj4uim3Dev 4iYa84hS+7lLDnRO8rRso5jMOMW0sI0FcMOtLyCbh4rgZLI/P5kTSjB3IV9FH3Ghb5/k kZ28/1Yv9IZfgtkqA10m5cMOocUd8spHPIf90ZUNhGRrdZtB+LAZip+albt+gt36Ulpm SZmUCg7oxkgdZ88k7fQCYXsOjleMPYsKubhoJp3QJkSlmLnpGJ+pfSvNagW4mP+xxcpQ zGCTW+H7jdZcK49VlJX8jRIyOMT8JMgE/PLswNDW1Ir7scT08UJyBaPZccu1617VfMuV uw== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 32hu1jmeut-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 30 Jul 2020 15:40:21 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06UFYjZg172022; Thu, 30 Jul 2020 15:38:20 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3020.oracle.com with ESMTP id 32hu5x0wut-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 30 Jul 2020 15:38:20 +0000 Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 06UFcI64020550; Thu, 30 Jul 2020 15:38:18 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Jul 2020 08:38:18 -0700 From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V1 32/32] vfio-pci: improved tracing Date: Thu, 30 Jul 2020 08:14:36 -0700 Message-Id: <1596122076-341293-33-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1596122076-341293-1-git-send-email-steven.sistare@oracle.com> References: <1596122076-341293-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9698 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 bulkscore=0 malwarescore=0 suspectscore=1 spamscore=0 mlxlogscore=999 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007300111 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9698 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 mlxlogscore=999 lowpriorityscore=0 malwarescore=0 clxscore=1015 mlxscore=0 impostorscore=0 phishscore=0 adultscore=0 suspectscore=1 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007300111 Received-SPF: pass client-ip=141.146.126.78; envelope-from=steven.sistare@oracle.com; helo=aserp2120.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/30 11:37:57 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -63 X-Spam_score: -6.4 X-Spam_bar: ------ X-Spam_report: (-6.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Daniel P. Berrange" , "Michael S. Tsirkin" , =?utf-8?q?Alex_Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Print more info for existing trace points: trace_kvm_irqchip_add_msi_route. trace_pci_update_mappings_del trace_pci_update_mappings_add Add new trace points: trace_kvm_irqchip_assign_irqfd trace_msix_table_mmio_write trace_vfio_dma_unmap trace_vfio_dma_map trace_vfio_region trace_vfio_descriptors trace_ram_block_add Signed-off-by: Steve Sistare --- accel/kvm/kvm-all.c | 8 ++++++-- accel/kvm/trace-events | 3 ++- exec.c | 3 +++ hw/pci/msix.c | 1 + hw/pci/pci.c | 10 ++++++---- hw/pci/trace-events | 5 +++-- hw/vfio/common.c | 16 +++++++++++++++- hw/vfio/pci.c | 1 + hw/vfio/trace-events | 9 ++++++--- trace-events | 2 ++ 10 files changed, 45 insertions(+), 13 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 63ef6af..5511ea7 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -46,6 +46,7 @@ #include "sysemu/reset.h" #include "hw/boards.h" +#include "trace-root.h" /* This check must be after config-host.h is included */ #ifdef CONFIG_EVENTFD @@ -1670,7 +1671,7 @@ int kvm_irqchip_add_msi_route(KVMState *s, int vector, PCIDevice *dev) } trace_kvm_irqchip_add_msi_route(dev ? dev->name : (char *)"N/A", - vector, virq); + vector, virq, msg.address, msg.data); kvm_add_routing_entry(s, &kroute); kvm_arch_add_msi_route_post(&kroute, vector, dev); @@ -1717,6 +1718,7 @@ static int kvm_irqchip_assign_irqfd(KVMState *s, EventNotifier *event, { int fd = event_notifier_get_fd(event); int rfd = resample ? event_notifier_get_fd(resample) : -1; + int ret; struct kvm_irqfd irqfd = { .fd = fd, @@ -1758,7 +1760,9 @@ static int kvm_irqchip_assign_irqfd(KVMState *s, EventNotifier *event, return -ENOSYS; } - return kvm_vm_ioctl(s, KVM_IRQFD, &irqfd); + ret = kvm_vm_ioctl(s, KVM_IRQFD, &irqfd); + trace_kvm_irqchip_assign_irqfd(fd, virq, rfd, ret); + return ret; } int kvm_irqchip_add_adapter_route(KVMState *s, AdapterInfo *adapter) diff --git a/accel/kvm/trace-events b/accel/kvm/trace-events index a68eb66..67a01e6 100644 --- a/accel/kvm/trace-events +++ b/accel/kvm/trace-events @@ -9,7 +9,8 @@ kvm_device_ioctl(int fd, int type, void *arg) "dev fd %d, type 0x%x, arg %p" kvm_failed_reg_get(uint64_t id, const char *msg) "Warning: Unable to retrieve ONEREG %" PRIu64 " from KVM: %s" kvm_failed_reg_set(uint64_t id, const char *msg) "Warning: Unable to set ONEREG %" PRIu64 " to KVM: %s" kvm_irqchip_commit_routes(void) "" -kvm_irqchip_add_msi_route(char *name, int vector, int virq) "dev %s vector %d virq %d" +kvm_irqchip_add_msi_route(char *name, int vector, int virq, uint64_t addr, uint32_t data) "%s, vector %d, virq %d, msg {addr 0x%"PRIx64", data 0x%x}" +kvm_irqchip_assign_irqfd(int fd, int virq, int rfd, int status) "(fd=%d, virq=%d, rfd=%d) KVM_IRQFD returns %d" kvm_irqchip_update_msi_route(int virq) "Updating MSI route virq=%d" kvm_irqchip_release_virq(int virq) "virq %d" kvm_set_ioeventfd_mmio(int fd, uint64_t addr, uint32_t val, bool assign, uint32_t size, bool datamatch) "fd: %d @0x%" PRIx64 " val=0x%x assign: %d size: %d match: %d" diff --git a/exec.c b/exec.c index 5473c09..dd99ee0 100644 --- a/exec.c +++ b/exec.c @@ -2319,6 +2319,9 @@ static void ram_block_add(RAMBlock *new_block, Error **errp, bool shared) } ram_block_notify_add(new_block->host, new_block->max_length); } + trace_ram_block_add(new_block->host, new_block->max_length, + memory_region_name(new_block->mr), + new_block->mr->readonly ? "ro" : "rw"); } #ifdef CONFIG_POSIX diff --git a/hw/pci/msix.c b/hw/pci/msix.c index 67e34f3..65a2882 100644 --- a/hw/pci/msix.c +++ b/hw/pci/msix.c @@ -189,6 +189,7 @@ static void msix_table_mmio_write(void *opaque, hwaddr addr, int vector = addr / PCI_MSIX_ENTRY_SIZE; bool was_masked; + trace_msix_table_mmio_write(dev->name, addr, val, size); was_masked = msix_is_masked(dev, vector); pci_set_long(dev->msix_table + addr, val); msix_handle_mask_update(dev, vector, was_masked); diff --git a/hw/pci/pci.c b/hw/pci/pci.c index c2e1509..6142411 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -1324,9 +1324,11 @@ void pci_update_mappings(PCIDevice *d) PCIIORegion *r; int i; pcibus_t new_addr; + const char *name; for(i = 0; i < PCI_NUM_REGIONS; i++) { r = &d->io_regions[i]; + name = r->memory ? r->memory->name : ""; /* this region isn't registered */ if (!r->size) @@ -1340,18 +1342,18 @@ void pci_update_mappings(PCIDevice *d) /* now do the real mapping */ if (r->addr != PCI_BAR_UNMAPPED) { - trace_pci_update_mappings_del(d, pci_dev_bus_num(d), + trace_pci_update_mappings_del(d->name, pci_dev_bus_num(d), PCI_SLOT(d->devfn), PCI_FUNC(d->devfn), - i, r->addr, r->size); + i, r->addr, r->size, name); memory_region_del_subregion(r->address_space, r->memory); } r->addr = new_addr; if (r->addr != PCI_BAR_UNMAPPED) { - trace_pci_update_mappings_add(d, pci_dev_bus_num(d), + trace_pci_update_mappings_add(d->name, pci_dev_bus_num(d), PCI_SLOT(d->devfn), PCI_FUNC(d->devfn), - i, r->addr, r->size); + i, r->addr, r->size, name); memory_region_add_subregion_overlap(r->address_space, r->addr, r->memory, 1); } diff --git a/hw/pci/trace-events b/hw/pci/trace-events index def4b39..6dd7015 100644 --- a/hw/pci/trace-events +++ b/hw/pci/trace-events @@ -1,8 +1,8 @@ # See docs/devel/tracing.txt for syntax documentation. # pci.c -pci_update_mappings_del(void *d, uint32_t bus, uint32_t slot, uint32_t func, int bar, uint64_t addr, uint64_t size) "d=%p %02x:%02x.%x %d,0x%"PRIx64"+0x%"PRIx64 -pci_update_mappings_add(void *d, uint32_t bus, uint32_t slot, uint32_t func, int bar, uint64_t addr, uint64_t size) "d=%p %02x:%02x.%x %d,0x%"PRIx64"+0x%"PRIx64 +pci_update_mappings_del(const char *dname, uint32_t bus, uint32_t slot, uint32_t func, int bar, uint64_t addr, uint64_t size, const char *name) "%s %02x:%02x.%x [%d] 0x%"PRIx64", 0x%"PRIx64"B \"%s\"" +pci_update_mappings_add(const char *dname, uint32_t bus, uint32_t slot, uint32_t func, int bar, uint64_t addr, uint64_t size, const char *name) "%s %02x:%02x.%x [%d] 0x%"PRIx64", 0x%"PRIx64"B \"%s\"" # pci_host.c pci_cfg_read(const char *dev, unsigned devid, unsigned fnid, unsigned offs, unsigned val) "%s %02u:%u @0x%x -> 0x%x" @@ -10,3 +10,4 @@ pci_cfg_write(const char *dev, unsigned devid, unsigned fnid, unsigned offs, uns # msix.c msix_write_config(char *name, bool enabled, bool masked) "dev %s enabled %d masked %d" +msix_table_mmio_write(char *name, uint64_t addr, uint64_t val, unsigned size) "(%s, @%"PRId64", 0x%"PRIx64", %dB)" diff --git a/hw/vfio/common.c b/hw/vfio/common.c index a51a093..23c8bf3 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -304,6 +304,8 @@ static int vfio_dma_unmap(VFIOContainer *container, return 0; } + trace_vfio_dma_unmap(container->fd, iova, size); + while (ioctl(container->fd, VFIO_IOMMU_UNMAP_DMA, &unmap)) { /* * The type1 backend has an off-by-one bug in the kernel (71a7d3d78e3c @@ -327,6 +329,11 @@ static int vfio_dma_unmap(VFIOContainer *container, return -errno; } + if (unmap.size != size) { + error_printf("warn: VFIO_UNMAP_DMA(0x%lx, 0x%lx) only unmaps 0x%llx", + iova, size, unmap.size); + } + return 0; } @@ -345,6 +352,9 @@ static int vfio_dma_map(VFIOContainer *container, hwaddr iova, return 0; } + trace_vfio_dma_map(container->fd, iova, size, vaddr, + (readonly ? "r" : "rw")); + if (!readonly) { map.flags |= VFIO_DMA_MAP_FLAG_WRITE; } @@ -985,7 +995,8 @@ int vfio_region_mmap(VFIORegion *region) trace_vfio_region_mmap(memory_region_name(®ion->mmaps[i].mem), region->mmaps[i].offset, region->mmaps[i].offset + - region->mmaps[i].size - 1); + region->mmaps[i].size - 1, + region->mmaps[i].mmap); } return 0; @@ -1696,6 +1707,9 @@ retry: goto retry; } + trace_vfio_region(vbasedev->name, index, (*info)->offset, (*info)->size, + (*info)->cap_offset, (*info)->flags); + return 0; } diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index f72e277..d74e078 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -41,6 +41,7 @@ #include "trace.h" #include "qapi/error.h" #include "migration/blocker.h" +#include "trace-root.h" #define TYPE_VFIO_PCI "vfio-pci" #define PCI_VFIO(obj) OBJECT_CHECK(VFIOPCIDevice, obj, TYPE_VFIO_PCI) diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index 10d899c..83cd0a6 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -25,7 +25,7 @@ vfio_pci_size_rom(const char *name, int size) "%s ROM size 0x%x" vfio_vga_write(uint64_t addr, uint64_t data, int size) " (0x%"PRIx64", 0x%"PRIx64", %d)" vfio_vga_read(uint64_t addr, int size, uint64_t data) " (0x%"PRIx64", %d) = 0x%"PRIx64 vfio_pci_read_config(const char *name, int addr, int len, int val) " (%s, @0x%x, len=0x%x) 0x%x" -vfio_pci_write_config(const char *name, int addr, int val, int len) " (%s, @0x%x, 0x%x, len=0x%x)" +vfio_pci_write_config(const char *name, int addr, int val, int len) "(%s, @0x%x, 0x%x, 0x%xB)" vfio_msi_setup(const char *name, int pos) "%s PCI MSI CAP @0x%x" vfio_msix_early_setup(const char *name, int pos, int table_bar, int offset, int entries) "%s PCI MSI-X CAP @0x%x, BAR %d, offset 0x%x, entries %d" vfio_check_pcie_flr(const char *name) "%s Supports FLR via PCIe cap" @@ -37,7 +37,7 @@ vfio_pci_hot_reset_dep_devices(int domain, int bus, int slot, int function, int vfio_pci_hot_reset_result(const char *name, const char *result) "%s hot reset: %s" vfio_populate_device_config(const char *name, unsigned long size, unsigned long offset, unsigned long flags) "Device %s config:\n size: 0x%lx, offset: 0x%lx, flags: 0x%lx" vfio_populate_device_get_irq_info_failure(const char *errstr) "VFIO_DEVICE_GET_IRQ_INFO failure: %s" -vfio_realize(const char *name, int group_id) " (%s) group %d" +vfio_realize(const char *name, int group_id) "(%s) group %d" vfio_mdev(const char *name, bool is_mdev) " (%s) is_mdev %d" vfio_add_ext_cap_dropped(const char *name, uint16_t cap, uint16_t offset) "%s 0x%x@0x%x" vfio_pci_reset(const char *name) " (%s)" @@ -109,7 +109,7 @@ vfio_get_device(const char * name, unsigned int flags, unsigned int num_regions, vfio_put_base_device(int fd) "close vdev->fd=%d" vfio_region_setup(const char *dev, int index, const char *name, unsigned long flags, unsigned long offset, unsigned long size) "Device %s, region %d \"%s\", flags: 0x%lx, offset: 0x%lx, size: 0x%lx" vfio_region_mmap_fault(const char *name, int index, unsigned long offset, unsigned long size, int fault) "Region %s mmaps[%d], [0x%lx - 0x%lx], fault: %d" -vfio_region_mmap(const char *name, unsigned long offset, unsigned long end) "Region %s [0x%lx - 0x%lx]" +vfio_region_mmap(const char *name, unsigned long offset, unsigned long end, void *addr) "%s [0x%lx - 0x%lx] maps to %p" vfio_region_exit(const char *name, int index) "Device %s, region %d" vfio_region_finalize(const char *name, int index) "Device %s, region %d" vfio_region_mmaps_set_enabled(const char *name, bool enabled) "Region %s mmaps enabled: %d" @@ -117,6 +117,9 @@ vfio_region_sparse_mmap_header(const char *name, int index, int nr_areas) "Devic vfio_region_sparse_mmap_entry(int i, unsigned long start, unsigned long end) "sparse entry %d [0x%lx - 0x%lx]" vfio_get_dev_region(const char *name, int index, uint32_t type, uint32_t subtype) "%s index %d, %08x/%0x8" vfio_dma_unmap_overflow_workaround(void) "" +vfio_dma_unmap(int fd, uint64_t iova, uint64_t size) "fd %d, iova 0x%"PRIx64", len 0x%"PRIx64 +vfio_dma_map(int fd, uint64_t iova, uint64_t size, void *addr, const char *access) "fd %d, iova 0x%"PRIx64", len 0x%"PRIx64", va %p, %s" +vfio_region(const char *name, int index, uint64_t offset, uint64_t size, int cap_offset, int flags) "%s [%d]: +0x%"PRIx64", 0x%"PRIx64"B, cap +0x%x, flags 0x%x" # platform.c vfio_platform_base_device_init(char *name, int groupid) "%s belongs to group #%d" diff --git a/trace-events b/trace-events index 42107eb..98589a4 100644 --- a/trace-events +++ b/trace-events @@ -107,6 +107,8 @@ qmp_job_complete(void *job) "job %p" qmp_job_finalize(void *job) "job %p" qmp_job_dismiss(void *job) "job %p" +# exec.c +ram_block_add(void *host, uint64_t maxlen, const char *name, const char *mode) "host=%p, maxlen=0x%"PRIx64", mr = {name=%s, %s}" ### Guest events, keep at bottom