Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp1534757lqt; Sat, 8 Jun 2024 02:14:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVe+k8ZPoq2gVvIG/KG22sMqzU8R81wLnTPt3fLLA18fZQwnlUHfbCmN2F0Efhfe21hv5OvK35kId7zQYggY6E+JL5IClZQ/ySr/pwxFA== X-Google-Smtp-Source: AGHT+IEpvtKfR1sqMYo9sJaLO05TAcinbYchfDDGguyvL4whcFAGs3ew85b1CFpJnCXgsU9/fRGa X-Received: by 2002:a17:906:f34d:b0:a5c:fd35:df3d with SMTP id a640c23a62f3a-a6cdad22eeamr247433766b.61.1717838069171; Sat, 08 Jun 2024 02:14:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717838069; cv=pass; d=google.com; s=arc-20160816; b=ZspkJnb41Mxk9MH7VyGBtlOy/1XzJ1XcwUIdMJosbGwHo76Y2Fnzj0nMolmjHxat0f v9jrfAOBJRp7qdXtAQlvuF42NJAjTL4FJgFvWmHRReQD22fLb4yMdJeRw+vyMZ57TqS+ B5v4x4kVOQnWS1Loy1loxZSWuxy2GS+HnPoJUSSjsVJuVvg7GyHwq1J+Ob7sfFkxUYFE PPLLIVQiNsdx1W82TSPp2BJE1saQHbu0xFkSj1/aTVMczMyVJbmn2lk/EGGPCE1HpIss zmeqYpCrfhw2BN0DKagWFB/piNfx6oSIipZmjcaQ7Mx7qW7f1iua0WtWEHJGCgYlPZ5d 1xNg== 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=Ku7v+UVkWkWp0wqpNRlbUjz2nl0FWZCw5kgGu5XvDzY=; fh=FecHJcBzpmPXbs7I8NJVUs+WJI+T+du3nb1/Fvk1WqU=; b=hL0N7jsTWvI5sWhh8QjDRBB4r2FCx8lWUO8687o0sOIqDckt3N61cGpWMj1OsARd2N nh+kefRdyCw3L492AngN3Ambjtq7gu9yGalshSLSVhb7ycK26/2G17IJrxzGf3p6Cihs ZePtS/rFwq2J1QnGjzBsgO4mfpv4G9bvjgd8EhhybOpOIuiR1/R3+GpFlJtn6lNBgTYr sQeZs4VUWy0UJOQNqniRCiz/kgDMMmKOhgsdA2PaU0dvsAsh984IUqRo/xfd++LLLrpj BlHgn5sm9rL5qoRSTcHP/ATwhFsf2E0AYqhcoAAZczQckHgKbvoSYU5QCXkIObuNS4oT 14Qg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Wz719ZCj; 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-206986-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206986-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a6c80748f55si260021366b.926.2024.06.08.02.14.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Jun 2024 02:14:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-206986-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Wz719ZCj; 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-206986-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206986-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 am.mirrors.kernel.org (Postfix) with ESMTPS id DBFFC1F215E6 for ; Sat, 8 Jun 2024 09:14:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D8685176FC3; Sat, 8 Jun 2024 09:14:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Wz719ZCj" 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 A262F12BE91 for ; Sat, 8 Jun 2024 09:14:16 +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=1717838058; cv=none; b=ZoxHPSaOZSjr6Bu4gs9lQCy95Lcvb0Qmrb1RngEnRNHj2gL1u/kUJHQNFq08f+svqg5dQcCjMLvDtND+xNdiVOQCUhLPeTfo5WLsMnsfzUouiIaDU71iU2R48Qq6KX0F9PgrtdJ6pKeJv/bPsD/Ly63wFIcRGsaAvDNefzMCbEY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717838058; c=relaxed/simple; bh=Q/TGAr0CiNDoDYrcj03jYZOrzqb1pAXuFRC9IC55pSM=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=mg60f5nH/IvVcQnWFHS0DsfaG4Mqkm5NgGzcXKV7a8nfSabxcjSN+Pfppusf65oB/ShxtG7EltTQ5ibwTnCmLdE7LrVBqpYa3BdRlXehuqmzIq1MexaxtrMpjctB+J2Q5SWoCNDq27cdSBF8ksnXyjZ8rQsWPzZO4mmB96AQEm8= 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=Wz719ZCj; 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=1717838055; 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=Ku7v+UVkWkWp0wqpNRlbUjz2nl0FWZCw5kgGu5XvDzY=; b=Wz719ZCjafINrMFosjA5rr2WT+LFjf605rVVeXaKcI65T2kEoBmiEuwGlnn/jZyao0hNPx dcmgl4oDdFwmcuE48FA0UQtzmZZxET9HrcieiOPTJvgZEB5jYtg61QfP8iLMjJkvdDQ138 mr2YlClEHWZaG2FyZsvhncBIpmCrvQs= Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-76-jX3gwbMgNkqyyXWKnnICjg-1; Sat, 08 Jun 2024 05:14:10 -0400 X-MC-Unique: jX3gwbMgNkqyyXWKnnICjg-1 Received: by mail-pj1-f70.google.com with SMTP id 98e67ed59e1d1-2c2dd7fb263so441043a91.0 for ; Sat, 08 Jun 2024 02:14:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717838049; x=1718442849; 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=Ku7v+UVkWkWp0wqpNRlbUjz2nl0FWZCw5kgGu5XvDzY=; b=u3Gd4azhHTRTcMJSJDHXSIqau+VSlr2r3lS1GmDzkQuocjpvgPYRP7hVm4cGQypzmu 77r5YQve0Oeckpd2TjsX+gqYrCLh5DkAE+psIIX7kA2+ORvePNpFOcgJturC+oQQu2So v4ZHn2m8tzQ5IFKlRro+GGTXoSFNdJzcIJGrPaH3g8s0aTXrvnFXzTCVnJFIM45UGcb7 cLsuWhbMw4SibJWXm8ufz/Fd/IzLCyZQquVlKfGd228O0T9t4hbG0s3nlSh7daO6C5CH 4ybV+eAQKLn7d8I2DYLtsCfbOh5jH7Njg/jXfBGcxMQR71QJOjMZU35/q0xdNytH9mNj 7Z/A== X-Forwarded-Encrypted: i=1; AJvYcCVFVPRbRo6hPM+M3iKtV+g7j/CtYxFWvBYVbSiESdcoirM4BDDomPa54zOrtds8RHgUW9t62EP5Xj42Tg2GdmywU4PiKe9qYGrahaI/ X-Gm-Message-State: AOJu0YyHIIjzWf9b416xWUj3Qazpc9lkLq/+cfUziz//87qJBM3Ha0sZ nvLz+2RglV84IM8rauJm6RWmsxozK4MuoP36DNi/MifH+OkLqU6e21C4UbuF9Og3KTm+q0UeC2V +Lw8CQEdBl+r97wmRocT/4l7TrTLyli9xRO3bTXP1SycCdeSzujYmpWVMN2YGmcbLZqwG/Z3XtT P6is859COuUpNNP/y+OTNTExc7ggjH9NRoL2Vx X-Received: by 2002:a17:90b:2352:b0:2c2:cfca:6783 with SMTP id 98e67ed59e1d1-2c2cfca6890mr2473199a91.45.1717838049451; Sat, 08 Jun 2024 02:14:09 -0700 (PDT) X-Received: by 2002:a17:90b:2352:b0:2c2:cfca:6783 with SMTP id 98e67ed59e1d1-2c2cfca6890mr2473190a91.45.1717838049109; Sat, 08 Jun 2024 02:14:09 -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-10-rick.p.edgecombe@intel.com> In-Reply-To: From: Paolo Bonzini Date: Sat, 8 Jun 2024 11:13:53 +0200 Message-ID: Subject: Re: [PATCH v2 09/15] KVM: x86/tdp_mmu: Support mirror root for TDP MMU To: "Edgecombe, Rick P" Cc: "seanjc@google.com" , "Huang, Kai" , "sagis@google.com" , "linux-kernel@vger.kernel.org" , "Aktas, Erdem" , "Zhao, Yan Y" , "dmatlack@google.com" , "kvm@vger.kernel.org" , "Yamahata, Isaku" , "isaku.yamahata@gmail.com" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Jun 7, 2024 at 10:27=E2=80=AFPM Edgecombe, Rick P wrote: > > static inline struct kvm_mmu_page * > > tdp_mmu_get_root_for_fault(struct kvm_vcpu *vcpu, struct kvm_page_fault > > *fault) > > { > > hpa_t root_hpa; > > if (unlikely(fault->is_private && kvm_has_mirror_tdp(kvm))) > > root_hpa =3D vcpu->arch.mmu->mirror_root_hpa; > > else > > root_hpa =3D vcpu->arch.mmu->root.hpa; > > return root_to_sp(root_hpa); > > } > > I was not loving the amount of indirection here in the patch, but thought= it > centralized the logic a bit better. This way seems good, given that the a= ctual > logic is not that complex. My proposed implementation is a bit TDX-specific though... Something like this is more agnostic, and it exploits nicely the difference between fault->addr and fault->gfn: if (!kvm_gfn_direct_mask(kvm) || (gpa_to_gfn(fault->addr) & kvm_gfn_direct_mask(kvm)) root_hpa =3D vcpu->arch.mmu->root.hpa; else root_hpa =3D vcpu->arch.mmu->mirror_root_hpa; return root_to_sp(root_hpa); Paolo