Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1719982pxb; Thu, 4 Nov 2021 07:19:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyRGXxI6LcyKuVJTquyOGPzzbKR/egNM6MEfNofCH2ySdFCPClITCAHYq68gEFzvDuo/lfZ X-Received: by 2002:a17:906:a217:: with SMTP id r23mr62653778ejy.548.1636035594353; Thu, 04 Nov 2021 07:19:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1636035594; cv=none; d=google.com; s=arc-20160816; b=J8/YLouFfL2M3obHMvlZ7VkIMkUhrnhWT7BSepNMoPaxc1hK4aacu5r/hoERnpL9PB xg7c2oHsF67xITzevbEw1eZnRAsCEV3WBx/m7nClK3zT2PyL7iC/vSumt2TyRY4hM725 /tl/H3HPvaGNgGQhEenACZmdyVEtXiwszicE3RGQu997G32T6c4Q+tE0xy/+XTtBGTDx 3MX8MnpJC4i0z1fuEa7Z+4w7HVnHg9CO6URs8vynA56sfASU7VMW24AMV+vBEpQedMyh KUzlju4FIgTGGPyD1pZJw7wJrK7t5D7PEwhkW5BFkyLcensbYf7ZyPoAZhiH9wkjFkGb 7YUw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=snzvB2Eqs6alxLZ8E2K86Mr6okKnEWBersg6ILSQ52o=; b=SQ85/AAg/AUbuvhjFEmI2Eztgde0sJDYhfSqRXbSofc5HxDjOKuuyWBq6ZbVICa6ol 577MPoSmUpaUS6vNxCa6XWt076u6cVVCukMyDLpGPQjQX31Z/MndWtn5FyoJ1/nbifxK 6fXA0zz3Gk/gkb6qA8T4BSRQFVPc3YaTf6T8eX0C+3YtUtAPXcbctgi9F/hqIJ+U1Qmr oKoG11iO0bZsCZDroTSJLUqFnOWyvr8ihHYMXQ/wRA4QaqCO3/s9nzCY32gz2iDUCJYk QPaJaSUagbbuiDbe17BVAmlHtvhQmQmbNfRyBlsi2+Rx0P7Lfabs2mwRZfpFaMn+dkIR VUNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qi5m1DSA; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bl4si9284662ejb.277.2021.11.04.07.19.20; Thu, 04 Nov 2021 07:19:54 -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=@linuxfoundation.org header.s=korg header.b=qi5m1DSA; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232427AbhKDOTQ (ORCPT + 99 others); Thu, 4 Nov 2021 10:19:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:47258 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232265AbhKDOSX (ORCPT ); Thu, 4 Nov 2021 10:18:23 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D6A4561244; Thu, 4 Nov 2021 14:15:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1636035345; bh=dCt/v9KhBK7diItIio296/T00c9URqlC+1F/Cbqh1C4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qi5m1DSAnLY3D0TYY18VPc7DtIKB1JD3rAOu5VBEfCjE0AHhrgbbt9jC9WXDVbN5u mvxFjbpwejBBJ0ceazLy7o/rLiXsgX5ROP+lTS5WIsG9BdoIqtOlE25xRpHT2BjJOV 5B7j7JzJluqSDbzppy7DJhBSc2jJqgN0rXZC0ePE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Changhui Zhong , Yi Zhang , Ming Lei , "Martin K. Petersen" Subject: [PATCH 5.4 1/9] scsi: core: Put LLD module refcnt after SCSI device is released Date: Thu, 4 Nov 2021 15:12:54 +0100 Message-Id: <20211104141158.434717408@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211104141158.384397574@linuxfoundation.org> References: <20211104141158.384397574@linuxfoundation.org> User-Agent: quilt/0.66 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ming Lei commit f2b85040acec9a928b4eb1b57a989324e8e38d3f upstream. 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: Greg Kroah-Hartman --- drivers/scsi/scsi.c | 4 +++- drivers/scsi/scsi_sysfs.c | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) --- a/drivers/scsi/scsi.c +++ b/drivers/scsi/scsi.c @@ -555,8 +555,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); --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c @@ -438,9 +438,12 @@ static void scsi_device_dev_release_user struct list_head *this, *tmp; struct scsi_vpd *vpd_pg80 = NULL, *vpd_pg83 = 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; @@ -481,11 +484,17 @@ static void scsi_device_dev_release_user 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); }