From patchwork Sat Oct 15 00:24:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 615670 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8C69C4332F for ; Sat, 15 Oct 2022 00:24:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229699AbiJOAYd (ORCPT ); Fri, 14 Oct 2022 20:24:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229681AbiJOAYc (ORCPT ); Fri, 14 Oct 2022 20:24:32 -0400 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37014A3AB4 for ; Fri, 14 Oct 2022 17:24:31 -0700 (PDT) Received: by mail-pj1-f53.google.com with SMTP id h12so6360915pjk.0 for ; Fri, 14 Oct 2022 17:24:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SpmXLmWlYQVnn1BcyLp3cCBXB/Od6Q2CqnBaVZAdo34=; b=pbnNoPz4ZNaXpMXGTkMOfPbxNVEGaUhKDlNtju4munijtF3s1il2+ZvTBNZ7ikFGAC NT12ux/IBQEYCWAEts3W3Bb4YLbjJTu6Kmf9U0pLwQqKLUrSmX+ofYvC5w+KeSZ/ZbfK hs3h2bFzgXiY4up6U5Z71P9sgc0sLHLZCxL9NAEb+pZzlAqC73rhcRd45yqx7hHlv2t7 caQtRn+ylSlkGoTct175e8glI6JFEylM3eMnvCkLAU8tt0lx+zWmRQaVpfXHk821qxQY rhjR1mGtZCHWG92WkAZGTl1m9HuxnJd/42FHqrrAJEXfOXen6ncKVPrgcA+6RbpGhx55 183w== X-Gm-Message-State: ACrzQf0cen/WrdFrM0FUi89k8EoMMGNijNbJKB5pfWcVBIQCHnEtCmsd 3B3wYRBXpFb4mGK7B7CSBKY= X-Google-Smtp-Source: AMsMyM6db6nw5GC8PMlhcwzz2FqKksJipnAsyV4gKZL18SqCrNC8+y4xneAgdtnK8AugsPD9uU6png== X-Received: by 2002:a17:902:da90:b0:17e:c64c:99c2 with SMTP id j16-20020a170902da9000b0017ec64c99c2mr391822plx.85.1665793470544; Fri, 14 Oct 2022 17:24:30 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([98.51.102.78]) by smtp.gmail.com with ESMTPSA id y17-20020a634951000000b0046a1c832e9fsm1937953pgk.34.2022.10.14.17.24.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Oct 2022 17:24:29 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , John Garry , Bradley Grove , Christoph Hellwig , Ming Lei , Hannes Reinecke , Mike Christie , Krzysztof Kozlowski Subject: [PATCH v7 1/8] scsi: esas2r: Initialize two host template members implicitly Date: Fri, 14 Oct 2022 17:24:11 -0700 Message-Id: <20221015002418.30955-2-bvanassche@acm.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221015002418.30955-1-bvanassche@acm.org> References: <20221015002418.30955-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Prepare for removing the 'proc_dir' and 'present' members from the SCSI host template by implicitly initializing 'present' and 'emulated' in 'driver_template'. Reviewed-by: John Garry Cc: Bradley Grove Cc: Christoph Hellwig Cc: Ming Lei Cc: Hannes Reinecke Cc: Mike Christie Cc: Krzysztof Kozlowski Signed-off-by: Bart Van Assche --- drivers/scsi/esas2r/esas2r_main.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/scsi/esas2r/esas2r_main.c b/drivers/scsi/esas2r/esas2r_main.c index 7a4eadad23d7..27f6e7ccded8 100644 --- a/drivers/scsi/esas2r/esas2r_main.c +++ b/drivers/scsi/esas2r/esas2r_main.c @@ -248,8 +248,6 @@ static struct scsi_host_template driver_template = { .sg_tablesize = SG_CHUNK_SIZE, .cmd_per_lun = ESAS2R_DEFAULT_CMD_PER_LUN, - .present = 0, - .emulated = 0, .proc_name = ESAS2R_DRVR_NAME, .change_queue_depth = scsi_change_queue_depth, .max_sectors = 0xFFFF, From patchwork Sat Oct 15 00:24:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 615375 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01E27C4332F for ; Sat, 15 Oct 2022 00:24:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229727AbiJOAYj (ORCPT ); Fri, 14 Oct 2022 20:24:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229693AbiJOAYd (ORCPT ); Fri, 14 Oct 2022 20:24:33 -0400 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36481A3AB0 for ; Fri, 14 Oct 2022 17:24:33 -0700 (PDT) Received: by mail-pl1-f171.google.com with SMTP id n7so6169378plp.1 for ; Fri, 14 Oct 2022 17:24:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vE65TSc6wxjQbrwNjWse98ak3WMgmY7yzNFoKZNQrfo=; b=LlVJEGgKNFuyNqzag4zUitvz0HMOKvuIYllbYD1UoFKBbsz5Z1c58EdAGSNZVMwvqO 6RGLiK1Z+wX8Gj0T2ZX/E7NlJTjER62XAhr+BsRyW9BI9/D61GMIkrjmTwTUkyLQpApl KPjrIOWzCZWJPFVCb8Yd5iYZvsbF/kiJE5nYd/RdcVVSNn7ybdnuBsGp4kCIf8o7LuB0 WNKv1glBJh2uEPYYxJpPhsaunSlIbWyYPMnk1prJUOrhJFxS5yFNe/fnM6FWNp7m+GO4 SINFUko3cEc6DCUHwLBZg0KbIa5dKK7qxnFcszdkpWOVyQFlOl+HwSyx22QmMSsWANA/ z57Q== X-Gm-Message-State: ACrzQf0qUB6npq+R/8eCSz1fF1cC92mZxiI6lW5OAXBtkhsBUXV27cZh dwLZj8CFwrfEaahXTIhKjOc= X-Google-Smtp-Source: AMsMyM4zBIom4spmNwSbsPYYxwU17zwD93D2/Bo7bPFenGQWRCmv748p35Q3P3WutMNkn6M3CowWkw== X-Received: by 2002:a17:902:e84a:b0:183:ee5e:fad0 with SMTP id t10-20020a170902e84a00b00183ee5efad0mr267749plg.66.1665793472639; Fri, 14 Oct 2022 17:24:32 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([98.51.102.78]) by smtp.gmail.com with ESMTPSA id y17-20020a634951000000b0046a1c832e9fsm1937953pgk.34.2022.10.14.17.24.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Oct 2022 17:24:31 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , John Garry , Bradley Grove , Christoph Hellwig , Ming Lei , Hannes Reinecke , Mike Christie , Krzysztof Kozlowski Subject: [PATCH v7 2/8] scsi: esas2r: Introduce scsi_template_proc_dir() Date: Fri, 14 Oct 2022 17:24:12 -0700 Message-Id: <20221015002418.30955-3-bvanassche@acm.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221015002418.30955-1-bvanassche@acm.org> References: <20221015002418.30955-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Prepare for removing the 'proc_dir' and 'present' members from the SCSI host template. This patch does not change any functionality. Reviewed-by: John Garry Cc: Bradley Grove Cc: Christoph Hellwig Cc: Ming Lei Cc: Hannes Reinecke Cc: Mike Christie Cc: Krzysztof Kozlowski Signed-off-by: Bart Van Assche --- drivers/scsi/esas2r/esas2r_main.c | 17 +++++++++++------ drivers/scsi/scsi_proc.c | 11 +++++++++++ include/scsi/scsi_host.h | 6 ++++++ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/esas2r/esas2r_main.c b/drivers/scsi/esas2r/esas2r_main.c index 27f6e7ccded8..d7a2c49ff5ee 100644 --- a/drivers/scsi/esas2r/esas2r_main.c +++ b/drivers/scsi/esas2r/esas2r_main.c @@ -635,10 +635,13 @@ static void __exit esas2r_exit(void) esas2r_log(ESAS2R_LOG_INFO, "%s called", __func__); if (esas2r_proc_major > 0) { + struct proc_dir_entry *proc_dir; + esas2r_log(ESAS2R_LOG_INFO, "unregister proc"); - remove_proc_entry(ATTONODE_NAME, - esas2r_proc_host->hostt->proc_dir); + proc_dir = scsi_template_proc_dir(esas2r_proc_host->hostt); + if (proc_dir) + remove_proc_entry(ATTONODE_NAME, proc_dir); unregister_chrdev(esas2r_proc_major, ESAS2R_DRVR_NAME); esas2r_proc_major = 0; @@ -728,11 +731,13 @@ const char *esas2r_info(struct Scsi_Host *sh) esas2r_proc_major); if (esas2r_proc_major > 0) { - struct proc_dir_entry *pde; + struct proc_dir_entry *proc_dir; + struct proc_dir_entry *pde = NULL; - pde = proc_create(ATTONODE_NAME, 0, - sh->hostt->proc_dir, - &esas2r_proc_ops); + proc_dir = scsi_template_proc_dir(sh->hostt); + if (proc_dir) + pde = proc_create(ATTONODE_NAME, 0, proc_dir, + &esas2r_proc_ops); if (!pde) { esas2r_log_dev(ESAS2R_LOG_WARN, diff --git a/drivers/scsi/scsi_proc.c b/drivers/scsi/scsi_proc.c index 95aee1ad1383..456b43097288 100644 --- a/drivers/scsi/scsi_proc.c +++ b/drivers/scsi/scsi_proc.c @@ -83,6 +83,17 @@ static int proc_scsi_host_open(struct inode *inode, struct file *file) 4 * PAGE_SIZE); } +/** + * scsi_template_proc_dir() - returns the procfs dir for a SCSI host template + * @sht: SCSI host template pointer. + */ +struct proc_dir_entry * +scsi_template_proc_dir(const struct scsi_host_template *sht) +{ + return sht->proc_dir; +} +EXPORT_SYMBOL_GPL(scsi_template_proc_dir); + static const struct proc_ops proc_scsi_ops = { .proc_open = proc_scsi_host_open, .proc_release = single_release, diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h index fcf25f1642a3..3854ffcb0b3e 100644 --- a/include/scsi/scsi_host.h +++ b/include/scsi/scsi_host.h @@ -751,6 +751,12 @@ extern struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *, int); extern int __must_check scsi_add_host_with_dma(struct Scsi_Host *, struct device *, struct device *); +#if defined(CONFIG_SCSI_PROC_FS) +struct proc_dir_entry * +scsi_template_proc_dir(const struct scsi_host_template *sht); +#else +#define scsi_template_proc_dir(sht) NULL +#endif extern void scsi_scan_host(struct Scsi_Host *); extern void scsi_rescan_device(struct device *); extern void scsi_remove_host(struct Scsi_Host *); From patchwork Sat Oct 15 00:24:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 615669 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98D65C433FE for ; Sat, 15 Oct 2022 00:24:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229736AbiJOAYk (ORCPT ); Fri, 14 Oct 2022 20:24:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229723AbiJOAYj (ORCPT ); Fri, 14 Oct 2022 20:24:39 -0400 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A181A3ABE for ; Fri, 14 Oct 2022 17:24:35 -0700 (PDT) Received: by mail-pf1-f175.google.com with SMTP id y191so6328605pfb.2 for ; Fri, 14 Oct 2022 17:24:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YQbuK20x0N7JV3KiyJ7uwhhcY3DUtyDNeAj6eT/NnHk=; b=QleTo68g/+eac99TGkamPddeKchePmo7XrOFdL+HXRUK5hPIeccZ5ucaysh6SjXrCQ 9DKc8An8/dRyPaSG0ac18HuyNUH/40GyKRI7G9nQ6L0++wgp72/bohSUXhKIMlqxXbTH DoRUYez6wh2ncm87eVYJrAnkWDGhkGQOToxOuaetgSqSXcB+DeugkoxbQ5T6JkyQXE3C olRTmNqdZRsx3j9hV1GacuGFM3CfK0uPsbM0aSTdQ2zPDSc6/PpbEYxxhd0L8GTLBwyI /aBoDZkCkc9BheMhlui4roD2zdgonOp1rNMz5361VNB+b+XakzjYD68UKPBf1YDTM6ba lhRQ== X-Gm-Message-State: ACrzQf0NK7cTbg/LX2+L6HPWzaslUVtNuLqQ2VB1aMloWMcL4cCnnd9F w3Vq0AWV+6nxsHcPbYN+wEU= X-Google-Smtp-Source: AMsMyM5oKQHxs1OfJu1rdgPO2+vG/PCZczpo+zo4wtfNUqE7D6PdR2h5yqvwisIGyxJIHjaIwgvVSA== X-Received: by 2002:a05:6a00:1707:b0:562:e790:dfc3 with SMTP id h7-20020a056a00170700b00562e790dfc3mr485338pfc.59.1665793474338; Fri, 14 Oct 2022 17:24:34 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([98.51.102.78]) by smtp.gmail.com with ESMTPSA id y17-20020a634951000000b0046a1c832e9fsm1937953pgk.34.2022.10.14.17.24.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Oct 2022 17:24:33 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , John Garry , Christoph Hellwig , Ming Lei , Hannes Reinecke , Mike Christie , Krzysztof Kozlowski Subject: [PATCH v7 3/8] scsi: core: Fail host creation if creating the proc directory fails Date: Fri, 14 Oct 2022 17:24:13 -0700 Message-Id: <20221015002418.30955-4-bvanassche@acm.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221015002418.30955-1-bvanassche@acm.org> References: <20221015002418.30955-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Users expect that the contents of /proc/scsi is in sync with the contents of /sys/class/scsi_host. Hence fail host creation if creating the proc directory fails. Suggested-by: John Garry Reviewed-by: John Garry Cc: Christoph Hellwig Cc: Ming Lei Cc: Hannes Reinecke Cc: Mike Christie Cc: Krzysztof Kozlowski Signed-off-by: Bart Van Assche --- drivers/scsi/hosts.c | 3 ++- drivers/scsi/scsi_priv.h | 4 ++-- drivers/scsi/scsi_proc.c | 13 +++++++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c index 9857dba09c95..12346e2297fd 100644 --- a/drivers/scsi/hosts.c +++ b/drivers/scsi/hosts.c @@ -519,7 +519,8 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize) "failed to create tmf workq\n"); goto fail; } - scsi_proc_hostdir_add(shost->hostt); + if (scsi_proc_hostdir_add(shost->hostt) < 0) + goto fail; return shost; fail: /* diff --git a/drivers/scsi/scsi_priv.h b/drivers/scsi/scsi_priv.h index c52de9a973e4..494f48e03e90 100644 --- a/drivers/scsi/scsi_priv.h +++ b/drivers/scsi/scsi_priv.h @@ -111,14 +111,14 @@ extern void scsi_evt_thread(struct work_struct *work); /* scsi_proc.c */ #ifdef CONFIG_SCSI_PROC_FS -extern void scsi_proc_hostdir_add(struct scsi_host_template *); +extern int scsi_proc_hostdir_add(struct scsi_host_template *); extern void scsi_proc_hostdir_rm(struct scsi_host_template *); extern void scsi_proc_host_add(struct Scsi_Host *); extern void scsi_proc_host_rm(struct Scsi_Host *); extern int scsi_init_procfs(void); extern void scsi_exit_procfs(void); #else -# define scsi_proc_hostdir_add(sht) do { } while (0) +# define scsi_proc_hostdir_add(sht) 0 # define scsi_proc_hostdir_rm(sht) do { } while (0) # define scsi_proc_host_add(shost) do { } while (0) # define scsi_proc_host_rm(shost) do { } while (0) diff --git a/drivers/scsi/scsi_proc.c b/drivers/scsi/scsi_proc.c index 456b43097288..8c84f1a74773 100644 --- a/drivers/scsi/scsi_proc.c +++ b/drivers/scsi/scsi_proc.c @@ -108,20 +108,25 @@ static const struct proc_ops proc_scsi_ops = { * * Sets sht->proc_dir to the new directory. */ - -void scsi_proc_hostdir_add(struct scsi_host_template *sht) +int scsi_proc_hostdir_add(struct scsi_host_template *sht) { + int ret = 0; + if (!sht->show_info) - return; + return 0; mutex_lock(&global_host_template_mutex); if (!sht->present++) { sht->proc_dir = proc_mkdir(sht->proc_name, proc_scsi); - if (!sht->proc_dir) + if (!sht->proc_dir) { printk(KERN_ERR "%s: proc_mkdir failed for %s\n", __func__, sht->proc_name); + ret = -ENOMEM; + } } mutex_unlock(&global_host_template_mutex); + + return ret; } /** From patchwork Sat Oct 15 00:24:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 615374 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42BD9C43217 for ; Sat, 15 Oct 2022 00:24:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229681AbiJOAYm (ORCPT ); Fri, 14 Oct 2022 20:24:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229734AbiJOAYk (ORCPT ); Fri, 14 Oct 2022 20:24:40 -0400 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4C9CB8C for ; Fri, 14 Oct 2022 17:24:36 -0700 (PDT) Received: by mail-pl1-f171.google.com with SMTP id n7so6169470plp.1 for ; Fri, 14 Oct 2022 17:24:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ia+y/8O8+wjdy0kvrz1w5K81uYbGrTon6wMcNG0Yng8=; b=3oU+QFJ+lNSS1wSHI/3/ijGwxlNCpfUMW4J7XSoVlTwCEF+l4NLC6jDiEOLijI00u0 R7rNoxsiqLW8ntiwYs/VQnCetV1yZAnYsj18QR2mhYASTHpFa++eVYZzvmypvq7pS2qW cql79vOfrPlkNS60knrBdpP58FsSbnR9+tYUs0F2O2irxm5i96mt6mdVPhunfHnLn8J2 fyRBjQPGCDxztN5RItuL2IzB/NfoGoV7QPLMKJB02aRgoig/i2Z3R6H931X0I2MPfhmy S7zkluwt/Kb2rkj8P9yj0Nl1iVitPQ3Iu01wMuSrr7yfpNxTcERdDgA3nW0vGOCkAzrn q16Q== X-Gm-Message-State: ACrzQf0Z7wXvxanADv0rAxQyWJNUAjOO0nawODiSZ397z3vEPUEjiTRT tg9s9sgUNptbxSYgTQUOaMo= X-Google-Smtp-Source: AMsMyM6qt8tV37rx389v8Nt/FvBb4GOC8cbFJiTfBesS75ZKEENa8WemoiCUDLX6bOnt5I+eGV2qqg== X-Received: by 2002:a17:902:d483:b0:182:cb98:26e8 with SMTP id c3-20020a170902d48300b00182cb9826e8mr257865plg.73.1665793476199; Fri, 14 Oct 2022 17:24:36 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([98.51.102.78]) by smtp.gmail.com with ESMTPSA id y17-20020a634951000000b0046a1c832e9fsm1937953pgk.34.2022.10.14.17.24.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Oct 2022 17:24:35 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , John Garry , Christoph Hellwig , Ming Lei , Hannes Reinecke , Mike Christie , Krzysztof Kozlowski Subject: [PATCH v7 4/8] scsi: core: Introduce a new list for SCSI proc directory entries Date: Fri, 14 Oct 2022 17:24:14 -0700 Message-Id: <20221015002418.30955-5-bvanassche@acm.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221015002418.30955-1-bvanassche@acm.org> References: <20221015002418.30955-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Instead of using scsi_host_template members to track the SCSI proc directory entries, track these entries in a list. This patch changes the time needed for looking up the proc dir pointer from O(1) into O(n). I think this is acceptable since the number of SCSI host adapter types per host is usually small (less than ten). This patch has been tested by attaching two USB storage devices to a qemu host: $ grep -aH . /proc/scsi/usb-storage/* /proc/scsi/usb-storage/7: Host scsi7: usb-storage /proc/scsi/usb-storage/7: Vendor: QEMU /proc/scsi/usb-storage/7: Product: QEMU USB HARDDRIVE /proc/scsi/usb-storage/7:Serial Number: 1-0000:00:02.1:00.0-6 /proc/scsi/usb-storage/7: Protocol: Transparent SCSI /proc/scsi/usb-storage/7: Transport: Bulk /proc/scsi/usb-storage/7: Quirks: SANE_SENSE /proc/scsi/usb-storage/8: Host scsi8: usb-storage /proc/scsi/usb-storage/8: Vendor: QEMU /proc/scsi/usb-storage/8: Product: QEMU USB HARDDRIVE /proc/scsi/usb-storage/8:Serial Number: 1-0000:00:02.1:00.0-7 /proc/scsi/usb-storage/8: Protocol: Transparent SCSI /proc/scsi/usb-storage/8: Transport: Bulk /proc/scsi/usb-storage/8: Quirks: SANE_SENSE This patch prepares for constifying most SCSI host templates. Reviewed-by: John Garry Cc: Christoph Hellwig Cc: Ming Lei Cc: Hannes Reinecke Cc: Mike Christie Cc: Krzysztof Kozlowski Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_priv.h | 4 +- drivers/scsi/scsi_proc.c | 121 ++++++++++++++++++++++++++++++++------- include/scsi/scsi_host.h | 12 ---- 3 files changed, 102 insertions(+), 35 deletions(-) diff --git a/drivers/scsi/scsi_priv.h b/drivers/scsi/scsi_priv.h index 494f48e03e90..96284a0e13fe 100644 --- a/drivers/scsi/scsi_priv.h +++ b/drivers/scsi/scsi_priv.h @@ -111,8 +111,8 @@ extern void scsi_evt_thread(struct work_struct *work); /* scsi_proc.c */ #ifdef CONFIG_SCSI_PROC_FS -extern int scsi_proc_hostdir_add(struct scsi_host_template *); -extern void scsi_proc_hostdir_rm(struct scsi_host_template *); +extern int scsi_proc_hostdir_add(const struct scsi_host_template *); +extern void scsi_proc_hostdir_rm(const struct scsi_host_template *); extern void scsi_proc_host_add(struct Scsi_Host *); extern void scsi_proc_host_rm(struct Scsi_Host *); extern int scsi_init_procfs(void); diff --git a/drivers/scsi/scsi_proc.c b/drivers/scsi/scsi_proc.c index 8c84f1a74773..4a6eb1741be0 100644 --- a/drivers/scsi/scsi_proc.c +++ b/drivers/scsi/scsi_proc.c @@ -43,8 +43,23 @@ static struct proc_dir_entry *proc_scsi; -/* Protect sht->present and sht->proc_dir */ +/* Protects scsi_proc_list */ static DEFINE_MUTEX(global_host_template_mutex); +static LIST_HEAD(scsi_proc_list); + +/** + * struct scsi_proc_entry - (host template, SCSI proc dir) association + * @entry: entry in scsi_proc_list. + * @sht: SCSI host template associated with the procfs directory. + * @proc_dir: procfs directory associated with the SCSI host template. + * @present: Number of SCSI hosts instantiated for @sht. + */ +struct scsi_proc_entry { + struct list_head entry; + const struct scsi_host_template *sht; + struct proc_dir_entry *proc_dir; + unsigned int present; +}; static ssize_t proc_scsi_host_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) @@ -83,6 +98,32 @@ static int proc_scsi_host_open(struct inode *inode, struct file *file) 4 * PAGE_SIZE); } +static struct scsi_proc_entry * +__scsi_lookup_proc_entry(const struct scsi_host_template *sht) +{ + struct scsi_proc_entry *e; + + lockdep_assert_held(&global_host_template_mutex); + + list_for_each_entry(e, &scsi_proc_list, entry) + if (e->sht == sht) + return e; + + return NULL; +} + +static struct scsi_proc_entry * +scsi_lookup_proc_entry(const struct scsi_host_template *sht) +{ + struct scsi_proc_entry *e; + + mutex_lock(&global_host_template_mutex); + e = __scsi_lookup_proc_entry(sht); + mutex_unlock(&global_host_template_mutex); + + return e; +} + /** * scsi_template_proc_dir() - returns the procfs dir for a SCSI host template * @sht: SCSI host template pointer. @@ -90,7 +131,9 @@ static int proc_scsi_host_open(struct inode *inode, struct file *file) struct proc_dir_entry * scsi_template_proc_dir(const struct scsi_host_template *sht) { - return sht->proc_dir; + struct scsi_proc_entry *e = scsi_lookup_proc_entry(sht); + + return e ? e->proc_dir : NULL; } EXPORT_SYMBOL_GPL(scsi_template_proc_dir); @@ -108,24 +151,41 @@ static const struct proc_ops proc_scsi_ops = { * * Sets sht->proc_dir to the new directory. */ -int scsi_proc_hostdir_add(struct scsi_host_template *sht) +int scsi_proc_hostdir_add(const struct scsi_host_template *sht) { - int ret = 0; + struct scsi_proc_entry *e; + int ret; if (!sht->show_info) return 0; mutex_lock(&global_host_template_mutex); - if (!sht->present++) { - sht->proc_dir = proc_mkdir(sht->proc_name, proc_scsi); - if (!sht->proc_dir) { - printk(KERN_ERR "%s: proc_mkdir failed for %s\n", - __func__, sht->proc_name); + e = __scsi_lookup_proc_entry(sht); + if (!e) { + e = kzalloc(sizeof(*e), GFP_KERNEL); + if (!e) { ret = -ENOMEM; + goto unlock; } } + if (e->present++) + goto success; + e->proc_dir = proc_mkdir(sht->proc_name, proc_scsi); + if (!e->proc_dir) { + printk(KERN_ERR "%s: proc_mkdir failed for %s\n", __func__, + sht->proc_name); + ret = -ENOMEM; + goto unlock; + } + e->sht = sht; + list_add_tail(&e->entry, &scsi_proc_list); +success: + e = NULL; + ret = 0; +unlock: mutex_unlock(&global_host_template_mutex); + kfree(e); return ret; } @@ -133,15 +193,19 @@ int scsi_proc_hostdir_add(struct scsi_host_template *sht) * scsi_proc_hostdir_rm - remove directory in /proc for a scsi host * @sht: owner of directory */ -void scsi_proc_hostdir_rm(struct scsi_host_template *sht) +void scsi_proc_hostdir_rm(const struct scsi_host_template *sht) { + struct scsi_proc_entry *e; + if (!sht->show_info) return; mutex_lock(&global_host_template_mutex); - if (!--sht->present && sht->proc_dir) { + e = __scsi_lookup_proc_entry(sht); + if (e && !--e->present) { remove_proc_entry(sht->proc_name, proc_scsi); - sht->proc_dir = NULL; + list_del(&e->entry); + kfree(e); } mutex_unlock(&global_host_template_mutex); } @@ -153,20 +217,29 @@ void scsi_proc_hostdir_rm(struct scsi_host_template *sht) */ void scsi_proc_host_add(struct Scsi_Host *shost) { - struct scsi_host_template *sht = shost->hostt; + const struct scsi_host_template *sht = shost->hostt; + struct scsi_proc_entry *e; struct proc_dir_entry *p; char name[10]; - if (!sht->proc_dir) + if (!sht->show_info) return; + e = scsi_lookup_proc_entry(sht); + if (!e) + goto err; + sprintf(name,"%d", shost->host_no); - p = proc_create_data(name, S_IRUGO | S_IWUSR, - sht->proc_dir, &proc_scsi_ops, shost); + p = proc_create_data(name, S_IRUGO | S_IWUSR, e->proc_dir, + &proc_scsi_ops, shost); if (!p) - printk(KERN_ERR "%s: Failed to register host %d in" - "%s\n", __func__, shost->host_no, - sht->proc_name); + goto err; + return; + +err: + shost_printk(KERN_ERR, shost, + "%s: Failed to register host (%s failed)\n", __func__, + e ? "proc_create_data()" : "scsi_proc_hostdir_add()"); } /** @@ -175,13 +248,19 @@ void scsi_proc_host_add(struct Scsi_Host *shost) */ void scsi_proc_host_rm(struct Scsi_Host *shost) { + const struct scsi_host_template *sht = shost->hostt; + struct scsi_proc_entry *e; char name[10]; - if (!shost->hostt->proc_dir) + if (!sht->show_info) + return; + + e = scsi_lookup_proc_entry(sht); + if (!e) return; sprintf(name,"%d", shost->host_no); - remove_proc_entry(name, shost->hostt->proc_dir); + remove_proc_entry(name, e->proc_dir); } /** * proc_print_scsidevice - return data about this host diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h index 3854ffcb0b3e..e71436183c0d 100644 --- a/include/scsi/scsi_host.h +++ b/include/scsi/scsi_host.h @@ -357,12 +357,6 @@ struct scsi_host_template { */ const char *proc_name; - /* - * Used to store the procfs directory if a driver implements the - * show_info method. - */ - struct proc_dir_entry *proc_dir; - /* * This determines if we will use a non-interrupt driven * or an interrupt driven scheme. It is set to the maximum number @@ -423,12 +417,6 @@ struct scsi_host_template { */ short cmd_per_lun; - /* - * present contains counter indicating how many boards of this - * type were found when we did the scan. - */ - unsigned char present; - /* If use block layer to manage tags, this is tag allocation policy */ int tag_alloc_policy; From patchwork Sat Oct 15 00:24:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 615668 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E0C1C4332F for ; Sat, 15 Oct 2022 00:24:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229712AbiJOAYn (ORCPT ); Fri, 14 Oct 2022 20:24:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229735AbiJOAYk (ORCPT ); Fri, 14 Oct 2022 20:24:40 -0400 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39BD6115E for ; Fri, 14 Oct 2022 17:24:38 -0700 (PDT) Received: by mail-pf1-f175.google.com with SMTP id i3so6295195pfk.9 for ; Fri, 14 Oct 2022 17:24:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=M3/UcHz4Yu/uLoBW7ZX3VNFRCJXoSeaQ3+8QJCWsGL0=; b=3Nww7lqHMLJlrAyr54vSJoRsq4xHV/8ffrOdxM5i/UWVHT/a7buoqG06KZI09LriTU zMhO32OazgrFKHynu8abeAYcl88uupRJzmOugdx7ZyueW5gsXev/vTLPj4z90lLEYnJm 7UU6RIePuzVYIeA6VPPOpu1wEMi4MXxqGfdZLkOx8otF8fPs9ySN30WYGr5Edc1axCVi NOjSLVaJqEkoD8qu/aHguVrZ4DX+C/AR1jg79dlZ2CoIWOosIXQ1NEUZhMQF9r9T/ajH W4JP7pT7wMSgecnw+dwOgut7Vxe0rfrNrOPzx0rDaR1diC2LrAhCpljkDdmg+KRA26hP hniw== X-Gm-Message-State: ACrzQf3kxkx8jk+pIiFz00GouzwFRS55ISExlqKnN+rYXhYRVhuwimuY UHxBWSJsVVoWFOFXdRJ+PaUJT9zwh6I= X-Google-Smtp-Source: AMsMyM5gtK6+vrRhG4ZdTqCKFR/Tkbp6E+sfPRATFz+j7tN3vVYpj2S9cR8SzrJ8VlkyjOTyzRz3ww== X-Received: by 2002:a65:674e:0:b0:43c:3b91:236e with SMTP id c14-20020a65674e000000b0043c3b91236emr427266pgu.510.1665793477951; Fri, 14 Oct 2022 17:24:37 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([98.51.102.78]) by smtp.gmail.com with ESMTPSA id y17-20020a634951000000b0046a1c832e9fsm1937953pgk.34.2022.10.14.17.24.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Oct 2022 17:24:37 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , Christoph Hellwig , Ming Lei , Hannes Reinecke , John Garry , Mike Christie , Krzysztof Kozlowski Subject: [PATCH v7 5/8] scsi: core: Rework scsi_single_lun_run() Date: Fri, 14 Oct 2022 17:24:15 -0700 Message-Id: <20221015002418.30955-6-bvanassche@acm.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221015002418.30955-1-bvanassche@acm.org> References: <20221015002418.30955-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Use __starget_for_each_device() instead of open-coding starget_for_each_device(). Run the queues asynchronously instead of synchronously. This patch removes code that calls scsi_device_put() from atomic context. Cc: Christoph Hellwig Cc: Ming Lei Cc: Hannes Reinecke Cc: John Garry Cc: Mike Christie Cc: Krzysztof Kozlowski Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_lib.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 8b89fab7c420..fa96d3cfdfa3 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -307,6 +307,18 @@ static void scsi_kick_queue(struct request_queue *q) blk_mq_run_hw_queues(q, false); } +/* + * Kick the queue of SCSI device @sdev if @sdev != current_sdev. Called with + * interrupts disabled. + */ +static void scsi_kick_sdev_queue(struct scsi_device *sdev, void *data) +{ + struct scsi_device *current_sdev = data; + + if (sdev != current_sdev) + blk_mq_run_hw_queues(sdev->request_queue, true); +} + /* * Called for single_lun devices on IO completion. Clear starget_sdev_user, * and call blk_run_queue for all the scsi_devices on the target - @@ -317,7 +329,6 @@ static void scsi_kick_queue(struct request_queue *q) static void scsi_single_lun_run(struct scsi_device *current_sdev) { struct Scsi_Host *shost = current_sdev->host; - struct scsi_device *sdev, *tmp; struct scsi_target *starget = scsi_target(current_sdev); unsigned long flags; @@ -334,22 +345,9 @@ static void scsi_single_lun_run(struct scsi_device *current_sdev) scsi_kick_queue(current_sdev->request_queue); spin_lock_irqsave(shost->host_lock, flags); - if (starget->starget_sdev_user) - goto out; - list_for_each_entry_safe(sdev, tmp, &starget->devices, - same_target_siblings) { - if (sdev == current_sdev) - continue; - if (scsi_device_get(sdev)) - continue; - - spin_unlock_irqrestore(shost->host_lock, flags); - scsi_kick_queue(sdev->request_queue); - spin_lock_irqsave(shost->host_lock, flags); - - scsi_device_put(sdev); - } - out: + if (!starget->starget_sdev_user) + __starget_for_each_device(starget, current_sdev, + scsi_kick_sdev_queue); spin_unlock_irqrestore(shost->host_lock, flags); } From patchwork Sat Oct 15 00:24:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 615373 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B25B9C4332F for ; Sat, 15 Oct 2022 00:24:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229582AbiJOAYr (ORCPT ); Fri, 14 Oct 2022 20:24:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229723AbiJOAYo (ORCPT ); Fri, 14 Oct 2022 20:24:44 -0400 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B7DC265E for ; Fri, 14 Oct 2022 17:24:40 -0700 (PDT) Received: by mail-pg1-f182.google.com with SMTP id f193so5703612pgc.0 for ; Fri, 14 Oct 2022 17:24:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EgkuSrNjHum1/Z6a5Iip+2bn6a7aorWuDIy1hT/cXe0=; b=dYOGJDdYbTP+URQinfu9u+l5M+oXqKH8eH5rK32keRtRoKG3vWiNSuarMR7uLf7AYx hnsbs6m1oq8ZHLPmNPfBSosmEelGBBaMzrgTsXlYws7Go3LnmKy1ggutERnQZtaHcH2J wi2EsAS13wK1nMJgmyX3n9MytosA3kkKgvjzQhGDMONBfvdFHkP10+FhUZldwgjsnmkc +dmvcbdjqJCjjeufTcudmSbWMpcXlZMe9/cigDZHNtJ4ztcmAwanlppX0BLQjsI2JpCU tbfrMIyDFLH0G5B3FCvwHaHx9PZdCoC0eOm7vKaj+7Eu4kh9jTkcnCJyDS+LXOZPLPdG O+mg== X-Gm-Message-State: ACrzQf1A6p+hQ7LnKZzrLj4iU07V3Kdr1ChC5/18TZ8SumW8lnhOX+3B SniHcveo4C9p5m0nCnYSSrg= X-Google-Smtp-Source: AMsMyM4zchBm15Omz2KBcGKdxuy1yzLUwPnE27hJ1wgHW0VQ6poIvjaKQrW37sOCQ9QLGUAipSHt9g== X-Received: by 2002:a63:4307:0:b0:464:a24d:8201 with SMTP id q7-20020a634307000000b00464a24d8201mr454525pga.116.1665793479523; Fri, 14 Oct 2022 17:24:39 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([98.51.102.78]) by smtp.gmail.com with ESMTPSA id y17-20020a634951000000b0046a1c832e9fsm1937953pgk.34.2022.10.14.17.24.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Oct 2022 17:24:38 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , Adrian Hunter , Avri Altman Subject: [PATCH v7 6/8] scsi: ufs: Simplify ufshcd_set_dev_pwr_mode() Date: Fri, 14 Oct 2022 17:24:16 -0700 Message-Id: <20221015002418.30955-7-bvanassche@acm.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221015002418.30955-1-bvanassche@acm.org> References: <20221015002418.30955-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Simplify the code for incrementing the SCSI device reference count in ufshcd_set_dev_pwr_mode(). This patch removes one scsi_device_put() call that happens from atomic context. Reviewed-by: Adrian Hunter Cc: Avri Altman Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufshcd.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 7256e6c43ca6..c8f0fe740005 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -8752,15 +8752,10 @@ static int ufshcd_set_dev_pwr_mode(struct ufs_hba *hba, spin_lock_irqsave(hba->host->host_lock, flags); sdp = hba->ufs_device_wlun; - if (sdp) { + if (sdp && scsi_device_online(sdp)) ret = scsi_device_get(sdp); - if (!ret && !scsi_device_online(sdp)) { - ret = -ENODEV; - scsi_device_put(sdp); - } - } else { + else ret = -ENODEV; - } spin_unlock_irqrestore(hba->host->host_lock, flags); if (ret) From patchwork Sat Oct 15 00:24:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 615667 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91AE8C433FE for ; Sat, 15 Oct 2022 00:25:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229749AbiJOAZA (ORCPT ); Fri, 14 Oct 2022 20:25:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229617AbiJOAYq (ORCPT ); Fri, 14 Oct 2022 20:24:46 -0400 Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0149F65E2 for ; Fri, 14 Oct 2022 17:24:42 -0700 (PDT) Received: by mail-pg1-f171.google.com with SMTP id u71so5682949pgd.2 for ; Fri, 14 Oct 2022 17:24:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7XmQEiLahFERiW82A0FHr4JWq40+ZHBdBXdCRFPHXPU=; b=tXy94ZoBAQNMlgHwbW5Tuv5Fj7lhBMF79o9NpajA7CTvKKJM8JkLEgsQbHdmuBffP6 PK9KGZc+fgsmsJgb5Nb8rvdx+ee0c22yUK7qTzCmb3UukE1MH+fM2pdZOH0aHz61lv0+ PF8DFIWk9EuaNxHsbkRAIQnDNLyvWwwE/a/e+w652Kjx106WreoJcTWqDaqDk0WweGnt xKAmWVeyGZ4Dc8R8lOLPLnxBmImKkv0vEmkoEYO4kpxudFO5ZUZDuvydPBckUZicuQoF U+Uol0u5bDC6D430Gyj2peeRFSSIAj+od8euMDsruUsYEtHB97IqKbA8pFQFe8A9eTgD djbw== X-Gm-Message-State: ACrzQf3dXOL8NjTvvQcVgFZWp4+2AzxIDR55xY9qI3caZgtLLua1aZwi tUhicP6PCPsNm0NK0DYvJmc= X-Google-Smtp-Source: AMsMyM4BgzRjmgxk854KS6b7ndXBpTo8K7dQG+X1aN3fUuSI3tteLPcaKaJCwOuVmPLB6EbW0V+MEQ== X-Received: by 2002:a05:6a00:ac6:b0:530:3197:48b6 with SMTP id c6-20020a056a000ac600b00530319748b6mr432052pfl.80.1665793481289; Fri, 14 Oct 2022 17:24:41 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([98.51.102.78]) by smtp.gmail.com with ESMTPSA id y17-20020a634951000000b0046a1c832e9fsm1937953pgk.34.2022.10.14.17.24.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Oct 2022 17:24:40 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , Christoph Hellwig , Ming Lei , Hannes Reinecke , Mike Christie , Krzysztof Kozlowski Subject: [PATCH v7 7/8] scsi: core: Remove the put_device() call from scsi_device_get() Date: Fri, 14 Oct 2022 17:24:17 -0700 Message-Id: <20221015002418.30955-8-bvanassche@acm.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221015002418.30955-1-bvanassche@acm.org> References: <20221015002418.30955-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org scsi_device_get() may be called from atomic context, e.g. by shost_for_each_device(). A later patch will allow put_device() to sleep for SCSI devices. Hence this patch that removes the put_device() call from scsi_device_get(). According to Rusty Russell's "Module Refcount and Stuff mini-FAQ", calling module_put() from atomic context is allowed since considerable time. See also https://lkml.org/lkml/2002/11/18/330. Cc: Christoph Hellwig Cc: Ming Lei Cc: Hannes Reinecke Cc: Mike Christie Cc: Krzysztof Kozlowski Signed-off-by: Bart Van Assche --- drivers/scsi/scsi.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c index c59eac7a32f2..9feb0323bc44 100644 --- a/drivers/scsi/scsi.c +++ b/drivers/scsi/scsi.c @@ -563,14 +563,14 @@ int scsi_device_get(struct scsi_device *sdev) { if (sdev->sdev_state == SDEV_DEL || sdev->sdev_state == SDEV_CANCEL) goto fail; - if (!get_device(&sdev->sdev_gendev)) - goto fail; if (!try_module_get(sdev->host->hostt->module)) - goto fail_put_device; + goto fail; + if (!get_device(&sdev->sdev_gendev)) + goto fail_put_module; return 0; -fail_put_device: - put_device(&sdev->sdev_gendev); +fail_put_module: + module_put(sdev->host->hostt->module); fail: return -ENXIO; } From patchwork Sat Oct 15 00:24:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 615372 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F13EEC4332F for ; Sat, 15 Oct 2022 00:25:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229762AbiJOAZB (ORCPT ); Fri, 14 Oct 2022 20:25:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229679AbiJOAYs (ORCPT ); Fri, 14 Oct 2022 20:24:48 -0400 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1344DF44 for ; Fri, 14 Oct 2022 17:24:43 -0700 (PDT) Received: by mail-pf1-f180.google.com with SMTP id d10so6313086pfh.6 for ; Fri, 14 Oct 2022 17:24:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=me3TZZ9YQv9Rupx9AI9XDyc6QvHjXPxe9brKdqSFDOA=; b=PprMoYuPjX10H52aze3aC36uHYZDHbfBaPwMZpqKuK9n+wqLt6A93VRbwqN5HDuCUz +WXycG/MYO0Sf0BbQNzd/3fHQ/mGQ6bIAUc0pDnwMwyFRsH6nqnXydmbRxv4XVThCzhl sse4wN0qG7oavVDbgQM3j881C4cyvlRKofVaxa1llgqwgkaEGAgdXdP2bziFyH6htaJa 68m+5mKg83zyITgFoHjQKZ63iBC98mZ8Id6YgmVD6D3dyVP+xmTMwCFoXCx3kkRkAWbh Pri2ZSU53FNfGOVlUyD0oaDsrcBhSqL8o8B7AxC/23SWDxtT2Etqs81Uiwj+pn15vTbZ W4IA== X-Gm-Message-State: ACrzQf3DqqpqPcyecuepyL6zBJNLXygLU5FMjAsXK2UOEbKtxi9qe/VR xXPP9bpAGpXrPdp2/E1OU4M= X-Google-Smtp-Source: AMsMyM7Oit/xGO96wJ6A5+HLsiAecKSxXhwbvEg1NAEbPm5A54WeMFTe/Ilj5rhJ81+8WicFAvPVpg== X-Received: by 2002:a63:5766:0:b0:440:2960:37d with SMTP id h38-20020a635766000000b004402960037dmr446200pgm.278.1665793482944; Fri, 14 Oct 2022 17:24:42 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([98.51.102.78]) by smtp.gmail.com with ESMTPSA id y17-20020a634951000000b0046a1c832e9fsm1937953pgk.34.2022.10.14.17.24.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Oct 2022 17:24:42 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , Christoph Hellwig , Ming Lei , Hannes Reinecke , John Garry , Mike Christie , Krzysztof Kozlowski Subject: [PATCH v7 8/8] scsi: core: Release SCSI devices synchronously Date: Fri, 14 Oct 2022 17:24:18 -0700 Message-Id: <20221015002418.30955-9-bvanassche@acm.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221015002418.30955-1-bvanassche@acm.org> References: <20221015002418.30955-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org All upstream scsi_device_put() calls happen from thread context. Hence simplify scsi_device_put() by always calling the release function synchronously. This patch prepares for constifying the SCSI host template by removing an assignment that clears the module pointer in the SCSI host template. scsi_device_dev_release_usercontext() was introduced in 2006 via commit 65110b216895 ("[SCSI] fix wrong context bugs in SCSI"). Cc: Christoph Hellwig Cc: Ming Lei Cc: Hannes Reinecke Cc: John Garry Cc: Mike Christie Cc: Krzysztof Kozlowski Signed-off-by: Bart Van Assche --- drivers/scsi/scsi.c | 2 ++ drivers/scsi/scsi_sysfs.c | 22 ++-------------------- include/scsi/scsi_device.h | 1 - 3 files changed, 4 insertions(+), 21 deletions(-) diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c index 9feb0323bc44..1426b9b03612 100644 --- a/drivers/scsi/scsi.c +++ b/drivers/scsi/scsi.c @@ -588,6 +588,8 @@ void scsi_device_put(struct scsi_device *sdev) { struct module *mod = sdev->host->hostt->module; + might_sleep(); + put_device(&sdev->sdev_gendev); module_put(mod); } diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c index c8b178983585..c76f5757b863 100644 --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c @@ -441,20 +441,15 @@ static void scsi_device_cls_release(struct device *class_dev) put_device(&sdev->sdev_gendev); } -static void scsi_device_dev_release_usercontext(struct work_struct *work) +static void scsi_device_dev_release(struct device *dev) { - struct scsi_device *sdev; + struct scsi_device *sdev = to_scsi_device(dev); struct device *parent; struct list_head *this, *tmp; struct scsi_vpd *vpd_pg80 = NULL, *vpd_pg83 = NULL; struct scsi_vpd *vpd_pg0 = NULL, *vpd_pg89 = NULL; struct scsi_vpd *vpd_pgb0 = NULL, *vpd_pgb1 = NULL, *vpd_pgb2 = NULL; unsigned long flags; - struct module *mod; - - sdev = container_of(work, struct scsi_device, ew.work); - - mod = sdev->host->hostt->module; parent = sdev->sdev_gendev.parent; @@ -516,19 +511,6 @@ 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); } static struct class sdev_class = { diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h index c36656d8ac6c..24bdbf7999ab 100644 --- a/include/scsi/scsi_device.h +++ b/include/scsi/scsi_device.h @@ -236,7 +236,6 @@ struct scsi_device { struct device sdev_gendev, sdev_dev; - struct execute_work ew; /* used to get process context on put */ struct work_struct requeue_work; struct scsi_device_handler *handler;