From: Linda Knippers <linda.knippers-VXdhtT5mjnY@public.gmane.org>
To: Alex Williamson
<alex.williamson-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Cc: David Woodhouse <dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>,
"iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org"
<iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>,
"Khan, Shuah" <shuah.khan-VXdhtT5mjnY@public.gmane.org>,
"Mingarelli,
Thomas" <Thomas.Mingarelli-VXdhtT5mjnY@public.gmane.org>
Subject: Re: [PATCH v2] Intel IOMMU patch to reprocess RMRR info
Date: Thu, 27 Sep 2012 17:50:37 -0400 [thread overview]
Message-ID: <5064CA2D.3030206@hp.com> (raw)
In-Reply-To: <1348781647.2320.264.camel-85EaTFmN5p//9pzu0YdTqQ@public.gmane.org>
Alex Williamson wrote:
> On Thu, 2012-09-27 at 21:10 +0000, Mingarelli, Thomas wrote:
>> Alex,
>>
>> Are you suggesting that a solution is to prevent devices with RMRRs
>> from being placed in the SI Domain in the first place (when pt mode is
>> used)?
>
> No, it seems like it's preferable that devices with RMRRs stay in the si
> domain if the device supports 64bit DMA. They're likely to cause less
> problems there and we can ignore the RMRRs in the si domain. The
> problem I'm trying to address is that the domain you're setting up with
> RMRRs is only used for dma_ops (ie. host driver use). If the device is
> attached to a guest, that domain gets discarded and the device is added
> to yet another domain, potentially with other devices. That domain is
> missing RMRRs, so now your device is going to generate VT-d faults. The
> device can then get removed from that domain, in which case the RMRRs
> should be removed, and again a new dma_ops domain needs to get created
> with RMRRs.
>
> It really seems like RMRRs are incompatible with IOMMU API use though.
> If an RMRR is setup for a VM domain, that's bad because a) it gives the
> VM direct access to that range of host memory, and b) it interferes with
> the guest use of the address space. a) is also bad for isolating
> devices on the host, but the spec makes it available for abuse. For b),
> it's not hard to imagine an RMRR range on the host that overlaps with
> DMA'able space on the guest. Data is read or written to the host memory
> instead of the guest memory. So maybe the right answer is to make
> intel_iommu_attach_device return error if requested to act on a device
> with RMRR ranges.
That sounds like the right answer to me. Tom, can you make that
change when you address the rest of the comments? Or should it
be a separate patch?
-- ljk
> Thanks,
>
> Alex
>
>> -----Original Message-----
>> From: Alex Williamson [mailto:alex.williamson-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org]
>> Sent: Thursday, September 27, 2012 3:37 PM
>> To: Mingarelli, Thomas
>> Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org; Knippers, Linda; Khan, Shuah; Don Dutile; David Woodhouse
>> Subject: Re: [PATCH v2] Intel IOMMU patch to reprocess RMRR info
>>
>> [adding David Woodhouse]
>>
>> On Tue, 2012-09-18 at 16:49 +0000, Tom Mingarelli wrote:
>>> When a 32bit PCI device is removed from the SI Domain, the RMRR information
>>> for this device becomes invalid and needs to be reprocessed to avoid DMA
>>> Read errors. These errors are evidenced by the Present bit being cleared in
>>> the device's context entry. Fixing this problem with an enhancement to process
>>> the RMRR info when the device is assigned to another domain. The Bus Master bit
>>> is cleared during the move to another domain and during the reprocessing of
>>> the RMRR info so no DMA can take place at this time.
>>> ----
>>> PATCH v1: https://lkml.org/lkml/2012/6/15/204
>>>
>>> drivers/iommu/intel-iommu.c | 47 ++++++++++++++++++++++++++++++++++++++++--
>>> 1 files changed, 44 insertions(+), 3 deletions(-)
>>>
>>> Signed-off-by: Thomas Mingarelli <thomas.mingarelli-VXdhtT5mjnY@public.gmane.org>
>>>
>>> diff -up ./drivers/iommu/intel-iommu.c.ORIG ./drivers/iommu/intel-iommu.c
>>> --- ./drivers/iommu/intel-iommu.c.ORIG 2012-09-18 09:58:25.147976889 -0500
>>> +++ ./drivers/iommu/intel-iommu.c 2012-09-18 10:39:43.286672765 -0500
>>> @@ -2706,11 +2706,39 @@ static int iommu_dummy(struct pci_dev *p
>>> return pdev->dev.archdata.iommu == DUMMY_DEVICE_DOMAIN_INFO;
>>> }
>>>
>>> +static int reprocess_rmrr(struct device *dev)
>>> +{
>>> + struct dmar_rmrr_unit *rmrr;
>>> + struct pci_dev *pdev;
>>> + int i, ret;
>>> +
>>> + pdev = to_pci_dev(dev);
>>> +
>>> + for_each_rmrr_units(rmrr) {
>>> + for (i = 0; i < rmrr->devices_cnt; i++) {
>>> + /*
>>> + * Here we are just concerned with
>>> + * finding the one device that was
>>> + * removed from the si_domain and
>>> + * re-evaluating its RMRR info.
>>> + */
>> I'm still not sure why this comment is wrapped so tightly.
>>
>>> + if (rmrr->devices[i] != pdev)
>>> + continue;
>>> + pr_info("IOMMU: Reprocess RMRR information for device %s.\n",
>>> + pci_name(pdev));
>>> + ret = iommu_prepare_rmrr_dev(rmrr, pdev);
>>> + if (ret)
>>> + pr_err("IOMMU: Reprocessing RMRR reserved region for device failed");
>> This could be "if (iommu_prepare_rmrr...)" because...
>>
>>> + }
>>> + }
>>> +return 0;
>> Why does return anything? Looks like it could be a void function since
>> you're not returning the only possible error case above and not checking
>> the return value below. You're missing an indent here anyway.
>>
>>> +}
>>> +
>>> /* Check if the pdev needs to go through non-identity map and unmap process.*/
>>> static int iommu_no_mapping(struct device *dev)
>>> {
>>> struct pci_dev *pdev;
>>> - int found;
>>> + int found, current_bus_master;
>>>
>>> if (unlikely(dev->bus != &pci_bus_type))
>>> return 1;
>>> @@ -2731,9 +2759,22 @@ static int iommu_no_mapping(struct devic
>>> * 32 bit DMA is removed from si_domain and fall back
>>> * to non-identity mapping.
>>> */
>>> - domain_remove_one_dev_info(si_domain, pdev);
>>> printk(KERN_INFO "32bit %s uses non-identity mapping\n",
>>> - pci_name(pdev));
>>> + pci_name(pdev));
>> White space damage? Change this to a pr_info if you really want to
>> touch it.
>>
>>> + /*
>>> + * If a device gets this far we need to clear the Bus
>>> + * Master bit before we start moving devices from domain
>>> + * to domain. We will also reset the Bus Master bit
>>> + * after reprocessing the RMRR info. However, we only
>>> + * do both the clearing and setting if needed.
>>> + */
>>> + current_bus_master = pdev->is_busmaster;
>>> + if (current_bus_master)
>>> + pci_clear_master(pdev);
>>> + domain_remove_one_dev_info(si_domain, pdev);
>>> + reprocess_rmrr(dev);
>>> + if (current_bus_master)
>>> + pci_set_master(pdev);
>> I don't know any better way to halt DMA since we can't move the device
>> to a new domain atomically, but what about the other cases where we
>> switch domains? For instance, what if some unsuspecting user tries to
>> assign the device to a guest? I think it's generally inadvisable to
>> assign a devices with RMRRs to a guest, but if they do, they're going to
>> run into the same problem. The RMRRs aren't reprocessed for the VM
>> domain and again aren't reprocessed when returned to a standard device
>> domain. Even more fun, if assigned to a VM domain, RMRRs should be
>> added with the device and removed if the device is later detached from
>> the domain.
>>
>> The lazy solution might be to disallow devices with RMRRs from being
>> attached via the IOMMU API interfaces (do we need more reasons not to
>> use RMRRs?). Otherwise we need to be proactive about setting up a new
>> domain with RMRR entries for every case and correctly tracking RMRRs for
>> VM domains. Thanks,
>>
>> Alex
>>
>>> return 0;
>>> }
>>> } else {
>>
>>
>
>
>
next prev parent reply other threads:[~2012-09-27 21:50 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-18 16:49 [PATCH v2] Intel IOMMU patch to reprocess RMRR info Tom Mingarelli
[not found] ` <20120918164955.12296.28799.sendpatchset-jP8EmR9A9vELnkn81s9yt/egYHeGw8Jk@public.gmane.org>
2012-09-18 17:46 ` Don Dutile
2012-09-27 20:36 ` Alex Williamson
[not found] ` <1348778200.2320.241.camel-85EaTFmN5p//9pzu0YdTqQ@public.gmane.org>
2012-09-27 21:10 ` Mingarelli, Thomas
[not found] ` <9774516974AF5F4C8A2C3C69CD3412332338F452-KNyhpuZufFMSZAcGdq5asR6epYMZPwEe5NbjCUgZEJk@public.gmane.org>
2012-09-27 21:34 ` Alex Williamson
[not found] ` <1348781647.2320.264.camel-85EaTFmN5p//9pzu0YdTqQ@public.gmane.org>
2012-09-27 21:50 ` David Woodhouse
[not found] ` <1348782605.2036.117.camel-Fexsq3y4057IgHVZqg5X0TlWvGAXklZc@public.gmane.org>
2012-09-28 9:46 ` Joerg Roedel
[not found] ` <20120928094625.GI10549-5C7GfCeVMHo@public.gmane.org>
2012-09-28 10:23 ` David Woodhouse
[not found] ` <1348827803.2036.121.camel-Fexsq3y4057IgHVZqg5X0TlWvGAXklZc@public.gmane.org>
2012-09-28 12:03 ` Joerg Roedel
2012-09-27 21:50 ` Linda Knippers [this message]
[not found] ` <5064CA2D.3030206-VXdhtT5mjnY@public.gmane.org>
2012-09-27 21:48 ` Mingarelli, Thomas
2012-09-27 21:52 ` Alex Williamson
2012-09-28 9:43 ` Joerg Roedel
[not found] ` <20120928094301.GH10549-5C7GfCeVMHo@public.gmane.org>
2012-09-28 12:40 ` Alex Williamson
[not found] ` <1348836008.2320.284.camel-85EaTFmN5p//9pzu0YdTqQ@public.gmane.org>
2012-09-28 12:52 ` Joerg Roedel
[not found] ` <20120928125246.GK10549-5C7GfCeVMHo@public.gmane.org>
2012-09-28 13:21 ` Alex Williamson
-- strict thread matches above, loose matches on Subject: below --
2012-09-18 17:27 Tom Mingarelli
2012-09-28 15:52 David Woodhouse
[not found] ` <uh6q9m8bwu6c2jov69m2aivu.1348847561292-2ueSQiBKiTY7tOexoI0I+QC/G2K4zDHf@public.gmane.org>
2012-09-28 16:30 ` Alex Williamson
2012-09-28 16:36 ` Linda Knippers
[not found] ` <5065D1F5.1090003-VXdhtT5mjnY@public.gmane.org>
2012-09-28 17:01 ` Joerg Roedel
[not found] ` <20120928170106.GE18962-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2012-09-28 17:06 ` Joerg Roedel
2012-09-28 17:28 ` Alex Williamson
2012-09-28 19:15 ` David Woodhouse
[not found] ` <1348859719.2036.128.camel-Fexsq3y4057IgHVZqg5X0TlWvGAXklZc@public.gmane.org>
2012-09-28 19:21 ` Mingarelli, Thomas
2012-09-28 19:35 ` Shuah Khan
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=5064CA2D.3030206@hp.com \
--to=linda.knippers-vxdhtt5mjny@public.gmane.org \
--cc=Thomas.Mingarelli-VXdhtT5mjnY@public.gmane.org \
--cc=alex.williamson-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
--cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
--cc=shuah.khan-VXdhtT5mjnY@public.gmane.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;
as well as URLs for NNTP newsgroup(s).