From patchwork Thu Sep 29 22:44: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: 12994708 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 F01A7C43217 for ; Thu, 29 Sep 2022 22:46:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230184AbiI2WqD (ORCPT ); Thu, 29 Sep 2022 18:46:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230263AbiI2Wpg (ORCPT ); Thu, 29 Sep 2022 18:45:36 -0400 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C82D6D48 for ; Thu, 29 Sep 2022 15:44:36 -0700 (PDT) Received: by mail-pf1-f172.google.com with SMTP id b23so2671805pfp.9 for ; Thu, 29 Sep 2022 15:44: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; bh=SpmXLmWlYQVnn1BcyLp3cCBXB/Od6Q2CqnBaVZAdo34=; b=P+lErRmtWJm0wipLhJxy8T9fToQRF/yToEN35cdLCCvlgyq8lIZ8BHYsFc6omx2hUM 2MWyXybqFYFB189UUEsa9lbKjlX+8w/qhenXs8PijHkjKVmUwWknVRDhFGl13l2NUCij Zdzu5bszELnSjcOjTW7JCF7FOc/Mh75atZoPaABJiv8zbmS413tc3X4zqtg29fIuxb5m syuok06JFp9OZBKfWfEbKMfxJu4Ue5ep+7Km6PN8B0yX0Epld3myl6ag4hKvrkF++zis co4/dFl2kHuFjAOy16gpl2CnaTacJJNxd4UonFPFXdu0kXM782AXaCuaiQ65myy8jhAS Yhkw== X-Gm-Message-State: ACrzQf0X1oKwO5fmCi4OyfTVxD+4lWtlVG0amg3DC36RUSxtKtX3rLas uQC+1c8hLsDU/YK/Ry3VHws= X-Google-Smtp-Source: AMsMyM4h6Uc/PckpHjHc7FlTEV86GP1oSE4/o4/RWpLCzV28fDS+qKAZrd9UHou33cRj9I8xcp6s6w== X-Received: by 2002:a05:6a00:1d9b:b0:541:1894:d5db with SMTP id z27-20020a056a001d9b00b005411894d5dbmr5701846pfw.78.1664491475826; Thu, 29 Sep 2022 15:44:35 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:56f2:482f:20c2:1d35]) by smtp.gmail.com with ESMTPSA id w22-20020a1709026f1600b0016d1b70872asm404508plk.134.2022.09.29.15.44.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Sep 2022 15:44:35 -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 , "James E.J. Bottomley" Subject: [PATCH v6 1/8] scsi: esas2r: Initialize two host template members implicitly Date: Thu, 29 Sep 2022 15:44:14 -0700 Message-Id: <20220929224421.587465-2-bvanassche@acm.org> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog In-Reply-To: <20220929224421.587465-1-bvanassche@acm.org> References: <20220929224421.587465-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 Thu Sep 29 22:44: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: 12994712 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 5A361C433F5 for ; Thu, 29 Sep 2022 22:46:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230213AbiI2WqL (ORCPT ); Thu, 29 Sep 2022 18:46:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230262AbiI2Wpg (ORCPT ); Thu, 29 Sep 2022 18:45:36 -0400 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C83DBD8C for ; Thu, 29 Sep 2022 15:44:38 -0700 (PDT) Received: by mail-pf1-f176.google.com with SMTP id b75so2682650pfb.7 for ; Thu, 29 Sep 2022 15:44: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; bh=GuaxyPekQwOEv+1YHUUtxyW6Rq419NNxCuDWec4VbOA=; b=054aFehUbXjphBX/3mP6DNCU0HWSJsx2j20q5jPMweEyKGzWagOb7B3SEkueqmu/CC mS4D6kXus5rJWBjHjx2H1WfFjMULg59zANmOrC0ydrh1D+GyaS0FysBihyMCEiMO1Vze uURjngzv9gOlZpsYIR9M6wqtbiYaN4uXWux2SELs/f0TLjo0SwQR186/Jetu6MmjqYly pSIFDoDdkSqCrwYwmVOD/S7CXVRnh4lW+x1YUYM+vZgKlnpy+0dOS4O8DHBd8Wz5rpnx Ypmt1PoewQxYyuwYIe6z6IVRoKhSQisQVJ/gRa1/BwU5nIIfNbehT9rXl//y+mjlq5SG xRhQ== X-Gm-Message-State: ACrzQf2+R52zQ3ssAz8FAwDKZZAGc+dXEG/MT46vZxfzKU95e16k8yuH qt/gqIquLzEXtQLdjfBrvu0= X-Google-Smtp-Source: AMsMyM4eYmdWUI/9D7JnW5z2QfC6bU22sdOUMBIGV8ixa4nqX5gkd8faks1o8oaNqFZxM4PjyWv9tA== X-Received: by 2002:a65:6e0f:0:b0:43a:1cd4:4ae6 with SMTP id bd15-20020a656e0f000000b0043a1cd44ae6mr4772174pgb.289.1664491477685; Thu, 29 Sep 2022 15:44:37 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:56f2:482f:20c2:1d35]) by smtp.gmail.com with ESMTPSA id w22-20020a1709026f1600b0016d1b70872asm404508plk.134.2022.09.29.15.44.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Sep 2022 15:44:37 -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 , "James E.J. Bottomley" Subject: [PATCH v6 2/8] scsi: esas2r: Introduce scsi_template_proc_dir() Date: Thu, 29 Sep 2022 15:44:15 -0700 Message-Id: <20220929224421.587465-3-bvanassche@acm.org> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog In-Reply-To: <20220929224421.587465-1-bvanassche@acm.org> References: <20220929224421.587465-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 aa7b7496c93a..c2b8427e0305 100644 --- a/include/scsi/scsi_host.h +++ b/include/scsi/scsi_host.h @@ -752,6 +752,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 Thu Sep 29 22:44: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: 12994710 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 96BA3C4332F for ; Thu, 29 Sep 2022 22:46:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230193AbiI2WqH (ORCPT ); Thu, 29 Sep 2022 18:46:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229636AbiI2Wpg (ORCPT ); Thu, 29 Sep 2022 18:45:36 -0400 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17CA32AC2 for ; Thu, 29 Sep 2022 15:44:40 -0700 (PDT) Received: by mail-pj1-f45.google.com with SMTP id u12so2657284pjj.1 for ; Thu, 29 Sep 2022 15:44: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; bh=Dga2FoWMsPDIzm7bQA4fn6a11AQGBoCeCg/M4Arbqr4=; b=fiGv+iUpNCQTtHjxC0jmVsUTb1XCS0+jl7FtTPtkvK9Heahrh7bkr6cy9CvGYbVdPd CH7zD/N4EhPl7cY0zTJqKhBwswFfuho503Cz5jyfslzaFiryv5zT1xZzzpyvyz+NIvXc 5MRsB2y/HMVUUuJtqSV/sibBO5HhtrHaDj3lPNuCIsfJ0T9eA+hzxZInF1WEmiWYdzwY ZM8ZI5n3fA3udwFelQPLdVHu57/eoc0vEyill8E2rf3GrdyokQt93wE/B4TmgVz7o96h m+XSdrIMq/KlG8zy+cB/4ehVTVabDyRRhvnIN2MZqSWFFTvIoH/uyxivWnlnHKiTbWm6 +Pvg== X-Gm-Message-State: ACrzQf1KOwY1v5oRhv5iPt/W46okmb0Ix8hmhcFcPtIaHuL4J+n4x9C0 MBjaBFK1w54WfCccNSB2wSo= X-Google-Smtp-Source: AMsMyM4aKh25aHSnVa7Kms7m5PMVYwzcUQNb4c+YST6HxXHRcMP+AaIKYsuB+nSqHBi4iddYIF+cKg== X-Received: by 2002:a17:90b:4f8d:b0:202:dd39:c03a with SMTP id qe13-20020a17090b4f8d00b00202dd39c03amr19154704pjb.71.1664491479490; Thu, 29 Sep 2022 15:44:39 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:56f2:482f:20c2:1d35]) by smtp.gmail.com with ESMTPSA id w22-20020a1709026f1600b0016d1b70872asm404508plk.134.2022.09.29.15.44.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Sep 2022 15:44:38 -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 , "James E.J. Bottomley" Subject: [PATCH v6 3/8] scsi: core: Fail host creation if creating the proc directory fails Date: Thu, 29 Sep 2022 15:44:16 -0700 Message-Id: <20220929224421.587465-4-bvanassche@acm.org> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog In-Reply-To: <20220929224421.587465-1-bvanassche@acm.org> References: <20220929224421.587465-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 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/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 0738238ed6cc..098d1970c451 100644 --- a/drivers/scsi/hosts.c +++ b/drivers/scsi/hosts.c @@ -517,7 +517,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 2b9e0559ddcb..a7da51bc22da 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 Thu Sep 29 22:44: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: 12994709 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 613A6C433FE for ; Thu, 29 Sep 2022 22:46:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230188AbiI2WqF (ORCPT ); Thu, 29 Sep 2022 18:46:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229494AbiI2Wpg (ORCPT ); Thu, 29 Sep 2022 18:45:36 -0400 Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3913B617F for ; Thu, 29 Sep 2022 15:44:42 -0700 (PDT) Received: by mail-pg1-f179.google.com with SMTP id c7so2655369pgt.11 for ; Thu, 29 Sep 2022 15:44: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; bh=fISvDpWTkp4Ttf1QjphjHfXikhuUQeXQ3c5SBemE8H4=; b=SsBb2HwL82Ta6dvKElrCLsIAF0FQ9k7tk3/AUC7IwpnVAStu4iaCiPXrzRce/ILqqr /a6xNGgL0eduJo77S11a238kHA/kiKcLlxwDikYU1/guYHbTFrnbH/+6PCcT55/UGwFu vXlzsg0nozPmfngMpBKQjd3jLI91SF2fahsC72bsUDKMwbl2ZdD1hFatbzyKZBFoAU86 oxfMTT4cez/5wZtd+yvcJhGNkhn5Kl6lyiriqUHSTN2kXmU5dVXC+SzbU+XEvIwxhrNa asT2WbFeUxZsNy6sZvoyMovJnMC97OlRjJ1LNSJ7lnJlBr9QtXpskw5CaRkMEy7NXHN1 lRQA== X-Gm-Message-State: ACrzQf2kHPq14w7vpgoQwiE4owV4df+a6bYX9GufGEORnhCwFJjD7eKP ojE8mx9EzrOh8awSX7GEXU4= X-Google-Smtp-Source: AMsMyM7BowzzOz+ckXZeUZ5aw9qE/Ie9md3O+UMHfGk6tHJEbD2Qiyy7AK3K/DaBlr2lhMwKcjTwAQ== X-Received: by 2002:a63:2b4b:0:b0:440:2963:5863 with SMTP id r72-20020a632b4b000000b0044029635863mr4741911pgr.28.1664491481419; Thu, 29 Sep 2022 15:44:41 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:56f2:482f:20c2:1d35]) by smtp.gmail.com with ESMTPSA id w22-20020a1709026f1600b0016d1b70872asm404508plk.134.2022.09.29.15.44.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Sep 2022 15:44:40 -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 , "James E.J. Bottomley" Subject: [PATCH v6 4/8] scsi: core: Introduce a new list for SCSI proc directory entries Date: Thu, 29 Sep 2022 15:44:17 -0700 Message-Id: <20220929224421.587465-5-bvanassche@acm.org> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog In-Reply-To: <20220929224421.587465-1-bvanassche@acm.org> References: <20220929224421.587465-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 a7da51bc22da..41bb763724f7 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 c2b8427e0305..f2294d44013c 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 Thu Sep 29 22:44: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: 12994711 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 2DE82C433F5 for ; Thu, 29 Sep 2022 22:46:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229713AbiI2WqJ (ORCPT ); Thu, 29 Sep 2022 18:46:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230259AbiI2Wph (ORCPT ); Thu, 29 Sep 2022 18:45:37 -0400 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD9FF63AF for ; Thu, 29 Sep 2022 15:44:43 -0700 (PDT) Received: by mail-pj1-f42.google.com with SMTP id r8-20020a17090a560800b00205eaaba073so2672065pjf.1 for ; Thu, 29 Sep 2022 15:44: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; bh=mBpdDy9J/eQ+4T5DAwBleE+5EWJWfVngpI443pompXc=; b=fGPssS17M2KXt+hN2iigj5PZrw35UVIBaklGHm4EHo11WZ/iJMkeLBh3Th03lOzvqi vbiETC4jYp+HVX7EyWUeUuswrYnUTJDQfl0TeDfBnTgdKlKbpBWyriyjedW4F9dqzk2n QvxT5dfVOmhNGs+2phRTi9eMZQWP+5vKWP9vAnqWUZgFGPYggsQroOMJgYBEcVxQJj27 KURlSDC9W1pk8BjSI2vwHq40zc1WE41U+Ogb8jbS5uRPxVv9E2UGUHjL1Cm3KjOTkPnO dRjkwE/XIzDLrs8MJbP4B9s8vl9wFP3FTv3FwuNTmvjvmSxbpMcUljjDgPLT+xN/MWcH WlGA== X-Gm-Message-State: ACrzQf0vfGxz02nM5sephoUA8947bMhjTRTRspQik6UawwmUiSG5DOZr QuqilaXYzCdJ1TAyMGZt1Aw= X-Google-Smtp-Source: AMsMyM6yvrTdyeJrXJnEdYGnScbds12z/NIoeS9pCuNAZn/NAwglcViFRVoZcWLaweDg/FXZf+l4Ow== X-Received: by 2002:a17:902:ecd2:b0:178:3b53:ebf7 with SMTP id a18-20020a170902ecd200b001783b53ebf7mr5380436plh.28.1664491483172; Thu, 29 Sep 2022 15:44:43 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:56f2:482f:20c2:1d35]) by smtp.gmail.com with ESMTPSA id w22-20020a1709026f1600b0016d1b70872asm404508plk.134.2022.09.29.15.44.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Sep 2022 15:44: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 , "James E.J. Bottomley" Subject: [PATCH v6 5/8] scsi: core: Rework scsi_single_lun_run() Date: Thu, 29 Sep 2022 15:44:18 -0700 Message-Id: <20220929224421.587465-6-bvanassche@acm.org> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog In-Reply-To: <20220929224421.587465-1-bvanassche@acm.org> References: <20220929224421.587465-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(). 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 473d9403f0c1..da1e6f9f9221 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -302,6 +302,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 - @@ -312,7 +324,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; @@ -329,22 +340,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 Thu Sep 29 22:44:19 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: 12994713 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 12397C4332F for ; Thu, 29 Sep 2022 22:46:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230226AbiI2WqM (ORCPT ); Thu, 29 Sep 2022 18:46:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229764AbiI2Wpn (ORCPT ); Thu, 29 Sep 2022 18:45:43 -0400 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84E41205D4 for ; Thu, 29 Sep 2022 15:44:52 -0700 (PDT) Received: by mail-pf1-f173.google.com with SMTP id w2so2718360pfb.0 for ; Thu, 29 Sep 2022 15:44:52 -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; bh=RZcV9LBa/cv0m+Kpk45TstAi3vY3bw2i/LMaNRSAq4Q=; b=6tvYSHcDctQdQdnH892+vwTUXqbhS1SWfw4g+pZAuheV4wJuIMndjsawYFEAP9zmJD ci2zpHh3p37Je9LQBkPm2r3rrmxWfk+P60RNo+5B6pL5bx4LXZkgxyxa1yx0McQvysD0 hLRCxTw1j8LMa7BcqeQnd1ggYUSj+JcmITOPV6H0MY/S33ZUizveMDaMDvG2AnqS7r8L GuUtNtuHGjKj0AHpMJg1pmjLZZgs2kAu5KJlde29/K/STVA/jZ71mzzB8IEbnwieq7A1 adOwuGsUrc7lhBH815GJ6Kz107DwP9IaMeMO27AEWtJTVN6q2om7HtlyizQA+N/IOzRq ENWA== X-Gm-Message-State: ACrzQf1sQljqLNcMIWTpkwvB7itajCF/pRypCl65D7iWObC5nO+KQ5TT McyVC0em2MDPX5w6XbSM4w3u7r3PGvw= X-Google-Smtp-Source: AMsMyM4ukYFxDvg99vEBbRJycZO31GPYJUgD7KZJPZpE7i+7IOmuFC0ffjMyTs0Mq8G9fY5GR4ggRA== X-Received: by 2002:a62:84c6:0:b0:538:3c39:5819 with SMTP id k189-20020a6284c6000000b005383c395819mr5805887pfd.4.1664491491716; Thu, 29 Sep 2022 15:44:51 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:56f2:482f:20c2:1d35]) by smtp.gmail.com with ESMTPSA id w22-20020a1709026f1600b0016d1b70872asm404508plk.134.2022.09.29.15.44.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Sep 2022 15:44:51 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , Adrian Hunter , Avri Altman , "James E.J. Bottomley" , Bean Huo , Jinyoung Choi Subject: [PATCH v6 6/8] scsi: ufs: Simplify ufshcd_set_dev_pwr_mode() Date: Thu, 29 Sep 2022 15:44:19 -0700 Message-Id: <20220929224421.587465-7-bvanassche@acm.org> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog In-Reply-To: <20220929224421.587465-1-bvanassche@acm.org> References: <20220929224421.587465-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. Cc: Adrian Hunter Cc: Avri Altman Signed-off-by: Bart Van Assche Reviewed-by: Adrian Hunter --- 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 7c15cbc737b4..6e61372fe027 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -8753,15 +8753,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 Thu Sep 29 22:44:20 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: 12994714 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 C8979C433F5 for ; Thu, 29 Sep 2022 22:46:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230227AbiI2WqN (ORCPT ); Thu, 29 Sep 2022 18:46:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230018AbiI2Wpo (ORCPT ); Thu, 29 Sep 2022 18:45:44 -0400 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF70126109 for ; Thu, 29 Sep 2022 15:44:53 -0700 (PDT) Received: by mail-pf1-f171.google.com with SMTP id b23so2672301pfp.9 for ; Thu, 29 Sep 2022 15:44:53 -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; bh=oHIU87340HTf+1cVSJxwNoDJwwchCbWiuG0K/QTNUSs=; b=Y8/cKYuDH0bUvCI8EGwzTdpB4JcWsTAiG+nIkNM9C6mspOX1C1RWSu4B5iaFel8B81 +HmnATt9jbc6QK2HSHses6go2Q471YuPoRGAAw2cHN49cptxaeiiCaEIhgTbAb5n5/hV LrcqDvF19HzZW4JF2zFKo3LAL5O0NPT1+PAew9YV9867YnphZ2jv0Kglqlp+Y3uIACDM vDfxYqMRwTWx6Dfw6Hz3i07jjDL2jPgbjad3K6+qpJfZEnC7RXo72FYoQbwHYb9Yyej0 8SJeMBoXNuiPiG5PTE0iGsVpt7oFS/AcYsOg/L7ubmMy9WguOM+zSoxoQZlbdUhlvD4z 192g== X-Gm-Message-State: ACrzQf2OjrlqrgKKUupAtk7HsX+9FpfFrkeYEMTVptpR0uzrMtabEyrW SZyt3huD+JzbnYG2MdrykWA= X-Google-Smtp-Source: AMsMyM5H7cVk2uB5hRYdx+9ALRAlNk23zETlgpM4/xjmT9cjzowv06c74wrdJgdQs0385IZJJKeMwQ== X-Received: by 2002:a63:1455:0:b0:438:e26b:ab1f with SMTP id 21-20020a631455000000b00438e26bab1fmr4745981pgu.183.1664491493410; Thu, 29 Sep 2022 15:44:53 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:56f2:482f:20c2:1d35]) by smtp.gmail.com with ESMTPSA id w22-20020a1709026f1600b0016d1b70872asm404508plk.134.2022.09.29.15.44.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Sep 2022 15:44:52 -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 , "James E.J. Bottomley" Subject: [PATCH v6 7/8] scsi: core: Remove the put_device() call from scsi_device_get() Date: Thu, 29 Sep 2022 15:44:20 -0700 Message-Id: <20220929224421.587465-8-bvanassche@acm.org> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog In-Reply-To: <20220929224421.587465-1-bvanassche@acm.org> References: <20220929224421.587465-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 086ec5b5862d..87bddd697fc6 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 Thu Sep 29 22:44:21 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: 12994715 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 3D3B6C433FE for ; Thu, 29 Sep 2022 22:46:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230060AbiI2WqP (ORCPT ); Thu, 29 Sep 2022 18:46:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230057AbiI2Wpp (ORCPT ); Thu, 29 Sep 2022 18:45:45 -0400 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD52427157 for ; Thu, 29 Sep 2022 15:44:55 -0700 (PDT) Received: by mail-pg1-f169.google.com with SMTP id 78so2650573pgb.13 for ; Thu, 29 Sep 2022 15:44:55 -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; bh=ggFXFXw8GzFeqSEw6TpqlKsVewsEFnUk9jps5x5QML4=; b=Xbor8gAUzr6dJhTzIfDuRrwzOJZlM4QOaU0IHS1qck/Cag9j5CcbT0pDvUj7vKIFHj ie3l8X4iH5asNa6TXJ7ZXBWSUmz8JRfUNqqLBxJFRPIhC/ZJE0g4c7dWiIwFIXUtppGx Zpi77PXHhwRm9vAUZJlU6AP3vDKMlvV0qr9a2VymJr0Jqy1CPCE6o8a9CqDNo1BJdk5x c1nxck/2z+sNyYxMn7Jl+eJxaofaDSR4f9Vmvk/Tp5L1dKXYs3Q8NPZ67LqvuX+ETC4w 5ntWb8m8hcNbbdjAfVeSc36zy/fIlJmPDSZfmL0XduFI2NueVR/nx5oZl8m5HG4bAanx 1GQQ== X-Gm-Message-State: ACrzQf0efCIJPnIpU/ysRgyu504tqcSiqxDeINxL/x0CupPvYEXyupXB 1/k/OCLQWotsM5dJj7v3xcw= X-Google-Smtp-Source: AMsMyM7vRKf4X2n4/jPeJ7KvPAY2T4LSkmrW+YjJ+WLooFfjmxTAZBhHmmH4cj1aap05PPYtEPE4wQ== X-Received: by 2002:a63:2cc2:0:b0:41c:681d:60d2 with SMTP id s185-20020a632cc2000000b0041c681d60d2mr4677805pgs.502.1664491495222; Thu, 29 Sep 2022 15:44:55 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:56f2:482f:20c2:1d35]) by smtp.gmail.com with ESMTPSA id w22-20020a1709026f1600b0016d1b70872asm404508plk.134.2022.09.29.15.44.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Sep 2022 15:44:54 -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 , "James E.J. Bottomley" Subject: [PATCH v6 8/8] scsi: core: Release SCSI devices synchronously Date: Thu, 29 Sep 2022 15:44:21 -0700 Message-Id: <20220929224421.587465-9-bvanassche@acm.org> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog In-Reply-To: <20220929224421.587465-1-bvanassche@acm.org> References: <20220929224421.587465-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 | 12 ++---------- include/scsi/scsi_device.h | 1 - 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c index 87bddd697fc6..e8bc4db297ab 100644 --- a/drivers/scsi/scsi.c +++ b/drivers/scsi/scsi.c @@ -586,6 +586,8 @@ EXPORT_SYMBOL(scsi_device_get); */ void scsi_device_put(struct scsi_device *sdev) { + might_sleep(); + /* * Decreasing the module reference count before the device reference * count is safe since scsi_remove_host() only returns after all diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c index dc4bda4d2319..dd8e0d0399cd 100644 --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c @@ -441,10 +441,9 @@ 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 = container_of(work, struct scsi_device, - ew.work); + struct scsi_device *sdev = to_scsi_device(dev); struct scsi_target *starget = sdev->sdev_target; struct device *parent; struct list_head *this, *tmp; @@ -518,13 +517,6 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work) put_device(parent); } -static void scsi_device_dev_release(struct device *dev) -{ - struct scsi_device *sdp = to_scsi_device(dev); - execute_in_process_context(scsi_device_dev_release_usercontext, - &sdp->ew); -} - static struct class sdev_class = { .name = "scsi_device", .dev_release = scsi_device_cls_release, diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h index 78039d1ec405..fa6070ce8b9b 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;