On Wed, Dec 21, 2022 at 04:22:33PM +0800, Robert Hoo wrote: > On Wed, 2022-12-21 at 10:55 +0800, Yuan Yao wrote: > > > +#ifdef CONFIG_X86_64 > > > +/* untag addr for guest, according to vCPU CR3 and CR4 settings */ > > > +static inline u64 kvm_untagged_addr(u64 addr, struct kvm_vcpu > > > *vcpu) > > > +{ > > > + if (addr >> 63 == 0) { > > > + /* User pointers */ > > > + if (kvm_read_cr3(vcpu) & X86_CR3_LAM_U57) > > > + addr = get_canonical(addr, 57); > > > + else if (kvm_read_cr3(vcpu) & X86_CR3_LAM_U48) { > > > + /* > > > + * If guest enabled 5-level paging and LAM_U48, > > > + * bit 47 should be 0, bit 48:56 contains meta > > > data > > > + * although bit 47:56 are valid 5-level address > > > + * bits. > > > + * If LAM_U48 and 4-level paging, bit47 is 0. > > > + */ > > > + WARN_ON(addr & _BITUL(47)); > > > > IIUC, LAM_47 userspace canonical checking rule requests "bit 63 == > > bit 47 == 0" > > before sign-extened the address. > > > > if so looks it's guest's fault to not follow the LAM canonical > > checking rule, > > what's the behavior of such violation on bare metal, #GP ? > > Spec (ISE 10.2) doesn't mention a #GP for this case. IIUC, those > overlap bits are zeroed. I mean the behavior of violation of "bit 63 == bit 47 == 0" rule, yes no words in ISE 10.2/3 describe the behavior of such violation case, but do you know more details of this or had some experiments on hardware/SIMIC ? > Current native Kernel LAM only enables LAM_U57. > > > The behavior > > shuld be same for guest instead of WARN_ON() on host, host does > > nothing wrong. > > > Agree that host did nothing wrong. So remove WARN_ON(), use a pr_warn() > instead? I here meant to warn that such case happens. I personally think that's not necessary if no hardware behavior is defined for such violation, KVM doesn't need to warn such guest violation on host, like KVM already done for many other cases (e.g #GP is injected for restricted canonical violation but not WARN_ON) > >