From nobody Fri Feb 18 21:33:53 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 9E65819DBFD7; Fri, 18 Feb 2022 21:33:53 +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 4K0lLn42Yqz3HSV; Fri, 18 Feb 2022 21:33:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645220033; 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=SyvFnQ0FiyCSUQyzgBKqjnYvYYZ1U4DN+cBNuQmPXn8=; b=daO7mrridsK240Yu0dQFdO/dy1mmgvCzyQ+Cd8gcZqvJnM4G02pJOK518tfuKHRlf8wK2S xjK/PUnERAkfPff3CGed/ADEDsyi4wsuqzr/+L1QfIVw4WcFS4irMgPgbgkde48cPMldNu tJLqmlfOXWc6dYhMHaruAQMNeAN2l+x42Eunp6LUEHPM/K8f96CMfUcPFjGAwGt05rKVVP 15gWQH4lykf7KlghCM93FEon0sPVoUgf/R0rKAe8QO4uIcEq1M6qQ5ZkCQQWZT/sHux4gp HTwVLrhLlrLt/RsqZSW4yAh2//ZEo00ruoyMasuCvdBIEi17CbTQqf22GQBoCw== 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 6A51A24ED0; Fri, 18 Feb 2022 21:33:53 +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 21ILXr2b017496; Fri, 18 Feb 2022 21:33:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 21ILXrO1017495; Fri, 18 Feb 2022 21:33:53 GMT (envelope-from git) Date: Fri, 18 Feb 2022 21:33:53 GMT Message-Id: <202202182133.21ILXrO1017495@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Kenneth D. Merry" Subject: git: 58df94091a3e - stable/13 - Fix non-printable characters in NVMe model and serial numbers. 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: ken X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 58df94091a3e67e9c54f4f1f8001e89d5fd5f3ec Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645220033; 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=SyvFnQ0FiyCSUQyzgBKqjnYvYYZ1U4DN+cBNuQmPXn8=; b=cy78jBKLwzUa1v4hf+nI7j+ZGYexknLEw1UNfue0EsafnDSV4T3RCn7NTTuWmoSlSEoV7W rhR2pGaRmtirPtf4VEYiihksm/qntzpMbwDISPGEvTFPXFmE4YQz6V511J7At+CK1PKasB aGfHdU2rUAL22gp7U6m+9r5lbeVlZg5aGSpugYXgolenFpDN9qM/g/vGQaCu2Y1CchpA0+ Nuyj472Y0Xs6ZtLkwDqriPSG+P4+luTbD5LclXLQEqqSlvRpJDy/IuEtDEkqTPsQHJ8nye Z43FRBEvWsJ3ZvcDosn43vuu9iVgjm+dv8U06rYPEzCHUQ0Y/YNsDLRxDtzVjg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1645220033; a=rsa-sha256; cv=none; b=P0mKeBijqkIBB8FWlSTd6/7JWzPwr5pOPcPjQp83mSE0B6TffpigBi6x5GgBqBKWFnRmQa lzEUSBhgquY1A2+YQ4aBYH4bghMLDmhqmcy3HdHm/q6URDri2B6fRYnuaQh5vdbEC7r66z ad4D0kqFEY0SGXHQLpc6m2nQMmjA/LQAcCNxb/pIlkrdBp8SiMv63SpbXkEk8Lhymu+6dj KbV4UBcVr+9AK8PTfpIT2o3yIHLNO+v2tt6+HsRJ+WTlf0padFjZSnlS3MfmzsCq2dusRc eFUA12sTNwVfDK/dJ7rFwL/cVoP+kp/WLd860yL8dJzja+tlvIE7E8u0xNSseA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by ken: URL: https://cgit.FreeBSD.org/src/commit/?id=58df94091a3e67e9c54f4f1f8001e89d5fd5f3ec commit 58df94091a3e67e9c54f4f1f8001e89d5fd5f3ec Author: Kenneth D. Merry AuthorDate: 2022-01-24 21:19:25 +0000 Commit: Kenneth D. Merry CommitDate: 2022-02-18 21:28:32 +0000 Fix non-printable characters in NVMe model and serial numbers. The NVMe 1.4 spec simply says that Model and Serial numbers are ASCII strings. Unlike SCSI, it doesn't prohibit non-printable characters or say that the strings should be padded with spaces. Since 2014, we have had cam_strvis_sbuf(), which gives additional options for handling non-ASCII characters. That behavior hasn't been available for non-sbuf consumers, so users of cam_strvis() were left with having octal ASCII codes inserted. So, to avoid having garbage or octal chracters in the strings, use cam_strvis_sbuf() to create a new function, cam_strvis_flag(), and re-implement cam_strvis() using cam_strvis_flag(). Now, for the NVMe drives, we can use cam_strvis_flag with the CAM_STRVIS_FLAG_NONASCII_SPC flag. This transforms non-printable characters into spaces. sys/cam/cam.c: Add a new function, cam_strvis_flag(), that creates an sbuf on the stack with the user's destination buffer, and calls cam_strvis_sbuf() with the given flag argument. Re-implement cam_strvis() to call cam_strvis_flag with the CAM_STRVIS_FLAG_NONASCII_ESC argument. This should be the equivalent of the old cam_strvis() function, except for the overhead of creating the sbuf and calling sbuf_putc/printf. sys/cam/cam.h: Declaration for cam_strvis_flag. sys/cam/nvme/nvme_all.c: In nvme_print_ident, use the NONASCII_SPC flag with cam_strvis_flag(). sys/cam/nvme/nvme_da.c: In ndaregister(), use cam_strvis_flag() with the NONASCII_SPC flag for the disk description and serial number we report to GEOM. sys/cam/nvme/nvme_xpt.c: In nvme_probe_done(), use cam_strvis_flag with the NONASCII_SPC flag when storing the drive serial number in the CAM EDT. Sponsored by: Spectra Logic Differential Revision: https://reviews.freebsd.org/D33973 (cherry picked from commit 3090d5045a1e5663f151ef3f50f3c7db8f9a9e3c) --- sys/cam/cam.c | 41 +++++++++++------------------------------ sys/cam/cam.h | 2 ++ sys/cam/nvme/nvme_all.c | 9 ++++++--- sys/cam/nvme/nvme_da.c | 10 ++++++---- sys/cam/nvme/nvme_xpt.c | 7 +++++-- 5 files changed, 30 insertions(+), 39 deletions(-) diff --git a/sys/cam/cam.c b/sys/cam/cam.c index 5b7e2a7e924f..5b7235e01314 100644 --- a/sys/cam/cam.c +++ b/sys/cam/cam.c @@ -123,38 +123,19 @@ SYSCTL_INT(_kern_cam, OID_AUTO, sort_io_queues, CTLFLAG_RWTUN, void cam_strvis(u_int8_t *dst, const u_int8_t *src, int srclen, int dstlen) { + cam_strvis_flag(dst, src, srclen, dstlen, + CAM_STRVIS_FLAG_NONASCII_ESC); +} - /* Trim leading/trailing spaces, nulls. */ - while (srclen > 0 && src[0] == ' ') - src++, srclen--; - while (srclen > 0 - && (src[srclen-1] == ' ' || src[srclen-1] == '\0')) - srclen--; - - while (srclen > 0 && dstlen > 1) { - u_int8_t *cur_pos = dst; +void +cam_strvis_flag(u_int8_t *dst, const u_int8_t *src, int srclen, int dstlen, + uint32_t flags) +{ + struct sbuf sb; - if (*src < 0x20 || *src >= 0x80) { - /* SCSI-II Specifies that these should never occur. */ - /* non-printable character */ - if (dstlen > 4) { - *cur_pos++ = '\\'; - *cur_pos++ = ((*src & 0300) >> 6) + '0'; - *cur_pos++ = ((*src & 0070) >> 3) + '0'; - *cur_pos++ = ((*src & 0007) >> 0) + '0'; - } else { - *cur_pos++ = '?'; - } - } else { - /* normal character */ - *cur_pos++ = *src; - } - src++; - srclen--; - dstlen -= cur_pos - dst; - dst = cur_pos; - } - *dst = '\0'; + sbuf_new(&sb, dst, dstlen, SBUF_FIXEDLEN); + cam_strvis_sbuf(&sb, src, srclen, flags); + sbuf_finish(&sb); } void diff --git a/sys/cam/cam.h b/sys/cam/cam.h index 2aaa2e3a5775..cb26d06723f5 100644 --- a/sys/cam/cam.h +++ b/sys/cam/cam.h @@ -377,6 +377,8 @@ caddr_t cam_quirkmatch(caddr_t target, caddr_t quirk_table, int num_entries, int entry_size, cam_quirkmatch_t *comp_func); void cam_strvis(u_int8_t *dst, const u_int8_t *src, int srclen, int dstlen); +void cam_strvis_flag(u_int8_t *dst, const u_int8_t *src, int srclen, + int dstlen, uint32_t flags); void cam_strvis_sbuf(struct sbuf *sb, const u_int8_t *src, int srclen, uint32_t flags); diff --git a/sys/cam/nvme/nvme_all.c b/sys/cam/nvme/nvme_all.c index 14fcd3a7536e..1eafdb1cece6 100644 --- a/sys/cam/nvme/nvme_all.c +++ b/sys/cam/nvme/nvme_all.c @@ -91,11 +91,14 @@ nvme_print_ident(const struct nvme_controller_data *cdata, { sbuf_printf(sb, "<"); - cam_strvis_sbuf(sb, cdata->mn, sizeof(cdata->mn), 0); + cam_strvis_sbuf(sb, cdata->mn, sizeof(cdata->mn), + CAM_STRVIS_FLAG_NONASCII_SPC); sbuf_printf(sb, " "); - cam_strvis_sbuf(sb, cdata->fr, sizeof(cdata->fr), 0); + cam_strvis_sbuf(sb, cdata->fr, sizeof(cdata->fr), + CAM_STRVIS_FLAG_NONASCII_SPC); sbuf_printf(sb, " "); - cam_strvis_sbuf(sb, cdata->sn, sizeof(cdata->sn), 0); + cam_strvis_sbuf(sb, cdata->sn, sizeof(cdata->sn), + CAM_STRVIS_FLAG_NONASCII_SPC); sbuf_printf(sb, ">\n"); } diff --git a/sys/cam/nvme/nvme_da.c b/sys/cam/nvme/nvme_da.c index 7a489afdb993..a3d72e1017c9 100644 --- a/sys/cam/nvme/nvme_da.c +++ b/sys/cam/nvme/nvme_da.c @@ -930,10 +930,12 @@ ndaregister(struct cam_periph *periph, void *arg) * d_ident and d_descr are both far bigger than the length of either * the serial or model number strings. */ - cam_strvis(disk->d_descr, cd->mn, - NVME_MODEL_NUMBER_LENGTH, sizeof(disk->d_descr)); - cam_strvis(disk->d_ident, cd->sn, - NVME_SERIAL_NUMBER_LENGTH, sizeof(disk->d_ident)); + cam_strvis_flag(disk->d_descr, cd->mn, NVME_MODEL_NUMBER_LENGTH, + sizeof(disk->d_descr), CAM_STRVIS_FLAG_NONASCII_SPC); + + cam_strvis_flag(disk->d_ident, cd->sn, NVME_SERIAL_NUMBER_LENGTH, + sizeof(disk->d_ident), CAM_STRVIS_FLAG_NONASCII_SPC); + disk->d_hba_vendor = cpi.hba_vendor; disk->d_hba_device = cpi.hba_device; disk->d_hba_subvendor = cpi.hba_subvendor; diff --git a/sys/cam/nvme/nvme_xpt.c b/sys/cam/nvme/nvme_xpt.c index 2aeda18ad3be..bdc1219729d2 100644 --- a/sys/cam/nvme/nvme_xpt.c +++ b/sys/cam/nvme/nvme_xpt.c @@ -376,8 +376,11 @@ device_fail: if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0) path->device->serial_num = (u_int8_t *) malloc(NVME_SERIAL_NUMBER_LENGTH + 1, M_CAMXPT, M_NOWAIT); if (path->device->serial_num != NULL) { - cam_strvis(path->device->serial_num, nvme_cdata->sn, - NVME_SERIAL_NUMBER_LENGTH, NVME_SERIAL_NUMBER_LENGTH + 1); + cam_strvis_flag(path->device->serial_num, + nvme_cdata->sn, sizeof(nvme_cdata->sn), + NVME_SERIAL_NUMBER_LENGTH + 1, + CAM_STRVIS_FLAG_NONASCII_SPC); + path->device->serial_num_len = strlen(path->device->serial_num); }