Received: from eggs.gnu.org ([2001:4830:134:3::10]:36108) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZyO7P-0002r5-7e for qemu-devel@nongnu.org; Mon, 16 Nov 2015 13:03:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZyO7J-0000TJ-2F for qemu-devel@nongnu.org; Mon, 16 Nov 2015 13:03:07 -0500 Received: from mail-pa0-x234.google.com ([2607:f8b0:400e:c03::234]:35548) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZyO7I-0000T6-Pn for qemu-devel@nongnu.org; Mon, 16 Nov 2015 13:03:00 -0500 Received: by pacej9 with SMTP id ej9so75269605pac.2 for ; Mon, 16 Nov 2015 10:02:59 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2104\)) From: Matt Gingell In-Reply-To: <56467C15.9010800@redhat.com> Date: Mon, 16 Nov 2015 10:03:04 -0800 Content-Transfer-Encoding: quoted-printable Message-Id: <4C46D219-3232-4392-9AB0-30552242580E@google.com> References: <0172715B-B1BD-40E8-96A2-3C320928447D@google.com> <56467C15.9010800@redhat.com> Subject: Re: [Qemu-devel] [PATCH 1/2] add support for KVM_CAP_SPLIT_IRQCHIP List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: qemu-devel@nongnu.org, Markus Armbruster Hi Eric, Thanks for your comments. I=E2=80=99m submitting a v2 based on your = feedback. Matt > On Nov 13, 2015, at 4:11 PM, Eric Blake wrote: >=20 > On 11/13/2015 04:25 PM, Matt Gingell wrote: >=20 > [meta-comment:] This patch was sent without an In-Reply-To header = tying > it back to the 0/2 cover letter, which means mailers render it as its > own thread. Git 'send-email' can do proper threading with the right > settings (although I'm not sure exactly what to suggest tweaking, if = the > defaults aren't already right). >=20 >> This patch adds the initial plumbing for split IRQ chip mode via >> KVM_CAP_SPLIT_IRQCHIP. In addition to option processing, a number of >> kvm_*_in_kernel macros are defined to help clarify which component is >> where. >>=20 >> Signed-off-by: Matt Gingell >> --- >=20 >> -static void machine_set_kernel_irqchip(Object *obj, bool value, = Error **errp) >> +static void machine_set_kernel_irqchip(Object *obj, Visitor *v, >> + void *opaque, const char = *name, >> + Error **errp) >> { >> - MachineState *ms =3D MACHINE(obj); >> - >> - ms->kernel_irqchip_allowed =3D value; >> - ms->kernel_irqchip_required =3D value; >> + OnOffSplit mode; >> + MachineState *ms =3D MACHINE(obj); >> + >> + visit_type_OnOffSplit(v, &mode, name, errp); >> + switch (mode) { >=20 > 'mode' starts life uninitialized, and the current contract of > visit_type_OnOffSplit (or any visit_type_Enum, for that matter) is = that > it is left unchanged except on success (see > qapi/qapi-visit-core.c:input_type_enum() for the implementation). > However, you are blindly calling switch without checking whether an > error was reported, which could lead to spurious code behavior = depending > on what was previously on the stack. >=20 > Arguably, we could fix the qapi generator for visit_type_Enum() to set > the parameter to the sentinel _MAX value on error, to make buggy code > like this less likely to do the wrong things on uninitialized input. = But > I don't know if that is a bug worth fixing during 2.5 hardfreeze (it's > more likely to expose other bugs, but why not let sleeping dogs lie > rather than risk regressions where things happened to work by chance). >=20 > So, your choices are to pre-initialize mode to a sane sentinel value, = or > else check for error before switching on mode (and remember that you > can't check errp directly, but would need a local err, since the = caller > may have passed in errp=3D=3DNULL). Or in code, either: >=20 > OnOffSplit mode =3D ON_OFF_SPLIT_MAX; > visit_type_OnOffSplit(v, &mode, name, errp); > switch (mode) { > case ON_OFF_SPLIT_MAX: > // flag invalid input; errp already contains potentially nice message >=20 > or: >=20 > OnOffSplit mode; > Error *err =3D NULL; > visit_type_OnOffSplit(v, &mode, name, &err); > if (err) { > // handle err, perhaps with error_propagate() > } else { > switch (mode) { > case ON_OFF_SPLIT_ON: > case ON_OFF_SPLIT_OFF: > case ON_OFF_SPLIT_SPLIT: > // handle > break; > default: > abort(); // unreachable > } >=20 >> + case ON_OFF_SPLIT_ON: >> + ms->kernel_irqchip_allowed =3D true; >> + ms->kernel_irqchip_required =3D true; >> + ms->kernel_irqchip_split =3D false; >> + break; >> + case ON_OFF_SPLIT_OFF: >> + ms->kernel_irqchip_allowed =3D false; >> + ms->kernel_irqchip_required =3D false; >> + ms->kernel_irqchip_split =3D false; >> + break; >> + case ON_OFF_SPLIT_SPLIT: >> + ms->kernel_irqchip_allowed =3D true; >> + ms->kernel_irqchip_required =3D true; >> + ms->kernel_irqchip_split =3D true; >> + break; >> + default: >> + error_report("Option 'kernel-irqchip' must be one of = on|off|split"); >> + exit(1); >=20 > Eww. Why are you calling exit() in a function that already returns = errp? > Shouldn't you instead just bubble the error up the stack? >=20 >=20 >> +++ b/qapi/common.json >> @@ -114,3 +114,19 @@ >> ## >> { 'enum': 'OnOffAuto', >> 'data': [ 'auto', 'on', 'off' ] } >> + >> +## >> +# @OnOffSplit >> +# >> +# An enumeration of three values: on, off, and split >> +# >> +# @on: Enabled >> +# >> +# @off: Disabled >> +# >> +# @split: Mixed >> +# >> +# Since: 2.6 >> +## >> +{ 'enum': 'OnOffSplit', >> + 'data': [ 'on', 'off', 'split' ] } >=20 > Use of qapi for the enum mapping looks sane. >=20 > --=20 > Eric Blake eblake redhat com +1-919-301-3266 > Libvirt virtualization library http://libvirt.org >=20