Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1591517pxb; Fri, 20 Aug 2021 09:05:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwyVeaczBJdQf3U1o4JcwBH+accdkA1XLyXwB4ag0KmHVdY6dnkrKUBOwi71oAUOPd2BKxU X-Received: by 2002:a17:906:b104:: with SMTP id u4mr21496934ejy.201.1629475508066; Fri, 20 Aug 2021 09:05:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1629475508; cv=pass; d=google.com; s=arc-20160816; b=DSSoCNNv5gD8NIYEtlB3NjpeVpHtzO+Iw9bGn8xrFoMi1HNnCnQ7Q20TjwAcxsymIE Q6E2cmxp9kzp93Xhd2eVkNrmQvyE5Luyph6mnREndMRFFn6RhqmvU1dOlXIU9iE7STYU HS9KJBGyDe1Lp5ownC8XCyhQhCLZPG8xvoPtGL21WVmvZSb9sIRa4PacIVNbqSl7nG1X kPugcPm/a2Uic2gAnpMvmdptbYjsjX5sBQR+1ADAKEFGka7GJdjMGP2yPn6tO/ZCcNik K2IIlngIkh0ym6qsGYXc64WKsy9MZW9Gbd9W9gfSoKeas10xE916FxYFSRDkTesR+J+D RB7g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=CP94SxoFqNd03EOGlUpc51w62BGvCOVTDriTneq6T60=; b=VEGgFKyz+4qdLRXHtZ1oLCiE1B3SvPnfCfVS7hY6UAaQCDYRxIxuOCuOpmGmLTPLgk y0WM/3DCJGWFh2YpZMH4ZrMfTMjnyu/d8LkJfgRaubsqEZg1jW5bnUGnjKd0A3URJfUT hE/KQzEd8NdEP3fRg6HZk2kLJYYNvw+RapIR7ublBJtpjcDQzkJ0BBT2Q/nnHufU+U1J gwx01LGT/k6EU9qoPbb8CQdz4clCfoREKicfIMDV+AIIYMlTzr7MffNtZUbVui2fo0ng epKKWtXaY1qYS3LdRcpYl19sUFZykOOju+OLVAbvgSnEMzu+oxjvhzVb4beXo3IEmb2m K3uw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=18DYd1Ph; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nc13si7960340ejc.649.2021.08.20.09.04.28; Fri, 20 Aug 2021 09:05:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=18DYd1Ph; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237569AbhHTQEd (ORCPT + 99 others); Fri, 20 Aug 2021 12:04:33 -0400 Received: from mail-co1nam11on2054.outbound.protection.outlook.com ([40.107.220.54]:58929 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S233093AbhHTQCd (ORCPT ); Fri, 20 Aug 2021 12:02:33 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FjAxHnGTbRuqdIp8z8+3xvWUNgJxMroeaw5EUmoguIkGguPKsVZiwU1bg5M9IRthh18cHpk5ue/aT62w7uFPSE/wDorHnZ8zMNoRDhh7IhdJB3JlFZWIOhJLFB0PuxZ+1Nmlxis/O8Rl+vI+o3tpinl3aQvjGzc6Cwzy/tbHsh29MW/bBqVYSXBn3/esxA3roBRB/uh3F7DLzEwM8W5/DTyoN+EAClLSuyEoKrqKeFnYbZwgyHrv/uJiAh7G5T1MPCFRODW13cNujcVt+qjwugKZEABOs/Eqt++ZRG+iiikxhpLz7078uBoDkkNAe2b+SV33U8mM/TnIZz8nPgI42w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CP94SxoFqNd03EOGlUpc51w62BGvCOVTDriTneq6T60=; b=SYVb7Hgc+n6x4q898sbLmdFrXr0cxkS0ikDB5ZIMBJd7yYaC1GqY2uE1HeV3Tjb7CDzbXk8PuDLizQwgmfW3QH14/D6ea1YYQsh4D9XROm5dt8pTN4iQmDT8mp160c8bRnN40TSUkjIUra6t94E2BLMVz9rO9ccF3iseepvqOSaaN2F0ssLcttJAmJujSPVhUwZ8qW/uWfWzpPAaBIuyJPR0jNdPWB9sRBdkbPDjZadUkCcG+B7lWNOHWeC3gvSvF+5PydeYlQ0MeOmdKqXlXrds5xwS6d7aZRFp1zBTqc/+LBOBSpk0zYtYwGXV/qCKY/HnCskosbBFbmhDSHrCxw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CP94SxoFqNd03EOGlUpc51w62BGvCOVTDriTneq6T60=; b=18DYd1PhqoqETwZqHWw874E5wVC+4XIOFOiUMDv151QhlDCq18AmHkxSTLnZF9HkHYDP7Z0d8Si+ndaMLV+8PZYB2Pjd22ah0a/sWhB1BlHu11jSmBRSe7HY3Rg4ahr+FQUi38LGMcHBCN0hTHoHKk/FxlYG/Sxu5QVr7X6LaOM= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) by SA0PR12MB4574.namprd12.prod.outlook.com (2603:10b6:806:94::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19; Fri, 20 Aug 2021 16:00:32 +0000 Received: from SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::78b7:7336:d363:9be3]) by SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::78b7:7336:d363:9be3%6]) with mapi id 15.20.4436.019; Fri, 20 Aug 2021 16:00:32 +0000 From: Brijesh Singh To: 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 Cc: Thomas Gleixner , Ingo Molnar , Joerg Roedel , Tom Lendacky , "H. Peter Anvin" , Ard Biesheuvel , Paolo Bonzini , Sean Christopherson , 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 , "Kirill A . Shutemov" , Andi Kleen , tony.luck@intel.com, marcorr@google.com, sathyanarayanan.kuppuswamy@linux.intel.com, Sean Christopherson , Isaku Yamahata , Brijesh Singh Subject: [PATCH Part2 v5 30/45] KVM: x86/mmu: Introduce kvm_mmu_map_tdp_page() for use by TDX and SNP Date: Fri, 20 Aug 2021 10:59:03 -0500 Message-Id: <20210820155918.7518-31-brijesh.singh@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210820155918.7518-1-brijesh.singh@amd.com> References: <20210820155918.7518-1-brijesh.singh@amd.com> Content-Type: text/plain X-ClientProxiedBy: SN7P222CA0013.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:124::11) To SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sbrijesh-desktop.amd.com (165.204.77.1) by SN7P222CA0013.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:124::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.18 via Frontend Transport; Fri, 20 Aug 2021 16:00:31 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b8dbf6f4-3a72-4302-b926-08d963f3a38f X-MS-TrafficTypeDiagnostic: SA0PR12MB4574: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nwknKwWUD+Qm7ORkJMQAPR7pB41RMj6/GZZdcc68dB7Dx8QiVGrRMFQi/Wmb7dz6/Eqlp05INYW1UIAjj24ywzhHO0wqiLjCT9cmT+xUETghVQEjYWpONqRJadcyif2iG+MA/GTA47Z7Dh/tnX4+NJJjK74YT8igmyVeWBb9WTgYFJYtgSidrFXibLl2OG7iTByMlLBu+MeQuOL3jIAdUl8R9OEanGm/roU69AU+6N1mW/a4YvL0OY5nEK0DXNi/bO8K6DJJgYsk3beMdimbNA+fRhrS33CyZMvsGsrHYjVHkpFhLm06G4bYoi7xo43nUunlxjJbl/NX6n1Uq58ZJjMUllG1OXEs54aW5W4FwUOOFqQjNz72BFY53DeZwTjPAS/Wlg0qp10zgrpzCsEeyFUr5B5XZIs7rBZk1Y5inkJoKMR1mo+SoXl1o+capy1KNZWibB3XsJkPBTHtpohR31bh4QWYUbdG/TzQ1up0VAAI2+pZmBW1hHzk8R+NUBU42R/IyNTURgv526r/PEkdkh/4Tvw4j7yJ0AoFUapOdpepwubWWfIrQ+cchFZ0YfRPbT9DLfa/At9l82sf+LhEnwP2bwD1w2z98vR5+WS9BSaAli7FpSSErJUJ/OcVWe4UFFOkXhJQh/Qdtg7cLG6bVZZEPAJM79fmELApWYpbjQYUhQ1Vte09iKay13qhBST8 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2718.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(136003)(376002)(396003)(346002)(366004)(39860400002)(1076003)(38100700002)(316002)(38350700002)(5660300002)(26005)(44832011)(4326008)(66556008)(54906003)(7416002)(7406005)(8676002)(66476007)(86362001)(66946007)(6666004)(2616005)(956004)(8936002)(2906002)(36756003)(83380400001)(478600001)(6486002)(7696005)(52116002)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?gS+QGQgUkGRkpD19SDZu97B+ec7ahnWTmr07kZBdmXfMRMz0d8S5Mp35JmUO?= =?us-ascii?Q?LglgcHRY3Adj8pjErDkKvSYzRF7yaL0E6lWEAPb6/RC1e/ju5aZumlGvQiHf?= =?us-ascii?Q?NkIfaPxh0iRNJkAl6ydpXdqg7DIdBdV6mzkaIkcAXXmPbwP60fM+C60ejKON?= =?us-ascii?Q?8VuqynrchXWME9HZ5zbsCscj6vk3SXIoWpi1J1R+Nxq3EIB+uyU7qmVUJ33t?= =?us-ascii?Q?j9mexDg4wAMEq9dL3J2ohRfNRSoCPs1o0NNFgAH7OqHpC7xTw0yPq5UR/jpq?= =?us-ascii?Q?5rfaJQKcDtWT0E+D/QBACbVJWXY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ascii?Q?cLaaIJb0vkAxm/Dg7lLMaAwIkYXCis67xOm8/Qp+eVgC1jIqMNVdSUjBP46M?= =?us-ascii?Q?LOqUwoDnmlby0xDH3w1x+wmt1WDDqOFM1Cdw9r3W4qDEg8n4dUhwmoQ91Yr6?= =?us-ascii?Q?ai5bZPq2z38/aRzfbXId96ok?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: b8dbf6f4-3a72-4302-b926-08d963f3a38f X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2718.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Aug 2021 16:00:32.3812 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: WLGAgpLfZZQ+NkEpiLzARwIpRrD9NjD1WZFmN0pWd/HL/VDuKER6bW1ptPelwIGIAJXMCkquMzmKKC3GdVo+Kg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4574 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Sean Christopherson Introduce a helper to directly (pun intended) fault-in a TDP page without having to go through the full page fault path. This allows TDX to get the resulting pfn and also allows the RET_PF_* enums to stay in mmu.c where they belong. Signed-off-by: Sean Christopherson Signed-off-by: Isaku Yamahata Signed-off-by: Brijesh Singh --- arch/x86/kvm/mmu.h | 3 +++ arch/x86/kvm/mmu/mmu.c | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h index 83e6c6965f1e..af063188d073 100644 --- a/arch/x86/kvm/mmu.h +++ b/arch/x86/kvm/mmu.h @@ -127,6 +127,9 @@ static inline int kvm_mmu_do_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, return vcpu->arch.mmu->page_fault(vcpu, cr2_or_gpa, err, prefault); } +kvm_pfn_t kvm_mmu_map_tdp_page(struct kvm_vcpu *vcpu, gpa_t gpa, + u32 error_code, int max_level); + /* * Currently, we have two sorts of write-protection, a) the first one * write-protects guest page to sync the guest modification, b) another one is diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 5cbcbedcaaa6..a21e64ec048b 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -3948,6 +3948,31 @@ int kvm_tdp_page_fault(struct kvm_vcpu *vcpu, gpa_t gpa, u32 error_code, max_level, true, &pfn); } +kvm_pfn_t kvm_mmu_map_tdp_page(struct kvm_vcpu *vcpu, gpa_t gpa, + u32 error_code, int max_level) +{ + kvm_pfn_t pfn; + int r; + + if (mmu_topup_memory_caches(vcpu, false)) + return KVM_PFN_ERR_FAULT; + + /* + * Loop on the page fault path to handle the case where an mmu_notifier + * invalidation triggers RET_PF_RETRY. In the normal page fault path, + * KVM needs to resume the guest in case the invalidation changed any + * of the page fault properties, i.e. the gpa or error code. For this + * path, the gpa and error code are fixed by the caller, and the caller + * expects failure if and only if the page fault can't be fixed. + */ + do { + r = direct_page_fault(vcpu, gpa, error_code, false, max_level, + true, &pfn); + } while (r == RET_PF_RETRY && !is_error_noslot_pfn(pfn)); + return pfn; +} +EXPORT_SYMBOL_GPL(kvm_mmu_map_tdp_page); + static void nonpaging_init_context(struct kvm_mmu *context) { context->page_fault = nonpaging_page_fault; -- 2.17.1