From: Alex Williamson <alex.williamson@redhat.com>
To: Jonathan Nieder <jrnieder@gmail.com>
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
torvalds@linux-foundation.org, akpm@linux-foundation.org,
alan@lxorguk.ukuu.org.uk, Greg KH <gregkh@linuxfoundation.org>,
Marcelo Tosatti <mtosatti@redhat.com>
Subject: Re: [ 49/62] KVM: unmap pages from the iommu when slots are removed
Date: Fri, 27 Apr 2012 16:08:27 -0600 [thread overview]
Message-ID: <1335564507.3112.473.camel@bling.home> (raw)
In-Reply-To: <20120427215408.GD2821@burratino>
On Fri, 2012-04-27 at 16:54 -0500, Jonathan Nieder wrote:
> Hi,
>
> Greg KH wrote:
>
> > 3.3-stable review patch.
> [...]
> > commit 32f6daad4651a748a58a3ab6da0611862175722f upstream.
> >
> > We've been adding new mappings, but not destroying old mappings.
> > This can lead to a page leak
>
> Does 3.0.y need this?
Yep, same issues exists there.
> The patch does not apply as is to 3.0.y because
> the latter lacks v3.3-rc1~131^2~41 ("KVM: introduce kvm_for_each_memslot
> macro"), but a backport is straightforward.
>
> Completely untested. Test results and other comments welcome.
Looks correct to me.
Acked-by: Alex Williamson <alex.williamson@redhat.com>
Thanks,
Alex
> -- >8 --
> From: Alex Williamson <alex.williamson@redhat.com>
> Date: Wed, 11 Apr 2012 09:51:49 -0600
>
> commit 32f6daad4651a748a58a3ab6da0611862175722f upstream.
>
> We've been adding new mappings, but not destroying old mappings.
> This can lead to a page leak as pages are pinned using
> get_user_pages, but only unpinned with put_page if they still
> exist in the memslots list on vm shutdown. A memslot that is
> destroyed while an iommu domain is enabled for the guest will
> therefore result in an elevated page reference count that is
> never cleared.
>
> Additionally, without this fix, the iommu is only programmed
> with the first translation for a gpa. This can result in
> peer-to-peer errors if a mapping is destroyed and replaced by a
> new mapping at the same gpa as the iommu will still be pointing
> to the original, pinned memory address.
>
> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
> ---
> include/linux/kvm_host.h | 6 ++++++
> virt/kvm/iommu.c | 12 ++++++++----
> virt/kvm/kvm_main.c | 5 +++--
> 3 files changed, 17 insertions(+), 6 deletions(-)
>
> diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> index 31ebb59cbd2f..82d5476e69cc 100644
> --- a/include/linux/kvm_host.h
> +++ b/include/linux/kvm_host.h
> @@ -554,6 +554,7 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id);
>
> #ifdef CONFIG_IOMMU_API
> int kvm_iommu_map_pages(struct kvm *kvm, struct kvm_memory_slot *slot);
> +void kvm_iommu_unmap_pages(struct kvm *kvm, struct kvm_memory_slot *slot);
> int kvm_iommu_map_guest(struct kvm *kvm);
> int kvm_iommu_unmap_guest(struct kvm *kvm);
> int kvm_assign_device(struct kvm *kvm,
> @@ -567,6 +568,11 @@ static inline int kvm_iommu_map_pages(struct kvm *kvm,
> return 0;
> }
>
> +static inline void kvm_iommu_unmap_pages(struct kvm *kvm,
> + struct kvm_memory_slot *slot)
> +{
> +}
> +
> static inline int kvm_iommu_map_guest(struct kvm *kvm)
> {
> return -ENODEV;
> diff --git a/virt/kvm/iommu.c b/virt/kvm/iommu.c
> index 62a9caf0563c..fb0f6e469bb4 100644
> --- a/virt/kvm/iommu.c
> +++ b/virt/kvm/iommu.c
> @@ -285,6 +285,11 @@ static void kvm_iommu_put_pages(struct kvm *kvm,
> }
> }
>
> +void kvm_iommu_unmap_pages(struct kvm *kvm, struct kvm_memory_slot *slot)
> +{
> + kvm_iommu_put_pages(kvm, slot->base_gfn, slot->npages);
> +}
> +
> static int kvm_iommu_unmap_memslots(struct kvm *kvm)
> {
> int i, idx;
> @@ -293,10 +298,9 @@ static int kvm_iommu_unmap_memslots(struct kvm *kvm)
> idx = srcu_read_lock(&kvm->srcu);
> slots = kvm_memslots(kvm);
>
> - for (i = 0; i < slots->nmemslots; i++) {
> - kvm_iommu_put_pages(kvm, slots->memslots[i].base_gfn,
> - slots->memslots[i].npages);
> - }
> + for (i = 0; i < slots->nmemslots; i++)
> + kvm_iommu_unmap_pages(kvm, &slots->memslots[i]);
> +
> srcu_read_unlock(&kvm->srcu, idx);
>
> return 0;
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 96ebc0679415..6b39ba9540e8 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -796,12 +796,13 @@ skip_lpage:
> if (r)
> goto out_free;
>
> - /* map the pages in iommu page table */
> + /* map/unmap the pages in iommu page table */
> if (npages) {
> r = kvm_iommu_map_pages(kvm, &new);
> if (r)
> goto out_free;
> - }
> + } else
> + kvm_iommu_unmap_pages(kvm, &old);
>
> r = -ENOMEM;
> slots = kzalloc(sizeof(struct kvm_memslots), GFP_KERNEL);
next prev parent reply other threads:[~2012-04-27 22:08 UTC|newest]
Thread overview: 89+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-24 22:33 [ 00/62] 3.3.4-stable review Greg KH
2012-04-24 22:32 ` [ 01/62] Perf: fix build breakage Greg KH
2012-04-24 22:32 ` [ 02/62] crypto: sha512 - Fix byte counter overflow in SHA-512 Greg KH
2012-04-24 22:32 ` [ 03/62] hwmon: fam15h_power: fix bogus values with current BIOSes Greg KH
2012-04-25 19:45 ` Ben Hutchings
2012-04-25 20:50 ` Guenter Roeck
2012-04-26 16:43 ` Greg KH
2012-04-26 16:47 ` Guenter Roeck
2012-04-26 21:15 ` Greg KH
2012-04-24 22:32 ` [ 04/62] ALSA: hda/conexant - Dont set HP pin-control bit unconditionally Greg KH
2012-04-24 22:32 ` [ 05/62] ALSA: hda/conexant - Set up the missing docking-station pins Greg KH
2012-04-24 22:32 ` [ 06/62] memblock: memblock should be able to handle zero length operations Greg KH
2012-04-24 22:32 ` [ 07/62] ARM: clps711x: serial driver hungs are a result of call disable_irq within ISR Greg KH
2012-04-24 22:32 ` [ 08/62] ARM: at91: fix at91sam9261ek Ethernet dm9000 irq Greg KH
2012-04-24 22:32 ` [ 09/62] ARM: OMAP1: DMTIMER: fix broken timer clock source selection Greg KH
2012-04-24 22:32 ` [ 10/62] ARM: OMAP: serial: Fix the ocp smart idlemode handling bug Greg KH
2012-04-24 22:32 ` [ 11/62] mmc: fixes for eMMC v4.5 discard operation Greg KH
2012-04-24 22:32 ` [ 12/62] mmc: fixes for eMMC v4.5 sanitize operation Greg KH
2012-04-24 22:32 ` [ 13/62] mmc: sdhci: refine non-removable card checking for card detection Greg KH
2012-04-24 22:32 ` [ 14/62] mmc: unbreak sdhci-esdhc-imx on i.MX25 Greg KH
2012-04-27 22:31 ` Jonathan Nieder
2012-04-28 6:03 ` Wolfram Sang
2012-04-30 1:06 ` Greg KH
2012-04-24 22:32 ` [ 15/62] xen/gntdev: do not set VM_PFNMAP Greg KH
2012-04-24 22:32 ` [ 16/62] xen/xenbus: Add quirk to deal with misconfigured backends Greg KH
2012-04-24 22:32 ` [ 17/62] USB: yurex: Remove allocation of coherent buffer for setup-packet buffer Greg KH
2012-04-24 22:32 ` [ 18/62] USB: yurex: Fix missing URB_NO_TRANSFER_DMA_MAP flag in urb Greg KH
2012-04-24 22:33 ` [ 19/62] uwb: fix use of del_timer_sync() in interrupt Greg KH
2012-04-24 22:33 ` [ 20/62] uwb: fix error handling Greg KH
2012-04-24 22:33 ` [ 21/62] davinci_mdio: Fix MDIO timeout check Greg KH
2012-04-24 22:33 ` [ 22/62] mwifiex: update pcie8766 scratch register addresses Greg KH
2012-04-24 22:33 ` [ 23/62] brcm80211: smac: resume transmit fifo upon receiving frames Greg KH
2012-04-25 22:39 ` Jonathan Nieder
2012-04-26 8:48 ` Arend van Spriel
2012-04-26 18:20 ` Jonathan Nieder
2012-04-30 1:04 ` Greg KH
2012-04-24 22:33 ` [ 24/62] mac80211: fix logic error in ibss channel type check Greg KH
2012-04-24 22:33 ` [ 25/62] media: rc-core: set mode for winbond-cir Greg KH
2012-04-24 22:33 ` [ 26/62] media: drxk: Does not unlock mutex if sanity check failed in scu_command() Greg KH
2012-04-24 22:33 ` [ 27/62] media: dvb_frontend: Fix a regression when switching back to DVB-S Greg KH
2012-04-24 22:33 ` [ 28/62] cfg80211: fix interface combinations check Greg KH
2012-04-24 22:33 ` [ 29/62] staging: r8712u: Fix regression caused by commit 8c213fa Greg KH
2012-04-24 22:33 ` [ 30/62] Fix modpost failures in fedora 17 Greg KH
2012-04-26 0:41 ` Jonathan Nieder
2012-04-26 0:48 ` David Miller
2012-04-30 1:05 ` Greg KH
2012-04-24 22:33 ` [ 31/62] mm: fix s390 BUG by __set_page_dirty_no_writeback on swap Greg KH
2012-04-24 22:33 ` [ 32/62] md: dont call ->add_disk unless there is good reason Greg KH
2012-04-24 22:33 ` [ 33/62] md: fix possible corruption of array metadata on shutdown Greg KH
2012-04-24 22:33 ` [ 34/62] jbd2: use GFP_NOFS for blkdev_issue_flush Greg KH
2012-04-24 22:33 ` [ 35/62] USB: serial: cp210x: Fixed usb_control_msg timeout values Greg KH
2012-04-24 22:33 ` [ 36/62] pch_uart: Fix dma channel unallocated issue Greg KH
2012-04-24 22:33 ` [ 37/62] drivers/tty/amiserial.c: add missing tty_unlock Greg KH
2012-04-24 22:33 ` [ 38/62] USB: sierra: avoid QMI/wwan interface on MC77xx Greg KH
2012-04-24 22:33 ` [ 39/62] EHCI: fix criterion for resuming the root hub Greg KH
2012-04-25 6:17 ` Jonathan Nieder
2012-04-30 1:04 ` Greg KH
2012-04-24 22:33 ` [ 40/62] EHCI: always clear the STS_FLR status bit Greg KH
2012-04-24 22:33 ` [ 41/62] USB: fix deadlock in bConfigurationValue attribute method Greg KH
2012-04-24 22:33 ` [ 42/62] usb: gadget: udc-core: stop UDC on device-initiated disconnect Greg KH
2012-04-24 22:33 ` [ 43/62] usb: gadget: udc-core: fix asymmetric calls in remove_driver Greg KH
2012-04-26 0:34 ` Ben Hutchings
2012-04-26 21:16 ` Greg KH
2012-04-27 8:00 ` Felipe Balbi
2012-04-24 22:33 ` [ 44/62] usb: gadget: eliminate NULL pointer dereference (bugfix) Greg KH
2012-04-24 22:33 ` [ 45/62] usb: musb: omap: fix crash when musb glue (omap) gets initialized Greg KH
2012-04-26 0:41 ` Ben Hutchings
2012-04-24 22:33 ` [ 46/62] usb: musb: omap: fix the error check for pm_runtime_get_sync Greg KH
2012-04-24 22:33 ` [ 47/62] PCI: Add quirk for still enabled interrupts on Intel Sandy Bridge GPUs Greg KH
2012-04-24 22:33 ` [ 48/62] ext4: fix endianness breakage in ext4_split_extent_at() Greg KH
2012-04-24 22:33 ` [ 49/62] KVM: unmap pages from the iommu when slots are removed Greg KH
2012-04-27 21:54 ` Jonathan Nieder
2012-04-27 22:08 ` Alex Williamson [this message]
2012-04-30 1:05 ` Greg KH
2012-04-24 22:33 ` [ 50/62] dell-laptop: add 3 machines that has touchpad LED Greg KH
2012-04-24 22:33 ` [ 51/62] dell-laptop: touchpad LED should persist its status after S3 Greg KH
2012-04-24 22:33 ` [ 52/62] Bluetooth: Add support for Atheros [04ca:3005] Greg KH
2012-04-24 22:33 ` [ 53/62] nfsd: fix b0rken error value for setattr on read-only mount Greg KH
2012-04-27 22:42 ` Jonathan Nieder
2012-04-24 22:33 ` [ 54/62] nfsd: fix error values returned by nfsd4_lockt() when nfsd_open() fails Greg KH
2012-04-27 22:54 ` Jonathan Nieder
2012-04-24 22:33 ` [ 55/62] nfsd: fix endianness breakage in TEST_STATEID handling Greg KH
2012-04-24 22:33 ` [ 56/62] nfsd: fix compose_entry_fh() failure exits Greg KH
2012-04-24 22:33 ` [ 57/62] btrfs: btrfs_root_readonly() broken on big-endian Greg KH
2012-04-24 22:33 ` [ 58/62] ocfs2: ->l_next_free_req breakage " Greg KH
2012-04-24 22:33 ` [ 59/62] ocfs: ->rl_used " Greg KH
2012-04-24 22:33 ` [ 60/62] ocfs2: ->rl_count endianness breakage Greg KH
2012-04-24 22:33 ` [ 61/62] ocfs2: ->e_leaf_clusters " Greg KH
2012-04-24 22:33 ` [ 62/62] lockd: fix the endianness bug Greg KH
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=1335564507.3112.473.camel@bling.home \
--to=alex.williamson@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=gregkh@linuxfoundation.org \
--cc=jrnieder@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mtosatti@redhat.com \
--cc=stable@vger.kernel.org \
--cc=torvalds@linux-foundation.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
all inboxes | Powered by JetHome®