From nobody Sun May 5 14:17:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1620391171; cv=none; d=zohomail.com; s=zohoarc; b=Zw+/zrFwjbV+tPUi7+uTeC94nr/2cduKmFu5JNDHDLlyP5BpyewVMPQkr5Se1gzQqWC6XVKRj+mS6Cvw8HUKN8eo0fdcY8um7Zb7n8MdCIom6XnmTSewgZIcmZLS0bmLCY1A7r8wCJ2UMcw6wyAWo+GrVC2Zqc7F/5eZXu+oxjs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620391171; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=fM+XV4xsrJ0PL8iFkG3vUaunvGZ6nUCTkbxCVv9GgRc=; b=lOWUvsjeUYXojPn7+TtnyUoDPzxzi9197S5B7DkU46R+tCVhpK/GI4fI61Q+B0ogYpFkhbbxcCojGGl/HswhfbSFXtmHVYzOqz4B+QLX0TOUbd2JKhnlmR+ITr6DdK19rcq3GXAWOGf/bxkZ3u5J3HQb9OAwTtSfqy6MDfSe8q4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620391171150211.77517159820377; Fri, 7 May 2021 05:39:31 -0700 (PDT) Received: from localhost ([::1]:57234 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lezlR-0000kh-8i for importer@patchew.org; Fri, 07 May 2021 08:39:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57216) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbP-0000VN-MM for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:07 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:40470) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbG-0001Q1-IL for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:07 -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 147CDx3a096787; Fri, 7 May 2021 12:28:53 GMT Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 38ctd89d15-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:28:53 +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 147CFkKJ168068; Fri, 7 May 2021 12:28:53 GMT Received: from pps.reinject (localhost [127.0.0.1]) by userp3020.oracle.com with ESMTP id 38csrh1sv4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:28:53 +0000 Received: from userp3020.oracle.com (userp3020.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 147CSqAO014186; Fri, 7 May 2021 12:28:52 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3020.oracle.com with ESMTP id 38csrh1su6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:28:52 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 147CSoxC016365; Fri, 7 May 2021 12:28:50 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 07 May 2021 05:28:49 -0700 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=fM+XV4xsrJ0PL8iFkG3vUaunvGZ6nUCTkbxCVv9GgRc=; b=UKBAJgRvsOjZK3iLXOx9nn74tygy8tqHF0JEsPLRAtN0RqppUphu7wr4hoJJd+mVmphH ZCWSMuPyox9YtKcrAMQYxXgkSDM4oMqYwpvFPBzBBsVrpiZMXh7yQ76xRE1T5o5Ln5F6 kouev89pBcj1cTCRgtC9iBtI0NkqDpVcY1lcfQzY21LYhXCiu2R/LvhjvF8RToHTtha1 yhyWcnxiizrqcKVpj6SpktjoSbOYhAzuD3J4fPb4V+9u5OT2kLao7jCNqhBzUhgSkeOo TCVFBlQ/TJPJoK1kW75YhjxaQHBTF+yKQLQHN+5UPaSGmeGH6bQyRdqvXFpgidPD6NC/ VA== From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V3 01/22] as_flat_walk Date: Fri, 7 May 2021 05:24:59 -0700 Message-Id: <1620390320-301716-2-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> References: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-GUID: 4Ap3RWcocOSL9lU7LYBrZKcYeZFgslAd X-Proofpoint-ORIG-GUID: 4Ap3RWcocOSL9lU7LYBrZKcYeZFgslAd X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9976 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 adultscore=0 clxscore=1015 spamscore=0 mlxlogscore=999 priorityscore=1501 lowpriorityscore=0 phishscore=0 suspectscore=0 impostorscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105070085 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=156.151.31.86; envelope-from=steven.sistare@oracle.com; helo=userp2130.oracle.com X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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" , Jason Zeng , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add an iterator over the sections of a flattened address space. Signed-off-by: Steve Sistare --- include/exec/memory.h | 17 +++++++++++++++++ softmmu/memory.c | 18 ++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/include/exec/memory.h b/include/exec/memory.h index 5728a68..2e5495a 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -2003,6 +2003,23 @@ bool memory_region_present(MemoryRegion *container, = hwaddr addr); */ bool memory_region_is_mapped(MemoryRegion *mr); =20 +typedef int (*qemu_flat_walk_cb)(MemoryRegionSection *s, + void *handle, + Error **errp); + +/** + * as_flat_walk: walk the ranges in the address space flat view and call @= func + * for each. Return 0 on success, else return non-zero with a message in + * @errp. + * + * @as: target address space + * @func: callback function + * @handle: passed to @func + * @errp: passed to @func + */ +int as_flat_walk(AddressSpace *as, qemu_flat_walk_cb func, + void *handle, Error **errp); + /** * memory_region_find: translate an address/size relative to a * MemoryRegion into a #MemoryRegionSection. diff --git a/softmmu/memory.c b/softmmu/memory.c index d4493ef..75d7d17 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -2570,6 +2570,24 @@ bool memory_region_is_mapped(MemoryRegion *mr) return mr->container ? true : false; } =20 +int as_flat_walk(AddressSpace *as, qemu_flat_walk_cb func, + void *handle, Error **errp) +{ + FlatView *view =3D address_space_get_flatview(as); + FlatRange *fr; + int ret; + + FOR_EACH_FLAT_RANGE(fr, view) { + MemoryRegionSection section =3D section_from_flat_range(fr, view); + ret =3D func(§ion, handle, errp); + if (ret) { + return ret; + } + } + + return 0; +} + /* Same as memory_region_find, but it does not add a reference to the * returned region. It must be called from an RCU critical section. */ --=20 1.8.3.1 From nobody Sun May 5 14:17:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1620391007; cv=none; d=zohomail.com; s=zohoarc; b=F+MWYxSAe97EX6lEMBAZrrfgqFid1xhHz1xxcF0Zd2kfQLqOOTfbiyK3dn9QoLJdcXARPEwkR0AmwEgMdlkO9H0J3w41MJFrZPEnDV4ETepQcziMH8oGgv/DgtwtJSCaNiM34toIMgKycrlYjPcZWkX0XJyzSavMmoj9mw2a1UA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620391007; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=lQBJ44QptfFTTE/3XPI+XHOEqOspc+Cq3thya32ShGc=; b=ZRD5G00Z3o+jdMWGdDvePFsyIugTFnsKNJ6X0GFTZJDsMzovUWjjdO2hWpHNr69aczfzOtuYT941ANanrkAuSniIJrtaWBIUbiWlpnEV/0QGWgziSX4QYmRGZZd0U2zTnDRjQMVqf4osaYBvkQFKPBPUx5PTieTS08oo+/i2nvo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620391007046286.3080576922929; Fri, 7 May 2021 05:36:47 -0700 (PDT) Received: from localhost ([::1]:49156 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lezio-0005ti-4m for importer@patchew.org; Fri, 07 May 2021 08:36:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57246) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbQ-0000Wf-9y for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:08 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:49842) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbI-0001Ph-7b for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:08 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 147CDl5Z148701; Fri, 7 May 2021 12:28:54 GMT Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2130.oracle.com with ESMTP id 38csrd9ew4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:28:53 +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 147CFMV0031113; Fri, 7 May 2021 12:28:53 GMT Received: from pps.reinject (localhost [127.0.0.1]) by userp3030.oracle.com with ESMTP id 38css8ss0e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:28:53 +0000 Received: from userp3030.oracle.com (userp3030.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 147CSqXK071367; Fri, 7 May 2021 12:28:52 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 38css8sry0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:28:52 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 147CSoX5017174; Fri, 7 May 2021 12:28:50 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 07 May 2021 05:28:50 -0700 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=lQBJ44QptfFTTE/3XPI+XHOEqOspc+Cq3thya32ShGc=; b=uduTUsJ7SKKI189DJw/WD51jc2O9HcMJiWQdQkhqb5BDcSFVwnZYRSD5ghVlfdtRxlVN 1ebL+GB4mXC40yMkKcr4jDkT1QfLVS5VyHPxCCHUZ5i8P/5wNj9byQEYRq3fMPWT3qXe ZBjMcWHdGFmGcl1PGqZPHbMCxcLbJvTevq1dmCzCR0IAK3MOmzY2Kld9TclycaGBhJxR 1dzlWf1TxM5aDx0WeEViOaZRXW9+IUrUHqfm8V906FxACzj3Nl1WXnqNZaY+XwRH5byi RUB8Wwm6F23jD/NNmJYdjEyBhnf6g6EAxEhnEZ7qpgZB3m3Rsfyfy/rG+uQSAmJiS8RQ HA== From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V3 02/22] qemu_ram_volatile Date: Fri, 7 May 2021 05:25:00 -0700 Message-Id: <1620390320-301716-3-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> References: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-ORIG-GUID: ibaBaQ8Ch7tA6zW18AhNpPGZavo3Buav X-Proofpoint-GUID: ibaBaQ8Ch7tA6zW18AhNpPGZavo3Buav X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9976 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 clxscore=1015 malwarescore=0 adultscore=0 mlxlogscore=999 impostorscore=0 phishscore=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105070085 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=141.146.126.79; envelope-from=steven.sistare@oracle.com; helo=aserp2130.oracle.com X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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" , Jason Zeng , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add a function that returns true if any ram_list block represents volatile memory. Signed-off-by: Steve Sistare --- include/exec/memory.h | 8 ++++++++ softmmu/memory.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/include/exec/memory.h b/include/exec/memory.h index 2e5495a..d87c059 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -2646,6 +2646,14 @@ bool ram_block_discard_is_disabled(void); */ bool ram_block_discard_is_required(void); =20 +/** + * qemu_ram_volatile: return true if any memory regions are writable and n= ot + * backed by shared memory. + * + * @errp: returned error message identifying the bad region. + */ +bool qemu_ram_volatile(Error **errp); + #endif =20 #endif diff --git a/softmmu/memory.c b/softmmu/memory.c index 75d7d17..b2d5092 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -2725,6 +2725,36 @@ void memory_global_dirty_log_stop(void) memory_global_dirty_log_do_stop(); } =20 +/* + * Return true if any memory regions are writable and not backed by shared + * memory. + */ +bool qemu_ram_volatile(Error **errp) +{ + RAMBlock *block; + MemoryRegion *mr; + bool ret =3D false; + + rcu_read_lock(); + QLIST_FOREACH_RCU(block, &ram_list.blocks, next) { + mr =3D block->mr; + if (mr && + memory_region_is_ram(mr) && + !memory_region_is_ram_device(mr) && + !memory_region_is_rom(mr) && + (block->fd =3D=3D -1 || !qemu_ram_is_shared(block))) { + + error_setg(errp, "Memory region %s is volatile", + memory_region_name(mr)); + ret =3D true; + break; + } + } + + rcu_read_unlock(); + return ret; +} + static void listener_add_address_space(MemoryListener *listener, AddressSpace *as) { --=20 1.8.3.1 From nobody Sun May 5 14:17:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1620391002; cv=none; d=zohomail.com; s=zohoarc; b=L3NfBmwJTVrgUgyNbhqmvTT4wBTwZ149SDIA7RRV+RDOK3QeMnZwPCX1PY0Ok5k+EX2YblBytFE8y9CiTuWCRDg0mmoTm79BYgKjnPx+KarcJc5HKfa4sAMBJSCFst/LSy1jr3+tLZKD/XxRD1DaABtB5xDsETBmeJFoKIhjIr8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620391002; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=N+f3B62Uq69OXUk1DnFhmpdUjDdZh056FJ3uuY5Hj7Y=; b=agqhVN9xF34hNckn4cgaQC9p+su5xZmJMPViXKoDSgAv/NS5n7opANthZ9ccnsHgio4IBD2MWz1crSPeFgFyVFfKJz7+BCetGQ1z7nymJDWWRC11tk0zoLBzRPvr0NenwJEcfSTqZj0WXkYZsPbGAPlGp9t3wCQUxfTWZydVjzs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620391002973578.9661441121872; Fri, 7 May 2021 05:36:42 -0700 (PDT) Received: from localhost ([::1]:48744 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lezij-0005gi-RQ for importer@patchew.org; Fri, 07 May 2021 08:36:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57212) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbP-0000V1-Gq for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:07 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:40474) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbG-0001Q4-Q2 for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:07 -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 147CDx3b096787; Fri, 7 May 2021 12:28:54 GMT Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 38ctd89d16-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:28:54 +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 147CFMRP031133; Fri, 7 May 2021 12:28:54 GMT Received: from pps.reinject (localhost [127.0.0.1]) by userp3030.oracle.com with ESMTP id 38css8ss1b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:28:54 +0000 Received: from userp3030.oracle.com (userp3030.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 147CSr19071397; Fri, 7 May 2021 12:28:53 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3030.oracle.com with ESMTP id 38css8sryw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:28:53 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 147CSpPQ019242; Fri, 7 May 2021 12:28:51 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 07 May 2021 05:28:51 -0700 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=N+f3B62Uq69OXUk1DnFhmpdUjDdZh056FJ3uuY5Hj7Y=; b=CODJniWneUDE4/AYkhPFATPnp6iBKUDIVYUPjP7ZRrUrW3EM0ft60Zit+8AoePvM8+U/ 5YsjPZ/taux6GUjNS+oBuH+b4nJbgp9J2BEMlDag6GhrdQijaXC7nJEtELBx/jvFsZY/ XVwy4RPH+hRHv69xcHhpHYFYjg58NJ1St+dsG5mTuQz5gcazuraBdsIO7ALiBvqEcx+6 DoIQVdHXpyoh/4wRvzSstmXOPF4iP903gRStrwulaVYZykTowAh+Yxxvq5PLaUV5k8X3 BHBrxzJRgKG1NfacK2Yez7WFXTPaZJ2QutcIuL1NT2p1Hn+Bh++Wsj3jpCO2bXw5ZAM9 GA== From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V3 03/22] oslib: qemu_clr_cloexec Date: Fri, 7 May 2021 05:25:01 -0700 Message-Id: <1620390320-301716-4-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> References: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-GUID: wXzCdmWYisY22YWLmpXUQm_gJWzNkfR- X-Proofpoint-ORIG-GUID: wXzCdmWYisY22YWLmpXUQm_gJWzNkfR- X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9976 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 adultscore=0 clxscore=1015 spamscore=0 mlxlogscore=999 priorityscore=1501 lowpriorityscore=0 phishscore=0 suspectscore=0 impostorscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105070085 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=156.151.31.86; envelope-from=steven.sistare@oracle.com; helo=userp2130.oracle.com X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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" , Jason Zeng , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Define qemu_clr_cloexec, analogous to qemu_set_cloexec. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Steve Sistare --- include/qemu/osdep.h | 1 + util/oslib-posix.c | 9 +++++++++ util/oslib-win32.c | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index cb2a07e..de06e60 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -577,6 +577,7 @@ static inline void qemu_timersub(const struct timeval *= val1, #endif =20 void qemu_set_cloexec(int fd); +void qemu_clr_cloexec(int fd); =20 /* Starting on QEMU 2.5, qemu_hw_version() returns "2.5+" by default * instead of QEMU_VERSION, so setting hw_version on MachineClass diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 36820fe..ac9229d 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -317,6 +317,15 @@ void qemu_set_cloexec(int fd) assert(f !=3D -1); } =20 +void qemu_clr_cloexec(int fd) +{ + int f; + f =3D fcntl(fd, F_GETFD); + assert(f !=3D -1); + f =3D fcntl(fd, F_SETFD, f & ~FD_CLOEXEC); + assert(f !=3D -1); +} + /* * Creates a pipe with FD_CLOEXEC set on both file descriptors */ diff --git a/util/oslib-win32.c b/util/oslib-win32.c index f68b801..b5c53b3 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -251,6 +251,10 @@ void qemu_set_cloexec(int fd) { } =20 +void qemu_clr_cloexec(int fd) +{ +} + /* Offset between 1/1/1601 and 1/1/1970 in 100 nanosec units */ #define _W32_FT_OFFSET (116444736000000000ULL) =20 --=20 1.8.3.1 From nobody Sun May 5 14:17:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1620390748; cv=none; d=zohomail.com; s=zohoarc; b=Iz+dr/42k/usRirGVdpAcVUEeXG61MmYJrm870ecU8x3ijczl4BNzVUv9+TDub/bF9BtiALTpHCuhL9mR/BgeAN2QVzzXC26Y6Q4cIHCqT/zHBeI5jAPwkpaBZpJEiiCkiI48DCNGRfGsUJTxb7kfhhLvbML1P0BA5k2Qw/QR1A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620390748; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=ARpEyzI3y4U8V40/CLSccsjvztc225pgFKz6D2WIVmQ=; b=RgIraCHOJMhI6RXOm359G85Gkv2X6HrdZntzXLjJOMQTKvuxRuYalNPLCFpbvrZ7lu/DZG+unOHS/c2zDXcompOT6nXYxKQy10wl5s2A/GThKXzik4OJffWabZtn7xaRLlTbezrx30pQd24m/giEltcR0DdjOhEI9NMaioc2FyY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620390748785197.49221690275374; Fri, 7 May 2021 05:32:28 -0700 (PDT) Received: from localhost ([::1]:40350 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lezed-0002Fx-EP for importer@patchew.org; Fri, 07 May 2021 08:32:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57164) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbK-0000RY-Qf for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:02 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:60344) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbI-0001Qm-9d for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29: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 147CETEG126746; Fri, 7 May 2021 12:28:56 GMT Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 38ctjv1cbf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:28:55 +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 147CFlmb168407; Fri, 7 May 2021 12:28:55 GMT Received: from pps.reinject (localhost [127.0.0.1]) by userp3020.oracle.com with ESMTP id 38csrh1sxb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:28:55 +0000 Received: from userp3020.oracle.com (userp3020.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 147CPaH6002524; Fri, 7 May 2021 12:28:54 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3020.oracle.com with ESMTP id 38csrh1swb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:28:54 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 147CSqET016385; Fri, 7 May 2021 12:28:52 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 07 May 2021 05:28:52 -0700 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=ARpEyzI3y4U8V40/CLSccsjvztc225pgFKz6D2WIVmQ=; b=XKi0OzIrubAH99Ru8UUTXqJ+IJ6hEGxsPjz+/20Wyk5OWSbrRgiKmjWh4gNx/v/Cdwky 69nLiK1B2tEG5vNi1LGctkShm90COoy4D/QBe9tV/IOwAL+oSSqbroAxXBKLmTj+FwPh AUrGod0V37Ym6IWbKSYPdCQExpNFOdVTzxjG7udIUiNBT5rcRwMvRbVNeY6EfpaxM9ps SL6Yj0RG0anWqNhbIQbmfGNvWaRiKpUGqSUEUG9MJv++xJdCTgudO/lZKi2rPbZxQncU /UxHE0qr+SsT4yC1Sge2+XSZQEv3yg/rI6sb0JXxjuq4FDTNOotbxmtPyWPrZsvVcWwp Eg== From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V3 04/22] util: env var helpers Date: Fri, 7 May 2021 05:25:02 -0700 Message-Id: <1620390320-301716-5-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> References: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-ORIG-GUID: VINH-8nMuODkwvsR9W4t5AjVhKvXKvN5 X-Proofpoint-GUID: VINH-8nMuODkwvsR9W4t5AjVhKvXKvN5 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9976 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 mlxscore=0 clxscore=1015 priorityscore=1501 bulkscore=0 suspectscore=0 lowpriorityscore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105070085 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=141.146.126.78; envelope-from=steven.sistare@oracle.com; helo=aserp2120.oracle.com X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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_BL=0.001, RCVD_IN_MSPIKE_L4=0.001, 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" , Jason Zeng , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add functions for saving fd's and other values in the environment via setenv, and for reading them back via getenv. Signed-off-by: Steve Sistare --- include/qemu/env.h | 23 +++++++++++++ util/env.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++= ++++ util/meson.build | 1 + 3 files changed, 123 insertions(+) create mode 100644 include/qemu/env.h create mode 100644 util/env.c diff --git a/include/qemu/env.h b/include/qemu/env.h new file mode 100644 index 0000000..3dad503 --- /dev/null +++ b/include/qemu/env.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2021 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_" + +typedef int (*walkenv_cb)(const char *name, const char *val, void *handle); + +int getenv_fd(const char *name); +void setenv_fd(const char *name, int fd); +void unsetenv_fd(const char *name); +void unsetenv_fdv(const char *fmt, ...); +int walkenv(const char *prefix, walkenv_cb cb, void *handle); +void printenv(void); + +#endif diff --git a/util/env.c b/util/env.c new file mode 100644 index 0000000..b09ba05 --- /dev/null +++ b/util/env.c @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2021 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 *f= ound) +{ + char var[80], *val; + uint64_t res; + + snprintf(var, sizeof(var), "%s%s", prefix, name); + val =3D getenv(var); + if (val) { + *found =3D true; + res =3D strtol(val, 0, 10); + } else { + *found =3D false; + res =3D 0; + } + return res; +} + +static void setenv_ulong(const char *prefix, const char *name, uint64_t va= l) +{ + 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); +} + +int getenv_fd(const char *name) +{ + bool found; + int fd =3D getenv_ulong(FD_PREFIX, name, &found); + if (!found) { + fd =3D -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); +} + +void unsetenv_fdv(const char *fmt, ...) +{ + va_list args; + char buf[80]; + va_start(args, fmt); + vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); +} + +int walkenv(const char *prefix, walkenv_cb cb, void *handle) +{ + char *str, name[128]; + char **envp =3D environ; + size_t prefix_len =3D strlen(prefix); + + while (*envp) { + str =3D *envp++; + if (!strncmp(str, prefix, prefix_len)) { + char *val =3D strchr(str, '=3D'); + str +=3D prefix_len; + strncpy(name, str, val - str); + name[val - str] =3D 0; + if (cb(name, val + 1, handle)) { + return 1; + } + } + } + return 0; +} + +void printenv(void) +{ + char **ptr =3D environ; + while (*ptr) { + puts(*ptr++); + } +} diff --git a/util/meson.build b/util/meson.build index 510765c..d2d90cc 100644 --- a/util/meson.build +++ b/util/meson.build @@ -22,6 +22,7 @@ util_ss.add(files('host-utils.c')) util_ss.add(files('bitmap.c', 'bitops.c')) util_ss.add(files('fifo8.c')) util_ss.add(files('cacheinfo.c', 'cacheflush.c')) +util_ss.add(files('env.c')) util_ss.add(files('error.c', 'qemu-error.c')) util_ss.add(files('qemu-print.c')) util_ss.add(files('id.c')) --=20 1.8.3.1 From nobody Sun May 5 14:17:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1620390760; cv=none; d=zohomail.com; s=zohoarc; b=LNKgEkwe2iuIfiysutSsCXRlAJGwa2nDatrUDuKQxpAR+MPsCFyQq250LdlUwhPqbmy3fADb/DNLGdZZldNSkUbZGSKQZeUwAjbJJYniYsc1VPWh7UlTIIF5T5RRwWAnhB/9WqQwdwDczYtJr8iFFBmIckyfvpOplTAqwIHJE1A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620390760; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=p16l0WPBMG4jZxEyxo+4hfuLsJ7gQEWt4ArQ0Bp4BeU=; b=fvw7DifD3Elb16zLmRucz3rIdSDysJRsdYBHxvpZ4+f6AqAhjTV90XN3/GHs+tqj4CHCeFRDv7uorU9zu6y+yQqq/pXXAn9yY410rVRnWXuBtQV1b1COfOEnuo9oWNYZmtUTNErVtXqj22scYKlmI60kOFqfEbOfmDZzWTsORQ0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620390760140664.381959596783; Fri, 7 May 2021 05:32:40 -0700 (PDT) Received: from localhost ([::1]:40726 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lezep-0002PX-1U for importer@patchew.org; Fri, 07 May 2021 08:32:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57202) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbO-0000U5-W9 for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:07 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:43710) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbJ-0001RN-Um for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29: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 147CShOF050065; Fri, 7 May 2021 12:28:57 GMT Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 38csqvhemb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:28:57 +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 147CGPPi173683; Fri, 7 May 2021 12:28:56 GMT Received: from pps.reinject (localhost [127.0.0.1]) by aserp3020.oracle.com with ESMTP id 38csrtb63s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:28:56 +0000 Received: from aserp3020.oracle.com (aserp3020.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 147CStBV027798; Fri, 7 May 2021 12:28:55 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 38csrtb638-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:28:55 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 147CSr3a016393; Fri, 7 May 2021 12:28:53 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 07 May 2021 05:28:53 -0700 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=p16l0WPBMG4jZxEyxo+4hfuLsJ7gQEWt4ArQ0Bp4BeU=; b=LeaXzw3VIIT8ohCXBMT34YCSN0CwmSJonObGx4kE9kiTr0IZcKTybJwsay3weP1B4gNh 8q3I//iLsU7Ex6toyjnweRwxQ5yBrDAFA5Ro0wEzlpYJD8ks5596JmZ242glSyqnRWZq 7i7JilpDxuR7DxrXvHsqYZ5tuPabFlA4UxE2CwuZ/RNNqvvv7ZwgNq+slHyse5c43C72 fWrv6Oqt3GtSGbv/WHvqmVu+EpjPNF8jcNVPQEUAQ4Z/Ef9t1P5e2l94+v85v0izOG8Q 9yTioolTgKsLK/8Kf4WUhCf9CUzyDlGjntxnTzRMp0GgjIk6KQR3v2R5KC56SSNusR1a Hw== From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V3 05/22] machine: memfd-alloc option Date: Fri, 7 May 2021 05:25:03 -0700 Message-Id: <1620390320-301716-6-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> References: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-ORIG-GUID: UByTe6NBJB6nqW4hLIXRGw49e6vWpgIB X-Proofpoint-GUID: UByTe6NBJB6nqW4hLIXRGw49e6vWpgIB X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9976 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 bulkscore=0 adultscore=0 suspectscore=0 spamscore=0 impostorscore=0 phishscore=0 clxscore=1015 mlxscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105070086 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=156.151.31.85; envelope-from=steven.sistare@oracle.com; helo=userp2120.oracle.com X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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=-0.001, 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" , Jason Zeng , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Allocate anonymous memory using memfd_create if the memfd-alloc machine option is set. Signed-off-by: Steve Sistare --- hw/core/machine.c | 19 +++++++++++++++++++ include/hw/boards.h | 1 + qemu-options.hx | 5 +++++ softmmu/physmem.c | 41 ++++++++++++++++++++++++++++++++--------- trace-events | 1 + util/qemu-config.c | 4 ++++ 6 files changed, 62 insertions(+), 9 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 40def78..3ce5303 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -375,6 +375,20 @@ static void machine_set_mem_merge(Object *obj, bool va= lue, Error **errp) ms->mem_merge =3D value; } =20 +static bool machine_get_memfd_alloc(Object *obj, Error **errp) +{ + MachineState *ms =3D MACHINE(obj); + + return ms->memfd_alloc; +} + +static void machine_set_memfd_alloc(Object *obj, bool value, Error **errp) +{ + MachineState *ms =3D MACHINE(obj); + + ms->memfd_alloc =3D value; +} + static bool machine_get_usb(Object *obj, Error **errp) { MachineState *ms =3D MACHINE(obj); @@ -858,6 +872,11 @@ static void machine_class_init(ObjectClass *oc, void *= data) object_class_property_set_description(oc, "mem-merge", "Enable/disable memory merge support"); =20 + object_class_property_add_bool(oc, "memfd-alloc", + machine_get_memfd_alloc, machine_set_memfd_alloc); + object_class_property_set_description(oc, "memfd-alloc", + "Enable/disable allocating anonymous memory using memfd_create"); + object_class_property_add_bool(oc, "usb", machine_get_usb, machine_set_usb); object_class_property_set_description(oc, "usb", diff --git a/include/hw/boards.h b/include/hw/boards.h index ad6c8fd..dceb7f7 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -305,6 +305,7 @@ struct MachineState { char *dt_compatible; bool dump_guest_core; bool mem_merge; + bool memfd_alloc; bool usb; bool usb_disabled; char *firmware; diff --git a/qemu-options.hx b/qemu-options.hx index fd21002..3392ac0 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -30,6 +30,7 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ " vmport=3Don|off|auto controls emulation of vmport (de= fault: auto)\n" " dump-guest-core=3Don|off include guest memory in a co= re dump (default=3Don)\n" " mem-merge=3Don|off controls memory merge support (def= ault: on)\n" + " memfd-alloc=3Don|off controls allocating anonymous me= mory using memfd_create (default: off)\n" " aes-key-wrap=3Don|off controls support for AES key wr= apping (default=3Don)\n" " dea-key-wrap=3Don|off controls support for DEA key wr= apping (default=3Don)\n" " suppress-vmdesc=3Don|off disables self-describing mig= ration (default=3Doff)\n" @@ -76,6 +77,10 @@ SRST supported by the host, de-duplicates identical memory pages among VMs instances (enabled by default). =20 + ``memfd-alloc=3Don|off`` + Enables or disables allocation of anonymous memory using memfd_cre= ate. + (disabled by default). + ``aes-key-wrap=3Don|off`` Enables or disables AES key wrapping support on s390-ccw hosts. This feature controls whether AES wrapping keys will be created diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 85034d9..695aa10 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -67,6 +67,7 @@ =20 #include "qemu/pmem.h" =20 +#include "qemu/memfd.h" #include "migration/vmstate.h" =20 #include "qemu/range.h" @@ -1931,35 +1932,57 @@ static void ram_block_add(RAMBlock *new_block, Erro= r **errp, bool shared) { RAMBlock *block; RAMBlock *last_block =3D NULL; + struct MemoryRegion *mr =3D new_block->mr; ram_addr_t old_ram_size, new_ram_size; Error *err =3D NULL; + const char *name; + void *addr =3D 0; + size_t maxlen; + MachineState *ms =3D MACHINE(qdev_get_machine()); =20 old_ram_size =3D last_ram_page(); =20 qemu_mutex_lock_ramlist(); - new_block->offset =3D find_ram_offset(new_block->max_length); + maxlen =3D new_block->max_length; + new_block->offset =3D find_ram_offset(maxlen); =20 if (!new_block->host) { if (xen_enabled()) { - xen_ram_alloc(new_block->offset, new_block->max_length, - new_block->mr, &err); + xen_ram_alloc(new_block->offset, maxlen, new_block->mr, &err); if (err) { error_propagate(errp, err); qemu_mutex_unlock_ramlist(); return; } } else { - new_block->host =3D qemu_anon_ram_alloc(new_block->max_length, - &new_block->mr->align, - shared); - if (!new_block->host) { + name =3D memory_region_name(new_block->mr); + if (ms->memfd_alloc) { + int mfd =3D -1; /* placeholder until next patch */ + mr->align =3D QEMU_VMALLOC_ALIGN; + if (mfd < 0) { + mfd =3D qemu_memfd_create(name, maxlen + mr->align, + 0, 0, 0, &err); + if (mfd < 0) { + return; + } + } + new_block->flags |=3D RAM_SHARED; + addr =3D file_ram_alloc(new_block, maxlen, mfd, + false, false, 0, errp); + trace_anon_memfd_alloc(name, maxlen, addr, mfd); + } else { + addr =3D qemu_anon_ram_alloc(maxlen, &mr->align, shared); + } + + if (!addr) { error_setg_errno(errp, errno, "cannot set up guest memory '%s'", - memory_region_name(new_block->mr)); + name); qemu_mutex_unlock_ramlist(); return; } - memory_try_enable_merging(new_block->host, new_block->max_leng= th); + memory_try_enable_merging(addr, maxlen); + new_block->host =3D addr; } } =20 diff --git a/trace-events b/trace-events index ac7cef9..99e8208 100644 --- a/trace-events +++ b/trace-events @@ -40,6 +40,7 @@ ram_block_discard_range(const char *rbname, void *hva, si= ze_t length, bool need_ # accel/tcg/cputlb.c memory_notdirty_write_access(uint64_t vaddr, uint64_t ram_addr, unsigned s= ize) "0x%" PRIx64 " ram_addr 0x%" PRIx64 " size %u" memory_notdirty_set_dirty(uint64_t vaddr) "0x%" PRIx64 +anon_memfd_alloc(const char *name, size_t size, void *ptr, int fd) "%s siz= e %zu ptr %p fd %d" =20 # gdbstub.c gdbstub_op_start(const char *device) "Starting gdbstub using device %s" diff --git a/util/qemu-config.c b/util/qemu-config.c index 670bd6e..135ec3b 100644 --- a/util/qemu-config.c +++ b/util/qemu-config.c @@ -205,6 +205,10 @@ static QemuOptsList machine_opts =3D { .type =3D QEMU_OPT_BOOL, .help =3D "enable/disable memory merge support", },{ + .name =3D "memfd-alloc", + .type =3D QEMU_OPT_BOOL, + .help =3D "enable/disable memfd_create for anonymous memory", + },{ .name =3D "usb", .type =3D QEMU_OPT_BOOL, .help =3D "Set on/off to enable/disable usb", --=20 1.8.3.1 From nobody Sun May 5 14:17:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1620390759; cv=none; d=zohomail.com; s=zohoarc; b=OfuXnSWoay7ncE4E6NLiFQmpD60pxmH+CWJ5F01Dpfdt7XzEh7Hx5U0cixAFh9duS6tmbOr73D9/mmY0Bov29XG/3W19nXmtGontMMtk4i3taS70YAZfepBsf2eyPoKRZxCPXp1iMxl5oon4uoXMHoN4gRrblJgrQe0wmmqBx44= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620390759; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=HHD0ffPoFv2m54Poufo3HoNOdK4KuAozbrE4/GpZMyA=; b=LlIoQf0YzsrOAIwJtM7hc/J6Rm9ZGPZsTUoNdQsSYfF/docJcj278W03R7cCOeu7n0bo5KcFFV1RZL9oV28iMrPuXMAKcRMagpx5pL2BPse3I4f8J+IN8f41dEdX9E/QBiI/nUpAhR6fGgF3VL69GdZ+t4TrfSLaxFeGxr4IyGI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620390759008381.68311350679244; Fri, 7 May 2021 05:32:39 -0700 (PDT) Received: from localhost ([::1]:40620 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lezem-0002Ms-SU for importer@patchew.org; Fri, 07 May 2021 08:32:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57186) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbO-0000Tl-PI for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:06 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:40530) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbJ-0001Rh-Ug for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29: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 147CE4ER096860; Fri, 7 May 2021 12:28:58 GMT Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 38ctd89d19-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:28: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 147CFYZL068959; Fri, 7 May 2021 12:28:57 GMT Received: from pps.reinject (localhost [127.0.0.1]) by aserp3030.oracle.com with ESMTP id 38csrev2fe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:28:57 +0000 Received: from aserp3030.oracle.com (aserp3030.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 147CSuQL109918; Fri, 7 May 2021 12:28:56 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3030.oracle.com with ESMTP id 38csrev2ef-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:28:56 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 147CSsRM011644; Fri, 7 May 2021 12:28:54 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 07 May 2021 05:28:54 -0700 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=HHD0ffPoFv2m54Poufo3HoNOdK4KuAozbrE4/GpZMyA=; b=nwwJv5uWpGtni5a3w6Zntgd+mLwW284dS32C9zwZEHnIQwXNR4jlwfli3MRI6GScscdC z20dWddCMoNgnMfky9O1Nwa1FD+50QWQxEUIXpWRwn1abJkNx0cVE67jY2n0Z3nGdNdi ijBKlhPgZD6XVg3EDpWyRcCozhz+oyL0SaSnmM31I+jfDf5lBayLrCD4oLP3Ec25B7Nu ytzQbaxmGFD8SQdRAHSo3Xi5H7IUAaudG087qmb4VgrvPmPMvJPhD0bNoyAxXZEjWRQs J4W5h5LBx6oBWb2d9Y5m10H7mwu9y3FuQ+Ttvizknj0z4TL9khrk0bfbsR3o2QYeeBZI rw== From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V3 06/22] vl: add helper to request re-exec Date: Fri, 7 May 2021 05:25:04 -0700 Message-Id: <1620390320-301716-7-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> References: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-GUID: DMCnyyMy6mxF5A4nUoSRRDZV8eqRAKzZ X-Proofpoint-ORIG-GUID: DMCnyyMy6mxF5A4nUoSRRDZV8eqRAKzZ X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9976 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 adultscore=0 clxscore=1015 spamscore=0 mlxlogscore=999 priorityscore=1501 lowpriorityscore=0 phishscore=0 suspectscore=0 impostorscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105070085 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=156.151.31.86; envelope-from=steven.sistare@oracle.com; helo=userp2130.oracle.com X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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" , Jason Zeng , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add a qemu_exec_requested() hook that causes the main loop to exit and re-exec qemu using the same initial arguments. If /usr/bin/qemu-exec exists, exec that instead. This is an optional site-specific trampoline that may alter the environment before exec'ing the qemu binary. Signed-off-by: Steve Sistare --- include/sysemu/runstate.h | 1 + include/sysemu/sysemu.h | 1 + softmmu/globals.c | 1 + softmmu/runstate.c | 28 ++++++++++++++++++++++++++++ softmmu/vl.c | 1 + 5 files changed, 32 insertions(+) diff --git a/include/sysemu/runstate.h b/include/sysemu/runstate.h index a535691..50c84af 100644 --- a/include/sysemu/runstate.h +++ b/include/sysemu/runstate.h @@ -56,6 +56,7 @@ void qemu_system_wakeup_enable(WakeupReason reason, bool = enabled); void qemu_register_wakeup_notifier(Notifier *notifier); void qemu_register_wakeup_support(void); void qemu_system_shutdown_request(ShutdownCause reason); +void qemu_system_exec_request(void); void qemu_system_powerdown_request(void); void qemu_register_powerdown_notifier(Notifier *notifier); void qemu_register_shutdown_notifier(Notifier *notifier); diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 8fae667..f56058e 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -9,6 +9,7 @@ /* vl.c */ =20 extern int only_migratable; +extern char **argv_main; extern const char *qemu_name; extern QemuUUID qemu_uuid; extern bool qemu_uuid_set; diff --git a/softmmu/globals.c b/softmmu/globals.c index 7d0fc81..2bb630d 100644 --- a/softmmu/globals.c +++ b/softmmu/globals.c @@ -60,6 +60,7 @@ bool boot_strict; uint8_t *boot_splash_filedata; int only_migratable; /* turn it off unless user states otherwise */ int icount_align_option; +char **argv_main; =20 /* The bytes in qemu_uuid are in the order specified by RFC4122, _not_ in = the * little-endian "wire format" described in the SMBIOS 2.6 specification. diff --git a/softmmu/runstate.c b/softmmu/runstate.c index ce8977c..bea7513 100644 --- a/softmmu/runstate.c +++ b/softmmu/runstate.c @@ -338,6 +338,7 @@ static ShutdownCause reset_requested; static ShutdownCause shutdown_requested; static int shutdown_signal; static pid_t shutdown_pid; +static int exec_requested; static int powerdown_requested; static int debug_requested; static int suspend_requested; @@ -367,6 +368,11 @@ static int qemu_shutdown_requested(void) return qatomic_xchg(&shutdown_requested, SHUTDOWN_CAUSE_NONE); } =20 +static int qemu_exec_requested(void) +{ + return qatomic_xchg(&exec_requested, 0); +} + static void qemu_kill_report(void) { if (!qtest_driver() && shutdown_signal) { @@ -625,6 +631,13 @@ void qemu_system_shutdown_request(ShutdownCause reason) qemu_notify_event(); } =20 +void qemu_system_exec_request(void) +{ + shutdown_requested =3D 1; + exec_requested =3D 1; + qemu_notify_event(); +} + static void qemu_system_powerdown(void) { qapi_event_send_powerdown(); @@ -660,6 +673,16 @@ void qemu_system_debug_request(void) qemu_notify_event(); } =20 +static void qemu_exec(void) +{ + const char *helper =3D "/usr/bin/qemu-exec"; + const char *bin =3D !access(helper, X_OK) ? helper : argv_main[0]; + + execvp(bin, argv_main); + error_report("execvp failed, errno %d.", errno); + exit(1); +} + static bool main_loop_should_exit(void) { RunState r; @@ -673,6 +696,11 @@ static bool main_loop_should_exit(void) } request =3D qemu_shutdown_requested(); if (request) { + + if (qemu_exec_requested()) { + qemu_exec(); + /* not reached */ + } qemu_kill_report(); qemu_system_shutdown(request); if (shutdown_action =3D=3D SHUTDOWN_ACTION_PAUSE) { diff --git a/softmmu/vl.c b/softmmu/vl.c index aadb526..04ab752 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -2662,6 +2662,7 @@ void qemu_init(int argc, char **argv, char **envp) =20 error_init(argv[0]); qemu_init_exec_dir(argv[0]); + argv_main =3D argv; =20 qemu_init_subsystems(); =20 --=20 1.8.3.1 From nobody Sun May 5 14:17:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1620391180; cv=none; d=zohomail.com; s=zohoarc; b=jrxm5G8vHK4ReJbjUPTLG6bdbtCvfB5vfqS4W1R4d6f3kdy030wKukE6xN7+Qldd2rCc0IqmxqzrCsjtBRegq3x0v/s7cdCAxuRG/ADcg69RVwiA7esUj9r+vZVllUr+m9Jj10AERzvcCMaFetR/FElz+mMaFJMI0zCUMGE7Obc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620391180; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=vPLd8S54CCxMgCD/tybBxsEQ40b5Zj0zwHpYhrCodZw=; b=RbQNk5x3uXrLHaC7Kd4g/PWIZjoVZdH4NlGbL1nzHujPOMx/ZXOMI1mJwWsnZoyMG0413rr2Zps421rLlzqvIBUQ0g/El/oZHXSfZa4HbIHSpp35bmKxF+5/ddZ/KSSr7xXLGEQhptrT7Aai6qynHkIiKpOSaBmm05ugna7bnds= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620391180088924.9664359567757; Fri, 7 May 2021 05:39:40 -0700 (PDT) Received: from localhost ([::1]:57652 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lezlb-0000uz-Bb for importer@patchew.org; Fri, 07 May 2021 08:39:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57274) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbR-0000Yc-5N for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:09 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:40534) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbJ-0001Rk-Us for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:08 -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 147CDrHY096765; Fri, 7 May 2021 12:28:57 GMT Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 38ctd89d18-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:28:57 +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 147CGQuT173796; Fri, 7 May 2021 12:28:56 GMT Received: from pps.reinject (localhost [127.0.0.1]) by aserp3020.oracle.com with ESMTP id 38csrtb64f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:28:56 +0000 Received: from aserp3020.oracle.com (aserp3020.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 147CSuxo027831; Fri, 7 May 2021 12:28:56 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3020.oracle.com with ESMTP id 38csrtb63q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:28:56 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 147CStoK017188; Fri, 7 May 2021 12:28:55 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 07 May 2021 05:28:54 -0700 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=vPLd8S54CCxMgCD/tybBxsEQ40b5Zj0zwHpYhrCodZw=; b=Eo2fuxMV+SugG7dVau5smdYZDc2g6x6AEKfDbFCcI4ST8AvTM3oB9t50SLJCsp77XfDI Oiv6c/Wo80+icw/peUlgsLcpToEmCKbis/8XHRV6PbCVE73cXvJPogNEX5Jh1ESlOR/H pMNjjv6ovQXpspMmPD6sAMS4B0VyyxKKxuqjaNUmY0+gJrzHj2DfLCk6JEOQKrsm9fX5 Wz9ZH1tWBo4nofA1mxttA+6nTCeXXJBEzJeHGdVjZ13rEAsH6rp6iLvz1L0bfU8ecYYd FtEa7NM2JjaU3iRQ0gcwUpqI93ICK6eDqixc2EocZLtgs42yUWBAdeqagISr7imtbk6x wg== From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V3 07/22] cpr Date: Fri, 7 May 2021 05:25:05 -0700 Message-Id: <1620390320-301716-8-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> References: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-GUID: e-0RGO8T30iYdqvp6ks5fDLJVEPNdg8O X-Proofpoint-ORIG-GUID: e-0RGO8T30iYdqvp6ks5fDLJVEPNdg8O X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9976 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 adultscore=0 clxscore=1015 spamscore=0 mlxlogscore=999 priorityscore=1501 lowpriorityscore=0 phishscore=0 suspectscore=0 impostorscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105070085 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=156.151.31.86; envelope-from=steven.sistare@oracle.com; helo=userp2130.oracle.com X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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" , Jason Zeng , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Provide the cprsave and cprload functions for live update. These save and restore VM state, with minimal guest pause time, so that qemu may be updated to a new version in between. cprsave stops the VM and saves vmstate to an ordinary file. It supports two modes: restart and reboot. For restart, cprsave exec's the qemu binary (or /usr/bin/qemu-exec if it exists) with the same argv. qemu restarts in a paused state and waits for the cprload command. To use the restart mode, qemu must be started with the memfd-alloc machine option. The memfd's are saved to the environment and kept open across exec, after which they are found from the environment and re-mmap'd. Hence guest ram is preserved in place, albeit with new virtual addresses in the qemu process. The caller resumes the guest by calling cprload, which loads state from the file. If the VM was running at cprsave time, then VM execution resumes. cprsave supports any type of guest image and block device, but the caller must not modify guest block devices between cprsave and cprload. For the reboot mode, cprsave saves state and exits qemu, and the caller is allowed to update the host kernel and system software and reboot. The caller resumes the guest by running qemu with the same arguments as the original process and calling cprload. To use this mode, guest ram must be mapped to a persistent shared memory file such as /dev/dax0.0 or /dev/shm PKRAM. The reboot mode supports vfio devices if the caller suspends the guest instead of stopping the VM, such as by issuing guest-suspend-ram to the qemu guest agent. The guest drivers' suspend methods flush outstanding requests and re-initialize the devices, and thus there is no device state to save and restore. The restart mode supports vfio devices in a subsequent patch. Signed-off-by: Steve Sistare --- include/migration/cpr.h | 17 +++++ include/sysemu/runstate.h | 1 + migration/cpr.c | 188 ++++++++++++++++++++++++++++++++++++++++++= ++++ migration/meson.build | 1 + migration/savevm.h | 2 + softmmu/physmem.c | 6 +- softmmu/runstate.c | 21 +++++- softmmu/vl.c | 6 ++ 8 files changed, 240 insertions(+), 2 deletions(-) create mode 100644 include/migration/cpr.h create mode 100644 migration/cpr.c diff --git a/include/migration/cpr.h b/include/migration/cpr.h new file mode 100644 index 0000000..42dec4e --- /dev/null +++ b/include/migration/cpr.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2021 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 MIGRATION_CPR_H +#define MIGRATION_CPR_H + +#include "qapi/qapi-types-cpr.h" + +bool cpr_active(void); +void cprsave(const char *file, CprMode mode, Error **errp); +void cprload(const char *file, Error **errp); + +#endif diff --git a/include/sysemu/runstate.h b/include/sysemu/runstate.h index 50c84af..d69dc2d 100644 --- a/include/sysemu/runstate.h +++ b/include/sysemu/runstate.h @@ -51,6 +51,7 @@ void qemu_system_reset_request(ShutdownCause reason); void qemu_system_suspend_request(void); void qemu_register_suspend_notifier(Notifier *notifier); bool qemu_wakeup_suspend_enabled(void); +void qemu_system_start_on_wake_request(void); void qemu_system_wakeup_request(WakeupReason reason, Error **errp); void qemu_system_wakeup_enable(WakeupReason reason, bool enabled); void qemu_register_wakeup_notifier(Notifier *notifier); diff --git a/migration/cpr.c b/migration/cpr.c new file mode 100644 index 0000000..e0da1cf --- /dev/null +++ b/migration/cpr.c @@ -0,0 +1,188 @@ +/* + * Copyright (c) 2021 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 "monitor/monitor.h" +#include "migration.h" +#include "migration/snapshot.h" +#include "chardev/char.h" +#include "migration/misc.h" +#include "migration/cpr.h" +#include "migration/global_state.h" +#include "qemu-file-channel.h" +#include "qemu-file.h" +#include "savevm.h" +#include "qapi/error.h" +#include "qapi/qmp/qerror.h" +#include "qemu/error-report.h" +#include "io/channel-buffer.h" +#include "io/channel-file.h" +#include "sysemu/cpu-timers.h" +#include "sysemu/runstate.h" +#include "sysemu/runstate-action.h" +#include "sysemu/sysemu.h" +#include "sysemu/replay.h" +#include "sysemu/xen.h" +#include "hw/vfio/vfio-common.h" +#include "hw/virtio/vhost.h" +#include "qemu/env.h" + +static int cpr_is_active; + +bool cpr_active(void) +{ + return cpr_is_active; +} + +QEMUFile *qf_file_open(const char *path, int flags, int mode, + const char *name, Error **errp) +{ + QIOChannelFile *fioc; + QIOChannel *ioc; + QEMUFile *f; + + if (flags & O_RDWR) { + error_setg(errp, "qf_file_open %s: O_RDWR not supported", path); + return 0; + } + + fioc =3D qio_channel_file_new_path(path, flags, mode, errp); + if (!fioc) { + return 0; + } + + ioc =3D QIO_CHANNEL(fioc); + qio_channel_set_name(ioc, name); + f =3D (flags & O_WRONLY) ? qemu_fopen_channel_output(ioc) : + qemu_fopen_channel_input(ioc); + object_unref(OBJECT(fioc)); + return f; +} + +static int preserve_fd(const char *name, const char *val, void *handle) +{ + qemu_clr_cloexec(atoi(val)); + return 0; +} + +void cprsave(const char *file, CprMode mode, Error **errp) +{ + int ret =3D 0; + QEMUFile *f; + int saved_vm_running =3D runstate_is_running(); + bool restart =3D (mode =3D=3D CPR_MODE_RESTART); + bool reboot =3D (mode =3D=3D CPR_MODE_REBOOT); + + if (reboot && qemu_ram_volatile(errp)) { + return; + } + + if (restart && xen_enabled()) { + error_setg(errp, "xen does not support cprsave restart"); + return; + } + + if (migrate_colo_enabled()) { + error_setg(errp, "error: cprsave does not support x-colo"); + return; + } + + if (replay_mode !=3D REPLAY_MODE_NONE) { + error_setg(errp, "error: cprsave does not support replay"); + return; + } + + f =3D qf_file_open(file, O_CREAT | O_WRONLY | O_TRUNC, 0600, "cprsave"= , errp); + if (!f) { + return; + } + + ret =3D global_state_store(); + if (ret) { + error_setg(errp, "Error saving global state"); + qemu_fclose(f); + return; + } + if (runstate_check(RUN_STATE_SUSPENDED)) { + /* Update timers_state before saving. Suspend did not so do. */ + cpu_disable_ticks(); + } + vm_stop(RUN_STATE_SAVE_VM); + + cpr_is_active =3D true; + ret =3D qemu_save_device_state(f); + qemu_fclose(f); + if (ret < 0) { + error_setg(errp, QERR_IO_ERROR); + goto err; + } + + if (ret < 0) { + if (!*errp) { + error_setg(errp, "Error %d while saving VM state", ret); + } + goto err; + } + + if (reboot) { + shutdown_action =3D SHUTDOWN_ACTION_POWEROFF; + qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); + } else if (restart) { + walkenv(FD_PREFIX, preserve_fd, 0); + setenv("QEMU_START_FREEZE", "", 1); + qemu_system_exec_request(); + } + goto done; + +err: + if (saved_vm_running) { + vm_start(); + } +done: + cpr_is_active =3D false; + return; +} + +void cprload(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 =3D qf_file_open(file, O_RDONLY, 0, "cprload", errp); + if (!f) { + return; + } + + if (qemu_get_be32(f) !=3D QEMU_VM_FILE_MAGIC || + qemu_get_be32(f) !=3D QEMU_VM_FILE_VERSION) { + error_setg(errp, "error: %s is not a vmstate file", file); + return; + } + + ret =3D qemu_load_device_state(f); + qemu_fclose(f); + if (ret < 0) { + error_setg(errp, "Error %d while loading VM state", ret); + return; + } + + state =3D global_state_get_runstate(); + if (state =3D=3D RUN_STATE_RUNNING) { + vm_start(); + } else { + runstate_set(state); + if (runstate_check(RUN_STATE_SUSPENDED)) { + qemu_system_start_on_wake_request(); + } + } +} diff --git a/migration/meson.build b/migration/meson.build index 3ecedce..c756374 100644 --- a/migration/meson.build +++ b/migration/meson.build @@ -15,6 +15,7 @@ softmmu_ss.add(files( 'channel.c', 'colo-failover.c', 'colo.c', + 'cpr.c', 'exec.c', 'fd.c', 'global_state.c', diff --git a/migration/savevm.h b/migration/savevm.h index 6461342..ce5d710 100644 --- a/migration/savevm.h +++ b/migration/savevm.h @@ -67,5 +67,7 @@ int qemu_loadvm_state_main(QEMUFile *f, MigrationIncoming= State *mis); int qemu_load_device_state(QEMUFile *f); int qemu_savevm_state_complete_precopy_non_iterable(QEMUFile *f, bool in_postcopy, bool inactivate_disks); +QEMUFile *qf_file_open(const char *path, int flags, int mode, + const char *name, Error **errp); =20 #endif diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 695aa10..b79f408 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -68,6 +68,7 @@ #include "qemu/pmem.h" =20 #include "qemu/memfd.h" +#include "qemu/env.h" #include "migration/vmstate.h" =20 #include "qemu/range.h" @@ -1957,7 +1958,7 @@ static void ram_block_add(RAMBlock *new_block, Error = **errp, bool shared) } else { name =3D memory_region_name(new_block->mr); if (ms->memfd_alloc) { - int mfd =3D -1; /* placeholder until next patch */ + int mfd =3D getenv_fd(name); mr->align =3D QEMU_VMALLOC_ALIGN; if (mfd < 0) { mfd =3D qemu_memfd_create(name, maxlen + mr->align, @@ -1965,7 +1966,9 @@ static void ram_block_add(RAMBlock *new_block, Error = **errp, bool shared) if (mfd < 0) { return; } + setenv_fd(name, mfd); } + qemu_clr_cloexec(mfd); new_block->flags |=3D RAM_SHARED; addr =3D file_ram_alloc(new_block, maxlen, mfd, false, false, 0, errp); @@ -2214,6 +2217,7 @@ void qemu_ram_free(RAMBlock *block) } =20 qemu_mutex_lock_ramlist(); + unsetenv_fd(memory_region_name(block->mr)); QLIST_REMOVE_RCU(block, next); ram_list.mru_block =3D NULL; /* Write list before version */ diff --git a/softmmu/runstate.c b/softmmu/runstate.c index bea7513..07952cc 100644 --- a/softmmu/runstate.c +++ b/softmmu/runstate.c @@ -115,6 +115,8 @@ static const RunStateTransition runstate_transitions_de= f[] =3D { { 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 }, =20 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING }, { RUN_STATE_FINISH_MIGRATE, RUN_STATE_PAUSED }, @@ -334,6 +336,7 @@ void vm_state_notify(bool running, RunState state) } } =20 +static bool start_on_wake_requested; static ShutdownCause reset_requested; static ShutdownCause shutdown_requested; static int shutdown_signal; @@ -567,6 +570,11 @@ void qemu_register_suspend_notifier(Notifier *notifier) notifier_list_add(&suspend_notifiers, notifier); } =20 +void qemu_system_start_on_wake_request(void) +{ + start_on_wake_requested =3D true; +} + void qemu_system_wakeup_request(WakeupReason reason, Error **errp) { trace_system_wakeup_request(reason); @@ -579,7 +587,18 @@ void qemu_system_wakeup_request(WakeupReason reason, E= rror **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_requested) { + start_on_wake_requested =3D false; + vm_start(); + } else { + runstate_set(RUN_STATE_RUNNING); + } + wakeup_reason =3D reason; qemu_notify_event(); } diff --git a/softmmu/vl.c b/softmmu/vl.c index 04ab752..4654693 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -3510,6 +3510,12 @@ void qemu_init(int argc, char **argv, char **envp) */ loc_set_none(); =20 + /* Equivalent to -S, but no need for parent to modify argv. */ + if (getenv("QEMU_START_FREEZE")) { + unsetenv("QEMU_START_FREEZE"); + autostart =3D 0; + } + qemu_validate_options(); qemu_process_sugar_options(); =20 --=20 1.8.3.1 From nobody Sun May 5 14:17:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1620391191; cv=none; d=zohomail.com; s=zohoarc; b=ZDu8k70hbxh8YhALzvSfr6KxM7FvtRVryuOLoHAbBTLDAkjdPnghocMlpr3mFtxU8V63hhTP0TWBVPjf1ov/qZXqqEUnKG1owoskst9+k5Zj/GwNHB46ZvFzSqMfmdpGt+l6VNRgYjLUW1qm1ERczohdUM9bocMIwQBq/iwsKU8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620391191; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=zeYY6QQF2/OIwjuNLMYlqEZVUbtqwO/F/LY+8WehK1g=; b=frSLFevUHDKh62E68AlPItRN/qQCEwxcnKfosn2ayFUikogFQnVArGnghR8hPf/SI3e4SRpBe/A0AyX5NqpjG7n7EC0Uq130C2C2AO5ni1jub8X7Jsgl7BIYBfVlyqsmPpIfLlTsxZk1Yzm0suD8mUJTeS1BMDc7H5R4NoK0a5A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620391191635941.5102357233038; Fri, 7 May 2021 05:39:51 -0700 (PDT) Received: from localhost ([::1]:57718 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lezlm-0000wn-OE for importer@patchew.org; Fri, 07 May 2021 08:39:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57312) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbS-0000dG-TZ for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:10 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:49894) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbK-0001Rv-Hn for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:10 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 147CDr2L148738; Fri, 7 May 2021 12:28:59 GMT Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2130.oracle.com with ESMTP id 38csrd9ewc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:28:59 +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 147CFY9U068921; Fri, 7 May 2021 12:28:59 GMT Received: from pps.reinject (localhost [127.0.0.1]) by aserp3030.oracle.com with ESMTP id 38csrev2gs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:28:59 +0000 Received: from aserp3030.oracle.com (aserp3030.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 147CPnbe097968; Fri, 7 May 2021 12:28:58 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3030.oracle.com with ESMTP id 38csrev2g2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:28:58 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 147CSuR8011657; Fri, 7 May 2021 12:28:56 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 07 May 2021 05:28:56 -0700 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=zeYY6QQF2/OIwjuNLMYlqEZVUbtqwO/F/LY+8WehK1g=; b=V1W4nKL96c21CGZFISLTXaXF+ex4k4pzp8MFQ2yvKEhOGv9ajb73r3qbNHUr2qS5XQ3m woIfr2qw1iHbeBKj0/mWWfoxs0ajosNMg9vqhlBe6BbKs/rnix+oYrhWb2EoDQQahLq3 GxFQWP9xQ00xl/avdDD+CVnOfSz2fHf6IffZvZ+MS/ypfP3pTf9q09t1I26h4PJFKrny QISAoXeH4Y/HUVHM7orMljo/QCGn/jqnyVP4GaZfJHGYwmoJOcvEbbpV7pK72hNtEZyi QAppUIUsxcBkq/ABPpDaSFLbnd9as8wAJLFwJF7nfzStaDihBjFSbdJlQ0/ruCKGq+yB 7A== From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V3 08/22] cpr: QMP interfaces Date: Fri, 7 May 2021 05:25:06 -0700 Message-Id: <1620390320-301716-9-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> References: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-ORIG-GUID: bV23kd7SYzmBaJ8pfXlsA7HNW4Y05GNI X-Proofpoint-GUID: bV23kd7SYzmBaJ8pfXlsA7HNW4Y05GNI X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9976 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 clxscore=1015 malwarescore=0 adultscore=0 mlxlogscore=999 impostorscore=0 phishscore=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105070085 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=141.146.126.79; envelope-from=steven.sistare@oracle.com; helo=aserp2130.oracle.com X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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" , Jason Zeng , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" cprsave calls cprsave(). Syntax: { 'enum': 'CprMode', 'data': [ 'reboot', 'restart' ] } { 'command': 'cprsave', 'data': { 'file': 'str', 'mode': 'CprMode' } } cprload calls cprload(). Syntax: { 'command': 'cprload', 'data': { 'file': 'str' } } cprinfo returns a list of supported modes. Syntax: { 'struct': 'CprInfo', 'data': { 'modes': [ 'CprMode' ] } } { 'command': 'cprinfo', 'returns': 'CprInfo' } Signed-off-by: Mark Kanda Signed-off-by: Steve Sistare --- monitor/qmp-cmds.c | 31 +++++++++++++++++++++ qapi/cpr.json | 76 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ qapi/meson.build | 1 + qapi/qapi-schema.json | 1 + 4 files changed, 109 insertions(+) create mode 100644 qapi/cpr.json diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c index f7d64a6..1128604 100644 --- a/monitor/qmp-cmds.c +++ b/monitor/qmp-cmds.c @@ -37,9 +37,11 @@ #include "qapi/qapi-commands-machine.h" #include "qapi/qapi-commands-misc.h" #include "qapi/qapi-commands-ui.h" +#include "qapi/qapi-commands-cpr.h" #include "qapi/qmp/qerror.h" #include "hw/mem/memory-device.h" #include "hw/acpi/acpi_dev_interface.h" +#include "migration/cpr.h" =20 NameInfo *qmp_query_name(Error **errp) { @@ -153,6 +155,35 @@ void qmp_cont(Error **errp) } } =20 +CprInfo *qmp_cprinfo(Error **errp) +{ + CprInfo *cprinfo; + CprModeList *mode, *mode_list =3D NULL; + CprMode i; + + cprinfo =3D g_malloc0(sizeof(*cprinfo)); + + for (i =3D 0; i < CPR_MODE__MAX; i++) { + mode =3D g_malloc0(sizeof(*mode)); + mode->value =3D i; + mode->next =3D mode_list; + mode_list =3D mode; + } + + cprinfo->modes =3D mode_list; + return cprinfo; +} + +void qmp_cprsave(const char *file, CprMode mode, Error **errp) +{ + cprsave(file, mode, errp); +} + +void qmp_cprload(const char *file, Error **errp) +{ + cprload(file, errp); +} + void qmp_system_wakeup(Error **errp) { if (!qemu_wakeup_suspend_enabled()) { diff --git a/qapi/cpr.json b/qapi/cpr.json new file mode 100644 index 0000000..2d80cca --- /dev/null +++ b/qapi/cpr.json @@ -0,0 +1,76 @@ +# -*- Mode: Python -*- +# +# Copyright (c) 2021 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. + +## +# =3D CPR +## + +{ 'include': 'common.json' } + +## +# @CprMode: +# +# @reboot: checkpoint can be cprload'ed after a host kexec reboot. +# +# @restart: checkpoint can be cprload'ed after restarting qemu. +# +# Since: 6.0 +## +{ 'enum': 'CprMode', + 'data': [ 'reboot', 'restart' ] } + + +## +# @CprInfo: +# +# @modes: @CprMode list +# +# Since: 6.0 +## +{ 'struct': 'CprInfo', + 'data': { 'modes': [ 'CprMode' ] } } + +## +# @cprinfo: +# +# Returns the modes supported by @cprsave. +# +# Returns: @CprInfo +# +# Since: 6.0 +# +## +{ 'command': 'cprinfo', + 'returns': 'CprInfo' } + +## +# @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: @CprMode mode +# +# Since: 6.0 +## +{ 'command': 'cprsave', + 'data': { 'file': 'str', + 'mode': 'CprMode' } } + +## +# @cprload: +# +# Start virtual machine from checkpoint file that was created earlier using +# the cprsave command. +# +# @file: name of checkpoint file +# +# Since: 6.0 +## +{ 'command': 'cprload', + 'data': { 'file': 'str' } } diff --git a/qapi/meson.build b/qapi/meson.build index 376f4ce..7e7c48a 100644 --- a/qapi/meson.build +++ b/qapi/meson.build @@ -26,6 +26,7 @@ qapi_all_modules =3D [ 'common', 'compat', 'control', + 'cpr', 'crypto', 'dump', 'error', diff --git a/qapi/qapi-schema.json b/qapi/qapi-schema.json index 4912b97..001d790 100644 --- a/qapi/qapi-schema.json +++ b/qapi/qapi-schema.json @@ -77,6 +77,7 @@ { 'include': 'ui.json' } { 'include': 'authz.json' } { 'include': 'migration.json' } +{ 'include': 'cpr.json' } { 'include': 'transaction.json' } { 'include': 'trace.json' } { 'include': 'compat.json' } --=20 1.8.3.1 From nobody Sun May 5 14:17:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1620392171; cv=none; d=zohomail.com; s=zohoarc; b=GPNkW1LB9wRYpW4Wyy6pXw0b/rndqwdTYoB+lwJZSOewwDRIPALpa7q304gNfYYqYsYMQZNJ00Eqd4ect6byVcSIoaSaluRoHoCM/dqThIzTv4jueVrGMxjtWLVAPPV6+G3OFengASlaA5MHJYMNegNgplvbZpSyf4fccRs7eKA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620392171; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=bhXktVqVbHebVf1zMiTZRGxxftF1sfcsqPDmjMN9oAc=; b=CvGBbnki+8mxommru3/Xa5ng3g1eYJ77wdhCdA+fTliS0RwLYQ0hvyv0fIZqERQpl5YdQUK6pIRZsVqR67drSpd7Wq2EgD9d51mkQlHoh8wruYx8b1NzVo3Xh09/CcR8XbcqqTjFCJt+PvpPdVdHONJdUQ2Eo63CvgFXdlvrr3Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620392171151765.2561246390367; Fri, 7 May 2021 05:56:11 -0700 (PDT) Received: from localhost ([::1]:39704 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lf01a-0000Tf-5M for importer@patchew.org; Fri, 07 May 2021 08:56:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57628) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezcL-0001S5-SA for qemu-devel@nongnu.org; Fri, 07 May 2021 08:30:05 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:40946) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezcJ-00023p-Gn for qemu-devel@nongnu.org; Fri, 07 May 2021 08:30:05 -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 147CE4SK096866; Fri, 7 May 2021 12:28:59 GMT Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 38ctd89d1d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:28:59 +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 147CFN5C031201; Fri, 7 May 2021 12:28:59 GMT Received: from pps.reinject (localhost [127.0.0.1]) by userp3030.oracle.com with ESMTP id 38css8ss6m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:28:59 +0000 Received: from userp3030.oracle.com (userp3030.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 147CSwSE071605; Fri, 7 May 2021 12:28:58 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 38css8ss54-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:28:58 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 147CSve9017194; Fri, 7 May 2021 12:28:57 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 07 May 2021 05:28:56 -0700 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=bhXktVqVbHebVf1zMiTZRGxxftF1sfcsqPDmjMN9oAc=; b=UfxB40QJCSglHuqIaOKbgDY6mwzjBFK5pb7b62nIdsVVGBEXPrWnflLtyQkDVDgjDQHc sy6OwGaSADDofMYz96Dy+gWxxlFUOmCt6bZeQsCOVq5LCJD6eezTvGjZucYtdLHmaXM4 eWFoTtqx2pyWZok3HxD4mwU/z2pW+puyG9P8feF6grSwc/ALc0kC32rRbppH7CJbppuI AHR3wX5y67+CfbeiqaBBRWjRk10Qwh92orKlSUsBLi3yPRwpTOOjmIxcWPUtuZ+IwoND SEluGVh7DeJvE1BN4cKFUdDNRxml/jjGnIdW8ojg5jYINldhjWN+iA5U+V2ts7MHSUr6 sg== From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V3 09/22] cpr: HMP interfaces Date: Fri, 7 May 2021 05:25:07 -0700 Message-Id: <1620390320-301716-10-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> References: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-GUID: wkejXdTJdjsuLdbkhkoqfIcb2uyZ6jPW X-Proofpoint-ORIG-GUID: wkejXdTJdjsuLdbkhkoqfIcb2uyZ6jPW X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9976 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 adultscore=0 clxscore=1015 spamscore=0 mlxlogscore=999 priorityscore=1501 lowpriorityscore=0 phishscore=0 suspectscore=0 impostorscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105070085 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=156.151.31.86; envelope-from=steven.sistare@oracle.com; helo=userp2130.oracle.com X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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" , Jason Zeng , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" cprsave Call cprsave(). Arguments: file : save vmstate to this file name mode: "reboot" or "restart" cprload Call cprload(). Arguments: file : load vmstate from this file name cprinfo Print to stdout a space-delimited list of modes supported by cprsave. Arguments: none Signed-off-by: Mark Kanda Signed-off-by: Steve Sistare --- hmp-commands.hx | 44 ++++++++++++++++++++++++++++++++++++++++++++ include/monitor/hmp.h | 3 +++ monitor/hmp-cmds.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) diff --git a/hmp-commands.hx b/hmp-commands.hx index 435c591..5c79c5a 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -351,6 +351,50 @@ SRST ERST =20 { + .name =3D "cprinfo", + .args_type =3D "", + .params =3D "", + .help =3D "return list of modes supported by cprsave", + .cmd =3D hmp_cprinfo, + }, + +SRST +``cprinfo`` +Return a space-delimited list of modes supported by cprsave. +ERST + + { + .name =3D "cprsave", + .args_type =3D "file:s,mode:s", + .params =3D "file 'restart'|'reboot'", + .help =3D "create a checkpoint of the VM in file", + .cmd =3D hmp_cprsave, + }, + +SRST +``cprsave`` *file* *mode* +Create a checkpoint of the whole virtual machine and save it in *file*. +If *mode* is 'reboot', the checkpoint remains valid after a host kexec +reboot. Guest ram must be backed by persistant shared memory. +If *mode* is 'restart', pause the VCPUs, exec /usr/bin/qemu-exec if it +exists, else exec argv[0], passing all the original command line arguments. +Guest ram must be allocated with the memfd-alloc machine option. +ERST + + { + .name =3D "cprload", + .args_type =3D "file:s", + .params =3D "file", + .help =3D "load VM checkpoint from file", + .cmd =3D hmp_cprload, + }, + +SRST +``cprload`` *file* +Load a virtual machine from checkpoint file *file* and continue VCPUs. +ERST + + { .name =3D "delvm", .args_type =3D "name:s", .params =3D "tag", diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index 605d572..e4ebdf1 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -58,6 +58,9 @@ void hmp_balloon(Monitor *mon, const QDict *qdict); void hmp_loadvm(Monitor *mon, const QDict *qdict); void hmp_savevm(Monitor *mon, const QDict *qdict); void hmp_delvm(Monitor *mon, const QDict *qdict); +void hmp_cprinfo(Monitor *mon, const QDict *qdict); +void hmp_cprsave(Monitor *mon, const QDict *qdict); +void hmp_cprload(Monitor *mon, const QDict *qdict); void hmp_migrate_cancel(Monitor *mon, const QDict *qdict); void hmp_migrate_continue(Monitor *mon, const QDict *qdict); void hmp_migrate_incoming(Monitor *mon, const QDict *qdict); diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 0ad5b77..e115a23 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -33,6 +33,7 @@ #include "qapi/qapi-commands-block.h" #include "qapi/qapi-commands-char.h" #include "qapi/qapi-commands-control.h" +#include "qapi/qapi-commands-cpr.h" #include "qapi/qapi-commands-machine.h" #include "qapi/qapi-commands-migration.h" #include "qapi/qapi-commands-misc.h" @@ -1173,6 +1174,53 @@ void hmp_announce_self(Monitor *mon, const QDict *qd= ict) qapi_free_AnnounceParameters(params); } =20 +void hmp_cprinfo(Monitor *mon, const QDict *qdict) +{ + Error *err =3D NULL; + CprInfo *cprinfo; + CprModeList *mode; + + cprinfo =3D qmp_cprinfo(&err); + if (err) { + goto out; + } + + for (mode =3D cprinfo->modes; mode; mode =3D mode->next) { + monitor_printf(mon, "%s ", CprMode_str(mode->value)); + } + +out: + hmp_handle_error(mon, err); + qapi_free_CprInfo(cprinfo); +} + +void hmp_cprsave(Monitor *mon, const QDict *qdict) +{ + Error *err =3D NULL; + const char *mode; + int val; + + mode =3D qdict_get_try_str(qdict, "mode"); + val =3D qapi_enum_parse(&CprMode_lookup, mode, -1, &err); + + if (val =3D=3D -1) { + goto out; + } + + qmp_cprsave(qdict_get_try_str(qdict, "file"), val, &err); + +out: + hmp_handle_error(mon, err); +} + +void hmp_cprload(Monitor *mon, const QDict *qdict) +{ + Error *err =3D NULL; + + qmp_cprload(qdict_get_try_str(qdict, "file"), &err); + hmp_handle_error(mon, err); +} + void hmp_migrate_cancel(Monitor *mon, const QDict *qdict) { qmp_migrate_cancel(NULL); --=20 1.8.3.1 From nobody Sun May 5 14:17:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1620391411; cv=none; d=zohomail.com; s=zohoarc; b=P9D7aqL1up0dakMiMDGsTnplHV0eP8U75h4VwgVVlrR/hcLMModV3Asahs9V7iQgwehlSwe4eHQSunX0i/bGTFFRQUuuiDqCUp7kV2m44QGTgjUPVak0Z/BlhUvZ4rjPxAVBz3OQieKfkbAysmgld3/u3PFCLGffGBxUbYrTkP0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620391411; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=Zc4qOmsp74EkY9xxz4Vkv8OgESU7vm07Wws0OhW7Nr4=; b=WpVlWVmY0ZLYqPIUdp9SnxebrqDAbERjXA95TE9uK5Q+kd0nshoI76IpwRcsB2Hd9It1fVZ45pwhF578J/FrTwZzpQSeuhgfT9jkIfMAtFPZIzyP917wMAp4vZw8S9Jus9QScJzA/Mf5QaM/QmM3qipn3OX5CoNsyhtOk1b6q0w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620391411758231.11061513349648; Fri, 7 May 2021 05:43:31 -0700 (PDT) Received: from localhost ([::1]:37254 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lezpK-0004Hb-6J for importer@patchew.org; Fri, 07 May 2021 08:43:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57304) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbS-0000bK-8e for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:10 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:40572) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbO-0001SL-F7 for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:09 -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 147CEBqQ096898; Fri, 7 May 2021 12:29:00 GMT Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 38ctd89d1j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29:00 +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 147CFNmA031183; Fri, 7 May 2021 12:29:00 GMT Received: from pps.reinject (localhost [127.0.0.1]) by userp3030.oracle.com with ESMTP id 38css8ss7k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29:00 +0000 Received: from userp3030.oracle.com (userp3030.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 147CSxQA071655; Fri, 7 May 2021 12:28:59 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3030.oracle.com with ESMTP id 38css8ss6v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:28:59 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 147CSv4K016413; Fri, 7 May 2021 12:28:58 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 07 May 2021 05:28:57 -0700 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=Zc4qOmsp74EkY9xxz4Vkv8OgESU7vm07Wws0OhW7Nr4=; b=JQH8fisMT2eJWqdJ1w3jZHSOz4e6GpsdiRblpLXUYlA8Y4kIdVGdH+mC4vtKw7+18da6 1n2HqXbOj53Wf9GZB4U6lUeCpTy2u3tbG37Y8IKged5Ranx/2pGptfyUCTyAZYX22KHW sZkmSwjvsfmNipfUYigiYhZHXFvl5Jb4Irfgh2xSmOBKYAVH6FwD/O0OA6MtxvFtaBp/ s0Eu2oVOCzBwCHHlShjWdWohdl2KxWr1LbYoDcvObiQKGTZYLfXEO/P89uor14K4M9Vf v3DBqPXBTGL+NBxhGc0lE4q0louQUHY5mi9joKlbGqvrA4X3nA2wmP59bB9eSVb5ryac PQ== From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V3 10/22] pci: export functions for cpr Date: Fri, 7 May 2021 05:25:08 -0700 Message-Id: <1620390320-301716-11-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> References: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-GUID: PlXDP6q2Ub-QcX5tlpl9qman2V5Oke0F X-Proofpoint-ORIG-GUID: PlXDP6q2Ub-QcX5tlpl9qman2V5Oke0F X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9976 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 adultscore=0 clxscore=1015 spamscore=0 mlxlogscore=999 priorityscore=1501 lowpriorityscore=0 phishscore=0 suspectscore=0 impostorscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105070085 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=156.151.31.86; envelope-from=steven.sistare@oracle.com; helo=userp2130.oracle.com X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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" , Jason Zeng , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Export msix_is_pending and msix_init_vector_notifiers for use by cpr. No functional change. Signed-off-by: Steve Sistare --- hw/pci/msix.c | 20 ++++++++++++++------ hw/pci/pci.c | 3 +-- include/hw/pci/msix.h | 5 +++++ include/hw/pci/pci.h | 1 + 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/hw/pci/msix.c b/hw/pci/msix.c index ae9331c..73f4259 100644 --- a/hw/pci/msix.c +++ b/hw/pci/msix.c @@ -64,7 +64,7 @@ static uint8_t *msix_pending_byte(PCIDevice *dev, int vec= tor) return dev->msix_pba + vector / 8; } =20 -static int msix_is_pending(PCIDevice *dev, int vector) +int msix_is_pending(PCIDevice *dev, unsigned int vector) { return *msix_pending_byte(dev, vector) & msix_pending_mask(vector); } @@ -579,6 +579,17 @@ static void msix_unset_notifier_for_vector(PCIDevice *= dev, unsigned int vector) dev->msix_vector_release_notifier(dev, vector); } =20 +void msix_init_vector_notifiers(PCIDevice *dev, + MSIVectorUseNotifier use_notifier, + MSIVectorReleaseNotifier release_notifier, + MSIVectorPollNotifier poll_notifier) +{ + assert(use_notifier && release_notifier); + dev->msix_vector_use_notifier =3D use_notifier; + dev->msix_vector_release_notifier =3D release_notifier; + dev->msix_vector_poll_notifier =3D poll_notifier; +} + int msix_set_vector_notifiers(PCIDevice *dev, MSIVectorUseNotifier use_notifier, MSIVectorReleaseNotifier release_notifier, @@ -586,11 +597,8 @@ int msix_set_vector_notifiers(PCIDevice *dev, { int vector, ret; =20 - assert(use_notifier && release_notifier); - - dev->msix_vector_use_notifier =3D use_notifier; - dev->msix_vector_release_notifier =3D release_notifier; - dev->msix_vector_poll_notifier =3D poll_notifier; + msix_init_vector_notifiers(dev, use_notifier, release_notifier, + poll_notifier); =20 if ((dev->config[dev->msix_cap + MSIX_CONTROL_OFFSET] & (MSIX_ENABLE_MASK | MSIX_MASKALL_MASK)) =3D=3D MSIX_ENABLE_MASK) { diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 8f35e13..e08d981 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -226,7 +226,6 @@ static const TypeInfo pcie_bus_info =3D { }; =20 static PCIBus *pci_find_bus_nr(PCIBus *bus, int bus_num); -static void pci_update_mappings(PCIDevice *d); static void pci_irq_handler(void *opaque, int irq_num, int level); static void pci_add_option_rom(PCIDevice *pdev, bool is_default_rom, Error= **); static void pci_del_option_rom(PCIDevice *pdev); @@ -1335,7 +1334,7 @@ static pcibus_t pci_bar_address(PCIDevice *d, return new_addr; } =20 -static void pci_update_mappings(PCIDevice *d) +void pci_update_mappings(PCIDevice *d) { PCIIORegion *r; int i; diff --git a/include/hw/pci/msix.h b/include/hw/pci/msix.h index 4c4a60c..46606cf 100644 --- a/include/hw/pci/msix.h +++ b/include/hw/pci/msix.h @@ -32,6 +32,7 @@ int msix_present(PCIDevice *dev); bool msix_is_masked(PCIDevice *dev, unsigned vector); void msix_set_pending(PCIDevice *dev, unsigned vector); void msix_clr_pending(PCIDevice *dev, int vector); +int msix_is_pending(PCIDevice *dev, unsigned vector); =20 int msix_vector_use(PCIDevice *dev, unsigned vector); void msix_vector_unuse(PCIDevice *dev, unsigned vector); @@ -41,6 +42,10 @@ void msix_notify(PCIDevice *dev, unsigned vector); =20 void msix_reset(PCIDevice *dev); =20 +void msix_init_vector_notifiers(PCIDevice *dev, + MSIVectorUseNotifier use_notifier, + MSIVectorReleaseNotifier release_notifier, + MSIVectorPollNotifier poll_notifier); int msix_set_vector_notifiers(PCIDevice *dev, MSIVectorUseNotifier use_notifier, MSIVectorReleaseNotifier release_notifier, diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 6be4e0c..bef3e49 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -902,5 +902,6 @@ extern const VMStateDescription vmstate_pci_device; } =20 MSIMessage pci_get_msi_message(PCIDevice *dev, int vector); +void pci_update_mappings(PCIDevice *d); =20 #endif --=20 1.8.3.1 From nobody Sun May 5 14:17:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1620391007; cv=none; d=zohomail.com; s=zohoarc; b=eXBhxoJvb4vKD0PmueGQo9keKH8Ar060r9tpIae6b+b2b18jy56WgZpavylSVtYE0T6QHi2VdVHmwIqqzNhkh8tAUbqtmDfd3Di48LLME465RtrflXWHUfd+edpLxi4SM6mARcbQVBn07+q/tOfIbTaU56hI/1NbamlR2mAB+KM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620391007; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=f/cR7RLpqsrjRgoH2IWPRKzglwS0GQnd3dK2jT120EE=; b=TXt+RbudgLMsusVJ2XMlDw1IU3/9Q7qVQakieGERfKWvJJcPeptgKnAIInhVqnhXSA6ZVA/6yhAD951N+5oIJG/zjjTchbxaxa3nthO8kDJyOOCVtohGhLyWr/FV/05DL5Lm7rXlHiTjaLqCCthpYO+PJVVT5RMBbmgNYLkBsa4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620391007307546.2950775040182; Fri, 7 May 2021 05:36:47 -0700 (PDT) Received: from localhost ([::1]:49206 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lezio-0005ux-KZ for importer@patchew.org; Fri, 07 May 2021 08:36:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57308) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbS-0000cA-IW for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:10 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:43762) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbO-0001SH-F3 for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29: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 147CShcL050046; Fri, 7 May 2021 12:29:01 GMT Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2120.oracle.com with ESMTP id 38csqvhemk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29:00 +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 147CFZHg069027; Fri, 7 May 2021 12:29:00 GMT Received: from pps.reinject (localhost [127.0.0.1]) by aserp3030.oracle.com with ESMTP id 38csrev2hg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29:00 +0000 Received: from aserp3030.oracle.com (aserp3030.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 147CPtJq098147; Fri, 7 May 2021 12:28:59 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3030.oracle.com with ESMTP id 38csrev2h2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:28:59 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 147CSwHl017215; Fri, 7 May 2021 12:28:58 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 07 May 2021 05:28:58 -0700 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=f/cR7RLpqsrjRgoH2IWPRKzglwS0GQnd3dK2jT120EE=; b=yYrSLnYlzhsd3Mact83+9B5Of9qALF5jyUVjltULY5UVlfDiWOtRHQvmY7K3umAk8v+h F/1M0hjzZdC9rCP4/3N6xo400D56hprKeJmMpY9MtsWTcvvtPtgxsIameRFDEDd43I0u kHHUlMpIteQNKjAggl1/pMuUtguyUMyK3FsWl5IMizZ90Zp2XboiVFUHJBtdKLhhTZZ/ ivQXDYDQ0iGvulkDUVK++Cp1MEI9yxFWlAzm03Xr5+93tzoebXX6IhmKh+vJbTbI57Bf TjAl5EPx4pvNeimq2NLwN2NhyAtSMzfk5WLNG285sgqVBXO45v5G/YMyzJopCWpJNacm LQ== From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V3 11/22] vfio-pci: refactor for cpr Date: Fri, 7 May 2021 05:25:09 -0700 Message-Id: <1620390320-301716-12-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> References: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-ORIG-GUID: AB5i8mQ0ama1AVLRf4LM7YdKOINJfE1l X-Proofpoint-GUID: AB5i8mQ0ama1AVLRf4LM7YdKOINJfE1l X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9976 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 bulkscore=0 adultscore=0 suspectscore=0 spamscore=0 impostorscore=0 phishscore=0 clxscore=1015 mlxscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105070086 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=156.151.31.85; envelope-from=steven.sistare@oracle.com; helo=userp2120.oracle.com X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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=-0.001, 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" , Jason Zeng , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Export vfio_address_spaces and vfio_listener_skipped_section. Add optional eventfd arg to vfio_add_kvm_msi_virq. Refactor vector use into a helper vfio_vector_init. All for use by cpr in a subsequent patch. No functional change. Signed-off-by: Steve Sistare --- hw/vfio/common.c | 4 ++-- hw/vfio/pci.c | 36 +++++++++++++++++++++++++----------- include/hw/vfio/vfio-common.h | 3 +++ 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index ae5654f..9220e64 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -42,7 +42,7 @@ =20 VFIOGroupList vfio_group_list =3D QLIST_HEAD_INITIALIZER(vfio_group_list); -static QLIST_HEAD(, VFIOAddressSpace) vfio_address_spaces =3D +VFIOAddressSpaceList vfio_address_spaces =3D QLIST_HEAD_INITIALIZER(vfio_address_spaces); =20 #ifdef CONFIG_KVM @@ -534,7 +534,7 @@ static int vfio_host_win_del(VFIOContainer *container, = hwaddr min_iova, return -1; } =20 -static bool vfio_listener_skipped_section(MemoryRegionSection *section) +bool vfio_listener_skipped_section(MemoryRegionSection *section) { return (!memory_region_is_ram(section->mr) && !memory_region_is_iommu(section->mr)) || diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 5c65aa0..7a4fb6c 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -411,7 +411,7 @@ static int vfio_enable_vectors(VFIOPCIDevice *vdev, boo= l msix) } =20 static void vfio_add_kvm_msi_virq(VFIOPCIDevice *vdev, VFIOMSIVector *vect= or, - int vector_n, bool msix) + int vector_n, bool msix, int eventfd) { int virq; =20 @@ -419,7 +419,9 @@ static void vfio_add_kvm_msi_virq(VFIOPCIDevice *vdev, = VFIOMSIVector *vector, return; } =20 - if (event_notifier_init(&vector->kvm_interrupt, 0)) { + if (eventfd >=3D 0) { + event_notifier_init_fd(&vector->kvm_interrupt, eventfd); + } else if (event_notifier_init(&vector->kvm_interrupt, 0)) { return; } =20 @@ -455,6 +457,22 @@ static void vfio_update_kvm_msi_virq(VFIOMSIVector *ve= ctor, MSIMessage msg, kvm_irqchip_commit_routes(kvm_state); } =20 +static void vfio_vector_init(VFIOPCIDevice *vdev, int nr, int eventfd) +{ + VFIOMSIVector *vector =3D &vdev->msi_vectors[nr]; + PCIDevice *pdev =3D &vdev->pdev; + + vector->vdev =3D vdev; + vector->virq =3D -1; + if (eventfd >=3D 0) { + event_notifier_init_fd(&vector->interrupt, eventfd); + } else if (event_notifier_init(&vector->interrupt, 0)) { + error_report("vfio: Error: event_notifier_init failed"); + } + vector->use =3D true; + msix_vector_use(pdev, nr); +} + static int vfio_msix_vector_do_use(PCIDevice *pdev, unsigned int nr, MSIMessage *msg, IOHandler *handler) { @@ -466,14 +484,10 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, u= nsigned int nr, =20 vector =3D &vdev->msi_vectors[nr]; =20 + vfio_vector_init(vdev, nr, -1); + if (!vector->use) { - vector->vdev =3D vdev; - vector->virq =3D -1; - if (event_notifier_init(&vector->interrupt, 0)) { - error_report("vfio: Error: event_notifier_init failed"); - } - vector->use =3D true; - msix_vector_use(pdev, nr); + vfio_vector_init(vdev, nr, -1); } =20 qemu_set_fd_handler(event_notifier_get_fd(&vector->interrupt), @@ -491,7 +505,7 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, uns= igned int nr, } } else { if (msg) { - vfio_add_kvm_msi_virq(vdev, vector, nr, true); + vfio_add_kvm_msi_virq(vdev, vector, nr, true, -1); } } =20 @@ -641,7 +655,7 @@ retry: * Attempt to enable route through KVM irqchip, * default to userspace handling if unavailable. */ - vfio_add_kvm_msi_virq(vdev, vector, i, false); + vfio_add_kvm_msi_virq(vdev, vector, i, false, -1); } =20 /* Set interrupt type prior to possible interrupts */ diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 6141162..00acb85 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -204,6 +204,8 @@ int vfio_get_device(VFIOGroup *group, const char *name, extern const MemoryRegionOps vfio_region_ops; typedef QLIST_HEAD(VFIOGroupList, VFIOGroup) VFIOGroupList; extern VFIOGroupList vfio_group_list; +typedef QLIST_HEAD(, VFIOAddressSpace) VFIOAddressSpaceList; +extern VFIOAddressSpaceList vfio_address_spaces; =20 bool vfio_mig_active(void); int64_t vfio_mig_bytes_transferred(void); @@ -222,6 +224,7 @@ struct vfio_info_cap_header * vfio_get_device_info_cap(struct vfio_device_info *info, uint16_t id); #endif extern const MemoryListener vfio_prereg_listener; +bool vfio_listener_skipped_section(MemoryRegionSection *section); =20 int vfio_spapr_create_window(VFIOContainer *container, MemoryRegionSection *section, --=20 1.8.3.1 From nobody Sun May 5 14:17:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1620391179; cv=none; d=zohomail.com; s=zohoarc; b=Wr9AGXIPsbC+qNW0tK4Bi1gTugdUHWlXcJ1HR7Kf3govrYGT5lgCaI3MmuFN2NXE4HlefTd+AKbrECfRN9TbhZTDqe4R9GTSGIWnOUcFHryh9wgxvuHY9ivzlPpIKd+/QtW65iOvKdOOxng9Q3M1rtJYkA0J6/aIMph0ry53LWo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620391179; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=KrA6dAK5QcQr1DhOaGtAgibx2ZH/6D8Ymg5IbhdtOWE=; b=RFjvGBV91iSsl3HkzfyukVbgCi4w+aejyBQIutIdzPQHZt8JjJ9DTkbpZ24qQFJ98bKbMhJWhxa9yR2UpoVvZicC0EQlSnbQ7k8cVZtKVqcYpFer0+hqCPWyqayh9b+UikcO9Jjpq9f0xtnapvw0y25AC15PhQ3wwqBir0imzqM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620391179780306.99817483275353; Fri, 7 May 2021 05:39:39 -0700 (PDT) Received: from localhost ([::1]:57554 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lezla-0000sa-Pc for importer@patchew.org; Fri, 07 May 2021 08:39:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57398) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbW-0000kL-2M for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:14 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:43798) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbP-0001Tp-Vp for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:13 -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 147CSiRE050073; Fri, 7 May 2021 12:29:03 GMT Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 38csqvhemr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29: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 147CFkf1168203; Fri, 7 May 2021 12:29:02 GMT Received: from pps.reinject (localhost [127.0.0.1]) by userp3020.oracle.com with ESMTP id 38csrh1t6g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29:02 +0000 Received: from userp3020.oracle.com (userp3020.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 147CL07w185198; Fri, 7 May 2021 12:29:01 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3020.oracle.com with ESMTP id 38csrh1t4f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29:01 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 147CSxdP019269; Fri, 7 May 2021 12:28:59 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 07 May 2021 05:28:59 -0700 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=KrA6dAK5QcQr1DhOaGtAgibx2ZH/6D8Ymg5IbhdtOWE=; b=EQcMq85uz6RiJ2SC9TLBl/exjXLfcmMk2YJzPfS7OT4HnBGxo/NJARktoUzJPUGooHty djwg8R9OJTtUIKTCwyEMFhEWH2AiaZ3qhOeGuATSprurd3sO/JHAvIRLm7MbKBbktpvn WiSXTr4Mdj5znpZBaJOBi/Sr2UsuifN84x+6sCIp/eemQjW5U/m5tXS49rf0z4pnvJCb e8Mc1wswMsjHEsFQ2YJHkY+8eu9IUtOlAP6f8EV9a8qKQ630TKyQj409zQR4VvNOQVjZ v7aoJJhHd2S9GABmoQpowk7Eba9QSgehvJ1kMIwSzdBY//N+Ir49YvWb9PQT5FI8K77v XQ== From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V3 12/22] vfio-pci: cpr part 1 Date: Fri, 7 May 2021 05:25:10 -0700 Message-Id: <1620390320-301716-13-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> References: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-ORIG-GUID: 7QImBClTHQ_2ef4voo_85oMLluBRlTpZ X-Proofpoint-GUID: 7QImBClTHQ_2ef4voo_85oMLluBRlTpZ X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9976 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 bulkscore=0 adultscore=0 suspectscore=0 spamscore=0 impostorscore=0 phishscore=0 clxscore=1015 mlxscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105070086 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=156.151.31.85; envelope-from=steven.sistare@oracle.com; helo=userp2120.oracle.com X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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=-0.001, 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" , Jason Zeng , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Enable vfio-pci devices to be saved and restored across an exec restart of qemu. At vfio creation time, save the value of vfio container, group, and device descriptors in the environment. In cprsave, suspend the use of virtual addresses in DMA mappings with VFIO_DMA_UNMAP_FLAG_VADDR, because guest ram will be remapped at a different VA after exec. DMA to already-mapped pages continues. Save the msi message area as part of vfio-pci vmstate, save the interrupt and notifier eventfd's in the environment, and clear the close-on-exec flag for the vfio descriptors. The flag is not cleared earlier because the descriptors should not persist across miscellaneous fork and exec calls that may be performed during normal operation. On qemu restart, vfio_realize() finds the descriptor env vars, uses the descriptors, and notes that the device is being reused. Device and iommu state is already configured, so operations in vfio_realize that would modify the configuration are skipped for a reused device, including vfio ioctl's and writes to PCI configuration space. The result is that vfio_realize constructs qemu data structures that reflect the current state of the device. However, the reconstruction is not complete until cprload is called. cprload loads the msi data and finds eventfds in the environment. It rebuilds vector data structures and attaches the interrupts to the new KVM instance. cprload then walks the flattened ranges of the vfio_address_spaces and calls VFIO_DMA_MAP_FLAG_VADDR to inform the kernel of the new VA's. Lastly, it starts the VM and suppresses vfio device reset. This functionality is delivered by 2 patches for clarity. Part 2 adds eventfd and vector support. Signed-off-by: Steve Sistare --- hw/pci/msi.c | 4 ++ hw/pci/pci.c | 4 ++ hw/vfio/common.c | 59 ++++++++++++++++++- hw/vfio/cpr.c | 131 ++++++++++++++++++++++++++++++++++++++= ++++ hw/vfio/meson.build | 1 + hw/vfio/pci.c | 65 +++++++++++++++++++-- hw/vfio/trace-events | 1 + include/hw/pci/pci.h | 1 + include/hw/vfio/vfio-common.h | 5 ++ linux-headers/linux/vfio.h | 27 +++++++++ migration/cpr.c | 7 +++ 11 files changed, 298 insertions(+), 7 deletions(-) create mode 100644 hw/vfio/cpr.c diff --git a/hw/pci/msi.c b/hw/pci/msi.c index 47d2b0f..39de6a7 100644 --- a/hw/pci/msi.c +++ b/hw/pci/msi.c @@ -225,6 +225,10 @@ int msi_init(struct PCIDevice *dev, uint8_t offset, dev->msi_cap =3D config_offset; dev->cap_present |=3D QEMU_PCI_CAP_MSI; =20 + if (dev->reused) { + return 0; + } + pci_set_word(dev->config + msi_flags_off(dev), flags); pci_set_word(dev->wmask + msi_flags_off(dev), PCI_MSI_FLAGS_QSIZE | PCI_MSI_FLAGS_ENABLE); diff --git a/hw/pci/pci.c b/hw/pci/pci.c index e08d981..27019ca 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -308,6 +308,10 @@ static void pci_do_device_reset(PCIDevice *dev) { int r; =20 + if (dev->reused) { + return; + } + pci_device_deassert_intx(dev); assert(dev->irq_state =3D=3D 0); =20 diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 9220e64..00d07b2 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -31,6 +31,7 @@ #include "exec/memory.h" #include "exec/ram_addr.h" #include "hw/hw.h" +#include "qemu/env.h" #include "qemu/error-report.h" #include "qemu/main-loop.h" #include "qemu/range.h" @@ -440,6 +441,10 @@ static int vfio_dma_unmap(VFIOContainer *container, return vfio_dma_unmap_bitmap(container, iova, size, iotlb); } =20 + if (container->reused) { + return 0; + } + while (ioctl(container->fd, VFIO_IOMMU_UNMAP_DMA, &unmap)) { /* * The type1 backend has an off-by-one bug in the kernel (71a7d3d7= 8e3c @@ -463,6 +468,11 @@ static int vfio_dma_unmap(VFIOContainer *container, return -errno; } =20 + if (unmap.size !=3D size) { + warn_report("VFIO_UNMAP_DMA(0x%lx, 0x%lx) only unmaps 0x%llx", + iova, size, unmap.size); + } + return 0; } =20 @@ -477,6 +487,10 @@ static int vfio_dma_map(VFIOContainer *container, hwad= dr iova, .size =3D size, }; =20 + if (container->reused) { + return 0; + } + if (!readonly) { map.flags |=3D VFIO_DMA_MAP_FLAG_WRITE; } @@ -1603,6 +1617,10 @@ static int vfio_init_container(VFIOContainer *contai= ner, int group_fd, if (iommu_type < 0) { return iommu_type; } + if (container->reused) { + container->iommu_type =3D iommu_type; + return 0; + } =20 ret =3D ioctl(group_fd, VFIO_GROUP_SET_CONTAINER, &container->fd); if (ret) { @@ -1703,6 +1721,8 @@ static int vfio_connect_container(VFIOGroup *group, A= ddressSpace *as, { VFIOContainer *container; int ret, fd; + bool reused; + char name[40]; VFIOAddressSpace *space; =20 space =3D vfio_get_address_space(as); @@ -1739,16 +1759,29 @@ static int vfio_connect_container(VFIOGroup *group,= AddressSpace *as, return ret; } =20 + snprintf(name, sizeof(name), "vfio_container_%d", group->groupid); + fd =3D getenv_fd(name); + reused =3D (fd >=3D 0); + QLIST_FOREACH(container, &space->containers, next) { + if (fd >=3D 0 && container->fd =3D=3D fd) { + group->container =3D container; + QLIST_INSERT_HEAD(&container->group_list, group, container_nex= t); + return 0; + } if (!ioctl(group->fd, VFIO_GROUP_SET_CONTAINER, &container->fd)) { group->container =3D container; QLIST_INSERT_HEAD(&container->group_list, group, container_nex= t); vfio_kvm_device_add_group(group); + setenv_fd(name, container->fd); return 0; } } =20 - fd =3D qemu_open_old("/dev/vfio/vfio", O_RDWR); + if (fd < 0) { + fd =3D qemu_open_old("/dev/vfio/vfio", O_RDWR); + } + if (fd < 0) { error_setg_errno(errp, errno, "failed to open /dev/vfio/vfio"); ret =3D -errno; @@ -1766,6 +1799,7 @@ static int vfio_connect_container(VFIOGroup *group, A= ddressSpace *as, container =3D g_malloc0(sizeof(*container)); container->space =3D space; container->fd =3D fd; + container->reused =3D reused; container->error =3D NULL; container->dirty_pages_supported =3D false; QLIST_INIT(&container->giommu_list); @@ -1893,6 +1927,7 @@ static int vfio_connect_container(VFIOGroup *group, A= ddressSpace *as, } =20 container->initialized =3D true; + setenv_fd(name, fd); =20 return 0; listener_release_exit: @@ -1920,6 +1955,7 @@ static void vfio_disconnect_container(VFIOGroup *grou= p) =20 QLIST_REMOVE(group, container_next); group->container =3D NULL; + unsetenv_fdv("vfio_container_%d", group->groupid); =20 /* * Explicitly release the listener first before unset container, @@ -1978,7 +2014,12 @@ VFIOGroup *vfio_get_group(int groupid, AddressSpace = *as, Error **errp) group =3D g_malloc0(sizeof(*group)); =20 snprintf(path, sizeof(path), "/dev/vfio/%d", groupid); - group->fd =3D qemu_open_old(path, O_RDWR); + + group->fd =3D getenv_fd(path); + if (group->fd < 0) { + group->fd =3D qemu_open_old(path, O_RDWR); + } + if (group->fd < 0) { error_setg_errno(errp, errno, "failed to open %s", path); goto free_group_exit; @@ -2012,6 +2053,8 @@ VFIOGroup *vfio_get_group(int groupid, AddressSpace *= as, Error **errp) =20 QLIST_INSERT_HEAD(&vfio_group_list, group, next); =20 + setenv_fd(path, group->fd); + return group; =20 close_fd_exit: @@ -2036,6 +2079,7 @@ void vfio_put_group(VFIOGroup *group) vfio_disconnect_container(group); QLIST_REMOVE(group, next); trace_vfio_put_group(group->fd); + unsetenv_fdv("/dev/vfio/%d", group->groupid); close(group->fd); g_free(group); =20 @@ -2049,8 +2093,14 @@ int vfio_get_device(VFIOGroup *group, const char *na= me, { struct vfio_device_info dev_info =3D { .argsz =3D sizeof(dev_info) }; int ret, fd; + bool reused; + + fd =3D getenv_fd(name); + reused =3D (fd >=3D 0); + if (fd < 0) { + fd =3D ioctl(group->fd, VFIO_GROUP_GET_DEVICE_FD, name); + } =20 - fd =3D ioctl(group->fd, VFIO_GROUP_GET_DEVICE_FD, name); if (fd < 0) { error_setg_errno(errp, errno, "error getting device from group %d", group->groupid); @@ -2095,6 +2145,8 @@ int vfio_get_device(VFIOGroup *group, const char *nam= e, vbasedev->num_irqs =3D dev_info.num_irqs; vbasedev->num_regions =3D dev_info.num_regions; vbasedev->flags =3D dev_info.flags; + vbasedev->reused =3D reused; + setenv_fd(name, fd); =20 trace_vfio_get_device(name, dev_info.flags, dev_info.num_regions, dev_info.num_irqs); @@ -2111,6 +2163,7 @@ void vfio_put_base_device(VFIODevice *vbasedev) QLIST_REMOVE(vbasedev, next); vbasedev->group =3D NULL; trace_vfio_put_base_device(vbasedev->fd); + unsetenv_fd(vbasedev->name); close(vbasedev->fd); } =20 diff --git a/hw/vfio/cpr.c b/hw/vfio/cpr.c new file mode 100644 index 0000000..c5ad9f2 --- /dev/null +++ b/hw/vfio/cpr.c @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2021 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 +#include +#include "hw/vfio/vfio-common.h" +#include "sysemu/kvm.h" +#include "qapi/error.h" +#include "trace.h" + +static int +vfio_dma_unmap_vaddr_all(VFIOContainer *container, Error **errp) +{ + struct vfio_iommu_type1_dma_unmap unmap =3D { + .argsz =3D sizeof(unmap), + .flags =3D VFIO_DMA_UNMAP_FLAG_VADDR | VFIO_DMA_UNMAP_FLAG_ALL, + .iova =3D 0, + .size =3D 0, + }; + if (ioctl(container->fd, VFIO_IOMMU_UNMAP_DMA, &unmap)) { + error_setg_errno(errp, errno, "vfio_dma_unmap_vaddr_all"); + return -errno; + } + return 0; +} + +static int vfio_dma_map_vaddr(VFIOContainer *container, hwaddr iova, + ram_addr_t size, void *vaddr, + Error **errp) +{ + struct vfio_iommu_type1_dma_map map =3D { + .argsz =3D sizeof(map), + .flags =3D VFIO_DMA_MAP_FLAG_VADDR, + .vaddr =3D (__u64)(uintptr_t)vaddr, + .iova =3D iova, + .size =3D size, + }; + if (ioctl(container->fd, VFIO_IOMMU_MAP_DMA, &map)) { + error_setg_errno(errp, errno, + "vfio_dma_map_vaddr(iova %lu, size %ld, va %p)", + iova, size, vaddr); + return -errno; + } + return 0; +} + +static int +vfio_region_remap(MemoryRegionSection *section, void *handle, Error **errp) +{ + MemoryRegion *mr =3D section->mr; + VFIOContainer *container =3D handle; + const char *name =3D memory_region_name(mr); + ram_addr_t size =3D int128_get64(section->size); + hwaddr offset, iova, roundup; + void *vaddr; + + if (vfio_listener_skipped_section(section) || memory_region_is_iommu(m= r)) { + return 0; + } + + offset =3D section->offset_within_address_space; + iova =3D TARGET_PAGE_ALIGN(offset); + roundup =3D iova - offset; + size =3D (size - roundup) & TARGET_PAGE_MASK; + vaddr =3D memory_region_get_ram_ptr(mr) + + section->offset_within_region + roundup; + + trace_vfio_region_remap(name, container->fd, iova, iova + size - 1, va= ddr); + return vfio_dma_map_vaddr(container, iova, size, vaddr, errp); +} + +bool vfio_cpr_capable(VFIOContainer *container, Error **errp) +{ + if (!ioctl(container->fd, VFIO_CHECK_EXTENSION, VFIO_UPDATE_VADDR) || + !ioctl(container->fd, VFIO_CHECK_EXTENSION, VFIO_UNMAP_ALL)) { + error_setg(errp, "VFIO container does not support VFIO_UPDATE_VADD= R " + "or VFIO_UNMAP_ALL"); + return false; + } else { + return true; + } +} + +int vfio_cprsave(Error **errp) +{ + VFIOAddressSpace *space; + VFIOContainer *container; + + QLIST_FOREACH(space, &vfio_address_spaces, list) { + QLIST_FOREACH(container, &space->containers, next) { + if (!vfio_cpr_capable(container, errp)) { + return 1; + } + if (vfio_dma_unmap_vaddr_all(container, errp)) { + return 1; + } + } + } + return 0; +} + +int vfio_cprload(Error **errp) +{ + VFIOAddressSpace *space; + VFIOContainer *container; + VFIOGroup *group; + VFIODevice *vbasedev; + + QLIST_FOREACH(space, &vfio_address_spaces, list) { + QLIST_FOREACH(container, &space->containers, next) { + if (!vfio_cpr_capable(container, errp)) { + return 1; + } + container->reused =3D false; + if (as_flat_walk(space->as, vfio_region_remap, container, errp= )) { + return 1; + } + } + } + QLIST_FOREACH(group, &vfio_group_list, next) { + QLIST_FOREACH(vbasedev, &group->device_list, next) { + vbasedev->reused =3D false; + } + } + return 0; +} diff --git a/hw/vfio/meson.build b/hw/vfio/meson.build index da9af29..e247b2b 100644 --- a/hw/vfio/meson.build +++ b/hw/vfio/meson.build @@ -5,6 +5,7 @@ vfio_ss.add(files( 'migration.c', )) vfio_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files( + 'cpr.c', 'display.c', 'pci-quirks.c', 'pci.c', diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 7a4fb6c..f7ac9f03 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -29,6 +29,8 @@ #include "hw/qdev-properties.h" #include "hw/qdev-properties-system.h" #include "migration/vmstate.h" +#include "migration/cpr.h" +#include "qemu/env.h" #include "qemu/error-report.h" #include "qemu/main-loop.h" #include "qemu/module.h" @@ -1612,6 +1614,14 @@ static void vfio_mmap_set_enabled(VFIOPCIDevice *vde= v, bool enabled) } } =20 +static void vfio_config_sync(VFIOPCIDevice *vdev, uint32_t offset, size_t = len) +{ + if (pread(vdev->vbasedev.fd, vdev->pdev.config + offset, len, + vdev->config_offset + offset) !=3D len) { + error_report("vfio_config_sync pread failed"); + } +} + static void vfio_bar_prepare(VFIOPCIDevice *vdev, int nr) { VFIOBAR *bar =3D &vdev->bars[nr]; @@ -1652,6 +1662,7 @@ static void vfio_bars_prepare(VFIOPCIDevice *vdev) static void vfio_bar_register(VFIOPCIDevice *vdev, int nr) { VFIOBAR *bar =3D &vdev->bars[nr]; + PCIDevice *pdev =3D &vdev->pdev; char *name; =20 if (!bar->size) { @@ -1672,7 +1683,10 @@ static void vfio_bar_register(VFIOPCIDevice *vdev, i= nt nr) } } =20 - pci_register_bar(&vdev->pdev, nr, bar->type, bar->mr); + pci_register_bar(pdev, nr, bar->type, bar->mr); + if (pdev->reused) { + vfio_config_sync(vdev, pci_bar(pdev, nr), 8); + } } =20 static void vfio_bars_register(VFIOPCIDevice *vdev) @@ -2884,6 +2898,7 @@ static void vfio_realize(PCIDevice *pdev, Error **err= p) vfio_put_group(group); goto error; } + pdev->reused =3D vdev->vbasedev.reused; =20 vfio_populate_device(vdev, &err); if (err) { @@ -3046,9 +3061,11 @@ static void vfio_realize(PCIDevice *pdev, Error **er= rp) vfio_intx_routing_notifier); vdev->irqchip_change_notifier.notify =3D vfio_irqchip_change; kvm_irqchip_add_change_notifier(&vdev->irqchip_change_notifier); - ret =3D vfio_intx_enable(vdev, errp); - if (ret) { - goto out_deregister; + if (!pdev->reused) { + ret =3D vfio_intx_enable(vdev, errp); + if (ret) { + goto out_deregister; + } } } =20 @@ -3098,6 +3115,11 @@ static void vfio_realize(PCIDevice *pdev, Error **er= rp) vfio_register_req_notifier(vdev); vfio_setup_resetfn_quirk(vdev); =20 + vfio_config_sync(vdev, pdev->msix_cap + PCI_MSIX_FLAGS, 2); + if (pdev->reused) { + pci_update_mappings(pdev); + } + return; =20 out_deregister: @@ -3153,6 +3175,10 @@ static void vfio_pci_reset(DeviceState *dev) { VFIOPCIDevice *vdev =3D VFIO_PCI(dev); =20 + if (vdev->pdev.reused) { + return; + } + trace_vfio_pci_reset(vdev->vbasedev.name); =20 vfio_pci_pre_reset(vdev); @@ -3260,6 +3286,36 @@ static Property vfio_pci_dev_properties[] =3D { DEFINE_PROP_END_OF_LIST(), }; =20 +static int vfio_pci_post_load(void *opaque, int version_id) +{ + VFIOPCIDevice *vdev =3D opaque; + PCIDevice *pdev =3D &vdev->pdev; + bool enabled; + + pdev->reused =3D false; + enabled =3D pci_get_word(pdev->config + PCI_COMMAND) & PCI_COMMAND_MAS= TER; + memory_region_set_enabled(&pdev->bus_master_enable_region, enabled); + + return 0; +} + +static bool vfio_pci_needed(void *opaque) +{ + return cpr_active(); +} + +static const VMStateDescription vfio_pci_vmstate =3D { + .name =3D "vfio-pci", + .unmigratable =3D 1, + .version_id =3D 0, + .minimum_version_id =3D 0, + .post_load =3D vfio_pci_post_load, + .needed =3D vfio_pci_needed, + .fields =3D (VMStateField[]) { + VMSTATE_END_OF_LIST() + } +}; + static void vfio_pci_dev_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); @@ -3267,6 +3323,7 @@ static void vfio_pci_dev_class_init(ObjectClass *klas= s, void *data) =20 dc->reset =3D vfio_pci_reset; device_class_set_props(dc, vfio_pci_dev_properties); + dc->vmsd =3D &vfio_pci_vmstate; dc->desc =3D "VFIO-based PCI device assignment"; set_bit(DEVICE_CATEGORY_MISC, dc->categories); pdc->realize =3D vfio_realize; diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index 079f53a..0f8b166 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -118,6 +118,7 @@ vfio_region_sparse_mmap_header(const char *name, int in= dex, int nr_areas) "Devic vfio_region_sparse_mmap_entry(int i, unsigned long start, unsigned long en= d) "sparse entry %d [0x%lx - 0x%lx]" vfio_get_dev_region(const char *name, int index, uint32_t type, uint32_t s= ubtype) "%s index %d, %08x/%0x8" vfio_dma_unmap_overflow_workaround(void) "" +vfio_region_remap(const char *name, int fd, uint64_t iova_start, uint64_t = iova_end, void *vaddr) "%s fd %d 0x%"PRIx64" - 0x%"PRIx64" [%p]" =20 # platform.c vfio_platform_base_device_init(char *name, int groupid) "%s belongs to gro= up #%d" diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index bef3e49..add7f46 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -360,6 +360,7 @@ struct PCIDevice { /* ID of standby device in net_failover pair */ char *failover_pair_id; uint32_t acpi_index; + bool reused; }; =20 void pci_register_bar(PCIDevice *pci_dev, int region_num, diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 00acb85..b46d850 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -85,6 +85,7 @@ typedef struct VFIOContainer { Error *error; bool initialized; bool dirty_pages_supported; + bool reused; uint64_t dirty_pgsizes; uint64_t max_dirty_bitmap_size; unsigned long pgsizes; @@ -124,6 +125,7 @@ typedef struct VFIODevice { bool no_mmap; bool ram_block_discard_allowed; bool enable_migration; + bool reused; VFIODeviceOps *ops; unsigned int num_irqs; unsigned int num_regions; @@ -200,6 +202,9 @@ VFIOGroup *vfio_get_group(int groupid, AddressSpace *as= , Error **errp); void vfio_put_group(VFIOGroup *group); int vfio_get_device(VFIOGroup *group, const char *name, VFIODevice *vbasedev, Error **errp); +int vfio_cprsave(Error **errp); +int vfio_cprload(Error **errp); +bool vfio_cpr_capable(VFIOContainer *container, Error **errp); =20 extern const MemoryRegionOps vfio_region_ops; typedef QLIST_HEAD(VFIOGroupList, VFIOGroup) VFIOGroupList; diff --git a/linux-headers/linux/vfio.h b/linux-headers/linux/vfio.h index 609099e..bc3a66e 100644 --- a/linux-headers/linux/vfio.h +++ b/linux-headers/linux/vfio.h @@ -46,6 +46,12 @@ */ #define VFIO_NOIOMMU_IOMMU 8 =20 +/* Supports VFIO_DMA_UNMAP_FLAG_ALL */ +#define VFIO_UNMAP_ALL 9 + +/* Supports VFIO DMA map and unmap with the VADDR flag */ +#define VFIO_UPDATE_VADDR 10 + /* * The IOCTL interface is designed for extensibility by embedding the * structure length (argsz) and flags into structures passed between @@ -1074,12 +1080,22 @@ struct vfio_iommu_type1_info_dma_avail { * * Map process virtual addresses to IO virtual addresses using the * provided struct vfio_dma_map. Caller sets argsz. READ &/ WRITE required. + * + * If flags & VFIO_DMA_MAP_FLAG_VADDR, record the new base vaddr for iova,= and + * unblock translation of host virtual addresses in the iova range. The v= addr + * must have previously been invalidated with VFIO_DMA_UNMAP_FLAG_VADDR. = To + * maintain memory consistency within the user application, the updated va= ddr + * must address the same memory object as originally mapped. Failure to d= o so + * will result in user memory corruption and/or device misbehavior. iova = and + * size must match those in the original MAP_DMA call. Protection is not + * changed, and the READ & WRITE flags must be 0. */ struct vfio_iommu_type1_dma_map { __u32 argsz; __u32 flags; #define VFIO_DMA_MAP_FLAG_READ (1 << 0) /* readable from device */ #define VFIO_DMA_MAP_FLAG_WRITE (1 << 1) /* writable from device */ +#define VFIO_DMA_MAP_FLAG_VADDR (1 << 2) __u64 vaddr; /* Process virtual address */ __u64 iova; /* IO virtual address */ __u64 size; /* Size of mapping (bytes) */ @@ -1102,6 +1118,7 @@ struct vfio_bitmap { * field. No guarantee is made to the user that arbitrary unmaps of iova * or size different from those used in the original mapping call will * succeed. + * * VFIO_DMA_UNMAP_FLAG_GET_DIRTY_BITMAP should be set to get the dirty bit= map * before unmapping IO virtual addresses. When this flag is set, the user = must * provide a struct vfio_bitmap in data[]. User must provide zero-allocated @@ -1111,11 +1128,21 @@ struct vfio_bitmap { * indicates that the page at that offset from iova is dirty. A Bitmap of = the * pages in the range of unmapped size is returned in the user-provided * vfio_bitmap.data. + * + * If flags & VFIO_DMA_UNMAP_FLAG_ALL, unmap all addresses. iova and size + * must be 0. This cannot be combined with the get-dirty-bitmap flag. + * + * If flags & VFIO_DMA_UNMAP_FLAG_VADDR, do not unmap, but invalidate host + * virtual addresses in the iova range. Tasks that attempt to translate an + * iova's vaddr will block. DMA to already-mapped pages continues. This + * cannot be combined with the get-dirty-bitmap flag. */ struct vfio_iommu_type1_dma_unmap { __u32 argsz; __u32 flags; #define VFIO_DMA_UNMAP_FLAG_GET_DIRTY_BITMAP (1 << 0) +#define VFIO_DMA_UNMAP_FLAG_ALL (1 << 1) +#define VFIO_DMA_UNMAP_FLAG_VADDR (1 << 2) __u64 iova; /* IO virtual address */ __u64 size; /* Size of mapping (bytes) */ __u8 data[]; diff --git a/migration/cpr.c b/migration/cpr.c index e0da1cf..e9a189b 100644 --- a/migration/cpr.c +++ b/migration/cpr.c @@ -132,6 +132,9 @@ void cprsave(const char *file, CprMode mode, Error **er= rp) shutdown_action =3D SHUTDOWN_ACTION_POWEROFF; qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); } else if (restart) { + if (vfio_cprsave(errp)) { + goto err; + } walkenv(FD_PREFIX, preserve_fd, 0); setenv("QEMU_START_FREEZE", "", 1); qemu_system_exec_request(); @@ -176,6 +179,10 @@ void cprload(const char *file, Error **errp) return; } =20 + if (vfio_cprload(errp)) { + return; + } + state =3D global_state_get_runstate(); if (state =3D=3D RUN_STATE_RUNNING) { vm_start(); --=20 1.8.3.1 From nobody Sun May 5 14:17:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1620391638; cv=none; d=zohomail.com; s=zohoarc; b=QdspBwemKQe1slayEx8VQpWrNep22VGMntEmmvHi9ykkzVzBqgHQsMep+KHz1scUb6N/ZjsX43PGUuYJyUjncY4YG9Chrbxee25yak0oaWlUMtGNrz+P5nnBZ4W9vdoODsm0sEaGW5z/19FyRBSWtCNscwMFL8Rew96j+ijPinI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620391638; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=610NsNf8Rel74OcPl+ylnlOHqqH7HT/kL5NeuPJY+JI=; b=Qu6Wjs3wkopL8Z4rC6KFfgymzy/7EbFeMdzrdWfhJycNTUwDIZYyE6oUR76Sh2wJCYjhI/pKKGyoeKyzzLPjLM5otwdZ0efvpu+kbvQSiDgnOv3hlA2CdndaT18xbCVxoYjrAvVWHbOndFCbbB1hJUFsK8sOIFFM0HvwYC9s5UY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620391638553300.5760320096797; Fri, 7 May 2021 05:47:18 -0700 (PDT) Received: from localhost ([::1]:46210 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lezsz-0008BO-D5 for importer@patchew.org; Fri, 07 May 2021 08:47:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57380) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbV-0000jA-Dg for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:13 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:49960) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbO-0001Tb-HR for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:13 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 147CDbak148649; Fri, 7 May 2021 12:29:03 GMT Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2130.oracle.com with ESMTP id 38csrd9ewj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29:03 +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 147CFX6F068826; Fri, 7 May 2021 12:29:03 GMT Received: from pps.reinject (localhost [127.0.0.1]) by aserp3030.oracle.com with ESMTP id 38csrev2km-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29:03 +0000 Received: from aserp3030.oracle.com (aserp3030.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 147CPqAF098030; Fri, 7 May 2021 12:29:02 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 38csrev2ju-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29:02 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 147CT0Wd016424; Fri, 7 May 2021 12:29:00 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 07 May 2021 05:29:00 -0700 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=610NsNf8Rel74OcPl+ylnlOHqqH7HT/kL5NeuPJY+JI=; b=j0KOGWgVqgKYSTzHigOSMhBFaRpM0DugtnEprUyh5GhWomyRiU6a/Rl6Z+rH4hhMPzl8 sMdXjqYBNBXXh3C+lBFUntMkKTq5TiVf72L5DCYxl1PWHjx45Enq1WG0ggteiUEvfEdn MK9q2iGTX3tM4ML3Og57NvYyBdqdtQWcnTWsoNNF85p0EUFNMGCRJ5TDm2D4BKH2hajI 44TLsin0hb/ranaK71qjHgxabQ2elxeVt19sgwuB5O3V04DVNuGzUg87cBBeTF6ynyNm VcxJcwCtxsFRTnY4JJahJTqEBz1sHkqzdEsx3VA9t6tqKB2mfH87Antm5z0GeW+giDYZ Kw== From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V3 13/22] vfio-pci: cpr part 2 Date: Fri, 7 May 2021 05:25:11 -0700 Message-Id: <1620390320-301716-14-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> References: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-ORIG-GUID: HWA7JgLFdeHbHGWQkC6ZWdiRPq-r1QqF X-Proofpoint-GUID: HWA7JgLFdeHbHGWQkC6ZWdiRPq-r1QqF X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9976 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 clxscore=1015 malwarescore=0 adultscore=0 mlxlogscore=999 impostorscore=0 phishscore=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105070085 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=141.146.126.79; envelope-from=steven.sistare@oracle.com; helo=aserp2130.oracle.com X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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" , Jason Zeng , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Finish cpr for vfio-pci by preserving eventfd's and vector state. Signed-off-by: Steve Sistare --- hw/vfio/pci.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++= ++-- 1 file changed, 108 insertions(+), 2 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index f7ac9f03..e983db4 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2661,6 +2661,27 @@ static void vfio_put_device(VFIOPCIDevice *vdev) vfio_put_base_device(&vdev->vbasedev); } =20 +static void setenv_event_fd(VFIOPCIDevice *vdev, int nr, const char *name, + EventNotifier *ev) +{ + char envname[256]; + int fd =3D event_notifier_get_fd(ev); + const char *vfname =3D vdev->vbasedev.name; + + if (fd >=3D 0) { + snprintf(envname, sizeof(envname), "%s_%s_%d", vfname, name, nr); + setenv_fd(envname, fd); + } +} + +static int getenv_event_fd(VFIOPCIDevice *vdev, int nr, const char *name) +{ + char envname[256]; + const char *vfname =3D vdev->vbasedev.name; + snprintf(envname, sizeof(envname), "%s_%s_%d", vfname, name, nr); + return getenv_fd(envname); +} + static void vfio_err_notifier_handler(void *opaque) { VFIOPCIDevice *vdev =3D opaque; @@ -2692,7 +2713,13 @@ static void vfio_err_notifier_handler(void *opaque) static void vfio_register_err_notifier(VFIOPCIDevice *vdev) { Error *err =3D NULL; - int32_t fd; + int32_t fd =3D getenv_event_fd(vdev, 0, "err"); + + if (fd >=3D 0) { + event_notifier_init_fd(&vdev->err_notifier, fd); + qemu_set_fd_handler(fd, vfio_err_notifier_handler, NULL, vdev); + return; + } =20 if (!vdev->pci_aer) { return; @@ -2753,7 +2780,14 @@ static void vfio_register_req_notifier(VFIOPCIDevice= *vdev) struct vfio_irq_info irq_info =3D { .argsz =3D sizeof(irq_info), .index =3D VFIO_PCI_REQ_IRQ_INDEX }; Error *err =3D NULL; - int32_t fd; + int32_t fd =3D getenv_event_fd(vdev, 0, "req"); + + if (fd >=3D 0) { + event_notifier_init_fd(&vdev->req_notifier, fd); + qemu_set_fd_handler(fd, vfio_req_notifier_handler, NULL, vdev); + vdev->req_enabled =3D true; + return; + } =20 if (!(vdev->features & VFIO_FEATURE_ENABLE_REQ)) { return; @@ -3286,12 +3320,82 @@ static Property vfio_pci_dev_properties[] =3D { DEFINE_PROP_END_OF_LIST(), }; =20 +static int vfio_pci_pre_save(void *opaque) +{ + VFIOPCIDevice *vdev =3D opaque; + int i; + + for (i =3D 0; i < vdev->nr_vectors; i++) { + VFIOMSIVector *vector =3D &vdev->msi_vectors[i]; + if (vector->use) { + setenv_event_fd(vdev, i, "interrupt", &vector->interrupt); + if (vector->virq >=3D 0) { + setenv_event_fd(vdev, i, "kvm_interrupt", + &vector->kvm_interrupt); + } + } + } + setenv_event_fd(vdev, 0, "err", &vdev->err_notifier); + setenv_event_fd(vdev, 0, "req", &vdev->req_notifier); + return 0; +} + +static void vfio_claim_vectors(VFIOPCIDevice *vdev, int nr_vectors, bool m= six) +{ + int i, fd; + bool pending =3D false; + PCIDevice *pdev =3D &vdev->pdev; + + vdev->nr_vectors =3D nr_vectors; + vdev->msi_vectors =3D g_new0(VFIOMSIVector, nr_vectors); + vdev->interrupt =3D msix ? VFIO_INT_MSIX : VFIO_INT_MSI; + + for (i =3D 0; i < nr_vectors; i++) { + VFIOMSIVector *vector =3D &vdev->msi_vectors[i]; + + fd =3D getenv_event_fd(vdev, i, "interrupt"); + if (fd >=3D 0) { + vfio_vector_init(vdev, i, fd); + qemu_set_fd_handler(fd, vfio_msi_interrupt, NULL, vector); + } + + fd =3D getenv_event_fd(vdev, i, "kvm_interrupt"); + if (fd >=3D 0) { + vfio_add_kvm_msi_virq(vdev, vector, i, msix, fd); + } + + if (msix && msix_is_pending(pdev, i) && msix_is_masked(pdev, i)) { + set_bit(i, vdev->msix->pending); + pending =3D true; + } + } + + if (msix) { + memory_region_set_enabled(&pdev->msix_pba_mmio, pending); + } +} + static int vfio_pci_post_load(void *opaque, int version_id) { VFIOPCIDevice *vdev =3D opaque; PCIDevice *pdev =3D &vdev->pdev; + int nr_vectors; bool enabled; =20 + if (msix_enabled(pdev)) { + nr_vectors =3D vdev->msix->entries; + vfio_claim_vectors(vdev, nr_vectors, true); + msix_init_vector_notifiers(pdev, vfio_msix_vector_use, + vfio_msix_vector_release, NULL); + + } else if (msi_enabled(pdev)) { + nr_vectors =3D msi_nr_vectors_allocated(pdev); + vfio_claim_vectors(vdev, nr_vectors, false); + + } else if (vfio_pci_read_config(pdev, PCI_INTERRUPT_PIN, 1)) { + error_report("vfio_pci_post_load does not support INTX"); + } + pdev->reused =3D false; enabled =3D pci_get_word(pdev->config + PCI_COMMAND) & PCI_COMMAND_MAS= TER; memory_region_set_enabled(&pdev->bus_master_enable_region, enabled); @@ -3310,8 +3414,10 @@ static const VMStateDescription vfio_pci_vmstate =3D= { .version_id =3D 0, .minimum_version_id =3D 0, .post_load =3D vfio_pci_post_load, + .pre_save =3D vfio_pci_pre_save, .needed =3D vfio_pci_needed, .fields =3D (VMStateField[]) { + VMSTATE_MSIX(pdev, VFIOPCIDevice), VMSTATE_END_OF_LIST() } }; --=20 1.8.3.1 From nobody Sun May 5 14:17:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1620391416; cv=none; d=zohomail.com; s=zohoarc; b=TpowKeXSeILB8LGRNg7PqMkb5DwoshCuOMT7n9hgJ5knxF2TQjw1mk+Z7mFqY+8ymA8ZXv3oC48nIyWXPGORz+NiRtuMVaEiauM6tN9P0T0p67erSVO+kJwZpwrOusF06IlFyImdeNkyH96VdwatcdL0Bz9QV8QIYgVn8y7Cn2U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620391416; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=JfjHWFHUNhb7JM67PxW1K1BAotVKjQnVbNBqz87553U=; b=iNYbHCfviAkraScp/KLwGsk2OqSGfSeSaEI53Jq6n+NVJVJ89JxmPkw1RKCSwUwYrpozR28eeL84bKf6zEpqnSWD8x+cDt1inaafHqjdl9IfaXCpAaRA+8FuxZtb+FxMznezvwReNJhSiPYBDcD33WmoibkYmClBz9zE8P8YPq0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620391416321727.6993379774511; Fri, 7 May 2021 05:43:36 -0700 (PDT) Received: from localhost ([::1]:37786 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lezpP-0004V1-Ga for importer@patchew.org; Fri, 07 May 2021 08:43:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57340) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbU-0000g2-3s for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:12 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:49986) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbP-0001Tr-TO for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:11 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 147CEJtJ148872; Fri, 7 May 2021 12:29:05 GMT Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2130.oracle.com with ESMTP id 38csrd9ewm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29: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 147CFkMl168017; Fri, 7 May 2021 12:29:04 GMT Received: from pps.reinject (localhost [127.0.0.1]) by userp3020.oracle.com with ESMTP id 38csrh1t9r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29:04 +0000 Received: from userp3020.oracle.com (userp3020.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 147CT3K6014655; Fri, 7 May 2021 12:29:03 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3020.oracle.com with ESMTP id 38csrh1t8c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29:03 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 147CT1Vm016430; Fri, 7 May 2021 12:29:01 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 07 May 2021 05:29:01 -0700 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=JfjHWFHUNhb7JM67PxW1K1BAotVKjQnVbNBqz87553U=; b=aIQNWHXzKS1n0T6GUQeUQ4k7pUFITq8pSxmsH+iiykdut9mnuURuhxFfermOa2Ehb8tH lOC6EvNRtdg3ez4GE2ae8S+oGITnz8Rj74T9Lz+tgLpO2H/mRV8uNOKPVHEKdDULx1eR N3x6d8NKm+1NGbVFfMdjJDrXIYI6LkDFN11W0V2uNdS8GKci5Q84VJPo4gWM7+sRvqTR LoZ4i4Lc1HAjIUtSHJV0/A2svyKjFKiECoap4E5iWe9vKGggUvBm5+1vQg6P518dken4 rrkfQUKmiOcIoLdknqRaHY8DGagbk2BnpLthDXqg3R4OqEURTLyAbHd5H7yi1vhOgpVH +Q== From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V3 14/22] vhost: reset vhost devices upon cprsave Date: Fri, 7 May 2021 05:25:12 -0700 Message-Id: <1620390320-301716-15-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> References: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-ORIG-GUID: iqFO6HJQCikgcx2EFq3caxffR8ecit2d X-Proofpoint-GUID: iqFO6HJQCikgcx2EFq3caxffR8ecit2d X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9976 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 clxscore=1015 malwarescore=0 adultscore=0 mlxlogscore=999 impostorscore=0 phishscore=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105070085 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=141.146.126.79; envelope-from=steven.sistare@oracle.com; helo=aserp2130.oracle.com X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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" , Jason Zeng , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" A vhost device is implicitly preserved across re-exec because its fd is not closed, and the value of the fd is specified on the command line for the new qemu to find. However, new qemu issues an VHOST_RESET_OWNER ioctl, which fails because the device already has an owner. To fix, reset the owner prior to exec. Signed-off-by: Mark Kanda Signed-off-by: Steve Sistare --- hw/virtio/vhost.c | 11 +++++++++++ include/hw/virtio/vhost.h | 1 + migration/cpr.c | 1 + 3 files changed, 13 insertions(+) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index e2163a0..8c0c9c3 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1820,6 +1820,17 @@ void vhost_dev_stop(struct vhost_dev *hdev, VirtIODe= vice *vdev) hdev->vdev =3D NULL; } =20 +void vhost_dev_reset_all(void) +{ + struct vhost_dev *dev; + + QLIST_FOREACH(dev, &vhost_devices, entry) { + if (dev->vhost_ops->vhost_reset_device(dev) < 0) { + VHOST_OPS_DEBUG("vhost_reset_device failed"); + } + } +} + int vhost_net_set_backend(struct vhost_dev *hdev, struct vhost_vring_file *file) { diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 4a8bc75..71704d4 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -106,6 +106,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque, void vhost_dev_cleanup(struct vhost_dev *hdev); int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev); void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev); +void vhost_dev_reset_all(void); int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev); void vhost_dev_disable_notifiers(struct vhost_dev *hdev, VirtIODevice *vde= v); =20 diff --git a/migration/cpr.c b/migration/cpr.c index e9a189b..3cde26f 100644 --- a/migration/cpr.c +++ b/migration/cpr.c @@ -136,6 +136,7 @@ void cprsave(const char *file, CprMode mode, Error **er= rp) goto err; } walkenv(FD_PREFIX, preserve_fd, 0); + vhost_dev_reset_all(); setenv("QEMU_START_FREEZE", "", 1); qemu_system_exec_request(); } --=20 1.8.3.1 From nobody Sun May 5 14:17:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1620391004; cv=none; d=zohomail.com; s=zohoarc; b=kOqlb4whEGR1sN9NIx3WuOLBF/dHIB0e7QEmrnensRj22IIvqA6Pz3Zt00Q7EhozJ5UYOqljZIj0agFWQ15WLPEb0gfsJfgZH91cZW1fBYJGX+y+TzGm4P7RsBQKm4IkEYq4TVnyf4SGAmhRs1F/HE9+zU1NRoWmluDN2G8knyk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620391004; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=c0E/zcDJGjSGN7JHoqA7EjNGE+X5H2Tp4mcfHSW8Qr4=; b=dkCOlAhsJwnSK28+TCzY6JIy2FnqwcqgaKH0xLabRso3zx5ZSESwP77KsC/8fldy9nnzhw0RQePleFWyKI7/9LWA0QFT33ilqWXLLN2+1nijGNwLkgUkWtEvs5HDl4aTb5iyq0IMSLBagX0mar3Fq8S5e6lSUSWSzA815ScBUGg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620391004301349.756614952826; Fri, 7 May 2021 05:36:44 -0700 (PDT) Received: from localhost ([::1]:48934 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lezil-0005mq-JS for importer@patchew.org; Fri, 07 May 2021 08:36:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57352) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbU-0000hF-Kq for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:12 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:49994) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbQ-0001U6-L1 for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:12 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 147CEs7u149340; Fri, 7 May 2021 12:29:05 GMT Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2130.oracle.com with ESMTP id 38csrd9ewn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29:05 +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 147CFl05168295; Fri, 7 May 2021 12:29:04 GMT Received: from pps.reinject (localhost [127.0.0.1]) by userp3020.oracle.com with ESMTP id 38csrh1tac-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29:04 +0000 Received: from userp3020.oracle.com (userp3020.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 147CT31n014690; Fri, 7 May 2021 12:29:03 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3020.oracle.com with ESMTP id 38csrh1t8k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29:03 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 147CT2Uo017250; Fri, 7 May 2021 12:29:02 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 07 May 2021 05:29:02 -0700 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=c0E/zcDJGjSGN7JHoqA7EjNGE+X5H2Tp4mcfHSW8Qr4=; b=gu0MAozimc0XuUCL4QzEZ7HW30F1vYofIgRACYwdeejRAY76Dg7x+u0rAbAzjgz9B1U2 cNq2J2EZ6dzjwEdpJNk6S3xfGXigfubVFNWo9823a+A9hWObgpKVnvoHrZFaCRSCzLNd ehC3QVwmapLXihafgJd3GgDLj/raWsmV2/DiPtj7M9N1lG3rB3HposbnPbkEPpRKCFzf gsMbV/5LN0MIbfNQa+KQlmhyEpHihT+eMJhMMRumdCpXWjO+krdBXT1F0Wc0Rx6xJBPP 5f5tKzuE3ftGcQm7ANhIRMtVCCD9f2scrKp+050tvbBBUvBnQ7CMeTRnepfiXcNiUDVe qQ== From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V3 15/22] hostmem-memfd: cpr support Date: Fri, 7 May 2021 05:25:13 -0700 Message-Id: <1620390320-301716-16-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> References: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-ORIG-GUID: 6m-KbUIzjW9l9fxyUapDCqG7Hir5Qox1 X-Proofpoint-GUID: 6m-KbUIzjW9l9fxyUapDCqG7Hir5Qox1 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9976 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 clxscore=1015 malwarescore=0 adultscore=0 mlxlogscore=999 impostorscore=0 phishscore=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105070085 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=141.146.126.79; envelope-from=steven.sistare@oracle.com; helo=aserp2130.oracle.com X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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" , Jason Zeng , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Preserve memory-backend-memfd memory objects during cpr. Signed-off-by: Steve Sistare --- backends/hostmem-memfd.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/backends/hostmem-memfd.c b/backends/hostmem-memfd.c index 69b0ae3..3503c89 100644 --- a/backends/hostmem-memfd.c +++ b/backends/hostmem-memfd.c @@ -15,6 +15,7 @@ #include "sysemu/sysemu.h" #include "qom/object_interfaces.h" #include "qemu/memfd.h" +#include "qemu/env.h" #include "qemu/module.h" #include "qapi/error.h" #include "qom/object.h" @@ -36,23 +37,25 @@ static void memfd_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) { HostMemoryBackendMemfd *m =3D MEMORY_BACKEND_MEMFD(backend); - char *name; - int fd; + char *name =3D host_memory_backend_get_name(backend); + int fd =3D getenv_fd(name); =20 if (!backend->size) { error_setg(errp, "can't create backend with size 0"); return; } =20 - fd =3D qemu_memfd_create(TYPE_MEMORY_BACKEND_MEMFD, backend->size, - m->hugetlb, m->hugetlbsize, m->seal ? - F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_SEAL : 0, - errp); - if (fd =3D=3D -1) { - return; + if (fd < 0) { + fd =3D qemu_memfd_create(TYPE_MEMORY_BACKEND_MEMFD, backend->size, + m->hugetlb, m->hugetlbsize, m->seal ? + F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_SEAL := 0, + errp); + if (fd =3D=3D -1) { + return; + } + setenv_fd(name, fd); } =20 - name =3D host_memory_backend_get_name(backend); memory_region_init_ram_from_fd(&backend->mr, OBJECT(backend), name, backend->size, backend->share, fd, 0, errp); --=20 1.8.3.1 From nobody Sun May 5 14:17:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1620391613; cv=none; d=zohomail.com; s=zohoarc; b=FqMv/gW5HUojj9Dh0+EZvK2uqlUGOFuEHiIMw3UxZDgBPHKfpmt8g4MK/tHRLWAY011VnnZrMm2rFp57mkWGOerGCSLur1dks85jxiYKpjFWhvoOXFJFAthMxx17VwXaeaXNQQAcdZD9Z1sJp0OT0eim6bN5ddIjGMOVAziVDXE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620391613; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=udyIHUkIBkYcTm208Cn0jkThzE9j/33KP3icVIEe804=; b=KgaynJtZsDdKcilEcS1bFq1d9FlST9dbv7UC1u1CJOsnA0E485NZFMLMTXAWzvRQ0KEvIWIHVYSCpZJ+pdTJV4VWL4yWO28jAzE/hBr+P8UfjIDa7PGMygTPvXZKY9mKU3FlDlvXnGENMqcYdstjKyn/qqWe3KCQ9hyPusAnpUw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620391613412278.70907016875947; Fri, 7 May 2021 05:46:53 -0700 (PDT) Received: from localhost ([::1]:45690 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lezsa-0007yb-LZ for importer@patchew.org; Fri, 07 May 2021 08:46:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57462) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbZ-0000sD-0f for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:17 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:49996) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbQ-0001UA-Pa for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:16 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 147CDcGZ148663; Fri, 7 May 2021 12:29:05 GMT Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2130.oracle.com with ESMTP id 38csrd9ewp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29: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 147CGQh9173728; Fri, 7 May 2021 12:29:05 GMT Received: from pps.reinject (localhost [127.0.0.1]) by aserp3020.oracle.com with ESMTP id 38csrtb69w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29:04 +0000 Received: from aserp3020.oracle.com (aserp3020.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 147CKq51192424; Fri, 7 May 2021 12:29:04 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 38csrtb69e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29:04 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 147CT3Xw019311; Fri, 7 May 2021 12:29:03 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 07 May 2021 05:29:03 -0700 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=udyIHUkIBkYcTm208Cn0jkThzE9j/33KP3icVIEe804=; b=QLbu0G4Z/ZB/nNBbFRMOjt4wCDF/PqmCxezDVxbI23EFcgMwdyG1uMLvXJ3MpRN1zq3B JfB2fkeZGU6zO2JZ19T9vTUvAkdbq2Jok8XWNuSsHGlx1uHCOf4FZ6rssZxsFIs8iBym gFEZnPLLhV29lx1Q/QbVdSKCd+WQf2ZHr/WM6zocrHsJoN7HlZz+dkENFFgX7UCziXLP pKwS9nCezSd+FibIRyNDY7tb9a4SXLZyPV4cIb+S1fBROSPl4Dv7Nz8qRY0piPJpjquU AW6ma/B//GYkFHp6MWpdaySHbdtWfoNakk+Fm0d9j6JGm4+O9s8iBmU4eQd71s35Q1xa cA== From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V3 16/22] chardev: cpr framework Date: Fri, 7 May 2021 05:25:14 -0700 Message-Id: <1620390320-301716-17-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> References: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-ORIG-GUID: frjONlfxf3J8JVbLIGtihAbww31sx6b2 X-Proofpoint-GUID: frjONlfxf3J8JVbLIGtihAbww31sx6b2 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9976 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 clxscore=1015 malwarescore=0 adultscore=0 mlxlogscore=999 impostorscore=0 phishscore=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105070085 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=141.146.126.79; envelope-from=steven.sistare@oracle.com; helo=aserp2130.oracle.com X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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" , Jason Zeng , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add QEMU_CHAR_FEATURE_CPR for devices that support cpr. Add the chardev close_on_cpr option for devices that can be closed on cpr and reopened after exec. cpr is allowed only if either QEMU_CHAR_FEATURE_CPR or close_on_cpr is set for all chardevs in the configuration. Signed-off-by: Steve Sistare --- chardev/char.c | 41 ++++++++++++++++++++++++++++++++++++++--- include/chardev/char.h | 5 +++++ migration/cpr.c | 3 +++ qapi/char.json | 5 ++++- qemu-options.hx | 26 ++++++++++++++++++++++---- 5 files changed, 72 insertions(+), 8 deletions(-) diff --git a/chardev/char.c b/chardev/char.c index 398f09d..596d4f9 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -37,6 +37,7 @@ #include "qemu/help_option.h" #include "qemu/module.h" #include "qemu/option.h" +#include "qemu/env.h" #include "qemu/id.h" #include "qemu/coroutine.h" #include "qemu/yank.h" @@ -240,6 +241,9 @@ static void qemu_char_open(Chardev *chr, ChardevBackend= *backend, ChardevClass *cc =3D CHARDEV_GET_CLASS(chr); /* Any ChardevCommon member would work */ ChardevCommon *common =3D backend ? backend->u.null.data : NULL; + char fdname[40]; + + chr->close_on_cpr =3D (common && common->close_on_cpr); =20 if (common && common->has_logfile) { int flags =3D O_WRONLY | O_CREAT; @@ -249,7 +253,14 @@ static void qemu_char_open(Chardev *chr, ChardevBacken= d *backend, } else { flags |=3D O_TRUNC; } - chr->logfd =3D qemu_open_old(common->logfile, flags, 0666); + snprintf(fdname, sizeof(fdname), "%s_log", chr->label); + chr->logfd =3D getenv_fd(fdname); + if (chr->logfd < 0) { + chr->logfd =3D qemu_open_old(common->logfile, flags, 0666); + if (!chr->close_on_cpr) { + setenv_fd(fdname, chr->logfd); + } + } if (chr->logfd < 0) { error_setg_errno(errp, errno, "Unable to open logfile %s", @@ -301,11 +312,12 @@ static void char_finalize(Object *obj) if (chr->be) { chr->be->chr =3D NULL; } - g_free(chr->filename); - g_free(chr->label); if (chr->logfd !=3D -1) { close(chr->logfd); + unsetenv_fdv("%s_log", chr->label); } + g_free(chr->filename); + g_free(chr->label); qemu_mutex_destroy(&chr->chr_write_lock); } =20 @@ -505,6 +517,8 @@ void qemu_chr_parse_common(QemuOpts *opts, ChardevCommo= n *backend) =20 backend->has_logappend =3D true; backend->logappend =3D qemu_opt_get_bool(opts, "logappend", false); + + backend->close_on_cpr =3D qemu_opt_get_bool(opts, "close-on-cpr", fals= e); } =20 static const ChardevClass *char_get_class(const char *driver, Error **errp) @@ -940,6 +954,9 @@ QemuOptsList qemu_chardev_opts =3D { },{ .name =3D "abstract", .type =3D QEMU_OPT_BOOL, + },{ + .name =3D "close-on-cpr", + .type =3D QEMU_OPT_BOOL, #endif }, { /* end of list */ } @@ -1207,6 +1224,24 @@ GSource *qemu_chr_timeout_add_ms(Chardev *chr, guint= ms, return source; } =20 +static int chr_cpr_capable(Object *obj, void *opaque) +{ + Chardev *chr =3D (Chardev *)obj; + Error **errp =3D opaque; + + if (qemu_chr_has_feature(chr, QEMU_CHAR_FEATURE_CPR) || chr->close_on_= cpr) { + return 0; + } + error_setg(errp, "error: chardev %s -> %s is not capable of cpr", + chr->label, chr->filename); + return 1; +} + +bool qemu_chr_cpr_capable(Error **errp) +{ + return !object_child_foreach(get_chardevs_root(), chr_cpr_capable, err= p); +} + void qemu_chr_cleanup(void) { object_unparent(get_chardevs_root()); diff --git a/include/chardev/char.h b/include/chardev/char.h index 7c0444f..e488ad1 100644 --- a/include/chardev/char.h +++ b/include/chardev/char.h @@ -50,6 +50,8 @@ typedef enum { /* Whether the gcontext can be changed after calling * qemu_chr_be_update_read_handlers() */ QEMU_CHAR_FEATURE_GCONTEXT, + /* Whether the device supports cpr */ + QEMU_CHAR_FEATURE_CPR, =20 QEMU_CHAR_FEATURE_LAST, } ChardevFeature; @@ -67,6 +69,7 @@ struct Chardev { int be_open; /* used to coordinate the chardev-change special-case: */ bool handover_yank_instance; + bool close_on_cpr; GSource *gsource; GMainContext *gcontext; DECLARE_BITMAP(features, QEMU_CHAR_FEATURE_LAST); @@ -291,4 +294,6 @@ void resume_mux_open(void); /* console.c */ void qemu_chr_parse_vc(QemuOpts *opts, ChardevBackend *backend, Error **er= rp); =20 +bool qemu_chr_cpr_capable(Error **errp); + #endif diff --git a/migration/cpr.c b/migration/cpr.c index 3cde26f..8dfd5f1 100644 --- a/migration/cpr.c +++ b/migration/cpr.c @@ -132,6 +132,9 @@ void cprsave(const char *file, CprMode mode, Error **er= rp) shutdown_action =3D SHUTDOWN_ACTION_POWEROFF; qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); } else if (restart) { + if (!qemu_chr_cpr_capable(errp)) { + goto err; + } if (vfio_cprsave(errp)) { goto err; } diff --git a/qapi/char.json b/qapi/char.json index 6413970..dea5dad 100644 --- a/qapi/char.json +++ b/qapi/char.json @@ -204,12 +204,15 @@ # @logfile: The name of a logfile to save output # @logappend: true to append instead of truncate # (default to false to truncate) +# @close-on-cpr: if true, close device's fd on cprsave. defaults to false. +# since 6.0. # # Since: 2.6 ## { 'struct': 'ChardevCommon', 'data': { '*logfile': 'str', - '*logappend': 'bool' } } + '*logappend': 'bool', + '*close-on-cpr': 'bool' } } =20 ## # @ChardevFile: diff --git a/qemu-options.hx b/qemu-options.hx index 3392ac0..ef2d24a 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3071,43 +3071,57 @@ DEFHEADING(Character device options:) =20 DEF("chardev", HAS_ARG, QEMU_OPTION_chardev, "-chardev help\n" - "-chardev null,id=3Did[,mux=3Don|off][,logfile=3DPATH][,logappend=3Don= |off]\n" + "-chardev null,id=3Did[,mux=3Don|off][,logfile=3DPATH][,logappend=3Don= |off][,close-on-cpr=3Don|off]\n" "-chardev socket,id=3Did[,host=3Dhost],port=3Dport[,to=3Dto][,ipv4=3Do= n|off][,ipv6=3Don|off][,nodelay=3Don|off][,reconnect=3Dseconds]\n" " [,server=3Don|off][,wait=3Don|off][,telnet=3Don|off][,websoc= ket=3Don|off][,reconnect=3Dseconds][,mux=3Don|off]\n" - " [,logfile=3DPATH][,logappend=3Don|off][,tls-creds=3DID][,tls= -authz=3DID] (tcp)\n" + " [,logfile=3DPATH][,logappend=3Don|off][,tls-creds=3DID][,tls= -authz=3DID][,close-on-cpr=3Don|off] (tcp)\n" "-chardev socket,id=3Did,path=3Dpath[,server=3Don|off][,wait=3Don|off]= [,telnet=3Don|off][,websocket=3Don|off][,reconnect=3Dseconds]\n" - " [,mux=3Don|off][,logfile=3DPATH][,logappend=3Don|off][,abstr= act=3Don|off][,tight=3Don|off] (unix)\n" + " [,mux=3Don|off][,logfile=3DPATH][,logappend=3Don|off][,abstr= act=3Don|off][,tight=3Don|off][,close-on-cpr=3Don|off] (unix)\n" "-chardev udp,id=3Did[,host=3Dhost],port=3Dport[,localaddr=3Dlocaladdr= ]\n" " [,localport=3Dlocalport][,ipv4=3Don|off][,ipv6=3Don|off][,mu= x=3Don|off]\n" - " [,logfile=3DPATH][,logappend=3Don|off]\n" + " [,logfile=3DPATH][,logappend=3Don|off][,close-on-cpr=3Don|of= f]\n" "-chardev msmouse,id=3Did[,mux=3Don|off][,logfile=3DPATH][,logappend= =3Don|off]\n" + " [,close-on-cpr=3Don|off]\n" "-chardev vc,id=3Did[[,width=3Dwidth][,height=3Dheight]][[,cols=3Dcols= ][,rows=3Drows]]\n" " [,mux=3Don|off][,logfile=3DPATH][,logappend=3Don|off]\n" + " [,close-on-cpr=3Don|off]\n" "-chardev ringbuf,id=3Did[,size=3Dsize][,logfile=3DPATH][,logappend=3D= on|off]\n" + " [,close-on-cpr=3Don|off]\n" "-chardev file,id=3Did,path=3Dpath[,mux=3Don|off][,logfile=3DPATH][,lo= gappend=3Don|off]\n" + " [,close-on-cpr=3Don|off]\n" "-chardev pipe,id=3Did,path=3Dpath[,mux=3Don|off][,logfile=3DPATH][,lo= gappend=3Don|off]\n" + " [,close-on-cpr=3Don|off]\n" #ifdef _WIN32 "-chardev console,id=3Did[,mux=3Don|off][,logfile=3DPATH][,logappend= =3Don|off]\n" "-chardev serial,id=3Did,path=3Dpath[,mux=3Don|off][,logfile=3DPATH][,= logappend=3Don|off]\n" #else "-chardev pty,id=3Did[,mux=3Don|off][,logfile=3DPATH][,logappend=3Don|= off]\n" + " [,close-on-cpr=3Don|off]\n" "-chardev stdio,id=3Did[,mux=3Don|off][,signal=3Don|off][,logfile=3DPA= TH][,logappend=3Don|off]\n" + " [,close-on-cpr=3Don|off]\n" #endif #ifdef CONFIG_BRLAPI "-chardev braille,id=3Did[,mux=3Don|off][,logfile=3DPATH][,logappend= =3Don|off]\n" + " [,close-on-cpr=3Don|off]\n" #endif #if defined(__linux__) || defined(__sun__) || defined(__FreeBSD__) \ || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__Dragon= Fly__) "-chardev serial,id=3Did,path=3Dpath[,mux=3Don|off][,logfile=3DPATH][,= logappend=3Don|off]\n" + " [,close-on-cpr=3Don|off]\n" "-chardev tty,id=3Did,path=3Dpath[,mux=3Don|off][,logfile=3DPATH][,log= append=3Don|off]\n" + " [,close-on-cpr=3Don|off]\n" #endif #if defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__) "-chardev parallel,id=3Did,path=3Dpath[,mux=3Don|off][,logfile=3DPATH]= [,logappend=3Don|off]\n" + " [,close-on-cpr=3Don|off]\n" "-chardev parport,id=3Did,path=3Dpath[,mux=3Don|off][,logfile=3DPATH][= ,logappend=3Don|off]\n" + " [,close-on-cpr=3Don|off]\n" #endif #if defined(CONFIG_SPICE) "-chardev spicevmc,id=3Did,name=3Dname[,debug=3Ddebug][,logfile=3DPATH= ][,logappend=3Don|off]\n" + " [,close-on-cpr=3Don|off]\n" "-chardev spiceport,id=3Did,name=3Dname[,debug=3Ddebug][,logfile=3DPAT= H][,logappend=3Don|off]\n" + " [,close-on-cpr=3Don|off]\n" #endif , QEMU_ARCH_ALL ) @@ -3182,6 +3196,10 @@ The general form of a character device option is: ``logappend`` option controls whether the log file will be truncated or appended to when opened. =20 + Every backend supports the ``close-on-cpr`` option. If on, the + devices's descriptor is closed during cprsave, and reopened after exec. + This is useful for devices that do not support cpr. + The available backends are: =20 ``-chardev null,id=3Did`` --=20 1.8.3.1 From nobody Sun May 5 14:17:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1620391851; cv=none; d=zohomail.com; s=zohoarc; b=Pw4p6qdi8kPOOVtD2HbEAwHcsytzdCBs2cxLsqmWUiBq022sk8+VXmov+lFA2ARZmZ1yITF1/ch0xVkU+AziqwZ4rTBUE/NW9v7KqqUt+bJgLFxV0rEDMavp7YgcTfSZHcraQcIz3Q5+4XketdIZ1yBOTC3A+dLkwYkWC9YOHj8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620391851; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=W9D93a69StMSST57/REUvy0BnsSr4UFvr3IDEErpitU=; b=R5n1PFzznCPrITxnFpjVPNS+lZhvOYWrBceh/G6yD99+OgFN98z9JJ7CRNpkwXdNALrhEoTgcI9gcmuwRuCH6jYhuozOrqutgPvkx9OhIUPbDgLNKlQvyZ3/eiD2OlnykeoPpK4/zsDp/Khgp13KMJWKjFo26o/l+Og0plzOriY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620391851522951.5246073835362; Fri, 7 May 2021 05:50:51 -0700 (PDT) Received: from localhost ([::1]:54024 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lezwQ-0002zz-Db for importer@patchew.org; Fri, 07 May 2021 08:50:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57448) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbY-0000q2-3L for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:16 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:50000) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbR-0001Uk-03 for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:15 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 147CDvBm148756; Fri, 7 May 2021 12:29:06 GMT Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2130.oracle.com with ESMTP id 38csrd9ewr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29: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 147CGOMw173596; Fri, 7 May 2021 12:29:05 GMT Received: from pps.reinject (localhost [127.0.0.1]) by aserp3020.oracle.com with ESMTP id 38csrtb6ab-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29:05 +0000 Received: from aserp3020.oracle.com (aserp3020.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 147CT5DB028264; Fri, 7 May 2021 12:29:05 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 38csrtb69x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29:05 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 147CT4eK019320; Fri, 7 May 2021 12:29:04 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 07 May 2021 05:29:04 -0700 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=W9D93a69StMSST57/REUvy0BnsSr4UFvr3IDEErpitU=; b=uGN+PwWD1YVr4p5XreXV1OsA+4GqYRMWGJz8gPtv0wZGHxWArZywd+qdju4xv9ZbU6SU wi5R1M+1P6v0mUIDghJz049wKGwRSvcCpFNJ+ItDE5a0JiSlDGJpxG4Hwo2zLKK1ehQt 0vneU8K24HykwiTp4wxFrIHW9vnjEVKDve6E6+GV7V1NGh+jYKb+SqnnAZ863Q6jj2Pf apPQUpUWn50zhay7KmezJpMSrImTUf4CNFGwApEAzjVd5HGVSqj0YPAihbXvaKV5qjVy Of4AbeUuHLWlzXHIEP3idIfXWBf8Snroe2TbfA4ty/tyWsUyQvXK02W101t1yutpfaIp UA== From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V3 17/22] chardev: cpr for simple devices Date: Fri, 7 May 2021 05:25:15 -0700 Message-Id: <1620390320-301716-18-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> References: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-ORIG-GUID: pat0bwK6ypowFk_MEK-KAl9Hx7N6057i X-Proofpoint-GUID: pat0bwK6ypowFk_MEK-KAl9Hx7N6057i X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9976 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 clxscore=1015 malwarescore=0 adultscore=0 mlxlogscore=999 impostorscore=0 phishscore=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105070085 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=141.146.126.79; envelope-from=steven.sistare@oracle.com; helo=aserp2130.oracle.com X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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" , Jason Zeng , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Set QEMU_CHAR_FEATURE_CPR for devices that trivially support cpr. char-stdio is slightly less trivial. Allow the gdb server by closing it on exec. Signed-off-by: Steve Sistare --- chardev/char-mux.c | 1 + chardev/char-null.c | 1 + chardev/char-serial.c | 1 + chardev/char-stdio.c | 8 ++++++++ gdbstub.c | 1 + include/chardev/char.h | 1 + migration/cpr.c | 1 + 7 files changed, 14 insertions(+) diff --git a/chardev/char-mux.c b/chardev/char-mux.c index 72beef2..af74eaf 100644 --- a/chardev/char-mux.c +++ b/chardev/char-mux.c @@ -337,6 +337,7 @@ static void qemu_chr_open_mux(Chardev *chr, */ *be_opened =3D muxes_opened; qemu_chr_fe_init(&d->chr, drv, errp); + qemu_chr_set_feature(chr, QEMU_CHAR_FEATURE_CPR); } =20 static void qemu_chr_parse_mux(QemuOpts *opts, ChardevBackend *backend, diff --git a/chardev/char-null.c b/chardev/char-null.c index 1c6a290..02acaff 100644 --- a/chardev/char-null.c +++ b/chardev/char-null.c @@ -32,6 +32,7 @@ static void null_chr_open(Chardev *chr, Error **errp) { *be_opened =3D false; + qemu_chr_set_feature(chr, QEMU_CHAR_FEATURE_CPR); } =20 static void char_null_class_init(ObjectClass *oc, void *data) diff --git a/chardev/char-serial.c b/chardev/char-serial.c index 7c3d84a..b585085 100644 --- a/chardev/char-serial.c +++ b/chardev/char-serial.c @@ -274,6 +274,7 @@ static void qmp_chardev_open_serial(Chardev *chr, qemu_set_nonblock(fd); tty_serial_init(fd, 115200, 'N', 8, 1); =20 + qemu_chr_set_feature(chr, QEMU_CHAR_FEATURE_CPR); qemu_chr_open_fd(chr, fd, fd); } #endif /* __linux__ || __sun__ */ diff --git a/chardev/char-stdio.c b/chardev/char-stdio.c index 403da30..9410c16 100644 --- a/chardev/char-stdio.c +++ b/chardev/char-stdio.c @@ -114,9 +114,17 @@ static void qemu_chr_open_stdio(Chardev *chr, =20 stdio_allow_signal =3D !opts->has_signal || opts->signal; qemu_chr_set_echo_stdio(chr, false); + qemu_chr_set_feature(chr, QEMU_CHAR_FEATURE_CPR); } #endif =20 +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/gdbstub.c b/gdbstub.c index 054665e..fdbf531 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -3540,6 +3540,7 @@ int gdbserver_start(const char *device) mon_chr =3D gdbserver_state.mon_chr; reset_gdbserver_state(); } + mon_chr->close_on_cpr =3D true; =20 create_processes(&gdbserver_state); =20 diff --git a/include/chardev/char.h b/include/chardev/char.h index e488ad1..96e5570 100644 --- a/include/chardev/char.h +++ b/include/chardev/char.h @@ -295,5 +295,6 @@ void resume_mux_open(void); void qemu_chr_parse_vc(QemuOpts *opts, ChardevBackend *backend, Error **er= rp); =20 bool qemu_chr_cpr_capable(Error **errp); +void qemu_term_exit(void); =20 #endif diff --git a/migration/cpr.c b/migration/cpr.c index 8dfd5f1..a65a671 100644 --- a/migration/cpr.c +++ b/migration/cpr.c @@ -140,6 +140,7 @@ void cprsave(const char *file, CprMode mode, Error **er= rp) } walkenv(FD_PREFIX, preserve_fd, 0); vhost_dev_reset_all(); + qemu_term_exit(); setenv("QEMU_START_FREEZE", "", 1); qemu_system_exec_request(); } --=20 1.8.3.1 From nobody Sun May 5 14:17:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1620391723; cv=none; d=zohomail.com; s=zohoarc; b=DFLMIDlWSSJ+Q46YBDvCCFUnTYOJ/mInR2m+cZZYdNjQmU3NP8+TdH8rly0vEfx13iG8OtTdSigh7bTuEAC3ikbuWqQt3gg6g9dycAOlZ/+7M39lptM8HF110uNoX8UeBDpodiqckwDCRrTneoDEeyhj3CFlTD795a+xBlTVv/M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620391723; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=2hHfE6MEGogQzthqOH4vqs5xuVFIGzYUunqFpRHnOoY=; b=JIfu0ASzLfaQKcgi+uJQ96j2UUw2Mr8K7rA6hWkp8zWd/domgvOVoJU4ajuma93ejLHC9/50KkGliGYIu3JFxrqjKomEKpaJWcvQXVPSYuLhZNpPHdZuhILTu4VMJ0+RAj6bC6M0X9GJ/iTjzYx7UGtRe8Nr2tnXnzij6kTAt54= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620391723467922.9261029706661; Fri, 7 May 2021 05:48:43 -0700 (PDT) Received: from localhost ([::1]:49302 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lezuM-00011m-A4 for importer@patchew.org; Fri, 07 May 2021 08:48:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57416) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbW-0000mo-Sg for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:14 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:40652) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbT-0001Wk-Te for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:14 -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 147CEAsD096895; Fri, 7 May 2021 12:29:07 GMT Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 38ctd89d1u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29:07 +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 147CFk5w168050; Fri, 7 May 2021 12:29:07 GMT Received: from pps.reinject (localhost [127.0.0.1]) by userp3020.oracle.com with ESMTP id 38csrh1tdd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29:07 +0000 Received: from userp3020.oracle.com (userp3020.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 147CT6J1014797; Fri, 7 May 2021 12:29:06 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3020.oracle.com with ESMTP id 38csrh1tbq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29:06 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 147CT5Yk017267; Fri, 7 May 2021 12:29:05 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 07 May 2021 05:29:04 -0700 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=2hHfE6MEGogQzthqOH4vqs5xuVFIGzYUunqFpRHnOoY=; b=JQFmzg7vDUfJQtebpqiKUZ+JGMcjUw5FGcLHRjrsUzj8cr0Vx+br1Mm1/vKimYkVGRJW vJsaPbCcYl06YQZLR0KSU6yZcIHBd7lb958h67niIvLMQ1UIp0OqAUNNO2hMqirZYPHD CeokcHggXNKVg6Gq08wgTLGazL3KV5O5Bl/1JQsy/+bNzdu3Y1H88sJWc2V/ASGxP5cS 29Ur55UZf5AMC5M9DWRojfVddVoVnb08k07NuS0mC3EsP/79P8MNOgBs9F9Y9LqIeW5R TBMEn8n5kTCXsIWkD45SRja7iR93Ga2zXrCXKZajRPvRQwZitifJ3ydLcCgWcSJWqAA3 jw== From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V3 18/22] chardev: cpr for pty Date: Fri, 7 May 2021 05:25:16 -0700 Message-Id: <1620390320-301716-19-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> References: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-GUID: pQkN0eIlm8dbRZYQcrHOUCR0KKiGDKA5 X-Proofpoint-ORIG-GUID: pQkN0eIlm8dbRZYQcrHOUCR0KKiGDKA5 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9976 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 adultscore=0 clxscore=1015 spamscore=0 mlxlogscore=999 priorityscore=1501 lowpriorityscore=0 phishscore=0 suspectscore=0 impostorscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105070085 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=156.151.31.86; envelope-from=steven.sistare@oracle.com; helo=userp2130.oracle.com X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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" , Jason Zeng , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Save and restore pty descriptors across cprsave and cprload. Signed-off-by: Steve Sistare --- chardev/char-pty.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/chardev/char-pty.c b/chardev/char-pty.c index a2d1e7c..c91151d 100644 --- a/chardev/char-pty.c +++ b/chardev/char-pty.c @@ -30,6 +30,7 @@ #include "qemu/sockets.h" #include "qemu/error-report.h" #include "qemu/module.h" +#include "qemu/env.h" #include "qemu/qemu-print.h" =20 #include "chardev/char-io.h" @@ -191,6 +192,7 @@ static void char_pty_finalize(Object *obj) Chardev *chr =3D CHARDEV(obj); PtyChardev *s =3D PTY_CHARDEV(obj); =20 + unsetenv_fd(chr->label); pty_chr_state(chr, 0); object_unref(OBJECT(s->ioc)); pty_chr_timer_cancel(s); @@ -207,19 +209,28 @@ static void char_pty_open(Chardev *chr, char pty_name[PATH_MAX]; char *name; =20 + master_fd =3D getenv_fd(chr->label); + if (master_fd >=3D 0) { + chr->filename =3D g_strdup_printf("pty:unknown"); + goto have_fd; + } + master_fd =3D qemu_openpty_raw(&slave_fd, pty_name); if (master_fd < 0) { error_setg_errno(errp, errno, "Failed to create PTY"); return; } - + if (!chr->close_on_cpr) { + setenv_fd(chr->label, master_fd); + } close(slave_fd); qemu_set_nonblock(master_fd); - chr->filename =3D g_strdup_printf("pty:%s", pty_name); qemu_printf("char device redirected to %s (label %s)\n", pty_name, chr->label); =20 +have_fd: + qemu_chr_set_feature(chr, QEMU_CHAR_FEATURE_CPR); s =3D PTY_CHARDEV(chr); s->ioc =3D QIO_CHANNEL(qio_channel_file_new_fd(master_fd)); name =3D g_strdup_printf("chardev-pty-%s", chr->label); --=20 1.8.3.1 From nobody Sun May 5 14:17:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1620391416; cv=none; d=zohomail.com; s=zohoarc; b=ictyLPhijJjo1Y/MYS7noLzFUffn8tRELJjtBlsEpD769+hYVQK5tFCtWpRCo6INJN7ozBqKz1cKdBpyVuW2/DCfW9HZ1iFClsqLFtYKlCF88tDfE2hQrXm4wrqmV+kdSLjOk+a9wiibp2XVepNMtzCuDIoeSt+C3Zf7rmzoDsA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620391416; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=z5xKbEJAlAVR4RVNr9CaGx/H1ESy+tpLGhwVIjQTbp4=; b=OX1p5vTYwb6IJXQ073uiVR+BK9UBhXPUNfE2OC5FHD76IwjK7lwejKJsaVoPI4/veFk51m2f8kOCqSsi0j9gM5X8fMLcmeFBDQxigIDdRA8MDWbOwu4//R9y4YUc2iZ6ZQ0jSIZS2EPJUMfk8u7hI5HcyizQ/+28WMwHFoC1kkQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620391416758686.8747336230153; Fri, 7 May 2021 05:43:36 -0700 (PDT) Received: from localhost ([::1]:37692 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lezpP-0004Sj-Q0 for importer@patchew.org; Fri, 07 May 2021 08:43:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57480) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbZ-0000ua-Oe for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:18 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:40668) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbV-0001Xn-G8 for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:17 -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 147CEE7C096919; Fri, 7 May 2021 12:29:09 GMT Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 38ctd89d1x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29:09 +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 147CGOWk173606; Fri, 7 May 2021 12:29:08 GMT Received: from pps.reinject (localhost [127.0.0.1]) by aserp3020.oracle.com with ESMTP id 38csrtb6c4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29:08 +0000 Received: from aserp3020.oracle.com (aserp3020.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 147CT8Pk028387; Fri, 7 May 2021 12:29:08 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3020.oracle.com with ESMTP id 38csrtb6bd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29:08 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 147CT6Dn011732; Fri, 7 May 2021 12:29:06 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 07 May 2021 05:29:05 -0700 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=z5xKbEJAlAVR4RVNr9CaGx/H1ESy+tpLGhwVIjQTbp4=; b=ucgSLJwtjalz/rES225hRJgiOyJZxW0KC0mCj/uHyFLW1/AEQWg/2QkDI/XeNy+PFcKG 5ixkK1d5xfbMeVnWRJN9zdwyvIkiJ3gnXT02pzLXH9GDDWSoILCaGrrllWfNa15FZg8y dUK9BqR2ctKm6Z56lCggTMVjhPJP4w6G6SQk3CkWXu6VQP/rXDQmhe/2k8xeqBmz3UKa Q5ZU2rpW6sqqn1HeRlfdC6uHSi7mE9oJ7dBKOWZczHiA2n3Pz1fRk3LqnPVTZR0tqLzW 3Wp1OK5YEwDbsCfYl+H1FOx5WDtHF+Rl/ifEkoePG2b2f5c6e234WNgd+Vemp994v+YX 1w== From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V3 19/22] chardev: cpr for sockets Date: Fri, 7 May 2021 05:25:17 -0700 Message-Id: <1620390320-301716-20-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> References: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-GUID: KMl-NKj3bJhg7O_XqHwJIg1g7qu8gPWE X-Proofpoint-ORIG-GUID: KMl-NKj3bJhg7O_XqHwJIg1g7qu8gPWE X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9976 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 adultscore=0 clxscore=1015 spamscore=0 mlxlogscore=999 priorityscore=1501 lowpriorityscore=0 phishscore=0 suspectscore=0 impostorscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105070085 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=156.151.31.86; envelope-from=steven.sistare@oracle.com; helo=userp2130.oracle.com X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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" , Jason Zeng , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Save accepted socket fds in the environment before cprsave, and look for fds in the environment after cprload. Reject cprsave if a socket enables the TLS or websocket option. Allow a monitor socket by closing it on exec. Signed-off-by: Mark Kanda Signed-off-by: Steve Sistare --- chardev/char-socket.c | 31 +++++++++++++++++++++++++++++++ monitor/hmp.c | 3 +++ monitor/qmp.c | 3 +++ 3 files changed, 37 insertions(+) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index daa89fe..110f263 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -27,7 +27,9 @@ #include "io/channel-socket.h" #include "io/channel-tls.h" #include "io/channel-websock.h" +#include "qemu/env.h" #include "io/net-listener.h" +#include "qemu/env.h" #include "qemu/error-report.h" #include "qemu/module.h" #include "qemu/option.h" @@ -414,6 +416,7 @@ static void tcp_chr_free_connection(Chardev *chr) SocketChardev *s =3D SOCKET_CHARDEV(chr); int i; =20 + unsetenv_fd(chr->label); if (s->read_msgfds_num) { for (i =3D 0; i < s->read_msgfds_num; i++) { close(s->read_msgfds[i]); @@ -976,6 +979,10 @@ static void tcp_chr_accept(QIONetListener *listener, QIO_CHANNEL(cioc)); } tcp_chr_new_client(chr, cioc); + + if (s->sioc && !chr->close_on_cpr) { + setenv_fd(chr->label, s->sioc->fd); + } } =20 =20 @@ -1231,6 +1238,24 @@ static gboolean socket_reconnect_timeout(gpointer op= aque) return false; } =20 +static void load_char_socket_fd(Chardev *chr, Error **errp) +{ + SocketChardev *sockchar =3D SOCKET_CHARDEV(chr); + QIOChannelSocket *sioc; + int fd =3D getenv_fd(chr->label); + + if (fd !=3D -1) { + sockchar =3D SOCKET_CHARDEV(chr); + sioc =3D qio_channel_socket_new_fd(fd, errp); + if (sioc) { + tcp_chr_accept(sockchar->listener, sioc, chr); + object_unref(OBJECT(sioc)); + } else { + error_setg(errp, "error: could not restore socket for %s", + chr->label); + } + } +} =20 static int qmp_chardev_open_socket_server(Chardev *chr, bool is_telnet, @@ -1441,6 +1466,10 @@ static void qmp_chardev_open_socket(Chardev *chr, } s->registered_yank =3D true; =20 + if (!s->tls_creds && !s->is_websock) { + qemu_chr_set_feature(chr, QEMU_CHAR_FEATURE_CPR); + } + /* be isn't opened until we get a connection */ *be_opened =3D false; =20 @@ -1456,6 +1485,8 @@ static void qmp_chardev_open_socket(Chardev *chr, return; } } + + load_char_socket_fd(chr, errp); } =20 static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend, diff --git a/monitor/hmp.c b/monitor/hmp.c index 6c0b33a..63700b3 100644 --- a/monitor/hmp.c +++ b/monitor/hmp.c @@ -1451,4 +1451,7 @@ void monitor_init_hmp(Chardev *chr, bool use_readline= , Error **errp) qemu_chr_fe_set_handlers(&mon->common.chr, monitor_can_read, monitor_r= ead, monitor_event, NULL, &mon->common, NULL, true= ); monitor_list_append(&mon->common); + + /* monitor cannot yet be preserved across cpr */ + chr->close_on_cpr =3D true; } diff --git a/monitor/qmp.c b/monitor/qmp.c index 2b0308f..495d68f 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -531,4 +531,7 @@ void monitor_init_qmp(Chardev *chr, bool pretty, Error = **errp) NULL, &mon->common, NULL, true); monitor_list_append(&mon->common); } + + /* Monitor cannot yet be preserved across cpr */ + chr->close_on_cpr =3D true; } --=20 1.8.3.1 From nobody Sun May 5 14:17:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1620391480; cv=none; d=zohomail.com; s=zohoarc; b=Zpfo7suhqY5QxCgw9M3+MuJr9QmmqkAwXCboHZK0nmgN7DkC5mGQ3DGwO2eHByjecYt+zUwUDIS7vgOzeJEwA4NfD5ruWUXaHjcmE7hT7QgKAEW26ECvbDqbP+KlBOcecZh5HMSwoaR4t0Hp357TLf20MZ+AZQWNkR7OMC7hURU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620391480; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=cbDIMfiCiERpNImnUSmmcFyFlWEeyMB25WzXlcFBRdw=; b=j1N6i/A1oaIh3Ew4XAIk9Ls5qRRBaPxbb0jt3edbdS43pt/8mef/ddoRdM8IcCtUbu04ZOi8qLlfzXk5o5aa8zjTAemV+wPzWee2sHBlznzaQTGxug9RmNmceSqVu/atnXfmb9CBkC9XBRYaW2NXcSwV7/+nDJ8znMEHQJRBlrE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620391480507421.51211900149417; Fri, 7 May 2021 05:44:40 -0700 (PDT) Received: from localhost ([::1]:40808 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lezqR-0005nN-C6 for importer@patchew.org; Fri, 07 May 2021 08:44:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57414) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbW-0000mP-NY for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:14 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:60428) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbT-0001Wi-HW for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:14 -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 147CEjao126849; Fri, 7 May 2021 12:29:08 GMT Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 38ctjv1cby-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29:08 +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 147CFYXB068860; Fri, 7 May 2021 12:29:08 GMT Received: from pps.reinject (localhost [127.0.0.1]) by aserp3030.oracle.com with ESMTP id 38csrev2p0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29:08 +0000 Received: from aserp3030.oracle.com (aserp3030.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 147CSLF4108458; Fri, 7 May 2021 12:29:07 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3030.oracle.com with ESMTP id 38csrev2np-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29:07 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 147CT632019336; Fri, 7 May 2021 12:29:06 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 07 May 2021 05:29:06 -0700 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=cbDIMfiCiERpNImnUSmmcFyFlWEeyMB25WzXlcFBRdw=; b=h1cjDF9fRie+Q718EtxYMYTgoV5GcpxUQzLKaBmd+7o0LqV5wN2dUVbi8N4kmU5NiV2U BbqkMuT4YeKSdVdmkO8is/Sh+SeY3hibUECHI4/LGKnXk4szC1pcxQwq22ZNpwOt+ADD s1D/yzwhQrpEACnJTMrtbktzvCm+CzYXTHefmrRmAzcr/WbWlAp+BJMerXxzKC+RTk8Z CQejag7caL/R4xhFVuIg1fBVi4s4Wc0uEn3qfrbmn7qDxBHVJnlqt+gyxAP2LprR5tlB lbaev2FBYWtpHcNJVxChLVI+gTqIqETSpPG2HNFqVks8JDuoAnMwvfymJYk9XfbJ4FNE Dw== From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V3 20/22] cpr: only-cpr-capable option Date: Fri, 7 May 2021 05:25:18 -0700 Message-Id: <1620390320-301716-21-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> References: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-ORIG-GUID: tKHRfDxyIQ_GI-ll602rYEALVdJDJhq8 X-Proofpoint-GUID: tKHRfDxyIQ_GI-ll602rYEALVdJDJhq8 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9976 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 mlxscore=0 clxscore=1015 priorityscore=1501 bulkscore=0 suspectscore=0 lowpriorityscore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105070085 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=141.146.126.78; envelope-from=steven.sistare@oracle.com; helo=aserp2120.oracle.com X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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_BL=0.001, RCVD_IN_MSPIKE_L4=0.001, 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" , Jason Zeng , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add the only-cpr-capable option, which causes qemu to exit with an error if any devices that are not capable of cpr are added. This guarantees that a cprsave operation will not fail with an unsupported device error. Signed-off-by: Steve Sistare --- chardev/char-socket.c | 4 ++++ hw/vfio/common.c | 5 +++++ hw/vfio/pci.c | 3 +++ include/sysemu/sysemu.h | 1 + migration/migration.c | 5 +++++ qemu-options.hx | 8 ++++++++ softmmu/globals.c | 1 + softmmu/physmem.c | 4 ++++ softmmu/vl.c | 14 +++++++++++++- stubs/cpr.c | 3 +++ stubs/meson.build | 1 + 11 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 stubs/cpr.c diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 110f263..b8c75ff 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -40,6 +40,7 @@ =20 #include "chardev/char-io.h" #include "qom/object.h" +#include "sysemu/sysemu.h" =20 /***********************************************************/ /* TCP Net console */ @@ -1468,6 +1469,9 @@ static void qmp_chardev_open_socket(Chardev *chr, =20 if (!s->tls_creds && !s->is_websock) { qemu_chr_set_feature(chr, QEMU_CHAR_FEATURE_CPR); + } else if (only_cpr_capable) { + error_setg(errp, "error: socket %s is not cpr capable due to %s op= tion", + chr->label, (s->tls_creds ? "TLS" : "websocket")); } =20 /* be isn't opened until we get a connection */ diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 00d07b2..f2f1926 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -37,6 +37,7 @@ #include "qemu/range.h" #include "sysemu/kvm.h" #include "sysemu/reset.h" +#include "sysemu/sysemu.h" #include "trace.h" #include "qapi/error.h" #include "migration/migration.h" @@ -1601,6 +1602,10 @@ static int vfio_get_iommu_type(VFIOContainer *contai= ner, =20 for (i =3D 0; i < ARRAY_SIZE(iommu_types); i++) { if (ioctl(container->fd, VFIO_CHECK_EXTENSION, iommu_types[i])) { + if (only_cpr_capable && !vfio_cpr_capable(container, errp)) { + error_prepend(errp, "only-cpr-capable is specified: "); + return -EINVAL; + } return iommu_types[i]; } } diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index e983db4..908b0e5 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -266,6 +266,9 @@ static int vfio_intx_enable(VFIOPCIDevice *vdev, Error = **errp) =20 if (!pin) { return 0; + } else if (only_cpr_capable) { + error_setg(errp, "INTX is not compatible with -only-cpr-capable"); + return -1; } =20 vfio_disable_interrupts(vdev); diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index f56058e..05c2d8e 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -9,6 +9,7 @@ /* vl.c */ =20 extern int only_migratable; +extern bool only_cpr_capable; extern char **argv_main; extern const char *qemu_name; extern QemuUUID qemu_uuid; diff --git a/migration/migration.c b/migration/migration.c index 8ca0341..181c8d5 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1262,6 +1262,11 @@ static bool migrate_caps_check(bool *cap_list, } } =20 + if (cap_list[MIGRATION_CAPABILITY_X_COLO] && only_cpr_capable) { + error_setg(errp, "x-colo is not compatible with -only-cpr-capable"= ); + return false; + } + return true; } =20 diff --git a/qemu-options.hx b/qemu-options.hx index ef2d24a..f1b372b 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4257,6 +4257,14 @@ SRST an unmigratable state. ERST =20 +DEF("only-cpr-capable", 0, QEMU_OPTION_only_cpr_capable, \ + "-only-cpr-capable allow only cpr capable devices\n", QEMU_ARCH_ALL) +SRST +``-only-cpr-capable`` + Only allow cpr capable devices, which guarantees that cprsave will not + fail with an unsupported device error. +ERST + DEF("nodefaults", 0, QEMU_OPTION_nodefaults, \ "-nodefaults don't create default devices\n", QEMU_ARCH_ALL) SRST diff --git a/softmmu/globals.c b/softmmu/globals.c index 2bb630d..752f119 100644 --- a/softmmu/globals.c +++ b/softmmu/globals.c @@ -59,6 +59,7 @@ int boot_menu; bool boot_strict; uint8_t *boot_splash_filedata; int only_migratable; /* turn it off unless user states otherwise */ +bool only_cpr_capable; int icount_align_option; char **argv_main; =20 diff --git a/softmmu/physmem.c b/softmmu/physmem.c index b79f408..04e3603 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -1973,6 +1973,10 @@ static void ram_block_add(RAMBlock *new_block, Error= **errp, bool shared) addr =3D file_ram_alloc(new_block, maxlen, mfd, false, false, 0, errp); trace_anon_memfd_alloc(name, maxlen, addr, mfd); + } else if (only_cpr_capable) { + error_setg(errp, + "only-cpr-capable requires -machine memfd-alloc=3Don"); + return; } else { addr =3D qemu_anon_ram_alloc(maxlen, &mr->align, shared); } diff --git a/softmmu/vl.c b/softmmu/vl.c index 4654693..76a14a0 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -2589,6 +2589,10 @@ void qmp_x_exit_preconfig(Error **errp) qemu_create_cli_devices(); qemu_machine_creation_done(); =20 + if (only_cpr_capable && !qemu_chr_cpr_capable(errp)) { + ; /* not reached due to error_fatal */ + } + if (loadvm) { Error *local_err =3D NULL; if (!load_snapshot(loadvm, NULL, false, NULL, &local_err)) { @@ -2598,7 +2602,12 @@ void qmp_x_exit_preconfig(Error **errp) } } if (replay_mode !=3D REPLAY_MODE_NONE) { - replay_vmstate_init(); + if (only_cpr_capable) { + error_setg(errp, "replay is not compatible with -only-cpr-capa= ble"); + /* not reached due to error_fatal */ + } else { + replay_vmstate_init(); + } } =20 if (incoming) { @@ -3340,6 +3349,9 @@ void qemu_init(int argc, char **argv, char **envp) case QEMU_OPTION_only_migratable: only_migratable =3D 1; break; + case QEMU_OPTION_only_cpr_capable: + only_cpr_capable =3D true; + break; case QEMU_OPTION_nodefaults: has_defaults =3D 0; break; diff --git a/stubs/cpr.c b/stubs/cpr.c new file mode 100644 index 0000000..aaa189e --- /dev/null +++ b/stubs/cpr.c @@ -0,0 +1,3 @@ +#include "qemu/osdep.h" + +bool only_cpr_capable; diff --git a/stubs/meson.build b/stubs/meson.build index be6f6d6..2003c77 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -5,6 +5,7 @@ stub_ss.add(files('blk-exp-close-all.c')) stub_ss.add(files('blockdev-close-all-bdrv-states.c')) stub_ss.add(files('change-state-handler.c')) stub_ss.add(files('cmos.c')) +stub_ss.add(files('cpr.c')) stub_ss.add(files('cpu-get-clock.c')) stub_ss.add(files('cpus-get-virtual-clock.c')) stub_ss.add(files('qemu-timer-notify-cb.c')) --=20 1.8.3.1 From nobody Sun May 5 14:17:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1620391637; cv=none; d=zohomail.com; s=zohoarc; b=Z9+Eyea09jacw/Xsgow/pF+juyW0pPX0pKgLZuMj9sw6q/1O8LeBbjB+CoECFfPiQZANbo/VHon0QFl064uoV47CcHKI8H4WDGfg8fnLYvB2WiX3uV+6pAuDTZ+mlxQlvBoELPRjUTduoQ3QROM2Pc4gzheApq4V9LbSQC9T/+4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620391637; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=jwSUd3eBPptGZN8xtVowoLPdImw26KI32p0lOJ+9RV0=; b=LTk2fE47AEeGb+fzJWXMF5hmSjJkOiYxfRaSVqVe2t11evNxcnh+ByyEsuslkAKcWot/q15B1hF5c+qv3dV1qfrG8WXbAd/RI6Ex4dkX/ZSLLwUhavx/c3r6ilu8Zo1yG5WGa0C1rX2XY/pcq6eJ6AT+N9yZZtesnB6B6+z4CV8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620391637626184.47517051346904; Fri, 7 May 2021 05:47:17 -0700 (PDT) Received: from localhost ([::1]:46150 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lezsy-00089o-Sc for importer@patchew.org; Fri, 07 May 2021 08:47:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57470) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbZ-0000u6-GW for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:18 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:60458) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbX-0001Ym-0g for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:17 -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 147CEDuY126682; Fri, 7 May 2021 12:29:11 GMT Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 38ctjv1cc4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29:11 +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 147CGQA9173756; Fri, 7 May 2021 12:29:11 GMT Received: from pps.reinject (localhost [127.0.0.1]) by aserp3020.oracle.com with ESMTP id 38csrtb6ek-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29:11 +0000 Received: from aserp3020.oracle.com (aserp3020.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 147CNPDV005557; Fri, 7 May 2021 12:29:10 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 38csrtb6cs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29:10 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 147CT76v016467; Fri, 7 May 2021 12:29:08 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 07 May 2021 05:29:07 -0700 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=jwSUd3eBPptGZN8xtVowoLPdImw26KI32p0lOJ+9RV0=; b=YvdTn1NQECvzAIsI1TaLU078RbV0h6G4ZeiKJfwdxFX338tABtrj+BchO0a0/TwP/UZw W3CvSBzixqKmlst0Zh57Q8ah9AVCdEd04O3kdnk2PUBdq6nokC7Ld0HpxP+zZd7ZjZ7D UF+X8Kn9xBlZikOJX5Z1dZLRbCSPQdn9PYDS5OzlSn3KZdnfu8KW3deu6yR6SfJaX6a+ ZwTDrwMgJqWIH1ju+bO/NuvFOvu3A4/XjehnZ82UvCIo9U7N+kd3w6IJqnIMmAn7t8P2 FDILMB9t7plVTk8wCVXzkK91HKaV7Bd/snD8KHeAzVbvtauFWDey8uAyC7xLwM4sDaBh yg== From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V3 21/22] cpr: maintainers Date: Fri, 7 May 2021 05:25:19 -0700 Message-Id: <1620390320-301716-22-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> References: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-ORIG-GUID: 9eA8Rol-ji44VjzrGSrqn2n0UnFKW-p0 X-Proofpoint-GUID: 9eA8Rol-ji44VjzrGSrqn2n0UnFKW-p0 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9976 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 mlxscore=0 clxscore=1015 priorityscore=1501 bulkscore=0 suspectscore=0 lowpriorityscore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105070085 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=141.146.126.78; envelope-from=steven.sistare@oracle.com; helo=aserp2120.oracle.com X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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_BL=0.001, RCVD_IN_MSPIKE_L4=0.001, 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" , Jason Zeng , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add the maintainers for cpr related files. Signed-off-by: Steve Sistare --- MAINTAINERS | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 36055f1..b69bbf5 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2843,6 +2843,17 @@ F: net/colo* F: net/filter-rewriter.c F: net/filter-mirror.c =20 +CPR +M: Steve Sistare +M: Mark Kanda +S: Maintained +F: hw/vfio/cpr.c +F: include/migration/cpr.h +F: migration/cpr.c +F: qapi/cpr.json +F: include/qemu/env.h +F: util/env.c + Record/replay M: Pavel Dovgalyuk R: Paolo Bonzini --=20 1.8.3.1 From nobody Sun May 5 14:17:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1620391899; cv=none; d=zohomail.com; s=zohoarc; b=mjRO3AdMJ/mqGYFMPQmSGZ0f3qfgrgU1X5/Fo0tFeE0reQxGoNwprRPuXDx97oEC3tqld9bZ0K+UqnCgAWsivN0zOnjEKatuM6MeZPSGvwFC17jpd2Q8l5hqIE6RXEJSO+N+YnotmOszLrznPkPlm9njI2AM3Kgvp7hjx6YPb7M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620391899; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=+vyo8cyFeJn4HRpXZj3DzYe6S1G5SWpclntcSWRLX3c=; b=WU13Sg322qLB3+kvgUdZmQokLbRBblA3ILbcwG+hD9YMtHYvoGkpee6RrTq15Q3At+RFLTdg5bLv0OcgMNLSKqXzNjAwu6bAnTVsAOq7A0FuV5rtBfbdRljfTX5HF5j6HEOzWVE2wf6SoAcmhG4rNuL2VcfSPpkiYbx+m4KrMbQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620391899281225.17596766357826; Fri, 7 May 2021 05:51:39 -0700 (PDT) Received: from localhost ([::1]:56274 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lezxB-00040B-2Y for importer@patchew.org; Fri, 07 May 2021 08:51:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57476) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbZ-0000uH-Jj for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:18 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:50044) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lezbV-0001YB-Tv for qemu-devel@nongnu.org; Fri, 07 May 2021 08:29:17 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 147CES77148914; Fri, 7 May 2021 12:29:10 GMT Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2130.oracle.com with ESMTP id 38csrd9ewx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29:10 +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 147CGRC8174290; Fri, 7 May 2021 12:29:10 GMT Received: from pps.reinject (localhost [127.0.0.1]) by aserp3020.oracle.com with ESMTP id 38csrtb6de-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29:10 +0000 Received: from aserp3020.oracle.com (aserp3020.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 147CP1Zx010092; Fri, 7 May 2021 12:29:09 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 38csrtb6cj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 May 2021 12:29:09 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 147CT8dZ019345; Fri, 7 May 2021 12:29:08 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 07 May 2021 05:29:08 -0700 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=+vyo8cyFeJn4HRpXZj3DzYe6S1G5SWpclntcSWRLX3c=; b=NZYoKEPUtlciKqYbtFrrhs6rPqs7XhVusLOKv+zhiOFgaFCJ1JLFZWaFSXQod2gh0hk8 MKbC+dVADeQ69/xCjdG12uXgn/nfHvwxktEgc/uyqUOwC69iEIzgCr/gHT7w4+yegiTQ F8PsH9p7ZkZcYu2m34FWFSrsqHbmSgIG3XDraWMvCz9tl4+Rj18FIrBJ8zR4FnxcDwWL VbgIH0Tn0Bn4YHiBYxjmjb0Wc719S18rsi0aorV2z+SZWGfC6yvy3iYUkNgz1h500YRP bwc2X0swLns0zhUh6LVYOFBwv9reyvzrldXrBf0c/Tw+p8mVujY7ofiFM3Vp2nghcD/B 2w== From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V3 22/22] simplify savevm Date: Fri, 7 May 2021 05:25:20 -0700 Message-Id: <1620390320-301716-23-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> References: <1620390320-301716-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-ORIG-GUID: UlBFNy98ERtzMxsnbvdEAn9lgbBVBB-z X-Proofpoint-GUID: UlBFNy98ERtzMxsnbvdEAn9lgbBVBB-z X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9976 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 clxscore=1015 malwarescore=0 adultscore=0 mlxlogscore=999 impostorscore=0 phishscore=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105070085 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=141.146.126.79; envelope-from=steven.sistare@oracle.com; helo=aserp2130.oracle.com X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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" , Jason Zeng , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Use qf_file_open to simplify a few functions in savevm.c. No functional change. Signed-off-by: Steve Sistare --- migration/savevm.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/migration/savevm.c b/migration/savevm.c index 52e2d72..d02bce2 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2904,8 +2904,9 @@ bool save_snapshot(const char *name, bool overwrite, = const char *vmstate, void qmp_xen_save_devices_state(const char *filename, bool has_live, bool = live, Error **errp) { + const char *ioc_name =3D "migration-xen-save-state"; + int flags =3D O_WRONLY | O_CREAT | O_TRUNC; QEMUFile *f; - QIOChannelFile *ioc; int saved_vm_running; int ret; =20 @@ -2919,14 +2920,10 @@ void qmp_xen_save_devices_state(const char *filenam= e, bool has_live, bool live, vm_stop(RUN_STATE_SAVE_VM); global_state_store_running(); =20 - ioc =3D qio_channel_file_new_path(filename, O_WRONLY | O_CREAT | O_TRU= NC, - 0660, errp); - if (!ioc) { + f =3D qf_file_open(filename, flags, 0660, ioc_name, errp); + if (!f) { goto the_end; } - qio_channel_set_name(QIO_CHANNEL(ioc), "migration-xen-save-state"); - f =3D qemu_fopen_channel_output(QIO_CHANNEL(ioc)); - object_unref(OBJECT(ioc)); ret =3D qemu_save_device_state(f); if (ret < 0 || qemu_fclose(f) < 0) { error_setg(errp, QERR_IO_ERROR); @@ -2954,8 +2951,8 @@ void qmp_xen_save_devices_state(const char *filename,= bool has_live, bool live, =20 void qmp_xen_load_devices_state(const char *filename, Error **errp) { + const char *ioc_name =3D "migration-xen-load-state"; QEMUFile *f; - QIOChannelFile *ioc; int ret; =20 /* Guest must be paused before loading the device state; the RAM state @@ -2967,14 +2964,10 @@ void qmp_xen_load_devices_state(const char *filenam= e, Error **errp) } vm_stop(RUN_STATE_RESTORE_VM); =20 - ioc =3D qio_channel_file_new_path(filename, O_RDONLY | O_BINARY, 0, er= rp); - if (!ioc) { + f =3D qf_file_open(filename, O_RDONLY | O_BINARY, 0, ioc_name, errp); + if (!f) { return; } - qio_channel_set_name(QIO_CHANNEL(ioc), "migration-xen-load-state"); - f =3D qemu_fopen_channel_input(QIO_CHANNEL(ioc)); - object_unref(OBJECT(ioc)); - ret =3D qemu_loadvm_state(f); qemu_fclose(f); if (ret < 0) { --=20 1.8.3.1