From patchwork Fri Aug 31 20:00:39 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dongsu Park X-Patchwork-Id: 1394351 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id D081ADFFCF for ; Fri, 31 Aug 2012 20:01:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754939Ab2HaUBM (ORCPT ); Fri, 31 Aug 2012 16:01:12 -0400 Received: from mail-bk0-f46.google.com ([209.85.214.46]:41393 "EHLO mail-bk0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754918Ab2HaUBH (ORCPT ); Fri, 31 Aug 2012 16:01:07 -0400 Received: by mail-bk0-f46.google.com with SMTP id j10so1457195bkw.19 for ; Fri, 31 Aug 2012 13:01:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=d1punRgQp48QlEkSBSpvwu2hKwGAkMANSwsoscSjTj4=; b=lfPyYvJcElItaRmjsh/26Sga+fVkSlo7MSu2VdxZegKHBhH0a5EpuEfR+MIFM1hAOz FlBHZtcJ0D0MeaqMaajnt+jxfLdR2gcDT6rwO45+RH4hHjcP8tDmHy1DepepVrXV8Pzb DlCYqztcmu0hcSUzaIIbNUE/6II1iRM+6H2p5ncn1EAf3z/+CyvnPr12ff5qILJfmvPf OLYgJZA2vrQWHP5ecAIqqtdJ6K2WLO2QMAMqZbiAW63aA7Y3p5FZydbZ1iAmk1lMaKMq hMF/rS5lAXqiwldcmLlNiJGoCXE5Z6C9yc9vkWXI8MBA+vbgneMsx1kwJWWQc54zs4di 8w/Q== Received: by 10.204.130.10 with SMTP id q10mr4656698bks.90.1346443266704; Fri, 31 Aug 2012 13:01:06 -0700 (PDT) Received: from dneo.profitbricks.localdomain (dslb-188-103-218-031.pools.arcor-ip.net. [188.103.218.31]) by mx.google.com with ESMTPS id 25sm4194314bkx.9.2012.08.31.13.01.05 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 31 Aug 2012 13:01:06 -0700 (PDT) From: dongsu.park@profitbricks.com To: bvanassche@acm.org Cc: dillowda@ornl.gov, roland@kernel.org, sean.hefty@intel.com, hal.rosenstock@gmail.com, JBottomley@parallels.com, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, Dongsu Park Subject: [PATCH 3/5] ib_srp: hold a mutex when adding a new target port Date: Fri, 31 Aug 2012 22:00:39 +0200 Message-Id: <1346443241-24844-4-git-send-email-dongsu.park@profitbricks.com> X-Mailer: git-send-email 1.7.11.1 In-Reply-To: <1346443241-24844-1-git-send-email-dongsu.park@profitbricks.com> References: <1346443241-24844-1-git-send-email-dongsu.park@profitbricks.com> X-Gm-Message-State: ALoCoQlUkQoLXMby1L+iHEf8l1NiE/cPLZI9QYOmWZ2put8b6POVinnjhoe4cfWJmHf8gtZx1X10 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Dongsu Park Unter circumstances, srp_rport_add() can make conflicts with srp_rport_delete(), dumping the call trace written below. That does not always occur. But its possible reason is adding sysfs entries for the SRP target too fast, even before the deletion hasn't finished yet. The possible solution is therefore holding a scan_mutex when calling device_add(). Example call trace: ------------[ cut here ]------------ WARNING: at block/genhd.c:1466 __disk_unblock_events+0x10f/0x120() Pid: 17238, comm: scsi_id Not tainted 3.2.8-pserver #1 Call Trace: [] ? warn_slowpath_common+0x7b/0xc0 [] ? __disk_unblock_events+0x10f/0x120 [] ? __blkdev_get+0x190/0x410 [] ? blkdev_get+0x310/0x310 [] ? blkdev_get+0x4b/0x310 [] ? blkdev_get+0x310/0x310 [] ? __dentry_open+0x263/0x370 [] ? path_get+0x1e/0x30 [] ? do_last+0x3e0/0x800 [] ? path_openat+0xdb/0x400 [] ? do_filp_open+0x4d/0xc0 [] ? alloc_fd+0x43/0x130 [] ? do_sys_open+0x105/0x1e0 [] ? system_call_fastpath+0x16/0x1b ---[ end trace 4edc2747f936431c ]--- ------------[ cut here ]------------ WARNING: at fs/sysfs/inode.c:323 sysfs_hash_and_remove+0xa4/0xb0() Hardware name: H8DGU sysfs: can not remove 'bsg', no directory Pid: 15816, comm: kworker/4:8 Tainted: G W 3.2.8 #1 Call Trace: [] ? warn_slowpath_common+0x7b/0xc0 [] ? warn_slowpath_fmt+0x45/0x50 [] ? sysfs_hash_and_remove+0xa4/0xb0 [] ? bsg_unregister_queue+0x3f/0x80 [] ? __scsi_remove_device+0x99/0xc0 [scsi_mod] [] ? scsi_forget_host+0x64/0x70 [scsi_mod] [] ? scsi_remove_host+0x61/0x100 [scsi_mod] [] ? srp_remove_work+0x137/0x1c0 [ib_srp] [] ? srp_free_req_data+0xd0/0xd0 [ib_srp] [] ? process_one_work+0x113/0x470 [] ? manage_workers+0x180/0x200 [] ? worker_thread+0x163/0x3e0 [] ? manage_workers+0x200/0x200 [] ? manage_workers+0x200/0x200 [] ? kthread+0x96/0xa0 [] ? kernel_thread_helper+0x4/0x10 [] ? kthread_worker_fn+0x180/0x180 [] ? gs_change+0x13/0x13 ---[ end trace 4edc2747f936431d ]--- ------------[ cut here ]------------ Signed-off-by: Dongsu Park --- drivers/scsi/scsi_transport_srp.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c index 7f17686..af3cb56 100644 --- a/drivers/scsi/scsi_transport_srp.c +++ b/drivers/scsi/scsi_transport_srp.c @@ -407,12 +407,15 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost, transport_setup_device(&rport->dev); + mutex_lock(&shost->scan_mutex); ret = device_add(&rport->dev); if (ret) { + mutex_unlock(&shost->scan_mutex); transport_destroy_device(&rport->dev); put_device(&rport->dev); return ERR_PTR(ret); } + mutex_unlock(&shost->scan_mutex); if (shost->active_mode & MODE_TARGET && ids->roles == SRP_RPORT_ROLE_INITIATOR) {