From patchwork Thu Jan 30 20:04:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arvind Sankar X-Patchwork-Id: 206609 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9CDE9C2D0DB for ; Thu, 30 Jan 2020 20:04:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7DEE42467B for ; Thu, 30 Jan 2020 20:04:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727585AbgA3UEq (ORCPT ); Thu, 30 Jan 2020 15:04:46 -0500 Received: from mail-qk1-f195.google.com ([209.85.222.195]:42907 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727161AbgA3UEp (ORCPT ); Thu, 30 Jan 2020 15:04:45 -0500 Received: by mail-qk1-f195.google.com with SMTP id q15so4200546qke.9; Thu, 30 Jan 2020 12:04:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eqydHU85bvvWn1OJe8yhKq7Ls97Ytffjp/MKGxfsBpI=; b=Gb53Gn/edCLgxBAREpQLiNgecu2I54UIzdKtDymF9421ZuCmDtOgkFKd3DNxfU8+4e mv+KYRbM0O5Q/VOuemmQmXbZvdm0OIE0VmaPeZt7NXKOgYAish3mT+pSrnTbH0XrI0oN CIHJ0W3E5gJ/eiQWj2cUoUXSE5b9yWonyP81pPgSdXvd+qhB30tLUZneupBTkjOq4mVX iHtzGpiUFEvrGfmxWMsl5cWwtmUGbWMhZmUhcaZnHP8tJVPm/Msc/HmOvAojZVbHQJ08 c/bKjQ3oAYeuri5t/cUuxVrxiDMTZNxnffXe3T9kSmGSappx31FBuElgu4dyPcCFFsWJ i2JA== X-Gm-Message-State: APjAAAXhD89Jl9Yrf61pZldgyAwGMdIJTSCD4b2NQieq9E9yeNJ6IPJL fv73BEZ4gvdAt2yaGrST9KE= X-Google-Smtp-Source: APXvYqyiHqbOtHebuX5AOvef45bQiRx886hofKxHoAMlQ9CNxgL18VeszY2xyz5D72LThs/ArNiLvg== X-Received: by 2002:a05:620a:16d3:: with SMTP id a19mr6359995qkn.427.1580414684510; Thu, 30 Jan 2020 12:04:44 -0800 (PST) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id k15sm3262865qkk.103.2020.01.30.12.04.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jan 2020 12:04:44 -0800 (PST) From: Arvind Sankar To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Jonathan Corbet , Ard Biesheuvel Cc: linux-efi@vger.kernel.org, x86@kernel.org, linux-doc@vger.kernel.org Subject: [PATCH 2/8] efi/x86: Allocate the GDT pointer on the stack Date: Thu, 30 Jan 2020 15:04:34 -0500 Message-Id: <20200130200440.1796058-3-nivedita@alum.mit.edu> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200130200440.1796058-1-nivedita@alum.mit.edu> References: <20200130200440.1796058-1-nivedita@alum.mit.edu> MIME-Version: 1.0 Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org The GDT pointer isn't needed after loading it into GDTR, so there is no need to dynamically allocate it. Signed-off-by: Arvind Sankar --- arch/x86/boot/compressed/eboot.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c index f89caae60057..a0a2fd0528af 100644 --- a/arch/x86/boot/compressed/eboot.c +++ b/arch/x86/boot/compressed/eboot.c @@ -713,7 +713,7 @@ struct boot_params *efi_main(efi_handle_t handle, efi_system_table_t *sys_table_arg, struct boot_params *boot_params) { - struct desc_ptr *gdt = NULL; + struct desc_ptr gdt; struct setup_header *hdr = &boot_params->hdr; efi_status_t status; struct desc_struct *desc; @@ -754,15 +754,8 @@ struct boot_params *efi_main(efi_handle_t handle, setup_quirks(boot_params); - status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, sizeof(*gdt), - (void **)&gdt); - if (status != EFI_SUCCESS) { - efi_printk("Failed to allocate memory for 'gdt' structure\n"); - goto fail; - } - - gdt->size = 0x800; - status = efi_low_alloc(gdt->size, 8, (unsigned long *)&gdt->address); + gdt.size = 0x800; + status = efi_low_alloc(gdt.size, 8, (unsigned long *)&gdt.address); if (status != EFI_SUCCESS) { efi_printk("Failed to allocate memory for 'gdt'\n"); goto fail; @@ -794,8 +787,8 @@ struct boot_params *efi_main(efi_handle_t handle, goto fail; } - memset((char *)gdt->address, 0x0, gdt->size); - desc = (struct desc_struct *)gdt->address; + memset((char *)gdt.address, 0x0, gdt.size); + desc = (struct desc_struct *)gdt.address; /* The first GDT is a dummy. */ desc++; @@ -879,7 +872,7 @@ struct boot_params *efi_main(efi_handle_t handle, } raw_local_irq_disable(); - native_load_gdt(gdt); + native_load_gdt(&gdt); return boot_params; fail: From patchwork Sun Feb 2 17:13:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arvind Sankar X-Patchwork-Id: 206600 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 245B5C3524C for ; Sun, 2 Feb 2020 17:14:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EBC3920679 for ; Sun, 2 Feb 2020 17:14:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726995AbgBBRN6 (ORCPT ); Sun, 2 Feb 2020 12:13:58 -0500 Received: from mail-qt1-f196.google.com ([209.85.160.196]:36061 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726905AbgBBRN6 (ORCPT ); Sun, 2 Feb 2020 12:13:58 -0500 Received: by mail-qt1-f196.google.com with SMTP id t13so9630421qto.3; Sun, 02 Feb 2020 09:13:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fNIctzUQqpzBYKShq+agBaG6jK3vI6wtoz79iRuDrBw=; b=sWkCGbdMQWvcwW4ZHprK51piBkeEU7tV8JfOcgdx8Bt5urzx+A56RoD4TFU3buuuM+ 6+3MuC5BTUgurRTh/MZ5YnuKisJEFFWVt9FUQ5IPXVI1m/QyFY+4rjCJHQvP5Uj535XQ NFLijm93UgzkXOtl/HIEGrOFSfy4id0ft5MFu3++hrivKTl7SCNUcemMJPhO2+X9x0Oi Edpab/AL3K+6EUjpYH0t0Wu2PlV1EkwST5wkZpyi7skfGilEv5PXAAJhGzj5VCxj67te iMQWnCSz9G8ls8NJTy74JwVIA8L2G5OOynIpCmzAi9AAKhqCTNbq9cngodyizQn96O0v niVw== X-Gm-Message-State: APjAAAWAOoIO3xJTV39+3AJi9v+uqOK7c3eS/ih2U6jg2CwPE+Uu7T37 yEBTu+pDtKbo9CESAKu01Jo= X-Google-Smtp-Source: APXvYqwebnSPusJY9nsi2lbUddkkzsLGkBomkzxc7tNp5ELHxXeAL1BDDv5tcF6aLeDghjwGVDgjuQ== X-Received: by 2002:aed:2321:: with SMTP id h30mr20706652qtc.355.1580663637426; Sun, 02 Feb 2020 09:13:57 -0800 (PST) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id 3sm8150081qte.59.2020.02.02.09.13.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Feb 2020 09:13:57 -0800 (PST) From: Arvind Sankar To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Ard Biesheuvel Cc: linux-efi@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/7] x86/boot: Reload GDTR after copying to the end of the buffer Date: Sun, 2 Feb 2020 12:13:49 -0500 Message-Id: <20200202171353.3736319-4-nivedita@alum.mit.edu> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200202171353.3736319-1-nivedita@alum.mit.edu> References: <20200130200440.1796058-1-nivedita@alum.mit.edu> <20200202171353.3736319-1-nivedita@alum.mit.edu> MIME-Version: 1.0 Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org The GDT may get overwritten during the copy or during extract_kernel, which will cause problems if any segment register is touched before the GDTR is reloaded by the decompressed kernel. For safety update the GDTR to point to the GDT within the copied kernel. Signed-off-by: Arvind Sankar --- arch/x86/boot/compressed/head_64.S | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index c56b30bd9c7b..27eb2a6786db 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -439,6 +439,16 @@ trampoline_return: cld popq %rsi + /* + * The GDT may get overwritten either during the copy we just did or + * during extract_kernel below. To avoid any issues, repoint the GDTR + * to the new copy of the GDT. + */ + leaq gdt64(%rbx), %rax + subq %rbp, 2(%rax) + addq %rbx, 2(%rax) + lgdt (%rax) + /* * Jump to the relocated address. */ From patchwork Sun Feb 2 17:13:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arvind Sankar X-Patchwork-Id: 206602 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B12FC3F68F for ; Sun, 2 Feb 2020 17:14:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F0AA8206E6 for ; Sun, 2 Feb 2020 17:14:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727096AbgBBROA (ORCPT ); Sun, 2 Feb 2020 12:14:00 -0500 Received: from mail-qt1-f194.google.com ([209.85.160.194]:42694 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727077AbgBBROA (ORCPT ); Sun, 2 Feb 2020 12:14:00 -0500 Received: by mail-qt1-f194.google.com with SMTP id j5so9601675qtq.9; Sun, 02 Feb 2020 09:13:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nE3tnB4sz785hw5rbejF4tfz+IwOjrONd7iKRpSiDW4=; b=cCpcclVECLtf/mzsi7r+zrxrQNe20fBNqPWzjRE4EmG1dzHUHQzw9ihCgXEwN3TU3D zwShAbg7Q53DPsu1vd8VB6ZglfbuP47Bu581Mq+/5PTlBoSNkNfVZVzWtj2f4zEBDeg8 mbtoqVBkzwFJAy2AdXgFCi+w9JawJ00bWnwjh5kMo4DmSJ9PdoIZ8Lzj1T0iED2Hfidm Z9DGUi7l6MzQNeFWMeR+1Dz73TxihbjVtPiWUysmGvL3VLikctZQJbTg1hU9ZWb+hCYB f5A9HjtrrpQYAd6XOAWntHDOtifEg9dJ0LE7x1lNEmkWHsuthXM/akSbOaNA6U0gnPAp bywA== X-Gm-Message-State: APjAAAUjIBZmlSvaZkywq0CIu56xaugRCkd2ak1SwPcs6zZP8au5xS5I ki2Rd/6/1yzQVyhxsympWmg= X-Google-Smtp-Source: APXvYqywrKwTAqSUK7OknHSth/qSMhWR8q5OnxRqruS3jS1/r4EGgJPZ2ZEpHcnud/nfrcB59shC4A== X-Received: by 2002:ac8:835:: with SMTP id u50mr20429296qth.15.1580663638947; Sun, 02 Feb 2020 09:13:58 -0800 (PST) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id 3sm8150081qte.59.2020.02.02.09.13.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Feb 2020 09:13:58 -0800 (PST) From: Arvind Sankar To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Ard Biesheuvel Cc: linux-efi@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/7] efi/x86: Remove GDT setup from efi_main Date: Sun, 2 Feb 2020 12:13:51 -0500 Message-Id: <20200202171353.3736319-6-nivedita@alum.mit.edu> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200202171353.3736319-1-nivedita@alum.mit.edu> References: <20200130200440.1796058-1-nivedita@alum.mit.edu> <20200202171353.3736319-1-nivedita@alum.mit.edu> MIME-Version: 1.0 Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org The 64-bit kernel will already load a GDT in startup_64, which is the next function to execute after return from efi_main. Add GDT setup code to the 32-bit kernel's startup_32 as well. Doing it in the head code has the advantage that we can avoid potentially corrupting the GDT during copy/decompression. This also removes dependence on having a specific GDT layout setup by the bootloader. Both startup_32 and startup_64 now clear interrupts on entry, so we can remove that from efi_main as well. Signed-off-by: Arvind Sankar --- arch/x86/boot/compressed/eboot.c | 103 ----------------------------- arch/x86/boot/compressed/head_32.S | 40 +++++++++-- 2 files changed, 34 insertions(+), 109 deletions(-) diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c index 287393d725f0..c92fe0b75cec 100644 --- a/arch/x86/boot/compressed/eboot.c +++ b/arch/x86/boot/compressed/eboot.c @@ -712,10 +712,8 @@ struct boot_params *efi_main(efi_handle_t handle, efi_system_table_t *sys_table_arg, struct boot_params *boot_params) { - struct desc_ptr *gdt = NULL; struct setup_header *hdr = &boot_params->hdr; efi_status_t status; - struct desc_struct *desc; unsigned long cmdline_paddr; sys_table = sys_table_arg; @@ -753,20 +751,6 @@ struct boot_params *efi_main(efi_handle_t handle, setup_quirks(boot_params); - status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, sizeof(*gdt), - (void **)&gdt); - if (status != EFI_SUCCESS) { - efi_printk("Failed to allocate memory for 'gdt' structure\n"); - goto fail; - } - - gdt->size = 0x800; - status = efi_low_alloc(gdt->size, 8, (unsigned long *)&gdt->address); - if (status != EFI_SUCCESS) { - efi_printk("Failed to allocate memory for 'gdt'\n"); - goto fail; - } - /* * If the kernel isn't already loaded at the preferred load * address, relocate it. @@ -793,93 +777,6 @@ struct boot_params *efi_main(efi_handle_t handle, goto fail; } - memset((char *)gdt->address, 0x0, gdt->size); - desc = (struct desc_struct *)gdt->address; - - /* The first GDT is a dummy. */ - desc++; - - if (IS_ENABLED(CONFIG_X86_64)) { - /* __KERNEL32_CS */ - desc->limit0 = 0xffff; - desc->base0 = 0x0000; - desc->base1 = 0x0000; - desc->type = SEG_TYPE_CODE | SEG_TYPE_EXEC_READ; - desc->s = DESC_TYPE_CODE_DATA; - desc->dpl = 0; - desc->p = 1; - desc->limit1 = 0xf; - desc->avl = 0; - desc->l = 0; - desc->d = SEG_OP_SIZE_32BIT; - desc->g = SEG_GRANULARITY_4KB; - desc->base2 = 0x00; - - desc++; - } else { - /* Second entry is unused on 32-bit */ - desc++; - } - - /* __KERNEL_CS */ - desc->limit0 = 0xffff; - desc->base0 = 0x0000; - desc->base1 = 0x0000; - desc->type = SEG_TYPE_CODE | SEG_TYPE_EXEC_READ; - desc->s = DESC_TYPE_CODE_DATA; - desc->dpl = 0; - desc->p = 1; - desc->limit1 = 0xf; - desc->avl = 0; - - if (IS_ENABLED(CONFIG_X86_64)) { - desc->l = 1; - desc->d = 0; - } else { - desc->l = 0; - desc->d = SEG_OP_SIZE_32BIT; - } - desc->g = SEG_GRANULARITY_4KB; - desc->base2 = 0x00; - desc++; - - /* __KERNEL_DS */ - desc->limit0 = 0xffff; - desc->base0 = 0x0000; - desc->base1 = 0x0000; - desc->type = SEG_TYPE_DATA | SEG_TYPE_READ_WRITE; - desc->s = DESC_TYPE_CODE_DATA; - desc->dpl = 0; - desc->p = 1; - desc->limit1 = 0xf; - desc->avl = 0; - desc->l = 0; - desc->d = SEG_OP_SIZE_32BIT; - desc->g = SEG_GRANULARITY_4KB; - desc->base2 = 0x00; - desc++; - - if (IS_ENABLED(CONFIG_X86_64)) { - /* Task segment value */ - desc->limit0 = 0x0000; - desc->base0 = 0x0000; - desc->base1 = 0x0000; - desc->type = SEG_TYPE_TSS; - desc->s = 0; - desc->dpl = 0; - desc->p = 1; - desc->limit1 = 0x0; - desc->avl = 0; - desc->l = 0; - desc->d = 0; - desc->g = SEG_GRANULARITY_4KB; - desc->base2 = 0x00; - desc++; - } - - asm volatile("cli"); - asm volatile ("lgdt %0" : : "m" (*gdt)); - return boot_params; fail: efi_printk("efi_main() failed!\n"); diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S index cb2cb91fce45..356060c5332c 100644 --- a/arch/x86/boot/compressed/head_32.S +++ b/arch/x86/boot/compressed/head_32.S @@ -64,12 +64,6 @@ SYM_FUNC_START(startup_32) cld cli - movl $__BOOT_DS, %eax - movl %eax, %ds - movl %eax, %es - movl %eax, %fs - movl %eax, %gs - movl %eax, %ss /* * Calculate the delta between where we were compiled to run @@ -84,6 +78,19 @@ SYM_FUNC_START(startup_32) 1: popl %ebp subl $1b, %ebp + /* Load new GDT */ + leal gdt(%ebp), %eax + movl %eax, 2(%eax) + lgdt (%eax) + + /* Load segment registers with our descriptors */ + movl $__BOOT_DS, %eax + movl %eax, %ds + movl %eax, %es + movl %eax, %fs + movl %eax, %gs + movl %eax, %ss + /* * %ebp contains the address we are loaded at by the boot loader and %ebx * contains the address where we should move the kernel image temporarily @@ -129,6 +136,16 @@ SYM_FUNC_START(startup_32) cld popl %esi + /* + * The GDT may get overwritten either during the copy we just did or + * during extract_kernel below. To avoid any issues, repoint the GDTR + * to the new copy of the GDT. EAX still contains the previously + * calculated relocation offset of init_size - _end. + */ + leal gdt(%ebx), %edx + addl %eax, 2(%edx) + lgdt (%edx) + /* * Jump to the relocated address. */ @@ -201,6 +218,17 @@ SYM_FUNC_START_LOCAL_NOALIGN(.Lrelocated) jmp *%eax SYM_FUNC_END(.Lrelocated) + .data + .balign 8 +SYM_DATA_START_LOCAL(gdt) + .word gdt_end - gdt - 1 + .long 0 + .word 0 + .quad 0x0000000000000000 /* Reserved */ + .quad 0x00cf9a000000ffff /* __KERNEL_CS */ + .quad 0x00cf92000000ffff /* __KERNEL_DS */ +SYM_DATA_END_LABEL(gdt, SYM_L_LOCAL, gdt_end) + /* * Stack and heap for uncompression */ From patchwork Sun Feb 2 17:13:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arvind Sankar X-Patchwork-Id: 206601 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49C03C3524C for ; Sun, 2 Feb 2020 17:14:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1D9062067C for ; Sun, 2 Feb 2020 17:14:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727093AbgBBROA (ORCPT ); Sun, 2 Feb 2020 12:14:00 -0500 Received: from mail-qk1-f194.google.com ([209.85.222.194]:34620 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726989AbgBBROA (ORCPT ); Sun, 2 Feb 2020 12:14:00 -0500 Received: by mail-qk1-f194.google.com with SMTP id g3so3346546qka.1; Sun, 02 Feb 2020 09:14:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jaSQqD1f11t4pGUDsgeYFl9+dx25Mu1OCOk2wHccxUc=; b=TTMwCmCrQz1HYEnLRwIdzFnaW69M9Rc1efT/gDVUaMyDW7OYyvPhYoyV8QQehEXeVa 5DTB6owCKFzOCCxqttFYmwUgmdJHxpRUXpnsy7XwOkm4xkPKvmqGbaLRKpv5DYqiZGA1 wkE3B4dQXTT2LMWOuI7oydriILNhkOLnnZKoMz0tmwD5u+v2D8+K5ZSiH0kWQm74JYBI PcoP8IfdT/JW7o6jNlReXMJ8qG0rXEysFnTcH73D7a92UI7y2Ow+yyKlazWPuMwZsJjx 3zJ9j6UTFbZmXem9Mo4987IZLKg5ydp6OWLsJBDapksbhx6C4hNPIAEcacDp9qctcvCs FcJQ== X-Gm-Message-State: APjAAAWtI5qVKc1eAXh+BOK/yUV8Q/6f66u3IXcvi/YK5JPRx/YMpdGm 3FrK5DUtTZvZaK4G3hRvZWI= X-Google-Smtp-Source: APXvYqwMtgW9EfbgzTEC8DH0j5loYu+zFEopOTh/5uDUhajtIkBVVcQ/d3uB0UAUTphurHIu38AIng== X-Received: by 2002:a37:48c4:: with SMTP id v187mr20383369qka.198.1580663639639; Sun, 02 Feb 2020 09:13:59 -0800 (PST) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id 3sm8150081qte.59.2020.02.02.09.13.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Feb 2020 09:13:59 -0800 (PST) From: Arvind Sankar To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Ard Biesheuvel Cc: linux-efi@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 6/7] x86/boot: GDT limit value should be size - 1 Date: Sun, 2 Feb 2020 12:13:52 -0500 Message-Id: <20200202171353.3736319-7-nivedita@alum.mit.edu> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200202171353.3736319-1-nivedita@alum.mit.edu> References: <20200130200440.1796058-1-nivedita@alum.mit.edu> <20200202171353.3736319-1-nivedita@alum.mit.edu> MIME-Version: 1.0 Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org The limit value for the GDTR should be such that adding it to the base address gives the address of the last byte of the GDT, i.e. it should be one less than the size, not the size. Signed-off-by: Arvind Sankar --- arch/x86/boot/compressed/head_64.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index 69cc6c68741e..c36e6156b6a3 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -624,12 +624,12 @@ SYM_FUNC_END(.Lno_longmode) .data SYM_DATA_START_LOCAL(gdt64) - .word gdt_end - gdt + .word gdt_end - gdt - 1 .quad 0 SYM_DATA_END(gdt64) .balign 8 SYM_DATA_START_LOCAL(gdt) - .word gdt_end - gdt + .word gdt_end - gdt - 1 .long gdt .word 0 .quad 0x00cf9a000000ffff /* __KERNEL32_CS */ From patchwork Thu Jan 30 20:04:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arvind Sankar X-Patchwork-Id: 206607 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CBEBAC3524B for ; Thu, 30 Jan 2020 20:04:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A29872467B for ; Thu, 30 Jan 2020 20:04:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727613AbgA3UEt (ORCPT ); Thu, 30 Jan 2020 15:04:49 -0500 Received: from mail-qk1-f194.google.com ([209.85.222.194]:34011 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727161AbgA3UEt (ORCPT ); Thu, 30 Jan 2020 15:04:49 -0500 Received: by mail-qk1-f194.google.com with SMTP id d10so4263032qke.1; Thu, 30 Jan 2020 12:04:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Z5UX2NdM3cfVWh/gVO4PCQr35u5EguDY40Iisa5P8eI=; b=ZfvnyZbHLv48gCXAfbWjjO8R8r2FSqRAsLnb1Gfd2+P2/Qg/4rV7uEVmVvz7IQpcDM rph1nuINtVP0fWzUEP7ejSSSyMO0zg4bd1NV2c27KrwHVDE1fHMe6scJrLprvoUl0ozY 4FuoZDmryBRURLEGuMq3RFDtyDpw5L1nKbUky0G0aZyqQqTl18VOGAZq7eaq1RXcHOJ8 Rwxly47BMwX6y9PfUI3Q08ZVPCk74b4ZGq+TZwfkPW+oFVSleAYselVV79GyYfxjk4LR okA26dtl1PMGDuxCd+a9u0aMAFAme8z/qD/6yNlXn1UB5YzOT5o4kWaDuSD2+FNGDHkU GYbQ== X-Gm-Message-State: APjAAAVY+HDfl4PXtCRQNth/GocxsKMh9GwoGRcLXqT6cvx03tkBayMJ 8j32qR4XVdS+oUjHcY9PWHA= X-Google-Smtp-Source: APXvYqzaPn9nWlNV0dKpLcZCIuA+cUjkceuKmWkJdS51ETLoGuZ+X4u4MtRlYICxJLClDx7ctXk6Qg== X-Received: by 2002:ae9:ec0a:: with SMTP id h10mr6596149qkg.303.1580414688403; Thu, 30 Jan 2020 12:04:48 -0800 (PST) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id k15sm3262865qkk.103.2020.01.30.12.04.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jan 2020 12:04:48 -0800 (PST) From: Arvind Sankar To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Jonathan Corbet , Ard Biesheuvel Cc: linux-efi@vger.kernel.org, x86@kernel.org, linux-doc@vger.kernel.org Subject: [PATCH 7/8] Documentation/x86/boot: Clarify segment requirements for EFI handover Date: Thu, 30 Jan 2020 15:04:39 -0500 Message-Id: <20200130200440.1796058-8-nivedita@alum.mit.edu> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200130200440.1796058-1-nivedita@alum.mit.edu> References: <20200130200440.1796058-1-nivedita@alum.mit.edu> MIME-Version: 1.0 Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org The 32-bit EFI handover entry point requires segments to be setup in the same way as for the regular 32-bit boot. Signed-off-by: Arvind Sankar --- Documentation/x86/boot.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/x86/boot.rst b/Documentation/x86/boot.rst index c9c201596c3e..3e13b7d57271 100644 --- a/Documentation/x86/boot.rst +++ b/Documentation/x86/boot.rst @@ -1412,6 +1412,12 @@ from the boot media and jump to the EFI handover protocol entry point which is hdr->handover_offset bytes from the beginning of startup_{32,64}. +For the 32-bit handover entry point, the GDT and segments must be setup as for +the 32-bit boot protocol, i.e. a GDT must be loaded with the descriptors for +selectors __BOOT_CS(0x10) and __BOOT_DS(0x18); both descriptors must be 4G flat +segment; __BOOT_CS must have execute/read permission, and __BOOT_DS must have +read/write permission; CS must be __BOOT_CS and DS, ES, SS must be __BOOT_DS. + The function prototype for the handover entry point looks like this:: efi_main(void *handle, efi_system_table_t *table, struct boot_params *bp) From patchwork Thu Jan 30 20:04:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arvind Sankar X-Patchwork-Id: 206606 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F7CBC35246 for ; Thu, 30 Jan 2020 20:04:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 78422214AF for ; Thu, 30 Jan 2020 20:04:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727161AbgA3UEu (ORCPT ); Thu, 30 Jan 2020 15:04:50 -0500 Received: from mail-qk1-f193.google.com ([209.85.222.193]:45052 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727614AbgA3UEu (ORCPT ); Thu, 30 Jan 2020 15:04:50 -0500 Received: by mail-qk1-f193.google.com with SMTP id v195so4177880qkb.11; Thu, 30 Jan 2020 12:04:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YnfSmd5BvkLFsh0nPNy/3uEL0TluYTwz+zLsYY8/uCw=; b=pwrfNcIe49di8w/alX63HlrtfvV1GzAa6nmYt1rx8vT6A6F0r+2DzIg93+27CmMbwu 2Dg92EYNKXO+X5qJrpRtQm0Sg8pU04axDfOl9t9nIIWUDg+MKXiAOO7qaBxK9uMOCcnc PmcKUlbN5hbpf5HSYnvYakMJESKckVoU+o4PWCByKpM2rFI+Y173gzytkF2daYo7JSmY aSe6jgkezBTU40TvpYIPOTVk7j8n10E04HIp96fklEyZtfEhODCMKEg2ailoOf6+8Wy/ LIjmcI0/rv85Kim07kqrxFcvay9RRpeSAZuX6yW4FDJ00zlUorEH2rOiBd5LIYDfMZ5j +OCg== X-Gm-Message-State: APjAAAVAepp2g92efaAvmoRwkUEVVLV4i2bvtIXBCtqJyxeBI/FSMEoc xtSCOQzPvU9YlrV7tbSFP8w= X-Google-Smtp-Source: APXvYqxZv8KxrwfLJ4RsleKR7BkXYUmiK80t5OGV/op/UYcaY1r/kLf5QnLszxdj9dCnT6tj2MTAXQ== X-Received: by 2002:a05:620a:1663:: with SMTP id d3mr7240564qko.204.1580414689272; Thu, 30 Jan 2020 12:04:49 -0800 (PST) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id k15sm3262865qkk.103.2020.01.30.12.04.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jan 2020 12:04:48 -0800 (PST) From: Arvind Sankar To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Jonathan Corbet , Ard Biesheuvel Cc: linux-efi@vger.kernel.org, x86@kernel.org, linux-doc@vger.kernel.org Subject: [PATCH 8/8] Documentation/x86/boot: Correct segment requirements for 64-bit boot Date: Thu, 30 Jan 2020 15:04:40 -0500 Message-Id: <20200130200440.1796058-9-nivedita@alum.mit.edu> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200130200440.1796058-1-nivedita@alum.mit.edu> References: <20200130200440.1796058-1-nivedita@alum.mit.edu> MIME-Version: 1.0 Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org 64-bit mode has no segment/GDT requirements as it does not really use segment registers. The entry code loads null descriptors into the data and stack segment registers. Signed-off-by: Arvind Sankar --- Documentation/x86/boot.rst | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Documentation/x86/boot.rst b/Documentation/x86/boot.rst index 3e13b7d57271..df2bf8abbbc1 100644 --- a/Documentation/x86/boot.rst +++ b/Documentation/x86/boot.rst @@ -1396,12 +1396,9 @@ In 64-bit boot protocol, the kernel is started by jumping to the At entry, the CPU must be in 64-bit mode with paging enabled. The range with setup_header.init_size from start address of loaded kernel and zero page and command line buffer get ident mapping; -a GDT must be loaded with the descriptors for selectors -__BOOT_CS(0x10) and __BOOT_DS(0x18); both descriptors must be 4G flat -segment; __BOOT_CS must have execute/read permission, and __BOOT_DS -must have read/write permission; CS must be __BOOT_CS and DS, ES, SS -must be __BOOT_DS; interrupt must be disabled; %rsi must hold the base -address of the struct boot_params. +interrupt must be disabled; %rsi must hold the base address of the +struct boot_params. As 64-bit mode does not really use segments, there +are no special requirements on the segment registers or descriptors. EFI Handover Protocol =====================