From nobody Wed Nov 23 09:44:04 2022 X-Original-To: dev-commits-src-branches@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 4NHGRS2jLjz4jCqv; Wed, 23 Nov 2022 09:44:04 +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 4NHGRS2H3hz4FsC; Wed, 23 Nov 2022 09:44:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1669196644; 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=lHIH0gyl/f9bsumpAlWKob1esesG3VGSgfXFqI5YR8k=; b=Ur0vsTJOe0XA6ss2d7NgtoBhuEs7VKNob74/T6pPC6lhFYtALb93w6wFFU4P8bwfEBTVYQ SWlye21VikaFcr/8YHF/Kh83qEatMEyrWEE03z4uiVrvnj9GPsdzwgySYvDTJznPUMXtW1 oNZ0hv7rTYTnTYXEluwZ7uck+bZXf2R/xgNEmsTkILlcjVDaWEFF0a/xUS4qS9PrzwQ4IW KuZGN+a7hdZrQajy8gqxyhtFo2KO8TkX99hgagF+1KZqAZwV6e2VNHKaUeDDUN/WRdsiPd lP/MuIsn1K4KdRUbDpSioFwKn/H5zD+IbTaO6DKc5Jist1Oey470/2hGDVvnkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1669196644; 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=lHIH0gyl/f9bsumpAlWKob1esesG3VGSgfXFqI5YR8k=; b=k9veRbTuMHqeHHt1QW8ZkDGvVv7tX5nzkEXPUUVjIK66lbJ4FzKqfdV7SoXU+ZkHPCX5A8 ZcyjjyUgh50m6jHnBw0OzasK6ExSBG7qcVeuC8+bz+Em+fx/uZtX8ycUSh23KuHFvdQ/M0 qitEVXCmI+qYE6BzDQeKAp+r74pIby9/YsEaeXaWQ4Nuvifi4yceugUcsyUrAmUF33ErsP JZ7JGr5l7ry+Np1a8VBstRVWdMWodPHpeHiv15M6PQNMgodCNIAeMjEqfebtfN6W5AzpqT 8XAnF91Nm4LRowYiKQEME7sT8322aN6Y2A65YJppB7T/9tG/i5vYPRna85jFnw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1669196644; a=rsa-sha256; cv=none; b=ISgFl5qzglIRJwu1MB5A3iS4LUAJW9QNSbz/NhA/FDfJGFRfUWtYxKbBY5tdHYHo0Tkw7D 8X6wOWAoN89/2YJfyDczpbcjKlrZAoLD/Yom0hu63OcakYwq4TsSByjHMn49h/tyBppspj jJlP5i78nHa5OL3HwHRNMipTiseD7+rEAnYxLMFr1lsHO9lR2At9dwd52VyRoDEIFF/Neb ii+D3+fEUMK2YzU/s/EjfFr03/SmlNbq117v/TNvy4AZy5AwrB5y81LN8n7WsLWCmSrgym bzhYkE5pd2gfgCu9XX+almqVKD3ZLXG4fDBXLrpt21NrcpL6h4V7i0WnvGzm/A== 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 4NHGRS1KPZzHr5; Wed, 23 Nov 2022 09:44:04 +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 2AN9i416015769; Wed, 23 Nov 2022 09:44:04 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2AN9i4NK015768; Wed, 23 Nov 2022 09:44:04 GMT (envelope-from git) Date: Wed, 23 Nov 2022 09:44:04 GMT Message-Id: <202211230944.2AN9i4NK015768@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: =?utf-8?Q?Corvin=20K=C3=B6hne?= Subject: git: 5ebc003a2882 - stable/13 - bhyve: abort and return FEATURE_NOT_SAVEABLE while set feature with a save flag for NVMe controller. List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: corvink X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 5ebc003a2882a35054a93411a2c4d60f6e9cec3c Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by corvink: URL: https://cgit.FreeBSD.org/src/commit/?id=5ebc003a2882a35054a93411a2c4d60f6e9cec3c commit 5ebc003a2882a35054a93411a2c4d60f6e9cec3c Author: Wanpeng Qian AuthorDate: 2022-11-14 13:02:44 +0000 Commit: Corvin Köhne CommitDate: 2022-11-22 06:51:28 +0000 bhyve: abort and return FEATURE_NOT_SAVEABLE while set feature with a save flag for NVMe controller. Currently bhyve's NVMe controller cannot save feature values cross reboot. It should return a FEATURE_NOT_SAVEABLE error when the command specifies a save flag. Quote from NVMe specification, page 205: https://nvmexpress.org/wp-content/uploads/NVM-Express-1_4-2019.06.10-Ratified.pdf If the Feature Identifier specified in the Set Features command is not saveable by the controller and the controller receives a Set Features command with the Save bit set to one, then the command shall be aborted with a status of Feature Identifier Not Saveable. Reviewed by: chuck (older version) Approved by: manu (mentor) MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D32767 (cherry picked from commit 8ab99dbea16728f3e34137310587a6aeb3f3d317) --- sys/dev/nvme/nvme.h | 16 ++++++++++++++++ usr.sbin/bhyve/pci_nvme.c | 10 +++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/sys/dev/nvme/nvme.h b/sys/dev/nvme/nvme.h index 177f18f916c1..2e0fb27c1d99 100644 --- a/sys/dev/nvme/nvme.h +++ b/sys/dev/nvme/nvme.h @@ -563,9 +563,25 @@ enum nvme_critical_warning_state { #define NVME_SS_PAGE_SSTAT_GDE_SHIFT (8) #define NVME_SS_PAGE_SSTAT_GDE_MASK (0x1) +/* Features */ +/* Get Features */ +#define NVME_FEAT_GET_SEL_SHIFT (8) +#define NVME_FEAT_GET_SEL_MASK (0x7) +#define NVME_FEAT_GET_FID_SHIFT (0) +#define NVME_FEAT_GET_FID_MASK (0xff) + +/* Set Features */ +#define NVME_FEAT_SET_SV_SHIFT (31) +#define NVME_FEAT_SET_SV_MASK (0x1) +#define NVME_FEAT_SET_FID_SHIFT (0) +#define NVME_FEAT_SET_FID_MASK (0xff) + /* Helper macro to combine *_MASK and *_SHIFT defines */ #define NVMEB(name) (name##_MASK << name##_SHIFT) +/* Helper macro to extract value from x */ +#define NVMEV(name, x) (((x) >> name##_SHIFT) & name##_MASK) + /* CC register SHN field values */ enum shn_value { NVME_SHN_NORMAL = 0x1, diff --git a/usr.sbin/bhyve/pci_nvme.c b/usr.sbin/bhyve/pci_nvme.c index 91cf919f49fd..9704081c12af 100644 --- a/usr.sbin/bhyve/pci_nvme.c +++ b/usr.sbin/bhyve/pci_nvme.c @@ -1820,7 +1820,8 @@ nvme_opc_set_features(struct pci_nvme_softc *sc, struct nvme_command *command, { struct nvme_feature_obj *feat; uint32_t nsid = command->nsid; - uint8_t fid = command->cdw10 & 0xFF; + uint8_t fid = NVMEV(NVME_FEAT_SET_FID, command->cdw10); + bool sv = NVMEV(NVME_FEAT_SET_SV, command->cdw10); DPRINTF("%s: Feature ID 0x%x (%s)", __func__, fid, nvme_fid_to_name(fid)); @@ -1829,6 +1830,13 @@ nvme_opc_set_features(struct pci_nvme_softc *sc, struct nvme_command *command, pci_nvme_status_genc(&compl->status, NVME_SC_INVALID_FIELD); return (1); } + + if (sv) { + pci_nvme_status_tc(&compl->status, NVME_SCT_COMMAND_SPECIFIC, + NVME_SC_FEATURE_NOT_SAVEABLE); + return (1); + } + feat = &sc->feat[fid]; if (feat->namespace_specific && (nsid == NVME_GLOBAL_NAMESPACE_TAG)) {