From nobody Mon Feb 21 21:57:49 2022 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 AD12C19EACED; Mon, 21 Feb 2022 21:57:50 +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 4K2bl21Vndz4gYq; Mon, 21 Feb 2022 21:57:50 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645480670; 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=umfn45+T5NGVUaZA/RCZo+Uq4MftNHFWFeEMlwk1X30=; b=ub2t9nHFtHc2RycScwlrBGDoC3QfXeA2Eyj6n+gzz2AV5ZsbLd9MXNS1PkxTWHIT99BJO+ qbF46MoXI28oagCrO7z9ygytA669bOC9Rkz0pHX/fkNKbI0uE4K1mbZ535HSuyfbThn2QZ /X2J1kboDdu3OEMel2vj9YV/4KPOQqCyAdNQFmSP6kcmDnPXALbkXzcboLtlqHswJE5Y0y lSz43OfH4UhK2pi/IksFEuANBSHILyI7Fd3/vE1SBa9AkmLFJQtrPOig7ErlnSwrWEBY9V TvxeRCawbRBmdCr+4Z4+o/LA9Vk2DdxGqdH3eoOzVM3eTGfdifRponxhdFP9qg== 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 E494018498; Mon, 21 Feb 2022 21:57:49 +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 21LLvnmn051960; Mon, 21 Feb 2022 21:57:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 21LLvnHt051959; Mon, 21 Feb 2022 21:57:49 GMT (envelope-from git) Date: Mon, 21 Feb 2022 21:57:49 GMT Message-Id: <202202212157.21LLvnHt051959@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Chuck Tuffli Subject: git: 67fa95bf0c0b - stable/13 - 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/stable/13 X-Git-Reftype: branch X-Git-Commit: 67fa95bf0c0b74603295f9fed25df22982effb1b Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645480670; 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=umfn45+T5NGVUaZA/RCZo+Uq4MftNHFWFeEMlwk1X30=; b=rFfyKC5SPYlLw3C0nBK/q+tr/uunAIXI16rnAKTWxrRNbX84sbCp2ODXGKeExMQpNj8kY8 Q5lRkF1odC0fe5rkU4pmwfAvw0L2Xo9cDNiba2K3+aA6BQA2kzf6ID18ej9cIJxeDF5pGU 6juenhCcTgXsgt0KFxGmr0K8aq+o6XCVlQ+kcvNby1sQ5mqZzDsk3l3krm7S0+siutHjKs 0PKZZJaaTp/StgjzeE5s6MYuO9Dw7Fg+8tzuOeMSjR77RZLlKqEfcBViSD0Aj3ZtyxMdE2 6O81SinJV/aNSH2Fprz4xinFh9sOjuvhQeY9/E68US9mbbEkX6pnYBC6x9a49w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1645480670; a=rsa-sha256; cv=none; b=UpZmPh7kKlkx9EQl+a04rj4Zx1iaCEn8nDvR0uTV8+wN4hT4tAII+31FMAIw0dnvGJm1T+ Bq5lNAEbPRMtb86BO8eQwxaygr8gibQEK8DRolEVEXLkMp48t96u6r52vh752GpF0MzpVM 1malQstEjqxwJyomn23gJEA0IqlMip6uDsRCPz4KnCIISG+hhLkgq99nbZmiXwLP7UjBMy /u/vCkjoAoUxPmkoX8imlabwHZPHTCsBtSlMH5t6E4Z00qxLsGguXmGt4VyXXoR8866TQe jujPEZMWDztonQJvdrYIRZi4raenYjaDTVceLjk6++LZMaVnuqTuF+gVN4kfaA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by chuck: URL: https://cgit.FreeBSD.org/src/commit/?id=67fa95bf0c0b74603295f9fed25df22982effb1b commit 67fa95bf0c0b74603295f9fed25df22982effb1b Author: Chuck Tuffli AuthorDate: 2021-12-15 07:17:55 +0000 Commit: Chuck Tuffli CommitDate: 2022-02-22 03:24:35 +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. (cherry picked from commit cf3ed8e0cd9505f21f614e8208f7afd9cfa4d621) --- 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); /*