patch: highmem zero-bounce
Subsystems (7)
Hi,
I updated the patches to 2.4.6-pre5, and removed the zone-dma32 addition. This means that machines with > 4GB of RAM will need to go all the way to low mem for bounces. I did this for several reasons:
- Linus didn't like the extra zone, so I'm probably redoing it the way he suggested.
- The current version had a bug that prevented 64GB highmem working.
The core has received no other updates that removal of GFP_DMA32 parts and gfp_mask for bouncing.
I can't put the patch on kernel.org atm, so I've just attached it here. It's not that big anyway. As soon as I can log back in, I'll post it there too.
Signature · 1 line
Jens Axboe
drivers/block/cciss.c renamed from opt/kernel/linux-2.4.6-pre5/drivers/block/cciss.c +19 -14
@@ -1124,7 +1124,7 @@ { temp64.val32.lower = cmd->SG[i].Addr.lower; temp64.val32.upper = cmd->SG[i].Addr.upper; -pci_unmap_single (hba[cmd->ctlr]->pdev, +pci_unmap_page (hba[cmd->ctlr]->pdev, temp64.val, cmd->SG[i].Len, (cmd->Request.Type.Direction ==XFER_READ ) ?PCI_DMA_FROMDEVICE :PCI_DMA_TODEVICE );
@@ -1220,7 +1220,7 @@static int cpq_back_merge_fn (request_queue_t *q,struct request *rq,struct buffer_head *bh,int max_segments) { -if (rq->bhtail->b_data + rq->bhtail->b_size == bh->b_data) +if (bh_bus (rq->bhtail) + rq->bhtail->b_size ==bh_bus (bh))return 1 ;return cpq_new_segment (q, rq, max_segments); }
@@ -1228,7 +1228,7 @@static int cpq_front_merge_fn (request_queue_t *q,struct request *rq,struct buffer_head *bh,int max_segments) { -if (bh->b_data + bh->b_size == rq->bh->b_data) +if (bh_bus (bh) + bh->b_size ==bh_bus (rq->bh))return 1 ;return cpq_new_segment (q, rq, max_segments); }
@@ -1238,7 +1238,7 @@ {int total_segments = rq->nr_segments + nxt->nr_segments; -if (rq->bhtail->b_data + rq->bhtail->b_size == nxt->bh->b_data) +if (bh_bus (rq->bhtail) + rq->bhtail->b_size ==bh_bus (nxt->bh)) total_segments--;if (total_segments >MAXSGENTRIES )
@@ -1259,7 +1259,7 @@ctlr_info_t *h= q->queuedata;CommandList_struct *c;int log_unit, start_blk, seg, sect; -char *lastdataend; +unsigned long lastdataend;struct buffer_head *bh;struct list_head *queue_head = &q->queue_head;struct request *creq;
@@ -1267,10 +1267,15 @@struct my_sg tmp_sg[MAXSGENTRIES ];int i; -// Loop till the queue is empty if or it is plugged +if (q->plugged) { +start_io (h); +return ; + } + +// Loop till the queue is empty while (1 ) { -if (q->plugged ||list_empty (queue_head)) { +if (list_empty (queue_head)) {start_io (h);return ; }
@@ -1318,12 +1323,12 @@ (int) creq->nr_sectors);#endif /* CCISS_DEBUG */ seg =0 ; - lastdataend =NULL ; + lastdataend =0 ; sect =0 ;while (bh) { sect += bh->b_size/512 ; -if (bh->b_data == lastdataend) +if (bh_bus (bh) == lastdataend) {// tack it on to the last segment tmp_sg[seg-1 ].len +=bh->b_size; lastdataend += bh->b_size;
@@ -1331,9 +1336,10 @@ {if (seg ==MAXSGENTRIES )BUG (); + tmp_sg[seg].page = bh->b_page; tmp_sg[seg].len = bh->b_size; - tmp_sg[seg].start_addr = bh->b_data; - lastdataend = bh->b_data + bh->b_size; + tmp_sg[seg].offset =bh_offset (bh); + lastdataend =bh_bus (bh) + bh->b_size; seg++; } bh = bh->b_reqnext;
@@ -1342,9 +1348,8 @@for (i=0 ; i<seg; i++) { c->SG[i].Len = tmp_sg[i].len; - temp64.val = (__u64 )pci_map_single ( h->pdev, - tmp_sg[i].start_addr, - tmp_sg[i].len, + temp64.val = (__u64 )pci_map_page ( h->pdev, + tmp_sg[i].page, tmp_sg[i].len, tmp_sg[i].offset, (c->Request.Type.Direction ==XFER_READ ) ?PCI_DMA_FROMDEVICE :PCI_DMA_TODEVICE ); c->SG[i].Addr.lower = temp64.val32.lower;
drivers/block/cciss.h renamed from opt/kernel/linux-2.4.6-pre5/drivers/block/cciss.h +3 -2
@@ -16,8 +16,9 @@#define MAJOR_NR COMPAQ_CISS_MAJORstruct my_sg { -int len; -char *start_addr; +struct page *page; +unsigned short len; +unsigned short offset; };struct ctlr_info ;
drivers/block/cpqarray.c renamed from opt/kernel/linux-2.4.6-pre5/drivers/block/cpqarray.c +21 -14
@@ -363,7 +363,7 @@static int cpq_back_merge_fn (request_queue_t *q,struct request *rq,struct buffer_head *bh,int max_segments) { -if (rq->bhtail->b_data + rq->bhtail->b_size == bh->b_data) +if (bh_bus (rq->bhtail) + rq->bhtail->b_size ==bh_bus (bh))return 1 ;return cpq_new_segment (q, rq, max_segments); }
@@ -371,7 +371,7 @@static int cpq_front_merge_fn (request_queue_t *q,struct request *rq,struct buffer_head *bh,int max_segments) { -if (bh->b_data + bh->b_size == rq->bh->b_data) +if (bh_bus (bh) + bh->b_size ==bh_bus (rq->bh))return 1 ;return cpq_new_segment (q, rq, max_segments); }
@@ -381,7 +381,7 @@ {int total_segments = rq->nr_segments + nxt->nr_segments; -if (rq->bhtail->b_data + rq->bhtail->b_size == nxt->bh->b_data) +if (bh_bus (rq->bhtail) + rq->bhtail->b_size ==bh_bus (nxt->bh)) total_segments--;if (total_segments >SG_MAX )
@@ -528,6 +528,7 @@ q =BLK_DEFAULT_QUEUE (MAJOR_NR + i); q->queuedata = hba[i];blk_init_queue (q, do_ida_request); +blk_queue_bounce_limit (q,BLK_BOUNCE_4G );blk_queue_headactive (q,0 ); blksize_size[MAJOR_NR +i] = ida_blocksizes + (i*256 ); hardsect_size[MAJOR_NR +i] = ida_hardsizes + (i*256 );
@@ -919,17 +920,22 @@ctlr_info_t *h = q->queuedata;cmdlist_t *c;int seg, sect; -char *lastdataend; +unsigned long lastdataend;struct list_head * queue_head = &q->queue_head;struct buffer_head *bh;struct request *creq;struct my_sg tmp_sg[SG_MAX ];int i; -// Loop till the queue is empty if or it is plugged +if (q->plugged) { +start_io (h); +return ; + } + +// Loop till the queue is empty while (1 ) { -if (q->plugged ||list_empty (queue_head)) { +if (list_empty (queue_head)) {start_io (h);return ; }
@@ -969,19 +975,20 @@printk ("sector=%d, nr_sectors=%d\n" , creq->sector, creq->nr_sectors); ); - seg =0 ; lastdataend =NULL ; + seg = lastdataend =0 ; sect =0 ;while (bh) { sect += bh->b_size/512 ; -if (bh->b_data == lastdataend) { +if (bh_bus (bh) == lastdataend) { tmp_sg[seg-1 ].size += bh->b_size; lastdataend += bh->b_size; }else {if (seg ==SG_MAX )BUG (); + tmp_sg[seg].page = bh->b_page; tmp_sg[seg].size = bh->b_size; - tmp_sg[seg].start_addr = bh->b_data; - lastdataend = bh->b_data + bh->b_size; + tmp_sg[seg].offset =bh_offset (bh); + lastdataend =bh_bus (bh) + bh->b_size; seg++; } bh = bh->b_reqnext;
@@ -990,9 +997,9 @@for ( i=0 ; i < seg; i++) { c->req.sg[i].size = tmp_sg[i].size; - c->req.sg[i].addr = (__u32 )pci_map_single ( - h->pci_dev, tmp_sg[i].start_addr, - tmp_sg[i].size, + c->req.sg[i].addr = (__u32 )pci_map_page ( + h->pci_dev, tmp_sg[i].page, tmp_sg[i].size, + tmp_sg[i].offset, (creq->cmd ==READ ) ?PCI_DMA_FROMDEVICE :PCI_DMA_TODEVICE ); }
@@ -1099,7 +1106,7 @@/* unmap the DMA mapping for all the scatter gather elements */ for (i=0 ; i<cmd->req.hdr.sg_cnt; i++) { -pci_unmap_single (hba[cmd->ctlr]->pci_dev, +pci_unmap_page (hba[cmd->ctlr]->pci_dev, cmd->req.sg[i].addr, cmd->req.sg[i].size, (cmd->req.hdr.cmd ==IDA_READ ) ?PCI_DMA_FROMDEVICE :PCI_DMA_TODEVICE ); }
drivers/block/cpqarray.h renamed from opt/kernel/linux-2.4.6-pre5/drivers/block/cpqarray.h +3 -2
@@ -57,8 +57,9 @@#ifdef __KERNEL__struct my_sg { -int size; -char *start_addr; +struct page *page; +unsigned short size; +unsigned short offset; };struct ctlr_info ;
drivers/block/elevator.c renamed from opt/kernel/linux-2.4.6-pre5/drivers/block/elevator.c +0 -1
@@ -110,7 +110,6 @@break ; }else if (__rq->sector - count == bh->b_rsector) { ret =ELEVATOR_FRONT_MERGE ; - __rq->elevator_sequence -= count; *req = __rq;break ; }
drivers/block/ll_rw_blk.c renamed from opt/kernel/linux-2.4.6-pre5/drivers/block/ll_rw_blk.c +39 -9
130 lines not on this page · raw message
drivers/block/loop.c renamed from opt/kernel/linux-2.4.6-pre5/drivers/block/loop.c +1 -3
@@ -453,9 +453,7 @@ goto err; } -#if CONFIG_HIGHMEM - rbh =create_bounce (rw, rbh); -#endif + rbh =blk_queue_bounce (q, rw, rbh);/* * file backed, queue for loop_thread to handle
drivers/ide/hpt34x.c renamed from opt/kernel/linux-2.4.6-pre5/drivers/ide/hpt34x.c +1 -0
@@ -425,6 +425,7 @@ hwif->autodma =0 ; hwif->dmaproc = &hpt34x_dmaproc; + hwif->highmem =1 ; }else { hwif->drives[0 ].autotune =1 ; hwif->drives[1 ].autotune =1 ;
drivers/ide/hpt366.c renamed from opt/kernel/linux-2.4.6-pre5/drivers/ide/hpt366.c +1 -0
@@ -710,6 +710,7 @@ hwif->autodma =1 ; else hwif->autodma = 0; + hwif->highmem =1 ; }else { hwif->autodma =0 ; hwif->drives[0 ].autotune =1 ;
drivers/ide/ide-disk.c renamed from opt/kernel/linux-2.4.6-pre5/drivers/ide/ide-disk.c +17 -11
@@ -27,9 +27,10 @@* Version 1.09 added increment of rq->sector in ide_multwrite * added UDMA 3/4 reporting * Version 1.10 request queue changes, Ultra DMA 100 +* Version 1.11 Highmem I/O support, Jens Axboe <[email protected]> */ -#define IDEDISK_VERSION "1.10" +#define IDEDISK_VERSION "1.11"#undef REALLY_SLOW_IO/* most systems can safely undef this */
@@ -140,6 +141,7 @@int i;unsigned int msect, nsect;struct request *rq; +char *to;/* new way for dealing with premature shared PCI interrupts */ if (!OK_STAT (stat=GET_STAT (),DATA_READY ,BAD_R_STAT )) {
@@ -150,8 +152,8 @@ide_set_handler (drive, &read_intr,WAIT_CMD ,NULL );return ide_started; } + msect = drive->mult_count; - read_next: rq =HWGROUP (drive)->rq;if (msect) {
@@ -160,14 +162,15 @@ msect -= nsect; }else nsect =1 ; -idedisk_input_data (drive, rq->buffer, nsect *SECTOR_WORDS ); + to =ide_map_buffer (rq); +idedisk_input_data (drive, to, nsect *SECTOR_WORDS );#ifdef DEBUG printk ("%s: read: sectors(%ld-%ld), buffer=0x%08lx, remaining=%ld\n" , drive->name, rq->sector, rq->sector+nsect-1 , (unsigned long ) rq->buffer+(nsect<<9 ), rq->nr_sectors-nsect);#endif +ide_unmap_buffer (to); rq->sector += nsect; - rq->buffer += nsect<<9 ; rq->errors =0 ; i = (rq->nr_sectors -= nsect);if (((long )(rq->current_nr_sectors -= nsect)) <=0 )
@@ -201,14 +204,15 @@#endif if ((rq->nr_sectors ==1 ) ^ ((stat &DRQ_STAT ) !=0 )) { rq->sector++; - rq->buffer +=512 ; rq->errors =0 ; i = --rq->nr_sectors; --rq->current_nr_sectors;if (((long )rq->current_nr_sectors) <=0 )ide_end_request (1 , hwgroup);if (i >0 ) { -idedisk_output_data (drive, rq->buffer,SECTOR_WORDS ); +char *to =ide_map_buffer (rq); +idedisk_output_data (drive, to,SECTOR_WORDS ); +ide_unmap_buffer (to);ide_set_handler (drive, &write_intr,WAIT_CMD ,NULL );return ide_started; }
@@ -238,14 +242,13 @@ do { char *buffer; int nsect = rq->current_nr_sectors; - + if (nsect > mcount) nsect = mcount; mcount -= nsect; - buffer = rq->buffer; + buffer = ide_map_buffer(rq); rq->sector += nsect; - rq->buffer += nsect << 9; rq->nr_sectors -= nsect; rq->current_nr_sectors -= nsect;
@@ -259,7 +262,7 @@ }else { rq->bh = bh; rq->current_nr_sectors = bh->b_size >>9 ; - rq->buffer = bh->b_data; + rq->hard_cur_sectors = rq->current_nr_sectors; } }
@@ -268,6 +271,7 @@* re-entering us on the last transfer. */ idedisk_output_data (drive, buffer, nsect<<7 ); +ide_unmap_buffer (buffer); }while (mcount);return 0 ;
@@ -451,8 +455,10 @@return ide_stopped; } }else { +char *buffer =ide_map_buffer (rq);ide_set_handler (drive, &write_intr,WAIT_CMD ,NULL ); -idedisk_output_data (drive, rq->buffer,SECTOR_WORDS ); +idedisk_output_data (drive, buffer,SECTOR_WORDS ); +ide_unmap_buffer (buffer); }return ide_started; }
drivers/ide/ide-dma.c renamed from opt/kernel/linux-2.4.6-pre5/drivers/ide/ide-dma.c +43 -16
94 lines not on this page · raw message
drivers/ide/pdc202xx.c renamed from opt/kernel/linux-2.4.6-pre5/drivers/ide/pdc202xx.c +1 -0
@@ -855,6 +855,7 @@#ifdef CONFIG_BLK_DEV_IDEDMA if (hwif->dma_base) { hwif->dmaproc = &pdc202xx_dmaproc; + hwif->highmem =1 ;if (!noautodma) hwif->autodma =1 ; }else {
drivers/ide/piix.c renamed from opt/kernel/linux-2.4.6-pre5/drivers/ide/piix.c +1 -0
@@ -512,6 +512,7 @@if (!hwif->dma_base)return ; + hwif->highmem =1 ;#ifndef CONFIG_BLK_DEV_IDEDMA hwif->autodma =0 ;#else /* CONFIG_BLK_DEV_IDEDMA */
drivers/scsi/aic7xxx/aic7xxx_linux_host.h renamed from opt/kernel/linux-2.4.6-pre5/drivers/scsi/aic7xxx/aic7xxx_linux_host.h +2 -1
@@ -81,7 +81,8 @@ present: 0, /* number of 7xxx's present */\ unchecked_isa_dma: 0, /* no memory DMA restrictions */\ use_clustering: ENABLE_CLUSTERING, \ - use_new_eh_code: 1 \ + use_new_eh_code: 1, \ + can_dma_32: 1 \ } #endif /* _AIC7XXX_LINUX_HOST_H_ */
drivers/scsi/hosts.c renamed from opt/kernel/linux-2.4.6-pre5/drivers/scsi/hosts.c +1 -0
@@ -230,6 +230,7 @@ retval->cmd_per_lun = tpnt->cmd_per_lun; retval->unchecked_isa_dma = tpnt->unchecked_isa_dma; retval->use_clustering = tpnt->use_clustering; + retval->can_dma_32 = tpnt->can_dma_32; retval->select_queue_depths = tpnt->select_queue_depths;
drivers/scsi/hosts.h renamed from opt/kernel/linux-2.4.6-pre5/drivers/scsi/hosts.h +3 -0
@@ -286,6 +286,8 @@*/ unsigned emulated:1; + unsigned can_dma_32:1; +/* * Name of proc directory */
@@ -384,6 +386,7 @@ unsigned in_recovery:1; unsigned unchecked_isa_dma:1; unsigned use_clustering:1; + unsigned can_dma_32:1;/* * True if this host was loaded as a loadable module */
drivers/scsi/qlogicfc.h renamed from opt/kernel/linux-2.4.6-pre5/drivers/scsi/qlogicfc.h +2 -1
@@ -100,7 +100,8 @@ cmd_per_lun: QLOGICFC_CMD_PER_LUN, \ present: 0, \ unchecked_isa_dma: 0, \ - use_clustering: ENABLE_CLUSTERING \ + use_clustering: ENABLE_CLUSTERING, \ + can_dma_32: 1 \ } #endif /* _QLOGICFC_H */
drivers/scsi/scsi.c renamed from opt/kernel/linux-2.4.6-pre5/drivers/scsi/scsi.c +7 -4
@@ -176,10 +176,13 @@* handler in the list - ultimately they call scsi_request_fn * to do the dirty deed. */ -void scsi_initialize_queue (Scsi_Device * SDpnt,struct Scsi_Host * SHpnt) { -blk_init_queue (&SDpnt->request_queue, scsi_request_fn); -blk_queue_headactive (&SDpnt->request_queue,0 ); - SDpnt->request_queue.queuedata = (void *) SDpnt; +void scsi_initialize_queue (Scsi_Device * SDpnt,struct Scsi_Host * SHpnt) +{ +request_queue_t *q = &SDpnt->request_queue; + +blk_init_queue (q, scsi_request_fn); +blk_queue_headactive (q,0 ); + q->queuedata = (void *) SDpnt; }#ifdef MODULE
drivers/scsi/scsi.h renamed from opt/kernel/linux-2.4.6-pre5/drivers/scsi/scsi.h +1 -1
@@ -391,7 +391,7 @@#define CONTIGUOUS_BUFFERS (X ,Y ) \ (virt_to_phys((X)->b_data+(X)->b_size-1)+1==virt_to_phys((Y)->b_data))#else -#define CONTIGUOUS_BUFFERS (X ,Y ) ((X->b_data+X->b_size) == Y->b_data) +#define CONTIGUOUS_BUFFERS (X ,Y ) (bh_bus((X)) + (X)->b_size == bh_bus((Y)))#endif
drivers/scsi/scsi_lib.c renamed from opt/kernel/linux-2.4.6-pre5/drivers/scsi/scsi_lib.c +19 -33
101 lines not on this page · raw message
drivers/scsi/scsi_merge.c renamed from opt/kernel/linux-2.4.6-pre5/drivers/scsi/scsi_merge.c +52 -84
297 lines not on this page · raw message
drivers/scsi/sym53c8xx.h renamed from opt/kernel/linux-2.4.6-pre5/drivers/scsi/sym53c8xx.h +2 -1
@@ -96,7 +96,8 @@ this_id: 7, \ sg_tablesize: SCSI_NCR_SG_TABLESIZE, \ cmd_per_lun: SCSI_NCR_CMD_PER_LUN, \ - use_clustering: DISABLE_CLUSTERING} + use_clustering: DISABLE_CLUSTERING, \ + can_dma_32: 1} #else
fs/buffer.c renamed from opt/kernel/linux-2.4.6-pre5/fs/buffer.c +5 -7
@@ -1270,13 +1270,11 @@ bh->b_page = page;if (offset >=PAGE_SIZE )BUG (); -if (PageHighMem (page)) -/* -* This catches illegal uses and preserves the offset: -*/ - bh->b_data = (char *)(0 + offset); -else - bh->b_data =page_address (page) + offset; +/* +* ->virtual is NULL on highmem pages, so we can catch the +* offset even though using page_address on it +*/ + bh->b_data =page_address (page) + offset; }/*
include/asm-i386/kmap_types.h renamed from opt/kernel/linux-2.4.6-pre5/include/asm-i386/kmap_types.h +1 -0
@@ -6,6 +6,7 @@KM_BOUNCE_WRITE ,KM_SKB_DATA ,KM_SKB_DATA_SOFTIRQ , +KM_BH_IRQ , KM_TYPE_NR };
include/asm-i386/page.h renamed from opt/kernel/linux-2.4.6-pre5/include/asm-i386/page.h +2 -1
@@ -116,7 +116,8 @@#define __va (x) ((void *)((unsigned long)(x)+PAGE_OFFSET))#define virt_to_page (kaddr) (mem_map + (__pa(kaddr) >> PAGE_SHIFT))#define VALID_PAGE (page) ((page - mem_map) < max_mapnr) - +#define page_to_phys (page) (((page) - mem_map) * PAGE_SIZE) +#define page_to_bus (page) page_to_phys((page))#endif /* __KERNEL__ */
include/asm-i386/pci.h renamed from opt/kernel/linux-2.4.6-pre5/include/asm-i386/pci.h +42 -3
72 lines not on this page · raw message
include/asm-i386/scatterlist.h renamed from opt/kernel/linux-2.4.6-pre5/include/asm-i386/scatterlist.h +23 -1
@@ -1,12 +1,34 @@#ifndef _I386_SCATTERLIST_H#define _I386_SCATTERLIST_H +/* +* temporary measure, include a page and offset. +*/ struct scatterlist { -char * address;/* Location data is to be transferred to */ +struct page * page;/* Location for highmem page, if any */ +char * address;/* Location data is to be transferred to, NULL for +* highmem page */ char * alt_address;/* Location of actual if address is a * dma indirect buffer. NULL otherwise */ +dma_addr_t dma_address;unsigned int length; +unsigned int offset;/* for highmem, page offset */ }; + +extern inline void set_bh_sg (struct scatterlist *sg,struct buffer_head *bh) +{ +if (PageHighMem (bh->b_page)) { + sg->page = bh->b_page; + sg->offset =bh_offset (bh); + sg->address =NULL ; + }else { + sg->page =NULL ; + sg->offset =0 ; + sg->address = bh->b_data; + } + + sg->length = bh->b_size; +}#define ISA_DMA_THRESHOLD (0x00ffffff)
include/linux/blkdev.h renamed from opt/kernel/linux-2.4.6-pre5/include/linux/blkdev.h +24 -1
@@ -38,7 +38,7 @@unsigned long hard_sector, hard_nr_sectors;unsigned int nr_segments;unsigned int nr_hw_segments; -unsigned long current_nr_sectors; +unsigned long current_nr_sectors, hard_cur_sectors;void * special;char * buffer;struct semaphore * sem;
@@ -112,6 +112,8 @@*/ char head_active; +struct page *bounce_limit; +/* * Is meant to protect the queue in the future instead of * io_request_lock
@@ -123,6 +125,27 @@*/ wait_queue_head_t wait_for_request; }; + +extern unsigned long blk_max_low_pfn; + +#define BLK_BOUNCE_HIGH (blk_max_low_pfn * PAGE_SIZE) +#define BLK_BOUNCE_4G PCI_MAX_DMA32 + +extern void blk_queue_bounce_limit (request_queue_t *,unsigned long ); + +#ifdef CONFIG_HIGHMEM +extern struct buffer_head *create_bounce (int ,struct buffer_head *); +extern inline struct buffer_head *blk_queue_bounce (request_queue_t *q,int rw, +struct buffer_head *bh) +{ +if (bh->b_page <= q->bounce_limit) +return bh; + +return create_bounce (rw, bh); +} +#else +#define blk_queue_bounce (q, rw, bh) (bh) +#endif struct blk_dev_struct {/*
include/linux/fs.h renamed from opt/kernel/linux-2.4.6-pre5/include/linux/fs.h +2 -0
@@ -278,6 +278,8 @@#define bh_offset (bh) ((unsigned long)(bh)->b_data & ~PAGE_MASK) +#define bh_bus (bh) (page_to_bus((bh)->b_page) + bh_offset((bh))) +extern void set_bh_page (struct buffer_head *bh,struct page *page,unsigned long offset);#define touch_buffer (bh) SetPageReferenced(bh->b_page)
include/linux/highmem.h renamed from opt/kernel/linux-2.4.6-pre5/include/linux/highmem.h +23 -2
@@ -13,8 +13,7 @@/* declarations for linux/mm/highmem.c */ FASTCALL(unsigned int nr_free_highpages(void)); -extern struct buffer_head *create_bounce (int rw,struct buffer_head * bh_orig); - +extern struct buffer_head *create_bounce (int rw,struct buffer_head * bh_orig);static inline char *bh_kmap (struct buffer_head *bh) {
@@ -26,6 +25,26 @@ kunmap(bh->b_page); } +/* +* remember to add offset! +*/ +static inline char *bh_kmap_irq (struct buffer_head *bh) +{ +unsigned long addr = (unsigned long )kmap_atomic (bh->b_page,KM_BH_IRQ ); + +if (addr & ~PAGE_MASK ) +BUG (); + +return (char *) addr +bh_offset (bh); +} + +static inline void bh_kunmap_irq (char *buffer) +{ +unsigned long ptr = (unsigned long ) buffer &PAGE_MASK ; + +kunmap_atomic ((void *) ptr,KM_BH_IRQ ); +} +#else /* CONFIG_HIGHMEM */ static inline unsigned int nr_free_highpages (void ) {return 0 ; }
@@ -39,6 +58,8 @@#define bh_kmap (bh) ((bh)->b_data)#define bh_kunmap (bh) do { } while (0) +#define bh_kmap_irq (bh) ((bh)->b_data) +#define bh_kunmap_irq (bh) do { } while (0)#endif /* CONFIG_HIGHMEM */
include/linux/ide.h renamed from opt/kernel/linux-2.4.6-pre5/include/linux/ide.h +16 -0
@@ -457,6 +457,7 @@ unsigned reset : 1; /* reset after probe */ unsigned autodma : 1; /* automatically try to enable DMA at boot */ unsigned udma_four : 1; /* 1=ATA-66 capable, 0=default */ + unsigned highmem : 1; /* can do full 32-bit dma */byte channel;/* for dual-port chips: 0=primary, 1=secondary */ #ifdef CONFIG_BLK_DEV_IDEPCI struct pci_dev *pci_dev;/* for pci chipsets */
@@ -752,6 +753,21 @@ ide_preempt,/* insert rq in front of current request */ ide_end /* insert rq at end of list, but don't wait for it */ } ide_action_t; + +/* +* temporarily mapping a (possible) highmem bio +*/ +#define ide_rq_offset (rq) (((rq)->hard_cur_sectors - (rq)->current_nr_sectors) << 9) + +extern inline void *ide_map_buffer (struct request *rq) +{ +return bh_kmap_irq (rq->bh) +ide_rq_offset (rq); +} + +extern inline void ide_unmap_buffer (char *buffer) +{ +bh_kunmap_irq (buffer); +}/* * This function issues a special IDE device request
include/linux/pci.h renamed from opt/kernel/linux-2.4.6-pre5/include/linux/pci.h +2 -0
@@ -314,6 +314,8 @@#define PCI_DMA_FROMDEVICE 2#define PCI_DMA_NONE 3 +#define PCI_MAX_DMA32 (0xffffffff) +#define DEVICE_COUNT_COMPATIBLE 4#define DEVICE_COUNT_IRQ 2#define DEVICE_COUNT_DMA 2
kernel/ksyms.c renamed from opt/kernel/linux-2.4.6-pre5/kernel/ksyms.c +2 -0
@@ -122,6 +122,8 @@EXPORT_SYMBOL (kunmap_high);EXPORT_SYMBOL (highmem_start_page);EXPORT_SYMBOL (create_bounce); +EXPORT_SYMBOL (kmap_prot); +EXPORT_SYMBOL (kmap_pte);#endif /* filesystem internal functions */
Quoted 4 lines · Jens Axboe
Hi,
I updated the patches to 2.4.6-pre5, and removed the zone-dma32 addition. This means that machines with > 4GB of RAM will need to go all
good, we can relax the ZONE_NORMAL later, that's a separate problem with skipping the bounces.
I can see one mm corruption race condition in the patch, you missed nested irq in the for kmap_irq_bh (PIO). You must _always_ __cli/__save_flags before accessing the KMAP_IRQ_BH slot, in case the remapping is required (so _only_ when the page is in the highmem zone). Otherwise memory corruption will happen when the race triggers (for example two ide disks in PIO mode doing I/O at the same time connected to different irq sources).
Andrea
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/
Quoted 8 lines · Andrea Arcangeli
Quoted 4 lines · Jens Axboe
Hi,
I updated the patches to 2.4.6-pre5, and removed the zone-dma32 addition. This means that machines with > 4GB of RAM will need to go all
good, we can relax the
ZONE_NORMALlater, that's a separate problem with skipping the bounces.
Exactly
Quoted 7 lines
I can see one mm corruption race condition in the patch, you missed nested irq in the for
kmap_irq_bh(PIO). You must _always_ __cli/__save_flags before accessing theKMAP_IRQ_BHslot, in case the remapping is required (so _only_ when the page is in the highmem zone). Otherwise memory corruption will happen when the race triggers (for example two ide disks in PIO mode doing I/O at the same time connected to different irq sources).
Ah yes, my bad. This requires some moving around, I'll post an updated patch later tonight. Thanks!
Signature · 6 lines
Jens Axboe -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/
Quoted 10 lines · Jens Axboe
Quoted 7 lines
I can see one mm corruption race condition in the patch, you missed nested irq in the for
kmap_irq_bh(PIO). You must _always_ __cli/__save_flags before accessing theKMAP_IRQ_BHslot, in case the remapping is required (so _only_ when the page is in the highmem zone). Otherwise memory corruption will happen when the race triggers (for example two ide disks in PIO mode doing I/O at the same time connected to different irq sources).Ah yes, my bad. This requires some moving around, I'll post an updated patch later tonight. Thanks!
A prelim and untested fix just whipped up
Signature · 1 line
Jens Axboe
linux/highmem.h renamed from linux/highmem.h~ +34 -1
@@ -26,7 +26,9 @@ }/* -* remember to add offset! +* remember to add offset! caller must also rememer to have done __save_flags +* and __cli prior to calling bh_kmap_irq, and __restore_flags after calling +* bh_kunmap_irq */ static inline char *bh_kmap_irq (struct buffer_head *bh) {
@@ -44,6 +46,37 @@kunmap_atomic ((void *) ptr,KM_BH_IRQ ); } + +static inline void bh_cpy_to_buf (char *buf,struct buffer_head *bh,int len) +{ +unsigned long flags; +char *bh_buf; + +__save_flags (flags); +__cli (); + + bh_buf =bh_kmap_irq (bh); +memcpy (buf, bh_buf, len); +bh_kunmap_irq (bh_buf); + +__restore_flags (flags); +} + +static inline void bh_cpy_from_buf (struct buffer_head *bh,char *buf,int len) +{ +unsigned long flags; +char *bh_buf; + +__save_flags (flags); +__cli (); + + bh_buf =bh_kmap_irq (bh); +memcpy (bh_buf, buf, len); +bh_kunmap_irq (bh_buf); + +__restore_flags (flags); +} +#else /* CONFIG_HIGHMEM */
linux/ide.h renamed from linux/ide.h~ +5 -2
@@ -759,14 +759,17 @@*/ #define ide_rq_offset (rq) (((rq)->hard_cur_sectors - (rq)->current_nr_sectors) << 9) -extern inline void *ide_map_buffer (struct request *rq) +extern inline void *ide_map_buffer (struct request *rq,unsigned long flags); { +__save_flags (flags); +__cli ();return bh_kmap_irq (rq->bh) +ide_rq_offset (rq); } -extern inline void ide_unmap_buffer (char *buffer) +extern inline void ide_unmap_buffer (char *buffer,unsigned long flags) {bh_kunmap_irq (buffer); +__restore_flags (flags); }/*
scsi/scsi_lib.c renamed from scsi/scsi_lib.c~ +2 -5
@@ -566,11 +566,8 @@scsi_free (SCpnt->buffer, SCpnt->sglist_len); }else {if (SCpnt->buffer != req->buffer) { -if (req->cmd ==READ ) { -char *to =bh_kmap_irq (req->bh); -memcpy (to, SCpnt->buffer, SCpnt->bufflen); -bh_kunmap_irq (to); - } +if (req->cmd ==READ ) +bh_cpy_from_buf (req->bh, SCpnt->buffer, SCpnt->bufflen);scsi_free (SCpnt->buffer, SCpnt->bufflen); } }
scsi/scsi_merge.c renamed from scsi/scsi_merge.c~ +2 -5
@@ -1022,11 +1022,8 @@dma_exhausted (SCpnt,0 ); } } -if (req->cmd ==WRITE ) { -char *buf =bh_kmap_irq (bh); -memcpy (buff, buf, this_count <<9 ); -bh_kunmap_irq (buf); - } +if (req->cmd ==WRITE ) +bh_cpy_buf_high (buff, bh, this_count <<9 ); } } SCpnt->request_bufflen = this_count <<9 ;
ide/ide-disk.c renamed from ide/ide-disk.c~ +13 -8
@@ -140,6 +140,7 @@byte stat;int i;unsigned int msect, nsect; +unsigned long flags;struct request *rq;char *to;
@@ -162,14 +163,14 @@ msect -= nsect; }else nsect =1 ; - to =ide_map_buffer (rq); + to =ide_map_buffer (rq, flags);idedisk_input_data (drive, to, nsect *SECTOR_WORDS );#ifdef DEBUG printk ("%s: read: sectors(%ld-%ld), buffer=0x%08lx, remaining=%ld\n" , drive->name, rq->sector, rq->sector+nsect-1 , (unsigned long ) rq->buffer+(nsect<<9 ), rq->nr_sectors-nsect);#endif -ide_unmap_buffer (to); +ide_unmap_buffer (to, flags); rq->sector += nsect; rq->errors =0 ; i = (rq->nr_sectors -= nsect);
@@ -193,6 +194,7 @@int i;ide_hwgroup_t *hwgroup =HWGROUP (drive);struct request *rq = hwgroup->rq; +unsigned long flags;if (!OK_STAT (stat=GET_STAT (),DRIVE_READY ,drive->bad_wstat)) {printk ("%s: write_intr error1: nr_sectors=%ld, stat=0x%02x\n" , drive->name, rq->nr_sectors, stat);
@@ -210,9 +212,9 @@if (((long )rq->current_nr_sectors) <=0 )ide_end_request (1 , hwgroup);if (i >0 ) { -char *to =ide_map_buffer (rq); +char *to =ide_map_buffer (rq, flags);idedisk_output_data (drive, to,SECTOR_WORDS ); -ide_unmap_buffer (to); +ide_unmap_buffer (to, flags);ide_set_handler (drive, &write_intr,WAIT_CMD ,NULL );return ide_started; }
@@ -242,12 +244,13 @@ do { char *buffer; int nsect = rq->current_nr_sectors; + unsigned long flags; if (nsect > mcount) nsect = mcount; mcount -= nsect; - buffer = ide_map_buffer(rq); + buffer = ide_map_buffer(rq, flags); rq->sector += nsect; rq->nr_sectors -= nsect; rq->current_nr_sectors -= nsect;
@@ -271,7 +274,7 @@* re-entering us on the last transfer. */ idedisk_output_data (drive, buffer, nsect<<7 ); -ide_unmap_buffer (buffer); +ide_unmap_buffer (buffer, flags); }while (mcount);return 0 ;
@@ -455,10 +458,12 @@return ide_stopped; } }else { -char *buffer =ide_map_buffer (rq); +unsigned long flags; +char *buffer =ide_map_buffer (rq, flags); +ide_set_handler (drive, &write_intr,WAIT_CMD ,NULL );idedisk_output_data (drive, buffer,SECTOR_WORDS ); -ide_unmap_buffer (buffer); +ide_unmap_buffer (buffer, flags); }return ide_started; }
Quoted 5 lines · Jens Axboe
Quoted 4 lines · Jens Axboe
Quoted 4 lines
I can see one mm corruption race condition in the patch, you missed nested irq in the for
kmap_irq_bh(PIO). You must _always_ __cli/__save_flags before accessing theKMAP_IRQ_BHslot, in case the remapping is required (so _only_ when the page is in the highmem zone).
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Otherwise memory corruption will happen when the race triggers (for example two ide disks in PIO mode doing I/O at the same time connected to different irq sources).
Ah yes, my bad. This requires some moving around, I'll post an updated patch later tonight. Thanks!
A prelim and untested fix just whipped up
Thanks!
I'd prefer if the __cli;__save_flags is embedded in the bh_kmap_irq in the slow path case where the remap is really required. We can avoid the cli for all the memory below 1G. This way it should also be harder to forget to cli ;). During PIO the irq should be enabled otherwise it means either the driver or the hardware is silly.
Plus adding a _fat_ warning in the bh_kmap_irq that nobody should re-enable interupt in the middle.
Andrea
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/
Quoted 16 lines · Andrea Arcangeli
Quoted 5 lines · Jens Axboe
Quoted 4 lines · Jens Axboe
Quoted 4 lines
I can see one mm corruption race condition in the patch, you missed nested irq in the for
kmap_irq_bh(PIO). You must _always_ __cli/__save_flags before accessing theKMAP_IRQ_BHslot, in case the remapping is required (so _only_ when the page is in the highmem zone).^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Otherwise memory corruption will happen when the race triggers (for example two ide disks in PIO mode doing I/O at the same time connected to different irq sources).
Ah yes, my bad. This requires some moving around, I'll post an updated patch later tonight. Thanks!
A prelim and untested fix just whipped up
Quoted 7 lines
Thanks!
I'd prefer if the __cli;__save_flags is embedded in the
bh_kmap_irqin the slow path case where the remap is really required. We can avoid the cli for all the memory below 1G. This way it should also be harder to forget to cli ;). During PIO the irq should be enabled otherwise it means either the driver or the hardware is silly.
Humm yes, I agree. I'll redo it tonight and send an updated incremental. Hopefully I'll be able to upload a new full version too.
Quoted 2 lines
Plus adding a _fat_ warning in the
bh_kmap_irqthat nobody should re-enable interupt in the middle.
Agree :)
Signature · 6 lines
Jens Axboe -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/
Quoted 2 lines · Jens Axboe
Humm yes, I agree. I'll redo it tonight and send an updated incremental. Hopefully I'll be able to upload a new full version too.
I was going to integrate the avoid-bounce-buffer support but I don't find anything recent except the bio patch for 2.5 that you uploaded yesterday:
andrea@athlon:~/mirror/kernel.org/people/axboe > find -mtime -1 ./v2.5
./v2.5/bio-14-pre4 andrea@athlon:~/mirror/kernel.org/people/axboe > find -mtime -25 ./v2.5
./v2.5/bio-14-pre4 andrea@athlon:~/mirror/kernel.org/people/axboe >
The bio patch would better be 2.5 material, I'd prefer only skipping the bounce between 1G to 4G in 2.4. Could you make a new patch with only the bounce skip between 1G and 4G against pre3?
btw, the latest bio patch from yesterday is still broken with respect to nested irqs:
+static inline void *kmap_atomic(struct page *page, enum km_type type) +{
+ unsigned long flags;
+ void *vaddr;
+
+ __save_flags(flags); + __cli(); + vaddr = __kmap_atomic(page, type); + __restore_flags(flags);
+
+ return vaddr;
+}
[..]
+static inline void kunmap_atomic(void *kvaddr, enum km_type type) +{
+#if HIGHMEM_DEBUG
+ unsigned long flags;
+
+ __save_flags(flags); + __cli(); + __kunmap_atomic(kvaddr, type); + __restore_flags(flags);
#endif
}
[..]
+#define bio_kmap_irq(bio) (kmap_atomic(bio_page((bio)), KM_BIO_IRQ) + bio_offset((bio))) +#define bio_kunmap_irq(ptr) kunmap_atomic((void *) (((unsigned long) (ptr)) & PAGE_MASK), KM_BIO_IRQ) [..]
+extern inline void *ide_map_buffer(struct request *rq)
+{
+ return bio_kmap_irq(rq->bio) + ide_rq_offset(rq);
+}
+
+extern inline void ide_unmap_buffer(char *buffer)
+{
+ bio_kunmap_irq(buffer);
+}
[..]
+ char *to = ide_map_buffer(rq); + idedisk_output_data (drive, to, SECTOR_WORDS); + ide_unmap_buffer(to);
[..]
the __cli() and __restore_flags() are not needed in kmap_atomic, and the bio_kmap_irq is still broken, the suprious __restore_flags in kmap_atomic is enabling irq again before you do the PIO, that will corrupt the pte of the KM_BIO_IRQ if a nested irq runs under us.
In short you don't need to __save_flags(); __cli() for all the KM but the BIO_IRQ one, and in the BIO_IRQ case you need to __restore_flags not after setting the pagetable, but after also all the I/O is finished (so in the kunmap, not in the kmap).
Andrea
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/
Quoted 8 lines · Andrea Arcangeli
Quoted 2 lines · Jens Axboe
Humm yes, I agree. I'll redo it tonight and send an updated incremental. Hopefully I'll be able to upload a new full version too.
I was going to integrate the avoid-bounce-buffer support but I don't find anything recent except the bio patch for 2.5 that you uploaded yesterday:
Quoted 7 lines
andrea@athlon:~/mirror/kernel.org/people/axboe > find -mtime -1 ./v2.5
./v2.5/bio-14-pre4 andrea@athlon:~/mirror/kernel.org/people/axboe > find -mtime -25 ./v2.5
./v2.5/bio-14-pre4 andrea@athlon:~/mirror/kernel.org/people/axboe >
Yes that's all yet, I haven't done a new block-highmem just for 2.4 just yet.
Quoted 3 lines
The bio patch would better be 2.5 material, I'd prefer only skipping the bounce between 1G to 4G in 2.4. Could you make a new patch with only the bounce skip between 1G and 4G against pre3?
Will do, but it will probably be after the weekend jfyi.
Quoted 2 lines
btw, the latest bio patch from yesterday is still broken with respect to nested irqs:
[snip]
Duh yes thanks for looking at that, it's not surprising as I haven't taken time to look at this properly yet. That's also why the 2.4 patch wasn't ready as soon as I would've liked. Thanks!
Signature · 6 lines
Jens Axboe -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/
Quoted 1 line · Jens Axboe
Will do, but it will probably be after the weekend jfyi.
Fine with me, thanks!
take your time and have fun,
Andrea
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/