From patchwork Tue Dec 1 00:48:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11941721 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9AA0CC63777 for ; Tue, 1 Dec 2020 00:49:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 61B1020857 for ; Tue, 1 Dec 2020 00:49:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="JjtJ9NSt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731101AbgLAAs5 (ORCPT ); Mon, 30 Nov 2020 19:48:57 -0500 Received: from mail-bn7nam10on2050.outbound.protection.outlook.com ([40.107.92.50]:4864 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727940AbgLAAs4 (ORCPT ); Mon, 30 Nov 2020 19:48:56 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nsr8Y0EOF3fiUrlon3vyA3F6Cz0lZN/j8an23XZ0bWimunv6L7rZ8THpXkZP7tNAm+w3FiDNvhG4lfsDDhd2X2Xc3kUE5IHZHttveQFajw4l85GPlhDZaiwCLMFedaif5UXDK1pkVWd46xcTy8MCJ4QFgulFv6zOsHKJBWwjnwwC3n1QjHfc6jSOYUGf/h5C3I8vwI3tZsLnrGB+MfPrYmB/joABf1Po6mQZe44/XFyrGTtXHDKgKcNpdD0SksQ9HHdg8O2Ih2wlj2K19ZZlbhX+KPhLdugJWF76XdtubRZjvrw2Rn6OL3PQDGjtlNav8hMJ6BfBTir9Z2P5nGkX6Q== 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=QVG+eUxGHSAHvJ6FCq1B3tjxHdMSDf14B/hANqfY+IU=; b=DudJVlEpMAiU+s6RaUWUP2QrGisW/mYwoJl/pmmG7Cd4uSt+bFOWBVLbXd2ny1h11Z6B+RFCmRkDReM8nPdqO7rrpnmKebiKV+gIyFknfYHcfv0aZG9dqcTKUp7A77lYJGj9DroTMqJdpuSO/tcdPIsuxSRfANVOYw98u+8WniyX+jw1i4Sh4Q7YvxveC6qzrCrpcc1XouzSqqSK++dlDZvY77MrtU6XZORoPA7ENyXjIbrDBcfci4EKqDRNF3/7bIII7mbuB8yU9MMMTRnfOqvHTo1xtwPCc8jh1lIVVmx9kD/24GRVcj4wMJtFwBumb5ZJ2i/QldvRQzmo9vcw9Q== 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=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QVG+eUxGHSAHvJ6FCq1B3tjxHdMSDf14B/hANqfY+IU=; b=JjtJ9NStxsZNK6LtF1/6ForDCqcZmR4PpuvBUB50dK+QIDw0vQss29o7LakbfZHnJ09fEF1kJZt0ZdwDe43xXXxuWeVVy1cq0gUFgm0ogZLmOktGLf5PCvDhcWJjdXWXIYXHAmYNVbjGnbOqybSy16WxL8DzYyqWYBcxtuvMpiw= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) by SN6PR12MB4751.namprd12.prod.outlook.com (2603:10b6:805:df::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.24; Tue, 1 Dec 2020 00:48:17 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::d8f2:fde4:5e1d:afec]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::d8f2:fde4:5e1d:afec%3]) with mapi id 15.20.3611.025; Tue, 1 Dec 2020 00:48:17 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, bp@suse.de, thomas.lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, srutherford@google.com, brijesh.singh@amd.com, dovmurik@linux.vnet.ibm.com, tobin@ibm.com, jejb@linux.ibm.com, frankeh@us.ibm.com, dgilbert@redhat.com Subject: [PATCH v2 7/9] KVM: x86: Mark _bss_decrypted section variables as decrypted in page encryption bitmap. Date: Tue, 1 Dec 2020 00:48:07 +0000 Message-Id: <047c39df25282c07cb3180a5c3a63f27ec8be134.1606782580.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: DM5PR20CA0009.namprd20.prod.outlook.com (2603:10b6:3:93::19) To SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by DM5PR20CA0009.namprd20.prod.outlook.com (2603:10b6:3:93::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.20 via Frontend Transport; Tue, 1 Dec 2020 00:48:16 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 21497cef-338e-49e5-adb0-08d89592cae9 X-MS-TrafficTypeDiagnostic: SN6PR12MB4751: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ScZbNw6dhzIMG2YE/23P0CDAoFHNcO5LEeWr7DhJCoo5SmK/IDj9flHL2v9Dp88Z8AUA/AUHB3o09cJyB+K3tk+o1eyBHBX1YFEvRN65e6w1eOXdnCf5+tR20QmLUdm/XHCH6FkBI9/rSbOc4tuk6CjYi7gsOouicmTTmXd6HTp/eb/Y1AGBJPmOcaw0DgFzsCcIg05YvAw69p4c7zIR4BNk4pZJ7F0rMZ7vz1OcZ0CmNWY9rjX0NmMlPFah3QVhoBLnObL6a1WvCqBjSHONLEiS368BJr9SzZy5PyxSzdHQaRlAJLy3z7jCn9Nz3TCpFra94VmdFHp08MHSyI9nmA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2767.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(396003)(346002)(366004)(39860400002)(136003)(83380400001)(6666004)(186003)(2616005)(6916009)(478600001)(4326008)(316002)(16526019)(52116002)(956004)(26005)(6486002)(7696005)(8936002)(8676002)(7416002)(86362001)(66946007)(66476007)(5660300002)(66556008)(2906002)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: HovFRfkOk574YP1G83wgF/fRppQWxPsvwvZehONwRCrttqGWhC/bbcj079MNu904CkB3iYsDUycJBnwXecMMgCgTlFR8fg7dDeyQcfm20VlO6DJyKQ1TpD2SdEPqc9bgNefGyK8U8WTFv+OsSnbfrn95YKCINBBy68W3QcqbM/uH83ydWIYq2GySUR0PbiiJmIfSOD+zPGdNRBymZkW0cTE6dxxCSAoxfG7xfK7WFdN87gnTat7lptO6eDlamoFsX1dsd804fxF5tpzGtgFDlgyakrKFOoCJ6g0ovSKDEqAiZawtbg9JEwIdgC4SUatf0kjenlgBbAKvcB8059URJxJXOji/0mk5N+9IrLQN1rbSXKYiZs0PzNrPgO0wtfBeN59/yvxC+p+BftbKMyI7U6sDKxkZxz9o85xvMCDvHDcdSqiZ+OrvAmGS3K2U1UGyES2x5Q3jvbayjd5Ih1GbWhcr/qd2B5xn2ws5TcSwJ5156y1rVc3fJmvFv/vYLpwJmJ8ha7RRMJCw/WoiyOSxv9a8shhh7Rjutzow06clbaxPp9n5KXX15bNyX9W5JJnYa7ZauACHLjMtfcAAgGElrxhNS2wAuXSLkAR5ramA9T34yangcsu5WWEJFOL1Lk2/3ADUQjQA2EIoB1GjL9jlIDE38ScrYKmWLldqC0bvIfpFjHQz4zVGP5YmqceCP4wM5uXmROqsA9zDyluD4aVBtS/f/FrXUNYH3ihW4rZIc0xnQ0nktwrX23kTYteQ+RP6t149rkZEh7L0cInEmnQyl1HND81TfKYvl81/jaqV0mG5n9cYszPTw0khrJa2KHBElnU0xb/eaSLK5nyQO3OD2/NOB/LbkWq94go2MbsG+/KsfO7MZpS5XiN/Ee7rWm1kKpChf/YMrRHUzVvHrt+APW01AH4PIRMkfdOBkEADQvivYiMGn21N1GkybzaNw/oGGXR9ZqEMsLSlXPHEMk5lPKC3tqOrVaM6MMNuKiwxB6Xlt5I+oufoyxRIsrj8AZWg X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 21497cef-338e-49e5-adb0-08d89592cae9 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2020 00:48:17.6800 (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: zxAltgtlvbQbFer5ZGclx4pjMkeqGPTaCns3ZYHNSYuL4C0v9bFUVWZFkczOZ9+/DebeEx2aliZiUI3X+j9fIg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB4751 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Ashish Kalra Ensure that _bss_decrypted section variables such as hv_clock_boot and wall_clock are marked as decrypted in the page encryption bitmap if sev guest is active. Signed-off-by: Ashish Kalra --- arch/x86/include/asm/mem_encrypt.h | 4 ++++ arch/x86/kernel/kvmclock.c | 12 ++++++++++++ arch/x86/mm/mem_encrypt.c | 6 ++++++ 3 files changed, 22 insertions(+) diff --git a/arch/x86/include/asm/mem_encrypt.h b/arch/x86/include/asm/mem_encrypt.h index 2f62bbdd9d12..a4fd6a4229eb 100644 --- a/arch/x86/include/asm/mem_encrypt.h +++ b/arch/x86/include/asm/mem_encrypt.h @@ -43,6 +43,8 @@ void __init sme_enable(struct boot_params *bp); int __init early_set_memory_decrypted(unsigned long vaddr, unsigned long size); int __init early_set_memory_encrypted(unsigned long vaddr, unsigned long size); +void __init early_set_mem_enc_dec_hypercall(unsigned long vaddr, int npages, + bool enc); void __init mem_encrypt_free_decrypted_mem(void); @@ -82,6 +84,8 @@ static inline int __init early_set_memory_decrypted(unsigned long vaddr, unsigned long size) { return 0; } static inline int __init early_set_memory_encrypted(unsigned long vaddr, unsigned long size) { return 0; } +static inline void __init +early_set_mem_enc_dec_hypercall(unsigned long vaddr, int npages, bool enc) {} static inline void mem_encrypt_free_decrypted_mem(void) { } diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c index aa593743acf6..94a4fbf80e44 100644 --- a/arch/x86/kernel/kvmclock.c +++ b/arch/x86/kernel/kvmclock.c @@ -333,6 +333,18 @@ void __init kvmclock_init(void) pr_info("kvm-clock: Using msrs %x and %x", msr_kvm_system_time, msr_kvm_wall_clock); + if (sev_active()) { + unsigned long nr_pages; + /* + * sizeof(hv_clock_boot) is already PAGE_SIZE aligned + */ + early_set_mem_enc_dec_hypercall((unsigned long)hv_clock_boot, + 1, 0); + nr_pages = DIV_ROUND_UP(sizeof(wall_clock), PAGE_SIZE); + early_set_mem_enc_dec_hypercall((unsigned long)&wall_clock, + nr_pages, 0); + } + this_cpu_write(hv_clock_per_cpu, &hv_clock_boot[0]); kvm_register_clock("primary cpu clock"); pvclock_set_pvti_cpu0_va(hv_clock_boot); diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c index 9d1ac65050d0..1bcfbcd2bfd7 100644 --- a/arch/x86/mm/mem_encrypt.c +++ b/arch/x86/mm/mem_encrypt.c @@ -376,6 +376,12 @@ int __init early_set_memory_encrypted(unsigned long vaddr, unsigned long size) return early_set_memory_enc_dec(vaddr, size, true); } +void __init early_set_mem_enc_dec_hypercall(unsigned long vaddr, int npages, + bool enc) +{ + set_memory_enc_dec_hypercall(vaddr, npages, enc); +} + /* * SME and SEV are very similar but they are not the same, so there are * times that the kernel will need to distinguish between SME and SEV. The