From patchwork Wed Mar 7 16:50:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 10264539 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 8ADE2602C8 for ; Wed, 7 Mar 2018 17:08:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 74CE8294D4 for ; Wed, 7 Mar 2018 17:08:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 691C829561; Wed, 7 Mar 2018 17:08:12 +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=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable 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 884D7294D4 for ; Wed, 7 Mar 2018 17:08:11 +0000 (UTC) Received: from localhost ([::1]:34430 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etcXy-0003YO-NH for patchwork-qemu-devel@patchwork.kernel.org; Wed, 07 Mar 2018 12:08:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50497) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etcHr-0004uz-U2 for qemu-devel@nongnu.org; Wed, 07 Mar 2018 11:51:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1etcHn-0008Qn-DQ for qemu-devel@nongnu.org; Wed, 07 Mar 2018 11:51:31 -0500 Received: from mail-bl2nam02on0056.outbound.protection.outlook.com ([104.47.38.56]:46551 helo=NAM02-BL2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1etcHn-0008QI-7V for qemu-devel@nongnu.org; Wed, 07 Mar 2018 11:51:27 -0500 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=7G9B06V1ZVnYtJ/DQG406HoMbC5Mp9cdR+4oFfg5BXw=; b=DWPdL90aobuuelaeBjbtikbluozjpIXk312EMkyH4poKMr1HQ/CqaVH6hAc8nZzAoPfd6rR+omzRxefUL/OsupKNyg+WuthX8VsY8+4v0aGzHZJpJNZR52x1WlrRVw5JifKUs0y/2eS0tQw0MECyTHliOBwSuA06IdHYUrZbM/I= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from wsp141597wss.amd.com (165.204.78.1) by SN1PR12MB0158.namprd12.prod.outlook.com (2a01:111:e400:5144::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.548.13; Wed, 7 Mar 2018 16:51:22 +0000 From: Brijesh Singh To: qemu-devel@nongnu.org Date: Wed, 7 Mar 2018 10:50:32 -0600 Message-Id: <20180307165038.88640-23-brijesh.singh@amd.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180307165038.88640-1-brijesh.singh@amd.com> References: <20180307165038.88640-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: SN4PR0501CA0095.namprd05.prod.outlook.com (2603:10b6:803:22::33) To SN1PR12MB0158.namprd12.prod.outlook.com (2a01:111:e400:5144::17) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 470a34bd-6062-4a87-695c-08d5844ba907 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:SN1PR12MB0158; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 3:PZvVhBFCawFdHRvbEUCL6dHjocJdaeBvLGwcwzh/wtwpdMJiL+/BncESmgLMj8Z0DIs4qOy8/PFYwukh5G3V0X8KYhz/8Cgur9PECGvu/oZBnWoImWvQs0/LBj1KEX6Xw7LoAXLSpXh5A/gH0LnO3I+Z40w6m5E/4XMawsxZXZRmLLzJxhtKIPH1JMFAIHiOJoGQPCcxxHATLnHBc3k3XYD7uQl4xRbqDcJmk5gXWBmdtWjJW7ygpHYb63FgfOay; 25:Nkl59FQ6/sT/nS8UKO+HRoqoBl9o8LII0yn5piaPbcRYQajCSGNp7/GbjM4DjrbWbujEV64liBlBuGEVWwYTLHsqMk6x/Mgjg6oEF6y3wP0UcB8sKiFdhhaWNmsmXp9BeNR+OFAHoTkKUWVar98MT7WJQMXtF0lGAgtjvpLhEutG01zF4roLVqtHBerOuoPmcGLf6lSja1R539AHhyBBs7fbZsaqB48jk7Qbhi0ucew4raiwvAnNysHY1EOcsiRd0SS/1mXPkU+AHsmPArh9fBTtiaTTq1o9ANyhIun8iHspW6xPSPNlGKQYHT9WK6/5xq3IY5JIrA/52j7+zmPxKg==; 31:xMB7RFxBft3q6pZ5FqRLIsMbA/pO9iRo50LhIQxNinuNcgHzsJ1SLbbDYlCUDt0cyeJ66+a9BxKizVxZmh7fGUyvbC875USG55sK6l2sUqB+9a3/BHw4DUo5cr7CEWCpOIDQp+s8gIIShup+MpWIk0wrvVUiBw8B5p56xhjpQ1zOViMpHAspZr/8FJ1iG38AOgIRJeI2F2cLc1xfZLNi6oGWXbMHNnvqznAmHH4tqsc= X-MS-TrafficTypeDiagnostic: SN1PR12MB0158: X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 20:WwS+uCt1lvuBpaTsrq1tY0UwiPWTe+1p9crKo5W2p6LGgFI+aJ48YQSUPSgyU+QS3eeTpQ1u/Ry2mi8+luFehnXTMV7q2/xtpEBmqs8ZY5nZrf2FI8P+s/QZ0JIpzm5/DlsBY5Jo3Z0/xmmf8f0VZcXWsip4iDK19q1Gp+78CW4RXofpdPhz3t5W2Hh78ucvHqDeCN2NfkiSOrYDsfPHA7/2drghj/Ncq0WdhJBaTSW0AEXLi5gXb/VbTWWhThTtfrM+mriOf1PB5/0Peb4LF+d1sIBW4WcYKc2nho3T7SR2Ayg7nupu112aB47Q5WSgueXkSIKp1mGeWcRiSVoXqSTwT9xeT0aMfEaK83zcztIPK4LHdef3vCoVZNYlf+HL3qy5gULT/ffLn5SeLJK2XjefMCxEzie8WU2l1EnX7x37hnbQs5WR+KN2uFx1Q+5OG1SCY23E64z1ldm4SJ+O+toLR+yo/oxI1eYjmwOBhjen76JE3tYH2yfSzR6DJlnm; 4:DUK1CNPgmXCp6csdPaiQOosnsfM484UKUgfARNqmYLk6lKIk6eV03nbnkwzKZlXfBG3qazNiiFQTf5YO84VV9LkGhxPqvjpvZexO2j9pZqSp+d1A2SMzMqBfhJW5xvMbU2bxmn6ewJNbqBoVQnN6kfjsaHGgEtntRiD2nXxT07mBJK7sdjNudEhcjSd+oIuL2pPm4Jz/n0uZeA13wLD8f/eI7L8kwM+Q1nvzsbS+T/5IhMWocuKU+WnDsEfi3bHRf3smKbYmkhv6efaBOBqvnKikC9WEueGZuXu1sN2Cd/b8RKgKK9xZxykqwuDDO2tC X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040501)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3231220)(944501244)(52105095)(3002001)(6055026)(6041288)(20161123562045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123560045)(6072148)(201708071742011); SRVR:SN1PR12MB0158; BCL:0; PCL:0; RULEID:; SRVR:SN1PR12MB0158; X-Forefront-PRVS: 0604AFA86B X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(1496009)(39380400002)(39860400002)(376002)(346002)(396003)(366004)(189003)(199004)(53936002)(8666007)(2950100002)(6486002)(6666003)(6916009)(53416004)(3846002)(1076002)(6116002)(4326008)(54906003)(8656006)(2906002)(25786009)(386003)(68736007)(478600001)(48376002)(50466002)(105586002)(2361001)(2351001)(86362001)(66066001)(106356001)(47776003)(186003)(16526019)(51416003)(76176011)(52116002)(7696005)(26005)(16586007)(316002)(50226002)(8936002)(8676002)(81156014)(81166006)(36756003)(7416002)(97736004)(305945005)(7736002)(39060400002)(5660300001); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0158; H:wsp141597wss.amd.com; 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: =?us-ascii?Q?1; SN1PR12MB0158; 23:Y6KaUnkpys6m6y8BkKamyNRTf/CMZA0J3wSSPxgkr?= =?us-ascii?Q?EEpGEdCm9sbQL4DKenE9zbc1xgvarWh4tpLBWZK02J4saF/l+GsIDLO+Q9JJ?= =?us-ascii?Q?9kJreH+LT/9Ole4EpTlLHzwten1tEfN8KPAsRCqM/FnzM3Q8LMBMPNATbyOG?= =?us-ascii?Q?jdEATGhi83LPwO8E+oT8iHXHGT55bg3qeOIb86teZNfJ33Rda1zGKEV86ADX?= =?us-ascii?Q?D3OhLohChpOBN/vdxoAwPfSDszGf6SQU+KrLB/UJcm2ndOiLSc1c0wbFEnVg?= =?us-ascii?Q?KjARVV+qPnVXNbPGwxqD8DI3wZ6cBNejk8yYhhzBwjGur7Rs2POz2P7ZnstU?= =?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cUMuw5YnDfY2tDlHayVNqV9aM6omtatnmMSu5FksGmZDOcuQCeWlI9AejbYz1PKKqSbQcyhEtahP3CDnIKXyYEJ2Oo9jkB6A/4EfcoIW8baIXKP6wQVvPIpibf0Las501syRgFA5JJNhu1uSD/4wpKP7WHzen0OJibmITkTlejkapRpF/a+ZZf3DceozjuHysl6dXHJzJwtDVls1kU SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 20:poDmGQ8ks8g0b0VxLz2DwFBhKd0dbtjOJY4eX3BvQMOw0KcACAbz1pynWUnmJFz+x4WzXz5G+DCuloi3HiZziBv5QlDiEq0qI6JFJ8bxmmaphzHIKGC5Qe0wGCx3NeJUyKK1PyIZGBClgHoNt3+NF6wLlrQ8c8KM3nexccfiFOFaQ9o7qV8jmKoTa3+Tzc5s5nfhzuhJQlBVQPqvGslmZyar1yrUnpqK0pecAXyIJkx2t3rQNqvSWTUDTmtjFacZ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2018 16:51:22.9948 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 470a34bd-6062-4a87-695c-08d5844ba907 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0158 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.38.56 Subject: [Qemu-devel] [PATCH v11 22/28] target/i386: clear C-bit when walking SEV guest page table 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: , Cc: Peter Maydell , Brijesh Singh , kvm@vger.kernel.org, "Michael S. Tsirkin" , Stefan Hajnoczi , Alexander Graf , "Edgar E. Iglesias" , Markus Armbruster , Bruce Rogers , Christian Borntraeger , Marcel Apfelbaum , Borislav Petkov , Thomas Lendacky , Eduardo Habkost , Richard Henderson , "Dr. David Alan Gilbert" , Alistair Francis , Cornelia Huck , Richard Henderson , Peter Crosthwaite , Paolo Bonzini 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 pte entry will have C-bit set, we need to clear the C-bit when walking the page table. Cc: Paolo Bonzini Cc: Richard Henderson Cc: Eduardo Habkost Signed-off-by: Brijesh Singh --- target/i386/helper.c | 31 +++++++++++++---------- target/i386/monitor.c | 68 +++++++++++++++++++++++++++++++++------------------ 2 files changed, 62 insertions(+), 37 deletions(-) diff --git a/target/i386/helper.c b/target/i386/helper.c index 58fb6eec562a..dc5c7005cf13 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 "sev_i386.h" #include "kvm_i386.h" #ifndef CONFIG_USER_ONLY #include "sysemu/sysemu.h" @@ -732,6 +733,9 @@ hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, vaddr addr) int32_t a20_mask; uint32_t page_offset; int page_size; + uint64_t me_mask; + + me_mask = sev_get_me_mask(); a20_mask = x86_get_a20_mask(env); if (!(env->cr[0] & CR0_PG_MASK)) { @@ -755,25 +759,25 @@ hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, vaddr addr) } if (la57) { - pml5e_addr = ((env->cr[3] & ~0xfff) + + pml5e_addr = ((env->cr[3] & ~0xfff & me_mask) + (((addr >> 48) & 0x1ff) << 3)) & a20_mask; - pml5e = ldq_phys_debug(cs, pml5e_addr); + pml5e = ldq_phys_debug(cs, pml5e_addr) & me_mask; if (!(pml5e & PG_PRESENT_MASK)) { return -1; } } else { - pml5e = env->cr[3]; + pml5e = env->cr[3] & me_mask; } pml4e_addr = ((pml5e & PG_ADDRESS_MASK) + (((addr >> 39) & 0x1ff) << 3)) & 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)) & a20_mask; - pdpe = x86_ldq_phys(cs, pdpe_addr); + pdpe = ldq_phys_debug(cs, pdpe_addr) & me_mask; if (!(pdpe & PG_PRESENT_MASK)) { return -1; } @@ -786,16 +790,16 @@ hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, vaddr addr) } else #endif { - pdpe_addr = ((env->cr[3] & ~0x1f) + ((addr >> 27) & 0x18)) & - a20_mask; - pdpe = ldq_phys_debug(cs, pdpe_addr); + pdpe_addr = ((env->cr[3] & ~0x1f & me_mask) + ((addr >> 27) & 0x18)) + & a20_mask; + 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)) & 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; } @@ -808,7 +812,7 @@ hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, vaddr addr) pte_addr = ((pde & PG_ADDRESS_MASK) + (((addr >> 12) & 0x1ff) << 3)) & 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; @@ -817,8 +821,9 @@ hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, vaddr addr) uint32_t pde; /* page directory entry */ - pde_addr = ((env->cr[3] & ~0xfff) + ((addr >> 20) & 0xffc)) & a20_mask; - pde = ldl_phys_debug(cs, pde_addr); + pde_addr = ((env->cr[3] & ~0xfff & me_mask) + ((addr >> 20) & 0xffc)) + & a20_mask; + pde = ldl_phys_debug(cs, pde_addr) & me_mask; if (!(pde & PG_PRESENT_MASK)) return -1; if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) { @@ -827,7 +832,7 @@ hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, vaddr addr) } else { /* page directory entry */ pte_addr = ((pde & ~0xfff) + ((addr >> 10) & 0xffc)) & 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 4d9019626031..7df31c3cdf1b 100644 --- a/target/i386/monitor.c +++ b/target/i386/monitor.c @@ -98,16 +98,20 @@ static void tlb_info_pae32(Monitor *mon, CPUArchState *env) unsigned int l1, l2, l3; uint64_t pdpe, pde, pte; uint64_t pdp_addr, pd_addr, pt_addr; + uint64_t me_mask; + + me_mask = sev_get_me_mask(); pdp_addr = env->cr[3] & ~0x1f; + pdp_addr &= me_mask; for (l1 = 0; l1 < 4; l1++) { cpu_physical_memory_read_debug(pdp_addr + l1 * 8, &pdpe, 8); - pdpe = le64_to_cpu(pdpe); + pdpe = le64_to_cpu(pdpe & me_mask); if (pdpe & PG_PRESENT_MASK) { pd_addr = pdpe & 0x3fffffffff000ULL; for (l2 = 0; l2 < 512; l2++) { cpu_physical_memory_read_debug(pd_addr + l2 * 8, &pde, 8); - pde = le64_to_cpu(pde); + pde = le64_to_cpu(pde & me_mask); if (pde & PG_PRESENT_MASK) { if (pde & PG_PSE_MASK) { /* 2M pages with PAE, CR4.PSE is ignored */ @@ -118,7 +122,7 @@ static void tlb_info_pae32(Monitor *mon, CPUArchState *env) for (l3 = 0; l3 < 512; l3++) { cpu_physical_memory_read_debug(pt_addr + l3 * 8, &pte, 8); - pte = le64_to_cpu(pte); + pte = le64_to_cpu(pte & me_mask); if (pte & PG_PRESENT_MASK) { print_pte(mon, env, (l1 << 30) + (l2 << 21) + (l3 << 12), @@ -140,10 +144,13 @@ static void tlb_info_la48(Monitor *mon, CPUArchState *env, uint64_t l1, l2, l3, l4; uint64_t pml4e, pdpe, pde, pte; uint64_t pdp_addr, pd_addr, pt_addr; + uint64_t me_mask; + + me_mask = sev_get_me_mask(); for (l1 = 0; l1 < 512; l1++) { cpu_physical_memory_read_debug(pml4_addr + l1 * 8, &pml4e, 8); - pml4e = le64_to_cpu(pml4e); + pml4e = le64_to_cpu(pml4e & me_mask); if (!(pml4e & PG_PRESENT_MASK)) { continue; } @@ -151,7 +158,7 @@ static void tlb_info_la48(Monitor *mon, CPUArchState *env, pdp_addr = pml4e & 0x3fffffffff000ULL; for (l2 = 0; l2 < 512; l2++) { cpu_physical_memory_read_debug(pdp_addr + l2 * 8, &pdpe, 8); - pdpe = le64_to_cpu(pdpe); + pdpe = le64_to_cpu(pdpe & me_mask); if (!(pdpe & PG_PRESENT_MASK)) { continue; } @@ -166,7 +173,7 @@ static void tlb_info_la48(Monitor *mon, CPUArchState *env, pd_addr = pdpe & 0x3fffffffff000ULL; for (l3 = 0; l3 < 512; l3++) { cpu_physical_memory_read_debug(pd_addr + l3 * 8, &pde, 8); - pde = le64_to_cpu(pde); + pde = le64_to_cpu(pde & me_mask); if (!(pde & PG_PRESENT_MASK)) { continue; } @@ -181,7 +188,7 @@ static void tlb_info_la48(Monitor *mon, CPUArchState *env, pt_addr = pde & 0x3fffffffff000ULL; for (l4 = 0; l4 < 512; l4++) { cpu_physical_memory_read_debug(pt_addr + l4 * 8, &pte, 8); - pte = le64_to_cpu(pte); + pte = le64_to_cpu(pte & me_mask); if (pte & PG_PRESENT_MASK) { print_pte(mon, env, (l0 << 48) + (l1 << 39) + (l2 << 30) + (l3 << 21) + (l4 << 12), @@ -198,11 +205,14 @@ static void tlb_info_la57(Monitor *mon, CPUArchState *env) uint64_t l0; uint64_t pml5e; uint64_t pml5_addr; + uint64_t me_mask; - pml5_addr = env->cr[3] & 0x3fffffffff000ULL; + me_mask = sev_get_me_mask(); + + pml5_addr = env->cr[3] & 0x3fffffffff000ULL & me_mask; for (l0 = 0; l0 < 512; l0++) { cpu_physical_memory_read_debug(pml5_addr + l0 * 8, &pml5e, 8); - pml5e = le64_to_cpu(pml5e); + pml5e = le64_to_cpu(pml5e & me_mask); if (pml5e & PG_PRESENT_MASK) { tlb_info_la48(mon, env, l0, pml5e & 0x3fffffffff000ULL); } @@ -230,7 +240,8 @@ void hmp_info_tlb(Monitor *mon, const QDict *qdict) if (env->cr[4] & CR4_LA57_MASK) { tlb_info_la57(mon, env); } else { - tlb_info_la48(mon, env, 0, env->cr[3] & 0x3fffffffff000ULL); + tlb_info_la48(mon, env, 0, env->cr[3] & 0x3fffffffff000ULL & + sev_get_me_mask()); } } else #endif @@ -314,19 +325,22 @@ static void mem_info_pae32(Monitor *mon, CPUArchState *env) uint64_t pdpe, pde, pte; uint64_t pdp_addr, pd_addr, pt_addr; hwaddr start, end; + uint64_t me_mask; - pdp_addr = env->cr[3] & ~0x1f; + me_mask = sev_get_me_mask(); + + pdp_addr = env->cr[3] & ~0x1f & me_mask; last_prot = 0; start = -1; for (l1 = 0; l1 < 4; l1++) { cpu_physical_memory_read_debug(pdp_addr + l1 * 8, &pdpe, 8); - pdpe = le64_to_cpu(pdpe); + pdpe = le64_to_cpu(pdpe & me_mask); end = l1 << 30; if (pdpe & PG_PRESENT_MASK) { pd_addr = pdpe & 0x3fffffffff000ULL; for (l2 = 0; l2 < 512; l2++) { cpu_physical_memory_read_debug(pd_addr + l2 * 8, &pde, 8); - pde = le64_to_cpu(pde); + pde = le64_to_cpu(pde & me_mask); end = (l1 << 30) + (l2 << 21); if (pde & PG_PRESENT_MASK) { if (pde & PG_PSE_MASK) { @@ -338,7 +352,7 @@ static void mem_info_pae32(Monitor *mon, CPUArchState *env) for (l3 = 0; l3 < 512; l3++) { cpu_physical_memory_read_debug(pt_addr + l3 * 8, &pte, 8); - pte = le64_to_cpu(pte); + pte = le64_to_cpu(pte & me_mask); end = (l1 << 30) + (l2 << 21) + (l3 << 12); if (pte & PG_PRESENT_MASK) { prot = pte & pde & (PG_USER_MASK | PG_RW_MASK | @@ -371,19 +385,22 @@ static void mem_info_la48(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 = sev_get_me_mask(); - pml4_addr = env->cr[3] & 0x3fffffffff000ULL; + pml4_addr = env->cr[3] & 0x3fffffffff000ULL & 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 = le64_to_cpu(pml4e); + pml4e = le64_to_cpu(pml4e & me_mask); 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 = le64_to_cpu(pdpe); + pdpe = le64_to_cpu(pdpe & me_mask); end = (l1 << 39) + (l2 << 30); if (pdpe & PG_PRESENT_MASK) { if (pdpe & PG_PSE_MASK) { @@ -396,7 +413,7 @@ static void mem_info_la48(Monitor *mon, CPUArchState *env) for (l3 = 0; l3 < 512; l3++) { cpu_physical_memory_read_debug(pd_addr + l3 * 8, &pde, 8); - pde = le64_to_cpu(pde); + pde = le64_to_cpu(pde & me_mask); end = (l1 << 39) + (l2 << 30) + (l3 << 21); if (pde & PG_PRESENT_MASK) { if (pde & PG_PSE_MASK) { @@ -410,7 +427,7 @@ static void mem_info_la48(Monitor *mon, CPUArchState *env) cpu_physical_memory_read_debug(pt_addr + l4 * 8, &pte, 8); - pte = le64_to_cpu(pte); + pte = le64_to_cpu(pte & me_mask); end = (l1 << 39) + (l2 << 30) + (l3 << 21) + (l4 << 12); if (pte & PG_PRESENT_MASK) { @@ -449,13 +466,16 @@ static void mem_info_la57(Monitor *mon, CPUArchState *env) uint64_t l0, l1, l2, l3, l4; uint64_t pml5e, pml4e, pdpe, pde, pte; uint64_t pml5_addr, pml4_addr, pdp_addr, pd_addr, pt_addr, start, end; + uint64_t me_mask; + + me_mask = sev_get_me_mask(); - pml5_addr = env->cr[3] & 0x3fffffffff000ULL; + pml5_addr = env->cr[3] & 0x3fffffffff000ULL & me_mask; last_prot = 0; start = -1; for (l0 = 0; l0 < 512; l0++) { cpu_physical_memory_read_debug(pml5_addr + l0 * 8, &pml5e, 8); - pml5e = le64_to_cpu(pml5e); + pml5e = le64_to_cpu(pml5e & me_mask); end = l0 << 48; if (!(pml5e & PG_PRESENT_MASK)) { prot = 0; @@ -466,7 +486,7 @@ static void mem_info_la57(Monitor *mon, CPUArchState *env) pml4_addr = pml5e & 0x3fffffffff000ULL; for (l1 = 0; l1 < 512; l1++) { cpu_physical_memory_read_debug(pml4_addr + l1 * 8, &pml4e, 8); - pml4e = le64_to_cpu(pml4e); + pml4e = le64_to_cpu(pml4e & me_mask); end = (l0 << 48) + (l1 << 39); if (!(pml4e & PG_PRESENT_MASK)) { prot = 0; @@ -477,7 +497,7 @@ static void mem_info_la57(Monitor *mon, CPUArchState *env) pdp_addr = pml4e & 0x3fffffffff000ULL; for (l2 = 0; l2 < 512; l2++) { cpu_physical_memory_read_debug(pdp_addr + l2 * 8, &pdpe, 8); - pdpe = le64_to_cpu(pdpe); + pdpe = le64_to_cpu(pdpe & me_mask); end = (l0 << 48) + (l1 << 39) + (l2 << 30); if (pdpe & PG_PRESENT_MASK) { prot = 0; @@ -496,7 +516,7 @@ static void mem_info_la57(Monitor *mon, CPUArchState *env) pd_addr = pdpe & 0x3fffffffff000ULL; for (l3 = 0; l3 < 512; l3++) { cpu_physical_memory_read_debug(pd_addr + l3 * 8, &pde, 8); - pde = le64_to_cpu(pde); + pde = le64_to_cpu(pde & me_mask); end = (l0 << 48) + (l1 << 39) + (l2 << 30) + (l3 << 21); if (pde & PG_PRESENT_MASK) { prot = 0;