From patchwork Fri Jul 24 02:51:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nicholas A. Bellinger" X-Patchwork-Id: 6856861 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id BB2239F1D4 for ; Fri, 24 Jul 2015 02:56:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C2F0B20632 for ; Fri, 24 Jul 2015 02:56:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CA3B62053C for ; Fri, 24 Jul 2015 02:56:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753462AbbGXC4I (ORCPT ); Thu, 23 Jul 2015 22:56:08 -0400 Received: from mail-oi0-f48.google.com ([209.85.218.48]:34333 "EHLO mail-oi0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752553AbbGXC4F (ORCPT ); Thu, 23 Jul 2015 22:56:05 -0400 Received: by oigd21 with SMTP id d21so9810590oig.1 for ; Thu, 23 Jul 2015 19:56: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:in-reply-to :references; bh=hLyM532ik/5TGdoXKcSRKpZsriRrGvta7maPHaR23iA=; b=TGvLo6EpGzm9Iwc0rPqo/bWmg8DwEp0hs4gkq3YLuW3Su2LI1PbJQkc/fg21mqbj8I oz4Zo2hFUCNsfsrZymoGI/JkMm82VLm+WsXkVbEjEGs3Yr470uDWfzzGyZLU9rO3xZTD 22caZoIthAf+hzKcil+Tn2YYOlfeX9FL4wDCLPoVULqgusOe90k6fF0jB2f0d/KTMsMf F4ydz8zzYFyAQeMgwRAul3T1zzHy/Y7oDnbsTgbpQJ8ImBbDS1iJeJ9gM+as/xWw+Me5 DxdFpArO7tKHlKRT/BmBMNY6EMpT+t1pfyQMe+Z0MZVTRDI9Da6+0YMYWLD26WGaAxxo lvjw== X-Gm-Message-State: ALoCoQlruVV5jHuTSDoviLySdaM/C/QPnVn5cNIO9+u0vfU/GS+bSvxzSP0/1M+G06xFD6bZjVLI X-Received: by 10.60.142.170 with SMTP id rx10mr12623524oeb.28.1437706564659; Thu, 23 Jul 2015 19:56:04 -0700 (PDT) Received: from localhost.localdomain (mail.linux-iscsi.org. [67.23.28.174]) by smtp.gmail.com with ESMTPSA id xp8sm4094706obc.10.2015.07.23.19.56.04 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 23 Jul 2015 19:56:04 -0700 (PDT) From: "Nicholas A. Bellinger" To: target-devel Cc: linux-scsi , Sagi Grimberg , Nicholas Bellinger , Sagi Grimberg Subject: [PATCH 3/4] iscsi-target: Fix iser explicit logout TX kthread leak Date: Fri, 24 Jul 2015 02:51:18 +0000 Message-Id: <1437706279-10580-4-git-send-email-nab@daterainc.com> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1437706279-10580-1-git-send-email-nab@daterainc.com> References: <1437706279-10580-1-git-send-email-nab@daterainc.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 fixes a regression introduced with the following commit in v4.0-rc1 code, where an explicit iser-target logout would result in ->tx_thread_active being incorrectly cleared by the logout post handler, and subsequent TX kthread leak: commit 88dcd2dab5c23b1c9cfc396246d8f476c872f0ca Author: Nicholas Bellinger Date: Thu Feb 26 22:19:15 2015 -0800 iscsi-target: Convert iscsi_thread_set usage to kthread.h To address this bug, change iscsit_logout_post_handler_closesession() and iscsit_logout_post_handler_samecid() to only cmpxchg() on ->tx_thread_active for traditional iscsi/tcp connections. This is required because iscsi/tcp connections are invoking logout post handler logic directly from TX kthread context, while iser connections are invoking logout post handler logic from a seperate workqueue context. Cc: Sagi Grimberg Cc: # v3.10+ Signed-off-by: Nicholas Bellinger --- drivers/target/iscsi/iscsi_target.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c index 202a428..cd77a06 100644 --- a/drivers/target/iscsi/iscsi_target.c +++ b/drivers/target/iscsi/iscsi_target.c @@ -4544,7 +4544,18 @@ static void iscsit_logout_post_handler_closesession( struct iscsi_conn *conn) { struct iscsi_session *sess = conn->sess; - int sleep = cmpxchg(&conn->tx_thread_active, true, false); + int sleep = 1; + /* + * Traditional iscsi/tcp will invoke this logic from TX thread + * context during session logout, so clear tx_thread_active and + * sleep if iscsit_close_connection() has not already occured. + * + * Since iser-target invokes this logic from it's own workqueue, + * always sleep waiting for RX/TX thread shutdown to complete + * within iscsit_close_connection(). + */ + if (conn->conn_transport->transport_type == ISCSI_TCP) + sleep = cmpxchg(&conn->tx_thread_active, true, false); atomic_set(&conn->conn_logout_remove, 0); complete(&conn->conn_logout_comp); @@ -4558,7 +4569,10 @@ static void iscsit_logout_post_handler_closesession( static void iscsit_logout_post_handler_samecid( struct iscsi_conn *conn) { - int sleep = cmpxchg(&conn->tx_thread_active, true, false); + int sleep = 1; + + if (conn->conn_transport->transport_type == ISCSI_TCP) + sleep = cmpxchg(&conn->tx_thread_active, true, false); atomic_set(&conn->conn_logout_remove, 0); complete(&conn->conn_logout_comp);