From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A1583C5AE59 for ; Tue, 3 Jun 2025 08:50:52 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.1004103.1383754 (Exim 4.92) (envelope-from ) id 1uMNLx-0008M4-Df; Tue, 03 Jun 2025 08:50:37 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1004103.1383754; Tue, 03 Jun 2025 08:50:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uMNLx-0008Lx-AC; Tue, 03 Jun 2025 08:50:37 +0000 Received: by outflank-mailman (input) for mailman id 1004103; Tue, 03 Jun 2025 08:50:36 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uMNLv-0008LS-E8 for xen-devel@lists.xenproject.org; Tue, 03 Jun 2025 08:50:36 +0000 Received: from 11.mo581.mail-out.ovh.net (11.mo581.mail-out.ovh.net [87.98.173.157]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ce230f34-4057-11f0-b894-0df219b8e170; Tue, 03 Jun 2025 10:50:31 +0200 (CEST) Received: from director3.ghost.mail-out.ovh.net (unknown [10.109.176.32]) by mo581.mail-out.ovh.net (Postfix) with ESMTP id 4bBPYf6pglz1QvJ for ; Tue, 3 Jun 2025 08:50:30 +0000 (UTC) Received: from ghost-submission-5b5ff79f4f-b5lhs (unknown [10.110.118.96]) by director3.ghost.mail-out.ovh.net (Postfix) with ESMTPS id 50725C335E; Tue, 3 Jun 2025 08:50:29 +0000 (UTC) Received: from 3mdeb.com ([37.59.142.112]) by ghost-submission-5b5ff79f4f-b5lhs with ESMTPSA id ZmE9CFW3PmgnWQAAZkLW6g (envelope-from ); Tue, 03 Jun 2025 08:50:29 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ce230f34-4057-11f0-b894-0df219b8e170 Authentication-Results:garm.ovh; auth=pass (GARM-112S006faa6357b-4629-49dd-9956-33b0c4d85953, 22913471B39E4060B5DF5B2870BF10C0EF5640C4) smtp.auth=sergii.dmytruk@3mdeb.com X-OVh-ClientIp:176.111.184.221 Date: Tue, 3 Jun 2025 11:50:10 +0300 From: Sergii Dmytruk To: Jan Beulich Cc: "Daniel P. Smith" , Ross Philipson , Andrew Cooper , Roger Pau =?iso-8859-1?Q?Monn=E9?= , Lukasz Hawrylko , Mateusz =?iso-8859-1?Q?M=F3wka?= , trenchboot-devel@googlegroups.com, xen-devel@lists.xenproject.org Subject: Re: [PATCH v2 01/22] x86/include/asm/intel-txt.h: constants and accessors for TXT registers and heap Message-ID: References: <31c7faf1-d393-40d5-87f9-1a01d1ab39cb@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Ovh-Tracer-Id: 13210746560626406489 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeeffedrtddtgdegtddutdculddtuddrgeefvddrtddtmdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefuvghrghhiihcuffhmhihtrhhukhcuoehsvghrghhiihdrughmhihtrhhukhesfehmuggvsgdrtghomheqnecuggftrfgrthhtvghrnhepvdfgveegtdffhfdugeevieehkeetudevfeefgedtleejledvfeeutdetudeiveelnecukfhppeduvdejrddtrddtrddupddujeeirdduuddurddukeegrddvvddupdefjedrheelrddugedvrdduuddvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepuddvjedrtddrtddruddpmhgrihhlfhhrohhmpehsvghrghhiihdrughmhihtrhhukhesfehmuggvsgdrtghomhdpnhgspghrtghpthhtohepuddprhgtphhtthhopeigvghnqdguvghvvghlsehlihhsthhsrdigvghnphhrohhjvggtthdrohhrghdpoffvtefjohhsthepmhhoheekudgmpdhmohguvgepshhmthhpohhuth DKIM-Signature: a=rsa-sha256; bh=HoeJbOdgFF8DGKZtGTTXnf1sgdKHTqI+Ki+n84Io8OA=; c=relaxed/relaxed; d=3mdeb.com; h=From; s=ovhmo3617313-selector1; t=1748940631; v=1; b=EP2herTYghv/L01tKNr6xvuldY3iyPHHLknCyEE3Iv+s1gKZNWeDiaCVcEzRyRUBGkvGujit PvptCrqcn/LF5mWTP+O6fLBQ41JN0k77JBUSVsECGnk8oiGJBdRoYEH9I6gG/sLFkHx92u8o+eD Umw4RfZhf6JF0EF3xAGc+Ife9a56WtCknbctBCbJ7FjR8OrXXnmgBd0KLIpUtMr5x2/32Fc8aWB x6jyDpwyg/FR5hEQoX6CtFBXzjI3JELOBx63HBGdpV6zz2QW7oLxnWHxbS0vSUlGsfabepmWK4b 22dTsB5jGh6U4GcuHTsV5fAmhIqG90Fpv9lXoAF4+oiqQ== On Tue, Jun 03, 2025 at 09:06:53AM +0200, Jan Beulich wrote: > On 03.06.2025 00:00, Sergii Dmytruk wrote: > > On Mon, Jun 02, 2025 at 09:17:37AM +0200, Jan Beulich wrote: > >> On 23.05.2025 21:51, Sergii Dmytruk wrote: > >>> On Wed, May 21, 2025 at 05:19:57PM +0200, Jan Beulich wrote: > >>>>> +static inline uint64_t txt_bios_data_size(void *heap) > >>>> > >>>> Here, below, and in general: Please try to have code be const-correct, i.e. > >>>> use pointers-to-const wherever applicable. > >>> > >>> I assume this doesn't apply to functions returning `void *`. The > >>> approach used in libc is to accept pointers-to-const but then cast the > >>> constness away for the return value, but this header isn't a widely-used > >>> code. > >> > >> Which is, from all I know, bad practice not only by my own view. > > > > I actually ended up doing that to have const-correctness in v3. In the > > absence of function overloads the casts have to be somewhere, can put > > them in the calling code instead. > > Casts of which kind? For context: There shouldn't be any casting away of > const-ness (or volatile-ness, for the sake of completeness). > > Jan Casting away const-ness inside of functions like static inline void *txt_bios_data_start(const void *heap) If a function accepts a const pointer and returns it, this turns a non-const incoming pointer into a const one. Without duplicating the code (either having const and non-const versions or repeating code in other ways), nothing can be made const cleanly in here including *_size() functions because they call *_start() functions: static inline uint64_t txt_os_mle_data_size(const void *heap) { return *((const uint64_t *)(txt_bios_data_start(heap) + // ^^^^ -- const txt_bios_data_size(heap))) - sizeof(uint64_t); } Regards