Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp4421381ybp; Mon, 7 Oct 2019 08:13:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqxyvKv9i7qwtCXyqU3JeTeeCYQnKEghAv6QlcWOzpvRoW6KGcz2NBxhswj2UXs6ypry0l+n X-Received: by 2002:a17:907:4242:: with SMTP id np2mr24349909ejb.102.1570461234871; Mon, 07 Oct 2019 08:13:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570461234; cv=none; d=google.com; s=arc-20160816; b=rMBM8ySeja/3AfRNYP8v7UlcUyx71CCRcNDiP24LvuvelDpiDQhEUnr+kCncvWjnuY WvgRugUT7YTvZvLO2eNzE/zqjLjQzANYx1swZcPlaVjrZ76akOffmvF/WUG7wXwq7CHm K/C1mOyEhV+dG+kYQLLyQTIdxiqYMNBANQHFNZNDvsfs0HWnBy+5EUnQl1Kozj669bIP zLMsSv0yhd5A0xFDvReITejMR+gi0L5Uv9qf+Af/A8cDzyMxyhX+yhtMiEGkiAd2mAo0 GlRC4A60sycG7iMQQuLsUiZgB4EpKvsavIdydOcaAzCgv/8YvxDJKqFL61cfFdVvFrc9 DLMw== 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=syonsVKU5mZGlhKXtxxG9+e2/fLiVHgLMz52kFBSJ4E=; b=zHb81jgQC3AAg0jQwOwA0nReLZ7h7Un+9XR2VjbarTKqj+38re6XTkckt4WFe99jd5 fQZWasrSVGVsjH/FNvAE5hORVFhZcf5E/F9wsr3zkgY/gkToTUgkY5n8wxrB+pBov3Yt PQdfG1IgJjpcoL5ZOvZwisGTAah51FY8v9vB0M8PYp80ZJ+1pkwH77DB8A/BI8e7sONe Bd8dwGV0XxTzRvdyObczQ45Wnd8dSj9QT31qhQWBqu4QkHEs7rTAlMYTzVEgm5CMP0BF Xjvce05szgyUZvgyEdH1adomojvNVVe4c32BxGccuqrlqLoNE3/C/6zGI3swipl0ua0c BQLw== 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 y11si7100063eje.365.2019.10.07.08.13.30; Mon, 07 Oct 2019 08:13:54 -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 S1728588AbfJGPNZ (ORCPT + 99 others); Mon, 7 Oct 2019 11:13:25 -0400 Received: from mga07.intel.com ([134.134.136.100]:57231 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728332AbfJGPNZ (ORCPT ); Mon, 7 Oct 2019 11:13:25 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Oct 2019 08:13:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.67,268,1566889200"; d="scan'208";a="196314615" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.41]) by orsmga003.jf.intel.com with ESMTP; 07 Oct 2019 08:13:23 -0700 Date: Mon, 7 Oct 2019 08:13:23 -0700 From: Sean Christopherson To: Ingo Molnar Cc: Dave Hansen , 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: <20191007151323.GB18016@linux.intel.com> References: <20191004134501.30651-1-changbin.du@gmail.com> <8b2c8164-d7ae-20b7-ff48-32eab9ec9760@intel.com> <20191004153115.GA19503@linux.intel.com> <20191007143255.GA59713@gmail.com> <20191007144423.GA25181@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191007144423.GA25181@gmail.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 Mon, Oct 07, 2019 at 04:44:23PM +0200, Ingo Molnar wrote: > > * Ingo Molnar wrote: > > > > 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"); > > > > Instead of trying to guess the reason of the #GPF (which guess might be > > wrong), please just state it as the reason if we are sure that the cause > > is a non-canonical address - and provide a best-guess if it's not but > > clearly signal that it's a guess. > > > > I.e. if I understood all the cases correctly we'd have three types of > > messages generated: > > > > !error_code: > > "General protection fault in user access, due to non-canonical address." A non-canonical #GP always has an error code of '0', but the reverse isn't technically true. And 32-bit mode obviously can't generate a non-canonical address. But practically speaking, since _ASM_EXTABLE_UA() should only be used for reg<->mem instructions, the only way to get a #GP on a usercopy instruction would be to corrupt the code itself or have a bad segment loaded in 32-bit mode. So qualifying the non-canonical message on '64-bit && !error_code' is techncally more precise/correct, but likely meaningless in practice. > > error_code && !is_canonical_addr(fault_addr): > > "General protection fault in user access. Non-canonical address?" > > > > error_code && is_canonical_addr(fault_addr): > > "General protection fault in user access. Segmentation bug?" > > Now that I've read the rest of the thread, since fault_addr is always 0 > we can ignore most of this I suspect ...