On Wed, 2022-01-12 at 06:44 +0000, Peng Fan wrote:
> > Subject: Re: [PATCH] hypervisor: arm/arm64: fix build error
> > 
> > On 12.01.22 07:56, Peng Fan (OSS) wrote:
> > > From: Peng Fan <[email protected]>
> > > 
> > > With gcc 5.15, met the following error
> > 
> > Which gcc version (surely not "5.15") from which distro? I've tried
> > with
> > manually adding -Werror=array-bounds to the build and using gcc-
> > 10.3.1, but
> > this message didn't trigger.
> 
> I use NXP linux 5.15-honister, gcc version 11.2.0.
> 
> > 
> > > 
> > > hypervisor/arch/arm64/control.c:33:9:
> > > error: ‘memset’ offset [0, 255] is out of the bounds [0, 0]
> > [-Werror=array-bounds]
> > >     33 |         memset(&this_cpu_data()->guest_regs, 0,
> > > sizeof(union
> > registers));
> > >        |
> > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > ~~
> > > cc1: all warnings being treated as errors
> > > 
> > > Fix this by use a volatile pointer to keep GCC from determining
> > > its
> > > value
> > > 
> > 
> > Do we something wrong here, or did the kernel, e.g., had to work
> > around such
> > issues as well? The workaround looks a bit odd.
> 
> It is gcc try to determining the array value, but I am not sure why
> it not.
> This patch is to let gcc not determine the array value to avoid
> build break.

This sounds like [1], another gcc 11.x issue with kernel / Jailhouse
sources. I had the same problem for x86 some time ago. Not sure if
there are kernel workarounds for that.

The bug was marked as duplicate of [2], which is the kernel issue.

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100834
[2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99578

> 
> Regards,
> Peng.
> 
> > 
> > Jan
> > 
> > > Signed-off-by: Peng Fan <[email protected]>
> > > ---
> > >   hypervisor/arch/arm/control.c   | 3 ++-
> > >   hypervisor/arch/arm64/control.c | 3 ++-
> > >   2 files changed, 4 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/hypervisor/arch/arm/control.c
> > > b/hypervisor/arch/arm/control.c index 46125e1a..c9c93982 100644
> > > --- a/hypervisor/arch/arm/control.c
> > > +++ b/hypervisor/arch/arm/control.c
> > > @@ -23,9 +23,10 @@
> > >   void arm_cpu_reset(unsigned long pc, bool aarch32)
> > >   {
> > >           u32 sctlr;
> > > + union registers * volatile guest_regs =
> > > +&this_cpu_data()->guest_regs;
> > > 
> > >           /* Wipe all banked and usr regs */
> > > - memset(&this_cpu_data()->guest_regs, 0, sizeof(union
> > > registers));
> > > + memset(guest_regs, 0, sizeof(union registers));
> > > 
> > >           arm_write_banked_reg(SP_usr, 0);
> > >           arm_write_banked_reg(SP_svc, 0);
> > > diff --git a/hypervisor/arch/arm64/control.c
> > > b/hypervisor/arch/arm64/control.c index 5b41b393..2c33c5f7 100644
> > > --- a/hypervisor/arch/arm64/control.c
> > > +++ b/hypervisor/arch/arm64/control.c
> > > @@ -22,6 +22,7 @@ void arm_cpu_reset(unsigned long pc, bool
> > > aarch32)
> > >   {
> > >           u64 hcr_el2;
> > >           u64 fpexc32_el2;
> > > + union registers * volatile guest_regs =
> > > +&this_cpu_data()->guest_regs;
> > > 
> > >           /* put the cpu in a reset state */
> > >           /* AARCH64_TODO: handle big endian support */ @@ -30,7
> > > +31,7
> > @@
> > > void arm_cpu_reset(unsigned long pc, bool aarch32)
> > >           arm_write_sysreg(PMCR_EL0, 0);
> > > 
> > >           /* wipe any other state to avoid leaking information
> > > accross cells */
> > > - memset(&this_cpu_data()->guest_regs, 0, sizeof(union
> > > registers));
> > > + memset(guest_regs, 0, sizeof(union registers));
> > > 
> > >           /* AARCH64_TODO: wipe floating point registers */
> > > 
> > 
> > --
> > Siemens AG, Technology
> > Competence Center Embedded Linux
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jailhouse-dev/115f149b84fcce90236cde99c1e3f2f11ec86307.camel%40siemens.com.

Reply via email to