linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tomasz Figa <tfiga@chromium.org>
To: Sakari Ailus <sakari.ailus@iki.fi>
Cc: Yong Zhi <yong.zhi@intel.com>,
	linux-media@vger.kernel.org,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	"Zheng, Jian Xu" <jian.xu.zheng@intel.com>,
	"Mani, Rajmohan" <rajmohan.mani@intel.com>,
	"Toivonen, Tuukka" <tuukka.toivonen@intel.com>,
	"open list:IOMMU DRIVERS" <iommu@lists.linux-foundation.org>,
	Joerg Roedel <joro@8bytes.org>
Subject: Re: [PATCH 02/12] intel-ipu3: mmu: implement driver
Date: Fri, 9 Jun 2017 21:09:04 +0900	[thread overview]
Message-ID: <CAAFQd5BsS1CyP=Yk2jgLixDoMRtxSuQrrCp7_ne9=vcU0AuyuA@mail.gmail.com> (raw)
In-Reply-To: <20170609111607.GQ1019@valkosipuli.retiisi.org.uk>

On Fri, Jun 9, 2017 at 8:16 PM, Sakari Ailus <sakari.ailus@iki.fi> wrote:
> Hi Tomasz,
>
> On Fri, Jun 09, 2017 at 02:59:10PM +0900, Tomasz Figa wrote:
>> On Fri, Jun 9, 2017 at 1:43 AM, Sakari Ailus <sakari.ailus@iki.fi> wrote:
>> >> >> +static void ipu3_mmu_domain_free(struct iommu_domain *dom)
>> >> >> +{
>> >> >> +       struct ipu3_mmu_domain *mmu_dom =
>> >> >> +               container_of(dom, struct ipu3_mmu_domain, domain);
>> >> >> +       uint32_t l1_idx;
>> >> >> +
>> >> >> +       for (l1_idx = 0; l1_idx < IPU3_MMU_L1PT_PTES; l1_idx++)
>> >> >> +               if (mmu_dom->pgtbl[l1_idx] != mmu_dom->dummy_l2_tbl)
>> >> >> +                       free_page((unsigned long)
>> >> >> +                                 TBL_VIRT_ADDR(mmu_dom->pgtbl[l1_idx]));
>> >> >> +
>> >> >> +       free_page((unsigned long)TBL_VIRT_ADDR(mmu_dom->dummy_page));
>> >> >> +       free_page((unsigned long)TBL_VIRT_ADDR(mmu_dom->dummy_l2_tbl));
>> >>
>> >> I might be overly paranoid, but reading back kernel virtual pointers
>> >> from device accessible memory doesn't seem safe to me. Other drivers
>> >> keep kernel pointers of page tables in a dedicated array (it's only 8K
>> >> of memory, but much better safety).
>> >
>> > Do you happen to have an example of that?
>>
>> Hmm, looks like I misread rockchip-iommu code. Let me quietly back off
>> from this claim, sorry.
>>
>> >
>> > All system memory typically is accessible for devices, I think you wanted to
>> > say that the device is intended to access that memory. Albeit for reading
>> > only.
>>
>> Unless you activate DMAR and make only the memory you want to be
>> accessible to your devices. I know DMAR is a device too, but there is
>> a difference between a system level fixed function IOMMU and a PCI
>> device running a closed source firmware. Still, given Robin's reply,
>> current DMA and IOMMU frameworks might not be able to handle this
>> easily, so let's temporarily forget about this setup. We might revisit
>> it later, with incremental patches, anyway.
>
> I don't think it's needed because
>
> 1) The firmware running on the device only has access to memory mapped to it
> by the MMU and
>
> 2) the MMU L1 page table base address is not writable to the firmware.

If that's the case, then I guess it's fine indeed.

>> >> >> +static int ipu3_mmu_bus_remove(struct device *dev)
>> >> >> +{
>> >> >> +       struct ipu3_mmu *mmu = dev_get_drvdata(dev);
>> >> >> +
>> >> >> +       put_iova_domain(&mmu->iova_domain);
>> >> >> +       iova_cache_put();
>> >>
>> >> Don't we need to set the L1 table address to something invalid and
>> >> invalidate the TLB, so that the IOMMU doesn't reference the page freed
>> >> below anymore?
>> >
>> > I think the expectation is that if a device gets removed, its memory is
>> > unmapped by that time. Unmapping that memory will cause explicit TLB flush.
>>
>> Right, but that will only mark the L2 entries as invalid. The L1 table
>> will still point to the L2 tables installed earlier and the MMU page
>> directory register will still point to the L1 table, despite the call
>> below freeing all the associated memory.
>
> Ah. I think I misunderstood what I read the previous time.
>
> An alternative would be not to release the L1 page table and the dummy pages
> --- the MMU does not have a concept of an invalid page. Now that the domain
> is gone, you can't really use the MMU anyway, can you?

Yes, given the hardware design, that would make sense indeed.

Best regards,
Tomasz

  reply	other threads:[~2017-06-09 12:09 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-05 20:39 [PATCH 00/12] Intel IPU3 ImgU patchset Yong Zhi
2017-06-05 20:39 ` [PATCH 01/12] videodev2.h, v4l2-ioctl: add IPU3 meta buffer format Yong Zhi
2017-06-05 20:43   ` Alan Cox
2017-06-09 10:55     ` Sakari Ailus
2017-06-06  4:30   ` Tomasz Figa
2017-06-06  4:30     ` Tomasz Figa
2017-06-06  7:25       ` Sakari Ailus
2017-06-06  8:04         ` Hans Verkuil
2017-06-06 10:09           ` Tomasz Figa
2017-06-16  5:52             ` Tomasz Figa
2017-06-16  8:25               ` Sakari Ailus
2017-06-16  8:35                 ` Tomasz Figa
2017-06-16  8:49                   ` Sakari Ailus
2017-06-16  9:03                     ` Tomasz Figa
2017-06-16  9:19                       ` Sakari Ailus
2017-06-16  9:29                         ` Tomasz Figa
2017-06-19  9:17                   ` Laurent Pinchart
2017-06-19 10:41                     ` Tomasz Figa
2017-06-05 20:39 ` [PATCH 02/12] intel-ipu3: mmu: implement driver Yong Zhi
2017-06-06  8:07   ` Hans Verkuil
2017-06-16  9:21     ` Sakari Ailus
2017-06-06 10:13   ` Tomasz Figa
2017-06-07  8:35     ` Tomasz Figa
2017-06-08 16:43       ` Sakari Ailus
2017-06-09  5:59         ` Tomasz Figa
2017-06-09 11:16           ` Sakari Ailus
2017-06-09 12:09             ` Tomasz Figa [this message]
2017-06-09  8:26       ` Tuukka Toivonen
2017-06-09 12:10         ` Tomasz Figa
2017-06-07 21:59     ` Sakari Ailus
2017-06-08  7:36       ` Tomasz Figa
2017-06-05 20:39 ` [PATCH 03/12] intel-ipu3: Add DMA API implementation Yong Zhi
2017-06-07  9:47   ` Tomasz Figa
2017-06-07 17:45     ` Alan Cox
2017-06-08  2:55       ` Tomasz Figa
2017-06-08 16:47         ` Sakari Ailus
2017-06-08 13:22     ` Robin Murphy
2017-06-08 14:35       ` Tomasz Figa
2017-06-08 18:07         ` Robin Murphy
2017-06-09  6:20           ` Tomasz Figa
2017-06-09 13:05             ` Robin Murphy
2017-06-05 20:39 ` [PATCH 04/12] intel-ipu3: Add user space ABI definitions Yong Zhi
2017-06-06  8:28   ` Hans Verkuil
2017-06-07 22:22     ` Sakari Ailus
2017-09-05 17:31       ` Zhi, Yong
2018-04-27 12:27       ` Sakari Ailus
2017-06-05 20:39 ` [PATCH 06/12] intel-ipu3: css: imgu dma buff pool Yong Zhi
2017-06-05 20:39 ` [PATCH 07/12] intel-ipu3: css: firmware management Yong Zhi
2017-06-06  8:38   ` Hans Verkuil
2017-06-14 21:46     ` Zhi, Yong
2017-06-16 10:15   ` Tomasz Figa
2017-06-05 20:39 ` [PATCH 08/12] intel-ipu3: params: compute and program ccs Yong Zhi
2017-06-05 20:39 ` [PATCH 09/12] intel-ipu3: css hardware setup Yong Zhi
2017-06-05 20:39 ` [PATCH 10/12] intel-ipu3: css pipeline Yong Zhi
2017-06-05 20:39 ` [PATCH 11/12] intel-ipu3: Add imgu v4l2 driver Yong Zhi
2017-06-06  9:08   ` Hans Verkuil
2017-06-09  9:20     ` Sakari Ailus
2017-06-14 23:40       ` Zhi, Yong
2017-06-05 20:39 ` [PATCH 12/12] intel-ipu3: imgu top level pci device Yong Zhi
2017-06-05 20:46 ` [PATCH 00/12] Intel IPU3 ImgU patchset Alan Cox
2017-06-14 22:26   ` Sakari Ailus
2017-06-15  8:26     ` Andy Shevchenko
2017-06-15  8:37       ` Sakari Ailus
2017-06-06  9:14 ` Hans Verkuil
     [not found] ` <1496695157-19926-6-git-send-email-yong.zhi@intel.com>
2017-06-08  8:29   ` [PATCH 05/12] intel-ipu3: css: tables Tomasz Figa
2017-06-09  9:43     ` Sakari Ailus

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='CAAFQd5BsS1CyP=Yk2jgLixDoMRtxSuQrrCp7_ne9=vcU0AuyuA@mail.gmail.com' \
    --to=tfiga@chromium.org \
    --cc=iommu@lists.linux-foundation.org \
    --cc=jian.xu.zheng@intel.com \
    --cc=joro@8bytes.org \
    --cc=linux-media@vger.kernel.org \
    --cc=rajmohan.mani@intel.com \
    --cc=sakari.ailus@iki.fi \
    --cc=sakari.ailus@linux.intel.com \
    --cc=tuukka.toivonen@intel.com \
    --cc=yong.zhi@intel.com \
    /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;
as well as URLs for NNTP newsgroup(s).