Skip to content

Commit 8e55352

Browse files
lorenzo-stoakesgregkh
authored andcommitted
intel_th: avoid using deprecated page->mapping, index fields
The struct page->mapping, index fields are deprecated and soon to be only available as part of a folio. It is likely the intel_th code which sets page->mapping, index is was implemented out of concern that some aspect of the page fault logic may encounter unexpected problems should they not. However, the appropriate interface for inserting kernel-allocated memory is vm_insert_page() in a VM_MIXEDMAP. By using the helper function vmf_insert_mixed() we can do this with minimal churn in the existing fault handler. By doing so, we bypass the remainder of the faulting logic. The pages are still pinned so there is no possibility of anything unexpected being done with the pages once established. It would also be reasonable to pre-map everything on fault, however to minimise churn we retain the fault handler. We also eliminate all code which clears page->mapping on teardown as this has now become unnecessary. The MSU code relies on faulting to function correctly, so is by definition dependent on CONFIG_MMU. We avoid spurious reports about compilation failure for unsupported platforms by making this requirement explicit in Kconfig as part of this change too. Signed-off-by: Lorenzo Stoakes <[email protected]> Acked-by: Alexander Shishkin <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent e9a573e commit 8e55352

File tree

2 files changed

+8
-24
lines changed

2 files changed

+8
-24
lines changed

drivers/hwtracing/intel_th/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ config INTEL_TH_STH
6060

6161
config INTEL_TH_MSU
6262
tristate "Intel(R) Trace Hub Memory Storage Unit"
63+
depends on MMU
6364
help
6465
Memory Storage Unit (MSU) trace output device enables
6566
storing STP traces to system memory. It supports single

drivers/hwtracing/intel_th/msu.c

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/io.h>
2020
#include <linux/workqueue.h>
2121
#include <linux/dma-mapping.h>
22+
#include <linux/pfn_t.h>
2223

2324
#ifdef CONFIG_X86
2425
#include <asm/set_memory.h>
@@ -976,7 +977,6 @@ static void msc_buffer_contig_free(struct msc *msc)
976977
for (off = 0; off < msc->nr_pages << PAGE_SHIFT; off += PAGE_SIZE) {
977978
struct page *page = virt_to_page(msc->base + off);
978979

979-
page->mapping = NULL;
980980
__free_page(page);
981981
}
982982

@@ -1158,9 +1158,6 @@ static void __msc_buffer_win_free(struct msc *msc, struct msc_window *win)
11581158
int i;
11591159

11601160
for_each_sg(win->sgt->sgl, sg, win->nr_segs, i) {
1161-
struct page *page = msc_sg_page(sg);
1162-
1163-
page->mapping = NULL;
11641161
dma_free_coherent(msc_dev(win->msc)->parent->parent, PAGE_SIZE,
11651162
sg_virt(sg), sg_dma_address(sg));
11661163
}
@@ -1601,22 +1598,10 @@ static void msc_mmap_close(struct vm_area_struct *vma)
16011598
{
16021599
struct msc_iter *iter = vma->vm_file->private_data;
16031600
struct msc *msc = iter->msc;
1604-
unsigned long pg;
16051601

16061602
if (!atomic_dec_and_mutex_lock(&msc->mmap_count, &msc->buf_mutex))
16071603
return;
16081604

1609-
/* drop page _refcounts */
1610-
for (pg = 0; pg < msc->nr_pages; pg++) {
1611-
struct page *page = msc_buffer_get_page(msc, pg);
1612-
1613-
if (WARN_ON_ONCE(!page))
1614-
continue;
1615-
1616-
if (page->mapping)
1617-
page->mapping = NULL;
1618-
}
1619-
16201605
/* last mapping -- drop user_count */
16211606
atomic_dec(&msc->user_count);
16221607
mutex_unlock(&msc->buf_mutex);
@@ -1626,16 +1611,14 @@ static vm_fault_t msc_mmap_fault(struct vm_fault *vmf)
16261611
{
16271612
struct msc_iter *iter = vmf->vma->vm_file->private_data;
16281613
struct msc *msc = iter->msc;
1614+
struct page *page;
16291615

1630-
vmf->page = msc_buffer_get_page(msc, vmf->pgoff);
1631-
if (!vmf->page)
1616+
page = msc_buffer_get_page(msc, vmf->pgoff);
1617+
if (!page)
16321618
return VM_FAULT_SIGBUS;
16331619

1634-
get_page(vmf->page);
1635-
vmf->page->mapping = vmf->vma->vm_file->f_mapping;
1636-
vmf->page->index = vmf->pgoff;
1637-
1638-
return 0;
1620+
get_page(page);
1621+
return vmf_insert_mixed(vmf->vma, vmf->address, page_to_pfn_t(page));
16391622
}
16401623

16411624
static const struct vm_operations_struct msc_mmap_ops = {
@@ -1676,7 +1659,7 @@ static int intel_th_msc_mmap(struct file *file, struct vm_area_struct *vma)
16761659
atomic_dec(&msc->user_count);
16771660

16781661
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
1679-
vm_flags_set(vma, VM_DONTEXPAND | VM_DONTCOPY);
1662+
vm_flags_set(vma, VM_DONTEXPAND | VM_DONTCOPY | VM_MIXEDMAP);
16801663
vma->vm_ops = &msc_mmap_ops;
16811664
return ret;
16821665
}

0 commit comments

Comments
 (0)