Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1112349ybf; Fri, 28 Feb 2020 14:27:04 -0800 (PST) X-Google-Smtp-Source: APXvYqwz1+I2ShiBI+7og05EpW2yhuPD9nGn+s9ifbmjIV8104UYvIcoHJiRHpB2rBsowhW2+vEj X-Received: by 2002:a9d:34c:: with SMTP id 70mr4765367otv.174.1582928824243; Fri, 28 Feb 2020 14:27:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582928824; cv=none; d=google.com; s=arc-20160816; b=TcfgM6BXRI8DOf7rtETUEGlr+2ZZrG+Ibi/WQK97ZIex5Yqr1xGFhLQB3TvNc0aBQD 6dJKcmELzr0hg7PpVrimgFpTmud+b5cgDlTBNgQdRPELGuyNjEaclh6OAOnyXvffLFPK 6QQJlGVktuztHTJlpOH9wGMEkP2VJHMEjFB7y5FL+daKkannTMURb5OsHTZkEFFweBnc Y0VJd/CYIaY7NyacrDP08Lw+wjEKcCSiGMrO3U+KEaaAyhEs3YhTqENhm0veJfIaA6qU Tdjl3MPMak4YPi2JDed1QiOgD9gbJniUr74yT0E060TaVjw3xCj+VdBoSGhLL/RhSSSx Qq4g== 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=gs+k6j3nEqBdHpmaTnihKrB4AYAXmnlFRelE87FaiyA=; b=n/PW5Jc1xdJTWbNtIywtR++iOMAsiANRgMa6Ron+L5rpk6gv792Dvsifl9bdSCN3oz wp8KYo0r/Rm9e1MMU+68gjXRm0iDjN9385PP4crBs/YwRr+gEbQ5/zNz6Pj/v3czfkr3 emf+ZcoGBm3FQLtHcT339CgzKJYK4yQqfZVKg974n7Pqy5UsHTYW3mlxYs36eCCc5n/v gD6zDBT9joz3OCTkDupU7s76bMy4S9QzfcCvIaEGwqXysRZqMReOilnOAN5gd5Q2pHHe sPgaJNnVchGqGw/qTPh/s3bDcVOSoy5vd/ko6uB4+8XedPY0mZcg+2zMDO8uxArFDZnf zi0A== 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 b3si2213289otf.141.2020.02.28.14.26.51; Fri, 28 Feb 2020 14:27:04 -0800 (PST) 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 S1726589AbgB1W0r (ORCPT + 99 others); Fri, 28 Feb 2020 17:26:47 -0500 Received: from mga04.intel.com ([192.55.52.120]:64794 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726151AbgB1W0r (ORCPT ); Fri, 28 Feb 2020 17:26:47 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Feb 2020 14:26:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,497,1574150400"; d="scan'208";a="232392124" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.202]) by orsmga008.jf.intel.com with ESMTP; 28 Feb 2020 14:26:46 -0800 Date: Fri, 28 Feb 2020 14:26:46 -0800 From: Sean Christopherson To: Paolo Bonzini Cc: Mohammed Gamal , kvm@vger.kernel.org, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 5/5] KVM: x86: mmu: Add guest physical address check in translate_gpa() Message-ID: <20200228222646.GI2329@linux.intel.com> References: <20200227172306.21426-1-mgamal@redhat.com> <20200227172306.21426-6-mgamal@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Thu, Feb 27, 2020 at 07:00:33PM +0100, Paolo Bonzini wrote: > On 27/02/20 18:23, Mohammed Gamal wrote: > > In case of running a guest with 4-level page tables on a 5-level page > > table host, it might happen that a guest might have a physical address > > with reserved bits set, but the host won't see that and trap it. > > > > Hence, we need to check page faults' physical addresses against the guest's > > maximum physical memory and if it's exceeded, we need to add > > the PFERR_RSVD_MASK bits to the PF's error code. > > You can just set it to PFERR_RSVD_MASK | PFERR_PRESENT_MASK (no need to > use an "|") and return UNMAPPED_GBA. But I would have thought that this > is not needed and the > > if (unlikely(FNAME(is_rsvd_bits_set)(mmu, pte, walker->level))) { > errcode = PFERR_RSVD_MASK | PFERR_PRESENT_MASK; > goto error; > } > > code would have catch the reserved bits. That would be my assumption as well. The only manual check should be in the top level EPT and NPT handlers. > > Also make sure the error code isn't overwritten by the page table walker. > > Returning UNMAPPED_GVA would remove that as well. > > I'm not sure this patch is enough however. For a usermode access with > "!pte.u pte.40" for example you should be getting: > > - a #PF with PRESENT|USER error code on a machine with physical address > width >=41; in this case you don't get an EPT violation or misconfig. > > - a #PF with RSVD error code on a machine with physical address with <41. > > You can enable verbose mode in access.c to see if this case is being generated, > and if so debug it. > > The solution for this would be to trap page faults and do a page table > walk (with vcpu->arch.walk_mmu->gva_to_gpa) to find the correct error > code. > > Paolo >