From nobody Thu Jun 30 21:50:06 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4BB8E8B5C0E; Thu, 30 Jun 2022 21:50:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4LYsSb10ddz3KsS; Thu, 30 Jun 2022 21:50:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656625807; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=8AmwE3bHT5LXCvjv/JKMRJ8phoIFazWwLFZlujeYeI0=; b=C2kMQsT0VNpCADAxPi+giyYFtq60RkU1lw5Q9Kvd0fKSPHjVr+AuYgx4IvupZb9VRaO9cd eJhV4jWVyEmBFw1WuAiLwBZJRcpz9tn5hPJ3GxpqN2HN9LNPa8TiXd09prMFBrV+ks2JQz lijvY6Rd7GIxqVWTRQTZltS65Yq8xL8vXY7DDvWAKEfZcvgwUIEBwTGDFdgv9WLCs0Tlcw SIHpIuXLbsCz5qb2iMm98pbIPLslKzNtWA3OXByzl1KrwHXp8wx0x71Njz8iO6YJYUXmRy hbwcjrryuCj2WcjMClkY38eE4+cXmEnByEDwep/MYgDDi/0aYuHQf5pqrxYYEw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id F2A026AF4; Thu, 30 Jun 2022 21:50:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 25ULo6MA066603; Thu, 30 Jun 2022 21:50:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25ULo6OC066600; Thu, 30 Jun 2022 21:50:06 GMT (envelope-from git) Date: Thu, 30 Jun 2022 21:50:06 GMT Message-Id: <202206302150.25ULo6OC066600@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: f0880ab791a5 - main - libvmmapi: Add vm_close() List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f0880ab791a510391a12f2ab7b01889b6774bca0 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656625807; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=8AmwE3bHT5LXCvjv/JKMRJ8phoIFazWwLFZlujeYeI0=; b=lzjzIkmgsKk/VwtM9Mat41BwYgoXBCESuLlqduqNDfNcm3knIqmEdg/lvo0kLhndbdUyeO 79fAFNl05E6swhOzUvu+kllJvX7yk8kCBjUznRDrZdvrlHXH63sf3QJDgEwKAew2ImX5oh Ic6SdBcuWq7TYIk0PB+wF3umgXVqGRCVTr22pU/F1Ik6kmMiU+uXZm563wdsBgKvEtcVf+ L1+50npG3y/BnCGGl2tvB/6ouXbMWlNgOnFC1kavjglv9BpV3esHU33PN49TxsIQkSoQ9F SlTJvuePi20D1FhQvofI5qwvNH1t0G1SE3xXYj6p3EpzNniWsjB7A5vS9G1btw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1656625807; a=rsa-sha256; cv=none; b=jNUJvCu3MDKyFtwSiB/psgfJ2scbkaBvheLOI8RxKS06qiZ9+LPEhS3pDI9MMUx0sdTB9i AFt1xTTgPB61ilnyu/tFgTpaTxFu0N+6gS0koJQ3PumsH1m46rLa3h6nd+hETXlSRn29j8 tjkj0E4bU6/CW1xlhBavycxKCcTASLzgX6rN+kMxqlGQ239jVrQQMb3PVFUQHXfx4eZK4L aCV+fx8CvUq24oRKKHhjCx/KP0L87UupWDpV3SPUILSNMyPlYTbTa+iQjCPk9zmvlvhS8t noAOmOiH1eJVZr6A5BJe0ChCnor7+ayqzRsCJUgDeX1uP0d3rF+dimo/VUB9qA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=f0880ab791a510391a12f2ab7b01889b6774bca0 commit f0880ab791a510391a12f2ab7b01889b6774bca0 Author: Vitaliy Gusev AuthorDate: 2022-06-30 21:21:57 +0000 Commit: John Baldwin CommitDate: 2022-06-30 21:21:57 +0000 libvmmapi: Add vm_close() Currently there is no way to safely free a vm structure without leaking the fd. vm_destroy() closes the fd but also destroys the VM whereas in some cases a VM needs to be opened (vm_open) and then closed (vm_close). Reviewed by: jhb Sponsored by: vStack Differential Revision: https://reviews.freebsd.org/D35073 --- lib/libvmmapi/vmmapi.c | 9 +++++++++ lib/libvmmapi/vmmapi.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/lib/libvmmapi/vmmapi.c b/lib/libvmmapi/vmmapi.c index e92b3199381f..260c2a2439ff 100644 --- a/lib/libvmmapi/vmmapi.c +++ b/lib/libvmmapi/vmmapi.c @@ -140,6 +140,15 @@ err: return (NULL); } +void +vm_close(struct vmctx *vm) +{ + assert(vm != NULL); + + close(vm->fd); + free(vm); +} + void vm_destroy(struct vmctx *vm) { diff --git a/lib/libvmmapi/vmmapi.h b/lib/libvmmapi/vmmapi.h index 87051973225a..438fd582db0e 100644 --- a/lib/libvmmapi/vmmapi.h +++ b/lib/libvmmapi/vmmapi.h @@ -33,6 +33,7 @@ #include #include +#include #include #include @@ -117,6 +118,7 @@ int vm_munmap_memseg(struct vmctx *ctx, vm_paddr_t gpa, size_t len); int vm_create(const char *name); int vm_get_device_fd(struct vmctx *ctx); struct vmctx *vm_open(const char *name); +void vm_close(struct vmctx *ctx); void vm_destroy(struct vmctx *ctx); int vm_parse_memsize(const char *optarg, size_t *memsize); int vm_setup_memory(struct vmctx *ctx, size_t len, enum vm_mmap_style s);