From patchwork Thu Sep 22 14:54:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 9345705 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 5EBB060757 for ; Thu, 22 Sep 2016 15:46:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4FFE82AB85 for ; Thu, 22 Sep 2016 15:46:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 43F3C2AB88; Thu, 22 Sep 2016 15:46:13 +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 0D3BA2AB85 for ; Thu, 22 Sep 2016 15:46:11 +0000 (UTC) Received: from localhost ([::1]:51291 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bn6CQ-00066b-2M for patchwork-qemu-devel@patchwork.kernel.org; Thu, 22 Sep 2016 11:46:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46646) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bn5Og-0002lV-87 for qemu-devel@nongnu.org; Thu, 22 Sep 2016 10:54:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bn5Ob-0008Sq-85 for qemu-devel@nongnu.org; Thu, 22 Sep 2016 10:54:46 -0400 Received: from mail-sn1nam02on0067.outbound.protection.outlook.com ([104.47.36.67]:58578 helo=NAM02-SN1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bn5Oa-0008Sc-UJ for qemu-devel@nongnu.org; Thu, 22 Sep 2016 10:54:41 -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=aaNHB0x1rzJHdDviIIV690uvCrmX7ECdRaGOBQlZ+Hk=; b=enIhhKzDCSnF8uB0mIgxqfU67hFbCuGZFyJwpTz3FjGZpdAClmK54ZCtuXZm8N46tmm6tx4i+bYqnWPyjn7OkJttJa2XWgdjoDfCZim2ZtZIWcWdmmNJbir3nTlV9EyLGot8hUJkh1f0WAnwUbO7VKSKbMtDWhJCvZl4NPT5b+U= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from [127.0.1.1] (165.204.77.1) by CY1PR12MB0665.namprd12.prod.outlook.com (10.163.238.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.629.8; Thu, 22 Sep 2016 14:54:36 +0000 From: Brijesh Singh To: , , , , , , , , Date: Thu, 22 Sep 2016 10:54:33 -0400 Message-ID: <147455607314.8519.15676884252094364037.stgit@brijesh-build-machine> In-Reply-To: <147455590865.8519.11191009507297313736.stgit@brijesh-build-machine> References: <147455590865.8519.11191009507297313736.stgit@brijesh-build-machine> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BY2PR21CA0033.namprd21.prod.outlook.com (10.162.74.171) To CY1PR12MB0665.namprd12.prod.outlook.com (10.163.238.150) X-MS-Office365-Filtering-Correlation-Id: c3e7e485-dd9e-4902-6e41-08d3e2f85fda X-Micro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Grpf7oDql93ym1nY8/IdIrshRFFkc4xOmgiAm34vgVWjcNfxgSKEeEU=; 20:ToKjoDY/9L9oQPlHyO7D4UzlN0XlOaKoRnK7QtrWsjIjYhuuelS94pv/ROevm/mPgMfKzHtoRpbMqJBwhfsOFD5DFnUD3BNNyYRhi+OpvkyjHLvQ3kZtJYw7392q2rz3uuXlGd8CEt5mzt+521Wjnlt+zFJdixhNxDw4I8Y9yEOQRcX9W9rfg+/cddICFY5Dacojh2JThqMcxw4KZZFRNDlE+OUI7li42RSX0lClTjY3BMT3sU6buPaa3gYm8e+9bacmk3vv8ugXW9AA3Xe3P6yvbNa0Y68Z8VIFWTF1r7XdLvb9YCePI+iMiWwp4nqYNftp94UBsPfp13YIT7qN3WmwZFscA7CbcdSPnCPvlsUlRQ/AlRjMCZRszWNQuqJujX5oDeQe/3RnuOkjUTGCbLRVWI9N6+30ERi9A9d4KyaWzyaawdU1++UPK1VI7POvBSz5RGl2BjAgjLNpgtgMAdrrbU5wOpNN6ZeMiem58MpISVm9S79mt0cRovO7kG29 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)(5005006)(8121501046)(3002001)(10201501046)(6055026); SRVR:CY1PR12MB0665; BCL:0; PCL:0; RULEID:; SRVR:CY1PR12MB0665; X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0665; 4:evYNnrTPW2KPQZJBSczXqppMV1ijPTAaf5X6DH7BgBL/Rz6c2tFw+As2OTnptqP3MqFs7OrnEoRYeiI95c7ifvBpVnmYPROb+Qw0OpBLamy0NX1BHzZZuE5dSME4ilgIBT9QDRaDsrIeCbD7SVMlJzT4JEr4bVsfbrlUFw/lSFy6iACtdMr/6wNCF3C8zLLNPBAsvJ4Mh1FkvjW1D3j3MnZG3fu8QwRoVrTFmJdZLKNXNlnu8MYe9tZoS/xb/92yvWva4cCMPFBFwy2Ua/fv30+Hh02G9N0U9PKgqQ9lF73pYgg5VMtxkMQSHVEP7Fapiil/GfgKKs9WouuQz6KIPGljxCb8sX+K7lMBSCGqiTPifqADtEfXKwZ5IFFL8KR8vlpWmnIF+q5ecztbu8gx1b8Zr7ZQ2aN29OFHqjwP2xsn9O/zg/J8z2RJVd8DjFVI X-Forefront-PRVS: 0073BFEF03 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6049001)(6009001)(7916002)(199003)(189002)(77096005)(229853001)(103116003)(19580395003)(305945005)(47776003)(33716001)(19580405001)(23676002)(105586002)(189998001)(7736002)(83506001)(33646002)(92566002)(8676002)(230700001)(106356001)(81156014)(107886002)(6116002)(9686002)(81166006)(76176999)(2201001)(97736004)(5001770100001)(42186005)(86362001)(68736007)(2906002)(50986999)(66066001)(3846002)(54356999)(5660300001)(50466002)(101416001)(4001350100001)(2950100001)(7846002)(586003)(575784001)(217873001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR12MB0665; H:[127.0.1.1]; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtDWTFQUjEyTUIwNjY1OzIzOjZBTTJiZVNHK0ljcFVoMk56TUZ2TTBBNk8y?= =?utf-8?B?NGFGQUR1MCtQN3JYTEd0L25mOWNWS1llMHJOdVdRbEZpY3hLTmpvRFFVanIx?= =?utf-8?B?b2JCWHBzZ3RZUXFjSGl4TjIrMjQxV2R6QnVETkEvUjAxOE9oZDZvU0xOSE44?= =?utf-8?B?WHFWOHY1SVZjRnBzNGtpeHZPRzZqT1ByekNmWWxHZStLNi9aQTl5cUY2bGUv?= =?utf-8?B?MHprSWZUSTlneXdWdml4aGlPQWRGMmFIa2N5WkZzV3hDWmh2RnYyQWNZckZx?= =?utf-8?B?aDN4dHRVVngwY1dLWGxMdTkxaEpPM29uNUZYRTJ4cktEVmdRd3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pE2TJZm35dJ6kV1AKQaqhRh8JzP5TDfa8qywNq7xWUuJon9Vcw==; 24:maFEhIWHZ/IoQsfXFMKgP/DUO3vItQZULI++euEJJqVha+xS+1tJN9Kl8Icb5iSjyloBpjR9qeeD9ryHplr1r5uu2tQmkeSxLNHrn1njPYA=; 7:fCgSKUhffsVpS4G3qtHE0ZF7VNHpqdjyDB0RFkIhBBn3ZZDkbVs/LLiJstlOWQ2dH11wqVKdXmGkq7Hgwh9/Q9YlUzW4yJvAWyi/jsKlnHQQttWGtCMruRi6jQD4YKsBqQR284xnYE2x7rT6lAFw0iniIydHC2PJSUUJ6wKhDmdhuw3m7tDqzE4+ALcw3rooedtiznwX9bui34SfEUC+MS38qXjzPTGco7OwQsHmMvPczLosp7V18GwV2IbCi4NAYZx7S3+CGdbBOJV1f06242CXR+LK2vvjq6TJKVpywsIAQe9MzZCXQuPP8QbPKX3X SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0665; 20:qb6yClC4af28utB8AIZfuBbyOwqB/YR3ZBjJeSNrLL7kcosk6PRK9+KCHbLDh/ToRhUcKrTafKKlEsEcZyUKl4ZOj4cso07xyWOCrufE2zVZm7aL6/UPVDyBYJMkDHU3N9oNIh0x53/ggSRmvUck/lu93OtaoA0UEPM+nbOe6KQeupb69tfs2nbAFDZrHXhDneM2buZ81Yyb9DlgEDWmyFKxWQJ+TklOcuRSkuB7eFgb3l6P/kt+G2Qjo8/sg7uo X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Sep 2016 14:54:36.7241 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR12MB0665 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.36.67 Subject: [Qemu-devel] [RFC PATCH v2 16/16] 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 | 35 +++++++++++++++++++++++++++++------ target-i386/monitor.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 6 deletions(-) diff --git a/target-i386/helper.c b/target-i386/helper.c index 88fa4fa..b8e9c7b 100644 --- a/target-i386/helper.c +++ b/target-i386/helper.c @@ -21,6 +21,7 @@ #include "cpu.h" #include "exec/exec-all.h" #include "sysemu/kvm.h" +#include "sysemu/sev.h" #include "kvm_i386.h" #ifndef CONFIG_USER_ONLY #include "sysemu/sysemu.h" @@ -1006,6 +1007,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 (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 +1031,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 +1057,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 = ldq_phys_debug(cs, pml4e_addr); + pml4e = ldq_phys_debug(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 = ldq_phys_debug(cs, pdpe_addr); + pdpe = ldq_phys_debug(cs, pdpe_addr) & me_mask; if (!(pdpe & PG_PRESENT_MASK)) { return -1; } @@ -1055,14 +1078,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 = ldq_phys_debug(cs, pdpe_addr); + pdpe = ldq_phys_debug(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 = ldq_phys_debug(cs, pde_addr); + pde = ldq_phys_debug(cs, pde_addr) & me_mask; if (!(pde & PG_PRESENT_MASK)) { return -1; } @@ -1075,7 +1098,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 = ldq_phys_debug(cs, pte_addr); + pte = ldq_phys_debug(cs, pte_addr) & me_mask; } if (!(pte & PG_PRESENT_MASK)) { return -1; @@ -1094,7 +1117,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 = ldl_phys_debug(cs, pte_addr); + pte = ldl_phys_debug(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..0fe0c03 100644 --- a/target-i386/monitor.c +++ b/target-i386/monitor.c @@ -27,6 +27,7 @@ #include "monitor/hmp-target.h" #include "hw/i386/pc.h" #include "sysemu/kvm.h" +#include "sysemu/sev.h" #include "hmp.h" @@ -54,6 +55,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 (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 +144,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 +170,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 +184,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 +356,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 +387,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 +402,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);