Received: by 2002:a05:6358:795:b0:dc:4c66:fc3e with SMTP id n21csp97709rwj; Fri, 28 Oct 2022 23:22:25 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5XHu4/1NBEujqdFA9qwxv1sqwFGQ/IPbUIcLqbGLyWuAEJfvOC37GjiCQb3iYuW9IjRSue X-Received: by 2002:a17:906:5dac:b0:791:93de:c61d with SMTP id n12-20020a1709065dac00b0079193dec61dmr2588379ejv.751.1667024545433; Fri, 28 Oct 2022 23:22:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667024545; cv=none; d=google.com; s=arc-20160816; b=vHvCaLX+O14qY8/gLSfRPjEMbNjrpwnx8TUt4sKNB0O0pR3s/zg2E8yoDJveRRKl2Q MMRZjXGKnjdsbcgzX7B91f+b3+Q/kLM8diZ3T0rFE/k+z3mBErzjPh4G6Yj/0sMcjO45 JNtuANpKMLqoFNcGBPNvw/W55KRHDhdKe2FU+D74semWJi6BW8aI8mTZ2VZ6LT66W+kg xt9JQfdiFv7v4PAjkPiou1M5EHeHTZLqYV1mGiA80bwM3ncHtBBu9PhR13ZNQvaQODKB N7Zox18Zl/YuhFH4PxrbNRUSV3HuN9rSwsYluBYokln6HMDVq/EA0oN4yhky1QFu+VGq CuhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=POYh1a3g4tSD+iZ3EtDUDAKH+jsoK2U96D1r6K4W9bk=; b=Dek/QafV8872331OC6wdWYkhn7iYfujQgAhiWuimmCMFOJls8vyr4ajjFOYMwJAQlN It1VB10yp3MBH030E9PGC68whPm4dhzCD6HOuVxtgiRluLqxXtrcNVYtiyvcju4cgJci bPmU8BQi7PkX7sFKEcxZTvPHSzPFTueLgs2XpbzX8ZiTEFIzbyST6WBHFZuHQpDNNRDm a9KkrF754y36KARytTJTnVqQiE74TJimOxFrz7psjSBwhbnXPJqWTghSMAJw1pyYybK+ 3d7p+KIOmwZg/DV0tpERD0hVlqErMcYALqsgEdG2F2UxKqxfynyHKJqWf3p6jYoPY7Ac iKFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bGOZ1J8Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g14-20020a50ec0e000000b004615a57e292si782398edr.426.2022.10.28.23.21.54; Fri, 28 Oct 2022 23:22:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bGOZ1J8Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229565AbiJ2FfZ (ORCPT + 99 others); Sat, 29 Oct 2022 01:35:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229538AbiJ2FfY (ORCPT ); Sat, 29 Oct 2022 01:35:24 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5F0357565 for ; Fri, 28 Oct 2022 22:35:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1667021721; x=1698557721; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=APZf4orwR0bmaXXk1zd0xukTX05Ic5bjW94jeQ9JrPw=; b=bGOZ1J8ZIePIKuuoaYf/oc2hAZGg1IAUAh9SSvrpPNFu3ZQwCebezVfS 53wj9/Vek6KNPgfpgeGmdYY4diqPZagwgWfbb5etdiwXn5hJsddHhUlzb o5jsjEmm2IDEarXGqQmsNMYvF2UPJRAfHaIVdcLE6lcmii944obf+yNwm ddOX+lWR7v5MXN1CBxEpYKK789h0bTwjl+RmU384Dq3aQjEeznn4J0MPI oTFOeFan4ir47Gq3ii4m/dE5eWNZKJPvKygvjxUUOksSfc4U9o5rZMNsL o9+6bBz2YNJTT83V86UWFNgt1vfUZYxNuXNHxToeHQ2f+54uPx/kcjjZx Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10514"; a="335288949" X-IronPort-AV: E=Sophos;i="5.95,223,1661842800"; d="scan'208";a="335288949" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Oct 2022 22:35:21 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10514"; a="758319635" X-IronPort-AV: E=Sophos;i="5.95,223,1661842800"; d="scan'208";a="758319635" Received: from tgajewsk-mobl.ger.corp.intel.com (HELO paris.ger.corp.intel.com) ([10.249.140.235]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Oct 2022 22:35:19 -0700 From: Gwan-gyeong Mun To: ndesaulniers@google.com Cc: peterz@infradead.org, llvm@lists.linux.dev, ashutosh.dixit@intel.com, andi.shyti@linux.intel.com, linux-kernel@vger.kernel.org Subject: [PATCH] bitfield: Use argument type for size comparison on Bitfield access macros Date: Sat, 29 Oct 2022 08:34:29 +0300 Message-Id: <20221029053429.38381-1-gwan-gyeong.mun@intel.com> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Fix the size comparison code that implicitly assumes that the mask argument of bitfield access macros is an unsigned long long type. If unsigned int type is used for mask, the first argument of Bitfield access macros, and clang is used to compile, this [1] option causes a build error.[2] [1] [-Werror,-Wtautological-constant-out-of-range-compare] [2] https://lore.kernel.org/intel-gfx/c1c548f8-71a8-0d4d-d591-58a0cd5dac20@intel.com Cc: Nick Desaulniers Cc: Peter Zijlstra Cc: llvm@lists.linux.dev Cc: Ashutosh Dixit Cc: Andi Shyti Signed-off-by: Gwan-gyeong Mun --- include/linux/bitfield.h | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h index c9be1657f03d..4382bd62b14f 100644 --- a/include/linux/bitfield.h +++ b/include/linux/bitfield.h @@ -9,6 +9,7 @@ #include #include +#include /* * Bitfield access macros @@ -69,7 +70,8 @@ ~((_mask) >> __bf_shf(_mask)) & (_val) : 0, \ _pfx "value too large for the field"); \ BUILD_BUG_ON_MSG(__bf_cast_unsigned(_mask, _mask) > \ - __bf_cast_unsigned(_reg, ~0ull), \ + __bf_cast_unsigned(_reg, \ + type_max(__unsigned_scalar_typeof(_reg))), \ _pfx "type of reg too small for mask"); \ __BUILD_BUG_ON_NOT_POWER_OF_2((_mask) + \ (1ULL << __bf_shf(_mask))); \ @@ -84,7 +86,10 @@ */ #define FIELD_MAX(_mask) \ ({ \ - __BF_FIELD_CHECK(_mask, 0ULL, 0ULL, "FIELD_MAX: "); \ + __BF_FIELD_CHECK(_mask, \ + type_min(__unsigned_scalar_typeof(_mask)), \ + type_min(__unsigned_scalar_typeof(_mask)), \ + "FIELD_MAX: "); \ (typeof(_mask))((_mask) >> __bf_shf(_mask)); \ }) @@ -97,7 +102,10 @@ */ #define FIELD_FIT(_mask, _val) \ ({ \ - __BF_FIELD_CHECK(_mask, 0ULL, 0ULL, "FIELD_FIT: "); \ + __BF_FIELD_CHECK(_mask, \ + type_min(__unsigned_scalar_typeof(_mask)), \ + type_min(__unsigned_scalar_typeof(_val)), \ + "FIELD_FIT: "); \ !((((typeof(_mask))_val) << __bf_shf(_mask)) & ~(_mask)); \ }) @@ -111,7 +119,9 @@ */ #define FIELD_PREP(_mask, _val) \ ({ \ - __BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_PREP: "); \ + __BF_FIELD_CHECK(_mask, \ + type_min(__unsigned_scalar_typeof(_mask)), \ + _val, "FIELD_PREP: "); \ ((typeof(_mask))(_val) << __bf_shf(_mask)) & (_mask); \ }) @@ -125,7 +135,9 @@ */ #define FIELD_GET(_mask, _reg) \ ({ \ - __BF_FIELD_CHECK(_mask, _reg, 0U, "FIELD_GET: "); \ + __BF_FIELD_CHECK(_mask, _reg, \ + type_min(__unsigned_scalar_typeof(_reg)), \ + "FIELD_GET: "); \ (typeof(_mask))(((_reg) & (_mask)) >> __bf_shf(_mask)); \ }) -- 2.37.1