All of lore.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: "Liu, Kechao" <kechao.liu@intel.com>
Cc: "kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"Shan, Haitao" <haitao.shan@intel.com>,
	"Han, Weidong" <weidong.han@intel.com>,
	"Yang, Sheng" <sheng.yang@intel.com>
Subject: Re: [PATCH] kvm-userspace: Load PCI option ROMs
Date: Tue, 23 Dec 2008 19:15:46 +0200	[thread overview]
Message-ID: <49511CC2.3010509@redhat.com> (raw)
In-Reply-To: <E88DD564E9DC5446A76B2B47C3BCCA15432C049A@pdsmsx503.ccr.corp.intel.com>

Liu, Kechao wrote:
> Load assigned devices' PCI option ROMs to the RAM of
> guest OS. And pass the corresponding devfns to BIOS.
>
>   

Sorry about the late review.

> +
> +    addr = qemu_ram_alloc(size);
> +    phys_addr = addr + phys_ram_base;
> +
> +    /* Write ROM data and devfn to phys_addr */
> +    memcpy((void *)phys_addr, rom, rom->rom_size * 512);
> +    *(uint8_t *)(phys_addr + rom->rom_size * 512) = devfn;
>   

phys_ram_base is dangerous.  It works in this case, but we'd like to 
avoid it.  Please use cpu_physical_memory_write_rom().

> +
> +    cpu_register_physical_memory(0xd0000 + offset, size, addr);
>   

Best to register this as a rom, though kvm will ignore it (we don't 
implement read-only memory at this time).

> +
> +/*
> + * Scan the assigned devices for the devices that have an option ROM, 
> + * and then load the corresponding ROM data to RAM.
> + */
> +ram_addr_t assigned_dev_load_option_roms(ram_addr_t rom_base_offset)
> +{
> +    ram_addr_t offset = rom_base_offset;
> +    AssignedDevInfo *adev;
> +
> +    LIST_FOREACH(adev, &adev_head, next) {
> +        int size;
> +        void *buf;
> +        FILE *fp;
> +        char rom_file[64]; 
> +        char cmd[64];
> +
> +        snprintf(rom_file, sizeof(rom_file), 
> +                 "/sys/bus/pci/devices/0000:%02x:%02x.%01x/rom", 
> +                 adev->bus, adev->dev, adev->func);
> +   
> +        if (access(rom_file, F_OK))
> +            continue;
> +
> +        /* Write something to the ROM file to enable it */
> +        snprintf(cmd, sizeof(cmd), "echo 1 > %s", rom_file);
> +        system(cmd);
>   

system()?!  Please just write to the file.

> +
> +        fp = fopen(rom_file, "rb");
> +        if (fp == NULL)
> +            continue;
> +
> +        /* Read the data of the ROM file to the buffer */
> +        fseek(fp, 0, SEEK_END);
> +        size = ftell(fp);
> +        fseek(fp, 0, SEEK_SET);
> +        buf = malloc(size);
> +        fread(buf, size, 1, fp);
> +
>   

Missing error checking.

> +        /* Scan the buffer for suitable ROMs and increase the offset */
> +        offset += scan_option_rom(adev->assigned_dev->dev.devfn, buf, offset);
> +        
> +        free(buf);
> +        fclose(fp);
> +    }
> +
> +    return offset;
> +}
> diff --git a/qemu/hw/device-assignment.h b/qemu/hw/device-assignment.h
>   

-- 
error compiling committee.c: too many arguments to function


      reply	other threads:[~2008-12-23 17:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-11 10:19 [PATCH] kvm-userspace: Load PCI option ROMs Liu, Kechao
2008-12-23 17:15 ` 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=49511CC2.3010509@redhat.com \
    --to=avi@redhat.com \
    --cc=haitao.shan@intel.com \
    --cc=kechao.liu@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=sheng.yang@intel.com \
    --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.