Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754822AbdLUWDG (ORCPT ); Thu, 21 Dec 2017 17:03:06 -0500 Received: from mail-bl2nam02on0052.outbound.protection.outlook.com ([104.47.38.52]:16318 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750920AbdLUWC7 (ORCPT ); Thu, 21 Dec 2017 17:02:59 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; From: Tom Lendacky Subject: [PATCH v2 1/5] x86/mm: Cleanup register saving in mem_encrypt_boot.S To: x86@kernel.org Cc: Brijesh Singh , linux-kernel@vger.kernel.org, Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Thomas Gleixner Date: Thu, 21 Dec 2017 16:02:53 -0600 Message-ID: <20171221220253.30632.5416.stgit@tlendack-t1.amdoffice.net> In-Reply-To: <20171221220242.30632.5031.stgit@tlendack-t1.amdoffice.net> References: <20171221220242.30632.5031.stgit@tlendack-t1.amdoffice.net> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BN6PR18CA0018.namprd18.prod.outlook.com (10.175.188.28) To CY4PR12MB1143.namprd12.prod.outlook.com (10.168.164.135) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: dcfdb498-6fbc-49f6-11f1-08d548be97de X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(48565401081)(5600026)(4604075)(2017052603307)(7153060);SRVR:CY4PR12MB1143; X-Microsoft-Exchange-Diagnostics: 1;CY4PR12MB1143;3:z0Z5vXb7QaHRFKy7VlQv8Dd3t1pvKN/5/J0h/K3QrIvifZXNKYpW44Ql+29XamuC6Jq52bni62EH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QdOOYXTquQZBSRPJOQ/0Sr9VhxTmQGSpbc0nnoiYgJYbrHfCcThm4ENDSYShtGYWr0uOBjz2RoXaxD0YytrhRVZmBKt03yQYRud7A8UmE4A2CupGPfDLd8p/+j1SarGtVdylY2YLIe0o0o3wqSc9785p4yo4fsLbCb0H0AWp/71gzmqKOYT8nIqbhuIKbUDeiIVeP9MA3k9UVW44uZ6aaDZc5G3KkmI/hIKSTWSlN2y2KgTQbXzmk1VydUvA3zutXZZldGyrhRHsiX2b23VAecd1gp/Sk1mWHn5ah9/;4:iyqirAYPFaAWGi8Iu5Z7+RE8CHgf1xCts+gkxpUCJIYX2wHpzSjgaotUfvrgoSIHElSBhxGX9LSNncaXPOWS4HQCtMNBzxJPoh5dS3VibjemaMKl23LeQdczxgNoNi7E/VnCuKf4JUoUMQPIL+zm8nIyI2c71N9AVHj6j11Ycfwrc1Wi9XhxhQQ2b688qfqkkJtT2D7k1ca5VtIEm9xYwOEGDQGvGaqMyf6DKykhHSmnbVZzoT9XiABetWcMiAnf39rl575jxQX07GgQS6Z7FGdIuRqNnQw8B42FfqxXR0kpnZncUWuitv4iSd5pqo20 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040470)(2401047)(8121501046)(5005006)(3002001)(93006095)(93001095)(3231023)(10201501046)(6055026)(6041268)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(20161123564045)(20161123558120)(6072148)(201708071742011);SRVR:CY4PR12MB1143;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:CY4PR12MB1143; X-Forefront-PRVS: 0528942FD8 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(346002)(39860400002)(366004)(39380400002)(396003)(376002)(199004)(189003)(53936002)(66066001)(76176011)(69596002)(55016002)(58126008)(81166006)(2361001)(4326008)(316002)(81156014)(305945005)(1076002)(97736004)(53416004)(16526018)(6506007)(50466002)(386003)(54906003)(6116002)(5660300001)(8936002)(25786009)(83506002)(86362001)(68736007)(8676002)(97746001)(230700001)(2906002)(105586002)(2486003)(7736002)(2351001)(52116002)(7696005)(106356001)(478600001)(6666003)(47776003)(3846002)(59450400001)(6916009)(23676004)(2950100002)(72206003)(9686003)(103116003);DIR:OUT;SFP:1101;SCL:1;SRVR:CY4PR12MB1143;H:tlendack-t1.amdoffice.net;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtDWTRQUjEyTUIxMTQzOzIzOk1lelROSnk1OUxxYmxIWC9TcDdEMXJMbkh0?= =?utf-8?B?b3l3UEdzWGhTY1hiaDloenlzazRvd2NzR1pNRmRhRERpWTErQkVBTDY0M1ZX?= =?utf-8?B?TUxpTVlreHZ2ZWQ0b0dRcmpYMDhjRnExQ0JVdWk4c3dDbjM4blJWWndaNmMv?= =?utf-8?B?VFBicU4xSWJXSmZpMytrQklaTzRuVjVMSktkSVNiYlk4QjdZcmlwMC90Smxq?= =?utf-8?B?WlJQdVZxakY2RHE3eWFwTERxQndQTG8xSlZPQ25obzRaZEZHQ1FNNXNLMmta?= =?utf-8?B?aUVUbk5ka2NVQ0Fzd1dsMGFzMDFlNmpOM2txUHZ1SVhYa1lEMTBTMFI0MkNQ?= =?utf-8?B?MUVZYUxhR09ZVWxodWpsK0pDejExWnZ4SVhwSVp1cjhDVU1JL1JqbWR4S0FB?= =?utf-8?B?TVVJK3dQUnFtWHZxQ3Fmbi8vQmtlNlF0cjBGZmlxZWt5ZGRwNEFySXBZaldR?= =?utf-8?B?QUIwMmxuTjNwVFdqdVN1aWpUR3YxT2NqQlRVQ2M2T1htdTVTMWhHVmpWWXJ3?= =?utf-8?B?QXk0ZlQvUlFJMWZZc1NBZCttbkFPelFrekJCQ0k0cFZMUDk4c3hQK2w2QXpo?= =?utf-8?B?NUdIeTY3T2dyRkRiRXBWODhRYkNod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uYe9FJ4MCBcgabQBd7hy6WJdsXNQ6IR+tUduGVBJb4wEhUaplLDyREIRU41c3PxbmbUB/htiSGtWSydEawms8VQ2/PjJnnz8jYGPFAqj6ojaYtZ2rJ0fHsD68nNhM3pNtS7ww7NAP/FRdaR0oGiZge0pg8jw4xqWXgn8fZlTIoXG/LU9d6aO8iAlS/vjZmqSFof/4EBBOx SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;CY4PR12MB1143;20:nSumSdrPabRkRup3eHnWyT/jswVpWx/y1aXXBOAcZCuvBMEPoiBak3P4n0HZ498zwMebbzCAvAUgfXnGMg/l3vDtmrZ3JExIAKGcBRCf7/k5MZR9+PV1/ph3RtR0vqCRTHnrpd8b/f97ZdXTnCnt/fDySTOlLhWUpU5mA8z2Ollb21M3Z1W7QFN/Ky78ZllLAOUPz9N7/5r1GG+O1oEmEd9kjJW/kowyADtKn1nh25IcXYLcGr+LHPplWfZn2BxK X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Dec 2017 22:02:56.2317 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dcfdb498-6fbc-49f6-11f1-08d548be97de X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1143 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1840 Lines: 59 Cleanup the use of push and pop and when registers are saved in the mem_encrypt_boot.S file in order to improve the readability of the code. Move parameter register saving into general purpose registers earlier in the code and move all the pushes to the beginning of the function with corresponding pops at the end. Signed-off-by: Tom Lendacky --- arch/x86/mm/mem_encrypt_boot.S | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/arch/x86/mm/mem_encrypt_boot.S b/arch/x86/mm/mem_encrypt_boot.S index 730e6d5..de36884 100644 --- a/arch/x86/mm/mem_encrypt_boot.S +++ b/arch/x86/mm/mem_encrypt_boot.S @@ -103,20 +103,19 @@ ENTRY(__enc_copy) orq $X86_CR4_PGE, %rdx mov %rdx, %cr4 + push %r15 + + movq %rcx, %r9 /* Save kernel length */ + movq %rdi, %r10 /* Save encrypted kernel address */ + movq %rsi, %r11 /* Save decrypted kernel address */ + /* Set the PAT register PA5 entry to write-protect */ - push %rcx movl $MSR_IA32_CR_PAT, %ecx rdmsr - push %rdx /* Save original PAT value */ + mov %rdx, %r15 /* Save original PAT value */ andl $0xffff00ff, %edx /* Clear PA5 */ orl $0x00000500, %edx /* Set PA5 to WP */ wrmsr - pop %rdx /* RDX contains original PAT value */ - pop %rcx - - movq %rcx, %r9 /* Save kernel length */ - movq %rdi, %r10 /* Save encrypted kernel address */ - movq %rsi, %r11 /* Save decrypted kernel address */ wbinvd /* Invalidate any cache entries */ @@ -138,12 +137,13 @@ ENTRY(__enc_copy) jnz 1b /* Kernel length not zero? */ /* Restore PAT register */ - push %rdx /* Save original PAT value */ movl $MSR_IA32_CR_PAT, %ecx rdmsr - pop %rdx /* Restore original PAT value */ + mov %r15, %rdx /* Restore original PAT value */ wrmsr + pop %r15 + ret .L__enc_copy_end: ENDPROC(__enc_copy)