On Fri, 28 Jun 2024 16:53:20 +0200 Christian Borntraeger <borntraeger@xxxxxxxxxxxxx> wrote: > Am 27.06.24 um 11:57 schrieb Heiko Carstens: > > On Thu, Jun 27, 2024 at 11:05:20AM +0200, Christian Borntraeger wrote: > >> in rare cases, e.g. for injecting a machine check we do intercept all > >> load PSW instructions via ICTL_LPSW. With facility 193 a new variant > >> LPSWEY was added. KVM needs to handle that as well. > >> > >> Fixes: a3efa8429266 ("KVM: s390: gen_facilities: allow facilities 165, 193, 194 and 196") > >> Reported-by: Marc Hartmayer <mhartmay@xxxxxxxxxxxxx> > >> Signed-off-by: Christian Borntraeger <borntraeger@xxxxxxxxxxxxx> > >> --- > >> arch/s390/include/asm/kvm_host.h | 1 + > >> arch/s390/kvm/kvm-s390.c | 1 + > >> arch/s390/kvm/kvm-s390.h | 16 ++++++++++++++++ > >> arch/s390/kvm/priv.c | 32 ++++++++++++++++++++++++++++++++ > >> 4 files changed, 50 insertions(+) > > > > ... > > > >> +static inline u64 kvm_s390_get_base_disp_siy(struct kvm_vcpu *vcpu, u8 *ar) > >> +{ > >> + u32 base1 = vcpu->arch.sie_block->ipb >> 28; > >> + u32 disp1 = ((vcpu->arch.sie_block->ipb & 0x0fff0000) >> 16) + long disp1 = ... > >> + ((vcpu->arch.sie_block->ipb & 0xff00) << 4); > >> + > >> + /* The displacement is a 20bit _SIGNED_ value */ > >> + if (disp1 & 0x80000) > >> + disp1+=0xfff00000; disp1 = sign_extend64(disp1, 20); > >> + > >> + if (ar) > >> + *ar = base1; > >> + > >> + return (base1 ? vcpu->run->s.regs.gprs[base1] : 0) + (long)(int)disp1; + disp1; > >> +} > > > > You may want to use sign_extend32() or sign_extend64() instead of open-coding. > > Something like sign_extend64(disp1, 31) > I actually find that harder to read, but I am open for other opinions. I think what he meant is what I wrote above, but it doesn't matter too much. with or without the above improvements: Reviewed-by: Claudio Imbrenda <imbrenda@xxxxxxxxxxxxx>