lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAAhV-H6ugTh8XmgruyWYoL53hYGtj3035xM=Y_+AMrnK-caM5w@mail.gmail.com>
Date:   Sat, 26 Aug 2023 23:16:05 +0800
From:   Huacai Chen <chenhuacai@...nel.org>
To:     WANG Xuerui <kernel@...0n.name>
Cc:     Huacai Chen <chenhuacai@...ngson.cn>,
        Arnd Bergmann <arnd@...db.de>, loongarch@...ts.linux.dev,
        linux-arch@...r.kernel.org, Xuefeng Li <lixuefeng@...ngson.cn>,
        Guo Ren <guoren@...nel.org>,
        Jiaxun Yang <jiaxun.yang@...goat.com>,
        linux-kernel@...r.kernel.org, loongson-kernel@...ts.loongnix.cn
Subject: Re: [PATCH] LoongArch: Ensure FP/SIMD registers in the core dump file
 is up to date

On Sat, Aug 26, 2023 at 3:52 PM WANG Xuerui <kernel@...0n.name> wrote:
>
> On 8/25/23 19:42, Huacai Chen wrote:
> > This is a port of commit 379eb01c21795edb4c ("riscv: Ensure the value
> > of FP registers in the core dump file is up to date").
> >
> > The values of FP/SIMD registers in the core dump file come from the
> > thread.fpu. However, kernel saves the FP/SIMD registers only before
> > scheduling out the process. If no process switch happens during the
> > exception handling, kernel will not have a chance to save the latest
> > values of FP/SIMD registers. So it may cause their values in the core
> > dump file incorrect. To solve this problem, force fpr_get()/simd_get()
> > to save the FP/SIMD registers into the thread.fpu if the target task
> > equals the current task.
> >
> > Signed-off-by: Huacai Chen <chenhuacai@...ngson.cn>
> > ---
> >   arch/loongarch/include/asm/fpu.h | 22 ++++++++++++++++++----
> >   arch/loongarch/kernel/ptrace.c   |  4 ++++
> >   2 files changed, 22 insertions(+), 4 deletions(-)
> >
> > diff --git a/arch/loongarch/include/asm/fpu.h b/arch/loongarch/include/asm/fpu.h
> > index b541f6248837..08a45e9fd15c 100644
> > --- a/arch/loongarch/include/asm/fpu.h
> > +++ b/arch/loongarch/include/asm/fpu.h
> > @@ -173,16 +173,30 @@ static inline void restore_fp(struct task_struct *tsk)
> >               _restore_fp(&tsk->thread.fpu);
> >   }
> >
> > -static inline union fpureg *get_fpu_regs(struct task_struct *tsk)
> > +static inline void get_fpu_regs(struct task_struct *tsk)
> Removing the return value from the signature means the function is no
> longer a getter, so maybe the name should get changed as well? Like
> "save_fpu_regs"?
OK, that makes sense and has been done in V2.

> >   {
> > +     unsigned int euen;
> > +
> >       if (tsk == current) {
> >               preempt_disable();
> > -             if (is_fpu_owner())
> > +
> > +             euen = csr_read32(LOONGARCH_CSR_EUEN);
> > +
> > +#ifdef CONFIG_CPU_HAS_LASX
> > +             if (euen & CSR_EUEN_LASXEN)
> > +                     _save_lasx(&current->thread.fpu);
> > +             else
> > +#endif
> > +#ifdef CONFIG_CPU_HAS_LSX
> > +             if (euen & CSR_EUEN_LSXEN)
> > +                     _save_lsx(&current->thread.fpu);
> > +             else
> > +#endif
> > +             if (euen & CSR_EUEN_FPEN)
> >                       _save_fp(&current->thread.fpu);
> > +
> >               preempt_enable();
> >       }
> > -
> > -     return tsk->thread.fpu.fpr;
> >   }
> >
> >   static inline int is_simd_owner(void)
> > diff --git a/arch/loongarch/kernel/ptrace.c b/arch/loongarch/kernel/ptrace.c
> > index 2bb5ec55ae1e..209e3d29e0b2 100644
> > --- a/arch/loongarch/kernel/ptrace.c
> > +++ b/arch/loongarch/kernel/ptrace.c
> > @@ -148,6 +148,8 @@ static int fpr_get(struct task_struct *target,
> >   {
> >       int r;
> >
> > +     get_fpu_regs(target);
> > +
> >       if (sizeof(target->thread.fpu.fpr[0]) == sizeof(elf_fpreg_t))
> >               r = gfpr_get(target, &to);
> >       else
> > @@ -279,6 +281,8 @@ static int simd_get(struct task_struct *target,
> >   {
> >       const unsigned int wr_size = NUM_FPU_REGS * regset->size;
> >
> > +     get_fpu_regs(target);
> > +
> >       if (!tsk_used_math(target)) {
> >               /* The task hasn't used FP or LSX, fill with 0xff */
> >               copy_pad_fprs(target, regset, &to, 0);
>
> Otherwise this should be fine. (I don't know why that helper is
> previously unused though...)
This helper was derived from MIPS but the call sites are missing, so fix it now.

Huacai
>
> --
> WANG "xen0n" Xuerui
>
> Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/
>
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ