From patchwork Wed Feb 7 16:06:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 10205607 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 171E16020F for ; Wed, 7 Feb 2018 16:24:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 036ED2902F for ; Wed, 7 Feb 2018 16:24:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EC1EE29036; Wed, 7 Feb 2018 16:24:58 +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 E13042902F for ; Wed, 7 Feb 2018 16:24:57 +0000 (UTC) Received: from localhost ([::1]:56187 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ejSWm-0005mK-W4 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 07 Feb 2018 11:24:57 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51788) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ejSFz-00066D-Bw for qemu-devel@nongnu.org; Wed, 07 Feb 2018 11:07:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ejSFx-00070h-0w for qemu-devel@nongnu.org; Wed, 07 Feb 2018 11:07:35 -0500 Received: from mail-by2nam01on0079.outbound.protection.outlook.com ([104.47.34.79]:23232 helo=NAM01-BY2-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 1ejSFw-000705-Jk for qemu-devel@nongnu.org; Wed, 07 Feb 2018 11:07:32 -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=fnuoX+lFJgM/8/5a4LxD4wrgpMTQ2AtKj2v/mKvES7s=; b=n2vSWMBkiP18sWvt6zvnJLafTNWa15JUDxWojddSdkJSLZsmKSKIaYW29uXRpMBbenegQsXVafN4ppJvdMp/1Ui0vfgIgdFFY10ZBGmXahj5XGigNyI+jIEyBZ8ppAQWM5u8S/+WZigYpCgkOI+4nzQdEPLynResDAkCr1pMjXs= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from wsp141597wss.amd.com (165.204.78.1) by CY1PR12MB0152.namprd12.prod.outlook.com (10.161.173.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.464.11; Wed, 7 Feb 2018 16:07:29 +0000 From: Brijesh Singh To: qemu-devel@nongnu.org Date: Wed, 7 Feb 2018 10:06:34 -0600 Message-Id: <20180207160638.98872-22-brijesh.singh@amd.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180207160638.98872-1-brijesh.singh@amd.com> References: <20180207160638.98872-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: DM3PR12CA0071.namprd12.prod.outlook.com (10.161.151.143) To CY1PR12MB0152.namprd12.prod.outlook.com (10.161.173.22) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 313497b8-abe5-4361-1c1e-08d56e44e3c6 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:CY1PR12MB0152; X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0152; 3:/kWrtGK7FOeEFgzHbEWkxYY9pW/fRjLU9RXgOhp52lIRF8o/fPCc6a89yaspIQLjSTR0JiKWznrp50TRYXrIcGp3DbO5E94bZwEx6oA554Qc5uzB7WdDi4ILMeh2Aw9pcjnKYfdzGGBxGt/XlFOhRYSSOpUBPVHfCdYPTDpyM/Rxn+k8BS6hi7z07iVNJBQrTuou1zfP11WJktNV0YO3W3qMP6uYJHfeR/O5R7JnNYaXmr1hAaJP1IupAGCfqBzy; 25:Sd0hgwA0Sc/bFOMnAcxmgF//ngXzhuU8yay+sO7p6DPy6+oXBGpZIMVtwGKnqYrhkayseib2/pVx/FLMt1UNeHK6frfBsS/7bUN23KRp9u0c6qjoso5b+qJ55zKYE2zGUF8JE0PHvPeExrTTLgebe53p/l+8k89L4cV+c7m3/r2gXaZh3q+qAlUo3ieOgf/crH8uglBpx2fszLWNuRKx9xXRxmH8m8cQHbrz/oriYP6edcieV/W4cTBxgCIOAVADemsvY0qGceySw5VNCGUSOl4uWFOS01LW/IC9xhGLw+aFJU9/nWiBxjF5/pWE6pGc/m3euKteIlxmR1LyZZOUCQ==; 31:qzaFgXhCeT6LHI3OHLqqjYRjryiFLXXaQcGUUUgfSFgGF0iMjk1ak9fnAZHzbuX54pVCWWO8DZbh0GgDxrpoJUYcOB43r0X/Cf+ol2iwl9DNVqJtZVnRYUr0mgSrmCGDmBo4WJl6Om8nUz47r2HMyLC2sZ+giEEdKC1Hz0bObQMcxEv6Fl/tNQ+eEXwbEsaSWy519TARlbXvZ2Qf3/2YuvJlIV6OCke3SUqjZaxHciw= X-MS-TrafficTypeDiagnostic: CY1PR12MB0152: X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0152; 20:F6Rje4a2Z08r204IGPXnKioX5svxZc4zcnC5XxJ4eCKlBV7bUKTx288OK7129YoScv0OyVoBmphgU0Ljhm7xYp1Ex81wl0fme6A1h9Bb2kI00SU7/alscA/suJbVl5Pxbi6gfS6XJljhMYnKFl5JoQLHIVXCkfLycon9HUY97B6oPcyx0JvSpg+adFacB2KyO0WZfh6JIyaAcQXxTuXQZmu8XvtJ5MBg0cuwQHSEsFlWCnvl83FbrQXSqdrpJIIz4b4Ptj2s1aq5NFboSk2p6uaArnKXHGT+nGWj0y1Jhh1LuPT3aeCS1buUBZqEZSjYZ0nbRBDT5g3wvMjujanxRDCsrBrGfrS10w/EKlRREFxRMHASo6HGQQ8snuauSQaYc7Yypx3PwRreI3+PqWPEJVpbhdcXXU9BTTSnTyS8XeazVuU3W761FH/q/4wzNya9exDw+bmJQxlyjZwVSj2rCrxFYvm9MgSSwp70EheOjDiKGGftQB/py91qGSXZrsey; 4:x1/OGHvKXpsdw1XyD4mEH41ZUtGqvgmzTgr2T2nfBA/DkDwD3bKaCRcEJYvARsKQn/VTF8Aqt1+NoeCtEsOYTmT9HS4B7t9PtzWcnm564xv+4PYyiprq8bohwG5tqHSb+b9xn/HdZlg2EiGFQgp/Xhm4EQAn2c31owb+DClxnII/i+QQ4+NFIovemhKdB3KT79a3W1RO9kKpjepZKLVV6ucADlBlf3/1+0rAfEuWEt/aQdZZBp7nyVdvll0ejKL+1tIB89LyBqGWDpIqWYyf+1CSHNEMq4fyL753tHRB++JGdmvpvVEVE3yy7qzwSVsn X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(5005006)(8121501046)(3002001)(93006095)(93001095)(10201501046)(3231101)(2400082)(944501161)(6055026)(6041288)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123558120)(20161123564045)(20161123560045)(6072148)(201708071742011); SRVR:CY1PR12MB0152; BCL:0; PCL:0; RULEID:; SRVR:CY1PR12MB0152; X-Forefront-PRVS: 0576145E86 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(1496009)(39860400002)(366004)(39380400002)(346002)(396003)(376002)(199004)(189003)(50226002)(68736007)(8666007)(51416003)(6916009)(7696005)(16526019)(1076002)(50466002)(6486002)(53416004)(7736002)(305945005)(53936002)(8656006)(8936002)(8676002)(7416002)(86362001)(4326008)(81156014)(81166006)(52116002)(6666003)(2950100002)(478600001)(2351001)(66066001)(16586007)(2906002)(54906003)(5660300001)(106356001)(2361001)(47776003)(48376002)(105586002)(3846002)(6116002)(36756003)(386003)(316002)(39060400002)(26005)(97736004)(186003)(76176011)(25786009); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR12MB0152; H:wsp141597wss.amd.com; 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: =?us-ascii?Q?1; CY1PR12MB0152; 23:8ojz91DtZJNMNkqvBEM+6ARWyaBsiRohaHQBB3v/R?= =?us-ascii?Q?g2zTIRuAIVcjcR00mmbTrNhfV8U6h04E3tJcNg4QQXyE7mssBBmAIHTXoQo+?= =?us-ascii?Q?FpMQAkPvfp9RCpbPJpbSHRfzDSwA11K2WQOt2WjBCBXSkrwvwjYOoEa8rY12?= =?us-ascii?Q?WUj2YOyEEA5e58lO3QeM31LQ0ei70MbbIrWWtWrSBLt6oIGCPrWFjRHpA2Qz?= =?us-ascii?Q?k1e3tZZ7g6ua0xF9EuDunJHz2z0k5B2HyFN6EYiKtvW1ylNE5ZY08goF13BI?= =?us-ascii?Q?bZha0v6ts3z8GeGAhSXYHRKwIQIGyUIKfgxNbRR0CeUJiNtcm8SwoIMuc3pB?= =?us-ascii?Q?dsapIAaYnLt1UJuMfgcjduWZwwwkwy7Nmp9GsnmGM1vMxuyn8WUMfR2my+Fw?= =?us-ascii?Q?7UFKK1gqbApSolJGZHcse4mYFGyrZBjR68vtbjxeYrW3xy5j5pUR1IMoct0E?= =?us-ascii?Q?Rqh7gIlTh0dyI37z9ad19BdddxAwNPvwyqrPbEJ0RlyuiySy+xIvHa4zgOhj?= =?us-ascii?Q?PnhiU7HPzBVPOFWZ/rkAwRLWKN5I1FpPUmlpBxKyFy/3ncbHXCEuLLeRBgFW?= =?us-ascii?Q?rZRIpJOecWsVVxJdwy+NfjPg6OavNMbEzm1I9ZtAirnFcSUGAPDBvJkDvitK?= =?us-ascii?Q?KSMyDjtg0C4fBHMJ7L0wvJeiEK+B7jYWuGjpUfAIIuTGPiw8gav2Wjys/ydx?= =?us-ascii?Q?YVWRL1HFz9mEv0uBmLgvt9UC4+cAQRojs8i2ywaRHQ3kO3iO1xKgIf2oIhq/?= =?us-ascii?Q?t5DqJTgiufTqlpTG2w41Hj5qydYqx0BrMn1oqM9czJHu/T2R94UthPHobEVr?= =?us-ascii?Q?8X+63hrlEglOA3/mZAPsYMvMUO9LuAXzZf++oKFYb90admkVq1087q01ILUp?= =?us-ascii?Q?ddwaBTWDFvkcdwEU7mlCvN36DK7tv5OKKdYHAGL9fNdifq1izyC7/yToUvJN?= =?us-ascii?Q?AAT6iLW55RtCaM6v284kSu2pMIDNuvtFVbRSu97UjCuh2QXK47Ez5EIuOvNU?= =?us-ascii?Q?yGz972++0BTLJ9J4OFCRA0X1LXDf44Gj2x0cxrb9vEfasAEs42M67X3+qGZ3?= =?us-ascii?Q?shDBCnt6nMprBMl9GQPbs+WRcDBL9iRGldZbcLcZIwHQ8QJR238v58L5MSev?= =?us-ascii?Q?nbkW5KdmTEaNRpfc6g9nCAf/s/Pt7y9XTGKka6EN4L2vyuhmcL+KJ/YbyuSR?= =?us-ascii?Q?CcEkoGoFqqT1EqNln4F7cd8ZRwEoV8a6AI2KxTDXJUMwzYUAfWqc78Do/Pnw?= =?us-ascii?Q?z3RzandD1oevzMh59R6Nix40LZAnZdj+BrespBDo5E2v+pWzNBRZch6Nacjf?= =?us-ascii?B?Zz09?= X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0152; 6:I02/u8zg52P0LMdMD4KZSX1oDPQe1ggtASzBVL3qrrBXlO6sVw9RqkZk0LztQMBncBUI5xfN+jdvxMNewBa1T9EsR+2mqEsZIYGW+HP87bmnFyhDxnAI64C/qb7vVv5IwAmmDAwCD6XwWAUCERjgCUQ4VOJWquINF5zZkYPVwCQaHo3gichHyOYIUJv4fN988yFG820xeolmpomERFn+zmRQexerVIWjvfmIYYszC3QEFXzapEOuqdXNwrSNcSwXI123m34ur67lbS6TUa4UlvBFT4Cam32YIxPf6i2PGElf5INbl0CdCT5Y6yP3TPVLuLOJbynQSMZTlKK6xc9YToJIm/wZtNO0bm/QFum63tE=; 5:2cgMGNB5fCtBP65/UZBcgNvvu56figejQdgZz1wR1x2TN7BPBXreHje4f07gosR4T6kV+WbioYJ7AeBLgNg295XMBgTFdgcBj5Wb91aht4lyJkjhcmtHafoPvBGZRrLbzrTw7e3GWFRibdCRdrz7BY5lcQu7EfPAFapNvn06NvQ=; 24:nIwY/0Sp4CGni8vNQQmgPqRmBJDA5Jf0xChGFrP+PtQDReF1F4HhXUtkgf/tyPY0x0X7Wh8hw8wjRvzoP99PXOG4YjTnZ2YcAY+R1gJh1pg=; 7:xVJqZ0zqE5tBz5vHdd3lOYdNDFXxcyh2GjstK6BvzsKm4rrNWRqNuSdYNULLVB7QSH9wP6Ipwc6Hq4Mu4IojagaWPQNnIC8y2NHOkrn220dsegUZ2wVm373eAelYuBtmGmjD4NH1WEbrJNYoKbOXwkK2XhzhsQ4Lb83cqzPLRYAc/36Z3qJqy6AVRoChwiGgXwBvgvoyA4+GHfzowbIchgWLBL+0nYiRyDGRpgUcftmQDbzqCDEEYLLFYOuXYbYd SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0152; 20:qPt+F2UUvL6Tk26rzIaQ7PX2beCs8i8Yvs4U37/iWviSgVvDvnYMJU/Cnt6wfTWX1CadaWe0BcpMSuUAH2/9TiySRw4P2D30yGx7Ve2CNVK1t1+XDGloyPOqt7SoAaDjhfAVqvYS9mZ8Ddhfg85kdZ5r4i8pLp2rTOKpuJa3m3hLhPz240ZYCmEu/BEK4MsAMmCGo4ZapepXc9wNuiWHDjCK2GFTfGtJR17rZmrpa35CMz2udzF1PiCuL2bNi0pf X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Feb 2018 16:07:29.1035 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 313497b8-abe5-4361-1c1e-08d56e44e3c6 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR12MB0152 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.34.79 Subject: [Qemu-devel] [PATCH v7 22/26] 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: "Edgar E. Iglesias" , Peter Maydell , Eduardo Habkost , kvm@vger.kernel.org, "Michael S. Tsirkin" , Marcel Apfelbaum , Markus Armbruster , Peter Crosthwaite , Richard Henderson , "Dr. David Alan Gilbert" , Alistair Francis , Christian Borntraeger , Brijesh Singh , Stefan Hajnoczi , Cornelia Huck , Paolo Bonzini , Thomas Lendacky , Borislav Petkov , Richard Henderson 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 | 69 +++++++++++++++++++++++++++++++++------------------ 2 files changed, 63 insertions(+), 37 deletions(-) diff --git a/target/i386/helper.c b/target/i386/helper.c index 5dc9e8839bc8..999154e21e80 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" @@ -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 63f7125ba885..44ae31d13bfa 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" @@ -93,16 +94,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 */ @@ -113,7 +118,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), @@ -135,10 +140,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; } @@ -146,7 +154,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; } @@ -161,7 +169,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; } @@ -176,7 +184,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), @@ -193,11 +201,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); } @@ -225,7 +236,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 @@ -309,19 +321,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) { @@ -333,7 +348,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 | @@ -366,19 +381,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) { @@ -391,7 +409,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) { @@ -405,7 +423,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) { @@ -444,13 +462,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; @@ -461,7 +482,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; @@ -472,7 +493,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; @@ -491,7 +512,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;