From patchwork Fri Jun 11 14:26:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 12315827 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham 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 A29A5C48BE0 for ; Fri, 11 Jun 2021 14:26:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7C078613E9 for ; Fri, 11 Jun 2021 14:26:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231272AbhFKO2q (ORCPT ); Fri, 11 Jun 2021 10:28:46 -0400 Received: from mail-mw2nam10on2071.outbound.protection.outlook.com ([40.107.94.71]:15267 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230129AbhFKO2p (ORCPT ); Fri, 11 Jun 2021 10:28:45 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c0/UF19Whx5B8KoEUqNQtPZazYqKIlCxZ5wMQ1LZ57STjLm/xZdvhDVF7vRwl4s4S6MvNJxVOGywIa+DhgaOAyfQCF8dFym6qd1kGL5DcZ0pCSnfAFt4JTpj6BuI1IOr+cA1h7cMAHbmqEKqTyVdefu0IghPEFzgJbnTvNykHrFG1qW6/jlH/N3DsyrQE0+lVMOlYFkDcPhlpO6CsldWP1WgxHsEGhVKk6njn+OvUVHpFs+W+APa5FWEGFMqQpeJan631XtK6kmYr5emx7sBV0g6fmuHf3edQWC9S1ReZsUYK1yXqGzM8As+7dL/FlioaUn77WF/19gLa9GT08QJ+g== 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=1E3ySw2AmPyoVZHlmiT34Tu8uA+MU5chXd+B/qEwiWg=; b=DM3kT+GPp7bGrOQ3FO98PkzRVwrC27Lceqsa0Nd42AZxgGCDbbMe18IvDh8BPab6KaUhgC23hzZoQOB7PcLq+aIWJdGI56QQ/fH3zTuNOyJZ0b3l7xDFpbhFomEq2CEl1irMdRz9Bo/2nbzp8E03ogOCTJm/0MxPf+wcf97DmGOtvmwBMYd5xRwpZAuS419EaLhJusGLHKLe2qVxBcApgo1n0Imotms2L/r8R/lAvX6D5fNxHzr8MojaJj5IzaMdg4a8J55UhohJWJ6ePd7uKuURSp1uQ6+T32fEiF6LwbNXteSATut/TTyyY1kuLHeHDhDYaIEqLtb9nycHVIsdZA== 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=1E3ySw2AmPyoVZHlmiT34Tu8uA+MU5chXd+B/qEwiWg=; b=sDWEsuA5EB3LPxMRMvmSqFphHLQa+cqhFz72BsCJxiHiUvsnsnrvCTOooEtPxfjQmtkqSgT6JC26qNXyIPsqTCRDBPhdyjIkqfC8BDanWz0KRjI+rV1mwoLzJJLB1wHDZy7Aguz76mNUSxcKmLFW/GIlrZksbMfVzi9ulQyb/kg= 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 SA0PR12MB4349.namprd12.prod.outlook.com (2603:10b6:806:98::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.24; Fri, 11 Jun 2021 14:26:46 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::958d:2e44:518c:744c]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::958d:2e44:518c:744c%7]) with mapi id 15.20.4219.024; Fri, 11 Jun 2021 14:26:45 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: seanjc@google.com, tglx@linutronix.de, bp@alien8.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, Thomas.Lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, srutherford@google.com, brijesh.singh@amd.com Subject: [PATCH v4 3/5] mm: x86: Invoke hypercall when page encryption status is changed Date: Fri, 11 Jun 2021 14:26:33 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA0PR11CA0193.namprd11.prod.outlook.com (2603:10b6:806:1bc::18) 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 SA0PR11CA0193.namprd11.prod.outlook.com (2603:10b6:806:1bc::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.20 via Frontend Transport; Fri, 11 Jun 2021 14:26:45 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8475be08-2d5f-4613-ad4f-08d92ce4f0f8 X-MS-TrafficTypeDiagnostic: SA0PR12MB4349: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4502; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YcyxpX6JkF7z84jswj+ShlRUSOArB+++O6lqeqeuo3imsbNWZzIjMAtsQ8udFi/uqgenENJdaduOWlf4+uiGhoaX4QPrB/N17yI8ywKI39IP4B9Qb9QgOA9W1eXvilJ9PhQocuTBRUyL7DQGOWBHkd5E8ZYjOA+YbhjXBn2XC55pN9FcwQ3u1H3kNfM9X+X/+geo1/Ef2kMksiLnIquA3/jtGWYhTt9jQQhG4RGNPAm+n4oWFnhML3G3Fgz8yznRnPGrGRaUVrOps+p1R1ZUt4bue1zaXmPUCDczzHAAmDWJvG3wPL23NlI8eyJhhs5hiB3Hhilqw6zsj7wKouVwfk3L2jatzGYGAYm02U732bg3+JtuC25fd1lqCTmsbkXd9JY+3jnJb58eQVjKEMT0Gwbh6NdDmPp08RJvMXVA3wuO8WyFWxWpvPiVcFwUfRY3mypNPR0nsbyBxDWGL/vVgJFCiyHMEeJ6CDrNzBkqUnHNx0xQD7BvUdCDijJGCe959RykQi0TO6LLs+r5tIGir6VsBimsrtlbWQnN1o9ha6POK9Bt/fwhJh7vZTJsoQZPHJdewpO62H5NSX/2uFO5mqQD+H/U4krP7vteprqiRx9XLNDmnlcYfFjw+kYVfdDRGaiwx+8VhrojQc4imAHnDw== 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)(39860400002)(396003)(376002)(346002)(366004)(136003)(5660300002)(6486002)(66556008)(6666004)(66946007)(83380400001)(66476007)(36756003)(52116002)(7696005)(38100700002)(38350700002)(316002)(956004)(4326008)(2906002)(2616005)(16526019)(7416002)(86362001)(186003)(26005)(8936002)(478600001)(8676002)(6916009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VJBDbpEI7Y9RYqid8fan6tcOOBW7zV6vWooZ2yFj4SagMQc3i58iCtcAGjboSaFf/BgFUvmV6EJEFmvtcsIZSyC2Dbq58hG8hH6GTKXsDEzFzU4OW+RGstGv5OU0pEYvSKJCU8ZxfEFJQBmJif/2+EpX7kGjORRyCh5HEBJi8AoksWmjvwDNFK9rdTugfW7CXidr9lskTt2n/qjJUEMfLBB5AjQxqzvtOdTWyPhvaTTkgcVuweMsxUvCAN99fJk/mdqRLugoz/vFgL1xwn3qMv9hII4F7wSeAVp+4ZzQsJNGNIubDXB+GX6qDhWDw7Dos/EmoJE8oz0H/pMUkZ3hOvrPLZJ6us5coMRd9PizF35/a/qW5lOOKd1pVWtoDL9GDrEIxadjvR7tT44L0cRUJePi9JFyDhuOiH6Q21qT/w1oS4a0mUpAAWEQ0Q12JfU5EdWq5ntnXIi1rbgVJGc5M3NA+2CKYsnZAU+6x6TmAQmoa25779cu7OZj5byN94h1twdx7hwIkbNAgB7YSjVXc3832PlIBx+senN8L0bkY+p+WgbejhHJl+611HwXKYcDZuyolAdoGwajfa95SyqQXyav4HtgQrXSC+31xcEhYQmFvAjCWDXmgs80BUBXcW0ecCcUJLL+6PKB+v356sxGMxya5ePgHzfTisfBBp/Le3gISVTnENPgmLFfTotUXzYT68dQzdHTEBqEeTEHakRhJq5s/IEzNGkZPv8XMNPmTvNmQfeDAUhOWskDx9APxVZ5C7Z/y1kLfFd6UinVvIZTXXEgHo6aEdBvbZWJodqlWnRqZR8KAopX4BU79i17SrpbtPxzlzaH7LBBgMdhvUWTcZPfxTlTduZxdyGyZhfJkONl65H3bW6ULB4mVHjkYzKPRx2kTN/sGcTWXhZ6k00eI80EGNBjt/gnfGZaZjpuHEkH21CHrGFaml8XHJUruo/p32OZ0+rEYetVy11CKxGhKGUkVL/J8AQhoDgec+SxviirJVo8wMiXsxsYYWqcfEeYG5kzBzdhePA2rENzR4OPFE20Z1foxDAGfr4mLQsjqkSkOhARGGQm7N4GD48e6JUId7YbJZ6C+nyE/nkrAIyXGTPNiLEIlcSz8p7lRPfk3k7rQVdWe22+FSMHzz1fs8L/7N0cF1FsSzTiSRYNIw7I+o56bfHijmEZTMgAK+A/z7QSRR69bdzH/hkNQtvjzQn6ScVN8ztA1KZBmTuetwhxhqBa7ovrlb12xkkhMz83duiRfjp8diDBcAt3e/oyNr5AsvVh5Zf/LS2T9PVLOUu6g/A9PpGynSSKk+g1MppRkNODy6f/BjB6qQVuA6w0UuXL X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8475be08-2d5f-4613-ad4f-08d92ce4f0f8 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jun 2021 14:26:45.8119 (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: m0VEpS2jYa90PzrST6M14fSa+WbBKDssTHXw0X1+VwaDjpQudsSRusDL1eWkL2BjX4+cu1KM39NCJ/aRzITftA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4349 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Brijesh Singh Invoke a hypercall when a memory region is changed from encrypted -> decrypted and vice versa. Hypervisor needs to know the page encryption status during the guest migration. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Paolo Bonzini Cc: Joerg Roedel Cc: Borislav Petkov Cc: Tom Lendacky Cc: x86@kernel.org Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Steve Rutherford Reviewed-by: Venu Busireddy Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra Reviewed-by: Borislav Petkov --- arch/x86/include/asm/paravirt.h | 6 +++ arch/x86/include/asm/paravirt_types.h | 1 + arch/x86/include/asm/set_memory.h | 1 + arch/x86/kernel/paravirt.c | 1 + arch/x86/mm/mem_encrypt.c | 67 +++++++++++++++++++++++---- arch/x86/mm/pat/set_memory.c | 6 +++ 6 files changed, 73 insertions(+), 9 deletions(-) diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h index da3a1ac82be5..540bf8cb37db 100644 --- a/arch/x86/include/asm/paravirt.h +++ b/arch/x86/include/asm/paravirt.h @@ -97,6 +97,12 @@ static inline void paravirt_arch_exit_mmap(struct mm_struct *mm) PVOP_VCALL1(mmu.exit_mmap, mm); } +static inline void notify_page_enc_status_changed(unsigned long pfn, + int npages, bool enc) +{ + PVOP_VCALL3(mmu.notify_page_enc_status_changed, pfn, npages, enc); +} + #ifdef CONFIG_PARAVIRT_XXL static inline void load_sp0(unsigned long sp0) { diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h index d9d6b0203ec4..664199820239 100644 --- a/arch/x86/include/asm/paravirt_types.h +++ b/arch/x86/include/asm/paravirt_types.h @@ -168,6 +168,7 @@ struct pv_mmu_ops { /* Hook for intercepting the destruction of an mm_struct. */ void (*exit_mmap)(struct mm_struct *mm); + void (*notify_page_enc_status_changed)(unsigned long pfn, int npages, bool enc); #ifdef CONFIG_PARAVIRT_XXL struct paravirt_callee_save read_cr2; diff --git a/arch/x86/include/asm/set_memory.h b/arch/x86/include/asm/set_memory.h index 43fa081a1adb..872617542bbc 100644 --- a/arch/x86/include/asm/set_memory.h +++ b/arch/x86/include/asm/set_memory.h @@ -83,6 +83,7 @@ int set_pages_rw(struct page *page, int numpages); int set_direct_map_invalid_noflush(struct page *page); int set_direct_map_default_noflush(struct page *page); bool kernel_page_present(struct page *page); +void notify_range_enc_status_changed(unsigned long vaddr, int npages, bool enc); extern int kernel_set_to_readonly; diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c index 04cafc057bed..1cc20ac9a54f 100644 --- a/arch/x86/kernel/paravirt.c +++ b/arch/x86/kernel/paravirt.c @@ -296,6 +296,7 @@ struct paravirt_patch_template pv_ops = { (void (*)(struct mmu_gather *, void *))tlb_remove_page, .mmu.exit_mmap = paravirt_nop, + .mmu.notify_page_enc_status_changed = paravirt_nop, #ifdef CONFIG_PARAVIRT_XXL .mmu.read_cr2 = __PV_IS_CALLEE_SAVE(native_read_cr2), diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c index ff08dc463634..455ac487cb9d 100644 --- a/arch/x86/mm/mem_encrypt.c +++ b/arch/x86/mm/mem_encrypt.c @@ -228,29 +228,76 @@ void __init sev_setup_arch(void) swiotlb_adjust_size(size); } -static void __init __set_clr_pte_enc(pte_t *kpte, int level, bool enc) +static unsigned long pg_level_to_pfn(int level, pte_t *kpte, pgprot_t *ret_prot) { - pgprot_t old_prot, new_prot; - unsigned long pfn, pa, size; - pte_t new_pte; + unsigned long pfn = 0; + pgprot_t prot; switch (level) { case PG_LEVEL_4K: pfn = pte_pfn(*kpte); - old_prot = pte_pgprot(*kpte); + prot = pte_pgprot(*kpte); break; case PG_LEVEL_2M: pfn = pmd_pfn(*(pmd_t *)kpte); - old_prot = pmd_pgprot(*(pmd_t *)kpte); + prot = pmd_pgprot(*(pmd_t *)kpte); break; case PG_LEVEL_1G: pfn = pud_pfn(*(pud_t *)kpte); - old_prot = pud_pgprot(*(pud_t *)kpte); + prot = pud_pgprot(*(pud_t *)kpte); break; default: - return; + WARN_ONCE(1, "Invalid level for kpte\n"); + return 0; } + if (ret_prot) + *ret_prot = prot; + + return pfn; +} + +void notify_range_enc_status_changed(unsigned long vaddr, int npages, bool enc) +{ +#ifdef CONFIG_PARAVIRT + unsigned long sz = npages << PAGE_SHIFT; + unsigned long vaddr_end = vaddr + sz; + + while (vaddr < vaddr_end) { + int psize, pmask, level; + unsigned long pfn; + pte_t *kpte; + + kpte = lookup_address(vaddr, &level); + if (!kpte || pte_none(*kpte)) { + WARN_ONCE(1, "kpte lookup for vaddr\n"); + return; + } + + pfn = pg_level_to_pfn(level, kpte, NULL); + if (!pfn) + continue; + + psize = page_level_size(level); + pmask = page_level_mask(level); + + notify_page_enc_status_changed(pfn, psize >> PAGE_SHIFT, enc); + + vaddr = (vaddr & pmask) + psize; + } +#endif +} + +static void __init __set_clr_pte_enc(pte_t *kpte, int level, bool enc) +{ + pgprot_t old_prot, new_prot; + unsigned long pfn, pa, size; + pte_t new_pte; + + pfn = pg_level_to_pfn(level, kpte, &old_prot); + if (!pfn) + return; + new_prot = old_prot; if (enc) pgprot_val(new_prot) |= _PAGE_ENC; @@ -285,12 +332,13 @@ static void __init __set_clr_pte_enc(pte_t *kpte, int level, bool enc) static int __init early_set_memory_enc_dec(unsigned long vaddr, unsigned long size, bool enc) { - unsigned long vaddr_end, vaddr_next; + unsigned long vaddr_end, vaddr_next, start; unsigned long psize, pmask; int split_page_size_mask; int level, ret; pte_t *kpte; + start = vaddr; vaddr_next = vaddr; vaddr_end = vaddr + size; @@ -345,6 +393,7 @@ static int __init early_set_memory_enc_dec(unsigned long vaddr, ret = 0; + notify_range_enc_status_changed(start, PAGE_ALIGN(size) >> PAGE_SHIFT, enc); out: __flush_tlb_all(); return ret; diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c index 156cd235659f..0c937daea0ae 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -2020,6 +2020,12 @@ static int __set_memory_enc_dec(unsigned long addr, int numpages, bool enc) */ cpa_flush(&cpa, 0); + /* + * Notify hypervisor that a given memory range is mapped encrypted + * or decrypted. + */ + notify_range_enc_status_changed(addr, numpages, enc); + return ret; } From patchwork Fri Jun 11 14:28:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 12315841 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,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 95ABBC48BE5 for ; Fri, 11 Jun 2021 14:29:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 72ACF613AE for ; Fri, 11 Jun 2021 14:29:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231361AbhFKObH (ORCPT ); Fri, 11 Jun 2021 10:31:07 -0400 Received: from mail-dm6nam12on2072.outbound.protection.outlook.com ([40.107.243.72]:29664 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230346AbhFKObG (ORCPT ); Fri, 11 Jun 2021 10:31:06 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AugUPhsmH9itr9hphywU01Yz7FLHYyUbGlYEipX583Jshf3cncw3rEF8QbvEanGswI3x9WHap2WOk/Ie9/INiJK4gl51AgYvkKkTMalNPSh4pVY37IEum1b0R508xiSybeuT2rzQqoIKDpkfc7TOBpcUasyFaq1LzGlKpRzDx5Ndy4xgIKzIfDYxa7vWZhRrHeALRUH4B8tKtQXB2IebDRQaUTo4bsG7haGGQ4ze8o1jnR4wagYIz00cRtFwP/q1600UmMsc0TewBD7JteFH7lA23/6WCFQIZeywd07zvrm3RhrfVrfEZRUQ4Ax27oHczfg3elLfwaRr9esfqmyZKA== 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=ImYRURSA0MWns+++F1GteOzG2evYIUzjTgbdkzculhc=; b=Gu9WShkRvRC6RFU9txL6K8UnK4lqjVF21CENFva883OvHfBKJa9rwDfibWL2GeUwmFApetjsmNMfgkEUVc07s6JnL2wi+IGQI2dAP0Jx4/cZV3hpMkoMIur/j9hJ5lnJDOfEsRBaG10nKkkjMK0QoQYsis/ZDeZ/fS8XBqL8kOps7f7f/H2zkoYjag6Wou8zvxRQqEWy6aOgF/AH99/b9ocPgT9X+ft18k938/ssUyzaAUsOjSi4MvWzswdtSDIXsyX0fRl4S7Si6JP2n94EtJPFzkdY/P92IWvQkjMOfAl2DN6uVmGGXdt3sy2ee1g6nEhMuUzbuZa5WwYx9FYtvg== 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=ImYRURSA0MWns+++F1GteOzG2evYIUzjTgbdkzculhc=; b=gtFNOYImn2S1NVgKtKre+lBk3Re/A9AUSstImgbkJciFkx/8BMZrN/jhivVWGSxPosOiVtU7f+W6evs2i9H46gOt9p645Z/oS5VO09vfmAwXjM1v6z06VuKbqFae7PQgVv0MyuEfQFHyhnjzbe2L1aeAuI+wMqCxJO7BTWVyNp0= 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 SA0PR12MB4382.namprd12.prod.outlook.com (2603:10b6:806:9a::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.23; Fri, 11 Jun 2021 14:29:07 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::958d:2e44:518c:744c]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::958d:2e44:518c:744c%7]) with mapi id 15.20.4219.024; Fri, 11 Jun 2021 14:29:07 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: seanjc@google.com, tglx@linutronix.de, bp@alien8.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, Thomas.Lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, srutherford@google.com, brijesh.singh@amd.com, linux-efi@vger.kernel.org Subject: [PATCH v4 4/5] EFI: Introduce the new AMD Memory Encryption GUID. Date: Fri, 11 Jun 2021 14:28:57 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN6PR2101CA0018.namprd21.prod.outlook.com (2603:10b6:805:106::28) 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 SN6PR2101CA0018.namprd21.prod.outlook.com (2603:10b6:805:106::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4242.4 via Frontend Transport; Fri, 11 Jun 2021 14:29:06 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e7516689-618a-4f96-da0a-08d92ce54517 X-MS-TrafficTypeDiagnostic: SA0PR12MB4382: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4941; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cmjOq+4k44Es0y2oeHCZQ2HJmi75YcqntgcleG3fBO0aSLE4XrNEX1WQ4s2hmGPyIosOGCi6FFC72TfYyAPpOC1ZPUsah71oGkeibWXb4QAu35YLLxi+yJDQ5h4zErcUWFbA9IEv6wtv4Gas1nn6wUBZK/7PzOltfc6ttVpGNyX2TVJES+t4Xtf/UUzJl/8jL8EDW44nCY8AVQ1IF4kvoyC2Szwa90IN5xNvjj3WccKlpVYy/0q184lC3Ve//qriEvc6P7/g4QGJVEPAnEiSGdmExQOQOv3HE7dDyZh0YiDeDUy6W02CIE+K9Cpq+1XWTBstamkmxyax38gd5l9viICfmBv2jlg4kPXnbjjrm4xt5g9JIo0NQ9+VYBqANEHLNMJ87xCvkLkEnk5Ctz9IS91pptuskDm52KcFeDHbcK57vkKIjDc3cICzXSHX6wWhYgFl4COlc7Z6j8bLuKqfmOptqSQDXGSIgI9WdnvbrKjwrC6ahDJMFvrfc8e4z1JYjsm9usV3X6t4Q/82NpR7MCOCMSMQo+IxWt95JZiezs0hq/3Bwq/9ziEXdJjZJbZKaah2y8pxc7EJQqCHbrQcQ/LXwzeI2C1aTSkw2xRPofqbIoLilVN9hXRF24rqQ6kGDgLDAGpFupu8oYUeoZqWVvM9jSyMuRQcRj1PX6JjEdA= 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)(366004)(346002)(39860400002)(136003)(396003)(4326008)(38100700002)(38350700002)(2906002)(52116002)(66946007)(8936002)(66476007)(66556008)(7696005)(6666004)(186003)(16526019)(478600001)(83380400001)(6486002)(8676002)(86362001)(26005)(36756003)(5660300002)(2616005)(6916009)(956004)(7416002)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: TR5cMB65hKPJQuU5cZmYaRh283v9REdBJIwBodnHy36IwsvAlSKcjOK5l1ScIDf8yqdacvPPGh3as20r0vgCBSvuo9uu7TK8dwdiT+BIJUG1fGJtQM0u1UqjSKVNoImNOaEh59D0t3n1BujZ3+OZhzM/pAbkMxRw/mPvKwkD1sGrIFO5EuC/yspvMBcI66uMXudGH/QwiPVoVhBUN4lAldv90+Q0nOgQQbP6G6S9RlerUGovXIu4e71vedKtYoakxmhnetRQL3EP9HDZdFXAEiX3bedBovvrYufqafRxLsxPTIVqMmhGdUWRJYNEP18UfqGvmN3vtdvnFUCt3yPM1o3S3ToT338T3bbLBl+FY7fqtNsf7IrFtwiDCcPrvO/cy8vhXJDzfM5QukdqT43g5wh6ei4446UV4NONi7P40WMxYb8YuvRVAAqQt++ImW6646ji4zR7EDZ9PIs6Wsts0X+sdfipmXd9uS6B1t3Virhe94diYW06J90nP1lm+r+tPa/2nfuQLec3he2R7Ppg9dGJON2CNuJV/Oyg08/tiQTjesrZxGhQ/qg7UiaOIFkSNaDZ8kugqGL+F7csxQfO201p7JBDJx1HgXLNqWp1bOMY3GgJEu0FUvxPHpYS6UisgQV7QKh198Q5/gX6HothV9qH96oaZe7KS93MGXgbRUG3jat0jhO67F4WYVeRHqf5y3fBg+TjHkKzOIDYO5aipjrAsRVgbacz11m7Tk7THZSz3xTFHm+ePamLkv94gj729lGjXZ+RcHZMBjjhfIX7p/ml+vSmylC+0kAwma7VKxXC89Bw5GGokDURJbMrsbLdx14/yR892SCsVE+kmWGSEdokLBeeUuHiRdyAYLKkLdXVR24J2M+aTvd2QMCJIuuppQaqFZDzPe8itTkPFcVkX9AJnmKTORe+quDH0aidzv/6+ywU0mBXdt3FDSc8hQviL5KXf/5eF8eth8D+tvYRs6y8UrYKR4pjJZIEleC2SXu1kQNl5gFmciT4VeLRSfTn/Z1U7WoP6lZeRlDg3zZYzkVEW/omb5JlVldKzVOjvJfhJjSbFjDmxzVhpN/l3p5VkqOGSPNeGYJXkew4RDEje5mHbF+0yPE7dyrID5Cp5yQK9HgTv2P/MzoQWUUyBEhau6gEgPpj1nEk4rdD7XabPKohd5jHvLA7oN6cxNxO1CNdR5I4dZnShoRqPs6eBleQB+IGDXzWPLI+CHakAyyrmf85+H57EurUsX1NR6ZdgRlzZligFwYf+NsuiFTHph1BVXSYbezBATLvAzZOb75rmJDMx0oFuun8pl7kNTpAgAnNHDLnpkk52ISdRfmCOgJI X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e7516689-618a-4f96-da0a-08d92ce54517 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jun 2021 14:29:06.9658 (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: lz4TEbV4VvXhzkOasYC4rRINxRuUioJC2Ji4kSShMCkq5SN+BFa4uJfCqiZ5LFuMQELTzIhu3+foenNH9m/CtA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4382 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Ashish Kalra Introduce a new AMD Memory Encryption GUID which is currently used for defining a new UEFI environment variable which indicates UEFI/OVMF support for the SEV live migration feature. This variable is setup when UEFI/OVMF detects host/hypervisor support for SEV live migration and later this variable is read by the kernel using EFI runtime services to verify if OVMF supports the live migration feature. Signed-off-by: Ashish Kalra Acked-by: Ard Biesheuvel --- include/linux/efi.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/linux/efi.h b/include/linux/efi.h index 6b5d36babfcc..dbd39b20e034 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -362,6 +362,7 @@ void efi_native_runtime_setup(void); /* OEM GUIDs */ #define DELLEMC_EFI_RCI2_TABLE_GUID EFI_GUID(0x2d9f28a2, 0xa886, 0x456a, 0x97, 0xa8, 0xf1, 0x1e, 0xf2, 0x4f, 0xf4, 0x55) +#define AMD_SEV_MEM_ENCRYPT_GUID EFI_GUID(0x0cf29b71, 0x9e51, 0x433a, 0xa3, 0xb7, 0x81, 0xf3, 0xab, 0x16, 0xb8, 0x75) typedef struct { efi_guid_t guid; From patchwork Fri Jun 11 14:30:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 12315843 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham 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 E2C0CC48BD1 for ; Fri, 11 Jun 2021 14:30:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C27A7613FA for ; Fri, 11 Jun 2021 14:30:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231522AbhFKOcW (ORCPT ); Fri, 11 Jun 2021 10:32:22 -0400 Received: from mail-mw2nam10on2079.outbound.protection.outlook.com ([40.107.94.79]:29568 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229722AbhFKOcV (ORCPT ); Fri, 11 Jun 2021 10:32:21 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XY28NNk5l/YLtZrVpjGIa9vW6BYDDh3MuPB9okgsszeCl/9E18K/87rExlvsxpEmTnRBUqI9lb0xKJoyqAKcsO1r5IsNUIc3ewF0ao0Z190k+Nt+lJY0v4yX4sRPka2+/G5OmpVlen+e2WDBsbTZ1MupBeCOgT8ZUeze/IFz3KV1E69nJkxeyz0AxbHLtfvZpQ2RSGBsVu0Rb8ku4GjRc4YPGMDPCqpgMciWlkl+cmBXYXyw21MP405a2DLR5mTNMtUUEIwRe5v8MuDOp/jhqrYjiE2qJV9K+FzxvtgSYsvWrjPnJFDrHj/omZKHvJ+54Wkjl1cNgrx6QaIcbTtl0g== 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=vE4UZQZslmQgUTYowq8clRL/j9I5zIf8ptmTi1JEh38=; b=KiI577KfGReEPMlEA6u1G3AS/K4By6dpbhehTshexdNxyWVdpXmy8ZZ3QgETqnOTppgEXbr8loXHFv39wqEl0hGCh1F79gFh1hETYPx8BR9u2O7jyq2/lXCzXS8i1bZKxQsq60y/qvgJRSMKFecCn84LdunCWWQwsJTSlXpIHbuiF8jNu9DEKPYQQYQEEjcPTklDklreYr6IxQsN9caIfDozdqhL122ORlvrwUd/sDpKjfC2atRHSYbJIqHnblgX+A3ULp0EuSCiEKWSA4FK1dcrckpqJ4LL28vuMP9Nkj2kppgzOU298/UHO5AgeXD0pnUz/XQRBkkJ9poxFgiJAg== 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=vE4UZQZslmQgUTYowq8clRL/j9I5zIf8ptmTi1JEh38=; b=QfZEoPQGODNgT4/0uWJybPwaqXSsdhDj+FNDfqdUj4VSRBiiWpmMKse7Uutm+uG65nub4eSZBHSHFQf9AD0rZgKvgt3KxooRTBZ1TStXG0Z/0ik3ZAlI8uJm/sBVl8OnRUJlKYjbRpQOvcCvX78+fR65Z9DUyE4WQ8PVovs7X0E= 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 SN6PR12MB2687.namprd12.prod.outlook.com (2603:10b6:805:73::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.24; Fri, 11 Jun 2021 14:30:21 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::958d:2e44:518c:744c]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::958d:2e44:518c:744c%7]) with mapi id 15.20.4219.024; Fri, 11 Jun 2021 14:30:21 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: seanjc@google.com, tglx@linutronix.de, bp@alien8.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, Thomas.Lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, srutherford@google.com, brijesh.singh@amd.com Subject: [PATCH v4 5/5] x86/kvm: Add guest support for detecting and enabling SEV Live Migration feature. Date: Fri, 11 Jun 2021 14:30:11 +0000 Message-Id: <8c581834c77284d5b9465b3388f07fa100f9fc4e.1623421410.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: SN1PR12CA0076.namprd12.prod.outlook.com (2603:10b6:802:20::47) 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 SN1PR12CA0076.namprd12.prod.outlook.com (2603:10b6:802:20::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.20 via Frontend Transport; Fri, 11 Jun 2021 14:30:21 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5072b8df-d18c-4d61-29eb-08d92ce5717e X-MS-TrafficTypeDiagnostic: SN6PR12MB2687: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:252; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: azZgKOfyKKt0EmDFPl98WTG3fIkfB+NPFrwPqdbZ43kr1W8DO6RLw0icCnLVZ3j5+dOFfVEqF4ZdmYBlQEgBu0qNeeeW+xvfpgAowEwoitReRD1Brpy81YBSbNtfHRwKv7IJr7sWE9hD+wbqkBplxuPboT4OATwerOES8cxRILHOt3CfzfIdeRtomhyXY8L6ZcBglumeFwdU7h4DoKk5zvjj0AvS7nMa72MSGyPE/rgXCGs5tHtnSuhxR3g27qnR14AEnUbR1rNxfHGgdntzb/mD786m1tTpb6cxTaSaR1OlSi9dQ5BmFTmTfzVd8URIKdYoIkzUsse3+3nxXuyeNT7XZ1j3EnV/g4ogCMpj7utrBzc+ACPjR9DhiT1gOT6sT1O6GECptIlwGgC4V+M00PELN5tdSdsXcS4pbs0Ki+0LSHoQHQU0kO73Hz8ybt+yDnwSbwX0DQ9hBeda6cYLgXOh1CRJ4a4YZddbuvjWBP7Z66pJWV4mWl00j2S+soPI+2dFM2mTZc8dR8bIehOMrgPavCBzGVAe70d1bkt6apE++3cw9THGBJnp2t5EOvHTtNR1t6cPEcAHfS8I19uzx8NUeBnTOWeLdgMQcB49d1Lzg8+hVisqOrt5x9hdiDhAz5G/IL8jwWiLjyNVpXJUYqnMR54u/FVVdDBuMGs3U9Q= 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)(366004)(396003)(39860400002)(346002)(376002)(136003)(8936002)(2906002)(66556008)(956004)(6486002)(186003)(66476007)(16526019)(6916009)(36756003)(316002)(66946007)(5660300002)(2616005)(26005)(7696005)(52116002)(6666004)(86362001)(8676002)(7416002)(83380400001)(4326008)(478600001)(38350700002)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 0dDq3xgClnbj03UsE3iLEoGIO5CoBTZ4TwboXn5tM62DRQj4hWxfMcNaVfIicPrE5Awiu9PDjzFCNlPKb6WAR3alu4keT+xZ9WYD3s/aCiZJTPclzPl5182BqfamTQeRgtyb4DMP8F9Rbz53V2CDzpMFFGwpT6/1hEOqXRZ0S1uITPnPGnoWfrEolEF5pQDn+Yb8HzoRKR9j4lqIKhyo8CHZ6rvJ9MDWPYwJXa/wDM2G+9TMYLsiX5sZ1eKoub7G+Wl+QW7tmIluibfOINixMXGbdYq2jU4AOCQyTn4a603rIg8zPqfjilN2DtYvlonYq0FYkqXUFF1fba9ZuZpEtftSJ9rnxWTIMKMnctSYequueArwodRtpcrBLay8nw4Tw5fmVNpfGttE9InFdmSN/0svELGvOrsDsS5WpLy9xYT9mLFPYQVm9cs9tI4l9gMC6o+hbae3pbg8LFjD35YWjFeoE5+qev6jn4wBAG5YrN+RKp9qVzPgvyKHWpdUbGbsrKrB+AVdiEp12NePwOWDLUQrVWfTeSHP8SU4p8uGuGg9Fls0EQbb+RdYzrLF7HOfxuky1lgx8uoU9WhgZIABCUQviy0RGQf2X1nr9BEnoPb6Hs3DnE6yOQeQLiimVxxq4XlU1Fb4RyMhKHfBsuyR1s9XE7PdK/5YCJL+QdlstbvgEJasPIW4FB7bpS9koWR1gsyfkglGxAs8Dmu0e4I9+zjthHHVcxXvDwsqCIVI8Ldv7e2dVIy9Dtx4ae/eVfiL+PDKkB2hbPf+5d9w/MNzXr4rTKrxG8fGle69h3EPhrbe8StRb/MoJ1hcplRAk9sZKFBXHIWf26fzmGBd+GJRgLmJrHN0Cqwds5usfgxtKy6mM75wHrBwyuN1BeKBQzStkBpuyRwb5f3PfemIjexWyVNyU7WjKu4rSHyw+uN25Vr5Li0zTsgG0d3aoDEUph7h/omrOq+p5DmZkZZI0c5qHB8K50oufNsrwhocNzs39X3qGMyBHAxxEbNFjfaRNyyYr4snzF61OdVd0hriFFTAfcFG3+Hw1IHQwM+OQOACiLFdwbCaTtQbA9gYDjcyVktoEbn36JeZUl3fyvvbSPk8v3BFVN0hTWY9wGpCjhxsSNTx5NuQP4+QvA9J8uMrJt2gRc+G9EHkhRINWBeIABqsj/jXpYteh1ceGSsicWv07ji+grxE68TctMAQyUZTheVAuxnanPgqJIqlPzAuVDd0XTfY7p6qsgw/XSnF61C0yFw+C8wgokx9yh3nqQuIcwtjO701Qm43R36IUdDBw88Ga84MXhofzfYm8aHhDsni/BWQW/X/3irRkdgMHHwj8J6d X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5072b8df-d18c-4d61-29eb-08d92ce5717e X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jun 2021 14:30:21.4211 (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: XcI7CwZ3KBSbuR2pWCIf2CFGJ3bugkd58tqWqgCgtLDOpdrqgTfN992slTORuy8CKgqxIFJrsUadueWn4kRS9A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2687 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Ashish Kalra The guest support for detecting and enabling SEV Live migration feature uses the following logic : - kvm_init_plaform() checks if its booted under the EFI - If not EFI, i) if kvm_para_has_feature(KVM_FEATURE_MIGRATION_CONTROL), issue a wrmsrl() to enable the SEV live migration support - If EFI, i) If kvm_para_has_feature(KVM_FEATURE_MIGRATION_CONTROL), read the UEFI variable which indicates OVMF support for live migration ii) the variable indicates live migration is supported, issue a wrmsrl() to enable the SEV live migration support The EFI live migration check is done using a late_initcall() callback. Also, ensure that _bss_decrypted section is marked as decrypted in the shared pages list. Also adds kexec support for SEV Live Migration. Reset the host's shared pages list related to kernel specific page encryption status settings before we load a new kernel by kexec. We cannot reset the complete shared pages list here as we need to retain the UEFI/OVMF firmware specific settings. The host's shared pages list is maintained for the guest to keep track of all unencrypted guest memory regions, therefore we need to explicitly mark all shared pages as encrypted again before rebooting into the new guest kernel. Signed-off-by: Ashish Kalra --- arch/x86/include/asm/mem_encrypt.h | 4 ++ arch/x86/kernel/kvm.c | 107 +++++++++++++++++++++++++++++ arch/x86/mm/mem_encrypt.c | 5 ++ 3 files changed, 116 insertions(+) diff --git a/arch/x86/include/asm/mem_encrypt.h b/arch/x86/include/asm/mem_encrypt.h index 9c80c68d75b5..8dd373cc8b66 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); @@ -83,6 +85,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/kvm.c b/arch/x86/kernel/kvm.c index a26643dc6bd6..80a81de4c470 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -40,6 +41,7 @@ #include #include #include +#include DEFINE_STATIC_KEY_FALSE(kvm_async_pf_enabled); @@ -433,6 +435,8 @@ static void kvm_guest_cpu_offline(bool shutdown) kvm_disable_steal_time(); if (kvm_para_has_feature(KVM_FEATURE_PV_EOI)) wrmsrl(MSR_KVM_PV_EOI_EN, 0); + if (kvm_para_has_feature(KVM_FEATURE_MIGRATION_CONTROL)) + wrmsrl(MSR_KVM_MIGRATION_CONTROL, 0); kvm_pv_disable_apf(); if (!shutdown) apf_task_wake_all(); @@ -547,6 +551,55 @@ static void kvm_send_ipi_mask_allbutself(const struct cpumask *mask, int vector) __send_ipi_mask(local_mask, vector); } +static int __init setup_efi_kvm_sev_migration(void) +{ + efi_char16_t efi_sev_live_migration_enabled[] = L"SevLiveMigrationEnabled"; + efi_guid_t efi_variable_guid = AMD_SEV_MEM_ENCRYPT_GUID; + efi_status_t status; + unsigned long size; + bool enabled; + + if (!sev_active() || + !kvm_para_has_feature(KVM_FEATURE_MIGRATION_CONTROL)) + return 0; + + if (!efi_enabled(EFI_BOOT)) + return 0; + + if (!efi_enabled(EFI_RUNTIME_SERVICES)) { + pr_info("%s : EFI runtime services are not enabled\n", __func__); + return 0; + } + + size = sizeof(enabled); + + /* Get variable contents into buffer */ + status = efi.get_variable(efi_sev_live_migration_enabled, + &efi_variable_guid, NULL, &size, &enabled); + + if (status == EFI_NOT_FOUND) { + pr_info("%s : EFI live migration variable not found\n", __func__); + return 0; + } + + if (status != EFI_SUCCESS) { + pr_info("%s : EFI variable retrieval failed\n", __func__); + return 0; + } + + if (enabled == 0) { + pr_info("%s: live migration disabled in EFI\n", __func__); + return 0; + } + + pr_info("%s : live migration enabled in EFI\n", __func__); + wrmsrl(MSR_KVM_MIGRATION_CONTROL, KVM_MIGRATION_READY); + + return true; +} + +late_initcall(setup_efi_kvm_sev_migration); + /* * Set the IPI entry points */ @@ -805,8 +858,62 @@ static bool __init kvm_msi_ext_dest_id(void) return kvm_para_has_feature(KVM_FEATURE_MSI_EXT_DEST_ID); } +static void kvm_sev_hc_page_enc_status(unsigned long pfn, int npages, bool enc) +{ + kvm_hypercall3(KVM_HC_MAP_GPA_RANGE, pfn << PAGE_SHIFT, npages, + KVM_MAP_GPA_RANGE_ENC_STAT(enc) | KVM_MAP_GPA_RANGE_PAGE_SZ_4K); +} + static void __init kvm_init_platform(void) { + if (sev_active() && + kvm_para_has_feature(KVM_FEATURE_MIGRATION_CONTROL)) { + unsigned long nr_pages; + int i; + + pv_ops.mmu.notify_page_enc_status_changed = + kvm_sev_hc_page_enc_status; + + /* + * Reset the host's shared pages list related to kernel + * specific page encryption status settings before we load a + * new kernel by kexec. Reset the page encryption status + * during early boot intead of just before kexec to avoid SMP + * races during kvm_pv_guest_cpu_reboot(). + * NOTE: We cannot reset the complete shared pages list + * here as we need to retain the UEFI/OVMF firmware + * specific settings. + */ + + for (i = 0; i < e820_table->nr_entries; i++) { + struct e820_entry *entry = &e820_table->entries[i]; + + if (entry->type != E820_TYPE_RAM) + continue; + + nr_pages = DIV_ROUND_UP(entry->size, PAGE_SIZE); + + kvm_hypercall3(KVM_HC_MAP_GPA_RANGE, entry->addr, + nr_pages, + KVM_MAP_GPA_RANGE_ENCRYPTED | KVM_MAP_GPA_RANGE_PAGE_SZ_4K); + } + + /* + * Ensure that _bss_decrypted section is marked as decrypted in the + * shared pages list. + */ + nr_pages = DIV_ROUND_UP(__end_bss_decrypted - __start_bss_decrypted, + PAGE_SIZE); + early_set_mem_enc_dec_hypercall((unsigned long)__start_bss_decrypted, + nr_pages, 0); + + /* + * If not booted using EFI, enable Live migration support. + */ + if (!efi_enabled(EFI_BOOT)) + wrmsrl(MSR_KVM_MIGRATION_CONTROL, + KVM_MIGRATION_READY); + } kvmclock_init(); x86_platform.apic_post_init = kvm_apic_init; } diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c index 455ac487cb9d..2673a89d17d9 100644 --- a/arch/x86/mm/mem_encrypt.c +++ b/arch/x86/mm/mem_encrypt.c @@ -409,6 +409,11 @@ 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) +{ + notify_range_enc_status_changed(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