Re: [Qemu-devel] [PATCH] drive-mirror:fix memory leak
On Wed, 01/22 15:56, Zhang Min wrote: In the function mirror_iteration() - qemu_iovec_init(), it allocates memory for op-qiov.iov, when the write request calls back, but in the function mirror_iteration_done(), it only frees the op, not free the op-qiov.iov, so this causes memory leak. Signed-off-by: Zhang Min rudy.zhang...@huawei.com --- block/mirror.c |1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index 2932bab..9840840 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -96,6 +96,7 @@ static void mirror_iteration_done(MirrorOp *op, int ret) bitmap_set(s-cow_bitmap, chunk_num, nb_chunks); } +g_free(op-qiov.iov); g_slice_free(MirrorOp, op); qemu_coroutine_enter(s-common.co, NULL); } -- 1.7.3.1.msysgit.0 Reviewed-by: Fam Zheng f...@redhat.com In the future please keep maintainers Cc'ed, as noted in the wiki page, so your patch can get better chance of being noticed. http://wiki.qemu.org/Contribute/SubmitAPatch Send patches to the mailing list and CC the relevant maintainer -- look in the MAINTAINERS file to find out who that is. Also try using scripts/getmaintainer.pl from the repository for learning the most common committers for the files you touched.
Re: [Qemu-devel] [Qemu-ppc] KVM and variable-endianness guest CPUs
Hi Alex, On Wed, Jan 22, 2014 at 12:11 PM, Alexander Graf ag...@suse.de wrote: Am 22.01.2014 um 07:31 schrieb Anup Patel a...@brainfault.org: On Wed, Jan 22, 2014 at 11:09 AM, Victor Kamensky victor.kamen...@linaro.org wrote: Hi Guys, Christoffer and I had a bit heated chat :) on this subject last night. Christoffer, really appreciate your time! We did not really reach agreement during the chat and Christoffer asked me to follow up on this thread. Here it goes. Sorry, it is very long email. I don't believe we can assign any endianity to mmio.data[] byte array. I believe mmio.data[] and mmio.len acts just memcpy and that is all. As memcpy does not imply any endianity of underlying data mmio.data[] should not either. Here is my definition: mmio.data[] is array of bytes that contains memory bytes in such form, for read case, that if those bytes are placed in guest memory and guest executes the same read access instruction with address to this memory, result would be the same as real h/w device memory access. Rest of KVM host and hypervisor part of code should really take care of mmio.data[] memory so it will be delivered to vcpu registers and restored by hypervisor part in such way that guest CPU register value is the same as it would be for real non-emulated h/w read access (that is emulation part). The same goes for write access, if guest writes into memory and those bytes are just copied to emulated h/w register it would have the same effect as real mapped h/w register write. In shorter form, i.e for len=4 access: endianity of integer at mmio.data[0] address should match endianity of emulated h/w device behind phys_addr address, regardless what is endianity of emulator, KVM host, hypervisor, and guest Examples that illustrate my definition -- 1) LE guest (E bit is off in ARM speak) reads integer (4 bytes) from mapped h/w LE device register - mmio.data[3] contains MSB, mmio.data[0] contains LSB. 2) BE guest (E bit is on in ARM speak) reads integer from mapped h/w LE device register - mmio.data[3] contains MSB, mmio.data[0] contains LSB. Note that if mmio.data[0] memory would be placed in guest address space and instruction restarted with new address, then it would meet BE guest expectations - the guest knows that it reads LE h/w so it will byteswap register before processing it further. This is BE guest ARM case (regardless of what KVM host endianity is). 3) BE guest reads integer from mapped h/w BE device register - mmio.data[0] contains MSB, mmio.data[3] contains LSB. Note that if mmio.data[0] memory would be placed in guest address space and instruction restarted with new address, then it would meet BE guest expectation - the guest knows that it reads BE h/w so it will proceed further without any other work. I guess, it is BE ppc case. Arguments in favor of memcpy semantics of mmio.data[] -- x) What are possible values of 'len'? Previous discussions imply that is always powers of 2. Why is that? Maybe there will be CPU that would need to do 5 bytes mmio access, or 6 bytes. How do you assign endianity to such case? 'len' 5 or 6, or any works fine with memcpy semantics. I admit it is hypothetical case, but IMHO it tests how clean ABI definition is. x) Byte array does not have endianity because it does not have any structure. If one would want to imply structure why mmio is not defined in such way so structure reflected in mmio definition? Something like: /* KVM_EXIT_MMIO */ struct { __u64 phys_addr; union { __u8 byte; __u16 hword; __u32 word; __u64 dword; } data; __u32 len; __u8 is_write; } mmio; where len is really serves as union discriminator and only allowed len values are 1, 2, 4, 8. In this case, I agree, endianity of integer types should be defined. I believe, use of byte array strongly implies that original intent was to have semantics of byte stream copy, just like memcpy does. x) Note there is nothing wrong with user kernel ABI to use just bytes stream as parameter. There is already precedents like 'read' and 'write' system calls :). x) Consider case when KVM works with emulated memory mapped h/w devices where some devices operate in LE mode and others operate in BE mode. It is defined by semantics of real h/w device which is it, and should be emulated by emulator and KVM given all other context. As far as mmio.data[] array concerned, if the same integer value is read from these devices registers, mmio.data[] memory should contain integer in opposite endianity for these two cases, i.e MSB is data[0] in
Re: [Qemu-devel] [PATCH] sheepdog: fix 'qemu-img map'
Am 21.01.2014 um 18:14 hat Liu Yuan geschrieben: It was muted in the previous commit 4bc74be9. Let's revive it since nothing prevents us to do it. With this patch, following command will work as other formats: $ qemu-img map sheepdog:image Cc: qemu-devel@nongnu.org Cc: Kevin Wolf kw...@redhat.com Cc: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Liu Yuan namei.u...@gmail.com Thanks, applied to the block branch. Kevin
Re: [Qemu-devel] [PATCH] qapi: Add backing and file to BlockStats
Am 22.01.2014 um 04:30 hat Fam Zheng geschrieben: Currently there is no way to query BlockStats of the backing chain. This adds backing and file fields into BlockStats to make it possible. The old optional field parent, which has the information for file, is kept there for backward compatibility, as an alias for file. However field name file is more consistent with file option name in the block device configuration interface. Signed-off-by: Fam Zheng f...@redhat.com I don't think it's a good idea to duplicate a field just because we like the new name better. Eric? Kevin
Re: [Qemu-devel] [PATCH] drive-mirror:fix memory leak
Am 22.01.2014 um 08:56 hat Zhang Min geschrieben: In the function mirror_iteration() - qemu_iovec_init(), it allocates memory for op-qiov.iov, when the write request calls back, but in the function mirror_iteration_done(), it only frees the op, not free the op-qiov.iov, so this causes memory leak. Signed-off-by: Zhang Min rudy.zhang...@huawei.com --- block/mirror.c |1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index 2932bab..9840840 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -96,6 +96,7 @@ static void mirror_iteration_done(MirrorOp *op, int ret) bitmap_set(s-cow_bitmap, chunk_num, nb_chunks); } +g_free(op-qiov.iov); g_slice_free(MirrorOp, op); qemu_coroutine_enter(s-common.co, NULL); } Please use qemu_iovec_destroy() instead. (I would also move it to right after the for loop that frees the individual buffers in qiov.) Kevin
Re: [Qemu-devel] [PATCH v3 1/4] qcow2: remove n_start and n_end of qcow2_alloc_cluster_offset()
Am 22.01.2014 um 07:57 hat Hu Tao geschrieben: n_start can be actually calculated from offset. The number of sectors to be allocated(n_end - n_start) can be passed in in num. By removing n_start and n_end, we can save two parameters. The side effect is there is a bug in qcow2.c:preallocate() that passes incorrect n_start to qcow2_alloc_cluster_offset() is fixed. The bug can be triggerred by a larger cluster size than the default value(65536), for example: ./qemu-img create -f qcow2 \ -o 'cluster_size=131072,preallocation=metadata' file.img 4G Reviewed-by: Max Reitz mre...@redhat.com Signed-off-by: Hu Tao hu...@cn.fujitsu.com --- block/qcow2-cluster.c | 14 ++ block/qcow2.c | 6 +++--- block/qcow2.h | 2 +- trace-events | 2 +- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 8534084..c57f39d 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -1182,7 +1182,7 @@ fail: * Return 0 on success and -errno in error cases */ int qcow2_alloc_cluster_offset(BlockDriverState *bs, uint64_t offset, -int n_start, int n_end, int *num, uint64_t *host_offset, QCowL2Meta **m) +int *num, uint64_t *host_offset, QCowL2Meta **m) { BDRVQcowState *s = bs-opaque; uint64_t start, remaining; @@ -1190,15 +1190,13 @@ int qcow2_alloc_cluster_offset(BlockDriverState *bs, uint64_t offset, uint64_t cur_bytes; int ret; -trace_qcow2_alloc_clusters_offset(qemu_coroutine_self(), offset, - n_start, n_end); +trace_qcow2_alloc_clusters_offset(qemu_coroutine_self(), offset, *num); -assert(n_start * BDRV_SECTOR_SIZE == offset_into_cluster(s, offset)); -offset = start_of_cluster(s, offset); +assert((offset ~BDRV_SECTOR_MASK) == 0); again: -start = offset + (n_start BDRV_SECTOR_BITS); -remaining = (n_end - n_start) BDRV_SECTOR_BITS; +start = offset; +remaining = *num BDRV_SECTOR_BITS; cluster_offset = 0; *host_offset = 0; cur_bytes = 0; @@ -1284,7 +1282,7 @@ again: } } -*num = (n_end - n_start) - (remaining BDRV_SECTOR_BITS); +*num -= remaining BDRV_SECTOR_BITS; assert(*num 0); assert(*host_offset != 0); diff --git a/block/qcow2.c b/block/qcow2.c index 8ec9db1..a0596ec 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1016,14 +1016,14 @@ static coroutine_fn int qcow2_co_writev(BlockDriverState *bs, trace_qcow2_writev_start_part(qemu_coroutine_self()); index_in_cluster = sector_num (s-cluster_sectors - 1); -n_end = index_in_cluster + remaining_sectors; +cur_nr_sectors = remaining_sectors; if (s-crypt_method n_end QCOW_MAX_CRYPT_CLUSTERS * s-cluster_sectors) { n_end = QCOW_MAX_CRYPT_CLUSTERS * s-cluster_sectors; } You don't want to change n_end here any more, this should affect cur_nr_sectors now. n_end becomes completely unused then and can be removed. I wonder why the compiler doesn't complain here, this is uninitialised use and a write-only variable at the same time. Kevin
Re: [Qemu-devel] [PATCH v3 4/4] qemu-iotests: add test for qcow2 preallocation with different cluster sizes
Am 22.01.2014 um 07:57 hat Hu Tao geschrieben: Signed-off-by: Hu Tao hu...@cn.fujitsu.com --- Note: the current largest test case number is 074, but Kevin suggested picking 079 as there are in-flight patches taken lower numbers. tests/qemu-iotests/079 | 69 ++ tests/qemu-iotests/079.out | 32 + tests/qemu-iotests/group | 1 + 3 files changed, 102 insertions(+) create mode 100755 tests/qemu-iotests/079 create mode 100644 tests/qemu-iotests/079.out diff --git a/tests/qemu-iotests/079 b/tests/qemu-iotests/079 new file mode 100755 index 000..5df045b --- /dev/null +++ b/tests/qemu-iotests/079 @@ -0,0 +1,69 @@ +#!/bin/bash +# +# Test qcow2 preallocation with different cluster_sizes +# +# Copyright (C) 2014 Fujitsu. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see http://www.gnu.org/licenses/. +# + +# creator +owner=hu...@cn.fujitsu.com + +seq=`basename $0` +echo QA output created by $seq + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap _cleanup; exit \$status 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +_supported_fmt qcow2 +_supported_proto file +_supported_os Linux + +function filter_test_dir() +{ +sed -e s#$IMGPROTO:$TEST_DIR#TEST_DIR#g \ +-e s#$TEST_DIR#TEST_DIR#g +} Can't you use _filter_testdir() from common.filter? If you need the additional $IMGPROTO: filter that is missing there, I think we can add it to the common.filter function. Kevin
Re: [Qemu-devel] [PATCH 3/3] add support for hyperv time parameter
Il 21/01/2014 22:12, Vadim Rozenfeld ha scritto: If you are planning some level of backwards compatibility with RHEL6, it may make sense to use separate subsections. I believe we have to make it backward compatible. In RHEL6 we added support for relaxed timers only, but upstream doesn't have such bits. Technically, hypercall page, vapic and iTSC pages will be introduced in RHEL7 and as you said, they will probably go to a different, new section, but for upstream the entire section is absolutely new. Ok, then upstream we have choice. Using 2 subsections is not wrong, and it makes sense since it's covered by different kernel capabilities. Paolo
Re: [Qemu-devel] [PATCH 4/5] sclp-s390: Define new SCLP codes and structures
On 16/12/13 21:51, Matthew Rosato wrote: Define new SCLP codes and structures that will be needed for s390 memory hotplug. Signed-off-by: Matthew Rosato mjros...@linux.vnet.ibm.com Can you rebase this patch against git://github.com/borntraeger/qemu.git s390-next and send it separately? This patch is pretty much non-controversial and I would apply it to s390-next. You could then base your v2 on that. Christian --- hw/s390x/sclp.c |2 +- include/hw/s390x/sclp.h | 46 ++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/hw/s390x/sclp.c b/hw/s390x/sclp.c index 86d6ae0..cb53d7e 100644 --- a/hw/s390x/sclp.c +++ b/hw/s390x/sclp.c @@ -45,7 +45,7 @@ static void sclp_execute(SCCB *sccb, uint64_t code) { S390SCLPDevice *sdev = get_event_facility(); -switch (code) { +switch (code SCLP_NO_CMD_PARM) { case SCLP_CMDW_READ_SCP_INFO: case SCLP_CMDW_READ_SCP_INFO_FORCED: read_SCP_info(sccb); diff --git a/include/hw/s390x/sclp.h b/include/hw/s390x/sclp.h index 231a38a..e80cb23 100644 --- a/include/hw/s390x/sclp.h +++ b/include/hw/s390x/sclp.h @@ -20,18 +20,31 @@ /* SCLP command codes */ #define SCLP_CMDW_READ_SCP_INFO 0x00020001 #define SCLP_CMDW_READ_SCP_INFO_FORCED 0x00120001 +#define SCLP_READ_STORAGE_ELEMENT_INFO 0x00040001 +#define SCLP_ATTACH_STORAGE_ELEMENT 0x00080001 +#define SCLP_ASSIGN_STORAGE 0x000D0001 +#define SCLP_UNASSIGN_STORAGE 0x000C0001 #define SCLP_CMD_READ_EVENT_DATA0x00770005 #define SCLP_CMD_WRITE_EVENT_DATA 0x00760005 #define SCLP_CMD_READ_EVENT_DATA0x00770005 #define SCLP_CMD_WRITE_EVENT_DATA 0x00760005 #define SCLP_CMD_WRITE_EVENT_MASK 0x00780005 +/* SCLP Memory hotplug codes */ +#define SCLP_NO_CMD_PARM0x00ff +#define SCLP_FC_ASSIGN_ATTACH_READ_STOR 0xE000ULL +#define SCLP_STARTING_SUBINCREMENT_ID 0x10001 +#define SCLP_INCREMENT_UNIT 0x1 +#define MAX_AVAIL_SLOTS 32 + /* SCLP response codes */ #define SCLP_RC_NORMAL_READ_COMPLETION 0x0010 #define SCLP_RC_NORMAL_COMPLETION 0x0020 +#define SCLP_RC_SCCB_BOUNDARY_VIOLATION 0x0100 #define SCLP_RC_INVALID_SCLP_COMMAND0x01f0 #define SCLP_RC_CONTAINED_EQUIPMENT_CHECK 0x0340 #define SCLP_RC_INSUFFICIENT_SCCB_LENGTH0x0300 +#define SCLP_RC_STANDBY_READ_COMPLETION 0x0410 #define SCLP_RC_INVALID_FUNCTION0x40f0 #define SCLP_RC_NO_EVENT_BUFFERS_STORED 0x60f0 #define SCLP_RC_INVALID_SELECTION_MASK 0x70f0 @@ -75,8 +88,41 @@ typedef struct ReadInfo { SCCBHeader h; uint16_t rnmax; uint8_t rnsize; +uint8_t _reserved1[16 - 11]; /* 11-15 */ +uint16_t entries_cpu; /* 16-17 */ +uint16_t offset_cpu;/* 18-19 */ +uint8_t _reserved2[24 - 20]; /* 20-23 */ +uint8_t loadparm[8]; /* 24-31 */ +uint8_t _reserved3[48 - 32]; /* 32-47 */ +uint64_t facilities;/* 48-55 */ +uint8_t _reserved0[100 - 56]; +uint32_t rnsize2; +uint64_t rnmax2; } QEMU_PACKED ReadInfo; +typedef struct ReadStorageElementInfo { +SCCBHeader h; +uint16_t max_id; +uint16_t assigned; +uint16_t standby; +uint8_t _reserved0[16 - 14]; /* 14-15 */ +uint32_t entries[0]; +} QEMU_PACKED ReadStorageElementInfo; + +typedef struct AttachStorageElement { +SCCBHeader h; +uint8_t _reserved0[10 - 8]; /* 8-9 */ +uint16_t assigned; +uint8_t _reserved1[16 - 12]; /* 12-15 */ +uint32_t entries[0]; +} QEMU_PACKED AttachStorageElement; + +typedef struct AssignStorage { +SCCBHeader h; +uint16_t rn; +} QEMU_PACKED AssignStorage; + + typedef struct SCCB { SCCBHeader h; char data[SCCB_DATA_LEN];
Re: [Qemu-devel] [PATCH v4 0/8] spapr: bootindex support
Il 22/01/2014 05:19, Alexey Kardashevskiy ha scritto: On 12/11/2013 09:22 PM, Alexey Kardashevskiy wrote: With the great help from Paolo, I am presenting yet another try of bootindex support on sPAPR, this time with some QOM fixes. Details are in the commit messages. Please, comment. Thanks. Alexey Kardashevskiy (5): boot: extend get_boot_devices_list() to ignore suffixes spapr-llan: add to boot device list spapr-vio: fix firmware names qdev: introduce FWPathProvider interface spapr: define interface to fix device pathname Hervé Poussineau (1): qom: detect bad reentrance during object_class_foreach Paolo Bonzini (2): qom: do not register interface types in the type table vl: allow customizing the class of /machine hw/core/Makefile.objs | 1 + hw/core/fw-path-provider.c| 34 ++ hw/core/qdev.c| 18 +- hw/net/spapr_llan.c | 3 ++ hw/nvram/fw_cfg.c | 2 +- hw/ppc/spapr.c| 80 ++- hw/ppc/spapr_vio.c| 2 ++ include/hw/boards.h | 1 + include/hw/fw-path-provider.h | 31 + include/sysemu/sysemu.h | 2 +- qom/object.c | 17 +++-- tests/Makefile| 1 + vl.c | 11 -- 13 files changed, 193 insertions(+), 10 deletions(-) create mode 100644 hw/core/fw-path-provider.c create mode 100644 include/hw/fw-path-provider.h Some bits from this went upstream but none of them is mine. What am I missing here? Thanks. No idea, perhaps it's because the same patches were present in multiple series? Alex, are you picking up what's left? Paolo
Re: [Qemu-devel] [Xen-devel] Project idea: make QEMU more flexible
Il 21/01/2014 19:27, Wei Liu ha scritto: Googling disable tcg would have provided an answer, but the patches were old enough to be basically useless. I'll refresh the current version in the next few days. Currently I am (or try to be) on vacation, so I cannot really say when, but I'll do my best. :) Hi Paolo, any update? Oops, sorry, I thought I had sent that out. It's in the disable-tcg branch on my github repository. Paolo
Re: [Qemu-devel] KVM and variable-endianness guest CPUs
On 22 January 2014 05:39, Victor Kamensky victor.kamen...@linaro.org wrote: Hi Guys, Christoffer and I had a bit heated chat :) on this subject last night. Christoffer, really appreciate your time! We did not really reach agreement during the chat and Christoffer asked me to follow up on this thread. Here it goes. Sorry, it is very long email. I don't believe we can assign any endianity to mmio.data[] byte array. I believe mmio.data[] and mmio.len acts just memcpy and that is all. As memcpy does not imply any endianity of underlying data mmio.data[] should not either. This email is about five times too long to be actually useful, but the major issue here is that the data being transferred is not just a bag of bytes. The data[] array plus the size field are being (mis)used to indicate that the memory transaction is one of: * an 8 bit access * a 16 bit access of some uint16_t value * a 32 bit access of some uint32_t value * a 64 bit access of some uint64_t value exactly as a CPU hardware bus would do. It's because the API is defined in this awkward way with a uint8_t[] array that we need to specify how both sides should go from the actual properties of the memory transaction (value and size) to filling in the array. Furthermore, device endianness is entirely irrelevant for deciding the properties of mmio.data[], because the thing we're modelling here is essentially the CPU-bus interface. In real hardware, the properties of individual devices on the bus are irrelevant to how the CPU's interface to the bus behaves, and similarly here the properties of emulated devices don't affect how KVM's interface to QEMU userspace needs to work. MemoryRegion's 'endianness' field, incidentally, is a dreadful mess that we should get rid of. It is attempting to model the property that some buses/bridges have of doing byte-lane-swaps on data that passes through as a property of the device itself. It would be better if we modelled it properly, with container regions having possible byte-swapping and devices just being devices. thanks -- PMM
Re: [Qemu-devel] [PATCH v3 1/4] KVM/X86: Fix xsave cpuid exposing bug
Il 21/01/2014 19:59, Liu, Jinsong ha scritto: From 3155a190ce6ebb213e6c724240f4e6620ba67a9d Mon Sep 17 00:00:00 2001 From: Liu Jinsong jinsong@intel.com Date: Fri, 13 Dec 2013 02:32:03 +0800 Subject: [PATCH v3 1/4] KVM/X86: Fix xsave cpuid exposing bug EBX of cpuid(0xD, 0) is dynamic per XCR0 features enable/disable. Bit 63 of XCR0 is reserved for future expansion. Signed-off-by: Liu Jinsong jinsong@intel.com Peter, can I have your acked-by on this? --- arch/x86/include/asm/xsave.h |2 ++ arch/x86/kvm/cpuid.c |6 +++--- arch/x86/kvm/x86.c |7 +-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h index 5547389..f6c4e85 100644 --- a/arch/x86/include/asm/xsave.h +++ b/arch/x86/include/asm/xsave.h @@ -13,6 +13,8 @@ #define XSTATE_BNDCSR 0x10 #define XSTATE_FPSSE (XSTATE_FP | XSTATE_SSE) +/* Bit 63 of XCR0 is reserved for future expansion */ +#define XSTATE_EXTEND_MASK (~(XSTATE_FPSSE | (1 63))) #define FXSAVE_SIZE512 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index c697625..2d661e6 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -28,7 +28,7 @@ static u32 xstate_required_size(u64 xstate_bv) int feature_bit = 0; u32 ret = XSAVE_HDR_SIZE + XSAVE_HDR_OFFSET; - xstate_bv = ~XSTATE_FPSSE; + xstate_bv = XSTATE_EXTEND_MASK; while (xstate_bv) { if (xstate_bv 0x1) { u32 eax, ebx, ecx, edx; @@ -74,8 +74,8 @@ void kvm_update_cpuid(struct kvm_vcpu *vcpu) vcpu-arch.guest_supported_xcr0 = (best-eax | ((u64)best-edx 32)) host_xcr0 KVM_SUPPORTED_XCR0; - vcpu-arch.guest_xstate_size = - xstate_required_size(vcpu-arch.guest_supported_xcr0); + vcpu-arch.guest_xstate_size = best-ebx = + xstate_required_size(vcpu-arch.xcr0); } kvm_pmu_cpuid_update(vcpu); diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 21ef1ba..1657ca2 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -576,13 +576,13 @@ static void kvm_put_guest_xcr0(struct kvm_vcpu *vcpu) int __kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr) { - u64 xcr0; + u64 xcr0 = xcr; + u64 old_xcr0 = vcpu-arch.xcr0; u64 valid_bits; /* Only support XCR_XFEATURE_ENABLED_MASK(xcr0) now */ if (index != XCR_XFEATURE_ENABLED_MASK) return 1; - xcr0 = xcr; if (!(xcr0 XSTATE_FP)) return 1; if ((xcr0 XSTATE_YMM) !(xcr0 XSTATE_SSE)) @@ -599,6 +599,9 @@ int __kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr) kvm_put_guest_xcr0(vcpu); vcpu-arch.xcr0 = xcr0; + + if ((xcr0 ^ old_xcr0) XSTATE_EXTEND_MASK) + kvm_update_cpuid(vcpu); return 0; }
Re: [Qemu-devel] [PATCH v3 1/4] KVM/X86: Fix xsave cpuid exposing bug
On 01/22/2014 02:21 AM, Paolo Bonzini wrote: Il 21/01/2014 19:59, Liu, Jinsong ha scritto: From 3155a190ce6ebb213e6c724240f4e6620ba67a9d Mon Sep 17 00:00:00 2001 From: Liu Jinsong jinsong@intel.com Date: Fri, 13 Dec 2013 02:32:03 +0800 Subject: [PATCH v3 1/4] KVM/X86: Fix xsave cpuid exposing bug EBX of cpuid(0xD, 0) is dynamic per XCR0 features enable/disable. Bit 63 of XCR0 is reserved for future expansion. Signed-off-by: Liu Jinsong jinsong@intel.com Peter, can I have your acked-by on this? Yes. Acked-by: H. Peter Anvin h...@linux.intel.com
Re: [Qemu-devel] [PATCH 06/24] target-arm: A64: Implement store-exclusive for system mode
On 22 January 2014 02:19, Hu Tao hu...@cn.fujitsu.com wrote: On Tue, Jan 21, 2014 at 08:12:12PM +, Peter Maydell wrote: +if (is_pair) { +TCGv_i64 addrhi = tcg_temp_new_i64(); +TCGv_i64 tmphi = tcg_temp_new_i64(); + +tcg_gen_addi_i64(addrhi, addr, 1 size); +tcg_gen_qemu_ld_i64(tmphi, addrhi, get_mem_index(s), MO_TE + size); +tcg_gen_brcond_i64(TCG_COND_NE, tmp, cpu_exclusive_high, fail_label); s/tmp/tmphi/ Thanks, nice catch. + +tcg_temp_free_i64(tmphi); +tcg_temp_free_i64(addrhi); Can addrhi be saved and free after doing store? It would have to be made a local-temp to avoid the branch trashing it. I preferred to make it a local and recalculate for the store on the basis that the TCG backend really ought to be capable of turning add tmp, addr, 4; load from tmp into a single load from addr+4 instruction, and having the constant go into a local-temp would probably defeat that. thanks -- PMM
Re: [Qemu-devel] [PATCH 08/24] target-arm: A64: Implement MSR (immediate) instructions
On 22 January 2014 03:10, Hu Tao hu...@cn.fujitsu.com wrote: On Tue, Jan 21, 2014 at 08:12:14PM +, Peter Maydell wrote: +/* MSR_i to update PSTATE. This is OK from EL0 only if UMA is set. + * Note that SPSel is never OK from EL0; we rely on handle_msr_i() + * to catch that case at translate time. + */ +if (arm_current_pl(env) == 0 !(env-cp15.c1_sys SCTLR_UMA)) { +raise_exception(env, EXCP_UDEF); Not sure EXCP_UDEF is correct here. In this case we are trapped from EL0 to EL1, and setting EC to 0x00 if ESR_EL1 is implemented. It's our closest current available exception and is what we've been using consistently for other bad-sysreg access exceptions. You are correct that for the full AArch64 system model we need to fix exception handling and provide a syndrome register value for every place we take an exception. That will come in a later patchset. thanks -- PMM
Re: [Qemu-devel] [Qemu-ppc] KVM and variable-endianness guest CPUs
On 22.01.2014, at 08:26, Victor Kamensky victor.kamen...@linaro.org wrote: On 21 January 2014 22:41, Alexander Graf ag...@suse.de wrote: Native endian really is just a shortcut for target endian which is LE for ARM and BE for PPC. There shouldn't be a qemu-system-armeb or qemu-system-ppc64le. I disagree. Fully functional ARM BE system is what we've been working on for last few months. 'We' is Linaro Networking Group, Endian subteam and some other guys in ARM and across community. Why we do that is a bit beyond of this discussion. ARM BE patches for both V7 and V8 are already in mainline kernel. But ARM BE KVM host is broken now. It is known deficiency that I am trying to fix. Please look at [1]. Patches for V7 BE KVM were proposed and currently under active discussion. Currently I work on ARM V8 BE KVM changes. So native endian in ARM is value of CPSR register E bit. If it is off native endian is LE, if it is on it is BE. Once and if we agree on ARM BE KVM host changes, the next step would be patches in qemu one of which introduces qemu-system-armeb. Please see [2]. I think we're facing an ideology conflict here. Yes, there should be a qemu-system-arm that is BE capable. There should also be a qemu-system-ppc64 that is LE capable. But there is no point in changing the default endiannes for the virtual CPUs that we plug in there. Both CPUs are perfectly capable of running in LE or BE mode, the question is just what we declare the default. Think about the PPC bootstrap. We start off with a BE firmware, then boot into the Linux kernel which calls a hypercall to set the LE bit on every interrupt. But there's no reason this little endian kernel couldn't theoretically have big endian user space running with access to emulated device registers. As Peter already pointed out, the actual breakage behind this is that we have a default endianness at all. But that's a very difficult thing to resolve and I don't think should be our primary goal. Just live with the fact that we declare ARM little endian in QEMU and swap things accordingly - then everyone's happy. This really only ever becomes a problem if you have devices that have awareness of the CPUs endian mode. The only one on PPC that I'm aware of that falls into this category is virtio and there are patches pending to solve that. I don't know if there are any QEMU emulated devices outside of virtio with this issue on ARM, but you'll have to make the emulation code for those look at the CPU state then. QEMU emulates everything that comes after the CPU, so imagine the ioctl struct as a bus package. Your bus doesn't care what endianness the CPU is in - it just gets data from the CPU. I am not sure that I follow above. Suppose I have move r1, #1 str r1, [r0] where r0 is device address. Now depending on CPSR E bit value device address will receive 1 as integer either in LE order or in BE order. That is how ARM v7 CPU works, regardless whether it is emulated or not. So if E bit is off (LE case) after str is executed byte at r0 address will get 1 byte at r0 + 1 address will get 0 byte at r0 + 2 address will get 0 byte at r0 + 3 address will get 0 If E bit is on (BE case) after str is executed byte at r0 address will get 0 byte at r0 + 1 address will get 0 byte at r0 + 2 address will get 0 byte at r0 + 3 address will get 1 my point that mmio.data[] just carries bytes for phys_addr mmio.data[0] would be value for byte at phys_addr, mmio.data[1] would be value for byte at phys_addr + 1, and so on. What we get is an instruction that traps because it wants to write r1 (which has value=1) into address x. So at that point we get the register value. Then we need to take a look at the E bit to see whether the write was supposed to be in non-host endianness because we need to emulate exactly the LE/BE difference you're indicating above. The way we implement this on PPC is that we simply byte swap the register value when guest_endian != host_endian. With this in place, QEMU can just memcpy() the value into a local register and feed it into its emulation code which expects a register value as if the CPU was running in native endianness as parameter - with native meaning little endian for qemu-system-arm. Device emulation code doesn't know what to do with a byte array. Take a look at QEMU's MMIO handler: case KVM_EXIT_MMIO: DPRINTF(handle_mmio\n); cpu_physical_memory_rw(run-mmio.phys_addr, run-mmio.data, run-mmio.len, run-mmio.is_write); ret = 0; break; which translates to switch (l) { case 8: /* 64 bit write access */ val = ldq_p(buf); error |= io_mem_write(mr, addr1, val, 8); break; case 4:
Re: [Qemu-devel] [PATCH v3 1/4] KVM/X86: Fix xsave cpuid exposing bug
Il 21/01/2014 19:59, Liu, Jinsong ha scritto: From 3155a190ce6ebb213e6c724240f4e6620ba67a9d Mon Sep 17 00:00:00 2001 From: Liu Jinsong jinsong@intel.com Date: Fri, 13 Dec 2013 02:32:03 +0800 Subject: [PATCH v3 1/4] KVM/X86: Fix xsave cpuid exposing bug EBX of cpuid(0xD, 0) is dynamic per XCR0 features enable/disable. Bit 63 of XCR0 is reserved for future expansion. Signed-off-by: Liu Jinsong jinsong@intel.com --- arch/x86/include/asm/xsave.h |2 ++ arch/x86/kvm/cpuid.c |6 +++--- arch/x86/kvm/x86.c |7 +-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h index 5547389..f6c4e85 100644 --- a/arch/x86/include/asm/xsave.h +++ b/arch/x86/include/asm/xsave.h @@ -13,6 +13,8 @@ #define XSTATE_BNDCSR 0x10 #define XSTATE_FPSSE (XSTATE_FP | XSTATE_SSE) +/* Bit 63 of XCR0 is reserved for future expansion */ +#define XSTATE_EXTEND_MASK (~(XSTATE_FPSSE | (1 63))) This should be 1ULL, not 1. The compiler should have warned you. Paolo #define FXSAVE_SIZE512 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index c697625..2d661e6 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -28,7 +28,7 @@ static u32 xstate_required_size(u64 xstate_bv) int feature_bit = 0; u32 ret = XSAVE_HDR_SIZE + XSAVE_HDR_OFFSET; - xstate_bv = ~XSTATE_FPSSE; + xstate_bv = XSTATE_EXTEND_MASK; while (xstate_bv) { if (xstate_bv 0x1) { u32 eax, ebx, ecx, edx; @@ -74,8 +74,8 @@ void kvm_update_cpuid(struct kvm_vcpu *vcpu) vcpu-arch.guest_supported_xcr0 = (best-eax | ((u64)best-edx 32)) host_xcr0 KVM_SUPPORTED_XCR0; - vcpu-arch.guest_xstate_size = - xstate_required_size(vcpu-arch.guest_supported_xcr0); + vcpu-arch.guest_xstate_size = best-ebx = + xstate_required_size(vcpu-arch.xcr0); } kvm_pmu_cpuid_update(vcpu); diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 21ef1ba..1657ca2 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -576,13 +576,13 @@ static void kvm_put_guest_xcr0(struct kvm_vcpu *vcpu) int __kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr) { - u64 xcr0; + u64 xcr0 = xcr; + u64 old_xcr0 = vcpu-arch.xcr0; u64 valid_bits; /* Only support XCR_XFEATURE_ENABLED_MASK(xcr0) now */ if (index != XCR_XFEATURE_ENABLED_MASK) return 1; - xcr0 = xcr; if (!(xcr0 XSTATE_FP)) return 1; if ((xcr0 XSTATE_YMM) !(xcr0 XSTATE_SSE)) @@ -599,6 +599,9 @@ int __kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr) kvm_put_guest_xcr0(vcpu); vcpu-arch.xcr0 = xcr0; + + if ((xcr0 ^ old_xcr0) XSTATE_EXTEND_MASK) + kvm_update_cpuid(vcpu); return 0; }
[Qemu-devel] [PATCH] Describe flaws in qcow/qcow2 encryption in the docs
The qemu-img.texi / qemu-doc.texi files currently describe the qcow2/qcow2 encryption thus Encryption uses the AES format which is very secure (128 bit keys). Use a long password (16 characters) to get maximum protection. While AES is indeed a strong encryption system, the way that QCow/QCow2 use it results in a poor/weak encryption system. Due to the use of predictable IVs it is vulnerable to chosen plaintext attacks which can reveal the existance of encrypted data. The direct use of the user passphrase as the encryption key also leads to an inability to change the passphrase of an image. If passphrase is ever compromised the image data will all be vulnerable, since it cannot be re-encrypted. The admin has to clone the image files with a new passphrase and then use a program like shred to secure erase all the old files. Recommend against any use of QCow/QCow2 encryption, directing users to dm-crypt / LUKS which can meet modern cryptography best practices. Signed-off-by: Daniel P. Berrange berra...@redhat.com --- qemu-doc.texi | 23 --- qemu-img.texi | 23 --- 2 files changed, 40 insertions(+), 6 deletions(-) BTW, I based this patch on info from this previous thread: https://lists.gnu.org/archive/html/qemu-devel/2013-07/msg04225.html If anyone knows of further flaws in qcow2 encryption that we should describe, I'll update the docs further. diff --git a/qemu-doc.texi b/qemu-doc.texi index 4e9c6e9..c9da6ad 100644 --- a/qemu-doc.texi +++ b/qemu-doc.texi @@ -547,10 +547,27 @@ File name of a base image (see @option{create} subcommand) @item backing_fmt Image format of the base image @item encryption -If this option is set to @code{on}, the image is encrypted. +If this option is set to @code{on}, the image is encrypted with 128-bit AES-CBC. + +The use of encryption in QCow and QCow2 images is considered to flawed by modern +cryptography standards, suffering from a number of design problems + +@itemize @minus +@item The AES-CBC cipher is used with predictable initialization vectors based +on the sector number. This makes it vulnerable to chosen plaintext attacks +which can reveal the existence of encrypted data. +@item The user passphrase is directly used as the encryption key. A poorly +choosen / short passphrase will compromise the security of the encryption. +In the event of the passphrase being compromised there is no way to change +the passphrase to protect data in any QCow images. The files must be cloned, +using a different encryption passphrase in the new file. The original file +must then be securely erased using a program like shred, though even this +is ineffective with many modern storage technologies. +@end itemize -Encryption uses the AES format which is very secure (128 bit keys). Use -a long password (16 characters) to get maximum protection. +Use of QCow / QCow2 encryption is thus strongly discouraged. Users are +recommended to use an alternative encryption technology such as the +Linux dm-crypt / LUKS system. @item cluster_size Changes the qcow2 cluster size (must be between 512 and 2M). Smaller cluster diff --git a/qemu-img.texi b/qemu-img.texi index 1bba91e..2192eb9 100644 --- a/qemu-img.texi +++ b/qemu-img.texi @@ -402,10 +402,27 @@ File name of a base image (see @option{create} subcommand) @item backing_fmt Image format of the base image @item encryption -If this option is set to @code{on}, the image is encrypted. +If this option is set to @code{on}, the image is encrypted with 128-bit AES-CBC. -Encryption uses the AES format which is very secure (128 bit keys). Use -a long password (16 characters) to get maximum protection. +The use of encryption in QCow and QCow2 images is considered to flawed by modern +cryptography standards, suffering from a number of design problems + +@itemize @minus +@item The AES-CBC cipher is used with predictable initialization vectors based +on the sector number. This makes it vulnerable to chosen plaintext attacks +which can reveal the existence of encrypted data. +@item The user passphrase is directly used as the encryption key. A poorly +choosen / short passphrase will compromise the security of the encryption. +In the event of the passphrase being compromised there is no way to change +the passphrase to protect data in any QCow images. The files must be cloned, +using a different encryption passphrase in the new file. The original file +must then be securely erased using a program like shred, though even this +is ineffective with many modern storage technologies. +@end itemize + +Use of QCow / QCow2 encryption is thus strongly discouraged. Users are +recommended to use an alternative encryption technology such as the +Linux dm-crypt / LUKS system. @item cluster_size Changes the qcow2 cluster size (must be between 512 and 2M). Smaller cluster -- 1.8.4.2
Re: [Qemu-devel] [PATCH v3 2/4] KVM/X86: Intel MPX vmx and msr handle
Il 21/01/2014 20:01, Liu, Jinsong ha scritto: From 31e68d752ac395dc6b65e6adf45be5324e92cdc8 Mon Sep 17 00:00:00 2001 From: Liu Jinsong jinsong@intel.com Date: Fri, 13 Dec 2013 02:32:43 +0800 Subject: [PATCH v3 2/4] KVM/X86: Intel MPX vmx and msr handle This patch handle vmx and msr of Intel MPX feature. Signed-off-by: Xudong Hao xudong@intel.com Signed-off-by: Liu Jinsong jinsong@intel.com --- arch/x86/include/asm/vmx.h|2 ++ arch/x86/include/uapi/asm/msr-index.h |1 + arch/x86/kvm/vmx.c| 12 ++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h index 966502d..1bf4681 100644 --- a/arch/x86/include/asm/vmx.h +++ b/arch/x86/include/asm/vmx.h @@ -85,6 +85,7 @@ #define VM_EXIT_SAVE_IA32_EFER 0x0010 #define VM_EXIT_LOAD_IA32_EFER 0x0020 #define VM_EXIT_SAVE_VMX_PREEMPTION_TIMER 0x0040 +#define VM_EXIT_CLEAR_BNDCFGS 0x0080 #define VM_EXIT_ALWAYSON_WITHOUT_TRUE_MSR 0x00036dff @@ -95,6 +96,7 @@ #define VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL 0x2000 #define VM_ENTRY_LOAD_IA32_PAT 0x4000 #define VM_ENTRY_LOAD_IA32_EFER 0x8000 +#define VM_ENTRY_LOAD_BNDCFGS 0x0001 #define VM_ENTRY_ALWAYSON_WITHOUT_TRUE_MSR 0x11ff diff --git a/arch/x86/include/uapi/asm/msr-index.h b/arch/x86/include/uapi/asm/msr-index.h index 37813b5..2a418c4 100644 --- a/arch/x86/include/uapi/asm/msr-index.h +++ b/arch/x86/include/uapi/asm/msr-index.h @@ -294,6 +294,7 @@ #define MSR_SMI_COUNT 0x0034 #define MSR_IA32_FEATURE_CONTROL0x003a #define MSR_IA32_TSC_ADJUST 0x003b +#define MSR_IA32_BNDCFGS 0x0d90 #define FEATURE_CONTROL_LOCKED (10) #define FEATURE_CONTROL_VMXON_ENABLED_INSIDE_SMX (11) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index b2fe1c2..6d7d9ad 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -439,6 +439,7 @@ struct vcpu_vmx { #endif int gs_ldt_reload_needed; int fs_reload_needed; + u64 msr_host_bndcfgs; } host_state; struct { int vm86_active; @@ -1647,6 +1648,8 @@ static void vmx_save_host_state(struct kvm_vcpu *vcpu) if (is_long_mode(vmx-vcpu)) wrmsrl(MSR_KERNEL_GS_BASE, vmx-msr_guest_kernel_gs_base); #endif + if (boot_cpu_has(X86_FEATURE_MPX)) + rdmsrl(MSR_IA32_BNDCFGS, vmx-host_state.msr_host_bndcfgs); for (i = 0; i vmx-save_nmsrs; ++i) kvm_set_shared_msr(vmx-guest_msrs[i].index, vmx-guest_msrs[i].data, @@ -1684,6 +1687,8 @@ static void __vmx_load_host_state(struct vcpu_vmx *vmx) #ifdef CONFIG_X86_64 wrmsrl(MSR_KERNEL_GS_BASE, vmx-msr_host_kernel_gs_base); #endif + if (vmx-host_state.msr_host_bndcfgs) + wrmsrl(MSR_IA32_BNDCFGS, vmx-host_state.msr_host_bndcfgs); /* * If the FPU is not active (through the host task or * the guest vcpu), then restore the cr0.TS bit. @@ -2800,7 +2805,7 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf) min |= VM_EXIT_HOST_ADDR_SPACE_SIZE; #endif opt = VM_EXIT_SAVE_IA32_PAT | VM_EXIT_LOAD_IA32_PAT | - VM_EXIT_ACK_INTR_ON_EXIT; + VM_EXIT_ACK_INTR_ON_EXIT | VM_EXIT_CLEAR_BNDCFGS; if (adjust_vmx_controls(min, opt, MSR_IA32_VMX_EXIT_CTLS, _vmexit_control) 0) return -EIO; @@ -2817,7 +2822,7 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf) _pin_based_exec_control = ~PIN_BASED_POSTED_INTR; min = 0; - opt = VM_ENTRY_LOAD_IA32_PAT; + opt = VM_ENTRY_LOAD_IA32_PAT | VM_ENTRY_LOAD_BNDCFGS; if (adjust_vmx_controls(min, opt, MSR_IA32_VMX_ENTRY_CTLS, _vmentry_control) 0) return -EIO; You need to disable MPX in the guest if the two controls are not available. You can do this, for example, in vmx_cpuid_update. Otherwise, nested VMX is broken. @@ -8636,6 +8641,9 @@ static int __init vmx_init(void) vmx_disable_intercept_for_msr(MSR_IA32_SYSENTER_CS, false); vmx_disable_intercept_for_msr(MSR_IA32_SYSENTER_ESP, false); vmx_disable_intercept_for_msr(MSR_IA32_SYSENTER_EIP, false); + if (boot_cpu_has(X86_FEATURE_MPX)) + vmx_disable_intercept_for_msr(MSR_IA32_BNDCFGS, true); This needs to be done unconditionally. Otherwise, reading/writing BNDCFGS will access a nonexistent VMCS field. Paolo memcpy(vmx_msr_bitmap_legacy_x2apic, vmx_msr_bitmap_legacy, PAGE_SIZE); memcpy(vmx_msr_bitmap_longmode_x2apic,
Re: [Qemu-devel] [PATCH] qapi: Add backing and file to BlockStats
On 01/22/2014 02:35 AM, Kevin Wolf wrote: Am 22.01.2014 um 04:30 hat Fam Zheng geschrieben: Currently there is no way to query BlockStats of the backing chain. This adds backing and file fields into BlockStats to make it possible. The old optional field parent, which has the information for file, is kept there for backward compatibility, as an alias for file. However field name file is more consistent with file option name in the block device configuration interface. Signed-off-by: Fam Zheng f...@redhat.com I don't think it's a good idea to duplicate a field just because we like the new name better. Eric? I concur - duplication for the sake of naming consistency doesn't add any measurable benefit; I'd rather just improve the docs for the existing name (libvirt will be forced to use the old name for back-compat reasons anyway, making the new name useless cruft that just makes the JSON longer and cost more cycles to parse then discard). -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature
Re: [Qemu-devel] [v19 04/25] add some QemuOpts functions for replace work
Am 20.01.2014 um 15:19 hat Chunyan Liu geschrieben: Add some qemu_opt functions to replace the same functionality of QEMUOptionParameter handling. Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- include/qemu/option.h |7 +++ util/qemu-option.c| 131 + 2 files changed, 138 insertions(+), 0 deletions(-) diff --git a/include/qemu/option.h b/include/qemu/option.h index 2c5b03f..8d77e2e 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -109,6 +109,7 @@ struct QemuOptsList { }; const char *qemu_opt_get(QemuOpts *opts, const char *name); +const char *qemu_opt_get_del(QemuOpts *opts, const char *name); /** * qemu_opt_has_help_opt: * @opts: options to search for a help request @@ -124,6 +125,9 @@ bool qemu_opt_has_help_opt(QemuOpts *opts); bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval); uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval); uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval); +bool qemu_opt_get_bool_del(QemuOpts *opts, const char *name, bool defval); +uint64_t qemu_opt_get_number_del(QemuOpts *opts, const char *name, uint64_t defval); +uint64_t qemu_opt_get_size_del(QemuOpts *opts, const char *name, uint64_t defval); int qemu_opt_unset(QemuOpts *opts, const char *name); int qemu_opt_set(QemuOpts *opts, const char *name, const char *value); void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value, @@ -159,4 +163,7 @@ void qemu_opts_print(QemuOpts *opts); int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque, int abort_on_failure); +QemuOptsList *qemu_opts_append(QemuOptsList *dst, QemuOptsList *list); +void qemu_opts_free(QemuOptsList *list); +void qemu_opts_print_help(QemuOptsList *list); #endif diff --git a/util/qemu-option.c b/util/qemu-option.c index 8944b62..6bd5154 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -379,6 +379,72 @@ QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest, return dest; } +static size_t count_opts_list(QemuOptsList *list) +{ +QemuOptDesc *desc = NULL; +size_t num_opts = 0; + +if (!list) +return 0; Braces. + +desc = list-desc; +while (desc desc-name) { +num_opts ++; +desc ++; +} + +return num_opts; +} + +/* Create a new QemuOptsList with a desc of the merge of the first + * and second. It will allocate space for one new QemuOptsList plus + * enough space for QemuOptDesc in first and second QemuOptsList. + * First argument's QemuOptDesc members take precedence over second's. + * The result's name and implied_opt_name are not copied from them. + * Both merge_lists should not be set. Both lists can be NULL. + */ +QemuOptsList *qemu_opts_append(QemuOptsList *dst, + QemuOptsList *list) You changed this function compared the qemu QEMUOptionParameter one in that it creates a new list instead of modifying dst. I'm not objecting to this change, but perhaps call it qemu_opts_concat() then. +{ +size_t num_opts, num_dst_opts; +QemuOptsList *tmp; +QemuOptDesc *desc; + +if (!dst !list) +return NULL; Braces. Also, why is it allowed to pass NULL for list? + +num_opts = count_opts_list(dst); +num_opts += count_opts_list(list); + +tmp = g_malloc0(sizeof(QemuOptsList) + (num_opts + 1) * sizeof(QemuOptDesc)); This is longer than 80 characters. +QTAILQ_INIT(tmp-head); +num_dst_opts = 0; + +/* copy dst-desc to new list */ +if (dst) { +desc = dst-desc; +while (desc desc-name) { for (desc = dst-desc; desc desc-name; desc++) +tmp-desc[num_dst_opts++] = *desc; +tmp-desc[num_dst_opts].name = NULL; Not strictly necessary as you're using g_malloc0. +desc++; +} +} + +/* add list-desc to new list */ +if (list) { +desc = list-desc; +while (desc desc-name) { +if (find_desc_by_name(tmp-desc, desc-name) == NULL) { +tmp-desc[num_dst_opts++] = *desc; +tmp-desc[num_dst_opts].name = NULL; +} +desc++; +} +} + +return tmp; +} + /* * Parses a parameter string (param) into an option list (dest). * @@ -528,6 +594,18 @@ const char *qemu_opt_get(QemuOpts *opts, const char *name) return opt ? opt-str : NULL; } +static void qemu_opt_del(QemuOpt *opt); + +const char *qemu_opt_get_del(QemuOpts *opts, const char *name) +{ +const char *str = qemu_opt_get(opts, name); +QemuOpt *opt = qemu_opt_find(opts, name); Somewhat inefficient to search the options list twice. +if (opt) { +qemu_opt_del(opt); +}
Re: [Qemu-devel] Simulate different network card vendors
Thanks Stefan. I don't have source code of QEMU emulation of the network card? I do have the source code(driver code) of the devices the I wanted to emulate. Basically,Ethernet controller, I wanted to emulate has following two main part 1)Ethernet PHY 2)Ethernet MAC nd have driver code for these devices. But I don't know what are the steps to emulate it for QEMU. Would you suggest me some links where I can get some idea of how emulating a Device for QEMU? Thanks, Rajan On Mon, Jan 20, 2014 at 9:52 PM, Stefan Hajnoczi stefa...@gmail.com wrote: On Sat, Jan 18, 2014 at 09:19:43AM -0800, rajan pathak wrote: I am looking forward to emulate single-chip Ethernet controller. I can find some of its source code online and it has two main part Ethernet PHY (any 1GB SGMII compatible) and Ethernet MAC . So ,DO I need to simply put the corresponding source files of PHY and MAC in hw/net directory of QEMU? I'm not sure what you mean. Do you have source code for QEMU emulation of the network card? If you have some other source code like a driver for the card, or emulation for the card but not for QEMU, then a lot more work would be necessary to emulate the card in QEMU. Also ,do I need to take care of underlying Ethernet controller(of my machine where I am trying to do this) from Broadcom in any way? QEMU uses mechanisms to send raw packets from userspace, like the tun/tap driver that many OSes have. Therefore the physical NIC doesn't matter, it's abstracted by the tun/tap interface that the host kernel provides.
Re: [Qemu-devel] [v19 05/25] change block layer to support both QemuOpts and QEMUOptionParameter
Am 20.01.2014 um 15:19 hat Chunyan Liu geschrieben: Change block layer to support both QemuOpts and QEMUOptionParameter. After this patch, it will change backend drivers one by one. At the end, QEMUOptionParameter will be removed and only QemuOpts is kept. Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- block.c | 339 +++-- block/cow.c |2 +- block/qcow.c |2 +- block/qcow2.c |2 +- block/qed.c |2 +- block/raw_bsd.c |2 +- block/vhdx.c |2 +- block/vmdk.c |4 +- block/vvfat.c |2 +- include/block/block.h |4 +- include/block/block_int.h |4 +- qemu-img.c| 172 --- 12 files changed, 372 insertions(+), 165 deletions(-) diff --git a/block.c b/block.c index 64e7d22..0dc0b09 100644 --- a/block.c +++ b/block.c @@ -395,6 +395,7 @@ typedef struct CreateCo { BlockDriver *drv; char *filename; QEMUOptionParameter *options; +QemuOpts *opts; int ret; Error *err; } CreateCo; @@ -407,7 +408,10 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque) CreateCo *cco = opaque; assert(cco-drv); -ret = cco-drv-bdrv_create(cco-filename, cco-options, local_err); +if (cco-drv-bdrv_create2) +ret = cco-drv-bdrv_create2(cco-filename, cco-opts, local_err); +else +ret = cco-drv-bdrv_create(cco-filename, cco-options, local_err); Braces if (error_is_set(local_err)) { error_propagate(cco-err, local_err); } @@ -415,7 +419,7 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque) } int bdrv_create(BlockDriver *drv, const char* filename, -QEMUOptionParameter *options, Error **errp) +QEMUOptionParameter *options, QemuOpts *opts, Error **errp) { int ret; @@ -424,11 +428,12 @@ int bdrv_create(BlockDriver *drv, const char* filename, .drv = drv, .filename = g_strdup(filename), .options = options, +.opts = opts, .ret = NOT_DONE, .err = NULL, }; -if (!drv-bdrv_create) { +if (!drv-bdrv_create !drv-bdrv_create2) { error_setg(errp, Driver '%s' does not support image creation, drv-format_name); ret = -ENOTSUP; goto out; @@ -460,7 +465,7 @@ out: } int bdrv_create_file(const char* filename, QEMUOptionParameter *options, - Error **errp) + QemuOpts *opts, Error **errp) { BlockDriver *drv; Error *local_err = NULL; @@ -472,7 +477,7 @@ int bdrv_create_file(const char* filename, QEMUOptionParameter *options, return -ENOENT; } -ret = bdrv_create(drv, filename, options, local_err); +ret = bdrv_create(drv, filename, options, opts, local_err); if (error_is_set(local_err)) { error_propagate(errp, local_err); } @@ -1053,7 +1058,8 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options, BlockDriverState *bs1; int64_t total_size; BlockDriver *bdrv_qcow2; -QEMUOptionParameter *create_options; +QEMUOptionParameter *create_options = NULL; +QemuOpts *opts = NULL; Trailing whitespace QDict *snapshot_options; /* if snapshot, we create a temporary backing file and open it @@ -1080,13 +1086,18 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options, } bdrv_qcow2 = bdrv_find_format(qcow2); -create_options = parse_option_parameters(, bdrv_qcow2-create_options, - NULL); - -set_option_parameter_int(create_options, BLOCK_OPT_SIZE, total_size); +if (bdrv_qcow2-bdrv_create2) { +opts = qemu_opts_create(bdrv_qcow2-create_opts, NULL, 0, error_abort); +qemu_opt_set_number(opts, BLOCK_OPT_SIZE, total_size); +} else { +create_options = Here as well +parse_option_parameters(, bdrv_qcow2-create_options, NULL); +set_option_parameter_int(create_options, BLOCK_OPT_SIZE, total_size); +} -ret = bdrv_create(bdrv_qcow2, tmp_filename, create_options, local_err); +ret = bdrv_create(bdrv_qcow2, tmp_filename, create_options, opts, local_err); free_option_parameters(create_options); +qemu_opts_del(opts); if (ret 0) { error_setg_errno(errp, -ret, Could not create temporary overlay '%s': %s, tmp_filename, @@ -4712,7 +4723,8 @@ void bdrv_img_create(const char *filename, const char *fmt, Error **errp, bool quiet) { QEMUOptionParameter *param = NULL,
Re: [Qemu-devel] [v19 06/25] cow.c: replace QEMUOptionParameter with QemuOpts
Am 20.01.2014 um 15:19 hat Chunyan Liu geschrieben: cow.c: replace QEMUOptionParameter with QemuOpts This line is both in the subject and in the body and thus appears twice in the commit message. Please remove it from the body. Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- block/cow.c | 46 ++ 1 files changed, 22 insertions(+), 24 deletions(-) Kevin
Re: [Qemu-devel] [v19 01/25] add def_value_str to QemuOptDesc
Am 20.01.2014 um 15:19 hat Chunyan Liu geschrieben: Add def_value_str (default value) to QemuOptDesc, to replace function of the default value in QEMUOptionParameter. And improved related functions. Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com It would be worth mentioning that qemu_opts_print() is unused, so changing the prototype and behaviour is fine. -int qemu_opts_print(QemuOpts *opts, void *dummy) +void qemu_opts_print(QemuOpts *opts) { QemuOpt *opt; +QemuOptDesc *desc = opts-list-desc; -fprintf(stderr, %s: %s:, opts-list-name, -opts-id ? opts-id : noid); -QTAILQ_FOREACH(opt, opts-head, next) { -fprintf(stderr, %s=\%s\, opt-name, opt-str); +if (desc[0].name == NULL) { I think 'if (opts_accepts_any(opts))' would be more readable. +QTAILQ_FOREACH(opt, opts-head, next) { +printf(%s=\%s\ , opt-name, opt-str); +} +return; +} +for (; desc desc-name; desc++) { +const char *value = desc-def_value_str; +QemuOpt *opt; + +opt = qemu_opt_find(opts, desc-name); +if (opt) { +value = opt-str; +} + +if (!value) { +continue; +} + +if (desc-type == QEMU_OPT_STRING) { +printf(%s='%s' , desc-name, value); +} else if (desc-type == QEMU_OPT_SIZE opt) { +printf(%s=% PRIu64 , desc-name, opt-value.uint); This is so that a value like '64k' gets expanded to '65536'? Perhaps add a comment? +} else { +printf(%s=%s , desc-name, value); +} } -fprintf(stderr, \n); -return 0; } Kevin
Re: [Qemu-devel] [v19 03/25] improve some functions in qemu-option.c
Am 20.01.2014 um 15:19 hat Chunyan Liu geschrieben: Improve opt_get and opt_set group of functions. For opt_get, check and handle NUlL input; for opt_set, when set to an existing option, rewrite the option with new value. Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com Why do we want to allow NULL opts? Silently ignoring NULL instead of crashing leads to more subtle failure. Is there a legitimate user passing NULL? util/qemu-option.c | 80 ++- 1 files changed, 66 insertions(+), 14 deletions(-) diff --git a/util/qemu-option.c b/util/qemu-option.c index fd84f95..8944b62 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -499,6 +499,9 @@ static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name) { QemuOpt *opt; +if (!opts) +return NULL; The qemu coding style requires braces here (and in the following instances). + QTAILQ_FOREACH_REVERSE(opt, opts-head, QemuOptHead, next) { if (strcmp(opt-name, name) != 0) continue; @@ -509,9 +512,13 @@ static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name) const char *qemu_opt_get(QemuOpts *opts, const char *name) { -QemuOpt *opt = qemu_opt_find(opts, name); +QemuOpt *opt; const QemuOptDesc *desc; +if (!opts) +return NULL; + +opt = qemu_opt_find(opts, name); if (!opt) { desc = find_desc_by_name(opts-list-desc, name); if (desc desc-def_value_str) { @@ -535,10 +542,15 @@ bool qemu_opt_has_help_opt(QemuOpts *opts) bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval) { -QemuOpt *opt = qemu_opt_find(opts, name); +QemuOpt *opt; const QemuOptDesc *desc; Error *local_err = NULL; +if (!opts) +return defval; + +opt = qemu_opt_find(opts, name); + if (opt == NULL) { desc = find_desc_by_name(opts-list-desc, name); if (desc desc-def_value_str) { @@ -553,10 +565,15 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval) uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval) { -QemuOpt *opt = qemu_opt_find(opts, name); +QemuOpt *opt; const QemuOptDesc *desc; Error *local_err = NULL; +if (!opts) +return defval; + +opt = qemu_opt_find(opts, name); + if (opt == NULL) { desc = find_desc_by_name(opts-list-desc, name); if (desc desc-def_value_str) { @@ -571,10 +588,14 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval) uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval) { -QemuOpt *opt = qemu_opt_find(opts, name); +QemuOpt *opt; const QemuOptDesc *desc; Error *local_err = NULL; +if (!opts) +return defval; + +opt = qemu_opt_find(opts, name); if (opt == NULL) { desc = find_desc_by_name(opts-list-desc, name); if (desc desc-def_value_str) { @@ -612,6 +633,10 @@ static void qemu_opt_parse(QemuOpt *opt, Error **errp) static void qemu_opt_del(QemuOpt *opt) { +if (!opt) { +return; +} + QTAILQ_REMOVE(opt-opts-head, opt, next); g_free((/* !const */ char*)opt-name); g_free((/* !const */ char*)opt-str); @@ -664,6 +689,13 @@ static void opt_set(QemuOpts *opts, const char *name, const char *value, return; } +opt = qemu_opt_find(opts, name); +if (opt) { +g_free((char*)opt-str); +opt-str = g_strdup(value); Why is qemu_opt_parse() not needed here? +return; +} + opt = g_malloc0(sizeof(*opt)); opt-name = g_strdup(name); opt-opts = opts; @@ -704,16 +736,24 @@ void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value, int qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val) { QemuOpt *opt; -const QemuOptDesc *desc = opts-list-desc; +const QemuOptDesc *desc; -opt = g_malloc0(sizeof(*opt)); -opt-desc = find_desc_by_name(desc, name); -if (!opt-desc !opts_accepts_any(opts)) { +desc = find_desc_by_name(opts-list-desc, name); +if (!desc !opts_accepts_any(opts)) { qerror_report(QERR_INVALID_PARAMETER, name); -g_free(opt); return -1; } +opt = qemu_opt_find(opts, name); +if (opt) { +g_free((char*)opt-str); +opt-value.boolean =val; Missing space after = +opt-str = g_strdup(val ? on : off); +return 0; +} + +opt = g_malloc0(sizeof(*opt)); +opt-desc = desc; opt-name = g_strdup(name); opt-opts = opts; opt-value.boolean = !!val; Kevin
Re: [Qemu-devel] [PATCH] Describe flaws in qcow/qcow2 encryption in the docs
On 01/22/2014 04:36 AM, Daniel P. Berrange wrote: The qemu-img.texi / qemu-doc.texi files currently describe the qcow2/qcow2 encryption thus Encryption uses the AES format which is very secure (128 bit keys). Use a long password (16 characters) to get maximum protection. While AES is indeed a strong encryption system, the way that QCow/QCow2 use it results in a poor/weak encryption system. Due to the use of predictable IVs it is vulnerable to chosen plaintext attacks which can reveal the existance of encrypted s/existance/existence/ data. The direct use of the user passphrase as the encryption key also leads to an inability to change the passphrase of an image. If passphrase is ever compromised the image data will all be vulnerable, since it cannot be re-encrypted. The admin has to clone the image files with a new passphrase and then use a program like shred to secure erase all the old files. Recommend against any use of QCow/QCow2 encryption, directing users to dm-crypt / LUKS which can meet modern cryptography best practices. Signed-off-by: Daniel P. Berrange berra...@redhat.com --- qemu-doc.texi | 23 --- qemu-img.texi | 23 --- 2 files changed, 40 insertions(+), 6 deletions(-) + +The use of encryption in QCow and QCow2 images is considered to flawed by modern +cryptography standards, suffering from a number of design problems s/$/:/ + +@itemize @minus +@item The AES-CBC cipher is used with predictable initialization vectors based +on the sector number. This makes it vulnerable to chosen plaintext attacks +which can reveal the existence of encrypted data. +@item The user passphrase is directly used as the encryption key. A poorly +choosen / short passphrase will compromise the security of the encryption. s/choosen/chosen/ +In the event of the passphrase being compromised there is no way to change Maybe s/^/@item / ? After all, the need to clone/shred after compromise is there whether the passphrase was poorly chosen or maximally chosen, it's just that poorly chosen is more likely to be easily compromised. +++ b/qemu-img.texi +@item The user passphrase is directly used as the encryption key. A poorly +choosen / short passphrase will compromise the security of the encryption. Copy and paste the fixes above here, too. -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature
Re: [Qemu-devel] [v19 07/25] gluster.c: replace QEMUOptionParameter with QemuOpts
Am 20.01.2014 um 15:19 hat Chunyan Liu geschrieben: gluster.c: replace QEMUOptionParameter with QemuOpts Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com This conflicts with the queued patch gluster: Add support for creating zero-filled image. Can you please rebase on top of my block branch? Kevin
Re: [Qemu-devel] [PATCH] kvm: print suberror on all internal errors
Il 21/01/2014 18:11, Radim Krčmář ha scritto: KVM introduced internal error exit reason and suberror at the same time, and later extended it with internal error data. QEMU does not report suberror on hosts between these two events because we check for the extension. (half a year in 2009, but it is misleading) Fix by removing KVM_CAP_INTERNAL_ERROR_DATA condition on printf. (partially improved by bb44e0d12df70 and ba4047cf848a3 in the past) Signed-off-by: Radim Krčmář rkrc...@redhat.com --- kvm-all.c | 7 +++ 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/kvm-all.c b/kvm-all.c index 0bfb060..0a91d8e 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -1539,17 +1539,16 @@ static void kvm_handle_io(uint16_t port, void *data, int direction, int size, static int kvm_handle_internal_error(CPUState *cpu, struct kvm_run *run) { -fprintf(stderr, KVM internal error.); +fprintf(stderr, KVM internal error. Suberror: %d\n, +run-internal.suberror); + if (kvm_check_extension(kvm_state, KVM_CAP_INTERNAL_ERROR_DATA)) { int i; -fprintf(stderr, Suberror: %d\n, run-internal.suberror); for (i = 0; i run-internal.ndata; ++i) { fprintf(stderr, extra data[%d]: %PRIx64\n, i, (uint64_t)run-internal.data[i]); } -} else { -fprintf(stderr, \n); } if (run-internal.suberror == KVM_INTERNAL_ERROR_EMULATION) { fprintf(stderr, emulation failure\n); Applied to uq/master, thanks (please remember uq/master in the subject line in the future). Paolo
Re: [Qemu-devel] [v19 12/25] qed.c: replace QEMUOptionParameter with QemuOpts
Am 20.01.2014 um 15:19 hat Chunyan Liu geschrieben: qed.c: replace QEMUOptionParameter with QemuOpts Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- block/qed.c | 89 +-- block/qed.h |3 +- 2 files changed, 45 insertions(+), 47 deletions(-) diff --git a/block/qed.h b/block/qed.h index 5d65bea..b024751 100644 --- a/block/qed.h +++ b/block/qed.h @@ -43,7 +43,7 @@ * * All fields are little-endian on disk. */ - +#define QED_DEFAULT_CLUSTER_SIZE 65536 enum { QED_MAGIC = 'Q' | 'E' 8 | 'D' 16 | '\0' 24, @@ -69,7 +69,6 @@ enum { */ QED_MIN_CLUSTER_SIZE = 4 * 1024, /* in bytes */ QED_MAX_CLUSTER_SIZE = 64 * 1024 * 1024, -QED_DEFAULT_CLUSTER_SIZE = 64 * 1024, /* Allocated clusters are tracked using a 2-level pagetable. Table size is * a multiple of clusters so large maximum image sizes can be supported What is this hunk good for? Kevin
Re: [Qemu-devel] [PATCH] Describe flaws in qcow/qcow2 encryption in the docs
On Wed, Jan 22, 2014 at 11:49:21AM +, Peter Maydell wrote: On 22 January 2014 11:36, Daniel P. Berrange berra...@redhat.com wrote: Recommend against any use of QCow/QCow2 encryption, directing users to dm-crypt / LUKS which can meet modern cryptography best practices. Couple of minor typo nits I spotted: Thanks Peter, sending a v2. Daniel -- |: http://berrange.com -o-http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Re: [Qemu-devel] [v19 22/25] vhdx.c: replace QEMUOptionParameter with QemuOpts
Am 20.01.2014 um 15:20 hat Chunyan Liu geschrieben: vhdx.c: replace QEMUOptionParameter with QemuOpts Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- block/vhdx.c | 93 +++-- block/vhdx.h |1 + 2 files changed, 45 insertions(+), 49 deletions(-) diff --git a/block/vhdx.c b/block/vhdx.c index c78675e..8021e8e 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -1711,7 +1711,7 @@ exit: *. ~ --- ~ ~ ~ ---. * 1MB */ -static int vhdx_create(const char *filename, QEMUOptionParameter *options, +static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp) { int ret = 0; @@ -1729,20 +1729,11 @@ static int vhdx_create(const char *filename, QEMUOptionParameter *options, VHDXImageType image_type; Error *local_err = NULL; -while (options options-name) { -if (!strcmp(options-name, BLOCK_OPT_SIZE)) { -image_size = options-value.n; -} else if (!strcmp(options-name, VHDX_BLOCK_OPT_LOG_SIZE)) { -log_size = options-value.n; -} else if (!strcmp(options-name, VHDX_BLOCK_OPT_BLOCK_SIZE)) { -block_size = options-value.n; -} else if (!strcmp(options-name, BLOCK_OPT_SUBFMT)) { -type = options-value.s; -} else if (!strcmp(options-name, VHDX_BLOCK_OPT_ZERO)) { -use_zero_blocks = options-value.n != 0; -} -options++; -} +image_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0); +log_size = qemu_opt_get_size_del(opts, VHDX_BLOCK_OPT_LOG_SIZE, 0); +block_size = qemu_opt_get_size_del(opts, VHDX_BLOCK_OPT_BLOCK_SIZE, 0); +type = qemu_opt_get_del(opts, BLOCK_OPT_SUBFMT); +use_zero_blocks = qemu_opt_get_bool_del(opts, VHDX_BLOCK_OPT_ZERO, 0); if (image_size VHDX_MAX_IMAGE_SIZE) { error_setg_errno(errp, EINVAL, Image size too large; max of 64TB); @@ -1791,7 +1782,7 @@ static int vhdx_create(const char *filename, QEMUOptionParameter *options, block_size = block_size VHDX_BLOCK_SIZE_MAX ? VHDX_BLOCK_SIZE_MAX : block_size; -ret = bdrv_create_file(filename, options, NULL, local_err); +ret = bdrv_create_file(filename, NULL, opts, local_err); if (ret 0) { error_propagate(errp, local_err); goto exit; @@ -1871,37 +1862,41 @@ static int vhdx_check(BlockDriverState *bs, BdrvCheckResult *result, return 0; } -static QEMUOptionParameter vhdx_create_options[] = { -{ -.name = BLOCK_OPT_SIZE, -.type = OPT_SIZE, -.help = Virtual disk size; max of 64TB. -}, -{ -.name = VHDX_BLOCK_OPT_LOG_SIZE, -.type = OPT_SIZE, -.value.n = 1 * MiB, -.help = Log size; min 1MB. -}, -{ -.name = VHDX_BLOCK_OPT_BLOCK_SIZE, -.type = OPT_SIZE, -.value.n = 0, -.help = Block Size; min 1MB, max 256MB. \ -0 means auto-calculate based on image size. -}, -{ -.name = BLOCK_OPT_SUBFMT, -.type = OPT_STRING, -.help = VHDX format type, can be either 'dynamic' or 'fixed'. \ -Default is 'dynamic'. -}, -{ -.name = VHDX_BLOCK_OPT_ZERO, -.type = OPT_FLAG, -.help = Force use of payload blocks of type 'ZERO'. Non-standard. -}, -{ NULL } +static QemuOptsList vhdx_create_opts = { +.name = vhdx-create-opts, +.head = QTAILQ_HEAD_INITIALIZER(vhdx_create_opts.head), +.desc = { +{ + .name = BLOCK_OPT_SIZE, + .type = QEMU_OPT_SIZE, + .help = Virtual disk size; max of 64TB. + }, + { + .name = VHDX_BLOCK_OPT_LOG_SIZE, + .type = QEMU_OPT_SIZE, + .def_value_str = stringify(DEFAULT_LOG_SIZE), + .help = Log size; min 1MB. + }, + { + .name = VHDX_BLOCK_OPT_BLOCK_SIZE, + .type = QEMU_OPT_SIZE, + .def_value_str = stringify(0), + .help = Block Size; min 1MB, max 256MB. \ + 0 means auto-calculate based on image size. + }, + { + .name = BLOCK_OPT_SUBFMT, + .type = QEMU_OPT_STRING, + .help = VHDX format type, can be either 'dynamic' or 'fixed'. \ + Default is 'dynamic'. + }, + { + .name = VHDX_BLOCK_OPT_ZERO, + .type = QEMU_OPT_BOOL, + .help = Force use of payload blocks of type 'ZERO'. Non-standard. + }, + { NULL } +} }; static BlockDriver bdrv_vhdx = { @@ -1913,11 +1908,11 @@ static BlockDriver bdrv_vhdx = { .bdrv_reopen_prepare= vhdx_reopen_prepare, .bdrv_co_readv = vhdx_co_readv, .bdrv_co_writev = vhdx_co_writev, -
Re: [Qemu-devel] [PATCH] Describe flaws in qcow/qcow2 encryption in the docs
On 22 January 2014 11:36, Daniel P. Berrange berra...@redhat.com wrote: Recommend against any use of QCow/QCow2 encryption, directing users to dm-crypt / LUKS which can meet modern cryptography best practices. Couple of minor typo nits I spotted: diff --git a/qemu-doc.texi b/qemu-doc.texi index 4e9c6e9..c9da6ad 100644 --- a/qemu-doc.texi +++ b/qemu-doc.texi @@ -547,10 +547,27 @@ File name of a base image (see @option{create} subcommand) @item backing_fmt Image format of the base image @item encryption -If this option is set to @code{on}, the image is encrypted. +If this option is set to @code{on}, the image is encrypted with 128-bit AES-CBC. + +The use of encryption in QCow and QCow2 images is considered to flawed by modern to be +cryptography standards, suffering from a number of design problems Missing .. + +@itemize @minus +@item The AES-CBC cipher is used with predictable initialization vectors based +on the sector number. This makes it vulnerable to chosen plaintext attacks +which can reveal the existence of encrypted data. +@item The user passphrase is directly used as the encryption key. A poorly +choosen / short passphrase will compromise the security of the encryption. chosen or short. +In the event of the passphrase being compromised there is no way to change +the passphrase to protect data in any QCow images. The files must be cloned, +using a different encryption passphrase in the new file. The original file +must then be securely erased using a program like shred, though even this +is ineffective with many modern storage technologies. +@end itemize -Encryption uses the AES format which is very secure (128 bit keys). Use -a long password (16 characters) to get maximum protection. +Use of QCow / QCow2 encryption is thus strongly discouraged. Users are +recommended to use an alternative encryption technology such as the +Linux dm-crypt / LUKS system. (same typos also in the texi version). thanks -- PMM
Re: [Qemu-devel] [Xen-devel] Project idea: make QEMU more flexible
On Wed, Jan 22, 2014 at 11:20:38AM +0100, Paolo Bonzini wrote: Il 21/01/2014 19:27, Wei Liu ha scritto: Googling disable tcg would have provided an answer, but the patches were old enough to be basically useless. I'll refresh the current version in the next few days. Currently I am (or try to be) on vacation, so I cannot really say when, but I'll do my best. :) Hi Paolo, any update? Oops, sorry, I thought I had sent that out. It's in the disable-tcg branch on my github repository. Thanks. I will have a look. Wei. Paolo
Re: [Qemu-devel] [Xen-devel] Hvmloader: Modify ACPI to only supply _EJ0 methods for PCIslots that support hotplug by runtime patching
Il 28/10/2013 10:38, Jan Beulich ha scritto: On 24.10.13 at 14:17, Gonglei (Arei) arei.gong...@huawei.com wrote: Now I test the patch based on the codes of trunk, which works well. The patch has been modified after your suggestion. Partly. I looks reasonable now, but still not pretty. But the tools maintainers will have to have the final say here anyway. Jan Are there news about this patch? Thanks for any reply.
Re: [Qemu-devel] [v19 24/25] cleanup QEMUOptionParameter
Am 20.01.2014 um 15:20 hat Chunyan Liu geschrieben: Now all places using QEMUOptionParameter could use QemuOpts too, remove QEMUOptionParameter related code. Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- block.c | 147 ++- block/cow.c |2 +- block/qcow.c |2 +- block/qcow2.c |2 +- block/qed.c |2 +- block/raw_bsd.c |2 +- block/vhdx.c |2 +- block/vmdk.c |4 +- block/vvfat.c |2 +- include/block/block.h |4 +- include/block/block_int.h |3 - include/qemu/option.h | 35 -- qemu-img.c| 93 ++- util/qemu-option.c| 294 - 14 files changed, 30 insertions(+), 564 deletions(-) diff --git a/block.c b/block.c index 8c490c6..b33d095 100644 --- a/block.c +++ b/block.c @@ -394,7 +394,6 @@ BlockDriver *bdrv_find_whitelisted_format(const char *format_name, typedef struct CreateCo { BlockDriver *drv; char *filename; -QEMUOptionParameter *options; QemuOpts *opts; int ret; Error *err; @@ -403,15 +402,13 @@ typedef struct CreateCo { static void coroutine_fn bdrv_create_co_entry(void *opaque) { Error *local_err = NULL; -int ret; +int ret = -1; CreateCo *cco = opaque; assert(cco-drv); if (cco-drv-bdrv_create2) ret = cco-drv-bdrv_create2(cco-filename, cco-opts, local_err); -else -ret = cco-drv-bdrv_create(cco-filename, cco-options, local_err); The if condition isn't needed any more, it is always true. if (error_is_set(local_err)) { error_propagate(cco-err, local_err); } @@ -324,22 +315,19 @@ fail: return NULL; } -static int add_old_style_options(const char *fmt, QEMUOptionParameter *list, +static int add_old_style_options(const char *fmt, QemuOpts *opts, const char *base_filename, const char *base_fmt) { if (base_filename) { -if ((opts qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, base_filename)) || -(list set_option_parameter(list, BLOCK_OPT_BACKING_FILE, base_filename))) { -error_report(Backing file not supported for file format '%s', +if (opts qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, base_filename)) {error_report(Backing file not supported for file format '%s', I think you lost a line break here. :-) fmt); return -1; } } if (base_fmt) { -if ((opts qemu_opt_set(opts, BLOCK_OPT_BACKING_FMT, base_fmt)) || -(list set_option_parameter(list, BLOCK_OPT_BACKING_FMT, base_fmt))) { +if (opts qemu_opt_set(opts, BLOCK_OPT_BACKING_FMT, base_fmt)) { error_report(Backing file format not supported for file format '%s', fmt); return -1; @@ -1152,7 +1140,6 @@ static int img_convert(int argc, char **argv) size_t bufsectors = IO_BUF_SIZE / BDRV_SECTOR_SIZE; const uint8_t *buf1; BlockDriverInfo bdi; -QEMUOptionParameter *param = NULL, *create_options = NULL; QemuOpts *opts = NULL; QemuOptsList *create_opts = NULL; char *options = NULL; @@ -1337,7 +1324,7 @@ static int img_convert(int argc, char **argv) } qemu_opt_set_number(opts, BLOCK_OPT_SIZE, total_sectors * 512); -ret = add_old_style_options(out_fmt, NULL, opts, out_baseimg, NULL); +ret = add_old_style_options(out_fmt, opts, out_baseimg, NULL); if (ret 0) { goto out; } @@ -1379,70 +1366,12 @@ static int img_convert(int argc, char **argv) } } else { -QEMUOptionParameter *out_baseimg_param; - -create_options = append_option_parameters(create_options, - drv-create_options); -create_options = append_option_parameters(create_options, - proto_drv-create_options); - -if (options) { -param = parse_option_parameters(options, create_options, param); -if (param == NULL) { -error_report(Invalid options for file format '%s'., out_fmt); -ret = -1; -goto out; -} -} else { -param = parse_option_parameters(, create_options, param); -} - -set_option_parameter_int(param, BLOCK_OPT_SIZE, total_sectors * 512); -ret = add_old_style_options(out_fmt, param, NULL, out_baseimg, NULL); -if (ret 0) { -goto out; -} - -/* Get backing
Re: [Qemu-devel] [v19 00/25] replace QEMUOptionParameter with QemuOpts
Am 20.01.2014 um 15:19 hat Chunyan Liu geschrieben: This patch series is to replace QEMUOptionParameter with QemuOpts, so that only one Qemu Option structure is kept in QEMU code. This version is based on Dong Xu's previous patches, to move the work forward. https://lists.gnu.org/archive/html/qemu-devel/2013-08/msg01695.html Please check the coding style of all patches, especially braces and trailing whitespace. I commented on a few occurences, but didn't do so consistently throughout the series. Kevin
Re: [Qemu-devel] [PATCH] qapi: Add backing and file to BlockStats
On 01/21/2014 08:30 PM, Fam Zheng wrote: Currently there is no way to query BlockStats of the backing chain. This adds backing and file fields into BlockStats to make it possible. The old optional field parent, which has the information for file, is kept there for backward compatibility, as an alias for file. Eww. BlockStats is a big struct (and getting bigger), which means this is a lot of JSON duplication to send over the wire just to get discarded (no matter whether the client uses the old or the new name). However field name file is more consistent with file option name in the block device configuration interface. Consistency is nice, but back-compat and efficiency take higher priority in this case. You are better off documenting that 'parent' refers to the details of the backing file, without adding a 'file' field. Signed-off-by: Fam Zheng f...@redhat.com --- block/qapi.c | 7 +++ qapi-schema.json | 15 +++ 2 files changed, 18 insertions(+), 4 deletions(-) +++ b/block/qapi.c @@ -316,6 +316,13 @@ BlockStats *bdrv_query_stats(const BlockDriverState *bs) if (bs-file) { s-has_parent = true; s-parent = bdrv_query_stats(bs-file); +s-has_file = true; +s-file = bdrv_query_stats(bs-file); +} Drop this portion. + +if (bs-backing_hd) { +s-has_backing = true; +s-backing = bdrv_query_stats(bs-backing_hd); } But this one is fine. return s; diff --git a/qapi-schema.json b/qapi-schema.json index f27c48a..c3c8aec 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -1022,15 +1022,22 @@ # # @stats: A @BlockDeviceStats for the device. # -# @parent: #optional This may point to the backing block device if this is a -# a virtual block device. If it's a backing block, this will point -# to the backing file is one is present. I'm okay if you improve the wording here, but keep this field untouched with just a better description. +# @file: #optional This may point to the file block device if present. +# (Since 2.0) Don't add this field. +# +# @backing: #optional This may point to the backing block device if present. +# (Since 2.0) +# s/may point/describes/ +# @parent: #optional An alias of @file for backward comatibility. (Since +# 0.14.0) s/comatibility/compatibility/ - except that I don't think you want to keep it as an alias. Also, the (Since 0.14.0) is bogus, since the field has existed for as long as the command has. -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature
[Qemu-devel] [PATCH v2] Describe flaws in qcow/qcow2 encryption in the docs
The qemu-img.texi / qemu-doc.texi files currently describe the qcow2/qcow2 encryption thus Encryption uses the AES format which is very secure (128 bit keys). Use a long password (16 characters) to get maximum protection. While AES is indeed a strong encryption system, the way that QCow/QCow2 use it results in a poor/weak encryption system. Due to the use of predictable IVs it is vulnerable to chosen plaintext attacks which can reveal the existance of encrypted data. The direct use of the user passphrase as the encryption key also leads to an inability to change the passphrase of an image. If passphrase is ever compromised the image data will all be vulnerable, since it cannot be re-encrypted. The admin has to clone the image files with a new passphrase and then use a program like shred to secure erase all the old files. Recommend against any use of QCow/QCow2 encryption, directing users to dm-crypt / LUKS which can meet modern cryptography best practices. Signed-off-by: Daniel P. Berrange berra...@redhat.com --- qemu-doc.texi | 23 --- qemu-img.texi | 23 --- 2 files changed, 40 insertions(+), 6 deletions(-) In v2: - Addressed typos reported by Peter Still welcome info about any other flaws qcow2 has in this area that should be documented. diff --git a/qemu-doc.texi b/qemu-doc.texi index 4e9c6e9..cb778af 100644 --- a/qemu-doc.texi +++ b/qemu-doc.texi @@ -547,10 +547,27 @@ File name of a base image (see @option{create} subcommand) @item backing_fmt Image format of the base image @item encryption -If this option is set to @code{on}, the image is encrypted. +If this option is set to @code{on}, the image is encrypted with 128-bit AES-CBC. + +The use of encryption in QCow and QCow2 images is considered to be flawed by +modern cryptography standards, suffering from a number of design problems: + +@itemize @minus +@item The AES-CBC cipher is used with predictable initialization vectors based +on the sector number. This makes it vulnerable to chosen plaintext attacks +which can reveal the existence of encrypted data. +@item The user passphrase is directly used as the encryption key. A poorly +choosen or short passphrase will compromise the security of the encryption. +In the event of the passphrase being compromised there is no way to change +the passphrase to protect data in any QCow images. The files must be cloned, +using a different encryption passphrase in the new file. The original file +must then be securely erased using a program like shred, though even this +is ineffective with many modern storage technologies. +@end itemize -Encryption uses the AES format which is very secure (128 bit keys). Use -a long password (16 characters) to get maximum protection. +Use of QCow / QCow2 encryption is thus strongly discouraged. Users are +recommended to use an alternative encryption technology such as the +Linux dm-crypt / LUKS system. @item cluster_size Changes the qcow2 cluster size (must be between 512 and 2M). Smaller cluster diff --git a/qemu-img.texi b/qemu-img.texi index 1bba91e..8cda3fc 100644 --- a/qemu-img.texi +++ b/qemu-img.texi @@ -402,10 +402,27 @@ File name of a base image (see @option{create} subcommand) @item backing_fmt Image format of the base image @item encryption -If this option is set to @code{on}, the image is encrypted. +If this option is set to @code{on}, the image is encrypted with 128-bit AES-CBC. -Encryption uses the AES format which is very secure (128 bit keys). Use -a long password (16 characters) to get maximum protection. +The use of encryption in QCow and QCow2 images is considered to be flawed by +modern cryptography standards, suffering from a number of design problems: + +@itemize @minus +@item The AES-CBC cipher is used with predictable initialization vectors based +on the sector number. This makes it vulnerable to chosen plaintext attacks +which can reveal the existence of encrypted data. +@item The user passphrase is directly used as the encryption key. A poorly +choosen or short passphrase will compromise the security of the encryption. +In the event of the passphrase being compromised there is no way to change +the passphrase to protect data in any QCow images. The files must be cloned, +using a different encryption passphrase in the new file. The original file +must then be securely erased using a program like shred, though even this +is ineffective with many modern storage technologies. +@end itemize + +Use of QCow / QCow2 encryption is thus strongly discouraged. Users are +recommended to use an alternative encryption technology such as the +Linux dm-crypt / LUKS system. @item cluster_size Changes the qcow2 cluster size (must be between 512 and 2M). Smaller cluster -- 1.8.4.2
Re: [Qemu-devel] [PATCH v3 0/4] X86/KVM: enable Intel MPX for KVM
Il 22/01/2014 06:29, Liu, Jinsong ha scritto: These patches are version 3 to enalbe Intel MPX for KVM. Version 1: * Add some Intel MPX definiation * Fix a cpuid(0x0d, 0) exposing bug, dynamic per XCR0 features enable/disable * vmx and msr handle for MPX support at KVM * enalbe MPX feature for guest Version 2: * remove generic MPX definiation, Qiaowei's patch has add the definiation at kernel side * add MSR_IA32_BNDCFGS to msrs_to_save Version 3: * rebase on latest kernel, which include Qiaowei's MPX common definiation pulled from HPA's tree I am afraid there is still some work to do on these patches, so they need to be delayed to 3.15. Patch 1: this seems mostly separate from the rest of the MPX work. I commented on the missing ULL suffix, but I would also like to understand why you put this patch in this series. Patch 2: As remarked in the reply to this patch: - the vmx_disable_intercept_for_msr has to be unconditional - you need a new kvm_x86_ops member mpx_supported, to disable MPX whenever the two VMX controls are not available. Patch 3: this patch needs to be rebased. Apart from that it is fine, but please move the VMX bits together with patch 2, and the other bits together with patch 4. Patch 4: this patch needs to be rebased and to use the new mpx_supported member If you also want to look at nested VMX support for MPX, that would be nice. It should not be hard. Otherwise we can take care of that later. Thanks for your work, Paolo
[Qemu-devel] [PATCH] cpu: implementing victim TLB for QEMU system emulated TLB
This patch adds a victim TLB to the QEMU system mode TLB. QEMU system mode page table walks are expensive. Taken by running QEMU qemu-system-x86_64 system mode on Intel PIN , a TLB miss and walking a 4-level page tables in guest Linux OS takes ~450 X86 instructions on average. QEMU system mode TLB is implemented using a directly-mapped hashtable. This structure suffers from conflict misses. Increasing the associativity of the TLB may not be the solution to conflict misses as all the ways may have to be walked in serial. A victim TLB is a TLB used to hold translations evicted from the primary TLB upon replacement. The victim TLB lies between the main TLB and its refill path. Victim TLB is of greater associativity (fully associative in this patch). It takes longer to lookup the victim TLB, but its likely better than a full page table walk. The memory translation path is changed as follows : Before Victim TLB: 1. Inline TLB lookup 2. Exit code cache on TLB miss. 3. Check for unaligned, IO accesses 4. TLB refill. 5. Do the memory access. 6. Return to code cache. After Victim TLB: 1. Inline TLB lookup 2. Exit code cache on TLB miss. 3. Check for unaligned, IO accesses 4. Victim TLB lookup. 5. If victim TLB misses, TLB refill 6. Do the memory access. 7. Return to code cache The advantage is that victim TLB can offer more associativity to a directly mapped TLB and thus potentially fewer page table walks while still keeping the time taken to flush within reasonable limits. However, placing a victim TLB before the refill path increase TLB refill path as the victim TLB is consulted before the TLB refill. The performance results demonstrate that the pros outweigh the cons. Attached are some performance results taken on SPECINT2006 train dataset and a Intel(R) Xeon(R) CPU E5620 @ 2.40GHz Linux machine. In summary, victim TLB improves the performance of qemu-system-x86_64 by 11% on average on SPECINT2006 and with highest improvement of in 254% in 464.h264ref. And victim TLB does not result in any performance degradation in any of the measured benchmarks. Furthermore, the implemented victim TLB is architecture independent and is expected to benefit other architectures in QEMU as well. Although there are measurement fluctuations, the performance improvement are very significant and by no means in the range of noises. Signed-off-by: Xin Tong trent.t...@gmail.com --- cputlb.c| 47 -- include/exec/cpu-defs.h | 15 ++--- include/exec/exec-all.h |2 ++ include/exec/softmmu_template.h | 69 --- 4 files changed, 122 insertions(+), 11 deletions(-) diff --git a/cputlb.c b/cputlb.c index b533f3f..bb83c07 100644 --- a/cputlb.c +++ b/cputlb.c @@ -34,6 +34,19 @@ /* statistics */ int tlb_flush_count; +#define TLB_XOR_SWAP(X, Y) do {*X = *X ^ *Y; *Y = *X ^ *Y; *X = *X ^ *Y;}while(0); + +/* used by victim tlb. swap the 2 given TLB entries as well as their corresponding IOTLB */ +void swap_tlb(CPUTLBEntry *te, CPUTLBEntry *se, hwaddr *iote, hwaddr *iose) +{ + /* tlb and iotlb swap */ + TLB_XOR_SWAP(iote, iose); + TLB_XOR_SWAP(te-addend, se-addend); + TLB_XOR_SWAP(te-addr_code, se-addr_code); + TLB_XOR_SWAP(te-addr_read, se-addr_read); + TLB_XOR_SWAP(te-addr_write, se-addr_write); +} + /* NOTE: * If flush_global is true (the usual case), flush all tlb entries. * If flush_global is false, flush (at least) all tlb entries not @@ -58,6 +71,7 @@ void tlb_flush(CPUArchState *env, int flush_global) cpu-current_tb = NULL; memset(env-tlb_table, -1, sizeof(env-tlb_table)); +memset(env-tlb_v_table, -1, sizeof(env-tlb_v_table)); memset(env-tb_jmp_cache, 0, sizeof(env-tb_jmp_cache)); env-tlb_flush_addr = -1; @@ -106,6 +120,14 @@ void tlb_flush_page(CPUArchState *env, target_ulong addr) tlb_flush_entry(env-tlb_table[mmu_idx][i], addr); } +/* check whether there are entries that need to be flushed in the vtlb */ +for (mmu_idx = 0; mmu_idx NB_MMU_MODES; mmu_idx++) { +unsigned int k; +for (k = 0;k CPU_VTLB_SIZE; k++) { + tlb_flush_entry(env-tlb_v_table[mmu_idx][k], addr); +} +} + tb_flush_jmp_cache(env, addr); } @@ -165,11 +187,15 @@ void cpu_tlb_reset_dirty_all(ram_addr_t start1, ram_addr_t length) env = cpu-env_ptr; for (mmu_idx = 0; mmu_idx NB_MMU_MODES; mmu_idx++) { unsigned int i; - for (i = 0; i CPU_TLB_SIZE; i++) { tlb_reset_dirty_range(env-tlb_table[mmu_idx][i], start1, length); } + +for (i = 0; i CPU_VTLB_SIZE; i++) { +tlb_reset_dirty_range(env-tlb_v_table[mmu_idx][i], + start1, length); +} } } } @@ -193,6 +219,13 @@ void tlb_set_dirty(CPUArchState *env, target_ulong vaddr) for (mmu_idx =
Re: [Qemu-devel] [PATCH v3 2/4] KVM/X86: Intel MPX vmx and msr handle
Il 22/01/2014 12:38, Paolo Bonzini ha scritto: Il 21/01/2014 20:01, Liu, Jinsong ha scritto: From 31e68d752ac395dc6b65e6adf45be5324e92cdc8 Mon Sep 17 00:00:00 2001 From: Liu Jinsong jinsong@intel.com Date: Fri, 13 Dec 2013 02:32:43 +0800 Subject: [PATCH v3 2/4] KVM/X86: Intel MPX vmx and msr handle This patch handle vmx and msr of Intel MPX feature. Signed-off-by: Xudong Hao xudong@intel.com Signed-off-by: Liu Jinsong jinsong@intel.com --- arch/x86/include/asm/vmx.h|2 ++ arch/x86/include/uapi/asm/msr-index.h |1 + arch/x86/kvm/vmx.c| 12 ++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h index 966502d..1bf4681 100644 --- a/arch/x86/include/asm/vmx.h +++ b/arch/x86/include/asm/vmx.h @@ -85,6 +85,7 @@ #define VM_EXIT_SAVE_IA32_EFER 0x0010 #define VM_EXIT_LOAD_IA32_EFER 0x0020 #define VM_EXIT_SAVE_VMX_PREEMPTION_TIMER 0x0040 +#define VM_EXIT_CLEAR_BNDCFGS 0x0080 #define VM_EXIT_ALWAYSON_WITHOUT_TRUE_MSR0x00036dff @@ -95,6 +96,7 @@ #define VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL 0x2000 #define VM_ENTRY_LOAD_IA32_PAT0x4000 #define VM_ENTRY_LOAD_IA32_EFER 0x8000 +#define VM_ENTRY_LOAD_BNDCFGS 0x0001 #define VM_ENTRY_ALWAYSON_WITHOUT_TRUE_MSR0x11ff diff --git a/arch/x86/include/uapi/asm/msr-index.h b/arch/x86/include/uapi/asm/msr-index.h index 37813b5..2a418c4 100644 --- a/arch/x86/include/uapi/asm/msr-index.h +++ b/arch/x86/include/uapi/asm/msr-index.h @@ -294,6 +294,7 @@ #define MSR_SMI_COUNT0x0034 #define MSR_IA32_FEATURE_CONTROL0x003a #define MSR_IA32_TSC_ADJUST 0x003b +#define MSR_IA32_BNDCFGS0x0d90 #define FEATURE_CONTROL_LOCKED(10) #define FEATURE_CONTROL_VMXON_ENABLED_INSIDE_SMX(11) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index b2fe1c2..6d7d9ad 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -439,6 +439,7 @@ struct vcpu_vmx { #endif int gs_ldt_reload_needed; int fs_reload_needed; +u64 msr_host_bndcfgs; } host_state; struct { int vm86_active; @@ -1647,6 +1648,8 @@ static void vmx_save_host_state(struct kvm_vcpu *vcpu) if (is_long_mode(vmx-vcpu)) wrmsrl(MSR_KERNEL_GS_BASE, vmx-msr_guest_kernel_gs_base); #endif +if (boot_cpu_has(X86_FEATURE_MPX)) +rdmsrl(MSR_IA32_BNDCFGS, vmx-host_state.msr_host_bndcfgs); for (i = 0; i vmx-save_nmsrs; ++i) kvm_set_shared_msr(vmx-guest_msrs[i].index, vmx-guest_msrs[i].data, @@ -1684,6 +1687,8 @@ static void __vmx_load_host_state(struct vcpu_vmx *vmx) #ifdef CONFIG_X86_64 wrmsrl(MSR_KERNEL_GS_BASE, vmx-msr_host_kernel_gs_base); #endif +if (vmx-host_state.msr_host_bndcfgs) +wrmsrl(MSR_IA32_BNDCFGS, vmx-host_state.msr_host_bndcfgs); /* * If the FPU is not active (through the host task or * the guest vcpu), then restore the cr0.TS bit. @@ -2800,7 +2805,7 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf) min |= VM_EXIT_HOST_ADDR_SPACE_SIZE; #endif opt = VM_EXIT_SAVE_IA32_PAT | VM_EXIT_LOAD_IA32_PAT | -VM_EXIT_ACK_INTR_ON_EXIT; +VM_EXIT_ACK_INTR_ON_EXIT | VM_EXIT_CLEAR_BNDCFGS; if (adjust_vmx_controls(min, opt, MSR_IA32_VMX_EXIT_CTLS, _vmexit_control) 0) return -EIO; @@ -2817,7 +2822,7 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf) _pin_based_exec_control = ~PIN_BASED_POSTED_INTR; min = 0; -opt = VM_ENTRY_LOAD_IA32_PAT; +opt = VM_ENTRY_LOAD_IA32_PAT | VM_ENTRY_LOAD_BNDCFGS; if (adjust_vmx_controls(min, opt, MSR_IA32_VMX_ENTRY_CTLS, _vmentry_control) 0) return -EIO; You need to disable MPX in the guest if the two controls are not available. You can do this, for example, in vmx_cpuid_update. Better: add a mpx_supported field to struct kvm_x86_ops. You can use invpcid_supported as a model. Otherwise, nested VMX is broken. @@ -8636,6 +8641,9 @@ static int __init vmx_init(void) vmx_disable_intercept_for_msr(MSR_IA32_SYSENTER_CS, false); vmx_disable_intercept_for_msr(MSR_IA32_SYSENTER_ESP, false); vmx_disable_intercept_for_msr(MSR_IA32_SYSENTER_EIP, false); +if (boot_cpu_has(X86_FEATURE_MPX)) +vmx_disable_intercept_for_msr(MSR_IA32_BNDCFGS, true); This needs to be done unconditionally. Otherwise, reading/writing BNDCFGS will access a nonexistent VMCS field. Paolo memcpy(vmx_msr_bitmap_legacy_x2apic, vmx_msr_bitmap_legacy, PAGE_SIZE); memcpy(vmx_msr_bitmap_longmode_x2apic,
Re: [Qemu-devel] [PATCH v4 0/8] spapr: bootindex support
On 01/22/2014 09:16 PM, Paolo Bonzini wrote: Il 22/01/2014 05:19, Alexey Kardashevskiy ha scritto: On 12/11/2013 09:22 PM, Alexey Kardashevskiy wrote: With the great help from Paolo, I am presenting yet another try of bootindex support on sPAPR, this time with some QOM fixes. Details are in the commit messages. Please, comment. Thanks. Alexey Kardashevskiy (5): boot: extend get_boot_devices_list() to ignore suffixes spapr-llan: add to boot device list spapr-vio: fix firmware names qdev: introduce FWPathProvider interface spapr: define interface to fix device pathname Hervé Poussineau (1): qom: detect bad reentrance during object_class_foreach Paolo Bonzini (2): qom: do not register interface types in the type table vl: allow customizing the class of /machine hw/core/Makefile.objs | 1 + hw/core/fw-path-provider.c| 34 ++ hw/core/qdev.c| 18 +- hw/net/spapr_llan.c | 3 ++ hw/nvram/fw_cfg.c | 2 +- hw/ppc/spapr.c| 80 ++- hw/ppc/spapr_vio.c| 2 ++ include/hw/boards.h | 1 + include/hw/fw-path-provider.h | 31 + include/sysemu/sysemu.h | 2 +- qom/object.c | 17 +++-- tests/Makefile| 1 + vl.c | 11 -- 13 files changed, 193 insertions(+), 10 deletions(-) create mode 100644 hw/core/fw-path-provider.c create mode 100644 include/hw/fw-path-provider.h Some bits from this went upstream but none of them is mine. What am I missing here? Thanks. No idea, perhaps it's because the same patches were present in multiple series? Alex, are you picking up what's left? Paolo In the Re: [Qemu-devel] [PATCH 2/2] qom: detect bad reentrance during object_class_foreach thread Andreas told me: === Be patient. 1) I am on holidays and thus not available full-time. 2) Alex has already sent out his ppc PULL, so no urgency. 3) As mentioned, I plan to post QOM and CPU PULLs later today. And no, you don't need to repost after parts of your series get applied pretty much unmodified. === So I wonder if I am not just patient enough :) -- Alexey
Re: [Qemu-devel] [PATCH v2] Describe flaws in qcow/qcow2 encryption in the docs
On 01/22/2014 05:28 AM, Daniel P. Berrange wrote: Recommend against any use of QCow/QCow2 encryption, directing users to dm-crypt / LUKS which can meet modern cryptography best practices. Signed-off-by: Daniel P. Berrange berra...@redhat.com --- qemu-doc.texi | 23 --- qemu-img.texi | 23 --- 2 files changed, 40 insertions(+), 6 deletions(-) + +@itemize @minus +@item The AES-CBC cipher is used with predictable initialization vectors based +on the sector number. This makes it vulnerable to chosen plaintext attacks +which can reveal the existence of encrypted data. +@item The user passphrase is directly used as the encryption key. A poorly +choosen or short passphrase will compromise the security of the encryption. s/choosen/chosen/ (both files) +In the event of the passphrase being compromised there is no way to change and still my question whether this deserves a third @item. -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature
Re: [Qemu-devel] outlined TLB lookup on x86
On Wed, Nov 27, 2013 at 8:12 PM, Richard Henderson r...@twiddle.net wrote: On 11/27/2013 08:41 PM, Xin Tong wrote: I am trying to implement a out-of-line TLB lookup for QEMU softmmu-x86-64 on x86-64 machine, potentially for better instruction cache performance, I have a few questions. 1. I see that tcg_out_qemu_ld_slow_path/tcg_out_qemu_st_slow_path are generated when tcg_out_tb_finalize is called. And when a TLB lookup misses, it jumps to the generated slow path and slow path refills the TLB, then load/store and jumps to the next emulated instruction. I am wondering is it easy to outline the code for the slow path. Hard. There's quite a bit of code on that slow path that's unique to the surrounding code context -- which registers contain inputs and outputs, where to continue after slow path. The amount of code that's in the TB slow path now is approximately minimal, as far as I can see. If you've got an idea for improvement, please share. ;-) I am thinking when a TLB misses, the outlined TLB lookup code should generate a call out to the qemu_ld/st_helpers[opc ~MO_SIGN] and rewalk the TLB after its refilled ? This code is off the critical path, so its not as important as the code when TLB hits. That would work for true TLB misses to RAM, but does not work for memory mapped I/O. 2. why not use a TLB or bigger size? currently the TLB has 18 entries. the TLB lookup is 10 x86 instructions , but every miss needs ~450 instructions, i measured this using Intel PIN. so even the miss rate is low (say 3%) the overall time spent in the cpu_x86_handle_mmu_fault is still signifcant. I'd be interested to experiment with different TLB sizes, to see what effect that has on performance. But I suspect that lack of TLB contexts mean that we wind up flushing the TLB more often than real hardware does, and therefore a larger TLB merely takes longer to flush. But be aware that we can't simply make the change universally. E.g. ARM can use an immediate 8-bit operand during the TLB lookup, but would have to use several insns to perform a 9-bit mask. Hi Richard I've done some experiments on increasing the size of the tlb. increasing the size of the tlb from 256 entries to 4096 entries gives significant performance improvement on the specint2006 benchmarks on qemu-system-x86_64 running on a x86_64 linux machine . i am in the process of exploring more tlb sizes and will post the data after i am done. Can you tell me whether ARM is the only architecture that requires special treatment for increasing tlb size beyond 256 entries so that i can whip up a patch to the QEMU mainline. Thank you, Xin I am thinking the tlb may need to be organized in a set associative fashion to reduce conflict miss, e.g. 2 way set associative to reduce the miss rate. or have a victim tlb that is 4 way associative and use x86 simd instructions to do the lookup once the direct-mapped tlb misses. Has anybody done any work on this front ? Even with SIMD, I don't believe you could make the fast-path of a set associative lookup fast. This is the sort of thing for which you really need the dedicated hardware of the real TLB. Feel free to prove me wrong with code, of course. r~
Re: [Qemu-devel] [PATCH uq/master] kvm: always update the MPX model specific register
On Mon, Jan 20, 2014 at 02:25:36PM +0100, Paolo Bonzini wrote: The original patch from Liu Jinsong restricted them to reset or full state updates, but that's unnecessary (and wrong) since the BNDCFGS MSR has no side effects. Why is it necessary to save/restore BNDCFGS MSR on states other than FULL and RESET? Cc: Liu Jinsong jinsong@intel.com Signed-off-by: Paolo Bonzini pbonz...@redhat.com --- target-i386/kvm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 221c8a0..d34981f 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -1161,6 +1161,9 @@ static int kvm_put_msrs(X86CPU *cpu, int level) kvm_msr_entry_set(msrs[n++], MSR_IA32_MISC_ENABLE, env-msr_ia32_misc_enable); } +if (has_msr_bndcfgs) { +kvm_msr_entry_set(msrs[n++], MSR_IA32_BNDCFGS, env-msr_bndcfgs); +} #ifdef TARGET_X86_64 if (lm_capable_kernel) { kvm_msr_entry_set(msrs[n++], MSR_CSTAR, env-cstar); @@ -1224,9 +1227,6 @@ static int kvm_put_msrs(X86CPU *cpu, int level) if (cpu-hyperv_vapic) { kvm_msr_entry_set(msrs[n++], HV_X64_MSR_APIC_ASSIST_PAGE, 0); } -if (has_msr_bndcfgs) { -kvm_msr_entry_set(msrs[n++], MSR_IA32_BNDCFGS, env-msr_bndcfgs); -} /* Note: MSR_IA32_FEATURE_CONTROL is written separately, see * kvm_put_msr_feature_control. */ -- 1.8.3.1 -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [Qemu-devel] [PATCH v2] Describe flaws in qcow/qcow2 encryption in the docs
Daniel P. Berrange berra...@redhat.com writes: The qemu-img.texi / qemu-doc.texi files currently describe the qcow2/qcow2 encryption thus Encryption uses the AES format which is very secure (128 bit keys). Use a long password (16 characters) to get maximum protection. While AES is indeed a strong encryption system, the way that QCow/QCow2 use it results in a poor/weak encryption system. Due to the use of predictable IVs Sector number zero-extended to 128 bits. it is vulnerable to chosen plaintext attacks which can reveal the existance of encrypted data. The direct use of the user passphrase as the encryption key also leads to an inability to change the passphrase of an image. If passphrase is ever compromised the image data will all be vulnerable, since it cannot be re-encrypted. The admin has to clone the image files with a new passphrase and then use a program like shred to secure erase all the old files. Recommend against any use of QCow/QCow2 encryption, directing users to dm-crypt / LUKS which can meet modern cryptography best practices. Signed-off-by: Daniel P. Berrange berra...@redhat.com Amateur crypto. Reviewed-by: Markus Armbruster arm...@redhat.com
Re: [Qemu-devel] [PATCH v2] Describe flaws in qcow/qcow2 encryption in the docs
On Wed, Jan 22, 2014 at 08:24:00AM -0700, Eric Blake wrote: On 01/22/2014 05:28 AM, Daniel P. Berrange wrote: Recommend against any use of QCow/QCow2 encryption, directing users to dm-crypt / LUKS which can meet modern cryptography best practices. Signed-off-by: Daniel P. Berrange berra...@redhat.com --- qemu-doc.texi | 23 --- qemu-img.texi | 23 --- 2 files changed, 40 insertions(+), 6 deletions(-) + +@itemize @minus +@item The AES-CBC cipher is used with predictable initialization vectors based +on the sector number. This makes it vulnerable to chosen plaintext attacks +which can reveal the existence of encrypted data. +@item The user passphrase is directly used as the encryption key. A poorly +choosen or short passphrase will compromise the security of the encryption. s/choosen/chosen/ (both files) +In the event of the passphrase being compromised there is no way to change and still my question whether this deserves a third @item. I was considering this to be a result of using the passphrase as the key. It does however read better if split out, so I've made that change. Daniel -- |: http://berrange.com -o-http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
[Qemu-devel] [PATCH v3] Describe flaws in qcow/qcow2 encryption in the docs
The qemu-img.texi / qemu-doc.texi files currently describe the qcow2/qcow2 encryption thus Encryption uses the AES format which is very secure (128 bit keys). Use a long password (16 characters) to get maximum protection. While AES is indeed a strong encryption system, the way that QCow/QCow2 use it results in a poor/weak encryption system. Due to the use of predictable IVs, based on the sector number extended to 128 bits, it is vulnerable to chosen plaintext attacks which can reveal the existence of encrypted data. The direct use of the user passphrase as the encryption key also leads to an inability to change the passphrase of an image. If passphrase is ever compromised the image data will all be vulnerable, since it cannot be re-encrypted. The admin has to clone the image files with a new passphrase and then use a program like shred to secure erase all the old files. Recommend against any use of QCow/QCow2 encryption, directing users to dm-crypt / LUKS which can meet modern cryptography best practices. Signed-off-by: Daniel P. Berrange berra...@redhat.com Reviewed-by: Markus Armbruster arm...@redhat.com --- qemu-doc.texi | 23 --- qemu-img.texi | 23 --- 2 files changed, 40 insertions(+), 6 deletions(-) Changed in v3: - Addressed feedback/typos from Eric Markus In v2: - Addressed typos reported by Peter Still welcome info about any other flaws qcow2 has in this area that should be documented. diff --git a/qemu-doc.texi b/qemu-doc.texi index 4e9c6e9..6f0b80b 100644 --- a/qemu-doc.texi +++ b/qemu-doc.texi @@ -547,10 +547,27 @@ File name of a base image (see @option{create} subcommand) @item backing_fmt Image format of the base image @item encryption -If this option is set to @code{on}, the image is encrypted. +If this option is set to @code{on}, the image is encrypted with 128-bit AES-CBC. + +The use of encryption in QCow and QCow2 images is considered to be flawed by +modern cryptography standards, suffering from a number of design problems: + +@itemize @minus +@item The AES-CBC cipher is used with predictable initialization vectors based +on the sector number. This makes it vulnerable to chosen plaintext attacks +which can reveal the existence of encrypted data. +@item The user passphrase is directly used as the encryption key. A poorly +chosen or short passphrase will compromise the security of the encryption. +@item In the event of the passphrase being compromised there is no way to +change the passphrase to protect data in any QCow images. The files must +be cloned, using a different encryption passphrase in the new file. The +original file must then be securely erased using a program like shred, +though even this is ineffective with many modern storage technologies. +@end itemize -Encryption uses the AES format which is very secure (128 bit keys). Use -a long password (16 characters) to get maximum protection. +Use of QCow / QCow2 encryption is thus strongly discouraged. Users are +recommended to use an alternative encryption technology such as the +Linux dm-crypt / LUKS system. @item cluster_size Changes the qcow2 cluster size (must be between 512 and 2M). Smaller cluster diff --git a/qemu-img.texi b/qemu-img.texi index 1bba91e..de74fda 100644 --- a/qemu-img.texi +++ b/qemu-img.texi @@ -402,10 +402,27 @@ File name of a base image (see @option{create} subcommand) @item backing_fmt Image format of the base image @item encryption -If this option is set to @code{on}, the image is encrypted. +If this option is set to @code{on}, the image is encrypted with 128-bit AES-CBC. -Encryption uses the AES format which is very secure (128 bit keys). Use -a long password (16 characters) to get maximum protection. +The use of encryption in QCow and QCow2 images is considered to be flawed by +modern cryptography standards, suffering from a number of design problems: + +@itemize @minus +@item The AES-CBC cipher is used with predictable initialization vectors based +on the sector number. This makes it vulnerable to chosen plaintext attacks +which can reveal the existence of encrypted data. +@item The user passphrase is directly used as the encryption key. A poorly +chosen or short passphrase will compromise the security of the encryption. +@item In the event of the passphrase being compromised there is no way to +change the passphrase to protect data in any QCow images. The files must +be cloned, using a different encryption passphrase in the new file. The +original file must then be securely erased using a program like shred, +though even this is ineffective with many modern storage technologies. +@end itemize + +Use of QCow / QCow2 encryption is thus strongly discouraged. Users are +recommended to use an alternative encryption technology such as the +Linux dm-crypt / LUKS system. @item cluster_size Changes the qcow2 cluster size (must be between 512 and 2M). Smaller cluster -- 1.8.4.2
[Qemu-devel] [PATCH] s390: Storage key global access
From: Jason J. Herne jjhe...@us.ibm.com Introduces global access to storage key data so we can set it for each cpu in the S390 cpu initialization routine. Signed-off-by: Jason J. Herne jjhe...@us.ibm.com --- hw/s390x/s390-virtio-ccw.c | 3 +-- hw/s390x/s390-virtio.c | 6 +++--- hw/s390x/s390-virtio.h | 2 +- target-s390x/cpu.h | 3 +++ 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index 733d988..62319b9 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -80,7 +80,6 @@ static void ccw_init(QEMUMachineInitArgs *args) MemoryRegion *sysmem = get_system_memory(); MemoryRegion *ram = g_new(MemoryRegion, 1); int shift = 0; -uint8_t *storage_keys; int ret; VirtualCssBus *css_bus; @@ -112,7 +111,7 @@ static void ccw_init(QEMUMachineInitArgs *args) storage_keys = g_malloc0(my_ram_size / TARGET_PAGE_SIZE); /* init CPUs */ -s390_init_cpus(args-cpu_model, storage_keys); +s390_init_cpus(args-cpu_model); if (kvm_enabled()) { kvm_s390_enable_css_support(s390_cpu_addr2state(0)); diff --git a/hw/s390x/s390-virtio.c b/hw/s390x/s390-virtio.c index 7adf92a..804483f 100644 --- a/hw/s390x/s390-virtio.c +++ b/hw/s390x/s390-virtio.c @@ -53,6 +53,7 @@ static VirtIOS390Bus *s390_bus; static S390CPU **ipi_states; +uint8_t *storage_keys; S390CPU *s390_cpu_addr2state(uint16_t cpu_addr) { @@ -176,7 +177,7 @@ void s390_init_ipl_dev(const char *kernel_filename, qdev_init_nofail(dev); } -void s390_init_cpus(const char *cpu_model, uint8_t *storage_keys) +void s390_init_cpus(const char *cpu_model) { int i; @@ -231,7 +232,6 @@ static void s390_init(QEMUMachineInitArgs *args) MemoryRegion *sysmem = get_system_memory(); MemoryRegion *ram = g_new(MemoryRegion, 1); int shift = 0; -uint8_t *storage_keys; void *virtio_region; hwaddr virtio_region_len; hwaddr virtio_region_start; @@ -273,7 +273,7 @@ static void s390_init(QEMUMachineInitArgs *args) storage_keys = g_malloc0(my_ram_size / TARGET_PAGE_SIZE); /* init CPUs */ -s390_init_cpus(args-cpu_model, storage_keys); +s390_init_cpus(args-cpu_model); /* Create VirtIO network adapters */ s390_create_virtio_net((BusState *)s390_bus, virtio-net-s390); diff --git a/hw/s390x/s390-virtio.h b/hw/s390x/s390-virtio.h index 5c405e7..c1cb042 100644 --- a/hw/s390x/s390-virtio.h +++ b/hw/s390x/s390-virtio.h @@ -20,7 +20,7 @@ typedef int (*s390_virtio_fn)(const uint64_t *args); void s390_register_virtio_hypercall(uint64_t code, s390_virtio_fn fn); -void s390_init_cpus(const char *cpu_model, uint8_t *storage_keys); +void s390_init_cpus(const char *cpu_model); void s390_init_ipl_dev(const char *kernel_filename, const char *kernel_cmdline, const char *initrd_filename, diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h index 68b5ab7..b1432c7 100644 --- a/target-s390x/cpu.h +++ b/target-s390x/cpu.h @@ -381,6 +381,9 @@ static inline void kvm_s390_interrupt_internal(S390CPU *cpu, int type, { } #endif + +extern uint8_t *storage_keys; + S390CPU *s390_cpu_addr2state(uint16_t cpu_addr); void s390_add_running_cpu(S390CPU *cpu); unsigned s390_del_running_cpu(S390CPU *cpu); -- 1.8.3.2
Re: [Qemu-devel] [PATCH 01/13 v7] dump: const-qualify the buf of WriteCoreDumpFunction
On 01/17/14 08:46, qiaonuohan wrote: WriteCoreDumpFunction is a function pointer that points to the function used to write content in buf into core file, so buf should be const-qualify. Signed-off-by: Qiao Nuohan qiaonuo...@cn.fujitsu.com --- dump.c|2 +- include/qom/cpu.h |3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/dump.c b/dump.c index 80a9116..42622de 100644 --- a/dump.c +++ b/dump.c @@ -99,7 +99,7 @@ static void dump_error(DumpState *s, const char *reason) dump_cleanup(s); } -static int fd_write_vmcore(void *buf, size_t size, void *opaque) +static int fd_write_vmcore(const void *buf, size_t size, void *opaque) { DumpState *s = opaque; size_t written_size; diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 7739e00..57b4164 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -28,7 +28,8 @@ #include qemu/tls.h #include qemu/typedefs.h -typedef int (*WriteCoreDumpFunction)(void *buf, size_t size, void *opaque); +typedef int (*WriteCoreDumpFunction)(const void *buf, size_t size, + void *opaque); /** * vaddr: Reviewed-by: Laszlo Ersek ler...@redhat.com
Re: [Qemu-devel] [PATCH v3] Describe flaws in qcow/qcow2 encryption in the docs
On 01/22/2014 08:47 AM, Daniel P. Berrange wrote: The qemu-img.texi / qemu-doc.texi files currently describe the qcow2/qcow2 encryption thus Recommend against any use of QCow/QCow2 encryption, directing users to dm-crypt / LUKS which can meet modern cryptography best practices. Signed-off-by: Daniel P. Berrange berra...@redhat.com Reviewed-by: Markus Armbruster arm...@redhat.com --- qemu-doc.texi | 23 --- qemu-img.texi | 23 --- 2 files changed, 40 insertions(+), 6 deletions(-) Reviewed-by: Eric Blake ebl...@redhat.com -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature
Re: [Qemu-devel] [PATCH 02/13 v7] dump: add argument to write_elfxx_notes
On 01/17/14 08:46, qiaonuohan wrote: write_elf32_notes/wirte_elf64_notes use fd_write_vmcore to write elf notes to vmcore. Adding parameter WriteCoreDumpFunction f makes it available to choose the method of writing elf notes Signed-off-by: Qiao Nuohan qiaonuo...@cn.fujitsu.com Reviewed-by: Laszlo Ersek ler...@redhat.com --- dump.c | 16 1 files changed, 8 insertions(+), 8 deletions(-) OK this seems to be unchanged, so my R-b stands. Laszlo
Re: [Qemu-devel] Simulate different network card vendors
On Wed, Jan 22, 2014 at 06:30:42PM +0530, rajan pathak wrote: But I don't know what are the steps to emulate it for QEMU. Would you suggest me some links where I can get some idea of how emulating a Device for QEMU? Look at existing code in hw/net/*.c, for example e1000.c. Stefan
Re: [Qemu-devel] [PATCH 03/13 v7] dump: add API to write header of flatten format
On 01/17/14 08:46, qiaonuohan wrote: flatten format will be used when writing kdump-compressed format. The format is also used by makedumpfile, you can refer to the following URL to get more detailed information about flatten format of kdump-compressed format: http://sourceforge.net/projects/makedumpfile/ The two functions here are used to write start flat header and end flat header to vmcore, and they will be called later when flatten format is used. struct MakedumpfileHeader stored at the head of vmcore is used to indicate the vmcore is in flatten format. struct MakedumpfileHeader { char signature[16]; /* = makedumpfile */ int64_t type; /* = 1 */ int64_t version;/* = 1 */ }; And struct MakedumpfileDataHeader, with offset and buf_size set to -1, is used to indicate the end of vmcore in flatten format. struct MakedumpfileDataHeader { int64_t offset; /* = -1 */ int64_t buf_size; /* = -1 */ }; Signed-off-by: Qiao Nuohan qiaonuo...@cn.fujitsu.com Reviewed-by: Laszlo Ersek ler...@redhat.com --- dump.c| 42 ++ include/sysemu/dump.h | 17 + 2 files changed, 59 insertions(+), 0 deletions(-) OK, comparing this with v6 02/11, I can see that you changed write_start_flat_header(): - element type of buf from char to uint8_t, - the array is now dynamically allocated, - it is not leaked even in case of error. My R-b stands. Thanks Laszlo
[Qemu-devel] [PATCH v2 06/42] input: qapi: define event types
Define input event types, using qapi. So we get nicely autogenerated types for our input events. And when it comes to qmp support some day things will be alot easier. Types are modeled after the linux input layer. There are separate event types for each value. There is a sync to indicate the end of a event group. Mouse events are splitted into motion events (one for each axis) and button events, which are grouped by sync. Keyboard events are using the existing KeyValue type. Signed-off-by: Gerd Hoffmann kra...@redhat.com --- qapi-schema.json | 76 1 file changed, 76 insertions(+) diff --git a/qapi-schema.json b/qapi-schema.json index f27c48a..38ffc88 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4270,3 +4270,79 @@ # Since: 1.7 ## { 'command': 'blockdev-add', 'data': { 'options': 'BlockdevOptions' } } + +## +# @InputButton +# +# Button of a pointer input device (mouse, tablet). +# +# Since: 2.0 +## +{ 'enum' : 'InputButton', + 'data' : [ 'Left', 'Middle', 'Right', 'WheelUp', 'WheelDown' ] } + +## +# @InputButton +# +# Position axis of a pointer input device (mouse, tablet). +# +# Since: 2.0 +## +{ 'enum' : 'InputAxis', + 'data' : [ 'X', 'Y' ] } + +## +# @InputKeyEvent +# +# Keyboard input event. +# +# @key:Which key this event is for. +# @down: True for key-down and false for key-up events. +# +# Since: 2.0 +## +{ 'type' : 'InputKeyEvent', + 'data' : { 'key' : 'KeyValue', + 'down': 'bool' } } + +## +# @InputBtnEvent +# +# Pointer button input event. +# +# @button: Which button this event is for. +# @down: True for key-down and false for key-up events. +# +# Since: 2.0 +## +{ 'type' : 'InputBtnEvent', + 'data' : { 'button' : 'InputButton', + 'down': 'bool' } } + +## +# @InputMoveEvent +# +# Pointer motion input event. +# +# @axis: Which axis is referenced by @value. +# @value: Pointer position. For absolute coordinates the +# valid range is 0 - 0x7 +# +# Since: 2.0 +## +{ 'type' : 'InputMoveEvent', + 'data' : { 'axis': 'InputAxis', + 'value' : 'int' } } + +## +# @InputEvent +# +# Input event union. +# +# Since: 2.0 +## +{ 'union' : 'InputEvent', + 'data' : { 'key' : 'InputKeyEvent', + 'btn' : 'InputBtnEvent', + 'rel' : 'InputMoveEvent', + 'abs' : 'InputMoveEvent' } } -- 1.8.3.1
[Qemu-devel] [PATCH v2 02/42] sdl2: baum build fix
--- backends/baum.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backends/baum.c b/backends/baum.c index 1132899..665107f 100644 --- a/backends/baum.c +++ b/backends/baum.c @@ -566,7 +566,7 @@ CharDriverState *chr_baum_init(void) BaumDriverState *baum; CharDriverState *chr; brlapi_handle_t *handle; -#ifdef CONFIG_SDL +#if defined(CONFIG_SDL) SDL_COMPILEDVERSION SDL_VERSIONNUM(2, 0, 0) SDL_SysWMinfo info; #endif int tty; @@ -595,7 +595,7 @@ CharDriverState *chr_baum_init(void) goto fail; } -#ifdef CONFIG_SDL +#if defined(CONFIG_SDL) SDL_COMPILEDVERSION SDL_VERSIONNUM(2, 0, 0) memset(info, 0, sizeof(info)); SDL_VERSION(info.version); if (SDL_GetWMInfo(info)) -- 1.8.3.1
[Qemu-devel] [PATCH v2 08/42] input: qapi: add pause key
It's missing. Signed-off-by: Gerd Hoffmann kra...@redhat.com --- qapi-schema.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qapi-schema.json b/qapi-schema.json index eace666..f7c2cc5 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -3391,7 +3391,7 @@ # # Since: 1.3.0 # -# 'unmapped' since 2.0 +# 'unmapped' and 'pause' since 2.0 ## { 'enum': 'QKeyCode', 'data': [ 'unmapped', @@ -3409,7 +3409,7 @@ 'kp_9', 'less', 'f11', 'f12', 'print', 'home', 'pgup', 'pgdn', 'end', 'left', 'up', 'down', 'right', 'insert', 'delete', 'stop', 'again', 'props', 'undo', 'front', 'copy', 'open', 'paste', 'find', 'cut', - 'lf', 'help', 'meta_l', 'meta_r', 'compose' ] } + 'lf', 'help', 'meta_l', 'meta_r', 'compose', 'pause' ] } ## # @KeyValue -- 1.8.3.1
[Qemu-devel] [PATCH v2 07/42] input: qapi: add unmapped key
Simplifies building something - QkeyCode mapping tables. Uninitialized entries can easily identified then. Signed-off-by: Gerd Hoffmann kra...@redhat.com --- qapi-schema.json | 5 - 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/qapi-schema.json b/qapi-schema.json index 38ffc88..eace666 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -3390,9 +3390,12 @@ # This is used by the send-key command. # # Since: 1.3.0 +# +# 'unmapped' since 2.0 ## { 'enum': 'QKeyCode', - 'data': [ 'shift', 'shift_r', 'alt', 'alt_r', 'altgr', 'altgr_r', 'ctrl', + 'data': [ 'unmapped', +'shift', 'shift_r', 'alt', 'alt_r', 'altgr', 'altgr_r', 'ctrl', 'ctrl_r', 'menu', 'esc', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'minus', 'equal', 'backspace', 'tab', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'bracket_left', 'bracket_right', -- 1.8.3.1
[Qemu-devel] [PATCH v2 21/42] input: mouse: add qemu_input_is_absolute()
Same as kbd_mouse_is_absolute(), but using new input core. Signed-off-by: Gerd Hoffmann kra...@redhat.com --- include/ui/input.h | 1 + ui/input.c | 8 2 files changed, 9 insertions(+) diff --git a/include/ui/input.h b/include/ui/input.h index c6f50c2..28afc45 100644 --- a/include/ui/input.h +++ b/include/ui/input.h @@ -41,6 +41,7 @@ void qemu_input_queue_btn(QemuConsole *src, InputButton btn, bool down); void qemu_input_update_buttons(QemuConsole *src, uint32_t *button_map, uint32_t button_old, uint32_t button_new); +bool qemu_input_is_absolute(void); int qemu_input_scale_axis(int value, int size_in, int size_out); InputEvent *qemu_input_event_new_move(InputEventKind kind, InputAxis axis, int value); diff --git a/ui/input.c b/ui/input.c index 2c4d4d6..30a5b70 100644 --- a/ui/input.c +++ b/ui/input.c @@ -183,6 +183,14 @@ void qemu_input_update_buttons(QemuConsole *src, uint32_t *button_map, } } +bool qemu_input_is_absolute(void) +{ +QemuInputHandlerState *s; + +s = qemu_input_find_handler(INPUT_EVENT_MASK_REL | INPUT_EVENT_MASK_ABS); +return (s != NULL) (s-handler-mask INPUT_EVENT_MASK_ABS); +} + int qemu_input_scale_axis(int value, int size_in, int size_out) { if (size_in 2) { -- 1.8.3.1
[Qemu-devel] [PATCH v2 04/42] console: export QemuConsole index, width, height
Add functions to query QemuConsole properties. Signed-off-by: Gerd Hoffmann kra...@redhat.com --- include/ui/console.h | 3 +++ ui/console.c | 24 2 files changed, 27 insertions(+) diff --git a/include/ui/console.h b/include/ui/console.h index 4156a87..8543d18 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -289,6 +289,9 @@ QemuConsole *qemu_console_lookup_by_device(DeviceState *dev); bool qemu_console_is_visible(QemuConsole *con); bool qemu_console_is_graphic(QemuConsole *con); bool qemu_console_is_fixedsize(QemuConsole *con); +int qemu_console_get_index(QemuConsole *con); +int qemu_console_get_width(QemuConsole *con, int fallback); +int qemu_console_get_height(QemuConsole *con, int fallback); void text_consoles_set_display(DisplayState *ds); void console_select(unsigned int index); diff --git a/ui/console.c b/ui/console.c index 502e160..0bbefe5 100644 --- a/ui/console.c +++ b/ui/console.c @@ -1641,6 +1641,30 @@ bool qemu_console_is_fixedsize(QemuConsole *con) return con (con-console_type != TEXT_CONSOLE); } +int qemu_console_get_index(QemuConsole *con) +{ +if (con == NULL) { +con = active_console; +} +return con ? con-index : -1; +} + +int qemu_console_get_width(QemuConsole *con, int fallback) +{ +if (con == NULL) { +con = active_console; +} +return con ? surface_width(con-surface) : fallback; +} + +int qemu_console_get_height(QemuConsole *con, int fallback) +{ +if (con == NULL) { +con = active_console; +} +return con ? surface_height(con-surface) : fallback; +} + static void text_console_set_echo(CharDriverState *chr, bool echo) { QemuConsole *s = chr-opaque; -- 1.8.3.1
[Qemu-devel] [PATCH v2 14/42] input: keyboard: switch sdl ui to new core
Signed-off-by: Gerd Hoffmann kra...@redhat.com --- ui/sdl.c | 27 +-- 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/ui/sdl.c b/ui/sdl.c index 736bb95..c3b8036 100644 --- a/ui/sdl.c +++ b/ui/sdl.c @@ -32,6 +32,7 @@ #include qemu-common.h #include ui/console.h +#include ui/input.h #include sysemu/sysemu.h #include x_keymap.h #include sdl_zoom.h @@ -263,9 +264,7 @@ static void reset_keys(void) int i; for(i = 0; i 256; i++) { if (modifiers_state[i]) { -if (i SCANCODE_GREY) -kbd_put_keycode(SCANCODE_EMUL0); -kbd_put_keycode(i | SCANCODE_UP); +qemu_input_event_send_key_number(dcl-con, i, false); modifiers_state[i] = 0; } } @@ -273,16 +272,12 @@ static void reset_keys(void) static void sdl_process_key(SDL_KeyboardEvent *ev) { -int keycode, v; +int keycode; if (ev-keysym.sym == SDLK_PAUSE) { /* specific case */ -v = 0; -if (ev-type == SDL_KEYUP) -v |= SCANCODE_UP; -kbd_put_keycode(0xe1); -kbd_put_keycode(0x1d | v); -kbd_put_keycode(0x45 | v); +qemu_input_event_send_key_qcode(dcl-con, Q_KEY_CODE_PAUSE, +ev-type == SDL_KEYDOWN); return; } @@ -314,19 +309,15 @@ static void sdl_process_key(SDL_KeyboardEvent *ev) case 0x45: /* num lock */ case 0x3a: /* caps lock */ /* SDL does not send the key up event, so we generate it */ -kbd_put_keycode(keycode); -kbd_put_keycode(keycode | SCANCODE_UP); +qemu_input_event_send_key_number(dcl-con, keycode, true); +qemu_input_event_send_key_number(dcl-con, keycode, false); return; #endif } /* now send the key code */ -if (keycode SCANCODE_GREY) -kbd_put_keycode(SCANCODE_EMUL0); -if (ev-type == SDL_KEYUP) -kbd_put_keycode(keycode | SCANCODE_UP); -else -kbd_put_keycode(keycode SCANCODE_KEYCODEMASK); +qemu_input_event_send_key_number(dcl-con, keycode, + ev-type == SDL_KEYDOWN); } static void sdl_update_caption(void) -- 1.8.3.1
[Qemu-devel] [PATCH v2 09/42] input: add core bits of the new input layer
Register and unregister handlers. Event dispatcher code. Signed-off-by: Gerd Hoffmann kra...@redhat.com --- include/ui/input.h | 32 + ui/Makefile.objs | 2 +- ui/input.c | 83 ++ 3 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 include/ui/input.h create mode 100644 ui/input.c diff --git a/include/ui/input.h b/include/ui/input.h new file mode 100644 index 000..3cf3641 --- /dev/null +++ b/include/ui/input.h @@ -0,0 +1,32 @@ +#ifndef INPUT_H +#define INPUT_H + +#include qapi-types.h + +#define INPUT_EVENT_MASK_KEY (1INPUT_EVENT_KIND_KEY) +#define INPUT_EVENT_MASK_BTN (1INPUT_EVENT_KIND_BTN) +#define INPUT_EVENT_MASK_REL (1INPUT_EVENT_KIND_REL) +#define INPUT_EVENT_MASK_ABS (1INPUT_EVENT_KIND_ABS) + +typedef struct QemuInputHandler QemuInputHandler; +typedef struct QemuInputHandlerState QemuInputHandlerState; + +typedef void (*QemuInputHandlerEvent)(DeviceState *dev, QemuConsole *src, + InputEvent *evt); +typedef void (*QemuInputHandlerSync)(DeviceState *dev); + +struct QemuInputHandler { +const char *name; +uint32_t mask; +QemuInputHandlerEvent event; +QemuInputHandlerSync sync; +}; + +QemuInputHandlerState *qemu_input_handler_register(DeviceState *dev, + QemuInputHandler *handler); +void qemu_input_handler_activate(QemuInputHandlerState *s); +void qemu_input_handler_unregister(QemuInputHandlerState *s); +void qemu_input_event_send(QemuConsole *src, InputEvent *evt); +void qemu_input_event_sync(void); + +#endif /* INPUT_H */ diff --git a/ui/Makefile.objs b/ui/Makefile.objs index 16db07a..e6a5ec1 100644 --- a/ui/Makefile.objs +++ b/ui/Makefile.objs @@ -7,7 +7,7 @@ vnc-obj-$(CONFIG_VNC_SASL) += vnc-auth-sasl.o vnc-obj-$(CONFIG_VNC_WS) += vnc-ws.o vnc-obj-y += vnc-jobs.o -common-obj-y += keymaps.o console.o cursor.o input-legacy.o qemu-pixman.o +common-obj-y += keymaps.o console.o cursor.o input.o input-legacy.o qemu-pixman.o common-obj-$(CONFIG_SPICE) += spice-core.o spice-input.o spice-display.o common-obj-$(CONFIG_SDL) += sdl.o sdl_zoom.o x_keymap.o sdl2.o common-obj-$(CONFIG_COCOA) += cocoa.o diff --git a/ui/input.c b/ui/input.c new file mode 100644 index 000..23c84f7 --- /dev/null +++ b/ui/input.c @@ -0,0 +1,83 @@ +#include sysemu/sysemu.h +#include qapi-types.h +#include ui/input.h + +struct QemuInputHandlerState { +DeviceState *dev; +QemuInputHandler *handler; +int id; +int events; +QTAILQ_ENTRY(QemuInputHandlerState) node; +}; +static QTAILQ_HEAD(, QemuInputHandlerState) handlers = +QTAILQ_HEAD_INITIALIZER(handlers); + +QemuInputHandlerState *qemu_input_handler_register(DeviceState *dev, + QemuInputHandler *handler) +{ +QemuInputHandlerState *s = g_new0(QemuInputHandlerState, 1); +static int id = 1; + +s-dev = dev; +s-handler = handler; +s-id = id++; +QTAILQ_INSERT_TAIL(handlers, s, node); +return s; +} + +void qemu_input_handler_activate(QemuInputHandlerState *s) +{ +QTAILQ_REMOVE(handlers, s, node); +QTAILQ_INSERT_HEAD(handlers, s, node); +} + +void qemu_input_handler_unregister(QemuInputHandlerState *s) +{ +QTAILQ_REMOVE(handlers, s, node); +g_free(s); +} + +static QemuInputHandlerState* +qemu_input_find_handler(uint32_t mask) +{ +QemuInputHandlerState *s; + +QTAILQ_FOREACH(s, handlers, node) { +if (mask s-handler-mask) { +return s; +} +} +return NULL; +} + +void qemu_input_event_send(QemuConsole *src, InputEvent *evt) +{ +QemuInputHandlerState *s; + +if (!runstate_is_running() !runstate_check(RUN_STATE_SUSPENDED)) { +return; +} + +s = qemu_input_find_handler(1 evt-kind); +s-handler-event(s-dev, src, evt); +s-events++; +} + +void qemu_input_event_sync(void) +{ +QemuInputHandlerState *s; + +if (!runstate_is_running() !runstate_check(RUN_STATE_SUSPENDED)) { +return; +} + +QTAILQ_FOREACH(s, handlers, node) { +if (!s-events) { +continue; +} +if (s-handler-sync) { +s-handler-sync(s-dev); +} +s-events = 0; +} +} -- 1.8.3.1
[Qemu-devel] [PATCH v2 00/42] rework input handling, sdl2 support
Hi, This patch series features a reworked input layer and sdl2 support. The input layer moves to a model modeled roughly after the linux event layer. It also uses qapi to create all the data types needed. First, because it is convinient to have all the support code generated, and also to make it easier to integrate with qmp some day. Porting work has only be done on the UI side so far. Input device emulation is still to be done. cocoa ui code has been updated, but is totally untested (not even compiled). Would be great if someone with macos hardware can give it a spin, and send fixup patches if needed. SDL2 consists of dave's original patch with a bunch of cleanups on top. Some of the cleanups depend on the new input layer code, thus the incremental patches are sprinkled all over the patch series for bisectability reasons. v2 fixes a few minor nits pointed out in v1 review. please review test, Gerd Dave Airlie (1): ui/sdl2 : initial port to SDL 2.0 (v2.0) Gerd Hoffmann (41): sdl2: baum build fix sdl2: remove text console logic console: export QemuConsole index,width,height input: rename file to legacy input: qapi: define event types input: qapi: add unmapped key input: qapi: add pause key input: add core bits of the new input layer input: keyboard: add helper functions to core input: keyboard: switch legacy handlers to new core input: keyboard: switch qmp_send_key() to new core. input: keyboard: switch gtk ui to new core input: keyboard: switch sdl ui to new core sdl2: switch keyboard handling to new core input: keyboard: switch vnc ui to new core input: keyboard: switch spice ui to new core input: keyboard: switch curses ui to new core input: mouse: add helpers functions to core input: mouse: add graphic_rotate support input: mouse: add qemu_input_is_absolute() input: mouse: switch legacy handlers to new core input: mouse: switch gtk ui to new core input: mouse: switch sdl ui to new core sdl2: switch mouse handling to new core input: mouse: switch vnc ui to new core input: mouse: switch spice ui to new core input: mouse: switch monitor to new core input: keyboard: switch cocoa ui to new core [untested] input: mouse: switch cocoa ui to new core [untested] input: trace events input-legacy: remove kbd_put_keycode input-legacy: remove kbd_mouse_has_absolute input-legacy: remove kbd_mouse_is_absolute input-legacy: remove kbd_mouse_event input: move mouse mode notifier to new core input: add input_mouse_mode tracepoint sdl2: simplify keymap handling sdl2: codestyle fixups input: move qmp_query_mice to new core input: move do_mouse_set to new core input: remove index_from_keycode (no users) backends/baum.c | 4 +- configure| 23 +- include/ui/console.h | 16 +- include/ui/input.h | 56 monitor.c| 31 +- qapi-schema.json | 83 +- trace-events | 9 + ui/Makefile.objs | 6 +- ui/cocoa.m | 81 +++-- ui/console.c | 24 ++ ui/curses.c | 47 +-- ui/gtk.c | 77 ++--- ui/input-legacy.c| 453 ui/input.c | 684 +++--- ui/sdl.c | 114 --- ui/sdl2-keymap.h | 266 + ui/sdl2.c| 829 +++ ui/sdl_keysym.h | 3 +- ui/spice-input.c | 84 -- ui/vnc.c | 71 ++--- ui/vnc.h | 1 + 21 files changed, 2251 insertions(+), 711 deletions(-) create mode 100644 include/ui/input.h create mode 100644 ui/input-legacy.c create mode 100644 ui/sdl2-keymap.h create mode 100644 ui/sdl2.c -- 1.8.3.1
[Qemu-devel] [PATCH v2 05/42] input: rename file to legacy
Rename ui/input.c to ui/input-legacy.c. We are going to replace it step by step. Signed-off-by: Gerd Hoffmann kra...@redhat.com --- ui/Makefile.objs | 2 +- ui/{input.c = input-legacy.c} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename ui/{input.c = input-legacy.c} (100%) diff --git a/ui/Makefile.objs b/ui/Makefile.objs index 721ad37..16db07a 100644 --- a/ui/Makefile.objs +++ b/ui/Makefile.objs @@ -7,7 +7,7 @@ vnc-obj-$(CONFIG_VNC_SASL) += vnc-auth-sasl.o vnc-obj-$(CONFIG_VNC_WS) += vnc-ws.o vnc-obj-y += vnc-jobs.o -common-obj-y += keymaps.o console.o cursor.o input.o qemu-pixman.o +common-obj-y += keymaps.o console.o cursor.o input-legacy.o qemu-pixman.o common-obj-$(CONFIG_SPICE) += spice-core.o spice-input.o spice-display.o common-obj-$(CONFIG_SDL) += sdl.o sdl_zoom.o x_keymap.o sdl2.o common-obj-$(CONFIG_COCOA) += cocoa.o diff --git a/ui/input.c b/ui/input-legacy.c similarity index 100% rename from ui/input.c rename to ui/input-legacy.c -- 1.8.3.1
[Qemu-devel] [PATCH v2 17/42] input: keyboard: switch spice ui to new core
--- ui/spice-input.c | 22 -- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/ui/spice-input.c b/ui/spice-input.c index 3beb8de..c9df699 100644 --- a/ui/spice-input.c +++ b/ui/spice-input.c @@ -26,12 +26,15 @@ #include qemu-common.h #include ui/qemu-spice.h #include ui/console.h +#include ui/keymaps.h +#include ui/input.h /* keyboard bits */ typedef struct QemuSpiceKbd { SpiceKbdInstance sin; int ledstate; +bool emul0; } QemuSpiceKbd; static void kbd_push_key(SpiceKbdInstance *sin, uint8_t frag); @@ -47,9 +50,24 @@ static const SpiceKbdInterface kbd_interface = { .get_leds = kbd_get_leds, }; -static void kbd_push_key(SpiceKbdInstance *sin, uint8_t frag) +static void kbd_push_key(SpiceKbdInstance *sin, uint8_t scancode) { -kbd_put_keycode(frag); +QemuSpiceKbd *kbd = container_of(sin, QemuSpiceKbd, sin); +int keycode; +bool up; + +if (scancode == SCANCODE_EMUL0) { +kbd-emul0 = true; +return; +} +keycode = scancode ~SCANCODE_UP; +up = scancode SCANCODE_UP; +if (kbd-emul0) { +kbd-emul0 = false; +keycode |= SCANCODE_GREY; +} + +qemu_input_event_send_key_number(NULL, keycode, !up); } static uint8_t kbd_get_leds(SpiceKbdInstance *sin) -- 1.8.3.1
Re: [Qemu-devel] [PATCH] tap-linux: Get features once and use it many times
On Sat, Jan 18, 2014 at 02:38:45PM +0900, Kusanagi Kouichi wrote: Signed-off-by: Kusanagi Kouichi sl...@ac.auone-net.jp --- net/tap-linux.c | 14 -- 1 file changed, 8 insertions(+), 6 deletions(-) Thanks, applied to my net tree: https://github.com/stefanha/qemu/commits/net Stefan
Re: [Qemu-devel] [PATCH 04/13 v7] dump: add API to write vmcore
On 01/17/14 08:46, qiaonuohan wrote: Function is used to write vmcore in flatten format. In flatten format, data is written block by block, and in front of each block, a struct MakedumpfileDataHeader is stored there to indicate the offset and size of the data block. struct MakedumpfileDataHeader { int64_t offset; int64_t buf_size; }; Signed-off-by: Qiao Nuohan qiaonuo...@cn.fujitsu.com Reviewed-by: Laszlo Ersek ler...@redhat.com --- dump.c | 21 + 1 files changed, 21 insertions(+), 0 deletions(-) Compared with v6 03/11, this patch hardwires the flat format (and adapts the commit message too). My R-b stands. Laszlo
[Qemu-devel] [PATCH v2 10/42] input: keyboard: add helper functions to core
A bunch of helper functions to manage keyboard events, to make life simpler for the ui code when submitting keyboard events. Signed-off-by: Gerd Hoffmann kra...@redhat.com --- include/ui/input.h | 5 + ui/input.c | 35 +++ 2 files changed, 40 insertions(+) diff --git a/include/ui/input.h b/include/ui/input.h index 3cf3641..189f131 100644 --- a/include/ui/input.h +++ b/include/ui/input.h @@ -29,4 +29,9 @@ void qemu_input_handler_unregister(QemuInputHandlerState *s); void qemu_input_event_send(QemuConsole *src, InputEvent *evt); void qemu_input_event_sync(void); +InputEvent *qemu_input_event_new_key(KeyValue *key, bool down); +void qemu_input_event_send_key(QemuConsole *src, KeyValue *key, bool down); +void qemu_input_event_send_key_number(QemuConsole *src, int num, bool down); +void qemu_input_event_send_key_qcode(QemuConsole *src, QKeyCode q, bool down); + #endif /* INPUT_H */ diff --git a/ui/input.c b/ui/input.c index 23c84f7..61c8089 100644 --- a/ui/input.c +++ b/ui/input.c @@ -81,3 +81,38 @@ void qemu_input_event_sync(void) s-events = 0; } } + +InputEvent *qemu_input_event_new_key(KeyValue *key, bool down) +{ +InputEvent *evt = g_new0(InputEvent, 1); +evt-key = g_new0(InputKeyEvent, 1); +evt-kind = INPUT_EVENT_KIND_KEY; +evt-key-key = key; +evt-key-down = down; +return evt; +} + +void qemu_input_event_send_key(QemuConsole *src, KeyValue *key, bool down) +{ +InputEvent *evt; +evt = qemu_input_event_new_key(key, down); +qemu_input_event_send(src, evt); +qemu_input_event_sync(); +qapi_free_InputEvent(evt); +} + +void qemu_input_event_send_key_number(QemuConsole *src, int num, bool down) +{ +KeyValue *key = g_new0(KeyValue, 1); +key-kind = KEY_VALUE_KIND_NUMBER; +key-number = num; +qemu_input_event_send_key(src, key, down); +} + +void qemu_input_event_send_key_qcode(QemuConsole *src, QKeyCode q, bool down) +{ +KeyValue *key = g_new0(KeyValue, 1); +key-kind = KEY_VALUE_KIND_QCODE; +key-qcode = q; +qemu_input_event_send_key(src, key, down); +} -- 1.8.3.1
[Qemu-devel] [PATCH v2 16/42] input: keyboard: switch vnc ui to new core
--- ui/vnc.c | 25 ++--- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/ui/vnc.c b/ui/vnc.c index 5601cc3..4658559 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -33,6 +33,7 @@ #include qapi/qmp/types.h #include qmp-commands.h #include qemu/osdep.h +#include ui/input.h #define VNC_REFRESH_INTERVAL_BASE GUI_REFRESH_INTERVAL_DEFAULT #define VNC_REFRESH_INTERVAL_INC 50 @@ -1542,9 +1543,7 @@ static void reset_keys(VncState *vs) int i; for(i = 0; i 256; i++) { if (vs-modifiers_state[i]) { -if (i SCANCODE_GREY) -kbd_put_keycode(SCANCODE_EMUL0); -kbd_put_keycode(i | SCANCODE_UP); +qemu_input_event_send_key_number(vs-vd-dcl.con, i, false); vs-modifiers_state[i] = 0; } } @@ -1553,12 +1552,8 @@ static void reset_keys(VncState *vs) static void press_key(VncState *vs, int keysym) { int keycode = keysym2scancode(vs-vd-kbd_layout, keysym) SCANCODE_KEYMASK; -if (keycode SCANCODE_GREY) -kbd_put_keycode(SCANCODE_EMUL0); -kbd_put_keycode(keycode SCANCODE_KEYCODEMASK); -if (keycode SCANCODE_GREY) -kbd_put_keycode(SCANCODE_EMUL0); -kbd_put_keycode(keycode | SCANCODE_UP); +qemu_input_event_send_key_number(vs-vd-dcl.con, keycode, true); +qemu_input_event_send_key_number(vs-vd-dcl.con, keycode, false); } static int current_led_state(VncState *vs) @@ -1700,12 +1695,7 @@ static void do_key_event(VncState *vs, int down, int keycode, int sym) } if (qemu_console_is_graphic(NULL)) { -if (keycode SCANCODE_GREY) -kbd_put_keycode(SCANCODE_EMUL0); -if (down) -kbd_put_keycode(keycode SCANCODE_KEYCODEMASK); -else -kbd_put_keycode(keycode | SCANCODE_UP); +qemu_input_event_send_key_number(vs-vd-dcl.con, keycode, down); } else { bool numlock = vs-modifiers_state[0x45]; bool control = (vs-modifiers_state[0x1d] || @@ -1826,10 +1816,7 @@ static void vnc_release_modifiers(VncState *vs) if (!vs-modifiers_state[keycode]) { continue; } -if (keycode SCANCODE_GREY) { -kbd_put_keycode(SCANCODE_EMUL0); -} -kbd_put_keycode(keycode | SCANCODE_UP); +qemu_input_event_send_key_number(vs-vd-dcl.con, keycode, false); } } -- 1.8.3.1
[Qemu-devel] [PATCH v2 23/42] input: mouse: switch gtk ui to new core
Signed-off-by: Gerd Hoffmann kra...@redhat.com --- ui/gtk.c | 58 +++--- 1 file changed, 19 insertions(+), 39 deletions(-) diff --git a/ui/gtk.c b/ui/gtk.c index 993a9b5..64a0228 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -190,7 +190,7 @@ static void gd_update_cursor(GtkDisplayState *s, gboolean override) on_vga = gd_on_vga(s); if ((override || on_vga) -(s-full_screen || kbd_mouse_is_absolute() || gd_is_grab_active(s))) { +(s-full_screen || qemu_input_is_absolute() || gd_is_grab_active(s))) { gdk_window_set_cursor(window, s-null_cursor); } else { gdk_window_set_cursor(window, NULL); @@ -576,7 +576,6 @@ static gboolean gd_motion_event(GtkWidget *widget, GdkEventMotion *motion, void *opaque) { GtkDisplayState *s = opaque; -int dx, dy; int x, y; int mx, my; int fbh, fbw; @@ -604,25 +603,21 @@ static gboolean gd_motion_event(GtkWidget *widget, GdkEventMotion *motion, return TRUE; } -if (kbd_mouse_is_absolute()) { -dx = x * 0x7FFF / (surface_width(s-ds) - 1); -dy = y * 0x7FFF / (surface_height(s-ds) - 1); -} else if (s-last_x == -1 || s-last_y == -1) { -dx = 0; -dy = 0; -} else { -dx = x - s-last_x; -dy = y - s-last_y; +if (qemu_input_is_absolute()) { +qemu_input_queue_abs(s-dcl.con, INPUT_AXIS_X, x, + surface_width(s-ds)); +qemu_input_queue_abs(s-dcl.con, INPUT_AXIS_Y, y, + surface_height(s-ds)); +qemu_input_event_sync(); +} else if (s-last_x != -1 s-last_y != -1 gd_is_grab_active(s)) { +qemu_input_queue_rel(s-dcl.con, INPUT_AXIS_X, x - s-last_x); +qemu_input_queue_rel(s-dcl.con, INPUT_AXIS_Y, y - s-last_y); +qemu_input_event_sync(); } - s-last_x = x; s-last_y = y; -if (kbd_mouse_is_absolute() || gd_is_grab_active(s)) { -kbd_mouse_event(dx, dy, 0, s-button_mask); -} - -if (!kbd_mouse_is_absolute() gd_is_grab_active(s)) { +if (!qemu_input_is_absolute() gd_is_grab_active(s)) { GdkScreen *screen = gtk_widget_get_screen(s-drawing_area); int x = (int)motion-x_root; int y = (int)motion-y_root; @@ -667,35 +662,20 @@ static gboolean gd_button_event(GtkWidget *widget, GdkEventButton *button, void *opaque) { GtkDisplayState *s = opaque; -int dx, dy; -int n; +InputButton btn; if (button-button == 1) { -n = 0x01; +btn = INPUT_BUTTON_LEFT; } else if (button-button == 2) { -n = 0x04; +btn = INPUT_BUTTON_MIDDLE; } else if (button-button == 3) { -n = 0x02; -} else { -n = 0x00; -} - -if (button-type == GDK_BUTTON_PRESS) { -s-button_mask |= n; -} else if (button-type == GDK_BUTTON_RELEASE) { -s-button_mask = ~n; -} - -if (kbd_mouse_is_absolute()) { -dx = s-last_x * 0x7FFF / (surface_width(s-ds) - 1); -dy = s-last_y * 0x7FFF / (surface_height(s-ds) - 1); +btn = INPUT_BUTTON_RIGHT; } else { -dx = 0; -dy = 0; +return TRUE; } -kbd_mouse_event(dx, dy, 0, s-button_mask); - +qemu_input_queue_btn(s-dcl.con, btn, button-type == GDK_BUTTON_PRESS); +qemu_input_event_sync(); return TRUE; } -- 1.8.3.1
[Qemu-devel] [PATCH v2 12/42] input: keyboard: switch qmp_send_key() to new core.
Signed-off-by: Gerd Hoffmann kra...@redhat.com --- ui/input-legacy.c | 11 +++ 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/ui/input-legacy.c b/ui/input-legacy.c index 80f4f5c..a4006cc 100644 --- a/ui/input-legacy.c +++ b/ui/input-legacy.c @@ -260,10 +260,8 @@ static void free_keycodes(void) static void release_keys(void *opaque) { while (keycodes_size 0) { -if (keycodes[--keycodes_size] SCANCODE_GREY) { -kbd_put_keycode(SCANCODE_EMUL0); -} -kbd_put_keycode(keycodes[keycodes_size] | SCANCODE_UP); +qemu_input_event_send_key_number(NULL, keycodes[--keycodes_size], + false); } free_keycodes(); @@ -297,10 +295,7 @@ void qmp_send_key(KeyValueList *keys, bool has_hold_time, int64_t hold_time, return; } -if (keycode SCANCODE_GREY) { -kbd_put_keycode(SCANCODE_EMUL0); -} -kbd_put_keycode(keycode SCANCODE_KEYCODEMASK); +qemu_input_event_send_key_number(NULL, keycode, true); keycodes = g_realloc(keycodes, sizeof(int) * (keycodes_size + 1)); keycodes[keycodes_size++] = keycode; -- 1.8.3.1
[Qemu-devel] [PATCH v2 35/42] input-legacy: remove kbd_mouse_event
--- include/ui/console.h | 1 - ui/input-legacy.c| 49 - 2 files changed, 50 deletions(-) diff --git a/include/ui/console.h b/include/ui/console.h index 21b32e4..71a0da3 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -47,7 +47,6 @@ QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func, void *opaque) void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry); void kbd_put_ledstate(int ledstate); -void kbd_mouse_event(int dx, int dy, int dz, int buttons_state); /* Does the current mouse generate absolute events */ void qemu_add_mouse_mode_change_notifier(Notifier *notify); diff --git a/ui/input-legacy.c b/ui/input-legacy.c index 412d401..26ff06f 100644 --- a/ui/input-legacy.c +++ b/ui/input-legacy.c @@ -505,55 +505,6 @@ void kbd_put_ledstate(int ledstate) } } -void kbd_mouse_event(int dx, int dy, int dz, int buttons_state) -{ -QEMUPutMouseEntry *entry; -QEMUPutMouseEvent *mouse_event; -void *mouse_event_opaque; -int width, height; - -if (!runstate_is_running() !runstate_check(RUN_STATE_SUSPENDED)) { -return; -} -if (QTAILQ_EMPTY(mouse_handlers)) { -return; -} - -entry = QTAILQ_FIRST(mouse_handlers); - -mouse_event = entry-qemu_put_mouse_event; -mouse_event_opaque = entry-qemu_put_mouse_event_opaque; - -if (mouse_event) { -if (entry-qemu_put_mouse_event_absolute) { -width = 0x7fff; -height = 0x7fff; -} else { -width = graphic_width - 1; -height = graphic_height - 1; -} - -switch (graphic_rotate) { -case 0: -mouse_event(mouse_event_opaque, -dx, dy, dz, buttons_state); -break; -case 90: -mouse_event(mouse_event_opaque, -width - dy, dx, dz, buttons_state); -break; -case 180: -mouse_event(mouse_event_opaque, -width - dx, height - dy, dz, buttons_state); -break; -case 270: -mouse_event(mouse_event_opaque, -dy, height - dx, dz, buttons_state); -break; -} -} -} - MouseInfoList *qmp_query_mice(Error **errp) { MouseInfoList *mice_list = NULL; -- 1.8.3.1
[Qemu-devel] [PATCH v2 31/42] input: trace events
Signed-off-by: Gerd Hoffmann kra...@redhat.com --- trace-events | 8 ui/input.c | 48 2 files changed, 56 insertions(+) diff --git a/trace-events b/trace-events index 9f4456a..a81d71e 100644 --- a/trace-events +++ b/trace-events @@ -1019,6 +1019,14 @@ gd_switch(int width, int height) width=%d, height=%d gd_update(int x, int y, int w, int h) x=%d, y=%d, w=%d, h=%d gd_key_event(int gdk_keycode, int qemu_keycode, const char *action) translated GDK keycode %d to QEMU keycode %d (%s) +# ui/input.c +input_event_key_number(int conidx, int number, bool down) con %d, key number 0x%d, down %d +input_event_key_qcode(int conidx, const char *qcode, bool down) con %d, key qcode %s, down %d +input_event_btn(int conidx, const char *btn, bool down) con %d, button %s, down %d +input_event_rel(int conidx, const char *axis, int value) con %d, axis %s, value %d +input_event_abs(int conidx, const char *axis, int value) con %d, axis %s, value 0x%x +input_event_sync(void) + # hw/display/vmware_vga.c vmware_value_read(uint32_t index, uint32_t value) index %d, value 0x%x vmware_value_write(uint32_t index, uint32_t value) index %d, value 0x%x diff --git a/ui/input.c b/ui/input.c index 30a5b70..00eef0f 100644 --- a/ui/input.c +++ b/ui/input.c @@ -1,6 +1,8 @@ #include sysemu/sysemu.h #include qapi-types.h +#include trace.h #include ui/input.h +#include ui/console.h struct QemuInputHandlerState { DeviceState *dev; @@ -77,6 +79,48 @@ static void qemu_input_transform_abs_rotate(InputEvent *evt) } } +static void qemu_input_event_trace(QemuConsole *src, InputEvent *evt) +{ +const char *name; +int idx = -1; + +if (src) { +idx = qemu_console_get_index(src); +} +switch (evt-kind) { +case INPUT_EVENT_KIND_KEY: +switch (evt-key-key-kind) { +case KEY_VALUE_KIND_NUMBER: +trace_input_event_key_number(idx, evt-key-key-number, + evt-key-down); +break; +case KEY_VALUE_KIND_QCODE: +name = QKeyCode_lookup[evt-key-key-qcode]; +trace_input_event_key_qcode(idx, name, evt-key-down); +break; +case KEY_VALUE_KIND_MAX: +/* keep gcc happy */ +break; +} +break; +case INPUT_EVENT_KIND_BTN: +name = InputButton_lookup[evt-btn-button]; +trace_input_event_btn(idx, name, evt-btn-down); +break; +case INPUT_EVENT_KIND_REL: +name = InputAxis_lookup[evt-rel-axis]; +trace_input_event_rel(idx, name, evt-rel-value); +break; +case INPUT_EVENT_KIND_ABS: +name = InputAxis_lookup[evt-abs-axis]; +trace_input_event_abs(idx, name, evt-abs-value); +break; +case INPUT_EVENT_KIND_MAX: +/* keep gcc happy */ +break; +} +} + void qemu_input_event_send(QemuConsole *src, InputEvent *evt) { QemuInputHandlerState *s; @@ -85,6 +129,8 @@ void qemu_input_event_send(QemuConsole *src, InputEvent *evt) return; } +qemu_input_event_trace(src, evt); + /* pre processing */ if (graphic_rotate (evt-kind == INPUT_EVENT_KIND_ABS)) { qemu_input_transform_abs_rotate(evt); @@ -104,6 +150,8 @@ void qemu_input_event_sync(void) return; } +trace_input_event_sync(); + QTAILQ_FOREACH(s, handlers, node) { if (!s-events) { continue; -- 1.8.3.1
[Qemu-devel] [PATCH v2 32/42] input-legacy: remove kbd_put_keycode
Signed-off-by: Gerd Hoffmann kra...@redhat.com --- include/ui/console.h | 1 - ui/input-legacy.c| 23 --- 2 files changed, 24 deletions(-) diff --git a/include/ui/console.h b/include/ui/console.h index a3062d0..c7f4e4f 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -46,7 +46,6 @@ void qemu_activate_mouse_event_handler(QEMUPutMouseEntry *entry); QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func, void *opaque); void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry); -void kbd_put_keycode(int keycode); void kbd_put_ledstate(int ledstate); void kbd_mouse_event(int dx, int dy, int dz, int buttons_state); diff --git a/ui/input-legacy.c b/ui/input-legacy.c index dd2dec3..3ac30e2 100644 --- a/ui/input-legacy.c +++ b/ui/input-legacy.c @@ -500,29 +500,6 @@ void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry) g_free(entry); } -void kbd_put_keycode(int keycode) -{ -static bool emul0; -bool up; - -if (keycode == SCANCODE_EMUL0) { -emul0 = true; -return; -} -if (keycode SCANCODE_UP) { -keycode = ~SCANCODE_UP; -up = true; -} else { -up = false; -} -if (emul0) { -keycode |= SCANCODE_GREY; -emul0 = false; -} - -qemu_input_event_send_key_number(NULL, keycode, !up); -} - void kbd_put_ledstate(int ledstate) { QEMUPutLEDEntry *cursor; -- 1.8.3.1
[Qemu-devel] [PATCH v2 30/42] input: mouse: switch cocoa ui to new core [untested]
Signed-off-by: Gerd Hoffmann kra...@redhat.com --- include/ui/console.h | 2 ++ ui/cocoa.m | 63 ++-- 2 files changed, 44 insertions(+), 21 deletions(-) diff --git a/include/ui/console.h b/include/ui/console.h index 8543d18..a3062d0 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -14,6 +14,8 @@ #define MOUSE_EVENT_LBUTTON 0x01 #define MOUSE_EVENT_RBUTTON 0x02 #define MOUSE_EVENT_MBUTTON 0x04 +#define MOUSE_EVENT_WHEELUP 0x08 +#define MOUSE_EVENT_WHEELDN 0x10 /* identical to the ps/2 keyboard bits */ #define QEMU_SCROLL_LOCK_LED (1 0) diff --git a/ui/cocoa.m b/ui/cocoa.m index d4af3e5..146fb21 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -27,6 +27,7 @@ #include qemu-common.h #include ui/console.h +#include ui/input.h #include sysemu/sysemu.h #ifndef MAC_OS_X_VERSION_10_4 @@ -49,14 +50,6 @@ #endif #define cgrect(nsrect) (*(CGRect *)(nsrect)) -#define COCOA_MOUSE_EVENT \ -if (isTabletEnabled) { \ -kbd_mouse_event((int)(p.x * 0x7FFF / (screen.width - 1)), (int)((screen.height - p.y) * 0x7FFF / (screen.height - 1)), 0, buttons); \ -} else if (isMouseGrabbed) { \ -kbd_mouse_event((int)[event deltaX], (int)[event deltaY], 0, buttons); \ -} else { \ -[NSApp sendEvent:event]; \ -} typedef struct { int width; @@ -67,6 +60,7 @@ typedef struct { NSWindow *normalWindow; static DisplayChangeListener *dcl; +static int last_buttons; int gArgc; char **gArgv; @@ -501,6 +495,7 @@ QemuCocoaView *cocoaView; int buttons = 0; int keycode; +bool mouse_event = false; NSPoint p = [event locationInWindow]; switch ([event type]) { @@ -620,7 +615,7 @@ QemuCocoaView *cocoaView; } } } -COCOA_MOUSE_EVENT +mouse_event = true; break; case NSLeftMouseDown: if ([event modifierFlags] NSCommandKeyMask) { @@ -628,15 +623,15 @@ QemuCocoaView *cocoaView; } else { buttons |= MOUSE_EVENT_LBUTTON; } -COCOA_MOUSE_EVENT +mouse_event = true; break; case NSRightMouseDown: buttons |= MOUSE_EVENT_RBUTTON; -COCOA_MOUSE_EVENT +mouse_event = true; break; case NSOtherMouseDown: buttons |= MOUSE_EVENT_MBUTTON; -COCOA_MOUSE_EVENT +mouse_event = true; break; case NSLeftMouseDragged: if ([event modifierFlags] NSCommandKeyMask) { @@ -644,19 +639,19 @@ QemuCocoaView *cocoaView; } else { buttons |= MOUSE_EVENT_LBUTTON; } -COCOA_MOUSE_EVENT +mouse_event = true; break; case NSRightMouseDragged: buttons |= MOUSE_EVENT_RBUTTON; -COCOA_MOUSE_EVENT +mouse_event = true; break; case NSOtherMouseDragged: buttons |= MOUSE_EVENT_MBUTTON; -COCOA_MOUSE_EVENT +mouse_event = true; break; case NSLeftMouseUp: if (isTabletEnabled) { -COCOA_MOUSE_EVENT +mouse_event = true; } else if (!isMouseGrabbed) { if (p.x -1 p.x screen.width p.y -1 p.y screen.height) { [self grabMouse]; @@ -664,18 +659,20 @@ QemuCocoaView *cocoaView; [NSApp sendEvent:event]; } } else { -COCOA_MOUSE_EVENT +mouse_event = true; } break; case NSRightMouseUp: -COCOA_MOUSE_EVENT +mouse_event = true; break; case NSOtherMouseUp: -COCOA_MOUSE_EVENT +mouse_event = true; break; case NSScrollWheel: if (isTabletEnabled || isMouseGrabbed) { -kbd_mouse_event(0, 0, -[event deltaY], 0); +button |= ([event deltaY] 0) ? +MOUSE_EVENT_WHEELUP : MOUSE_EVENT_WHEELDN; +mouse_event = true; } else { [NSApp sendEvent:event]; } @@ -683,6 +680,30 @@ QemuCocoaView *cocoaView; default: [NSApp sendEvent:event]; } + +if (mouse_event) { +if (last_buttons != buttons) { +static uint32_t bmap[INPUT_BUTTON_MAX] = { +[INPUT_BUTTON_LEFT] = MOUSE_EVENT_LBUTTON, +[INPUT_BUTTON_MIDDLE] = MOUSE_EVENT_MBUTTON, +[INPUT_BUTTON_RIGHT] = MOUSE_EVENT_RBUTTON, +[INPUT_BUTTON_WHEEL_UP] = MOUSE_EVENT_WHEELUP, +[INPUT_BUTTON_WHEEL_DOWN] = MOUSE_EVENT_WHEELDN, +}; +qemu_input_update_buttons(con, bmap, last_buttons, buttons);
[Qemu-devel] Intel AVX instructions
Intel AVX instructions have been out for some time since sandy-bridge. Is there value to support it in QEMU. I am thinking abut a google summer of code this year to bring support for AVX/AVX2.0 to QEMU. Xin
[Qemu-devel] [PATCH v2 40/42] input: move qmp_query_mice to new core
Signed-off-by: Gerd Hoffmann kra...@redhat.com --- ui/input-legacy.c | 23 --- ui/input.c| 29 + 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/ui/input-legacy.c b/ui/input-legacy.c index 7f8e72b..7843482 100644 --- a/ui/input-legacy.c +++ b/ui/input-legacy.c @@ -483,29 +483,6 @@ void kbd_put_ledstate(int ledstate) } } -MouseInfoList *qmp_query_mice(Error **errp) -{ -MouseInfoList *mice_list = NULL; -QEMUPutMouseEntry *cursor; -bool current = true; - -QTAILQ_FOREACH(cursor, mouse_handlers, node) { -MouseInfoList *info = g_malloc0(sizeof(*info)); -info-value = g_malloc0(sizeof(*info-value)); -info-value-name = g_strdup(cursor-qemu_put_mouse_event_name); -info-value-index = cursor-index; -info-value-absolute = !!cursor-qemu_put_mouse_event_absolute; -info-value-current = current; - -current = false; - -info-next = mice_list; -mice_list = info; -} - -return mice_list; -} - void do_mouse_set(Monitor *mon, const QDict *qdict) { QEMUPutMouseEntry *cursor; diff --git a/ui/input.c b/ui/input.c index 55449dc..2945a3c 100644 --- a/ui/input.c +++ b/ui/input.c @@ -1,5 +1,6 @@ #include sysemu/sysemu.h #include qapi-types.h +#include qmp-commands.h #include trace.h #include ui/input.h #include ui/console.h @@ -307,3 +308,31 @@ void qemu_remove_mouse_mode_change_notifier(Notifier *notify) { notifier_remove(notify); } + +MouseInfoList *qmp_query_mice(Error **errp) +{ +MouseInfoList *mice_list = NULL; +MouseInfoList *info; +QemuInputHandlerState *s; +bool current = true; + +QTAILQ_FOREACH(s, handlers, node) { +if (!(s-handler-mask + (INPUT_EVENT_MASK_REL | INPUT_EVENT_MASK_ABS))) { +continue; +} + +info = g_new0(MouseInfoList, 1); +info-value = g_new0(MouseInfo, 1); +info-value-index = s-id; +info-value-name = g_strdup(s-handler-name); +info-value-absolute = s-handler-mask INPUT_EVENT_MASK_ABS; +info-value-current = current; + +current = false; +info-next = mice_list; +mice_list = info; +} + +return mice_list; +} -- 1.8.3.1
[Qemu-devel] [PATCH v2 36/42] input: move mouse mode notifier to new core
Signed-off-by: Gerd Hoffmann kra...@redhat.com --- include/ui/console.h | 4 include/ui/input.h | 4 ui/input-legacy.c| 34 +- ui/input.c | 30 ++ 4 files changed, 35 insertions(+), 37 deletions(-) diff --git a/include/ui/console.h b/include/ui/console.h index 71a0da3..9a282cb 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -48,10 +48,6 @@ void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry); void kbd_put_ledstate(int ledstate); -/* Does the current mouse generate absolute events */ -void qemu_add_mouse_mode_change_notifier(Notifier *notify); -void qemu_remove_mouse_mode_change_notifier(Notifier *notify); - struct MouseTransformInfo { /* Touchscreen resolution */ int x; diff --git a/include/ui/input.h b/include/ui/input.h index 28afc45..4976f3d 100644 --- a/include/ui/input.h +++ b/include/ui/input.h @@ -49,4 +49,8 @@ void qemu_input_queue_rel(QemuConsole *src, InputAxis axis, int value); void qemu_input_queue_abs(QemuConsole *src, InputAxis axis, int value, int size); +void qemu_input_check_mode_change(void); +void qemu_add_mouse_mode_change_notifier(Notifier *notify); +void qemu_remove_mouse_mode_change_notifier(Notifier *notify); + #endif /* INPUT_H */ diff --git a/ui/input-legacy.c b/ui/input-legacy.c index 26ff06f..7f8e72b 100644 --- a/ui/input-legacy.c +++ b/ui/input-legacy.c @@ -65,8 +65,6 @@ static QTAILQ_HEAD(, QEMUPutLEDEntry) led_handlers = QTAILQ_HEAD_INITIALIZER(led_handlers); static QTAILQ_HEAD(, QEMUPutMouseEntry) mouse_handlers = QTAILQ_HEAD_INITIALIZER(mouse_handlers); -static NotifierList mouse_mode_notifiers = -NOTIFIER_LIST_INITIALIZER(mouse_mode_notifiers); static const int key_defs[] = { [Q_KEY_CODE_SHIFT] = 0x2a, @@ -364,20 +362,6 @@ void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry) g_free(entry); } -static void check_mode_change(void) -{ -static int current_is_absolute; -int is_absolute; - -is_absolute = qemu_input_is_absolute(); - -if (is_absolute != current_is_absolute) { -notifier_list_notify(mouse_mode_notifiers, NULL); -} - -current_is_absolute = is_absolute; -} - static void legacy_mouse_event(DeviceState *dev, QemuConsole *src, InputEvent *evt) { @@ -448,8 +432,6 @@ QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func, s-s = qemu_input_handler_register((DeviceState *)s, s-h); -check_mode_change(); - return s; } @@ -459,8 +441,6 @@ void qemu_activate_mouse_event_handler(QEMUPutMouseEntry *entry) QTAILQ_INSERT_HEAD(mouse_handlers, entry, node); qemu_input_handler_activate(entry-s); - -check_mode_change(); } void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry) @@ -471,8 +451,6 @@ void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry) g_free(entry-qemu_put_mouse_event_name); g_free(entry); - -check_mode_change(); } QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func, @@ -551,15 +529,5 @@ void do_mouse_set(Monitor *mon, const QDict *qdict) monitor_printf(mon, Mouse at given index not found\n); } -check_mode_change(); -} - -void qemu_add_mouse_mode_change_notifier(Notifier *notify) -{ -notifier_list_add(mouse_mode_notifiers, notify); -} - -void qemu_remove_mouse_mode_change_notifier(Notifier *notify) -{ -notifier_remove(notify); +qemu_input_check_mode_change(); } diff --git a/ui/input.c b/ui/input.c index 00eef0f..a32bcff 100644 --- a/ui/input.c +++ b/ui/input.c @@ -13,6 +13,8 @@ struct QemuInputHandlerState { }; static QTAILQ_HEAD(, QemuInputHandlerState) handlers = QTAILQ_HEAD_INITIALIZER(handlers); +static NotifierList mouse_mode_notifiers = +NOTIFIER_LIST_INITIALIZER(mouse_mode_notifiers); QemuInputHandlerState *qemu_input_handler_register(DeviceState *dev, QemuInputHandler *handler) @@ -24,6 +26,8 @@ QemuInputHandlerState *qemu_input_handler_register(DeviceState *dev, s-handler = handler; s-id = id++; QTAILQ_INSERT_TAIL(handlers, s, node); + +qemu_input_check_mode_change(); return s; } @@ -31,12 +35,14 @@ void qemu_input_handler_activate(QemuInputHandlerState *s) { QTAILQ_REMOVE(handlers, s, node); QTAILQ_INSERT_HEAD(handlers, s, node); +qemu_input_check_mode_change(); } void qemu_input_handler_unregister(QemuInputHandlerState *s) { QTAILQ_REMOVE(handlers, s, node); g_free(s); +qemu_input_check_mode_change(); } static QemuInputHandlerState* @@ -276,3 +282,27 @@ void qemu_input_queue_abs(QemuConsole *src, InputAxis axis, int value, int size) qemu_input_event_send(src, evt); qapi_free_InputEvent(evt); } + +void qemu_input_check_mode_change(void) +{ +static int current_is_absolute; +int
Re: [Qemu-devel] outlined TLB lookup on x86
On 01/22/2014 07:28 AM, Xin Tong wrote: Can you tell me whether ARM is the only architecture that requires special treatment for increasing tlb size beyond 256 entries so that i can whip up a patch to the QEMU mainline. The major constraint for the non-arm ports is CPU_TLB_ENTRY_SIZE + CPU_TLB_BITS immediate bit size I.e. (CPU_TLB_SIZE - 1) CPU_TLB_ENTRY_BITS is representable as an immediate within an AND instruction. MIPS has a 16-bit unsigned immediate, and as written would generate bad code for CPU_TLB_BITS 11. I386 has a 32-bit signed immediate, and would generate bad code for CPU_TLB_BITS 26. Though I can't imagine you want to make it that big. SPARC has a 13-bit signed immediate, But it's written with a routine which checks the size of the constant and loads it if necessary. Which is good, because that's clearly already happening for CPU_TLB_BITS 7. AArch64, ia64, ppc, ppc64 all use fully capable extract-bit-field type insns and could handle any change you make. S390 is written using generic routines like sparc, so it won't fail with any change. It ought to be adjusted to use the extract-bit-field type insns that exist in the current generation of machines. The oldest generation of machine would have reduced performance with CPU_TLB_BITS 11. ARM is also a case in which armv6t2 and later could be written with an extract-bit-field insn, but previous versions would need to use 2 insns to form the constant. But at least we'd be able to combine the shift and and insns. r~
Re: [Qemu-devel] [PATCH uq/master] kvm: always update the MPX model specific register
Il 22/01/2014 16:29, Marcelo Tosatti ha scritto: The original patch from Liu Jinsong restricted them to reset or full state updates, but that's unnecessary (and wrong) since the BNDCFGS MSR has no side effects. Why is it necessary to save/restore BNDCFGS MSR on states other than FULL and RESET? Yes, nothing in QEMU except reset will touch the MSR, but this applies also to all the other MSRs that are saved unconditionally. It's nice to be able to poke them with gdb, and saving/restoring the MSR provides that. Paolo
[Qemu-devel] [PATCH v2 34/42] input-legacy: remove kbd_mouse_is_absolute
--- include/ui/console.h | 1 - ui/input-legacy.c| 11 +-- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/include/ui/console.h b/include/ui/console.h index 53e956d..21b32e4 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -50,7 +50,6 @@ void kbd_put_ledstate(int ledstate); void kbd_mouse_event(int dx, int dy, int dz, int buttons_state); /* Does the current mouse generate absolute events */ -int kbd_mouse_is_absolute(void); void qemu_add_mouse_mode_change_notifier(Notifier *notify); void qemu_remove_mouse_mode_change_notifier(Notifier *notify); diff --git a/ui/input-legacy.c b/ui/input-legacy.c index 22796fa..412d401 100644 --- a/ui/input-legacy.c +++ b/ui/input-legacy.c @@ -369,7 +369,7 @@ static void check_mode_change(void) static int current_is_absolute; int is_absolute; -is_absolute = kbd_mouse_is_absolute(); +is_absolute = qemu_input_is_absolute(); if (is_absolute != current_is_absolute) { notifier_list_notify(mouse_mode_notifiers, NULL); @@ -554,15 +554,6 @@ void kbd_mouse_event(int dx, int dy, int dz, int buttons_state) } } -int kbd_mouse_is_absolute(void) -{ -if (QTAILQ_EMPTY(mouse_handlers)) { -return 0; -} - -return QTAILQ_FIRST(mouse_handlers)-qemu_put_mouse_event_absolute; -} - MouseInfoList *qmp_query_mice(Error **errp) { MouseInfoList *mice_list = NULL; -- 1.8.3.1
[Qemu-devel] [PATCH v2 20/42] input: mouse: add graphic_rotate support
Transform absolute mouse events according to graphic_rotate. Legacy input code does it for both absolute and relative events, but the logic is broken for relative coordinates, so this is most likely not used anyway. Signed-off-by: Gerd Hoffmann kra...@redhat.com --- ui/input.c | 33 + 1 file changed, 33 insertions(+) diff --git a/ui/input.c b/ui/input.c index a02172e..2c4d4d6 100644 --- a/ui/input.c +++ b/ui/input.c @@ -50,6 +50,33 @@ qemu_input_find_handler(uint32_t mask) return NULL; } +static void qemu_input_transform_abs_rotate(InputEvent *evt) +{ +switch (graphic_rotate) { +case 90: +if (evt-abs-axis == INPUT_AXIS_X) { +evt-abs-axis = INPUT_AXIS_Y; +} +if (evt-abs-axis == INPUT_AXIS_Y) { +evt-abs-axis = INPUT_AXIS_X; +evt-abs-axis = INPUT_EVENT_ABS_SIZE - 1 - evt-abs-axis; +} +break; +case 180: +evt-abs-axis = INPUT_EVENT_ABS_SIZE - 1 - evt-abs-axis; +break; +case 270: +if (evt-abs-axis == INPUT_AXIS_X) { +evt-abs-axis = INPUT_AXIS_Y; +evt-abs-axis = INPUT_EVENT_ABS_SIZE - 1 - evt-abs-axis; +} +if (evt-abs-axis == INPUT_AXIS_Y) { +evt-abs-axis = INPUT_AXIS_X; +} +break; +} +} + void qemu_input_event_send(QemuConsole *src, InputEvent *evt) { QemuInputHandlerState *s; @@ -58,6 +85,12 @@ void qemu_input_event_send(QemuConsole *src, InputEvent *evt) return; } +/* pre processing */ +if (graphic_rotate (evt-kind == INPUT_EVENT_KIND_ABS)) { +qemu_input_transform_abs_rotate(evt); +} + +/* send event */ s = qemu_input_find_handler(1 evt-kind); s-handler-event(s-dev, src, evt); s-events++; -- 1.8.3.1
[Qemu-devel] [PATCH v2 42/42] input: remove index_from_keycode (no users)
Signed-off-by: Gerd Hoffmann kra...@redhat.com --- include/ui/console.h | 1 - ui/input-legacy.c| 14 -- 2 files changed, 15 deletions(-) diff --git a/include/ui/console.h b/include/ui/console.h index 9a282cb..3bf69ee 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -329,7 +329,6 @@ void curses_display_init(DisplayState *ds, int full_screen); /* input.c */ int index_from_key(const char *key); -int index_from_keycode(int code); /* gtk.c */ void early_gtk_display_init(void); diff --git a/ui/input-legacy.c b/ui/input-legacy.c index b51e6ad..f38984b 100644 --- a/ui/input-legacy.c +++ b/ui/input-legacy.c @@ -220,20 +220,6 @@ int index_from_key(const char *key) return i; } -int index_from_keycode(int code) -{ -int i; - -for (i = 0; i Q_KEY_CODE_MAX; i++) { -if (key_defs[i] == code) { -break; -} -} - -/* Return Q_KEY_CODE_MAX if the code is invalid */ -return i; -} - static int *keycodes; static int keycodes_size; static QEMUTimer *key_timer; -- 1.8.3.1
Re: [Qemu-devel] [PATCH v11 00/11] Drop in_use from BlockDriverState and enable point-in-time snapshot exporting over NBD
On Wed, Jan 08, 2014 at 06:07:41PM +0800, Fam Zheng wrote: This series adds for point-in-time snapshot NBD exporting based on blockdev-backup (variant of drive-backup with existing device as target). We get a thin point-in-time snapshot by COW mechanism of drive-backup, and export it through built in NBD server. The steps are as below: What's the status on this? Kevin? Is this going to get merged sometime soonish? Thanks, Ian [snip]
[Qemu-devel] [PATCH v2 38/42] sdl2: simplify keymap handling
sdl2 gives us scancodes (i.e. identifies keys by location not by keysym mapped to it). We can map them directly to QKeyCodes, pass them on to the new input core and be done with it. No need to jump though any keymap hops. Zap the code. Also operate directly on SDL scancodes for any hotkeys. Signed-off-by: Gerd Hoffmann kra...@redhat.com --- ui/sdl2-keymap.h | 266 +++ ui/sdl2.c| 147 ++-- ui/sdl2_scancode_translate.h | 260 -- 3 files changed, 298 insertions(+), 375 deletions(-) create mode 100644 ui/sdl2-keymap.h delete mode 100644 ui/sdl2_scancode_translate.h diff --git a/ui/sdl2-keymap.h b/ui/sdl2-keymap.h new file mode 100644 index 000..5a12f45 --- /dev/null +++ b/ui/sdl2-keymap.h @@ -0,0 +1,266 @@ + +/* map SDL2 scancodes to QKeyCode */ + +static const int sdl2_scancode_to_qcode[SDL_NUM_SCANCODES] = { +[SDL_SCANCODE_A] = Q_KEY_CODE_A, +[SDL_SCANCODE_B] = Q_KEY_CODE_B, +[SDL_SCANCODE_C] = Q_KEY_CODE_C, +[SDL_SCANCODE_D] = Q_KEY_CODE_D, +[SDL_SCANCODE_E] = Q_KEY_CODE_E, +[SDL_SCANCODE_F] = Q_KEY_CODE_F, +[SDL_SCANCODE_G] = Q_KEY_CODE_G, +[SDL_SCANCODE_H] = Q_KEY_CODE_H, +[SDL_SCANCODE_I] = Q_KEY_CODE_I, +[SDL_SCANCODE_J] = Q_KEY_CODE_J, +[SDL_SCANCODE_K] = Q_KEY_CODE_K, +[SDL_SCANCODE_L] = Q_KEY_CODE_L, +[SDL_SCANCODE_M] = Q_KEY_CODE_M, +[SDL_SCANCODE_N] = Q_KEY_CODE_N, +[SDL_SCANCODE_O] = Q_KEY_CODE_O, +[SDL_SCANCODE_P] = Q_KEY_CODE_P, +[SDL_SCANCODE_Q] = Q_KEY_CODE_Q, +[SDL_SCANCODE_R] = Q_KEY_CODE_R, +[SDL_SCANCODE_S] = Q_KEY_CODE_S, +[SDL_SCANCODE_T] = Q_KEY_CODE_T, +[SDL_SCANCODE_U] = Q_KEY_CODE_U, +[SDL_SCANCODE_V] = Q_KEY_CODE_V, +[SDL_SCANCODE_W] = Q_KEY_CODE_W, +[SDL_SCANCODE_X] = Q_KEY_CODE_X, +[SDL_SCANCODE_Y] = Q_KEY_CODE_Y, +[SDL_SCANCODE_Z] = Q_KEY_CODE_Z, + +[SDL_SCANCODE_1] = Q_KEY_CODE_1, +[SDL_SCANCODE_2] = Q_KEY_CODE_2, +[SDL_SCANCODE_3] = Q_KEY_CODE_3, +[SDL_SCANCODE_4] = Q_KEY_CODE_4, +[SDL_SCANCODE_5] = Q_KEY_CODE_5, +[SDL_SCANCODE_6] = Q_KEY_CODE_6, +[SDL_SCANCODE_7] = Q_KEY_CODE_7, +[SDL_SCANCODE_8] = Q_KEY_CODE_8, +[SDL_SCANCODE_9] = Q_KEY_CODE_9, +[SDL_SCANCODE_0] = Q_KEY_CODE_0, + +[SDL_SCANCODE_RETURN]= Q_KEY_CODE_RET, +[SDL_SCANCODE_ESCAPE]= Q_KEY_CODE_ESC, +[SDL_SCANCODE_BACKSPACE] = Q_KEY_CODE_BACKSPACE, +[SDL_SCANCODE_TAB] = Q_KEY_CODE_TAB, +[SDL_SCANCODE_SPACE] = Q_KEY_CODE_SPC, +[SDL_SCANCODE_MINUS] = Q_KEY_CODE_MINUS, +[SDL_SCANCODE_EQUALS]= Q_KEY_CODE_EQUAL, +[SDL_SCANCODE_LEFTBRACKET] = Q_KEY_CODE_BRACKET_LEFT, +[SDL_SCANCODE_RIGHTBRACKET] = Q_KEY_CODE_BRACKET_RIGHT, +[SDL_SCANCODE_BACKSLASH] = Q_KEY_CODE_BACKSLASH, +#if 0 +[SDL_SCANCODE_NONUSHASH] = Q_KEY_CODE_NONUSHASH, +#endif +[SDL_SCANCODE_SEMICOLON] = Q_KEY_CODE_SEMICOLON, +[SDL_SCANCODE_APOSTROPHE]= Q_KEY_CODE_APOSTROPHE, +[SDL_SCANCODE_GRAVE] = Q_KEY_CODE_GRAVE_ACCENT, +[SDL_SCANCODE_COMMA] = Q_KEY_CODE_COMMA, +[SDL_SCANCODE_PERIOD]= Q_KEY_CODE_DOT, +[SDL_SCANCODE_SLASH] = Q_KEY_CODE_SLASH, +[SDL_SCANCODE_CAPSLOCK] = Q_KEY_CODE_CAPS_LOCK, + +[SDL_SCANCODE_F1]= Q_KEY_CODE_F1, +[SDL_SCANCODE_F2]= Q_KEY_CODE_F2, +[SDL_SCANCODE_F3]= Q_KEY_CODE_F3, +[SDL_SCANCODE_F4]= Q_KEY_CODE_F4, +[SDL_SCANCODE_F5]= Q_KEY_CODE_F5, +[SDL_SCANCODE_F6]= Q_KEY_CODE_F6, +[SDL_SCANCODE_F7]= Q_KEY_CODE_F7, +[SDL_SCANCODE_F8]= Q_KEY_CODE_F8, +[SDL_SCANCODE_F9]= Q_KEY_CODE_F9, +[SDL_SCANCODE_F10] = Q_KEY_CODE_F10, +[SDL_SCANCODE_F11] = Q_KEY_CODE_F11, +[SDL_SCANCODE_F12] = Q_KEY_CODE_F12, + +[SDL_SCANCODE_PRINTSCREEN] = Q_KEY_CODE_PRINT, +[SDL_SCANCODE_SCROLLLOCK]= Q_KEY_CODE_SCROLL_LOCK, +[SDL_SCANCODE_PAUSE] = Q_KEY_CODE_PAUSE, +[SDL_SCANCODE_INSERT]= Q_KEY_CODE_INSERT, +[SDL_SCANCODE_HOME] = Q_KEY_CODE_HOME, +[SDL_SCANCODE_PAGEUP]
Re: [Qemu-devel] outlined TLB lookup on x86
On 22 January 2014 15:28, Xin Tong trent.t...@gmail.com wrote: On Wed, Nov 27, 2013 at 8:12 PM, Richard Henderson r...@twiddle.net wrote: I'd be interested to experiment with different TLB sizes, to see what effect that has on performance. But I suspect that lack of TLB contexts mean that we wind up flushing the TLB more often than real hardware does, and therefore a larger TLB merely takes longer to flush. I've done some experiments on increasing the size of the tlb. increasing the size of the tlb from 256 entries to 4096 entries gives significant performance improvement on the specint2006 benchmarks on qemu-system-x86_64 running on a x86_64 linux machine . i am in the process of exploring more tlb sizes and will post the data after i am done. Of course a single big benchmark program is probably the best case for not having lots of TLB flushing. It would probably also be instructive to benchmark other cases, like OS bootup, running multiple different programs simultaneously and system call heavy workloads. Has anybody ever looked at implementing proper TLB contexts? thanks -- PMM
[Qemu-devel] [PATCH v2 41/42] input: move do_mouse_set to new core
This removes the last user of the lecagy input mouse handler list, so we can remove more legacy bits with this. Signed-off-by: Gerd Hoffmann kra...@redhat.com --- ui/input-legacy.c | 43 --- ui/input.c| 21 + 2 files changed, 21 insertions(+), 43 deletions(-) diff --git a/ui/input-legacy.c b/ui/input-legacy.c index 7843482..b51e6ad 100644 --- a/ui/input-legacy.c +++ b/ui/input-legacy.c @@ -35,12 +35,6 @@ struct QEMUPutMouseEntry { QEMUPutMouseEvent *qemu_put_mouse_event; void *qemu_put_mouse_event_opaque; int qemu_put_mouse_event_absolute; -char *qemu_put_mouse_event_name; - -int index; - -/* used internally by qemu for handling mice */ -QTAILQ_ENTRY(QEMUPutMouseEntry) node; /* new input core */ QemuInputHandler h; @@ -412,17 +406,12 @@ QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func, const char *name) { QEMUPutMouseEntry *s; -static int mouse_index = 0; s = g_malloc0(sizeof(QEMUPutMouseEntry)); s-qemu_put_mouse_event = func; s-qemu_put_mouse_event_opaque = opaque; s-qemu_put_mouse_event_absolute = absolute; -s-qemu_put_mouse_event_name = g_strdup(name); -s-index = mouse_index++; - -QTAILQ_INSERT_TAIL(mouse_handlers, s, node); s-h.name = name; s-h.mask = INPUT_EVENT_MASK_BTN | @@ -437,19 +426,13 @@ QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func, void qemu_activate_mouse_event_handler(QEMUPutMouseEntry *entry) { -QTAILQ_REMOVE(mouse_handlers, entry, node); -QTAILQ_INSERT_HEAD(mouse_handlers, entry, node); - qemu_input_handler_activate(entry-s); } void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry) { -QTAILQ_REMOVE(mouse_handlers, entry, node); - qemu_input_handler_unregister(entry-s); -g_free(entry-qemu_put_mouse_event_name); g_free(entry); } @@ -482,29 +465,3 @@ void kbd_put_ledstate(int ledstate) cursor-put_led(cursor-opaque, ledstate); } } - -void do_mouse_set(Monitor *mon, const QDict *qdict) -{ -QEMUPutMouseEntry *cursor; -int index = qdict_get_int(qdict, index); -int found = 0; - -if (QTAILQ_EMPTY(mouse_handlers)) { -monitor_printf(mon, No mouse devices connected\n); -return; -} - -QTAILQ_FOREACH(cursor, mouse_handlers, node) { -if (cursor-index == index) { -found = 1; -qemu_activate_mouse_event_handler(cursor); -break; -} -} - -if (!found) { -monitor_printf(mon, Mouse at given index not found\n); -} - -qemu_input_check_mode_change(); -} diff --git a/ui/input.c b/ui/input.c index 2945a3c..575c50e 100644 --- a/ui/input.c +++ b/ui/input.c @@ -336,3 +336,24 @@ MouseInfoList *qmp_query_mice(Error **errp) return mice_list; } + +void do_mouse_set(Monitor *mon, const QDict *qdict) +{ +QemuInputHandlerState *s; +int index = qdict_get_int(qdict, index); +int found = 0; + +QTAILQ_FOREACH(s, handlers, node) { +if (s-id == index) { +found = 1; +qemu_input_handler_activate(s); +break; +} +} + +if (!found) { +monitor_printf(mon, Mouse at given index not found\n); +} + +qemu_input_check_mode_change(); +} -- 1.8.3.1
[Qemu-devel] [PATCH v2 19/42] input: mouse: add helpers functions to core
Likewise a bunch of helper functions to manage mouse button and movement events, again to make life easier for the ui code. Signed-off-by: Gerd Hoffmann kra...@redhat.com --- include/ui/input.h | 14 +++ ui/input.c | 71 ++ 2 files changed, 85 insertions(+) diff --git a/include/ui/input.h b/include/ui/input.h index 189f131..c6f50c2 100644 --- a/include/ui/input.h +++ b/include/ui/input.h @@ -8,6 +8,8 @@ #define INPUT_EVENT_MASK_REL (1INPUT_EVENT_KIND_REL) #define INPUT_EVENT_MASK_ABS (1INPUT_EVENT_KIND_ABS) +#define INPUT_EVENT_ABS_SIZE 0x8000 + typedef struct QemuInputHandler QemuInputHandler; typedef struct QemuInputHandlerState QemuInputHandlerState; @@ -34,4 +36,16 @@ void qemu_input_event_send_key(QemuConsole *src, KeyValue *key, bool down); void qemu_input_event_send_key_number(QemuConsole *src, int num, bool down); void qemu_input_event_send_key_qcode(QemuConsole *src, QKeyCode q, bool down); +InputEvent *qemu_input_event_new_btn(InputButton btn, bool down); +void qemu_input_queue_btn(QemuConsole *src, InputButton btn, bool down); +void qemu_input_update_buttons(QemuConsole *src, uint32_t *button_map, + uint32_t button_old, uint32_t button_new); + +int qemu_input_scale_axis(int value, int size_in, int size_out); +InputEvent *qemu_input_event_new_move(InputEventKind kind, + InputAxis axis, int value); +void qemu_input_queue_rel(QemuConsole *src, InputAxis axis, int value); +void qemu_input_queue_abs(QemuConsole *src, InputAxis axis, + int value, int size); + #endif /* INPUT_H */ diff --git a/ui/input.c b/ui/input.c index 61c8089..a02172e 100644 --- a/ui/input.c +++ b/ui/input.c @@ -116,3 +116,74 @@ void qemu_input_event_send_key_qcode(QemuConsole *src, QKeyCode q, bool down) key-qcode = q; qemu_input_event_send_key(src, key, down); } + +InputEvent *qemu_input_event_new_btn(InputButton btn, bool down) +{ +InputEvent *evt = g_new0(InputEvent, 1); +evt-btn = g_new0(InputBtnEvent, 1); +evt-kind = INPUT_EVENT_KIND_BTN; +evt-btn-button = btn; +evt-btn-down = down; +return evt; +} + +void qemu_input_queue_btn(QemuConsole *src, InputButton btn, bool down) +{ +InputEvent *evt; +evt = qemu_input_event_new_btn(btn, down); +qemu_input_event_send(src, evt); +qapi_free_InputEvent(evt); +} + +void qemu_input_update_buttons(QemuConsole *src, uint32_t *button_map, + uint32_t button_old, uint32_t button_new) +{ +InputButton btn; +uint32_t mask; + +for (btn = 0; btn INPUT_BUTTON_MAX; btn++) { +mask = button_map[btn]; +if ((button_old mask) == (button_new mask)) { +continue; +} +qemu_input_queue_btn(src, btn, button_new mask); +} +} + +int qemu_input_scale_axis(int value, int size_in, int size_out) +{ +if (size_in 2) { +return size_out / 2; +} +return (int64_t)value * (size_out - 1) / (size_in - 1); +} + +InputEvent *qemu_input_event_new_move(InputEventKind kind, + InputAxis axis, int value) +{ +InputEvent *evt = g_new0(InputEvent, 1); +InputMoveEvent *move = g_new0(InputMoveEvent, 1); + +evt-kind = kind; +evt-data = move; +move-axis = axis; +move-value = value; +return evt; +} + +void qemu_input_queue_rel(QemuConsole *src, InputAxis axis, int value) +{ +InputEvent *evt; +evt = qemu_input_event_new_move(INPUT_EVENT_KIND_REL, axis, value); +qemu_input_event_send(src, evt); +qapi_free_InputEvent(evt); +} + +void qemu_input_queue_abs(QemuConsole *src, InputAxis axis, int value, int size) +{ +InputEvent *evt; +int scaled = qemu_input_scale_axis(value, size, INPUT_EVENT_ABS_SIZE); +evt = qemu_input_event_new_move(INPUT_EVENT_KIND_ABS, axis, scaled); +qemu_input_event_send(src, evt); +qapi_free_InputEvent(evt); +} -- 1.8.3.1
[Qemu-devel] [PATCH v2 33/42] input-legacy: remove kbd_mouse_has_absolute
Signed-off-by: Gerd Hoffmann kra...@redhat.com --- include/ui/console.h | 3 --- ui/input-legacy.c| 21 ++--- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/include/ui/console.h b/include/ui/console.h index c7f4e4f..53e956d 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -54,9 +54,6 @@ int kbd_mouse_is_absolute(void); void qemu_add_mouse_mode_change_notifier(Notifier *notify); void qemu_remove_mouse_mode_change_notifier(Notifier *notify); -/* Of all the mice, is there one that generates absolute events */ -int kbd_mouse_has_absolute(void); - struct MouseTransformInfo { /* Touchscreen resolution */ int x; diff --git a/ui/input-legacy.c b/ui/input-legacy.c index 3ac30e2..22796fa 100644 --- a/ui/input-legacy.c +++ b/ui/input-legacy.c @@ -366,20 +366,16 @@ void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry) static void check_mode_change(void) { -static int current_is_absolute, current_has_absolute; +static int current_is_absolute; int is_absolute; -int has_absolute; is_absolute = kbd_mouse_is_absolute(); -has_absolute = kbd_mouse_has_absolute(); -if (is_absolute != current_is_absolute || -has_absolute != current_has_absolute) { +if (is_absolute != current_is_absolute) { notifier_list_notify(mouse_mode_notifiers, NULL); } current_is_absolute = is_absolute; -current_has_absolute = has_absolute; } static void legacy_mouse_event(DeviceState *dev, QemuConsole *src, @@ -567,19 +563,6 @@ int kbd_mouse_is_absolute(void) return QTAILQ_FIRST(mouse_handlers)-qemu_put_mouse_event_absolute; } -int kbd_mouse_has_absolute(void) -{ -QEMUPutMouseEntry *entry; - -QTAILQ_FOREACH(entry, mouse_handlers, node) { -if (entry-qemu_put_mouse_event_absolute) { -return 1; -} -} - -return 0; -} - MouseInfoList *qmp_query_mice(Error **errp) { MouseInfoList *mice_list = NULL; -- 1.8.3.1
[Qemu-devel] [PATCH v2 24/42] input: mouse: switch sdl ui to new core
Signed-off-by: Gerd Hoffmann kra...@redhat.com --- ui/sdl.c | 84 ++-- 1 file changed, 39 insertions(+), 45 deletions(-) diff --git a/ui/sdl.c b/ui/sdl.c index c3b8036..c1a16be 100644 --- a/ui/sdl.c +++ b/ui/sdl.c @@ -353,7 +353,7 @@ static void sdl_hide_cursor(void) if (!cursor_hide) return; -if (kbd_mouse_is_absolute()) { +if (qemu_input_is_absolute()) { SDL_ShowCursor(1); SDL_SetCursor(sdl_cursor_hidden); } else { @@ -366,10 +366,10 @@ static void sdl_show_cursor(void) if (!cursor_hide) return; -if (!kbd_mouse_is_absolute() || !qemu_console_is_graphic(NULL)) { +if (!qemu_input_is_absolute() || !qemu_console_is_graphic(NULL)) { SDL_ShowCursor(1); if (guest_cursor -(gui_grab || kbd_mouse_is_absolute() || absolute_enabled)) +(gui_grab || qemu_input_is_absolute() || absolute_enabled)) SDL_SetCursor(guest_sprite); else SDL_SetCursor(sdl_cursor_normal); @@ -388,8 +388,9 @@ static void sdl_grab_start(void) } if (guest_cursor) { SDL_SetCursor(guest_sprite); -if (!kbd_mouse_is_absolute() !absolute_enabled) +if (!qemu_input_is_absolute() !absolute_enabled) { SDL_WarpMouse(guest_x, guest_y); +} } else sdl_hide_cursor(); SDL_WM_GrabInput(SDL_GRAB_ON); @@ -418,7 +419,7 @@ static void absolute_mouse_grab(void) static void sdl_mouse_mode_change(Notifier *notify, void *data) { -if (kbd_mouse_is_absolute()) { +if (qemu_input_is_absolute()) { if (!absolute_enabled) { absolute_enabled = 1; if (qemu_console_is_graphic(NULL)) { @@ -433,33 +434,36 @@ static void sdl_mouse_mode_change(Notifier *notify, void *data) } } -static void sdl_send_mouse_event(int dx, int dy, int dz, int x, int y, int state) +static void sdl_send_mouse_event(int dx, int dy, int x, int y, int state) { -int buttons = 0; - -if (state SDL_BUTTON(SDL_BUTTON_LEFT)) { -buttons |= MOUSE_EVENT_LBUTTON; -} -if (state SDL_BUTTON(SDL_BUTTON_RIGHT)) { -buttons |= MOUSE_EVENT_RBUTTON; -} -if (state SDL_BUTTON(SDL_BUTTON_MIDDLE)) { -buttons |= MOUSE_EVENT_MBUTTON; -} - -if (kbd_mouse_is_absolute()) { -dx = x * 0x7FFF / (real_screen-w - 1); -dy = y * 0x7FFF / (real_screen-h - 1); +static uint32_t bmap[INPUT_BUTTON_MAX] = { +[INPUT_BUTTON_LEFT] = SDL_BUTTON(SDL_BUTTON_LEFT), +[INPUT_BUTTON_MIDDLE] = SDL_BUTTON(SDL_BUTTON_MIDDLE), +[INPUT_BUTTON_RIGHT] = SDL_BUTTON(SDL_BUTTON_RIGHT), +[INPUT_BUTTON_WHEEL_UP] = SDL_BUTTON(SDL_BUTTON_WHEELUP), +[INPUT_BUTTON_WHEEL_DOWN] = SDL_BUTTON(SDL_BUTTON_WHEELDOWN), +}; +static uint32_t prev_state; + +if (prev_state != state) { +qemu_input_update_buttons(dcl-con, bmap, prev_state, state); +prev_state = state; +} + +if (qemu_input_is_absolute()) { +qemu_input_queue_abs(dcl-con, INPUT_AXIS_X, x, + real_screen-w); +qemu_input_queue_abs(dcl-con, INPUT_AXIS_Y, y, + real_screen-h); } else if (guest_cursor) { x -= guest_x; y -= guest_y; guest_x += x; guest_y += y; -dx = x; -dy = y; +qemu_input_queue_rel(dcl-con, INPUT_AXIS_X, x); +qemu_input_queue_rel(dcl-con, INPUT_AXIS_Y, y); } - -kbd_mouse_event(dx, dy, dz, buttons); +qemu_input_event_sync(); } static void sdl_scale(int width, int height) @@ -687,7 +691,7 @@ static void handle_mousemotion(SDL_Event *ev) int max_x, max_y; if (qemu_console_is_graphic(NULL) -(kbd_mouse_is_absolute() || absolute_enabled)) { +(qemu_input_is_absolute() || absolute_enabled)) { max_x = real_screen-w - 1; max_y = real_screen-h - 1; if (gui_grab (ev-motion.x == 0 || ev-motion.y == 0 || @@ -700,8 +704,8 @@ static void handle_mousemotion(SDL_Event *ev) sdl_grab_start(); } } -if (gui_grab || kbd_mouse_is_absolute() || absolute_enabled) { -sdl_send_mouse_event(ev-motion.xrel, ev-motion.yrel, 0, +if (gui_grab || qemu_input_is_absolute() || absolute_enabled) { +sdl_send_mouse_event(ev-motion.xrel, ev-motion.yrel, ev-motion.x, ev-motion.y, ev-motion.state); } } @@ -710,35 +714,24 @@ static void handle_mousebutton(SDL_Event *ev) { int buttonstate = SDL_GetMouseState(NULL, NULL); SDL_MouseButtonEvent *bev; -int dz; if (!qemu_console_is_graphic(NULL)) { return; } bev = ev-button; -if (!gui_grab !kbd_mouse_is_absolute()) { +if (!gui_grab !qemu_input_is_absolute()) { if (ev-type == SDL_MOUSEBUTTONUP bev-button == SDL_BUTTON_LEFT) {
[Qemu-devel] [PATCH v2 39/42] sdl2: codestyle fixups
--- ui/Makefile.objs | 2 +- ui/sdl2.c| 173 +-- 2 files changed, 104 insertions(+), 71 deletions(-) diff --git a/ui/Makefile.objs b/ui/Makefile.objs index e6a5ec1..6f2294e 100644 --- a/ui/Makefile.objs +++ b/ui/Makefile.objs @@ -15,6 +15,6 @@ common-obj-$(CONFIG_CURSES) += curses.o common-obj-$(CONFIG_VNC) += $(vnc-obj-y) common-obj-$(CONFIG_GTK) += gtk.o x_keymap.o -$(obj)/sdl.o $(obj)/sdl_zoom.o $(obj)/sdl2.o: QEMU_CFLAGS += $(SDL_CFLAGS) +$(obj)/sdl.o $(obj)/sdl_zoom.o $(obj)/sdl2.o: QEMU_CFLAGS += $(SDL_CFLAGS) $(obj)/gtk.o: QEMU_CFLAGS += $(GTK_CFLAGS) $(VTE_CFLAGS) diff --git a/ui/sdl2.c b/ui/sdl2.c index 5338b90..f1532e9 100644 --- a/ui/sdl2.c +++ b/ui/sdl2.c @@ -40,7 +40,7 @@ #include sdl2-keymap.h static int sdl2_num_outputs; -static struct sdl2_console_state { +static struct sdl2_state { DisplayChangeListener dcl; DisplaySurface *surface; SDL_Texture *texture; @@ -66,21 +66,22 @@ static int gui_grab_code = KMOD_LALT | KMOD_LCTRL; static uint8_t modifiers_state[SDL_NUM_SCANCODES]; static SDL_Cursor *sdl_cursor_normal; static SDL_Cursor *sdl_cursor_hidden; -static int absolute_enabled = 0; -static int guest_cursor = 0; +static int absolute_enabled; +static int guest_cursor; static int guest_x, guest_y; -static SDL_Cursor *guest_sprite = NULL; -static int scaling_active = 0; +static SDL_Cursor *guest_sprite; +static int scaling_active; static Notifier mouse_mode_notifier; -static void sdl_update_caption(struct sdl2_console_state *scon); +static void sdl_update_caption(struct sdl2_state *scon); -static struct sdl2_console_state *get_scon_from_window(uint32_t window_id) +static struct sdl2_state *get_scon_from_window(uint32_t window_id) { int i; for (i = 0; i sdl2_num_outputs; i++) { -if (sdl2_console[i].real_window == SDL_GetWindowFromID(window_id)) +if (sdl2_console[i].real_window == SDL_GetWindowFromID(window_id)) { return sdl2_console[i]; +} } return NULL; } @@ -88,14 +89,16 @@ static struct sdl2_console_state *get_scon_from_window(uint32_t window_id) static void sdl_update(DisplayChangeListener *dcl, int x, int y, int w, int h) { -struct sdl2_console_state *scon = container_of(dcl, struct sdl2_console_state, dcl); +struct sdl2_state *scon = container_of(dcl, struct sdl2_state, dcl); SDL_Rect rect; DisplaySurface *surf = qemu_console_surface(dcl-con); -if (!surf) +if (!surf) { return; -if (!scon-texture) +} +if (!scon-texture) { return; +} rect.x = x; rect.y = y; @@ -108,14 +111,14 @@ static void sdl_update(DisplayChangeListener *dcl, SDL_RenderPresent(scon-real_renderer); } -static void do_sdl_resize(struct sdl2_console_state *scon, int width, int height, int bpp) +static void do_sdl_resize(struct sdl2_state *scon, int width, int height, + int bpp) { int flags; if (scon-real_window scon-real_renderer) { if (width height) { SDL_RenderSetLogicalSize(scon-real_renderer, width, height); - SDL_SetWindowSize(scon-real_window, width, height); } else { SDL_DestroyRenderer(scon-real_renderer); @@ -128,10 +131,11 @@ static void do_sdl_resize(struct sdl2_console_state *scon, int width, int height return; } flags = 0; -if (gui_fullscreen) +if (gui_fullscreen) { flags |= SDL_WINDOW_FULLSCREEN; -else +} else { flags |= SDL_WINDOW_RESIZABLE; +} scon-real_window = SDL_CreateWindow(, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, @@ -144,7 +148,7 @@ static void do_sdl_resize(struct sdl2_console_state *scon, int width, int height static void sdl_switch(DisplayChangeListener *dcl, DisplaySurface *new_surface) { -struct sdl2_console_state *scon = container_of(dcl, struct sdl2_console_state, dcl); +struct sdl2_state *scon = container_of(dcl, struct sdl2_state, dcl); int format = 0; int idx = scon-idx; DisplaySurface *old_surface = scon-surface; @@ -154,13 +158,16 @@ static void sdl_switch(DisplayChangeListener *dcl, scon-surface = new_surface; } -if (!new_surface idx 0) +if (!new_surface idx 0) { scon-surface = NULL; +} -if (new_surface == NULL) +if (new_surface == NULL) { do_sdl_resize(scon, 0, 0, 0); -else -do_sdl_resize(scon, surface_width(scon-surface), surface_height(scon-surface), 0); +} else { +do_sdl_resize(scon, surface_width(scon-surface), + surface_height(scon-surface), 0); +} if (old_surface scon-texture) { SDL_DestroyTexture(scon-texture); @@ -169,14 +176,16 @@ static void sdl_switch(DisplayChangeListener
Re: [Qemu-devel] [v19 00/25] replace QEMUOptionParameter with QemuOpts
On Wed, Jan 22, 2014 at 03:35:15PM +0100, Kevin Wolf wrote: Am 20.01.2014 um 15:19 hat Chunyan Liu geschrieben: This patch series is to replace QEMUOptionParameter with QemuOpts, so that only one Qemu Option structure is kept in QEMU code. This version is based on Dong Xu's previous patches, to move the work forward. https://lists.gnu.org/archive/html/qemu-devel/2013-08/msg01695.html Please check the coding style of all patches, especially braces and trailing whitespace. I commented on a few occurences, but didn't do so consistently throughout the series. Use scripts/checkpatch.pl to scan your patches for coding style violations. Stefan
[Qemu-devel] [PATCH v2 27/42] input: mouse: switch spice ui to new core
Signed-off-by: Gerd Hoffmann kra...@redhat.com --- ui/spice-input.c | 62 ++-- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/ui/spice-input.c b/ui/spice-input.c index c9df699..6dab23b 100644 --- a/ui/spice-input.c +++ b/ui/spice-input.c @@ -98,41 +98,52 @@ static void kbd_leds(void *opaque, int ledstate) typedef struct QemuSpicePointer { SpiceMouseInstance mouse; SpiceTabletInstance tablet; -int width, height, x, y; +int width, height; +uint32_t last_bmask; Notifier mouse_mode; bool absolute; } QemuSpicePointer; -static int map_buttons(int spice_buttons) +static void spice_update_buttons(QemuSpicePointer *pointer, + int wheel, uint32_t button_mask) { -int qemu_buttons = 0; - -/* - * Note: SPICE_MOUSE_BUTTON_* specifies the wire protocol but this - * isn't what we get passed in via interface callbacks for the - * middle and right button ... - */ -if (spice_buttons SPICE_MOUSE_BUTTON_MASK_LEFT) { -qemu_buttons |= MOUSE_EVENT_LBUTTON; +static uint32_t bmap[INPUT_BUTTON_MAX] = { +[INPUT_BUTTON_LEFT]= 0x01, +[INPUT_BUTTON_MIDDLE] = 0x04, +[INPUT_BUTTON_RIGHT] = 0x02, +[INPUT_BUTTON_WHEEL_UP]= 0x10, +[INPUT_BUTTON_WHEEL_DOWN] = 0x20, +}; + +if (wheel 0) { +button_mask |= 0x10; } -if (spice_buttons 0x04 /* SPICE_MOUSE_BUTTON_MASK_MIDDLE */) { -qemu_buttons |= MOUSE_EVENT_MBUTTON; +if (wheel 0) { +button_mask |= 0x20; } -if (spice_buttons 0x02 /* SPICE_MOUSE_BUTTON_MASK_RIGHT */) { -qemu_buttons |= MOUSE_EVENT_RBUTTON; + +if (pointer-last_bmask == button_mask) { +return; } -return qemu_buttons; +qemu_input_update_buttons(NULL, bmap, pointer-last_bmask, button_mask); +pointer-last_bmask = button_mask; } static void mouse_motion(SpiceMouseInstance *sin, int dx, int dy, int dz, uint32_t buttons_state) { -kbd_mouse_event(dx, dy, dz, map_buttons(buttons_state)); +QemuSpicePointer *pointer = container_of(sin, QemuSpicePointer, mouse); +spice_update_buttons(pointer, dz, buttons_state); +qemu_input_queue_rel(NULL, INPUT_AXIS_X, dx); +qemu_input_queue_rel(NULL, INPUT_AXIS_Y, dy); +qemu_input_event_sync(); } static void mouse_buttons(SpiceMouseInstance *sin, uint32_t buttons_state) { -kbd_mouse_event(0, 0, 0, map_buttons(buttons_state)); +QemuSpicePointer *pointer = container_of(sin, QemuSpicePointer, mouse); +spice_update_buttons(pointer, 0, buttons_state); +qemu_input_event_sync(); } static const SpiceMouseInterface mouse_interface = { @@ -163,9 +174,10 @@ static void tablet_position(SpiceTabletInstance* sin, int x, int y, { QemuSpicePointer *pointer = container_of(sin, QemuSpicePointer, tablet); -pointer-x = x * 0x7FFF / (pointer-width - 1); -pointer-y = y * 0x7FFF / (pointer-height - 1); -kbd_mouse_event(pointer-x, pointer-y, 0, map_buttons(buttons_state)); +spice_update_buttons(pointer, 0, buttons_state); +qemu_input_queue_abs(NULL, INPUT_AXIS_X, x, pointer-width); +qemu_input_queue_abs(NULL, INPUT_AXIS_Y, y, pointer-width); +qemu_input_event_sync(); } @@ -174,7 +186,8 @@ static void tablet_wheel(SpiceTabletInstance* sin, int wheel, { QemuSpicePointer *pointer = container_of(sin, QemuSpicePointer, tablet); -kbd_mouse_event(pointer-x, pointer-y, wheel, map_buttons(buttons_state)); +spice_update_buttons(pointer, wheel, buttons_state); +qemu_input_event_sync(); } static void tablet_buttons(SpiceTabletInstance *sin, @@ -182,7 +195,8 @@ static void tablet_buttons(SpiceTabletInstance *sin, { QemuSpicePointer *pointer = container_of(sin, QemuSpicePointer, tablet); -kbd_mouse_event(pointer-x, pointer-y, 0, map_buttons(buttons_state)); +spice_update_buttons(pointer, 0, buttons_state); +qemu_input_event_sync(); } static const SpiceTabletInterface tablet_interface = { @@ -199,7 +213,7 @@ static const SpiceTabletInterface tablet_interface = { static void mouse_mode_notifier(Notifier *notifier, void *data) { QemuSpicePointer *pointer = container_of(notifier, QemuSpicePointer, mouse_mode); -bool is_absolute = kbd_mouse_is_absolute(); +bool is_absolute = qemu_input_is_absolute(); if (pointer-absolute == is_absolute) { return; -- 1.8.3.1
[Qemu-devel] [PATCH v2 37/42] input: add input_mouse_mode tracepoint
Signed-off-by: Gerd Hoffmann kra...@redhat.com --- trace-events | 1 + ui/input.c | 1 + 2 files changed, 2 insertions(+) diff --git a/trace-events b/trace-events index a81d71e..322ad11 100644 --- a/trace-events +++ b/trace-events @@ -1026,6 +1026,7 @@ input_event_btn(int conidx, const char *btn, bool down) con %d, button %s, down input_event_rel(int conidx, const char *axis, int value) con %d, axis %s, value %d input_event_abs(int conidx, const char *axis, int value) con %d, axis %s, value 0x%x input_event_sync(void) +input_mouse_mode(int absolute) absolute %d # hw/display/vmware_vga.c vmware_value_read(uint32_t index, uint32_t value) index %d, value 0x%x diff --git a/ui/input.c b/ui/input.c index a32bcff..55449dc 100644 --- a/ui/input.c +++ b/ui/input.c @@ -291,6 +291,7 @@ void qemu_input_check_mode_change(void) is_absolute = qemu_input_is_absolute(); if (is_absolute != current_is_absolute) { +trace_input_mouse_mode(is_absolute); notifier_list_notify(mouse_mode_notifiers, NULL); } -- 1.8.3.1
[Qemu-devel] [PATCH v2 11/42] input: keyboard: switch legacy handlers to new core
legacy kbd event handlers are registered in the new core, so they receive events from the new input core code. keycode - scancode translation needed here. legacy kbd_put_keycode() sends events to the new core. scancode - keycode translation needed here. So with this patch the new input core is fully functional for keyboard events. New + legacy interfaces can be mixed in any way. Signed-off-by: Gerd Hoffmann kra...@redhat.com --- ui/input-legacy.c | 66 ++- 1 file changed, 56 insertions(+), 10 deletions(-) diff --git a/ui/input-legacy.c b/ui/input-legacy.c index 1c70f60..80f4f5c 100644 --- a/ui/input-legacy.c +++ b/ui/input-legacy.c @@ -29,6 +29,7 @@ #include qmp-commands.h #include qapi-types.h #include ui/keymaps.h +#include ui/input.h struct QEMUPutMouseEntry { QEMUPutMouseEvent *qemu_put_mouse_event; @@ -45,7 +46,7 @@ struct QEMUPutMouseEntry { struct QEMUPutKbdEntry { QEMUPutKBDEvent *put_kbd; void *opaque; -QTAILQ_ENTRY(QEMUPutKbdEntry) next; +QemuInputHandlerState *s; }; struct QEMUPutLEDEntry { @@ -56,8 +57,6 @@ struct QEMUPutLEDEntry { static QTAILQ_HEAD(, QEMUPutLEDEntry) led_handlers = QTAILQ_HEAD_INITIALIZER(led_handlers); -static QTAILQ_HEAD(, QEMUPutKbdEntry) kbd_handlers = -QTAILQ_HEAD_INITIALIZER(kbd_handlers); static QTAILQ_HEAD(, QEMUPutMouseEntry) mouse_handlers = QTAILQ_HEAD_INITIALIZER(mouse_handlers); static NotifierList mouse_mode_notifiers = @@ -312,20 +311,56 @@ void qmp_send_key(KeyValueList *keys, bool has_hold_time, int64_t hold_time, muldiv64(get_ticks_per_sec(), hold_time, 1000)); } +static void legacy_kbd_event(DeviceState *dev, QemuConsole *src, + InputEvent *evt) +{ +QEMUPutKbdEntry *entry = (QEMUPutKbdEntry *)dev; +int keycode = keycode_from_keyvalue(evt-key-key); + +if (!entry || !entry-put_kbd) { +return; +} +if (evt-key-key-kind == KEY_VALUE_KIND_QCODE +evt-key-key-qcode == Q_KEY_CODE_PAUSE) { +/* specific case */ +int v = evt-key-down ? 0 : 0x80; +entry-put_kbd(entry-opaque, 0xe1); +entry-put_kbd(entry-opaque, 0x1d | v); +entry-put_kbd(entry-opaque, 0x45 | v); +return; +} +if (keycode SCANCODE_GREY) { +entry-put_kbd(entry-opaque, SCANCODE_EMUL0); +keycode = ~SCANCODE_GREY; +} +if (!evt-key-down) { +keycode |= SCANCODE_UP; +} +entry-put_kbd(entry-opaque, keycode); +} + +static QemuInputHandler legacy_kbd_handler = { +.name = legacy-kbd, +.mask = INPUT_EVENT_MASK_KEY, +.event = legacy_kbd_event, +}; + QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque) { QEMUPutKbdEntry *entry; -entry = g_malloc0(sizeof(QEMUPutKbdEntry)); +entry = g_new0(QEMUPutKbdEntry, 1); entry-put_kbd = func; entry-opaque = opaque; -QTAILQ_INSERT_HEAD(kbd_handlers, entry, next); +entry-s = qemu_input_handler_register((DeviceState *)entry, + legacy_kbd_handler); return entry; } void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry) { -QTAILQ_REMOVE(kbd_handlers, entry, next); +qemu_input_handler_unregister(entry-s); +g_free(entry); } static void check_mode_change(void) @@ -409,14 +444,25 @@ void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry) void kbd_put_keycode(int keycode) { -QEMUPutKbdEntry *entry = QTAILQ_FIRST(kbd_handlers); +static bool emul0; +bool up; -if (!runstate_is_running() !runstate_check(RUN_STATE_SUSPENDED)) { +if (keycode == SCANCODE_EMUL0) { +emul0 = true; return; } -if (entry entry-put_kbd) { -entry-put_kbd(entry-opaque, keycode); +if (keycode SCANCODE_UP) { +keycode = ~SCANCODE_UP; +up = true; +} else { +up = false; +} +if (emul0) { +keycode |= SCANCODE_GREY; +emul0 = false; } + +qemu_input_event_send_key_number(NULL, keycode, !up); } void kbd_put_ledstate(int ledstate) -- 1.8.3.1
[Qemu-devel] [PATCH v2 15/42] sdl2: switch keyboard handling to new core
--- ui/sdl2.c | 23 ++- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/ui/sdl2.c b/ui/sdl2.c index e7a30b3..ac3ac19 100644 --- a/ui/sdl2.c +++ b/ui/sdl2.c @@ -33,6 +33,7 @@ #include qemu-common.h #include ui/console.h +#include ui/input.h #include sysemu/sysemu.h #include x_keymap.h #include sdl_zoom.h @@ -236,9 +237,7 @@ static void reset_keys(void) int i; for(i = 0; i 256; i++) { if (modifiers_state[i]) { -if (i SCANCODE_GREY) -kbd_put_keycode(SCANCODE_EMUL0); -kbd_put_keycode(i | SCANCODE_UP); +qemu_input_event_send_key_number(NULL, i, false); modifiers_state[i] = 0; } } @@ -246,11 +245,12 @@ static void reset_keys(void) static void sdl_process_key(SDL_KeyboardEvent *ev) { -int keycode, v; +int keycode; +#if 0 if (ev-keysym.sym == SDLK_PAUSE) { /* specific case */ -v = 0; +int v = 0; if (ev-type == SDL_KEYUP) v |= SCANCODE_UP; kbd_put_keycode(0xe1); @@ -258,6 +258,7 @@ static void sdl_process_key(SDL_KeyboardEvent *ev) kbd_put_keycode(0x45 | v); return; } +#endif if (kbd_layout) { keycode = sdl_keyevent_to_keycode_generic(ev); @@ -284,18 +285,14 @@ static void sdl_process_key(SDL_KeyboardEvent *ev) case 0x45: /* num lock */ case 0x3a: /* caps lock */ /* SDL does not send the key up event, so we generate it */ -kbd_put_keycode(keycode); -kbd_put_keycode(keycode | SCANCODE_UP); +qemu_input_event_send_key_number(NULL, keycode, true); +qemu_input_event_send_key_number(NULL, keycode, false); return; } /* now send the key code */ -if (keycode SCANCODE_GREY) -kbd_put_keycode(SCANCODE_EMUL0); -if (ev-type == SDL_KEYUP) -kbd_put_keycode(keycode | SCANCODE_UP); -else -kbd_put_keycode(keycode SCANCODE_KEYCODEMASK); +qemu_input_event_send_key_number(NULL, keycode, + ev-type == SDL_KEYDOWN); } static void sdl_update_caption(struct sdl2_console_state *scon) -- 1.8.3.1
[Qemu-devel] [PATCH v2 26/42] input: mouse: switch vnc ui to new core
Signed-off-by: Gerd Hoffmann kra...@redhat.com --- ui/vnc.c | 46 ++ ui/vnc.h | 1 + 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/ui/vnc.c b/ui/vnc.c index 4658559..7dfc94a 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -1484,7 +1484,7 @@ static void client_cut_text(VncState *vs, size_t len, uint8_t *text) static void check_pointer_type_change(Notifier *notifier, void *data) { VncState *vs = container_of(notifier, VncState, mouse_mode_notifier); -int absolute = kbd_mouse_is_absolute(); +int absolute = qemu_input_is_absolute(); if (vnc_has_feature(vs, VNC_FEATURE_POINTER_TYPE_CHANGE) vs-absolute != absolute) { vnc_lock_output(vs); @@ -1503,39 +1503,37 @@ static void check_pointer_type_change(Notifier *notifier, void *data) static void pointer_event(VncState *vs, int button_mask, int x, int y) { -int buttons = 0; -int dz = 0; +static uint32_t bmap[INPUT_BUTTON_MAX] = { +[INPUT_BUTTON_LEFT] = 0x01, +[INPUT_BUTTON_MIDDLE] = 0x02, +[INPUT_BUTTON_RIGHT] = 0x04, +[INPUT_BUTTON_WHEEL_UP] = 0x08, +[INPUT_BUTTON_WHEEL_DOWN] = 0x10, +}; +QemuConsole *con = vs-vd-dcl.con; int width = surface_width(vs-vd-ds); int height = surface_height(vs-vd-ds); -if (button_mask 0x01) -buttons |= MOUSE_EVENT_LBUTTON; -if (button_mask 0x02) -buttons |= MOUSE_EVENT_MBUTTON; -if (button_mask 0x04) -buttons |= MOUSE_EVENT_RBUTTON; -if (button_mask 0x08) -dz = -1; -if (button_mask 0x10) -dz = 1; +if (vs-last_bmask != button_mask) { +qemu_input_update_buttons(con, bmap, vs-last_bmask, button_mask); +vs-last_bmask = button_mask; +} if (vs-absolute) { -kbd_mouse_event(width 1 ? x * 0x7FFF / (width - 1) : 0x4000, -height 1 ? y * 0x7FFF / (height - 1) : 0x4000, -dz, buttons); +qemu_input_queue_abs(con, INPUT_AXIS_X, x, width); +qemu_input_queue_abs(con, INPUT_AXIS_Y, y, height); } else if (vnc_has_feature(vs, VNC_FEATURE_POINTER_TYPE_CHANGE)) { -x -= 0x7FFF; -y -= 0x7FFF; - -kbd_mouse_event(x, y, dz, buttons); +qemu_input_queue_rel(con, INPUT_AXIS_X, x - 0x7FFF); +qemu_input_queue_rel(con, INPUT_AXIS_Y, y - 0x7FFF); } else { -if (vs-last_x != -1) -kbd_mouse_event(x - vs-last_x, -y - vs-last_y, -dz, buttons); +if (vs-last_x != -1) { +qemu_input_queue_rel(con, INPUT_AXIS_X, x - vs-last_x); +qemu_input_queue_rel(con, INPUT_AXIS_Y, y - vs-last_y); +} vs-last_x = x; vs-last_y = y; } +qemu_input_event_sync(); } static void reset_keys(VncState *vs) diff --git a/ui/vnc.h b/ui/vnc.h index 6e99213..e63c142 100644 --- a/ui/vnc.h +++ b/ui/vnc.h @@ -257,6 +257,7 @@ struct VncState int absolute; int last_x; int last_y; +uint32_t last_bmask; int client_width; int client_height; VncShareMode share_mode; -- 1.8.3.1
Re: [Qemu-devel] [PATCH 07/13 v7] dump: add members to DumpState and init some of them
comments below On 01/17/14 08:46, qiaonuohan wrote: add some members to DumpState that will be used in writing vmcore in kdump-compressed format. some of them, like page_size, will be initialized in the patch. Signed-off-by: Qiao Nuohan qiaonuo...@cn.fujitsu.com --- dump.c| 30 ++ include/sysemu/dump.h |7 +++ 2 files changed, 37 insertions(+), 0 deletions(-) diff --git a/dump.c b/dump.c index 2b940bd..bf7d31d 100644 --- a/dump.c +++ b/dump.c @@ -79,6 +79,16 @@ typedef struct DumpState { uint8_t *note_buf; /* buffer for notes */ size_t note_buf_offset; /* the writing place in note_buf */ +uint32_t nr_cpus; /* number of guest's cpu */ +size_t page_size; /* guest's page size */ +uint32_t page_shift;/* guest's page shift */ +uint64_t max_mapnr; /* the biggest guest's phys-mem's number */ +size_t len_dump_bitmap; /* the size of the place used to store + dump_bitmap in vmcore */ +off_t offset_dump_bitmap; /* offset of dump_bitmap part in vmcore */ +off_t offset_page; /* offset of page part in vmcore */ +size_t num_dumpable;/* number of page that can be dumped */ +uint32_t flag_compress; /* indicate the compression format */ } DumpState; v6 06/11 addded these, but we have the following changes here: - flag_flatten is gone, OK, - bunch of comments, good, - page_shift and num_dumpable are now added at once (originally in v6 07/11). static int dump_cleanup(DumpState *s) @@ -796,6 +806,16 @@ static ram_addr_t get_start_block(DumpState *s) return -1; } +static void get_max_mapnr(DumpState *s) +{ +MemoryMapping *memory_mapping; + +QTAILQ_FOREACH(memory_mapping, s-list.head, next) { +s-max_mapnr = paddr_to_pfn(memory_mapping-phys_addr + +memory_mapping-length, s-page_shift); +} +} + static int dump_init(DumpState *s, int fd, bool paging, bool has_filter, int64_t begin, int64_t length, Error **errp) { This is from v6 10/11, OK. @@ -864,6 +884,16 @@ static int dump_init(DumpState *s, int fd, bool paging, bool has_filter, qemu_get_guest_simple_memory_mapping(s-list, s-guest_phys_blocks); } +s-nr_cpus = nr_cpus; +s-page_size = TARGET_PAGE_SIZE; +s-page_shift = ffs(s-page_size) - 1; + +get_max_mapnr(s); Again from v6 10/11, good. The flag_flatten assignment has been dropped. Initialization seems to happen in a good spot this time too. + +uint64_t tmp; +tmp = DIV_ROUND_UP(DIV_ROUND_UP(s-max_mapnr, CHAR_BIT), s-page_size); +s-len_dump_bitmap = tmp * s-page_size; + if (s-has_filter) { memory_mapping_filter(s-list, s-begin, s-length); } Again from v6 10/11. These assignments now all occur without depending on a user request for a compressed dump (kept this way in v7 12/13 too), but they are not costly. The loop in get_max_mapnr() iterates over less than 10 mappings in the non-paging dump case, and in the paging dump case it also shouldn't be more than a hundred or so (as I recall from earlier testing). This might be worth some regression-testing (perf-wise), but it looks OK to me. diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h index b32b390..995bf47 100644 --- a/include/sysemu/dump.h +++ b/include/sysemu/dump.h @@ -20,6 +20,13 @@ #define VERSION_FLAT_HEADER (1)/* version of flattened format */ #define END_FLAG_FLAT_HEADER(-1) +#define ARCH_PFN_OFFSET (0) + +#define paddr_to_pfn(X, page_shift) \ +(((unsigned long long)(X) (page_shift)) - ARCH_PFN_OFFSET) From v6 07/11, needed by get_max_mapnr(). +#define pfn_to_paddr(X, page_shift) \ +(((unsigned long long)(X) + ARCH_PFN_OFFSET) (page_shift)) + typedef struct ArchDumpInfo { int d_machine; /* Architecture */ int d_endian; /* ELFDATA2LSB or ELFDATA2MSB */ From v6 09/11. Not strictly needed right now, but it does make sense for consistency. Reviewed-by: Laszlo Ersek ler...@redhat.com