From patchwork Wed Dec 14 19:39:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13073453 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 6E54FC4332F for ; Wed, 14 Dec 2022 19:59:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 131208E0005; Wed, 14 Dec 2022 14:59:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0E1C68E0002; Wed, 14 Dec 2022 14:59:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EC55A8E0005; Wed, 14 Dec 2022 14:59:05 -0500 (EST) 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 DC79B8E0002 for ; Wed, 14 Dec 2022 14:59:05 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C2803C0F68 for ; Wed, 14 Dec 2022 19:59:05 +0000 (UTC) X-FDA: 80241975450.01.D2A35B7 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2067.outbound.protection.outlook.com [40.107.100.67]) by imf04.hostedemail.com (Postfix) with ESMTP id F033D40007 for ; Wed, 14 Dec 2022 19:59:02 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=JgkA0n3S; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf04.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.100.67 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1671047943; 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=c9OMyyUVR8eMaZT1tXrQgQK+Hcvc0WsRBQ75uDBC6AQ=; b=cr/yP+F6TwelY9pJwA4PfBSn20t3CHD+6Gk8p6iZplm7CXxcvqdpsHOS/buA1LcORhVoL5 0MwLg/jawJOKKGnya0snY4aynGbouX1xOVM/xJCqZEgm1/acXOPjJjk7UlWJmZzyx32/2H BUxIwzSyTTEAiNcbrQ++UZJXVew5ak0= ARC-Authentication-Results: i=2; imf04.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=JgkA0n3S; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf04.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.100.67 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1671047943; a=rsa-sha256; cv=pass; b=HJuNHjtxqdJFwpnrAqsP/A2nlbZy7gpbs7B/U0ufNno9akn9a55mN6EV4086jEDgQi/TKa thz1hp+//fcEOW6du0wuRP/zZCzhp+QBz0w4zzhqapK/wWl0PEkiv3snAATwgSPFg/V7jD GgMQUQw+GkB9gnupAM3hHTEbCGGPpZk= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jooYwiNZmsaLaKLqUl7rYJpLA4A+Uz0YsJIGIvaYyaDNa4QKamvzuH/TdI83Bl+WMQxQTPR2til4UG4anGO6Fh/oRnBs9/hRfEa2gyZ9WqCu0BPwgkJgk6DORhH68CNJ8DhgYdY6ovmeS/sNAFHqAHpFSGGJdgGBhCFUgdJfAYIfeI7Wgh+CDnHrUN1+u3+8cSN/SdhMGgzr/Mjj0v+hyfjKbRRhbjaflXt2mFn4+LMWR7ZUWZ70m2i7C372YRIWhCznsJ1MGSBm87pUzhhe29zTPkZtr2tv+ClxJjvPSZ3xGv4n/wjO1A6tcbMC7nxLxyIiksmSjfElS0bKAjB19w== 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=c9OMyyUVR8eMaZT1tXrQgQK+Hcvc0WsRBQ75uDBC6AQ=; b=fm4lpT5Vsn2LXI00MJLqc9rSW07ljgbxHYbNEpAcIIsjxdhmf8brwF99RNxvlp8ihPhQJRlIe0dQkyOfdDI/CRyzVpsH8k1hRw3HDCJ4ieZwOSmMY2ftZLN8P2lVxs96I6ziWqVR9I8w9J0iITUacJJN/VLxsSv5IrxuwHRcU9TbmvnA1SVcmwChIV2X1pjrjy4QYCdPGP4a5niIqZGnhYe/+rlvTuXe/g54cDXo4uaGUB68dacgy81ASwub3WeW9/e3yS7VeVzEP+U4LoCvk3siKEmczWPjhNrciKsh4VUn4i/NK6QIn9AaloKroi/05t5YNw84RKezaoGuOw4UMg== 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=c9OMyyUVR8eMaZT1tXrQgQK+Hcvc0WsRBQ75uDBC6AQ=; b=JgkA0n3SIzbwKW9uA1deQkmrVDRQJ9Jmb5B4rm3nONVnNooXzF2b4VT8XIOPdfNUeoQgZars975Bv1ybYOGuI4lCnXI7sSx72ksze2gMTmv9Ct90r3KMtPK80RCJluix931tcrhvfqVxvG1jjIOzYPbcn4XU7LxB7gmKhme8z38= Received: from DS7PR05CA0092.namprd05.prod.outlook.com (2603:10b6:8:56::10) by BY5PR12MB4260.namprd12.prod.outlook.com (2603:10b6:a03:206::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.19; Wed, 14 Dec 2022 19:59:00 +0000 Received: from CY4PEPF0000C971.namprd02.prod.outlook.com (2603:10b6:8:56:cafe::23) by DS7PR05CA0092.outlook.office365.com (2603:10b6:8:56::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.5 via Frontend Transport; Wed, 14 Dec 2022 19:58:59 +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 CY4PEPF0000C971.mail.protection.outlook.com (10.167.242.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5924.10 via Frontend Transport; Wed, 14 Dec 2022 19:58:59 +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.2375.34; Wed, 14 Dec 2022 13:58:58 -0600 From: Michael Roth To: CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Nikunj A Dadhania Subject: [PATCH RFC v7 03/64] KVM: SVM: Advertise private memory support to KVM Date: Wed, 14 Dec 2022 13:39:55 -0600 Message-ID: <20221214194056.161492-4-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221214194056.161492-1-michael.roth@amd.com> References: <20221214194056.161492-1-michael.roth@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000C971:EE_|BY5PR12MB4260:EE_ X-MS-Office365-Filtering-Correlation-Id: 9dfc367c-6ec4-4aea-1bca-08dade0da42b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6Y02O8URML45FklxAygMIa+ZCM/fa5PynNut5ZWgKQTA6ztUAqY6Y76SyEX+V9QP6vwvXypz2PCx/aRXc0rsa9UrkVyQ6uGHeQSTJin+jFLkygvTrai9HcJA6e/NGK0ExAyiDJEK1kKXuf8YdNIpUsf2zVLdVCEH+y8tDnj01Sdg4+BS1o2qTysbAD2VrlGLBkb+WoMZD4glNfSQyNkM0fYBvkLXW+lQr4whROflha8qQm7ZRDJGJ5HZjKIqZqAzaMGQFQV6Tjw9VFBHJ8WsQG/nBijBCgvFUo9So7VwKHRHbfKnavFdkBNvNhqCtOmnjweRLtMdTB62ckrYxOppR+H7d62Nop75G14pS3efm8Gm4K2bcedo3CDTtna+10wylvYsuExGtc5+LiqvT5KVjqPLSI10aiCXd312ZKkUTeXblrJ6AJkq0rpNH7WxBICy8cQndx7/kgvgTkSy0Y9EsraZRi7PE11SOpz+qn4qjPxSLqo5/O1VSMakJrQTTjwvLcpg1XN33Wo3+IoG+a4z05VNd9l3sG9aY/eJwVKTlyC+nGgPRPss/w1hEgy+s7jX8B5hZaVgtc2fYUwPT0duiJbFmxnjZPE/D+R2q8wT6ATcfCdc8sEvyegv/bPiph/jjQ/ZcHIIVwgEqjWbc0jvRjufc4AGYHK3dMc2wwvH+S3Q30CQuu91CAQS5zGrabiU+tDttUJwY2CWnuZZ4g4D00oykrNeWYSTTdTbXJqJuLE= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:CA;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(136003)(396003)(346002)(39860400002)(376002)(451199015)(36840700001)(46966006)(40470700004)(82740400003)(478600001)(2616005)(26005)(36756003)(16526019)(8936002)(47076005)(70586007)(40460700003)(1076003)(70206006)(82310400005)(8676002)(6916009)(54906003)(6666004)(4326008)(316002)(86362001)(40480700001)(2906002)(81166007)(356005)(44832011)(41300700001)(7406005)(83380400001)(336012)(5660300002)(186003)(426003)(7416002)(36860700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Dec 2022 19:58:59.5326 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9dfc367c-6ec4-4aea-1bca-08dade0da42b 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: CY4PEPF0000C971.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4260 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: F033D40007 X-Rspam-User: X-Stat-Signature: t3wmtafmaydhg4jaei1jcz59kysahbdz X-HE-Tag: 1671047942-143820 X-HE-Meta: U2FsdGVkX18/fbT5Mr0z0/evAiulWlLqrjZaWCRanBS4KEiiY0PWhtVMRL4sKSaGCfyclKZCE8Y6u8AYjTiNYLWW5aWQgn1+6oT0QhC39F+O4CNKJnZMLd8D/6KGlrhCt4cqy1Etkh8a5LPqG6H77U52DXeyM8plzJL0Q9mmodo9ABRnT13eYP5W9Qa+ZwKUANnfGfNcYJWJPzWeLxfEqsvn+DqzBqMrJcJ4ZdtcdNnWfjTmBGY1bgiRAgVEczlqoNEzjsRCT7CVSJZb7zlXGrd2NydxTa8vqLkNgdWlgxqY85uyMfskHtAY3Gu04i3qLVsCJG0QcSjtvPHhn146j8rkL9+O0hEmlPmYO50Aj+ETk0ZxAxXNCWar+5aiyV953qyJ35BJpfHcCGJqcJ3sSYXz2eNnGxec7RctlNaCZNpAxm6OP7YFff7MKLwe3mX0CuOf6zvUxTCJgjmSEBiohv5ZeEyiOa+SU11rfJ3cP1yHwfjCRJKIMnOWeEanpvS9MnB/thB00zbcx3/KWTMUwGaUKu9q7KRRttMaUUufpF0zt+MyFcRu1nFwrZqanxX3GrQk+befsIJo93wpMIs6sGnDyP7KDle65V1lqClhcr3Dt4UjowewjEXIUTaJ9N3nZWi67xymH59nBf0pD4al9ifV4Xh5CkD0KIY2hglMHr8PLJ55x4vkNwRaN+Du+CD37B+4LwXUSaLCFqwdKRj9tFJP8gnCBavq3+jKiIgbfVDgL7pFN5MwCLrpzXxP++VnISCHe14GSj2QVZAMN/fuOKt3dyU6tV0JyCxWGeiI/LXeOQNtgJua7fExvbdzYetvojJ2CD3ElI8saBJVngcgwTlawG7/NNOjDpnKVtVdaBMvUD0kjK2xaGI+EhtQ/Tcd75OrY0q4qFHmeO/CnMqO/SLUEs09hyd05kA63gnfhV9AJHBiOkyf/mx81V56sDxSIV4j+YP/UCrqnCTtfeS wuGv9Wt3 SDoOy 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: From: Nikunj A Dadhania KVM should use private memory for guests that have upm_mode flag set. Add a kvm_x86_ops hook for determining UPM support that accounts for this situation by only enabling UPM test mode in the case of non-SEV guests. Signed-off-by: Nikunj A Dadhania [mdr: add x86 hook for determining restricted/private memory support] Signed-off-by: Michael Roth --- arch/x86/include/asm/kvm-x86-ops.h | 1 + arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/svm/svm.c | 10 ++++++++++ arch/x86/kvm/x86.c | 8 ++++++++ 4 files changed, 20 insertions(+) diff --git a/arch/x86/include/asm/kvm-x86-ops.h b/arch/x86/include/asm/kvm-x86-ops.h index abccd51dcfca..f530a550c092 100644 --- a/arch/x86/include/asm/kvm-x86-ops.h +++ b/arch/x86/include/asm/kvm-x86-ops.h @@ -131,6 +131,7 @@ KVM_X86_OP(msr_filter_changed) KVM_X86_OP(complete_emulated_msr) KVM_X86_OP(vcpu_deliver_sipi_vector) KVM_X86_OP_OPTIONAL_RET0(vcpu_get_apicv_inhibit_reasons); +KVM_X86_OP_OPTIONAL_RET0(private_mem_enabled); #undef KVM_X86_OP #undef KVM_X86_OP_OPTIONAL diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 2b6244525107..9317abffbf68 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1635,6 +1635,7 @@ struct kvm_x86_ops { void (*load_mmu_pgd)(struct kvm_vcpu *vcpu, hpa_t root_hpa, int root_level); + int (*private_mem_enabled)(struct kvm *kvm); bool (*has_wbinvd_exit)(void); diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 91352d692845..7f3e4d91c0c6 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4694,6 +4694,14 @@ static int svm_vm_init(struct kvm *kvm) return 0; } +static int svm_private_mem_enabled(struct kvm *kvm) +{ + if (sev_guest(kvm)) + return kvm->arch.upm_mode ? 1 : 0; + + return IS_ENABLED(CONFIG_HAVE_KVM_PRIVATE_MEM_TESTING) ? 1 : 0; +} + static struct kvm_x86_ops svm_x86_ops __initdata = { .name = "kvm_amd", @@ -4774,6 +4782,8 @@ static struct kvm_x86_ops svm_x86_ops __initdata = { .vcpu_after_set_cpuid = svm_vcpu_after_set_cpuid, + .private_mem_enabled = svm_private_mem_enabled, + .has_wbinvd_exit = svm_has_wbinvd_exit, .get_l2_tsc_offset = svm_get_l2_tsc_offset, diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 99ecf99bc4d2..bb6adb216054 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -12266,6 +12266,14 @@ void __user * __x86_set_memory_region(struct kvm *kvm, int id, gpa_t gpa, } EXPORT_SYMBOL_GPL(__x86_set_memory_region); +bool kvm_arch_has_private_mem(struct kvm *kvm) +{ + if (static_call(kvm_x86_private_mem_enabled)(kvm)) + return true; + + return false; +} + void kvm_arch_pre_destroy_vm(struct kvm *kvm) { kvm_mmu_pre_destroy_vm(kvm);