Skip to contentSkip to conversation

FAILED: patch "[PATCH] s390/dasd: Use correct lock while counting channel queue" failed to apply to 5.4-stable tree

PATCH In review [email protected] 3 participants 6 messages Jun 11, 2023 – Feb 19, 2025

Subsystems (3)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 5.4-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.4.y
git checkout FETCH_HEAD
git cherry-pick -x ccc45cb4e7271c74dbb27776ae8f73d84557f5c6
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2023061111-tracing-shakiness-9054@gregkh' --subject-prefix 'PATCH 5.4.y' HEAD^..

Possible dependencies:

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From ccc45cb4e7271c74dbb27776ae8f73d84557f5c6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20H=C3=B6ppner?= <[email protected]>
Date: Fri, 9 Jun 2023 17:37:50 +0200
Subject: [PATCH] s390/dasd: Use correct lock while counting channel queue
length
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The lock around counting the channel queue length in the BIODASDINFO ioctl was incorrectly changed to the dasd_block->queue_lock with commit 583d6535cb9d ("dasd: remove dead code"). This can lead to endless list iterations and a subsequent crash.

The queue_lock is supposed to be used only for queue lists belonging to dasd_block. For dasd_device related queue lists the ccwdev lock must be used.

Fix the mentioned issues by correctly using the ccwdev lock instead of the queue lock.

drivers/s390/block/dasd_ioctl.c +2 -2
index 9327dcdd6e5e..8fca725b3dae 100644
@@ -552,10 +552,10 @@ static int __dasd_ioctl_information(struct dasd_block *block,
 
 	memcpy(dasd_info->type, base->discipline->name, 4);
 
-	spin_lock_irqsave(&block->queue_lock, flags);
+	spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
 	list_for_each(l, &base->ccw_queue)
 		dasd_info->chanq_len++;
-	spin_unlock_irqrestore(&block->queue_lock, flags);
+	spin_unlock_irqrestore(get_ccwdev_lock(base->cdev), flags);
 	return 0;
 }
 
maintainer
#1 lore raw

PATCH 1/1 s390/dasd: Use correct lock while counting channel queue length

The lock around counting the channel queue length in the BIODASDINFO ioctl was incorrectly changed to the dasd_block->queue_lock with commit 583d6535cb9d ("dasd: remove dead code"). This can lead to endless list iterations and a subsequent crash.

The queue_lock is supposed to be used only for queue lists belonging to dasd_block. For dasd_device related queue lists the ccwdev lock must be used.

Fix the mentioned issues by correctly using the ccwdev lock instead of the queue lock.

Fixes 583d6535cb9d ("dasd: remove dead code")
(cherry picked from commit ccc45cb4e7271c74dbb27776ae8f73d84557f5c6)
---
 drivers/s390/block/dasd_ioctl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/s390/block/dasd_ioctl.c +2 -2
index 9a5f3add325f..c995dae5cc6f 100644
@@ -516,10 +516,10 @@ static int dasd_ioctl_information(struct dasd_block *block,
 
 	memcpy(dasd_info->type, base->discipline->name, 4);
 
-	spin_lock_irqsave(&block->queue_lock, flags);
+	spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
 	list_for_each(l, &base->ccw_queue)
 		dasd_info->chanq_len++;
-	spin_unlock_irqrestore(&block->queue_lock, flags);
+	spin_unlock_irqrestore(get_ccwdev_lock(base->cdev), flags);
 
 	rc = 0;
 	if (copy_to_user(argp, dasd_info,
Signature · 1 line
2.39.2
maintainer
#2 lore raw

Re: [PATCH 5.4.y] s390/dasd: Use correct lock while counting channel queue length

[ Sasha's backport helper bot ]

Hi,

Summary of potential issues:
❌ Build failures detected
⚠️ Found matching upstream commit but patch is missing proper reference to it

Found matching upstream commit: ccc45cb4e7271c74dbb27776ae8f73d84557f5c6

Status in newer kernel trees:
6.13.y | Present (exact SHA1)
6.12.y | Present (exact SHA1)
6.6.y | Present (exact SHA1)
6.1.y | Present (different SHA1: 1e1e2ee0cf7f)

Note: The patch differs from the upstream commit:
---
Failed to apply patch cleanly.
---

Results of testing on various branches:

| Branch                    | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| stable/linux-5.4.y        |  Failed     |  N/A       |

Build Errors:
Patch failed to apply on stable/linux-5.4.y. Reject:

diff a/drivers/s390/block/dasd_ioctl.c b/drivers/s390/block/dasd_ioctl.c (rejected hunks)
@@ -516,10 +516,10 @@ static int dasd_ioctl_information(struct dasd_block *block,

memcpy(dasd_info->type, base->discipline->name, 4);

- spin_lock_irqsave(&block->queue_lock, flags);
+ spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
list_for_each(l, &base->ccw_queue)
dasd_info->chanq_len++;
- spin_unlock_irqrestore(&block->queue_lock, flags);
+ spin_unlock_irqrestore(get_ccwdev_lock(base->cdev), flags);

rc = 0;
if (copy_to_user(argp, dasd_info,

maintainer
#3 lore raw

PATCH 1/1 WIP

In reply to [email protected]
---
 arch/s390/include/asm/idals.h  |  51 ++++
 drivers/s390/char/tape.h       |   9 +-
 drivers/s390/char/tape_34xx.c  |  10 +
 drivers/s390/char/tape_char.c  | 436 +++++++++++++++++++++++++++++----
 drivers/s390/char/tape_class.c |   2 +-
 drivers/s390/char/tape_core.c  |   5 +-
 drivers/s390/char/tape_std.c   | 146 +++++------
 drivers/s390/char/tape_std.h   |   1 +
 8 files changed, 512 insertions(+), 148 deletions(-)
arch/s390/include/asm/idals.h +51 -0
index ac68c657b28c..3b9f4cb300b5 100644
@@ -137,6 +137,7 @@ static inline struct idal_buffer *idal_buffer_alloc(size_t size, int page_order)
 
 	nr_ptrs = (size + IDA_BLOCK_SIZE - 1) >> IDA_SIZE_SHIFT;
 	nr_chunks = (PAGE_SIZE << page_order) >> IDA_SIZE_SHIFT;
+	pr_warn("DEBUG: ib struct_size: %lu\n", struct_size(ib, data, nr_ptrs));
 	ib = kmalloc(struct_size(ib, data, nr_ptrs), GFP_DMA | GFP_KERNEL);
 	if (!ib)
 		return ERR_PTR(-ENOMEM);
@@ -247,6 +248,8 @@ static inline size_t idal_buffer_from_user(struct idal_buffer *ib, const void __
 	BUG_ON(count > ib->size);
 	for (i = 0; count > IDA_BLOCK_SIZE; i++) {
 		vaddr = dma64_to_virt(ib->data[i]);
+		pr_warn("DEBUG(idal_buf_from_user): count(%d): %lu idaws: %llx vaddr: %p\n",
+			i, count, ib->data[i], vaddr);
 		left = copy_from_user(vaddr, from, IDA_BLOCK_SIZE);
 		if (left)
 			return left + count - IDA_BLOCK_SIZE;
@@ -257,4 +260,52 @@ static inline size_t idal_buffer_from_user(struct idal_buffer *ib, const void __
 	return copy_from_user(vaddr, from, count);
 }
 
+static inline size_t idal_to_user(dma64_t *idaws, void __user *to, size_t count)
+{
+	size_t left;
+	void *vaddr;
+
+	/* BUG_ON(count > ib->size); */
+	while (count > IDA_BLOCK_SIZE) {
+		vaddr = dma64_to_virt(*idaws++);
+		left = copy_to_user(to, vaddr, IDA_BLOCK_SIZE);
+		pr_warn("DEBUG(idal_to_user): vaddr %p left/count: %lu/%lu\n",
+			vaddr, left, count);
+		if (left)
+			return left + count - IDA_BLOCK_SIZE;
+		to = (void __user *)to + IDA_BLOCK_SIZE;
+		count -= IDA_BLOCK_SIZE;
+	}
+	vaddr = dma64_to_virt(*idaws);
+	left = copy_to_user(to, vaddr, count);
+	pr_warn("DEBUG(idal_to_user last): vaddr %p left/count: %lu/%lu\n",
+		vaddr, left, count);
+	return left;
+	/* return copy_to_user(to, vaddr, count); */
+}
+
+static inline size_t idal_from_user(dma64_t *idaws, const void __user *from,
+				    size_t count)
+{
+	size_t left;
+	void *vaddr;
+
+	/* BUG_ON(count > ib->size); */
+	while (count > IDA_BLOCK_SIZE) {
+		vaddr = dma64_to_virt(*idaws++);
+		left = copy_from_user(vaddr, from, IDA_BLOCK_SIZE);
+		pr_warn("DEBUG(idal_from_user): vaddr %p left/count: %lu/%lu\n",
+			vaddr, left, count);
+		if (left)
+			return left + count - IDA_BLOCK_SIZE;
+		from = (void __user *)from + IDA_BLOCK_SIZE;
+		count -= IDA_BLOCK_SIZE;
+	}
+	vaddr = dma64_to_virt(*idaws);
+	left = copy_from_user(vaddr, from, count);
+	pr_warn("DEBUG(idal_from_user last): vaddr %p left/count: %lu/%lu\n",
+		vaddr, left, count);
+	return left;
+	/* return copy_from_user(vaddr, from, count); */
+}
 #endif
drivers/s390/char/tape.h +6 -3
index a4bbee0f19f4..9f00a57888cd 100644
@@ -130,6 +130,7 @@ struct tape_request {
 	int retries;			/* retry counter for error recovery. */
 	int rescnt;			/* residual count from devstat. */
 	struct timer_list timer;	/* timer for std_assign_timeout(). */
+	struct irb irb;			/* device status */
 
 	/* Callback for delivering final status. */
 	void (*callback)(struct tape_request *, void *);
@@ -346,8 +347,9 @@ tape_ccw_repeat(struct ccw1 *ccw, __u8 cmd_code, int count)
 	return ccw;
 }
 
-static inline struct ccw1 *
-tape_ccw_ida_idal(struct ccw1 *ccw, __u8 cmd_code, struct idal_buffer *idal)
+static inline struct ccw1 *tape_ccw_ida_idal(struct ccw1 *ccw, __u8 cmd_code,
+					     dma64_t *idaws, void *vaddr,
+					     int length)
 {
 	ccw->cmd_code = cmd_code;
 	ccw->flags    = CCW_FLAG_IDA;
@@ -355,7 +357,8 @@ tape_ccw_ida_idal(struct ccw1 *ccw, __u8 cmd_code, struct idal_buffer *idal)
 	// Create IDA Words to chain entire data list
 	// idaws: cqr->data == idal buffer?! == ib->data?!
 	// dst: vaddr buffer
-	//idal_create_words(idaws, dst, blksize);
+	ccw->cda = virt_to_dma32(idaws);
+	idaws = idal_create_words(idaws, vaddr, length);
 
 	return ccw++;
 }
drivers/s390/char/tape_34xx.c +10 -0
index dccae8202d2f..b1d8333550b0 100644
@@ -17,6 +17,9 @@
 #include <linux/workqueue.h>
 #include <linux/slab.h>
 
+#include <asm/css_chars.h>
+#include <asm/ccwdev.h>
+
 #define TAPE_DBF_AREA	tape_34xx_dbf
 
 #include "tape.h"
@@ -1059,6 +1062,9 @@ tape_34xx_setup_device(struct tape_device * device)
 	struct list_head *	discdata;
 	struct tape_34xx_rdc_data *rdc_data;
 
+	int fcx_in_css;
+	unsigned int mdc;
+
 	DBF_EVENT(6, "34xx device setup\n");
 	rdc_data = kmalloc(sizeof(*rdc_data), GFP_KERNEL | GFP_DMA);
 	if (!rdc_data) {
@@ -1076,6 +1082,10 @@ tape_34xx_setup_device(struct tape_device * device)
 	pr_warn("DEBUG: max_blksize: %u opt_blksize: %u\n",
 		rdc_data->max_block_size, rdc_data->opt_block_size);
 
+	fcx_in_css = css_general_characteristics.fcx;
+	mdc = ccw_device_get_mdc(device->cdev, 0);
+	pr_warn("DEBUG: fcx: %d mdc: %u\n", fcx_in_css, mdc);
+
 	if ((rc = tape_std_assign(device)) == 0) {
 		if ((rc = tape_34xx_medium_sense(device)) != 0) {
 			DBF_LH(3, "34xx medium sense returned %d\n", rc);
drivers/s390/char/tape_char.c +382 -54

535 lines not on this page · raw message

drivers/s390/char/tape_class.c +1 -1
index 5de3729a238a..703033875ab1 100644
@@ -119,7 +119,7 @@ EXPORT_SYMBOL(unregister_tape_dev);
 
 static int __init tape_init(void)
 {
-	pr_warn("DEBUG: tape classe module reloaded... 1\n");
+	pr_warn("DEBUG: tape classe module reloaded... 2\n");
 	return class_register(&tape_class);
 }
 
drivers/s390/char/tape_core.c +3 -2
index ea63e122b169..7e03bc44d0ae 100644
@@ -1098,9 +1098,10 @@ __tape_do_irq (struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
 	}
 
 	/* May be an unsolicited irq */
-	if(request != NULL)
+	if(request != NULL) {
 		request->rescnt = irb->scsw.cmd.count;
-	else if ((irb->scsw.cmd.dstat == 0x85 || irb->scsw.cmd.dstat == 0x80) &&
+		memcpy(&request->irb, irb, sizeof(*irb));
+	} else if ((irb->scsw.cmd.dstat == 0x85 || irb->scsw.cmd.dstat == 0x80) &&
 		 !list_empty(&device->req_queue)) {
 		/* Not Ready to Ready after long busy ? */
 		struct tape_request *req;
drivers/s390/char/tape_std.c +58 -88

384 lines not on this page · raw message

drivers/s390/char/tape_std.h +1 -0
index def8e6425d49..6251547a4ae7 100644
@@ -102,6 +102,7 @@ struct tape_request *tape_std_read_block(struct tape_device *, size_t);
 void tape_std_read_backward(struct tape_device *device,
 			    struct tape_request *request);
 struct tape_request *tape_std_write_block(struct tape_device *, size_t);
+struct tape_request *tape_std_write_block_new(struct tape_device *, const void __user *, size_t);
 
 /* Some non-mtop commands. */
 int tape_std_assign(struct tape_device *);
Signature · 1 line
2.45.2
author maintainer
#4 lore raw

Re: [PATCH 5.4.y] WIP

Quoted 10 lines · Jan Höppner
---
 arch/s390/include/asm/idals.h  |  51 ++++
 drivers/s390/char/tape.h       |   9 +-
 drivers/s390/char/tape_34xx.c  |  10 +
 drivers/s390/char/tape_char.c  | 436 +++++++++++++++++++++++++++++----
 drivers/s390/char/tape_class.c |   2 +-
 drivers/s390/char/tape_core.c  |   5 +-
 drivers/s390/char/tape_std.c   | 146 +++++------
 drivers/s390/char/tape_std.h   |   1 +
 8 files changed, 512 insertions(+), 148 deletions(-)

I'm confused, is this a patch submission of a backport?

maintainer
#5 lore raw

Re: [PATCH 5.4.y] WIP

Quoted 12 lines · Greg KH
Quoted 10 lines · Jan Höppner
---
 arch/s390/include/asm/idals.h  |  51 ++++
 drivers/s390/char/tape.h       |   9 +-
 drivers/s390/char/tape_34xx.c  |  10 +
 drivers/s390/char/tape_char.c  | 436 +++++++++++++++++++++++++++++----
 drivers/s390/char/tape_class.c |   2 +-
 drivers/s390/char/tape_core.c  |   5 +-
 drivers/s390/char/tape_std.c   | 146 +++++------
 drivers/s390/char/tape_std.h   |   1 +
 8 files changed, 512 insertions(+), 148 deletions(-)
Quoted 2 lines

I'm confused, is this a patch submission of a backport?

Hi Greg,

I'm very sorry, please ignore this completely. I was clearly to dumb to use my bash backward search correctly. I accidentally ran an old command that send this WIP patch, which is not meant to be for the outside world at all yet.

I already put a safety net in place so this won't happen again! My apologies for the inconvenience.

regards,
Jan