From nobody Mon Feb 9 03:10:56 2026 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) (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 BA4842500B4 for ; Mon, 10 Feb 2025 17:50:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739209810; cv=none; b=QdutOyrs9TSs7YLgcdsV3y+ZhdkU02CwoN/6s69i13fjNI4/flxG0EyEYmAzQ7CNsy85dKPcL8Btj7YNLSFzSSm0+xOTiPwRK2TBH+9aF0mh/0Kfo46fVNQxxdMi7t9gG8hVpe6E0pOWmN+xOCeX9//y+RYZdPbhQalLCcBqcWs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739209810; c=relaxed/simple; bh=G5bgzA1i0JexLpJUuL+udRJGEluZcdR0IcmYEAloLcA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=iu2+4fZwiSoqcmxDgoPF8rRP3WT6x5igDjakJ7tAXiUdE7IbjlevTEXKxii8wCzPD9DOhZ4g+iMWyk3gHDAKPBuPuehlhaA4GheoFn3AOzElch+v9IeTICJI425cPzpcDy/NZCAKjMiLEcU20OG3r0hlIYu/fyuVFU39BoXTLow= 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=PmormK+z; arc=none smtp.client-ip=209.85.221.73 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="PmormK+z" Received: by mail-wr1-f73.google.com with SMTP id ffacd0b85a97d-38de12153d4so639521f8f.0 for ; Mon, 10 Feb 2025 09:50:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1739209807; x=1739814607; 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=fkAzosm8jxvfCHu0gcd5Qhm8qoV8uLpEa5VS5jM7qwI=; b=PmormK+zs0QTGmRefoHg3z24Pb2/ONhGw8xkyvTAhXRGqIxrheavgUtIVqVX9jo0au yRQnC19Tw48sTnf5IA07gAjd2KAVDvXLw2Jd6sJoPE4nmAagtvYjhHQn6ojScGETmFie a2PgIU52o7JLdV7dda9NBjQ5AsfOt0NPFVKIMYOav6w+EJgUyTEtAfGTY49WJ5wxfNWE G7vsgMUPREupA3DOxpmEUHlnuP9h4rlA2GVpu636H2siTi2e+8oq3eWweWtlltfxCWXS hrIp62qJKSuLm0wMzVUp7X+r2ReNcrb8VvCIje4DeqaCVbYt3aUd3vwL9qN/wEAVgAhp VwCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739209807; x=1739814607; 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=fkAzosm8jxvfCHu0gcd5Qhm8qoV8uLpEa5VS5jM7qwI=; b=iB3SSsTP3yD1uAiMecaRRImzMF1+mue3j2UpTv3X4wuXtxarUkHcmejYp2zmreofWL AP/4uyzkkzslvrPiYD0BAPaOFXLqxZKRDMRi1AXlZ/TtpzqBXnL9Nz1H7SmE8XqfZ78k jQfbHkFBpaR/4v1GzIdjms24tTtGnCUppxByBTfZoeJ7yVSzHRR6KKIlPJMQsI9hJ9GT iH3/r0I2vzQMO8FRkWO4YhrRiow5V3sdS28mojwrvv3ltgTG+XXzWh4K6s9FvzzgP8eq GTQ8pghyVMQLblobBFvMlGSKXIZ0ocdOu3kmjkqT0PTzXV7S5gMcyMY+ppjxux0iGXH2 yMJQ== X-Gm-Message-State: AOJu0YwRB9Kn/3WJV8BjAMEbsaswgoKQrgt3xCpWRqeY4NhfB/Pn0jQY SGNbc/qxfuC4mJgJ3qDD7H+uxjGTJ+C00MBg1O7LnUlAO/Tbq2CG5kwgu2TQUUO7jMDspg== X-Google-Smtp-Source: AGHT+IG+VvMjqwPmxscsDUKG0E78+g6xTP/xB9+9wt/8NrZrtcQpHQnuSBRdw0akfa85CdEW0jfWOijI X-Received: from wmbfp27.prod.google.com ([2002:a05:600c:699b:b0:436:1a60:654e]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a5d:6d03:0:b0:38d:d664:67d8 with SMTP id ffacd0b85a97d-38dd6646bddmr5499501f8f.11.1739209807039; Mon, 10 Feb 2025 09:50:07 -0800 (PST) Date: Mon, 10 Feb 2025 18:49:45 +0100 In-Reply-To: <20250210174941.3251435-9-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: <20250210174941.3251435-9-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=2088; i=ardb@kernel.org; h=from:subject; bh=pDo4LLvdeMJ133Ru7rxDyvLMRfDLzKvHZSwUtXn8YcY=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIX2VjcWe4EenT3+xuVeh0TmrQvx74c3798MPblatDgnOq Xv3QnFaRykLgxgHg6yYIovA7L/vdp6eKFXrPEsWZg4rE8gQBi5OAZhIBiMjwxz/nnsXdNsnvto1 4fuV+1Pduzaqd07L9azssPmce4xnthAjw8d502+uMCrUetwubWe4++/54/nPgiVCkzR6pMtNd// LZgMA X-Mailer: git-send-email 2.48.1.502.g6dc24dfdaf-goog Message-ID: <20250210174941.3251435-12-ardb+git@google.com> Subject: [PATCH v2 3/7] x86/efi/mixed: Factor out and clean up long mode entry From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, x86@kernel.org, hdegoede@redhat.com, Ard Biesheuvel Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel Entering long mode involves setting the EFER_LME and CR4.PAE bits before enabling paging by setting CR0.PG bit. It also involves disabling interrupts, given that the firmware's 32-bit IDT becomes invalid as soon as the CPU transitions into long mode. Reloading the CR3 register is not necessary at boot time, given that the EFI firmware as well as the kernel's EFI stub use a 1:1 mapping of the 32-bit addressable memory in the system. Break out this code into a separate helper for clarity, and so that it can be reused in a subsequent patch. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/efi_mixed.S | 29 ++++++++++---------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/arch/x86/boot/compressed/efi_mixed.S b/arch/x86/boot/compresse= d/efi_mixed.S index b7886e2591fc..0b6b37b08f82 100644 --- a/arch/x86/boot/compressed/efi_mixed.S +++ b/arch/x86/boot/compressed/efi_mixed.S @@ -170,10 +170,6 @@ SYM_FUNC_START_LOCAL(efi_enter32) movl %edx, %gs movl %edx, %ss =20 - /* Reload pgtables */ - movl %cr3, %eax - movl %eax, %cr3 - /* Disable paging */ movl %cr0, %eax btrl $X86_CR0_PG_BIT, %eax @@ -199,30 +195,35 @@ SYM_FUNC_START_LOCAL(efi_enter32) lidtl 16(%ebx) lgdtl (%ebx) =20 + xorl %eax, %eax + lldt %ax + + call efi32_enable_long_mode + + pushl $__KERNEL_CS + pushl %ebp + lret +SYM_FUNC_END(efi_enter32) + +SYM_FUNC_START_LOCAL(efi32_enable_long_mode) movl %cr4, %eax btsl $(X86_CR4_PAE_BIT), %eax movl %eax, %cr4 =20 - movl %cr3, %eax - movl %eax, %cr3 - movl $MSR_EFER, %ecx rdmsr btsl $_EFER_LME, %eax wrmsr =20 - xorl %eax, %eax - lldt %ax - - pushl $__KERNEL_CS - pushl %ebp + /* Disable interrupts - the firmware's IDT does not work in long mode */ + cli =20 /* Enable paging */ movl %cr0, %eax btsl $X86_CR0_PG_BIT, %eax movl %eax, %cr0 - lret -SYM_FUNC_END(efi_enter32) + ret +SYM_FUNC_END(efi32_enable_long_mode) =20 /* * This is the common EFI stub entry point for mixed mode. --=20 2.48.1.362.g079036d154-goog