Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp570530lqt; Fri, 19 Apr 2024 04:36:00 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU5oZ+sum9YFCBiKXxb/5jct5X2APJTVZXO9RQBVFEQp17yoSLKCubuN4OOJnWzXA5/3Dp3jQwOQCAOJaWw1IBJQOka5BmeLhTnWRADuA== X-Google-Smtp-Source: AGHT+IGlpGfbcNGYYVN6s8kCIgCg2DEoMaaT71MnAjispLOi+4oFzK0u8HKZ2pU/38pIvAijez1s X-Received: by 2002:a05:620a:16b7:b0:78d:6786:7637 with SMTP id s23-20020a05620a16b700b0078d67867637mr1845847qkj.71.1713526560011; Fri, 19 Apr 2024 04:36:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713526559; cv=pass; d=google.com; s=arc-20160816; b=W59FlF2elb+N8nJhl+TX943c2z0k5e3+YA8UtpLfYQ9lIjxGBZXy+ptZHVZCLo3/j6 r2mejcjK4FmWYPaGYuKzYo4lcTAC55VWja99Kf09LG0cUcZ3I5n1kOHtzeanQdRm89OX mGtZgUjZALE0NBnGSpFwShf06ExZ4IcZv/RQTB005qgnHdSDvjl4cg8FDSNB+/JjmoDX r7/iZ4rro3aquLodUIMwKXu6H8mdiLK7tw0tSKInhv2RAYuDMXdyA9oWTVjsQNLIcCHn RWSSB1Bdbj7ZpmMIGJGN/YgvaKdMEQoHpl+l0pyHwDLU6eItmlQekF3eyBgdPTtk+eij eMxg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id; bh=8xJo1iE+MpyYnzTox+HNu4cFWvvore+ilh6MMNgutSg=; fh=F0ft3U0FTeidoUFkWBSpAcLh9RVzVXQKvMvkoXBUNn4=; b=jVwO9NIXQC4S2NGBI4ks7ARJbhD0CUR56wxkJLMz9liZ1MMKWK3gIaC6lA1HeLOrS5 4qaOm02Sj5hbl0U/JtQCrDNtXqy8jOhdRiseqtD3RbxUl5TDwU4ednOWiXSnYFgc7ZWJ zW9awhT4oizXXx1bpr7PndfSMEWA2dPDSfZnw2bx00RHMWlATb5ZTXwzljBIdrJBns3I Pc1trGxLeccAcWm3V0ZQmiIWHlxvOyoxev8M3sP5vyqwSQtj6jXpnZ0MrYMWoez5rgG7 AxqDy6RAqI0Ija00aDzu10CnqszWVF8xhuAygIhVgS2n/w7pibPe9y9rxjpUTI/gRL8+ cvjA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-151377-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151377-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id c10-20020a05620a134a00b007902736f3c3si556321qkl.576.2024.04.19.04.35.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 04:35:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-151377-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-151377-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151377-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id AD8E11C21046 for ; Fri, 19 Apr 2024 11:35:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F293C823A9; Fri, 19 Apr 2024 11:35:50 +0000 (UTC) Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (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 CA40781723; Fri, 19 Apr 2024 11:35:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713526550; cv=none; b=kgd+VZa1/33vyuxFfWVhvpbCoPDoX1VUF9f2OwlgSTAb6G0O8YUd85lRMKHq1iDqobpKxwomJoRHW/abcX+IDCxTuEU3ODLrxEW8mJ0+kv6Ba3sK0MsFNQD8+YOu00btH+Ge+hHgNzfPE2uHWGzmtrujXjvZl3H5d2iFTe5d/Pk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713526550; c=relaxed/simple; bh=rlq/tKihz5oJ2zPYopZmFp+AEw0r3N3aYzkfb/0gwG8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=gfF+PcV/faiGVSa2vPQBfrdDa9SYN8iFAmrveFFDYcp102erO2hVbwQq/JawxKJV7Wu4GgX0tFGxq4uZaljDhQyarcoAykiCVOA0jwsogeF7RKP6fO/dKiyqA2JhbSFuxzQWXzpl17WYLgjC7tasWn8rfnQ/sx+C7mh08jZzPJE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-565c6cf4819so5331301a12.1; Fri, 19 Apr 2024 04:35:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713526547; x=1714131347; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=8xJo1iE+MpyYnzTox+HNu4cFWvvore+ilh6MMNgutSg=; b=GPdFiCe7HCYhbkap68VjwROLljNSG6+zBaBH7Cay+KcouFO6Wx2KZl2Q7MjeMgsyhM KZboGhqz6Fzu3PhGc8xhLANauRUxEP4hMu7SGsZ9lehmqVuXj1epnbDh55ujj1RR11Hj ox07qJPtdDbmH+1utwsFXtjUR5bsTkP4NzCPMFlaz8AY6pve6GtN6i37SlwWVyRvpGJ2 aJAUMexMm5YyExEJijdpj8LSAaAn7xYthCfFznB1tTKh/BeSuSbfbCpdWFWU1TxK72JG C1w8F0GfamtDe+EzC8gx7qcO4ppFlYTotZi/lX4NoAeMTdPe1Ifz+wSvoT97MwcnQxuk Ndmw== X-Forwarded-Encrypted: i=1; AJvYcCXP9JnOK6pltPBDVvxY6ir91DAVyky+uoVlUCIqfiJRyuQf5X8FC/KyEXS4HGVWoMmjLWct1M+zX9U1IIVguBCZS5G2FRry3tKbZ3ZGw/fRfbapH04Mygwqi4mQ+InJegm67Dd3 X-Gm-Message-State: AOJu0YyO2F1007i+cQR0exBlpID0iP7Z1iRHefjez7YH3mthTpHfjgsy JuTIkPrzhto0GJG81vhRS2yedLTBVAuZBczSWVlQZME5rCQXkOO0 X-Received: by 2002:a17:906:ae94:b0:a51:ab81:6062 with SMTP id md20-20020a170906ae9400b00a51ab816062mr4348557ejb.30.1713526546888; Fri, 19 Apr 2024 04:35:46 -0700 (PDT) Received: from ?IPV6:2a0b:e7c0:0:107::aaaa:69? ([2a0b:e7c0:0:107::aaaa:69]) by smtp.gmail.com with ESMTPSA id jp4-20020a170906f74400b00a4734125fd2sm2086049ejb.31.2024.04.19.04.35.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 19 Apr 2024 04:35:46 -0700 (PDT) Message-ID: <3f23b551-4815-4a06-9217-ff5beeb80df2@kernel.org> Date: Fri, 19 Apr 2024 13:35:44 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] x86/purgatory: Switch to the position-independent small code model To: Ard Biesheuvel , linux-kernel@vger.kernel.org Cc: x86@kernel.org, Ard Biesheuvel , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Song Liu , Ricardo Ribalda , Fangrui Song , Arthur Eubanks , stable@vger.kernel.org References: <20240418201705.3673200-2-ardb+git@google.com> Content-Language: en-US From: Jiri Slaby Autocrypt: addr=jirislaby@kernel.org; keydata= xsFNBE6S54YBEACzzjLwDUbU5elY4GTg/NdotjA0jyyJtYI86wdKraekbNE0bC4zV+ryvH4j rrcDwGs6tFVrAHvdHeIdI07s1iIx5R/ndcHwt4fvI8CL5PzPmn5J+h0WERR5rFprRh6axhOk rSD5CwQl19fm4AJCS6A9GJtOoiLpWn2/IbogPc71jQVrupZYYx51rAaHZ0D2KYK/uhfc6neJ i0WqPlbtIlIrpvWxckucNu6ZwXjFY0f3qIRg3Vqh5QxPkojGsq9tXVFVLEkSVz6FoqCHrUTx wr+aw6qqQVgvT/McQtsI0S66uIkQjzPUrgAEtWUv76rM4ekqL9stHyvTGw0Fjsualwb0Gwdx ReTZzMgheAyoy/umIOKrSEpWouVoBt5FFSZUyjuDdlPPYyPav+hp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BFAVzRQ5nVrrLDAJZ8Y5ioWcm99JtSIIxXxt9FJaGc1Bgsi5K/+dyTKL wLMJgiBzbVx8G+fCJJ9YtlNOPWhbKPlrQ8+AY52Aagi9WNhe6XfJdh5g6ptiOILm330mkR4g W6nEgZVyIyTq3ekOuruftWL99qpP5zi+eNrMmLRQx9iecDNgFr342R9bTDlb1TLuRb+/tJ98 f/bIWIr0cqQmqQ33FgRhrG1+Xml6UXyJ2jExmlO8JljuOGeXYh6ZkIEyzqzffzBLXZCujlYQ DFXpyMNVJ2ZwPmX2mWEoYuaBU0JN7wM+/zWgOf2zRwhEuD3A2cO2PxoiIfyUEfB9SSmffaK/ S4xXoB6wvGENZ85Hg37C7WDNdaAt6Xh2uQIly5grkgvWppkNy4ZHxE+jeNsU7tg= In-Reply-To: <20240418201705.3673200-2-ardb+git@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 18. 04. 24, 22:17, Ard Biesheuvel wrote: > From: Ard Biesheuvel > > On x86, the ordinary, position dependent 'small' and 'kernel' code models only > support placement of the executable in 32-bit addressable memory, due to > the use of 32-bit signed immediates to generate references to global > variables. For the kernel, this implies that all global variables must > reside in the top 2 GiB of the kernel virtual address space, where the > implicit address bits 63:32 are equal to sign bit 31. > > This means the kernel code model is not suitable for other bare metal > executables such as the kexec purgatory, which can be placed arbitrarily > in the physical address space, where its address may no longer be > representable as a sign extended 32-bit quantity. For this reason, > commit > > e16c2983fba0 ("x86/purgatory: Change compiler flags from -mcmodel=kernel to -mcmodel=large to fix kexec relocation errors") > > switched to the 'large' code model, which uses 64-bit immediates for all > symbol references, including function calls, in order to avoid relying > on any assumptions regarding proximity of symbols in the final > executable. > > The large code model is rarely used, clunky and the least likely to > operate in a similar fashion when comparing GCC and Clang, so it is best > avoided. This is especially true now that Clang 18 has started to emit > executable code in two separate sections (.text and .ltext), which > triggers an issue in the kexec loading code at runtime. > > Instead, use the position independent small code model, which makes no > assumptions about placement but only about proximity, where all > referenced symbols must be within -/+ 2 GiB, i.e., in range for a > RIP-relative reference. Use hidden visibility to suppress the use of a > GOT, which carries absolute addresses that are not covered by static ELF > relocations, and is therefore incompatible with the kexec loader's > relocation logic. FWIW: Fixes: https://bugzilla.suse.com/show_bug.cgi?id=1211853 thanks, -- js suse labs