Skip to contentSkip to conversation

pktcdvd: Fix overflow for discs with large packets

PATCH In review Peter Osterlund 2 participants 7 messages Feb 3, 2006 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 pktcdvd: Fix overflow for discs with large packets

From: Phillip Susi <[email protected]>

The pktcdvd driver was using an 8 bit field to store the packet length obtained from the disc track info. This causes it to overflow packet length values of 128KB or more. I changed the field to 32 bits to fix this.

The pktcdvd driver defaulted to its maximum allowed packet length when it detected a 0 in the track info field. I changed this to fail the operation and refuse to access the media. This seems more sane than attempting to access it with a value that almost certainly will not work.

---

 drivers/block/pktcdvd.c |    2 +-
 include/linux/pktcdvd.h |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/block/pktcdvd.c +1 -1
index 81ad466..f0a0ad4 100644
@@ -1640,7 +1640,7 @@ static int pkt_probe_settings(struct pkt
 	pd->settings.size = be32_to_cpu(ti.fixed_packet_size) << 2;
 	if (pd->settings.size == 0) {
 		printk("pktcdvd: detected zero packet size!\n");
-		pd->settings.size = 128;
+		return -ENXIO;
 	}
 	if (pd->settings.size > PACKET_MAX_SECTORS) {
 		printk("pktcdvd: packet size is too big\n");
include/linux/pktcdvd.h +1 -1
index 2c177e4..d1c9c4a 100644
@@ -114,7 +114,7 @@ struct pkt_ctrl_command {
 
 struct packet_settings
 {
-	__u8			size;		/* packet size in (512 byte) sectors */
+	__u32			size;		/* packet size in (512 byte) sectors */
 	__u8			fp;		/* fixed packets */
 	__u8			link_loss;	/* the rest is specified
 						 * as per Mt Fuji */
Signature · 2 lines
Peter Osterlund - [email protected]
http://web.telia.com/~u89404340
#1 lore raw

PATCH 2/5 pktcdvd: Remove version string

The version information is not useful for a driver that is maintained in Linus' kernel tree.

---

 drivers/block/pktcdvd.c |    3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)
drivers/block/pktcdvd.c +0 -3
index f0a0ad4..01f070a 100644
@@ -43,8 +43,6 @@
  *
  *************************************************************************/
 
-#define VERSION_CODE	"v0.2.0a 2004-07-14 Jens Axboe ([email protected]) and [email protected]"
-
 #include <linux/pktcdvd.h>
 #include <linux/config.h>
 #include <linux/module.h>
@@ -2679,7 +2677,6 @@ static int __init pkt_init(void)
 
 	pkt_proc = proc_mkdir("pktcdvd", proc_root_driver);
 
-	DPRINTK("pktcdvd: %s\n", VERSION_CODE);
 	return 0;
 
 out:
Signature · 2 lines
Peter Osterlund - [email protected]
http://web.telia.com/~u89404340
#2 lore raw

PATCH 3/5 Let CDROM_PKTCDVD_WCACHE depend on EXPERIMENTAL

From: Adrian Bunk <[email protected]>

Unless the help text is outdated, this seems to be logical.

---

 drivers/block/Kconfig |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/block/Kconfig +2 -2
index 139cbba..db6818f 100644
@@ -437,8 +437,8 @@ config CDROM_PKTCDVD_BUFFERS
 	  pktsetup time.
 
 config CDROM_PKTCDVD_WCACHE
-	bool "Enable write caching"
-	depends on CDROM_PKTCDVD
+	bool "Enable write caching (EXPERIMENTAL)"
+	depends on CDROM_PKTCDVD && EXPERIMENTAL
 	help
 	  If enabled, write caching will be set for the CD-R/W device. For now
 	  this option is dangerous unless the CD-RW media is known good, as we
Signature · 2 lines
Peter Osterlund - [email protected]
http://web.telia.com/~u89404340
#3 lore raw

PATCH 4/5 pktcdvd: Don't waste kernel memory

Allocate memory for read-gathering at open time, when it is known just how much memory is needed. This avoids wasting kernel memory when the real packet size is smaller than the maximum packet size supported by the driver. This is always the case when using DVD discs.

---

 drivers/block/Kconfig   |    4 ++--
 drivers/block/pktcdvd.c |   53 +++++++++++++++++++++++++----------------------
 include/linux/pktcdvd.h |    4 ++--
 3 files changed, 32 insertions(+), 29 deletions(-)
drivers/block/Kconfig +2 -2
index db6818f..8b13316 100644
@@ -433,8 +433,8 @@ config CDROM_PKTCDVD_BUFFERS
 	  This controls the maximum number of active concurrent packets. More
 	  concurrent packets can increase write performance, but also require
 	  more memory. Each concurrent packet will require approximately 64Kb
-	  of non-swappable kernel memory, memory which will be allocated at
-	  pktsetup time.
+	  of non-swappable kernel memory, memory which will be allocated when
+	  a disc is opened for writing.
 
 config CDROM_PKTCDVD_WCACHE
 	bool "Enable write caching (EXPERIMENTAL)"
drivers/block/pktcdvd.c +28 -25

158 lines not on this page · raw message

include/linux/pktcdvd.h +2 -2
index d1c9c4a..1623da8 100644
@@ -170,7 +170,7 @@ struct packet_iosched
 #error "PAGE_SIZE must be a multiple of CD_FRAMESIZE"
 #endif
 #define PACKET_MAX_SIZE		32
-#define PAGES_PER_PACKET	(PACKET_MAX_SIZE * CD_FRAMESIZE / PAGE_SIZE)
+#define FRAMES_PER_PAGE		(PAGE_SIZE / CD_FRAMESIZE)
 #define PACKET_MAX_SECTORS	(PACKET_MAX_SIZE * CD_FRAMESIZE >> 9)
 
 enum packet_data_state {
@@ -219,7 +219,7 @@ struct packet_data
 	atomic_t		io_errors;	/* Number of read/write errors during IO */
 
 	struct bio		*r_bios[PACKET_MAX_SIZE]; /* bios to use during data gathering */
-	struct page		*pages[PAGES_PER_PACKET];
+	struct page		*pages[PACKET_MAX_SIZE / FRAMES_PER_PAGE];
 
 	int			cache_valid;	/* If non-zero, the data for the zone defined */
 						/* by the sector variable is completely cached */
Signature · 2 lines
Peter Osterlund - [email protected]
http://web.telia.com/~u89404340
#4 lore raw

PATCH 5/5 pktcdvd: Allow larger packets

From: Phillip Susi <[email protected]>

The pktcdvd driver uses a compile time macro constant to define the maximum supported packet length. I changed this from 32 sectors to 128 sectors because that allows over 100 MB of additional usable space on a 700 MB cdrw, and increases throughput.

Note that you need a modified cdrwtool program that can format a CDRW disc with larger packets to benefit from this change.

---

 include/linux/pktcdvd.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
include/linux/pktcdvd.h +1 -1
index 1623da8..8a94c71 100644
@@ -169,7 +169,7 @@ struct packet_iosched
 #if (PAGE_SIZE % CD_FRAMESIZE) != 0
 #error "PAGE_SIZE must be a multiple of CD_FRAMESIZE"
 #endif
-#define PACKET_MAX_SIZE		32
+#define PACKET_MAX_SIZE		128
 #define FRAMES_PER_PAGE		(PAGE_SIZE / CD_FRAMESIZE)
 #define PACKET_MAX_SECTORS	(PACKET_MAX_SIZE * CD_FRAMESIZE >> 9)
 
Signature · 2 lines
Peter Osterlund - [email protected]
http://web.telia.com/~u89404340
#5 lore raw

Re: [PATCH 2/5] pktcdvd: Remove version string

In reply to Peter Osterlund

Cuma 3 Şubat 2006 22:18 tarihinde şunları yazmıştınız:

Quoted 24 lines

The version information is not useful for a driver that is maintained in Linus' kernel tree.

---

 drivers/block/pktcdvd.c |    3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)
drivers/block/pktcdvd.c +0 -1
index f0a0ad4..01f070a 100644
@@ -43,8 +43,6 @@
  *
 
 *************************************************************************/
 
-#define VERSION_CODE	"v0.2.0a 2004-07-14 Jens Axboe ([email protected]) and

[email protected]" -
#include <linux/pktcdvd.h>
#include <linux/config.h>
#include <linux/module.h>

drivers/block/pktcdvd.c static int __init pkt_init(void) · line 2682

Quoted 7 lines
drivers/block/pktcdvd.c +0 -1
@@ -2679,7 +2677,6 @@ static int __init pkt_init(void)
 
 	pkt_proc = proc_mkdir("pktcdvd", proc_root_driver);
 
-	DPRINTK("pktcdvd: %s\n", VERSION_CODE);
 	return 0;
 
 out:

Hmm this is useful to do dmesg|grep pktcdvd though when you compile it in the kernel. So I would like to keep it in.

Just my 2 cents.

Regards,
ismail

#6 lore raw

Re: [PATCH 2/5] pktcdvd: Remove version string

Quoted 5 lines · Ismail Donmez

Cuma 3 Şubat 2006 22:18 tarihinde şunları yazmıştınız:

Quoted 4 lines

The version information is not useful for a driver that is maintained in Linus' kernel tree.

...

Quoted 2 lines

Hmm this is useful to do dmesg|grep pktcdvd though when you compile it in the kernel. So I would like to keep it in.

Why is it useful? The actual version number can't be that useful since it hasn't been updated since 2004. If you just want to know if the driver is currently in the kernel, you can do:

cat /proc/misc | grep pktcdvd

Signature · 2 lines
Peter Osterlund - [email protected]
http://web.telia.com/~u89404340