Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp534176lqd; Wed, 24 Apr 2024 09:21:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU7fzniRKsKPbjiHv2f4IQ/TIYsOVaSdb4pzsuGE+M6DdynhIBTXUXybE9rjn4W9W4+Ry7sgcuceN5Yadx85jQpsBVrenbg2GtcZLgavA== X-Google-Smtp-Source: AGHT+IE9WjdGDg0lWj6PFp1hF7J6S9IQZSKKxYG4UDlCoB8FnGntXEXk1BiOSsnIW2eJRpaAy+tQ X-Received: by 2002:a17:90b:3011:b0:2a7:d810:2f5e with SMTP id hg17-20020a17090b301100b002a7d8102f5emr2613585pjb.48.1713975693889; Wed, 24 Apr 2024 09:21:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713975693; cv=pass; d=google.com; s=arc-20160816; b=r+QVpb+6AEKbys0OceXHjXSOctQ8zbIwjgpLMEJ3gxV6OEFBeXgNgS2wAPTTCmxQdl mqhCo8/5iXHDKgwgYol44CJUTEDotM9zy8alwXTcZJsL7d398cQ8AfFiSdTcIRTe6FGQ 6vBen/xHDxWBtaqTrQAoBr42XLVdJfVsc1HDFrm9XFXc+efFQdvgeqxPUuPta7r8fln8 RlCDkF4RDH6FUXsKbNIod32XPB62/oedK/WDw0OaO3T5I6yteg7Z04mWwM0GEc30DFVu 0aMccht9Z+44FE+uVW5djvzTAPrpvVNKT6fjprhrA9yaTcIQsKA5Ge/edKp7+Fsc/qYa 3mqw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=I1uZvGOJrDJyNyZbDNRiP2qZHG8ZyjcmYdwIIxk4UA4=; fh=FsvQoRfUYCb7YWgVN8g3QkTLNjgBrJZxscq7eE3+/Gs=; b=Xqf+WSwH+kKPoNExgqPUxHnvQTLx3gD64ySqXCCCpSrqwYsPgqSmLsJGVqO69OF4x9 toVahpauECL+NX1qCP+tLkR4FT6w7coLua7DwC3/FTzBAZeIvv/2LQcujQNl4EPEDZqU e1gP00kkeIsWuj3AUc7OmgaUN7z+u3RCyM+fAcE6xNhZKp+S2Kh8bpyFQDR6jygrTmf7 XgBbojqtxEsClaHpiVGKR1fYlAV3Tx3dID0vC3njxqNbLDCnea1NsXoBWHKQ5ORSpIXZ XSBmf5xbO/Hc9eCY/tHqEb9sMaYTEzIE0msh9nA338X2KhEQAiZrDYSk1/I5R+axtJ/O 7BSA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=HwQvhJ0F; arc=pass (i=1 spf=pass spfdomain=flex--ardb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-157257-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157257-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id q6-20020a17090a938600b002a280773045si11588807pjo.91.2024.04.24.09.21.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 09:21:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-157257-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=HwQvhJ0F; arc=pass (i=1 spf=pass spfdomain=flex--ardb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-157257-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157257-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 96259B2DFC7 for ; Wed, 24 Apr 2024 15:54:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 69B7A16C6B0; Wed, 24 Apr 2024 15:53:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="HwQvhJ0F" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 46AB9168AF1 for ; Wed, 24 Apr 2024 15:53:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713974024; cv=none; b=uwgX+cBnfPCqRqTdprJjIKfSXcnLkcOMHuaZCDyRxPzxu5kmMYI46MKj031wOJdt8iBQUYi9+AVh14OYkhWlA0wjpVeoVAWrYfSYra3bJP8hYhrm9bLj6+XGlie5NhoSftWruWZja/sew4LC/4poP7PDU8UbOwcEJkjFIbk6c3s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713974024; c=relaxed/simple; bh=9+swj6gVAPxZ4sAKUioQftvHESZtWdbvHkiKo8iymQ0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=C8+0LJaBIOYvARypqBZZ9rakMYpYFw2BsO46J1dR0mLDurtwQ2X+p7iGtrzTJ9xYiHrPJvreYVnDbGSH6MMDkmODfu5I3Gd418M5cZ8Q5AiGjljtYDU76EU/PBlJd6FrYdmcDpKY2/UusqCPuBd9yXnXt59hZgCsRjW9ZWJfYQU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=HwQvhJ0F; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dbf618042daso64851276.0 for ; Wed, 24 Apr 2024 08:53:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713974022; x=1714578822; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=I1uZvGOJrDJyNyZbDNRiP2qZHG8ZyjcmYdwIIxk4UA4=; b=HwQvhJ0FaHR78G6Jbt6K/CIL9VbHYYXTkU5MnotDrw0ec4ncEmmD7mvT8LO4J+McIH pay+7sq7VwRA1e0dPXByUXSYJ8OycnQDqbavL/5dDNmLfQJ9SpmyeuoZuxSe+QcvtP18 +6jzrBqVADyzAZqJ8Jw5lXOz4YY4BigPRikyYNOxtuSrW3YosopitVSU61Xi06ZVvgC5 kY2awLOqUINZtSdJ2A0ypad0t9fPSa/WadwbUSiwiVoK98dQmhdgf880AN+Ut9mrgG0P CPG+5K/CnP1U5Ef8iTwn0Xxxnu3ScZ+jnPowg24fdtNhUb37PWpRR79/ZxE32vZC3ATk n7iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713974022; x=1714578822; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=I1uZvGOJrDJyNyZbDNRiP2qZHG8ZyjcmYdwIIxk4UA4=; b=P5eYym/OeGfK/aymv92e9xWETGVRpoQOmXpyizbK7Ci+DWV1T6y/4ufmqi5aUa/vSa yBcleH525SVUauAS59/AvWPzpMmf3DhVgf7b5B/KCblDo0Ai9Xul6lownNyA/jAFUjRg HO4IfAYA319CUY9LPjpVI/cfu7OvOqSpIA7/hw9lrY89FEEujwt5eU56gOF4GMTG3C5y C686mRtK1Pt22E1CN3bdP8v1e0QBrX+Yvn3KbaXc+0kV+RJknK9lydHjvmn0fJtAnHXq 9mxDCvDdmhAwBksUwh0AjoFFmx5w8C7EbV1SBmX/clhUHRwuL+27gszXtYvGJ7amDyRv BbDA== X-Gm-Message-State: AOJu0YwzZB9Cq+1xZzXOpD5WABCyZrKAlFBbfFHS/cce6AubSCnuN8JR XCCX7XT0QqUYaX6mYDX3pLTQNNzvLV7NbODin5dtCZ1YQK2vbJYQvUm/7dtvnnMZuDWBnmgPzpp TMhiykVBaAfbG+yliYFq6ibuV7Gwa45JBYXMT/4jneBbchnPAJXdnJfhlYlAReluS4P445SRPo4 uKvzttjznFvymy/58cxZt1xCRhvro3ug== X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a05:6902:120b:b0:de4:67d9:a2c6 with SMTP id s11-20020a056902120b00b00de467d9a2c6mr203644ybu.2.1713974022222; Wed, 24 Apr 2024 08:53:42 -0700 (PDT) Date: Wed, 24 Apr 2024 17:53:14 +0200 In-Reply-To: <20240424155309.1719454-11-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240424155309.1719454-11-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=1348; i=ardb@kernel.org; h=from:subject; bh=XNDtlXNqERbrKnet8kKgoeintaNkpRS0TQFFAtyMk8M=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIU1T69WP2+KSbU965hyyfHHbMubHPOZrK1Ia1xxZZPv4e ocgr9GmjlIWBjEOBlkxRRaB2X/f7Tw9UarWeZYszBxWJpAhDFycAjCRgzGMDDOOXfadUMz1Y5e7 1Eej2e0P/GS3/Nw2R0dVO2trpJaVz3SG//FvfZ746Kprbm2vkwqLLn3/d4XNfJnneuvDPfcZZ/1 4xAQA X-Mailer: git-send-email 2.44.0.769.g3c40516874-goog Message-ID: <20240424155309.1719454-15-ardb+git@google.com> Subject: [RFC PATCH 4/9] x86/purgatory: Avoid absolute reference to GDT From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, Ard Biesheuvel , Arnd Bergmann , Eric Biederman , kexec@lists.infradead.org, Nathan Chancellor , Nick Desaulniers , Kees Cook , Bill Wendling , Justin Stitt , Masahiro Yamada Content-Type: text/plain; charset="UTF-8" From: Ard Biesheuvel The purgatory is almost entirely position independent, without any need for any relocation processing at load time except for the reference to the GDT in the entry code. Generate this reference at runtime instead, to remove the last R_X86_64_64 relocation from this code. While the GDT itself needs to be preserved in memory as long as it is live, the GDT descriptor that is used to program the GDT can be discarded so it can be allocated on the stack. Signed-off-by: Ard Biesheuvel --- arch/x86/purgatory/entry64.S | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/arch/x86/purgatory/entry64.S b/arch/x86/purgatory/entry64.S index 9913877b0dbe..888661d9db9c 100644 --- a/arch/x86/purgatory/entry64.S +++ b/arch/x86/purgatory/entry64.S @@ -16,7 +16,11 @@ SYM_CODE_START(entry64) /* Setup a gdt that should be preserved */ - lgdt gdt(%rip) + leaq gdt(%rip), %rax + pushq %rax + pushw $gdt_end - gdt - 1 + lgdt (%rsp) + addq $10, %rsp /* load the data segments */ movl $0x18, %eax /* data segment */ @@ -83,8 +87,8 @@ SYM_DATA_START_LOCAL(gdt) * 0x08 unused * so use them as gdt ptr */ - .word gdt_end - gdt - 1 - .quad gdt + .word 0 + .quad 0 .word 0, 0, 0 /* 0x10 4GB flat code segment */ -- 2.44.0.769.g3c40516874-goog