From nobody Fri Jan 28 00:25:50 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 8F25E197EC4B; Fri, 28 Jan 2022 00:25: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 4JlJCL3Sc9z59LM; Fri, 28 Jan 2022 00:25:50 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643329550; 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=zrHxdnymLP/hSXHCQXCoyU8T1wuQpRl3pnt6RniBk34=; b=JhoUESCjbKIDp8rsMA8dAJV/W15ZnaZ1XSJuAfX2F14THLhzQW4vRssG/KvvXC0tJEfZxR TObebZeWfH2kDFD960p1hgLbCXp9IKHqivtziHetRc65a12k27IHtQm0Xw1Y+YVPysyx4U utod2H5D4sexDkjJd76P8W5Y0clPSUmUxrVBnp3RPRCEnx0RHn1dsfC0Q9jzV5JaJGsceN sa+FOBY2BAXFZ1MNr869R79C6mtsNudd3FdykOa/LWszl7yegTq0qW0VuhhksevT5HUVvu EFzRtby3JgeaupGlOLl6fvH1NFdihXx6B90BvelIvW80JiI2Cw7hfld3ZGfmag== 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 56CA82044D; Fri, 28 Jan 2022 00:25:50 +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 20S0PoPj046119; Fri, 28 Jan 2022 00:25:50 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20S0Pogh046118; Fri, 28 Jan 2022 00:25:50 GMT (envelope-from git) Date: Fri, 28 Jan 2022 00:25:50 GMT Message-Id: <202201280025.20S0Pogh046118@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alexander Motin Subject: git: 6f840e49af37 - stable/13 - cam: Optimize write protection MODE SENSE in da(4). 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: mav X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 6f840e49af37ac3437957f30d6e45279316298dd Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643329550; 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=zrHxdnymLP/hSXHCQXCoyU8T1wuQpRl3pnt6RniBk34=; b=QXQmFcBRKAecN3xVzSsiglUGQLAzhRF0GOl0lTbWxwv/ASQ+sJhJhyoBjTZ92fIxSuRX9W bZ3Sydb+t/CHbsCGBCrMYF0ulNs3wTQmUZdZwG0QKKveyWkrFULWILH32jyH2P3OAWfi9J mB8lnw2d3K47nRsn6z182bxQLzHWfy05hsTL3TNsicfLRbiF1SbSjgAuo6CtGTHuTKK5n+ PwdGZ89UvPV56NpURHfVNfbtkNhlsUo4aUsDRIkwt2M7apW27kF2FB0Im4fNF4sj0IHpjV 8jyDJAW77KtgUmzoR1XOSRZODjqibtvgnDFyj3BQFqj+Ndfg0KnnlrTOTzFYDA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1643329550; a=rsa-sha256; cv=none; b=Nrv/o8J/InwuHTZeGdN3rIQ/kFNCKPzWyJV+yX088GjjlLaVuUIleHF/KoHMwXmh0ehdwS PzoXWwaczZtqcCelgUDCah1dsuw7KIhugNABwXNyfGJju1cA6r7JVbd7ar0/0Rskx7CweC delpbxMMpc5m56LlX1D54gdjkIFCM4Kv1wGp1SiBj/yerBVEA+RMfLVSkj/y7q8yULiPQC eqZjtGvUYUjdIhRteAj8NTpmI2wHChYOBmSfnVLvCdEeGcLIWzsrm4k43qA2PnYBJYk0LK hMnwYUYW+/3kc6iybCenL2jW2Vsrvd4arinBCPwS1ziUtj+HnplBmws0hEejgA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=6f840e49af37ac3437957f30d6e45279316298dd commit 6f840e49af37ac3437957f30d6e45279316298dd Author: Alexander Motin AuthorDate: 2022-01-14 22:48:19 +0000 Commit: Alexander Motin CommitDate: 2022-01-28 00:25:45 +0000 cam: Optimize write protection MODE SENSE in da(4). Before this change on every open da(4) driver read all mode pages to use only one bit. It was done so to not depend on the list of pages supported by the disk. But I've found that at least for SATL of LSI/ Broadcom HBAs with WD HDDs Power Condition mode page reading may take significant amount of time, much more than any other mode page, that visibly increased disk retaste time by GEOM. Address that by using data returned by the first MODE SENSE request to limit the following ones to only one (the first for now) mode page. With the change simultaneous retaste of 39 SATA disks takes about 2.5s instead of more than 4s before, and I no longer see "dareprobe" status on GEOM event thread. MFC after: 2 weeks Sponsored by: iXsystems, Inc. (cherry picked from commit a9a2cdaf3c193ee1b597d0eef51544636421d973) --- sys/cam/scsi/scsi_da.c | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/sys/cam/scsi/scsi_da.c b/sys/cam/scsi/scsi_da.c index a5f0198468f5..f710e82eda9b 100644 --- a/sys/cam/scsi/scsi_da.c +++ b/sys/cam/scsi/scsi_da.c @@ -345,6 +345,7 @@ struct da_softc { da_flags flags; da_quirks quirks; int minimum_cmd_size; + int mode_page; int error_inject; int trim_max_ranges; int delete_available; /* Delete methods possibly available */ @@ -2895,6 +2896,9 @@ daregister(struct cam_periph *periph, void *arg) else softc->minimum_cmd_size = 6; + /* On first PROBE_WP request all more pages, then adjust. */ + softc->mode_page = SMS_ALL_PAGES_PAGE; + /* Predict whether device may support READ CAPACITY(16). */ if (SID_ANSI_REV(&cgd->inq_data) >= SCSI_REV_SPC3 && (softc->quirks & DA_Q_NO_RC16) == 0) { @@ -3488,7 +3492,7 @@ out: void *mode_buf; int mode_buf_len; - if (da_disable_wp_detection) { + if (da_disable_wp_detection || softc->mode_page < 0) { if ((softc->flags & DA_FLAG_CAN_RC16) != 0) softc->state = DA_STATE_PROBE_RC16; else @@ -3512,7 +3516,7 @@ out: /*tag_action*/ MSG_SIMPLE_Q_TAG, /*dbd*/ FALSE, /*pc*/ SMS_PAGE_CTRL_CURRENT, - /*page*/ SMS_ALL_PAGES_PAGE, + /*page*/ softc->mode_page, /*param_buf*/ mode_buf, /*param_len*/ mode_buf_len, /*minimum_cmd_size*/ softc->minimum_cmd_size, @@ -4672,12 +4676,9 @@ dadone(struct cam_periph *periph, union ccb *done_ccb) static void dadone_probewp(struct cam_periph *periph, union ccb *done_ccb) { - struct scsi_mode_header_6 *mode_hdr6; - struct scsi_mode_header_10 *mode_hdr10; struct da_softc *softc; struct ccb_scsiio *csio; u_int32_t priority; - uint8_t dev_spec; CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probewp\n")); @@ -4695,18 +4696,31 @@ dadone_probewp(struct cam_periph *periph, union ccb *done_ccb) (unsigned long)csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK, periph, done_ccb)); - if (softc->minimum_cmd_size > 6) { - mode_hdr10 = (struct scsi_mode_header_10 *)csio->data_ptr; - dev_spec = mode_hdr10->dev_spec; - } else { - mode_hdr6 = (struct scsi_mode_header_6 *)csio->data_ptr; - dev_spec = mode_hdr6->dev_spec; - } if (cam_ccb_status(done_ccb) == CAM_REQ_CMP) { + int len, off; + uint8_t dev_spec; + + if (csio->cdb_len > 6) { + struct scsi_mode_header_10 *mh = + (struct scsi_mode_header_10 *)csio->data_ptr; + len = 2 + scsi_2btoul(mh->data_length); + off = sizeof(*mh) + scsi_2btoul(mh->blk_desc_len); + dev_spec = mh->dev_spec; + } else { + struct scsi_mode_header_6 *mh = + (struct scsi_mode_header_6 *)csio->data_ptr; + len = 1 + mh->data_length; + off = sizeof(*mh) + mh->blk_desc_len; + dev_spec = mh->dev_spec; + } if ((dev_spec & 0x80) != 0) softc->disk->d_flags |= DISKFLAG_WRITE_PROTECT; else softc->disk->d_flags &= ~DISKFLAG_WRITE_PROTECT; + + /* Next time request only the first of returned mode pages. */ + if (off < len && off < csio->dxfer_len - csio->resid) + softc->mode_page = csio->data_ptr[off] & SMPH_PC_MASK; } else { int error; @@ -4723,6 +4737,9 @@ dadone_probewp(struct cam_periph *periph, union ccb *done_ccb) /*timeout*/0, /*getcount_only*/0); } + + /* We don't depend on it, so don't try again. */ + softc->mode_page = -1; } }