All of lore.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@qumranet.com>
To: "Kay, Allen M" <allen.m.kay@intel.com>
Cc: kvm@vger.kernel.org, Amit Shah <amit.shah@qumranet.com>,
	Muli Ben-Yehuda <MULI@il.ibm.com>,
	Ben-Ami Yassour <benami@il.ibm.com>,
	Anthony Liguori <anthony@codemonkey.ws>,
	Chris Wright <chrisw@redhat.com>,
	"Han, Weidong" <weidong.han@intel.com>
Subject: Re: [PATCH 4/4][VTD] vt-d specific files in KVM
Date: Fri, 20 Jun 2008 21:24:15 +0300	[thread overview]
Message-ID: <485BF5CF.3060608@qumranet.com> (raw)
In-Reply-To: <1FE6DD409037234FAB833C420AA843EC018831D5@orsmsx424.amr.corp.intel.com>

Kay, Allen M wrote:
> vt-d specific files in KVM for contructing vt-d page tables and
> programming vt-d context entries.
>
> Signed-off-by: Allen M. Kay <allen.m.kay@intel.com>
>   
> diff --git a/arch/x86/kvm/vtd.c b/arch/x86/kvm/vtd.c
> new file mode 100644
> index 0000000..634802c
> --- /dev/null
> +++ b/arch/x86/kvm/vtd.c
> @@ -0,0 +1,197 @@
> +/*
> + * Copyright (c) 2006, Intel Corporation.
> + *
> + * This program is free software; you can redistribute it and/or 
> modify it
> + * under the terms and conditions of the GNU General Public License,
> + * version 2, as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope it will be useful, but WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public 
> License for
> + * more details.
> + *
> + * You should have received a copy of the GNU General Public License 
> along with
> + * this program; if not, write to the Free Software Foundation, Inc., 
> 59 Temple
> + * Place - Suite 330, Boston, MA 02111-1307 USA.
> + *
> + * Copyright (C) 2006-2008 Intel Corporation
> + * Author: Allen M. Kay <allen.m.kay@intel.com>
> + * Author: Weidong Han <weidong.han@intel.com>
> + */
> +
> +#include <linux/list.h>
> +#include <linux/kvm_host.h>
> +#include <linux/pci.h>
> +#include <linux/dmar.h>
> +#include <linux/intel-iommu.h>
> +#include "vtd.h"
> +
> +int kvm_iommu_map_pages(struct kvm *kvm,
> +    gfn_t base_gfn, unsigned long npages)
> +{
> +    gfn_t gfn = base_gfn;
> +    pfn_t pfn;
> +    struct page *page;
> +    int i, rc;
> +
> +    if (!kvm->arch.domain)
> +        return -EFAULT;
> +
> +    printk(KERN_DEBUG "kvm_iommu_map_page: gpa = %lx\n",
> +        gfn << PAGE_SHIFT);
> +    printk(KERN_DEBUG "kvm_iommu_map_page: hpa = %lx\n",
> +        gfn_to_pfn(kvm, base_gfn) << PAGE_SHIFT);
> +    printk(KERN_DEBUG "kvm_iommu_map_page: size = %lx\n",
> +        npages*PAGE_SIZE);
> +
> +    for (i = 0; i < npages; i++) {
> +        pfn = gfn_to_pfn(kvm, gfn);
> +        if (pfn_valid(pfn)) {
> +            rc = kvm_intel_iommu_page_mapping(kvm->arch.domain,
> +                gfn << PAGE_SHIFT, pfn << PAGE_SHIFT,
> +                PAGE_SIZE, DMA_PTE_READ | DMA_PTE_WRITE);
> +            if (rc) {
> +                page = gfn_to_page(kvm, gfn);
> +                put_page(page);

This is racy.  gfn_to_page() can return a different page each time it is 
called.  Instead iommu_map_page() should drop the refcount if it fails.

-- 
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.


      parent reply	other threads:[~2008-06-20 18:24 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-10  0:43 [PATCH 4/4][VTD] vt-d specific files in KVM Kay, Allen M
2008-06-10 10:27 ` Muli Ben-Yehuda
2008-06-10 14:26   ` Anthony Liguori
2008-06-10 14:56     ` Muli Ben-Yehuda
2008-06-10 15:02       ` Anthony Liguori
2008-06-10 15:15         ` Muli Ben-Yehuda
2008-06-10 15:24           ` Anthony Liguori
2008-06-10 16:07             ` Muli Ben-Yehuda
2008-06-20 18:24 ` Avi Kivity [this message]

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=485BF5CF.3060608@qumranet.com \
    --to=avi@qumranet.com \
    --cc=MULI@il.ibm.com \
    --cc=allen.m.kay@intel.com \
    --cc=amit.shah@qumranet.com \
    --cc=anthony@codemonkey.ws \
    --cc=benami@il.ibm.com \
    --cc=chrisw@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=weidong.han@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.