Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp1538006lqt; Sat, 8 Jun 2024 02:26:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUIVZ/M5T390K32PTktXOYpOkVwSjLHpu/uz4vMeAMSTcSwGqeO1L+JJzKGKr83dhxMbGgQlawxoE+asyr9mSb/tE0gMCN5GcCiEDWGEQ== X-Google-Smtp-Source: AGHT+IFQEuRbSnZVHjHERR8jnUDoN6aXLGia+unM04v96PfaELk7ElVNJFp4erVG6HAdxpMtU6J0 X-Received: by 2002:a05:6e02:19cb:b0:374:7f1c:c3f5 with SMTP id e9e14a558f8ab-37580243e8cmr54090115ab.0.1717838787062; Sat, 08 Jun 2024 02:26:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717838787; cv=pass; d=google.com; s=arc-20160816; b=NgZj5WeoA+MBXoJfwv2EXFrfsirmT3t/F68tjYQY67poT0uoPpUXGBeYH/BQxZtDsa +/l2BI7uiJhNNiJYvYjuYgQXZZAnNAqV3tT6bQ1giUbUuI4hVfqX68nsffiItyp28KCL +EgVxIU8kx9hFggj9KTRvI5Y72Bl3D4f7wFBroFYKbdFW8M43sOtiXGAeG+eoiyzY8NA +CDJogJUeLuUFiy8x+FSC9i2pF1WPy7d1XEkF6zpgj50JbI0NQvaIEBmH194BmRvRrkm 3iFtgEj+tZtfJRqV0NO/SJb5WauEdTGojFWmRFeWOmHb3sUpqsFAoeF2613gWs9KYAU/ Cicw== 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=kNnj0sYqfR+gPARY56d6Q9vYuZ/hYLYTEqKn/JW0FmA=; fh=xpEsYJPFUw768ZbMoL26MQq18wGNGXzrssjBE1gxz7A=; b=VV2oJkX1uMZGLpckprEWwK8V3dFZ5SpxMqHNxmBzVh+NwmVRxgOF5WzbLBZ6GlLa/T 3X5hPK19mNWuV8/0iACBpZBcB9ahrt5g4QwK18Z+MuUa08GVo4KnsW9n0TNMLcAaPdRR e321WPnWPUVXPCSJStuk8aRcCWcXvsA69ZcP7DzYmu4c0kf3UADNogQbsoHnPNZhvU/D ozbTIziN491adcYGWD04M5/IQsAVSxojE+Lw3UNjeYC3W3sPLVZapL84SqtzbcUk7pwR 62NGbhQRfDEPVaeRnTn1N6RSIGj3Qh9dnPXbN/LY3q22lrKTNd38+yjBs8PiL9+mH150 Ictw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Ys529IGt; 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-206996-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206996-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. [147.75.48.161]) by mx.google.com with ESMTPS id 41be03b00d2f7-6de294f8ab7si4409237a12.720.2024.06.08.02.26.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Jun 2024 02:26:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-206996-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Ys529IGt; 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-206996-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206996-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 41C40B20D07 for ; Sat, 8 Jun 2024 09:26:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 072DA176FC9; Sat, 8 Jun 2024 09:26:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Ys529IGt" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 690795024E for ; Sat, 8 Jun 2024 09:26:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717838764; cv=none; b=csGF9mVcDmUxRkw3GRuNvCJP9fuEZoBqMkVPtDQO9CuU9jX86BthZJ6PpYrjba1LYWeb6F2utzYcm9CtTq+JIvY/e1Tg81RmTp0dctiLbP6JnYJBWS9loFbfKzjzmIjOT6FkapSPTIgOyaKQtAYULq633gwm2HBQrlcH/Dvcabg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717838764; c=relaxed/simple; bh=IytfdB5VJ0hTZVIZ58WgO+XxvdZCWiQDHH+30k+/zGc=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=EBYuEFJ+CPxSNaf+xNsDxWMllbG8BpJKhYlPbhymv7DLW1Z+luvggCdRvzQJOm3qOnT4XhHQxXTPHCarpqqm/PkFb6lKdIzAqKnqTqfYF76ZLTGKm7WqmXdldA3uhzz7ZubX0C4uEwNw03z4BG6magZ/IRv+/DqQYXsUh7OvZgo= 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=Ys529IGt; arc=none smtp.client-ip=170.10.129.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=1717838761; 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=kNnj0sYqfR+gPARY56d6Q9vYuZ/hYLYTEqKn/JW0FmA=; b=Ys529IGt25vTWWjXgVIAWJi3mhUtV2pg+5h0XVIv86DO/f4uMAIJ0FHs2kXAHw2rllUMLM kCn2HwczToloHbGaJnw4OeExZorujc1mtQu2vWXJWpvfk4E0DJfUabvBgC4LcnwL75jPLS COu3yoY3/+C9oGYNt/A2iLwt2UlkW1o= Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-617-7xiIgInmOnummYWKNmt6tQ-1; Sat, 08 Jun 2024 05:25:58 -0400 X-MC-Unique: 7xiIgInmOnummYWKNmt6tQ-1 Received: by mail-pg1-f199.google.com with SMTP id 41be03b00d2f7-6c380e03048so2794169a12.3 for ; Sat, 08 Jun 2024 02:25:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717838757; x=1718443557; 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=kNnj0sYqfR+gPARY56d6Q9vYuZ/hYLYTEqKn/JW0FmA=; b=MIMCGEob1MDfKBqU3qCqllSEKXrwPevLd95semDn6b1oAw+OCr20JwFpwOuWgurhK/ TP/sUlGZ6wvOc2GoMKT65/UBiQkp+5CoJ+mfE1JvW4mU3Cf5AcyGFIZvecec3EgbPUYg gDajXWWMjVT47e59GF/k6GPvjcaGUdapPykFV3FNCPjEHjYfWmfegHdFwBfw84McQikn bw1Ued7gliAxQq+ZgDgSLo5Bld9jimv1lt+vorFrYtgYvdI+8IefWkVH2GmQKW8FvPaZ r1wyTHzuvCpXB82DVCMxs3ulsElDts97YsBP398TlPb9S9xTBxZgb42aUCzonzSZXJoN RgGw== X-Forwarded-Encrypted: i=1; AJvYcCWAg3vi+7TgQ/oN4oTA6daYwo0NCjEHTABWe8YHMaB08yoEVOgz4xiQhKva0QlmuS5MW98+hPMZ58hiV48FZ+ctbqW9WcYw/vLRpTqj X-Gm-Message-State: AOJu0YxDrsB9cugjfdOf4Vckuh04YkcCQWWPmXHSTkSI3L1gN94V17ua 0wheeDjD4RPWKOxrRs08kT8aeTZ3n19JMl3gzM26vfu7ryDkWHP5hJbT/av9Qmk+iKZvllyQ8q+ YE43yhipigZp8Uf+21g9zyYR2IHsv4Sf73oioT29Nf1VB8lsLqGYgsgj1PbIIBFxtHGb71Zw5/U qSkGArc27PezeKVPGbvZWG6304nhMdK/bLrNjc X-Received: by 2002:a05:6a20:7fa8:b0:1b0:25b6:a749 with SMTP id adf61e73a8af0-1b2f9c6dademr4560999637.48.1717838757069; Sat, 08 Jun 2024 02:25:57 -0700 (PDT) X-Received: by 2002:a05:6a20:7fa8:b0:1b0:25b6:a749 with SMTP id adf61e73a8af0-1b2f9c6dademr4560990637.48.1717838756694; Sat, 08 Jun 2024 02:25:56 -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-12-rick.p.edgecombe@intel.com> In-Reply-To: From: Paolo Bonzini Date: Sat, 8 Jun 2024 11:25:43 +0200 Message-ID: Subject: Re: [PATCH v2 11/15] KVM: x86/tdp_mmu: Reflect tearing down mirror page tables 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 11:46=E2=80=AFPM Edgecombe, Rick P wrote: > > Also, please rename the last argument to pfn_for_gfn. I'm not proud of > > it, but it took me over 10 minutes to understand if the pfn referred > > to the gfn itself, or to the external SP that holds the spte... > > There's a possibility that it isn't just me. :) > > Ah, I see how that could be confusing. > > > (In general, this patch took me a _lot_ to review... there were a > > couple of places that left me incomprehensibly puzzled, more on this > > below). > > Sorry for that. Thanks for taking the time to weed through it anyway. Oh, don't worry, I have no idea what made this patch stick out as the hardest one... Maybe it's really that there is such a thing as too many comments in some cases, and also the mutual recursion between handle_removed_pt() and handle_changed_spte(). Nothing that can't be fixed. > > > + kvm_pfn_t old_pfn =3D spte_to_pfn(old_spte); > > > + int ret; > > > + > > > + /* > > > + * Allow only leaf page to be zapped. Reclaim non-leaf page t= ables > > > page > > > > This comment left me confused, so I'll try to rephrase and see if I > > can explain what happens. Correct me if I'm wrong. > > > > The only paths to handle_removed_pt() are: > > - kvm_tdp_mmu_zap_leafs() > > - kvm_tdp_mmu_zap_invalidated_roots() > > > > but because kvm_mmu_zap_all_fast() does not operate on mirror roots, > > the latter can only happen at VM destruction time. > > > > But it's not clear why it's worth mentioning it here, or even why it > > is special at all. Isn't that just what handle_removed_pt() does at > > the end? Why does it matter that it's only done at VM destruction > > time? > > > > In other words, it seems to me that this comment is TMI. And if I am > > wrong (which may well be), the extra information should explain the > > "why" in more detail, and it should be around the call to > > reflect_free_spt, not here. > > TDX of course has the limitation around the ordering of the zapping S-EPT= . So I > read the comment to be referring to how the implementation avoids zapping= any > non-leaf PTEs during TD runtime. Ok, I think then you can just replace it with a comment that explains why TDX needs it, as it's one of those places where we let TDX assumptions creep into common code - which is not a big deal per se, it's just worth mentioning it in a comment. Unlike the tdp_mmu_get_root_for_fault() remark I have just sent for patch 9/15, here the assumption is more algorithmic and less about a specific line of code, and I think that makes it okay. Paolo > > > - /* Don't support setting for the non-atomic case */ > > > - if (is_mirror_sptep(sptep)) > > > + if (is_mirror_sptep(sptep)) { > > > + /* Only support zapping for the non-atomic case */ > > > > Like for patch 10, this comment should point out why we never get here > > for mirror SPs. > > Ok.