Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2368938rdb; Mon, 12 Feb 2024 02:30:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IFFUL1ACUafUZDyUMdovfyxEeK6UX0b5Mjbaew7YLI9pDlcwwO1BUggpKbnzE7ynmCVs1Ab X-Received: by 2002:a05:6808:201a:b0:3c0:32a1:693e with SMTP id q26-20020a056808201a00b003c032a1693emr5939595oiw.42.1707733830904; Mon, 12 Feb 2024 02:30:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707733830; cv=pass; d=google.com; s=arc-20160816; b=Po5ab5AmaSTXkaKJwGuYoO7b/XWmOlohr1u/1YuIoSQ9GH126kbgPQEnXeVPX1FlHd 74HLI8mkplg46/hqnEwFQk/UpE7+Q87jkvuLTWKDaxJ4PCLemIPp4uz4P1P9pa/vPSRT zL83swZs19vAuzpjh5NpxyP1CdbcKf37vvG+NqGGz4Pr2yRvCfmnK2Btri783C5gCNLy qk7RqVfgPqNHAjwDso1vEDBuIwJqMVxeWZovFBoh19Jy6UOYp69mlmePiutW44uEiXXj J01nZh5I3ICl1GdAqi13c9KKEqGAqZWd7A43SX5wkKrQxq2jy2dXjQAXY/kEp/yKMcOh FwVA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=xbEOSaawXH7zOkm7lWBcOWhVGmzO+y0LgNswENFILP4=; fh=DwEWmYrrLjqjOT0oiSMzaiBzyjQb6QkxbJcx3zaoHV4=; b=CJdkLyWTXx7NXSpMwhpayL+2oVuRTB3mwvR9OX87ip9BJ2UPYiLlFrpo6i3e0Kl1Wa /OWGt1E/22W8wLuZvRN/CmEpYRbWTXr6gEiRYkQvgYSFxOVWiDEw4oUklkekeqR4J/LT j6Qb7mNxcw5jOzp/FOp+OiB5/xdvk57bmuVn8eJHcMq/u6YuFIU758wrdNtl181m4Jv5 gPHFv6+WdP5tf3hxnbd4kzT79Z+KtWZ6HMU8Xu9ujnwfRIRHMChtnQCq2YLGMEii7XAt Kd7n++qq/jXtlR21GapH03MVKHvdcD3QHdkhcofQ8P8OYaE4ofWwoyFGu3pnodHv20We TUbw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=eLUyuWQc; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-61311-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61311-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=2; AJvYcCXmKzdTXGqVfrjc4PCXqliiMRRk9QfuLM3ueIEKuyxdoFhPg0g7YbobS2IuzbXG4pxjAXUZ8eNerz0lU6p7WFYQ/AOv8XrN2xQSb9e0sg== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id g24-20020a05620a13d800b00783f3ba639asi5595538qkl.674.2024.02.12.02.30.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 02:30:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61311-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=@redhat.com header.s=mimecast20190719 header.b=eLUyuWQc; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-61311-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61311-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 825A01C223C0 for ; Mon, 12 Feb 2024 10:30:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D596418AED; Mon, 12 Feb 2024 10:30:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="eLUyuWQc" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 4EBC2182A3 for ; Mon, 12 Feb 2024 10:30:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707733809; cv=none; b=iE1KIosbdbFX6RZ3TXLfALSFf73bMZDMeufVdb8te01aBYYnzz5gZ2khgAZCwJ8IVEXBxCG7JN76fu6fFGQwH2S5l9iiroT426cQbtlV/Oig4B+Fdfwny6lbIKFnRjxRwIE5RgBwOhHKnIkKSoZ2GBeBHS+EpFTEI9lhqIgDRg4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707733809; c=relaxed/simple; bh=H7fKjnfkFZJqm1/uhc0nHamHeLBXPVOBRneRuCwvSDc=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=IwlEWD2Y3M2IFKoPgUIdcSZKJpEOPH3RzQOMG9DNlJ2xxlN5h2L0teY4mEcIUrOgkoLvTnkIL66XZSQ7knO+xv+pJyILUrmgittqxBbAGxclK12gJRH3DjXHXM58K3EcZRuuZ9/P9ikWXydUhJsAHh447COcsE0BZ5BvrxBgKqU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=eLUyuWQc; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707733806; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xbEOSaawXH7zOkm7lWBcOWhVGmzO+y0LgNswENFILP4=; b=eLUyuWQcKDrvatiE1PRSRNfPYe89XStwpDhiHzoW2EmwmkyowHXCaU6biNbtD8G2pBe0fe vT9U9WOse87BbQCwSMgTSoYJ6ALaobFchBVdt9hdPVvb2uK/pefDSrSHTek2VBs0G+mMRb 8HRqesBvzyCTlMcSZpFC+sHm3TcSfrY= Received: from mail-vs1-f72.google.com (mail-vs1-f72.google.com [209.85.217.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-464-vyDslhbbPgqyZIM_krQ6KA-1; Mon, 12 Feb 2024 05:30:04 -0500 X-MC-Unique: vyDslhbbPgqyZIM_krQ6KA-1 Received: by mail-vs1-f72.google.com with SMTP id ada2fe7eead31-46d639c4883so622997137.2 for ; Mon, 12 Feb 2024 02:30:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707733804; x=1708338604; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xbEOSaawXH7zOkm7lWBcOWhVGmzO+y0LgNswENFILP4=; b=qpfZPlkZ0t86zVr/CgOvbp5RzR6FsjdYPFr3hHu/8b6ImMqm2hTFL8kRYyC3euh5Mr Czbv4jsmeq8kjYGyiQr+w6c8NtauU+mWcnFh0M6Il6xIGGp0F4nfuTWryYTd1eQv+VXG JMi0GiX4oBTd2s9hv4Dbbb0IRKlTexWS5JCnJUc0voUZAejrX4K3VVjwUptiQdJ3FBKq VT1IH3ASm/5alBVoPaAsNOwPiFGsMY40/Ebtx7GFGn49EH3gh3ER6Nw0+e/ClgH6Z4Ez vf4yBt0Z6edVqzotfUD9G7Y59gzzCRSk/iVxSE3AKdrff06g7jCp1T56ZdYgEG70xSBd 99Qw== X-Gm-Message-State: AOJu0YzNlXXMETyFqG31VrPVPv7BNjSVjiFCrK1Qk5rB2roxPwhMk/e0 QcRpjaiNz+/ysFXYkub5hl/YgH0nT3hZ6D1qoFkxgP9J9FWL+p6jzj2crIzDXDxDm7Nonzxn2p9 YiFcCG5IKaelzMTy+tCUQI7jCXUZcQPPHedwXSxBKPWir006ACBHZ4FLuJFwIH8neEZvLzeYRsQ t1DihZDbsTkVCIYgNP2EFhQWnqm4XxX+XfjFhD X-Received: by 2002:a05:6102:83:b0:46d:246e:93d3 with SMTP id t3-20020a056102008300b0046d246e93d3mr3339610vsp.17.1707733804263; Mon, 12 Feb 2024 02:30:04 -0800 (PST) X-Received: by 2002:a05:6102:83:b0:46d:246e:93d3 with SMTP id t3-20020a056102008300b0046d246e93d3mr3339592vsp.17.1707733803936; Mon, 12 Feb 2024 02:30:03 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: In-Reply-To: From: Paolo Bonzini Date: Mon, 12 Feb 2024 11:29:51 +0100 Message-ID: Subject: Re: [PATCH v18 044/121] KVM: x86/mmu: Assume guest MMIOs are shared To: isaku.yamahata@intel.com Cc: 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Jan 23, 2024 at 12:55=E2=80=AFAM 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., GP= As > either have no kvm_memory_slot or are backed by host MMIOs). So that gues= ts > can access those MMIO regions. I'm not sure how the patch below deals with host MMIOs? > Signed-off-by: Chao Gao Missing Signed-off-by. Also, this patch conflicts with "[PATCH v11 09/35] KVM: x86: Determine shared/private faults based on vm_type". I think in general the logic in that patch (which forces an exit to userspace if needed, to convert the MMIO area to shared) can be applied to sw-protected and TDX guests as well. I'm preparing a set of common patches that can be applied for 6.9 and will include something after testing with sw-protected VMs. Paolo > --- > 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 e93bc16a5e9b..583ae9d6bf5d 100644 > --- a/arch/x86/kvm/mmu/mmu.c > +++ b/arch/x86/kvm/mmu/mmu.c > @@ -4371,7 +4371,12 @@ static int __kvm_faultin_pfn(struct kvm_vcpu *vcpu= , struct kvm_page_fault *fault > return RET_PF_EMULATE; > } > > - if (fault->is_private !=3D kvm_mem_is_private(vcpu->kvm, fault->g= fn)) { > + /* > + * !fault->slot means MMIO. Don't require explicit GPA conversio= n for > + * MMIO because MMIO is assigned at the boot time. > + */ > + if (fault->slot && > + fault->is_private !=3D kvm_mem_is_private(vcpu->kvm, fault->g= fn)) { > if (vcpu->kvm->arch.vm_type =3D=3D KVM_X86_SW_PROTECTED_V= M) > return RET_PF_RETRY; > kvm_mmu_prepare_memory_fault_exit(vcpu, fault); > -- > 2.25.1 >