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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C074EC43334 for ; Tue, 12 Jul 2022 12:48:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 47C0B94006A; Tue, 12 Jul 2022 08:48:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4058E940063; Tue, 12 Jul 2022 08:48:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2CC7B94006A; Tue, 12 Jul 2022 08:48:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 19F44940063 for ; Tue, 12 Jul 2022 08:48:38 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E6C45343A7 for ; Tue, 12 Jul 2022 12:48:37 +0000 (UTC) X-FDA: 79678426674.13.DAD9735 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf02.hostedemail.com (Postfix) with ESMTP id 35EF78002A for ; Tue, 12 Jul 2022 12:48:37 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 098D5B81865; Tue, 12 Jul 2022 12:48:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3CC2DC341C8; Tue, 12 Jul 2022 12:48:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1657630114; bh=u3UpGccjJ2q2H3+rErFteKR1Zd4HKdFuMd3EDwq08Fo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=kpicQ+ZAooSoAWd/cbF7tEWilDBpOtRbO/CQ05knRl/3aaxqqTDxIYrMPkuh7rVzm CqOwnSljY6yj29NZhMXWhq56TX0PAjpsJsRLWMC7jwfxq3mQ5f3mtfUphRBQJBNkNl IE1Lcg5sRhAJjsgf6uU/V7b82XrLFdLz7wtw1fvbPw5WxYeQoNGdsqUMHIncxeYp2Z meRl83O2hLAnHWfQL/+tf0AFHFznlFOllqZ7+BuUZiADXMw1GB0hUV9PxZ+XIHUfyW SiOy4NWlkd5VQ9hRH4AxrI5Rv0xv4X4Yh+CvrhJqX8Hei+kL/ayL6vbp38bPL3Ugkc EKo8rWTxvw5vw== Date: Tue, 12 Jul 2022 15:48:31 +0300 From: Jarkko Sakkinen To: Ashish Kalra Cc: x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-mm@kvack.org, linux-crypto@vger.kernel.org, tglx@linutronix.de, mingo@redhat.com, jroedel@suse.de, thomas.lendacky@amd.com, hpa@zytor.com, ardb@kernel.org, pbonzini@redhat.com, seanjc@google.com, vkuznets@redhat.com, jmattson@google.com, luto@kernel.org, dave.hansen@linux.intel.com, slp@redhat.com, pgonda@google.com, peterz@infradead.org, srinivas.pandruvada@linux.intel.com, rientjes@google.com, dovmurik@linux.ibm.com, tobin@ibm.com, bp@alien8.de, michael.roth@amd.com, vbabka@suse.cz, kirill@shutemov.name, ak@linux.intel.com, tony.luck@intel.com, marcorr@google.com, sathyanarayanan.kuppuswamy@linux.intel.com, alpergun@google.com, dgilbert@redhat.com Subject: Re: [PATCH Part2 v6 41/49] KVM: SVM: Add support to handle the RMP nested page fault Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657630117; a=rsa-sha256; cv=none; b=hH2j/BJ448s0kCxNW1fpI2n1fNtYOOrQvcQ/CP+ZNk6P/rNI0vWzywxPI3bXNN70PJ1hgj MUJ5ihk75j+jkK1ux1emXRg+wU+FmsG55Szc6k3N8MFY2Y2/QrobAQKwVvUYnN9CT0YxLU q5z/MgJ7K9JdTb+BrPsGWWagrXmkreY= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=kpicQ+ZA; spf=pass (imf02.hostedemail.com: domain of jarkko@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=jarkko@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657630117; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=zCqsPYNYak1v92UKNOrytssaD/81z7mGi1LTOMbya8g=; b=5+oKLpa/jIcD7Glsg+YBTzQ26xDV/gglMkj5HQa/m1XY3XIA9yZzLvqTsazhhWoFnBSU9h t96fmoCp111y7KUjg/ibpXtTEamP4G46xbFP03yrFcSiBul/AkCL6uepCk1xHivIhRHfdQ bBkG3o668LJoze5RL4WCSDNHTcG4GIo= X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 35EF78002A X-Rspam-User: X-Stat-Signature: eftj6fn4n9r3rx9fefik6pkeqxis4boj Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=kpicQ+ZA; spf=pass (imf02.hostedemail.com: domain of jarkko@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=jarkko@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-HE-Tag: 1657630117-941908 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 Tue, Jul 12, 2022 at 03:45:13PM +0300, Jarkko Sakkinen wrote: > On Tue, Jul 12, 2022 at 03:34:00PM +0300, Jarkko Sakkinen wrote: > > On Mon, Jun 20, 2022 at 11:13:03PM +0000, Ashish Kalra wrote: > > > From: Brijesh Singh > > > > > > When SEV-SNP is enabled in the guest, the hardware places restrictions on > > > all memory accesses based on the contents of the RMP table. When hardware > > > encounters RMP check failure caused by the guest memory access it raises > > > the #NPF. The error code contains additional information on the access > > > type. See the APM volume 2 for additional information. > > > > > > Signed-off-by: Brijesh Singh > > > --- > > > arch/x86/kvm/svm/sev.c | 76 ++++++++++++++++++++++++++++++++++++++++++ > > > arch/x86/kvm/svm/svm.c | 14 +++++--- > > > 2 files changed, 86 insertions(+), 4 deletions(-) > > > > > > diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c > > > index 4ed90331bca0..7fc0fad87054 100644 > > > --- a/arch/x86/kvm/svm/sev.c > > > +++ b/arch/x86/kvm/svm/sev.c > > > @@ -4009,3 +4009,79 @@ void sev_post_unmap_gfn(struct kvm *kvm, gfn_t gfn, kvm_pfn_t pfn) > > > > > > spin_unlock(&sev->psc_lock); > > > } > > > + > > > +void handle_rmp_page_fault(struct kvm_vcpu *vcpu, gpa_t gpa, u64 error_code) > > > +{ > > > + int rmp_level, npt_level, rc, assigned; > > > + struct kvm *kvm = vcpu->kvm; > > > + gfn_t gfn = gpa_to_gfn(gpa); > > > + bool need_psc = false; > > > + enum psc_op psc_op; > > > + kvm_pfn_t pfn; > > > + bool private; > > > + > > > + write_lock(&kvm->mmu_lock); > > > + > > > + if (unlikely(!kvm_mmu_get_tdp_walk(vcpu, gpa, &pfn, &npt_level))) > > > > This function does not exist. Should it be kvm_mmu_get_tdp_page? > > Ugh, ignore that. > > This the actual issue: > > $ git grep kvm_mmu_get_tdp_walk > arch/x86/kvm/mmu/mmu.c:bool kvm_mmu_get_tdp_walk(struct kvm_vcpu *vcpu, gpa_t gpa, kvm_pfn_t *pfn, int *level) > arch/x86/kvm/mmu/mmu.c:EXPORT_SYMBOL_GPL(kvm_mmu_get_tdp_walk); > arch/x86/kvm/svm/sev.c: rc = kvm_mmu_get_tdp_walk(vcpu, gpa, &pfn, &npt_level); > > It's not declared in any header. diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h index 0e1f4d92b89b..33267f619e61 100644 --- a/arch/x86/kvm/mmu.h +++ b/arch/x86/kvm/mmu.h @@ -164,6 +164,8 @@ static inline void kvm_mmu_load_pgd(struct kvm_vcpu *vcpu) kvm_pfn_t kvm_mmu_map_tdp_page(struct kvm_vcpu *vcpu, gpa_t gpa, u32 error_code, int max_level); +bool kvm_mmu_get_tdp_walk(struct kvm_vcpu *vcpu, gpa_t gpa, kvm_pfn_t *pfn, int *level): + /* * Check if a given access (described through the I/D, W/R and U/S bits of a * page fault error code pfec) causes a permission fault with the given PTE BTW, kvm_mmu_map_tdp_page() ought to be in single line since it's less than 100 characters. BR, Jarkko