Received: by 2002:ab2:68c1:0:b0:1fd:9a81:d0e4 with SMTP id e1csp468100lqp; Sun, 9 Jun 2024 04:48:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXIjGe5DPCT4d1AZFZBCiskbwlshvCk3XkWew4UZ96OYesuytfQrI3OgdAUkelH6Ryd6cH6q1AyGgMgm70GLDMOmFkhgV7AUrZn6CcqtA== X-Google-Smtp-Source: AGHT+IFa6fSNUpCzYR6+Y9G9VIK/vnO/4eAQo4Pd7maBh7xJ6nBVcq+Ai1XYRkShO+P0g7zo4a66 X-Received: by 2002:a05:6870:32d3:b0:254:b9d5:a31d with SMTP id 586e51a60fabf-254b9d5a637mr1166622fac.30.1717933739513; Sun, 09 Jun 2024 04:48:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717933739; cv=pass; d=google.com; s=arc-20160816; b=RtlZIYUk0nLQ1cET5Tg03TxslBKmgzTkpLbyrwzzhc+0yh6oNVMG7yOWfo9a8MPlF5 aIdQdbXaTJ9sdhHcXwO17Y2ZUW/tF6hunSNpmaLECFE2CrJhjKHI57dhpLqf8WSfr4Rs PQ+EWaDMxGBFCfSAkzG2jhM2TvxYkxFWpCIkboEpGz/7RFLJeLAYaxG6GTEBo4g19ubF yCUnN1PZJZlvknKxNNDlxtYNqIS/VYigqMXzVyg8Ppi21VpPL2nYDSByXkkIYV3a+gdV xWrNicPwhdm7eLEMdkhClqRjQgD5yHtyETMJNlhi+M6vn7fDyo39AHq4qxYOQ25qw8hD rOAQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:references:in-reply-to :user-agent:subject:cc:to:from:date:dkim-signature:dkim-filter; bh=m+JFpwIO8dtkMONml90NvN4KcZv0aOqbfWbhdqLkHVo=; fh=tipSLxfNOPvgnOFsCYjfuBCVyWPoG480iY2OduknxPo=; b=rNOD+nBF42P/uLPx6gx1lEQIdu4a9Uqk1bBwO00LILnVxt/n2e/Xhl29fYJp6+N3vN YmmyZoal0u4gTev+VKzxxV4EhoX8mdjwS7NX3kEtvAWpqKFPwzguhU2k8IsNBKdleSjf MWM4hyO3qVK+sW+yBWxHiHf+OjxHLU4IGV1REYTY0UjUN/ueHpxDiIiAahXxtnnzXVm9 +pqDLpDGIuOsS0cxxme0YWmeer9YIKc1jRc7/d+uaqTgWAvqG1lsJ+aRham8zbT2Fq1v 9LX0Z+RJx2E8aZ6nil9OK89XGkdUxGtkGUM6gD7VpryDm54XBB5+HVGtDO1xck4oGxhm vr6g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@zytor.com header.s=2024051501 header.b="CVA/97LG"; arc=pass (i=1 spf=pass spfdomain=zytor.com dkim=pass dkdomain=zytor.com dmarc=pass fromdomain=zytor.com); spf=pass (google.com: domain of linux-kernel+bounces-207351-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-207351-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.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 d2e1a72fcca58-7042b587914si1997037b3a.333.2024.06.09.04.48.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jun 2024 04:48:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-207351-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=@zytor.com header.s=2024051501 header.b="CVA/97LG"; arc=pass (i=1 spf=pass spfdomain=zytor.com dkim=pass dkdomain=zytor.com dmarc=pass fromdomain=zytor.com); spf=pass (google.com: domain of linux-kernel+bounces-207351-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-207351-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.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 581CDB20DA5 for ; Sun, 9 Jun 2024 11:48:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4DD913BB48; Sun, 9 Jun 2024 11:48:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=zytor.com header.i=@zytor.com header.b="CVA/97LG" Received: from mail.zytor.com (terminus.zytor.com [198.137.202.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F3B82E832; Sun, 9 Jun 2024 11:48:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.136 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717933724; cv=none; b=suk5+LSbWTPbnLkz0ju5IjyCrexYWJXMaZsFRzsu+XVdQv2gyXR86ANdx4zywev5xgv2AcEQpudDPGPXAc/Xvhze45wJS5V9wuhivQimmTKwI01fHr+6AXInrHEyrfpDlimAE42lAzvtJXfAV2Ul4CI4WKoq/xatLuGPUKLecMI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717933724; c=relaxed/simple; bh=SYZL2TWgbSIkhn/R6U/bSGznHqQlrLwO6krktXsoLcc=; h=Date:From:To:CC:Subject:In-Reply-To:References:Message-ID: MIME-Version:Content-Type; b=oXMWnQlSGNWSR1Ywe0ANZgccXd5/rOOq00dk7KzoJ7vQJVgJRVDTmAsUS428Xe4yuU/CIbeVZDElaT57H8Gk2S9Bw48EldgbfRnd8r2NFApVZGxwcaG87tRv3/7tfxf5xPbHRMSdI7mtx41PVoh/jtuMZnYBhQR8UD0tjYASbHY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zytor.com; spf=pass smtp.mailfrom=zytor.com; dkim=pass (2048-bit key) header.d=zytor.com header.i=@zytor.com header.b=CVA/97LG; arc=none smtp.client-ip=198.137.202.136 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zytor.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zytor.com Received: from [127.0.0.1] ([76.133.66.138]) (authenticated bits=0) by mail.zytor.com (8.17.2/8.17.1) with ESMTPSA id 459BlqVL2567475 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NO); Sun, 9 Jun 2024 04:47:52 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 459BlqVL2567475 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2024051501; t=1717933673; bh=m+JFpwIO8dtkMONml90NvN4KcZv0aOqbfWbhdqLkHVo=; h=Date:From:To:CC:Subject:In-Reply-To:References:From; b=CVA/97LGg3fPQ1ex6wqWvVogrITI0cV3JuI963UEjAoamJaxw9U3CoHJvXGGaCdHB X4xZZdoO8vIPp3sHKGILctO2nyD2Ze1DjaUctbuHzoiH9WuhGeQJ1w31ss37FgSE3W 2RzAON5suqVxGhpF/qf00YD3GfNj05JMoLHPD4G0lZKNBCnTcGLIVDo5oAsXO4LabP Wc4IKxyaaW6XyJB86/bex8zP6DBqy5CpsVH7R2cnsoxa2/ZCYHROvUyOcUoj9NaM+i pzK/nh7WP3yO2D+YviHaP9Nqo+QvCTZXUjFLRA6euX5DMbmgjRdnXzYkXZrJ0H+E1z l7R3ut/+81m8Q== Date: Sun, 09 Jun 2024 04:47:51 -0700 From: "H. Peter Anvin" To: Borislav Petkov , Linus Torvalds CC: Ingo Molnar , Thomas Gleixner , Rasmus Villemoes , Josh Poimboeuf , Linux Kernel Mailing List , the arch/x86 maintainers , linux-arch Subject: Re: [PATCH] x86: add 'runtime constant' infrastructure User-Agent: K-9 Mail for Android In-Reply-To: <20240609112240.GBZmWQgNQXguD_8Nc8@fat_crate.local> References: <20240608193504.429644-2-torvalds@linux-foundation.org> <20240609112240.GBZmWQgNQXguD_8Nc8@fat_crate.local> Message-ID: <00BA183C-4EE6-46AE-AEC8-94B612222373@zytor.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On June 9, 2024 4:22:40 AM PDT, Borislav Petkov wrote: >On Sat, Jun 08, 2024 at 12:35:05PM -0700, Linus Torvalds wrote: >> Ingo / Peter / Borislav - I enabled this for 32-bit x86 too, because it >> was literally trivial (had to remove a "q" from "movq")=2E I did a >> test-build and it looks find, but I didn't actually try to boot it=2E= =20 > >Will do once you have your final version=2E I still have an Atom, 32-bit >only laptop lying around here=2E > >> +#define runtime_const_ptr(sym) ({ \ >> + typeof(sym) __ret; \ >> + asm("mov %1,%0\n1:\n" \ >> + "=2Epushsection runtime_ptr_" #sym ",\"a\"\n\t" \ >> + "=2Elong 1b - %c2 - =2E\n\t" \ >> + "=2Epopsection" \ >> + :"=3Dr" (__ret) \ >> + :"i" ((unsigned long)0x0123456789abcdefull), \ >> + "i" (sizeof(long))); \ >> + __ret; }) > >You might wanna use asm symbolic names for the operands so that it is >more readable: > >#define runtime_const_ptr(sym) ({ = \ > typeof(sym) __ret; = \ > asm("mov %[constant] ,%[__ret]\n1:\n" = \ > "=2Epushsection runtime_ptr_" #sym ",\"a\"\n\t" = \ > "=2Elong 1b - %c[sizeoflong] - =2E\n\t" = \ > "=2Epopsection" = \ > : [__ret] "=3Dr" (__ret) = \ > : [constant] "i" ((unsigned long)0x0123456789abcdefull), = \ > [sizeoflong] "i" (sizeof(long))); = \ > __ret; }) > >For example=2E > >> +// The 'typeof' will create at _least_ a 32-bit type, but >> +// will happily also take a bigger type and the 'shrl' will >> +// clear the upper bits > >Can we pls use the multiline comments, like you do below in the same >file=2E > >Otherwise, it looks ok to me and it boots in a guest=2E > >I'll take the final version for a spin on real hw in a couple of days, >once the review dust settles=2E > >Thx=2E > 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 reference= s until alternatives are run=2E I don't know if that was overthinking the problem=2E=2E=2E