Skip to contentSkip to conversation

msi: Only keep one msi_desc in each slab entry.

PATCH In review Eric W. Biederman 2 participants 5 messages Jul 10, 2006 – Jul 11, 2006 PCI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 msi: Only keep one msi_desc in each slab entry.

It looks like someone confused kmem_cache_create with a different allocator and was attempting to give it knowledge of how many cache entries there were.

With the unfortunate result that each slab entry was big enough to hold every irq.

---
 drivers/pci/msi.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/pci/msi.c +2 -2
index 0cd4a3e..082e942 100644
@@ -40,13 +40,13 @@ msi_register(struct msi_ops *ops)
 
 static void msi_cache_ctor(void *p, kmem_cache_t *cache, unsigned long flags)
 {
-	memset(p, 0, NR_IRQS * sizeof(struct msi_desc));
+	memset(p, 0, sizeof(struct msi_desc));
 }
 
 static int msi_cache_init(void)
 {
 	msi_cachep = kmem_cache_create("msi_cache",
-			NR_IRQS * sizeof(struct msi_desc),
+			sizeof(struct msi_desc),
 		       	0, SLAB_HWCACHE_ALIGN, msi_cache_ctor, NULL);
 	if (!msi_cachep)
 		return -ENOMEM;
Signature · 1 line
1.4.1.gac83a
#1 lore raw
Quoted 18 lines · Eric W. Biederman

It looks like someone confused kmem_cache_create with a different allocator and was attempting to give it knowledge of how many cache entries there were.

With the unfortunate result that each slab entry was big enough to hold every irq.

---
 drivers/pci/msi.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/pci/msi.c +0 -0
index 0cd4a3e..082e942 100644

drivers/pci/msi.c msi_register(struct msi_ops *ops) · line 43

Quoted 5 lines
drivers/pci/msi.c +1 -1
@@ -40,13 +40,13 @@ msi_register(struct msi_ops *ops)
 
 static void msi_cache_ctor(void *p, kmem_cache_t *cache, unsigned long flags)
 {
-       memset(p, 0, NR_IRQS * sizeof(struct msi_desc));
+       memset(p, 0, sizeof(struct msi_desc));

You can use kmem_cache_zalloc() for this.

Quoted 19 lines
drivers/pci/msi.c +1 -2
 }
 
 static int msi_cache_init(void)
 {
        msi_cachep = kmem_cache_create("msi_cache",
-                       NR_IRQS * sizeof(struct msi_desc),
+                       sizeof(struct msi_desc),
                        0, SLAB_HWCACHE_ALIGN, msi_cache_ctor, NULL);
        if (!msi_cachep)
                return -ENOMEM;
--

1.4.1.gac83a

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#2 lore raw
Quoted 20 lines · Pekka Enberg
Quoted 19 lines · Eric W. Biederman

It looks like someone confused kmem_cache_create with a different allocator and was attempting to give it knowledge of how many cache entries there were.

With the unfortunate result that each slab entry was big enough to hold every irq.

---
 drivers/pci/msi.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/pci/msi.c +0 -0
index 0cd4a3e..082e942 100644
@@ -40,13 +40,13 @@ msi_register(struct msi_ops *ops)
 
Quoted 6 lines

drivers/pci/msi.c msi_register(struct msi_ops *ops) · line 43

Quoted 4 lines
drivers/pci/msi.c +1 -1
 static void msi_cache_ctor(void *p, kmem_cache_t *cache, unsigned long flags)
 {
-       memset(p, 0, NR_IRQS * sizeof(struct msi_desc));
+       memset(p, 0, sizeof(struct msi_desc));

You can use kmem_cache_zalloc() for this.

Please look at what the code changes.
Please recognize how very bad the current code is behaving.

As for the rest sure go ahead and create a patch to address it but that really is a separate issue and thus a separate patch.

I'm just trying to keep the kernel from calling BUG_ON the first time a msi irq is allocated on a kernel with a maximum NR_CPUS configuration, and from wasting memory the rest of the time.

Or you know how bad the msi code is when every patch to fix a major issue is followed up comments on how to improve the code even further.

Eric

Quoted 19 lines
Quoted 19 lines
drivers/pci/msi.c +1 -2
 }
 
 static int msi_cache_init(void)
 {
        msi_cachep = kmem_cache_create("msi_cache",
-                       NR_IRQS * sizeof(struct msi_desc),
+                       sizeof(struct msi_desc),
                        0, SLAB_HWCACHE_ALIGN, msi_cache_ctor, NULL);
        if (!msi_cachep)
                return -ENOMEM;
--

1.4.1.gac83a

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#3 lore raw
Quoted 2 lines · Eric W. Biederman

Please look at what the code changes.
Please recognize how very bad the current code is behaving.

Yes, there's plenty of slab confusion going on.

Quoted 9 lines · Eric W. Biederman

As for the rest sure go ahead and create a patch to address it but that really is a separate issue and thus a separate patch.

I'm just trying to keep the kernel from calling BUG_ON the first time a msi irq is allocated on a kernel with a maximum NR_CPUS configuration, and from wasting memory the rest of the time.

Or you know how bad the msi code is when every patch to fix a major issue is followed up comments on how to improve the code even further.

Ok.

---

drivers/pci/msi.c +3 -9
index 36bc7c4..77b08ee 100644
@@ -45,16 +45,11 @@ msi_register(struct msi_ops *ops)
 	return 0;
 }
 
-static void msi_cache_ctor(void *p, kmem_cache_t *cache, unsigned long flags)
-{
-	memset(p, 0, NR_IRQS * sizeof(struct msi_desc));
-}
-
 static int msi_cache_init(void)
 {
 	msi_cachep = kmem_cache_create("msi_cache",
-			NR_IRQS * sizeof(struct msi_desc),
-		       	0, SLAB_HWCACHE_ALIGN, msi_cache_ctor, NULL);
+			sizeof(struct msi_desc),
+		       	0, SLAB_HWCACHE_ALIGN, NULL, NULL);
 	if (!msi_cachep)
 		return -ENOMEM;
 
@@ -402,11 +397,10 @@ static struct msi_desc* alloc_msi_entry(
 {
 	struct msi_desc *entry;
 
-	entry = kmem_cache_alloc(msi_cachep, SLAB_KERNEL);
+	entry = kmem_cache_zalloc(msi_cachep, GFP_KERNEL);
 	if (!entry)
 		return NULL;
 
-	memset(entry, 0, sizeof(struct msi_desc));
 	entry->link.tail = entry->link.head = 0;	/* single message */
 	entry->dev = NULL;
 
#4 lore raw
Quoted 10 lines · Pekka J Enberg
Quoted 2 lines · Eric W. Biederman

Please look at what the code changes.
Please recognize how very bad the current code is behaving.

Yes, there's plenty of slab confusion going on.

Quoted 3 lines · Eric W. Biederman

As for the rest sure go ahead and create a patch to address it but that really is a separate issue and thus a separate patch.

Quoted 8 lines
Quoted 6 lines

I'm just trying to keep the kernel from calling BUG_ON the first time a msi irq is allocated on a kernel with a maximum NR_CPUS configuration, and from wasting memory the rest of the time.

Or you know how bad the msi code is when every patch to fix a major issue is followed up comments on how to improve the code even further.

Ok.

Looks good to me.

Quoted 39 lines

---

drivers/pci/msi.c +3 -9
index 36bc7c4..77b08ee 100644
@@ -45,16 +45,11 @@ msi_register(struct msi_ops *ops)
 	return 0;
 }
 
-static void msi_cache_ctor(void *p, kmem_cache_t *cache, unsigned long flags)
-{
-	memset(p, 0, NR_IRQS * sizeof(struct msi_desc));
-}
-
 static int msi_cache_init(void)
 {
 	msi_cachep = kmem_cache_create("msi_cache",
-			NR_IRQS * sizeof(struct msi_desc),
-		       	0, SLAB_HWCACHE_ALIGN, msi_cache_ctor, NULL);
+			sizeof(struct msi_desc),
+		       	0, SLAB_HWCACHE_ALIGN, NULL, NULL);
 	if (!msi_cachep)
 		return -ENOMEM;
 
@@ -402,11 +397,10 @@ static struct msi_desc* alloc_msi_entry(
 {
 	struct msi_desc *entry;
 
-	entry = kmem_cache_alloc(msi_cachep, SLAB_KERNEL);
+	entry = kmem_cache_zalloc(msi_cachep, GFP_KERNEL);
 	if (!entry)
 		return NULL;
 
-	memset(entry, 0, sizeof(struct msi_desc));
 	entry->link.tail = entry->link.head = 0;	/* single message */
 	entry->dev = NULL;