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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 A6EA0D1AD5E for ; Wed, 16 Oct 2024 14:02:06 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3E30710E71B; Wed, 16 Oct 2024 14:02:06 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by gabe.freedesktop.org (Postfix) with ESMTP id 3D1F110E71B for ; Wed, 16 Oct 2024 14:02:05 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 56310FEC; Wed, 16 Oct 2024 07:02:34 -0700 (PDT) Received: from [10.57.87.74] (unknown [10.57.87.74]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 29C0F3F71E; Wed, 16 Oct 2024 07:02:03 -0700 (PDT) Message-ID: Date: Wed, 16 Oct 2024 15:02:00 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 01/14] drm/panthor: Add uAPI To: Erik Faye-Lund , Boris Brezillon , dri-devel@lists.freedesktop.org Cc: Daniel Stone , Liviu Dudau , Steven Price , kernel@collabora.com, Chris Diamand , Ketil Johnsen References: <20240229162230.2634044-1-boris.brezillon@collabora.com> <20240229162230.2634044-2-boris.brezillon@collabora.com> <64ff75ddede7623c16ed0272eef5e950ae34e7d5.camel@collabora.com> <1bd37b18455607b709529c8def963c4561e2ff1e.camel@collabora.com> From: Robin Murphy Content-Language: en-GB In-Reply-To: <1bd37b18455607b709529c8def963c4561e2ff1e.camel@collabora.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On 2024-10-16 2:50 pm, Erik Faye-Lund wrote: > On Wed, 2024-10-16 at 15:16 +0200, Erik Faye-Lund wrote: >> On Thu, 2024-02-29 at 17:22 +0100, Boris Brezillon wrote: >>> +/** >>> + * enum drm_panthor_sync_op_flags - Synchronization operation >>> flags. >>> + */ >>> +enum drm_panthor_sync_op_flags { >>> + /** @DRM_PANTHOR_SYNC_OP_HANDLE_TYPE_MASK: Synchronization >>> handle type mask. */ >>> + DRM_PANTHOR_SYNC_OP_HANDLE_TYPE_MASK = 0xff, >>> + >>> + /** @DRM_PANTHOR_SYNC_OP_HANDLE_TYPE_SYNCOBJ: >>> Synchronization object type. */ >>> + DRM_PANTHOR_SYNC_OP_HANDLE_TYPE_SYNCOBJ = 0, >>> + >>> + /** >>> + * @DRM_PANTHOR_SYNC_OP_HANDLE_TYPE_TIMELINE_SYNCOBJ: >>> Timeline synchronization >>> + * object type. >>> + */ >>> + DRM_PANTHOR_SYNC_OP_HANDLE_TYPE_TIMELINE_SYNCOBJ = 1, >>> + >>> + /** @DRM_PANTHOR_SYNC_OP_WAIT: Wait operation. */ >>> + DRM_PANTHOR_SYNC_OP_WAIT = 0 << 31, >>> + >>> + /** @DRM_PANTHOR_SYNC_OP_SIGNAL: Signal operation. */ >>> + DRM_PANTHOR_SYNC_OP_SIGNAL = (int)(1u << 31), >> >> Why do we cast to int here? 1u << 31 doesn't fit in a 32-bit signed >> integer, so isn't this undefined behavior in C? >> > > Seems this was proposed here: > https://lore.kernel.org/dri-devel/89be8f8f-7c4e-4efd-0b7b-c30bcfbf1d23@arm.com/ > > ...that kinda sounds like bad advice to me. > > Also, it's been pointed out to me elsewhere that this isn't > *technically speaking* undefined, it's "implementation defined". But as > far as kernel interfaces goes, that's pretty much the same; we can't > guarantee that the kernel and the user-space is using the same > implementation. > > Here's the quote from the C99 spec, section 6.3.1.3 "Signed and > unsigned integers": > > """ > Otherwise, the new type is signed and the value cannot be represented > in it; either the result is implementation-defined or an > implementation-defined signal is raised > """" > > I think a better approach be to use -1 << 31, which is well-defined. > But the problem then becomes assigning it into > drm_panthor_sync_op::flags in a well-defined way... Could we make the > field signed? That seems a bit bad as well... Is that a problem? Signed->unsigned conversion is always well-defined (6.3.1.3 again), since it doesn't depend on how the signed type represents negatives. Robin.