From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FSL_HELO_FAKE,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46A52C07E95 for ; Tue, 20 Jul 2021 19:38:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CFD8A610CC for ; Tue, 20 Jul 2021 19:38:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CFD8A610CC Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 6B4476B0036; Tue, 20 Jul 2021 15:38:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 63CE86B005D; Tue, 20 Jul 2021 15:38:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4683B6B006C; Tue, 20 Jul 2021 15:38:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0234.hostedemail.com [216.40.44.234]) by kanga.kvack.org (Postfix) with ESMTP id 1E4216B0036 for ; Tue, 20 Jul 2021 15:38:22 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 95B13824805A for ; Tue, 20 Jul 2021 19:38:20 +0000 (UTC) X-FDA: 78383977560.18.F761294 Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) by imf19.hostedemail.com (Postfix) with ESMTP id 4F68AB000183 for ; Tue, 20 Jul 2021 19:38:20 +0000 (UTC) Received: by mail-pg1-f179.google.com with SMTP id j4so6822054pgk.5 for ; Tue, 20 Jul 2021 12:38:20 -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=MYjb98nUHtACR4qDjz9qyYSCve9jBpfJAkyBIpxkMa+nIFuiGkfrdJSvtN9yZMZkeh GLGZu6q8XcHgLnycoKgA5L1NfkX7/KA6Am/jsqtGEGbuQtAgkgpl/ldEFKSlI/wZa652 4GH0wncyfAhJI50nYgaSlrV8/0/7FEMOQEQE8pCnfqQYXiv4tpTFBC08sj8J+UKHioGz jmtXrj6SAC4307HAj3+ubzMcxZ6wCiRdE6WdMImIAUmRoojKGk7mG/asnLLCbQ7xuQ5y TOfFuS9Y7StxRKaMoOa3qC0hDOU/GpA3CKmSRTAoRpa2Z4Ij8F41BHG4ABcmOo5lmB8H CRFA== X-Gm-Message-State: AOAM531VSJ7HGSCXGl1FZx6rL/6fv2OjbxNOzaSFHnF7FpPwtI8kv8Lc F8JOSt1zHzGzjNrt4OeHiWOylQ== 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> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1ed3c439-a02c-7182-b140-32cddd5e4f34@amd.com> Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=U3suekfY; spf=pass (imf19.hostedemail.com: domain of seanjc@google.com designates 209.85.215.179 as permitted sender) smtp.mailfrom=seanjc@google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam02 X-Stat-Signature: eo1if3g7ffx1cid444xzbd8qtuhozzbu X-Rspamd-Queue-Id: 4F68AB000183 X-HE-Tag: 1626809900-64273 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 ca= ll > > snp_lookup_page_in_rmptable() directly from MMU code. That would req= uire tracking > > that a VM is SNP-enabled in arch code, but I'm pretty sure info has a= lready bled > > into common KVM in one form or another. >=20 > 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/*).=A0 So far there was no need as such b= ut > 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 >=20 > enum { >=20 > =A0=A0 GUEST_TYPE_SEV, >=20 > =A0=A0 GUEST_TYPE_SEV_ES, >=20 > =A0=A0 GUEST_TYPE_SEV_SNP, >=20 > }; >=20 > struct kvm { >=20 > =A0=A0 ... >=20 > =A0 u64 enc_type; >=20 > }; >=20 > bool kvm_guest_enc_type(struct kvm *kvm, enum type); { >=20 > =A0=A0=A0 return !!kvm->enc_type & type; >=20 > } >=20 > 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 leve= raging. 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 per= sonally 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.162518= 6503.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 th= at 2mb/1gb > > pages in the NPT _must_ have RMP.page_size=3D1, and 4kb pages in the = NPT _must_ > > have RMP.page_size=3D0. That means that the RMP adjustment is not a = constraint, > > it's an exact requirement. Specifically, if the RMP is a 2mb page th= en 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 tha= t's a very > > convoluted and sub-optimal solution. >=20 > 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. >=20 > 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 hav= e > to perform psmash. Boo, there's no way to communicate to the guest that it's doing PVALIDATE= wrong is there?