[openib-general] Re: Re: [Andrew Morton] inappropriate use of in_atomic()

Michael S. Tsirkin mst at mellanox.co.il
Sun Mar 27 07:58:47 PST 2005


Quoting r. Libor Michalek <libor at topspin.com>:
> Subject: Re: Re: [Andrew Morton] inappropriate use of in_atomic()
> 
> On Sun, Mar 20, 2005 at 08:12:42PM +0200, Michael S. Tsirkin wrote:
> > Quoting r. Libor Michalek <libor at topspin.com>:
> > > Subject: Re: Re: [Andrew Morton] inappropriate use of in_atomic()
> > > 
> > > On Fri, Mar 11, 2005 at 09:31:08AM +0200, Michael S. Tsirkin wrote:
> > > > 
> > > > Sdp also has a couple of uses.
> > > > Maybe we can use the atomic branch in all cases here, as well?
> > > > Libor?
> > > 
> > >   Yes, the case in sdp_iocb.c can probably always take the atomic
> > > path. The kmap/kunmap cases really only care whether we're in an
> > > interrupt, so switching to in_interrupt() should be sufficient.
> > 
> > Recent comments by Andrew indicate that it is better to always
> > use kmap_atomic/kunmap_atomic if possible. This will also
> > let us get rid of the wrapper function, which is good.
> > 
> > Why do you think we need to kmap?
> 
>   I didn't realize that the atomic version was prefered over the
> regular kmap. The only thing that needs to be done is to make sure
> that the local CPU interrupts are off before calling kamp_atomic,
> instead we currently check to see if we're in an interrupt and call
> the appropriate function. I have no problem changing it to just
> atomic.
> 
> -Libor
> 

My understanding is you must give kmap_atomic the proper parameter:
KM_IRQ0/KM_SOFTIRQ0/KM_USR0, to avoid conflicts with other callers of
kmap on the same CPU.

Something like this then?

Signed-off-by: Michael S. Tsirkin <mst at mellanox.co.il>

Index: ulp/sdp/sdp_iocb.h
===================================================================
--- ulp/sdp/sdp_iocb.h	(revision 2050)
+++ ulp/sdp/sdp_iocb.h	(working copy)
@@ -133,10 +133,12 @@
  */
 static inline void *sdp_kmap(struct page *page)
 {
-	if (in_atomic() || irqs_disabled())
+	if (in_irq())
 		return kmap_atomic(page, KM_IRQ0);
+	else if (in_softirq())
+		return kmap_atomic(page, KM_SOFTIRQ0);
 	else
-		return kmap(page);
+		return kmap_atomic(page, KM_USR0);
 }
 
 /*
@@ -144,10 +146,12 @@
  */
 static inline void sdp_kunmap(struct page *page)
 {
-	if (in_atomic() || irqs_disabled())
+	if (in_irq())
 		kunmap_atomic(page, KM_IRQ0);
+	else if (in_softirq())
+		kunmap_atomic(page, KM_SOFTIRQ0);
 	else
-		kunmap(page);
+		kunmap_atomic(page, KM_USR0);
 }
 
 #endif /* _SDP_IOCB_H */
-- 
MST - Michael S. Tsirkin



More information about the general mailing list