From patchwork Tue Sep 13 14:49:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 9329341 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 51BC86077F for ; Tue, 13 Sep 2016 15:51:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4120F290E1 for ; Tue, 13 Sep 2016 15:51:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 354E42930B; Tue, 13 Sep 2016 15:51:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 40FF5290E1 for ; Tue, 13 Sep 2016 15:51:09 +0000 (UTC) Received: from localhost ([::1]:49760 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjpzH-0003D0-Ux for patchwork-qemu-devel@patchwork.kernel.org; Tue, 13 Sep 2016 11:51:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55175) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjpY1-0004tv-B5 for qemu-devel@nongnu.org; Tue, 13 Sep 2016 11:23:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bjpXw-0002yL-Fn for qemu-devel@nongnu.org; Tue, 13 Sep 2016 11:22:57 -0400 Received: from mail-sn1nam02on0077.outbound.protection.outlook.com ([104.47.36.77]:5469 helo=NAM02-SN1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjpXw-0002ws-4n for qemu-devel@nongnu.org; Tue, 13 Sep 2016 11:22:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=u6yKfKC4Wlw7fq81+iRSa9lh5JzZole8VqsFANAh6V4=; b=ow8Fjj+d4yPVmYAsQDPj696UIfHNFlNgcHw6FzjqH1wg0J2d1+pSLzgbzFCPvqDChJz4YJrLcIqRSnPdokwDvf0oDFIslryqOA4j9ZMt9zhxh7h5iyXbCIbEg0kv26d5h6Jbm6Ci9HSyhb0hoOvcLb0TieOLfTJWG8ih/WvPOJE= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from [127.0.1.1] (165.204.77.1) by BLUPR12MB0660.namprd12.prod.outlook.com (10.163.217.30) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.609.9; Tue, 13 Sep 2016 14:49:52 +0000 From: Brijesh Singh To: , , , , , , , , Date: Tue, 13 Sep 2016 10:49:48 -0400 Message-ID: <147377818825.11859.17231343609113478405.stgit@brijesh-build-machine> In-Reply-To: <147377800565.11859.4411044563640180545.stgit@brijesh-build-machine> References: <147377800565.11859.4411044563640180545.stgit@brijesh-build-machine> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BLUPR0301CA0036.namprd03.prod.outlook.com (10.162.113.174) To BLUPR12MB0660.namprd12.prod.outlook.com (10.163.217.30) X-MS-Office365-Filtering-Correlation-Id: 43b495f5-ab67-4844-0431-08d3dbe53870 X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0660; 2:B72RO9CjuoizKhFbxHl5jfMCJSFtCxh23fm2P54XQKU7gxyfpZGpyA4GdEsSPolsRkI/m/SHqvyxx9h+KwYQjDZsqqKU4TpvFmuTBcdu4wk76jqgsETC6ZqH3h0HxGhqyDA6+K6/nfW4OZ6LGoI1iJd24LkK/Zanv1kr910OCtHjuDABtVOyVGuNVm0bEuxJ; 3:2DR61kw1dghfkHLqxLxhrz2FU40m72NCJLUcKfGIr6+ewKD/QiadGJv464EbGdietlBWSP4o2feSQqOokyBHrRQrunjN72EL7wxx/nKlgzYW+hGEpltJodQdF63Hr38W; 25:z9QlIqk3s1zagUe7xPSPgrMqqIabuXfnPWu8pza2DvcGDEv9TTbsKnZeDjZBpa8lU7cN1bxb4DjhwoO3ZYZ7UQukTMqowBlGETKAKFF7qb2VxGrhTq816LZ57WPBmCC1k35ZwBdXog/u+LOhISS3iG6FmEMOX6De9qcoGvoDJE3bFO8xmR6Mh8a6/WFVUhQl2i5xGkVx5e/sWvEgMGdMW0kTxnEiDvgybg8NjanrB7tWN6aOaPDeHbKL31/N2srXeVaOhTbdxWO5Br/NbzaBcn6BahAkVZFGT+Sr2ww8vNpViJUgqjqqb1JAow5rJlpOYsGE/hE2ErD5OJcQk/B6dKXB9KroOCUuhfyxn+8hAapRLAbwCcckPA92G4OcukcdhhGrJeUnrpQ1dcorhTqgV5IAGaomH0/Zxt1osPa6kfs= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR12MB0660; X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0660; 31:Q7UI2qq+1+C5net5+r9+ah9OgBuDt6+XEkiKjDHLfJL0EAdBi2DrWWQCLIKXso68iI175U+Fhjhdm32DPpa1lJSvyp8jNDEOEFVUyl9VRmNxCo2su8CE9OmSiQc7aJ//FMWxZir4wELxiiC36q/RpNzPe3XKSZJCXZsfyEMALGVqg5idzCG2TCVWpt75Yinhhen6VdSQvWwEMq1crydT6DNAyxMYDAAViMmXMLxVGmY=; 20:VKDg73Ux0Sovs5oMta1mZCBEhWqhEYnJtishne4QroCqhd40SACWmhxkv+6CsOe/51GIQ1mfotQ/+wBE+x+IsDfgrZP1UW50B2QaNLe7EyYp5VULcCaa/6HW3ENONO2ff3ZxIjEAnx6Q1N9XVeXao6u82lkb9UxYQ1fqCwbkFU95vKU3xTtdafIybCTDYyYgo2qOjfl2/aaYdpG22OHdmsMK9KuxJMfZsZ9xcAb2cZRkQTJmjvgJRXuM7Re7Ze45uYoTxWypHIREnybTg6tRtKY7Qt2aVAbyS7r+ke5iJnTfN2yEMY8W2w07aZ1883bOZaDucJBA3IYe0dOLhXfYbj0plC/X3XW+OBALKz3rWzEt+zpgNiN0ptHjmYM5Frpku4EgliyyRUfw2J0A5oqTsdhEtHRQeVl/Cg/sluHU4Gwb/uUoZbwnnDgVX6yyt4MB3fvBtYPYxz5xt3ItuVM24eJPVdcCQcpNu/gOBuXvAVbh8Ll2gIfDjDjXi15G/cVZ X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6055026); SRVR:BLUPR12MB0660; BCL:0; PCL:0; RULEID:; SRVR:BLUPR12MB0660; X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0660; 4:DeO11VrYcwKk8+qHyYwO123KR9wvDRCPIkF1SHsLe0TCzrBwGXCX93wnVwV1+90clYHb6QojGxZx4jZdY1L2vdmBUA9EosH22MYCpf7JAG/lat5X2aHAS98QFJ3TPGjYGDdbPddA/sPLyb5WoVr/cE6Bs44QT1DrkJg0JiiQc6+L7zEcpD66/XXgZZAhwSuzk/6qBzaJTCOgIlwq7UCajcaRV4L2yw7oJjwKRb+LxUCgQbeHaPa0rjeiGVtniKgtfK5YFJLdqASt6pif2wYSX6ZxIX/aji5y4MrJgUHmQFzNfmVin5wzOAc6yOu2VtkPwpy8Dnk9wKMquEyFF7v13uSIK8VSHp8p6mL/U/WzmRfimrBQdsrG59B1SHqIyydF2lVaS01WatMEeTL84qNDh+/oDaEJX/9WFLh0/IDqvC25T4vZ6/3EDzgMYavAqDy7 X-Forefront-PRVS: 0064B3273C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(6049001)(7916002)(189002)(199003)(7846002)(586003)(47776003)(6116002)(7736002)(2201001)(66066001)(50466002)(92566002)(5660300001)(33716001)(230700001)(2950100001)(2906002)(5001770100001)(189998001)(77096005)(4001350100001)(86362001)(81166006)(3846002)(23676002)(42186005)(97736004)(76176999)(19580395003)(103116003)(101416001)(8676002)(83506001)(81156014)(107886002)(33646002)(305945005)(54356999)(50986999)(19580405001)(68736007)(9686002)(106356001)(105586002)(229853001)(217873001); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR12MB0660; H:[127.0.1.1]; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtCTFVQUjEyTUIwNjYwOzIzOnRsUHVGNk9saGQ2YjhGdXdUNE9zTE9kOHlG?= =?utf-8?B?TmJ4NFh2d0tDTjQ1UzVlZ3BTSXBUWnU3SXBUb0REL09NdkE1RnNJYWlmU2tC?= =?utf-8?B?ZWxEOVBndlJObnNBSTZxK0JMcTcya210TUVOc2RLZ0ZkY3dnQ0s3emRiTHkw?= =?utf-8?B?YkVUbWJvY28zTXJuUUlRMEIvR1kzZTgrSDlKQ2RmRkJxZkZjMTlaeU43NG1I?= =?utf-8?B?cXR0bkZlMVJmT0FFM1ZBcnVjTXN3YVg5WnZNbHhaWTJFR1pNS1FEUm1BdU5X?= =?utf-8?B?eFhIZ0ZSK3Rwb2JLTDFyYUhwRUFmUUxZaGwwMW8yem10enZ4OEM4NWpLQ2VO?= =?utf-8?B?TlRjOVpYbXc3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hAZ0pyMICzvlgKN1/gmYHpYq9Z/rTXJz2HolYwZ+RDvV5KpkwwmoTId0RHjjX0HLOed5h/1j/zgl5w=; 7:rbKSyzBg8c5myPnrCqZHAYoQiIL5mdsEmL89PFz9SN+xVWUys/u23ZhoaLeDQUr9SbPxRixFANB8Qd1ZJwLL2Jb/OackuYjiW1JS6JblOhullsP4uZYqXudeEYpovlQ+GklgGxUlKgEjf6bGt6qwrbwWGraiDvfutEKtIvgZb87Sg+T9Kmy9LdgzqI4gh7rqrP3o6r4Tu8DulU06tyQQvZ8+OjaHAR4dfvt1gf/mGLX9KQzx95sLEaXMRCPeKty1 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0660; 20:nG+QMuBIHMRg3WlACLetQxvqRj84uWflAERBn+H+qN++p86q6DPYgbm2vuhE+fMN3ArbyljfqoKyrFdtGz+IZbFzMLYZpzsbnzFtlRPdwbJuIZLsedweOjWS3q6NJ+I3Blp28+YBf+Th3o4qzsXvhv0rDIqC4O1wj4w8frRxnLs65EcK/XhF4EbWTj8P41DP2x8rkzkW94p9U7HubJ1U2HBDz9bPLoabk+cXtaSbjwowidb1sZ2PQ1s4gVo86DeX X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Sep 2016 14:49:52.5146 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR12MB0660 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.36.77 X-Mailman-Approved-At: Tue, 13 Sep 2016 11:45:47 -0400 Subject: [Qemu-devel] [RFC PATCH v1 18/22] i386: clear C-bit in SEV guest page table walk X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP In SEV-enabled guest the physical addresses in page table will have C-bit set, we need to clear the C-bit when walking the page table. The C-bit position should be available in cpuid Fn8000_001f[EBX] Signed-off-by: Brijesh Singh --- target-i386/helper.c | 36 +++++++++++++++++++++++++++++------- target-i386/monitor.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 7 deletions(-) diff --git a/target-i386/helper.c b/target-i386/helper.c index 1c250b8..a9d8aef 100644 --- a/target-i386/helper.c +++ b/target-i386/helper.c @@ -1006,6 +1006,22 @@ do_check_protect_pse36: return 1; } +static uint64_t get_me_mask(void) +{ + uint64_t me_mask = 0; + + /* In SEV guest page tables addresses will have memory encryption bit set, + * C-bit should be cleared while doing the page table walk. + */ + if (kvm_sev_enabled()) { + uint32_t pos; + pos = kvm_arch_get_supported_cpuid(kvm_state, 0x8000001f, 0, R_EBX); + me_mask = (1UL << pos); + } + + return ~me_mask; +} + hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, vaddr addr) { X86CPU *cpu = X86_CPU(cs); @@ -1014,6 +1030,12 @@ hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, vaddr addr) uint64_t pte; uint32_t page_offset; int page_size; + uint64_t me_mask; + + me_mask = get_me_mask(); + + /* In SEV guest, CR3 will have memory encryption bit set, clear it */ + env->cr[3] &= me_mask; if (!(env->cr[0] & CR0_PG_MASK)) { pte = addr & env->a20_mask; @@ -1034,13 +1056,13 @@ hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, vaddr addr) } pml4e_addr = ((env->cr[3] & ~0xfff) + (((addr >> 39) & 0x1ff) << 3)) & env->a20_mask; - pml4e = x86_ldq_phys(cs, pml4e_addr); + pml4e = x86_ldq_phys(cs, pml4e_addr) & me_mask; if (!(pml4e & PG_PRESENT_MASK)) { return -1; } pdpe_addr = ((pml4e & PG_ADDRESS_MASK) + (((addr >> 30) & 0x1ff) << 3)) & env->a20_mask; - pdpe = x86_ldq_phys(cs, pdpe_addr); + pdpe = x86_ldq_phys(cs, pdpe_addr) & me_mask; if (!(pdpe & PG_PRESENT_MASK)) { return -1; } @@ -1055,14 +1077,14 @@ hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, vaddr addr) { pdpe_addr = ((env->cr[3] & ~0x1f) + ((addr >> 27) & 0x18)) & env->a20_mask; - pdpe = x86_ldq_phys(cs, pdpe_addr); + pdpe = x86_ldq_phys(cs, pdpe_addr) & me_mask; if (!(pdpe & PG_PRESENT_MASK)) return -1; } pde_addr = ((pdpe & PG_ADDRESS_MASK) + (((addr >> 21) & 0x1ff) << 3)) & env->a20_mask; - pde = x86_ldq_phys(cs, pde_addr); + pde = x86_ldq_phys(cs, pde_addr) & me_mask; if (!(pde & PG_PRESENT_MASK)) { return -1; } @@ -1075,7 +1097,7 @@ hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, vaddr addr) pte_addr = ((pde & PG_ADDRESS_MASK) + (((addr >> 12) & 0x1ff) << 3)) & env->a20_mask; page_size = 4096; - pte = x86_ldq_phys(cs, pte_addr); + pte = x86_ldq_phys(cs, pte_addr) & me_mask; } if (!(pte & PG_PRESENT_MASK)) { return -1; @@ -1085,7 +1107,7 @@ hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, vaddr addr) /* page directory entry */ pde_addr = ((env->cr[3] & ~0xfff) + ((addr >> 20) & 0xffc)) & env->a20_mask; - pde = x86_ldl_phys(cs, pde_addr); + pde = x86_ldl_phys(cs, pde_addr) & me_mask; if (!(pde & PG_PRESENT_MASK)) return -1; if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) { @@ -1094,7 +1116,7 @@ hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, vaddr addr) } else { /* page directory entry */ pte_addr = ((pde & ~0xfff) + ((addr >> 10) & 0xffc)) & env->a20_mask; - pte = x86_ldl_phys(cs, pte_addr); + pte = x86_ldl_phys(cs, pte_addr) & me_mask; if (!(pte & PG_PRESENT_MASK)) { return -1; } diff --git a/target-i386/monitor.c b/target-i386/monitor.c index 47d3c2d..94e6c70 100644 --- a/target-i386/monitor.c +++ b/target-i386/monitor.c @@ -54,6 +54,22 @@ static void print_pte(Monitor *mon, hwaddr addr, pte & PG_RW_MASK ? 'W' : '-'); } +static uint64_t get_me_mask(void) +{ + uint64_t me_mask = 0; + + /* In SEV guest page tables addresses will have memory encryption bit set, + * C-bit should be cleared while doing the page table walk. + */ + if (kvm_sev_enabled()) { + uint32_t pos; + pos = kvm_arch_get_supported_cpuid(kvm_state, 0x8000001f, 0, R_EBX); + me_mask = (1UL << pos); + } + + return ~me_mask; +} + static void tlb_info_32(Monitor *mon, CPUArchState *env) { unsigned int l1, l2; @@ -127,15 +143,21 @@ static void tlb_info_64(Monitor *mon, CPUArchState *env) uint64_t l1, l2, l3, l4; uint64_t pml4e, pdpe, pde, pte; uint64_t pml4_addr, pdp_addr, pd_addr, pt_addr; + uint64_t me_mask; + + me_mask = get_me_mask(); pml4_addr = env->cr[3] & 0x3fffffffff000ULL; + pml4_addr &= me_mask; for (l1 = 0; l1 < 512; l1++) { cpu_physical_memory_read_debug(pml4_addr + l1 * 8, &pml4e, 8); + pml4e &= me_mask; pml4e = le64_to_cpu(pml4e); if (pml4e & PG_PRESENT_MASK) { pdp_addr = pml4e & 0x3fffffffff000ULL; for (l2 = 0; l2 < 512; l2++) { cpu_physical_memory_read_debug(pdp_addr + l2 * 8, &pdpe, 8); + pdpe &= me_mask; pdpe = le64_to_cpu(pdpe); if (pdpe & PG_PRESENT_MASK) { if (pdpe & PG_PSE_MASK) { @@ -147,6 +169,7 @@ static void tlb_info_64(Monitor *mon, CPUArchState *env) for (l3 = 0; l3 < 512; l3++) { cpu_physical_memory_read_debug(pd_addr + l3 * 8, &pde, 8); + pde &= me_mask; pde = le64_to_cpu(pde); if (pde & PG_PRESENT_MASK) { if (pde & PG_PSE_MASK) { @@ -160,6 +183,7 @@ static void tlb_info_64(Monitor *mon, CPUArchState *env) cpu_physical_memory_read_debug(pt_addr + l4 * 8, &pte, 8); + pte &= me_mask; pte = le64_to_cpu(pte); if (pte & PG_PRESENT_MASK) { print_pte(mon, (l1 << 39) + @@ -331,18 +355,24 @@ static void mem_info_64(Monitor *mon, CPUArchState *env) uint64_t l1, l2, l3, l4; uint64_t pml4e, pdpe, pde, pte; uint64_t pml4_addr, pdp_addr, pd_addr, pt_addr, start, end; + uint64_t me_mask; + + me_mask = get_me_mask(); pml4_addr = env->cr[3] & 0x3fffffffff000ULL; + pml4_addr &= me_mask; last_prot = 0; start = -1; for (l1 = 0; l1 < 512; l1++) { cpu_physical_memory_read_debug(pml4_addr + l1 * 8, &pml4e, 8); + pml4e &= me_mask; pml4e = le64_to_cpu(pml4e); end = l1 << 39; if (pml4e & PG_PRESENT_MASK) { pdp_addr = pml4e & 0x3fffffffff000ULL; for (l2 = 0; l2 < 512; l2++) { cpu_physical_memory_read_debug(pdp_addr + l2 * 8, &pdpe, 8); + pdpe &= me_mask; pdpe = le64_to_cpu(pdpe); end = (l1 << 39) + (l2 << 30); if (pdpe & PG_PRESENT_MASK) { @@ -356,6 +386,7 @@ static void mem_info_64(Monitor *mon, CPUArchState *env) for (l3 = 0; l3 < 512; l3++) { cpu_physical_memory_read_debug(pd_addr + l3 * 8, &pde, 8); + pde &= me_mask; pde = le64_to_cpu(pde); end = (l1 << 39) + (l2 << 30) + (l3 << 21); if (pde & PG_PRESENT_MASK) { @@ -370,6 +401,7 @@ static void mem_info_64(Monitor *mon, CPUArchState *env) cpu_physical_memory_read_debug(pt_addr + l4 * 8, &pte, 8); + pte &= me_mask; pte = le64_to_cpu(pte); end = (l1 << 39) + (l2 << 30) + (l3 << 21) + (l4 << 12);