From: Roman Kagan Subject: Re: [PATCH v2] x86/hyper-v: Mark TLFS structures packed Date: Mon, 3 Dec 2018 07:15:25 +0000 Message-ID: <20181203071520.GA17278@rkaganb.sw.ru> References: <20181130125422.21494-1-vkuznets@redhat.com> <87k1krh588.fsf@vitty.brq.redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-2" Content-Transfer-Encoding: quoted-printable Cc: Nadav Amit , kvm list , Paolo Bonzini , =?iso-8859-2?Q?Radim_Kr=E8m=E1=F8?= , LKML , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , "x86@kernel.org" , "Michael Kelley (EOSG)" , Thomas Gleixner To: Vitaly Kuznetsov Return-path: In-Reply-To: <87k1krh588.fsf@vitty.brq.redhat.com> Content-Language: en-US Content-ID: Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org On Mon, Dec 03, 2018 at 12:35:35AM +0100, Vitaly Kuznetsov wrote: > Nadav Amit writes: >=20 > [skip] >=20 > > > > Having said that, something else is sort of strange in the TLFS definit= ions, > > I think (I really know little about this whole protocol). Look at the > > following definitions from hyperv-tlfs.h: > > > >> struct hv_vpset { > >> u64 format; > >> u64 valid_bank_mask; > >> u64 bank_contents[]; > >> }; > >>=20 > >> struct hv_tlb_flush_ex { > >> u64 address_space; > >> u64 flags; > >> struct hv_vpset hv_vp_set; > >> u64 gva_list[]; > >> }; > > > > It seems you have two flexible array members at the end of hv_tlb_flush= _ex. > > This causes bank_contents[x] and gva_list[x] to overlap. So unless they= have > > the same meaning, this asks for trouble IMHO. > > >=20 > This is weird but intentional :-) We're just following Hyper-V spec > here. >=20 > E.g. HvFlushVirtualAddressListEx hypercall has the following input ABI: >=20 > [Fixed len head][[Fixed len VP set spec]Var len VP set][Var len addr List= ] >=20 > "Fixed len VP set spec" defines the true length of "Var len VP set" and > "Address List" starts right after that. The length of the whole > structure is also known. >=20 > So bank_contents[] and gva_list[] do overlap (and have different > meaning). We take special precautions when forming the structure > (e.g. fill_gva_list() takes 'offset'). This basically means that the argument of this hypercall can't be represented by a C struct. gva_list just can't be used. So I'd rather remove it from the struct (but leave a comment to that end perhaps), and construct the message in place (as is done now anyway). Roman.