From patchwork Sat Aug 12 22:30:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 9897535 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 941E4603B4 for ; Sat, 12 Aug 2017 22:31:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7EAD8288F8 for ; Sat, 12 Aug 2017 22:31:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 734F128903; Sat, 12 Aug 2017 22:31:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24133288F8 for ; Sat, 12 Aug 2017 22:31:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752046AbdHLWaU (ORCPT ); Sat, 12 Aug 2017 18:30:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60224 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752023AbdHLWaT (ORCPT ); Sat, 12 Aug 2017 18:30:19 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 96BF02CE93D; Sat, 12 Aug 2017 22:30:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 96BF02CE93D Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=mchristi@redhat.com Received: from rh2.redhat.com (ovpn-120-52.rdu2.redhat.com [10.10.120.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0167F171E7; Sat, 12 Aug 2017 22:30:18 +0000 (UTC) From: Mike Christie To: target-devel@vger.kernel.org, nab@linux-iscsi.org Cc: Mike Christie Subject: [PATCH 1/2] tcmu: delay freeing the device resources until after deletion Date: Sat, 12 Aug 2017 17:30:16 -0500 Message-Id: <1502577017-1236-1-git-send-email-mchristi@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sat, 12 Aug 2017 22:30:19 +0000 (UTC) Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Userspace could still be accessing the ring and might even still have commands it is trying to complete (if cmd_time_out != 0, so the kernel has dropped the cmd/ref count and made the device deletable) when a deletion is executed. This moves the userspace deletion to the beginning of the function so we know once it is done userspace is not accessing the kernel. Signed-off-by: Mike Christie --- drivers/target/target_core_user.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c index 7d1da43..db129e9 100644 --- a/drivers/target/target_core_user.c +++ b/drivers/target/target_core_user.c @@ -1653,6 +1653,8 @@ static void tcmu_destroy_device(struct se_device *dev) bool all_expired = true; int i; + tcmu_netlink_event(udev, TCMU_CMD_REMOVED_DEVICE, 0, NULL); + del_timer_sync(&udev->timeout); mutex_lock(&root_udev_mutex); @@ -1680,8 +1682,6 @@ static void tcmu_destroy_device(struct se_device *dev) tcmu_blocks_release(udev); - tcmu_netlink_event(udev, TCMU_CMD_REMOVED_DEVICE, 0, NULL); - uio_unregister_device(&udev->uio_info); /* release ref from configure */