Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1173259rbb; Mon, 26 Feb 2024 00:34:13 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXodz5bZEvI1buTBQjljW8K0w9eWshWqBn+XRRo3IZ8ZyVd6TISKnkuKJ7FBYBA/1IRsLNxEtw5HGsw9Lp62MEMFBzMAp3ydJr2Zv6tEA== X-Google-Smtp-Source: AGHT+IHG1JoFKoKxwLcm/zxOVk6i7M+rwu4QF1EEEBf0BEGtTWMm6oH3cGM4NL0nmogeaLkx1Gx6 X-Received: by 2002:a05:6a20:94c3:b0:1a0:ee90:7790 with SMTP id ht3-20020a056a2094c300b001a0ee907790mr7862473pzb.48.1708936452840; Mon, 26 Feb 2024 00:34:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708936452; cv=pass; d=google.com; s=arc-20160816; b=wgI0WL2TCXp7ZFv46W990q8gExoRNOWCN516YDQKQ7QABb3JWaDyrUDd2+ZCo6DgZs /Kdh8E3bGgIFiJgzopyYx+I91Z5hoATyLLopkNIUdqsk20k++7Z5jaJxnZ4eXXm6HyIN VmYly0IfUprGqK/lBUKaSlJc+b04fQonr0oWIOBSZ9XC+E/fXX6yXTG4Iz4irhrLX21I lGrBK7EOg5vBkTMQg/VpIdqQ8L2A96izcSfFb/gPps9r8tfU5QyhAQSPPc8MMLpzJrdm XmR+GiL+DSSHp7akrSgEAS/Tkp68U1E3TSGVzQC/yHr3PWFOXIJ1jPMA90h+kI3MaK1a ay5Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=b7osJdmkfbXL5UuOR9afmuq+A+BEQYR1wQNui0HjG1o=; fh=1gGDAeF21c6AITri72SbLgKrk/wFaPJiWExhgpdJOYA=; b=YnceQGSCXfBdSnWdGSzq0Tt0UgEfNIV8A11itNGen40EDhRRxamBwtWwuauZsLHx5b rCuO7Z2Si0upUcwxSUBG6e7aOOfaHzdutZLuq6Ni3YUjQ12PtBs5+rCqIMTcR787xx2d RqEfmsoM9OUje0HhqXtrnebHz4JIcKK8MHDAS/S2mqtyeITAbcRE1FcIMm8LnSB0odW/ NxLoC1Vc9qlnLtluDvJfnE+4rtV+2OQoFeWUROxQKBBPs2zK2m1qINLfoyAljR4dxLsF sSHGi9LD28DTdE3DvMLvqcDxEmCVR+VvXPDAo6ut869Te12mzCm6OqWonRS6Iv989lDZ OpsA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bMOlfcli; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-80779-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80779-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id b11-20020a170902d50b00b001dc91aa56fesi2344844plg.537.2024.02.26.00.34.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 00:34:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80779-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bMOlfcli; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-80779-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80779-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 8AA55281357 for ; Mon, 26 Feb 2024 08:34:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A921354BE2; Mon, 26 Feb 2024 08:27:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="bMOlfcli" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D8E452F86; Mon, 26 Feb 2024 08:27:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708936071; cv=none; b=R6Aa9mkw1JpWzjiUe2uXibZkGAZPmyve59edPLs7j4I6G5YtZpK3Ek+xN2suoonvQsmS90JoZXcAjuPETJr2qnGCEYopEzkQoyr1JWvIdjUbuDthDAHkYXt4hDyaxQz4DmYm+IPMiLUr9n9w0skKA8nj2F9Fj7L6I9kuPMmgCGY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708936071; c=relaxed/simple; bh=gBqTh0BqhczjXbWb42Bx3PUV8vhAtv81RcTY6rA0AfQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Lcw8/OpnX710CDmEjSFFsHdxh5RbdrZqdMxmgjjGf43kXpqjME2oRa9QzM7f5Z0EMYKc//QbjybRu5oW6HeA4U7hG2eqUDJ8AKmOv9P1SSO6S5XB4iB1LL2ZrUUvmHtxCnnLfxAPQZ7M8a7xOje6lkfvVJtfYUHC33oFoyGOpUs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=bMOlfcli; arc=none smtp.client-ip=192.198.163.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708936069; x=1740472069; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gBqTh0BqhczjXbWb42Bx3PUV8vhAtv81RcTY6rA0AfQ=; b=bMOlfcliAAiavUwFuqQ/8EYVSX9Bw85QWmgmZtz2Y0YLLhWdHzxLE4Ty bVSo+sXPebCbjIRlH8Xc+Qcz6bocvFRS2HQwJXGSxMCNVH0WUYCiJ3REL 0c8BeK/TlmcAnCb6YeWARBEcuV1MFk8uLPBWQkhLqI/TDz1VQ8d1QyQFp XQ1SirVMLA3O5gs7Wg42zdOv02vTTwJDRtSMZ9H9APN3Yx9kECtnMXEFc 1FAr7OpZ4iHNZY3x78/ErLUX3ASOQU9sFWSRlm6rdsoZvorA+R35TDJvz OWhfgSWBaYKJtAZiDBSXPiv/LVlED8zvlVWDhoukWNWCe1f11UqDjLMNh w==; X-IronPort-AV: E=McAfee;i="6600,9927,10995"; a="28631502" X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="28631502" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 00:27:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="6474353" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 00:27:44 -0800 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 , Kai Huang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com, Chao Gao Subject: [PATCH v19 018/130] KVM: x86/mmu: Assume guest MMIOs are shared Date: Mon, 26 Feb 2024 00:25:20 -0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Chao Gao TODO: Drop this patch once the common patch is merged. When memory slot isn't found for kvm page fault, handle it as MMIO. The guest of TDX_VM, SNP_VM, or SW_PROTECTED_VM don't necessarily convert the virtual MMIO range to shared before accessing it. When the guest tries to access the virtual device's MMIO without any private/shared conversion, An NPT fault or EPT violation is raised first to find private-shared mismatch. Don't raise KVM_EXIT_MEMORY_FAULT, fall back to KVM_PFN_NOLSLOT. Signed-off-by: Chao Gao Signed-off-by: Isaku Yamahata --- v19: - Added slot check before kvm_faultin_private_pfn() - updated comment - rewrite the commit message --- arch/x86/kvm/mmu/mmu.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index ca0c91f14063..c45252ed2ffd 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -4342,6 +4342,7 @@ static int kvm_faultin_pfn_private(struct kvm_vcpu *vcpu, static int __kvm_faultin_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) { struct kvm_memory_slot *slot = fault->slot; + bool force_mmio; bool async; /* @@ -4371,12 +4372,21 @@ 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 for SNP and TDX. Don't require explicit GPA + * conversion for MMIO because MMIO is assigned at the boot time. Fall + * to !is_private case to get pfn = KVM_PFN_NOSLOT. + */ + force_mmio = !slot && + vcpu->kvm->arch.vm_type != KVM_X86_DEFAULT_VM && + vcpu->kvm->arch.vm_type != KVM_X86_SW_PROTECTED_VM; + if (!force_mmio && + fault->is_private != kvm_mem_is_private(vcpu->kvm, fault->gfn)) { kvm_mmu_prepare_memory_fault_exit(vcpu, fault); return -EFAULT; } - if (fault->is_private) + if (!force_mmio && fault->is_private) return kvm_faultin_pfn_private(vcpu, fault); async = false; -- 2.25.1