Re: [Qemu-devel] [PATCH 14/17] Move daemonize handling to OS specific files
On Fri, 2010-06-25 at 13:02 -0400, Jes Sorensen wrote: On 06/25/10 18:41, Frank Arnold wrote: On Thu, 2010-06-10 at 05:42 -0400, jes.soren...@redhat.com wrote: diff --git a/os-posix.c b/os-posix.c index 6417d16..1672e06 100644 --- a/os-posix.c +++ b/os-posix.c @@ -160,6 +162,9 @@ void os_parse_cmd_args(int index, const char *optarg) case QEMU_OPTION_chroot: chroot_dir = optarg; break; +case QEMU_OPTION_daemonize: +daemonize = 1; +break; } return; } This move broke the -daemonize option for us. We are using the qemu-kvm tree. The issue is that the QEMU_OPTION_* enumeration between vl.c and os-posix.c is out of sync. In our case MAP_POPULATE is defined in vl.c but is not in os-posix.c. This excludes the option -mem-prealloc in os-posix.c, see qemu-options.def for the ifdef statement. All subsequent options are off by one in comparison to vl.c. Just including sys/mman.h in os-posix.c fixes the issue for me. But I'm not sure if there is a more generic fix to that problem. Thanks for the update. What do you mean that it changes the numbering, do you get a compile time error or are you saying that it is the order of parsing the options that change? Are you building on Linux or another OS? We are doing KVM testing, so it is Linux. What I did is putting lines like this somewhere into vl.c and os-posix.c: fprintf(stderr, os: QEMU_OPTION_daemonize: %i, QEMU_OPTION_daemonize); fprintf(stderr, vl: QEMU_OPTION_daemonize: %i, QEMU_OPTION_daemonize); Resulting in the following output on stderr: os: QEMU_OPTION_daemonize: 85 vl: QEMU_OPTION_daemonize: 86 No compile time errors. The preprocessing of qemu-options.h is done separately for both files. This results in a missing option definition for os-posix.c and discrepancy in the option enumeration. -- Frank Arnold Systems Design Technician, Software Test AMD Operating System Research Center Dresden, Germany Tel: +49 351 448 356702 Legal Information: Advanced Micro Devices GmbH Einsteinring 24 85609 Dornach b. München Geschäftsführer: Alberto Bozzo, Andrew Bowd Sitz: Dornach, Gemeinde Aschheim, Landkreis München Registergericht München, HRB Nr. 43632
Re: [Qemu-devel] [PATCH 14/17] Move daemonize handling to OS specific files
On Thu, 2010-06-10 at 05:42 -0400, jes.soren...@redhat.com wrote: diff --git a/os-posix.c b/os-posix.c index 6417d16..1672e06 100644 --- a/os-posix.c +++ b/os-posix.c @@ -160,6 +162,9 @@ void os_parse_cmd_args(int index, const char *optarg) case QEMU_OPTION_chroot: chroot_dir = optarg; break; +case QEMU_OPTION_daemonize: +daemonize = 1; +break; } return; } This move broke the -daemonize option for us. We are using the qemu-kvm tree. The issue is that the QEMU_OPTION_* enumeration between vl.c and os-posix.c is out of sync. In our case MAP_POPULATE is defined in vl.c but is not in os-posix.c. This excludes the option -mem-prealloc in os-posix.c, see qemu-options.def for the ifdef statement. All subsequent options are off by one in comparison to vl.c. Just including sys/mman.h in os-posix.c fixes the issue for me. But I'm not sure if there is a more generic fix to that problem. -- Frank Arnold System Design Technician, Software Test AMD Operating System Research Center Dresden, Germany Tel: +49 351 448 356702 Legal Information: Advanced Micro Devices GmbH Einsteinring 24 85609 Dornach b. München Geschäftsführer: Alberto Bozzo, Andrew Bowd Sitz: Dornach, Gemeinde Aschheim, Landkreis München Registergericht München, HRB Nr. 43632
[Qemu-devel] [PATCH v2 13/16] savevm: Create a new continue flag to avoid resending block name
Allows us to compress the protocol a bit by setting a flag on the offset which indicates we're still working within the same block as last time. That way we can avoid sending the block name for every page. Suggested by Anthony Liguori. Signed-off-by: Alex Williamson alex.william...@redhat.com --- arch_init.c | 94 +++ 1 files changed, 50 insertions(+), 44 deletions(-) diff --git a/arch_init.c b/arch_init.c index 186645b..2f082f3 100644 --- a/arch_init.c +++ b/arch_init.c @@ -87,6 +87,7 @@ const uint32_t arch_type = QEMU_ARCH; #define RAM_SAVE_FLAG_MEM_SIZE 0x04 #define RAM_SAVE_FLAG_PAGE 0x08 #define RAM_SAVE_FLAG_EOS 0x10 +#define RAM_SAVE_FLAG_CONTINUE 0x20 static int is_dup_page(uint8_t *page, uint8_t ch) { @@ -120,6 +121,7 @@ static int ram_save_block(QEMUFile *f) do { if (cpu_physical_memory_get_dirty(current_addr, MIGRATION_DIRTY_FLAG)) { uint8_t *p; +int cont = (block == last_block) ? RAM_SAVE_FLAG_CONTINUE : 0; cpu_physical_memory_reset_dirty(current_addr, current_addr + TARGET_PAGE_SIZE, @@ -128,17 +130,21 @@ static int ram_save_block(QEMUFile *f) p = block-host + offset; if (is_dup_page(p, *p)) { -qemu_put_be64(f, offset | RAM_SAVE_FLAG_COMPRESS); -qemu_put_byte(f, strlen(block-idstr)); -qemu_put_buffer(f, (uint8_t *)block-idstr, -strlen(block-idstr)); +qemu_put_be64(f, offset | cont | RAM_SAVE_FLAG_COMPRESS); +if (!cont) { +qemu_put_byte(f, strlen(block-idstr)); +qemu_put_buffer(f, (uint8_t *)block-idstr, +strlen(block-idstr)); +} qemu_put_byte(f, *p); bytes_sent = 1; } else { -qemu_put_be64(f, offset | RAM_SAVE_FLAG_PAGE); -qemu_put_byte(f, strlen(block-idstr)); -qemu_put_buffer(f, (uint8_t *)block-idstr, -strlen(block-idstr)); +qemu_put_be64(f, offset | cont | RAM_SAVE_FLAG_PAGE); +if (!cont) { +qemu_put_byte(f, strlen(block-idstr)); +qemu_put_buffer(f, (uint8_t *)block-idstr, +strlen(block-idstr)); +} qemu_put_buffer(f, p, TARGET_PAGE_SIZE); bytes_sent = TARGET_PAGE_SIZE; } @@ -289,6 +295,36 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque) return (stage == 2) (expected_time = migrate_max_downtime()); } +static inline void *host_from_stream_offset(QEMUFile *f, +ram_addr_t offset, +int flags) +{ +static RAMBlock *block = NULL; +char id[256]; +uint8_t len; + +if (flags RAM_SAVE_FLAG_CONTINUE) { +if (!block) { +fprintf(stderr, Ack, bad migration stream!\n); +return NULL; +} + +return block-host + offset; +} + +len = qemu_get_byte(f); +qemu_get_buffer(f, (uint8_t *)id, len); +id[len] = 0; + +QLIST_FOREACH(block, ram_list.blocks, next) { +if (!strncmp(id, block-idstr, sizeof(id))) +return block-host + offset; +} + +fprintf(stderr, Can't find block %s!\n, id); +return NULL; +} + int ram_load(QEMUFile *f, void *opaque, int version_id) { ram_addr_t addr; @@ -346,26 +382,11 @@ int ram_load(QEMUFile *f, void *opaque, int version_id) void *host; uint8_t ch; -if (version_id == 3) { +if (version_id == 3) host = qemu_get_ram_ptr(addr); -} else { -RAMBlock *block; -char id[256]; -uint8_t len; - -len = qemu_get_byte(f); -qemu_get_buffer(f, (uint8_t *)id, len); -id[len] = 0; +else +host = host_from_stream_offset(f, addr, flags); -QLIST_FOREACH(block, ram_list.blocks, next) { -if (!strncmp(id, block-idstr, sizeof(id))) -break; -} -if (!block) -return -EINVAL; - -host = block-host + addr; -} ch = qemu_get_byte(f); memset(host, ch, TARGET_PAGE_SIZE); #ifndef _WIN32 @@ -377,26 +398,11 @@ int ram_load(QEMUFile *f, void *opaque, int version_id) } else if (flags RAM_SAVE_FLAG_PAGE) { void *host; -if (version_id == 3) { +if (version_id == 3) host = qemu_get_ram_ptr(addr); -} else { -RAMBlock *block; -char
Re: [Qemu-devel] Guest OS hangs on usb_add
On 06/25/10 12:32, Gianni Tedesco wrote: A device MAY provide extended descriptors in 2 ways mentioned in the spec, but ISTR finding at least one device in the wild with standard descriptors extended which were not so much used by the host but by application software. So not sure about your patch, a quirks blacklist based on idDevice/idProduct might be the better fix here. Makes sense. I should add vend/prod id check. However the more serious problem is spinning on zero length descriptor when truncated descriptors are not valid and zero length (in fact 2) is totally unacceptable. Following patch checks for truncation. Gianni, Please check my later patch submitted last night. I basically did the same thing you did, but with few differences: - if descriptor size is 2, goto fail - if the descriptor is USB_DT_CONFIG, we can skip through all the sub descriptors using wTotalLength field. - otherwise, simply skip it One thing to also watch out for is the string descriptors. I might be wrong, but it appears (from reading the doc) that string descriptors (at least for the device descriptor) can be interspersed with the config descriptors, in which case (config_descr_len USB_DT_CONFIG_SIZE) without checking descriptor type might unwittingly lead to failure. -TJ diff --git a/hw/usb.h b/hw/usb.h index 00d2802..efd4a65 100644 --- a/hw/usb.h +++ b/hw/usb.h @@ -117,6 +117,14 @@ #define USB_DT_INTERFACE 0x04 #define USB_DT_ENDPOINT 0x05 +/* + * Descriptor sizes per descriptor type + */ +#define USB_DT_DEVICE_SIZE 18 +#define USB_DT_CONFIG_SIZE 9 +#define USB_DT_INTERFACE_SIZE9 +#define USB_DT_ENDPOINT_SIZE 7 + #define USB_ENDPOINT_XFER_CONTROL0 #define USB_ENDPOINT_XFER_ISOC 1 #define USB_ENDPOINT_XFER_BULK 2 diff --git a/usb-linux.c b/usb-linux.c index 88273ff..d259290 100644 --- a/usb-linux.c +++ b/usb-linux.c @@ -299,7 +299,7 @@ static int usb_host_claim_interfaces(USBHostDevice *dev, int configuration) i = 0; dev_descr_len = dev-descr[0]; -if (dev_descr_len dev-descr_len) { +if ( dev_descr_len USB_DT_DEVICE_SIZE || dev_descr_len dev-descr_len) { goto fail; } @@ -314,6 +314,8 @@ static int usb_host_claim_interfaces(USBHostDevice *dev, int configuration) continue; } config_descr_len = dev-descr[i]; +if ( config_descr_len USB_DT_CONFIG_SIZE ) +goto fail; printf(husb: config #%d need %d\n, dev-descr[i + 5], configuration);
[Qemu-devel] [PATCH v2 14/16] qemu_ram_free: Implement it
Now that we can support a ram_addr_t space with holes, we can implement qemu_ram_free(). Signed-off-by: Alex Williamson alex.william...@redhat.com --- cpu-all.h |3 +++ exec.c| 59 +++ 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/cpu-all.h b/cpu-all.h index 5d8342b..224ca40 100644 --- a/cpu-all.h +++ b/cpu-all.h @@ -867,6 +867,9 @@ typedef struct RAMBlock { ram_addr_t length; char idstr[256]; QLIST_ENTRY(RAMBlock) next; +#if defined(__linux__) !defined(TARGET_S390X) +int fd; +#endif } RAMBlock; typedef struct RAMList { diff --git a/exec.c b/exec.c index a136c13..e8108d7 100644 --- a/exec.c +++ b/exec.c @@ -2699,7 +2699,9 @@ static long gethugepagesize(const char *path) return fs.f_bsize; } -static void *file_ram_alloc(ram_addr_t memory, const char *path) +static void *file_ram_alloc(RAMBlock *block, +ram_addr_t memory, +const char *path) { char *filename; void *area; @@ -2762,19 +2764,35 @@ static void *file_ram_alloc(ram_addr_t memory, const char *path) close(fd); return (NULL); } +block-fd = fd; return area; } #endif static ram_addr_t find_ram_offset(ram_addr_t size) { -RAMBlock *block; -ram_addr_t last = 0; +RAMBlock *block, *next_block; +ram_addr_t offset, mingap = ULONG_MAX; + +if (QLIST_EMPTY(ram_list.blocks)) +return 0; -QLIST_FOREACH(block, ram_list.blocks, next) -last = MAX(last, block-offset + block-length); +QLIST_FOREACH(block, ram_list.blocks, next) { +ram_addr_t end, next = ULONG_MAX; -return last; +end = block-offset + block-length; + +QLIST_FOREACH(next_block, ram_list.blocks, next) { +if (next_block-offset = end) { +next = MIN(next, next_block-offset); +} +} +if (next - end = size next - end mingap) { +offset = end; +mingap = next - end; +} +} +return offset; } ram_addr_t qemu_ram_alloc(DeviceState *dev, const char *name, ram_addr_t size) @@ -2810,7 +2828,7 @@ ram_addr_t qemu_ram_alloc(DeviceState *dev, const char *name, ram_addr_t size) if (mem_path) { #if defined (__linux__) !defined(TARGET_S390X) -new_block-host = file_ram_alloc(size, mem_path); +new_block-host = file_ram_alloc(new_block, size, mem_path); if (!new_block-host) { new_block-host = qemu_vmalloc(size); #ifdef MADV_MERGEABLE @@ -2852,7 +2870,32 @@ ram_addr_t qemu_ram_alloc(DeviceState *dev, const char *name, ram_addr_t size) void qemu_ram_free(ram_addr_t addr) { -/* TODO: implement this. */ +RAMBlock *block; + +QLIST_FOREACH(block, ram_list.blocks, next) { +if (addr == block-offset) { +QLIST_REMOVE(block, next); +if (mem_path) { +#if defined (__linux__) !defined(TARGET_S390X) +if (block-fd) { +munmap(block-host, block-length); +close(block-fd); +} else { +qemu_vfree(block-host); +} +#endif +} else { +#if defined(TARGET_S390X) defined(CONFIG_KVM) +munmap(block-host, block-length); +#else +qemu_vfree(block-host); +#endif +} +qemu_free(block); +return; +} +} + } /* Return a host pointer to ram allocated with qemu_ram_alloc.
[Qemu-devel] [PATCH 05/12] blockdev: Clean up automatic drive deletion
We automatically delete blockdev host parts on unplug of the guest device. Too much magic, but we can't change that now. The delete happens early in the guest device teardown, before the connection to the host part is severed. Thus, the guest part's pointer to the host part dangles for a brief time. No actual harm comes from this, but we'll catch such dangling pointers a few commits down the road. Clean up the dangling pointers by delaying the automatic deletion until the guest part's pointer is gone. Device usb-storage deliberately makes two qdev properties refer to the same drive, because it automatically creates a second device. Again, too much magic we can't change now. Multiple references worked okay before, but now free_drive() dies for the second one. Zap the extra reference. Signed-off-by: Markus Armbruster arm...@redhat.com --- blockdev.c | 23 +++ blockdev.h |4 hw/qdev-properties.c | 10 ++ hw/scsi-disk.c |2 +- hw/scsi-generic.c|2 +- hw/usb-msd.c | 20 hw/virtio-pci.c |2 +- 7 files changed, 56 insertions(+), 7 deletions(-) diff --git a/blockdev.c b/blockdev.c index 8023cfd..827ea1c 100644 --- a/blockdev.c +++ b/blockdev.c @@ -17,6 +17,29 @@ static QTAILQ_HEAD(drivelist, DriveInfo) drives = QTAILQ_HEAD_INITIALIZER(drives); +/* + * We automatically delete the drive when a device using it gets + * unplugged. Questionable feature, but we can't just drop it. + * Device models call blockdev_mark_auto_del() to schedule the + * automatic deletion, and generic qdev code calls blockdev_auto_del() + * when deletion is actually safe. + */ +void blockdev_mark_auto_del(BlockDriverState *bs) +{ +DriveInfo *dinfo = drive_of_blockdev(bs); + +dinfo-auto_del = 1; +} + +void blockdev_auto_del(BlockDriverState *bs) +{ +DriveInfo *dinfo = drive_of_blockdev(bs); + +if (dinfo-auto_del) { +drive_uninit(dinfo); +} +} + QemuOpts *drive_add(const char *file, const char *fmt, ...) { va_list ap; diff --git a/blockdev.h b/blockdev.h index 4bf75b1..418ebb6 100644 --- a/blockdev.h +++ b/blockdev.h @@ -13,6 +13,9 @@ #include block.h #include qemu-queue.h +void blockdev_mark_auto_del(BlockDriverState *bs); +void blockdev_auto_del(BlockDriverState *bs); + typedef enum { IF_NONE, IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH, IF_MTD, IF_SD, IF_VIRTIO, IF_XEN, @@ -28,6 +31,7 @@ typedef struct DriveInfo { BlockInterfaceType type; int bus; int unit; +int auto_del; /* see blockdev_mark_auto_del() */ QemuOpts *opts; char serial[BLOCK_SERIAL_STRLEN + 1]; QTAILQ_ENTRY(DriveInfo) next; diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c index 5a8739d..15ca6d3 100644 --- a/hw/qdev-properties.c +++ b/hw/qdev-properties.c @@ -293,6 +293,15 @@ static int parse_drive(DeviceState *dev, Property *prop, const char *str) return 0; } +static void free_drive(DeviceState *dev, Property *prop) +{ +DriveInfo **ptr = qdev_get_prop_ptr(dev, prop); + +if (*ptr) { +blockdev_auto_del((*ptr)-bdrv); +} +} + static int print_drive(DeviceState *dev, Property *prop, char *dest, size_t len) { DriveInfo **ptr = qdev_get_prop_ptr(dev, prop); @@ -305,6 +314,7 @@ PropertyInfo qdev_prop_drive = { .size = sizeof(DriveInfo*), .parse = parse_drive, .print = print_drive, +.free = free_drive, }; /* --- character device --- */ diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 2b38984..d76e640 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -1043,7 +1043,7 @@ static void scsi_destroy(SCSIDevice *dev) SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev); scsi_disk_purge_requests(s); -drive_uninit(s-qdev.conf.dinfo); +blockdev_mark_auto_del(s-qdev.conf.dinfo-bdrv); } static int scsi_disk_initfn(SCSIDevice *dev) diff --git a/hw/scsi-generic.c b/hw/scsi-generic.c index e31060e..1859c94 100644 --- a/hw/scsi-generic.c +++ b/hw/scsi-generic.c @@ -453,7 +453,7 @@ static void scsi_destroy(SCSIDevice *d) r = DO_UPCAST(SCSIGenericReq, req, QTAILQ_FIRST(s-qdev.requests)); scsi_remove_request(r); } -drive_uninit(s-qdev.conf.dinfo); +blockdev_mark_auto_del(s-qdev.conf.dinfo-bdrv); } static int scsi_generic_initfn(SCSIDevice *dev) diff --git a/hw/usb-msd.c b/hw/usb-msd.c index 8e9718c..3dbfcab 100644 --- a/hw/usb-msd.c +++ b/hw/usb-msd.c @@ -522,24 +522,36 @@ static void usb_msd_password_cb(void *opaque, int err) static int usb_msd_initfn(USBDevice *dev) { MSDState *s = DO_UPCAST(MSDState, dev, dev); +DriveInfo *dinfo = s-conf.dinfo; -if (!s-conf.dinfo || !s-conf.dinfo-bdrv) { +if (!dinfo || !dinfo-bdrv) { error_report(usb-msd: drive property not set); return -1; } +/* + * Hack alert: this pretends to be a block device, but it's really + * a SCSI bus that can serve only a
Re: [Qemu-devel] [PATCH 14/17] Move daemonize handling to OS specific files
On Fri, 2010-06-25 at 19:34 +0200, Frank Arnold wrote: On Fri, 2010-06-25 at 13:02 -0400, Jes Sorensen wrote: On 06/25/10 18:41, Frank Arnold wrote: On Thu, 2010-06-10 at 05:42 -0400, jes.soren...@redhat.com wrote: diff --git a/os-posix.c b/os-posix.c index 6417d16..1672e06 100644 --- a/os-posix.c +++ b/os-posix.c @@ -160,6 +162,9 @@ void os_parse_cmd_args(int index, const char *optarg) case QEMU_OPTION_chroot: chroot_dir = optarg; break; +case QEMU_OPTION_daemonize: +daemonize = 1; +break; } return; } This move broke the -daemonize option for us. We are using the qemu-kvm tree. The issue is that the QEMU_OPTION_* enumeration between vl.c and os-posix.c is out of sync. In our case MAP_POPULATE is defined in vl.c but is not in os-posix.c. This excludes the option -mem-prealloc in os-posix.c, see qemu-options.def for the ifdef statement. All subsequent options are off by one in comparison to vl.c. Just including sys/mman.h in os-posix.c fixes the issue for me. But I'm not sure if there is a more generic fix to that problem. Thanks for the update. What do you mean that it changes the numbering, do you get a compile time error or are you saying that it is the order of parsing the options that change? Are you building on Linux or another OS? We are doing KVM testing, so it is Linux. What I did is putting lines like this somewhere into vl.c and os-posix.c: fprintf(stderr, os: QEMU_OPTION_daemonize: %i, QEMU_OPTION_daemonize); fprintf(stderr, vl: QEMU_OPTION_daemonize: %i, QEMU_OPTION_daemonize); Resulting in the following output on stderr: os: QEMU_OPTION_daemonize: 85 vl: QEMU_OPTION_daemonize: 86 No compile time errors. The preprocessing of qemu-options.h is done separately for both files. This results in a missing option definition for os-posix.c and discrepancy in the option enumeration. Sorry, missed the part where your patch comes into play: From vl.c the function os_parse_cmd_args is called with option index 86, and the switch statement in os-posix.c's os_parse_cmd_args checks for 85 to set the daemonize. Obviously, this wont work. -- Frank
[Qemu-devel] [PATCH v2 12/16] savevm: Use RAM blocks for basis of migration
We don't want to assume a contiguous address space, so migrate based on RAM blocks instead of a fixed linear address map. This will allow us to have holes in the ram_addr_t namespace, so we can implement qemu_ram_free(). Signed-off-by: Alex Williamson alex.william...@redhat.com --- arch_init.c | 67 +-- 1 files changed, 42 insertions(+), 25 deletions(-) diff --git a/arch_init.c b/arch_init.c index 37aad9d..186645b 100644 --- a/arch_init.c +++ b/arch_init.c @@ -105,27 +105,26 @@ static int is_dup_page(uint8_t *page, uint8_t ch) static int ram_save_block(QEMUFile *f) { -static ram_addr_t current_addr = 0; -ram_addr_t saved_addr = current_addr; -ram_addr_t addr = 0; -uint64_t total_ram = ram_bytes_total(); +static RAMBlock *last_block = NULL; +static ram_addr_t last_offset = 0; +RAMBlock *block = last_block; +ram_addr_t offset = last_offset; +ram_addr_t current_addr; int bytes_sent = 0; -while (addr total_ram) { +if (!block) +block = QLIST_FIRST(ram_list.blocks); + +current_addr = block-offset + offset; + +do { if (cpu_physical_memory_get_dirty(current_addr, MIGRATION_DIRTY_FLAG)) { -RAMBlock *block; -ram_addr_t offset; uint8_t *p; cpu_physical_memory_reset_dirty(current_addr, current_addr + TARGET_PAGE_SIZE, MIGRATION_DIRTY_FLAG); -QLIST_FOREACH(block, ram_list.blocks, next) { -if (current_addr - block-offset block-length) -break; -} -offset = current_addr - block-offset; p = block-host + offset; if (is_dup_page(p, *p)) { @@ -146,9 +145,21 @@ static int ram_save_block(QEMUFile *f) break; } -addr += TARGET_PAGE_SIZE; -current_addr = (saved_addr + addr) % total_ram; -} + +offset += TARGET_PAGE_SIZE; +if (offset = block-length) { +offset = 0; +block = QLIST_NEXT(block, next); +if (!block) +block = QLIST_FIRST(ram_list.blocks); +} + +current_addr = block-offset + offset; + +} while (current_addr != last_block-offset + last_offset); + +last_block = block; +last_offset = offset; return bytes_sent; } @@ -157,13 +168,16 @@ static uint64_t bytes_transferred; static ram_addr_t ram_save_remaining(void) { -ram_addr_t addr; +RAMBlock *block; ram_addr_t count = 0; -uint64_t total_ram = ram_bytes_total(); -for (addr = 0; addr total_ram; addr += TARGET_PAGE_SIZE) { -if (cpu_physical_memory_get_dirty(addr, MIGRATION_DIRTY_FLAG)) { -count++; +QLIST_FOREACH(block, ram_list.blocks, next) { +ram_addr_t addr; +for (addr = block-offset; addr block-offset + block-length; + addr += TARGET_PAGE_SIZE) { +if (cpu_physical_memory_get_dirty(addr, MIGRATION_DIRTY_FLAG)) { +count++; +} } } @@ -210,20 +224,23 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque) if (stage == 1) { RAMBlock *block; -uint64_t total_ram = ram_bytes_total(); bytes_transferred = 0; /* Make sure all dirty bits are set */ -for (addr = 0; addr total_ram; addr += TARGET_PAGE_SIZE) { -if (!cpu_physical_memory_get_dirty(addr, MIGRATION_DIRTY_FLAG)) { -cpu_physical_memory_set_dirty(addr); +QLIST_FOREACH(block, ram_list.blocks, next) { +for (addr = block-offset; addr block-offset + block-length; + addr += TARGET_PAGE_SIZE) { +if (!cpu_physical_memory_get_dirty(addr, + MIGRATION_DIRTY_FLAG)) { +cpu_physical_memory_set_dirty(addr); +} } } /* Enable dirty memory tracking */ cpu_physical_memory_set_dirty_tracking(1); -qemu_put_be64(f, total_ram | RAM_SAVE_FLAG_MEM_SIZE); +qemu_put_be64(f, ram_bytes_total() | RAM_SAVE_FLAG_MEM_SIZE); QLIST_FOREACH(block, ram_list.blocks, next) { qemu_put_byte(f, strlen(block-idstr));
[Qemu-devel] [PATCH] ARM: semi-hosting support for stderr
Hello, I propose this small patch so that ARM semi-hosting handles stderr as expected when linking with Newlib/libgloss. diff --git a/arm-semi.c b/arm-semi.c index 9549e6c..6874036 100644 --- a/arm-semi.c +++ b/arm-semi.c @@ -211,8 +211,11 @@ uint32_t do_arm_semihosting(CPUState *env) if (strcmp(s, :tt) == 0) { if (ARG(1) 4) return STDIN_FILENO; -else +else if (ARG(1) == 4) return STDOUT_FILENO; + else + return STDERR_FILENO; /* See newlib/libgloss + implementation. */ } if (use_gdb_syscalls()) { gdb_do_syscall(arm_semi_cb, open,%s,%x,1a4, ARG(0), Christophe
[Qemu-devel] [PATCH 10/12] block: Fix virtual media change for if=none
BlockDriverState member removable controls whether virtual media change (monitor commands change, eject) is allowed. It is set when the type hint is BDRV_TYPE_CDROM or BDRV_TYPE_FLOPPY. The type hint is only set by drive_init(). It sets BDRV_TYPE_FLOPPY for if=floppy. It sets BDRV_TYPE_CDROM for media=cdrom and if=ide, scsi, xen, or none. if=ide and if=scsi work, because the type hint makes it a CD-ROM. if=xen likewise, I think. For the same reason, if=none works when it's used by ide-drive or scsi-disk. For other guest devices, there are problems: * fdc: you can't change virtual media $ qemu [...] -drive if=none,id=foo,... -global isa-fdc.driveA=foo QEMU 0.12.50 monitor - type 'help' for more information (qemu) eject foo Device 'foo' is not removable unless you add media=cdrom, but that makes it readonly. * virtio: if you add media=cdrom, you can change virtual media. If you eject, the guest gets I/O errors. If you change, the guest sees the drive's contents suddenly change. * scsi-generic: if you add media=cdrom, you can change virtual media. I didn't test what that does to the guest or the physical device, but it can't be pretty. Signed-off-by: Markus Armbruster arm...@redhat.com --- block.c |8 block.h |1 + hw/fdc.c | 10 -- hw/ide/core.c |1 + hw/scsi-disk.c|5 - hw/scsi-generic.c |1 + hw/virtio-blk.c |1 + 7 files changed, 24 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index 34055e0..2ae4275 100644 --- a/block.c +++ b/block.c @@ -1292,6 +1292,14 @@ BlockErrorAction bdrv_get_on_error(BlockDriverState *bs, int is_read) return is_read ? bs-on_read_error : bs-on_write_error; } +void bdrv_set_removable(BlockDriverState *bs, int removable) +{ +bs-removable = removable; +if (removable bs == bs_snapshots) { +bs_snapshots = NULL; +} +} + int bdrv_is_removable(BlockDriverState *bs) { return bs-removable; diff --git a/block.h b/block.h index 012c2a1..3d03b3e 100644 --- a/block.h +++ b/block.h @@ -162,6 +162,7 @@ int bdrv_get_translation_hint(BlockDriverState *bs); void bdrv_set_on_error(BlockDriverState *bs, BlockErrorAction on_read_error, BlockErrorAction on_write_error); BlockErrorAction bdrv_get_on_error(BlockDriverState *bs, int is_read); +void bdrv_set_removable(BlockDriverState *bs, int removable); int bdrv_is_removable(BlockDriverState *bs); int bdrv_is_read_only(BlockDriverState *bs); int bdrv_is_sg(BlockDriverState *bs); diff --git a/hw/fdc.c b/hw/fdc.c index 1496cfa..6c74878 100644 --- a/hw/fdc.c +++ b/hw/fdc.c @@ -1847,10 +1847,16 @@ static void fdctrl_result_timer(void *opaque) static void fdctrl_connect_drives(FDCtrl *fdctrl) { unsigned int i; +FDrive *drive; for (i = 0; i MAX_FD; i++) { -fd_init(fdctrl-drives[i]); -fd_revalidate(fdctrl-drives[i]); +drive = fdctrl-drives[i]; + +fd_init(drive); +fd_revalidate(drive); +if (drive-bs) { +bdrv_set_removable(drive-bs, 1); +} } } diff --git a/hw/ide/core.c b/hw/ide/core.c index cc4591b..ebdceb5 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -2629,6 +2629,7 @@ void ide_init_drive(IDEState *s, BlockDriverState *bs, pstrcpy(s-version, sizeof(s-version), QEMU_VERSION); } ide_reset(s); +bdrv_set_removable(bs, s-is_cdrom); } static void ide_init1(IDEBus *bus, int unit) diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 9c78979..2211245 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -1049,6 +1049,7 @@ static void scsi_destroy(SCSIDevice *dev) static int scsi_disk_initfn(SCSIDevice *dev) { SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev); +int is_cd; DriveInfo *dinfo; if (!s-qdev.conf.bs) { @@ -1056,6 +1057,7 @@ static int scsi_disk_initfn(SCSIDevice *dev) return -1; } s-bs = s-qdev.conf.bs; +is_cd = bdrv_get_type_hint(s-bs) == BDRV_TYPE_CDROM; if (!s-serial) { /* try to fall back to value set with legacy -drive serial=... */ @@ -1072,7 +1074,7 @@ static int scsi_disk_initfn(SCSIDevice *dev) return -1; } -if (bdrv_get_type_hint(s-bs) == BDRV_TYPE_CDROM) { +if (is_cd) { s-qdev.blocksize = 2048; } else { s-qdev.blocksize = s-qdev.conf.logical_block_size; @@ -1081,6 +1083,7 @@ static int scsi_disk_initfn(SCSIDevice *dev) s-qdev.type = TYPE_DISK; qemu_add_vm_change_state_handler(scsi_dma_restart_cb, s); +bdrv_set_removable(s-bs, is_cd); return 0; } diff --git a/hw/scsi-generic.c b/hw/scsi-generic.c index 79347f4..3915e78 100644 --- a/hw/scsi-generic.c +++ b/hw/scsi-generic.c @@ -509,6 +509,7 @@ static int scsi_generic_initfn(SCSIDevice *dev) DPRINTF(block size %d\n, s-qdev.blocksize); s-driver_status = 0; memset(s-sensebuf, 0, sizeof(s-sensebuf)); +bdrv_set_removable(s-bs,
[Qemu-devel] [PATCH v2 06/16] savevm: Make use of DeviceState
For callers that pass a device we can traverse up the qdev tree and make use of the BusInfo.get_dev_path information for creating unique savevm id strings. This avoids needing to rely on the instance number, which can cause problems with device initialization order and hotplug. For compatibility, we also store away the old id string and instance so we can accept migrations from VMs as we add new get_dev_path implementations. Signed-off-by: Alex Williamson alex.william...@redhat.com --- savevm.c | 84 ++ 1 files changed, 79 insertions(+), 5 deletions(-) diff --git a/savevm.c b/savevm.c index 0052406..e4f50b1 100644 --- a/savevm.c +++ b/savevm.c @@ -72,6 +72,7 @@ #include qemu-common.h #include hw/hw.h +#include hw/qdev.h #include net.h #include monitor.h #include sysemu.h @@ -988,6 +989,11 @@ const VMStateInfo vmstate_info_unused_buffer = { .put = put_unused_buffer, }; +typedef struct CompatEntry { +char idstr[256]; +int instance_id; +} CompatEntry; + typedef struct SaveStateEntry { QTAILQ_ENTRY(SaveStateEntry) entry; char idstr[256]; @@ -1001,6 +1007,7 @@ typedef struct SaveStateEntry { LoadStateHandler *load_state; const VMStateDescription *vmsd; void *opaque; +CompatEntry *compat; } SaveStateEntry; @@ -1022,6 +1029,23 @@ static int calculate_new_instance_id(const char *idstr) return instance_id; } +static int calculate_compat_instance_id(const char *idstr) +{ +SaveStateEntry *se; +int instance_id = 0; + +QTAILQ_FOREACH(se, savevm_handlers, entry) { +if (!se-compat) +continue; + +if (strcmp(idstr, se-compat-idstr) == 0 + instance_id = se-compat-instance_id) { +instance_id = se-compat-instance_id + 1; +} +} +return instance_id; +} + /* TODO: Individual devices generally have very little idea about the rest of the system, so instance_id should be removed/replaced. Meanwhile pass -1 as instance_id if you do not already have a clearly @@ -1039,7 +1063,6 @@ int register_savevm_live(DeviceState *dev, SaveStateEntry *se; se = qemu_mallocz(sizeof(SaveStateEntry)); -pstrcpy(se-idstr, sizeof(se-idstr), idstr); se-version_id = version_id; se-section_id = global_section_id++; se-set_params = set_params; @@ -1049,11 +1072,28 @@ int register_savevm_live(DeviceState *dev, se-opaque = opaque; se-vmsd = NULL; +if (dev dev-parent_bus dev-parent_bus-info-get_dev_path) { +char *id = dev-parent_bus-info-get_dev_path(dev); +if (id) { +pstrcpy(se-idstr, sizeof(se-idstr), id); +pstrcat(se-idstr, sizeof(se-idstr), /); +qemu_free(id); + +se-compat = qemu_mallocz(sizeof(CompatEntry)); +pstrcpy(se-compat-idstr, sizeof(se-compat-idstr), idstr); +se-compat-instance_id = instance_id == -1 ? + calculate_compat_instance_id(idstr) : instance_id; +instance_id = -1; +} +} +pstrcat(se-idstr, sizeof(se-idstr), idstr); + if (instance_id == -1) { -se-instance_id = calculate_new_instance_id(idstr); +se-instance_id = calculate_new_instance_id(se-idstr); } else { se-instance_id = instance_id; } +assert(!se-compat || se-instance_id == 0); /* add at the end of list */ QTAILQ_INSERT_TAIL(savevm_handlers, se, entry); return 0; @@ -1074,9 +1114,20 @@ int register_savevm(DeviceState *dev, void unregister_savevm(DeviceState *dev, const char *idstr, void *opaque) { SaveStateEntry *se, *new_se; +char id[256] = ; + +if (dev dev-parent_bus dev-parent_bus-info-get_dev_path) { +char *path = dev-parent_bus-info-get_dev_path(dev); +if (path) { +pstrcpy(id, sizeof(id), path); +pstrcat(id, sizeof(id), /); +qemu_free(path); +} +} +pstrcat(id, sizeof(id), idstr); QTAILQ_FOREACH_SAFE(se, savevm_handlers, entry, new_se) { -if (strcmp(se-idstr, idstr) == 0 se-opaque == opaque) { +if (strcmp(se-idstr, id) == 0 se-opaque == opaque) { QTAILQ_REMOVE(savevm_handlers, se, entry); qemu_free(se); } @@ -1094,7 +1145,6 @@ int vmstate_register_with_alias_id(DeviceState *dev, int instance_id, assert(alias_id == -1 || required_for_version = vmsd-minimum_version_id); se = qemu_mallocz(sizeof(SaveStateEntry)); -pstrcpy(se-idstr, sizeof(se-idstr), vmsd-name); se-version_id = vmsd-version_id; se-section_id = global_section_id++; se-save_live_state = NULL; @@ -1104,11 +1154,28 @@ int vmstate_register_with_alias_id(DeviceState *dev, int instance_id, se-vmsd = vmsd; se-alias_id = alias_id; +if (dev dev-parent_bus dev-parent_bus-info-get_dev_path) { +char *id = dev-parent_bus-info-get_dev_path(dev); +if (id) { +
[Qemu-devel] [PATCH 11/12] ide: Make PIIX and ISA IDE init functions return the qdev
Signed-off-by: Markus Armbruster arm...@redhat.com --- hw/ide.h | 11 ++- hw/ide/isa.c |8 hw/ide/piix.c |6 -- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/hw/ide.h b/hw/ide.h index 0e7d540..f0cb320 100644 --- a/hw/ide.h +++ b/hw/ide.h @@ -1,17 +1,18 @@ #ifndef HW_IDE_H #define HW_IDE_H -#include qdev.h +#include isa.h +#include pci.h /* ide-isa.c */ -int isa_ide_init(int iobase, int iobase2, int isairq, - DriveInfo *hd0, DriveInfo *hd1); +ISADevice *isa_ide_init(int iobase, int iobase2, int isairq, +DriveInfo *hd0, DriveInfo *hd1); /* ide-pci.c */ void pci_cmd646_ide_init(PCIBus *bus, DriveInfo **hd_table, int secondary_ide_enabled); -void pci_piix3_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn); -void pci_piix4_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn); +PCIDevice *pci_piix3_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn); +PCIDevice *pci_piix4_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn); /* ide-macio.c */ int pmac_ide_init (DriveInfo **hd_table, qemu_irq irq, diff --git a/hw/ide/isa.c b/hw/ide/isa.c index b6c6347..10777ca 100644 --- a/hw/ide/isa.c +++ b/hw/ide/isa.c @@ -75,8 +75,8 @@ static int isa_ide_initfn(ISADevice *dev) return 0; }; -int isa_ide_init(int iobase, int iobase2, int isairq, - DriveInfo *hd0, DriveInfo *hd1) +ISADevice *isa_ide_init(int iobase, int iobase2, int isairq, +DriveInfo *hd0, DriveInfo *hd1) { ISADevice *dev; ISAIDEState *s; @@ -86,14 +86,14 @@ int isa_ide_init(int iobase, int iobase2, int isairq, qdev_prop_set_uint32(dev-qdev, iobase2, iobase2); qdev_prop_set_uint32(dev-qdev, irq, isairq); if (qdev_init(dev-qdev) 0) -return -1; +return NULL; s = DO_UPCAST(ISAIDEState, dev, dev); if (hd0) ide_create_drive(s-bus, 0, hd0); if (hd1) ide_create_drive(s-bus, 1, hd1); -return 0; +return dev; } static ISADeviceInfo isa_ide_info = { diff --git a/hw/ide/piix.c b/hw/ide/piix.c index dad6e86..fa6 100644 --- a/hw/ide/piix.c +++ b/hw/ide/piix.c @@ -160,22 +160,24 @@ static int pci_piix4_ide_initfn(PCIDevice *dev) /* hd_table must contain 4 block drivers */ /* NOTE: for the PIIX3, the IRQs and IOports are hardcoded */ -void pci_piix3_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn) +PCIDevice *pci_piix3_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn) { PCIDevice *dev; dev = pci_create_simple(bus, devfn, piix3-ide); pci_ide_create_devs(dev, hd_table); +return dev; } /* hd_table must contain 4 block drivers */ /* NOTE: for the PIIX4, the IRQs and IOports are hardcoded */ -void pci_piix4_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn) +PCIDevice *pci_piix4_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn) { PCIDevice *dev; dev = pci_create_simple(bus, devfn, piix4-ide); pci_ide_create_devs(dev, hd_table); +return dev; } static PCIDeviceInfo piix_ide_info[] = { -- 1.6.6.1
[Qemu-devel] [PATCH v2 11/16] savevm: Migrate RAM based on name/offset
Synchronize RAM blocks with the target and migrate using name/offset pairs. This ensures both source and target have the same view of RAM and that we get the right bits into the right slot. Signed-off-by: Alex Williamson alex.william...@redhat.com --- arch_init.c | 118 ++- vl.c|2 + 2 files changed, 108 insertions(+), 12 deletions(-) diff --git a/arch_init.c b/arch_init.c index 109dcef..37aad9d 100644 --- a/arch_init.c +++ b/arch_init.c @@ -113,20 +113,33 @@ static int ram_save_block(QEMUFile *f) while (addr total_ram) { if (cpu_physical_memory_get_dirty(current_addr, MIGRATION_DIRTY_FLAG)) { +RAMBlock *block; +ram_addr_t offset; uint8_t *p; cpu_physical_memory_reset_dirty(current_addr, current_addr + TARGET_PAGE_SIZE, MIGRATION_DIRTY_FLAG); -p = qemu_get_ram_ptr(current_addr); +QLIST_FOREACH(block, ram_list.blocks, next) { +if (current_addr - block-offset block-length) +break; +} +offset = current_addr - block-offset; +p = block-host + offset; if (is_dup_page(p, *p)) { -qemu_put_be64(f, current_addr | RAM_SAVE_FLAG_COMPRESS); +qemu_put_be64(f, offset | RAM_SAVE_FLAG_COMPRESS); +qemu_put_byte(f, strlen(block-idstr)); +qemu_put_buffer(f, (uint8_t *)block-idstr, +strlen(block-idstr)); qemu_put_byte(f, *p); bytes_sent = 1; } else { -qemu_put_be64(f, current_addr | RAM_SAVE_FLAG_PAGE); +qemu_put_be64(f, offset | RAM_SAVE_FLAG_PAGE); +qemu_put_byte(f, strlen(block-idstr)); +qemu_put_buffer(f, (uint8_t *)block-idstr, +strlen(block-idstr)); qemu_put_buffer(f, p, TARGET_PAGE_SIZE); bytes_sent = TARGET_PAGE_SIZE; } @@ -196,6 +209,7 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque) } if (stage == 1) { +RAMBlock *block; uint64_t total_ram = ram_bytes_total(); bytes_transferred = 0; @@ -210,6 +224,12 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque) cpu_physical_memory_set_dirty_tracking(1); qemu_put_be64(f, total_ram | RAM_SAVE_FLAG_MEM_SIZE); + +QLIST_FOREACH(block, ram_list.blocks, next) { +qemu_put_byte(f, strlen(block-idstr)); +qemu_put_buffer(f, (uint8_t *)block-idstr, strlen(block-idstr)); +qemu_put_be64(f, block-length); +} } bytes_transferred_last = bytes_transferred; @@ -257,7 +277,7 @@ int ram_load(QEMUFile *f, void *opaque, int version_id) ram_addr_t addr; int flags; -if (version_id != 3) { +if (version_id 3 || version_id 4) { return -EINVAL; } @@ -268,23 +288,99 @@ int ram_load(QEMUFile *f, void *opaque, int version_id) addr = TARGET_PAGE_MASK; if (flags RAM_SAVE_FLAG_MEM_SIZE) { -if (addr != ram_bytes_total()) { -return -EINVAL; +if (version_id == 3) { +if (addr != ram_bytes_total()) { +return -EINVAL; +} +} else { +/* Synchronize RAM block list */ +char id[256]; +ram_addr_t length; +ram_addr_t total_ram_bytes = addr; + +while (total_ram_bytes) { +RAMBlock *block; +uint8_t len; + +len = qemu_get_byte(f); +qemu_get_buffer(f, (uint8_t *)id, len); +id[len] = 0; +length = qemu_get_be64(f); + +QLIST_FOREACH(block, ram_list.blocks, next) { +if (!strncmp(id, block-idstr, sizeof(id))) { +if (block-length != length) +return -EINVAL; +break; +} +} + +if (!block) { +if (!qemu_ram_alloc(NULL, id, length)) +return -ENOMEM; +} + +total_ram_bytes -= length; +} } } if (flags RAM_SAVE_FLAG_COMPRESS) { -uint8_t ch = qemu_get_byte(f); -memset(qemu_get_ram_ptr(addr), ch, TARGET_PAGE_SIZE); +void *host; +uint8_t ch; + +if (version_id == 3) { +host = qemu_get_ram_ptr(addr); +} else { +RAMBlock *block; +char id[256]; +
[Qemu-devel] [PATCH v2 16/16] ramblocks: No more being lazy about duplicate names
Now that we have a working qemu_ram_free() and the primary runtime user of it has been updated, don't be lenient about duplicate id strings. We also shouldn't need to create them ondemand at the target. Signed-off-by: Alex Williamson alex.william...@redhat.com --- arch_init.c |5 +++-- exec.c | 13 +++-- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/arch_init.c b/arch_init.c index 2f082f3..47bb4b2 100644 --- a/arch_init.c +++ b/arch_init.c @@ -369,8 +369,9 @@ int ram_load(QEMUFile *f, void *opaque, int version_id) } if (!block) { -if (!qemu_ram_alloc(NULL, id, length)) -return -ENOMEM; +fprintf(stderr, Unknown ramblock \%s\, cannot +accept migration\n, id); +return -EINVAL; } total_ram_bytes -= length; diff --git a/exec.c b/exec.c index e8108d7..ef2a89d 100644 --- a/exec.c +++ b/exec.c @@ -2813,16 +2813,9 @@ ram_addr_t qemu_ram_alloc(DeviceState *dev, const char *name, ram_addr_t size) QLIST_FOREACH(block, ram_list.blocks, next) { if (!strcmp(block-idstr, new_block-idstr)) { -if (block-length == new_block-length) { -fprintf(stderr, RAMBlock \%s\ exists, assuming lack of -free.\n, new_block-idstr); -qemu_free(new_block); -return block-offset; -} else { -fprintf(stderr, RAMBlock \%s\ already registered with -different size, abort\n, new_block-idstr); -abort(); -} +fprintf(stderr, RAMBlock \%s\ already registered, abort!\n, +new_block-idstr); +abort(); } }
[Qemu-devel] [PATCH 3/8] Init qemu_system_cond
Signed-off-by: Jan Kiszka jan.kis...@siemens.com --- cpus.c |1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/cpus.c b/cpus.c index fcd0f09..37e6b33 100644 --- a/cpus.c +++ b/cpus.c @@ -331,6 +331,7 @@ int qemu_init_main_loop(void) return ret; qemu_cond_init(qemu_pause_cond); +qemu_cond_init(qemu_system_cond); qemu_mutex_init(qemu_fair_mutex); qemu_mutex_init(qemu_global_mutex); qemu_mutex_lock(qemu_global_mutex); -- 1.7.1
[Qemu-devel] [PATCH v2 08/16] virtio-net: Incorporate a DeviceState pointer and let savevm track instances
Stuff a pointer to the DeviceState into the VirtIONet structure so that we can easily remove the vmstate entry later. Also, let vmstate track the instance number (it should always be zero internally since the device path should now be unique). Signed-off-by: Alex Williamson alex.william...@redhat.com --- hw/virtio-net.c |7 --- 1 files changed, 4 insertions(+), 3 deletions(-) diff --git a/hw/virtio-net.c b/hw/virtio-net.c index e9768e0..f41db45 100644 --- a/hw/virtio-net.c +++ b/hw/virtio-net.c @@ -60,6 +60,7 @@ typedef struct VirtIONet uint8_t *macs; } mac_table; uint32_t *vlans; +DeviceState *qdev; } VirtIONet; /* TODO @@ -890,7 +891,6 @@ static void virtio_net_vmstate_change(void *opaque, int running, int reason) VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf) { VirtIONet *n; -static int virtio_net_id; n = (VirtIONet *)virtio_common_init(virtio-net, VIRTIO_ID_NET, sizeof(struct virtio_net_config), @@ -923,7 +923,8 @@ VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf) n-vlans = qemu_mallocz(MAX_VLAN 3); -register_savevm(NULL, virtio-net, virtio_net_id++, VIRTIO_NET_VM_VERSION, +n-qdev = dev; +register_savevm(dev, virtio-net, -1, VIRTIO_NET_VM_VERSION, virtio_net_save, virtio_net_load, n); n-vmstate = qemu_add_vm_change_state_handler(virtio_net_vmstate_change, n); @@ -941,7 +942,7 @@ void virtio_net_exit(VirtIODevice *vdev) qemu_purge_queued_packets(n-nic-nc); -unregister_savevm(NULL, virtio-net, n); +unregister_savevm(n-qdev, virtio-net, n); qemu_free(n-mac_table.macs); qemu_free(n-vlans);
[Qemu-devel] [PATCH 06/12] qdev: Decouple qdev_prop_drive from DriveInfo
Make the property point to BlockDriverState, cutting out the DriveInfo middleman. This prepares the ground for block devices that don't have a DriveInfo. Currently all user-defined ones have a DriveInfo, because the only way to define one is -drive friends (they go through drive_init()). DriveInfo is closely tied to -drive, and like -drive, it mixes information about host and guest part of the block device. I'm working towards a new way to define block devices, with clean host/guest separation, and I need to get DriveInfo out of the way for that. Fortunately, the device models are perfectly happy with BlockDriverState, except for two places: ide_drive_initfn() and scsi_disk_initfn() need to check the DriveInfo for a serial number set with legacy -drive serial=... Use drive_of_blockdev() there. Device model code should now use DriveInfo only when explicitly dealing with drives defined the old way, i.e. without -device. Signed-off-by: Markus Armbruster arm...@redhat.com --- block_int.h |6 ++ hw/fdc.c | 22 ++ hw/ide/core.c| 17 + hw/ide/internal.h|2 +- hw/ide/qdev.c| 12 hw/pci-hotplug.c |4 ++-- hw/qdev-properties.c | 21 - hw/qdev.h|6 +++--- hw/s390-virtio.c |2 +- hw/scsi-bus.c|8 hw/scsi-disk.c | 16 +++- hw/scsi-generic.c|6 +++--- hw/scsi.h|2 +- hw/usb-msd.c | 15 +++ hw/virtio-blk.c |2 +- hw/virtio-pci.c |4 ++-- 16 files changed, 73 insertions(+), 72 deletions(-) diff --git a/block_int.h b/block_int.h index b64a009..e60aed4 100644 --- a/block_int.h +++ b/block_int.h @@ -210,10 +210,8 @@ void *qemu_blockalign(BlockDriverState *bs, size_t size); int is_windows_drive(const char *filename); #endif -struct DriveInfo; - typedef struct BlockConf { -struct DriveInfo *dinfo; +BlockDriverState *bs; uint16_t physical_block_size; uint16_t logical_block_size; uint16_t min_io_size; @@ -234,7 +232,7 @@ static inline unsigned int get_physical_block_exp(BlockConf *conf) } #define DEFINE_BLOCK_PROPERTIES(_state, _conf) \ -DEFINE_PROP_DRIVE(drive, _state, _conf.dinfo),\ +DEFINE_PROP_DRIVE(drive, _state, _conf.bs), \ DEFINE_PROP_UINT16(logical_block_size, _state,\ _conf.logical_block_size, 512), \ DEFINE_PROP_UINT16(physical_block_size, _state, \ diff --git a/hw/fdc.c b/hw/fdc.c index 45a876d..08712bc 100644 --- a/hw/fdc.c +++ b/hw/fdc.c @@ -80,7 +80,6 @@ typedef enum FDiskFlags { } FDiskFlags; typedef struct FDrive { -DriveInfo *dinfo; BlockDriverState *bs; /* Drive status */ FDriveType drive; @@ -100,7 +99,6 @@ typedef struct FDrive { static void fd_init(FDrive *drv) { /* Drive */ -drv-bs = drv-dinfo ? drv-dinfo-bdrv : NULL; drv-drive = FDRIVE_DRV_NONE; drv-perpendicular = 0; /* Disk */ @@ -1862,10 +1860,10 @@ FDCtrl *fdctrl_init_isa(DriveInfo **fds) dev = isa_create(isa-fdc); if (fds[0]) { -qdev_prop_set_drive(dev-qdev, driveA, fds[0]); +qdev_prop_set_drive(dev-qdev, driveA, fds[0]-bdrv); } if (fds[1]) { -qdev_prop_set_drive(dev-qdev, driveB, fds[1]); +qdev_prop_set_drive(dev-qdev, driveB, fds[1]-bdrv); } if (qdev_init(dev-qdev) 0) return NULL; @@ -1884,10 +1882,10 @@ FDCtrl *fdctrl_init_sysbus(qemu_irq irq, int dma_chann, fdctrl = sys-state; fdctrl-dma_chann = dma_chann; /* FIXME */ if (fds[0]) { -qdev_prop_set_drive(dev, driveA, fds[0]); +qdev_prop_set_drive(dev, driveA, fds[0]-bdrv); } if (fds[1]) { -qdev_prop_set_drive(dev, driveB, fds[1]); +qdev_prop_set_drive(dev, driveB, fds[1]-bdrv); } qdev_init_nofail(dev); sysbus_connect_irq(sys-busdev, 0, irq); @@ -1905,7 +1903,7 @@ FDCtrl *sun4m_fdctrl_init(qemu_irq irq, target_phys_addr_t io_base, dev = qdev_create(NULL, SUNW,fdtwo); if (fds[0]) { -qdev_prop_set_drive(dev, drive, fds[0]); +qdev_prop_set_drive(dev, drive, fds[0]-bdrv); } qdev_init_nofail(dev); sys = DO_UPCAST(FDCtrlSysBus, busdev.qdev, dev); @@ -2030,8 +2028,8 @@ static ISADeviceInfo isa_fdc_info = { .qdev.vmsd = vmstate_isa_fdc, .qdev.reset = fdctrl_external_reset_isa, .qdev.props = (Property[]) { -DEFINE_PROP_DRIVE(driveA, FDCtrlISABus, state.drives[0].dinfo), -DEFINE_PROP_DRIVE(driveB, FDCtrlISABus, state.drives[1].dinfo), +DEFINE_PROP_DRIVE(driveA, FDCtrlISABus, state.drives[0].bs), +DEFINE_PROP_DRIVE(driveB, FDCtrlISABus, state.drives[1].bs), DEFINE_PROP_END_OF_LIST(), }, }; @@ -2053,8 +2051,8 @@ static SysBusDeviceInfo
[Qemu-devel] [PATCH v2 10/16] ramblocks: Make use of DeviceState pointer and BusInfo.get_dev_path
With these two pieces in place, we can start naming ramblocks. When the device is present and it lives on a bus that provides a device path, we concatenate the path and the provided name. Otherwise we just use name. The resulting id string must be unique. For now we assume an allocation for the same name and size is a device that has been removed and reinserted and return the same block. This will go away once qemu_ram_free() is implemented. Signed-off-by: Alex Williamson alex.william...@redhat.com --- cpu-all.h |1 + exec.c| 29 +++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/cpu-all.h b/cpu-all.h index dbb2139..5d8342b 100644 --- a/cpu-all.h +++ b/cpu-all.h @@ -865,6 +865,7 @@ typedef struct RAMBlock { uint8_t *host; ram_addr_t offset; ram_addr_t length; +char idstr[256]; QLIST_ENTRY(RAMBlock) next; } RAMBlock; diff --git a/exec.c b/exec.c index dc47831..a136c13 100644 --- a/exec.c +++ b/exec.c @@ -36,6 +36,7 @@ #include qemu-common.h #include tcg.h #include hw/hw.h +#include hw/qdev.h #include osdep.h #include kvm.h #include qemu-timer.h @@ -2778,10 +2779,34 @@ static ram_addr_t find_ram_offset(ram_addr_t size) ram_addr_t qemu_ram_alloc(DeviceState *dev, const char *name, ram_addr_t size) { -RAMBlock *new_block; +RAMBlock *new_block, *block; size = TARGET_PAGE_ALIGN(size); -new_block = qemu_malloc(sizeof(*new_block)); +new_block = qemu_mallocz(sizeof(*new_block)); + +if (dev dev-parent_bus dev-parent_bus-info-get_dev_path) { +char *id = dev-parent_bus-info-get_dev_path(dev); +if (id) { +snprintf(new_block-idstr, sizeof(new_block-idstr), %s/, id); +qemu_free(id); +} +} +pstrcat(new_block-idstr, sizeof(new_block-idstr), name); + +QLIST_FOREACH(block, ram_list.blocks, next) { +if (!strcmp(block-idstr, new_block-idstr)) { +if (block-length == new_block-length) { +fprintf(stderr, RAMBlock \%s\ exists, assuming lack of +free.\n, new_block-idstr); +qemu_free(new_block); +return block-offset; +} else { +fprintf(stderr, RAMBlock \%s\ already registered with +different size, abort\n, new_block-idstr); +abort(); +} +} +} if (mem_path) { #if defined (__linux__) !defined(TARGET_S390X)
[Qemu-devel] [PATCH 1/8] Introduce proper compiler barrier
Define barrier() as optimization barrier and replace (potentially unreliable) asm() fences. Signed-off-by: Jan Kiszka jan.kis...@siemens.com --- cpu-exec.c |5 +++-- qemu-barrier.h |3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cpu-exec.c b/cpu-exec.c index 026980a..525b3b4 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -21,6 +21,7 @@ #include disas.h #include tcg.h #include kvm.h +#include qemu-barrier.h #if !defined(CONFIG_SOFTMMU) #undef EAX @@ -233,7 +234,7 @@ int cpu_exec(CPUState *env1) use it. */ QEMU_BUILD_BUG_ON (sizeof (saved_env_reg) != sizeof (env)); saved_env_reg = (host_reg_t) env; -asm(); +barrier(); env = env1; if (exit_request) { @@ -669,7 +670,7 @@ int cpu_exec(CPUState *env1) #endif /* restore global registers */ -asm(); +barrier(); env = (void *) saved_env_reg; /* fail safe : never use cpu_single_env outside cpu_exec() */ diff --git a/qemu-barrier.h b/qemu-barrier.h index 3bd1075..b77fce2 100644 --- a/qemu-barrier.h +++ b/qemu-barrier.h @@ -4,4 +4,7 @@ /* FIXME: arch dependant, x86 version */ #define smp_wmb() asm volatile( ::: memory) +/* Compiler barrier */ +#define barrier() asm volatile( ::: memory) + #endif -- 1.7.1
[Qemu-devel] [PATCH v2 02/16] pc: Allocate all ram in a single qemu_ram_alloc()
This will benefit us when we migrate based on ramblock name since we won't be bouncing between separate blocks. Signed-off-by: Alex Williamson alex.william...@redhat.com --- hw/pc.c | 22 +- 1 files changed, 9 insertions(+), 13 deletions(-) diff --git a/hw/pc.c b/hw/pc.c index 1848151..d6f3aa4 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -893,27 +893,23 @@ void pc_memory_init(ram_addr_t ram_size, *above_4g_mem_size_p = above_4g_mem_size; *below_4g_mem_size_p = below_4g_mem_size; +#if TARGET_PHYS_ADDR_BITS == 32 +if (above_4g_mem_size 0) { +hw_error(To much RAM for 32-bit physical address); +} +#endif linux_boot = (kernel_filename != NULL); /* allocate RAM */ -ram_addr = qemu_ram_alloc(below_4g_mem_size); +ram_addr = qemu_ram_alloc(below_4g_mem_size + above_4g_mem_size); cpu_register_physical_memory(0, 0xa, ram_addr); cpu_register_physical_memory(0x10, below_4g_mem_size - 0x10, ram_addr + 0x10); - -/* above 4giga memory allocation */ -if (above_4g_mem_size 0) { -#if TARGET_PHYS_ADDR_BITS == 32 -hw_error(To much RAM for 32-bit physical address); -#else -ram_addr = qemu_ram_alloc(above_4g_mem_size); -cpu_register_physical_memory(0x1ULL, - above_4g_mem_size, - ram_addr); +#if TARGET_PHYS_ADDR_BITS 32 +cpu_register_physical_memory(0x1ULL, above_4g_mem_size, + ram_addr + below_4g_mem_size); #endif -} - /* BIOS load */ if (bios_name == NULL)
[Qemu-devel] [PATCH 12/12] pc: Fix CMOS info for drives defined with -device
Drives defined with -drive if=ide get get created along with the IDE controller, inside machine-init(). That's before cmos_init(). Drives defined with -device get created during generic device init. That's after cmos_init(). Because of that, CMOS has no information on them (type, geometry, translation). Older versions of Windows such as XP reportedly choke on that. Split off the part of CMOS initialization that needs to know about -device devices, and turn it into a reset handler, so it runs after device creation. Signed-off-by: Markus Armbruster arm...@redhat.com --- hw/ide.h |2 + hw/ide/qdev.c |7 hw/pc.c | 94 +++- hw/pc.h |3 +- hw/pc_piix.c | 16 +++--- 5 files changed, 81 insertions(+), 41 deletions(-) diff --git a/hw/ide.h b/hw/ide.h index f0cb320..4ccb580 100644 --- a/hw/ide.h +++ b/hw/ide.h @@ -23,4 +23,6 @@ void mmio_ide_init (target_phys_addr_t membase, target_phys_addr_t membase2, qemu_irq irq, int shift, DriveInfo *hd0, DriveInfo *hd1); +void ide_get_bs(BlockDriverState *bs[], BusState *qbus); + #endif /* HW_IDE_H */ diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c index b4bc5ac..2d9acbb 100644 --- a/hw/ide/qdev.c +++ b/hw/ide/qdev.c @@ -88,6 +88,13 @@ IDEDevice *ide_create_drive(IDEBus *bus, int unit, DriveInfo *drive) return DO_UPCAST(IDEDevice, qdev, dev); } +void ide_get_bs(BlockDriverState *bs[], BusState *qbus) +{ +IDEBus *bus = DO_UPCAST(IDEBus, qbus, qbus); +bs[0] = bus-master ? bus-master-conf.bs : NULL; +bs[1] = bus-slave ? bus-slave-conf.bs : NULL; +} + /* - */ typedef struct IDEDrive { diff --git a/hw/pc.c b/hw/pc.c index 1848151..0cea196 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -25,6 +25,7 @@ #include pc.h #include apic.h #include fdc.h +#include ide.h #include pci.h #include vmware_vga.h #include monitor.h @@ -275,14 +276,65 @@ static int pc_boot_set(void *opaque, const char *boot_device) return set_boot_dev(opaque, boot_device, 0); } -/* hd_table must contain 4 block drivers */ +typedef struct pc_cmos_init_late_arg { +ISADevice *rtc_state; +BusState *idebus0, *idebus1; +} pc_cmos_init_late_arg; + +static void pc_cmos_init_late(void *opaque) +{ +pc_cmos_init_late_arg *arg = opaque; +ISADevice *s = arg-rtc_state; +int val; +BlockDriverState *hd_table[4]; +int i; + +ide_get_bs(hd_table, arg-idebus0); +ide_get_bs(hd_table + 2, arg-idebus1); + +rtc_set_memory(s, 0x12, (hd_table[0] ? 0xf0 : 0) | (hd_table[1] ? 0x0f : 0)); +if (hd_table[0]) +cmos_init_hd(0x19, 0x1b, hd_table[0], s); +if (hd_table[1]) +cmos_init_hd(0x1a, 0x24, hd_table[1], s); + +val = 0; +for (i = 0; i 4; i++) { +if (hd_table[i]) { +int cylinders, heads, sectors, translation; +/* NOTE: bdrv_get_geometry_hint() returns the physical +geometry. It is always such that: 1 = sects = 63, 1 += heads = 16, 1 = cylinders = 16383. The BIOS +geometry can be different if a translation is done. */ +translation = bdrv_get_translation_hint(hd_table[i]); +if (translation == BIOS_ATA_TRANSLATION_AUTO) { +bdrv_get_geometry_hint(hd_table[i], cylinders, heads, sectors); +if (cylinders = 1024 heads = 16 sectors = 63) { +/* No translation. */ +translation = 0; +} else { +/* LBA translation. */ +translation = 1; +} +} else { +translation--; +} +val |= translation (i * 2); +} +} +rtc_set_memory(s, 0x39, val); + +qemu_unregister_reset(pc_cmos_init_late, opaque); +} + void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size, - const char *boot_device, DriveInfo **hd_table, + const char *boot_device, + BusState *idebus0, BusState *idebus1, FDCtrl *floppy_controller, ISADevice *s) { int val; int fd0, fd1, nb; -int i; +static pc_cmos_init_late_arg arg; /* various important CMOS locations needed by PC/Bochs bios */ @@ -351,38 +403,10 @@ void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size, rtc_set_memory(s, REG_EQUIPMENT_BYTE, val); /* hard drives */ - -rtc_set_memory(s, 0x12, (hd_table[0] ? 0xf0 : 0) | (hd_table[1] ? 0x0f : 0)); -if (hd_table[0]) -cmos_init_hd(0x19, 0x1b, hd_table[0]-bdrv, s); -if (hd_table[1]) -cmos_init_hd(0x1a, 0x24, hd_table[1]-bdrv, s); - -val = 0; -for (i = 0; i 4; i++) { -if (hd_table[i]) { -int cylinders, heads, sectors, translation; -/* NOTE: bdrv_get_geometry_hint() returns the physical -geometry.
[Qemu-devel] [PATCH v2 07/16] eepro100: Add a dev field to eeprom new/free functions
This allows us to create a more meaningful savevm string. Signed-off-by: Alex Williamson alex.william...@redhat.com --- hw/eepro100.c |4 ++-- hw/eeprom93xx.c |8 hw/eeprom93xx.h |4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/hw/eepro100.c b/hw/eepro100.c index 0ddca8b..2b75c8f 100644 --- a/hw/eepro100.c +++ b/hw/eepro100.c @@ -1835,7 +1835,7 @@ static int pci_nic_uninit(PCIDevice *pci_dev) cpu_unregister_io_memory(s-mmio_index); vmstate_unregister(pci_dev-qdev, s-vmstate, s); -eeprom93xx_free(s-eeprom); +eeprom93xx_free(pci_dev-qdev, s-eeprom); qemu_del_vlan_client(s-nic-nc); return 0; } @@ -1862,7 +1862,7 @@ static int e100_nic_init(PCIDevice *pci_dev) /* Add 64 * 2 EEPROM. i82557 and i82558 support a 64 word EEPROM, * i82559 and later support 64 or 256 word EEPROM. */ -s-eeprom = eeprom93xx_new(EEPROM_SIZE); +s-eeprom = eeprom93xx_new(pci_dev-qdev, EEPROM_SIZE); /* Handler for memory-mapped I/O */ s-mmio_index = diff --git a/hw/eeprom93xx.c b/hw/eeprom93xx.c index 6ba546f..660b28f 100644 --- a/hw/eeprom93xx.c +++ b/hw/eeprom93xx.c @@ -289,7 +289,7 @@ void eeprom93xx_reset(eeprom_t *eeprom) } #endif -eeprom_t *eeprom93xx_new(uint16_t nwords) +eeprom_t *eeprom93xx_new(DeviceState *dev, uint16_t nwords) { /* Add a new EEPROM (with 16, 64 or 256 words). */ eeprom_t *eeprom; @@ -316,15 +316,15 @@ eeprom_t *eeprom93xx_new(uint16_t nwords) /* Output DO is tristate, read results in 1. */ eeprom-eedo = 1; logout(eeprom = 0x%p, nwords = %u\n, eeprom, nwords); -vmstate_register(NULL, 0, vmstate_eeprom, eeprom); +vmstate_register(dev, 0, vmstate_eeprom, eeprom); return eeprom; } -void eeprom93xx_free(eeprom_t *eeprom) +void eeprom93xx_free(DeviceState *dev, eeprom_t *eeprom) { /* Destroy EEPROM. */ logout(eeprom = 0x%p\n, eeprom); -vmstate_unregister(NULL, vmstate_eeprom, eeprom); +vmstate_unregister(dev, vmstate_eeprom, eeprom); qemu_free(eeprom); } diff --git a/hw/eeprom93xx.h b/hw/eeprom93xx.h index 47282d3..8ba0e28 100644 --- a/hw/eeprom93xx.h +++ b/hw/eeprom93xx.h @@ -23,10 +23,10 @@ typedef struct _eeprom_t eeprom_t; /* Create a new EEPROM with (nwords * 2) bytes. */ -eeprom_t *eeprom93xx_new(uint16_t nwords); +eeprom_t *eeprom93xx_new(DeviceState *dev, uint16_t nwords); /* Destroy an existing EEPROM. */ -void eeprom93xx_free(eeprom_t *eeprom); +void eeprom93xx_free(DeviceState *dev, eeprom_t *eeprom); /* Read from the EEPROM. */ uint16_t eeprom93xx_read(eeprom_t *eeprom);
[Qemu-devel] [PATCH 4/8] Fix cpu_exit for tcp_cpu_exec
If a cpu_exit request is pending, ensure that we leave the CPU loop quickly. For this purpose, keep the global exit_request pending until we are about to leave tcg_cpu_exec. Also, immediately break out of the SMP loop if the request is set, do not run till the end of the chain. This preserves the VCPU scheduling order in SMP mode. Signed-off-by: Jan Kiszka jan.kis...@siemens.com --- cpu-exec.c |3 +-- cpus.c |3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cpu-exec.c b/cpu-exec.c index 5f88f3f..d170566 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -237,9 +237,8 @@ int cpu_exec(CPUState *env1) barrier(); env = env1; -if (exit_request) { +if (unlikely(exit_request)) { env-exit_request = 1; -exit_request = 0; } #if defined(TARGET_I386) diff --git a/cpus.c b/cpus.c index 37e6b33..ff5e804 100644 --- a/cpus.c +++ b/cpus.c @@ -769,7 +769,7 @@ bool tcg_cpu_exec(void) if (next_cpu == NULL) next_cpu = first_cpu; -for (; next_cpu != NULL; next_cpu = next_cpu-next_cpu) { +for (; next_cpu != NULL !exit_request; next_cpu = next_cpu-next_cpu) { CPUState *env = cur_cpu = next_cpu; qemu_clock_enable(vm_clock, @@ -788,6 +788,7 @@ bool tcg_cpu_exec(void) break; } } +exit_request = 0; return tcg_has_work(); } -- 1.7.1
[Qemu-devel] [PATCH 03/12] blockdev: Remove drive_get_serial()
Unused since commit 6ced55a5. Signed-off-by: Markus Armbruster arm...@redhat.com --- blockdev.c | 12 blockdev.h |1 - 2 files changed, 0 insertions(+), 13 deletions(-) diff --git a/blockdev.c b/blockdev.c index 3b8c606..e0495e5 100644 --- a/blockdev.c +++ b/blockdev.c @@ -78,18 +78,6 @@ int drive_get_max_bus(BlockInterfaceType type) return max_bus; } -const char *drive_get_serial(BlockDriverState *bdrv) -{ -DriveInfo *dinfo; - -QTAILQ_FOREACH(dinfo, drives, next) { -if (dinfo-bdrv == bdrv) -return dinfo-serial; -} - -return \0; -} - static void bdrv_format_print(void *opaque, const char *name) { fprintf(stderr, %s, name); diff --git a/blockdev.h b/blockdev.h index 23ea576..a936785 100644 --- a/blockdev.h +++ b/blockdev.h @@ -40,7 +40,6 @@ extern DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit); extern DriveInfo *drive_get_by_id(const char *id); extern int drive_get_max_bus(BlockInterfaceType type); extern void drive_uninit(DriveInfo *dinfo); -extern const char *drive_get_serial(BlockDriverState *bdrv); extern QemuOpts *drive_add(const char *file, const char *fmt, ...); extern DriveInfo *drive_init(QemuOpts *arg, int default_to_scsi, -- 1.6.6.1
[Qemu-devel] [PATCH v2 15/16] pci: Free the space allocated for the option rom on removal
Signed-off-by: Alex Williamson alex.william...@redhat.com --- hw/pci.c | 11 +++ 1 files changed, 11 insertions(+), 0 deletions(-) diff --git a/hw/pci.c b/hw/pci.c index fe7c5c3..a7ff566 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -76,6 +76,7 @@ static struct BusInfo pci_bus_info = { static void pci_update_mappings(PCIDevice *d); static void pci_set_irq(void *opaque, int irq_num, int level); static int pci_add_option_rom(PCIDevice *pdev); +static void pci_del_option_rom(PCIDevice *pdev); static uint16_t pci_default_sub_vendor_id = PCI_SUBVENDOR_ID_REDHAT_QUMRANET; static uint16_t pci_default_sub_device_id = PCI_SUBDEVICE_ID_QEMU; @@ -709,6 +710,7 @@ static int pci_unregister_device(DeviceState *dev) return ret; pci_unregister_io_regions(pci_dev); +pci_del_option_rom(pci_dev); do_pci_unregister_device(pci_dev); return 0; } @@ -1765,6 +1767,15 @@ static int pci_add_option_rom(PCIDevice *pdev) return 0; } +static void pci_del_option_rom(PCIDevice *pdev) +{ +if (!pdev-rom_offset) +return; + +qemu_ram_free(pdev-rom_offset); +pdev-rom_offset = 0; +} + /* Reserve space and add capability to the linked list in pci config space */ int pci_add_capability_at_offset(PCIDevice *pdev, uint8_t cap_id, uint8_t offset, uint8_t size)
[Qemu-devel] [PATCH v2 09/16] qemu_ram_alloc: Add DeviceState and name parameters
These will be used to generate unique id strings for ramblocks. The name field is required, the device pointer is optional as most callers don't have a device. When there's no device or the device isn't a child of a bus implementing BusInfo.get_dev_path, the name should be unique for the platform. Signed-off-by: Alex Williamson alex.william...@redhat.com --- cpu-common.h |2 +- exec.c|2 +- hw/an5206.c |4 ++-- hw/armv7m.c |9 ++--- hw/axis_dev88.c |4 ++-- hw/dummy_m68k.c |2 +- hw/etraxfs.c |6 +++--- hw/g364fb.c |2 +- hw/gumstix.c |6 -- hw/integratorcp.c |4 ++-- hw/mainstone.c|6 -- hw/mcf5208.c |4 ++-- hw/mips_jazz.c|4 ++-- hw/mips_malta.c |4 ++-- hw/mips_mipssim.c |4 ++-- hw/mips_r4k.c |6 +++--- hw/musicpal.c | 11 +++ hw/omap1.c|6 -- hw/omap2.c|6 -- hw/omap_sx1.c | 12 hw/onenand.c |2 +- hw/palm.c |3 ++- hw/pc.c |7 --- hw/pci.c |7 ++- hw/petalogix_s3adsp1800_mmu.c |7 --- hw/ppc405_boards.c| 18 +- hw/ppc405_uc.c|2 +- hw/ppc4xx_devs.c |4 +++- hw/ppc_newworld.c |6 +++--- hw/ppc_oldworld.c |6 +++--- hw/ppc_prep.c |4 ++-- hw/ppce500_mpc8544ds.c|3 ++- hw/pxa2xx.c | 12 hw/r2d.c |4 ++-- hw/realview.c |6 +++--- hw/s390-virtio.c |2 +- hw/sm501.c|2 +- hw/spitz.c|2 +- hw/sun4m.c|8 hw/sun4u.c|4 ++-- hw/syborg.c |2 +- hw/tc6393xb.c |2 +- hw/tcx.c |2 +- hw/tosa.c |2 +- hw/versatilepb.c |2 +- hw/vga.c |2 +- hw/vmware_vga.c |2 +- 47 files changed, 130 insertions(+), 97 deletions(-) diff --git a/cpu-common.h b/cpu-common.h index b24cecc..71e7933 100644 --- a/cpu-common.h +++ b/cpu-common.h @@ -40,7 +40,7 @@ static inline void cpu_register_physical_memory(target_phys_addr_t start_addr, } ram_addr_t cpu_get_physical_page_desc(target_phys_addr_t addr); -ram_addr_t qemu_ram_alloc(ram_addr_t); +ram_addr_t qemu_ram_alloc(DeviceState *dev, const char *name, ram_addr_t size); void qemu_ram_free(ram_addr_t addr); /* This should only be used for ram local to a device. */ void *qemu_get_ram_ptr(ram_addr_t addr); diff --git a/exec.c b/exec.c index 088d665..dc47831 100644 --- a/exec.c +++ b/exec.c @@ -2776,7 +2776,7 @@ static ram_addr_t find_ram_offset(ram_addr_t size) return last; } -ram_addr_t qemu_ram_alloc(ram_addr_t size) +ram_addr_t qemu_ram_alloc(DeviceState *dev, const char *name, ram_addr_t size) { RAMBlock *new_block; diff --git a/hw/an5206.c b/hw/an5206.c index f584d88..b9f19a9 100644 --- a/hw/an5206.c +++ b/hw/an5206.c @@ -54,11 +54,11 @@ static void an5206_init(ram_addr_t ram_size, /* DRAM at address zero */ cpu_register_physical_memory(0, ram_size, -qemu_ram_alloc(ram_size) | IO_MEM_RAM); +qemu_ram_alloc(NULL, an5206.ram, ram_size) | IO_MEM_RAM); /* Internal SRAM. */ cpu_register_physical_memory(AN5206_RAMBAR_ADDR, 512, -qemu_ram_alloc(512) | IO_MEM_RAM); +qemu_ram_alloc(NULL, an5206.sram, 512) | IO_MEM_RAM); mcf5206_init(AN5206_MBAR_ADDR, env); diff --git a/hw/armv7m.c b/hw/armv7m.c index 854261d..588ec98 100644 --- a/hw/armv7m.c +++ b/hw/armv7m.c @@ -200,9 +200,11 @@ qemu_irq *armv7m_init(int flash_size, int sram_size, /* Flash programming is done via the SCU, so pretend it is ROM. */ cpu_register_physical_memory(0, flash_size, - qemu_ram_alloc(flash_size) | IO_MEM_ROM); + qemu_ram_alloc(NULL, armv7m.flash, +flash_size) | IO_MEM_ROM); cpu_register_physical_memory(0x2000, sram_size, - qemu_ram_alloc(sram_size) | IO_MEM_RAM); + qemu_ram_alloc(NULL, armv7m.sram, +sram_size) | IO_MEM_RAM); armv7m_bitband_init(); nvic = qdev_create(NULL, armv7m_nvic); @@ -236,7 +238,8 @@ qemu_irq *armv7m_init(int flash_size, int sram_size, space. This stops qemu complaining about executing code outside RAM when
[Qemu-devel] [PATCH v2 00/16] Make migration work with hotplug
v2: Not too many comments, hope that's because everyone agrees ;) A couple minor changes. The 2nd patch is new and provides a bit of an optimization for large memory pc guets. The first two patches stand on their own even if we're undecided about the rest. Thanks, Alex changes: - Use pci_find_domain() for PCI domain, thanks Isaku - Convert pc to allocate all ram in one chunk, which avoids penalizing large memory VMs bouncing between ramblocks during migration. v1: Ok, new approach. I'm going to attempt to extract myself for the canonical device path approach, because we're missing too many pieces to make that work. Instead, I'll take Anthony's advice and try to simplify. We still want a unique name for ramblocks and savevm, but the hotplug problem today is only for PCI devices. PCI conveniently has globally unique, dare I say canonical, addressing in the form of domain:bus:device.func. To get to this, let's add a new function on the BusInfo structure called get_dev_path(). For a PCI device, we can simply traverse up the qdev tree to the BusInfo structure, look for the function, and call it to return a global PCI address. For some buses, these functions could chain up to their parent bus appending strings together to get a unique path. An example would be USB, where the USB port number may not be unique. If we traverse up to the PCI device providing USB, and then to the PCI bus, we get a globally unique PCI path, appended with a USB port number. To make this work for ramblocks and savevm, we need a DeviceState pointer when the they are create/registered, and we need a caller provided context in case there are multiple ramblocks/savevm associated with a device. Savevm already provies the context, and I've attempted to make reasonable guesses at these for the ramblocks. Note that most of the ramblocks aren't associated with a device, so I don't think it makes sense to link savevm and ramblocks together with the same absolute id string. Once we have savevm with unique id strings, rather than hotplug unfriendly instance numbers, we can be sure that the right driver instance is loading the correct vmstate. I've also implemented a compat field for this, so we can still accept incoming migrations from previous versions. Once we have ramblocks with a unique id string, we can switch to using id + offset for migration, which enables a ram_addr_t space that supports gaps, which enables us to implement qemu_ram_free(). With that, I think we can finally do migrations reliable after hotplug! Note that the target VM still needs to be created to match the current devices and bus addresses of the source VM. We can also still maintain compatibility for migrations here by bumping the ram migration version and supporting both new and old (just hope the source hasn't done any hotplugs). Sound reasonable? Is get_dev_path the right name? In the right place? The PCI return is currently :bb:dd.f, should this be PCI::bb:dd.f? Something else? Thanks, Alex --- Alex Williamson (16): ramblocks: No more being lazy about duplicate names pci: Free the space allocated for the option rom on removal qemu_ram_free: Implement it savevm: Create a new continue flag to avoid resending block name savevm: Use RAM blocks for basis of migration savevm: Migrate RAM based on name/offset ramblocks: Make use of DeviceState pointer and BusInfo.get_dev_path qemu_ram_alloc: Add DeviceState and name parameters virtio-net: Incorporate a DeviceState pointer and let savevm track instances eepro100: Add a dev field to eeprom new/free functions savevm: Make use of DeviceState savevm: Add DeviceState param pci: Implement BusInfo.get_dev_path() qdev: Add a get_dev_path() function to BusInfo pc: Allocate all ram in a single qemu_ram_alloc() Remove uses of ram.last_offset (aka last_ram_offset) arch_init.c | 183 +++-- audio/audio.c |2 block-migration.c |4 - cpu-all.h |5 + cpu-common.h |2 exec.c| 96 +++--- hw/adb.c |4 - hw/ads7846.c |2 hw/an5206.c |4 - hw/arm_gic.c |2 hw/arm_timer.c|4 - hw/armv7m.c |9 +- hw/armv7m_nvic.c |2 hw/axis_dev88.c |4 - hw/cirrus_vga.c |2 hw/cuda.c |2 hw/dma.c |4 - hw/dummy_m68k.c |2 hw/eepro100.c |8 +- hw/eeprom93xx.c |8 +- hw/eeprom93xx.h |4 - hw/etraxfs.c |6 + hw/fw_cfg.c |2 hw/g364fb.c |4 - hw/grackle_pci.c
[Qemu-devel] [PATCH 07/12] blockdev: drive_get_by_id() is no longer used, remove
Signed-off-by: Markus Armbruster arm...@redhat.com --- blockdev.c | 12 blockdev.h |1 - 2 files changed, 0 insertions(+), 13 deletions(-) diff --git a/blockdev.c b/blockdev.c index 827ea1c..3747098 100644 --- a/blockdev.c +++ b/blockdev.c @@ -75,18 +75,6 @@ DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit) return NULL; } -DriveInfo *drive_get_by_id(const char *id) -{ -DriveInfo *dinfo; - -QTAILQ_FOREACH(dinfo, drives, next) { -if (strcmp(id, dinfo-id)) -continue; -return dinfo; -} -return NULL; -} - int drive_get_max_bus(BlockInterfaceType type) { int max_bus; diff --git a/blockdev.h b/blockdev.h index 418ebb6..a72d335 100644 --- a/blockdev.h +++ b/blockdev.h @@ -41,7 +41,6 @@ typedef struct DriveInfo { #define MAX_SCSI_DEVS 7 extern DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit); -extern DriveInfo *drive_get_by_id(const char *id); extern int drive_get_max_bus(BlockInterfaceType type); extern void drive_uninit(DriveInfo *dinfo); extern DriveInfo *drive_of_blockdev(BlockDriverState *bs); -- 1.6.6.1
[Qemu-devel] [PATCH 1/2] Add virtio-blk support to path_id
This patch adds a case handling path_id invoked on a virtio-blk device. Currently path_id walks the parent path to virtio-pci but doesn't know that it's the end of the path and exits without building the path (providing no output resulting in no disk/by-path symlinks to virtio-blk devices). This patch handles the virtio-pci path and updates the path accordingly. /lib/udev/path_id --debug /block/vda udev_device_new_from_syspath: device 0x2300120 has devpath '/devices/virtio-pci/virtio1/block/vda' udev_device_new_from_syspath: device 0x2300380 has devpath '/devices/virtio-pci/virtio1' udev_device_new_from_syspath: device 0x2300670 has devpath '/devices/virtio-pci' ID_PATH=virtio-pci-virtio1 And with the current persistent-storage rules generates: % ls -al /dev/disk/by-path | grep vda lrwxrwxrwx. 1 root root 9 Jun 1 22:09 virtio-pci-virtio1 - ../../vda Signed-off-by: Ryan Harper ry...@us.ibm.com --- extras/path_id/path_id.c |3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/extras/path_id/path_id.c b/extras/path_id/path_id.c index dcee378..c19bfd0 100644 --- a/extras/path_id/path_id.c +++ b/extras/path_id/path_id.c @@ -448,6 +448,9 @@ int main(int argc, char **argv) } else if (strcmp(subsys, xen) == 0) { path_prepend(path, xen-%s, udev_device_get_sysname(parent)); parent = skip_subsystem(parent, xen); + } else if (strcmp(subsys, virtio) == 0) { + path_prepend(path, virtio-pci-%s, udev_device_get_sysname(parent)); + parent = skip_subsystem(parent, virtio); } parent = udev_device_get_parent(parent); -- 1.6.3.3
[Qemu-devel] [PATCH v2 03/16] qdev: Add a get_dev_path() function to BusInfo
This function is meant to provide a stable device path for buses which are able to implement it. If a bus has a globally unique addresses scheme, one address level may be sufficient to provide a path. Other buses may need to recursively traverse up the qdev tree. Signed-off-by: Alex Williamson alex.william...@redhat.com --- hw/qdev.h |3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/hw/qdev.h b/hw/qdev.h index be5ad67..d64619f 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -49,10 +49,13 @@ struct DeviceState { }; typedef void (*bus_dev_printfn)(Monitor *mon, DeviceState *dev, int indent); +typedef char *(*bus_get_dev_path)(DeviceState *dev); + struct BusInfo { const char *name; size_t size; bus_dev_printfn print_dev; +bus_get_dev_path get_dev_path; Property *props; };
[Qemu-devel] [PATCH v2 04/16] pci: Implement BusInfo.get_dev_path()
This works great for PCI since a segment:bus:dev.fn uniquely describes a global address. No need to traverse up the qdev tree. PCI segment support is a placeholder for compatibility once we support multiple segments. Signed-off-by: Alex Williamson alex.william...@redhat.com --- hw/pci.c | 14 ++ 1 files changed, 14 insertions(+), 0 deletions(-) diff --git a/hw/pci.c b/hw/pci.c index 7787005..1e77ae6 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -58,11 +58,13 @@ struct PCIBus { }; static void pcibus_dev_print(Monitor *mon, DeviceState *dev, int indent); +static char *pcibus_get_dev_path(DeviceState *dev); static struct BusInfo pci_bus_info = { .name = PCI, .size = sizeof(PCIBus), .print_dev = pcibus_dev_print, +.get_dev_path = pcibus_get_dev_path, .props = (Property[]) { DEFINE_PROP_PCI_DEVFN(addr, PCIDevice, devfn, -1), DEFINE_PROP_STRING(romfile, PCIDevice, romfile), @@ -1853,6 +1855,18 @@ static void pcibus_dev_print(Monitor *mon, DeviceState *dev, int indent) } } +static char *pcibus_get_dev_path(DeviceState *dev) +{ +PCIDevice *d = (PCIDevice *)dev; +char path[16]; + +snprintf(path, sizeof(path), %04x:%02x:%02x.%x, + pci_find_domain(d-bus), d-config[PCI_SECONDARY_BUS], + PCI_SLOT(d-devfn), PCI_FUNC(d-devfn)); + +return strdup(path); +} + static PCIDeviceInfo bridge_info = { .qdev.name= pci-bridge, .qdev.size= sizeof(PCIBridge),
[Qemu-devel] Re: [PATCH 2/2] tcg-s390: New TCG Target.
On 06/17/2010 12:40 PM, Aurelien Jarno wrote: +/* Handle the modifiers. */ +if (ct TCG_CT_CONST_NEG) { +val = -val; +} This modifier is only used by subi. Wouldn't it be better to use a TCG_CT_CONST_SUBI instead? Not really. This negation needs to happen *before* the sign-extension of TCG_CT_CONST_32 in order to get correct results. While I could do a CONST_SUBI, I would have to handle CONST_32 again within the CONST_SUBI clause and I would not consider that better. r~
Re: [Qemu-devel] [PATCH 14/17] Move daemonize handling to OS specific files
On 06/25/10 18:41, Frank Arnold wrote: On Thu, 2010-06-10 at 05:42 -0400, jes.soren...@redhat.com wrote: diff --git a/os-posix.c b/os-posix.c index 6417d16..1672e06 100644 --- a/os-posix.c +++ b/os-posix.c @@ -160,6 +162,9 @@ void os_parse_cmd_args(int index, const char *optarg) case QEMU_OPTION_chroot: chroot_dir = optarg; break; +case QEMU_OPTION_daemonize: +daemonize = 1; +break; } return; } This move broke the -daemonize option for us. We are using the qemu-kvm tree. The issue is that the QEMU_OPTION_* enumeration between vl.c and os-posix.c is out of sync. In our case MAP_POPULATE is defined in vl.c but is not in os-posix.c. This excludes the option -mem-prealloc in os-posix.c, see qemu-options.def for the ifdef statement. All subsequent options are off by one in comparison to vl.c. Just including sys/mman.h in os-posix.c fixes the issue for me. But I'm not sure if there is a more generic fix to that problem. Thanks for the update. What do you mean that it changes the numbering, do you get a compile time error or are you saying that it is the order of parsing the options that change? Are you building on Linux or another OS? Cheers, Jes
Re: [Qemu-devel] [patch 2/3] QEMU-C-F: Introducing qemu userspace tool qemu-core-filter.
On 06/22/2010 06:32 PM, Anthony Liguori wrote: Hrm, the way you've sent this patch makes Thunderbird unhappy. It appears the whole thing is treated as an attachment. In the future, I'd suggest avoiding the Content-Disposition tag Sure. I will take care of this in future. On 06/21/2010 11:01 PM, Mahesh Salgaonkar wrote: Qemu userspace tool to filter out guest OS memory from qemu core file. Use '--enable-core-filter' option while running ./configure script to build qemu-core-filter tool. This is a post-processing tool works offline on qemu coredumps. This tool helps to reuce the size of qemu core file (generated by qemu crash) by removing guest OS memory from original core file. Currently it is only supported for Linux on x86 and x86_64. There are a few problems with a tool like this. The first is that it depends on very specific internals of qemu (namely, the way we allocate ram). If we applied this, we would get subtle breakages if we made even the slightest changes to qemu. This is the precise reason we would like to get this tool integrated into QEMU sources. So, whenever something changes in qemu, then this tool can be modified accordingly. IMHO, the value is also questionable. There is quite a bit of sensitive data left in the core file after removing guest memory. Any DMA buffer may contain very sensitive data (for instance, if you crash during a read of /etc/shadow). Even the CPU registers can contain sensitive data. I think the only really viable approach to this problem is to take a white list approach instead of a black list approach. That means extracting useful information that we're reasonably confident preserves privacy. That would be information like a back trace, the crash reason, etc. Tools like apport and ABT already do exactly this and they also present an interface to the user to validate the data before sending it. They also provide a way to collect other information (like host dmesg). I understand your point but this tool can be of interest of people who sends out large coredump files to service centers for initial analysis. This tool will help them to reduce the size of core file before sending it to service centers for analysis. What do you think? Regards, Anthony Liguori Regards, -Mahesh.
[Qemu-devel] [PATCH 01/12] scsi: scsi_bus_legacy_handle_cmdline() can fail, fix callers
None of its callers checks for failure. scsi_hot_add() can crash because of that: (qemu) drive_add 4 if=scsi,format=host_device,file=/dev/sg1 scsi-generic: scsi generic interface too old Segmentation fault (core dumped) Fix all callers, not just scsi_hot_add(). Signed-off-by: Markus Armbruster arm...@redhat.com --- hw/esp.c |3 +-- hw/lsi53c895a.c |2 +- hw/pci-hotplug.c |3 +++ hw/scsi-bus.c| 11 +++ hw/scsi.h|2 +- hw/usb-msd.c |3 +++ 6 files changed, 16 insertions(+), 8 deletions(-) diff --git a/hw/esp.c b/hw/esp.c index 7740879..349052a 100644 --- a/hw/esp.c +++ b/hw/esp.c @@ -679,8 +679,7 @@ static int esp_init1(SysBusDevice *dev) qdev_init_gpio_in(dev-qdev, parent_esp_reset, 1); scsi_bus_new(s-bus, dev-qdev, 0, ESP_MAX_DEVS, esp_command_complete); -scsi_bus_legacy_handle_cmdline(s-bus); -return 0; +return scsi_bus_legacy_handle_cmdline(s-bus); } static SysBusDeviceInfo esp_info = { diff --git a/hw/lsi53c895a.c b/hw/lsi53c895a.c index f5a91ba..c2a8010 100644 --- a/hw/lsi53c895a.c +++ b/hw/lsi53c895a.c @@ -2176,7 +2176,7 @@ static int lsi_scsi_init(PCIDevice *dev) scsi_bus_new(s-bus, dev-qdev, 1, LSI_MAX_DEVS, lsi_command_complete); if (!dev-qdev.hotplugged) { -scsi_bus_legacy_handle_cmdline(s-bus); +return scsi_bus_legacy_handle_cmdline(s-bus); } return 0; } diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c index c39e640..55c9fe3 100644 --- a/hw/pci-hotplug.c +++ b/hw/pci-hotplug.c @@ -90,6 +90,9 @@ static int scsi_hot_add(Monitor *mon, DeviceState *adapter, */ dinfo-unit = qemu_opt_get_number(dinfo-opts, unit, -1); scsidev = scsi_bus_legacy_add_drive(scsibus, dinfo, dinfo-unit); +if (!scsidev) { +return -1; +} dinfo-unit = scsidev-id; if (printinfo) diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c index 24bd060..d5b66c1 100644 --- a/hw/scsi-bus.c +++ b/hw/scsi-bus.c @@ -83,7 +83,6 @@ void scsi_qdev_register(SCSIDeviceInfo *info) } /* handle legacy '-drive if=scsi,...' cmd line args */ -/* FIXME callers should check for failure, but don't */ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, DriveInfo *dinfo, int unit) { const char *driver; @@ -98,18 +97,22 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, DriveInfo *dinfo, int unit) return DO_UPCAST(SCSIDevice, qdev, dev); } -void scsi_bus_legacy_handle_cmdline(SCSIBus *bus) +int scsi_bus_legacy_handle_cmdline(SCSIBus *bus) { DriveInfo *dinfo; -int unit; +int res = 0, unit; for (unit = 0; unit MAX_SCSI_DEVS; unit++) { dinfo = drive_get(IF_SCSI, bus-busnr, unit); if (dinfo == NULL) { continue; } -scsi_bus_legacy_add_drive(bus, dinfo, unit); +if (!scsi_bus_legacy_add_drive(bus, dinfo, unit)) { +res = -1; +break; +} } +return res; } void scsi_dev_clear_sense(SCSIDevice *dev) diff --git a/hw/scsi.h b/hw/scsi.h index b668e27..b1b5f73 100644 --- a/hw/scsi.h +++ b/hw/scsi.h @@ -98,7 +98,7 @@ static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d) } SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, DriveInfo *dinfo, int unit); -void scsi_bus_legacy_handle_cmdline(SCSIBus *bus); +int scsi_bus_legacy_handle_cmdline(SCSIBus *bus); void scsi_dev_clear_sense(SCSIDevice *dev); void scsi_dev_set_sense(SCSIDevice *dev, uint8_t key); diff --git a/hw/usb-msd.c b/hw/usb-msd.c index 003bd8a..8e9718c 100644 --- a/hw/usb-msd.c +++ b/hw/usb-msd.c @@ -531,6 +531,9 @@ static int usb_msd_initfn(USBDevice *dev) s-dev.speed = USB_SPEED_FULL; scsi_bus_new(s-bus, s-dev.qdev, 0, 1, usb_msd_command_complete); s-scsi_dev = scsi_bus_legacy_add_drive(s-bus, s-conf.dinfo, 0); +if (!s-scsi_dev) { +return -1; +} s-bus.qbus.allow_hotplug = 0; usb_msd_handle_reset(dev); -- 1.6.6.1
[Qemu-devel] [PATCH 09/12] savevm: Survive hot-unplug of snapshot device
savevm.c keeps a pointer to the snapshot block device. If you manage to get that device deleted, the pointer dangles, and the next snapshot operation will crash burn. Unplugging a guest device that uses it does the trick: $ MALLOC_PERTURB_=234 qemu-system-x86_64 [...] QEMU 0.12.50 monitor - type 'help' for more information (qemu) info snapshots No available block device supports snapshots (qemu) drive_add auto if=none,file=tmp.qcow2 OK (qemu) device_add usb-storage,id=foo,drive=none1 (qemu) info snapshots Snapshot devices: none1 Snapshot list (from none1): IDTAG VM SIZEDATE VM CLOCK (qemu) device_del foo (qemu) info snapshots Snapshot devices: Segmentation fault (core dumped) Move management of that pointer to block.c, and zap it when the device it points to goes away. Signed-off-by: Markus Armbruster arm...@redhat.com --- block.c | 25 + block.h |1 + savevm.c | 31 --- 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/block.c b/block.c index 5e0ffa0..34055e0 100644 --- a/block.c +++ b/block.c @@ -63,6 +63,9 @@ static QTAILQ_HEAD(, BlockDriverState) bdrv_states = static QLIST_HEAD(, BlockDriver) bdrv_drivers = QLIST_HEAD_INITIALIZER(bdrv_drivers); +/* The device to use for VM snapshots */ +static BlockDriverState *bs_snapshots; + /* If non-zero, use only whitelisted block drivers */ static int use_bdrv_whitelist; @@ -660,6 +663,9 @@ void bdrv_close_all(void) void bdrv_delete(BlockDriverState *bs) { assert(!bs-peer); +if (bs == bs_snapshots) { +bs_snapshots = NULL; +} /* remove from list, if necessary */ if (bs-device_name[0] != '\0') { @@ -1772,6 +1778,25 @@ int bdrv_can_snapshot(BlockDriverState *bs) return 1; } +BlockDriverState *bdrv_snapshots(void) +{ +BlockDriverState *bs; + +if (bs_snapshots) +return bs_snapshots; + +bs = NULL; +while ((bs = bdrv_next(bs))) { +if (bdrv_can_snapshot(bs)) { +goto ok; +} +} +return NULL; + ok: +bs_snapshots = bs; +return bs; +} + int bdrv_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) { diff --git a/block.h b/block.h index 88ac06e..012c2a1 100644 --- a/block.h +++ b/block.h @@ -193,6 +193,7 @@ const char *bdrv_get_encrypted_filename(BlockDriverState *bs); void bdrv_get_backing_filename(BlockDriverState *bs, char *filename, int filename_size); int bdrv_can_snapshot(BlockDriverState *bs); +BlockDriverState *bdrv_snapshots(void); int bdrv_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info); int bdrv_snapshot_goto(BlockDriverState *bs, diff --git a/savevm.c b/savevm.c index 20354a8..f1f450e 100644 --- a/savevm.c +++ b/savevm.c @@ -83,9 +83,6 @@ #include qemu_socket.h #include qemu-queue.h -/* point to the block driver where the snapshots are managed */ -static BlockDriverState *bs_snapshots; - #define SELF_ANNOUNCE_ROUNDS 5 #ifndef ETH_P_RARP @@ -1575,26 +1572,6 @@ out: return ret; } -static BlockDriverState *get_bs_snapshots(void) -{ -BlockDriverState *bs; - -if (bs_snapshots) -return bs_snapshots; -/* FIXME what if bs_snapshots gets hot-unplugged? */ - -bs = NULL; -while ((bs = bdrv_next(bs))) { -if (bdrv_can_snapshot(bs)) { -goto ok; -} -} -return NULL; - ok: -bs_snapshots = bs; -return bs; -} - static int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info, const char *name) { @@ -1674,7 +1651,7 @@ void do_savevm(Monitor *mon, const QDict *qdict) } } -bs = get_bs_snapshots(); +bs = bdrv_snapshots(); if (!bs) { monitor_printf(mon, No block device can accept snapshots\n); return; @@ -1769,7 +1746,7 @@ int load_vmstate(const char *name) } } -bs = get_bs_snapshots(); +bs = bdrv_snapshots(); if (!bs) { error_report(No block device supports snapshots); return -EINVAL; @@ -1833,7 +1810,7 @@ void do_delvm(Monitor *mon, const QDict *qdict) int ret; const char *name = qdict_get_str(qdict, name); -bs = get_bs_snapshots(); +bs = bdrv_snapshots(); if (!bs) { monitor_printf(mon, No block device supports snapshots\n); return; @@ -1863,7 +1840,7 @@ void do_info_snapshots(Monitor *mon) int nb_sns, i; char buf[256]; -bs = get_bs_snapshots(); +bs = bdrv_snapshots(); if (!bs) { monitor_printf(mon, No available block device supports snapshots\n); return; -- 1.6.6.1
[Qemu-devel] [PATCH 08/12] block: Catch attempt to attach multiple devices to a blockdev
For instance, -device scsi-disk,drive=foo -device scsi-disk,drive=foo happily creates two SCSI disks connected to the same block device. It's all downhill from there. Device usb-storage deliberately attaches twice to the same blockdev, which fails with the fix in place. Detach before the second attach there. Also catch attempt to delete while a guest device model is attached. Signed-off-by: Markus Armbruster arm...@redhat.com --- block.c | 22 ++ block.h |3 +++ block_int.h |2 ++ hw/fdc.c | 10 +- hw/ide/qdev.c|2 +- hw/pci-hotplug.c |5 - hw/qdev-properties.c | 21 - hw/qdev.h|3 ++- hw/s390-virtio.c |2 +- hw/scsi-bus.c|4 +++- hw/usb-msd.c | 11 +++ 11 files changed, 70 insertions(+), 15 deletions(-) diff --git a/block.c b/block.c index e71a771..5e0ffa0 100644 --- a/block.c +++ b/block.c @@ -659,6 +659,8 @@ void bdrv_close_all(void) void bdrv_delete(BlockDriverState *bs) { +assert(!bs-peer); + /* remove from list, if necessary */ if (bs-device_name[0] != '\0') { QTAILQ_REMOVE(bdrv_states, bs, list); @@ -672,6 +674,26 @@ void bdrv_delete(BlockDriverState *bs) qemu_free(bs); } +int bdrv_attach(BlockDriverState *bs, DeviceState *qdev) +{ +if (bs-peer) { +return -EBUSY; +} +bs-peer = qdev; +return 0; +} + +void bdrv_detach(BlockDriverState *bs, DeviceState *qdev) +{ +assert(bs-peer == qdev); +bs-peer = NULL; +} + +DeviceState *bdrv_get_attached(BlockDriverState *bs) +{ +return bs-peer; +} + /* * Run consistency checks on an image * diff --git a/block.h b/block.h index 6a157f4..88ac06e 100644 --- a/block.h +++ b/block.h @@ -71,6 +71,9 @@ int bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags); int bdrv_open(BlockDriverState *bs, const char *filename, int flags, BlockDriver *drv); void bdrv_close(BlockDriverState *bs); +int bdrv_attach(BlockDriverState *bs, DeviceState *qdev); +void bdrv_detach(BlockDriverState *bs, DeviceState *qdev); +DeviceState *bdrv_get_attached(BlockDriverState *bs); int bdrv_check(BlockDriverState *bs); int bdrv_read(BlockDriverState *bs, int64_t sector_num, uint8_t *buf, int nb_sectors); diff --git a/block_int.h b/block_int.h index e60aed4..a94b801 100644 --- a/block_int.h +++ b/block_int.h @@ -148,6 +148,8 @@ struct BlockDriverState { BlockDriver *drv; /* NULL means no media */ void *opaque; +DeviceState *peer; + char filename[1024]; char backing_file[1024]; /* if non zero, the image is a diff of this file image */ diff --git a/hw/fdc.c b/hw/fdc.c index 08712bc..1496cfa 100644 --- a/hw/fdc.c +++ b/hw/fdc.c @@ -1860,10 +1860,10 @@ FDCtrl *fdctrl_init_isa(DriveInfo **fds) dev = isa_create(isa-fdc); if (fds[0]) { -qdev_prop_set_drive(dev-qdev, driveA, fds[0]-bdrv); +qdev_prop_set_drive_nofail(dev-qdev, driveA, fds[0]-bdrv); } if (fds[1]) { -qdev_prop_set_drive(dev-qdev, driveB, fds[1]-bdrv); +qdev_prop_set_drive_nofail(dev-qdev, driveB, fds[1]-bdrv); } if (qdev_init(dev-qdev) 0) return NULL; @@ -1882,10 +1882,10 @@ FDCtrl *fdctrl_init_sysbus(qemu_irq irq, int dma_chann, fdctrl = sys-state; fdctrl-dma_chann = dma_chann; /* FIXME */ if (fds[0]) { -qdev_prop_set_drive(dev, driveA, fds[0]-bdrv); +qdev_prop_set_drive_nofail(dev, driveA, fds[0]-bdrv); } if (fds[1]) { -qdev_prop_set_drive(dev, driveB, fds[1]-bdrv); +qdev_prop_set_drive_nofail(dev, driveB, fds[1]-bdrv); } qdev_init_nofail(dev); sysbus_connect_irq(sys-busdev, 0, irq); @@ -1903,7 +1903,7 @@ FDCtrl *sun4m_fdctrl_init(qemu_irq irq, target_phys_addr_t io_base, dev = qdev_create(NULL, SUNW,fdtwo); if (fds[0]) { -qdev_prop_set_drive(dev, drive, fds[0]-bdrv); +qdev_prop_set_drive_nofail(dev, drive, fds[0]-bdrv); } qdev_init_nofail(dev); sys = DO_UPCAST(FDCtrlSysBus, busdev.qdev, dev); diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c index 3bb94c6..b4bc5ac 100644 --- a/hw/ide/qdev.c +++ b/hw/ide/qdev.c @@ -83,7 +83,7 @@ IDEDevice *ide_create_drive(IDEBus *bus, int unit, DriveInfo *drive) dev = qdev_create(bus-qbus, ide-drive); qdev_prop_set_uint32(dev, unit, unit); -qdev_prop_set_drive(dev, drive, drive-bdrv); +qdev_prop_set_drive_nofail(dev, drive, drive-bdrv); qdev_init_nofail(dev); return DO_UPCAST(IDEDevice, qdev, dev); } diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c index d743192..b47e01e 100644 --- a/hw/pci-hotplug.c +++ b/hw/pci-hotplug.c @@ -214,7 +214,10 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon, return NULL; } dev = pci_create(bus, devfn, virtio-blk-pci); -
[Qemu-devel] [PATCH 7/8] Rename tcg_cpu_exec and tcg_has_work
These functions are also used for kvm under !CONFIG_IOTHREAD, having 'tcg' in their name is just misleading. Signed-off-by: Jan Kiszka jan.kis...@siemens.com --- cpus.c | 10 +- cpus.h |2 +- vl.c |2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cpus.c b/cpus.c index 2ce839d..c024421 100644 --- a/cpus.c +++ b/cpus.c @@ -130,7 +130,7 @@ static int cpu_has_work(CPUState *env) return 0; } -static int tcg_has_work(void) +static int any_cpu_has_work(void) { CPUState *env; @@ -405,7 +405,7 @@ static void qemu_tcg_wait_io_event(void) { CPUState *env; -while (!tcg_has_work()) +while (!any_cpu_has_work()) qemu_cond_timedwait(tcg_halt_cond, qemu_global_mutex, 1000); qemu_mutex_unlock(qemu_global_mutex); @@ -506,7 +506,7 @@ static void *tcg_cpu_thread_fn(void *arg) qemu_cond_timedwait(qemu_system_cond, qemu_global_mutex, 100); while (1) { -tcg_cpu_exec(); +cpu_exec_all(); qemu_tcg_wait_io_event(); } @@ -767,7 +767,7 @@ static int qemu_cpu_exec(CPUState *env) return ret; } -bool tcg_cpu_exec(void) +bool cpu_exec_all(void) { int ret = 0; @@ -793,7 +793,7 @@ bool tcg_cpu_exec(void) } } exit_request = 0; -return tcg_has_work(); +return any_cpu_has_work(); } void set_numa_modes(void) diff --git a/cpus.h b/cpus.h index 774150a..af267ea 100644 --- a/cpus.h +++ b/cpus.h @@ -13,7 +13,7 @@ extern int smp_threads; extern int debug_requested; extern int vmstop_requested; void vm_state_notify(int running, int reason); -bool tcg_cpu_exec(void); +bool cpu_exec_all(void); void set_numa_modes(void); void set_cpu_log(const char *optarg); void list_cpus(FILE *f, int (*cpu_fprintf)(FILE *f, const char *fmt, ...), diff --git a/vl.c b/vl.c index 920717a..0938656 100644 --- a/vl.c +++ b/vl.c @@ -1325,7 +1325,7 @@ static void main_loop(void) int64_t ti; #endif #ifndef CONFIG_IOTHREAD -nonblocking = tcg_cpu_exec(); +nonblocking = cpu_exec_all(); #endif #ifdef CONFIG_PROFILER ti = profile_getclock(); -- 1.7.1
[Qemu-devel] Re: UIO interrupts being lost
On Thu, Jun 24, 2010 at 05:43:15PM -0600, Cam Macdonell wrote: Hi Michael, I'm trying to write a uio driver for my shared memory device for KVM and I'm running into a situation where several interrupts in quick succession are not all triggering the callback function in my kernel UIO driver, say 2 out of 5. My driver does not set the Interrupt Disable bit and if it helps, I'm using MSI-X interrupts. Even without the interrupt disable bit set, is there still a window where successive interrupts can be lost if they arrive too quickly? Thanks, Cam Yes, I think so: if an interrupt is delivered when ISR is running, it gets queued, but a second one gets lost. A queueing mechanism is necessary to avoid losing information, e.g. virtio implements exactly that. Why don't you reuse virtio for signalling? If I understand what Anthony said correctly, he objected to the specific implementation, not to the idea of reusing virtio spec and code. -- MST
[Qemu-devel] [PATCH 02/12] ide: Make it explicit that ide_create_drive() can't fail
All callers of ide_create_drive() ignore its value. Currently harmless, because it fails only when qdev_init() fails, which fails only when ide_drive_initfn() fails, which never fails. Brittle. Change it to die instead of silently ignoring failure. Signed-off-by: Markus Armbruster arm...@redhat.com --- hw/ide/qdev.c |3 +-- 1 files changed, 1 insertions(+), 2 deletions(-) diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c index 0f9f22e..127478b 100644 --- a/hw/ide/qdev.c +++ b/hw/ide/qdev.c @@ -84,8 +84,7 @@ IDEDevice *ide_create_drive(IDEBus *bus, int unit, DriveInfo *drive) dev = qdev_create(bus-qbus, ide-drive); qdev_prop_set_uint32(dev, unit, unit); qdev_prop_set_drive(dev, drive, drive); -if (qdev_init(dev) 0) -return NULL; +qdev_init_nofail(dev); return DO_UPCAST(IDEDevice, qdev, dev); } -- 1.6.6.1
[Qemu-devel] [PATCH 8/8] Rework debug exception processing for gdb use
Guest debugging is currently broken under CONFIG_IOTHREAD. The reason is inconsistent or even lacking signaling the debug events from the source VCPU to the main loop and the gdbstub. This patch addresses the issue by pushing this signaling into a CPUDebugExcpHandler: cpu_debug_handler is registered as first handler, thus will be executed last after potential breakpoint emulation handlers. It sets informs the gdbstub about the debug event source, requests a debug exit of the main loop and stops the current VCPU. This mechanism works both for TCG and KVM, with and without IO-thread. Signed-off-by: Jan Kiszka jan.kis...@siemens.com --- cpus.c| 26 -- kvm-all.c |2 -- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/cpus.c b/cpus.c index c024421..a607d9a 100644 --- a/cpus.c +++ b/cpus.c @@ -140,6 +140,13 @@ static int any_cpu_has_work(void) return 0; } +static void cpu_debug_handler(CPUState *env) +{ +gdb_set_stop_cpu(env); +debug_requested = EXCP_DEBUG; +vm_stop(EXCP_DEBUG); +} + #ifndef _WIN32 static int io_thread_fd = -1; @@ -235,6 +242,8 @@ static void qemu_event_increment(void) #ifndef CONFIG_IOTHREAD int qemu_init_main_loop(void) { +cpu_set_debug_excp_handler(cpu_debug_handler); + return qemu_event_init(); } @@ -325,6 +334,8 @@ int qemu_init_main_loop(void) { int ret; +cpu_set_debug_excp_handler(cpu_debug_handler); + ret = qemu_event_init(); if (ret) return ret; @@ -769,8 +780,6 @@ static int qemu_cpu_exec(CPUState *env) bool cpu_exec_all(void) { -int ret = 0; - if (next_cpu == NULL) next_cpu = first_cpu; for (; next_cpu != NULL !exit_request; next_cpu = next_cpu-next_cpu) { @@ -781,14 +790,11 @@ bool cpu_exec_all(void) if (qemu_alarm_pending()) break; -if (cpu_can_run(env)) -ret = qemu_cpu_exec(env); -else if (env-stop) -break; - -if (ret == EXCP_DEBUG) { -gdb_set_stop_cpu(env); -debug_requested = EXCP_DEBUG; +if (cpu_can_run(env)) { +if (qemu_cpu_exec(env) == EXCP_DEBUG) { +break; +} +} else if (env-stop) { break; } } diff --git a/kvm-all.c b/kvm-all.c index 5684e51..cb8ae9a 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -913,8 +913,6 @@ int kvm_cpu_exec(CPUState *env) DPRINTF(kvm_exit_debug\n); #ifdef KVM_CAP_SET_GUEST_DEBUG if (kvm_arch_debug(run-debug.arch)) { -gdb_set_stop_cpu(env); -vm_stop(EXCP_DEBUG); env-exception_index = EXCP_DEBUG; return 0; } -- 1.7.1
[Qemu-devel] [PATCH 4/7] provide opaque CPUState to files that are compiled once
This patch unpoisons CPUState and env in once-compiled files. To achieve this, it defines an opaque struct CPUState in cpu-common.h. This also requires tweaking the relationship between CPUState and CPUXYZState in target files. Unpoisoning env is needed because it is widely used as the name for CPUState arguments. To avoid having references to the global register variable creeping into target-independent files, the patch rationalizes inclusions at the head of target-*/exec.h. All exec.h files now include cpu.h explicitly and very early. Inclusions from machine-independent context will then error out in cpu-defs.h, even if env is not poisoned. Signed-off-by: Paolo Bonzini pbonz...@redhat.com --- cpu-common.h |3 +++ cpu-defs.h |1 + poison.h |3 --- target-alpha/cpu.h |4 +--- target-alpha/exec.h |6 ++ target-arm/cpu.h |6 +++--- target-arm/exec.h|5 ++--- target-cris/cpu.h|6 +++--- target-cris/exec.h |6 +++--- target-i386/cpu.h|6 +++--- target-i386/exec.h |7 ++- target-m68k/cpu.h|6 +++--- target-m68k/exec.h |6 +++--- target-microblaze/cpu.h |7 +++ target-microblaze/exec.h |6 +++--- target-mips/cpu.h|5 + target-mips/exec.h |6 ++ target-ppc/cpu.h |3 +-- target-ppc/exec.h|2 -- target-s390x/cpu.h |6 +++--- target-s390x/exec.h |7 +++ target-sh4/cpu.h |6 +++--- target-sh4/exec.h|5 ++--- target-sparc/cpu.h |6 +++--- target-sparc/exec.h |3 +++ 25 files changed, 56 insertions(+), 71 deletions(-) diff --git a/cpu-common.h b/cpu-common.h index b24cecc..f325e60 100644 --- a/cpu-common.h +++ b/cpu-common.h @@ -18,6 +18,9 @@ #include bswap.h #include qemu-queue.h +struct CPUState; +typedef struct CPUState CPUState; + #if !defined(CONFIG_USER_ONLY) /* address in the RAM (different from a physical address) */ diff --git a/cpu-defs.h b/cpu-defs.h index 8d4bf86..f56e85b 100644 --- a/cpu-defs.h +++ b/cpu-defs.h @@ -30,6 +30,7 @@ #include osdep.h #include qemu-queue.h #include targphys.h +#include cpu-common.h #ifndef TARGET_LONG_BITS #error TARGET_LONG_BITS must be defined before including this header diff --git a/poison.h b/poison.h index d7db7f4..e7814cb 100644 --- a/poison.h +++ b/poison.h @@ -33,9 +33,6 @@ #pragma GCC poison TARGET_PAGE_BITS #pragma GCC poison TARGET_PAGE_ALIGN -#pragma GCC poison CPUState -#pragma GCC poison env - #pragma GCC poison CPU_INTERRUPT_HARD #pragma GCC poison CPU_INTERRUPT_EXITTB #pragma GCC poison CPU_INTERRUPT_TIMER diff --git a/target-alpha/cpu.h b/target-alpha/cpu.h index 314d6ac..795b2bd 100644 --- a/target-alpha/cpu.h +++ b/target-alpha/cpu.h @@ -24,7 +24,7 @@ #define TARGET_LONG_BITS 64 -#define CPUState struct CPUAlphaState +#define CPUAlphaState CPUState #include cpu-defs.h @@ -317,8 +317,6 @@ enum { IPR_LAST, }; -typedef struct CPUAlphaState CPUAlphaState; - typedef struct pal_handler_t pal_handler_t; struct pal_handler_t { /* Reset */ diff --git a/target-alpha/exec.h b/target-alpha/exec.h index 66526e2..789305f 100644 --- a/target-alpha/exec.h +++ b/target-alpha/exec.h @@ -21,8 +21,9 @@ #define __ALPHA_EXEC_H__ #include config.h - #include dyngen-exec.h +#include cpu.h +#include exec-all.h #define TARGET_LONG_BITS 64 @@ -32,9 +33,6 @@ register struct CPUAlphaState *env asm(AREG0); #define SPARAM(n) ((int32_t)PARAM##n) #define FP_STATUS (env-fp_status) -#include cpu.h -#include exec-all.h - #if !defined(CONFIG_USER_ONLY) #include softmmu_exec.h #endif /* !defined(CONFIG_USER_ONLY) */ diff --git a/target-arm/cpu.h b/target-arm/cpu.h index f3d138d..b6cf887 100644 --- a/target-arm/cpu.h +++ b/target-arm/cpu.h @@ -23,7 +23,7 @@ #define ELF_MACHINEEM_ARM -#define CPUState struct CPUARMState +#define CPUARMState CPUState #include cpu-defs.h @@ -70,7 +70,7 @@ struct arm_boot_info; s2n+1 maps to the most significant half of dn */ -typedef struct CPUARMState { +struct CPUARMState { /* Regs for current mode. */ uint32_t regs[16]; /* Frequently accessed CPSR bits are stored separately for efficiently. @@ -206,7 +206,7 @@ typedef struct CPUARMState { } cp[15]; void *nvic; struct arm_boot_info *boot_info; -} CPUARMState; +}; CPUARMState *cpu_arm_init(const char *cpu_model); void arm_translate_init(void); diff --git a/target-arm/exec.h b/target-arm/exec.h index 0225c3f..4042eca 100644 --- a/target-arm/exec.h +++ b/target-arm/exec.h @@ -18,14 +18,13 @@ */ #include config.h #include dyngen-exec.h +#include cpu.h +#include exec-all.h register struct CPUARMState *env asm(AREG0); #define M0 env-iwmmxt.val -#include cpu.h -#include exec-all.h - static inline int cpu_has_work(CPUState *env) { return (env-interrupt_request diff --git
[Qemu-devel] [PATCH 00/12] More block-related fixes and cleanups
I'm working on cleanly separating block device host and guest parts. I'd like to route all this work through Kevin's block tree. This is still just preliminaries. There will be at least one more round of cleanup fixes before blockdev_add proper. I intend to start with a minimal QMP-only version, then add features. Markus Armbruster (12): scsi: scsi_bus_legacy_handle_cmdline() can fail, fix callers ide: Make it explicit that ide_create_drive() can't fail blockdev: Remove drive_get_serial() blockdev: New drive_of_blockdev() blockdev: Clean up automatic drive deletion qdev: Decouple qdev_prop_drive from DriveInfo blockdev: drive_get_by_id() is no longer used, remove block: Catch attempt to attach multiple devices to a blockdev savevm: Survive hot-unplug of snapshot device block: Fix virtual media change for if=none ide: Make PIIX and ISA IDE init functions return the qdev pc: Fix CMOS info for drives defined with -device block.c | 55 + block.h |5 +++ block_int.h |8 ++-- blockdev.c | 45 +++- blockdev.h |7 +++- hw/esp.c |3 +- hw/fdc.c | 32 +--- hw/ide.h | 13 --- hw/ide/core.c| 18 + hw/ide/internal.h|2 +- hw/ide/isa.c |8 ++-- hw/ide/piix.c|6 ++- hw/ide/qdev.c| 22 --- hw/lsi53c895a.c |2 +- hw/pc.c | 94 +++-- hw/pc.h |3 +- hw/pc_piix.c | 16 ++--- hw/pci-hotplug.c | 10 - hw/qdev-properties.c | 46 + hw/qdev.h|7 ++-- hw/s390-virtio.c |2 +- hw/scsi-bus.c| 19 ++ hw/scsi-disk.c | 21 ++- hw/scsi-generic.c|7 ++-- hw/scsi.h|4 +- hw/usb-msd.c | 29 --- hw/virtio-blk.c |3 +- hw/virtio-pci.c |4 +- savevm.c | 31 ++-- 29 files changed, 344 insertions(+), 178 deletions(-)
[Qemu-devel] [PATCH 04/12] blockdev: New drive_of_blockdev()
Signed-off-by: Markus Armbruster arm...@redhat.com --- blockdev.c | 12 blockdev.h |1 + 2 files changed, 13 insertions(+), 0 deletions(-) diff --git a/blockdev.c b/blockdev.c index e0495e5..8023cfd 100644 --- a/blockdev.c +++ b/blockdev.c @@ -78,6 +78,18 @@ int drive_get_max_bus(BlockInterfaceType type) return max_bus; } +DriveInfo *drive_of_blockdev(BlockDriverState *bs) +{ +DriveInfo *dinfo; + +QTAILQ_FOREACH(dinfo, drives, next) { +if (dinfo-bdrv == bs) { +return dinfo; +} +} +return NULL; +} + static void bdrv_format_print(void *opaque, const char *name) { fprintf(stderr, %s, name); diff --git a/blockdev.h b/blockdev.h index a936785..4bf75b1 100644 --- a/blockdev.h +++ b/blockdev.h @@ -40,6 +40,7 @@ extern DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit); extern DriveInfo *drive_get_by_id(const char *id); extern int drive_get_max_bus(BlockInterfaceType type); extern void drive_uninit(DriveInfo *dinfo); +extern DriveInfo *drive_of_blockdev(BlockDriverState *bs); extern QemuOpts *drive_add(const char *file, const char *fmt, ...); extern DriveInfo *drive_init(QemuOpts *arg, int default_to_scsi, -- 1.6.6.1
[Qemu-devel] [PATCH 7/7] poison TARGET_xxx for compile once object
prevents those ifdefs from creeping in again. Cc: Isaku Yamahata yamah...@valinux.co.jp Signed-off-by: Paolo Bonzini pbonz...@redhat.com --- cpu-common.h |4 qemu-common.h |5 + 2 files changed, 1 insertions(+), 8 deletions(-) diff --git a/cpu-common.h b/cpu-common.h index d905258..639c58d 100644 --- a/cpu-common.h +++ b/cpu-common.h @@ -11,10 +11,6 @@ #include targphys.h #endif -#ifndef NEED_CPU_H -#include poison.h -#endif - #include bswap.h #include qemu-queue.h diff --git a/qemu-common.h b/qemu-common.h index 8339cb1..423639b 100644 --- a/qemu-common.h +++ b/qemu-common.h @@ -86,15 +86,12 @@ static inline char *realpath(const char *path, char *resolved_path) /* FIXME: Remove NEED_CPU_H. */ #ifndef NEED_CPU_H - #include setjmp.h #include osdep.h #include bswap.h - +#include poison.h #else - #include cpu.h - #endif /* !defined(NEED_CPU_H) */ /* bottom halves */ -- 1.7.0.1
[Qemu-devel] [PATCH v3 0/2] Add virtio-blk support to persistent-storage rules
This patch series provides updates to udev to allow the creation symlinks for virtio-blk devices, specifically disk/by-id and disk/by-path. This is most useful for virtio-blk devices that do not yet have any filesystem for which a UUID can be extracted (disk/by-uuid). These patches (save the path_id fix) require an updated[1] qemu (on the host) and virtio-blk (in the guest)[2] to generate the by-id path; however if the guest or host qemu isn't capable then no action is taken. Changes since v2: - Added 'serial' sysfs attribute to virtio-blk code upstream [2] - Dropped VBID ioctl upstream [3] - Switched rules to extract serial attributes directly Changes since v1: - Switch ID_VIRTIO_SERIAL to ID_SERIAL - Switched IOCTL_CMD to use numeric value - Add ID_SERIAL_SHORT - Update persistent-storage rules to use ID_SERIAL for virtioblk_id 1. http://lists.gnu.org/archive/html/qemu-devel/2010-03/msg01869.html 2. https://lists.linux-foundation.org/pipermail/virtualization/2010-June/015326.html 3. https://lists.linux-foundation.org/pipermail/virtualization/2010-June/015325.html
[Qemu-devel] [PATCH 5/7] add qdev property type cpu
Signed-off-by: Paolo Bonzini pbonz...@redhat.com --- cpus.c | 16 cpus.h |2 ++ hw/qdev-properties.c | 44 hw/qdev.h|5 + 4 files changed, 67 insertions(+), 0 deletions(-) diff --git a/cpus.c b/cpus.c index fcd0f09..da6ec44 100644 --- a/cpus.c +++ b/cpus.c @@ -91,6 +91,22 @@ void cpu_synchronize_all_post_init(void) } } +CPUState *cpu_get_by_id(int id) +{ +CPUState *cpu; + +for (cpu = first_cpu; cpu; cpu = cpu-next_cpu) +if (cpu-cpu_index == id) +return cpu; + +return NULL; +} + +int cpu_get_id(CPUState *env) +{ +return env-cpu_index; +} + int cpu_is_stopped(CPUState *env) { return !vm_running || env-stopped; diff --git a/cpus.h b/cpus.h index 774150a..df3c193 100644 --- a/cpus.h +++ b/cpus.h @@ -6,6 +6,8 @@ int qemu_init_main_loop(void); void qemu_main_loop_start(void); void resume_all_vcpus(void); void pause_all_vcpus(void); +CPUState *cpu_get_by_id(int id); +int cpu_get_id(CPUState *env); /* vl.c */ extern int smp_cores; diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c index 5a8739d..2759c83 100644 --- a/hw/qdev-properties.c +++ b/hw/qdev-properties.c @@ -1,6 +1,7 @@ #include net.h #include qdev.h #include qerror.h +#include cpus.h void *qdev_get_prop_ptr(DeviceState *dev, Property *prop) { @@ -281,6 +282,44 @@ PropertyInfo qdev_prop_string = { .free = free_string, }; +/* --- cpu --- */ + +static int parse_cpu(DeviceState *dev, Property *prop, const char *str) +{ +CPUState **ptr = qdev_get_prop_ptr(dev, prop); +char *end; +int id; + +if (!*str) +return -ENOENT; + +id = strtol (str, end, 0); +if (*end) +return -ENOENT; + +*ptr = cpu_get_by_id(id); +if (*ptr == NULL) +return -ENOENT; +return 0; +} + +static int print_cpu(DeviceState *dev, Property *prop, char *dest, size_t len) +{ +CPUState **ptr = qdev_get_prop_ptr(dev, prop); +if (*ptr) +return snprintf(dest, len, CPU #%d, cpu_get_id(*ptr)); +else + return snprintf(dest, len, CPU #null); +} + +PropertyInfo qdev_prop_cpu = { +.name = cpu, +.type = PROP_TYPE_CPU, +.size = sizeof(DriveInfo*), +.parse = parse_cpu, +.print = print_cpu, +}; + /* --- drive --- */ static int parse_drive(DeviceState *dev, Property *prop, const char *str) @@ -657,6 +696,11 @@ void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value) qdev_prop_set(dev, name, value, PROP_TYPE_PTR); } +void qdev_prop_set_cpu(DeviceState *dev, const char *name, CPUState *value) +{ +qdev_prop_set(dev, name, value, PROP_TYPE_CPU); +} + void qdev_prop_set_defaults(DeviceState *dev, Property *props) { if (!props) diff --git a/hw/qdev.h b/hw/qdev.h index be5ad67..eec2f52 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -90,6 +90,7 @@ enum PropertyType { PROP_TYPE_VLAN, PROP_TYPE_PTR, PROP_TYPE_BIT, +PROP_TYPE_CPU, }; struct PropertyInfo { @@ -203,6 +204,7 @@ extern PropertyInfo qdev_prop_drive; extern PropertyInfo qdev_prop_netdev; extern PropertyInfo qdev_prop_vlan; extern PropertyInfo qdev_prop_pci_devfn; +extern PropertyInfo qdev_prop_cpu; #define DEFINE_PROP(_name, _state, _field, _prop, _type) { \ .name = (_name),\ @@ -257,6 +259,8 @@ extern PropertyInfo qdev_prop_pci_devfn; DEFINE_PROP(_n, _s, _f, qdev_prop_drive, DriveInfo*) #define DEFINE_PROP_MACADDR(_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr) +#define DEFINE_PROP_CPU(_n, _s, _f) \ +DEFINE_PROP(_n, _s, _f, qdev_prop_cpu, CPUState*) #define DEFINE_PROP_END_OF_LIST() \ {} @@ -276,6 +280,7 @@ void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *valu void qdev_prop_set_netdev(DeviceState *dev, const char *name, VLANClientState *value); void qdev_prop_set_vlan(DeviceState *dev, const char *name, VLANState *value); void qdev_prop_set_drive(DeviceState *dev, const char *name, DriveInfo *value); +void qdev_prop_set_cpu(DeviceState *dev, const char *name, CPUState *value); void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value); /* FIXME: Remove opaque pointer properties. */ void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value); -- 1.7.0.1
Re: [Qemu-devel] Guest OS hangs on usb_add
On Thu, 2010-06-24 at 05:45 +0100, TJ wrote: Here is small patch that fixed my problem. In looking at the USB spec, it seems pretty clear cut about the whole device/config/interface/endpoint descriptor hierarchy, so the usb_host_claim_interfaces can be optimized instead of parsing through each descriptor to skip through config descriptors using wTotalLength field. And again, some checks can be done for descriptor types and/or sizes. A device MAY provide extended descriptors in 2 ways mentioned in the spec, but ISTR finding at least one device in the wild with standard descriptors extended which were not so much used by the host but by application software. So not sure about your patch, a quirks blacklist based on idDevice/idProduct might be the better fix here. However the more serious problem is spinning on zero length descriptor when truncated descriptors are not valid and zero length (in fact 2) is totally unacceptable. Following patch checks for truncation. diff --git a/hw/usb.h b/hw/usb.h index 00d2802..efd4a65 100644 --- a/hw/usb.h +++ b/hw/usb.h @@ -117,6 +117,14 @@ #define USB_DT_INTERFACE 0x04 #define USB_DT_ENDPOINT0x05 +/* + * Descriptor sizes per descriptor type + */ +#define USB_DT_DEVICE_SIZE 18 +#define USB_DT_CONFIG_SIZE 9 +#define USB_DT_INTERFACE_SIZE 9 +#define USB_DT_ENDPOINT_SIZE 7 + #define USB_ENDPOINT_XFER_CONTROL 0 #define USB_ENDPOINT_XFER_ISOC 1 #define USB_ENDPOINT_XFER_BULK 2 diff --git a/usb-linux.c b/usb-linux.c index 88273ff..d259290 100644 --- a/usb-linux.c +++ b/usb-linux.c @@ -299,7 +299,7 @@ static int usb_host_claim_interfaces(USBHostDevice *dev, int configuration) i = 0; dev_descr_len = dev-descr[0]; -if (dev_descr_len dev-descr_len) { +if ( dev_descr_len USB_DT_DEVICE_SIZE || dev_descr_len dev-descr_len) { goto fail; } @@ -314,6 +314,8 @@ static int usb_host_claim_interfaces(USBHostDevice *dev, int configuration) continue; } config_descr_len = dev-descr[i]; +if ( config_descr_len USB_DT_CONFIG_SIZE ) +goto fail; printf(husb: config #%d need %d\n, dev-descr[i + 5], configuration);
Re: [Qemu-devel] VxWorks kernel for qemu emulating PowerPC?
On 06/07/2010 04:03 AM, hadi motamedi wrote: Dear All Can you please let me know if the qemu emulating PowerPC (I mean qemu-system-ppc.exe) can accept VxWork kernet for boot up? Thank you As is, the QEMU PowerPC platform will definitely not boot a VxWorks image. It is possible to boot a VxWorks image using the x86 system emulation. You would have to create a floppy image and pass that in for your vx-boot loader. Unless you are also putting your kernel image on the floppy, you would need to invoke qemu to use an intel e100 nic and make sure the VxWorks BSP is configured properly. Jason.
[Qemu-devel] [PATCH 6/7] replace void* uses with opaque CPUState*
Because we all love type safety, don't we? Signed-off-by: Paolo Bonzini pbonz...@redhat.com --- cpu-common.h |1 - cpus.c| 23 --- hw/apic.c |4 ++-- hw/pc.c |4 ++-- qemu-common.h |7 --- 5 files changed, 16 insertions(+), 23 deletions(-) diff --git a/cpu-common.h b/cpu-common.h index f325e60..d905258 100644 --- a/cpu-common.h +++ b/cpu-common.h @@ -19,7 +19,6 @@ #include qemu-queue.h struct CPUState; -typedef struct CPUState CPUState; #if !defined(CONFIG_USER_ONLY) diff --git a/cpus.c b/cpus.c index da6ec44..5b62e27 100644 --- a/cpus.c +++ b/cpus.c @@ -259,10 +259,8 @@ void qemu_main_loop_start(void) { } -void qemu_init_vcpu(void *_env) +void qemu_init_vcpu(CPUState *env) { -CPUState *env = _env; - env-nr_cores = smp_cores; env-nr_threads = smp_threads; if (kvm_enabled()) @@ -270,7 +268,7 @@ void qemu_init_vcpu(void *_env) return; } -int qemu_cpu_self(void *env) +int qemu_cpu_self(CPUState *env) { return 1; } @@ -288,7 +286,7 @@ void pause_all_vcpus(void) { } -void qemu_cpu_kick(void *env) +void qemu_cpu_kick(CPUState *env) { return; } @@ -524,16 +522,14 @@ static void *tcg_cpu_thread_fn(void *arg) return NULL; } -void qemu_cpu_kick(void *_env) +void qemu_cpu_kick(CPUState *env) { -CPUState *env = _env; qemu_cond_broadcast(env-halt_cond); qemu_thread_signal(env-thread, SIG_IPI); } -int qemu_cpu_self(void *_env) +int qemu_cpu_self(CPUState *env) { -CPUState *env = _env; QemuThread this; qemu_thread_self(this); @@ -666,9 +662,8 @@ void resume_all_vcpus(void) } } -static void tcg_init_vcpu(void *_env) +static void tcg_init_vcpu(CPUState *env) { -CPUState *env = _env; /* share a single thread for all cpus with TCG */ if (!tcg_cpu_thread) { env-thread = qemu_mallocz(sizeof(QemuThread)); @@ -695,10 +690,8 @@ static void kvm_start_vcpu(CPUState *env) qemu_cond_timedwait(qemu_cpu_cond, qemu_global_mutex, 100); } -void qemu_init_vcpu(void *_env) +void qemu_init_vcpu(CPUState *env) { -CPUState *env = _env; - env-nr_cores = smp_cores; env-nr_threads = smp_threads; if (kvm_enabled()) @@ -840,7 +833,7 @@ void set_cpu_log(const char *optarg) int64_t cpu_get_icount(void) { int64_t icount; -CPUState *env = cpu_single_env;; +CPUState *env = cpu_single_env; icount = qemu_icount; if (env) { diff --git a/hw/apic.c b/hw/apic.c index d686b51..85737c4 100644 --- a/hw/apic.c +++ b/hw/apic.c @@ -94,7 +94,7 @@ typedef struct APICState APICState; struct APICState { SysBusDevice busdev; -void *cpu_env; +CPUState *cpu_env; uint32_t apicbase; uint8_t id; uint8_t arb_id; @@ -1006,7 +1006,7 @@ static SysBusDeviceInfo apic_info = { .qdev.no_user = 1, .qdev.props = (Property[]) { DEFINE_PROP_UINT8(id, APICState, id, -1), -DEFINE_PROP_PTR(cpu_env, APICState, cpu_env), +DEFINE_PROP_CPU(cpu_env, APICState, cpu_env), DEFINE_PROP_END_OF_LIST(), } }; diff --git a/hw/pc.c b/hw/pc.c index 1848151..0497260 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -766,7 +766,7 @@ DeviceState *cpu_get_current_apic(void) } } -static DeviceState *apic_init(void *env, uint8_t apic_id) +static DeviceState *apic_init(CPUState *env, uint8_t apic_id) { DeviceState *dev; SysBusDevice *d; @@ -774,7 +774,7 @@ static DeviceState *apic_init(void *env, uint8_t apic_id) dev = qdev_create(NULL, apic); qdev_prop_set_uint8(dev, id, apic_id); -qdev_prop_set_ptr(dev, cpu_env, env); +qdev_prop_set_cpu(dev, cpu_env, env); qdev_init_nofail(dev); d = sysbus_from_qdev(dev); diff --git a/qemu-common.h b/qemu-common.h index ac839aa..8339cb1 100644 --- a/qemu-common.h +++ b/qemu-common.h @@ -17,6 +17,7 @@ typedef struct QEMUTimer QEMUTimer; typedef struct QEMUFile QEMUFile; typedef struct QEMUBH QEMUBH; typedef struct DeviceState DeviceState; +typedef struct CPUState CPUState; /* we put basic includes here to avoid repeating them in device drivers */ #include stdlib.h @@ -239,8 +240,8 @@ void qemu_service_io(void); void qemu_notify_event(void); /* Unblock cpu */ -void qemu_cpu_kick(void *env); -int qemu_cpu_self(void *env); +void qemu_cpu_kick(CPUState *env); +int qemu_cpu_self(CPUState *env); /* work queue */ struct qemu_work_item { @@ -253,7 +254,7 @@ struct qemu_work_item { #ifdef CONFIG_USER_ONLY #define qemu_init_vcpu(env) do { } while (0) #else -void qemu_init_vcpu(void *env); +void qemu_init_vcpu(CPUState *env); #endif typedef struct QEMUIOVector { -- 1.7.0.1
[Qemu-devel] [PATCH 3/7] include stdio.h freely, remove dyngen-exec.h hacks
Signed-off-by: Paolo Bonzini pbonz...@redhat.com --- disas.h |5 + dyngen-exec.h | 16 qemu-common.h |7 --- 3 files changed, 1 insertions(+), 27 deletions(-) diff --git a/disas.h b/disas.h index 6a9332d..1af0511 100644 --- a/disas.h +++ b/disas.h @@ -2,17 +2,14 @@ #define _QEMU_DISAS_H #include qemu-common.h +#include stdio.h #ifdef NEED_CPU_H /* Disassemble this for me please... (debugging). */ void disas(FILE *out, void *code, unsigned long size); void target_disas(FILE *out, target_ulong code, target_ulong size, int flags); - -/* The usual mess... FIXME: Remove this condition once dyngen-exec.h is gone */ -#ifndef __DYNGEN_EXEC_H__ void monitor_disas(Monitor *mon, CPUState *env, target_ulong pc, int nb_insn, int is_physical, int flags); -#endif /* Look up symbol for debugging purpose. Returns if unknown. */ const char *lookup_symbol(target_ulong orig_addr); diff --git a/dyngen-exec.h b/dyngen-exec.h index 5bfef3f..d65b618 100644 --- a/dyngen-exec.h +++ b/dyngen-exec.h @@ -19,13 +19,6 @@ #if !defined(__DYNGEN_EXEC_H__) #define __DYNGEN_EXEC_H__ -/* prevent Solaris from trying to typedef FILE in gcc's - include/floatingpoint.h which will conflict with the - definition down below */ -#ifdef __sun__ -#define _FILEDEFED -#endif - /* NOTE: standard headers should be used with special care at this point because host CPU registers are used as global variables. Some host headers do not allow that. */ @@ -40,15 +33,6 @@ /* XXX: This may be wrong for 64-bit ILP32 hosts. */ typedef void * host_reg_t; -#ifdef CONFIG_BSD -typedef struct __sFILE FILE; -#else -typedef struct FILE FILE; -#endif -extern int fprintf(FILE *, const char *, ...); -extern int fputs(const char *, FILE *); -extern int printf(const char *, ...); - #if defined(__i386__) #define AREG0 ebp #elif defined(__x86_64__) diff --git a/qemu-common.h b/qemu-common.h index 3fb2f0b..ac839aa 100644 --- a/qemu-common.h +++ b/qemu-common.h @@ -18,11 +18,6 @@ typedef struct QEMUFile QEMUFile; typedef struct QEMUBH QEMUBH; typedef struct DeviceState DeviceState; -/* Hack around the mess dyngen-exec.h causes: We need QEMU_NORETURN in files that - cannot include the following headers without conflicts. This condition has - to be removed once dyngen is gone. */ -#ifndef __DYNGEN_EXEC_H__ - /* we put basic includes here to avoid repeating them in device drivers */ #include stdlib.h #include stdio.h @@ -293,6 +288,4 @@ static inline uint8_t from_bcd(uint8_t val) #include module.h -#endif /* dyngen-exec.h hack */ - #endif -- 1.7.0.1
[Qemu-devel] [PATCH v2 01/16] Remove uses of ram.last_offset (aka last_ram_offset)
We currently need this either to allocate the next ram_addr_t for a new block, or for total memory to be migrated. Both of which we can calculate without need of this to keep us in a contiguous address space. Signed-off-by: Alex Williamson alex.william...@redhat.com --- arch_init.c | 23 --- cpu-all.h |1 - exec.c | 19 ++- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/arch_init.c b/arch_init.c index eb5b67c..109dcef 100644 --- a/arch_init.c +++ b/arch_init.c @@ -108,9 +108,10 @@ static int ram_save_block(QEMUFile *f) static ram_addr_t current_addr = 0; ram_addr_t saved_addr = current_addr; ram_addr_t addr = 0; +uint64_t total_ram = ram_bytes_total(); int bytes_sent = 0; -while (addr ram_list.last_offset) { +while (addr total_ram) { if (cpu_physical_memory_get_dirty(current_addr, MIGRATION_DIRTY_FLAG)) { uint8_t *p; @@ -133,7 +134,7 @@ static int ram_save_block(QEMUFile *f) break; } addr += TARGET_PAGE_SIZE; -current_addr = (saved_addr + addr) % ram_list.last_offset; +current_addr = (saved_addr + addr) % total_ram; } return bytes_sent; @@ -145,8 +146,9 @@ static ram_addr_t ram_save_remaining(void) { ram_addr_t addr; ram_addr_t count = 0; +uint64_t total_ram = ram_bytes_total(); -for (addr = 0; addr ram_list.last_offset; addr += TARGET_PAGE_SIZE) { +for (addr = 0; addr total_ram; addr += TARGET_PAGE_SIZE) { if (cpu_physical_memory_get_dirty(addr, MIGRATION_DIRTY_FLAG)) { count++; } @@ -167,7 +169,13 @@ uint64_t ram_bytes_transferred(void) uint64_t ram_bytes_total(void) { -return ram_list.last_offset; +RAMBlock *block; +uint64_t total = 0; + +QLIST_FOREACH(block, ram_list.blocks, next) +total += block-length; + +return total; } int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque) @@ -188,10 +196,11 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque) } if (stage == 1) { +uint64_t total_ram = ram_bytes_total(); bytes_transferred = 0; /* Make sure all dirty bits are set */ -for (addr = 0; addr ram_list.last_offset; addr += TARGET_PAGE_SIZE) { +for (addr = 0; addr total_ram; addr += TARGET_PAGE_SIZE) { if (!cpu_physical_memory_get_dirty(addr, MIGRATION_DIRTY_FLAG)) { cpu_physical_memory_set_dirty(addr); } @@ -200,7 +209,7 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque) /* Enable dirty memory tracking */ cpu_physical_memory_set_dirty_tracking(1); -qemu_put_be64(f, ram_list.last_offset | RAM_SAVE_FLAG_MEM_SIZE); +qemu_put_be64(f, total_ram | RAM_SAVE_FLAG_MEM_SIZE); } bytes_transferred_last = bytes_transferred; @@ -259,7 +268,7 @@ int ram_load(QEMUFile *f, void *opaque, int version_id) addr = TARGET_PAGE_MASK; if (flags RAM_SAVE_FLAG_MEM_SIZE) { -if (addr != ram_list.last_offset) { +if (addr != ram_bytes_total()) { return -EINVAL; } } diff --git a/cpu-all.h b/cpu-all.h index e31c2de..dbb2139 100644 --- a/cpu-all.h +++ b/cpu-all.h @@ -870,7 +870,6 @@ typedef struct RAMBlock { typedef struct RAMList { uint8_t *phys_dirty; -ram_addr_t last_offset; QLIST_HEAD(ram, RAMBlock) blocks; } RAMList; extern RAMList ram_list; diff --git a/exec.c b/exec.c index 7f64384..058b709 100644 --- a/exec.c +++ b/exec.c @@ -2765,6 +2765,17 @@ static void *file_ram_alloc(ram_addr_t memory, const char *path) } #endif +static ram_addr_t find_ram_offset(ram_addr_t size) +{ +RAMBlock *block; +ram_addr_t last = 0; + +QLIST_FOREACH(block, ram_list.blocks, next) +last = MAX(last, block-offset + block-length); + +return last; +} + ram_addr_t qemu_ram_alloc(ram_addr_t size) { RAMBlock *new_block; @@ -2798,18 +2809,16 @@ ram_addr_t qemu_ram_alloc(ram_addr_t size) madvise(new_block-host, size, MADV_MERGEABLE); #endif } -new_block-offset = ram_list.last_offset; +new_block-offset = find_ram_offset(size); new_block-length = size; QLIST_INSERT_HEAD(ram_list.blocks, new_block, next); ram_list.phys_dirty = qemu_realloc(ram_list.phys_dirty, -(ram_list.last_offset + size) TARGET_PAGE_BITS); -memset(ram_list.phys_dirty + (ram_list.last_offset TARGET_PAGE_BITS), +(new_block-offset + size) TARGET_PAGE_BITS); +memset(ram_list.phys_dirty + (new_block-offset TARGET_PAGE_BITS), 0xff, size TARGET_PAGE_BITS); -ram_list.last_offset += size; - if (kvm_enabled()) kvm_setup_guest_memory(new_block-host, size);
[Qemu-devel] [PATCH 2/7] include qemu-common.h when needed by the next patches
All of these files were already including qemu-common.h indirectly, e.g. via cpu-all.h, just not early enough. Signed-off-by: Paolo Bonzini pbonz...@redhat.com --- arm-semi.c|2 +- bsd-user/qemu.h |1 + cpu-exec.c|1 + darwin-user/qemu.h|1 + disas.c |1 + exec.c|2 +- linux-user/arm/nwfpe/fpa11.h |3 ++- linux-user/main.c |1 - linux-user/qemu.h |1 + m68k-semi.c |2 +- target-alpha/helper.c |1 + target-alpha/op_helper.c |1 + target-alpha/translate.c |2 +- target-arm/helper.c |2 +- target-arm/iwmmxt_helper.c|1 + target-arm/neon_helper.c |1 + target-arm/op_helper.c|1 + target-arm/translate.c|1 + target-cris/helper.c |1 + target-cris/mmu.c |1 + target-cris/op_helper.c |1 + target-cris/translate.c |2 +- target-i386/cpuid.c |1 + target-i386/helper.c |2 +- target-i386/op_helper.c |1 + target-i386/translate.c |1 + target-m68k/helper.c |2 +- target-m68k/op_helper.c |1 + target-m68k/translate.c |1 + target-microblaze/helper.c|1 + target-microblaze/mmu.c |1 + target-microblaze/op_helper.c |1 + target-microblaze/translate.c |2 +- target-mips/helper.c |1 + target-mips/op_helper.c |1 + target-mips/translate.c |2 +- target-ppc/helper.c |2 +- target-ppc/op_helper.c|1 + target-ppc/translate.c|2 +- target-s390x/helper.c |2 +- target-s390x/op_helper.c |1 + target-sh4/helper.c |1 + target-sh4/op_helper.c|2 ++ target-sh4/translate.c|2 +- target-sparc/helper.c |2 +- target-sparc/op_helper.c |1 + target-sparc/translate.c |1 + translate-all.c |1 + 48 files changed, 49 insertions(+), 17 deletions(-) diff --git a/arm-semi.c b/arm-semi.c index 0687b03..4c5ab65 100644 --- a/arm-semi.c +++ b/arm-semi.c @@ -26,7 +26,7 @@ #include stdio.h #include time.h -#include cpu.h +#include config.h #ifdef CONFIG_USER_ONLY #include qemu.h diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 554ff8b..6450571 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -4,6 +4,7 @@ #include signal.h #include string.h +#include qemu-common.h #include cpu.h #undef DEBUG_REMAP diff --git a/cpu-exec.c b/cpu-exec.c index 026980a..e4e0def 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -17,6 +17,7 @@ * License along with this library; if not, see http://www.gnu.org/licenses/. */ #include config.h +#include qemu-common.h #include exec.h #include disas.h #include tcg.h diff --git a/darwin-user/qemu.h b/darwin-user/qemu.h index 462bbda..a5d53ea 100644 --- a/darwin-user/qemu.h +++ b/darwin-user/qemu.h @@ -4,6 +4,7 @@ #include signal.h #include string.h +#include qemu-common.h #include cpu.h #include thunk.h diff --git a/disas.c b/disas.c index 79a98de..2905459 100644 --- a/disas.c +++ b/disas.c @@ -1,5 +1,6 @@ /* General disassemble this chunk code. Used for debugging. */ #include config.h +#include qemu-common.h #include dis-asm.h #include elf.h #include errno.h diff --git a/exec.c b/exec.c index 7f64384..8b61259 100644 --- a/exec.c +++ b/exec.c @@ -31,9 +31,9 @@ #include unistd.h #include inttypes.h +#include qemu-common.h #include cpu.h #include exec-all.h -#include qemu-common.h #include tcg.h #include hw/hw.h #include osdep.h diff --git a/linux-user/arm/nwfpe/fpa11.h b/linux-user/arm/nwfpe/fpa11.h index 07419e2..0e64897 100644 --- a/linux-user/arm/nwfpe/fpa11.h +++ b/linux-user/arm/nwfpe/fpa11.h @@ -25,7 +25,8 @@ #include stdio.h #include errno.h -#include cpu.h +#include qemu-common.h +#include cpu.h #define GET_FPA11() (qemufpa) diff --git a/linux-user/main.c b/linux-user/main.c index 403c8d3..e0511ee 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -27,7 +27,6 @@ #include sys/resource.h #include qemu.h -#include qemu-common.h #include cache-utils.h /* For tb_lock */ #include exec-all.h diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 1878d5a..e2bd7f8 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -4,6 +4,7 @@ #include signal.h #include string.h +#include qemu-common.h #include cpu.h #undef DEBUG_REMAP diff --git a/m68k-semi.c b/m68k-semi.c index d16bc67..7baa97b 100644 --- a/m68k-semi.c +++ b/m68k-semi.c @@ -27,7 +27,7 @@ #include sys/time.h #include time.h -#include cpu.h +#include config.h #if defined(CONFIG_USER_ONLY) #include qemu.h #define SEMIHOSTING_HEAP_SIZE (128 * 1024 * 1024) diff --git a/target-alpha/helper.c b/target-alpha/helper.c index b6d2160..043dbc1 100644 --- a/target-alpha/helper.c +++
[Qemu-devel] [Bug 586175] Re: Windows XP/2003 doesn't boot
I can reproduce with qemu-kvm 0.12.4 like the original reporter. I cannot reproduce with qemu-kvm upstream, qemu stable, or qemu upstream. So boot=on could be the culprit. Libvirt generated command line: LC_ALL=C PATH=/sbin:/usr/sbin:/bin:/usr/bin QEMU_AUDIO_DRV=none /usr/bin /qemu-system-x86_64 -S -M pc-0.12 -no-kvm -m 512 -smp 1,sockets=1,cores=1,threads=1 -name winxp_test -uuid 634dff56-8c5a-fdbb- b5fc-091bcf78e586 -nodefaults -chardev socket,id=monitor,path=/var/lib/libvirt/qemu/winxp_test.monitor,server,nowait -mon chardev=monitor,mode=readline -rtc base=localtime -boot c -drive file=/var/lib/libvirt/images/winxp_test.img,if=none,id=drive- ide0-0-0,boot=on,format=raw -device ide-drive,bus=ide.0,unit=0,drive =drive-ide0-0-0,id=ide0-0-0 -drive file=/mnt/data/media/win_xp_sp3_32.iso,if=none,media=cdrom,id=drive- ide0-1-0,readonly=on,format=raw -device ide-drive,bus=ide.1,unit=0,drive =drive-ide0-1-0,id=ide0-1-0 -device rtl8139,vlan=0,id=net0,mac=52:54:00:ac:e8:ca,bus=pci.0,addr=0x4 -net tap,fd=20,vlan=0,name=hostnet0 -chardev pty,id=serial0 -device isa- serial,chardev=serial0 -usb -device usb-tablet,id=input0 -vnc 127.0.0.1:1 -k en-us -vga std -device virtio-balloon- pci,id=balloon0,bus=pci.0,addr=0x3 Markus has a patch internally against an older qemu-kvm release that apparently fixes the issue, however the upstream code is different so it doesn't cleanly apply. Maybe this will give someone a hint for a proper upstream solution: hw/pc.c |4 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/hw/pc.c b/hw/pc.c index d142282..c60a79a 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -271,12 +271,16 @@ static void cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size, */ for (i = 0; i 4; i++) { char id[32]; +int cylinders, heads, secs; if (hd_table[i]) continue; snprintf(id, sizeof(id), drive-ide0-%d-%d, i / MAX_IDE_DEVS, i % MAX_IDE_DEVS); hd_table[i] = drive_get_by_id(id); +if (hd_table[i]) { +bdrv_guess_geometry(hd_table[i]-bdrv, cylinders, heads, secs); +} } /* various important CMOS locations needed by PC/Bochs bios */ -- Windows XP/2003 doesn't boot https://bugs.launchpad.net/bugs/586175 You received this bug notification because you are a member of qemu- devel-ml, which is subscribed to QEMU. Status in QEMU: Incomplete Status in Debian GNU/Linux: New Status in Fedora: Unknown Bug description: Hello everyone, my qemu doesn't boot any Windows XP/2003 installations if I try to boot the image. If I boot the install cd first, it's boot manager counts down and triggers the boot on it's own. That's kinda stupid. I'm using libvirt, but even by a simple qemu-kvm -drive file=image.img,media=disk,if=ide,boot=on it won't boot. Qemu hangs at the message Booting from Hard Disk... I'm using qemu-kvm-0.12.4 with SeaBIOS 0.5.1 on Gentoo (No-Multilib and AMD64). It's a server, that means I'm using VNC as the primary graphic output but i don't think it should be an issue.
[Qemu-devel] RE: qemu fail to parse command line with -pcidevice 00:19.0
Thanks, Mark. -Original Message- From: Markus Armbruster [mailto:arm...@redhat.com] Sent: 2010年6月25日 12:58 To: Hao, Xudong Cc: qemu-devel@nongnu.org; aligu...@us.ibm.com; k...@vger.kernel.org Subject: Re: qemu fail to parse command line with -pcidevice 00:19.0 Hao, Xudong xudong@intel.com writes: Work-around: -device pci-assign,host=00:19.1 OK, this new way can work when create guest with static assignment. But how to hot add a pci device to guest? the old hot add command pci_add pci_addr=auto host host=00:19.0 has the same parse error. Command line's -device becomes monitor's device_add: device_add pci-assign,host=00:19.1 BTW: if we use add -net none in qemu command, guest can not be created and nothing error printed. Do you have plan to fix this parse issue? Separate issue. Fix posted: Subject: [Qemu-devel] [PATCH] net: Fix VM start with '-net none' Date: Tue, 15 Jun 2010 13:30:39 +0530 Message-Id: 22a96312232a0458fc04268b79d17828c824df42.1276588830.git.amit.s...@redhat.com You could have found this yourself :)
[Qemu-devel] [PATCH 6/8] Drop redundant global cur_cpu variable
Signed-off-by: Jan Kiszka jan.kis...@siemens.com --- cpus.c |5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-) diff --git a/cpus.c b/cpus.c index aef92cd..2ce839d 100644 --- a/cpus.c +++ b/cpus.c @@ -39,7 +39,6 @@ #define SIG_IPI SIGUSR1 #endif -static CPUState *cur_cpu; static CPUState *next_cpu; /***/ @@ -775,10 +774,10 @@ bool tcg_cpu_exec(void) if (next_cpu == NULL) next_cpu = first_cpu; for (; next_cpu != NULL !exit_request; next_cpu = next_cpu-next_cpu) { -CPUState *env = cur_cpu = next_cpu; +CPUState *env = next_cpu; qemu_clock_enable(vm_clock, - (cur_cpu-singlestep_enabled SSTEP_NOTIMER) == 0); + (env-singlestep_enabled SSTEP_NOTIMER) == 0); if (qemu_alarm_pending()) break; -- 1.7.1
[Qemu-devel] [PATCH 0/8] Fix various IO-thread breakages
This series unbreaks -smp 1 and guest debugging in CONFIG_IOTHREAD mode. I still find the SMP scheduling in cpu_exec_all suboptimal, but at least it works now. Dependencies are: http://thread.gmane.org/gmane.comp.emulators.kvm.devel/52718 (kvm queue) http://thread.gmane.org/gmane.comp.emulators.qemu/75087 The full series can be found at git://git.kiszka.org/qemu.git queues/iothread Jan Kiszka (8): Introduce proper compiler barrier Fix cpu_unlink_tb race Init qemu_system_cond Fix cpu_exit for tcp_cpu_exec Fix qemu_wait_io_event processing in io-thread mode Drop redundant global cur_cpu variable Rename tcg_cpu_exec and tcg_has_work Rework debug exception processing for gdb use cpu-exec.c | 15 +++-- cpus.c | 58 +-- cpus.h |2 +- kvm-all.c |2 - qemu-barrier.h |3 ++ vl.c |2 +- 6 files changed, 48 insertions(+), 34 deletions(-)
[Qemu-devel] Re: qemu fail to parse command line with -pcidevice 00:19.0
Hidetoshi Seto seto.hideto...@jp.fujitsu.com writes: (2010/06/24 15:08), Markus Armbruster wrote: Note to qemu-devel: this issue is qemu-kvm only. Hao, Xudong xudong@intel.com writes: When assign one PCI device, qemu fail to parse the command line: qemu-system_x86 -smp 2 -m 1024 -hda /path/to/img -pcidevice host=00:19.0 Error: qemu-system-x86_64: Parameter 'id' expects an identifier Identifiers consist of letters, digits, '-', '.', '_', starting with a letter. pcidevice argument parse error; please check the help text for usage Could not add assigned device host=00:19.0 https://bugs.launchpad.net/qemu/+bug/597932 This issue caused by qemu-kvm commit b560a9ab9be06afcbb78b3791ab836dad208a239. The bug is in add_assigned_device(): r = get_param_value(id, sizeof(id), id, arg); if (!r) r = get_param_value(id, sizeof(id), name, arg); if (!r) r = get_param_value(id, sizeof(id), host, arg); We end up with invalid ID 00:19.0. ... Are there any strong reason why we cannot use ':' in the identifier? Paul Brook (cc'ed) objected.
Re: [Qemu-devel] [Bug 595117] Re: qemu-nbd slow and missing writeback cache option
On Thu, Jun 24, 2010 at 01:16:03AM +0100, Jamie Lokier wrote: Serge Hallyn wrote: The default of qemu-img (of using O_SYNC) is not very sensible because anyway, the client (the kernel) uses caches (write-back), (and qemu-nbd -d doesn't flush those by the way). So if for instance qemu-nbd is killed, regardless of whether qemu-nbd uses O_SYNC, O_DIRECT or not, the data in the image will not be consistent anyway, unless syncs are done by the client (like fsync on the nbd device or sync mount option), and with qemu-nbd's O_SYNC mode, those syncs will be extremely slow. Do the client syncs cause the nbd server to fsync or fdatasync the file? NBD does not have support for cache flushes. Any nbd server needs to use O_DSYNC-like semantics. I really wish qemu's options didn't give the false impression nocache does less caching than writethrough. O_DIRECT does caching in the disk controller/hardware, while O_SYNC hopefully does not, nowadays. The current cache= options are misleading in many ways. I'll post a patchset soon to distangle the notion of using direct vs buffered I/O from exposing and implementing a guest visible volatile write cache. Exposing these improvements on the command linkes will have to wait for the new -blockdev option.
[Qemu-devel] [PATCH 2/8] Fix cpu_unlink_tb race
If a signal hit after the env-exit_request check but before cpu_exec updated env-current_tb, cpu_unlink_tb called from the signal hander will not unlink the current TB. This may leave us stuck in a guest loop if no further unlink is invoked. Fix this by reordering current_tb update and exit_request check, additionally enforcing the correct order via a compiler barrier. Signed-off-by: Jan Kiszka jan.kis...@siemens.com --- cpu-exec.c |7 --- 1 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cpu-exec.c b/cpu-exec.c index 525b3b4..5f88f3f 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -600,8 +600,9 @@ int cpu_exec(CPUState *env1) TB, but before it is linked into a potentially infinite loop and becomes env-current_tb. Avoid starting execution if there is a pending interrupt. */ -if (!unlikely (env-exit_request)) { -env-current_tb = tb; +env-current_tb = tb; +barrier(); +if (likely(!env-exit_request)) { tc_ptr = tb-tc_ptr; /* execute the generated code */ #if defined(__sparc__) !defined(CONFIG_SOLARIS) @@ -610,7 +611,6 @@ int cpu_exec(CPUState *env1) #define env cpu_single_env #endif next_tb = tcg_qemu_tb_exec(tc_ptr); -env-current_tb = NULL; if ((next_tb 3) == 2) { /* Instruction counter expired. */ int insns_left; @@ -639,6 +639,7 @@ int cpu_exec(CPUState *env1) } } } +env-current_tb = NULL; /* reset soft MMU for next block (it can currently only be set by a memory fault) */ } /* for(;;) */ -- 1.7.1
[Qemu-devel] [PATCH 2/2] Add virtio-blk by-id rules based on 'serial' attribute
Using virtio-blk serial attributes add rules to extract drive serial numbers and generate by-id links for the block device and partitions. With these rules added, we now see the following symlinks in disk/by-id % ls -al /dev/disk/by-id | grep vdb lrwxrwxrwx. 1 root root 9 Jun 1 22:09 virtio-QM1 - ../../vda lrwxrwxrwx. 1 root root 10 Jun 1 22:09 virtio-QM1-part1 - ../../vda1 Signed-off-by: Ryan Harper ry...@us.ibm.com --- rules/rules.d/60-persistent-storage.rules |4 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/rules/rules.d/60-persistent-storage.rules b/rules/rules.d/60-persistent-storage.rules index 1f46041..6449e07 100644 --- a/rules/rules.d/60-persistent-storage.rules +++ b/rules/rules.d/60-persistent-storage.rules @@ -18,6 +18,10 @@ TEST==whole_disk, GOTO=persistent_storage_end # for partitions import parent information ENV{DEVTYPE}==partition, IMPORT{parent}=ID_* +# virtio-blk +KERNEL==vd*[!0-9], ATTRS{serial}==?*, ENV{ID_SERIAL}=$attr{serial}, SYMLINK+=disk/by-id/virtio-$env{ID_SERIAL} +KERNEL==vd*[0-9], ATTRS{serial}==?*, ENV{ID_SERIAL}=$attr{serial}, SYMLINK+=disk/by-id/virtio-$env{ID_SERIAL}-part%n + # USB devices use their own serial number KERNEL==sd*[!0-9]|sr*, ENV{ID_SERIAL}!=?*, SUBSYSTEMS==usb, IMPORT{program}=usb_id --export %p # ATA devices with their own ata kernel subsystem -- 1.6.3.3
[Qemu-devel] Re: [PATCH 03/12] blockdev: Remove drive_get_serial()
On Fri, Jun 25, 2010 at 06:53:23PM +0200, Markus Armbruster wrote: Unused since commit 6ced55a5. Signed-off-by: Markus Armbruster arm...@redhat.com Looks good, Reviewed-by: Christoph Hellwig h...@lst.de
[Qemu-devel] [PATCH 1/7] rtc: Remove TARGET_I386 from qemu-config.c, enables driftfix
From: Amit Shah amit.s...@redhat.com qemu-config.c doesn't contain any target-specific code, and the TARGET_I386 conditional code didn't get compiled as a result. Removing this enables the driftfix parameter for rtc. Signed-off-by: Amit Shah amit.s...@redhat.com Signed-off-by: Paolo Bonzini pbonz...@redhat.com --- qemu-config.c |2 -- 1 files changed, 0 insertions(+), 2 deletions(-) diff --git a/qemu-config.c b/qemu-config.c index 95abe61..730ffd9 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -247,11 +247,9 @@ QemuOptsList qemu_rtc_opts = { },{ .name = clock, .type = QEMU_OPT_STRING, -#ifdef TARGET_I386 },{ .name = driftfix, .type = QEMU_OPT_STRING, -#endif }, { /* end if list */ } }, -- 1.7.0.1
[Qemu-devel] [PATCH 0/7] poison TARGET_xxx for compile once object and header file cleanups
This is a different way to achieve the same objective as Isamu's patch. Basically, his patch becomes the (much simpler) patch 7 of this series, and everything else is something I had had lying around for a while. :) Patch 1 is simply Amit's patch, included here for convenience as it's not been applied yet. Patches 2 and 3 remove some dyngen-exec.h hacks at the price of requiring qemu-common.h included in more places. I don't see this as a big price; all of these files were already including qemu-common.h indirectly, e.g. via cpu-all.h, just not early enough. Patches 4 provides a CPUState type, albeit an opaque one, to files that are not compiled per-target. The advantage of this are apparent in patches 5 and 6: opaque pointers that are actually CPUState pointers are now type-safe, and it is even possible to define a cpu property type for the occasional device that has to be connected to a particular CPU (the PC APICs in particular). Finally, patch 7 redoes Isamu's patch just by moving five lines of code into qemu-common.h. Amit Shah (1): rtc: Remove TARGET_I386 from qemu-config.c, enables driftfix Paolo Bonzini (6): include qemu-common.h when needed by the next patches include stdio.h freely, remove dyngen-exec.h hacks provide opaque CPUState to files that are compiled once add qdev property type cpu replace void* uses with opaque CPUState* poison TARGET_xxx for compile once object arm-semi.c|2 +- bsd-user/qemu.h |1 + cpu-common.h |6 +--- cpu-defs.h|1 + cpu-exec.c|1 + cpus.c| 39 ++-- cpus.h|2 + darwin-user/qemu.h|1 + disas.c |1 + disas.h |5 +--- dyngen-exec.h | 16 -- exec.c|2 +- hw/apic.c |4 +- hw/pc.c |4 +- hw/qdev-properties.c | 44 + hw/qdev.h |5 linux-user/arm/nwfpe/fpa11.h |3 +- linux-user/main.c |1 - linux-user/qemu.h |1 + m68k-semi.c |2 +- poison.h |3 -- qemu-common.h | 19 - qemu-config.c |2 - target-alpha/cpu.h|4 +-- target-alpha/exec.h |6 +--- target-alpha/helper.c |1 + target-alpha/op_helper.c |1 + target-alpha/translate.c |2 +- target-arm/cpu.h |6 ++-- target-arm/exec.h |5 +-- target-arm/helper.c |2 +- target-arm/iwmmxt_helper.c|1 + target-arm/neon_helper.c |1 + target-arm/op_helper.c|1 + target-arm/translate.c|1 + target-cris/cpu.h |6 ++-- target-cris/exec.h|6 ++-- target-cris/helper.c |1 + target-cris/mmu.c |1 + target-cris/op_helper.c |1 + target-cris/translate.c |2 +- target-i386/cpu.h |6 ++-- target-i386/cpuid.c |1 + target-i386/exec.h|7 + target-i386/helper.c |2 +- target-i386/op_helper.c |1 + target-i386/translate.c |1 + target-m68k/cpu.h |6 ++-- target-m68k/exec.h|6 ++-- target-m68k/helper.c |2 +- target-m68k/op_helper.c |1 + target-m68k/translate.c |1 + target-microblaze/cpu.h |7 ++--- target-microblaze/exec.h |6 ++-- target-microblaze/helper.c|1 + target-microblaze/mmu.c |1 + target-microblaze/op_helper.c |1 + target-microblaze/translate.c |2 +- target-mips/cpu.h |5 +--- target-mips/exec.h|6 +--- target-mips/helper.c |1 + target-mips/op_helper.c |1 + target-mips/translate.c |2 +- target-ppc/cpu.h |3 +- target-ppc/exec.h |2 - target-ppc/helper.c |2 +- target-ppc/op_helper.c|1 + target-ppc/translate.c|2 +- target-s390x/cpu.h|6 ++-- target-s390x/exec.h |7 ++--- target-s390x/helper.c |2 +- target-s390x/op_helper.c |1 + target-sh4/cpu.h |6 ++-- target-sh4/exec.h |5 +-- target-sh4/helper.c |1 + target-sh4/op_helper.c|2 + target-sh4/translate.c|2 +- target-sparc/cpu.h|6 ++-- target-sparc/exec.h |3 ++ target-sparc/helper.c |2 +- target-sparc/op_helper.c |1 + target-sparc/translate.c |1 + translate-all.c |1 + 83 files changed, 189 insertions(+), 147 deletions(-)
[Qemu-devel] Re: qemu fail to parse command line with -pcidevice 00:19.0
(2010/06/24 15:08), Markus Armbruster wrote: Note to qemu-devel: this issue is qemu-kvm only. Hao, Xudong xudong@intel.com writes: When assign one PCI device, qemu fail to parse the command line: qemu-system_x86 -smp 2 -m 1024 -hda /path/to/img -pcidevice host=00:19.0 Error: qemu-system-x86_64: Parameter 'id' expects an identifier Identifiers consist of letters, digits, '-', '.', '_', starting with a letter. pcidevice argument parse error; please check the help text for usage Could not add assigned device host=00:19.0 https://bugs.launchpad.net/qemu/+bug/597932 This issue caused by qemu-kvm commit b560a9ab9be06afcbb78b3791ab836dad208a239. The bug is in add_assigned_device(): r = get_param_value(id, sizeof(id), id, arg); if (!r) r = get_param_value(id, sizeof(id), name, arg); if (!r) r = get_param_value(id, sizeof(id), host, arg); We end up with invalid ID 00:19.0. ... Are there any strong reason why we cannot use ':' in the identifier? Thanks, H.Seto
[Qemu-devel] Re: [PATCH 02/12] ide: Make it explicit that ide_create_drive() can't fail
On Fri, Jun 25, 2010 at 06:53:22PM +0200, Markus Armbruster wrote: All callers of ide_create_drive() ignore its value. Currently harmless, because it fails only when qdev_init() fails, which fails only when ide_drive_initfn() fails, which never fails. Brittle. Change it to die instead of silently ignoring failure. Signed-off-by: Markus Armbruster arm...@redhat.com Looks good, Reviewed-by: Christoph Hellwig h...@lst.de
[Qemu-devel] Re: [PATCHv3] virtio-net: correct packet length math
On Fri, Jun 25, 2010 at 12:47:03PM +0530, Amit Shah wrote: On (Thu) Jun 24 2010 [18:54:07], Michael S. Tsirkin wrote: We were requesting too much when checking buffer length: size already includes host header length. Further, we should not exit if we get a packet that is too long, since this might not be under control of the guest. Just drop the packet. control of the host? Well, host too I guess. What I was trying to say, it might not be the fault of the guest that it got a packet that is too long. @@ -579,19 +581,32 @@ static ssize_t virtio_net_receive(VLANClientState *nc, const uint8_t *buf, size_ mhdr = (struct virtio_net_hdr_mrg_rxbuf *)sg[0].iov_base; offset += receive_header(n, sg, elem.in_num, - buf + offset, size - offset, hdr_len); -total += hdr_len; + buf + offset, size - offset, guest_hdr_len); +total += guest_hdr_len; } /* copy in packet. ugh */ len = iov_from_buf(sg, elem.in_num, buf + offset, size - offset); total += len; +offset += len; +/* If buffers can't be merged, at this point we + * must have consumed the complete packet. + * Otherwise, drop it. */ +if (!n-mergeable_rx_bufs offset size) { +#if 0 +fprintf(stderr, virtio-net truncated non-mergeable packet: + +i %zd mergeable %d offset %zd, size %zd, +guest hdr len %zd, host hdr len %zd\n, +i, n-mergeable_rx_bufs, +offset, size, guest_hdr_len, host_hdr_len); +#endif +return size; +} Before returning, won't you have to finish off the virtqueue operations -- fill, flush, kick, etc.? Amit No, this would consume a buffer. We just want to drop the packet without side-effects. But we do need to decrement the inuse counter. I'll respin the patch. -- MST
[Qemu-devel] Re: [PATCH v2] lsi53c895a: fix Phase Mismatch Jump
On 06/14/2010 07:11 PM, Paolo Bonzini wrote: lsi_bad_phase has a bug in the choice of pmjad1/pmjad2. This does not matter with Linux guests because it uses just one routine for both, but it breaks Windows 64-bit guests. This is the text from the spec: [The PMJCTL] bit controls which decision mechanism is used when jumping on phase mismatch. When this bit is cleared the LSI53C895A will use Phase Mismatch Jump Address 1 (PMJAD1) when the WSR bit is cleared and Phase Mismatch Jump Address 2 (PMJAD2) when the WSR bit is set. When this bit is set the LSI53C895A will use jump address one (PMJAD1) on data out (data out, command, message out) transfers and jump address two (PMJAD2) on data in (data in, status, message in) transfers. Which means: CCNTL0.PMJCTL 0 SCNTL2.WSR = 0 PMJAD1 0 SCNTL2.WSR = 1 PMJAD2 1out PMJAD1 1in PMJAD2 In qemu, what you get instead is: CCNTL0.PMJCTL 0out PMJAD1 0in PMJAD2 1out PMJAD1 1in PMJAD1 Considering that qemu always has SCNTL2.WSR cleared, the two marked cases (corresponding to phase mismatch on input) are always jumping to the wrong PMJAD register. The patch implements the correct semantics. Signed-off-by: Paolo Bonzinipbonz...@redhat.com --- Looks correct. But why not assigning s-pmjad[12] directly? Would improve readability IMO. No particular reason, hence fine by me. hw/lsi53c895a.c |6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/lsi53c895a.c b/hw/lsi53c895a.c index f5a91ba..9a37fed 100644 --- a/hw/lsi53c895a.c +++ b/hw/lsi53c895a.c @@ -490,10 +490,10 @@ static void lsi_bad_phase(LSIState *s, int out, int new_phase) { /* Trigger a phase mismatch. */ if (s-ccntl0 LSI_CCNTL0_ENPMJ) { -if ((s-ccntl0 LSI_CCNTL0_PMJCTL) || out) { -s-dsp = s-pmjad1; +if ((s-ccntl0 LSI_CCNTL0_PMJCTL)) { +s-dsp = out ? s-pmjad1 : s-pmjad2; } else { -s-dsp = s-pmjad2; +s-dsp = (s-scntl2 LSI_SCNTL2_WSR ? s-pmjad2 : s-pmjad1); } DPRINTF(Data phase mismatch jump to %08x\n, s-dsp); } else { PING Paolo
[Qemu-devel] Re: [PATCHv3] virtio-net: correct packet length math
On (Thu) Jun 24 2010 [18:54:07], Michael S. Tsirkin wrote: We were requesting too much when checking buffer length: size already includes host header length. Further, we should not exit if we get a packet that is too long, since this might not be under control of the guest. Just drop the packet. control of the host? @@ -579,19 +581,32 @@ static ssize_t virtio_net_receive(VLANClientState *nc, const uint8_t *buf, size_ mhdr = (struct virtio_net_hdr_mrg_rxbuf *)sg[0].iov_base; offset += receive_header(n, sg, elem.in_num, - buf + offset, size - offset, hdr_len); -total += hdr_len; + buf + offset, size - offset, guest_hdr_len); +total += guest_hdr_len; } /* copy in packet. ugh */ len = iov_from_buf(sg, elem.in_num, buf + offset, size - offset); total += len; +offset += len; +/* If buffers can't be merged, at this point we + * must have consumed the complete packet. + * Otherwise, drop it. */ +if (!n-mergeable_rx_bufs offset size) { +#if 0 +fprintf(stderr, virtio-net truncated non-mergeable packet: + +i %zd mergeable %d offset %zd, size %zd, +guest hdr len %zd, host hdr len %zd\n, +i, n-mergeable_rx_bufs, +offset, size, guest_hdr_len, host_hdr_len); +#endif +return size; +} Before returning, won't you have to finish off the virtqueue operations -- fill, flush, kick, etc.? Amit
[Qemu-devel] Re: [PATCH v2] Makefile: poison TARGET_xxx for compile once.
On 06/25/2010 05:02 AM, Isaku Yamahata wrote: poison TARGET_xxx for compile once object to prevent those ifdef from creeping in again. didn't poison env which is used as function argument as void *env. Although it would be possible to sort it out, for now just not poison it. qemu-malloc.c didn't compile, so I make it non compile-once for now. It is linked via block-obj-y in Makefile.obj and common-obj-y in Makefile.objs through block-obj-y. So qemu-malloc.o is explicitly added to rules. I'm still skeptical, not about the goal but about the means. I'm going to push again for my patch to make CPUState opaque for non-per-target files. I haven't heard good reasons against it. The main objection was that hw files would have no reason for accessing CPUState. But this makes no sense if CPUState is opaque, and on the other hand we have now a proliferation of void* arguments and fields (e.g. in qemu_cpu_kick). Which I am taught is a very bad thing. If that patch was accepted, we'd just need this to implement your proposal: diff --git a/cpu-common.h b/cpu-common.h index f325e60..78f8b12 100644 --- a/cpu-common.h +++ b/cpu-common.h @@ -11,10 +11,6 @@ #include targphys.h #endif -#ifndef NEED_CPU_H -#include poison.h -#endif - #include bswap.h #include qemu-queue.h diff --git a/qemu-common.h b/qemu-common.h index 3fb2f0b..3f92d40 100644 --- a/qemu-common.h +++ b/qemu-common.h @@ -90,15 +90,12 @@ static inline char *realpath(const char *path, char *resolved_path) /* FIXME: Remove NEED_CPU_H. */ #ifndef NEED_CPU_H - #include setjmp.h #include osdep.h #include bswap.h - +#include poison.h #else - #include cpu.h - #endif /* !defined(NEED_CPU_H) */ /* bottom halves */ I'll put this together in a complete patch series and post. Paolo
[Qemu-devel] Re: [PATCH 01/12] scsi: scsi_bus_legacy_handle_cmdline() can fail, fix callers
On Fri, Jun 25, 2010 at 06:53:21PM +0200, Markus Armbruster wrote: None of its callers checks for failure. scsi_hot_add() can crash because of that: (qemu) drive_add 4 if=scsi,format=host_device,file=/dev/sg1 scsi-generic: scsi generic interface too old Segmentation fault (core dumped) Fix all callers, not just scsi_hot_add(). Looks good, Reviewed-by: Christoph Hellwig h...@lst.de
[Qemu-devel] Qemu support for integration
Hi, we are a company which makes a toolset for hardware/software co-design and parallel programming http://www.proximusda.com We would like to try to link Qemu with our solution in order to support virtual prototyping. For that we are looking for (potentially paid) support by the Qemu developer team for integration, hookup of external IP to emulate embedded systems and potentially a license to utilize the technology in conjunction with ours. Please get back to us with a proposal on how we could jointly accomplish this. Best Regards, Enno Wein CTO, ProximusDA GmbH
[Qemu-devel] [PATCH 5/8] Fix qemu_wait_io_event processing in io-thread mode
When checking for I/O events in the tcg CPU loop, make sure that we call qemu_wait_io_event_common for all CPUs, not only the current one. Otherwise pause_all_vcpus may lock up or run_on_cpu requests may starve. Rename qemu_wait_io_event to qemu_tcg_wait_io_event at this chance and purge its argument list as it has no use for it. Signed-off-by: Jan Kiszka jan.kis...@siemens.com --- cpus.c | 13 + 1 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cpus.c b/cpus.c index ff5e804..aef92cd 100644 --- a/cpus.c +++ b/cpus.c @@ -402,10 +402,12 @@ static void qemu_wait_io_event_common(CPUState *env) flush_queued_work(env); } -static void qemu_wait_io_event(CPUState *env) +static void qemu_tcg_wait_io_event(void) { +CPUState *env; + while (!tcg_has_work()) -qemu_cond_timedwait(env-halt_cond, qemu_global_mutex, 1000); +qemu_cond_timedwait(tcg_halt_cond, qemu_global_mutex, 1000); qemu_mutex_unlock(qemu_global_mutex); @@ -418,7 +420,10 @@ static void qemu_wait_io_event(CPUState *env) qemu_mutex_unlock(qemu_fair_mutex); qemu_mutex_lock(qemu_global_mutex); -qemu_wait_io_event_common(env); + +for (env = first_cpu; env != NULL; env = env-next_cpu) { +qemu_wait_io_event_common(env); +} } static void qemu_kvm_eat_signal(CPUState *env, int timeout) @@ -503,7 +508,7 @@ static void *tcg_cpu_thread_fn(void *arg) while (1) { tcg_cpu_exec(); -qemu_wait_io_event(cur_cpu); +qemu_tcg_wait_io_event(); } return NULL; -- 1.7.1
[Qemu-devel] Re: [PATCH 04/12] blockdev: New drive_of_blockdev()
+DriveInfo *drive_of_blockdev(BlockDriverState *bs) I'd call this find_drive_by_blockdev.
Re: [Qemu-devel] [PATCH 0/7] poison TARGET_xxx for compile once object and header file cleanups
On 06/25/2010 05:52 AM, Paolo Bonzini wrote: This is a different way to achieve the same objective as Isamu's patch. Basically, his patch becomes the (much simpler) patch 7 of this series, and everything else is something I had had lying around for a while. :) Patch 1 is simply Amit's patch, included here for convenience as it's not been applied yet. Patches 2 and 3 remove some dyngen-exec.h hacks at the price of requiring qemu-common.h included in more places. I don't see this as a big price; all of these files were already including qemu-common.h indirectly, e.g. via cpu-all.h, just not early enough. Patches 4 provides a CPUState type, albeit an opaque one, to files that are not compiled per-target. The advantage of this are apparent in patches 5 and 6: opaque pointers that are actually CPUState pointers are now type-safe, and it is even possible to define a cpu property type for the occasional device that has to be connected to a particular CPU (the PC APICs in particular). Finally, patch 7 redoes Isamu's patch just by moving five lines of code into qemu-common.h. Amit Shah (1): rtc: Remove TARGET_I386 from qemu-config.c, enables driftfix Paolo Bonzini (6): include qemu-common.h when needed by the next patches include stdio.h freely, remove dyngen-exec.h hacks provide opaque CPUState to files that are compiled once add qdev property type cpu replace void* uses with opaque CPUState* poison TARGET_xxx for compile once object Reviewed-by: Richard Henderson r...@twiddle.net I like this cleanup. Although I would personally prefer an additional patch that removes the define silliness that patch 4 works around. In other words I think there's no point in having CPUARMState et al; we should use CPUState universally. r~
Re: [Qemu-devel] [Bug 586175] Re: Windows XP/2003 doesn't boot
Cole Robinson crobi...@redhat.com writes: I can reproduce with qemu-kvm 0.12.4 like the original reporter. I cannot reproduce with qemu-kvm upstream, qemu stable, or qemu upstream. So boot=on could be the culprit. Libvirt generated command line: LC_ALL=C PATH=/sbin:/usr/sbin:/bin:/usr/bin QEMU_AUDIO_DRV=none /usr/bin /qemu-system-x86_64 -S -M pc-0.12 -no-kvm -m 512 -smp 1,sockets=1,cores=1,threads=1 -name winxp_test -uuid 634dff56-8c5a-fdbb- b5fc-091bcf78e586 -nodefaults -chardev socket,id=monitor,path=/var/lib/libvirt/qemu/winxp_test.monitor,server,nowait -mon chardev=monitor,mode=readline -rtc base=localtime -boot c -drive file=/var/lib/libvirt/images/winxp_test.img,if=none,id=drive- ide0-0-0,boot=on,format=raw -device ide-drive,bus=ide.0,unit=0,drive =drive-ide0-0-0,id=ide0-0-0 -drive file=/mnt/data/media/win_xp_sp3_32.iso,if=none,media=cdrom,id=drive- ide0-1-0,readonly=on,format=raw -device ide-drive,bus=ide.1,unit=0,drive =drive-ide0-1-0,id=ide0-1-0 -device rtl8139,vlan=0,id=net0,mac=52:54:00:ac:e8:ca,bus=pci.0,addr=0x4 -net tap,fd=20,vlan=0,name=hostnet0 -chardev pty,id=serial0 -device isa- serial,chardev=serial0 -usb -device usb-tablet,id=input0 -vnc 127.0.0.1:1 -k en-us -vga std -device virtio-balloon- pci,id=balloon0,bus=pci.0,addr=0x3 Markus has a patch internally against an older qemu-kvm release that apparently fixes the issue, however the upstream code is different so it doesn't cleanly apply. Maybe this will give someone a hint for a proper upstream solution: [snipp...] That's only the second part of a revolting emergency hack. Anyway, I posted a fix for current master yesterday: Subject: [PATCH 12/12] pc: Fix CMOS info for drives defined with -device Date: Fri, 25 Jun 2010 18:53:32 +0200 Message-Id: 1277484812-22012-13-git-send-email-arm...@redhat.com If it still needs backporting it to stable when I've dug myself out of my current pit, I'll give it a try. Wouldn't mind if somebody else beat me to it.
[Qemu-devel] Re: [PATCH 04/12] blockdev: New drive_of_blockdev()
Christoph Hellwig h...@lst.de writes: +DriveInfo *drive_of_blockdev(BlockDriverState *bs) I'd call this find_drive_by_blockdev. For what it's worth, all externally visible functions dealing with drives start with drive_.