From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753682AbdF2UOu (ORCPT ); Thu, 29 Jun 2017 16:14:50 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:34139 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753646AbdF2UOr (ORCPT ); Thu, 29 Jun 2017 16:14:47 -0400 Date: Thu, 29 Jun 2017 13:14:43 -0700 From: "Paul E. McKenney" To: Tejun Heo Cc: linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: spin_unlock_wait() in ata_scsi_cmd_error_handler()? Reply-To: paulmck@linux.vnet.ibm.com References: <20170629181057.GA5228@linux.vnet.ibm.com> <20170629195322.GB9745@htj.duckdns.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170629195322.GB9745@htj.duckdns.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 x-cbid: 17062920-0044-0000-0000-00000360A9D5 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007294; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000214; SDB=6.00880532; UDB=6.00438968; IPR=6.00660684; BA=6.00005447; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00016012; XFM=3.00000015; UTC=2017-06-29 20:14:45 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17062920-0045-0000-0000-0000078EA9DA Message-Id: <20170629201443.GD2393@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-06-29_14:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1706290326 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 29, 2017 at 03:53:22PM -0400, Tejun Heo wrote: > Hello, Paul. > > On Thu, Jun 29, 2017 at 11:10:57AM -0700, Paul E. McKenney wrote: > > If this code fragment doesn't deadlock, then CPU 0's spin_unlock_wait() > > must have executed before CPU 1's spin_lock(). However, even on x86, > > CPU 0's prior writes can be reordered with its subsequent reads, which > > means that r1 == 0 is possible, which means that the above condition > > could hold, even on x86. > > I see. Ah, that's a mind bender. It has indeed been providing at least its share of entertainment over the past little while. ;-) > > One of the uses of spin_unlock_wait() is in ata_scsi_cmd_error_handler() > > in the file drivers/ata/libata-eh.c. Your commit ad9e27624479b > > ("libata-eh-fw: update ata_scsi_error() for new EH") last touched it, > > though it predates that commit. > > > > My question to you is whether the code in ata_scsi_cmd_error_handler() > > needs release semantics. If it does, my recommendation is to replace > > the spin_unlock_wait(ap->lock) with this (adding the needed curly braces, > > of course): > > > > spin_lock(ap->lock); > > spin_unlock(ap->lock); > > > > If the code only needs acquire semantics, no change required. > > > > If your code requires release semantics, and there is some reason why > > my suggested replacement above is a bad idea, please let me know! > > That part of the code should be dead now. I don't think we no longer > have any driver which doesn't have error handler set. I should rip > out that if/else. Also, ACQUIRE semantics should be enough there. > Nothing changes from the EH side there. It looks like we actually might get rid of spin_unlock_wait entirely. But how about if I just pull the spin_lock_irqsave() before the "if" and the spin_lock_irqrestore() after the "if"? Same effect, only difference is that the "if" and the "ap->eh_tries = ATA_EH_MAX_TRIES" end up under the lock, and I bet that you won't be able to measure the difference. (Please see below.) I will do this because I just now happened to be editing that file on my "eradicate spin_unlock_wait()" quest, but can easily rework the patch as desired. If you want something different, just let me know! Thanx, Paul ------------------------------------------------------------------------ commit 39a15ef3b324b08606953d519e9bc538318f3c15 Author: Paul E. McKenney Date: Thu Jun 29 13:10:47 2017 -0700 drivers/ata: Replace spin_unlock_wait() with lock/unlock pair There is no agreed-upon definition of spin_unlock_wait()'s semantics, and it appears that all callers could do just as well with a lock/unlock pair. This commit therefore eliminates the spin_unlock_wait() call and associated else-clause and hoists the then-clause's lock and unlock out of the "if" statement. This should be safe from a performance perspective because according to Tejun there should be few if any drivers that don't set their own error handler. Signed-off-by: Paul E. McKenney Cc: Tejun Heo Cc: Cc: Will Deacon Cc: Peter Zijlstra Cc: Alan Stern Cc: Andrea Parri Cc: Linus Torvalds diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c index ef68232b5222..779f6f18c1f4 100644 --- a/drivers/ata/libata-eh.c +++ b/drivers/ata/libata-eh.c @@ -645,12 +645,11 @@ void ata_scsi_cmd_error_handler(struct Scsi_Host *host, struct ata_port *ap, * completions are honored. A scmd is determined to have * timed out iff its associated qc is active and not failed. */ + spin_lock_irqsave(ap->lock, flags); if (ap->ops->error_handler) { struct scsi_cmnd *scmd, *tmp; int nr_timedout = 0; - spin_lock_irqsave(ap->lock, flags); - /* This must occur under the ap->lock as we don't want a polled recovery to race the real interrupt handler @@ -700,12 +699,11 @@ void ata_scsi_cmd_error_handler(struct Scsi_Host *host, struct ata_port *ap, if (nr_timedout) __ata_port_freeze(ap); - spin_unlock_irqrestore(ap->lock, flags); /* initialize eh_tries */ ap->eh_tries = ATA_EH_MAX_TRIES; - } else - spin_unlock_wait(ap->lock); + } + spin_unlock_irqrestore(ap->lock, flags); } EXPORT_SYMBOL(ata_scsi_cmd_error_handler);