Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753848AbeAJT0K (ORCPT + 1 other); Wed, 10 Jan 2018 14:26:10 -0500 Received: from mail-sn1nam01on0055.outbound.protection.outlook.com ([104.47.32.55]:40576 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753807AbeAJT0D (ORCPT ); Wed, 10 Jan 2018 14:26:03 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; From: Tom Lendacky Subject: [PATCH v3 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: Wed, 10 Jan 2018 13:25:56 -0600 Message-ID: <20180110192556.6026.74187.stgit@tlendack-t1.amdoffice.net> In-Reply-To: <20180110192544.6026.17285.stgit@tlendack-t1.amdoffice.net> References: <20180110192544.6026.17285.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: DM5PR21CA0043.namprd21.prod.outlook.com (10.172.92.157) To MWHPR12MB1152.namprd12.prod.outlook.com (10.169.204.16) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 06f57392-c3ce-41a1-4c90-08d5585ffb0d X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(5600026)(4604075)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(48565401081)(2017052603307)(7153060)(7193020);SRVR:MWHPR12MB1152; X-Microsoft-Exchange-Diagnostics: 1;MWHPR12MB1152;3:OhLCdmmajiNwJ0TkogWgrXoJ4aHK6ibFSBT0+eUADPzJnadgzWJirX+sP3thO6z+PnBwoTOngs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h+fqlMbwT8nMUXp0DfWdIyS/gL8xQq//eq2eMutvP5yePF9caDTsggB1AL6YmhwYJ29Yeuabt+y7Sapk6qFUeWHaUCNKvMqIN/BfjQvscYm+MdfiOphu9U3uK33XWBXab4WJXvz+1x3n9Pe0ndzuB0hpXcsqveXZq1KsKCliTPzugXW386WraoLZDWgJ2vJiHtWWOqjpqDb1w3fTIvhdzniUWpRB0uYeg/1cVcIXN6ktoQYJsKPVwiBSnJa1/UpVd6MwSZji;4:2dVksMHlQhx3gj/FtXIJl+NjtoOeN+Ql6IBR5clwr+4aMyQCNc/4+csVDxWL4CoRBLwWzKEMHxMelBkW+/MNQg4FbFxyEXkcJ7+6fWgVkjT7mYG/sTzlhlxca3xC144bIcCnOiE3l/RyDNb/sSDbedFtb23rOgFv6hlVUQVunMu/fEGTzUYv8ltHeotXDuxlPPfsEfEw7kPGbKHVhTRGpSVEBvoDiXSKK5Vwyh3+/2tXInh+X3udla+M5yZonmU/z9oOUMEymMiL/24UHgLmRJJJHAw1dA8Fe/YGm9ou4OG/ii5jOwkYbiYKUjD9Vgux 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)(93006095)(93001095)(10201501046)(3231023)(944501075)(3002001)(6055026)(6041268)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123560045)(20161123562045)(20161123564045)(6072148)(201708071742011);SRVR:MWHPR12MB1152;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:MWHPR12MB1152; X-Forefront-PRVS: 0548586081 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(396003)(346002)(366004)(39860400002)(376002)(39380400002)(189003)(199004)(2361001)(58126008)(55016002)(316002)(53936002)(9686003)(4326008)(54906003)(25786009)(69596002)(83506002)(103116003)(2906002)(16526018)(106356001)(50466002)(230700001)(5660300001)(59450400001)(2486003)(23676004)(7696005)(76176011)(52116002)(105586002)(2351001)(8676002)(81166006)(6666003)(8936002)(47776003)(2950100002)(53416004)(6916009)(86362001)(68736007)(66066001)(97736004)(305945005)(7736002)(97746001)(72206003)(1076002)(478600001)(386003)(81156014)(6506007)(3846002)(6116002);DIR:OUT;SFP:1101;SCL:1;SRVR:MWHPR12MB1152;H:tlendack-t1.amdoffice.net;FPR:;SPF:None;PTR:InfoNoRecords;MX:3;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtNV0hQUjEyTUIxMTUyOzIzOk1sTlBFZkdEUXdhUXBqZEdMV1pQLzlKa1hj?= =?utf-8?B?NW1rSWZLeFVQQzVBVS95SkJWdlFTUGtwaW5wbmF2K3RWbkFBN3dLYU5vOTJF?= =?utf-8?B?YmxUWjI0MTlteTQxMWxEYU00djFOai9IbXNTRUt0TnB2TXZpemVxRHBmSW41?= =?utf-8?B?aFJtWXZHT3EyTWFZL1dBQmV3V2k5d25xL0lkUE95MW01bFZDTmUzakh3d3lv?= =?utf-8?B?bzZYMEZnYUdLQkcvNzgzT2YvdVE5SWZZaWVsUVdjWWhWWnYrUmVUbzBOcjNU?= =?utf-8?B?RDU5anlyTUw1bTlOMGQvSWxwSWJIbTRXT0NLNjlhVndpOWgycVBZc25NcjRW?= =?utf-8?B?RWRCTkh3WkpLUjVmYm1EVzVjRGpuenF2SFRXT1NPSExlQ1phNlpQanBhd2lk?= =?utf-8?B?WVJZY0RTV3dvZVJsQm42ckp0cWRERDlNWFFtVGdhUmZWand2d00zMzYwM0tv?= =?utf-8?B?MDBPSVkrTlZUWGtOV1lVdms2aERFdGZJUjRSaDJ6WHZiVHpnRVBiUnVkbVBa?= =?utf-8?B?UmhCZWJoVTJKc1hObTBQU2IvY05WYXJGc3k5dVVWNlFsZWRzdEZ0cTd5aHpC?= =?utf-8?B?MWdBMzNoZzJXYWpBSWU1NnYwMkhSK2tZZFlDR3hTekpkZFBuOHBYTlZ2dFdv?= =?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3jBVBSIFgOBBJjgdrQxPqyYCmgFZ9C3XHhl2QDj2QAGGGf9qQi+YIw6gKGDzo21ppozlyO/J91y60NyeoDq85Nk486F2offjo9Ww1VJPjO7GChleG1LXDwjout6ElPL3EmLGRXSztmUNGA9Gh7FUPMERkHNAj SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;MWHPR12MB1152;20:WPlgfJHcszRPJj4oq6w2fDY93EWNH/b3YjMGY98L8uJIi3/nFVVKjbZpgCa4x+Sk2kUdsbD+R1DOnNEJwqZZJ6gtABKCYE2ji+FiBc+bIAHoBN6heuZBHx515TW8YA8lT9gh0g9ASLdVT+QqC/2YdlmDyg8z2656n6yItC9DAHMWWYisF0wB9thy1oLI6uX1Op2+QKlETp53/nQRXV3+KVR3PBwHYRzSv5f2Z/kuAYW0SWUSJdkaDbfUv5XIxBAv X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jan 2018 19:25:59.4258 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 06f57392-c3ce-41a1-4c90-08d5585ffb0d X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1152 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: 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)