public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Muli Ben-Yehuda <muli@il.ibm.com>
To: Anthony Liguori <anthony@codemonkey.ws>
Cc: avi@redhat.com, kvm@vger.kernel.org, weidong.han@intel.com,
	Ben-Ami Yassour1 <BENAMI@il.ibm.com>,
	amit.shah@redhat.com, allen.m.kay@intel.com
Subject: Re: [PATCH 5/6] device assignment: support for assigning PCI devices to guests
Date: Tue, 28 Oct 2008 17:53:05 +0200	[thread overview]
Message-ID: <20081028155305.GE6737@il.ibm.com> (raw)
In-Reply-To: <490733B5.5010102@codemonkey.ws>

On Tue, Oct 28, 2008 at 10:45:57AM -0500, Anthony Liguori wrote:

>> +ifeq ($(USE_KVM), 1)
>> +OBJS+= device-assignment.o
>> +endif
>
> I don't think you want to build this on PPC so I think you need a
> stronger check.

Good point. How about checking TARGET_BASE_ARCH = i386?

>> +static void assigned_dev_ioport_writel(void *opaque, uint32_t addr,
>> +                       uint32_t value)
>> +{
>> +    AssignedDevRegion *r_access = opaque;
>> +    uint32_t r_pio = guest_to_host_ioport(r_access, addr);
>> +
>> +    DEBUG("%s: r_pio=%08x e_physbase=%08x r_virtbase=%08lx value=%08x\n",
>> +	  r_pio, (int)r_access->e_physbase,
>> +          (unsigned long)r_access->r_virtbase, value);
>>   
>
> The format doesn't match the parameter count.

Yep, already fixed.

>> +static void assigned_dev_ioport_map(PCIDevice *pci_dev, int region_num,
>> +                                    uint32_t addr, uint32_t size, int 
>> type)
>> +{
>> +    AssignedDevice *r_dev = (AssignedDevice *) pci_dev;
>> +    AssignedDevRegion *region = &r_dev->v_addrs[region_num];
>> +    uint32_t old_port = region->u.r_baseport;
>> +    uint32_t old_num = region->e_size;
>> +    int first_map = (old_num == 0);
>> +    struct ioperm_data data;
>> +    int i;
>> +
>> +    region->e_physbase = addr;
>> +    region->e_size = size;
>> +
>> +    DEBUG("e_phys=0x%x r_baseport=%x type=0x%x len=%d region_num=%d \n",
>> +          addr, region->u.r_baseport, type, size, region_num);
>> +
>> +    memset(&data, 0, sizeof(data));
>> +
>> +    if (!first_map) {
>> +	data.start_port = old_port;
>> +	data.num = old_num; +	data.turn_on = 0;
>> +
>> +	for (i = 0; i < smp_cpus; ++i)
>> +	    kvm_ioperm(qemu_kvm_cpu_env(i), &data);
>>   
>
> How does this interact with VCPU hot-plug?

I have no idea. Weidong?

>> +#ifdef KVM_CAP_IOMMU
>> +        /* We always enable the IOMMU if present
>> +         * (or when not disabled on the command line)
>> +         */
>> +        r = kvm_check_extension(kvm_context, KVM_CAP_IOMMU);
>> +        if (r && !disable_iommu)
>> +            assigned_dev_data.flags |= KVM_DEV_ASSIGN_ENABLE_IOMMU;
>> +#endif
>> +        r = kvm_assign_pci_device(kvm_context, &assigned_dev_data);
>> +        if (r < 0) {
>> +            fprintf(stderr, "Could not notify kernel about "
>> +                "assigned device \"%s\"\n", e_dev_name);
>> +            perror("register_real_device");
>> +            goto out;
>> +        }
>> +    }
>>   
>
> You still succeed if KVM_CAP_DEVICE_ASSIGNMENT isn't defined?  That
> means a newer userspace compiled on an older kernel will silently
> fail if they try to do device assignment.  There's probably no
> reason to build this file if KVM_CAP_DEVICE_ASSIGNMENT isn't defined
> (see how the in-kernel PIT gets conditionally build depending on
> whether that cap is available).

Ok, I'll take a look at this.

>> +#endif
>> +    term_printf("Registered host PCI device %02x:%02x.%1x "
>> +		"(\"%s\") as guest device %02x:%02x.%1x\n",
>> +		r_bus, r_dev, r_func, e_dev_name,
>> +		pci_bus_num(e_bus), e_device, r_func);
>>
>>   
>
> If I read the code correctly, this term_printf() happens regardless
> of whether this is being done for PCI hotplug or for command-line
> assignment?  That's a problem as it'll print garbage on the monitor
> when you start QEMU which could break management applications.

Is there a more suitable alternative or shall I just nuke it?

>> diff --git a/qemu/hw/pc.c b/qemu/hw/pc.c
>> index d559f0c..5fdb726 100644
>> --- a/qemu/hw/pc.c
>> +++ b/qemu/hw/pc.c
>> @@ -33,6 +33,7 @@
>>  #include "boards.h"
>>  #include "console.h"
>>  #include "fw_cfg.h"
>> +#include "device-assignment.h"
>>   #include "qemu-kvm.h"
>>  @@ -1157,6 +1158,21 @@ static void pc_init1(ram_addr_t ram_size, int 
>> vga_ram_size,
>>       if (pci_enabled)
>>          virtio_balloon_init(pci_bus);
>> +
>> +    if (kvm_enabled() && device_assignment_enabled) {
>> +	int i;
>>   
>
> Stray tab.

Grrr. Silly emacs.

>
>> +        for (i = 0; i < assigned_devices_index; i++) {
>> +            if (add_assigned_device(assigned_devices[i]) < 0) {
>> +                fprintf(stderr, "Warning: could not add assigned device 
>> %s\n",
>> +                        assigned_devices[i]);
>> +            }
>> +        }
>> +
>> +	if (init_all_assigned_devices(pci_bus)) {
>> +	    fprintf(stderr, "Failed to initialize assigned devices\n");
>> +	    exit (1);
>> +	}
>> +    }
>>  }
>>  +#if defined(TARGET_I386) || defined(TARGET_X86_64) || defined(__linux__)
>> +            case QEMU_OPTION_pcidevice:
>> +		device_assignment_enabled = 1;
>> +		if (assigned_devices_index >= MAX_DEV_ASSIGN_CMDLINE) {
>> +                    fprintf(stderr, "Too many assigned devices\n");
>> +                    exit(1);
>> +		}
>> +		assigned_devices[assigned_devices_index] = optarg;
>> +		assigned_devices_index++;
>> +                break;
>>   
>
> Tab damage.

Thanks, will fix in the next revision.

Cheers,
Muli
-- 
The First Workshop on I/O Virtualization (WIOV '08)
Dec 2008, San Diego, CA, http://www.usenix.org/wiov08/
                       <->
SYSTOR 2009---The Israeli Experimental Systems Conference
http://www.haifa.il.ibm.com/conferences/systor2009/

  reply	other threads:[~2008-10-28 15:53 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-28 10:06 [v8] Userspace patches for PCI device assignment muli
2008-10-28 10:06 ` [PATCH 1/6] device assignment: add ioctl wrappers muli
2008-10-28 10:06   ` [PATCH 2/6] device assignment: introduce pci_map_irq to get irq nr from pin number muli
2008-10-28 10:06     ` [PATCH 3/6] device assignment: introduce functions to correlate pin number and irq muli
2008-10-28 10:06       ` [PATCH 4/6] device assignment: build vtd.c for Intel IOMMU support muli
2008-10-28 10:06         ` [PATCH 5/6] device assignment: support for assigning PCI devices to guests muli
2008-10-28 10:06           ` [PATCH 6/6] device assignment: support for hot-plugging PCI devices muli
2008-10-28 14:10           ` [PATCH 5/6] device assignment: support for assigning PCI devices to guests Han, Weidong
2008-10-28 15:32             ` Muli Ben-Yehuda
     [not found]           ` <715D42877B251141A38726ABF5CABF2C018683D874@pdsmsx503.ccr.corp.intel.com>
2008-10-28 15:31             ` Han, Weidong
2008-10-28 15:36           ` Han, Weidong
2008-10-28 15:47             ` Muli Ben-Yehuda
2008-10-28 15:45           ` Anthony Liguori
2008-10-28 15:53             ` Muli Ben-Yehuda [this message]
2008-10-29  7:56               ` Zhang, Xiantao
2008-10-29 10:27                 ` Muli Ben-Yehuda
2008-10-29  8:22               ` Han, Weidong
2008-10-29 10:25               ` Muli Ben-Yehuda
2008-10-29 10:39                 ` Muli Ben-Yehuda
2008-10-28 16:55           ` Mark McLoughlin
2008-10-29 10:31             ` Muli Ben-Yehuda
2008-10-29 11:07               ` Mark McLoughlin
2008-10-29 11:15               ` Mark McLoughlin
2008-10-29 11:47                 ` Muli Ben-Yehuda
2008-10-29  7:38         ` [PATCH 4/6] device assignment: build vtd.c for Intel IOMMU support Zhang, Xiantao
  -- strict thread matches above, loose matches on Subject: below --
2008-10-29 10:22 [v9] Userspace patches for PCI device assignment muli
2008-10-29 10:22 ` [PATCH 1/6] device assignment: add ioctl wrappers muli
2008-10-29 10:22   ` [PATCH 2/6] device assignment: introduce pci_map_irq to get irq nr from pin number muli
2008-10-29 10:22     ` [PATCH 3/6] device assignment: introduce functions to correlate pin number and irq muli
2008-10-29 10:22       ` [PATCH 4/6] device assignment: build vtd.c for Intel IOMMU support muli
2008-10-29 10:22         ` [PATCH 5/6] device assignment: support for assigning PCI devices to guests muli
2008-10-29 12:19 [v10] Userspace patches for PCI device assignment muli
2008-10-29 12:19 ` [PATCH 1/6] device assignment: add ioctl wrappers muli
2008-10-29 12:19   ` [PATCH 2/6] device assignment: introduce pci_map_irq to get irq nr from pin number muli
2008-10-29 12:19     ` [PATCH 3/6] device assignment: introduce functions to correlate pin number and irq muli
2008-10-29 12:19       ` [PATCH 4/6] device assignment: build vtd.c for Intel IOMMU support muli
2008-10-29 12:20         ` [PATCH 5/6] device assignment: support for assigning PCI devices to guests muli
2008-10-29 12:27           ` Mark McLoughlin
2008-10-29 14:40             ` Muli Ben-Yehuda

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=20081028155305.GE6737@il.ibm.com \
    --to=muli@il.ibm.com \
    --cc=BENAMI@il.ibm.com \
    --cc=allen.m.kay@intel.com \
    --cc=amit.shah@redhat.com \
    --cc=anthony@codemonkey.ws \
    --cc=avi@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox