Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1467759rbb; Mon, 26 Feb 2024 10:06:40 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVJkxzKEeRscmG781lfzudEsfIVaiG8g1PQwqDU0bgXsCTe/L5yrU66xs4imbPYGr6YeYnW1v9CA1jNqkZyBNz67dJEaLnRCbuLGR9BAQ== X-Google-Smtp-Source: AGHT+IHY/EkK8vaywWPDMna8e4sKxajOxt64ULo9W/OF2Y39LXyhyXMbV46L3T6e3KcqI9CXcl3Y X-Received: by 2002:a05:6808:6489:b0:3c1:9a60:9248 with SMTP id fh9-20020a056808648900b003c19a609248mr6355323oib.14.1708970800338; Mon, 26 Feb 2024 10:06:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708970800; cv=pass; d=google.com; s=arc-20160816; b=et2paPeYoV3UW0bSBL5IjsOACBu0toBOD7eKgWB1wkU5t9xdvC+JLe1rtfxw2lt6I0 G51PlPt0/3wWR8UPR0CjGEQFPPcjmjyBQkQQkOBtnhnxo3J1FHvR170fIWr0snXzkJYa nusfQmgYTP+oSMCb/vyJmYWdtPlaXRkp7P/W51M3LSnsL/AacBTW1lQ7iEXceukKj7gp 9L0SYZA7p90q7HMrX4FeDSclWT4VZ14OqlpANcurpiTqHQG5FJTiQ0z6hX/n3IBkZM+L oTJoZqgofS3L1oR+YHURH0swPN2aYUYGP5/hWo07kR2ofpdYgPOZt6l6EO9I/ZNXlnlz 2JrQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=MRx/x0erWmAEIx530rYkid6JXvgQX0R/b5dlxjOGl9U=; fh=3EPC+byySiBHS9FFi2J5eecz/AOj4wcceg54MQfY2ZQ=; b=fAN0Q+MMO+oXuol//fk03OvM3ksBHEotCU2MNOqbSsUgXYvCjOhIGlu5uY26EElv2I 2u7k+pvNWMF21exDRCFare/uKWH49GSk45imVoikNxQP5Lvio/UBh0tXQ3huD3BVrrnt lnBtT7OoXvSHCp2rUkGu7ObSjUNnb72zzaNMejagPy7ZCB7Dk+JyNMPXolhSJtApHsJ6 TwZyEfA5yVTLUNE50Jb9iqkG+SdsHYPlYJUYeYFX0fCBo4I9Di20tpa/7nvc0ZFXkMfR WyGRmM4RRxXXq9vQgumAR0JVNSP3eluuSS8dGkwyRSFhXZWB+88K/3NoKa5IfWEi9qJ7 eTMg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KiDWBdZX; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-82120-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82120-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id p27-20020a056102125b00b0046d289b694asi605993vsg.156.2024.02.26.10.06.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 10:06:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-82120-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KiDWBdZX; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-82120-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82120-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 101431C2BAA9 for ; Mon, 26 Feb 2024 18:06:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0BB7312EBF6; Mon, 26 Feb 2024 18:06:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="KiDWBdZX" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 2709612DD87; Mon, 26 Feb 2024 18:06:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708970791; cv=none; b=Q/gCo3ADTUv1GSJiYbztCcQ/s+Dy7Lwti2xoErni0YNIIQicqVhVlkdPb2opfl5OwJpkTQ9NCpJuZr07PyhpSx9Wn178JjqCFNpV6clzUFWYBq8/p+gyfVdVQg4Nky34DQ9UZHbsBTmUtgtY4/MMFT1FLr6DvfrBbrwsGfnaoPE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708970791; c=relaxed/simple; bh=+qKKWlBc2Z+IVbGPagJK6EFTeqoeC1JGKYkeOHNof0w=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=f4oyINpTQ4sjIELdypNVuF38yBF8n5vlGMaLQJGam7i50dTw0/0SdtDkAqyXAEE1oYPn1wWvjbJoJBXt64mipGtXgJacRpG5tVTQQaC48NpC8ovVSu/QDSJNqrKHI9mFIvJvviSunwWRDvZ+LCfFdar7DMJLK8mPlBdfHLQUFDo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=KiDWBdZX; arc=none smtp.client-ip=192.198.163.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.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=1708970789; x=1740506789; h=date:from:to:cc:subject:message-id:references: mime-version:content-transfer-encoding:in-reply-to; bh=+qKKWlBc2Z+IVbGPagJK6EFTeqoeC1JGKYkeOHNof0w=; b=KiDWBdZXPqTE/Y4lmu3/uJ6B1hf1y4N9S5tdBbpuKOHLjicnIIe10K95 RO3QsMtGkMxsiL1TLTEanGer52LlP4WObOCAoZxWVVHcLKtcTanUtVle/ XWB/HHBXHl6nP7wqYlW35KHat0c2J+h7X2T8GKEakYiAgVv00C8XSJeRU cmCmQJ8JTs2HR87lh5Q7b4o4UQ1sJXxEUbB/asXxC+AbkQH/G71gFW4LG mI1csxQa9d4cJj4H5XRYvZFDrEgD2i03BC/OZ7svj9WfzPUBcVCl0WaPx UrwqPqKYeStAH6gxx2geGciIp9w1U5pCjYo6ypDWy1DRTtJt7GAV47mC1 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="13981897" X-IronPort-AV: E=Sophos;i="6.06,186,1705392000"; d="scan'208";a="13981897" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 10:06:28 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,186,1705392000"; d="scan'208";a="11532248" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by orviesa005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 10:06:27 -0800 Date: Mon, 26 Feb 2024 10:06:26 -0800 From: Isaku Yamahata To: Paolo Bonzini Cc: isaku.yamahata@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, isaku.yamahata@gmail.com, erdemaktas@google.com, Sean Christopherson , Sagi Shahar , Kai Huang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com, Chao Gao , isaku.yamahata@linux.intel.com Subject: Re: [PATCH v18 044/121] KVM: x86/mmu: Assume guest MMIOs are shared Message-ID: <20240226180626.GE177224@ls.amr.corp.intel.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Mon, Feb 12, 2024 at 11:29:51AM +0100, Paolo Bonzini wrote: > On Tue, Jan 23, 2024 at 12:55 AM wrote: > > > > 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. > > I'm not sure how the patch below deals with host MMIOs? It falls back to shared case to hit KVM_PFN_NOSLOT. It will be handled as MMIO. Anyway I found it breaks SW_PROTECTED case. So I came up with the following. I think we'd like to handle as - SW_PROTECTED => KVM_EXIT_MEMORY_FAULT - SNP, TDX => MMIO. - 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); -- Isaku Yamahata