[lkml]   [2019]   [Oct]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: [PATCH] x86/mm: determine whether the fault address is canonical
On 10/4/19 6:45 AM, Changbin Du wrote:
> +static inline bool is_canonical_addr(u64 addr)
> +{
> +#ifdef CONFIG_X86_64
> + int shift = 64 - boot_cpu_data.x86_phys_bits;

I think you mean to check the virtual bits member, not "phys_bits".

BTW, I also prefer the IS_ENABLED(CONFIG_) checks to explicit #ifdefs.
Would one of those work in this case?

As for the error message:

> {
> - WARN_ONCE(trapnr == X86_TRAP_GP, "General protection fault in user access. Non-canonical address?");
> + WARN_ONCE(trapnr == X86_TRAP_GP, "General protection fault at %s address in user access.",
> + is_canonical_addr(fault_addr) ? "canonical" : "non-canonical");

I've always read that as "the GP might have been caused by a
non-canonical access". The main nit I'd have with the change is that I
don't think all #GP's during user access functions which are given a
non-canonical address *necessarily* caused the #GP.

There are a billion ways you can get a #GP and I bet canonical
violations aren't the only way you can get one in a user copy function.

 \ /
  Last update: 2019-10-04 16:40    [W:0.101 / U:0.256 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site