From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 249DBC433F5 for ; Mon, 2 May 2022 11:13:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377497AbiEBLQn (ORCPT ); Mon, 2 May 2022 07:16:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232682AbiEBLQd (ORCPT ); Mon, 2 May 2022 07:16:33 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A515A5FFA; Mon, 2 May 2022 04:13:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1651489984; x=1683025984; h=message-id:subject:from:to:cc:date:in-reply-to: references:mime-version:content-transfer-encoding; bh=EC3+2wnZVexq801X0N/krg0yVyBm5vCd1GA2Nj1Q5VM=; b=GVsHRlOzTJFpDWz/SJPREFD7ZRgp23pauv5Z6MVovMHu+wyVg0VWw6TC NPijD11Ep8FjPA4DQAneO9GdIG2tmgqDn0zpK8hAjv/rMJGLnEZKZreZs S2xj64BGNgwFC7tOUKSDpy2slne/botKQfxLc8Ur6Tm66RlvJFqZpNxj4 ufY8248YXWk73X8SiuxgmDEhwgPFapHTlX8t1LP7FaTi7z49XscEt76Xq kwLFDGscjnI5iyTXr58XZQwCZZA/31ESNkNZqLsbTMlrYrvsJMLyh2r0J ZJgHbkglPSclEb12oaNbSFZP1pgb2Y44Qmx7b1kXEkso7vXjHtSJ9aRxT w==; X-IronPort-AV: E=McAfee;i="6400,9594,10334"; a="267339596" X-IronPort-AV: E=Sophos;i="5.91,190,1647327600"; d="scan'208";a="267339596" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 May 2022 04:12:57 -0700 X-IronPort-AV: E=Sophos;i="5.91,190,1647327600"; d="scan'208";a="535801181" Received: from bwu50-mobl.amr.corp.intel.com (HELO khuang2-desk.gar.corp.intel.com) ([10.254.2.219]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 May 2022 04:12:54 -0700 Message-ID: <2d10ff16d3f5fa03886721c24f2db10d79759ed2.camel@intel.com> Subject: Re: [PATCH] KVM: x86/mmu: Do not create SPTEs for GFNs that exceed host.MAXPHYADDR From: Kai Huang To: Sean Christopherson , Paolo Bonzini Cc: Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Maxim Levitsky , Ben Gardon , David Matlack Date: Mon, 02 May 2022 23:12:52 +1200 In-Reply-To: <20220428233416.2446833-1-seanjc@google.com> References: <20220428233416.2446833-1-seanjc@google.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.4 (3.42.4-1.fc35) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2022-04-28 at 23:34 +0000, Sean Christopherson wrote: > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > index 904f0faff218..c10ae25135e3 100644 > --- a/arch/x86/kvm/mmu/mmu.c > +++ b/arch/x86/kvm/mmu/mmu.c > @@ -3010,9 +3010,15 @@ static bool handle_abnormal_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fa >   /* >   * If MMIO caching is disabled, emulate immediately without >   * touching the shadow page tables as attempting to install an > - * MMIO SPTE will just be an expensive nop. > + * MMIO SPTE will just be an expensive nop.  Do not cache MMIO > + * whose gfn is greater than host.MAXPHYADDR, any guest that > + * generates such gfns is either malicious or in the weeds. > + * Note, it's possible to observe a gfn > host.MAXPHYADDR if > + * and only if host.MAXPHYADDR is inaccurate with respect to > + * hardware behavior, e.g. if KVM itself is running as a VM. >   */ > - if (unlikely(!enable_mmio_caching)) { > + if (unlikely(!enable_mmio_caching) || > +     unlikely(fault->gfn > kvm_mmu_max_gfn_host())) { Shouldn't we check fault->gfn against cpuid_maxphyaddr(vcpu) instead of kvm_mmu_max_gfn_host() here? >   *ret_val = RET_PF_EMULATE; >   return true; >   } -- Thanks, -Kai