From: Alexander Shishkin <alexander.shishkin@linux.intel.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-kernel@vger.kernel.org,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
stable@vger.kernel.org
Subject: [GIT PULL 01/22] intel_th: msu: Fix single mode with IOMMU
Date: Fri, 3 May 2019 11:44:34 +0300 [thread overview]
Message-ID: <20190503084455.23436-2-alexander.shishkin@linux.intel.com> (raw)
In-Reply-To: <20190503084455.23436-1-alexander.shishkin@linux.intel.com>
Currently, the pages that are allocated for the single mode of MSC are not
mapped into the device's dma space and the code is incorrectly using
*_to_phys() in place of a dma address. This fails with IOMMU enabled and
is otherwise bad practice.
Fix the single mode buffer allocation to map the pages into the device's
DMA space.
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Fixes: ba82664c134e ("intel_th: Add Memory Storage Unit driver")
Cc: stable@vger.kernel.org # v4.4+
---
drivers/hwtracing/intel_th/msu.c | 35 +++++++++++++++++++++++++++++---
1 file changed, 32 insertions(+), 3 deletions(-)
diff --git a/drivers/hwtracing/intel_th/msu.c b/drivers/hwtracing/intel_th/msu.c
index ba7aaf421f36..8ff326c0c406 100644
--- a/drivers/hwtracing/intel_th/msu.c
+++ b/drivers/hwtracing/intel_th/msu.c
@@ -84,6 +84,7 @@ struct msc_iter {
* @reg_base: register window base address
* @thdev: intel_th_device pointer
* @win_list: list of windows in multiblock mode
+ * @single_sgt: single mode buffer
* @nr_pages: total number of pages allocated for this buffer
* @single_sz: amount of data in single mode
* @single_wrap: single mode wrap occurred
@@ -104,6 +105,7 @@ struct msc {
struct intel_th_device *thdev;
struct list_head win_list;
+ struct sg_table single_sgt;
unsigned long nr_pages;
unsigned long single_sz;
unsigned int single_wrap : 1;
@@ -617,22 +619,45 @@ static void intel_th_msc_deactivate(struct intel_th_device *thdev)
*/
static int msc_buffer_contig_alloc(struct msc *msc, unsigned long size)
{
+ unsigned long nr_pages = size >> PAGE_SHIFT;
unsigned int order = get_order(size);
struct page *page;
+ int ret;
if (!size)
return 0;
+ ret = sg_alloc_table(&msc->single_sgt, 1, GFP_KERNEL);
+ if (ret)
+ goto err_out;
+
+ ret = -ENOMEM;
page = alloc_pages(GFP_KERNEL | __GFP_ZERO, order);
if (!page)
- return -ENOMEM;
+ goto err_free_sgt;
split_page(page, order);
- msc->nr_pages = size >> PAGE_SHIFT;
+ sg_set_buf(msc->single_sgt.sgl, page_address(page), size);
+
+ ret = dma_map_sg(msc_dev(msc)->parent->parent, msc->single_sgt.sgl, 1,
+ DMA_FROM_DEVICE);
+ if (ret < 0)
+ goto err_free_pages;
+
+ msc->nr_pages = nr_pages;
msc->base = page_address(page);
- msc->base_addr = page_to_phys(page);
+ msc->base_addr = sg_dma_address(msc->single_sgt.sgl);
return 0;
+
+err_free_pages:
+ __free_pages(page, order);
+
+err_free_sgt:
+ sg_free_table(&msc->single_sgt);
+
+err_out:
+ return ret;
}
/**
@@ -643,6 +668,10 @@ static void msc_buffer_contig_free(struct msc *msc)
{
unsigned long off;
+ dma_unmap_sg(msc_dev(msc)->parent->parent, msc->single_sgt.sgl,
+ 1, DMA_FROM_DEVICE);
+ sg_free_table(&msc->single_sgt);
+
for (off = 0; off < msc->nr_pages << PAGE_SHIFT; off += PAGE_SIZE) {
struct page *page = virt_to_page(msc->base + off);
--
2.20.1
next prev parent reply other threads:[~2019-05-03 8:45 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-03 8:44 [GIT PULL 00/22] intel_th: Updates for v5.2 Alexander Shishkin
2019-05-03 8:44 ` Alexander Shishkin [this message]
2019-05-03 8:44 ` [GIT PULL 02/22] intel_th: SPDX-ify the documentation Alexander Shishkin
2019-05-03 8:44 ` [GIT PULL 03/22] intel_th: Rework resource passing between glue layers and core Alexander Shishkin
2019-05-03 8:44 ` [GIT PULL 04/22] intel_th: Skip subdevices if their MMIO is missing Alexander Shishkin
2019-05-03 8:44 ` [GIT PULL 05/22] intel_th: Add "rtit" source device Alexander Shishkin
2019-05-03 8:44 ` [GIT PULL 06/22] intel_th: Communicate IRQ via resource Alexander Shishkin
2019-05-03 8:44 ` [GIT PULL 07/22] intel_th: pci: Use MSI interrupt signalling Alexander Shishkin
2019-05-03 8:44 ` [GIT PULL 08/22] intel_th: msu: Start handling IRQs Alexander Shishkin
2019-05-03 8:44 ` [GIT PULL 09/22] intel_th: Only report useful IRQs to subdevices Alexander Shishkin
2019-05-03 8:44 ` [GIT PULL 10/22] intel_th: msu: Replace open-coded list_{first,last,next}_entry variants Alexander Shishkin
2019-05-03 8:44 ` [GIT PULL 11/22] intel_th: msu: Switch over to scatterlist Alexander Shishkin
2019-05-03 8:44 ` [GIT PULL 12/22] intel_th: msu: Support multipage blocks Alexander Shishkin
2019-05-03 16:15 ` Greg Kroah-Hartman
2019-05-03 8:44 ` [GIT PULL 13/22] intel_th: msu: Factor out pipeline draining Alexander Shishkin
2019-05-03 8:44 ` [GIT PULL 14/22] intel_th: gth: Factor out trace start/stop Alexander Shishkin
2019-05-03 8:44 ` [GIT PULL 15/22] intel_th: Add switch triggering support Alexander Shishkin
2019-05-03 8:44 ` [GIT PULL 16/22] intel_th: msu: Correct the block wrap detection Alexander Shishkin
2019-05-03 8:44 ` [GIT PULL 17/22] intel_th: msu: Add a sysfs attribute to trigger window switch Alexander Shishkin
2019-05-03 8:44 ` [GIT PULL 18/22] intel_th: msu: Add current window tracking Alexander Shishkin
2019-05-03 8:44 ` [GIT PULL 19/22] intel_th: msu: Introduce buffer driver interface Alexander Shishkin
2019-05-03 16:19 ` Greg Kroah-Hartman
2019-05-03 8:44 ` [GIT PULL 20/22] intel_th: msu: Add a sysfs attribute showing possible modes Alexander Shishkin
2019-05-03 16:13 ` Greg Kroah-Hartman
2019-05-03 8:44 ` [GIT PULL 21/22] intel_th: msu-sink: An example msu buffer driver Alexander Shishkin
2019-05-03 8:44 ` [GIT PULL 22/22] intel_th: msu: Preserve pre-existing buffer configuration Alexander Shishkin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190503084455.23436-2-alexander.shishkin@linux.intel.com \
--to=alexander.shishkin@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox