Miscellaneous patches and bug fixes
cover Miscellaneous patches and bug fixes
This patch series adds few improvements to the cxlflash driver and it also contains couple of bug fixes.
This patch series is intended for 4.18 and is bisectable.
Matthew R. Ochs (1):
cxlflash: Use local mutex for AFU serialization
Uma Krishnan (6):
cxlflash: Yield to active send threads
cxlflash: Limit the debug logs in the IO path
cxlflash: Acquire semaphore before invoking ioctl services
cxlflash: Add include guards to backend.h
cxlflash: Abstract hardware dependent assignments
cxlflash: Isolate external module dependencies
drivers/scsi/cxlflash/Kconfig | 2 +- drivers/scsi/cxlflash/Makefile | 4 +++- drivers/scsi/cxlflash/backend.h | 5 +++++ drivers/scsi/cxlflash/common.h | 1 + drivers/scsi/cxlflash/lunmgt.c | 4 +++- drivers/scsi/cxlflash/main.c | 21 +++++++++------------ drivers/scsi/cxlflash/main.h | 20 ++++++++++++++++++++ drivers/scsi/cxlflash/superpipe.c | 9 ++++++++- drivers/scsi/cxlflash/vlun.c | 3 ++- 9 files changed, 52 insertions(+), 17 deletions(-)
Signature · 1 line
2.1.0
PATCH 1/7 cxlflash: Yield to active send threads
The following Oops may be encountered if the device is reset, i.e. EEH recovery, while there is heavy I/O traffic:
59:mon> t
[c000200db64bb680] c008000009264c40 cxlflash_queuecommand+0x3b8/0x500
[cxlflash]
[c000200db64bb770] c00000000090d3b0 scsi_dispatch_cmd+0x130/0x2f0 [c000200db64bb7f0] c00000000090fdd8 scsi_request_fn+0x3c8/0x8d0 [c000200db64bb900] c00000000067f528 __blk_run_queue+0x68/0xb0 [c000200db64bb930] c00000000067ab80 __elv_add_request+0x140/0x3c0 [c000200db64bb9b0] c00000000068daac blk_execute_rq_nowait+0xec/0x1a0 [c000200db64bba00] c00000000068dbb0 blk_execute_rq+0x50/0xe0 [c000200db64bba50] c0000000006b2040 sg_io+0x1f0/0x520 [c000200db64bbaf0] c0000000006b2e94 scsi_cmd_ioctl+0x534/0x610 [c000200db64bbc20] c000000000926208 sd_ioctl+0x118/0x280 [c000200db64bbcc0] c00000000069f7ac blkdev_ioctl+0x7fc/0xe30 [c000200db64bbd20] c000000000439204 block_ioctl+0x84/0xa0 [c000200db64bbd40] c0000000003f8514 do_vfs_ioctl+0xd4/0xa00 [c000200db64bbde0] c0000000003f8f04 SyS_ioctl+0xc4/0x130 [c000200db64bbe30] c00000000000b184 system_call+0x58/0x6c
When there is no room to send the I/O request, the cached room is refreshed by reading the memory mapped command room value from the AFU. The AFU register mapping is refreshed during a reset, creating a race condition that can lead to the Oops above.
During a device reset, the AFU should not be unmapped until all the active send threads quiesce. An atomic counter, cmds_active, is currently used to track internal AFU commands and quiesce during reset. This same counter can also be used for the active send threads.
--- drivers/scsi/cxlflash/main.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/scsi/cxlflash/main.c +2 -0
@@ -616,6 +616,7 @@ static int cxlflash_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scp) rc =0 ; goto out;default : +atomic_inc (&afu->cmds_active);break ; }
@@ -641,6 +642,7 @@ static int cxlflash_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scp)memcpy (cmd->rcb.cdb, scp->cmnd,sizeof (cmd->rcb.cdb)); rc = afu->send_cmd (afu, cmd); +atomic_dec (&afu->cmds_active); out:return rc; }
Signature · 1 line
2.1.0
PATCH 2/7 cxlflash: Limit the debug logs in the IO path
In reply to Uma KrishnanThe kernel log can get filled with debug messages from send_cmd_ioarrin() when dynamic debug is enabled for the cxlflash module and there is a lot of legacy I/O traffic.
While these messages are necessary to debug issues that involve command tracking, the abundance of data can overwrite other useful data in the log. The best option available is to limit the messages that should serve most of the common use cases.
--- drivers/scsi/cxlflash/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/cxlflash/main.c +2 -2
@@ -339,8 +339,8 @@ static int send_cmd_ioarrin(struct afu *afu, struct afu_cmd *cmd)writeq_be ((u64)&cmd->rcb, &hwq->host_map->ioarrin); out:spin_unlock_irqrestore (&hwq->hsq_slock, lock_flags); -dev_dbg (dev,"%s: cmd=%p len=%u ea=%016llx rc=%d\n" , __func__, - cmd, cmd->rcb.data_len, cmd->rcb.data_ea, rc); +dev_dbg_ratelimited (dev,"%s: cmd=%p len=%u ea=%016llx rc=%d\n" , + __func__, cmd, cmd->rcb.data_len, cmd->rcb.data_ea, rc);return rc; }
Signature · 1 line
2.1.0
PATCH 3/7 cxlflash: Acquire semaphore before invoking ioctl services
In reply to Uma KrishnanWhen a superpipe process that makes use of virtual LUNs is terminated or killed abruptly, there is a possibility that the cxlflash driver could hang and deprive other operations on the adapter.
The release fop registered to be invoked on a context close, detaches every LUN associated with the context. The underlying service to detach the LUN assumes it has been called with the read semaphore held, and releases the semaphore before any operation that could be time consuming.
When invoked without holding the read semaphore, an opportunity is created for the semaphore's count to become negative when it is temporarily released during one of these potential lengthy operations. This negative count results in subsequent acquisition attempts taking forever, leading to the hang.
To support the current design point of holding the semaphore on the ioctl() paths, the release fop should acquire it before invoking any ioctl services.
--- drivers/scsi/cxlflash/superpipe.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/scsi/cxlflash/superpipe.c +6 -0
@@ -988,6 +988,10 @@ static int cxlflash_disk_detach(struct scsi_device *sdev,* theoretically never occur), every call into this routine results * in a complete freeing of a context. * +* Detaching the LUN is typically an ioctl() operation and the underlying +* code assumes that ioctl_rwsem has been acquired as a reader. To support +* that design point, the semaphore is acquired and released around detach. +* * Return: 0 on success */ static int cxlflash_cxl_release (struct inode *inode,struct file *file)
@@ -1026,9 +1030,11 @@ static int cxlflash_cxl_release(struct inode *inode, struct file *file)dev_dbg (dev,"%s: close for ctxid=%d\n" , __func__, ctxid); +down_read (&cfg->ioctl_rwsem); detach.context_id = ctxi->ctxid;list_for_each_entry_safe (lun_access, t, &ctxi->luns, list)_cxlflash_disk_detach (lun_access->sdev, ctxi, &detach); +up_read (&cfg->ioctl_rwsem); out_release: cfg->ops->fd_release (inode, file); out:
Signature · 1 line
2.1.0
PATCH 4/7 cxlflash: Use local mutex for AFU serialization
In reply to Uma KrishnanFrom: "Matthew R. Ochs" <[email protected]>
AFUs can only process a single AFU command at a time. This is enforced with a global mutex situated within the AFU send routine. As this mutex has a global scope, it has the potential to unnecessarily block commands destined for other AFUs.
Instead of using a global mutex, transition the mutex to be per-AFU. This will allow commands to only be blocked by siblings of the same AFU.
--- drivers/scsi/cxlflash/common.h | 1 + drivers/scsi/cxlflash/main.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-)
drivers/scsi/cxlflash/common.h +1 -0
@@ -240,6 +240,7 @@ struct afu {struct cxlflash_afu_map __iomem *afu_map;/* entire MMIO map */ atomic_t cmds_active;/* Number of currently active AFU commands */ +struct mutex sync_active;/* Mutex to serialize AFU commands */ u64 hb;u32 internal_lun;/* User-desired LUN mode for this AFU */
drivers/scsi/cxlflash/main.c +3 -3
@@ -2126,6 +2126,7 @@ static int init_afu(struct cxlflash_cfg *cfg) cfg->ops->perst_reloads_same_image (cfg->afu_cookie, true); +mutex_init (&afu->sync_active); afu->num_hwqs = afu->desired_hwqs;for (i =0 ; i < afu->num_hwqs; i++) { rc =init_mc (cfg, i);
@@ -2309,7 +2310,6 @@ static int send_afu_cmd(struct afu *afu, struct sisl_ioarcb *rcb)char *buf =NULL ;int rc =0 ;int nretry =0 ; -static DEFINE_MUTEX (sync_active);if (cfg->state !=STATE_NORMAL ) { dev_dbg(dev, "%s: Sync not required state=%u\n",
@@ -2317,7 +2317,7 @@ static int send_afu_cmd(struct afu *afu, struct sisl_ioarcb *rcb)return 0 ; } -mutex_lock (&sync_active); +mutex_lock (&afu->sync_active);atomic_inc (&afu->cmds_active); buf = kmalloc(sizeof(*cmd) + __alignof__(*cmd) - 1, GFP_KERNEL);if (unlikely (!buf)) {
@@ -2372,7 +2372,7 @@ static int send_afu_cmd(struct afu *afu, struct sisl_ioarcb *rcb) *rcb->ioasa = cmd->sa; out:atomic_dec (&afu->cmds_active); -mutex_unlock (&sync_active); +mutex_unlock (&afu->sync_active);kfree (buf);dev_dbg (dev,"%s: returning rc=%d\n" , __func__, rc);return rc;
Signature · 1 line
2.1.0
PATCH 5/7 cxlflash: Add include guards to backend.h
In reply to Uma KrishnanThe new header file, backend.h, that was recently added is missing the include guards. This commit adds the guards.
--- drivers/scsi/cxlflash/backend.h | 5 +++++ 1 file changed, 5 insertions(+)
drivers/scsi/cxlflash/backend.h +5 -0
@@ -12,6 +12,9 @@* 2 of the License, or (at your option) any later version. */ +#ifndef _CXLFLASH_BACKEND_H +#define _CXLFLASH_BACKEND_H +extern const struct cxlflash_backend_ops cxlflash_cxl_ops;extern const struct cxlflash_backend_ops cxlflash_ocxl_ops;
@@ -45,3 +48,5 @@ struct cxlflash_backend_ops {int (*fd_mmap)(struct file *file,struct vm_area_struct *vm); int (*fd_release)(struct inode *inode, struct file *file); }; + +#endif /* _CXLFLASH_BACKEND_H */
Signature · 1 line
2.1.0
PATCH 6/7 cxlflash: Abstract hardware dependent assignments
In reply to Uma KrishnanAs a staging cleanup to support transport specific builds of the cxlflash module, relocate device dependent assignments to header files. This will avoid littering the core driver with conditional compilation logic.
--- drivers/scsi/cxlflash/main.c | 7 ++----- drivers/scsi/cxlflash/main.h | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-)
drivers/scsi/cxlflash/main.c +2 -5
@@ -3708,11 +3708,8 @@ static int cxlflash_probe(struct pci_dev *pdev, cfg->init_state =INIT_STATE_NONE ; cfg->dev = pdev; cfg->cxl_fops = cxlflash_cxl_fops; - -if (ddv->flags &CXLFLASH_OCXL_DEV ) - cfg->ops = &cxlflash_ocxl_ops; -else - cfg->ops = &cxlflash_cxl_ops; + cfg->ops =cxlflash_assign_ops (ddv); +WARN_ON_ONCE (!cfg->ops);/* * Promoted LUNs move to the top of the LUN table. The rest stay on
drivers/scsi/cxlflash/main.h +15 -0
@@ -20,6 +20,8 @@#include <scsi/scsi.h> #include <scsi/scsi_device.h> +#include "backend.h" +#define CXLFLASH_NAME "cxlflash"#define CXLFLASH_ADAPTER_NAME "IBM POWER CXL Flash Adapter"#define CXLFLASH_MAX_ADAPTERS 32
@@ -100,6 +102,19 @@ struct dev_dependent_vals {#define CXLFLASH_OCXL_DEV 0x0000000000000004ULL }; +static inline const struct cxlflash_backend_ops * +cxlflash_assign_ops (struct dev_dependent_vals *ddv) +{ +const struct cxlflash_backend_ops *ops =NULL ; + +if (ddv->flags &CXLFLASH_OCXL_DEV ) + ops = &cxlflash_ocxl_ops; +if (!(ddv->flags &CXLFLASH_OCXL_DEV )) + ops = &cxlflash_cxl_ops; + +return ops; +} +struct asyc_intr_info {u64 status;char *desc;
Signature · 1 line
2.1.0
PATCH 7/7 cxlflash: Isolate external module dependencies
In reply to Uma KrishnanDepending on the underlying transport, cxlflash has a dependency on either the CXL or OCXL drivers, which are enabled via their Kconfig option. Instead of having a module wide dependency on these config options, it is better to isolate the object modules that are dependent on the CXL and OCXL drivers and adjust the module dependencies accordingly.
This commit isolates the object files that are dependent on CXL and/or OCXL. The cxl/ocxl fops used in the core driver are tucked under an ifdef to avoid compilation errors.
--- drivers/scsi/cxlflash/Kconfig | 2 +- drivers/scsi/cxlflash/Makefile | 4 +++- drivers/scsi/cxlflash/lunmgt.c | 4 +++- drivers/scsi/cxlflash/main.c | 2 -- drivers/scsi/cxlflash/main.h | 5 +++++ drivers/scsi/cxlflash/superpipe.c | 3 ++- drivers/scsi/cxlflash/vlun.c | 3 ++- 7 files changed, 16 insertions(+), 7 deletions(-)
drivers/scsi/cxlflash/Kconfig +1 -1
@@ -4,7 +4,7 @@ config CXLFLASH tristate "Support for IBM CAPI Flash" - depends on PCI && SCSI && CXL && OCXL && EEH + depends on PCI && SCSI && (CXL || OCXL) && EEH select IRQ_POLL default m help
drivers/scsi/cxlflash/Makefile +3 -1
@@ -1,2 +1,4 @@ obj-$(CONFIG_CXLFLASH) += cxlflash.o -cxlflash-y += main.o superpipe.o lunmgt.o vlun.o cxl_hw.o ocxl_hw.o +cxlflash-y += main.o superpipe.o lunmgt.o vlun.o +cxlflash-$(CONFIG_CXL) += cxl_hw.o +cxlflash-$(CONFIG_OCXL) += ocxl_hw.o
drivers/scsi/cxlflash/lunmgt.c +3 -1
@@ -12,9 +12,11 @@* 2 of the License, or (at your option) any later version. */ -#include <misc/cxl.h> #include <asm/unaligned.h> +#include <linux/interrupt.h> +#include <linux/pci.h> +#include <scsi/scsi_host.h> #include <uapi/scsi/cxlflash_ioctl.h>
drivers/scsi/cxlflash/main.c +0 -2
@@ -19,8 +19,6 @@#include <asm/unaligned.h> -#include <misc/cxl.h> -#include <scsi/scsi_cmnd.h> #include <scsi/scsi_host.h> #include <uapi/scsi/cxlflash_ioctl.h>
drivers/scsi/cxlflash/main.h +5 -0
@@ -107,10 +107,15 @@ cxlflash_assign_ops(struct dev_dependent_vals *ddv) {const struct cxlflash_backend_ops *ops =NULL ; +#ifdef CONFIG_OCXL if (ddv->flags &CXLFLASH_OCXL_DEV ) ops = &cxlflash_ocxl_ops; +#endif + +#ifdef CONFIG_CXL if (!(ddv->flags &CXLFLASH_OCXL_DEV )) ops = &cxlflash_cxl_ops; +#endif return ops; }
drivers/scsi/cxlflash/superpipe.c +2 -1
@@ -14,8 +14,9 @@#include <linux/delay.h> #include <linux/file.h> +#include <linux/interrupt.h> +#include <linux/pci.h> #include <linux/syscalls.h> -#include <misc/cxl.h> #include <asm/unaligned.h> #include <scsi/scsi.h>
drivers/scsi/cxlflash/vlun.c +2 -1
@@ -12,8 +12,9 @@* 2 of the License, or (at your option) any later version. */ +#include <linux/interrupt.h> +#include <linux/pci.h> #include <linux/syscalls.h> -#include <misc/cxl.h> #include <asm/unaligned.h> #include <asm/bitsperlong.h>
Signature · 1 line
2.1.0
Re: [PATCH 1/7] cxlflash: Yield to active send threads
In reply to Uma KrishnanQuoted 26 lines · Uma Krishnan
The following Oops may be encountered if the device is reset, i.e. EEH recovery, while there is heavy I/O traffic:
59:mon> t
[c000200db64bb680]c008000009264c40cxlflash_queuecommand+0x3b8/0x500
[cxlflash]
[c000200db64bb770]c00000000090d3b0scsi_dispatch_cmd+0x130/0x2f0[c000200db64bb7f0]c00000000090fdd8scsi_request_fn+0x3c8/0x8d0[c000200db64bb900]c00000000067f528__blk_run_queue+0x68/0xb0[c000200db64bb930]c00000000067ab80__elv_add_request+0x140/0x3c0[c000200db64bb9b0]c00000000068daacblk_execute_rq_nowait+0xec/0x1a0[c000200db64bba00]c00000000068dbb0blk_execute_rq+0x50/0xe0[c000200db64bba50]c0000000006b2040sg_io+0x1f0/0x520[c000200db64bbaf0]c0000000006b2e94scsi_cmd_ioctl+0x534/0x610[c000200db64bbc20]c000000000926208sd_ioctl+0x118/0x280[c000200db64bbcc0]c00000000069f7acblkdev_ioctl+0x7fc/0xe30[c000200db64bbd20]c000000000439204block_ioctl+0x84/0xa0[c000200db64bbd40]c0000000003f8514do_vfs_ioctl+0xd4/0xa00[c000200db64bbde0]c0000000003f8f04SyS_ioctl+0xc4/0x130[c000200db64bbe30]c00000000000b184system_call+0x58/0x6cWhen there is no room to send the I/O request, the cached room is refreshed by reading the memory mapped command room value from the AFU. The AFU register mapping is refreshed during a reset, creating a race condition that can lead to the Oops above.
Quoted 6 lines
During a device reset, the AFU should not be unmapped until all the active send threads quiesce. An atomic counter,
cmds_active, is currently used to track internal AFU commands and quiesce during reset. This same counter can also be used for the active send threads.Signed-off-by Uma Krishnan <[email protected]>
Re: [PATCH 2/7] cxlflash: Limit the debug logs in the IO path
In reply to Uma KrishnanQuoted 10 lines · Uma Krishnan
The kernel log can get filled with debug messages from
send_cmd_ioarrin()when dynamic debug is enabled for the cxlflash module and there is a lot of legacy I/O traffic.While these messages are necessary to debug issues that involve command tracking, the abundance of data can overwrite other useful data in the log. The best option available is to limit the messages that should serve most of the common use cases.
Signed-off-by Uma Krishnan <[email protected]>
Re: [PATCH 3/7] cxlflash: Acquire semaphore before invoking ioctl services
In reply to Uma KrishnanQuoted 15 lines · Uma Krishnan
When a superpipe process that makes use of virtual LUNs is terminated or killed abruptly, there is a possibility that the cxlflash driver could hang and deprive other operations on the adapter.
The release fop registered to be invoked on a context close, detaches every LUN associated with the context. The underlying service to detach the LUN assumes it has been called with the read semaphore held, and releases the semaphore before any operation that could be time consuming.
When invoked without holding the read semaphore, an opportunity is created for the semaphore's count to become negative when it is temporarily released during one of these potential lengthy operations. This negative count results in subsequent acquisition attempts taking forever, leading to the hang.
Quoted 5 lines
To support the current design point of holding the semaphore on the
ioctl()paths, the release fop should acquire it before invoking any ioctl services.Signed-off-by Uma Krishnan <[email protected]>
Re: [PATCH 5/7] cxlflash: Add include guards to backend.h
In reply to Uma KrishnanQuoted 4 lines · Uma Krishnan
The new header file,
backend.h, that was recently added is missing the include guards. This commit adds the guards.Signed-off-by Uma Krishnan <[email protected]>
Re: [PATCH 6/7] cxlflash: Abstract hardware dependent assignments
In reply to Uma KrishnanQuoted 5 lines · Uma Krishnan
As a staging cleanup to support transport specific builds of the cxlflash module, relocate device dependent assignments to header files. This will avoid littering the core driver with conditional compilation logic.
Signed-off-by Uma Krishnan <[email protected]>
Re: [PATCH 7/7] cxlflash: Isolate external module dependencies
In reply to Uma KrishnanQuoted 11 lines · Uma Krishnan
Depending on the underlying transport, cxlflash has a dependency on either the CXL or OCXL drivers, which are enabled via their
Kconfigoption. Instead of having a module wide dependency on these config options, it is better to isolate the object modules that are dependent on the CXL and OCXL drivers and adjust the module dependencies accordingly.This commit isolates the object files that are dependent on CXL and/or OCXL. The cxl/ocxl fops used in the core driver are tucked under an ifdef to avoid compilation errors.
Signed-off-by Uma Krishnan <[email protected]>
Martin K. Petersen
AppliedUma,
Quoted 2 lines
This patch series adds few improvements to the cxlflash driver and it also contains couple of bug fixes.
Applied to 4.18/scsi-queue, thank you!
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering