From: Eduardo Habkost Subject: Re: [Qemu-devel] [PATCH] machine: Add kvm-type property Date: Mon, 2 Jun 2014 11:44:37 -0300 Message-ID: <20140602144437.GE17594@otherpad.lan.raisama.net> References: <1401482467-31550-1-git-send-email-ehabkost@redhat.com> <1401611464.2875.99.camel@localhost.localdomain> <1401699419.2875.117.camel@localhost.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: kvm@vger.kernel.org, Alexander Graf , qemu-devel@nongnu.org, "Aneesh Kumar K.V" , Paolo Bonzini , Andreas =?iso-8859-1?Q?F=E4rber?= To: marcel.a@redhat.com Return-path: Received: from mx1.redhat.com ([209.132.183.28]:61632 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754776AbaFBOoo (ORCPT ); Mon, 2 Jun 2014 10:44:44 -0400 Content-Disposition: inline In-Reply-To: <1401699419.2875.117.camel@localhost.localdomain> Sender: kvm-owner@vger.kernel.org List-ID: On Mon, Jun 02, 2014 at 11:56:59AM +0300, Marcel Apfelbaum wrote: > On Sun, 2014-06-01 at 11:31 +0300, Marcel Apfelbaum wrote: > > On Fri, 2014-05-30 at 17:41 -0300, Eduardo Habkost wrote: > > > The kvm-type machine option was left out when MachineState was > > > introduced, preventing the kvm-type option from being used. Add t= he > > > missing property. > > Very interesting how did I miss that. > > Thanks! > > Marcel > >=20 > > >=20 > > > Signed-off-by: Eduardo Habkost > > > Cc: Andreas F=E4rber > > > Cc: Aneesh Kumar K.V > > > Cc: Alexander Graf > > > Cc: Marcel Apfelbaum > > > --- > > > Tested in a x86 machine only. Help would be welcome to test it on= a PPC > > > machine using -machine spapr and KVM. > > >=20 > > > Before this patch: > > >=20 > > > $ qemu-system-x86_64 -machine pc,kvm-type=3Dhv,accel=3Dkvm > > > qemu-system-x86_64: Property '.kvm-type' not found > > >=20 > > > (This means the option won't work even for sPAPR machines.) > > >=20 > > > After applying this patch: > > >=20 > > > $ qemu-system-x86_64 -machine pc,kvm-type=3Dhv,accel=3Dkvm > > > Invalid argument kvm-type=3Dhv > > >=20 > > > (This means the x86 KVM init code is seeing (and rejecting) the o= ption, > > > and the sPAPR code can use it.) > > >=20 > > > Note that qemu-system-x86_64 will segfault with the above command= -line > > > unless an additional fix (submitted today) is applied (kvm: Ensur= e > > > negative return value on kvm_init() error handling path). > > > --- > > > hw/core/machine.c | 17 +++++++++++++++++ > > > include/hw/boards.h | 1 + > > > 2 files changed, 18 insertions(+) > > >=20 > > > diff --git a/hw/core/machine.c b/hw/core/machine.c > > > index cbba679..ed47b3a 100644 > > > --- a/hw/core/machine.c > > > +++ b/hw/core/machine.c > > > @@ -235,6 +235,21 @@ static void machine_set_firmware(Object *obj= , const char *value, Error **errp) > > > ms->firmware =3D g_strdup(value); > > > } > > > =20 > > > +static char *machine_get_kvm_type(Object *obj, Error **errp) > > > +{ > > > + MachineState *ms =3D MACHINE(obj); > > > + > > > + return g_strdup(ms->kvm_type); > > > +} > > > + > > > +static void machine_set_kvm_type(Object *obj, const char *value,= Error **errp) > > > +{ > > > + MachineState *ms =3D MACHINE(obj); > > > + > > > + g_free(ms->kvm_type); > Hi, >=20 > Here also, like in my other replies, I think it should be the caller > responsibility to free the string. A set method should not touch > its parameter. We are not freeing the parameter, we are freeing ms->kvm_type, which wa= s allocated previously by the setter method itself (using g_strdup()). Th= e caller doesn't even have access to ms->kvm_type directly. The fact that ms->kvm_type is a strdup()ed string is an internal implementation detail. We even have setter methods that do _not_ use strdup(), and just copy the data to a static buffer (see target-i386/cpu.c). --=20 Eduardo