Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2688100rwd; Sun, 28 May 2023 22:14:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Vi0dX8GLc7fHpAOqIl5hEO9/M5uQ5SZRZZEG93oh/u1SqIkIQ7ayEeBrHFuEBrc/cEafZ X-Received: by 2002:a17:903:11c3:b0:1ac:8717:d436 with SMTP id q3-20020a17090311c300b001ac8717d436mr12749759plh.60.1685337286915; Sun, 28 May 2023 22:14:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685337286; cv=none; d=google.com; s=arc-20160816; b=EDIaVoJRcpeXLv2DtnUxNpUxg6fCfsXlY7d9zxKQCsI5SAqSuUY6g6RabcA+CH083O 1Dj+L/A9Ww/ceuZXp2qIkkiHM6GKhMF2Cp7RpUYKZEWn+hPPCiioXn+P7O9/cwTIjs8L VkmIJzJ1x5xFHoTbUx51p0Zmjmnrjl3r9+QSgEz5+8PeJuqXhUvNN23cSGjMDKhsubhr RVC09VHSOk2aAMmuFHZ8HCssWH5Td4Jawt3PHL7WKZE7K/GN1peFP4N7NzUgHnW/YytS yeDUyPh8DCwUeXxmsuDxuEnCHgb4UJ+1SdScix1cA/taW513nlsSDU+R12eCE5zvRHK0 J9Eg== 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=q0TqeFQDXQJqJxRez1m39rpDfeppPmjzFjZvUK1Kam8=; b=Yg925xgs/FSAlTJ6jmo2WGrExGunG7DE5I6qqk4PSbMSY58ioNVJyjjUKGU4zyRbdJ OliKsy9Jz2Aftd2YjTqe18US9llsxjrS2Cna+eqniklx0h4kfQbWT1A8nKYPhH5VfO9E M03J3nur+bW7AvDK8r5de6rD03Zd8NzYS8LvC1/xMNp9sWUcHXAwYKkGeiZ4H3gEMcDt QeUKoKDTamNtS51ziuB1THGrztQwE3Lhlx7iIWCwveB8xLKuibSe6SGPNQfoe5ynyFKx O5eqfcP2gbqTFXrq+QKJnSUANVuoT1td/dBxrSPcN3U7DbK5Zzfp0xLrtst/yVNMv85r 0yjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VPIZ807M; 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 g9-20020a170902868900b001ab29e16b3asi8413659plo.286.2023.05.28.22.14.35; Sun, 28 May 2023 22:14:46 -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=VPIZ807M; 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 S231631AbjE2EZP (ORCPT + 99 others); Mon, 29 May 2023 00:25:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231616AbjE2EYg (ORCPT ); Mon, 29 May 2023 00:24:36 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BB371737; Sun, 28 May 2023 21:22:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685334154; x=1716870154; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QSJUl/UEPqdnzZy+hiBrlByUnOkcTkL1Gi8Agd/4FZY=; b=VPIZ807MeA2MvMgSQZHjtXeE1sgDXm600fL275gbkNG1zY1l5W+Ze2t/ 4vmQIHyf1zDVX/VvPnhNRdsxv6WXD4xqsZbBhBdc9DKtDM+fD5er0cC6i J9M6YYwBOBYMWipchwk1tVnQvG+6Nss2oltkyfyZNwQwQML2OkEHSg421 0wnyFuQbURGhlmOvj/CR/gl4FYjZs8kqJWtk7LPeotp87QHZCUEA1EBH1 7MF8YljGPlNcSob21GJr7ATEzcIoKkxtZA3/atAVTw4lTdevwqIY6oM8i nrNmJTGS461YQWC8XZzeShYmK+cDj9UEdKd6SjMclTH4WQZf/g4Lettm0 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10724"; a="334965944" X-IronPort-AV: E=Sophos;i="6.00,200,1681196400"; d="scan'208";a="334965944" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2023 21:21:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10724"; a="775784256" X-IronPort-AV: E=Sophos;i="6.00,200,1681196400"; d="scan'208";a="775784256" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2023 21:21:12 -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, Chao Gao Subject: [PATCH v14 039/113] KVM: x86/mmu: Assume guest MMIOs are shared Date: Sun, 28 May 2023 21:19:21 -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.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 --- 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 544df394b085..a7bf0cecabc2 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -4395,7 +4395,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)) return kvm_do_memory_fault_exit(vcpu, fault); if (fault->is_private) -- 2.25.1