Re: [EXTERNAL] Re: How to add a -W flag in local Makefile

From: Konstantin Belousov <kostikbel_at_gmail.com>
Date: Sat, 20 Apr 2024 19:34:30 UTC
On Sat, Apr 20, 2024 at 12:01:13PM +0000, Souradeep Chakrabarti wrote:
> 
> 
> >-----Original Message-----
> >From: owner-freebsd-hackers@FreeBSD.org <owner-freebsd-
> >hackers@FreeBSD.org> On Behalf Of Dag-Erling Smørgrav
> >Sent: Friday, April 19, 2024 4:28 PM
> >To: Wei Hu <weh@microsoft.com>
> >Cc: Konstantin Belousov <kostikbel@gmail.com>; Warner Losh
> ><imp@bsdimp.com>; freebsd-hackers@FreeBSD.org
> >Subject: [EXTERNAL] Re: How to add a -W flag in local Makefile
> >
> >Wei Hu <weh@microsoft.com> writes:
> >> The same code already exists in Linux and Windows. Linux also added a
> >> compiling flag to suppress similar warnings.
> >
> >That's not an excuse.  The code makes no sense.
> The way it works is as follows:
> 
> > > +struct hv_vpset {
> > > +       uint64_t format;
> > > +       uint64_t valid_bank_mask;
> > > +       uint64_t bank_contents[];
> > > +} __packed;
> > > +
> > > +struct hv_tlb_flush_ex {
> > > +       uint64_t address_space;
> > > +       uint64_t flags;
> > > +       struct hv_vpset hv_vp_set;
> > > +       uint64_t gva_list[];
> > > +} __packed;
> 
> Here an pointer is allocated for struct hv_tlb_flush_ex with 4K size.
> Now gva_list and bank_contents are sharing same space.
> But gva_list gets filled up from the particular index position, where bank_contents
> is ending. 
> Total space used by bank_contents[0-(n-1)] + gva_list[n-end_of_the heap allocated] = 4K - (sizeof(format) + sizeof(valid_bank_mask) + sizeof(address_space) + sizeof(flags) )
> During a call to hypervisor we need to send in this message format for proper deserialization and there we also specify the bank_contents index that is n-1.

Indexing bank_contents is not a valid C code.  You do not need the second
flexible member, instead you should calculate the location manually and
access it there.  Your hack relies on the internal layouts of the structures,
but should instead use proper address arithmetic.

> Thanks 
> Souradeep
> >
> >> Anyway, the purpose of this email is to understand how to add such
> >> flags in local Makefiles and make it effective for global buildkernel.
> >> Adding such flags in local Makefiles already proves to be working when
> >> only building under local directory.
> >
> >You would have to add it to every line in sys/conf/files* that references a C file
> >which includes this header.
> >
> >DES
> >--
> >Dag-Erling Smørgrav - des@FreeBSD.org
>