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] [thread-next>] [day] [month] [year] [list]
Message-ID: <CABgGipVKwpyAwYL1yQrkt_fJb94eMZTU_xrvgmnrzVsud+-1XA@mail.gmail.com>
Date: Thu, 21 Dec 2023 15:54:38 +0800
From: Andy Chiu <andy.chiu@...ive.com>
To: "Wang, Xiao W" <xiao.w.wang@...el.com>
Cc: Song Shuai <songshuaishuai@...ylab.org>, 
	"paul.walmsley@...ive.com" <paul.walmsley@...ive.com>, "palmer@...belt.com" <palmer@...belt.com>, 
	"aou@...s.berkeley.edu" <aou@...s.berkeley.edu>, "greentime.hu@...ive.com" <greentime.hu@...ive.com>, 
	"conor.dooley@...rochip.com" <conor.dooley@...rochip.com>, "guoren@...nel.org" <guoren@...nel.org>, 
	"bjorn@...osinc.com" <bjorn@...osinc.com>, "heiko@...ech.de" <heiko@...ech.de>, 
	"ruinland.tsai@...ive.com" <ruinland.tsai@...ive.com>, 
	"linux-riscv@...ts.infradead.org" <linux-riscv@...ts.infradead.org>, 
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] riscv: vector: Check SR_SD before saving vstate

On Thu, Dec 21, 2023 at 3:37 PM Wang, Xiao W <xiao.w.wang@...el.com> wrote:
>
>
>
> > -----Original Message-----
> > From: Song Shuai <songshuaishuai@...ylab.org>
> > Sent: Thursday, December 21, 2023 3:05 PM
> > To: paul.walmsley@...ive.com; palmer@...belt.com;
> > aou@...s.berkeley.edu; andy.chiu@...ive.com; greentime.hu@...ive.com;
> > conor.dooley@...rochip.com; guoren@...nel.org;
> > songshuaishuai@...ylab.org; bjorn@...osinc.com; Wang, Xiao W
> > <xiao.w.wang@...el.com>; heiko@...ech.de; ruinland.tsai@...ive.com
> > Cc: linux-riscv@...ts.infradead.org; linux-kernel@...r.kernel.org
> > Subject: [PATCH] riscv: vector: Check SR_SD before saving vstate
> >
> > The SD bit summarizes the dirty states of FS, VS, or XS fields,
> > providing a "fast check" before saving fstate or vstate.
> >
> > Let __switch_to_vector() check SD bit as __switch_to_fpu() does.
>
> It looks a duplication of status check since the __switch_to_*() internally will check the ext specific status bit.
> Can we just remove SR_SD check for the fpu() case?

Hi, I came to the same question when adding the Vector context switch.
I think the better solution is to skip saving both fpu and vector if
the SD is clear. However, this may make code less maintainable because
fpu and vector code are scattered and we must mix code together by
doing that. Also, we will have to duplicate has_fpu and has_vector
check because of the branch dependency

e.g.

if (likely((regs->status & SR_SD))) {
    if (has_fpu())
        fstate_save()
    if (has_vector())
        vstate_save()
}

if (has_fpu()) <--- duplicated check (nop)
    fstate_restore()
if (has_vector()) <--- same
    vstate_restore()

So, it really is "Is it worth to trade extra nop with SR_SD that
potentially skip one SR_*S check"

Besides, with user space libraries start embracing Vector, I don't
expect SR_SD would be in "cleared" state very often. Though I haven't
done any real-world experiment yet.

>
> BRs,
> Xiao
>
> >
> > Fixes: 3a2df6323def ("riscv: Add task switch support for vector")
> > Signed-off-by: Song Shuai <songshuaishuai@...ylab.org>
> > ---
> >  arch/riscv/include/asm/vector.h | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/arch/riscv/include/asm/vector.h b/arch/riscv/include/asm/vector.h
> > index 87aaef656257..d30fa56f67c6 100644
> > --- a/arch/riscv/include/asm/vector.h
> > +++ b/arch/riscv/include/asm/vector.h
> > @@ -190,7 +190,8 @@ static inline void __switch_to_vector(struct
> > task_struct *prev,
> >       struct pt_regs *regs;
> >
> >       regs = task_pt_regs(prev);
> > -     riscv_v_vstate_save(prev, regs);
> > +     if (unlikely(regs->status & SR_SD))
> > +             riscv_v_vstate_save(prev, regs);
> >       riscv_v_vstate_restore(next, task_pt_regs(next));
> >  }
> >
> > --
> > 2.20.1
>

Thanks,
Andy

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ