From patchwork Mon Jun 12 04:25:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13275583 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 5445FC7EE25 for ; Mon, 12 Jun 2023 04:57:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DEE236B0074; Mon, 12 Jun 2023 00:57:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D9D2E6B0075; Mon, 12 Jun 2023 00:57:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C65788E0002; Mon, 12 Jun 2023 00:57:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id B88836B0074 for ; Mon, 12 Jun 2023 00:57:13 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 862FC120110 for ; Mon, 12 Jun 2023 04:57:13 +0000 (UTC) X-FDA: 80892886746.15.DEE2533 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2046.outbound.protection.outlook.com [40.107.93.46]) by imf26.hostedemail.com (Postfix) with ESMTP id 9CB5D140002 for ; Mon, 12 Jun 2023 04:57:10 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=xMJCEKRt; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf26.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.93.46 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1686545830; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=s6CZtGI3H4GAYAVMJzlyGlbmtiu/olxIiSDrYkbBXYE=; b=8c10ySD8GP7V7rWpDMqTLmRA6sUNvis/XG6S6iIlBaN+T6cxotQcbPkhhwZQvhmO+9K8VC YRjGXyBW7zIijLI7RhZ16WTD3Jzm4lj/Rl/ykZCjXQiHJs3tKtaXBNMWysNhriIa/czl0z +nyCQYYb3G6J5z+Voub8ARxnKDrFgmY= ARC-Authentication-Results: i=2; imf26.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=xMJCEKRt; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf26.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.93.46 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1686545830; a=rsa-sha256; cv=pass; b=VAjn0v0GoUxAoxPj/2r5z2QE215OudpMKUrah3UscZeGCFLfXSeFpme8qPeQFel+Or43oB k/S+cslar/HR5ZLv8CHxLAP7roZxQKzA+8ZuL5yhlh1/H/WQj3cdgC7Auz4qaAUdfVkJl7 LSImljWYOZLXeHRW6t995fZcADecHlU= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dSMM1sXVfktDwQu5Bw0PhsI5OLEzWTkpBZHZ364Ea5i4m7nou3FRlLghQ+gYmxAz/yXxAkVKqqCGW4Ka6ddFdrOYCWBRcGPWogi5NJ+KG5VKsggdPJ/2mDk+aw/qH9O0U1nkzbpKepOWVv9EaJLpHDxMIVH558oWGeEq7bYzyhvM76/hzkCSLARDorN0ifg1bJwKVPvx3bGz54GDHTRhDHN6+8BIH5ytetXG+5lAHMlZ5jnSd95DUXMyyeYrqtJKvjAWKnzZ1ab/cBCcAfWP/rURyWMFMtcWCWtuIfTeVDAdYVPxv9RPaKj9qgh7ObNRN5wRF/48H+Af83Nvh9TGgQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=s6CZtGI3H4GAYAVMJzlyGlbmtiu/olxIiSDrYkbBXYE=; b=TM1tUeqOjKRmDzl8XGPwzGl6ckRUP0QezfAjHkdwfyUteeDXfb6AaFIMIipt5lXoF2ZYt/5PeTArKA8/6XZoIfIz7f9xDM1iKB7N/hF52ZF1YB7zAmUpMMXWiqijPyEnnJdLvjVfDlrfNWcmMxHMqKiW19YFvKDfXkc24+lJ3tzajS+TnX311mvyd1h1a/Kw14MqFJMfeKKqFsnLxi36UJfN5QNgN35QGGiSSltymChqqw++Div4YG6KXwydTLIL2001BHWmFT1g6bNe7rHGvI8ftxsnRv9Tyh0yzsY6u1WYgHpzY1yaAQukU6mrmRkixyMbdgVOSxPkVix6QFGLrg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); 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=s6CZtGI3H4GAYAVMJzlyGlbmtiu/olxIiSDrYkbBXYE=; b=xMJCEKRtjEGKkQpanHWDrK8bUbDFvm0/4lpDnaYYJ6CA68hdqoVt7tVNkyfqsg6R3N5pYT9IJUOsPLcNnaL7JwuCptNOaUR5miS70VUl0RrdlKFRW01+hmINDK3UvUvEFogzvfuA+kT1eoPY2MxUAibf244aQKNzjBf1HBgFdJU= Received: from DS7PR06CA0022.namprd06.prod.outlook.com (2603:10b6:8:2a::10) by CY8PR12MB7562.namprd12.prod.outlook.com (2603:10b6:930:95::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.44; Mon, 12 Jun 2023 04:57:08 +0000 Received: from CY4PEPF0000E9DA.namprd05.prod.outlook.com (2603:10b6:8:2a:cafe::c2) by DS7PR06CA0022.outlook.office365.com (2603:10b6:8:2a::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.33 via Frontend Transport; Mon, 12 Jun 2023 04:57:08 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000E9DA.mail.protection.outlook.com (10.167.241.79) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6500.22 via Frontend Transport; Mon, 12 Jun 2023 04:57:07 +0000 Received: from localhost (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Sun, 11 Jun 2023 23:56:46 -0500 From: Michael Roth To: CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH RFC v9 04/51] KVM: x86: Determine shared/private faults using a configurable mask Date: Sun, 11 Jun 2023 23:25:12 -0500 Message-ID: <20230612042559.375660-5-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230612042559.375660-1-michael.roth@amd.com> References: <20230612042559.375660-1-michael.roth@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9DA:EE_|CY8PR12MB7562:EE_ X-MS-Office365-Filtering-Correlation-Id: dd3dd272-df8a-4926-2570-08db6b017979 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OlfPSbJS/xpr/4TLPGEjKnOFjpnp/Juw8RbQsmQ1EqJnBCcdOz+FJzdlYDRAtml3CtOffVki5/hyyKRIrJIcRLOLIeQySe7h0Q2YeAL9TmWLc0RsRfwULdmSYSzshhKNQ9i4EIeZ+GeF/8u1m0j7ywv300fkBRkmjJULSGemQ8MXXKt0742UKsWgudd6Lxr++bEkCuBVNjpuBGHTiqcD6ai9/8gLm1sE+UkZpWbnvA2qGye0eEcBs2ZdbB2DP5i96d6AEjUrTH5zrIsTLodVUXCW8mWoWFzZzX0EQUDj7FCMyz7W1DjlKGwdpWFQ0krPtTLx7gUzFpmKG2+68z1JcKLR/NGrVG49O4KN/Ys1sd9AqdvdsSQ2AU+RVbRSVxfcbE8qB2mrMNWBXURBr1nK37ffQuG9E+XcHeW2EyyfQA3swhEGF4hg4SduFfRoPHremf9Bg+TrfslDXVz75mBqhU+Gamk74MjDSPPGpHW/GkhEmMzhD17wtDy3ORSOstDWpAi2gpo41JkSdXqpJdY02yttmDmsf1mSgXrnv3vLmlk2VMwZTWryJMuyE7hWtE3tLDJiCzq2rejGlGnJgpNIFoLX3RRYUogej7Gjb8i14WUQYnqL4HvmR7SeKSzNaAmRAseAR4mbYpJkemedGO0U/vo0H3x7mUDp8dBUaVC3sqZC60lYz9plI/3cDORElA6DRUWtQ5hUhvOAGXypurmB2HVCr8rQURnMo4AzhsM1cK02xXe9vuNUezt8AxX+jzyXpSpSOxeD3vocXDAc/C5Svg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(376002)(346002)(136003)(396003)(451199021)(36840700001)(40470700004)(46966006)(54906003)(5660300002)(6916009)(4326008)(7406005)(7416002)(8936002)(8676002)(44832011)(41300700001)(316002)(186003)(16526019)(2906002)(478600001)(70206006)(70586007)(6666004)(40460700003)(1076003)(356005)(82740400003)(81166007)(40480700001)(26005)(83380400001)(426003)(336012)(47076005)(36860700001)(36756003)(86362001)(82310400005)(2616005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jun 2023 04:57:07.8929 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dd3dd272-df8a-4926-2570-08db6b017979 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000E9DA.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7562 X-Rspamd-Queue-Id: 9CB5D140002 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: bwp9xsqp6frjymrg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1tJnXN0zfu/jz5WdKCLthuO2w/wRMnyV+nzM6uGgSxUdD43TCQyWoAOULtAsNalDshfZLr0ZaVe9GxlZ8WhvCmGdKPxyRWIShKLOcUA5546SDs6Xn46PcJ1pH3eIeBpUbB65QW/qwURW9MrNMZ4CbJaXq+/QEwWJ7Cv8SKtIItaXP9VQ+AThCyTaHVPQEW9NxYI/FErnHrSfKoWauZdCrAh8xWabpUTw4qZpREg3gURXQM0bqFqUljFnw8R4pw== 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: This will be used to determine whether or not an #NPF should be serviced using a normal page vs. a guarded/gmem one. Signed-off-by: Michael Roth --- arch/x86/include/asm/kvm_host.h | 7 +++++++ arch/x86/kvm/mmu/mmu_internal.h | 35 ++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index b3bd24f2a390..c26f76641121 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1445,6 +1445,13 @@ struct kvm_arch { */ #define SPLIT_DESC_CACHE_MIN_NR_OBJECTS (SPTE_ENT_PER_PAGE + 1) struct kvm_mmu_memory_cache split_desc_cache; + + /* + * When set, used to determine whether a fault should be treated as + * private in the context of protected VMs which use a separate gmem + * pool to back private guest pages. + */ + u64 mmu_private_fault_mask; }; struct kvm_vm_stat { diff --git a/arch/x86/kvm/mmu/mmu_internal.h b/arch/x86/kvm/mmu/mmu_internal.h index 780b91e1da9f..9b9e75aa43f4 100644 --- a/arch/x86/kvm/mmu/mmu_internal.h +++ b/arch/x86/kvm/mmu/mmu_internal.h @@ -252,6 +252,39 @@ struct kvm_page_fault { int kvm_tdp_page_fault(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault); +static bool kvm_mmu_fault_is_private(struct kvm *kvm, gpa_t gpa, u64 err) +{ + struct kvm_memory_slot *slot; + bool private_fault = false; + gfn_t gfn = gpa_to_gfn(gpa); + + slot = gfn_to_memslot(kvm, gfn); + if (!slot) { + pr_debug("%s: no slot, GFN: 0x%llx\n", __func__, gfn); + goto out; + } + + if (!kvm_slot_can_be_private(slot)) { + pr_debug("%s: slot is not private, GFN: 0x%llx\n", __func__, gfn); + goto out; + } + + if (kvm->arch.mmu_private_fault_mask) { + private_fault = !!(err & kvm->arch.mmu_private_fault_mask); + goto out; + } + + /* + * Handling below is for UPM self-tests and guests that treat userspace + * as the authority on whether a fault should be private or not. + */ + private_fault = kvm_mem_is_private(kvm, gpa >> PAGE_SHIFT); + +out: + pr_debug("%s: GFN: 0x%llx, private: %d\n", __func__, gfn, private_fault); + return private_fault; +} + /* * Return values of handle_mmio_page_fault(), mmu.page_fault(), fast_page_fault(), * and of course kvm_mmu_do_page_fault(). @@ -301,7 +334,7 @@ static inline int kvm_mmu_do_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, .max_level = KVM_MAX_HUGEPAGE_LEVEL, .req_level = PG_LEVEL_4K, .goal_level = PG_LEVEL_4K, - .is_private = kvm_mem_is_private(vcpu->kvm, cr2_or_gpa >> PAGE_SHIFT), + .is_private = kvm_mmu_fault_is_private(vcpu->kvm, cr2_or_gpa, err), }; int r;