From patchwork Thu Oct 9 03:34:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nicholas A. Bellinger" X-Patchwork-Id: 5056321 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 37CF7C11AB for ; Thu, 9 Oct 2014 04:04:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1A39D2015A for ; Thu, 9 Oct 2014 04:04:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8A93D20158 for ; Thu, 9 Oct 2014 04:04:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750800AbaJIEEI (ORCPT ); Thu, 9 Oct 2014 00:04:08 -0400 Received: from mail-oi0-f46.google.com ([209.85.218.46]:58364 "EHLO mail-oi0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750727AbaJIEEG (ORCPT ); Thu, 9 Oct 2014 00:04:06 -0400 Received: by mail-oi0-f46.google.com with SMTP id h136so970913oig.33 for ; Wed, 08 Oct 2014 21:04:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=yMa/YMpwVw3pLERZ0TMfuK+jabDLYv7gcg6nmUbRmvA=; b=PmamBKeL5Kqrk3nPkOniAbJuj1C92HPqPkLVXtbV2k1KM4xUQQoiDS4B5bx0qKNpwv tX/Ikde0Q6RaOLu8Xk9xfgDNSv4UVtFL69z/w5efnwavGGd/8teqC3/1HuGfLTfietfT Mf9jS7rKU/s1eje7YNs2b+3MMy8mVvDeNmQkVo5bk9EuJYXRGKe+zX4xCMqUFVXEFbHp WRgnmvsdMlYSRgZtS6y5xo9sPVciQcdkMcvyctfSHRWk43I9GLDXj6Un+h11ezeOW0av GFvguaZnzT4k7yP3CZEnwMB39UKdc+cW1Jb04jSaxgBSRMLD+V0loin6atvAwmZyCC7d 1FEg== X-Gm-Message-State: ALoCoQkDe1Z9jXuuCZxDBua82rRvnPJf0zrUJkcM4kaqU5vrXSjvYHpo6sMAl3X6lWKyHq4msSD8 X-Received: by 10.182.200.166 with SMTP id jt6mr17764812obc.1.1412827444704; Wed, 08 Oct 2014 21:04:04 -0700 (PDT) Received: from localhost.localdomain (mail.linux-iscsi.org. [67.23.28.174]) by mx.google.com with ESMTPSA id gv9sm2057379obc.17.2014.10.08.21.04.04 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 08 Oct 2014 21:04:04 -0700 (PDT) From: "Nicholas A. Bellinger" To: target-devel Cc: linux-scsi , kvm-devel , Nicholas Bellinger , "Michael S. Tsirkin" , Paolo Bonzini , Stefan Hajnoczi Subject: [PATCH] vhost-scsi: Take configfs group dependency during VHOST_SCSI_SET_ENDPOINT Date: Thu, 9 Oct 2014 03:34:55 +0000 Message-Id: <1412825695-15134-1-git-send-email-nab@daterainc.com> X-Mailer: git-send-email 1.7.2.5 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Nicholas Bellinger This patch addresses a bug where individual vhost-scsi configfs endpoint groups can be removed from below while active exports to QEMU userspace still exist, resulting in an OOPs. It adds a configfs_depend_item() in vhost_scsi_set_endpoint() to obtain an explicit dependency on se_tpg->tpg_group in order to prevent individual vhost-scsi WWPN endpoints from being released via normal configfs methods while an QEMU ioctl reference still exists. Also, add matching configfs_undepend_item() in vhost_scsi_clear_endpoint() to release the dependency, once QEMU's reference to the individual group at /sys/kernel/config/target/vhost/$WWPN/$TPGT is released. Cc: Michael S. Tsirkin Cc: Paolo Bonzini Cc: Stefan Hajnoczi Cc: # 3.6+ Signed-off-by: Nicholas Bellinger --- drivers/vhost/scsi.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c index 69906ca..bc1b620 100644 --- a/drivers/vhost/scsi.c +++ b/drivers/vhost/scsi.c @@ -1312,6 +1312,7 @@ static int vhost_scsi_set_endpoint(struct vhost_scsi *vs, struct vhost_scsi_target *t) { + struct se_portal_group *se_tpg; struct tcm_vhost_tport *tv_tport; struct tcm_vhost_tpg *tpg; struct tcm_vhost_tpg **vs_tpg; @@ -1359,6 +1360,19 @@ vhost_scsi_set_endpoint(struct vhost_scsi *vs, ret = -EEXIST; goto out; } + /* + * In order to ensure individual vhost-scsi configfs + * groups cannot be removed while in use by vhost ioctl, + * go ahead and take an explicit se_tpg->tpg_group.cg_item + * dependency now. + */ + se_tpg = &tpg->se_tpg; + ret = configfs_depend_item(se_tpg->se_tpg_tfo->tf_subsys, + &se_tpg->tpg_group.cg_item); + if (ret) { + pr_warn("configfs_depend_item() failed: %d\n", ret); + goto out; + } tpg->tv_tpg_vhost_count++; tpg->vhost_scsi = vs; vs_tpg[tpg->tport_tpgt] = tpg; @@ -1401,6 +1415,7 @@ static int vhost_scsi_clear_endpoint(struct vhost_scsi *vs, struct vhost_scsi_target *t) { + struct se_portal_group *se_tpg; struct tcm_vhost_tport *tv_tport; struct tcm_vhost_tpg *tpg; struct vhost_virtqueue *vq; @@ -1449,6 +1464,13 @@ vhost_scsi_clear_endpoint(struct vhost_scsi *vs, vs->vs_tpg[target] = NULL; match = true; mutex_unlock(&tpg->tv_tpg_mutex); + /* + * Release se_tpg->tpg_group.cg_item configfs dependency now + * to allow vhost-scsi WWPN se_tpg->tpg_group shutdown to occur. + */ + se_tpg = &tpg->se_tpg; + configfs_undepend_item(se_tpg->se_tpg_tfo->tf_subsys, + &se_tpg->tpg_group.cg_item); } if (match) { for (i = 0; i < VHOST_SCSI_MAX_VQ; i++) {