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=ham 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 D1D87C3A589 for ; Tue, 20 Aug 2019 13:42:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9E1F222DD6 for ; Tue, 20 Aug 2019 13:42:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566308546; bh=bX09ssadu/1oiVKOYAUmOwBp8D46nwwxLq1K/JTtefE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Rj2MqmqLyJyJ0fXX/BnuLVtGEbfCjl8zXTiK87vj22Nwgy/pxnHOGrHipCY1fOyvk nnQFKNrOWQ4R6mrvNoxaO9LYDnDBB37jTWaPgThDDgFGvBRjvKT4N1mAv8C+kO4o1t 2ucPEkYx61bgQjf6h0kZA5O7Aegufq2h0Om+Ho2I= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730622AbfHTNmZ (ORCPT ); Tue, 20 Aug 2019 09:42:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:37608 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730586AbfHTNmV (ORCPT ); Tue, 20 Aug 2019 09:42:21 -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 8571C233FF; Tue, 20 Aug 2019 13:42:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566308541; bh=bX09ssadu/1oiVKOYAUmOwBp8D46nwwxLq1K/JTtefE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DmjiS6ymZ/eONc7JdxujGyllCBx7/8HZSB+6fmv0aVYPGnZHQQcQl1b85i66G2/fX +3zfu5cv4lSPJGihoFieCxAIfWyMWJuMLW+ASjscel586a4Ig/hX9PJ3TIfPzDv+b2 3Y098y0JitYbXwLfIN0dige3i+GFL8doUlvlwj7w= 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 4.19 08/27] nvmet-loop: Flush nvme_delete_wq when removing the port Date: Tue, 20 Aug 2019 09:41:54 -0400 Message-Id: <20190820134213.11279-8-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190820134213.11279-1-sashal@kernel.org> References: <20190820134213.11279-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 9908082b32c4b..137a27fa369cb 100644 --- a/drivers/nvme/target/loop.c +++ b/drivers/nvme/target/loop.c @@ -678,6 +678,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