Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2941537ybl; Sun, 11 Aug 2019 11:50:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqxFU4eGOUBs8RO/iyh4J6FcpzE/i2VWimLcu04eJs4Rileou74qBUKyxMTgKV+K3b0xS5D2 X-Received: by 2002:a17:902:2aab:: with SMTP id j40mr28190693plb.76.1565549441431; Sun, 11 Aug 2019 11:50:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565549441; cv=none; d=google.com; s=arc-20160816; b=s+WI9YGib1qAdk8MW/3HjnQd4TfXC65VBMqg0wtXJcGXh7ipyWN1rrQYSElcxypWom ke3rQ+2Ig+RbN2FNMGkXr9w8sxoaJivnnUrSSxbzGO+L6b0EWKbMC7t/PwogjF2S3frj 1Suc62LuSt3XozKQi9cRfN/pMHXbOAgiwGJQ1td22AsDk4T2hpp3c59VgGRSDX5ORUie q0NETdPN435ueR2vyoUzt7QoymvQHaVn6lLdQBrYOgdS5KV+0ABOdEf8J0LKFTtnfFBn M/2UzLdiWGv/BMtIYOHLQ8XTTBTVI2I/Oy2KSpKcLylwvGRrvENegRbAoDwYsUUkfGQx vnaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=IEYY3BqnM8b1RPxwyAoBl6+XjM31KhEUVwkBh71t+1U=; b=uz3OTFLMk9BgB3KKdgTCykKbnkxcTJ6lOHFNCnMzk2fqYkQkFlveekQRWxMzuiMTST 6/LSmk0epXJWafF3klS7QHxpojtq9vvANE/U+Zn2efxmcPZDHR4BUPpVO73McD3Ir0l8 aonyk9K9kkQyjgRM1HJK6TNPQy9AqdqWuD8FLDxvzA0Y6wjLWeUtOExvAnW05v8L+Dyv FEpIJofyO4Dq2p7zAgbWIZv74hCvsIuRdZW61Txq8FzfiGrd91j/xkzk75XXI4ZhazjF +JxJHSdtuCVkdECWRK7wQlpBdcyv2cdTohu04FoeslPTJ2x08u5Vpl2eCzC+ZOvb8fod 3IFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MpTg4xV3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a5si59301900plm.340.2019.08.11.11.50.26; Sun, 11 Aug 2019 11:50:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MpTg4xV3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726267AbfHKStp (ORCPT + 99 others); Sun, 11 Aug 2019 14:49:45 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:39998 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726014AbfHKStp (ORCPT ); Sun, 11 Aug 2019 14:49:45 -0400 Received: by mail-lj1-f196.google.com with SMTP id e27so1303926ljb.7 for ; Sun, 11 Aug 2019 11:49:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IEYY3BqnM8b1RPxwyAoBl6+XjM31KhEUVwkBh71t+1U=; b=MpTg4xV3+ndLHG9PcSw3xMceaVbWrdjGv7sAyWBSVbuyIRB0tP/4hgtlmT3nTndWbe AOUhJdAGB0ATrTCHPDTltE22gLp6Zze8N7S8uUilSoVd+B4DHZa7HKDace1l0NimCGvA dxGkP3+KSf+qBUeoGxNZMh7f0ysnU8LXXuG+vTL3nPkfgeULyC4l+0uhflbGbuS+kiHA tOL006qzU1IzX1Ive1yFz4ej+mF+R677Na+vidCZIjispQHm+fjZm6O6c9tifTTkuQCA zjxtQNJOrDiDoKHi94OdXm3pbq6dJyksHj1F/2aQ+aq6Jm1Kv/nxx/+0iWsQM5lhnLoJ AE/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IEYY3BqnM8b1RPxwyAoBl6+XjM31KhEUVwkBh71t+1U=; b=eySqYgbI6qkVFEEZZBTiFLtQJh7h6oRQh/cCxoHzdR61B1s/Y+wLdqcPbP3TE289TC KpeBB7drCbO9ILnv+/MZlEWBlUTC6w5exeZw/okoHuaanqyiMpg5pPjAw/tsvpbGbYGs 8siiFlVpWsOvxTUB91lWYU0nNYQOofWTyON6nihcFrwudpi7NMYwsQfUwa4d4isAsvDa rUD0by/YFzfXgkM88lxRnGyR/b+NgdXxGWRAj4M/ezDCYfzMZ0xcMoPd7Jyv7Mz/5efl eE+iS3stU5VOKRN/0XKdn9tKMrHaBf7AQ6qmrgZ/KxE090hWb8/Uu5lUEU57Qma1rQer Ulpg== X-Gm-Message-State: APjAAAVjeuiNteyoa9STgMGmTvFxCq273ERAj4AgEIxjQDpopBndwF3I NIEpNwGNSkhkJdS4RoMaufU= X-Received: by 2002:a2e:2c09:: with SMTP id s9mr83390ljs.222.1565549383345; Sun, 11 Aug 2019 11:49:43 -0700 (PDT) Received: from localhost.localdomain (h-158-174-186-115.NA.cust.bahnhof.se. [158.174.186.115]) by smtp.gmail.com with ESMTPSA id r21sm5250117lfi.32.2019.08.11.11.49.41 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 11 Aug 2019 11:49:42 -0700 (PDT) From: Rikard Falkeborn To: rikard.falkeborn@gmail.com Cc: akpm@linux-foundation.org, joe@perches.com, johannes@sipsolutions.net, linux-kernel@vger.kernel.org, yamada.masahiro@socionext.com, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Kees Cook , x86@kernel.org Subject: [PATCH v3 0/3] Add compile time sanity check of GENMASK inputs Date: Sun, 11 Aug 2019 20:49:35 +0200 Message-Id: <20190811184938.1796-1-rikard.falkeborn@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190801230358.4193-1-rikard.falkeborn@gmail.com> References: <20190801230358.4193-1-rikard.falkeborn@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, A new attempt to try to add build time validity checks of GENMASK (and GENMASK_ULL) inputs. There main differences from v2: Remove a define of BUILD_BUG_ON in x86/boot to avoid a compiler warning about redefining BUILD_BUG_ON. Instead, use the common one from include/. Drop patch 2 in v2 where GENMASK arguments where made more verbose. Add a cast in the BUILD_BUG_ON_ZERO macro change the type to int to avoid the somewhat clumpsy casts of BUILD_BUG_ON_ZERO. The second patch in this series adds such a cast to BUILD_BUG_ON_ZERO, which makes it possible to avoid casts when using BUILD_BUG_ON_ZERO in patch 3. I have checked all users of BUILD_BUG_ON_ZERO and I did not find a case where adding a cast to int would affect existing users but I'd feel much more comfortable if someone else double (or tripple) checked (there are ~80 instances plus ~10 copies in tools). Perhaps I should have CC:d maintainers of files using BUILD_BUG_ON_ZERO? Finally, use __builtin_constant_p instead of __is_constexpr. This avoids pulling in kernel.h in bits.h. Joe Perches sent a patch series to fix existing misuses, currently there are five such misuses (which patches pending) left in Linus tree and two (with patches pending) in linux-next. Those patches should fix all "simple" misuses of GENMASK (cases where the arguments are numerical constants). Pushing v2 to linux-next also revealed an arm-specific misuse where GENMASK was used in another macro (and also broke the arm-builds). There is a patch to fix that by Nathan Chancellor (not in linux-next yet). Those patches should be merged before the last patch of this series to avoid breaking builds. Changelog Since v2 - Use __builtin_constant_p instead of __is_constexpr to avoid pulling in kernel.h (that include was missing in v2, so the header was no longer builable standalone - add cast to BUILD_BUG_ON_ZERO to make the type int - Remove unnecessary casts due to the above - Drop patch that renamed macro arguments Since v1 - Add comment about why inputs are not checked when used in asm file - Use UL(0) instead of 0 - Extract mask creation in a separate macro to improve readability - Use high and low instead of h and l (part of this was extracted to a separate patch) - Updated commit message Rikard Falkeborn (3): x86/boot: Use common BUILD_BUG_ON linux/build_bug.h: Change type to int linux/bits.h: Add compile time sanity check of GENMASK inputs arch/x86/boot/boot.h | 2 -- arch/x86/boot/main.c | 1 + include/linux/bits.h | 21 +++++++++++++++++++-- include/linux/build_bug.h | 4 ++-- 4 files changed, 22 insertions(+), 6 deletions(-) -- 2.22.0