[openib-general] [PATCH] sdp: get rid of in_atomic
Michael S. Tsirkin
mst at mellanox.co.il
Thu May 5 05:04:55 PDT 2005
Hello, Libor!
Here's a rediff against the latest bits. Could you please comment on
this patch?
sdp_kmap and sdp_kunmap use in_atomic and kmap_atomic in an
unsafe manner. The following patch replaces all uses of these macros with
kmap_atomic on IRQ0/IRQ1 slot, while disabling local interrupts.
Works fine for me.
Signed-off-by: Michael S. Tsirkin <mst at mellanox.co.il>
Index: ulp/sdp/sdp_send.c
===================================================================
--- ulp/sdp/sdp_send.c (revision 2235)
+++ ulp/sdp/sdp_send.c (working copy)
@@ -641,6 +641,7 @@ static int sdp_send_data_iocb_src(struct
SDP_BUFF_F_CLR_UNSIG(buff);
if (conn->send_mode == SDP_MODE_COMB) {
+ unsigned long flags;
void *addr;
int pos;
int off;
@@ -662,21 +663,22 @@ static int sdp_send_data_iocb_src(struct
result = -EFAULT;
goto error;
}
- /*
- * map, copy, unmap.
- */
- addr = sdp_kmap(iocb->page_array[pos]);
+
+ local_irq_save(flags);
+
+ addr = kmap_atomic(iocb->page_array[pos], KM_IRQ0);
if (!addr) {
result = -ENOMEM;
+ local_irq_restore(flags);
goto error;
}
memcpy(buff->tail, (addr + off), len);
- sdp_kunmap(iocb->page_array[pos]);
- /*
- * update pointers
- */
+ kunmap_atomic(iocb->page_array[pos], KM_IRQ0);
+
+ local_irq_restore(flags);
+
buff->data_size = len;
buff->tail += len;
@@ -731,14 +733,16 @@ static int sdp_send_iocb_buff_write(stru
counter = (iocb->post + iocb->page_offset) >> PAGE_SHIFT;
offset = (iocb->post + iocb->page_offset) & (~PAGE_MASK);
- while (buff->tail < buff->end &&
- iocb->len > 0) {
- /*
- * map correct page of iocb
- */
- addr = sdp_kmap(iocb->page_array[counter]);
- if (!addr)
+
+ while (buff->tail < buff->end && iocb->len > 0) {
+ unsigned long flags;
+ local_irq_save(flags);
+
+ addr = kmap_atomic(iocb->page_array[counter], KM_IRQ0);
+ if (!addr) {
+ local_irq_restore(flags);
break;
+ }
copy = min((PAGE_SIZE - offset),
(unsigned long)(buff->end - buff->tail));
@@ -756,7 +760,8 @@ static int sdp_send_iocb_buff_write(stru
offset += copy;
offset &= (~PAGE_MASK);
- sdp_kunmap(iocb->page_array[counter++]);
+ kunmap_atomic(iocb->page_array[counter++], KM_IRQ0);
+ local_irq_restore(flags);
}
return 0;
Index: ulp/sdp/sdp_recv.c
===================================================================
--- ulp/sdp/sdp_recv.c (revision 2235)
+++ ulp/sdp/sdp_recv.c (working copy)
@@ -659,12 +659,11 @@ static int sdp_read_buff_iocb(struct sdp
counter = (iocb->post + iocb->page_offset) >> PAGE_SHIFT;
offset = (iocb->post + iocb->page_offset) & (~PAGE_MASK);
- while (buff->data < buff->tail &&
- iocb->len > 0) {
- /*
- * map correct page of iocb
- */
- addr = sdp_kmap(iocb->page_array[counter]);
+ while (buff->data < buff->tail && iocb->len > 0) {
+ unsigned long flags;
+ local_irq_save(flags);
+
+ addr = kmap_atomic(iocb->page_array[counter], KM_IRQ0);
if (!addr)
break;
@@ -684,7 +683,9 @@ static int sdp_read_buff_iocb(struct sdp
iocb->io_addr += copy;
- sdp_kunmap(iocb->page_array[counter++]);
+ kunmap_atomic(iocb->page_array[counter++], KM_IRQ0);
+
+ local_irq_restore(flags);
}
/*
* restore tail from OOB offset.
Index: ulp/sdp/sdp_iocb.h
===================================================================
--- ulp/sdp/sdp_iocb.h (revision 2235)
+++ ulp/sdp/sdp_iocb.h (working copy)
@@ -124,30 +126,4 @@ struct sdpc_iocb_q {
int size; /* current number of IOCBs in table */
};
-/*
- * Address translations
- */
-
-/*
- * sdp_kmap - map a page into kernel space
- */
-static inline void *sdp_kmap(struct page *page)
-{
- if (in_atomic() || irqs_disabled())
- return kmap_atomic(page, KM_IRQ0);
- else
- return kmap(page);
-}
-
-/*
- * sdp_kunmap - unmap a page into kernel space
- */
-static inline void sdp_kunmap(struct page *page)
-{
- if (in_atomic() || irqs_disabled())
- kunmap_atomic(page, KM_IRQ0);
- else
- kunmap(page);
-}
-
#endif /* _SDP_IOCB_H */
--
MST - Michael S. Tsirkin
More information about the general
mailing list