Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4369976imm; Mon, 14 May 2018 06:40:07 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoaWUKtu7JWNsfoT4YGLZFP9fvxiQ9OSZqoPp7Lp1N2cx/yIiktmHqSUGeMPG1dECOaPIzy X-Received: by 2002:a65:4484:: with SMTP id l4-v6mr7817425pgq.103.1526305207244; Mon, 14 May 2018 06:40:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526305207; cv=none; d=google.com; s=arc-20160816; b=szGjWJDCkkgdOFhlwK3BlHbJYh/yFzPKA0hxNECVRuHe3Lhz8+stKKSUFOgBFOi8mm puXSrdnuTfW3yfNHjPhfR4PBMl0gxszngO4LcUTJKkWxyRvJRnliUO2RjUP3qcmefwek 6Y3YNb2v2Hf/q89JLnnWIQNYGE7IupdpVh70Ezw56OKI5V490VlMkH4b3Hi+d6+mZTS8 /3Z8kqRohRa8w6LvLeDTEcO34aRD/mekMoYfiShmtCUqiM1smHQM4zjL5JZtZ5cd8hb8 z1GhzWCwyS+2FS7lXDuLQtilAcV9TMt+LR6KDrCkNuI8lNwdM2KjKd1frko9OgYYgj3s KePQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:subject:cc:to :from:date:arc-authentication-results; bh=TW6DewibqpFNCNOY3ExLATjGCvQM1DgprXzinXCAy/g=; b=m7D56RUYGTSQmHxNIquEmUwlv41+ATqtE/0ZlKYQcOWJrOOBiizv2pczf+MFAg+CK8 KMpnOay6RxQwtOi51Tsggfg2Aq7p0iwx7EXkaqnZi9MSrtlFJb9G2KJVDQLcO4kAb095 bnBF5KSadZ/f0hErRrOUV1e60NuujLP1E7SjCBX399uvlN0zlgx6hYC7zjuKPoV1s6iQ WrUOvzO/irDd1dbXByDB9THkneNW3UP7YKyMnlKyH0kJ/Z/17HdqTnrBP9GOIntZix5f KYvOy0hHNVA6xxkTDxbf4x7jqAQZkMVWf8uaiqvPN+QsF+VK7s/tuxOb3b5cFw08yRbs 5OSA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t6-v6si9977955pfg.114.2018.05.14.06.39.53; Mon, 14 May 2018 06:40:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932294AbeENNhX (ORCPT + 99 others); Mon, 14 May 2018 09:37:23 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:55510 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753027AbeENNhW (ORCPT ); Mon, 14 May 2018 09:37:22 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w4EDYNS5003392 for ; Mon, 14 May 2018 09:37:21 -0400 Received: from e13.ny.us.ibm.com (e13.ny.us.ibm.com [129.33.205.203]) by mx0a-001b2d01.pphosted.com with ESMTP id 2hy98memy7-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 14 May 2018 09:37:21 -0400 Received: from localhost by e13.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 14 May 2018 09:37:20 -0400 Received: from b01cxnp22033.gho.pok.ibm.com (9.57.198.23) by e13.ny.us.ibm.com (146.89.104.200) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 14 May 2018 09:37:18 -0400 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w4EDbHBj46333952; Mon, 14 May 2018 13:37:17 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8E3E1B2056; Mon, 14 May 2018 10:39:15 -0400 (EDT) Received: from paulmck-ThinkPad-W541 (unknown [9.85.188.179]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP id 5A9BCB204D; Mon, 14 May 2018 10:39:15 -0400 (EDT) Received: by paulmck-ThinkPad-W541 (Postfix, from userid 1000) id 20C2E16C3120; Mon, 14 May 2018 06:38:49 -0700 (PDT) Date: Mon, 14 May 2018 06:38:49 -0700 From: "Paul E. McKenney" To: Johannes Thumshirn Cc: Christoph Hellwig , Keith Busch , Sagi Grimberg , Linux Kernel Mailinglist , Linux NVMe Mailinglist , Hannes Reinecke , Christoph Hellwig Subject: Re: [PATCH] nvme: fix lockdep warning in nvme_mpath_clear_current_path Reply-To: paulmck@linux.vnet.ibm.com References: <20180514121312.13624-1-jthumshirn@suse.de> <20180514124230.GA654@infradead.org> <20180514125725.uobtf2nf4corisea@linux-x5ow.site> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180514125725.uobtf2nf4corisea@linux-x5ow.site> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 x-cbid: 18051413-0008-0000-0000-000003073C45 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009024; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000260; SDB=6.01032185; UDB=6.00527665; IPR=6.00811316; MB=3.00021105; MTD=3.00000008; XFM=3.00000015; UTC=2018-05-14 13:37:20 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18051413-0009-0000-0000-0000393EC80B Message-Id: <20180514133849.GV26088@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-05-14_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1805140140 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 14, 2018 at 02:57:25PM +0200, Johannes Thumshirn wrote: > On Mon, May 14, 2018 at 05:42:30AM -0700, Christoph Hellwig wrote: > > > extern unsigned int nvme_io_timeout; > > > #define NVME_IO_TIMEOUT (nvme_io_timeout * HZ) > > > @@ -454,7 +455,9 @@ static inline void nvme_mpath_clear_current_path(struct nvme_ns *ns) > > > { > > > struct nvme_ns_head *head = ns->head; > > > > > > - if (head && ns == srcu_dereference(head->current_path, &head->srcu)) > > > + if (head && > > > + ns == rcu_dereference_protected(head->current_path, > > > + lockdep_is_held(&ns->ctrl->subsys->lock))) > > > rcu_assign_pointer(head->current_path, NULL); > > > } > > > struct nvme_ns *nvme_find_path(struct nvme_ns_head *head); > > > > We don't really dereference it at all in fact, but just check the > > pointers for equality. I wonder if there is a better way to do this, > > as my ANA patches add a caller without the lock (and withou SRU > > protection either now that I think of it) - for a pure pointer compare > > we really should not need any sort of protection. > > Uff maybe, but are you sure a comparison of two pointer is always > atomic (on all architectures)? > > Paul, can you shed some light on us mere mortal, whether the above > rcu_dereference_protected() is needed or if a simple ns == > head->current_path is sufficient. One approach is the following: static inline void nvme_mpath_clear_current_path(struct nvme_ns *ns) { struct nvme_ns_head *head = ns->head; if (head && ns == rcu_access_pointer(head->current_path)) rcu_assign_pointer(head->current_path, NULL); } Without the rcu_access_pointer(), sparse (and thus the 0-day test robot) will complain that you are accessing an RCU-protected pointer without using RCU. However, rcu_access_pointer() won't ever give any lockdep splats about there being no RCU read-side critical section. You might still want rcu_dereference_protected() because it will yell at you if the lock is not held. Yes, the comparison will still be valid without the lock (at least at the exact moment when the load occurred), but the rcu_assign_pointer() might be a bit problematic if that lock is not held, right? But it is your guys' code, so I must defer to you for the intent. Thanx, Paul