Received: by 2002:ab2:68c1:0:b0:1fd:9a81:d0e4 with SMTP id e1csp569091lqp; Sun, 9 Jun 2024 08:57:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXJLPanN1yV73JBpZIZYYlKXAWTiW/2u15UkERfq5ckyIbjZlsFT4SRjxuEyGM7foKYnUEGOZ9QCd6rGMHGGEdDasL/fX31+bhgND6Cpw== X-Google-Smtp-Source: AGHT+IFj2vRehJlV8/KVVRJn4LpgK0fFAsRyoxfWjZWVQ78kzEJzn7ibM2HIoWbv2q7DMgEDPZln X-Received: by 2002:a17:906:37c5:b0:a6e:f6b0:c4a9 with SMTP id a640c23a62f3a-a6ef6b0cc93mr447335166b.9.1717948672011; Sun, 09 Jun 2024 08:57:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717948672; cv=pass; d=google.com; s=arc-20160816; b=iwq4zefpsLZ0QMpfOl81j9Z8rhc2L7+koDxWdUkDUazku7iY1O6sue2bRtK01sWm7u fyTWgvCst3evbriXQHqNBUVlgOaJH2VEnAomcABcAEN3zA/jD8KRg/Yn7VpAcC+xelW5 SW0t0zlCFmjciYiaBRQR9KT6OTHeT9/eCeJQ0OL9OUxuD8JR4s8Rn+Urn2vETVi/Z0Kd LJh5+hlSvBT3smALoz8lXZ7C1sDzRHMHdbl2ADCShGHc/QVp845zgLsXsSwjzGjW0NOE r8A5xAkhHIPoHIGWHEHU+jh3LNLjq7u7JQGDsB87UNz1nheTuVS6YxMJ9z+IFmTiVl0G hYBw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=Yj9Z56DW6+nSHM9dJZ7yiVMylhEQOTIVepZXRaOEBmQ=; fh=LagLvHsrr7Bnr92p1cZW9ryv/tDQ/zvPs7uJ4dpuvnA=; b=BZx7swK7+a9cqN7Pql+K63Ef0IYVERBjLZm/txGd/Hk4LY0mA7MX02NS7YDxA0biUm 5MxP4QOVWSXZuSxNTKjvpSFcRIenLiH7EBWuBQ3fJKBBBZbNqHWZXVw16TrNmHGfOFbj LTS8Xcvsn5FDr/2OAvmBBjan+xtOMfeYXFi4EaLThmU+Y05HvRJEOU/5sXbOQLgF1Zc2 vj2NSE/MEbyfh4Npgd8kEmjPKPpsZOOWTA0QlGFv9hskkWjobXyLhOw8dGXBBYSLzyU0 6EKKcffc2jldLfixFWfSbvRGbSsoZnBT8hNup+M167Ghe8N+0e0u8Y2eu8fXGAztqYtX ZByQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=LrH9hwc5; arc=pass (i=1 spf=pass spfdomain=linuxfoundation.org dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-207400-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-207400-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a6c805979acsi381949366b.43.2024.06.09.08.57.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jun 2024 08:57:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-207400-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=LrH9hwc5; arc=pass (i=1 spf=pass spfdomain=linuxfoundation.org dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-207400-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-207400-linux.lists.archive=gmail.com@vger.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 am.mirrors.kernel.org (Postfix) with ESMTPS id A73B31F2196C for ; Sun, 9 Jun 2024 15:48:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6E0E545BFF; Sun, 9 Jun 2024 15:47:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="LrH9hwc5" Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (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 64E9D45BF1 for ; Sun, 9 Jun 2024 15:47:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717948075; cv=none; b=RGgdBDApZX7ahyjNHhQFd9szRF6AEwgcSXJoLQM5qh8nrtJzFrVnFn8JOmCQ5MpLAJ/M4h94fvb71J+/3M3wpJS+SVPhMyhlhYY4sHZfKl11TzN12LGUMcH8WMVmVYGxiGNpg954acmaR1iTZPCjSWuT0FXR7aWYjghRCZVu8SU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717948075; c=relaxed/simple; bh=rWELLHoGeL+cuZcwTGrspQgmi3NpQFHoFf+sewYQBwk=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Q9RJRr73QqP1kpgb3PkvQFLYfIxF1Gud2HlhVBqQ5oZKehDhdFbWwMvHE797ddYWQNT9CZ6FGpi/J6Fblb1WaTbu/wZzondoduo3Pmz4aPo9CJFo7DRfm3mVblRIHrv2ON+F7b9YW2w1wDDilTyUlQpzaaXFNVdNDX6LT79sAwE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org; spf=pass smtp.mailfrom=linuxfoundation.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=LrH9hwc5; arc=none smtp.client-ip=209.85.218.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linuxfoundation.org Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a6ef8e62935so189749066b.3 for ; Sun, 09 Jun 2024 08:47:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1717948071; x=1718552871; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Yj9Z56DW6+nSHM9dJZ7yiVMylhEQOTIVepZXRaOEBmQ=; b=LrH9hwc5MpaI3dJuoPY73fPwi8F4SL/HfR+UgVr/swwFfBxChNmiwhJuWhmYsKksv9 ftKi563hZTQlZqEHXOgY5T8AAcJxuhYurwHiylXmQbaa583DfKCcJuNFNmR1A+v6/dhC 4AMERydO/hXUrgGeeBrzZJK7hGRUS82aF9mJY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717948071; x=1718552871; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Yj9Z56DW6+nSHM9dJZ7yiVMylhEQOTIVepZXRaOEBmQ=; b=fM2DW2yo+I6h0xbXC7hzybZkmtgXT+59jzu+UpkLskOp8Zp4Hrthgb/9BnhE0JjoXv 5TpfSdTrMTrr1+mQFffTz6eCKeoWH3OKkh+qJ34ZbU4mkryOrXd0f8XA1HHQLpgbfQOl Hk6UvW+y6IJGDyyzlev+dJG9K/WDf3Bl/lNYx33R4uQyaEOjj0jOwIYL5XplwlBwoSZ3 QyWEEWt5wEJEMiW0amR3CxlFI0ko3ojwjoPvQz89HILzGN0bvlehOUvHKwoCfnAg6eAf +XGm69HAdTHWPyl0CSjXxedbiIAQ1hSbGP/ZghTH3E0XbAsSyzk/P3JrvF5yK/nkdSxq VOqQ== X-Forwarded-Encrypted: i=1; AJvYcCX9JLVRmGzgykA6FX1GaCggtHBWG5sVnHM3YkFLqDNO7Yeq70900yQDwUljcJ4P5zL9CWGCuxMCsENZNnGTytkFES7aWpgkb8sF8g2P X-Gm-Message-State: AOJu0YypLLWK+C7Mx5CRnd/y5JktHfoAbxJITadFFJ5EelSNl8h0ShIJ ciBhdHzRJtbV6aP+Jm//anPjqCdTfUnJxPuGkJ07y3G5NFi6lFKQgtkA+GVcTV1nQKzMix8Iy+o jJHg= X-Received: by 2002:a17:907:2d27:b0:a6f:1daa:9031 with SMTP id a640c23a62f3a-a6f1daa9cc0mr84513166b.42.1717948071514; Sun, 09 Jun 2024 08:47:51 -0700 (PDT) Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com. [209.85.218.48]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a6e67133de7sm356693866b.57.2024.06.09.08.47.50 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 09 Jun 2024 08:47:50 -0700 (PDT) Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-a6f1da33826so31455866b.0 for ; Sun, 09 Jun 2024 08:47:50 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCUmLSKHi3oCc4FMdDxMz0OUDxT/g9L0KTsVYercxsduiBWJT/ycdHMQU5QXuC/V7uL+K7txwczDSYh/c5iU2QTPsGuFsJb996F2ZlYN X-Received: by 2002:a17:907:3ea0:b0:a6f:1b3d:8e0e with SMTP id a640c23a62f3a-a6f1b3d9041mr125143666b.25.1717948070458; Sun, 09 Jun 2024 08:47:50 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240608193504.429644-2-torvalds@linux-foundation.org> <20240609112240.GBZmWQgNQXguD_8Nc8@fat_crate.local> <00BA183C-4EE6-46AE-AEC8-94B612222373@zytor.com> In-Reply-To: <00BA183C-4EE6-46AE-AEC8-94B612222373@zytor.com> From: Linus Torvalds Date: Sun, 9 Jun 2024 08:47:33 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] x86: add 'runtime constant' infrastructure To: "H. Peter Anvin" Cc: Borislav Petkov , Ingo Molnar , Thomas Gleixner , Rasmus Villemoes , Josh Poimboeuf , Linux Kernel Mailing List , "the arch/x86 maintainers" , linux-arch Content-Type: text/plain; charset="UTF-8" On Sun, 9 Jun 2024 at 04:48, H. Peter Anvin wrote: > > So the biggest difference versus what I had in progress was that I had > the idea of basically doing "ro_after_init" behavior by doing memory > references until alternatives are run. Yeah, that would make it a lot more complicated, because now you need to replace the whole asm, and you need to write it in a way that it can be replaced with alternate code. It's a bit akin to what Rasmus' RAI code did, but while I liked Rasmus' patch, I honestly don't think there is any advantage to having that "load from memory" alternate version. At least for something like the dcache lookup, the "before things have been initialized" state is that the runtime constant pointer is NULL, so the pre-init code would cause an oops anyway, even if it had that "load from memory" fallback. Now, there may be other uses for these kinds of runtime constants, but I do think the main one - and the one I wrote this for - is simply a boot-time allocation. So I think that kind of "before it's initialized, it won't work whether there's a load from memory or not" is fairly fundamental. There are other constants this could be used for - particularly things like "size of virtual memory". That #define task_size_max() \ ((_AC(1,UL) << __VIRTUAL_MASK_SHIFT) - PAGE_SIZE) thing really used to be a big pain back when we used it in every get_user/put_user call. We replaced it with just the sign bit test, though, and now it's gone. (I still see it in profiles in strncpy_from_user(), but it's not really noticeable, and it's fixable using a similar address masking thing). I'd expect that there are other cases than the dcache lookup that wants this, but none that really show up on any of the profiles _I_ tend to run (but I don't benchmark networking, for example). There is the security layer blob_sizes "constants" that could possibly use this, but a part of the cost there is that since they aren't compile-time constants, the compiler can't just use a common base pointer. So even if those were converted to runtime constants, it wouldn't make the code generation all _that_ much better. Linus