Skip to contentSkip to conversation

SLAB vs. pci_alloc_xxx in usb-uhci patch

DISCUSSION Peter Zaitcev 3 participants 4 messages Mar 6, 2001 – Mar 7, 2001

lore
Share & tools
lore
#0 lore raw
Quoted 6 lines

From: "David S. Miller" <[email protected]>
Date: Mon, 5 Mar 2001 20:53:21 -0800 (PST)

[...]
Gerard Roudier wrote for the sym53c8xx driver the exact thing UHCI/OHCI need for this.

Thanks for the hint.

***

Anyways, is this the end of the discussion regarding my patch? If it goes in, then fine. If not, fine too... Just let me know so that I can close the bug properly. Manfred said plainly "usb-uhci is broken", Alan kinda manuevered around my small problem, Dave Brownell looks unconvinced. So?

-- Pete

#1 lore raw
Quoted 1 line

Anyways, is this the end of the discussion regarding my patch?

I think one of the maintainers for usb-uhci (Georg) said he'd want the general fix ...

Quoted 3 lines

Manfred said plainly "usb-uhci is broken", Alan kinda manuevered around my small problem, Dave Brownell looks unconvinced. So?

There are two problems I see.

(1) CONFIG_SLAB_DEBUG breaks the documented requirement that the slab cache return adequately aligned data ... which the appended patch should probably handle nicely (something like it sure did :-) and with less danger than the large patch you posted.

(2) The USB host controller drivers all need something like a pci_consistent slab cache, which doesn't currently exist. I have something like that in the works, and David Miller noted one driver that I may steal from.

- Dave

slab.c Tue Mar 6 15:05:58 2001 renamed from slab.c-orig Tue Mar 6 15:01:26 2001 +3 -5
@@ -676,12 +676,10 @@
  }
  
 #if DEBUG
+ /* redzoning would break cache alignment requirements */
+ if (flags & SLAB_HWCACHE_ALIGN)
+  flags &= ~SLAB_RED_ZONE;
  if (flags & SLAB_RED_ZONE) {
-  /*
-   * There is no point trying to honour cache alignment
-   * when redzoning.
-   */
-  flags &= ~SLAB_HWCACHE_ALIGN;
   size += 2*BYTES_PER_WORD; /* words for redzone */
  }
 #endif
#2 lore raw
In reply to Peter Zaitcev
Quoted 6 lines · David Brownell

There are two problems I see.

(1) CONFIG_SLAB_DEBUG breaks the documented requirement that the slab cache return adequately aligned data ...

adequately aligned for the _cpu_, not for some controllers. It's neither documented that HW_CACHEALIGN aligns to 16 byte boundaries nor that kmalloc uses HW_CACHEALIGN.

Quoted 15 lines

which the appended patch should probably handle nicely (something like it sure did :-) and with less danger than the large patch you posted.

(2) The USB host controller drivers all need something like a pci_consistent slab cache, which doesn't currently exist. I have something like that in the works, and David Miller noted one driver that I may steal from.

- Dave

slab.c Tue Mar 6 15:05:58 2001 line 681

Quoted 6 lines
slab.c Tue Mar 6 15:05:58 2001 renamed from slab.c-orig Tue Mar 6 15:01:26 2001 +3 -0
@@ -676,12 +676,10 @@
  }
 
 #if DEBUG
+ /* redzoning would break cache alignment requirements */
+ if (flags & SLAB_HWCACHE_ALIGN)
+  flags &= ~SLAB_RED_ZONE;

The problem is that you've just disabled red zoning for kmalloc. And kmalloc is the only case where redzoning is important: If a caller uses kmem_cache_alloc() for a structure then he won't write beyond the end of the structure.

I think everyone agrees that (2) correct fix. I see 2 temporary workarounds: either your patch or

+ #ifdef CONFIG_SLAB_DEBUG
+ #error
+ #endif

in uhci.c.

--
Manfred

#3 lore raw
In reply to Peter Zaitcev
Quoted 6 lines
Quoted 3 lines

(1) CONFIG_SLAB_DEBUG breaks the documented requirement that the slab cache return adequately aligned data ...

adequately aligned for the _cpu_, not for some controllers. It's neither documented that HW_CACHEALIGN aligns to 16 byte boundaries

It's documented in mm/slab.c (line 612 in my ac7+tweaks). "Aligns to hardware cache line." The only cacheline define I've found is in <asm/cache.h> for L1_CACHE_BYTES, which is often more than 16 (not on x86).

If you don't like the patch I forwarded, then please submit one that changes the kmem_cache_create() API spec ... one or the other is needed. (I'd not change that API!!)

Quoted 8 lines

nor that kmalloc uses HW_CACHEALIGN. ...

Quoted 3 lines

+ /* redzoning would break cache alignment requirements */
+ if (flags & SLAB_HWCACHE_ALIGN)
+ flags &= ~SLAB_RED_ZONE;

The problem is that you've just disabled red zoning for kmalloc. And
kmalloc is the only case where redzoning is important: ...

If kmalloc wants to get auto redzoning, then I think it shouldn't be using SLAB_HWCACHE_ALIGN when CONFIG_SLAB_DEBUG.
That'd be another simple fix. (Or, make it use some new flag that's just a performance hint that can be ignored for debugging.)

Quoted 1 line

I think everyone agrees that (2) correct fix.

I was saying that there were two bugs (two fixes needed), and you're saying that there's only one ... despite the evidence of the API spec. But you could persuade me there's a third bug: kmalloc misuse of that kmem_cache API.

Quoted 7 lines

I see 2 temporary workarounds: either your patch or

+ #ifdef CONFIG_SLAB_DEBUG
+ #error
+ #endif

in uhci.c.

Better in linux/drivers/usb/Config.in instead. All the host controller drivers rely on the kmem_cache_create() API spec to be followed. (Even the OHCI driver, when using kmalloc not kmem_cache.)

- Dave