From nobody Tue Dec 14 23:30:25 2021 X-Original-To: dev-commits-src-all@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 7AC7418DF501; Tue, 14 Dec 2021 23:30:26 +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 4JDF3k0ydvz4t57; Tue, 14 Dec 2021 23:30:26 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 02B2911C06; Tue, 14 Dec 2021 23:30:26 +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 1BENUPAL039852; Tue, 14 Dec 2021 23:30:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BENUP6O039851; Tue, 14 Dec 2021 23:30:25 GMT (envelope-from git) Date: Tue, 14 Dec 2021 23:30:25 GMT Message-Id: <202112142330.1BENUP6O039851@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Chuck Tuffli Subject: git: cf3ed8e0cd95 - main - bhyve nvme: Inform guests of namespace resize List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: chuck X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: cf3ed8e0cd9505f21f614e8208f7afd9cfa4d621 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1639524626; 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=Wg1yighHvpGk5ADcNdhnM+BZZSzdttKGfHmyKxcxgFU=; b=M0WejZN6FTdjktGSa4iQ5yBKa7p2UIb8/kM6NaVgzUlLHJI+9GQPy6jGS6LtkkyqJu8GKX Zzvq1r38wnnGG26SgZdmVgtsjKEAnotUDNpfE5eNWLRoHXKiAbCKF16Mj0m16xF1SNGcRO QlFO5LAlNDIhEyxmqge0ymaIFra6vnW96G13HFswzmWxKq3MRGrlyjxrXl4rlbuQei0lFV 9J7bIzSqc3Yo7G1AdBGi50MMaFV7MPnN/i2kXx5dJSy6mgy/gfT6o+H+/53X9j/bcH7OMB Ebiar6u+n1+JkD1ySoDX2rWxWaiFKW8QccXGOKqnj7U7NdPBlad7V4l2FBBvxQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1639524626; a=rsa-sha256; cv=none; b=LobHdWZyaKanzYplJ+TKz8/tvnkcoXeyH8k9MGE+6q2/6xQllb4E5ozSc44vQLXIV/1FwE GoyyejLDemSPdD8pWvDH2hmBdFiOmXXQf2UOpluaw1kuQ9J6XQ5DXARotpgA7qNPBe+0Vx wNx7qMet9S7u47CJjAXKo2EaxYLDwegP8dN6n0qmNlrr8gVlEsirD+TgHyeZwa/eQfklXo Gr53lClPdNryscpr32CAquFqw6mS9kdvCWigZWzsjOPOmgqyqfmZoNaent2l8yfYedQnkr S77ozl7SuldttIjSqmwcguvnkp98t3t9NWbZR00oFhC/yrcFYZYinuwgb7leEA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by chuck: URL: https://cgit.FreeBSD.org/src/commit/?id=cf3ed8e0cd9505f21f614e8208f7afd9cfa4d621 commit cf3ed8e0cd9505f21f614e8208f7afd9cfa4d621 Author: Chuck Tuffli AuthorDate: 2021-12-15 07:17:55 +0000 Commit: Chuck Tuffli CommitDate: 2021-12-15 07:17:55 +0000 bhyve nvme: Inform guests of namespace resize Register a "block resize" callback to be notified of changes to the backing storage for the Namespace. Use this to generate an Asynchronous Event Notification, Namespace Attributes Changed when the guest OS provides an Asynchronous Event Request. MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D32953 --- usr.sbin/bhyve/pci_nvme.c | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/usr.sbin/bhyve/pci_nvme.c b/usr.sbin/bhyve/pci_nvme.c index 6fd1aa14b9e3..07b079ecd4a1 100644 --- a/usr.sbin/bhyve/pci_nvme.c +++ b/usr.sbin/bhyve/pci_nvme.c @@ -296,6 +296,7 @@ struct pci_nvme_softc { struct nvme_error_information_entry err_log; struct nvme_health_information_page health_log; struct nvme_firmware_page fw_log; + struct nvme_ns_list ns_log; struct pci_nvme_blockstore nvstore; @@ -598,15 +599,23 @@ crc16(uint16_t crc, const void *buffer, unsigned int len) } static void -pci_nvme_init_nsdata(struct pci_nvme_softc *sc, - struct nvme_namespace_data *nd, uint32_t nsid, - struct pci_nvme_blockstore *nvstore) +pci_nvme_init_nsdata_size(struct pci_nvme_blockstore *nvstore, + struct nvme_namespace_data *nd) { /* Get capacity and block size information from backing store */ nd->nsze = nvstore->size / nvstore->sectsz; nd->ncap = nd->nsze; nd->nuse = nd->nsze; +} + +static void +pci_nvme_init_nsdata(struct pci_nvme_softc *sc, + struct nvme_namespace_data *nd, uint32_t nsid, + struct pci_nvme_blockstore *nvstore) +{ + + pci_nvme_init_nsdata_size(nvstore, nd); if (nvstore->type == NVME_STOR_BLOCKIF) nvstore->deallocate = blockif_candelete(nvstore->ctx); @@ -642,6 +651,7 @@ pci_nvme_init_logpages(struct pci_nvme_softc *sc) memset(&sc->err_log, 0, sizeof(sc->err_log)); memset(&sc->health_log, 0, sizeof(sc->health_log)); memset(&sc->fw_log, 0, sizeof(sc->fw_log)); + memset(&sc->ns_log, 0, sizeof(sc->ns_log)); /* Set read/write remainder to round up according to spec */ sc->read_dunits_remainder = 999; @@ -1363,6 +1373,13 @@ nvme_opc_get_log_page(struct pci_nvme_softc* sc, struct nvme_command* command, MIN(logsize, sizeof(sc->fw_log)), NVME_COPY_TO_PRP); break; + case NVME_LOG_CHANGED_NAMESPACE: + nvme_prp_memcpy(sc->nsc_pi->pi_vmctx, command->prp1, + command->prp2, (uint8_t *)&sc->ns_log, + MIN(logsize, sizeof(sc->ns_log)), + NVME_COPY_TO_PRP); + memset(&sc->ns_log, 0, sizeof(sc->ns_log)); + break; default: DPRINTF("%s get log page %x command not supported", __func__, logpage); @@ -2970,6 +2987,28 @@ pci_nvme_parse_config(struct pci_nvme_softc *sc, nvlist_t *nvl) return (0); } +static void +pci_nvme_resized(struct blockif_ctxt *bctxt, void *arg, size_t new_size) +{ + struct pci_nvme_softc *sc; + struct pci_nvme_blockstore *nvstore; + struct nvme_namespace_data *nd; + + sc = arg; + nvstore = &sc->nvstore; + nd = &sc->nsdata; + + nvstore->size = new_size; + pci_nvme_init_nsdata_size(nvstore, nd); + + /* Add changed NSID to list */ + sc->ns_log.ns[0] = 1; + sc->ns_log.ns[1] = 0; + + pci_nvme_aen_post(sc, PCI_NVME_AE_TYPE_NOTICE, + PCI_NVME_AE_INFO_NS_ATTR_CHANGED); +} + static int pci_nvme_init(struct vmctx *ctx, struct pci_devinst *pi, nvlist_t *nvl) { @@ -3035,6 +3074,7 @@ pci_nvme_init(struct vmctx *ctx, struct pci_devinst *pi, nvlist_t *nvl) pthread_mutex_init(&sc->mtx, NULL); sem_init(&sc->iosemlock, 0, sc->ioslots); + blockif_register_resize_callback(sc->nvstore.ctx, pci_nvme_resized, sc); pci_nvme_init_queues(sc, sc->max_queues, sc->max_queues); /*