Re: [PATCH qemu-kvm] Add raw(af_packet) network backend to qemu

2010-01-28 Thread Arnd Bergmann
On Wednesday 27 January 2010, Anthony Liguori wrote:
 
  Introducing something that is known to be problematic from a security
  perspective without any clear idea of what the use-case for it is is a
  bad idea IMHO.
   
  vepa on existing kernels is one use-case.
 
 
 Considering VEPA enabled hardware doesn't exist today and the standards 
 aren't even finished being defined, I don't think it's a really strong 
 use case ;-)

The hairpin turn (the part that is required on the bridge) was implemented
in the Linux bridge in 2.6.32, so that is one existing implementation you
can use as a peer.

The VEPA mode in macvlan only made it into 2.6.33, so using the raw socket
on older kernels does not give you actual VEPA semantics.

The part of the standard that is still under discussion is the management
side, which is almost entirely unrelated to this question though. With
Linux-2.6.33 on both sides using raw/macvlan and bridge respectively,
you can have a working VEPA setup. The only thing missing is that the
hypervisor will not be able to tell the bridge to automatically enable
hairpin mode (you need to do that on the bridge on a per-port basis).


Now, the most important use case I see for the raw socket interface
in qemu is to get vhost-net and the qemu user implementation to
support the same feature set. If you ask for a network setup involving
a raw socket and vhost-net and the kernel can support raw sockets
but for some reason fails to set up vhost-net, you should have a
fallback that has the exact same semantics at a possibly significant
performance loss.

Arnd

--
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] Add definitions for current cpu models..

2010-01-28 Thread Arnd Bergmann
On Monday 25 January 2010, Dor Laor wrote:
 x86   qemu64
 x86   phenom
 x86 core2duo
 x86kvm64
 x86   qemu32
 x86  coreduo
 x86  486
 x86  pentium
 x86 pentium2
 x86 pentium3
 x86   athlon
 x86 n270

I think a really nice addition would be an autodetect option for those
users (e.g. desktop) that know they do not want to migrate the guest
to a lower-spec machine. 

That option IMHO should just show up as identical to the host cpu, with
the exception of features that are not supported in the guest.

Arnd
--
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-kvm: enable get/set vcpu events on reset and migration

2010-01-28 Thread Jan Kiszka
Marcelo Tosatti wrote:
 The last two hunks will cause the same !CONFIG_KVM breakages qemu-kvm's
 mpstate used to as well. You may either fix it up temporarily or wait
 for my refactoring that is now scheduled with highest priority (should
 be ready today or tomorrow).
 
 It needs to go in 0.12-stable, so we'll have to leave with it.
 

One additional patch is required to account for the new event flags,
also for upstream. Will post it in a minute.

 Feel free to revert from master when refactoring.
 
 Gleb/Glauber can you review please.
 
 
 
 qemu-kvm should reset and save/restore vcpu events.
 
 Signed-off-by: Marcelo Tosatti mtosa...@redhat.com
 
 diff --git a/kvm.h b/kvm.h
 index e2a945b..9fa4e25 100644
 --- a/kvm.h
 +++ b/kvm.h
 @@ -52,6 +52,9 @@ int kvm_set_migration_log(int enable);
  int kvm_has_sync_mmu(void);
  #endif /* KVM_UPSTREAM */
  int kvm_has_vcpu_events(void);
 +int kvm_put_vcpu_events(CPUState *env);
 +int kvm_get_vcpu_events(CPUState *env);
 +

Such hunks were better off in qemu-kvm.h, but this one is not the first
here.

  #ifdef KVM_UPSTREAM
  
  void kvm_setup_guest_memory(void *start, size_t size);
 @@ -96,7 +99,9 @@ int kvm_arch_init(KVMState *s, int smp_cpus);
  
  int kvm_arch_init_vcpu(CPUState *env);
  
 +#endif
  void kvm_arch_reset_vcpu(CPUState *env);
 +#ifdef KVM_UPSTREAM
  
  struct kvm_guest_debug;
  struct kvm_debug_exit_arch;
 diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c
 index 82e362c..7f820a4 100644
 --- a/qemu-kvm-x86.c
 +++ b/qemu-kvm-x86.c
 @@ -1457,8 +1457,9 @@ void kvm_arch_push_nmi(void *opaque)
  
  void kvm_arch_cpu_reset(CPUState *env)
  {
 -env-interrupt_injected = -1;
 +kvm_arch_reset_vcpu(env);
  kvm_arch_load_regs(env);
 +kvm_put_vcpu_events(env);
  if (!cpu_is_bsp(env)) {
   if (kvm_irqchip_in_kernel()) {
  #ifdef KVM_CAP_MP_STATE
 diff --git a/qemu-kvm.c b/qemu-kvm.c
 index 1c34846..f891a3e 100644
 --- a/qemu-kvm.c
 +++ b/qemu-kvm.c
 @@ -2187,6 +2187,11 @@ static int kvm_create_context(void)
  return r;
  }
  
 +kvm_state-vcpu_events = 0;
 +#ifdef KVM_CAP_VCPU_EVENTS
 +kvm_state-vcpu_events = kvm_check_extension(kvm_state, 
 KVM_CAP_VCPU_EVENTS);
 +#endif
 +
  kvm_init_ap();
  if (kvm_irqchip) {
  if (!qemu_kvm_has_gsi_routing()) {
 diff --git a/target-i386/kvm.c b/target-i386/kvm.c
 index 9af1e48..79be2d5 100644
 --- a/target-i386/kvm.c
 +++ b/target-i386/kvm.c
 @@ -285,6 +285,7 @@ int kvm_arch_init_vcpu(CPUState *env)
  return kvm_vcpu_ioctl(env, KVM_SET_CPUID2, cpuid_data);
  }
  
 +#endif
  void kvm_arch_reset_vcpu(CPUState *env)
  {
  env-exception_injected = -1;
 @@ -292,6 +293,7 @@ void kvm_arch_reset_vcpu(CPUState *env)
  env-nmi_injected = 0;
  env-nmi_pending = 0;
  }
 +#ifdef KVM_UPSTREAM
  
  static int kvm_has_msr_star(CPUState *env)
  {
 @@ -776,8 +778,9 @@ static int kvm_get_mp_state(CPUState *env)
  env-mp_state = mp_state.mp_state;
  return 0;
  }
 +#endif
  
 -static int kvm_put_vcpu_events(CPUState *env)
 +int kvm_put_vcpu_events(CPUState *env)
  {
  #ifdef KVM_CAP_VCPU_EVENTS
  struct kvm_vcpu_events events;
 @@ -807,7 +810,7 @@ static int kvm_put_vcpu_events(CPUState *env)
  #endif
  }
  
 -static int kvm_get_vcpu_events(CPUState *env)
 +int kvm_get_vcpu_events(CPUState *env)
  {
  #ifdef KVM_CAP_VCPU_EVENTS
  struct kvm_vcpu_events events;
 @@ -844,6 +847,7 @@ static int kvm_get_vcpu_events(CPUState *env)
  return 0;
  }
  
 +#ifdef KVM_UPSTREAM
  int kvm_arch_put_registers(CPUState *env)
  {
  int ret;
 diff --git a/target-i386/machine.c b/target-i386/machine.c
 index 47ca6e8..0b8a33a 100644
 --- a/target-i386/machine.c
 +++ b/target-i386/machine.c
 @@ -323,7 +323,10 @@ static void cpu_pre_save(void *opaque)
  int i;
  
  cpu_synchronize_state(env);
 -kvm_save_mpstate(env);
 +if (kvm_enabled()) {
 +kvm_save_mpstate(env);
 +kvm_get_vcpu_events(env);
 +}
  
  /* FPU */
  env-fpus_vmstate = (env-fpus  ~0x3800) | (env-fpstt  0x7)  11;
 @@ -374,6 +377,7 @@ static int cpu_post_load(void *opaque, int version_id)
  
  kvm_load_tsc(env);
  kvm_load_mpstate(env);
 +kvm_put_vcpu_events(env);
  }
  
  return 0;

Otherwise builds and works fine here.

Jan

-- 
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
--
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


[PATCH] uq/master: KVM: Request setting of nmi_pending and sipi_vector

2010-01-28 Thread Jan Kiszka
The final version of VCPU events in 2.6.33 will allow to skip
nmi_pending and sipi_vector on KVM_SET_VCPU_EVENTS. For now let's write
them unconditionally, which is unproblematic for upstream due to missing
SMP support. Future version which enable SMP will write them only on
reset.

Signed-off-by: Jan Kiszka jan.kis...@siemens.com
---

The same patch can be used by qemu-kvm as it will only trigger on
init/reset unlike upstream.

 target-i386/kvm.c |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 5b093ce..b457b96 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -794,6 +794,9 @@ static int kvm_put_vcpu_events(CPUState *env)
 
 events.sipi_vector = env-sipi_vector;
 
+events.flags =
+KVM_VCPUEVENT_VALID_NMI_PENDING | KVM_VCPUEVENT_VALID_SIPI_VECTOR;
+
 return kvm_vcpu_ioctl(env, KVM_SET_VCPU_EVENTS, events);
 #else
 return 0;
-- 
1.6.0.2
--
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: KVM problems with Xeon L5530

2010-01-28 Thread Matteo Ghezzi
2010/1/28 Brian Jackson i...@theiggy.com:
 What version of qemu-kvm?

qemu-kvm 0.12.2-1

 There was a similar thread a while back, maybe you could try some of the
 suggestions and/or info gathering tips from it.

tried every suggestion form that thread... contacted the original
poster and narrowed down the problem:
we both have an Intel engineering sample and not a finalized cpu.
I'll buy a new one and re-check.
Thanks for your help.
--
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] Add definitions for current cpu models..

2010-01-28 Thread Alexander Graf

On 28.01.2010, at 09:19, Arnd Bergmann wrote:

 On Monday 25 January 2010, Dor Laor wrote:
 x86   qemu64
 x86   phenom
 x86 core2duo
 x86kvm64
 x86   qemu32
 x86  coreduo
 x86  486
 x86  pentium
 x86 pentium2
 x86 pentium3
 x86   athlon
 x86 n270
 
 I think a really nice addition would be an autodetect option for those
 users (e.g. desktop) that know they do not want to migrate the guest
 to a lower-spec machine. 
 
 That option IMHO should just show up as identical to the host cpu, with
 the exception of features that are not supported in the guest.

That's exactly what -cpu host is. IIRC it's the default now.

Alex
--
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: [RFC][PATCH] KVM: Introduce modification context for cpu_synchronize_state

2010-01-28 Thread Jan Kiszka
Marcelo Tosatti wrote:
 On Wed, Jan 27, 2010 at 03:54:08PM +0100, Jan Kiszka wrote:
 This patch originates in the mp_state writeback issue: During runtime
 and even on reset, we must not write the previously saved VCPU state
 back into the kernel in an uncontrolled fashion. E.g mp_state should
 only written on reset or on VCPU setup. Certain clocks (e.g. the TSC)
 may only be written on setup or after vmload.

 By introducing additional information about the context of the planned
 vcpu state manipulation, we can simply skip sensitive states like
 mp_state when updating the in-kernel state. The planned modifications
 are defined when calling cpu_synchronize_state. They accumulate, ie.
 once a full writeback was requested, it will stick until it was
 performed.

 This patch already fixes existing writeback issues in upstream KVM by
 only selectively writing MSR_IA32_TSC, MSR_KVM_SYSTEM_TIME,
 MSR_KVM_WALL_CLOCK, the mp_state and the vcpu_events.

 Signed-off-by: Jan Kiszka jan.kis...@siemens.com
 ---

 This patch is intentionally written against uq/master. As upstream is
 less convoluted (yet :) ), it may help understanding the basic idea. An
 add-on patch for qemu-kvm that both cleans up the current code and also
 moves kvm_get/set_lapic into kvm_arch_get/put_registers (hmm, maybe also
 renaming that services...) will follow soon if no one sees fundamental
 problems of this approach.

  exec.c|4 ++--
  gdbstub.c |   10 +-
  hw/apic.c |2 +-
  hw/ppc_newworld.c |2 +-
  hw/ppc_oldworld.c |2 +-
  hw/s390-virtio.c  |2 +-
  kvm-all.c |   31 +++
  kvm.h |   13 +
  monitor.c |4 ++--
  target-i386/helper.c  |2 +-
  target-i386/kvm.c |   31 +++
  target-i386/machine.c |4 ++--
  target-ppc/kvm.c  |2 +-
  target-ppc/machine.c  |4 ++--
  target-s390x/kvm.c|   17 -
  15 files changed, 78 insertions(+), 52 deletions(-)

 diff --git a/kvm-all.c b/kvm-all.c
 index f8350c9..8595cd9 100644
 --- a/kvm-all.c
 +++ b/kvm-all.c
 @@ -57,7 +57,8 @@ struct KVMState
  KVMSlot slots[32];
  int fd;
  int vmfd;
 -int regs_modified;
 +int synchronized;
 +int pending_modifications;
  int coalesced_mmio;
  #ifdef KVM_CAP_COALESCED_MMIO
  struct kvm_coalesced_mmio_ring *coalesced_mmio_ring;
 
 Should be per-vcpu.

Yep, good chance to clean this up in upstream.

 
 @@ -155,10 +156,12 @@ static void kvm_reset_vcpu(void *opaque)
  CPUState *env = opaque;
  
  kvm_arch_reset_vcpu(env);
 -if (kvm_arch_put_registers(env)) {
 +if (kvm_arch_put_registers(env, env-kvm_state-pending_modifications
 +| CPU_MODIFY_RESET)) {
  fprintf(stderr, Fatal: kvm vcpu reset failed\n);
  abort();
  }
 +env-kvm_state-pending_modifications = CPU_MODIFY_NONE;
 
 Can't the writeback here happen at exec_cpu?

Don't think so (longterm). The reset callbacks are run synchronously,
writing back on exec would happen asynchronously, leaving some vcpus in
pre-reset state when others already start over.

 
 @@ -946,9 +953,9 @@ static void kvm_invoke_set_guest_debug(void *data)
  struct kvm_set_guest_debug_data *dbg_data = data;
  CPUState *env = dbg_data-env;
  
 -if (env-kvm_state-regs_modified) {
 -kvm_arch_put_registers(env);
 -env-kvm_state-regs_modified = 0;
 +if (env-kvm_state-pending_modifications) {
 +kvm_arch_put_registers(env, env-kvm_state-pending_modifications);
 +env-kvm_state-pending_modifications = CPU_MODIFY_NONE;
  }
 
 Why's synchronous writeback needed here?

Older kernels overwrote the effect of set_guest_debug on eflags when
updating the registers.

But this hunk is scheduled for refactoring which will take it to the
same place as all the other vcpu state writebacks. That will enforce the
ordering more naturally.

 
 Otherwise seems fine.
 

Jan

-- 
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
--
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


High availability VM

2010-01-28 Thread Pablo Mellado

Hi there,

I would need a system running in a VM with high availability. My current 
version of KVM in Debian Lenny does not support to take snapshots of the 
VM while it is running. So I was wondering if I can migrate the VM and 
then make the snapshot on the source host. Once the snapshot is done, I 
would migrate the machine back to the source host. Is that possible? Can 
I run a savevm command on a already migrated VM?


The main idea is to make snapshots in a daily basis, and in case the 
host machine fails (i.e. hardware failure), starts the last snapshot in 
a new host.


Best regards,

  Pablo

--

Pablo Mellado
Software Engineer

Instituto de Radioastronomia Milimetrica
Avenida Divina Pastora 7, Local 20
E 18012 Granada, España
Telefono: +34 958 805 456 
Fax: +34 958 222363


--
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] Fix qemu-img can't create qcow image based on read-only image

2010-01-28 Thread Kevin Wolf
Am 28.01.2010 06:22, schrieb Sheng Yang:
 Commit 03cbdac7 Disable fall-back to read-only when cannot open drive's
 file for read-write result in read-only image can't be used as backed
 image in qemu-img.
 
 CC: Naphtali Sprei nsp...@redhat.com
 Signed-off-by: Sheng Yang sh...@linux.intel.com
 ---
 
 This issue blocked our QA's KVM nightly test. But in fact, I don't like this
 patch, feeling uncomfortable to change long existed interface... Any
 alternative? Add a readonly command line would change the default behavior(I
 don't think fall back to readonly looks like a bug); or even revert the
 commit? What's the story behind it?
 
  qemu-img.c |   15 ++-
  1 files changed, 10 insertions(+), 5 deletions(-)
 
 diff --git a/qemu-img.c b/qemu-img.c
 index 3cea8ce..f8be5cb 100644
 --- a/qemu-img.c
 +++ b/qemu-img.c
 @@ -188,11 +188,13 @@ static int read_password(char *buf, int buf_size)
  #endif
  
  static BlockDriverState *bdrv_new_open(const char *filename,
 -   const char *fmt)
 +   const char *fmt,
 +   int readonly)
  {
  BlockDriverState *bs;
  BlockDriver *drv;
  char password[256];
 +int flags = BRDV_O_FLAGS;
  
  bs = bdrv_new();
  if (!bs)
 @@ -204,7 +206,10 @@ static BlockDriverState *bdrv_new_open(const char 
 *filename,
  } else {
  drv = NULL;
  }
 -if (bdrv_open2(bs, filename, BRDV_O_FLAGS | BDRV_O_RDWR, drv)  0) {
 +if (!readonly) {
 +flags |= BDRV_O_RDWR;
 +}
 +if (bdrv_open2(bs, filename, flags, drv)  0) {
  error(Could not open '%s', filename);
  }
  if (bdrv_is_encrypted(bs)) {
 @@ -343,7 +348,7 @@ static int img_create(int argc, char **argv)
  }
  }
  
 -bs = bdrv_new_open(backing_file-value.s, fmt);
 +bs = bdrv_new_open(backing_file-value.s, fmt, 1);
  bdrv_get_geometry(bs, size);
  size *= 512;
  bdrv_delete(bs);
 @@ -627,7 +632,7 @@ static int img_convert(int argc, char **argv)
  
  total_sectors = 0;
  for (bs_i = 0; bs_i  bs_n; bs_i++) {
 -bs[bs_i] = bdrv_new_open(argv[optind + bs_i], fmt);
 +bs[bs_i] = bdrv_new_open(argv[optind + bs_i], fmt, 0);

Shouldn't it be read-only here, too?

Kevin
--
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: [Autotest] [Autotest PATCH] KVM-test: Add a subtest 'qemu_img'

2010-01-28 Thread Yolkfull Chow
On Tue, Jan 26, 2010 at 03:11:34PM -0200, Lucas Meneghel Rodrigues wrote:
 On Tue, 2010-01-26 at 11:25 +0800, Yolkfull Chow wrote:
  This is designed to test all subcommands of 'qemu-img' however
  so far 'commit' is not implemented.
 
 Hi Yolkful, this is very good! Seeing this test made me think about that
 stand alone autotest module we commited a while ago, that does
 qemu_iotests testsuite on the host.
 
 Perhaps we could 'port' this module to the kvm test, since it is more
 convenient to execute it inside a kvm test job (in a job where we test
 more than 2 build types, for example, we need to execute qemu_img and
 qemu_io_tests for every qemu-img built).
 
 Could you look at implementing this?
 
  * For 'check' subcommand test, it will 'dd' to create a file with specified
  size and see whether it's supported to be checked. Then convert it to be
  supported formats (qcow2 and raw so far) to see whether there's error
  after convertion.
  
  * For 'convert' subcommand test, it will convert both to 'qcow2' and 'raw' 
  from
  the format specified in config file. And only check 'qcow2' after 
  convertion.
  
  * For 'snapshot' subcommand test, it will create two snapshots and list 
  them.
  Finally delete them if no errors found.
  
  * For 'info' subcommand test, it simply get output from specified image 
  file.
  
  Signed-off-by: Yolkfull Chow yz...@redhat.com
  ---
   client/tests/kvm/tests/qemu_img.py |  155 
  
   client/tests/kvm/tests_base.cfg.sample |   36 
   2 files changed, 191 insertions(+), 0 deletions(-)
   create mode 100644 client/tests/kvm/tests/qemu_img.py
  
  diff --git a/client/tests/kvm/tests/qemu_img.py 
  b/client/tests/kvm/tests/qemu_img.py
  new file mode 100644
  index 000..1ae04f0
  --- /dev/null
  +++ b/client/tests/kvm/tests/qemu_img.py
  @@ -0,0 +1,155 @@
  +import os, logging, commands
  +from autotest_lib.client.common_lib import error
  +import kvm_vm
  +
  +
  +def run_qemu_img(test, params, env):
  +
  +`qemu-img' functions test:
  +1) Judge what subcommand is going to be tested
  +2) Run subcommand test
  +
  +@param test: kvm test object
  +@param params: Dictionary with the test parameters
  +@param env: Dictionary with test environment.
  +
  +cmd = params.get(qemu_img_binary)
 
 It is a good idea to verify if cmd above resolves to an absolute path,
 to avoid problems. If it doesn't resolve, verify if there's the symbolic
 link under kvm test dir pointing to qemu-img, and if it does exist, make
 sure it points to a valid file (ie, symlink is not broken).
 
  +subcommand = params.get(subcommand)
  +image_format = params.get(image_format)
  +image_name = kvm_vm.get_image_filename(params, test.bindir)
  +
  +def check(img):
  +global cmd
  +cmd +=  check %s % img
  +logging.info(Checking image '%s'... % img)
  +s, o = commands.getstatusoutput(cmd)
  +if not (s == 0 or does not support checks in o):
  +return (False, o)
  +return (True, )
 
 Please use utils.system_output here instead of the equivalent commands
 API on the above code. This comment applies to all further uses of
 commands.[function].
 
  +
  +# Subcommand 'qemu-img check' test
  +# This tests will 'dd' to create a specified size file, and check it.
  +# Then convert it to supported image_format in each loop and check 
  again.
  +def check_test():
  +size = params.get(dd_image_size)
  +test_image = params.get(dd_image_name)
  +create_image_cmd = params.get(create_image_cmd)
  +create_image_cmd = create_image_cmd % (test_image, size)
  +s, o = commands.getstatusoutput(create_image_cmd)
  +if s != 0:
  +raise error.TestError(Failed command: %s; Output is: %s %
  + (create_image_cmd, o))
  +s, o = check(test_image)
  +if not s:
  +raise error.TestFail(Failed to check image '%s' with error: 
  %s %
  +  (test_image, 
  o))
  +for fmt in params.get(supported_image_formats).split():
  +output_image = test_image + .%s % fmt
  +convert(fmt, test_image, output_image)
  +s, o = check(output_image)
  +if not s:
  +raise error.TestFail(Check image '%s' got error: %s %
  + (output_image, o))
  +commands.getoutput(rm -f %s % output_image)
  +commands.getoutput(rm -f %s % test_image)
  +#Subcommand 'qemu-img create' test
  +def create_test():
  +global cmd
 
 I don't like very much this idea of using a global variable, instead it
 should be preferrable to use a class and have a class attribute with
 'cmd'. This way it would be safer, since the usage of cmd is
 encapsulated. This 

[ kvm-Bugs-2941537 ] rtl8139 (and others) emulation not working in OsX86

2010-01-28 Thread SourceForge.net
Bugs item #2941537, was opened at 2010-01-28 11:57
Message generated for change (Tracker Item Submitted) made by nebukadneza
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=893831aid=2941537group_id=180599

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: intel
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: NebuK (nebukadneza)
Assigned to: Nobody/Anonymous (nobody)
Summary: rtl8139 (and others) emulation not working in OsX86 

Initial Comment:
OsX86 (hackint0sh) works quite well using kvm (0.88), speed and everything is 
decent. There are drivers available for either the e1000 or rtl8139 emulated 
network interfaces. The problem for rtl8139 is: the card is recognized and 
brought up nicely, just no packets are sent (guest side: packet counter 
increases, host side: no packets on tap0 (via tcpdump or ifconfig packet 
count)). The e1000 is recognized but cannot be brought up (no cable connected).

--

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=893831aid=2941537group_id=180599
--
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: KVM problems with Xeon L5530

2010-01-28 Thread Matteo Ghezzi
Upgraded to 2.6.33-rc5, same qemu-kvm version, same hardware.
The Vnc screen is still black and the virtual machine, but now I don't
have anymore messages in the logs but directly at standard output:

KVM internal error. Suberror: 2
extra data[0]: 8010
extra data[1]: 8b0d
rax 0003 rbx 0065 rcx  rdx
03ce
rsi  rdi 7ad0 rsp 6eb0 rbp

r8   r9   r10  r11

r12  r13  r14  r15

rip 014a rflags 00010002
cs c000 (000c/ p 1 dpl 3 db 0 s 1 type 3 l 0 g 0 avl 0)
ds  (/ p 1 dpl 3 db 0 s 1 type 3 l 0 g 0 avl 0)
es f000 (000f/ p 1 dpl 3 db 0 s 1 type 3 l 0 g 0 avl 0)
ss  (/ p 1 dpl 3 db 0 s 1 type 3 l 0 g 0 avl 0)
fs  (/ p 1 dpl 3 db 0 s 1 type 3 l 0 g 0 avl 0)
gs  (/ p 1 dpl 3 db 0 s 1 type 3 l 0 g 0 avl 0)
tr  (feffd000/2088 p 1 dpl 0 db 0 s 0 type b l 0 g 0 avl 0)
ldt  (/ p 1 dpl 0 db 0 s 0 type 2 l 0 g 0 avl 0)
gdt f7a20/37
idt 0/3ff
cr0 10 cr2 0 cr3 0 cr4 0 cr8 0 efer 0
--
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: High availability VM

2010-01-28 Thread Martin Maurer
 -Original Message-
 From: kvm-ow...@vger.kernel.org [mailto:kvm-ow...@vger.kernel.org] On
 Behalf Of Pablo Mellado
 Sent: Donnerstag, 28. Jänner 2010 09:55
 To: kvm@vger.kernel.org
 Subject: High availability VM
 
 Hi there,
 
 I would need a system running in a VM with high availability. My
 current
 version of KVM in Debian Lenny does not support to take snapshots of
 the
 VM while it is running. So I was wondering if I can migrate the VM and
 then make the snapshot on the source host. Once the snapshot is done, I
 would migrate the machine back to the source host. Is that possible?
 Can
 I run a savevm command on a already migrated VM?
 
 The main idea is to make snapshots in a daily basis, and in case the
 host machine fails (i.e. hardware failure), starts the last snapshot in
 a new host.

You use LVM snapshots for online backups.
http://pve.proxmox.com/wiki/Backup_-_Restore_-_Live_Migration

For improving HA, take a look on DRBD.

Br, Martin

 
 Best regards,
 
Pablo
 
 --
 
 Pablo Mellado
 Software Engineer
 
 Instituto de Radioastronomia Milimetrica
 Avenida Divina Pastora 7, Local 20
 E 18012 Granada, España
 Telefono: +34 958 805 456
 Fax: +34 958 222363
 
 --
 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


--
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: [PATCH qemu-kvm] Add raw(af_packet) network backend to qemu

2010-01-28 Thread Or Gerlitz

Sridhar Samudrala wrote:

On Wed, 2010-01-27 at 22:39 +0100, Arnd Bergmann wrote:
we already have -net socket,fd and any user that passes an fd into 
that already knows what he wants to do with it. Making it work with 
raw sockets is just a natural extension to this

Didn't realize that -net socket is already there and supports TCP and UDP 
sockets. I will look into extending -net socket to support AF_PACKET SOCK_RAW 
type sockets
The original thought was that the -raw option will be integrated in a 
pass through manner, that is bypassing the qemu vlan (internal bridge). 
This will allow qemu to use the mac address of the SR-IOV (e.g HW VF, 
software macvlan) NIC as the mac delivered to the VM, in that sense it 
is pretty different from the -net socket option.


Or.
--
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


[PATCH 01/11] iommu-api: Rename -{un}map function pointers to -{un}map_range

2010-01-28 Thread Joerg Roedel
The new function pointer names match better with the
top-level functions of the iommu-api which are using them.
Main intention of this change is to make the -{un}map
pointer names free for two new mapping functions.

Signed-off-by: Joerg Roedel joerg.roe...@amd.com
---
 arch/x86/kernel/amd_iommu.c |4 ++--
 drivers/base/iommu.c|4 ++--
 drivers/pci/intel-iommu.c   |4 ++--
 include/linux/iommu.h   |8 
 4 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/arch/x86/kernel/amd_iommu.c b/arch/x86/kernel/amd_iommu.c
index adb0ba0..59cae7c 100644
--- a/arch/x86/kernel/amd_iommu.c
+++ b/arch/x86/kernel/amd_iommu.c
@@ -2515,8 +2515,8 @@ static struct iommu_ops amd_iommu_ops = {
.domain_destroy = amd_iommu_domain_destroy,
.attach_dev = amd_iommu_attach_device,
.detach_dev = amd_iommu_detach_device,
-   .map = amd_iommu_map_range,
-   .unmap = amd_iommu_unmap_range,
+   .map_range = amd_iommu_map_range,
+   .unmap_range = amd_iommu_unmap_range,
.iova_to_phys = amd_iommu_iova_to_phys,
.domain_has_cap = amd_iommu_domain_has_cap,
 };
diff --git a/drivers/base/iommu.c b/drivers/base/iommu.c
index 8ad4ffe..f4c86c4 100644
--- a/drivers/base/iommu.c
+++ b/drivers/base/iommu.c
@@ -83,14 +83,14 @@ EXPORT_SYMBOL_GPL(iommu_detach_device);
 int iommu_map_range(struct iommu_domain *domain, unsigned long iova,
phys_addr_t paddr, size_t size, int prot)
 {
-   return iommu_ops-map(domain, iova, paddr, size, prot);
+   return iommu_ops-map_range(domain, iova, paddr, size, prot);
 }
 EXPORT_SYMBOL_GPL(iommu_map_range);
 
 void iommu_unmap_range(struct iommu_domain *domain, unsigned long iova,
  size_t size)
 {
-   iommu_ops-unmap(domain, iova, size);
+   iommu_ops-unmap_range(domain, iova, size);
 }
 EXPORT_SYMBOL_GPL(iommu_unmap_range);
 
diff --git a/drivers/pci/intel-iommu.c b/drivers/pci/intel-iommu.c
index 4173125..a714e3d 100644
--- a/drivers/pci/intel-iommu.c
+++ b/drivers/pci/intel-iommu.c
@@ -3714,8 +3714,8 @@ static struct iommu_ops intel_iommu_ops = {
.domain_destroy = intel_iommu_domain_destroy,
.attach_dev = intel_iommu_attach_device,
.detach_dev = intel_iommu_detach_device,
-   .map= intel_iommu_map_range,
-   .unmap  = intel_iommu_unmap_range,
+   .map_range  = intel_iommu_map_range,
+   .unmap_range= intel_iommu_unmap_range,
.iova_to_phys   = intel_iommu_iova_to_phys,
.domain_has_cap = intel_iommu_domain_has_cap,
 };
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 3af4ffd..0f18f37 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -36,10 +36,10 @@ struct iommu_ops {
void (*domain_destroy)(struct iommu_domain *domain);
int (*attach_dev)(struct iommu_domain *domain, struct device *dev);
void (*detach_dev)(struct iommu_domain *domain, struct device *dev);
-   int (*map)(struct iommu_domain *domain, unsigned long iova,
-  phys_addr_t paddr, size_t size, int prot);
-   void (*unmap)(struct iommu_domain *domain, unsigned long iova,
- size_t size);
+   int (*map_range)(struct iommu_domain *domain, unsigned long iova,
+phys_addr_t paddr, size_t size, int prot);
+   void (*unmap_range)(struct iommu_domain *domain, unsigned long iova,
+   size_t size);
phys_addr_t (*iova_to_phys)(struct iommu_domain *domain,
unsigned long iova);
int (*domain_has_cap)(struct iommu_domain *domain,
-- 
1.6.6


--
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


[PATCH 07/11] x86/amd-iommu: Make iommu_map_page and alloc_pte aware of page sizes

2010-01-28 Thread Joerg Roedel
This patch changes the old map_size parameter of alloc_pte
to a page_size parameter which can be used more easily to
alloc a pte for intermediate page sizes.

Signed-off-by: Joerg Roedel joerg.roe...@amd.com
---
 arch/x86/include/asm/amd_iommu_types.h |   28 +
 arch/x86/kernel/amd_iommu.c|   53 
 2 files changed, 61 insertions(+), 20 deletions(-)

diff --git a/arch/x86/include/asm/amd_iommu_types.h 
b/arch/x86/include/asm/amd_iommu_types.h
index ba19ad4..5e8da56 100644
--- a/arch/x86/include/asm/amd_iommu_types.h
+++ b/arch/x86/include/asm/amd_iommu_types.h
@@ -172,6 +172,34 @@
(~((1ULL  (12 + ((lvl) * 9))) - 1)))
 #define PM_ALIGNED(lvl, addr)  ((PM_MAP_MASK(lvl)  (addr)) == (addr))
 
+/*
+ * Returns the page table level to use for a given page size
+ * Pagesize is expected to be a power-of-two
+ */
+#define PAGE_SIZE_LEVEL(pagesize) \
+   ((__ffs(pagesize) - 12) / 9)
+/*
+ * Returns the number of ptes to use for a given page size
+ * Pagesize is expected to be a power-of-two
+ */
+#define PAGE_SIZE_PTE_COUNT(pagesize) \
+   (1ULL  ((__ffs(pagesize) - 12) % 9))
+
+/*
+ * Aligns a given io-virtual address to a given page size
+ * Pagesize is expected to be a power-of-two
+ */
+#define PAGE_SIZE_ALIGN(address, pagesize) \
+   ((address)  ~((pagesize) - 1))
+/*
+ * Creates an IOMMU PTE for an address an a given pagesize
+ * The PTE has no permission bits set
+ * Pagesize is expected to be a power-of-two larger than 4096
+ */
+#define PAGE_SIZE_PTE(address, pagesize)   \
+   (((address) | ((pagesize) - 1))\
+(~(pagesize  1))  PM_ADDR_MASK)
+
 #define IOMMU_PTE_P  (1ULL  0)
 #define IOMMU_PTE_TV (1ULL  1)
 #define IOMMU_PTE_U  (1ULL  59)
diff --git a/arch/x86/kernel/amd_iommu.c b/arch/x86/kernel/amd_iommu.c
index 59cae7c..4170031 100644
--- a/arch/x86/kernel/amd_iommu.c
+++ b/arch/x86/kernel/amd_iommu.c
@@ -730,18 +730,22 @@ static bool increase_address_space(struct 
protection_domain *domain,
 
 static u64 *alloc_pte(struct protection_domain *domain,
  unsigned long address,
- int end_lvl,
+ unsigned long page_size,
  u64 **pte_page,
  gfp_t gfp)
 {
+   int level, end_lvl;
u64 *pte, *page;
-   int level;
+
+   BUG_ON(!is_power_of_2(page_size));
 
while (address  PM_LEVEL_SIZE(domain-mode))
increase_address_space(domain, gfp);
 
-   level =  domain-mode - 1;
-   pte   = domain-pt_root[PM_LEVEL_INDEX(level, address)];
+   level   = domain-mode - 1;
+   pte = domain-pt_root[PM_LEVEL_INDEX(level, address)];
+   address = PAGE_SIZE_ALIGN(address, page_size);
+   end_lvl = PAGE_SIZE_LEVEL(page_size);
 
while (level  end_lvl) {
if (!IOMMU_PTE_PRESENT(*pte)) {
@@ -751,6 +755,10 @@ static u64 *alloc_pte(struct protection_domain *domain,
*pte = PM_LEVEL_PDE(level, virt_to_phys(page));
}
 
+   /* No level skipping support yet */
+   if (PM_PTE_LEVEL(*pte) != level)
+   return NULL;
+
level -= 1;
 
pte = IOMMU_PTE_PAGE(*pte);
@@ -806,31 +814,36 @@ static int iommu_map_page(struct protection_domain *dom,
  unsigned long bus_addr,
  unsigned long phys_addr,
  int prot,
- int map_size)
+ unsigned long page_size)
 {
u64 __pte, *pte;
-
-   bus_addr  = PAGE_ALIGN(bus_addr);
-   phys_addr = PAGE_ALIGN(phys_addr);
-
-   BUG_ON(!PM_ALIGNED(map_size, bus_addr));
-   BUG_ON(!PM_ALIGNED(map_size, phys_addr));
+   int i, count;
 
if (!(prot  IOMMU_PROT_MASK))
return -EINVAL;
 
-   pte = alloc_pte(dom, bus_addr, map_size, NULL, GFP_KERNEL);
+   bus_addr  = PAGE_ALIGN(bus_addr);
+   phys_addr = PAGE_ALIGN(phys_addr);
+   count = PAGE_SIZE_PTE_COUNT(page_size);
+   pte   = alloc_pte(dom, bus_addr, page_size, NULL, GFP_KERNEL);
+
+   for (i = 0; i  count; ++i)
+   if (IOMMU_PTE_PRESENT(pte[i]))
+   return -EBUSY;
 
-   if (IOMMU_PTE_PRESENT(*pte))
-   return -EBUSY;
+   if (page_size  PAGE_SIZE) {
+   __pte = PAGE_SIZE_PTE(phys_addr, page_size);
+   __pte |= PM_LEVEL_ENC(7) | IOMMU_PTE_P | IOMMU_PTE_FC;
+   } else
+   __pte = phys_addr | IOMMU_PTE_P | IOMMU_PTE_FC;
 
-   __pte = phys_addr | IOMMU_PTE_P;
if (prot  IOMMU_PROT_IR)
__pte |= IOMMU_PTE_IR;
if (prot  IOMMU_PROT_IW)
__pte |= IOMMU_PTE_IW;
 
-   *pte = __pte;
+   for (i = 0; i  count; ++i)
+   pte[i] = __pte;
 
update_domain(dom);
 

[PATCH 10/11] x86/amd-iommu: Implement -{un}map callbacks for iommu-api

2010-01-28 Thread Joerg Roedel
This patch implements the new callbacks for the IOMMU-API
with functions that can handle different page sizes in the
IOMMU page table.

Signed-off-by: Joerg Roedel joerg.roe...@amd.com
---
 arch/x86/kernel/amd_iommu.c |   29 +
 1 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kernel/amd_iommu.c b/arch/x86/kernel/amd_iommu.c
index 52e44af..0e068c9 100644
--- a/arch/x86/kernel/amd_iommu.c
+++ b/arch/x86/kernel/amd_iommu.c
@@ -2552,6 +2552,33 @@ static void amd_iommu_unmap_range(struct iommu_domain 
*dom,
iommu_flush_tlb_pde(domain);
 }
 
+static int amd_iommu_map(struct iommu_domain *dom, unsigned long iova,
+phys_addr_t paddr, int gfp_order, int iommu_prot)
+{
+   unsigned long page_size = 0x1000UL  gfp_order;
+   struct protection_domain *domain = dom-priv;
+   int prot = 0;
+
+   if (iommu_prot  IOMMU_READ)
+   prot |= IOMMU_PROT_IR;
+   if (iommu_prot  IOMMU_WRITE)
+   prot |= IOMMU_PROT_IW;
+
+   return iommu_map_page(domain, iova, paddr, prot, page_size);
+}
+
+static int amd_iommu_unmap(struct iommu_domain *dom, unsigned long iova,
+  int gfp_order)
+{
+   struct protection_domain *domain = dom-priv;
+   unsigned long page_size, unmap_size;
+
+   page_size  = 0x1000UL  gfp_order;
+   unmap_size = iommu_unmap_page(domain, iova, page_size);
+
+   return get_order(unmap_size);
+}
+
 static phys_addr_t amd_iommu_iova_to_phys(struct iommu_domain *dom,
  unsigned long iova)
 {
@@ -2587,6 +2614,8 @@ static struct iommu_ops amd_iommu_ops = {
.domain_destroy = amd_iommu_domain_destroy,
.attach_dev = amd_iommu_attach_device,
.detach_dev = amd_iommu_detach_device,
+   .map = amd_iommu_map,
+   .unmap = amd_iommu_unmap,
.map_range = amd_iommu_map_range,
.unmap_range = amd_iommu_unmap_range,
.iova_to_phys = amd_iommu_iova_to_phys,
-- 
1.6.6


--
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


[PATCH 11/11] iommu-api: Remove iommu_{un}map_range functions

2010-01-28 Thread Joerg Roedel
These functions are not longer used and can be removed
savely. There functionality is now provided by the
iommu_{un}map functions which are also capable of multiple
page sizes.

Signed-off-by: Joerg Roedel joerg.roe...@amd.com
---
 arch/x86/kernel/amd_iommu.c |   48 ---
 drivers/base/iommu.c|   26 +-
 include/linux/iommu.h   |   20 -
 3 files changed, 2 insertions(+), 92 deletions(-)

diff --git a/arch/x86/kernel/amd_iommu.c b/arch/x86/kernel/amd_iommu.c
index 0e068c9..d8da998 100644
--- a/arch/x86/kernel/amd_iommu.c
+++ b/arch/x86/kernel/amd_iommu.c
@@ -2506,52 +2506,6 @@ static int amd_iommu_attach_device(struct iommu_domain 
*dom,
return ret;
 }
 
-static int amd_iommu_map_range(struct iommu_domain *dom,
-  unsigned long iova, phys_addr_t paddr,
-  size_t size, int iommu_prot)
-{
-   struct protection_domain *domain = dom-priv;
-   unsigned long i,  npages = iommu_num_pages(paddr, size, PAGE_SIZE);
-   int prot = 0;
-   int ret;
-
-   if (iommu_prot  IOMMU_READ)
-   prot |= IOMMU_PROT_IR;
-   if (iommu_prot  IOMMU_WRITE)
-   prot |= IOMMU_PROT_IW;
-
-   iova  = PAGE_MASK;
-   paddr = PAGE_MASK;
-
-   for (i = 0; i  npages; ++i) {
-   ret = iommu_map_page(domain, iova, paddr, prot, PAGE_SIZE);
-   if (ret)
-   return ret;
-
-   iova  += PAGE_SIZE;
-   paddr += PAGE_SIZE;
-   }
-
-   return 0;
-}
-
-static void amd_iommu_unmap_range(struct iommu_domain *dom,
- unsigned long iova, size_t size)
-{
-
-   struct protection_domain *domain = dom-priv;
-   unsigned long i,  npages = iommu_num_pages(iova, size, PAGE_SIZE);
-
-   iova  = PAGE_MASK;
-
-   for (i = 0; i  npages; ++i) {
-   iommu_unmap_page(domain, iova, PAGE_SIZE);
-   iova  += PAGE_SIZE;
-   }
-
-   iommu_flush_tlb_pde(domain);
-}
-
 static int amd_iommu_map(struct iommu_domain *dom, unsigned long iova,
 phys_addr_t paddr, int gfp_order, int iommu_prot)
 {
@@ -2616,8 +2570,6 @@ static struct iommu_ops amd_iommu_ops = {
.detach_dev = amd_iommu_detach_device,
.map = amd_iommu_map,
.unmap = amd_iommu_unmap,
-   .map_range = amd_iommu_map_range,
-   .unmap_range = amd_iommu_unmap_range,
.iova_to_phys = amd_iommu_iova_to_phys,
.domain_has_cap = amd_iommu_domain_has_cap,
 };
diff --git a/drivers/base/iommu.c b/drivers/base/iommu.c
index 55d37e4..6e6b6a1 100644
--- a/drivers/base/iommu.c
+++ b/drivers/base/iommu.c
@@ -80,20 +80,6 @@ void iommu_detach_device(struct iommu_domain *domain, struct 
device *dev)
 }
 EXPORT_SYMBOL_GPL(iommu_detach_device);
 
-int iommu_map_range(struct iommu_domain *domain, unsigned long iova,
-   phys_addr_t paddr, size_t size, int prot)
-{
-   return iommu_ops-map_range(domain, iova, paddr, size, prot);
-}
-EXPORT_SYMBOL_GPL(iommu_map_range);
-
-void iommu_unmap_range(struct iommu_domain *domain, unsigned long iova,
- size_t size)
-{
-   iommu_ops-unmap_range(domain, iova, size);
-}
-EXPORT_SYMBOL_GPL(iommu_unmap_range);
-
 phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain,
   unsigned long iova)
 {
@@ -119,10 +105,7 @@ int iommu_map(struct iommu_domain *domain, unsigned long 
iova,
 
BUG_ON((iova | paddr)  invalid_mask);
 
-   if (iommu_ops-map)
-   return iommu_ops-map(domain, iova, paddr, gfp_order, prot);
-
-   return iommu_ops-map_range(domain, iova, paddr, size, prot);
+   return iommu_ops-map(domain, iova, paddr, gfp_order, prot);
 }
 EXPORT_SYMBOL_GPL(iommu_map);
 
@@ -136,11 +119,6 @@ int iommu_unmap(struct iommu_domain *domain, unsigned long 
iova, int gfp_order)
 
BUG_ON(iova  invalid_mask);
 
-   if (iommu_ops-unmap)
-   return iommu_ops-unmap(domain, iova, gfp_order);
-
-   iommu_ops-unmap_range(domain, iova, size);
-
-   return gfp_order;
+   return iommu_ops-unmap(domain, iova, gfp_order);
 }
 EXPORT_SYMBOL_GPL(iommu_unmap);
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 5a7a3d8..be22ad8 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -40,10 +40,6 @@ struct iommu_ops {
   phys_addr_t paddr, int gfp_order, int prot);
int (*unmap)(struct iommu_domain *domain, unsigned long iova,
 int gfp_order);
-   int (*map_range)(struct iommu_domain *domain, unsigned long iova,
-phys_addr_t paddr, size_t size, int prot);
-   void (*unmap_range)(struct iommu_domain *domain, unsigned long iova,
-   size_t size);
phys_addr_t (*iova_to_phys)(struct iommu_domain *domain,

[PATCH 0/11] Large Page Support for IOMMU-API and KVM

2010-01-28 Thread Joerg Roedel
Hi,

here is a patch set which implements support for variable page sizes in the
IOMMU-API and changes the KVM device passthrough code to map the guest physical
memory with the best page sizes.

With this code a guest with 1GB of memory mapped with a 1GB page will not use
4kb PTEs in the IO page table but will map this memory with these page sizes:

512k, 128k, io hole, 1M, 2M, 4M, 8M, 16M, 32M, 64M, 128M, 256M and 512M

instead.

This code also changes the AMD IOMMU driver to implement these page sizes in
the IO page tables.
Please review these patches and send me any comments you might have :-)

To test this code some fixes in the AMD IOMMU driver are required which are
currently in the -tip tree and will probably hit upstream soon. If anybody want
to test this code please pull the code from 

git://git.kernel.org/pub/scm/linux/kernel/git/joro/linux-2.6-iommu.git 
iommu/largepages

This branch is based on avi/master and contains the fixes and the patches from
this patchset.

Thanks,

Joerg

Diffstat:

 arch/x86/include/asm/amd_iommu_types.h |   34 ++
 arch/x86/kernel/amd_iommu.c|  195 
 arch/x86/kvm/mmu.c |   18 +---
 drivers/base/iommu.c   |   43 +---
 drivers/pci/intel-iommu.c  |   22 ++--
 include/linux/iommu.h  |   24 ++--
 include/linux/kvm_host.h   |1 +
 virt/kvm/iommu.c   |  106 ++
 virt/kvm/kvm_main.c|   25 
 9 files changed, 323 insertions(+), 145 deletions(-)

Shortlog:

Joerg Roedel (11):
  iommu-api: Rename -{un}map function pointers to -{un}map_range
  iommu-api: Add iommu_map and iommu_unmap functions
  iommu-api: Add -{un}map callbacks to iommu_ops
  VT-d: Change {un}map_range functions to implement {un}map interface
  kvm: Introduce kvm_host_page_size
  kvm: Change kvm_iommu_map_pages to map large pages
  x86/amd-iommu: Make iommu_map_page and alloc_pte aware of page sizes
  x86/amd-iommu: Make iommu_unmap_page and fetch_pte aware of page sizes
  x86/amd-iommu: Make amd_iommu_iova_to_phys aware of multiple page sizes
  x86/amd-iommu: Implement -{un}map callbacks for iommu-api
  iommu-api: Remove iommu_{un}map_range functions



--
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


[PATCH 06/11] kvm: Change kvm_iommu_map_pages to map large pages

2010-01-28 Thread Joerg Roedel
This patch changes the implementation of of
kvm_iommu_map_pages to map the pages with the host page size
into the io virtual address space.

Signed-off-by: Joerg Roedel joerg.roe...@amd.com
---
 virt/kvm/iommu.c |  106 ++---
 1 files changed, 84 insertions(+), 22 deletions(-)

diff --git a/virt/kvm/iommu.c b/virt/kvm/iommu.c
index 65a5143..92a434d 100644
--- a/virt/kvm/iommu.c
+++ b/virt/kvm/iommu.c
@@ -32,12 +32,27 @@ static int kvm_iommu_unmap_memslots(struct kvm *kvm);
 static void kvm_iommu_put_pages(struct kvm *kvm,
gfn_t base_gfn, unsigned long npages);
 
+static pfn_t kvm_pin_pages(struct kvm *kvm, struct kvm_memory_slot *slot,
+  gfn_t gfn, unsigned long size)
+{
+   gfn_t end_gfn;
+   pfn_t pfn;
+
+   pfn = gfn_to_pfn_memslot(kvm, slot, gfn);
+   end_gfn = gfn + (size  PAGE_SHIFT);
+   gfn+= 1;
+
+   while (gfn  end_gfn)
+   gfn_to_pfn_memslot(kvm, slot, gfn++);
+
+   return pfn;
+}
+
 int kvm_iommu_map_pages(struct kvm *kvm, struct kvm_memory_slot *slot)
 {
-   gfn_t gfn = slot-base_gfn;
-   unsigned long npages = slot-npages;
+   gfn_t gfn, end_gfn;
pfn_t pfn;
-   int i, r = 0;
+   int r = 0;
struct iommu_domain *domain = kvm-arch.iommu_domain;
int flags;
 
@@ -45,31 +60,58 @@ int kvm_iommu_map_pages(struct kvm *kvm, struct 
kvm_memory_slot *slot)
if (!domain)
return 0;
 
+   gfn = slot-base_gfn;
+   end_gfn = gfn + slot-npages;
+
flags = IOMMU_READ | IOMMU_WRITE;
if (kvm-arch.iommu_flags  KVM_IOMMU_CACHE_COHERENCY)
flags |= IOMMU_CACHE;
 
-   for (i = 0; i  npages; i++) {
-   /* check if already mapped */
-   if (iommu_iova_to_phys(domain, gfn_to_gpa(gfn)))
+
+   while (gfn  end_gfn) {
+   unsigned long page_size;
+
+   /* Check if already mapped */
+   if (iommu_iova_to_phys(domain, gfn_to_gpa(gfn))) {
+   gfn += 1;
continue;
+   }
+
+   /* Get the page size we could use to map */
+   page_size = kvm_host_page_size(kvm, gfn);
+
+   /* Make sure the page_size does not exceed the memslot */
+   while ((gfn + (page_size  PAGE_SHIFT))  end_gfn)
+   page_size = 1;
+
+   /* Make sure gfn is aligned to the page size we want to map */
+   while ((gfn  PAGE_SHIFT)  (page_size - 1))
+   page_size = 1;
+
+   /*
+* Pin all pages we are about to map in memory. This is
+* important because we unmap and unpin in 4kb steps later.
+*/
+   pfn = kvm_pin_pages(kvm, slot, gfn, page_size);
+
+   /* Map into IO address space */
+   r = iommu_map(domain, gfn_to_gpa(gfn), pfn_to_hpa(pfn),
+ get_order(page_size), flags);
+
+   gfn += page_size  PAGE_SHIFT;
 
-   pfn = gfn_to_pfn_memslot(kvm, slot, gfn);
-   r = iommu_map_range(domain,
-   gfn_to_gpa(gfn),
-   pfn_to_hpa(pfn),
-   PAGE_SIZE, flags);
if (r) {
printk(KERN_ERR kvm_iommu_map_address:
   iommu failed to map pfn=%lx\n, pfn);
goto unmap_pages;
}
-   gfn++;
+
}
+
return 0;
 
 unmap_pages:
-   kvm_iommu_put_pages(kvm, slot-base_gfn, i);
+   kvm_iommu_put_pages(kvm, slot-base_gfn, gfn);
return r;
 }
 
@@ -186,27 +228,47 @@ out_unmap:
return r;
 }
 
+static void kvm_unpin_pages(struct kvm *kvm, pfn_t pfn, unsigned long npages)
+{
+   unsigned long i;
+
+   for (i = 0; i  npages; ++i)
+   kvm_release_pfn_clean(pfn + i);
+}
+
 static void kvm_iommu_put_pages(struct kvm *kvm,
gfn_t base_gfn, unsigned long npages)
 {
-   gfn_t gfn = base_gfn;
+   struct iommu_domain *domain;
+   gfn_t end_gfn, gfn;
pfn_t pfn;
-   struct iommu_domain *domain = kvm-arch.iommu_domain;
-   unsigned long i;
u64 phys;
 
+   domain  = kvm-arch.iommu_domain;
+   end_gfn = base_gfn + npages;
+   gfn = base_gfn;
+
/* check if iommu exists and in use */
if (!domain)
return;
 
-   for (i = 0; i  npages; i++) {
+   while (gfn  end_gfn) {
+   unsigned long unmap_pages;
+   int order;
+
+   /* Get physical address */
phys = iommu_iova_to_phys(domain, gfn_to_gpa(gfn));
-   pfn = phys  PAGE_SHIFT;
-   kvm_release_pfn_clean(pfn);
-   gfn++;
-   }
+   pfn  = 

[PATCH 02/11] iommu-api: Add iommu_map and iommu_unmap functions

2010-01-28 Thread Joerg Roedel
These two functions provide support for mapping and
unmapping physical addresses to io virtual addresses. The
difference to the iommu_(un)map_range() is that the new
functions take a gfp_order parameter instead of a size. This
allows the IOMMU backend implementations to detect easier if
a given range can be mapped by larger page sizes.
These new functions should replace the old ones in the long
term.

Signed-off-by: Joerg Roedel joerg.roe...@amd.com
---
 drivers/base/iommu.c  |   31 +++
 include/linux/iommu.h |   16 
 2 files changed, 47 insertions(+), 0 deletions(-)

diff --git a/drivers/base/iommu.c b/drivers/base/iommu.c
index f4c86c4..cf7cbec 100644
--- a/drivers/base/iommu.c
+++ b/drivers/base/iommu.c
@@ -107,3 +107,34 @@ int iommu_domain_has_cap(struct iommu_domain *domain,
return iommu_ops-domain_has_cap(domain, cap);
 }
 EXPORT_SYMBOL_GPL(iommu_domain_has_cap);
+
+int iommu_map(struct iommu_domain *domain, unsigned long iova,
+ phys_addr_t paddr, int gfp_order, int prot)
+{
+   unsigned long invalid_mask;
+   size_t size;
+
+   size = 0x1000UL  gfp_order;
+   invalid_mask = size - 1;
+
+   BUG_ON((iova | paddr)  invalid_mask);
+
+   return iommu_ops-map_range(domain, iova, paddr, size, prot);
+}
+EXPORT_SYMBOL_GPL(iommu_map);
+
+int iommu_unmap(struct iommu_domain *domain, unsigned long iova, int gfp_order)
+{
+   unsigned long invalid_mask;
+   size_t size;
+
+   size = 0x1000UL  gfp_order;
+   invalid_mask = size - 1;
+
+   BUG_ON(iova  invalid_mask);
+
+   iommu_ops-unmap_range(domain, iova, size);
+
+   return gfp_order;
+}
+EXPORT_SYMBOL_GPL(iommu_unmap);
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 0f18f37..6d0035b 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -60,6 +60,10 @@ extern int iommu_map_range(struct iommu_domain *domain, 
unsigned long iova,
   phys_addr_t paddr, size_t size, int prot);
 extern void iommu_unmap_range(struct iommu_domain *domain, unsigned long iova,
  size_t size);
+extern int iommu_map(struct iommu_domain *domain, unsigned long iova,
+phys_addr_t paddr, int gfp_order, int prot);
+extern int iommu_unmap(struct iommu_domain *domain, unsigned long iova,
+  int gfp_order);
 extern phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain,
  unsigned long iova);
 extern int iommu_domain_has_cap(struct iommu_domain *domain,
@@ -108,6 +112,18 @@ static inline void iommu_unmap_range(struct iommu_domain 
*domain,
 {
 }
 
+static inline int iommu_map(struct iommu_domain *domain, unsigned long iova,
+   phys_addr_t paddr, int gfp_order, int prot)
+{
+   return -ENODEV;
+}
+
+static inline int iommu_unmap(struct iommu_domain *domain, unsigned long iova,
+ int gfp_order)
+{
+   return -ENODEV;
+}
+
 static inline phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain,
 unsigned long iova)
 {
-- 
1.6.6


--
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


[PATCH 09/11] x86/amd-iommu: Make amd_iommu_iova_to_phys aware of multiple page sizes

2010-01-28 Thread Joerg Roedel
This patch extends the amd_iommu_iova_to_phys() function to
handle different page sizes correctly. It doesn't use
fetch_pte() anymore because we don't know (or care about)
the page_size used for mapping the given iova.

Signed-off-by: Joerg Roedel joerg.roe...@amd.com
---
 arch/x86/kernel/amd_iommu.c |   13 +
 1 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/amd_iommu.c b/arch/x86/kernel/amd_iommu.c
index 503d312..52e44af 100644
--- a/arch/x86/kernel/amd_iommu.c
+++ b/arch/x86/kernel/amd_iommu.c
@@ -2556,17 +2556,22 @@ static phys_addr_t amd_iommu_iova_to_phys(struct 
iommu_domain *dom,
  unsigned long iova)
 {
struct protection_domain *domain = dom-priv;
-   unsigned long offset = iova  ~PAGE_MASK;
+   unsigned long offset_mask;
phys_addr_t paddr;
-   u64 *pte;
+   u64 *pte, __pte;
 
pte = fetch_pte(domain, iova);
 
if (!pte || !IOMMU_PTE_PRESENT(*pte))
return 0;
 
-   paddr  = *pte  IOMMU_PAGE_MASK;
-   paddr |= offset;
+   if (PM_PTE_LEVEL(*pte) == 0)
+   offset_mask = PAGE_SIZE - 1;
+   else
+   offset_mask = PTE_PAGE_SIZE(*pte) - 1;
+
+   __pte = *pte  PM_ADDR_MASK;
+   paddr = (__pte  ~offset_mask) | (iova  offset_mask);
 
return paddr;
 }
-- 
1.6.6


--
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


[PATCH 03/11] iommu-api: Add -{un}map callbacks to iommu_ops

2010-01-28 Thread Joerg Roedel
This patch adds new callbacks for mapping and unmapping
pages to the iommu_ops structure. These callbacks are aware
of page sizes which makes them different to the
-{un}map_range callbacks.

Signed-off-by: Joerg Roedel joerg.roe...@amd.com
---
 drivers/base/iommu.c  |6 ++
 include/linux/iommu.h |4 
 2 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/drivers/base/iommu.c b/drivers/base/iommu.c
index cf7cbec..55d37e4 100644
--- a/drivers/base/iommu.c
+++ b/drivers/base/iommu.c
@@ -119,6 +119,9 @@ int iommu_map(struct iommu_domain *domain, unsigned long 
iova,
 
BUG_ON((iova | paddr)  invalid_mask);
 
+   if (iommu_ops-map)
+   return iommu_ops-map(domain, iova, paddr, gfp_order, prot);
+
return iommu_ops-map_range(domain, iova, paddr, size, prot);
 }
 EXPORT_SYMBOL_GPL(iommu_map);
@@ -133,6 +136,9 @@ int iommu_unmap(struct iommu_domain *domain, unsigned long 
iova, int gfp_order)
 
BUG_ON(iova  invalid_mask);
 
+   if (iommu_ops-unmap)
+   return iommu_ops-unmap(domain, iova, gfp_order);
+
iommu_ops-unmap_range(domain, iova, size);
 
return gfp_order;
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 6d0035b..5a7a3d8 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -36,6 +36,10 @@ struct iommu_ops {
void (*domain_destroy)(struct iommu_domain *domain);
int (*attach_dev)(struct iommu_domain *domain, struct device *dev);
void (*detach_dev)(struct iommu_domain *domain, struct device *dev);
+   int (*map)(struct iommu_domain *domain, unsigned long iova,
+  phys_addr_t paddr, int gfp_order, int prot);
+   int (*unmap)(struct iommu_domain *domain, unsigned long iova,
+int gfp_order);
int (*map_range)(struct iommu_domain *domain, unsigned long iova,
 phys_addr_t paddr, size_t size, int prot);
void (*unmap_range)(struct iommu_domain *domain, unsigned long iova,
-- 
1.6.6


--
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


[PATCH 08/11] x86/amd-iommu: Make iommu_unmap_page and fetch_pte aware of page sizes

2010-01-28 Thread Joerg Roedel
This patch extends the functionality of iommu_unmap_page
and fetch_pte to support arbitrary page sizes.

Signed-off-by: Joerg Roedel joerg.roe...@amd.com
---
 arch/x86/include/asm/amd_iommu_types.h |6 ++
 arch/x86/kernel/amd_iommu.c|   90 +--
 2 files changed, 78 insertions(+), 18 deletions(-)

diff --git a/arch/x86/include/asm/amd_iommu_types.h 
b/arch/x86/include/asm/amd_iommu_types.h
index 5e8da56..b150c74 100644
--- a/arch/x86/include/asm/amd_iommu_types.h
+++ b/arch/x86/include/asm/amd_iommu_types.h
@@ -200,6 +200,12 @@
(((address) | ((pagesize) - 1))\
 (~(pagesize  1))  PM_ADDR_MASK)
 
+/*
+ * Takes a PTE value with mode=0x07 and returns the page size it maps
+ */
+#define PTE_PAGE_SIZE(pte) \
+   (1ULL  (1 + ffz(((pte) | 0xfffULL
+
 #define IOMMU_PTE_P  (1ULL  0)
 #define IOMMU_PTE_TV (1ULL  1)
 #define IOMMU_PTE_U  (1ULL  59)
diff --git a/arch/x86/kernel/amd_iommu.c b/arch/x86/kernel/amd_iommu.c
index 4170031..503d312 100644
--- a/arch/x86/kernel/amd_iommu.c
+++ b/arch/x86/kernel/amd_iommu.c
@@ -776,28 +776,47 @@ static u64 *alloc_pte(struct protection_domain *domain,
  * This function checks if there is a PTE for a given dma address. If
  * there is one, it returns the pointer to it.
  */
-static u64 *fetch_pte(struct protection_domain *domain,
- unsigned long address, int map_size)
+static u64 *fetch_pte(struct protection_domain *domain, unsigned long address)
 {
int level;
u64 *pte;
 
-   level =  domain-mode - 1;
-   pte   = domain-pt_root[PM_LEVEL_INDEX(level, address)];
+   if (address  PM_LEVEL_SIZE(domain-mode))
+   return NULL;
+
+   level   =  domain-mode - 1;
+   pte = domain-pt_root[PM_LEVEL_INDEX(level, address)];
 
-   while (level  map_size) {
+   while (level  0) {
+
+   /* Not Present */
if (!IOMMU_PTE_PRESENT(*pte))
return NULL;
 
+   /* Large PTE */
+   if (PM_PTE_LEVEL(*pte) == 0x07) {
+   unsigned long pte_mask, __pte;
+
+   /*
+* If we have a series of large PTEs, make
+* sure to return a pointer to the first one.
+*/
+   pte_mask = PTE_PAGE_SIZE(*pte);
+   pte_mask = ~((PAGE_SIZE_PTE_COUNT(pte_mask)  3) - 1);
+   __pte= ((unsigned long)pte)  pte_mask;
+
+   return (u64 *)__pte;
+   }
+
+   /* No level skipping support yet */
+   if (PM_PTE_LEVEL(*pte) != level)
+   return NULL;
+
level -= 1;
 
+   /* Walk to the next level */
pte = IOMMU_PTE_PAGE(*pte);
pte = pte[PM_LEVEL_INDEX(level, address)];
-
-   if ((PM_PTE_LEVEL(*pte) == 0)  level != map_size) {
-   pte = NULL;
-   break;
-   }
}
 
return pte;
@@ -850,13 +869,48 @@ static int iommu_map_page(struct protection_domain *dom,
return 0;
 }
 
-static void iommu_unmap_page(struct protection_domain *dom,
-unsigned long bus_addr, int map_size)
+static unsigned long iommu_unmap_page(struct protection_domain *dom,
+ unsigned long bus_addr,
+ unsigned long page_size)
 {
-   u64 *pte = fetch_pte(dom, bus_addr, map_size);
+   unsigned long long unmap_size, unmapped;
+   u64 *pte;
+
+   BUG_ON(!is_power_of_2(page_size));
+
+   unmapped = 0;
+
+   while (unmapped  page_size) {
+
+   pte = fetch_pte(dom, bus_addr);
+
+   if (!pte) {
+   /*
+* No PTE for this address
+* move forward in 4kb steps
+*/
+   unmap_size = PAGE_SIZE;
+   } else if (PM_PTE_LEVEL(*pte) == 0) {
+   /* 4kb PTE found for this address */
+   unmap_size = PAGE_SIZE;
+   *pte   = 0ULL;
+   } else {
+   int count, i;
+
+   /* Large PTE found which maps this address */
+   unmap_size = PTE_PAGE_SIZE(*pte);
+   count  = PAGE_SIZE_PTE_COUNT(unmap_size);
+   for (i = 0; i  count; i++)
+   pte[i] = 0ULL;
+   }
+
+   bus_addr  = (bus_addr  ~(unmap_size - 1)) + unmap_size;
+   unmapped += unmap_size;
+   }
+
+   BUG_ON(!is_power_of_2(unmapped));
 
-   if (pte)
-   *pte = 0;
+   return unmapped;
 }
 
 /*
@@ -1054,7 +1108,7 @@ static int alloc_new_range(struct dma_ops_domain *dma_dom,
for (i = 

[PATCH 04/11] VT-d: Change {un}map_range functions to implement {un}map interface

2010-01-28 Thread Joerg Roedel
This patch changes the iommu-api functions for mapping and
unmapping page ranges to use the new page-size based
interface. This allows to remove the range based functions
later.

Signed-off-by: Joerg Roedel joerg.roe...@amd.com
---
 drivers/pci/intel-iommu.c |   22 --
 1 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/drivers/pci/intel-iommu.c b/drivers/pci/intel-iommu.c
index a714e3d..f1d3b85 100644
--- a/drivers/pci/intel-iommu.c
+++ b/drivers/pci/intel-iommu.c
@@ -3626,14 +3626,15 @@ static void intel_iommu_detach_device(struct 
iommu_domain *domain,
domain_remove_one_dev_info(dmar_domain, pdev);
 }
 
-static int intel_iommu_map_range(struct iommu_domain *domain,
-unsigned long iova, phys_addr_t hpa,
-size_t size, int iommu_prot)
+static int intel_iommu_map(struct iommu_domain *domain,
+  unsigned long iova, phys_addr_t hpa,
+  int gfp_order, int iommu_prot)
 {
struct dmar_domain *dmar_domain = domain-priv;
u64 max_addr;
int addr_width;
int prot = 0;
+   size_t size;
int ret;
 
if (iommu_prot  IOMMU_READ)
@@ -3643,6 +3644,7 @@ static int intel_iommu_map_range(struct iommu_domain 
*domain,
if ((iommu_prot  IOMMU_CACHE)  dmar_domain-iommu_snooping)
prot |= DMA_PTE_SNP;
 
+   size = 0x1000UL  gfp_order;
max_addr = iova + size;
if (dmar_domain-max_addr  max_addr) {
int min_agaw;
@@ -3669,19 +3671,19 @@ static int intel_iommu_map_range(struct iommu_domain 
*domain,
return ret;
 }
 
-static void intel_iommu_unmap_range(struct iommu_domain *domain,
-   unsigned long iova, size_t size)
+static int intel_iommu_unmap(struct iommu_domain *domain,
+unsigned long iova, int gfp_order)
 {
struct dmar_domain *dmar_domain = domain-priv;
-
-   if (!size)
-   return;
+   size_t size = 0x1000UL  gfp_order;
 
dma_pte_clear_range(dmar_domain, iova  VTD_PAGE_SHIFT,
(iova + size - 1)  VTD_PAGE_SHIFT);
 
if (dmar_domain-max_addr == iova + size)
dmar_domain-max_addr = iova;
+
+   return gfp_order;
 }
 
 static phys_addr_t intel_iommu_iova_to_phys(struct iommu_domain *domain,
@@ -3714,8 +3716,8 @@ static struct iommu_ops intel_iommu_ops = {
.domain_destroy = intel_iommu_domain_destroy,
.attach_dev = intel_iommu_attach_device,
.detach_dev = intel_iommu_detach_device,
-   .map_range  = intel_iommu_map_range,
-   .unmap_range= intel_iommu_unmap_range,
+   .map= intel_iommu_map,
+   .unmap  = intel_iommu_unmap,
.iova_to_phys   = intel_iommu_iova_to_phys,
.domain_has_cap = intel_iommu_domain_has_cap,
 };
-- 
1.6.6


--
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: KVM problems with Xeon L5530

2010-01-28 Thread Kenni Lund
2010/1/28 Matteo Ghezzi tenyos...@gmail.com:
SNIP
 I've tried starting the old vmachines on the new hardware but if I
 enable kvm acceleration in qemu I got a black screen via vnc, and the

Enable kvm in qemu? KVM should always be enabled in Arch, when you run
qemu-kvm. You're not running [qemu-executable] --enable-kvm from the
qemu package, right? Last time I checked, the KVM support in upstream
qemu wasn't very good and gave me various errors. Make sure you have
the qemu-kvm package installed and not the qemu package (which also
has KVM support).

Best Regards
Kenni Lund
--
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: [Autotest] [Autotest PATCH] KVM-test: Add a subtest 'qemu_img'

2010-01-28 Thread Lucas Meneghel Rodrigues
On Thu, 2010-01-28 at 17:37 +0800, Yolkfull Chow wrote:
 On Tue, Jan 26, 2010 at 03:11:34PM -0200, Lucas Meneghel Rodrigues wrote:
  That said, I was wondering if we could consolidate all qemu-img tests to
  a single execution, instead of splitting it to several variants. We
  could keep a failure record, execute all tests and fail the entire test
  if any of them failed. It's not like terribly important, but it seems
  more logical to group all qemu-img subcommands testing under a single
  test.
 
 Hi Lucas,
 
 After considering above suggestion about merging all qemu-img tests into 
 single test,
 I did decision that keep current method due to reason that:
  1) it's convenient to maintain so many parameters of each test variant.
  2) current method does not affect global results since even if one subtest 
 of 'qemu-img' failes,
 it will nor block following subtests (we can still get whole test results)
  3) it's possible for user to run single subtest of qemu-img, say only test 
 'rebase' subcommand
 
 As you also said this is not terribly important, let's keep it going. What's 
 your opinion?

Ok, I am fine with it!

Lucas

--
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


[ kvm-Bugs-2941282 ] Ubuntu 10.04 installer fails due to I/O errors with virtio

2010-01-28 Thread SourceForge.net
Bugs item #2941282, was opened at 2010-01-27 17:19
Message generated for change (Comment added) made by sjolshagen
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=893831aid=2941282group_id=180599

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 7
Private: No
Submitted By: Marti Raudsepp (intgr)
Assigned to: Nobody/Anonymous (nobody)
Summary: Ubuntu 10.04 installer fails due to I/O errors with virtio

Initial Comment:
I tried installing Ubuntu 10.04 and Fedora 12 in a KVM virtual machine using 
virtio, on a 8G raw file-backed disk. Both installers failed half-way due to 
I/O errors. So I tried reproducing it and managed to repeat it 6 times. The bug 
doesn't occur with IDE emulation. The bug happens fairly quickly with -smp 4 -- 
usually within 5 minutes -- but is much rarer with -smp 1.

Ubuntu installer has kernel 2.6.32-11-generic
Fedora 12 has kernel 2.6.31.5-127.fc12.x86_64
Host has kernel 2.6.32.6 (Arch Linux) and QEMU 0.12.2

When testing with -smp 1, it also produced a kernel oops from 
block/blk-core.c:245. This line warns when the function is called with 
interrupts enabled:
void blk_start_queue(struct request_queue *q)
{
WARN_ON(!irqs_disabled());

queue_flag_clear(QUEUE_FLAG_STOPPED, q);
__blk_run_queue(q);
}


--- host machine ---

[ma...@newn]% qemu-kvm --version
QEMU PC emulator version 0.12.2 (qemu-kvm-0.12.2), Copyright (c) 2003-2008 
Fabrice Bellard
[ma...@newn]% ps aux |grep crash
root 16283 31.4  7.1 427020 289960 ?   Sl   22:44   8:37 
/usr/bin/qemu-kvm -S -M pc-0.11 -enable-kvm -m 256 -smp 1 -name 
ubuntu-crashtest -uuid 0d7d4f2d-5589-160b-1f1b-75d46e293a2c -chardev 
socket,id=monitor,path=/var/lib/libvirt/qemu/ubuntu-crashtest.monitor,server,nowait
 -monitor chardev:monitor -boot d -drive 
file=/store/iso/lucid-desktop-amd64.iso,if=ide,media=cdrom,index=2,format=raw 
-drive file=/store/virt/ubuntu-crashtest.img,if=virtio,index=0,format=raw -net 
nic,macaddr=52:54:00:45:e7:19,vlan=0,name=nic.0 -net 
tap,fd=43,vlan=0,name=tap.0 -serial none -parallel none -usb -usbdevice tablet 
-vnc 127.0.0.1:1 -k en-us -vga cirrus -soundhw es1370 -balloon virtio
marti17700  0.0  0.0   8360   968 pts/4S+   23:11   0:00 grep crash
[ma...@newn]% stat /store/virt/ubuntu-crashtest.img
  File: `/store/virt/ubuntu-crashtest.img'
  Size: 8589934592  Blocks: 5615368IO Block: 4096   regular file
Device: fe01h/65025dInode: 4718596 Links: 1
Access: (0600/-rw---)  Uid: (0/root)   Gid: (0/root)
Access: 2010-01-27 22:43:45.128113080 +0200
Modify: 2010-01-27 23:09:11.523577452 +0200
Change: 2010-01-27 23:09:11.523577452 +0200
[ma...@newn]% uname -a
Linux newn 2.6.32-ARCH #1 SMP PREEMPT Mon Jan 25 20:33:50 CET 2010 x86_64 AMD 
Phenom(tm) II X4 940 Processor AuthenticAMD GNU/Linux
[ma...@newn]% cat /proc/cpuinfo
processor   : 0
vendor_id   : AuthenticAMD
cpu family  : 16
model   : 4
model name  : AMD Phenom(tm) II X4 940 Processor
stepping: 2
cpu MHz : 800.000
cache size  : 512 KB
physical id : 0
siblings: 4
core id : 0
cpu cores   : 4
apicid  : 0
initial apicid  : 0
fpu : yes
fpu_exception   : yes
cpuid level : 5
wp  : yes
flags   : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov 
pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb 
rdtscp lm 3dnowext 3dnow constant_tsc rep_good nonstop_tsc extd_apicid pni 
monitor cx16 popcnt lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a 
misalignsse 3dnowprefetch osvw ibs skinit wdt
bogomips: 6028.69
TLB size: 1024 4K pages
clflush size: 64
cache_alignment : 64
address sizes   : 48 bits physical, 48 bits virtual
power management: ts ttp tm stc 100mhzsteps hwpstate

*snip* three more CPU cores

--- Ubuntu guest VM ---

ubu...@ubuntu:/tmp$ uname -a
Linux ubuntu 2.6.32-11-generic #15-Ubuntu SMP Tue Jan 19 20:38:41 UTC 2010 
x86_64 GNU/Linux
ubu...@ubuntu:/tmp$ cat /sys/block/vda/stat
   7388948289  1661218   39497026765   947851  6284676  9459960
0   987890  9893220
ubu...@ubuntu:/tmp$ dmesg
[0.00] Initializing cgroup subsys cpuset
[0.00] Initializing cgroup subsys cpu
[0.00] Linux version 2.6.32-11-generic (bui...@crested) (gcc version 
4.4.3 20100116 (prerelease) (Ubuntu 4.4.2-9ubuntu4) ) #15-Ubuntu SMP Tue Jan 19 
20:38:41 UTC 2010 (Ubuntu 2.6.32-11.15-generic)
[0.00] Command line: BOOT_IMAGE=/casper/vmlinuz 
file=/cdrom/preseed/ubuntu.seed boot=casper only-ubiquity 
initrd=/casper/initrd.lz quiet splash --
[0.00] KERNEL supported cpus:
[0.00]   Intel GenuineIntel
[0.00]   AMD AuthenticAMD
[0.00]   Centaur CentaurHauls
[0.00] BIOS-provided 

[PATCH 0/5] KVM: Cleanups: X86EMUL_* related.

2010-01-28 Thread Takuya Yoshikawa
Hi,

Sorry for a bit noisy cleanups. But during this
work, we noticed some buggy return value checks
and determined to send this work as a patch series.

Thanks,
 Takuya Yoshikawa
--
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


[PATCH 1/5] KVM: Use X86EMUL_* to check the return value from read_std

2010-01-28 Thread Takuya Yoshikawa
read_std is one of the x86_emulate_ops. This patch fix the
return value check to use the proper macro.

Signed-off-by: Takuya Yoshikawa yoshikawa.tak...@oss.ntt.co.jp
---
 arch/x86/kvm/emulate.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 645b245..b124578 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -607,7 +607,7 @@ static int do_fetch_insn_byte(struct x86_emulate_ctxt *ctxt,
if (linear  fc-start || linear = fc-end) {
size = min(15UL, PAGE_SIZE - offset_in_page(linear));
rc = ops-read_std(linear, fc-data, size, ctxt-vcpu);
-   if (rc)
+   if (rc != X86EMUL_CONTINUE)
return rc;
fc-start = linear;
fc-end = linear + size;
@@ -662,7 +662,7 @@ static int read_descriptor(struct x86_emulate_ctxt *ctxt,
*address = 0;
rc = ops-read_std((unsigned long)ptr, (unsigned long *)size, 2,
   ctxt-vcpu);
-   if (rc)
+   if (rc != X86EMUL_CONTINUE)
return rc;
rc = ops-read_std((unsigned long)ptr + 2, address, op_bytes,
   ctxt-vcpu);
-- 
1.6.3.3

--
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-kvm: enable get/set vcpu events on reset and migration

2010-01-28 Thread Gleb Natapov
On Tue, Jan 26, 2010 at 10:26:22PM -0200, Marcelo Tosatti wrote:
 @@ -374,6 +375,7 @@ static int cpu_post_load(void *opaque, int version_id)
  
  kvm_load_tsc(env);
  kvm_load_mpstate(env);
 +kvm_put_vcpu_events(env);
  }
It is confusing to call functions load/save for some state and put/get for
others, but the function kvm_put_vcpu_events() is called upstream this
way :(

Otherwise looks OK.

--
Gleb.
--
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


[PATCH 3/5] KVM: Restrict rc values in x86_emulate_insn to X86EMUL_* values

2010-01-28 Thread Takuya Yoshikawa
This patch differentiate the X86EMUL_* values returned from
X86EMUL_* type functions.

Note: During this work, we noticed some buggy return value
  checks in x86_emulate_insn(). See FIXME in this patch.

Signed-off-by: Takuya Yoshikawa yoshikawa.tak...@oss.ntt.co.jp
---
 arch/x86/kvm/emulate.c |   73 +---
 1 files changed, 44 insertions(+), 29 deletions(-)

diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 9953f5b..d49e9de 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -1693,7 +1693,7 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt, struct 
x86_emulate_ops *ops)
struct decode_cache *c = ctxt-decode;
unsigned int port;
int io_dir_in;
-   int rc = 0;
+   int rc = X86EMUL_CONTINUE;
 
ctxt-interruptibility = 0;
 
@@ -1791,7 +1791,7 @@ special_insn:
break;
case 0x07:  /* pop es */
rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_ES);
-   if (rc != 0)
+   if (rc != X86EMUL_CONTINUE)
goto done;
break;
case 0x08 ... 0x0d:
@@ -1810,7 +1810,7 @@ special_insn:
break;
case 0x17:  /* pop ss */
rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_SS);
-   if (rc != 0)
+   if (rc != X86EMUL_CONTINUE)
goto done;
break;
case 0x18 ... 0x1d:
@@ -1822,7 +1822,7 @@ special_insn:
break;
case 0x1f:  /* pop ds */
rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_DS);
-   if (rc != 0)
+   if (rc != X86EMUL_CONTINUE)
goto done;
break;
case 0x20 ... 0x25:
@@ -1853,7 +1853,7 @@ special_insn:
case 0x58 ... 0x5f: /* pop reg */
pop_instruction:
rc = emulate_pop(ctxt, ops, c-dst.val, c-op_bytes);
-   if (rc != 0)
+   if (rc != X86EMUL_CONTINUE)
goto done;
break;
case 0x60:  /* pusha */
@@ -1861,7 +1861,7 @@ special_insn:
break;
case 0x61:  /* popa */
rc = emulate_popa(ctxt, ops);
-   if (rc != 0)
+   if (rc != X86EMUL_CONTINUE)
goto done;
break;
case 0x63:  /* movsxd */
@@ -2002,7 +2002,7 @@ special_insn:
}
case 0x8f:  /* pop (sole member of Grp1a) */
rc = emulate_grp1a(ctxt, ops);
-   if (rc != 0)
+   if (rc != X86EMUL_CONTINUE)
goto done;
break;
case 0x90: /* nop / xchg r8,rax */
@@ -2135,7 +2135,7 @@ special_insn:
break;
case 0xcb:  /* ret far */
rc = emulate_ret_far(ctxt, ops);
-   if (rc)
+   if (rc != X86EMUL_CONTINUE)
goto done;
break;
case 0xd0 ... 0xd1: /* Grp2 */
@@ -2205,7 +2205,7 @@ special_insn:
break;
case 0xf6 ... 0xf7: /* Grp3 */
rc = emulate_grp3(ctxt, ops);
-   if (rc != 0)
+   if (rc != X86EMUL_CONTINUE)
goto done;
break;
case 0xf8: /* clc */
@@ -2231,14 +2231,14 @@ special_insn:
break;
case 0xfe ... 0xff: /* Grp4/Grp5 */
rc = emulate_grp45(ctxt, ops);
-   if (rc != 0)
+   if (rc != X86EMUL_CONTINUE)
goto done;
break;
}
 
 writeback:
rc = writeback(ctxt, ops);
-   if (rc != 0)
+   if (rc != X86EMUL_CONTINUE)
goto done;
 
/* Commit shadow register state. */
@@ -2263,8 +2263,18 @@ twobyte_insn:
if (c-modrm_mod != 3 || c-modrm_rm != 1)
goto cannot_emulate;
 
-   rc = kvm_fix_hypercall(ctxt-vcpu);
-   if (rc)
+   /* FIXME:
+* kvm_fix_hypercall() calls emulator_write_emulated()
+* and if the return value is not X86EMUL_CONTINUE then
+* returns -EFAULT, otherwise returns X86EMUL_CONTINUE.
+*
+* To handle the former case, original code just did
+* goto done with rc = -EFAULT and passed the
+* if (X86EMUL_UNHANDLEABLE) check.
+* Instead of this, we just set rc to X86EMUL_CONTINUE.
+*/
+   rc = X86EMUL_CONTINUE;
+   if (kvm_fix_hypercall(ctxt-vcpu))
goto done;
 
/* Let the processor re-execute the fixed 

[PATCH 4/5] KVM: load|save_guest_segment_descriptor() should return X86EMUL_* values

2010-01-28 Thread Takuya Yoshikawa
These two functions should return X86EMUL_* values.

Signed-off-by: Takuya Yoshikawa yoshikawa.tak...@oss.ntt.co.jp
---
 arch/x86/kvm/x86.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index ac8672f..78b8ddb 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -4663,7 +4663,7 @@ static int load_guest_segment_descriptor(struct kvm_vcpu 
*vcpu, u16 selector,
 
if (dtable.limit  index * 8 + 7) {
kvm_queue_exception_e(vcpu, GP_VECTOR, selector  0xfffc);
-   return 1;
+   return X86EMUL_UNHANDLEABLE;
}
return kvm_read_guest_virt(dtable.base + index*8, seg_desc, 
sizeof(*seg_desc), vcpu);
 }
@@ -4678,7 +4678,7 @@ static int save_guest_segment_descriptor(struct kvm_vcpu 
*vcpu, u16 selector,
get_segment_descriptor_dtable(vcpu, selector, dtable);
 
if (dtable.limit  index * 8 + 7)
-   return 1;
+   return X86EMUL_UNHANDLEABLE;
return kvm_write_guest_virt(dtable.base + index*8, seg_desc, 
sizeof(*seg_desc), vcpu);
 }
 
-- 
1.6.3.3

--
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


[PATCH 5/5] KVM: Fix the usage of X86EMUL_* values in x86.c

2010-01-28 Thread Takuya Yoshikawa
pio_copy_data() and load|save_guest_segment_descriptor()
return X86EMUL_* values. Mixing up these values with 0, 1, ...
may produce unpridictable bugs.

Signed-off-by: Takuya Yoshikawa yoshikawa.tak...@oss.ntt.co.jp
---
 arch/x86/kvm/x86.c |   27 +++
 1 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 78b8ddb..67f8231 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3454,7 +3454,6 @@ int complete_pio(struct kvm_vcpu *vcpu)
 {
struct kvm_pio_request *io = vcpu-arch.pio;
long delta;
-   int r;
unsigned long val;
 
if (!io-string) {
@@ -3465,9 +3464,9 @@ int complete_pio(struct kvm_vcpu *vcpu)
}
} else {
if (io-in) {
-   r = pio_copy_data(vcpu);
-   if (r)
-   return r;
+   int ret = pio_copy_data(vcpu);
+   if (ret != X86EMUL_CONTINUE)
+   return 1;
}
 
delta = 1;
@@ -3567,7 +3566,6 @@ int kvm_emulate_pio_string(struct kvm_vcpu *vcpu, int in,
  gva_t address, int rep, unsigned port)
 {
unsigned now, in_page;
-   int ret = 0;
 
vcpu-run-exit_reason = KVM_EXIT_IO;
vcpu-run-io.direction = in ? KVM_EXIT_IO_IN : KVM_EXIT_IO_OUT;
@@ -3613,20 +3611,22 @@ int kvm_emulate_pio_string(struct kvm_vcpu *vcpu, int 
in,
 
if (!vcpu-arch.pio.in) {
/* string PIO write */
-   ret = pio_copy_data(vcpu);
+   int ret = pio_copy_data(vcpu);
if (ret == X86EMUL_PROPAGATE_FAULT) {
kvm_inject_gp(vcpu, 0);
return 1;
}
-   if (ret == 0  !pio_string_write(vcpu)) {
+   if (ret == X86EMUL_UNHANDLEABLE)
+   return 1;
+   if (ret == X86EMUL_CONTINUE  !pio_string_write(vcpu)) {
complete_pio(vcpu);
if (vcpu-arch.pio.count == 0)
-   ret = 1;
+   return 1;
}
}
/* no string PIO read support yet */
 
-   return ret;
+   return 0;
 }
 EXPORT_SYMBOL_GPL(kvm_emulate_pio_string);
 
@@ -4743,7 +4743,8 @@ int kvm_load_segment_descriptor(struct kvm_vcpu *vcpu, 
u16 selector,
if (is_vm86_segment(vcpu, seg) || !is_protmode(vcpu))
return kvm_load_realmode_segment(vcpu, selector, seg);
 
-   if (load_guest_segment_descriptor(vcpu, selector, seg_desc))
+   if (load_guest_segment_descriptor(vcpu, selector, seg_desc)
+   != X86EMUL_CONTINUE)
return 1;
seg_desct_to_kvm_desct(seg_desc, selector, kvm_seg);
 
@@ -4971,10 +4972,12 @@ int kvm_task_switch(struct kvm_vcpu *vcpu, u16 
tss_selector, int reason)
/* FIXME: Handle errors. Failure to read either TSS or their
 * descriptors should generate a pagefault.
 */
-   if (load_guest_segment_descriptor(vcpu, tss_selector, nseg_desc))
+   if (load_guest_segment_descriptor(vcpu, tss_selector, nseg_desc)
+   != X86EMUL_CONTINUE)
goto out;
 
-   if (load_guest_segment_descriptor(vcpu, old_tss_sel, cseg_desc))
+   if (load_guest_segment_descriptor(vcpu, old_tss_sel, cseg_desc)
+   != X86EMUL_CONTINUE)
goto out;
 
if (reason != TASK_SWITCH_IRET) {
-- 
1.6.3.3

--
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-kvm: enable get/set vcpu events on reset and migration

2010-01-28 Thread Jan Kiszka
Gleb Natapov wrote:
 On Tue, Jan 26, 2010 at 10:26:22PM -0200, Marcelo Tosatti wrote:
 @@ -374,6 +375,7 @@ static int cpu_post_load(void *opaque, int version_id)
  
  kvm_load_tsc(env);
  kvm_load_mpstate(env);
 +kvm_put_vcpu_events(env);
  }
 It is confusing to call functions load/save for some state and put/get for
 others, but the function kvm_put_vcpu_events() is called upstream this
 way :(

It's temporary, 0.12-only. load/save (and a lot more) will disappear
once we completed merging with upstream code.

Jan

-- 
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
--
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] Add definitions for current cpu models..

2010-01-28 Thread Anthony Liguori

On 01/28/2010 02:43 AM, Alexander Graf wrote:

On 28.01.2010, at 09:19, Arnd Bergmann wrote:

   

On Monday 25 January 2010, Dor Laor wrote:
 

x86   qemu64
x86   phenom
x86 core2duo
x86kvm64
x86   qemu32
x86  coreduo
x86  486
x86  pentium
x86 pentium2
x86 pentium3
x86   athlon
x86 n270
   

I think a really nice addition would be an autodetect option for those
users (e.g. desktop) that know they do not want to migrate the guest
to a lower-spec machine.

That option IMHO should just show up as identical to the host cpu, with
the exception of features that are not supported in the guest.
 

That's exactly what -cpu host is. IIRC it's the default now.
   


Not yet.  Someone has to send a patch.

We can't enforce this wrt migration until someone implements migration 
of cpuid state.


Regards,

Anthony Liguori


Alex
--
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
   


--
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: [PATCH qemu-kvm] Add raw(af_packet) network backend to qemu

2010-01-28 Thread Anthony Liguori

On 01/28/2010 07:56 AM, Michael S. Tsirkin wrote:

Now, the most important use case I see for the raw socket interface
in qemu is to get vhost-net and the qemu user implementation to
support the same feature set. If you ask for a network setup involving
a raw socket and vhost-net and the kernel can support raw sockets
but for some reason fails to set up vhost-net, you should have a
fallback that has the exact same semantics at a possibly significant
performance loss.

Arnd
 

Makes sense. A simple reason you can't do vhost-net would be
that you are using tcg.
   


Some good arguments have been raised in this thread.  I really don't 
like making our security depend on something external to qemu that is 
not widely used or understood.


That said, I'm not seeing a lot of great alternatives.  I definitely 
like -net socket better than -net raw.  In the absence of an 
extraordinarily clever solution, I think we may be stuck with doing this.


Regards,

Anthony Liguori

--
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: [PATCH qemu-kvm] Add raw(af_packet) network backend to qemu

2010-01-28 Thread Anthony Liguori

On 01/28/2010 08:13 AM, Anthony Liguori wrote:

On 01/28/2010 07:56 AM, Michael S. Tsirkin wrote:

Now, the most important use case I see for the raw socket interface
in qemu is to get vhost-net and the qemu user implementation to
support the same feature set. If you ask for a network setup involving
a raw socket and vhost-net and the kernel can support raw sockets
but for some reason fails to set up vhost-net, you should have a
fallback that has the exact same semantics at a possibly significant
performance loss.

Arnd

Makes sense. A simple reason you can't do vhost-net would be
that you are using tcg.


Some good arguments have been raised in this thread.  I really don't 
like making our security depend on something external to qemu that is 
not widely used or understood.


Thinking about it, I don't think network namespaces actually provides us 
the security that we need.  It's quite easy to break out of it if not 
being used in the context of a full container.


But this discussion belongs in netdev, I'll raise the issue there.

Regards,

Anthony Liguori
--
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: [PATCH qemu-kvm] Add raw(af_packet) network backend to qemu

2010-01-28 Thread Michael S. Tsirkin
On Thu, Jan 28, 2010 at 08:13:53AM -0600, Anthony Liguori wrote:
 On 01/28/2010 07:56 AM, Michael S. Tsirkin wrote:
 Now, the most important use case I see for the raw socket interface
 in qemu is to get vhost-net and the qemu user implementation to
 support the same feature set. If you ask for a network setup involving
 a raw socket and vhost-net and the kernel can support raw sockets
 but for some reason fails to set up vhost-net, you should have a
 fallback that has the exact same semantics at a possibly significant
 performance loss.

 Arnd
  
 Makes sense. A simple reason you can't do vhost-net would be
 that you are using tcg.


 Some good arguments have been raised in this thread.  I really don't  
 like making our security depend on something external to qemu that is  
 not widely used or understood.

 That said, I'm not seeing a lot of great alternatives.  I definitely  
 like -net socket better than -net raw.  In the absence of an  
 extraordinarily clever solution, I think we may be stuck with doing this.

Agreed on all points.

 Regards,

 Anthony Liguori
--
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: [PATCH qemu-kvm] Add raw(af_packet) network backend to qemu

2010-01-28 Thread Anthony Liguori

On 01/28/2010 08:52 AM, Michael S. Tsirkin wrote:

On Thu, Jan 28, 2010 at 08:13:53AM -0600, Anthony Liguori wrote:
   

On 01/28/2010 07:56 AM, Michael S. Tsirkin wrote:
 

Now, the most important use case I see for the raw socket interface
in qemu is to get vhost-net and the qemu user implementation to
support the same feature set. If you ask for a network setup involving
a raw socket and vhost-net and the kernel can support raw sockets
but for some reason fails to set up vhost-net, you should have a
fallback that has the exact same semantics at a possibly significant
performance loss.

Arnd

 

Makes sense. A simple reason you can't do vhost-net would be
that you are using tcg.

   

Some good arguments have been raised in this thread.  I really don't
like making our security depend on something external to qemu that is
not widely used or understood.

That said, I'm not seeing a lot of great alternatives.  I definitely
like -net socket better than -net raw.  In the absence of an
extraordinarily clever solution, I think we may be stuck with doing this.
 

Agreed on all points.
   


The scenario I'm concerned about is:

normal user uses libvirt to launch custom qemu instance.  libvirt passes 
an fd of a raw socket to qemu and puts the qemu process in a restricted 
network namespace.  user has another program running listening on a unix 
domain socket and does something to the qemu process that causes it to 
open the domain socket and send the fd it received from libvirt via 
SCM_RIGHTS.


user now has a raw socket that is not confined to a network namespace.

I'm trying to digest the disablenetwork thread right now.  Basically 
though, what would be ideal is a /dev/net/ethN that we could open, and 
use read/write to send packets to and use ioctls to issue commands to do 
things like enable/disable offloads.


I understand that raw socket is the interface we have today but I think 
we aren't going to be able to get around the need for a restricted file 
descriptor vs. using process restrictions to achieve isolation.


Regards,

Anthony Liguori


Regards,

Anthony Liguori
 


--
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


[ kvm-Bugs-2941282 ] Ubuntu 10.04 installer fails due to I/O errors with virtio

2010-01-28 Thread SourceForge.net
Bugs item #2941282, was opened at 2010-01-27 17:19
Message generated for change (Comment added) made by sjolshagen
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=893831aid=2941282group_id=180599

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 7
Private: No
Submitted By: Marti Raudsepp (intgr)
Assigned to: Nobody/Anonymous (nobody)
Summary: Ubuntu 10.04 installer fails due to I/O errors with virtio

Initial Comment:
I tried installing Ubuntu 10.04 and Fedora 12 in a KVM virtual machine using 
virtio, on a 8G raw file-backed disk. Both installers failed half-way due to 
I/O errors. So I tried reproducing it and managed to repeat it 6 times. The bug 
doesn't occur with IDE emulation. The bug happens fairly quickly with -smp 4 -- 
usually within 5 minutes -- but is much rarer with -smp 1.

Ubuntu installer has kernel 2.6.32-11-generic
Fedora 12 has kernel 2.6.31.5-127.fc12.x86_64
Host has kernel 2.6.32.6 (Arch Linux) and QEMU 0.12.2

When testing with -smp 1, it also produced a kernel oops from 
block/blk-core.c:245. This line warns when the function is called with 
interrupts enabled:
void blk_start_queue(struct request_queue *q)
{
WARN_ON(!irqs_disabled());

queue_flag_clear(QUEUE_FLAG_STOPPED, q);
__blk_run_queue(q);
}


--- host machine ---

[ma...@newn]% qemu-kvm --version
QEMU PC emulator version 0.12.2 (qemu-kvm-0.12.2), Copyright (c) 2003-2008 
Fabrice Bellard
[ma...@newn]% ps aux |grep crash
root 16283 31.4  7.1 427020 289960 ?   Sl   22:44   8:37 
/usr/bin/qemu-kvm -S -M pc-0.11 -enable-kvm -m 256 -smp 1 -name 
ubuntu-crashtest -uuid 0d7d4f2d-5589-160b-1f1b-75d46e293a2c -chardev 
socket,id=monitor,path=/var/lib/libvirt/qemu/ubuntu-crashtest.monitor,server,nowait
 -monitor chardev:monitor -boot d -drive 
file=/store/iso/lucid-desktop-amd64.iso,if=ide,media=cdrom,index=2,format=raw 
-drive file=/store/virt/ubuntu-crashtest.img,if=virtio,index=0,format=raw -net 
nic,macaddr=52:54:00:45:e7:19,vlan=0,name=nic.0 -net 
tap,fd=43,vlan=0,name=tap.0 -serial none -parallel none -usb -usbdevice tablet 
-vnc 127.0.0.1:1 -k en-us -vga cirrus -soundhw es1370 -balloon virtio
marti17700  0.0  0.0   8360   968 pts/4S+   23:11   0:00 grep crash
[ma...@newn]% stat /store/virt/ubuntu-crashtest.img
  File: `/store/virt/ubuntu-crashtest.img'
  Size: 8589934592  Blocks: 5615368IO Block: 4096   regular file
Device: fe01h/65025dInode: 4718596 Links: 1
Access: (0600/-rw---)  Uid: (0/root)   Gid: (0/root)
Access: 2010-01-27 22:43:45.128113080 +0200
Modify: 2010-01-27 23:09:11.523577452 +0200
Change: 2010-01-27 23:09:11.523577452 +0200
[ma...@newn]% uname -a
Linux newn 2.6.32-ARCH #1 SMP PREEMPT Mon Jan 25 20:33:50 CET 2010 x86_64 AMD 
Phenom(tm) II X4 940 Processor AuthenticAMD GNU/Linux
[ma...@newn]% cat /proc/cpuinfo
processor   : 0
vendor_id   : AuthenticAMD
cpu family  : 16
model   : 4
model name  : AMD Phenom(tm) II X4 940 Processor
stepping: 2
cpu MHz : 800.000
cache size  : 512 KB
physical id : 0
siblings: 4
core id : 0
cpu cores   : 4
apicid  : 0
initial apicid  : 0
fpu : yes
fpu_exception   : yes
cpuid level : 5
wp  : yes
flags   : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov 
pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb 
rdtscp lm 3dnowext 3dnow constant_tsc rep_good nonstop_tsc extd_apicid pni 
monitor cx16 popcnt lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a 
misalignsse 3dnowprefetch osvw ibs skinit wdt
bogomips: 6028.69
TLB size: 1024 4K pages
clflush size: 64
cache_alignment : 64
address sizes   : 48 bits physical, 48 bits virtual
power management: ts ttp tm stc 100mhzsteps hwpstate

*snip* three more CPU cores

--- Ubuntu guest VM ---

ubu...@ubuntu:/tmp$ uname -a
Linux ubuntu 2.6.32-11-generic #15-Ubuntu SMP Tue Jan 19 20:38:41 UTC 2010 
x86_64 GNU/Linux
ubu...@ubuntu:/tmp$ cat /sys/block/vda/stat
   7388948289  1661218   39497026765   947851  6284676  9459960
0   987890  9893220
ubu...@ubuntu:/tmp$ dmesg
[0.00] Initializing cgroup subsys cpuset
[0.00] Initializing cgroup subsys cpu
[0.00] Linux version 2.6.32-11-generic (bui...@crested) (gcc version 
4.4.3 20100116 (prerelease) (Ubuntu 4.4.2-9ubuntu4) ) #15-Ubuntu SMP Tue Jan 19 
20:38:41 UTC 2010 (Ubuntu 2.6.32-11.15-generic)
[0.00] Command line: BOOT_IMAGE=/casper/vmlinuz 
file=/cdrom/preseed/ubuntu.seed boot=casper only-ubiquity 
initrd=/casper/initrd.lz quiet splash --
[0.00] KERNEL supported cpus:
[0.00]   Intel GenuineIntel
[0.00]   AMD AuthenticAMD
[0.00]   Centaur CentaurHauls
[0.00] BIOS-provided 

Re: [PATCH qemu-kvm] Add raw(af_packet) network backend to qemu

2010-01-28 Thread Michael S. Tsirkin
On Thu, Jan 28, 2010 at 09:05:45AM -0600, Anthony Liguori wrote:
 On 01/28/2010 08:52 AM, Michael S. Tsirkin wrote:
 On Thu, Jan 28, 2010 at 08:13:53AM -0600, Anthony Liguori wrote:

 On 01/28/2010 07:56 AM, Michael S. Tsirkin wrote:
  
 Now, the most important use case I see for the raw socket interface
 in qemu is to get vhost-net and the qemu user implementation to
 support the same feature set. If you ask for a network setup involving
 a raw socket and vhost-net and the kernel can support raw sockets
 but for some reason fails to set up vhost-net, you should have a
 fallback that has the exact same semantics at a possibly significant
 performance loss.

   Arnd

  
 Makes sense. A simple reason you can't do vhost-net would be
 that you are using tcg.


 Some good arguments have been raised in this thread.  I really don't
 like making our security depend on something external to qemu that is
 not widely used or understood.

 That said, I'm not seeing a lot of great alternatives.  I definitely
 like -net socket better than -net raw.  In the absence of an
 extraordinarily clever solution, I think we may be stuck with doing this.
  
 Agreed on all points.


 The scenario I'm concerned about is:

 normal user uses libvirt to launch custom qemu instance.  libvirt passes  
 an fd of a raw socket to qemu and puts the qemu process in a restricted  
 network namespace.  user has another program running listening on a unix  
 domain socket and does something to the qemu process that causes it to  
 open the domain socket and send the fd it received from libvirt via  
 SCM_RIGHTS.

 user now has a raw socket that is not confined to a network namespace.

 I'm trying to digest the disablenetwork thread right now.  Basically  
 though, what would be ideal is a /dev/net/ethN that we could open, and  
 use read/write to send packets to and use ioctls to issue commands to do  
 things like enable/disable offloads.

 I understand that raw socket is the interface we have today but I think  
 we aren't going to be able to get around the need for a restricted file  
 descriptor vs. using process restrictions to achieve isolation.


So actually, this is an interesting argument in favor of
turning disablenetwork from per-process as it is now
to per-file.


 Regards,

 Anthony Liguori

 Regards,

 Anthony Liguori
  
--
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: [PATCH qemu-kvm] Add raw(af_packet) network backend to qemu

2010-01-28 Thread Jens Osterkamp
On Thursday 28 January 2010, Arnd Bergmann wrote:
 On Wednesday 27 January 2010, Sridhar Samudrala wrote:
  On Wed, 2010-01-27 at 22:39 +0100, Arnd Bergmann wrote:
   On Wednesday 27 January 2010, Anthony Liguori wrote:
 I think -net socket,fd should just be (trivially) extended to work
 with raw sockets out of the box, with no support for opening it.
 Then you can have libvirt or some wrapper open a raw socket and a
 private namespace and just pass it down.

 That'd work. Anthony?
   
The fundamental problem that I have with all of this is that we
should not be introducing new network backends that are based around
something only a developer is going to understand.  If I'm a user and
I want to use an external switch in VEPA mode, how in the world am I
going to know that I'm supposed to use the -net raw backend or the
-net socket backend?  It might as well be the -net butterflies
backend as far as a user is concerned.
  
   My point is that we already have -net socket,fd and any user that
   passes an fd into that already knows what he wants to do with it.
   Making it work with raw sockets is just a natural extension to this,
   which works on all kernels and (with separate namespaces) is reasonably
   secure.
 
  Didn't realize that -net socket is already there and supports TCP and
  UDP sockets. I will look into extending -net socket to support AF_PACKET
  SOCK_RAW type sockets.

 Actually, Jens had a patch doing this in early 2009 already but we
 decided to not send that one out at the time after Or had sent his
 version of the raw socket interface, which was a superset. Maybe Jens
 can post his patch again if that still applies?

It's been a while since I last looked at it. I think it will need a bitt 
massaging before it will apply again.

Jens

--
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


[ kvm-Bugs-2930756 ] sdl window intermittently scales instead of resizing

2010-01-28 Thread SourceForge.net
Bugs item #2930756, was opened at 2010-01-12 11:20
Message generated for change (Comment added) made by jamincollins
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=893831aid=2930756group_id=180599

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Jamin W. Collins (jamincollins)
Assigned to: Nobody/Anonymous (nobody)
Summary: sdl window intermittently scales instead of resizing

Initial Comment:
CPU: Intel(R) Core(TM)2 Duo CPU T8300  @ 2.40GHz
Host OS: Ubuntu 9.10 (karmic) 64-bit
Guest OS: all

Normally, the SDL output window for a VM resizes to match the VM's resolution. 
However, intermittently the output is instead scaled within the window. I can't 
seem to find any pattern to when the output is scaled versus when the window is 
resized. I would prefer that the window be resized as needed to display the VM 
in a 1:1 manner.

The Ubuntu report for this can be found here: 
https://bugs.launchpad.net/ubuntu/+source/qemu-kvm/+bug/504368

--

Comment By: Jamin W. Collins (jamincollins)
Date: 2010-01-28 11:34

Message:
Just happened again under 0.12.2.  It's much less frequent than before (or
seems to be) but still happens.

$ kvm --version
QEMU PC emulator version 0.12.2 (qemu-kvm-0.12.2), Copyright (c) 2003-2008
Fabrice Bellard


--

Comment By: Jamin W. Collins (jamincollins)
Date: 2010-01-27 20:46

Message:
Can't say with absolute certainty yet, have only been using 0.12.2 since a
while after your message.  However, so far I haven't seen a single instance
of scaling and I've tried stopping and restarting a number of different
VMs.  So, at this point it looks much better.

--

Comment By: Brian Jackson (iggy_cav)
Date: 2010-01-27 17:37

Message:
Can you reproduce with qemu-kvm-0.12.x?

--

Comment By: Jamin W. Collins (jamincollins)
Date: 2010-01-12 11:26

Message:
Sorry, should probably have included the version of KVM:
$ kvm --version
QEMU PC emulator version 0.11.0 (qemu-kvm-0.11.0), Copyright (c) 2003-2008
Fabrice Bellard
$ apt-cache policy kvm
kvm:
  Installed: 1:84+dfsg-0ubuntu16+0.11.0+0ubuntu6.3


--

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=893831aid=2930756group_id=180599
--
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: [PATCH qemu-kvm] Add raw(af_packet) network backend to qemu

2010-01-28 Thread Anthony Liguori

On 01/28/2010 10:37 AM, Michael S. Tsirkin wrote:

So actually, this is an interesting argument in favor of
turning disablenetwork from per-process as it is now
to per-file.
   


Yup.  I think we really need a file-based restriction mechanism and so 
far, neither disablenetwork or network namespace seems to do that.


I think you might be able to mitigate this with SELinux since I'm fairly 
certain it can prevent SCM_RIGHTS but SELinux is not something that can 
be enforced within a set of applications so we'd be relying on SELinux 
being enabled (honestly, unlikely) and the policy being correctly 
configured (unlikely in the general case at least).


Regards,

Anthony Liguori

   

Regards,

Anthony Liguori

 

Regards,

Anthony Liguori

 


--
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: [PATCH qemu-kvm] Add raw(af_packet) network backend to qemu

2010-01-28 Thread Michael S. Tsirkin
On Thu, Jan 28, 2010 at 11:58:48AM -0600, Anthony Liguori wrote:
 On 01/28/2010 10:37 AM, Michael S. Tsirkin wrote:
 So actually, this is an interesting argument in favor of
 turning disablenetwork from per-process as it is now
 to per-file.


 Yup.  I think we really need a file-based restriction mechanism and so  
 far, neither disablenetwork or network namespace seems to do that.

 I think you might be able to mitigate this with SELinux since I'm fairly  
 certain it can prevent SCM_RIGHTS but SELinux is not something that can  
 be enforced within a set of applications so we'd be relying on SELinux  
 being enabled (honestly, unlikely) and the policy being correctly  
 configured (unlikely in the general case at least).

 Regards,

 Anthony Liguori

I am not convinced SELinux being disabled is a problem we necessarily
need to deal with, and qemu does not verify e.g. that it is not run as
root either. A more serious problem IMO is that SCM_RIGHTS might be
needed for some other functionality.


 Regards,

 Anthony Liguori

  
 Regards,

 Anthony Liguori

  
--
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


[patch 1/3] KVM: x86: add ioctls to get/set PIO state

2010-01-28 Thread Marcelo Tosatti
A vcpu can be stopped after handling IO in userspace,
but before returning to kernel to finish processing.

Add ioctls to get/set the PIO state.

Signed-off-by: Marcelo Tosatti mtosa...@redhat.com

diff --git a/arch/x86/include/asm/kvm.h b/arch/x86/include/asm/kvm.h
index f46b79f..c1b2b8c 100644
--- a/arch/x86/include/asm/kvm.h
+++ b/arch/x86/include/asm/kvm.h
@@ -284,4 +284,18 @@ struct kvm_vcpu_events {
__u32 reserved[10];
 };
 
+struct kvm_pio_request {
+   __u64 guest_gva;
+   __u32 count;
+   __u32 cur_count;
+   __u16 port;
+   __u8 size;
+   __u8 in;
+   __u8 string;
+   __u8 down;
+   __u8 rep;
+   __u8 pad;
+};
+
+
 #endif /* _ASM_X86_KVM_H */
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 1522337..28f31e1 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -222,18 +222,6 @@ struct kvm_pv_mmu_op_buffer {
char buf[512] __aligned(sizeof(long));
 };
 
-struct kvm_pio_request {
-   unsigned long count;
-   int cur_count;
-   gva_t guest_gva;
-   int in;
-   int port;
-   int size;
-   int string;
-   int down;
-   int rep;
-};
-
 /*
  * x86 supports 3 paging modes (4-level 64-bit, 3-level 64-bit, and 2-level
  * 32-bit).  The kvm_mmu structure abstracts the details of the current mmu
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index ac8672f..99d991a 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1575,6 +1575,9 @@ int kvm_dev_ioctl_check_extension(long ext)
case KVM_CAP_COALESCED_MMIO:
r = KVM_COALESCED_MMIO_PAGE_OFFSET;
break;
+   case KVM_CAP_PIO:
+   r = KVM_PIO_PAGE_OFFSET;
+   break;
case KVM_CAP_VAPIC:
r = !kvm_x86_ops-cpu_has_accelerated_tpr();
break;
@@ -2175,6 +2178,26 @@ static int kvm_vcpu_ioctl_x86_set_vcpu_events(struct 
kvm_vcpu *vcpu,
return 0;
 }
 
+static void kvm_vcpu_ioctl_x86_get_pio(struct kvm_vcpu *vcpu,
+  struct kvm_pio_request *pio)
+{
+   vcpu_load(vcpu);
+   memcpy(pio, vcpu-arch.pio, sizeof(struct kvm_pio_request));
+   vcpu_put(vcpu);
+}
+
+static int kvm_vcpu_ioctl_x86_set_pio(struct kvm_vcpu *vcpu,
+ struct kvm_pio_request *pio)
+{
+   if (!pio-string  pio-size  4)
+   return -EINVAL;
+
+   vcpu_load(vcpu);
+   memcpy(vcpu-arch.pio, pio, sizeof(struct kvm_pio_request));
+   vcpu_put(vcpu);
+   return 0;
+}
+
 long kvm_arch_vcpu_ioctl(struct file *filp,
 unsigned int ioctl, unsigned long arg)
 {
@@ -2353,6 +2376,27 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
r = kvm_vcpu_ioctl_x86_set_vcpu_events(vcpu, events);
break;
}
+   case KVM_SET_VCPU_PIO: {
+   struct kvm_pio_request pio;
+
+   r = -EFAULT;
+   if (copy_from_user(pio, argp, sizeof(struct kvm_pio_request)))
+   break;
+
+   r = kvm_vcpu_ioctl_x86_set_pio(vcpu, pio);
+   break;
+   }
+   case KVM_GET_VCPU_PIO: {
+   struct kvm_pio_request pio;
+
+   kvm_vcpu_ioctl_x86_get_pio(vcpu, pio);
+   
+   r = -EFAULT;
+   if (copy_to_user(argp, pio, sizeof(struct kvm_pio_request)))
+   break;
+   r = 0;
+   break;
+   }
default:
r = -EINVAL;
}
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 4c4937e..0b56d41 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -500,6 +500,7 @@ struct kvm_ioeventfd {
 #define KVM_CAP_HYPERV 44
 #define KVM_CAP_HYPERV_VAPIC 45
 #define KVM_CAP_HYPERV_SPIN 46
+#define KVM_CAP_PIO 47
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
@@ -686,6 +687,8 @@ struct kvm_clock_data {
 /* Available with KVM_CAP_VCPU_EVENTS */
 #define KVM_GET_VCPU_EVENTS   _IOR(KVMIO,  0x9f, struct kvm_vcpu_events)
 #define KVM_SET_VCPU_EVENTS   _IOW(KVMIO,  0xa0, struct kvm_vcpu_events)
+#define KVM_GET_VCPU_PIO  _IOR(KVMIO,  0xa1, struct kvm_pio_request)
+#define KVM_SET_VCPU_PIO  _IOW(KVMIO,  0xa2, struct kvm_pio_request)
 
 #define KVM_DEV_ASSIGN_ENABLE_IOMMU(1  0)
 


--
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


[patch 2/3] uqmaster: save/restore pio state

2010-01-28 Thread Marcelo Tosatti
Save/restore in-kernel KVM PIO state. This is necessary to allow
migration with in-progress PIO operation.

FIXME: adjust CPUState and VMState version.

Signed-off-by: Marcelo Tosatti mtosa...@redhat.com

Index: qemu-kvm/target-i386/cpu.h
===
--- qemu-kvm.orig/target-i386/cpu.h
+++ qemu-kvm/target-i386/cpu.h
@@ -570,6 +570,18 @@ typedef struct {
 uint64_t mask;
 } MTRRVar;
 
+typedef struct {
+uint64_t guest_gva;
+uint32_t count;
+uint32_t cur_count;
+uint16_t port;
+uint8_t size;
+uint8_t in;
+uint8_t string;
+uint8_t down;
+uint8_t rep;
+} KVMPIOState;
+
 #define CPU_NB_REGS64 16
 #define CPU_NB_REGS32 8
 
@@ -702,7 +714,9 @@ typedef struct CPUX86State {
 uint8_t has_error_code;
 uint32_t sipi_vector;
 uint32_t cpuid_kvm_features;
-
+
+KVMPIOState kvm_pio;
+
 /* in order to simplify APIC support, we leave this pointer to the
user */
 struct APICState *apic_state;
Index: qemu-kvm/target-i386/kvm.c
===
--- qemu-kvm.orig/target-i386/kvm.c
+++ qemu-kvm/target-i386/kvm.c
@@ -289,6 +289,7 @@ void kvm_arch_reset_vcpu(CPUState *env)
 env-interrupt_injected = -1;
 env-nmi_injected = 0;
 env-nmi_pending = 0;
+memset(env-kvm_pio, 0, sizeof(KVMPIOState));
 }
 
 static int kvm_has_msr_star(CPUState *env)
@@ -837,6 +838,57 @@ static int kvm_get_vcpu_events(CPUState 
 return 0;
 }
 
+static int kvm_put_pio(CPUState *env)
+{
+#ifdef KVM_CAP_PIO
+struct kvm_pio_request pio;
+
+if (!kvm_has_vcpu_pio())
+return 0;
+
+pio.count = env-kvm_pio.count;
+pio.cur_count = env-kvm_pio.cur_count;
+pio.guest_gva = env-kvm_pio.guest_gva;
+pio.in = env-kvm_pio.in;
+pio.port = env-kvm_pio.port;
+pio.size = env-kvm_pio.size;
+pio.string = env-kvm_pio.string;
+pio.down = env-kvm_pio.down;
+pio.rep = env-kvm_pio.rep;
+
+return kvm_vcpu_ioctl(env, KVM_SET_VCPU_PIO, pio);
+#else
+return 0;
+#endif
+}
+
+static int kvm_get_pio(CPUState *env)
+{
+#ifdef KVM_CAP_PIO
+struct kvm_pio_request pio;
+int ret;
+
+if (!kvm_has_vcpu_pio())
+return 0;
+
+ret = kvm_vcpu_ioctl(env, KVM_GET_VCPU_PIO, pio);
+if (ret  0)
+return ret;
+
+env-kvm_pio.count = pio.count;
+env-kvm_pio.cur_count = pio.cur_count;
+env-kvm_pio.guest_gva = pio.guest_gva;
+env-kvm_pio.in = pio.in;
+env-kvm_pio.port = pio.port;
+env-kvm_pio.size = pio.size;
+env-kvm_pio.string = pio.string;
+env-kvm_pio.down = pio.down;
+env-kvm_pio.rep = pio.rep;
+#endif
+
+return 0;
+}
+
 int kvm_arch_put_registers(CPUState *env)
 {
 int ret;
@@ -865,6 +917,10 @@ int kvm_arch_put_registers(CPUState *env
 if (ret  0)
 return ret;
 
+ret = kvm_put_pio(env);
+if (ret  0)
+return ret;
+
 return 0;
 }
 
@@ -896,6 +952,10 @@ int kvm_arch_get_registers(CPUState *env
 if (ret  0)
 return ret;
 
+ret = kvm_get_pio(env);
+if (ret  0)
+return ret;
+
 return 0;
 }
 
Index: qemu-kvm/target-i386/machine.c
===
--- qemu-kvm.orig/target-i386/machine.c
+++ qemu-kvm/target-i386/machine.c
@@ -62,6 +62,34 @@ static const VMStateDescription vmstate_
 #define VMSTATE_MTRR_VARS(_field, _state, _n, _v)\
 VMSTATE_STRUCT_ARRAY(_field, _state, _n, _v, vmstate_mtrr_var, MTRRVar)
 
+static const VMStateDescription vmstate_kvm_pio = {
+.name = kvm_pio,
+.version_id = 1,
+.minimum_version_id = 1,
+.minimum_version_id_old = 1,
+.fields  = (VMStateField []) {
+VMSTATE_UINT64(guest_gva, KVMPIOState),
+VMSTATE_UINT32(count, KVMPIOState),
+VMSTATE_UINT32(cur_count, KVMPIOState),
+VMSTATE_UINT8(in, KVMPIOState),
+VMSTATE_UINT16(port, KVMPIOState),
+VMSTATE_UINT8(size, KVMPIOState),
+VMSTATE_UINT8(string, KVMPIOState),
+VMSTATE_UINT8(down, KVMPIOState),
+VMSTATE_UINT8(rep, KVMPIOState),
+VMSTATE_END_OF_LIST()
+}
+};
+
+#define VMSTATE_KVM_PIO(_field, _state, _version) { \
+.name   = (stringify(_field)),  \
+.version_id = _version, \
+.size   = sizeof(KVMPIOState),  \
+.vmsd   = vmstate_kvm_pio, \
+.flags  = VMS_STRUCT,   \
+.offset = vmstate_offset_value(_state, _field, KVMPIOState),\
+}
+
 static void put_fpreg_error(QEMUFile *f, void *opaque, size_t size)
 {
 fprintf(stderr, call put_fpreg() with invalid arguments\n);
@@ -464,6 +492,9 @@ static const VMStateDescription vmstate_
 /* KVM pvclock msr */
 VMSTATE_UINT64_V(system_time_msr, CPUState, 11),
 

[patch 0/3] save/restore in-progress PIO

2010-01-28 Thread Marcelo Tosatti
qemu patches against uq/master.

MMIO suffers from the same problem.

--
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


[PATCH] KVM test: Improvements and cleanups to build subtest

2010-01-28 Thread Lucas Meneghel Rodrigues
 1) Make git build of only the userspace bits
 2) If kernel module build fails (kvm-kmod bug), issue a warning
and proceed with test.
 3) Cleanup usage of private methods using name mangling (_ instead
of __ prepended to the name of the methods).

This is in preparation to new distros and a future without kvm-kmod.

Signed-off-by: Lucas Meneghel Rodrigues l...@redhat.com
---
 client/tests/kvm/tests/build.py |  143 ---
 1 files changed, 74 insertions(+), 69 deletions(-)

diff --git a/client/tests/kvm/tests/build.py b/client/tests/kvm/tests/build.py
index f5f67ad..2e05a56 100644
--- a/client/tests/kvm/tests/build.py
+++ b/client/tests/kvm/tests/build.py
@@ -181,7 +181,7 @@ class KojiInstaller:
 logging.info(Both tag and build parameters provided, ignoring tag 

  parameter...)
 if self.tag and not self.build:
-self.build = self.__get_build()
+self.build = self._get_build()
 if not self.tag and not self.build:
 raise error.TestError(Koji install selected but neither koji_tag 
   nor koji_build parameters provided. Please 
@@ -201,7 +201,7 @@ class KojiInstaller:
 self.test_bindir = test.bindir
 
 
-def __get_build(self):
+def _get_build(self):
 
 Get the source package build name, according to the appropriate tag.
 
@@ -212,10 +212,14 @@ class KojiInstaller:
 for line in latest_raw:
 if line.startswith(self.src_pkg):
 build_name = line.split()[0]
+
+if not build_name:
+raise error.TestError(There are no packages built for tag: %s %
+  self.tag)
 return build_name
 
 
-def __clean_previous_installs(self):
+def _clean_previous_installs(self):
 
 Remove all rpms previously installed.
 
@@ -227,7 +231,7 @@ class KojiInstaller:
 utils.system(yum remove -y %s % removable_packages)
 
 
-def __get_packages(self):
+def _get_packages(self):
 
 Downloads the entire build for the specific build name. It's
 inefficient, but it saves the need of having an NFS share set.
@@ -241,7 +245,7 @@ class KojiInstaller:
 utils.system(download_cmd)
 
 
-def __install_packages(self):
+def _install_packages(self):
 
 Install all relevant packages from the build that was just downloaded.
 
@@ -261,7 +265,7 @@ class KojiInstaller:
 utils.system(yum install --nogpgcheck -y %s % installable_packages)
 
 
-def __check_installed_binaries(self):
+def _check_installed_binaries(self):
 
 Make sure the relevant binaries installed actually come from the build
 that was installed.
@@ -278,10 +282,10 @@ class KojiInstaller:
 
 
 def install(self):
-self.__clean_previous_installs()
-self.__get_packages()
-self.__install_packages()
-self.__check_installed_binaries()
+self._clean_previous_installs()
+self._get_packages()
+self._install_packages()
+self._check_installed_binaries()
 create_symlinks(test_bindir=self.test_bindir,
 bin_list=self.qemu_bin_paths)
 if self.load_modules:
@@ -375,7 +379,7 @@ class SourceDirInstaller:
 self.configure_options = check_configure_options(configure_script)
 
 
-def __build(self):
+def _build(self):
 make_jobs = utils.count_cpus()
 os.chdir(self.srcdir)
 # For testing purposes, it's better to build qemu binaries with
@@ -389,7 +393,7 @@ class SourceDirInstaller:
 utils.system(step)
 
 
-def __install(self):
+def _install(self):
 os.chdir(self.srcdir)
 logging.info(Installing KVM userspace)
 if self.repo_type == 1:
@@ -399,16 +403,16 @@ class SourceDirInstaller:
 create_symlinks(self.test_bindir, self.prefix)
 
 
-def __load_modules(self):
+def _load_modules(self):
 load_kvm_modules(module_dir=self.srcdir,
  extra_modules=self.extra_modules)
 
 
 def install(self):
-self.__build()
-self.__install()
+self._build()
+self._install()
 if self.load_modules:
-self.__load_modules()
+self._load_modules()
 
 
 class GitInstaller:
@@ -462,25 +466,24 @@ class GitInstaller:
 user_tag = params.get(user_tag, HEAD)
 kmod_tag = params.get(kmod_tag, HEAD)
 
-if not kernel_repo:
-message = KVM git repository path not specified
-logging.error(message)
-raise error.TestError(message)
 if not user_repo:
 message = KVM user git repository path not specified
 logging.error(message)
 raise error.TestError(message)
 
-kernel_srcdir = os.path.join(srcdir, kvm)
-

Re: [PATCH qemu-kvm] Add raw(af_packet) network backend to qemu

2010-01-28 Thread Anthony Liguori

On 01/28/2010 12:04 PM, Michael S. Tsirkin wrote:

On Thu, Jan 28, 2010 at 11:58:48AM -0600, Anthony Liguori wrote:
   

On 01/28/2010 10:37 AM, Michael S. Tsirkin wrote:
 

So actually, this is an interesting argument in favor of
turning disablenetwork from per-process as it is now
to per-file.

   

Yup.  I think we really need a file-based restriction mechanism and so
far, neither disablenetwork or network namespace seems to do that.

I think you might be able to mitigate this with SELinux since I'm fairly
certain it can prevent SCM_RIGHTS but SELinux is not something that can
be enforced within a set of applications so we'd be relying on SELinux
being enabled (honestly, unlikely) and the policy being correctly
configured (unlikely in the general case at least).

Regards,

Anthony Liguori
 

I am not convinced SELinux being disabled is a problem we necessarily
need to deal with, and qemu does not verify e.g. that it is not run as
root either. A more serious problem IMO is that SCM_RIGHTS might be
needed for some other functionality.
   


It would mean that libvirt is insecure unless SELinux is enabled.  
That's a pretty fundamental flaw IMHO.


At any rate, I think we both agree that we need to figure out a 
solution, so that's good :-)


Regards,

Anthony Liguori
--
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: [patch 3/3] uqmaster: save/restore PIO page

2010-01-28 Thread Anthony Liguori

On 01/28/2010 01:03 PM, Marcelo Tosatti wrote:

KVM uses a page mapped by userspace as a buffer for PIO.

Save/restore it.

Signed-off-by: Marcelo Tosattimtosa...@redhat.com

Index: qemu-kvm/target-i386/cpu.h
===
--- qemu-kvm.orig/target-i386/cpu.h
+++ qemu-kvm/target-i386/cpu.h
@@ -716,6 +716,7 @@ typedef struct CPUX86State {
  uint32_t cpuid_kvm_features;

  KVMPIOState kvm_pio;
+uint8_t kvm_pio_page[4096];
   


TARGET_PAGE_SIZE?

Regards,

Anthony Liguori
--
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: [PATCH qemu-kvm] Add raw(af_packet) network backend to qemu

2010-01-28 Thread Arnd Bergmann
On Thursday 28 January 2010, Anthony Liguori wrote:
 normal user uses libvirt to launch custom qemu instance.  libvirt passes 
 an fd of a raw socket to qemu and puts the qemu process in a restricted 
 network namespace.  user has another program running listening on a unix 
 domain socket and does something to the qemu process that causes it to 
 open the domain socket and send the fd it received from libvirt via 
 SCM_RIGHTS.

I looked at the af_unix code and it seems to suggest that this is not
possible, because you cannot bind to a socket that belongs to a different
network namespace. I haven't tried it though, so I may have missed
something.

Arnd

--
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: [PATCH 04/11] VT-d: Change {un}map_range functions to implement {un}map interface

2010-01-28 Thread David Woodhouse
On Thu, 2010-01-28 at 12:37 +0100, Joerg Roedel wrote:
 This patch changes the iommu-api functions for mapping and
 unmapping page ranges to use the new page-size based
 interface. This allows to remove the range based functions
 later. 

 +   size = 0x1000UL  gfp_order;

Um, that's not a page-size based interface. Page size isn't always 4KiB;
this code runs on IA64 too.

We have enough fun with CPU vs. DMA page size on IA64 already :)

-- 
David WoodhouseOpen Source Technology Centre
david.woodho...@intel.com  Intel Corporation

--
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: [PATCH] uq/master: KVM: Request setting of nmi_pending and sipi_vector

2010-01-28 Thread Marcelo Tosatti
On Thu, Jan 28, 2010 at 09:30:51AM +0100, Jan Kiszka wrote:
 The final version of VCPU events in 2.6.33 will allow to skip
 nmi_pending and sipi_vector on KVM_SET_VCPU_EVENTS. For now let's write
 them unconditionally, which is unproblematic for upstream due to missing
 SMP support. Future version which enable SMP will write them only on
 reset.
 
 Signed-off-by: Jan Kiszka jan.kis...@siemens.com

Applied, thanks.

--
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


Avoiding the page cache?

2010-01-28 Thread Marek Olszewski

Hello,

I'm trying to start using kvm to do some research here at MIT.  I would 
like to try out some interesting page mapping ideas we have that would 
be easier to try out in a hypervisor than inside the linux kernel.  
However, I would like to start hacking a simple version of kvm that 
doesn't do any shadow page table caching as this would make things much 
easier.  I noticed that some earlier versions of kvm in the mainline 
kernel repository (eg 399badf315bd...) around January 2007 do this, but 
I had trouble getting them to work with qemu on an x86_64 processor 
(seems like x86_64 was not supported that well in the kvm branch of qemu 
back then).  How hard do you guys think in would be to change the 
current code to avoid using the cache?


I'm guessing I would have to change mmu_free_roots() to free all the 
pages in the shadow page table, but beyond that I'm a bit lost.  Can 
anybody help me out with some small pointers to get me started?


Thanks!

Marek
--
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: [PATCH 06/11] kvm: Change kvm_iommu_map_pages to map large pages

2010-01-28 Thread Marcelo Tosatti
On Thu, Jan 28, 2010 at 12:37:57PM +0100, Joerg Roedel wrote:
 This patch changes the implementation of of
 kvm_iommu_map_pages to map the pages with the host page size
 into the io virtual address space.
 
 Signed-off-by: Joerg Roedel joerg.roe...@amd.com
 ---
  virt/kvm/iommu.c |  106 ++---
  1 files changed, 84 insertions(+), 22 deletions(-)
 
 diff --git a/virt/kvm/iommu.c b/virt/kvm/iommu.c
 index 65a5143..92a434d 100644
 --- a/virt/kvm/iommu.c
 +++ b/virt/kvm/iommu.c
 @@ -32,12 +32,27 @@ static int kvm_iommu_unmap_memslots(struct kvm *kvm);
  static void kvm_iommu_put_pages(struct kvm *kvm,
   gfn_t base_gfn, unsigned long npages);
  
 +static pfn_t kvm_pin_pages(struct kvm *kvm, struct kvm_memory_slot *slot,
 +gfn_t gfn, unsigned long size)
 +{
 + gfn_t end_gfn;
 + pfn_t pfn;
 +
 + pfn = gfn_to_pfn_memslot(kvm, slot, gfn);

If gfn_to_pfn_memslot returns pfn of bad_page, you might create a
large iommu translation for it?

 + /* Map into IO address space */
 + r = iommu_map(domain, gfn_to_gpa(gfn), pfn_to_hpa(pfn),
 +   get_order(page_size), flags);
 +
 + gfn += page_size  PAGE_SHIFT;

Should increase gfn after checking for failure, otherwise wrong
npages is passed to kvm_iommu_put_pages.

  
 - pfn = gfn_to_pfn_memslot(kvm, slot, gfn);
 - r = iommu_map_range(domain,
 - gfn_to_gpa(gfn),
 - pfn_to_hpa(pfn),
 - PAGE_SIZE, flags);
   if (r) {
   printk(KERN_ERR kvm_iommu_map_address:
  iommu failed to map pfn=%lx\n, pfn);
   goto unmap_pages;
   }
 - gfn++;
 +
   }
 +
   return 0;
  
  unmap_pages:
 - kvm_iommu_put_pages(kvm, slot-base_gfn, i);
 + kvm_iommu_put_pages(kvm, slot-base_gfn, gfn);
   return r;
  }

--
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] Fix qemu-img can't create qcow image based on read-only image

2010-01-28 Thread Sheng Yang
On Thursday 28 January 2010 17:17:22 Kevin Wolf wrote:
 Am 28.01.2010 06:22, schrieb Sheng Yang:
  Commit 03cbdac7 Disable fall-back to read-only when cannot open drive's
  file for read-write result in read-only image can't be used as backed
  image in qemu-img.
 
  CC: Naphtali Sprei nsp...@redhat.com
  Signed-off-by: Sheng Yang sh...@linux.intel.com
  ---
 
  This issue blocked our QA's KVM nightly test. But in fact, I don't like
  this patch, feeling uncomfortable to change long existed interface... Any
  alternative? Add a readonly command line would change the default
  behavior(I don't think fall back to readonly looks like a bug); or even
  revert the commit? What's the story behind it?
 
   qemu-img.c |   15 ++-
   1 files changed, 10 insertions(+), 5 deletions(-)
 
  diff --git a/qemu-img.c b/qemu-img.c
  index 3cea8ce..f8be5cb 100644
  --- a/qemu-img.c
  +++ b/qemu-img.c
  @@ -188,11 +188,13 @@ static int read_password(char *buf, int buf_size)
   #endif
 
   static BlockDriverState *bdrv_new_open(const char *filename,
  -   const char *fmt)
  +   const char *fmt,
  +   int readonly)
   {
   BlockDriverState *bs;
   BlockDriver *drv;
   char password[256];
  +int flags = BRDV_O_FLAGS;
 
   bs = bdrv_new();
   if (!bs)
  @@ -204,7 +206,10 @@ static BlockDriverState *bdrv_new_open(const char
  *filename, } else {
   drv = NULL;
   }
  -if (bdrv_open2(bs, filename, BRDV_O_FLAGS | BDRV_O_RDWR, drv)  0) {
  +if (!readonly) {
  +flags |= BDRV_O_RDWR;
  +}
  +if (bdrv_open2(bs, filename, flags, drv)  0) {
   error(Could not open '%s', filename);
   }
   if (bdrv_is_encrypted(bs)) {
  @@ -343,7 +348,7 @@ static int img_create(int argc, char **argv)
   }
   }
 
  -bs = bdrv_new_open(backing_file-value.s, fmt);
  +bs = bdrv_new_open(backing_file-value.s, fmt, 1);
   bdrv_get_geometry(bs, size);
   size *= 512;
   bdrv_delete(bs);
  @@ -627,7 +632,7 @@ static int img_convert(int argc, char **argv)
 
   total_sectors = 0;
   for (bs_i = 0; bs_i  bs_n; bs_i++) {
  -bs[bs_i] = bdrv_new_open(argv[optind + bs_i], fmt);
  +bs[bs_i] = bdrv_new_open(argv[optind + bs_i], fmt, 0);
 
 Shouldn't it be read-only here, too?
 
Yes. 

Seems you guys are OK with this solution(and I think it's reasonable to remove 
the fall back). I would update the patch, hopefully it can be applied soon and 
picked up by Marcelo to resolve our block issue...

-- 
regards
Yang, Sheng
--
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


[PATCH v2] qemu-img: Fix qemu-img can't create qcow image based on read-only image

2010-01-28 Thread Sheng Yang
Commit 03cbdac7 Disable fall-back to read-only when cannot open drive's
file for read-write result in read-only image can't be used as backed
image in qemu-img.

Cc: Naphtali Sprei nsp...@redhat.com
Signed-off-by: Sheng Yang sh...@linux.intel.com
---
 qemu-img.c |   15 ++-
 1 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index 3cea8ce..ac4d15e 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -188,11 +188,13 @@ static int read_password(char *buf, int buf_size)
 #endif
 
 static BlockDriverState *bdrv_new_open(const char *filename,
-   const char *fmt)
+   const char *fmt,
+   int readonly)
 {
 BlockDriverState *bs;
 BlockDriver *drv;
 char password[256];
+int flags = BRDV_O_FLAGS;
 
 bs = bdrv_new();
 if (!bs)
@@ -204,7 +206,10 @@ static BlockDriverState *bdrv_new_open(const char 
*filename,
 } else {
 drv = NULL;
 }
-if (bdrv_open2(bs, filename, BRDV_O_FLAGS | BDRV_O_RDWR, drv)  0) {
+if (!readonly) {
+flags |= BDRV_O_RDWR;
+}
+if (bdrv_open2(bs, filename, flags, drv)  0) {
 error(Could not open '%s', filename);
 }
 if (bdrv_is_encrypted(bs)) {
@@ -343,7 +348,7 @@ static int img_create(int argc, char **argv)
 }
 }
 
-bs = bdrv_new_open(backing_file-value.s, fmt);
+bs = bdrv_new_open(backing_file-value.s, fmt, 1);
 bdrv_get_geometry(bs, size);
 size *= 512;
 bdrv_delete(bs);
@@ -627,7 +632,7 @@ static int img_convert(int argc, char **argv)
 
 total_sectors = 0;
 for (bs_i = 0; bs_i  bs_n; bs_i++) {
-bs[bs_i] = bdrv_new_open(argv[optind + bs_i], fmt);
+bs[bs_i] = bdrv_new_open(argv[optind + bs_i], fmt, 1);
 if (!bs[bs_i])
 error(Could not open '%s', argv[optind + bs_i]);
 bdrv_get_geometry(bs[bs_i], bs_sectors);
@@ -685,7 +690,7 @@ static int img_convert(int argc, char **argv)
 }
 }
 
-out_bs = bdrv_new_open(out_filename, out_fmt);
+out_bs = bdrv_new_open(out_filename, out_fmt, 0);
 
 bs_i = 0;
 bs_offset = 0;
-- 
1.5.4.5

--
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: Unable to single-step in kvm, always results in a resume

2010-01-28 Thread Nicholas Amon



Jan Kiszka wrote:

Nicholas Amon wrote:
  
So now I can step instruction but my breakpoints do not work.  I have 
verified that disabling kvm restores the breakpoint functionality.  Any 
suggestions?



What kind of breakpoints, hardware-assisted or normal BPs? Are you
trying to break into real-mode code (as stated below - BTW, top-postings
should be avoided!) that happens to run on a non-brand-new Intel host? I
never fully tested how well guest debugging works if KVM has to emulate
instructions, and I wouldn't be surprised if there are limitations.

Jan

  

Jan Kiszka wrote:


Hi Nicholas,

please don't drop CCs on reply.

Nicholas Amon wrote:
  
  

Hi Jan,

Thanks for responding.  Yes, I am able to step instruction when I 
disable kvm w/ the no-kvm option.  My host kernel is 64bit  2.6.27 and 
the program that I am debugging is 32 bit but starts in real mode.  But 
the KVM module I am running is from kvm-88.  Is there anyway I can check 
the version definitively?



kvm modules issue a message when being loaded, check your kernel log.
qemu-kvm gives you the version via -version.

OK, the problems you see is likely related to the very old versions you
use. Update to recent kvm-kmod (2.6.32 series) and qemu-kvm (0.12
series) and retry.

Jan

  
  

Thanks,

Nicholas

Jan Kiszka wrote:



Jan Kiszka wrote:
  
  
  

Nicholas Amon wrote:




Hi All,

I am trying to single-step through my kernel using qemu and kvm.  I have
run qemu via:  qemu-system-x86_64 -s -S -hda
/home/nickamon/lab1/obj/kernel.img and also connected to the process
using gdb.

Problem is that whenever I try and step instruction, it seems to resume
my kernel rather than allowing me to progress instruction by
instruction.  I have built the kvm snapshot from git and still no luck. 
Tried following the code for a few hours and have no luck.  Any

suggestions?
  
  
  

What's you host kernel or kvm-kmod version?





...and does -no-kvm make any difference (except that it's much slower)?

Jan

  
  
  


  
My apologies for the late response.  Normal breakpoints and yes I am 
breaking in real mode.  This isn't a big issue for me since I am able to 
break when I disable kvm.  So basically I disable kvm when I want to 
debug and enable it during normal execution.  Thanks for all your help.


Nick

Nicholas Amon
See How to Control  Track High-Risk Users: Join our Webinar on Tuesday, 
June 2

Network World Names Xceedium GateKeeper RSA 2009 Best of Show

--
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


[PATCH] KVM test: Fixing sha/md5 deprecation messages

2010-01-28 Thread Lucas Meneghel Rodrigues
When using python  2.4, use the recommended hashlib.
When using python 2.4, fall back to the md5 and sha
modules.

Signed-off-by: Lucas Meneghel Rodrigues l...@redhat.com
---
 client/tests/kvm/kvm_utils.py   |   18 ++
 client/tests/kvm/ppm_utils.py   |   12 +---
 client/tests/kvm/tests/steps.py |2 +-
 3 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py
index 5452026..b1f184e 100644
--- a/client/tests/kvm/kvm_utils.py
+++ b/client/tests/kvm/kvm_utils.py
@@ -4,10 +4,14 @@ KVM test utility functions.
 @copyright: 2008-2009 Red Hat Inc.
 
 
-import md5, sha, thread, subprocess, time, string, random, socket, os, signal
+import thread, subprocess, time, string, random, socket, os, signal
+try:
+import hashlib
+except ImportError:
+import md5, sha
 import select, re, logging, commands, cPickle, pty
 from autotest_lib.client.bin import utils
-from autotest_lib.client.common_lib import error
+from autotest_lib.client.common_lib import error, logging_config
 import kvm_subprocess
 
 
@@ -789,9 +793,15 @@ def hash_file(filename, size=None, method=md5):
 f = open(filename, 'rb')
 
 if method == md5:
-hash = md5.new()
+try:
+hash = hashlib.new('md5')
+except NameError:
+hash = md5.new()
 elif method == sha1:
-hash = sha.new()
+try:
+hash = hashlib.new('sha1')
+except NameError:
+hash = sha.new()
 else:
 logging.error(Unknown hash type %s, returning None % method)
 return None
diff --git a/client/tests/kvm/ppm_utils.py b/client/tests/kvm/ppm_utils.py
index 8ff31da..aaea298 100644
--- a/client/tests/kvm/ppm_utils.py
+++ b/client/tests/kvm/ppm_utils.py
@@ -4,8 +4,11 @@ Utility functions to deal with ppm (qemu screendump format) 
files.
 @copyright: Red Hat 2008-2009
 
 
-import md5, os, struct, time, re
-
+import os, struct, time, re
+try:
+import hashlib
+except ImportError:
+import md5
 
 # Some directory/filename utils, for consistency
 
@@ -120,7 +123,10 @@ def image_md5sum(width, height, data):
 @data: PPM file data
 
 header = P6\n%d %d\n255\n % (width, height)
-md5obj = md5.new(header)
+try:
+md5obj = hashlib.md5(header)
+except NameError:
+md5obj = md5.new(header)
 md5obj.update(data)
 return md5obj.hexdigest()
 
diff --git a/client/tests/kvm/tests/steps.py b/client/tests/kvm/tests/steps.py
index 456fb44..8ebe7c1 100644
--- a/client/tests/kvm/tests/steps.py
+++ b/client/tests/kvm/tests/steps.py
@@ -4,7 +4,7 @@ Utilities to perform automatic guest installation using step 
files.
 @copyright: Red Hat 2008-2009
 
 
-import os, time, md5, re, shutil, logging
+import os, time, re, shutil, logging
 from autotest_lib.client.common_lib import utils, error
 import kvm_utils, ppm_utils, kvm_subprocess
 try:
-- 
1.6.6

--
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


[PATCH 2/6] KVM test: Define defaults for KVM test

2010-01-28 Thread Lucas Meneghel Rodrigues
Define reasonable defaults for the kvm test, to make it
easier to start using KVM autotest and encourage people
to play with it. The defaults are:

 * qemu and qemu-kvm are expected to be found under
   /usr/bin.
 * The auxiliary directories are expected to be
   found under /tmp/kvm_autotest_root, since some
   people might want to use a nfs share to provide
   cds.

A first time config script will be provided to assist
people creating their first kvm test setup so it can
be done answering a few questions and leaving the
heavy lifting to the script.

Signed-off-by: Lucas Meneghel Rodrigues l...@redhat.com
---
 client/tests/kvm/tests.cfg.sample |   15 +++
 1 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/client/tests/kvm/tests.cfg.sample 
b/client/tests/kvm/tests.cfg.sample
index c478ba2..23f50ba 100644
--- a/client/tests/kvm/tests.cfg.sample
+++ b/client/tests/kvm/tests.cfg.sample
@@ -6,19 +6,18 @@ include cdkeys.cfg
 
 # Modify/comment the following lines if you wish to modify
 # the paths of the image files, ISO files, step files or qemu binaries.
-# If you keep these lines commented, all mentioned paths are expected
-# to be found in the KVM test dir (tests/kvm/).
-# On the example below:
+#
+# As for the defaults:
 # * qemu and qemu-img are expected to be found under /usr/bin/qemu-kvm and
 #   /usr/bin/qemu-img respectively.
 # * All image files are expected under /tmp/kvm_autotest_root/images/
 # * All iso files are expected under /tmp/kvm_autotest_root/isos/
 # * All step files are expected under /tmp/kvm_autotest_root/steps/
-#qemu_binary = /usr/bin/qemu-kvm
-#qemu_img_binary = /usr/bin/qemu-img
-#image_name.* ?= /tmp/kvm_autotest_root/
-#cdrom.* ?= /tmp/kvm_autotest_root/
-#steps ?= /tmp/kvm_autotest_root/
+qemu_binary = /usr/bin/qemu-kvm
+qemu_img_binary = /usr/bin/qemu-img
+image_name.* ?= /tmp/kvm_autotest_root/
+cdrom.* ?= /tmp/kvm_autotest_root/
+steps ?= /tmp/kvm_autotest_root/
 
 variants:
 - @full:
-- 
1.6.6

--
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


[PATCH 3/6] KVM test: Make sure reset and shutdown are the last ones

2010-01-28 Thread Lucas Meneghel Rodrigues
system_reset, system_powerdown and shutdown *must*
be the last ones defined, since the effect of such
tests can leave the VM on a bad state.

Signed-off-by: Lucas Meneghel Rodrigues l...@redhat.com
---
 client/tests/kvm/tests_base.cfg.sample |   35 +--
 1 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/client/tests/kvm/tests_base.cfg.sample 
b/client/tests/kvm/tests_base.cfg.sample
index 8a7a13d..fdd04cb 100644
--- a/client/tests/kvm/tests_base.cfg.sample
+++ b/client/tests/kvm/tests_base.cfg.sample
@@ -236,6 +236,24 @@ variants:
 - fmt_raw:
 image_format_stg = raw
 
+- vlan_tag:  install setup unattended_install
+type = vlan_tag
+# subnet should not be used by host
+subnet = 192.168.123
+vlans = 10 20
+nic_mode = tap
+vms +=  vm2
+extra_params_vm1 +=  -snapshot
+extra_params_vm2 +=  -snapshot
+kill_vm_gracefully_vm2 = no
+address_index_vm2 = 1
+
+- physical_resources_check: install setup unattended_install
+type = physical_resources_check
+catch_uuid_cmd = dmidecode | awk -F: '/UUID/ {print $2}'
+
+# system_reset, system_powerdown and shutdown *must* be the last ones
+# defined, since the effect of such tests can leave the VM on a bad state.
 - system_reset: install setup unattended_install
 type = boot
 reboot_method = system_reset
@@ -254,22 +272,7 @@ variants:
 shutdown_method = shell
 kill_vm = yes
 kill_vm_gracefully = no
-
-- vlan_tag:  install setup unattended_install
-type = vlan_tag
-# subnet should not be used by host
-subnet = 192.168.123
-vlans = 10 20
-nic_mode = tap
-vms +=  vm2
-extra_params_vm1 +=  -snapshot
-extra_params_vm2 +=  -snapshot
-kill_vm_gracefully_vm2 = no
-address_index_vm2 = 1
-
-- physical_resources_check: install setup unattended_install
-type = physical_resources_check
-catch_uuid_cmd = dmidecode | awk -F: '/UUID/ {print $2}'
+# Do not define test variants below shutdown
 
 # NICs
 variants:
-- 
1.6.6

--
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


[PATCH 4/6] KVM test: Moving KvmLogging utility class to kvm_utils

2010-01-28 Thread Lucas Meneghel Rodrigues
Some of the auxiliary kvm test programs need to
use logging configuration, we ended up duplicating
code across the test. Move the duplicated instances
to a single one living in kvm_utils.py.

Signed-off-by: Lucas Meneghel Rodrigues l...@redhat.com
---
 client/tests/kvm/cd_hash.py|7 +--
 client/tests/kvm/kvm_config.py |8 +---
 client/tests/kvm/kvm_utils.py  |   10 ++
 3 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/client/tests/kvm/cd_hash.py b/client/tests/kvm/cd_hash.py
index 483d71c..a857ed8 100755
--- a/client/tests/kvm/cd_hash.py
+++ b/client/tests/kvm/cd_hash.py
@@ -10,11 +10,6 @@ import common, kvm_utils
 from autotest_lib.client.common_lib import logging_config, logging_manager
 
 
-class KvmLoggingConfig(logging_config.LoggingConfig):
-def configure_logging(self, results_dir=None, verbose=False):
-super(KvmLoggingConfig, self).configure_logging(use_console=True,
-verbose=verbose)
-
 if __name__ == __main__:
 parser = optparse.OptionParser()
 parser.add_option('-i', '--iso', type=string, dest=filename,
@@ -25,7 +20,7 @@ if __name__ == __main__:
 options, args = parser.parse_args()
 filename = options.filename
 
-logging_manager.configure_logging(KvmLoggingConfig())
+logging_manager.configure_logging(kvm_utils.KvmLoggingConfig())
 
 if not filename:
 parser.print_help()
diff --git a/client/tests/kvm/kvm_config.py b/client/tests/kvm/kvm_config.py
index 798ef56..51f069a 100755
--- a/client/tests/kvm/kvm_config.py
+++ b/client/tests/kvm/kvm_config.py
@@ -11,12 +11,6 @@ from autotest_lib.client.common_lib import error
 from autotest_lib.client.common_lib import logging_config, logging_manager
 
 
-class KvmLoggingConfig(logging_config.LoggingConfig):
-def configure_logging(self, results_dir=None, verbose=False):
-super(KvmLoggingConfig, self).configure_logging(use_console=True,
-verbose=verbose)
-
-
 class config:
 
 Parse an input file or string that follows the KVM Test Config File format
@@ -517,7 +511,7 @@ if __name__ == __main__:
 
 # Here we configure the stand alone program to use the autotest
 # logging system.
-logging_manager.configure_logging(KvmLoggingConfig(), verbose=debug)
+logging_manager.configure_logging(kvm_utils.KvmLoggingConfig(), 
verbose=debug)
 list = config(filename, debug=debug).get_list()
 i = 0
 for dict in list:
diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py
index f8089f7..5452026 100644
--- a/client/tests/kvm/kvm_utils.py
+++ b/client/tests/kvm/kvm_utils.py
@@ -970,6 +970,16 @@ def get_vendor_from_pci_id(pci_id):
 return re.sub(:,  , commands.getoutput(cmd))
 
 
+class KvmLoggingConfig(logging_config.LoggingConfig):
+
+Used with the sole purpose of providing convenient logging setup
+for the KVM test auxiliary programs.
+
+def configure_logging(self, results_dir=None, verbose=False):
+super(KvmLoggingConfig, self).configure_logging(use_console=True,
+verbose=verbose)
+
+
 class PciAssignable(object):
 
 Request PCI assignable devices on host. It will check whether to request
-- 
1.6.6

--
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


[PATCH 5/6] KVM test: Getting rid of annoying deprecation message

2010-01-28 Thread Lucas Meneghel Rodrigues
When using python  2.5, use the recommended hashlib.
When using python 2.4, fall back to the md5 and sha
modules.

Signed-off-by: Lucas Meneghel Rodrigues l...@redhat.com
---
 client/tests/kvm/kvm_utils.py   |   18 ++
 client/tests/kvm/ppm_utils.py   |   12 +---
 client/tests/kvm/tests/steps.py |2 +-
 3 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py
index 5452026..b1f184e 100644
--- a/client/tests/kvm/kvm_utils.py
+++ b/client/tests/kvm/kvm_utils.py
@@ -4,10 +4,14 @@ KVM test utility functions.
 @copyright: 2008-2009 Red Hat Inc.
 
 
-import md5, sha, thread, subprocess, time, string, random, socket, os, signal
+import thread, subprocess, time, string, random, socket, os, signal
+try:
+import hashlib
+except ImportError:
+import md5, sha
 import select, re, logging, commands, cPickle, pty
 from autotest_lib.client.bin import utils
-from autotest_lib.client.common_lib import error
+from autotest_lib.client.common_lib import error, logging_config
 import kvm_subprocess
 
 
@@ -789,9 +793,15 @@ def hash_file(filename, size=None, method=md5):
 f = open(filename, 'rb')
 
 if method == md5:
-hash = md5.new()
+try:
+hash = hashlib.new('md5')
+except NameError:
+hash = md5.new()
 elif method == sha1:
-hash = sha.new()
+try:
+hash = hashlib.new('sha1')
+except NameError:
+hash = sha.new()
 else:
 logging.error(Unknown hash type %s, returning None % method)
 return None
diff --git a/client/tests/kvm/ppm_utils.py b/client/tests/kvm/ppm_utils.py
index 8ff31da..aaea298 100644
--- a/client/tests/kvm/ppm_utils.py
+++ b/client/tests/kvm/ppm_utils.py
@@ -4,8 +4,11 @@ Utility functions to deal with ppm (qemu screendump format) 
files.
 @copyright: Red Hat 2008-2009
 
 
-import md5, os, struct, time, re
-
+import os, struct, time, re
+try:
+import hashlib
+except ImportError:
+import md5
 
 # Some directory/filename utils, for consistency
 
@@ -120,7 +123,10 @@ def image_md5sum(width, height, data):
 @data: PPM file data
 
 header = P6\n%d %d\n255\n % (width, height)
-md5obj = md5.new(header)
+try:
+md5obj = hashlib.md5(header)
+except NameError:
+md5obj = md5.new(header)
 md5obj.update(data)
 return md5obj.hexdigest()
 
diff --git a/client/tests/kvm/tests/steps.py b/client/tests/kvm/tests/steps.py
index 456fb44..8ebe7c1 100644
--- a/client/tests/kvm/tests/steps.py
+++ b/client/tests/kvm/tests/steps.py
@@ -4,7 +4,7 @@ Utilities to perform automatic guest installation using step 
files.
 @copyright: Red Hat 2008-2009
 
 
-import os, time, md5, re, shutil, logging
+import os, time, re, shutil, logging
 from autotest_lib.client.common_lib import utils, error
 import kvm_utils, ppm_utils, kvm_subprocess
 try:
-- 
1.6.6

--
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


[PATCH 6/6] KVM test: Add a get_started.py script

2010-01-28 Thread Lucas Meneghel Rodrigues
In order to make it easier to get started with KVM
testing, add a script that helps with setting up
directories, paths and iso files for the default
test configuration (Fedora 12 guest install, boot
test, shutdown). Once the first idea of how things
work is formed, one may start to tinker with
configuration files.

Added pointers to the online documentation.

Signed-off-by: Lucas Meneghel Rodrigues l...@redhat.com
---
 client/tests/kvm/README |   19 +++-
 client/tests/kvm/get_started.py |  103 +++
 2 files changed, 121 insertions(+), 1 deletions(-)
 create mode 100755 client/tests/kvm/get_started.py

diff --git a/client/tests/kvm/README b/client/tests/kvm/README
index 88d2c15..628f3d9 100644
--- a/client/tests/kvm/README
+++ b/client/tests/kvm/README
@@ -1,3 +1,20 @@
-In order to get started, please refer to the online documentation:
+For the impatient:
+
+Execute the get_started.py script located on this directory,
+that will guide you through setting up the default kvm test
+scenario:
+
+ * Guest install with Fedora 12
+ * Boot, reboot and shutdown test
+
+The script will help you to create all the directories, and
+even get the OS iso in case you don't have it yet.
+
+For the not so impatient:
+
+You are *strongly* advised to read the online docs:
 
 http://www.linux-kvm.org/page/KVM-Autotest/Client_Install
+
+So you can have a better idea of how the test is organized
+and how it works.
diff --git a/client/tests/kvm/get_started.py b/client/tests/kvm/get_started.py
new file mode 100755
index 000..51d98f0
--- /dev/null
+++ b/client/tests/kvm/get_started.py
@@ -0,0 +1,103 @@
+#!/usr/bin/python
+
+Program to help setup kvm test environment
+
+...@copyright: Red Hat 2010
+
+
+import os, sys, optparse, logging, shutil
+import common, kvm_utils
+from autotest_lib.client.common_lib import logging_manager
+from autotest_lib.client.bin import utils, os_dep
+
+
+if __name__ == __main__:
+logging_manager.configure_logging(kvm_utils.KvmLoggingConfig(),
+  verbose=True)
+logging.info(KVM test config helper)
+
+logging.info(1 - Verifying directories (check if the directory structure 
+ expected by the default test config is there))
+base_dir = /tmp/kvm_autotest_root
+sub_dir_list = [images, isos, steps_data]
+for sub_dir in sub_dir_list:
+sub_dir_path = os.path.join(base_dir, sub_dir)
+if not os.path.isdir(sub_dir_path):
+logging.debug(Creating %s, sub_dir_path)
+os.makedirs(sub_dir_path)
+else:
+logging.debug(Dir %s exists, not creating %
+  sub_dir_path)
+logging.info(Do you want to setup NFS mounts for some of those 
+ dirs? (y/n))
+setup_nfs = raw_input()
+if setup_nfs == 'y':
+logging.info(Exiting the script so you can setup the NFS mounts. 
+ When you are done, re-run this script.)
+sys.exit(0)
+
+logging.info(2 - Creating config files from samples (copy the default 
+ config samples to actual config files))
+kvm_test_dir = os.path.dirname(sys.modules[__name__].__file__)
+kvm_test_dir = os.path.abspath(kvm_test_dir)
+config_file_list = [address_pools.cfg, build.cfg, cdkeys.cfg,
+tests_base.cfg, tests.cfg]
+for config_file in config_file_list:
+src_file = os.path.join(kvm_test_dir, %s.sample % config_file)
+dst_file = os.path.join(kvm_test_dir, config_file)
+if not os.path.isfile(dst_file):
+logging.debug(Creating config file %s from sample, dst_file)
+shutil.copyfile(src_file, dst_file)
+else:
+logging.debug(Config file %s exists, not touching % dst_file)
+
+logging.info(3 - Verifying iso (make sure we have the OS iso needed for 
+ the default test set))
+base_iso_name = Fedora-12-x86_64-DVD.iso
+fedora_dir = pub/fedora/linux/releases/12/Fedora/x86_64/iso
+url = os.path.join(http://download.fedoraproject.org/;, fedora_dir,
+   base_iso_name)
+md5sum = 6dd31e292cc2eb1140544e9b1ba61c56
+iso_dir = os.path.join(base_dir, 'images', 'linux')
+if not iso_dir:
+os.makedirs(iso_dir)
+iso_path = os.path.join(iso_dir, base_iso_name)
+if not os.path.isfile(iso_path) or (
+  kvm_utils.hash_file(iso_path, method=md5) != md5sum):
+logging.warning(%s not found or corrupted, iso_path)
+logging.warning(Would you like to download it? (y/n))
+iso_download = raw_input()
+if iso_download == 'y':
+kvm_utils.unmap_url_cache(iso_dir, url, md5sum)
+else:
+logging.warning(Missing file %s. Please download it % iso_path)
+else:
+logging.debug(%s present, with proper checksum)
+
+logging.info(4 - Checking if qemu is installed (certify qemu and qemu-kvm 

+ 

[PATCH] enable PCI multiple-segments for pass-through device

2010-01-28 Thread Zhai, Edwin
These 2 patches enable optional parameter(default 0) - PCI segment(or 
domain) besides BDF, when assigning PCI device to guest.


Signed-off-by: Zhai Edwin edwin.z...@intel.com


--
best rgds,
edwin

Index: linux-2.6/virt/kvm/assigned-dev.c
===
--- linux-2.6.orig/virt/kvm/assigned-dev.c
+++ linux-2.6/virt/kvm/assigned-dev.c
@@ -526,7 +526,8 @@ static int kvm_vm_ioctl_assign_device(st
r = -ENOMEM;
goto out;
}
-   dev = pci_get_bus_and_slot(assigned_dev-busnr,
+   dev = pci_get_domain_bus_and_slot(assigned_dev-segnr,
+  assigned_dev-busnr,
   assigned_dev-devfn);
if (!dev) {
printk(KERN_INFO %s: host device not found\n, __func__);
@@ -548,6 +549,7 @@ static int kvm_vm_ioctl_assign_device(st
pci_reset_function(dev);
 
match-assigned_dev_id = assigned_dev-assigned_dev_id;
+   match-host_segnr = assigned_dev-segnr;
match-host_busnr = assigned_dev-busnr;
match-host_devfn = assigned_dev-devfn;
match-flags = assigned_dev-flags;
Index: linux-2.6/virt/kvm/iommu.c
===
--- linux-2.6.orig/virt/kvm/iommu.c
+++ linux-2.6/virt/kvm/iommu.c
@@ -106,7 +106,8 @@ int kvm_assign_device(struct kvm *kvm,
 
r = iommu_attach_device(domain, pdev-dev);
if (r) {
-   printk(KERN_ERR assign device %x:%x.%x failed,
+   printk(KERN_ERR assign device %x:%x:%x.%x failed,
+   pci_domain_nr(pdev-bus),
pdev-bus-number,
PCI_SLOT(pdev-devfn),
PCI_FUNC(pdev-devfn));
@@ -127,7 +128,8 @@ int kvm_assign_device(struct kvm *kvm,
goto out_unmap;
}
 
-   printk(KERN_DEBUG assign device: host bdf = %x:%x:%x\n,
+   printk(KERN_DEBUG assign device %x:%x:%x.%x\n,
+   assigned_dev-host_segnr,
assigned_dev-host_busnr,
PCI_SLOT(assigned_dev-host_devfn),
PCI_FUNC(assigned_dev-host_devfn));
@@ -154,7 +156,8 @@ int kvm_deassign_device(struct kvm *kvm,
 
iommu_detach_device(domain, pdev-dev);
 
-   printk(KERN_DEBUG deassign device: host bdf = %x:%x:%x\n,
+   printk(KERN_DEBUG deassign device %x:%x:%x.%x\n,
+   assigned_dev-host_segnr,
assigned_dev-host_busnr,
PCI_SLOT(assigned_dev-host_devfn),
PCI_FUNC(assigned_dev-host_devfn));
Index: linux-2.6/include/linux/kvm.h
===
--- linux-2.6.orig/include/linux/kvm.h
+++ linux-2.6/include/linux/kvm.h
@@ -691,8 +691,9 @@ struct kvm_assigned_pci_dev {
__u32 busnr;
__u32 devfn;
__u32 flags;
+   __u32 segnr;
union {
-   __u32 reserved[12];
+   __u32 reserved[11];
};
 };
 
Index: linux-2.6/include/linux/kvm_host.h
===
--- linux-2.6.orig/include/linux/kvm_host.h
+++ linux-2.6/include/linux/kvm_host.h
@@ -400,6 +400,7 @@ struct kvm_assigned_dev_kernel {
struct work_struct interrupt_work;
struct list_head list;
int assigned_dev_id;
+   int host_segnr;
int host_busnr;
int host_devfn;
unsigned int entries_nr;
Index: qemu-kvm/hw/device-assignment.c
===
--- qemu-kvm.orig/hw/device-assignment.c
+++ qemu-kvm/hw/device-assignment.c
@@ -595,8 +595,8 @@ static int get_real_device_id(const char
 return get_real_id(devpath, device, val);
 }
 
-static int get_real_device(AssignedDevice *pci_dev, uint8_t r_bus,
-   uint8_t r_dev, uint8_t r_func)
+static int get_real_device(AssignedDevice *pci_dev, uint16_t r_seg,
+   uint8_t r_bus, uint8_t r_dev, uint8_t r_func)
 {
 char dir[128], name[128];
 int fd, r = 0, v;
@@ -609,8 +609,8 @@ static int get_real_device(AssignedDevic
 
 dev-region_number = 0;
 
-snprintf(dir, sizeof(dir), /sys/bus/pci/devices/:%02x:%02x.%x/,
-r_bus, r_dev, r_func);
+snprintf(dir, sizeof(dir), /sys/bus/pci/devices/%04x:%02x:%02x.%x/,
+r_seg, r_bus, r_dev, r_func);
 
 snprintf(name, sizeof(name), %sconfig, dir);
 
@@ -752,9 +752,9 @@ static void free_assigned_device(Assigne
 }
 }
 
-static uint32_t calc_assigned_dev_id(uint8_t bus, uint8_t devfn)
+static uint32_t calc_assigned_dev_id(uint16_t seg, uint8_t bus, uint8_t devfn)
 {
-return (uint32_t)bus  8 | (uint32_t)devfn;
+return (uint32_t)seg  16 | (uint32_t)bus  8 | (uint32_t)devfn;
 }
 
 static void assign_failed_examine(AssignedDevice *dev)
@@ -763,9 +763,8 @@ static void assign_failed_examine(Assign
 uint16_t vendor_id, device_id;
 int r;
 

[Autotest PATCH] KVM-test: Add a subtest 'qemu_img'

2010-01-28 Thread Yolkfull Chow
This is designed to test all subcommands of 'qemu-img' however
so far 'commit' is not implemented.

* For 'check' subcommand test, it will 'dd' to create a file with specified
size and see whether it's supported to be checked. Then convert it to be
supported formats ('qcow2' and 'raw' so far) to see whether there's error
after convertion.

* For 'convert' subcommand test, it will convert both to 'qcow2' and 'raw' from
the format specified in config file. And only check 'qcow2' after convertion.

* For 'snapshot' subcommand test, it will create two snapshots and list them.
Finally delete them if no errors found.

* For 'info' subcommand test, it will check image format  size according to
output of 'info' subcommand  at specified image file.

* For 'rebase' subcommand test, it will create first snapshot 'sn1' based on 
original
base_img, and create second snapshot based on sn1. And then rebase sn2 to 
base_img.
After rebase check the baking_file of sn2.

This supports two rebase mode: unsafe mode and safe mode:
Unsafe mode:
With -u an unsafe mode is enabled that doesn't require the backing files to 
exist.
It merely changes the backing file reference in the COW image. This is useful 
for
renaming or moving the backing file. The user is responsible to make sure that 
the
new backing file has no changes compared to the old one, or corruption may 
occur.

Safe Mode:
Both the current and the new backing file need to exist, and after the rebase, 
the
COW image is guaranteed to have the same guest visible content as before.
To achieve this, old and new backing file are compared and, if necessary, data 
is
copied from the old backing file into the COW image.

Signed-off-by: Yolkfull Chow yz...@redhat.com
---
 client/tests/kvm/tests/qemu_img.py |  235 
 client/tests/kvm/tests_base.cfg.sample |   40 ++
 2 files changed, 275 insertions(+), 0 deletions(-)
 create mode 100644 client/tests/kvm/tests/qemu_img.py

diff --git a/client/tests/kvm/tests/qemu_img.py 
b/client/tests/kvm/tests/qemu_img.py
new file mode 100644
index 000..e6352a0
--- /dev/null
+++ b/client/tests/kvm/tests/qemu_img.py
@@ -0,0 +1,235 @@
+import re, os, logging, commands
+from autotest_lib.client.common_lib import utils, error
+import kvm_vm, kvm_utils
+
+
+def run_qemu_img(test, params, env):
+
+`qemu-img' functions test:
+1) Judge what subcommand is going to be tested
+2) Run subcommand test
+
+@param test: kvm test object
+@param params: Dictionary with the test parameters
+@param env: Dictionary with test environment.
+
+cmd = kvm_utils.get_path(test.bindir, params.get(qemu_img_binary))
+if not os.path.exists(cmd):
+raise error.TestError(Binary of 'qemu-img' not found)
+image_format = params.get(image_format)
+image_size = params.get(image_size, 10G)
+image_name = kvm_vm.get_image_filename(params, test.bindir)
+
+def check(cmd, img):
+cmd +=  check %s % img
+logging.info(Checking image '%s'... % img)
+o = commands.getoutput(cmd)
+if does not support checks in o or No errors in o:
+return (True, )
+return (False, o)
+
+# Subcommand 'qemu-img check' test
+# This tests will 'dd' to create a specified size file, and check it.
+# Then convert it to supported image_format in each loop and check again.
+def check_test(cmd):
+test_image = params.get(image_name_dd)
+create_image_cmd = params.get(create_image_cmd)
+create_image_cmd = create_image_cmd % test_image
+s, o = commands.getstatusoutput(create_image_cmd)
+if s != 0:
+raise error.TestError(Failed command: %s; Output is: %s %
+ (create_image_cmd, o))
+s, o = check(cmd, test_image)
+if not s:
+raise error.TestFail(Check image '%s' failed with error: %s %
+   (test_image, o))
+for fmt in params.get(supported_image_formats).split():
+output_image = test_image + .%s % fmt
+convert(cmd, fmt, test_image, output_image)
+s, o = check(cmd, output_image)
+if not s:
+raise error.TestFail(Check image '%s' got error: %s %
+ (output_image, o))
+os.remove(output_image)
+os.remove(test_image)
+
+def create(cmd, img_name, fmt, img_size=None, base_img=None,
+   base_img_fmt=None, encrypted=no):
+cmd +=  create
+if encrypted == yes:
+cmd +=  -e
+if base_img:
+cmd +=  -b %s % base_img
+if base_img_fmt:
+cmd +=  -F %s % base_img_fmt
+cmd +=  -f %s % fmt
+cmd +=  %s % img_name
+if img_size:
+cmd +=  %s % img_size
+s, o = commands.getstatusoutput(cmd)
+if s != 0:
+

Re: [Autotest PATCH] KVM-test: Add a subtest 'qemu_img'

2010-01-28 Thread Yolkfull Chow
On Fri, Jan 29, 2010 at 03:00:09PM +0800, Yolkfull Chow wrote:
 This is designed to test all subcommands of 'qemu-img' however
 so far 'commit' is not implemented.
 
 * For 'check' subcommand test, it will 'dd' to create a file with specified
 size and see whether it's supported to be checked. Then convert it to be
 supported formats ('qcow2' and 'raw' so far) to see whether there's error
 after convertion.
 
 * For 'convert' subcommand test, it will convert both to 'qcow2' and 'raw' 
 from
 the format specified in config file. And only check 'qcow2' after convertion.
 
 * For 'snapshot' subcommand test, it will create two snapshots and list them.
 Finally delete them if no errors found.
 
 * For 'info' subcommand test, it will check image format  size according to
 output of 'info' subcommand  at specified image file.
 
 * For 'rebase' subcommand test, it will create first snapshot 'sn1' based on 
 original
 base_img, and create second snapshot based on sn1. And then rebase sn2 to 
 base_img.
 After rebase check the baking_file of sn2.
 
 This supports two rebase mode: unsafe mode and safe mode:
 Unsafe mode:
 With -u an unsafe mode is enabled that doesn't require the backing files to 
 exist.
 It merely changes the backing file reference in the COW image. This is useful 
 for
 renaming or moving the backing file. The user is responsible to make sure 
 that the
 new backing file has no changes compared to the old one, or corruption may 
 occur.
 
 Safe Mode:
 Both the current and the new backing file need to exist, and after the 
 rebase, the
 COW image is guaranteed to have the same guest visible content as before.
 To achieve this, old and new backing file are compared and, if necessary, 
 data is
 copied from the old backing file into the COW image.
 
 Signed-off-by: Yolkfull Chow yz...@redhat.com
 ---
  client/tests/kvm/tests/qemu_img.py |  235 
 
  client/tests/kvm/tests_base.cfg.sample |   40 ++
  2 files changed, 275 insertions(+), 0 deletions(-)
  create mode 100644 client/tests/kvm/tests/qemu_img.py
 
 diff --git a/client/tests/kvm/tests/qemu_img.py 
 b/client/tests/kvm/tests/qemu_img.py
 new file mode 100644
 index 000..e6352a0
 --- /dev/null
 +++ b/client/tests/kvm/tests/qemu_img.py
 @@ -0,0 +1,235 @@
 +import re, os, logging, commands
 +from autotest_lib.client.common_lib import utils, error
 +import kvm_vm, kvm_utils
 +
 +
 +def run_qemu_img(test, params, env):
 +
 +`qemu-img' functions test:
 +1) Judge what subcommand is going to be tested
 +2) Run subcommand test
 +
 +@param test: kvm test object
 +@param params: Dictionary with the test parameters
 +@param env: Dictionary with test environment.
 +
 +cmd = kvm_utils.get_path(test.bindir, params.get(qemu_img_binary))
 +if not os.path.exists(cmd):
 +raise error.TestError(Binary of 'qemu-img' not found)
 +image_format = params.get(image_format)
 +image_size = params.get(image_size, 10G)
 +image_name = kvm_vm.get_image_filename(params, test.bindir)
 +
 +def check(cmd, img):
 +cmd +=  check %s % img
 +logging.info(Checking image '%s'... % img)
 +o = commands.getoutput(cmd)
 +if does not support checks in o or No errors in o:
 +return (True, )
 +return (False, o)
 +
 +# Subcommand 'qemu-img check' test
 +# This tests will 'dd' to create a specified size file, and check it.
 +# Then convert it to supported image_format in each loop and check again.
 +def check_test(cmd):
 +test_image = params.get(image_name_dd)
 +create_image_cmd = params.get(create_image_cmd)
 +create_image_cmd = create_image_cmd % test_image
 +s, o = commands.getstatusoutput(create_image_cmd)
 +if s != 0:
 +raise error.TestError(Failed command: %s; Output is: %s %
 + (create_image_cmd, o))
 +s, o = check(cmd, test_image)
 +if not s:
 +raise error.TestFail(Check image '%s' failed with error: %s %
 +   (test_image, o))
 +for fmt in params.get(supported_image_formats).split():
 +output_image = test_image + .%s % fmt
 +convert(cmd, fmt, test_image, output_image)
 +s, o = check(cmd, output_image)
 +if not s:
 +raise error.TestFail(Check image '%s' got error: %s %
 + (output_image, o))
 +os.remove(output_image)
 +os.remove(test_image)
 +
 +def create(cmd, img_name, fmt, img_size=None, base_img=None,
 +   base_img_fmt=None, encrypted=no):
 +cmd +=  create
 +if encrypted == yes:
 +cmd +=  -e
 +if base_img:
 +cmd +=  -b %s % base_img
 +if base_img_fmt:
 +cmd +=  -F %s % base_img_fmt
 +

Re: [Qemu-devel] [PATCH v2] qemu-img: Fix qemu-img can't create qcow image based on read-only image

2010-01-28 Thread Kevin Wolf
Am 29.01.2010 03:15, schrieb Sheng Yang:
 Commit 03cbdac7 Disable fall-back to read-only when cannot open drive's
 file for read-write result in read-only image can't be used as backed
 image in qemu-img.
 
 Cc: Naphtali Sprei nsp...@redhat.com
 Signed-off-by: Sheng Yang sh...@linux.intel.com

Acked-by: Kevin Wolf kw...@redhat.com
--
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


[PATCH] KVM: Remove redundant check in vm_need_virtualize_apic_accesses()

2010-01-28 Thread Gui Jianfeng
flexpriority_enabled implies cpu_has_vmx_virtualize_apic_accesses() returning
true, so we don't need this check here.

Signed-off-by: Gui Jianfeng guijianf...@cn.fujitsu.com
---
 arch/x86/kvm/vmx.c |4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 9f56110..0e6af4a 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -358,9 +358,7 @@ static inline int cpu_has_vmx_ple(void)
 
 static inline int vm_need_virtualize_apic_accesses(struct kvm *kvm)
 {
-   return flexpriority_enabled 
-   (cpu_has_vmx_virtualize_apic_accesses()) 
-   (irqchip_in_kernel(kvm));
+   return flexpriority_enabled  irqchip_in_kernel(kvm);
 }
 
 static inline int cpu_has_vmx_vpid(void)
-- 
1.5.4.rc3


--
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: [PATCH] KVM: Remove redundant check in vm_need_virtualize_apic_accesses()

2010-01-28 Thread Sheng Yang
On Friday 29 January 2010 15:36:59 Gui Jianfeng wrote:
 flexpriority_enabled implies cpu_has_vmx_virtualize_apic_accesses()
  returning true, so we don't need this check here.
 
Looks fine to me.

-- 
regards
Yang, Sheng

 Signed-off-by: Gui Jianfeng guijianf...@cn.fujitsu.com
 ---
  arch/x86/kvm/vmx.c |4 +---
  1 files changed, 1 insertions(+), 3 deletions(-)
 
 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
 index 9f56110..0e6af4a 100644
 --- a/arch/x86/kvm/vmx.c
 +++ b/arch/x86/kvm/vmx.c
 @@ -358,9 +358,7 @@ static inline int cpu_has_vmx_ple(void)
 
  static inline int vm_need_virtualize_apic_accesses(struct kvm *kvm)
  {
 - return flexpriority_enabled 
 - (cpu_has_vmx_virtualize_apic_accesses()) 
 - (irqchip_in_kernel(kvm));
 + return flexpriority_enabled  irqchip_in_kernel(kvm);
  }
 
  static inline int cpu_has_vmx_vpid(void)
 
--
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