From nobody Sat Apr 15 22:32:45 2023 X-Original-To: dev-commits-src-main@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 4PzSkQ6VXsz45Cr0; Sat, 15 Apr 2023 22:32:46 +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 4PzSkQ0KN9z4K7S; Sat, 15 Apr 2023 22:32:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1681597966; 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=X1wQyM80S4IEs//Yek0TlhKcJBdI3zlYtWfocQR6Qdc=; b=MlLbSrz8371oVBBt2L1KumWocVvOXlaCApnNar++H0sVnIy+uLGb9e5vS9EmXkNFpCyrgO 9XXKxo7n0/92R3nhgxaZ/d1Sa+sJ13rhhfM0krRUHqYynTKBjZNwTDuiW8DU3fBv1a1Yl+ FhjRmFXW2V0CIE7WmtxCiN2kO9seqsTsy6yY+aRcVa7esTbuvj1RyEG242dTZ0Wn7DlFk4 +Uk0DIS2+GZ5Pp4ETTRNABEG9YZs3vIjmEcjcLVhJ+BRCi1CUFCmsBB/tYwph+3GMFg2lC sgX0XGVFEGXiQ7Wjsyf1Sjy5oCaXgfy8f42T7J5Z8WJK8a4cp5MvfXNPeCeh2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1681597966; 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=X1wQyM80S4IEs//Yek0TlhKcJBdI3zlYtWfocQR6Qdc=; b=gxnp63VET5fPkeoHnd5uUZXsB9GkHgUcEtOlJ1v2IkPRM5VQ+I6AlJXpUOBIcAosnxenOW 099YAiL/BL15X1I/0fD7mDmoOYwEV8kKk9DK5pzFO2X7zyEp1iajdYkf44LO+Js/Exr+vQ ZOXtI3vRE/E8wwUeYVZ4NqrW5AaZU7snvSTrkgMIVh5IVMiCVIOfHcYOMP9jlWbmtsSW9y lDAc46WT//2nhiHUfmuE2tGWVhyul7zWqSZJu/QhXSNzrBOu8yaYuf+jNuE8Y1sxr539kl GqVUwMpcD9ghWJr8tMIWbJHDZx1pSH7e0UkwLgM105GFllrYpDeHh514P02uuA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1681597966; a=rsa-sha256; cv=none; b=Tv2nJOaqyAAnHK/+UaLawv1fJ/Po+ozmUGarAK/sIFijCcHQxSTXG3nE9nZJy0Kkemd38I mBZdFIp8lX/1y86P/kDIxvzsh/Q5IkZTCjrWOLDkraeBV3pPd389SNU3V1HNyyBBZFvUbq NxOW19mZ9aoMaWz1j36LTdMFS3+P+l9r51SVni0tHIEZCz/NKLWOHGhS7ZxjmRHXsqmkZh tmNICZXJuoYIvnnCzMT5CPKUXu2VgK4UkukfsSFwF2e+hAwhPLW35g0zEALrfJKUVvFZmv bi9FzCmeLDCpVz6p8r3ceuGzERQn/a5xZp6DCfoJi8MF83jQAGKj5rtLaX9YOQ== 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 4PzSkP6S0TzNnY; Sat, 15 Apr 2023 22:32:45 +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 33FMWj9u002835; Sat, 15 Apr 2023 22:32:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 33FMWjsd002834; Sat, 15 Apr 2023 22:32:45 GMT (envelope-from git) Date: Sat, 15 Apr 2023 22:32:45 GMT Message-Id: <202304152232.33FMWjsd002834@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: fd02926a68c9 - main - cam: Properly mask out the status bits to get completion code List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: fd02926a68c9570f00f7e50d64c1d0673581fb35 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=fd02926a68c9570f00f7e50d64c1d0673581fb35 commit fd02926a68c9570f00f7e50d64c1d0673581fb35 Author: Warner Losh AuthorDate: 2023-04-14 14:32:20 +0000 Commit: Warner Losh CommitDate: 2023-04-15 22:32:41 +0000 cam: Properly mask out the status bits to get completion code ccb_h.status has two parts: the actual status and some addition bits to indicate additional information. It must be masked before comparing against completion codes. Add new inline function cam_ccb_success to simplify this to test whether or not the request succeeded. Most of the code already does this, but a few places don't (the rest likely should be converted to use cam_ccb_status and/or cam_ccb_success, but that's for another day). This caused at least one bug in recognizing devices behind a SATA port multiplexer, though some of these checks were fine with the special knowledge of the code paths involved. PR: 270459 Sponsored by: Netflix MFC After: 1 week (and maybe a EN requst) Reviewed by: ken, mav Differential Revision: https://reviews.freebsd.org/D39572 --- sys/cam/ata/ata_xpt.c | 4 ++-- sys/cam/cam_ccb.h | 6 ++++++ sys/cam/cam_xpt.c | 2 +- sys/cam/nvme/nvme_da.c | 3 +-- sys/cam/scsi/scsi_enc_ses.c | 4 ++-- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/sys/cam/ata/ata_xpt.c b/sys/cam/ata/ata_xpt.c index 2b299412b48e..643508c5d395 100644 --- a/sys/cam/ata/ata_xpt.c +++ b/sys/cam/ata/ata_xpt.c @@ -1003,7 +1003,7 @@ noerror: path->bus->sim->max_tagged_dev_openings != 0) { /* Check if the SIM does not want queued commands. */ xpt_path_inq(&cpi, path); - if (cpi.ccb_h.status == CAM_REQ_CMP && + if (cam_ccb_success((union ccb *)&cpi) && (cpi.hba_inquiry & PI_TAG_ABLE)) { /* Report SIM which tags are allowed. */ bzero(&cts, sizeof(cts)); @@ -1481,7 +1481,7 @@ ata_scan_bus(struct cam_periph *periph, union ccb *request_ccb) /* If there is PMP... */ if ((scan_info->cpi->hba_inquiry & PI_SATAPM) && (scan_info->counter == scan_info->cpi->max_target)) { - if (work_ccb->ccb_h.status == CAM_REQ_CMP) { + if (cam_ccb_success(work_ccb)) { /* everything else will be probed by it */ /* Free the current request path- we're done with it. */ xpt_free_path(work_ccb->ccb_h.path); diff --git a/sys/cam/cam_ccb.h b/sys/cam/cam_ccb.h index 1ae310d399b7..a6b12b6a3584 100644 --- a/sys/cam/cam_ccb.h +++ b/sys/cam/cam_ccb.h @@ -1516,6 +1516,12 @@ cam_ccb_status(union ccb *ccb) return ((cam_status)(ccb->ccb_h.status & CAM_STATUS_MASK)); } +static inline bool +cam_ccb_success(union ccb *ccb) +{ + return (cam_ccb_status(ccb) == CAM_REQ_CMP); +} + void cam_calc_geometry(struct ccb_calc_geometry *ccg, int extended); static __inline void diff --git a/sys/cam/cam_xpt.c b/sys/cam/cam_xpt.c index f3e9f2772e62..efedcaf5cf92 100644 --- a/sys/cam/cam_xpt.c +++ b/sys/cam/cam_xpt.c @@ -4018,7 +4018,7 @@ xpt_bus_register(struct cam_sim *sim, device_t parent, uint32_t bus) xpt_path_inq(&cpi, path); - if (cpi.ccb_h.status == CAM_REQ_CMP) { + if (cam_ccb_success((union ccb *)&cpi)) { struct xpt_xport **xpt; SET_FOREACH(xpt, cam_xpt_xport_set) { diff --git a/sys/cam/nvme/nvme_da.c b/sys/cam/nvme/nvme_da.c index 51689d0e4a23..94915ec6a726 100644 --- a/sys/cam/nvme/nvme_da.c +++ b/sys/cam/nvme/nvme_da.c @@ -441,8 +441,7 @@ ndaioctl(struct disk *dp, u_long cmd, void *data, int fflag, */ cam_periph_unlock(periph); cam_periph_unmapmem(ccb, &mapinfo); - error = (ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP ? - 0 : EIO; + error = cam_ccb_success(ccb) ? 0 : EIO; out: cam_periph_lock(periph); xpt_release_ccb(ccb); diff --git a/sys/cam/scsi/scsi_enc_ses.c b/sys/cam/scsi/scsi_enc_ses.c index 557038d9b9f6..58b0a5af74cd 100644 --- a/sys/cam/scsi/scsi_enc_ses.c +++ b/sys/cam/scsi/scsi_enc_ses.c @@ -986,7 +986,7 @@ ses_paths_iter(enc_softc_t *enc, enc_element_t *elm, xpt_setup_ccb(&cgd.ccb_h, path, CAM_PRIORITY_NORMAL); cgd.ccb_h.func_code = XPT_GDEV_TYPE; xpt_action((union ccb *)&cgd); - if (cgd.ccb_h.status == CAM_REQ_CMP) + if (cam_ccb_success((union ccb *)&cgd)) callback(enc, elm, path, callback_arg); xpt_free_path(path); @@ -1065,7 +1065,7 @@ ses_setphyspath_callback(enc_softc_t *enc, enc_element_t *elm, xpt_action((union ccb *)&cdai); if ((cdai.ccb_h.status & CAM_DEV_QFRZN) != 0) cam_release_devq(cdai.ccb_h.path, 0, 0, 0, FALSE); - if (cdai.ccb_h.status == CAM_REQ_CMP) + if (cam_ccb_success((union ccb *)&cdai)) args->num_set++; } xpt_path_unlock(path);