From nobody Tue Oct 03 01:31:18 2023 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 4S00dz0C4wz4vVlQ; Tue, 3 Oct 2023 01:31:19 +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 4S00dy6pWwz4KMG; Tue, 3 Oct 2023 01:31:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696296679; 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=z7pNO3Eh+YkwAQjzJ2PHm1dkPBiAfoDzYMoBfNWo2Sg=; b=s/y4O9GbKIMwJVBKvGHSyXvLb9k1Cctbz/mgr/Ricy22RBRBL9q0afxRsINMInb2WnJ7h7 I4V+xyzBTxpYOF43QrBGsZ/yQhjLJa0q0FeS2KBpsa1z/dXpGPxWMvKV23OAtg9cfzmJTC OIDu2qTYiAyOKuo5AGLaCnEHon9pJa6KZHom6JBYzLDaZibjtNMlYMtiWHJ7sV9K9OuI/P Gh2uaXy5a+jWOdGWfgpluIqTnVBqQemNKmSb0wz9e1K1+M7ShTy97G5VDBwyjMoxeGcKdE r+vmMGfOjoLl9fbTfV5FufuGIee5HPwoNEZOVbfkOQq6hrKtHYsI8upUQECjww== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1696296679; a=rsa-sha256; cv=none; b=eTJK1XvzgKF3+cbu1GDvt5PMD762LHaj7NukhVo4soMXYfzHYhVcfX5LvyrUFLpPa4hZm7 N/3GYGzzGgopQMzAWUwA26HZoGZr+N4xLAmtN98lZPafYQUtUw9BB39Atg6LitYHQbZ4hU rvuCKlSRlwx5tTIdLZzHXMAe0odI4WThwWV3+3cxX9RFZOySDX8ErQcy6EIMxqq9kMvBmV GoD/eHYgHislazujiuOE1QXZmXStsRO9CZXOlctNBZdXsi5cvM95T/ktJQfjkE8/6nBvWC pnRRKBlHHOUyhhhqRzWAm0jWS49494Ec+4dLYPwyCciZUmVPoDitPROB6UlCHg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696296679; 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=z7pNO3Eh+YkwAQjzJ2PHm1dkPBiAfoDzYMoBfNWo2Sg=; b=seb4FKCFrDMy26i/ILeJg9yY9/s7NEbZTNfOzoAl1HcveS+NDYDSKcB5QnX/VMjHHWBSSH H+Y1EUJ8oIQRGQQMzqaicTHFzoIpN/r6GC5E5uPNO+2h5bSExjRCd2twVE+Y8wMuTcqnFI I3uf28r1vLCl3grqKzcmYtwF/jzosO6z+GY+e9Ou2+Ij2OfLR3sOyw+UOMcZTYSQVXtFxI NCSgNIFMD2xTOLZWQ9ecNJEnTkYJkaeGVzb/F4DsoP+qJ6LLaEI9BU7g7k+nZwVE2eQ+g3 bx1fsN8EedV8J8ZFxgQMf8zHksa81/+0rJ4Ixx/4j4o7pk9n4OmvG2s6wl4bew== 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 4S00dy5rx2zZk0; Tue, 3 Oct 2023 01:31:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3931VIYC096243; Tue, 3 Oct 2023 01:31:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3931VIst096240; Tue, 3 Oct 2023 01:31:18 GMT (envelope-from git) Date: Tue, 3 Oct 2023 01:31:18 GMT Message-Id: <202310030131.3931VIst096240@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alan Somers Subject: git: c70a4185c637 - stable/14 - mprutil: "fix user reply buffer (64)..." warnings 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: asomers X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: c70a4185c637754428f36536af3bdc9181fa5155 Auto-Submitted: auto-generated The branch stable/14 has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=c70a4185c637754428f36536af3bdc9181fa5155 commit c70a4185c637754428f36536af3bdc9181fa5155 Author: Alan Somers AuthorDate: 2023-02-22 22:06:43 +0000 Commit: Alan Somers CommitDate: 2023-10-03 01:31:12 +0000 mprutil: "fix user reply buffer (64)..." warnings Depending on the card's firmware version, it may return different length responses for MPI2_FUNCTION_IOC_FACTS. But the first part of the response contains the length of the rest, so query it first to get the length and then use that to size the buffer for the full response. Also, correctly zero-initialize MPI2_IOC_FACTS_REQUEST. It only worked by luck before. PR: 264848 Reported by: Julien Cigar Sponsored by: Axcient Reviewed by: scottl, imp Differential Revision: https://reviews.freebsd.org/D38739 (cherry picked from commit 7d154c4dc64e61af7ca536c4e9927fa07c675a83) --- sys/dev/mpr/mpr.c | 2 +- sys/dev/mpr/mpr_user.c | 4 ++-- sys/dev/mps/mps.c | 2 +- sys/dev/mps/mps_user.c | 4 ++-- usr.sbin/mpsutil/mps_cmd.c | 40 +++++++++++++++++++++++++++------------- 5 files changed, 33 insertions(+), 19 deletions(-) diff --git a/sys/dev/mpr/mpr.c b/sys/dev/mpr/mpr.c index 72993be8834e..23f7ff0c3e9a 100644 --- a/sys/dev/mpr/mpr.c +++ b/sys/dev/mpr/mpr.c @@ -1871,7 +1871,7 @@ mpr_setup_sysctl(struct mpr_softc *sc) SYSCTL_ADD_STRING(sysctl_ctx, SYSCTL_CHILDREN(sysctl_tree), OID_AUTO, "msg_version", CTLFLAG_RD, sc->msg_version, - strlen(sc->msg_version), "message interface version"); + strlen(sc->msg_version), "message interface version (deprecated)"); SYSCTL_ADD_INT(sysctl_ctx, SYSCTL_CHILDREN(sysctl_tree), OID_AUTO, "io_cmds_active", CTLFLAG_RD, diff --git a/sys/dev/mpr/mpr_user.c b/sys/dev/mpr/mpr_user.c index d9dc3d2377a2..f2847ae36d66 100644 --- a/sys/dev/mpr/mpr_user.c +++ b/sys/dev/mpr/mpr_user.c @@ -852,7 +852,7 @@ mpr_user_pass_thru(struct mpr_softc *sc, mpr_pass_thru_t *data) rpl = (MPI2_DEFAULT_REPLY *)cm->cm_reply; sz = rpl->MsgLength * 4; - if (sz > data->ReplySize) { + if (bootverbose && sz > data->ReplySize) { mpr_printf(sc, "%s: user reply buffer (%d) " "smaller than returned buffer (%d)\n", __func__, data->ReplySize, sz); @@ -1077,7 +1077,7 @@ mpr_user_pass_thru(struct mpr_softc *sc, mpr_pass_thru_t *data) rpl = (MPI2_DEFAULT_REPLY *)cm->cm_reply; sz = rpl->MsgLength * 4; - if (sz > data->ReplySize) { + if (bootverbose && sz > data->ReplySize) { mpr_printf(sc, "%s: user reply buffer (%d) smaller " "than returned buffer (%d)\n", __func__, data->ReplySize, sz); diff --git a/sys/dev/mps/mps.c b/sys/dev/mps/mps.c index 43362b96b7b6..f358ab8a73a9 100644 --- a/sys/dev/mps/mps.c +++ b/sys/dev/mps/mps.c @@ -1719,7 +1719,7 @@ mps_setup_sysctl(struct mps_softc *sc) SYSCTL_ADD_STRING(sysctl_ctx, SYSCTL_CHILDREN(sysctl_tree), OID_AUTO, "msg_version", CTLFLAG_RD, sc->msg_version, - strlen(sc->msg_version), "message interface version"); + strlen(sc->msg_version), "message interface version (deprecated)"); SYSCTL_ADD_INT(sysctl_ctx, SYSCTL_CHILDREN(sysctl_tree), OID_AUTO, "io_cmds_active", CTLFLAG_RD, diff --git a/sys/dev/mps/mps_user.c b/sys/dev/mps/mps_user.c index cf2fdb2b2adb..3d1b478d81b1 100644 --- a/sys/dev/mps/mps_user.c +++ b/sys/dev/mps/mps_user.c @@ -851,7 +851,7 @@ mps_user_pass_thru(struct mps_softc *sc, mps_pass_thru_t *data) rpl = (MPI2_DEFAULT_REPLY *)cm->cm_reply; sz = rpl->MsgLength * 4; - if (sz > data->ReplySize) { + if (bootverbose && sz > data->ReplySize) { mps_printf(sc, "%s: user reply buffer (%d) " "smaller than returned buffer (%d)\n", __func__, data->ReplySize, sz); @@ -1005,7 +1005,7 @@ mps_user_pass_thru(struct mps_softc *sc, mps_pass_thru_t *data) rpl = (MPI2_DEFAULT_REPLY *)cm->cm_reply; sz = rpl->MsgLength * 4; - if (sz > data->ReplySize) { + if (bootverbose && sz > data->ReplySize) { mps_printf(sc, "%s: user reply buffer (%d) smaller " "than returned buffer (%d)\n", __func__, data->ReplySize, sz); diff --git a/usr.sbin/mpsutil/mps_cmd.c b/usr.sbin/mpsutil/mps_cmd.c index 448e4cea602f..2101bbba73b0 100644 --- a/usr.sbin/mpsutil/mps_cmd.c +++ b/usr.sbin/mpsutil/mps_cmd.c @@ -721,25 +721,39 @@ mps_pass_command(int fd, void *req, uint32_t req_len, void *reply, return (0); } +/* Return the length in bytes of the device's MPI2_IOC_FACTS reply */ +static size_t +mps_get_ioc_factslen(int fd) +{ + MPI2_IOC_FACTS_REQUEST req; + const size_t factslen = 4; + char factsbuf[4] = {0}; + MPI2_IOC_FACTS_REPLY *facts = (MPI2_IOC_FACTS_REPLY*)factsbuf; + int error; + + bzero(&req, sizeof(req)); + req.Function = MPI2_FUNCTION_IOC_FACTS; + error = mps_pass_command(fd, &req, sizeof(MPI2_IOC_FACTS_REQUEST), + factsbuf, factslen, NULL, 0, NULL, 0, 10); + + if (error) + return (0); + + /* The card's response is measured in dwords */ + return (facts->MsgLength * 4); +} + MPI2_IOC_FACTS_REPLY * mps_get_iocfacts(int fd) { MPI2_IOC_FACTS_REPLY *facts; MPI2_IOC_FACTS_REQUEST req; - char msgver[8], sysctlname[128]; - size_t len, factslen; + size_t factslen; int error; - snprintf(sysctlname, sizeof(sysctlname), "dev.%s.%d.msg_version", - is_mps ? "mps" : "mpr", mps_unit); - - factslen = sizeof(MPI2_IOC_FACTS_REPLY); - len = sizeof(msgver); - error = sysctlbyname(sysctlname, msgver, &len, NULL, 0); - if (error == 0) { - if (strncmp(msgver, "2.6", sizeof(msgver)) == 0) - factslen += 4; - } + factslen = mps_get_ioc_factslen(fd); + if (factslen == 0) + return (NULL); facts = malloc(factslen); if (facts == NULL) { @@ -747,7 +761,7 @@ mps_get_iocfacts(int fd) return (NULL); } - bzero(&req, factslen); + bzero(&req, sizeof(req)); req.Function = MPI2_FUNCTION_IOC_FACTS; #if 1