From patchwork Wed Dec 14 19:39:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13073498 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 6947BC4332F for ; Wed, 14 Dec 2022 20:06:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 105AF8E001A; Wed, 14 Dec 2022 15:06:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0DC7C8E0002; Wed, 14 Dec 2022 15:06:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EBED78E001A; Wed, 14 Dec 2022 15:06:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id DD0288E0002 for ; Wed, 14 Dec 2022 15:06:47 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id A9BF2802AC for ; Wed, 14 Dec 2022 20:06:47 +0000 (UTC) X-FDA: 80241994854.11.2FCB251 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2072.outbound.protection.outlook.com [40.107.93.72]) by imf29.hostedemail.com (Postfix) with ESMTP id D0BF712000E for ; Wed, 14 Dec 2022 20:06:44 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=q3NnRn6p; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf29.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.93.72 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=1671048405; 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=oDqQcjWyY2cIFrvOsbgzHIjD9E0pfLSJhyuXKLlLr8s=; b=tJfDs4biDYOsc7zt7EtnJLxfyOpht5lMu6MNyPs3Pcsi9UH6FjWmGiBUtv+E+FnKfI5x3s GgX0qSchK4JaiVPuB4xKYelatNEq90ypWQ0s5TA1pkVpqPO49fzZLU89UieuTKaw5oNVDC fQnU4Xvsnwe9sIzH9YeiLxqV9l5E8+Q= ARC-Authentication-Results: i=2; imf29.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=q3NnRn6p; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf29.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.93.72 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=1671048405; a=rsa-sha256; cv=pass; b=iz3iHNHC0upFb32V6y6OfhGYCqaaaehbBxnyRKY9/GqLNVAtBTkyvVJcQ/SnjDo7/g2G35 RahVZ0wZv6QSzCw/zH3w7STLzwGhDwRkKTSAyVjQXGmB0//uAQqyBjFZ5IWcHub0VZGi7+ RSqMCT3DzYK2l38cerVLompUoQtIOiM= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e0sunLe5fQ1Kdu9fSnWOX2E0oV9bFUA96BYOt5fQ0jZhIJ4yW8Ui5UQ/Pcw/Ynd87RKYetMDRRW7Lvp8o0WVslK0AmjQ7vrekaogE6ZzU8yzPyqtBAQX1ITwq+g7DaYUTKQ5CZa43B49G2gLJc+fwxT8cOjOnYHbxDErCm3nmURIPHFjNS2NCXORilfyMu3NVmktT3ORTKqrWtdLwpQPFGXhhNx1j8qrm3jV7RFO1tW0a/ZhdWjlmFe4mC2NJT8hASd2/WU8KxZBJcGolLAy0blhBskmCsMnlmouQZEKNT+98aZnuJq1ZO3aWDTheCO4Fkx203lk02aZNtWUeAqNjA== 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=oDqQcjWyY2cIFrvOsbgzHIjD9E0pfLSJhyuXKLlLr8s=; b=PiKnC8ndnZpHj/5Pd1MFOLMzV/DPzpVO6m6Z54fG68yIkYne9AvMlY4OSGe87Cbv0pfQ3LzU2DfzNvkbuPeWFAo5AiS7k0jc4/D0uHOnxnhLIhvGu2YSXe3hpCJLTq1i+uXOFoxQ5ZaW7Sc1S3RWkkJ1CCL840NGAyv/mfXnH++WyIzMqdMuyxZllBhpyV7q8TYIOWtV3hcwQ0fHsAbaIdo4QWREd/LUDDNXBjv3HaP/GgayPr/8Rhkq4EGOqsNlWV4zoDG4CRmf2Pi2L6fYpFVU889NlaeEYueNxB//Oa09w0JwX5rqMT03QpMZXl1AjgvOFKjmhJgSnh4lWBwmKA== 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=oDqQcjWyY2cIFrvOsbgzHIjD9E0pfLSJhyuXKLlLr8s=; b=q3NnRn6phP8ZYit6k9BrPTqI+hpyNWIKhMIG5KA4xgo2PTLvjAwNSEljd2fUfeTV/qSbz+R2w9p44EAccC6Z8MakBg5BhYDD5+kDC6R94UlcApBst+7Y2YqTf/8zsg/BQHVgPpRgEIjE9pu7YM1DFfFSds6mCWzftfmnsJ4n3OI= Received: from MW4PR04CA0164.namprd04.prod.outlook.com (2603:10b6:303:85::19) by BN9PR12MB5161.namprd12.prod.outlook.com (2603:10b6:408:11a::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.11; Wed, 14 Dec 2022 20:06:42 +0000 Received: from CO1NAM11FT063.eop-nam11.prod.protection.outlook.com (2603:10b6:303:85:cafe::6b) by MW4PR04CA0164.outlook.office365.com (2603:10b6:303:85::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.11 via Frontend Transport; Wed, 14 Dec 2022 20:06:42 +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 CO1NAM11FT063.mail.protection.outlook.com (10.13.175.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5924.11 via Frontend Transport; Wed, 14 Dec 2022 20:06:42 +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 14:06:41 -0600 From: Michael Roth To: CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH RFC v7 05/64] KVM: x86: Add 'update_mem_attr' x86 op Date: Wed, 14 Dec 2022 13:39:57 -0600 Message-ID: <20221214194056.161492-6-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: CO1NAM11FT063:EE_|BN9PR12MB5161:EE_ X-MS-Office365-Filtering-Correlation-Id: 17ec48fb-14f8-41fb-83a8-08dade0eb801 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: j9GdpxQggZ8mc4xddKO8SXNdXrz9pFyCn494klrJeSsZe8mcxu0asGOfJvvyHrFvfwQ7pUNiTXZr5CrMIDTM5HAx83u75Rp5YvLyrxo60zqo7Ecp3wroOPSYOpfM6FBWipe6EWJUhRHwLuVFWkZHh3AxGQ9Q79jrdn0l0Byivk//+Qtjp+EOPqVBpvkt1cVTUgIm0lQf3wNKTGA0wgzrli8ENNbKa4atvS7yCEUc1VntAftxP3Kpygi7Vb1LBMVzulwPj8PBaqmztZgflqu37zwod+ob7YzyrB0XzESccxmLYsYGBYBpKXNRXRKa/Yjk1llPpkV8LbKoJZhN5OuLk/qMcLvJMfI4gkFCyobHvSmActk4vBDRuKzrLkZjxSV8437zCgh3NKJOPodFtSg9CcYiTgG+xKpXWHzNd9eaQowvIqiVEcsLLGqbWybl7IWx28pi86OwsfKgC13tr5UW1YfpZbXUo6glFIaGq+keLO1dA6nv07neg4s7NvUE3oniAdFnENhptGNsL7HiJvfJ7HQFEQLS/eXk5tfgOPvVLho6k/riw6OvPYmZ6YIL5nFRRR7tLsFRFqAoR4KOR4pW4ZfbbdcJSFWMHha2fciPZSjjE74PJDjPxm/AzHqMky5NkMmZ/ugPySp7KQaAIn7Xtj84ISY/uO0Curv5MEcvCqB6KIT57aYk9gv+sKFEzI9GaI4iBChxEHcPBtTCXHnwhWSPkpcStI1DTByPTei5fg0= 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)(39860400002)(136003)(396003)(346002)(376002)(451199015)(46966006)(40470700004)(36840700001)(36756003)(2906002)(7416002)(7406005)(40480700001)(36860700001)(40460700003)(5660300002)(336012)(8936002)(44832011)(86362001)(1076003)(2616005)(15650500001)(81166007)(356005)(426003)(47076005)(82740400003)(83380400001)(6916009)(54906003)(186003)(316002)(16526019)(6666004)(82310400005)(4326008)(41300700001)(26005)(8676002)(478600001)(70206006)(70586007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Dec 2022 20:06:42.2799 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 17ec48fb-14f8-41fb-83a8-08dade0eb801 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: CO1NAM11FT063.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5161 X-Rspamd-Queue-Id: D0BF712000E X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: zm87a1tt9a3dpu8hcm1qwrzcocm4cz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HU3fUUHcyJj+flYSgFA== 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 callback will handle any platform-specific handling needed for converting pages between shared/private. Signed-off-by: Michael Roth --- arch/x86/include/asm/kvm-x86-ops.h | 1 + arch/x86/include/asm/kvm_host.h | 2 ++ arch/x86/kvm/mmu/mmu.c | 10 ++++++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/kvm-x86-ops.h b/arch/x86/include/asm/kvm-x86-ops.h index efae987cdce0..52f94a0ba5e9 100644 --- a/arch/x86/include/asm/kvm-x86-ops.h +++ b/arch/x86/include/asm/kvm-x86-ops.h @@ -133,6 +133,7 @@ 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); KVM_X86_OP_OPTIONAL_RET0(fault_is_private); +KVM_X86_OP_OPTIONAL_RET0(update_mem_attr) #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 92539708f062..13802389f0f9 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1637,6 +1637,8 @@ struct kvm_x86_ops { int root_level); int (*private_mem_enabled)(struct kvm *kvm); int (*fault_is_private)(struct kvm *kvm, gpa_t gpa, u64 error_code, bool *private_fault); + int (*update_mem_attr)(struct kvm_memory_slot *slot, unsigned int attr, + gfn_t start, gfn_t end); bool (*has_wbinvd_exit)(void); diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 61a7c221b966..a0c41d391547 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -7130,7 +7130,7 @@ static void kvm_update_lpage_private_shared_mixed(struct kvm *kvm, { unsigned long pages, mask; gfn_t gfn, gfn_end, first, last; - int level; + int level, ret; bool mixed; /* @@ -7153,7 +7153,7 @@ static void kvm_update_lpage_private_shared_mixed(struct kvm *kvm, linfo_set_mixed(gfn, slot, level, mixed); if (first == last) - return; + goto out; for (gfn = first + pages; gfn < last; gfn += pages) linfo_set_mixed(gfn, slot, level, false); @@ -7166,6 +7166,12 @@ static void kvm_update_lpage_private_shared_mixed(struct kvm *kvm, mixed = mem_attrs_mixed(kvm, slot, level, attrs, gfn, gfn_end); linfo_set_mixed(gfn, slot, level, mixed); } + +out: + ret = static_call(kvm_x86_update_mem_attr)(slot, attrs, start, end); + if (ret) + pr_warn_ratelimited("Failed to update GFN range 0x%llx-0x%llx with attributes 0x%lx. Ret: %d\n", + start, end, attrs, ret); } void kvm_arch_set_memory_attributes(struct kvm *kvm,