Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp263084rwb; Tue, 25 Jul 2023 15:38:14 -0700 (PDT) X-Google-Smtp-Source: APBJJlGv/A8i+NH+0FRJ3ee4MjofqITbbUuTHstuFp2ov8qFcq5WD3RP2HqpkLP7AOxJx8o3+/yH X-Received: by 2002:a05:6a21:3806:b0:134:a478:6061 with SMTP id yi6-20020a056a21380600b00134a4786061mr262726pzb.26.1690324693701; Tue, 25 Jul 2023 15:38:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690324693; cv=none; d=google.com; s=arc-20160816; b=I+5w6AzYEa6pv108gJ3x/xZsJoUoONq6vmCvFtiiDDTnZuANKawvtgZddTGDsJ5lwr uLaEXo8f3vwHi4u/DGduWFBX+ILFUEzR3ehxxKa0KTUoHEqXsD4Pz5QAaekbdCDTCN9r uvRInpj3Y1lGq2bxlEqYZZ78Lndf+FSJrokCDkec274fx/UGR9CLronAzU2TDJknFPtH SP/be4FRswfvedi9rIZyUu+DZ5ppWX8su3HJ3OjgaKnRaRvkfFbJI+FRe0xR+rWyAAmY cyVSyXI4UraUuDaQdc0XQLB4SOKsweYjB2pn1gJqHrzLDxVfzplgBGd4k0huXM59bTGY lHYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Vu2BVQwmCPmtGqoCHa9JwaeCmhnUTD5vSt6Z3iRAVlc=; fh=UJL44GK56ky0KzxbJVmu+rqKQ/SR3Yf5PGdMxNbAuG4=; b=i29whrh1dsLec26vD5c4f/1BJzUS479++jzZfsOBYbzg/UsvS/vWlRlXfeANPc+gjy cUQmUnXkBu9CXct5foFwm9h9ziVBGY1j1k6RXyfcql74ureNCsTmrU+x0Z8CGz+Hyts5 83V+N1+Tzsd0QxBg5AeEwAg03y4x8QN+AWPi5joUikxxmPCW8PJBQxaMbCwJgQ1ZIsM6 hw5BdCUqP/GAp8yjRczpMEl8SCeJFW+5z4LPC4R23FGPdV9U/PaKhanAsM62qwGsTkU6 NSPpqciAwVW4y3cH7o2D9Tk+fzs8bZIq8yaXGdl0BKBYrrR3X+kTEMGldCu3IYsc1z8A kk8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=OESg9OJo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h10-20020a056a001a4a00b0068050054196si12372797pfv.299.2023.07.25.15.38.01; Tue, 25 Jul 2023 15:38:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=OESg9OJo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232365AbjGYWT5 (ORCPT + 99 others); Tue, 25 Jul 2023 18:19:57 -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: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; } - if (fault->is_private != 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 != kvm_mem_is_private(vcpu->kvm, fault->gfn)) { if (vcpu->kvm->arch.vm_type == KVM_X86_SW_PROTECTED_VM) return RET_PF_RETRY; else -- 2.25.1