From nobody Sun Feb 8 23:05:00 2026 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 41E7EC05052 for ; Tue, 25 Jul 2023 22:20:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232468AbjGYWT6 (ORCPT ); Tue, 25 Jul 2023 18:19:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232236AbjGYWS3 (ORCPT ); Tue, 25 Jul 2023 18:18:29 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B13426A2; Tue, 25 Jul 2023 15:16:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690323375; x=1721859375; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BFQ/sesQVcdvoe6xpw9/CVcgY2UBxZorT/LZeWCLqRI=; b=OESg9OJoYnKOotcBAmCjlJxS4CAZ+zmQlUXIS9+ewBvSKd9xSPMUYCfW /loH1eeiinfTCGKctMceznIlOi6GL2qX9NBOrJkYJHyxFqEl4CBxiVw4k LXuLvWR1iMgNrQ5cXuPVn9Oe8TOQOiVTD4BQJvNFelqXJeYSWS/LS6Y6d vu/hU47gp9z6bp9p1PdtcdV7ZsHdNaK/tUSBeMCwQyi7vvCdAvylIM0nE Ov/KZU9u4Wg0DmP+o7ub5GiT/BbQqQwvPrd/MG1VrTB1NZ2XqXotMtGB9 aAEcPHyxm7oUZEaVHM+BkZHMOutQNrq4SKObW44XIV81ATfxRltqqO4la A==; X-IronPort-AV: E=McAfee;i="6600,9927,10782"; a="357863250" X-IronPort-AV: E=Sophos;i="6.01,231,1684825200"; d="scan'208";a="357863250" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jul 2023 15:15:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10782"; a="1056938916" X-IronPort-AV: E=Sophos;i="6.01,231,1684825200"; d="scan'208";a="1056938916" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jul 2023 15:15:36 -0700 From: isaku.yamahata@intel.com To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar , David Matlack , Kai Huang , Zhi Wang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com, Chao Gao Subject: [PATCH v15 040/115] KVM: x86/mmu: Assume guest MMIOs are shared Date: Tue, 25 Jul 2023 15:13:51 -0700 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Chao Gao Guest TD doesn't necessarily invoke MAP_GPA to convert the virtual MMIO range to shared before accessing it. When TD tries to access the virtual device's MMIO as shared, an EPT violation is raised first. kvm_mem_is_private() checks whether the GFN is shared or private. If MAP_GPA is not called for the GPA, KVM thinks the GPA is private and refuses shared access, and doesn't set up shared EPT entry. The guest can't make progress. Instead of requiring the guest to invoke MAP_GPA for regions of virtual MMIOs assume regions of virtual MMIOs are shared in KVM as well (i.e., GPAs either have no kvm_memory_slot or are backed by host MMIOs). So that guests can access those MMIO regions. Signed-off-by: Chao Gao Signed-off-by: Isaku Yamahata --- arch/x86/kvm/mmu/mmu.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 9bf8d05937c5..ffe292b3a44d 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -4418,7 +4418,12 @@ static int __kvm_faultin_pfn(struct kvm_vcpu *vcpu, = struct kvm_page_fault *fault return RET_PF_EMULATE; } =20 - if (fault->is_private !=3D kvm_mem_is_private(vcpu->kvm, fault->gfn)) { + /* + * !fault->slot means MMIO. Don't require explicit GPA conversion for + * MMIO because MMIO is assigned at the boot time. + */ + if (fault->slot && + fault->is_private !=3D kvm_mem_is_private(vcpu->kvm, fault->gfn)) { if (vcpu->kvm->arch.vm_type =3D=3D KVM_X86_SW_PROTECTED_VM) return RET_PF_RETRY; else --=20 2.25.1