Skip to contentSkip to conversation

stm class/intel_th: Fixes for v4.17

GIT PULL Alexander Shishkin 1 participant 3 messages May 24, 2018

Subsystems (5)
lore
Share & tools
lore

Alexander Shishkin

author maintainer
#0 lore raw

Hi Greg,

These are 2 fixes I have for this release cycle, pretty straightforward. Static checkers approve. Individual patches follow. Please consider pulling or applying. Thanks!

The following changes since commit 60cc43fc888428bb2f18f08997432d426a243338:

Linux 4.17-rc1 (2018-04-15 18:24:20 -0700)

are available in the Git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/ash/stm.git tags/stm-intel_th-fixes-for-greg-20180524

for you to fetch changes up to 3ce35db3ff05400e5676d0155cf261cc6bd3d351:

intel_th: Use correct device when freeing buffers (2018-05-24 10:55:03 +0300)

----------------------------------------------------------------
stm class/intel_th: Fixes for v4.17-rc1

These are 2 fixes, both backportable to stable:
* stm master array allocation moved to vmalloc
* intel_th/msu dma buffer deallocation fix.

----------------------------------------------------------------
Alexander Shishkin (2):
stm class: Use vmalloc for the master map
intel_th: Use correct device when freeing buffers

 drivers/hwtracing/intel_th/msu.c | 6 +++---
 drivers/hwtracing/stm/core.c     | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)
Signature · 1 line
2.17.0
author maintainer
#1 lore raw

[GIT PULL 1/2] stm class: Use vmalloc for the master map

Fengguang is running into a warning from the buddy allocator:

Quoted 4 lines

swapper/0: page allocation failure: order:9, mode:0x14040c0(GFP_KERNEL|__GFP_COMP), nodemask=(null)

CPU: 1 PID: 1 Comm: swapper/0 Not tainted 4.17.0-rc1 #262
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1 04/01/2014
Call Trace:

...

Quoted 2 lines
 __kmalloc+0x14b/0x180: ____cache_alloc at mm/slab.c:3127
 stm_register_device+0xf3/0x5c0: stm_register_device at drivers/hwtracing/stm/core.c:695

...

Which is basically a result of the stm class trying to allocate ~512kB for the dummy_stm with its default parameters. There's no reason, however, for it not to be vmalloc()ed instead, which is what this patch does.

---
 drivers/hwtracing/stm/core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/hwtracing/stm/core.c +3 -3
index 05386b76465e..657badb479a5 100644
@@ -674,7 +674,7 @@ static void stm_device_release(struct device *dev)
 {
 	struct stm_device *stm = to_stm_device(dev);
 
-	kfree(stm);
+	vfree(stm);
 }
 
 int stm_register_device(struct device *parent, struct stm_data *stm_data,
@@ -691,7 +691,7 @@ int stm_register_device(struct device *parent, struct stm_data *stm_data,
 		return -EINVAL;
 
 	nmasters = stm_data->sw_end - stm_data->sw_start + 1;
-	stm = kzalloc(sizeof(*stm) + nmasters * sizeof(void *), GFP_KERNEL);
+	stm = vzalloc(sizeof(*stm) + nmasters * sizeof(void *));
 	if (!stm)
 		return -ENOMEM;
 
@@ -744,7 +744,7 @@ int stm_register_device(struct device *parent, struct stm_data *stm_data,
 	/* matches device_initialize() above */
 	put_device(&stm->dev);
 err_free:
-	kfree(stm);
+	vfree(stm);
 
 	return err;
 }
Signature · 1 line
2.17.0
author maintainer
#2 lore raw

[GIT PULL 2/2] intel_th: Use correct device when freeing buffers

In reply to Alexander Shishkin

Commit d5c435df4a890 ("intel_th: msu: Use the real device in case of IOMMU domain allocation") changes dma buffer allocation to use the actual underlying device, but forgets to change the deallocation path, which leads to (if you've got CAP_SYS_RAWIO):

Quoted 5 lines
# echo 0,0 > /sys/bus/intel_th/devices/0-msc0/nr_pages
------------[ cut here ]------------
kernel BUG at ../linux/drivers/iommu/intel-iommu.c:3670!
CPU: 3 PID: 231 Comm: sh Not tainted 4.17.0-rc1+ #2729
RIP: 0010:intel_unmap+0x11e/0x130

...

Quoted 3 lines
Call Trace:
 intel_free_coherent+0x3e/0x60
 msc_buffer_win_free+0x100/0x160 [intel_th_msu]

This patch fixes the buffer deallocation code to use the correct device.

Fixes d5c435df4a890 ("intel_th: msu: Use the real device in case of IOMMU domain allocation")
CC [email protected] # v4.14+
---
 drivers/hwtracing/intel_th/msu.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/hwtracing/intel_th/msu.c +3 -3
index ede388309376..634f58042c77 100644
@@ -733,8 +733,8 @@ static int msc_buffer_win_alloc(struct msc *msc, unsigned int nr_blocks)
 		/* Reset the page to write-back before releasing */
 		set_memory_wb((unsigned long)win->block[i].bdesc, 1);
 #endif
-		dma_free_coherent(msc_dev(msc), size, win->block[i].bdesc,
-				  win->block[i].addr);
+		dma_free_coherent(msc_dev(msc)->parent->parent, size,
+				  win->block[i].bdesc, win->block[i].addr);
 	}
 	kfree(win);
 
@@ -769,7 +769,7 @@ static void msc_buffer_win_free(struct msc *msc, struct msc_window *win)
 		/* Reset the page to write-back before releasing */
 		set_memory_wb((unsigned long)win->block[i].bdesc, 1);
 #endif
-		dma_free_coherent(msc_dev(win->msc), PAGE_SIZE,
+		dma_free_coherent(msc_dev(win->msc)->parent->parent, PAGE_SIZE,
 				  win->block[i].bdesc, win->block[i].addr);
 	}
 
Signature · 1 line
2.17.0