* Christoph Lameter (clameter@sgi.com) wrote:Slub Freeoffset check overflow Check for overflow of the freeoffset version number. I just thought adding this check in CONFIG_SLUB_DEBUG makes sense. It's really unlikely that enough interrupt handlers will nest over the slub fast path, and each of them do about a million alloc/free on 32 bits or a huge amount of alloc/free on 64 bits, but just in case, it seems good to warn if we detect we are half-way to a version overflow. Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca> --- mm/slub.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) Index: linux-2.6-lttng/mm/slub.c =================================================================== --- linux-2.6-lttng.orig/mm/slub.c 2008-02-29 08:05:01.000000000 -0500 +++ linux-2.6-lttng/mm/slub.c 2008-02-29 08:16:13.000000000 -0500 @@ -1660,7 +1660,7 @@ static __always_inline void *slab_alloc( */ #ifdef SLUB_FASTPATH - unsigned long freeoffset, newoffset; + unsigned long freeoffset, newoffset, resoffset; c = get_cpu_slab(s, raw_smp_processor_id()); do { @@ -1682,8 +1682,18 @@ static __always_inline void *slab_alloc( newoffset = freeoffset; newoffset &= ~c->off_mask; newoffset |= (unsigned long)object[c->offset] & c->off_mask; - } while (cmpxchg_local(&c->freeoffset, freeoffset, newoffset) - != freeoffset); + resoffset = cmpxchg_local(&c->freeoffset, freeoffset, + newoffset); +#ifdef CONFIG_SLUB_DEBUG + /* + * Just to be paranoid : warn if we detect that enough + * allocations nested on top of us to get the counter to go + * half-way to overflow. That would be insane to do that much + * allocations in interrupt handers, but check it anyway. + */ + WARN_ON(resoffset - freeoffset > -1UL >> 1); +#endif + } while (resoffset != freeoffset); #else unsigned long flags; @@ -1822,7 +1832,7 @@ static __always_inline void slab_free(st struct kmem_cache_cpu *c; #ifdef SLUB_FASTPATH - unsigned long freeoffset, newoffset; + unsigned long freeoffset, newoffset, resoffset; c = get_cpu_slab(s, raw_smp_processor_id()); debug_check_no_locks_freed(object, s->objsize); @@ -1850,8 +1860,18 @@ static __always_inline void slab_free(st newoffset = freeoffset + c->off_mask + 1; newoffset &= ~c->off_mask; newoffset |= (unsigned long)object & c->off_mask; - } while (cmpxchg_local(&c->freeoffset, freeoffset, newoffset) - != freeoffset); + resoffset = cmpxchg_local(&c->freeoffset, freeoffset, + newoffset); +#ifdef CONFIG_SLUB_DEBUG + /* + * Just to be paranoid : warn if we detect that enough + * allocations nested on top of us to get the counter to go + * half-way to overflow. That would be insane to do that much + * allocations in interrupt handers, but check it anyway. + */ + WARN_ON(resoffset - freeoffset > -1UL >> 1); +#endif + } while (resoffset != freeoffset); #else unsigned long flags; -- Mathieu Desnoyers Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F BA06 3F25 A8FE 3BAE 9A68 --
| Vladislav Bolkhovitin | Re: Integration of SCST in the mainstream Linux kernel |
| Greg Kroah-Hartman | [PATCH 005/196] Chinese: add translation of SubmittingDrivers |
| Yinghai Lu | [PATCH 01/33] x86: add after_bootmem for 32bit |
| Joerg Roedel | [PATCH] AMD IOMMU: replace to_pages macro with iommu_num_pages |
git: | |
| Jan Wielemaker | Re: git filter-branch --subdirectory-filter, still a mistery |
| Nguyễn Thái Ngọc Duy | [PATCH 01/14] Extend index to save more flags |
| davidk | Removing files |
| Guido Ostkamp | [PATCH] Fix "identifier redeclared" compilation error with SUN cc |
| David Miller | [GIT]: Networking |
| Lachlan Andrew | Re: [PATCH] tcp-illinois: incorrect beta usage |
| Julius Volz | [PATCHv2 RFC 01/25] IPVS: Add CONFIG_IP_VS_IPV6 option for IPv6 support |
| Mark Lord | Re: 2.6.25-rc8: FTP transfer errors |
| Richard Stallman | Real men don't attack straw men |
| Greg KH | Re: Free Linux Driver Development! |
| Marcos Laufer | dmesg IBM x3650 OpenBSD 4.3 |
| Mark Kettenis | Re: Random crashes with Intel D945GCLF2 |
