From owner-freebsd-scsi@FreeBSD.ORG Wed Dec 12 02:17:29 2007 Return-Path: Delivered-To: freebsd-scsi@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3C7EB16A417 for ; Wed, 12 Dec 2007 02:17:29 +0000 (UTC) (envelope-from simokawa@freebsd.org) Received: from mail4.ecc.u-tokyo.ac.jp (mail3.ecc.u-tokyo.ac.jp [133.11.205.99]) by mx1.freebsd.org (Postfix) with ESMTP id C165A13C46B for ; Wed, 12 Dec 2007 02:17:28 +0000 (UTC) (envelope-from simokawa@freebsd.org) Received: from mail0.ecc.u-tokyo.ac.jp (mail0.ecc.u-tokyo.ac.jp [133.11.50.199]) by mail4.ecc.u-tokyo.ac.jp (Postfix) with ESMTP id 0904B5B1669 for ; Wed, 12 Dec 2007 10:32:20 +0900 (JST) Received: from spam001.ecc.u-tokyo.ac.jp (spam001.ecc.u-tokyo.ac.jp [133.11.50.194]) by mail0.ecc.u-tokyo.ac.jp (Postfix) with ESMTP id 611491C58003 for ; Wed, 12 Dec 2007 10:32:18 +0900 (JST) Received: from maru5.nunu.org (157.82.169.72 [157.82.169.72]) by spam001.ecc.u-tokyo.ac.jp (SpamBlock.pst 3.4.102) with ESMTP id <86sl28snpe.wl%simokawa@FreeBSD.ORG> for ; Wed, 12 Dec 2007 10:31:41 +0900 Date: Wed, 12 Dec 2007 10:31:41 +0900 Message-ID: <86sl28snpe.wl%simokawa@FreeBSD.ORG> From: Hidetoshi Shimokawa To: Sean Bruno In-Reply-To: <1197420795.2738.6.camel@iago.office.miralink.com> References: <1197420795.2738.6.camel@iago.office.miralink.com> User-Agent: Wanderlust/2.15.2 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.8 (=?ISO-8859-4?Q?Shij=F2?=) APEL/10.6 Emacs/22.0.50 (i386-unknown-freebsd5.4) MULE/5.0 (SAKAKI) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII X-IP: 157.82.169.72 X-FROM-DOMAIN: freebsd.org X-FROM-EMAIL: simokawa@freebsd.org X-SPAM-MARK: by Spam Filter Rule Cc: freebsd-scsi@freebsd.org, freebsd-firewire@freebsd.org, nate@root.org Subject: Re: scsi_target witness lock error X-BeenThere: freebsd-scsi@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SCSI subsystem List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 Dec 2007 02:17:29 -0000 Hi Sean, At Tue, 11 Dec 2007 16:53:15 -0800, Sean Bruno wrote: > > While I was debugging some random stuff with the firewire target, I > noted the following witness lock: > > http://www.consultcsg.com/scsitarget_witness.txt > > It looks like there is some kind of conflict between the locks in > sys/cam/scsi/scsi_target.c and the kern environment locks? I'm fairly > certain that this is an easy fix, but I just don't see how to work > around it. > > Sean This a patch I sent Scott several months ago. It may help you. (this is for -current at that time) /\ Hidetoshi Shimokawa \/ simokawa@FreeBSD.ORG Subject: scsi_target and WITNESS From: Hidetoshi Shimokawa Date: Fri, 01 Jun 2007 11:57:50 +0900 Message-ID: <86vee8pej5.wl%simokawa@FreeBSD.ORG> Hi Scott, scsi_target seems to have several problems with WITNESS and MPSAFE sim. I applied the following patch to workaround recurse/sleep/pagefault problems. I think you should have a better fix. ============================================= (cd /usr/src && patch -p6) < diff_to_current ============================================= --- //depot/vendor/freebsd/src/sys/cam/scsi/scsi_target.c 2007/04/15 08:53:22 +++ //depot/user/simokawa/firewire_lock/sys/cam/scsi/scsi_target.c 2007/05/21 14:31:55 @@ -372,10 +372,14 @@ int retval; softc = (struct targ_softc *)kn->kn_hook; +#if 0 cam_periph_lock(softc->periph); +#endif retval = !TAILQ_EMPTY(&softc->user_ccb_queue) || !TAILQ_EMPTY(&softc->abort_queue); +#if 0 cam_periph_unlock(softc->periph); +#endif return (retval); } @@ -585,12 +589,12 @@ cam_periph_unlock(softc->periph); break; default: - cam_periph_lock(softc->periph); if ((func_code & XPT_FC_QUEUED) != 0) { CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH, ("Sending queued ccb %#x (%p)\n", func_code, user_ccb)); descr = targgetdescr(softc); + cam_periph_lock(softc->periph); descr->user_ccb = user_ccb; descr->priority = priority; descr->func_code = func_code; @@ -601,6 +605,7 @@ CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH, ("Sending inline ccb %#x (%p)\n", func_code, user_ccb)); + cam_periph_lock(softc->periph); ccb = targgetccb(softc, func_code, priority); descr = (struct targ_cmd_descr *) ccb->ccb_h.targ_descr; @@ -762,7 +767,9 @@ && ((ccb_h->flags & CAM_DIR_MASK) != CAM_DIR_NONE)) || (ccb_h->func_code == XPT_DEV_MATCH))) { + cam_periph_unlock(softc->periph); error = cam_periph_mapmem(ccb, mapinfo); + cam_periph_lock(softc->periph); /* * cam_periph_mapmem returned an error, we can't continue. @@ -966,13 +973,16 @@ int ccb_len; ccb_len = targccblen(type); + /* XXX */ + cam_periph_unlock(softc->periph); MALLOC(ccb, union ccb *, ccb_len, M_TARG, M_WAITOK); + ccb->ccb_h.targ_descr = targgetdescr(softc); + cam_periph_lock(softc->periph); CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH, ("getccb %p\n", ccb)); xpt_setup_ccb(&ccb->ccb_h, softc->path, priority); ccb->ccb_h.func_code = type; ccb->ccb_h.cbfcnp = targdone; - ccb->ccb_h.targ_descr = targgetdescr(softc); return (ccb); } @@ -1099,6 +1109,7 @@ static void notify_user(struct targ_softc *softc) { + mtx_assert(softc->periph->sim->mtx, MA_OWNED); /* * Notify users sleeping via poll(), kqueue(), and * blocking read().