Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1029697ybp; Fri, 4 Oct 2019 08:33:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqzKiRI+a3WFd8VIMqueOgnUijLdA6Obb1vbPhk8V0OV8mLCqkgoV3YV9X7gCDYvhLf+sTQ7 X-Received: by 2002:a50:a7c4:: with SMTP id i62mr15645381edc.92.1570203196962; Fri, 04 Oct 2019 08:33:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570203196; cv=none; d=google.com; s=arc-20160816; b=cT1UANwtywd2UbsuAFaVekTlqS3qUK7Z5OTjCFP4qTS34giMhrrNINsDi6WatNcUzB jVyt7rKNmyAy7qlg82ql2K/ipR4ozh3paNdn7DlajabvcHBZSY0uaWXHWqfwciQzdDwX HeFeIDYtkMRsPQIGJarGm3VNSvXrLx29J1BItK+spnoNY5R+qLwFwNHQv3v5xMlH3gm8 zuGOHm0AiS8b2IVXCtLFZqHZZOOmog3tEzriYMh8rxX1mIJN1qlL8P8xTkNptqPgA7SJ sUaiPMmHTz7uHd98jF+nwFL5GpHDeSU9WlQya9t8TOAmyw2xpD79RYvaVzHdeU62evPO BrfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=3FVduO9ngkGlkgnltlajQcSXXQJhfmwiJAutosvQ4Gc=; b=0ZwgVrGVHwY22my1VtgzcM7WrWU+UIYmr9/vY1IoZqdwxZN/AFo8B+ibjXWHjoEhG0 K23Bur9RaYSVRFi/gBnDn8qI2z9m11ekwbi3gH8GMMfCHlicFDKroPNkxmzL3sJo2Cqa 1x+HGdXCxAvJyaJeJphWwx0nniNqpNqk6f1kVrAa/nHLdGk8eKUmUpeFYdBL/O0a7TZP YXsS1GeQ7IDJc+1QPUk9zI4vIQFLLphNBEpQGiGC2dd9JX85IKvPCsofP2UZ8omTAMvw dACp3dzNsced7JgQ+kLfMwq6R18Cd/QiTqpZ+oeYAgRf2weXN+YnRTdkzf4gd/YlSCzL xx/A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l6si3784530edc.67.2019.10.04.08.32.52; Fri, 04 Oct 2019 08:33:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389856AbfJDPbS (ORCPT + 99 others); Fri, 4 Oct 2019 11:31:18 -0400 Received: from mga06.intel.com ([134.134.136.31]:61274 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389710AbfJDPbR (ORCPT ); Fri, 4 Oct 2019 11:31:17 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Oct 2019 08:31:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.67,256,1566889200"; d="scan'208";a="393593551" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.41]) by fmsmga006.fm.intel.com with ESMTP; 04 Oct 2019 08:31:16 -0700 Date: Fri, 4 Oct 2019 08:31:15 -0700 From: Sean Christopherson To: Dave Hansen Cc: Changbin Du , Dave Hansen , Andy Lutomirski , x86@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] x86/mm: determine whether the fault address is canonical Message-ID: <20191004153115.GA19503@linux.intel.com> References: <20191004134501.30651-1-changbin.du@gmail.com> <8b2c8164-d7ae-20b7-ff48-32eab9ec9760@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8b2c8164-d7ae-20b7-ff48-32eab9ec9760@intel.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 04, 2019 at 07:39:08AM -0700, Dave Hansen wrote: > 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. All the other reasons would require a fairly egregious kernel bug, hence the speculation that the #GP is due to a non-canonical address. Something like the following would be more precise, though highly unlikely to ever be exercised, e.g. KVM had a fatal bug related to injecting a non-zero error code that went unnoticed for years. WARN_ONCE(trapnr == X86_TRAP_GP, "General protection fault in user access. %s?\n", (IS_ENABLED(CONFIG_X86_64) && !error_code) ? "Non-canonical address" : "Segmentation bug");