From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4322FC3A589 for ; Tue, 20 Aug 2019 13:47:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 04B8C2087E for ; Tue, 20 Aug 2019 13:47:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566308870; bh=8o/LSptQLsr6zpE2YbbmP/Z5u/j0QrHLq0kkAVY5C8o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=CgBNXmkocY2npKOM0CUeCeDfY5q8GdDAC+o0ca/BieIJkRLBgyhh4/5zY4ohk6XRl lvUKpQBzDc/Dq40qeNAE7QyCuSru/f/lLxk9bu7m5fmjZDG/5mo0bA3U2PZyqR3MGA sRfpMJg5H8X9wI4QeWki1yKQpWahdEU2eowQHwRA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730747AbfHTNrt (ORCPT ); Tue, 20 Aug 2019 09:47:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:35410 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730163AbfHTNkj (ORCPT ); Tue, 20 Aug 2019 09:40:39 -0400 Received: from sasha-vm.mshome.net (unknown [12.236.144.82]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8B9B9230F2; Tue, 20 Aug 2019 13:40:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566308439; bh=8o/LSptQLsr6zpE2YbbmP/Z5u/j0QrHLq0kkAVY5C8o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WEDCrNkT65/hZYRN7Uf6CnYvWGgcjmG1O0eOPv+86gPcsRhyQZIwx3721CR5y8sF8 HC4JY8iHH8kCxew/Eb/VAcJInG3ShI9wsox4STT0BzG9YbfBrgA0OUrqeBn04iAGYb +FgNjes0WKlsnQHYdDqFkKkid/sjSZE5kj7SIx5k= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Logan Gunthorpe , Sagi Grimberg , Max Gurtovoy , Sasha Levin , linux-nvme@lists.infradead.org Subject: [PATCH AUTOSEL 5.2 11/44] nvmet-loop: Flush nvme_delete_wq when removing the port Date: Tue, 20 Aug 2019 09:39:55 -0400 Message-Id: <20190820134028.10829-11-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190820134028.10829-1-sashal@kernel.org> References: <20190820134028.10829-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Logan Gunthorpe [ Upstream commit 86b9a63e595ff03f9d0a7b92b6acc231fecefc29 ] After calling nvme_loop_delete_ctrl(), the controllers will not yet be deleted because nvme_delete_ctrl() only schedules work to do the delete. This means a race can occur if a port is removed but there are still active controllers trying to access that memory. To fix this, flush the nvme_delete_wq before returning from nvme_loop_remove_port() so that any controllers that might be in the process of being deleted won't access a freed port. Signed-off-by: Logan Gunthorpe Reviewed-by: Sagi Grimberg Reviewed-by: Max Gurtovoy Reviewed-by : Chaitanya Kulkarni Signed-off-by: Sagi Grimberg Signed-off-by: Sasha Levin --- drivers/nvme/target/loop.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/nvme/target/loop.c b/drivers/nvme/target/loop.c index 9e211ad6bdd3d..da9cd07461fbb 100644 --- a/drivers/nvme/target/loop.c +++ b/drivers/nvme/target/loop.c @@ -654,6 +654,14 @@ static void nvme_loop_remove_port(struct nvmet_port *port) mutex_lock(&nvme_loop_ports_mutex); list_del_init(&port->entry); mutex_unlock(&nvme_loop_ports_mutex); + + /* + * Ensure any ctrls that are in the process of being + * deleted are in fact deleted before we return + * and free the port. This is to prevent active + * ctrls from using a port after it's freed. + */ + flush_workqueue(nvme_delete_wq); } static const struct nvmet_fabrics_ops nvme_loop_ops = { -- 2.20.1