Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2593394rdb; Wed, 21 Feb 2024 12:37:52 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUVSURN9cuUuvRTG3gqGu7iJbknhpB3NvcZ1K7Ie2q/wJRTi3D8vkXr+9a1z2JoK/EB1bmTyC/03O5H3vVyvDfULOvQrIJUfBWfJoaWCQ== X-Google-Smtp-Source: AGHT+IHdt99jI+3A1JX0EUH4+X9fSkTnWs+bQiGRGpQDwMEBAtZ7Dy4iyubmnhLJ1G1tW6Ye2KN5 X-Received: by 2002:a17:907:b9d3:b0:a3f:1cb8:8b9a with SMTP id xa19-20020a170907b9d300b00a3f1cb88b9amr3234993ejc.51.1708547872216; Wed, 21 Feb 2024 12:37:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708547872; cv=pass; d=google.com; s=arc-20160816; b=zX7dF/Q0Z+8CzNnmqWDaQFMDxmwwfCh3UvynPOcUMmU8wghSz1JBkj3B6zNFmns0/y oIZ9UME4W5AmoX+VHByl70gbuGQ7LfAGADX5f9bP+q5iHH4/9cbo5VMxBOcwQbSrfG0I 3/5Iee9TIng0uKFHjkljXUqH9AiultR3R+2FrZItX++yH2EjKXWyGkQwW4I0sZkNYtdN ffplvMlsS7yt0Xoa6qAO6Bbzz87oNpM5SbUOxrSVxXjN1IphilbH3l8JpWNmQgd0+BFz MKg6X33xlyg5spgizesO+BK2eG3Q6faJxAyWUWHGSPEvDtOEc7tiK4zZyn8wsyeexkLR w56A== 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=LemITai8o2S9gTBYLEbvTlpnnxm99PXeiUxZksmifiI=; fh=k16s6+vBWIRJkwgKPoeQgGxmJDAl6Mf3XzGIYK9obqY=; b=UfbkdWZEUs79WJWUr0LQxkNzGJvDWzhzKyrcPOoQS2XmPCXn2tt/eAsxl/lU55XOs/ lxYtBc5J6SPjfmO65YHJ8eP4g0PJytU+IeQsgmm2/fovbjkl4vyh6ouV6zqifzD5ZaCL clDBCnhFlAQurVFw7VmWJRplIXybdtbp4y2TplLayB7O0VWOOjhVf0qBS4gsdO2cxCwn s6mJ4/jbt5EPsdrjTS2dyRMmS96rvWvnWViQ4aceK2CKgGHXhMaC6m+2PMHgGfphTjdm +9Z92YVnfB9p+l6B6Ms0tqWlpSRbDFMJn3I8mb58cF/kgXKWGzAKmfJaPMJwIt/n87gt v/qQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rs3Cua4L; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-75470-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75470-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.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 oz19-20020a1709077d9300b00a3f0e623cd2si1793539ejc.882.2024.02.21.12.37.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 12:37:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75470-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=@linaro.org header.s=google header.b=rs3Cua4L; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-75470-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75470-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.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 C533A1F24EBA for ; Wed, 21 Feb 2024 20:37:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 34BF13C46D; Wed, 21 Feb 2024 20:37:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="rs3Cua4L" Received: from mail-yb1-f180.google.com (mail-yb1-f180.google.com [209.85.219.180]) (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 5B0934A1D for ; Wed, 21 Feb 2024 20:37:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708547864; cv=none; b=CT4RTtioVlBiTU9izRPk3MDvOeJHTZzuQgP3KrKtUYSWyFCA2mlExzQTez2pPgnrhempkbtQYxv3ddDPDhqhdnK56MoDV2PdcO7jhICLUr3a11BKvrEKP9vp1X7/tIth/pAcGC3k2vkFMZkCByNpfgyG5sHDBdEdPd3m4RnZQYQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708547864; c=relaxed/simple; bh=pD1anHYz7Qvyjwrl3Ul7SA/vuVDFvvq0ON2C3+jQcVQ=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=SPFs8raW2Srx4odNB+6SuKhWuCJZpAH1XNjLLWHOxZBmI0sJ+rFbetX7lu/4HHP+gi4gpQkZ8RRO2KeEtLFFEIeiHCCK+Xiygd+XLx/rFOyuzC9Cxto8TbsKfYrJKLOIEeK83u/DqURrtx/eXeSivmLwuNxAXEwB8GxDXqARWcA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=rs3Cua4L; arc=none smtp.client-ip=209.85.219.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-yb1-f180.google.com with SMTP id 3f1490d57ef6-dcbef31a9dbso4773063276.1 for ; Wed, 21 Feb 2024 12:37:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708547861; x=1709152661; 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=LemITai8o2S9gTBYLEbvTlpnnxm99PXeiUxZksmifiI=; b=rs3Cua4LskIupLa1meID+vLP7z0mv9s/WRsVO8KAE+jdYS05qAJn6HzHg/Jm0yaVHK NRMrfdjemU5qBvBoKCHTuX0aOCTmuD2FiKHWd3DoALbddOU4X/7SnwiN0TAp6M+oSbIl wAJNeKTOaZ0LwqOl7DcC2Imfgm6v5Ie4yhhPoZ6ZZ21RmSuC+ctACT/By85HOma27Cyh J9eNMTUdojNuT+g8LXAlCkUr9kPgcxNTg/SvAeX5oTaJTIgwDn03euc/UwVjka1ra74f Xe9fxC+/+rDprqbNblDVdrlxmNZf5yZV2SuRii3OVJ1WpibMkes8eY5qm+HaWC2uuShv Amng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708547861; x=1709152661; 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=LemITai8o2S9gTBYLEbvTlpnnxm99PXeiUxZksmifiI=; b=SHzDCjZR8KkjzJDyV/kaLxipInSJ/oNPCvVNX6jBXpVCPGyMs4be4ghu/S7apKtg3E 09MMyxMSGL7PHcwzCz+gd9JyY60YAdlAvQIMM1gIdjkJx9+Xx4DOQHEWtNMpUDC2T7Zw +5IqiueTkYixSg9ctRt9bwd8s3qgdmNs1Qx7YrW2NKE99CwoCrh0zhSboNipEUfil+MT oSeHY0xrmBLq1H0xLXP03+1Z5hup7++SC6Jq5FLS8CykLeynsPTAnSovd//fiR5J9S3s SaywmJp6ScuhZ5p4gjp9Y6hwR+sE9qMNlSon/2LYp2xKDseEdwG9puAO8xEBCnk03txd 48ag== X-Forwarded-Encrypted: i=1; AJvYcCW5QKWDA03E33dHAPUlZDLmgSU9OCp2xpJe+SHp5D7QndJSGE08cv7wvxhldS6bKtdmzRmF1ACm+blKNVBFKU5NdZHDuU4N0yaF68hY X-Gm-Message-State: AOJu0Yw+nWLsT6i3nm5b70R10zEnLDMurtIbovyU2LFEXCrragaGKLno PQ3AY1/oqHsSFPpS560D8j0a9xa6D66b7nmhHh4ECwgw7n46y/LKcshYbZ+aXL44MvPK8cevFX2 p++0PohpC/tPUsoFSbOc/B0+665ew6+9fTPpzoroQBGNHJkNe8qY= X-Received: by 2002:a5b:d09:0:b0:dc7:4367:2527 with SMTP id y9-20020a5b0d09000000b00dc743672527mr420992ybp.49.1708547861221; Wed, 21 Feb 2024 12:37:41 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240208074521.577076-1-lucas.demarchi@intel.com> <20240208074521.577076-2-lucas.demarchi@intel.com> In-Reply-To: From: Dmitry Baryshkov Date: Wed, 21 Feb 2024 22:37:30 +0200 Message-ID: Subject: Re: [PATCH v3 1/3] bits: introduce fixed-type genmasks To: Lucas De Marchi Cc: Yury Norov , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Andy Shevchenko , Jani Nikula , intel-xe@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, Jani Nikula Content-Type: text/plain; charset="UTF-8" On Wed, 21 Feb 2024 at 22:30, Dmitry Baryshkov wrote: > > On Thu, 8 Feb 2024 at 09:45, Lucas De Marchi wrote: > > > > From: Yury Norov > > > > Generalize __GENMASK() to support different types, and implement > > fixed-types versions of GENMASK() based on it. The fixed-type version > > allows more strict checks to the min/max values accepted, which is > > useful for defining registers like implemented by i915 and xe drivers > > with their REG_GENMASK*() macros. > > > > The strict checks rely on shift-count-overflow compiler check to > > fail the build if a number outside of the range allowed is passed. > > Example: > > > > #define FOO_MASK GENMASK_U32(33, 4) > > > > will generate a warning like: > > > > ../include/linux/bits.h:41:31: error: left shift count >= width of type [-Werror=shift-count-overflow] > > 41 | (((t)~0ULL - ((t)(1) << (l)) + 1) & \ > > | ^~ > > > > Signed-off-by: Yury Norov > > Signed-off-by: Lucas De Marchi > > Acked-by: Jani Nikula > > --- > > include/linux/bitops.h | 1 - > > include/linux/bits.h | 32 ++++++++++++++++++++++---------- > > 2 files changed, 22 insertions(+), 11 deletions(-) > > > > diff --git a/include/linux/bitops.h b/include/linux/bitops.h > > index 2ba557e067fe..1db50c69cfdb 100644 > > --- a/include/linux/bitops.h > > +++ b/include/linux/bitops.h > > @@ -15,7 +15,6 @@ > > # define aligned_byte_mask(n) (~0xffUL << (BITS_PER_LONG - 8 - 8*(n))) > > #endif > > > > -#define BITS_PER_TYPE(type) (sizeof(type) * BITS_PER_BYTE) > > #define BITS_TO_LONGS(nr) __KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(long)) > > #define BITS_TO_U64(nr) __KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(u64)) > > #define BITS_TO_U32(nr) __KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(u32)) > > diff --git a/include/linux/bits.h b/include/linux/bits.h > > index 7c0cf5031abe..bd56f32de44e 100644 > > --- a/include/linux/bits.h > > +++ b/include/linux/bits.h > > @@ -6,6 +6,8 @@ > > #include > > #include > > > > +#define BITS_PER_TYPE(type) (sizeof(type) * BITS_PER_BYTE) > > + > > #define BIT_MASK(nr) (UL(1) << ((nr) % BITS_PER_LONG)) > > #define BIT_WORD(nr) ((nr) / BITS_PER_LONG) > > #define BIT_ULL_MASK(nr) (ULL(1) << ((nr) % BITS_PER_LONG_LONG)) > > @@ -30,16 +32,26 @@ > > #define GENMASK_INPUT_CHECK(h, l) 0 > > #endif > > > > -#define __GENMASK(h, l) \ > > - (((~UL(0)) - (UL(1) << (l)) + 1) & \ > > - (~UL(0) >> (BITS_PER_LONG - 1 - (h)))) > > -#define GENMASK(h, l) \ > > - (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l)) > > +/* > > + * Generate a mask for the specified type @t. Additional checks are made to > > + * guarantee the value returned fits in that type, relying on > > + * shift-count-overflow compiler check to detect incompatible arguments. > > + * For example, all these create build errors or warnings: > > + * > > + * - GENMASK(15, 20): wrong argument order > > + * - GENMASK(72, 15): doesn't fit unsigned long > > + * - GENMASK_U32(33, 15): doesn't fit in a u32 > > + */ > > +#define __GENMASK(t, h, l) \ > > + (GENMASK_INPUT_CHECK(h, l) + \ > > + (((t)~0ULL - ((t)(1) << (l)) + 1) & \ > > + ((t)~0ULL >> (BITS_PER_TYPE(t) - 1 - (h))))) > > > > -#define __GENMASK_ULL(h, l) \ > > - (((~ULL(0)) - (ULL(1) << (l)) + 1) & \ > > - (~ULL(0) >> (BITS_PER_LONG_LONG - 1 - (h)))) > > -#define GENMASK_ULL(h, l) \ > > - (GENMASK_INPUT_CHECK(h, l) + __GENMASK_ULL(h, l)) > > +#define GENMASK(h, l) __GENMASK(unsigned long, h, l) > > +#define GENMASK_ULL(h, l) __GENMASK(unsigned long long, h, l) > > +#define GENMASK_U8(h, l) __GENMASK(u8, h, l) > > +#define GENMASK_U16(h, l) __GENMASK(u16, h, l) > > +#define GENMASK_U32(h, l) __GENMASK(u32, h, l) > > +#define GENMASK_U64(h, l) __GENMASK(u64, h, l) > > This breaks drm-tip on arm64 architecture: > Excuse me, it seems a c&p from gitlab didn't work as expected. arch/arm64/kernel/entry-fpsimd.S: Assembler messages: arch/arm64/kernel/entry-fpsimd.S:271: Error: found 'l', expected: ')' arch/arm64/kernel/entry-fpsimd.S:66: Info: macro invoked from here arch/arm64/kernel/entry-fpsimd.S:271: Error: found 'l', expected: ')' arch/arm64/kernel/entry-fpsimd.S:66: Info: macro invoked from here arch/arm64/kernel/entry-fpsimd.S:271: Error: found 'l', expected: ')' arch/arm64/kernel/entry-fpsimd.S:66: Info: macro invoked from here arch/arm64/kernel/entry-fpsimd.S:271: Error: found 'l', expected: ')' arch/arm64/kernel/entry-fpsimd.S:66: Info: macro invoked from here arch/arm64/kernel/entry-fpsimd.S:271: Error: unexpected characters following instruction at operand 3 -- `bic x2,x1,(0+(((unsigned long)~0ULL-((unsigned long)(1)<<(0))+1)&((unsigned long)~0ULL>>((sizeof(unsigned long)*8)-1-(3)))))' arch/arm64/kernel/entry-fpsimd.S:66: Info: macro invoked from here arch/arm64/kernel/entry-fpsimd.S:282: Error: found 'l', expected: ')' arch/arm64/kernel/entry-fpsimd.S:98: Info: macro invoked from here arch/arm64/kernel/entry-fpsimd.S:282: Error: found 'l', expected: ')' arch/arm64/kernel/entry-fpsimd.S:98: Info: macro invoked from here arch/arm64/kernel/entry-fpsimd.S:282: Error: found 'l', expected: ')' arch/arm64/kernel/entry-fpsimd.S:98: Info: macro invoked from here arch/arm64/kernel/entry-fpsimd.S:282: Error: found 'l', expected: ')' arch/arm64/kernel/entry-fpsimd.S:98: Info: macro invoked from here arch/arm64/kernel/entry-fpsimd.S:282: Error: unexpected characters following instruction at operand 3 -- `bic x2,x1,(0+(((unsigned long)~0ULL-((unsigned long)(1)<<(0))+1)&((unsigned long)~0ULL>>((sizeof(unsigned long)*8)-1-(3)))))' arch/arm64/kernel/entry-fpsimd.S:98: Info: macro invoked from here make[4]: *** [scripts/Makefile.build:361: arch/arm64/kernel/entry-fpsimd.o] Error 1 make[3]: *** [scripts/Makefile.build:481: arch/arm64/kernel] Error 2 make[2]: *** [scripts/Makefile.build:481: arch/arm64] Error 2 make[2]: *** Waiting for unfinished jobs... -- With best wishes Dmitry