Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp505384lqt; Thu, 6 Jun 2024 09:38:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVdhd1rzWVJSNc0HgAbqvkUbtpX1emowcSqRPEFTLjExlu+dsjzF7i5krP1maCDHmv3QJb3jQLSxBdKma4O+mihgfP8/soVo8HBMAiVSw== X-Google-Smtp-Source: AGHT+IFMPEV1d2QiyfIWVIatDu+d2kKU3lJoBAt9382IKytQGDtANX7hK1VM8YwKRSiUCOxzdih7 X-Received: by 2002:a17:90a:b011:b0:2bf:7e0a:8a9a with SMTP id 98e67ed59e1d1-2c29998560cmr4235104a91.7.1717691932553; Thu, 06 Jun 2024 09:38:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717691932; cv=pass; d=google.com; s=arc-20160816; b=bSOsZqlGfrn0OsyVka1aMY97LQrQ10rRCnNH6oLH4VSNHkDWl46plX7tZWWHLz3nBK oge7lGB07PpHU+RBjXbsw9+duiIfer4e75bgip4lyeoR19I7DMo3QgSiUaLXJ35jzLCS qvDkqCu08aEG7PEa2FQCQeLf/YvtjIWGyXNRtRLz4VSR2gUOeB9ukuSn8OblsPqYjd6C 5uk1quUPCXtAW0YJPJDsehEJuJnwfRQ0rpRsvwn0rVjTzfkXyORuR0eF06W587vRn/sa 8caVFttpiCg9hUwYeXeqWGk1h/DLgJ/wDfQiO2YvRTSNP1Rk3HfYLHPQb87SE9EmAVMN iKoQ== 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=AqdpCvnzMbEvDLDb+VyMlSvq06RVNzNNqxG9y9taPwg=; fh=7sqwjFcPbvtDX2o0hoHCb39BRm63FjwzOFGP5ryGzkk=; b=Lh/qag8m+wL1t94nrHMqQhhvHxVsrZcH64W9n+V0UdDvqJfLgY9j8e3EjsRrlUV54K zPfPDcSv7PneYcsuwcNLaYPkCX0wQZwQsghUZUtEqK6Nm9i32yT/aEYCd+dXfOGD8k1G hve+h9pQN2d58gBsntpMIRShtXPbNykNs0qsVPpjIqauwKE66RpDpRBzhNll5RqL+EIs A/gOscTKn0KfxO1vy2bk52yNrk4OJ4IPwHLgPXvAG6gpcP9SjVyerI0/QlF5F1xPjFts +M6eCoDW3SGX8YrFEJNAmCO9HjCCYVKjOg4kHpI36CeHzyHheQGI/YsJxE32nXfOOyOI iTXg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dqei6xmL; 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-204640-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204640-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2c28059fafasi3383883a91.0.2024.06.06.09.38.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 09:38:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-204640-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dqei6xmL; 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-204640-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204640-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 5E50AB2A0BE for ; Thu, 6 Jun 2024 16:07:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4E1B3197A8E; Thu, 6 Jun 2024 16:06:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="dqei6xmL" 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 E047B1DDC9 for ; Thu, 6 Jun 2024 16:06:48 +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=1717690010; cv=none; b=Gs/WDojJplhjAdmSvIoOql5P2u0sy557sUqtH27uAocaJZdGmn9oCjlSfREhyWawCQXGuiwaAZ85pIrTx62ZfYU2JFtP7v1zSwztIuhAfNCI7I3EKGDlKcUKnJBUT2gDJyLEdi75dOKemIdpxBD4Dq8DwKQxJM3Tjt8PLhqY7a4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717690010; c=relaxed/simple; bh=xtP+8AIj85C1/WgIWPRNG4p8BLG3rnAPCNR1vfpZHEk=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=mHMUvr7KjThoob7EgK5vVqppVCQyk2F5Xh/1FuzQNLBEVlpxmkrkHQpUuAWto3y6/KPlL37/EIjSrJoi4VpOqBUk25BM5FMPH2I+xZbMLZ3aL19r2qrdXevHK/WBimikGPtLZGaYIaq1ArSGRTn4qFFNHqXubnoOSJVWyzpSD8I= 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=dqei6xmL; 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=1717690007; 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=AqdpCvnzMbEvDLDb+VyMlSvq06RVNzNNqxG9y9taPwg=; b=dqei6xmLmKZN51YWgAxyhWNZ/Q6qVl8ZCQboPAa0Ks+WvLr0PWbNpWQ4a0ZpZne0kEi/Cm TQKmUiDhCqvlqZnPONSOzKV3j+3XRSMiAN5/f3OZ2yzUOXswH2qhAZT5Pe+AlLCMk/D1DT p4UZiv2kC/4Pw+Cs4wH8McLDyM8pI68= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-492-UlyuETeoNZiecGHH36orWg-1; Thu, 06 Jun 2024 12:06:46 -0400 X-MC-Unique: UlyuETeoNZiecGHH36orWg-1 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-35dceae6283so1064159f8f.2 for ; Thu, 06 Jun 2024 09:06:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717690005; x=1718294805; 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=AqdpCvnzMbEvDLDb+VyMlSvq06RVNzNNqxG9y9taPwg=; b=SDXY0xPeyDpRszdIqPpEZO+pR6+IjB+kE0zJ5Tho+9s2hi7AKwzlzU4PPVuD7op/dr S0Wfj36endMK60qNeg2g2G6chGQxJ9IWSywHgKqb9z3OStkaQ1G8DuKvh51KB19KrF1o 0RZ2+yrynnfIFLL2V20IO9zchhMwr+tSmK/Gq3vfaAPeoxODyL7yYoiSbDyW5l4ZynN3 ssgeJVcMvOKMft1mxjd3j+wZpis0A+mCANuIiBK3zobFjmFgFm7uJ0ckosu54XZTjjJw VkEH5eqVHC1b3w/6eiiQYCf9AeYqdwqrOnt1ddJRhgfxm0Af7mtEGGt70TLgeSUB9Jx3 kahQ== X-Forwarded-Encrypted: i=1; AJvYcCUlZ6Ijxw5kt+83XmDUM/RSe+KceY/ic4C2z4xpQei16CrSyCS8O4KVFEC1FD6SFH71opxPqxovkejwhuLedpy3bwp+7ANR6caWEOTa X-Gm-Message-State: AOJu0Yx1eip4ecRzED3mzKiLZGlyi0dFV1vW03J7LszbivN4QulFnSzV /EYEqfbV3UcbQDkeGmzSMZl16TaJ3MX017bmtrZATKgIyd+YBKXebnZ8v1j8wYgnc6JAFTtLbCG V7v0q6tbgyHkp6hiy90jOIKOfL4CZO9MdhswmhgY5yt4XzWfVN/Tbnh1lAzREwZvJgTN4hnclnh lJvCjPWm9d82e7AVSUx4g1BP4UuTQ3SG2557DC X-Received: by 2002:a5d:5750:0:b0:356:49a8:7e0a with SMTP id ffacd0b85a97d-35efed1d686mr56105f8f.11.1717690005380; Thu, 06 Jun 2024 09:06:45 -0700 (PDT) X-Received: by 2002:a5d:5750:0:b0:356:49a8:7e0a with SMTP id ffacd0b85a97d-35efed1d686mr56090f8f.11.1717690004987; Thu, 06 Jun 2024 09:06:44 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240530210714.364118-1-rick.p.edgecombe@intel.com> <20240530210714.364118-5-rick.p.edgecombe@intel.com> In-Reply-To: <20240530210714.364118-5-rick.p.edgecombe@intel.com> From: Paolo Bonzini Date: Thu, 6 Jun 2024 18:06:33 +0200 Message-ID: Subject: Re: [PATCH v2 04/15] KVM: x86/mmu: Add a new mirror_pt member for union kvm_mmu_page_role To: Rick Edgecombe Cc: seanjc@google.com, kvm@vger.kernel.org, kai.huang@intel.com, dmatlack@google.com, erdemaktas@google.com, isaku.yamahata@gmail.com, linux-kernel@vger.kernel.org, sagis@google.com, yan.y.zhao@intel.com, Isaku Yamahata Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, May 30, 2024 at 11:07=E2=80=AFPM Rick Edgecombe wrote: > > From: Isaku Yamahata > > Introduce a "mirror_pt" member to the kvm_mmu_page_role union to identify > SPTEs associated with the mirrored EPT. > > The TDX module maintains the private half of the EPT mapped in the TD in > its protected memory. KVM keeps a copy of the private GPAs in a mirrored > EPT tree within host memory. This "mirror_pt" attribute enables vCPUs to > find and get the root page of mirrored EPT from the MMU root list for a > guest TD. This also allows KVM MMU code to detect changes in mirrored EPT > according to the "mirror_pt" mmu page role and propagate the changes to > the private EPT managed by TDX module. > > Signed-off-by: Isaku Yamahata > Signed-off-by: Rick Edgecombe > --- > TDX MMU Prep v2: > - Rename private -> mirrored > > TDX MMU Prep: > - Remove warning and NULL check in is_private_sptep() (Rick) > - Update commit log (Yan) > > v19: > - Fix is_private_sptep() when NULL case. > - drop CONFIG_KVM_MMU_PRIVATE > --- > arch/x86/include/asm/kvm_host.h | 13 ++++++++++++- > arch/x86/kvm/mmu/mmu_internal.h | 5 +++++ > arch/x86/kvm/mmu/spte.h | 5 +++++ > 3 files changed, 22 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_h= ost.h > index 250899a0239b..084f4708aff1 100644 > --- a/arch/x86/include/asm/kvm_host.h > +++ b/arch/x86/include/asm/kvm_host.h > @@ -351,7 +351,8 @@ union kvm_mmu_page_role { > unsigned ad_disabled:1; > unsigned guest_mode:1; > unsigned passthrough:1; > - unsigned :5; > + unsigned mirror_pt:1; "is_mirror". > + unsigned :4; > > /* > * This is left at the top of the word so that > @@ -363,6 +364,16 @@ union kvm_mmu_page_role { > }; > }; > > +static inline bool kvm_mmu_page_role_is_mirror(union kvm_mmu_page_role r= ole) > +{ > + return !!role.mirror_pt; > +} > + > +static inline void kvm_mmu_page_role_set_mirrored(union kvm_mmu_page_rol= e *role) > +{ > + role->mirror_pt =3D 1; > +} Not needed, remove it. > /* > * kvm_mmu_extended_role complements kvm_mmu_page_role, tracking propert= ies > * relevant to the current MMU configuration. When loading CR0, CR4, o= r EFER, > diff --git a/arch/x86/kvm/mmu/mmu_internal.h b/arch/x86/kvm/mmu/mmu_inter= nal.h > index faef40a561f9..6d82e389cd65 100644 > --- a/arch/x86/kvm/mmu/mmu_internal.h > +++ b/arch/x86/kvm/mmu/mmu_internal.h > @@ -157,6 +157,11 @@ static inline int kvm_mmu_page_as_id(struct kvm_mmu_= page *sp) > return kvm_mmu_role_as_id(sp->role); > } > > +static inline bool is_mirror_sp(const struct kvm_mmu_page *sp) > +{ > + return kvm_mmu_page_role_is_mirror(sp->role); > +} e.g. "return sp->role.is_mirror". > static inline void *kvm_mmu_mirrored_spt(struct kvm_mmu_page *sp) > { > return sp->mirrored_spt; This one is also unnecessary BTW. Otherwise looks good. Paolo > diff --git a/arch/x86/kvm/mmu/spte.h b/arch/x86/kvm/mmu/spte.h > index 5dd5405fa07a..b3c065280ba1 100644 > --- a/arch/x86/kvm/mmu/spte.h > +++ b/arch/x86/kvm/mmu/spte.h > @@ -265,6 +265,11 @@ static inline struct kvm_mmu_page *root_to_sp(hpa_t = root) > return spte_to_child_sp(root); > } > > +static inline bool is_mirror_sptep(u64 *sptep) > +{ > + return is_mirror_sp(sptep_to_sp(sptep)); > +} > + > static inline bool is_mmio_spte(struct kvm *kvm, u64 spte) > { > return (spte & shadow_mmio_mask) =3D=3D kvm->arch.shadow_mmio_val= ue && > -- > 2.34.1 >