From: Roman Kagan Subject: Re: [PATCH] x86/hyper-v: define structures from TLFS as packed Date: Fri, 30 Nov 2018 14:26:07 +0000 Message-ID: <20181130142603.GB2358@rkaganb.sw.ru> References: <20181130121511.12331-1-vkuznets@redhat.com> <20181130131122.GA2358@rkaganb.sw.ru> <87va4ewug9.fsf@vitty.brq.redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-2" Content-Transfer-Encoding: quoted-printable Cc: "kvm@vger.kernel.org" , Paolo Bonzini , =?iso-8859-2?Q?Radim_Kr=E8m=E1=F8?= , "linux-kernel@vger.kernel.org" , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , "x86@kernel.org" , "Michael Kelley (EOSG)" , Nadav Amit , Thomas Gleixner To: Vitaly Kuznetsov Return-path: In-Reply-To: <87va4ewug9.fsf@vitty.brq.redhat.com> Content-Language: en-US Content-ID: <6FEEFBF866AF5747881DCC47ABA50CE2@eurprd08.prod.outlook.com> Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org On Fri, Nov 30, 2018 at 02:44:54PM +0100, Vitaly Kuznetsov wrote: > Roman Kagan writes: >=20 > > On Fri, Nov 30, 2018 at 01:15:11PM +0100, Vitaly Kuznetsov wrote: > >> Without 'packed' compiler is free to add optimization paddings and re-= order > >> structure fields for randomization/optimization. And structures from > >> hyperv-tlfs.h are used for hypervisor-guest communication, we need to > >> ultimately forbid such practices. > > > > Note that __packed also reduces the structure alignment to 1, which is > > not necessarily what you want. > > > > E.g. some of these structures are passed by pointer to the hypercall, > > which requires its arguments to be 8byte-aligned. >=20 > Hm, >=20 > I thought we always take precautions for Hyper-V hypercall arguments, in > particular >=20 > PV IPI/TLB flush use pre-allocated hyperv_pcpu_input_arg, > hv_post_message() uses pre-allocated message page, other call sites use > fast hypercalls where we use registers. Looks so indeed. > I also checked this patch before sending out, WS2016 guest boots without > issues. Any particular places you're worried about? It's Linux guests on Hyper-V that need to be checked. > > I'm also not sure > > that passing unaligned argument to [rw]msr is ok, need to > > double-check. >=20 > My understanding is that rdmsr/wrmsr instuctions are registers-only. Indeed. > We can, of course, just add __aligned(8) to some structures but I'd like > to find the reason first. I guess you're right, in the current code the relevant structures are made sufficiently aligned by other means. False alarm, sorry. Roman.