From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D20F3168 for ; Tue, 20 Jul 2021 19:38:19 +0000 (UTC) Received: by mail-pf1-f172.google.com with SMTP id p36so367394pfw.11 for ; Tue, 20 Jul 2021 12:38:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=opGYJ8ATKeLRJGjAJK6R9tbhbI7CJxP6XB4aUSj1rRc=; b=U3suekfYP80TfhnSWCdW0AeB5YxRYqo2o3/gq9NjySLOotsA/QHsKv4nrfgs9Q6OW4 KjSFSlK0XO5pyVT8FlownP4GS3PcIrtF/1itOWU4Pga+6PwG15GCcUmAHgnsNMPMi4LX DxT0uRyt0039tsJZa4N+W8sH3nZ3ORXDV7KdShXCKvh6oAxgtZUERz3/kYRLyJ5E2nWy NESQv+xyyGvE5IhgT/cYsM8bQaF8F8f+olP6Pv+1dQQcP53pETJLgqGRDE75b9vRhf5t erL1h5JQ4WgB3pRfhQQaD4CT4UWWh7xaKg8C46eFTZOacYR8kBVBLxEUzPFoFCtyV1A7 oJRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=opGYJ8ATKeLRJGjAJK6R9tbhbI7CJxP6XB4aUSj1rRc=; b=g2MlquX7JWmbeOO4Zzrigwrw/sh11OXHywMqZlIOxZLytbM8FgVWdmjJfjhBtxX4bE r4pF8uPPb8r2rNTCQ9m3VegS/RROoBu/DiEE/t94aFqcRVQcHAN7221rfJrT42VpvAS2 xgPcN2FroppNi7GrqOHR6KC281CdAJeB+ygcWd2LbZatLJxjJDvJAw07dZ5bZ5Xm2BAA A2KdY+ImWh3RZGWeTWaVbyHyuTnCLK26ryEUywu+8Mly8GWL00uDJUQcodsXbNLbjkzS xh1g+6jBsjlQPkd3lYFIU9Bdgn6K8LjYr9ftlR1ISbFgntulv6EgiDA7n60JbrDW8bq2 9Liw== X-Gm-Message-State: AOAM533yXR4Cyv5YegP5+irZnBJxpvIOYJ8GSXP3zf4R2kypeloMuqm5 r47MgAPk21Ak0aVaeyGcfPoIGQ== X-Google-Smtp-Source: ABdhPJxaIdbx05Hn/m0/ilrMVvfZTLe2YGc+vQnLw4+1SqOXt5bk80Vq8MgVTJaPuxiVmjKAyXSIhA== X-Received: by 2002:a63:5620:: with SMTP id k32mr6362897pgb.32.1626809898963; Tue, 20 Jul 2021 12:38:18 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id a20sm23827514pfv.101.2021.07.20.12.38.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 12:38:18 -0700 (PDT) Date: Tue, 20 Jul 2021 19:38:14 +0000 From: Sean Christopherson To: Brijesh Singh Cc: x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-efi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-coco@lists.linux.dev, linux-mm@kvack.org, linux-crypto@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Joerg Roedel , Tom Lendacky , "H. Peter Anvin" , Ard Biesheuvel , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Andy Lutomirski , Dave Hansen , Sergio Lopez , Peter Gonda , Peter Zijlstra , Srinivas Pandruvada , David Rientjes , Dov Murik , Tobin Feldman-Fitzthum , Borislav Petkov , Michael Roth , Vlastimil Babka , tony.luck@intel.com, npmccallum@redhat.com, brijesh.ksingh@gmail.com Subject: Re: [PATCH Part2 RFC v4 27/40] KVM: X86: Add kvm_x86_ops to get the max page level for the TDP Message-ID: References: <20210707183616.5620-1-brijesh.singh@amd.com> <20210707183616.5620-28-brijesh.singh@amd.com> <1ed3c439-a02c-7182-b140-32cddd5e4f34@amd.com> Precedence: bulk X-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1ed3c439-a02c-7182-b140-32cddd5e4f34@amd.com> On Fri, Jul 16, 2021, Brijesh Singh wrote: > On 7/16/21 2:19 PM, Sean Christopherson wrote: > > On Wed, Jul 07, 2021, Brijesh Singh wrote: > > Another option would be to drop the kvm_x86_ops hooks entirely and call > > snp_lookup_page_in_rmptable() directly from MMU code. That would require tracking > > that a VM is SNP-enabled in arch code, but I'm pretty sure info has already bled > > into common KVM in one form or another. > > I would prefer this as it eliminates some of the other unnecessary call > sites. Unfortunately, currently there is no generic way to know if its > an SEV guest (outside the svm/*).  So far there was no need as such but > with SNP having such information would help. Should we extend the > 'struct kvm' to include a new field that can be used to determine the > guest type. Something like > > enum { > >    GUEST_TYPE_SEV, > >    GUEST_TYPE_SEV_ES, > >    GUEST_TYPE_SEV_SNP, > > }; > > struct kvm { > >    ... > >   u64 enc_type; > > }; > > bool kvm_guest_enc_type(struct kvm *kvm, enum type); { > >     return !!kvm->enc_type & type; > > } > > The mmu.c can then call kvm_guest_enc_type() to check if its SNP guest > and use the SNP lookup directly to determine the pagesize. The other option is to use vm_type, which TDX is already planning on leveraging. Paolo raised the question of whether or not the TDX type could be reused for SNP. We should definitely sort that out before merging either series. I'm personally in favor of separating TDX and SNP, it seems inevitable that common code will want to differentiate between the two. https://lkml.kernel.org/r/8eb87cd52a89d957af03f93a9ece5634426a7757.1625186503.git.isaku.yamahata@intel.com > > As the APM is currently worded, this is wrong, and the whole "tdp_max_page_level" > > name is wrong. As noted above, the Page-Size bullet points states that 2mb/1gb > > pages in the NPT _must_ have RMP.page_size=1, and 4kb pages in the NPT _must_ > > have RMP.page_size=0. That means that the RMP adjustment is not a constraint, > > it's an exact requirement. Specifically, if the RMP is a 2mb page then KVM must > > install a 2mb (or 1gb) page. Maybe it works because KVM will PSMASH the RMP > > after installing a bogus 4kb NPT and taking an RMP violation, but that's a very > > convoluted and sub-optimal solution. > > This is why I was passing the preferred max_level in the pre-fault > handle then later query the npt level; use the npt level in the RMP to > make sure they are in sync. > > There is yet another reason why we can't avoid the PSMASH after doing > everything to ensure that NPT and RMP are in sync. e.g if NPT and RMP > are programmed with 2mb size but the guest tries to PVALIDATE the page > as a 4k. In that case, we will see #NPF with page size mismatch and have > to perform psmash. Boo, there's no way to communicate to the guest that it's doing PVALIDATE wrong is there?