From owner-svn-src-stable-12@freebsd.org Fri Aug 28 10:01:04 2020 Return-Path: Delivered-To: svn-src-stable-12@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 01A543D3A04; Fri, 28 Aug 2020 10:01:04 +0000 (UTC) (envelope-from avg@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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BdFV767rfz4JKL; Fri, 28 Aug 2020 10:01:03 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id B6329131A7; Fri, 28 Aug 2020 10:01:03 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 07SA13kO011190; Fri, 28 Aug 2020 10:01:03 GMT (envelope-from avg@FreeBSD.org) Received: (from avg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 07SA13gG011188; Fri, 28 Aug 2020 10:01:03 GMT (envelope-from avg@FreeBSD.org) Message-Id: <202008281001.07SA13gG011188@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: avg set sender to avg@FreeBSD.org using -f From: Andriy Gapon Date: Fri, 28 Aug 2020 10:01:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r364907 - stable/12/sys/cam X-SVN-Group: stable-12 X-SVN-Commit-Author: avg X-SVN-Commit-Paths: stable/12/sys/cam X-SVN-Commit-Revision: 364907 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Aug 2020 10:01:04 -0000 Author: avg Date: Fri Aug 28 10:01:03 2020 New Revision: 364907 URL: https://svnweb.freebsd.org/changeset/base/364907 Log: MFC r358864 by imp: Eliminate xpt_copy_path. Modified: stable/12/sys/cam/cam_xpt.c stable/12/sys/cam/cam_xpt.h Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/cam/cam_xpt.c ============================================================================== --- stable/12/sys/cam/cam_xpt.c Fri Aug 28 08:54:27 2020 (r364906) +++ stable/12/sys/cam/cam_xpt.c Fri Aug 28 10:01:03 2020 (r364907) @@ -804,7 +804,8 @@ static void xpt_scanner_thread(void *dummy) { union ccb *ccb; - struct cam_path path; + struct mtx *mtx; + struct cam_ed *device; xpt_lock_buses(); for (;;) { @@ -816,15 +817,22 @@ xpt_scanner_thread(void *dummy) xpt_unlock_buses(); /* - * Since lock can be dropped inside and path freed - * by completion callback even before return here, - * take our own path copy for reference. + * We need to lock the device's mutex which we use as + * the path mutex. We can't do it directly because the + * cam_path in the ccb may wind up going away because + * the path lock may be dropped and the path retired in + * the completion callback. We do this directly to keep + * the reference counts in cam_path sane. We also have + * to copy the device pointer because ccb_h.path may + * be freed in the callback. */ - xpt_copy_path(&path, ccb->ccb_h.path); - xpt_path_lock(&path); + mtx = xpt_path_mtx(ccb->ccb_h.path); + device = ccb->ccb_h.path->device; + xpt_acquire_device(device); + mtx_lock(mtx); xpt_action(ccb); - xpt_path_unlock(&path); - xpt_release_path(&path); + mtx_unlock(mtx); + xpt_release_device(device); xpt_lock_buses(); } @@ -3701,15 +3709,6 @@ xpt_clone_path(struct cam_path **new_path_ptr, struct new_path = (struct cam_path *)malloc(sizeof(*path), M_CAMPATH, M_NOWAIT); if (new_path == NULL) return(CAM_RESRC_UNAVAIL); - xpt_copy_path(new_path, path); - *new_path_ptr = new_path; - return (CAM_REQ_CMP); -} - -void -xpt_copy_path(struct cam_path *new_path, struct cam_path *path) -{ - *new_path = *path; if (path->bus != NULL) xpt_acquire_bus(path->bus); @@ -3717,6 +3716,8 @@ xpt_copy_path(struct cam_path *new_path, struct cam_pa xpt_acquire_target(path->target); if (path->device != NULL) xpt_acquire_device(path->device); + *new_path_ptr = new_path; + return (CAM_REQ_CMP); } void Modified: stable/12/sys/cam/cam_xpt.h ============================================================================== --- stable/12/sys/cam/cam_xpt.h Fri Aug 28 08:54:27 2020 (r364906) +++ stable/12/sys/cam/cam_xpt.h Fri Aug 28 10:01:03 2020 (r364907) @@ -140,8 +140,6 @@ cam_status xpt_compile_path(struct cam_path *new_path lun_id_t lun_id); cam_status xpt_clone_path(struct cam_path **new_path, struct cam_path *path); -void xpt_copy_path(struct cam_path *new_path, - struct cam_path *path); void xpt_release_path(struct cam_path *path);