Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp379216pxb; Mon, 25 Oct 2021 10:03:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzf3q6lNhVlsePnhYX5mu6PmOVddQjL6X4xgrwo0AjAFuN4Ax75kO/sJyWIHv11LVsq3mrE X-Received: by 2002:a17:906:a041:: with SMTP id bg1mr24020186ejb.470.1635181386854; Mon, 25 Oct 2021 10:03:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635181386; cv=none; d=google.com; s=arc-20160816; b=Mnh2Pk4ATdF458cOqaikRd4fYyAPy4vQV5CT48RvXnwKDaCQ8Wog+gwN1y6QFPts18 TNaAI0cTgshG9TqNwOZUpiRlG5i8ziwnNPt3iNZ2Z0j51o5lLWY3QuRzLY/9RtP50+8x TmMK9FkvxG2UPtInlz2bzpDdrQePWj7DHlkjEfJ/qNoxrpaWgp0Pqct9DY/VTEwSv5HQ nvv5Tvg9XMN0gBD3jzOqYMdeDWKzZU+cXppMOENKXet6N5B+WWmTphp+dvgfwKBolxEI aY5F0oBUVUd3u/zH1ix1s/rSUuZykV5iByL+vsxiQoZdE4WXOSEGzGmgVtPftKek3eDa fhwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=qede6TjDxiLY0lfyamfDAU80kDIRWE4IaVFgcVduVbo=; b=m75iSqmfk4xTu//4GYj7YO8uZynRVMI4ZCE7zdK0TD0CG3ainpAGZ0FRtq/ysdDys2 OsPp2E7DvOVlm+8Ou2ArCe8Oafi/QIjziWJBUWEAUZeQuP4Mm76nDaXoUFQwmiO4wWxf GURTVybM3uTSHEzLOfQ64Lo6VL2TA1ku7laI5Km5THk1yHcMTX1Nyj0FVpQkCvx2Vlq3 Gyei8d1AZpHdHWVC1U+gPr+K8prZ/Ur6TmZDlJTGGg4fh254ff6JbGVCHpZ2tZ5OT/gO IV5OJVm59ycRY8wjjXsL7ytlb/KD5vOPPwoTlUSWeYfrjgKrOvOiBLSBw0772aQZdNPg AKpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="bZ/D5NEV"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bk22si23385197ejb.746.2021.10.25.10.02.20; Mon, 25 Oct 2021 10:03:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="bZ/D5NEV"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234201AbhJYRCN (ORCPT + 99 others); Mon, 25 Oct 2021 13:02:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:54512 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234151AbhJYRCJ (ORCPT ); Mon, 25 Oct 2021 13:02:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C1D8660F92; Mon, 25 Oct 2021 16:59:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1635181186; bh=3TFO/T2EnCi4p90u8EHPpy5i/lZnFyiAgAbYZ9zQVOU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bZ/D5NEVZKaNlUKxKVF5u77OqL2+z31cTN6+SG8/LWYjSAn70mj78XAS9MGinvrbh U/PVyzNnyxRDFOBZDPl8eGTHQqGDFerFlRGwvHLZff/ENANNRkR3PScT5Kk4FO6e/7 LEEpKNnDP/cFWoINj3AgdrrZYdo2uzVn6wM3x2pvN44Bf+ybIJqMLG/a3+n5W2Q1yZ PLL8U9Hr2Ow10YD7GDPAJsSCVIHDaoGo0xp9HRRim37yA0wg3co3nbtKGJe4zK8bXu qNob7pnaTz2smk4bQXLd1atDZZstcmVPRrHawosTLZeVLKXwSM7QGvovilxrI6TfyU T3L6IJhVZMrdw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ming Lei , Greg Kroah-Hartman , Changhui Zhong , Yi Zhang , "Martin K . Petersen" , Sasha Levin , jejb@linux.ibm.com, linux-scsi@vger.kernel.org Subject: [PATCH AUTOSEL 5.14 04/18] scsi: core: Put LLD module refcnt after SCSI device is released Date: Mon, 25 Oct 2021 12:59:17 -0400 Message-Id: <20211025165939.1393655-4-sashal@kernel.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211025165939.1393655-1-sashal@kernel.org> References: <20211025165939.1393655-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ming Lei [ Upstream commit f2b85040acec9a928b4eb1b57a989324e8e38d3f ] SCSI host release is triggered when SCSI device is freed. We have to make sure that the low-level device driver module won't be unloaded before SCSI host instance is released because shost->hostt is required in the release handler. Make sure to put LLD module refcnt after SCSI device is released. Fixes a kernel panic of 'BUG: unable to handle page fault for address' reported by Changhui and Yi. Link: https://lore.kernel.org/r/20211008050118.1440686-1-ming.lei@redhat.com Cc: Greg Kroah-Hartman Reported-by: Changhui Zhong Reported-by: Yi Zhang Tested-by: Yi Zhang Signed-off-by: Ming Lei Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/scsi.c | 4 +++- drivers/scsi/scsi_sysfs.c | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c index d26025cf5de3..71dd0989c78a 100644 --- a/drivers/scsi/scsi.c +++ b/drivers/scsi/scsi.c @@ -553,8 +553,10 @@ EXPORT_SYMBOL(scsi_device_get); */ void scsi_device_put(struct scsi_device *sdev) { - module_put(sdev->host->hostt->module); + struct module *mod = sdev->host->hostt->module; + put_device(&sdev->sdev_gendev); + module_put(mod); } EXPORT_SYMBOL(scsi_device_put); diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c index c0d31119d6d7..ed05c3565e83 100644 --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c @@ -448,9 +448,12 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work) struct scsi_vpd *vpd_pg80 = NULL, *vpd_pg83 = NULL; struct scsi_vpd *vpd_pg0 = NULL, *vpd_pg89 = NULL; unsigned long flags; + struct module *mod; sdev = container_of(work, struct scsi_device, ew.work); + mod = sdev->host->hostt->module; + scsi_dh_release_device(sdev); parent = sdev->sdev_gendev.parent; @@ -501,11 +504,17 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work) if (parent) put_device(parent); + module_put(mod); } static void scsi_device_dev_release(struct device *dev) { struct scsi_device *sdp = to_scsi_device(dev); + + /* Set module pointer as NULL in case of module unloading */ + if (!try_module_get(sdp->host->hostt->module)) + sdp->host->hostt->module = NULL; + execute_in_process_context(scsi_device_dev_release_usercontext, &sdp->ew); } -- 2.33.0