From 35fc51e7a5056889421270c1fb63d8ec45fbccf4 Mon Sep 17 00:00:00 2001 From: "Aneesh Kumar K.V" Date: Wed, 21 Nov 2007 12:25:41 +0100 Subject: [PATCH 1/6] blktrace: Make sure BLKTRACETEARDOWN does the full cleanup. if blktrace program segfault it will not be able to call BLKTRACETEARDOWN. Now if we run the blktrace again that would result in a failure to create the block/ debugfs directory.This will result in blk_remove_root() to be called which will set blk_tree_root to NULL. But the debugfs block dir still exist because it contain subdirectory. Now if we try to fix it using BLKTRACETEARDOWN it won't work because blk_tree_root is NULL. Fix the same. Tested as below root@qemu-image:/home/kvaneesh/blktrace# ./blktrace -d /dev/hdc Segmentation fault root@qemu-image:/home/kvaneesh/blktrace# ./blktrace -d /dev/hdc BLKTRACESETUP: No such file or directory Failed to start trace on /dev/hdc root@qemu-image:/home/kvaneesh/blktrace# ./blktrace -k /dev/hdc root@qemu-image:/home/kvaneesh/blktrace# ./blktrace -d /dev/hdc Signed-off-by: Aneesh Kumar K.V Signed-off-by: Jens Axboe --- block/blktrace.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/block/blktrace.c b/block/blktrace.c index d00ac3993c18..498a0a54a6aa 100644 --- a/block/blktrace.c +++ b/block/blktrace.c @@ -202,6 +202,7 @@ static void blk_remove_tree(struct dentry *dir) static struct dentry *blk_create_tree(const char *blk_name) { struct dentry *dir = NULL; + int created = 0; mutex_lock(&blk_tree_mutex); @@ -209,13 +210,17 @@ static struct dentry *blk_create_tree(const char *blk_name) blk_tree_root = debugfs_create_dir("block", NULL); if (!blk_tree_root) goto err; + created = 1; } dir = debugfs_create_dir(blk_name, blk_tree_root); if (dir) root_users++; - else - blk_remove_root(); + else { + /* Delete root only if we created it */ + if (created) + blk_remove_root(); + } err: mutex_unlock(&blk_tree_mutex); From 8c8d7214d1b35726e950db1f73317e28e827f1cd Mon Sep 17 00:00:00 2001 From: FUJITA Tomonori Date: Wed, 21 Nov 2007 12:26:31 +0100 Subject: [PATCH 2/6] alpha: fix sg_page breakage Signed-off-by: FUJITA Tomonori Signed-off-by: Jens Axboe --- arch/alpha/kernel/pci-noop.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/arch/alpha/kernel/pci-noop.c b/arch/alpha/kernel/pci-noop.c index 174b729c504b..468b76ce66a1 100644 --- a/arch/alpha/kernel/pci-noop.c +++ b/arch/alpha/kernel/pci-noop.c @@ -12,6 +12,7 @@ #include #include #include +#include #include "proto.h" @@ -172,18 +173,19 @@ dma_alloc_coherent(struct device *dev, size_t size, EXPORT_SYMBOL(dma_alloc_coherent); int -dma_map_sg(struct device *dev, struct scatterlist *sg, int nents, +dma_map_sg(struct device *dev, struct scatterlist *sgl, int nents, enum dma_data_direction direction) { int i; + struct scatterlist *sg; - for (i = 0; i < nents; i++ ) { + for_each_sg(sgl, sg, nents, i) { void *va; - BUG_ON(!sg[i].page); - va = page_address(sg[i].page) + sg[i].offset; - sg_dma_address(sg + i) = (dma_addr_t)virt_to_bus(va); - sg_dma_len(sg + i) = sg[i].length; + BUG_ON(!sg_page(sg)); + va = sg_virt(sg); + sg_dma_address(sg) = (dma_addr_t)virt_to_bus(va); + sg_dma_len(sg) = sg->length; } return nents; From c7674030e5eb83d9ba29318fb9b3ccedf84d583e Mon Sep 17 00:00:00 2001 From: Jerome Marchand Date: Fri, 23 Nov 2007 09:17:53 +0100 Subject: [PATCH 3/6] block: Fix memory leak in alloc_disk_node() Fix a memory leak in alloc_disk_node(). Don't forget to free 'dkstats' when the allocation of 'part' failed. Signed-off-by: Jerome Marchand Signed-off-by: Jens Axboe --- block/genhd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block/genhd.c b/block/genhd.c index e609996f2e76..f2ac914160d1 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -715,6 +715,7 @@ struct gendisk *alloc_disk_node(int minors, int node_id) disk->part = kmalloc_node(size, GFP_KERNEL | __GFP_ZERO, node_id); if (!disk->part) { + free_disk_stats(disk); kfree(disk); return NULL; } From 05e5b136459b11cd9559370d5756719e08074fe0 Mon Sep 17 00:00:00 2001 From: Haavard Skinnemoen Date: Fri, 23 Nov 2007 10:19:00 +0100 Subject: [PATCH 4/6] mmc: Add missing sg_init_table() call mmc_init_queue only initializes the scatterlists with sg_init_table() when using a bounce buffer. This leads to a BUG() when CONFIG_DEBUG_SG is set. Signed-off-by: Haavard Skinnemoen Signed-off-by: Jens Axboe --- drivers/mmc/card/queue.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/card/queue.c b/drivers/mmc/card/queue.c index 1b9c9b6da5b7..30cd13b13ac3 100644 --- a/drivers/mmc/card/queue.c +++ b/drivers/mmc/card/queue.c @@ -180,12 +180,13 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card, spinlock_t *lock blk_queue_max_hw_segments(mq->queue, host->max_hw_segs); blk_queue_max_segment_size(mq->queue, host->max_seg_size); - mq->sg = kzalloc(sizeof(struct scatterlist) * + mq->sg = kmalloc(sizeof(struct scatterlist) * host->max_phys_segs, GFP_KERNEL); if (!mq->sg) { ret = -ENOMEM; goto cleanup_queue; } + sg_init_table(mq->sg, host->max_phys_segs); } init_MUTEX(&mq->thread_sem); From 7c9f29b128aab5ac95af553e8d8e0e372647f1d5 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Tue, 27 Nov 2007 09:23:51 +0100 Subject: [PATCH 5/6] Revert "ll_rw_blk: temporarily enable max_segments tweaking" This was a temporary debugging thing for sg chaining testing, revert it now as it has served its purpose. This reverts commit 563063a808de6b2004d5b8a09ddcb6125481f4b2. Signed-off-by: Jens Axboe --- block/ll_rw_blk.c | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/block/ll_rw_blk.c b/block/ll_rw_blk.c index 3b927be03850..8b919940b2ab 100644 --- a/block/ll_rw_blk.c +++ b/block/ll_rw_blk.c @@ -4080,23 +4080,7 @@ static ssize_t queue_max_hw_sectors_show(struct request_queue *q, char *page) return queue_var_show(max_hw_sectors_kb, (page)); } -static ssize_t queue_max_segments_show(struct request_queue *q, char *page) -{ - return queue_var_show(q->max_phys_segments, page); -} -static ssize_t queue_max_segments_store(struct request_queue *q, - const char *page, size_t count) -{ - unsigned long segments; - ssize_t ret = queue_var_store(&segments, page, count); - - spin_lock_irq(q->queue_lock); - q->max_phys_segments = segments; - spin_unlock_irq(q->queue_lock); - - return ret; -} static struct queue_sysfs_entry queue_requests_entry = { .attr = {.name = "nr_requests", .mode = S_IRUGO | S_IWUSR }, .show = queue_requests_show, @@ -4120,12 +4104,6 @@ static struct queue_sysfs_entry queue_max_hw_sectors_entry = { .show = queue_max_hw_sectors_show, }; -static struct queue_sysfs_entry queue_max_segments_entry = { - .attr = {.name = "max_segments", .mode = S_IRUGO | S_IWUSR }, - .show = queue_max_segments_show, - .store = queue_max_segments_store, -}; - static struct queue_sysfs_entry queue_iosched_entry = { .attr = {.name = "scheduler", .mode = S_IRUGO | S_IWUSR }, .show = elv_iosched_show, @@ -4137,7 +4115,6 @@ static struct attribute *default_attrs[] = { &queue_ra_entry.attr, &queue_max_hw_sectors_entry.attr, &queue_max_sectors_entry.attr, - &queue_max_segments_entry.attr, &queue_iosched_entry.attr, NULL, }; From 645a8d94629fd812a220d54876339a1ddafd9bc2 Mon Sep 17 00:00:00 2001 From: Tejun Heo Date: Tue, 27 Nov 2007 09:30:39 +0100 Subject: [PATCH 6/6] scatterlist: add more safeguards Add more safeguards to protect against misinterpreting a chain entry as a normal scatterlist and vice-versa. * Make sure the entry isn't a chain when assigning and reading a normal sg. * Clear offset and length when chaining. Signed-off-by: Tejun Heo Signed-off-by: Jens Axboe --- include/linux/scatterlist.h | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h index 259735044148..416e000dfe81 100644 --- a/include/linux/scatterlist.h +++ b/include/linux/scatterlist.h @@ -26,6 +26,16 @@ #define SG_MAGIC 0x87654321 +/* + * We overload the LSB of the page pointer to indicate whether it's + * a valid sg entry, or whether it points to the start of a new scatterlist. + * Those low bits are there for everyone! (thanks mason :-) + */ +#define sg_is_chain(sg) ((sg)->page_link & 0x01) +#define sg_is_last(sg) ((sg)->page_link & 0x02) +#define sg_chain_ptr(sg) \ + ((struct scatterlist *) ((sg)->page_link & ~0x03)) + /** * sg_assign_page - Assign a given page to an SG entry * @sg: SG entry @@ -47,6 +57,7 @@ static inline void sg_assign_page(struct scatterlist *sg, struct page *page) BUG_ON((unsigned long) page & 0x03); #ifdef CONFIG_DEBUG_SG BUG_ON(sg->sg_magic != SG_MAGIC); + BUG_ON(sg_is_chain(sg)); #endif sg->page_link = page_link | (unsigned long) page; } @@ -73,7 +84,14 @@ static inline void sg_set_page(struct scatterlist *sg, struct page *page, sg->length = len; } -#define sg_page(sg) ((struct page *) ((sg)->page_link & ~0x3)) +static inline struct page *sg_page(struct scatterlist *sg) +{ +#ifdef CONFIG_DEBUG_SG + BUG_ON(sg->sg_magic != SG_MAGIC); + BUG_ON(sg_is_chain(sg)); +#endif + return (struct page *)((sg)->page_link & ~0x3); +} /** * sg_set_buf - Set sg entry to point at given data @@ -88,16 +106,6 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf, sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf)); } -/* - * We overload the LSB of the page pointer to indicate whether it's - * a valid sg entry, or whether it points to the start of a new scatterlist. - * Those low bits are there for everyone! (thanks mason :-) - */ -#define sg_is_chain(sg) ((sg)->page_link & 0x01) -#define sg_is_last(sg) ((sg)->page_link & 0x02) -#define sg_chain_ptr(sg) \ - ((struct scatterlist *) ((sg)->page_link & ~0x03)) - /** * sg_next - return the next scatterlist entry in a list * @sg: The current sg entry @@ -179,6 +187,13 @@ static inline void sg_chain(struct scatterlist *prv, unsigned int prv_nents, #ifndef ARCH_HAS_SG_CHAIN BUG(); #endif + + /* + * offset and length are unused for chain entry. Clear them. + */ + prv->offset = 0; + prv->length = 0; + /* * Set lowest bit to indicate a link pointer, and make sure to clear * the termination bit if it happens to be set.