From patchwork Sun Mar 10 02:04:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13587951 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 7B36617E1 for ; Sun, 10 Mar 2024 02:05:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710036336; cv=none; b=EhnXHcw1OF4fhTeoX351pwp1g7tRFkz58W6nCisdTup4ZZPWae7DYHtawAfWDO8yTFfQw/1hLwq0krn7L9purZUJZXSHqNKId/4XHBsmNip0fCRwVIdczP3kYdU5LfztYlDEqJ1TrqJ7OZGcLho6Ta4VXg7dpd0VaamAxHDy2ek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710036336; c=relaxed/simple; bh=ZSKBQS+8Mn7aJnZUbJUB/8XB7m9MXAj5PzIqShvjvqw=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=jdpgx8t0qSMOllIMCC4k6qsIyqyeNeHlsyIJKccnewg+NuuHrc6LV3IWHuemC39vNsNOmd8BYvIhmVl3zwyWzfZHvEkKeFsJWRq+tDSbKi5NdB1G97l90W2izCLhmVqbyW8p1YUtX//MFtRMt5VY/YEOTuBZ6nqSKta3sL3TF+E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=BZG3qtOl; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="BZG3qtOl" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc6b5d1899eso5900201276.0 for ; Sat, 09 Mar 2024 18:05:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710036333; x=1710641133; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=s1Gx+zOxHa5G/G1Me70ulKh3Qhwa8FiZyBNMKmpUzIM=; b=BZG3qtOl1Lk1bJytdZIVHW9ExdwmwN/JyuPocEHdNsRCuLVNgssy0pB7ZrYEQaeIYt Xpch/sx+B2mZNpYIaXqj2ErUzL6DyoV9k51hqaseqtNGf+tFPDIRK0M4UZno+WFKhLzx I/I7jVpTe4tOwOALJYHX3N8rV1W+aEpvY8fz70RitI7T1/f6kzlysPSkUjqFAx4JYqr7 RL4UC9w9/wJzj4mfBMoUr9SbFp/bd2Wl1eTTa5pbVD6pheNUauDUd02cBvj+dgS3dj0R cif0w2wMFYBZxxJYd0amy0KrezZWmVQ9RRQYg5tMQh/H/faAl1wfckVzIhOyijqDmJWc XsiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710036333; x=1710641133; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=s1Gx+zOxHa5G/G1Me70ulKh3Qhwa8FiZyBNMKmpUzIM=; b=bECHWuLtC5liX//0IId2hogg2S1oaBZ/B11Eq1QPKo6lMh1XPNlAwKx/cRvBjD/wre ucjIh86aihsef1UsysSV7JW8kHxnXctq1cMqIWZcHwmTlBBQdDGyKywZ0qWKMJ3YHGQm HnYp0b9lICFyy/Q5KmgG9H4vzp9SW98tiz/+mEYO6FIPK0WfXTpDlgeZgXa6FedLT4Rb IYYdEtbU/mt7VnK8udLjfbbwojwu1lDXoLbDbq79P1gM9IhNXxR2/EyTN+qHCIt9+NCO DfT8OtwWElhIw5wgD2lRtbvcxy9lyUbvJqKzL9yOEQmP2/L6FgKLZXY7LmZq3z389eUH Er3Q== X-Forwarded-Encrypted: i=1; AJvYcCXi7jQAqrIzdYPjoOEJ2Ob/cR/kmtVXNNkQ0j7zEQU/4elzu6c7gvr9l0IxphK98kzDE2Kr969rkLOf7Jn31V2eXDV+txYzXgCFXePJVVfX X-Gm-Message-State: AOJu0Ywbtyw7axOQH5ah9ERxtgK/60wf7fsAjntsXJLO+n0Otd3odHYU qRfBM2S0fa3tn76z12tDxBRtuHGcVT+5C8VmCL1IZWwSrxZ02XAJcjD7ua275C1HHRAukQf3CP1 nPpdHgg== X-Google-Smtp-Source: AGHT+IF4u5R6JlS2lv4g7BW2szOoJKeUuXHhe4ENBdL2Zr6Mgb8g7E49MW+hNNmJV1buj1jkBdxVOnRyOcxA X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:a63d:1b65:e810:3ad3]) (user=irogers job=sendgmr) by 2002:a05:6902:10c2:b0:dbd:b4e8:1565 with SMTP id w2-20020a05690210c200b00dbdb4e81565mr1091610ybu.4.1710036333476; Sat, 09 Mar 2024 18:05:33 -0800 (PST) Date: Sat, 9 Mar 2024 18:04:56 -0800 In-Reply-To: <20240310020509.647319-1-irogers@google.com> Message-Id: <20240310020509.647319-2-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240310020509.647319-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Subject: [PATCH v1 01/13] tools bpf: Synchronize bpf.h with kernel uapi version From: Ian Rogers To: Arnd Bergmann , Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Ian Rogers , Adrian Hunter , Paolo Bonzini , Shuah Khan , Kees Cook , "Gustavo A. R. Silva" , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Andrew Morton , Liam Howlett , Miguel Ojeda , Will Deacon , Mark Brown , David Laight , "Michael S. Tsirkin" , Shunsuke Mie , Yafang Shao , Kui-Feng Lee , James Clark , Nick Forrington , Leo Yan , German Gomez , Rob Herring , John Garry , Sean Christopherson , Anup Patel , Fuad Tabba , Andrew Jones , Chao Peng , Haibo Xu , Peter Xu , Vishal Annapurve , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-hardening@vger.kernel.org, llvm@lists.linux.dev Commit 91051f003948 ("tcp: Dump bound-only sockets in inet_diag.") added BPF_TCP_BOUND_INACTIVE to the enum of tcp states in uapi's bpf.h. Synchronize the tools version of the file. To avoid future divergence add uapi/linux/bpf.h, include/uapi/linux/bpf_common.h and include/uapi/linux/bpf_perf_event.h to the check-headers.sh script. Signed-off-by: Ian Rogers --- tools/include/uapi/linux/bpf.h | 1 + tools/perf/check-headers.sh | 3 +++ 2 files changed, 4 insertions(+) diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index 7f24d898efbb..754e68ca8744 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -6904,6 +6904,7 @@ enum { BPF_TCP_LISTEN, BPF_TCP_CLOSING, /* Now a valid state */ BPF_TCP_NEW_SYN_RECV, + BPF_TCP_BOUND_INACTIVE, BPF_TCP_MAX_STATES /* Leave at the end! */ }; diff --git a/tools/perf/check-headers.sh b/tools/perf/check-headers.sh index 66ba33dbcef2..64dbf199dff9 100755 --- a/tools/perf/check-headers.sh +++ b/tools/perf/check-headers.sh @@ -6,6 +6,9 @@ NC='\033[0m' # No Color declare -a FILES FILES=( + "include/uapi/linux/bpf.h" + "include/uapi/linux/bpf_common.h" + "include/uapi/linux/bpf_perf_event.h" "include/uapi/linux/const.h" "include/uapi/drm/drm.h" "include/uapi/drm/i915_drm.h" From patchwork Sun Mar 10 02:04:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13587952 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 414235394 for ; Sun, 10 Mar 2024 02:05:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710036339; cv=none; b=DFNr8G6h8kcGb/3fV92FXonG2AsN2RmmTPY0Ne3bkHb2fmKOYQZPJcoZFTt69FrMYEX/f5+K6rFsexMw517y22LAHZ9LX/XHfhyZNAkqD6pddbGGFTdNrgh/v0OuCUmi6636nXN2+2CIoyhvJQMARtTdSfqlYbcGy7XZ4I/u60s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710036339; c=relaxed/simple; bh=D2uX+Mnk+6vztSUZd5hP00XWtGAz0CoTxvXAkzGNj1I=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=kAJ+vBJXxIkC9AtljqsX5vcI15/yVrPb8W6L3sK8jMSb/Xsn83lAo7mKo4Wyz+UuA7+QgcwF/glSUTzrazL2v+RTMjWy8AusJ32Lz4yM8nSK3LFJq8qwpzGRfE0wduIC8QrNIaStlkfldTRz2676R+cLi1gMNVsQp/sgUCUDnsA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=kMIRydFx; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="kMIRydFx" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-60a2386e932so7272877b3.1 for ; Sat, 09 Mar 2024 18:05:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710036336; x=1710641136; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=T7XIYLAkcLSrj5FLrGjKI8q+UW4mZzYyudvGuQ4/TZo=; b=kMIRydFxidKzY7BpYx9EUp/eSGgFea4GwwQrTWrZFWAG+5gWnMJU0Gbf6KDWEXRVbB yt7yTV4W7LoKxr4bwuLNicNelGV0VJdo8+Xxc3tr9qWqEormXicnooeGM+XBHP/F8Lpv MkZPbXBbSyvDxovJoSlKKkCQ8NeOEsoPsWWeQ/wCQOw3jDd+VazdaPjgJjjglqJ2YrqQ DzXZQwEmve8ZRYv9vrjP3ObWuuQVtRPblfKrVNINjUlnr0Z/lkXrGfycXXpfWJCveve2 LkbG7/7/jskn+XiPH/2MRqGAtT1mcFiev5F2k5tRA7Uy3qUjHzrB0948Z1PAUaO33IXn CXSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710036336; x=1710641136; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=T7XIYLAkcLSrj5FLrGjKI8q+UW4mZzYyudvGuQ4/TZo=; b=vTMQBr5uNME6yyU02IZU4E06GLIMJAFSMAawOMwihJRUwT/fessxFxeMlqDp1zm4Dg Zjo+nDSeZ0CBMX+9YXpHpvhSxap25YqdsjffWeamRkWszI0RIQYhWKn0eUrWMFgXPwOU bAHQPkX76vzqjHO7y6V+oBya/EGvv7roaGvEWdoSzGJ+CRHVMsIE+nCFL8jjX3hvakC2 2VJQxqFwopOTrdVzJj1Krhi74Cwbyte9izksWBn+WFa0Vz2fVvrBNx6N75De1qeVfLS/ 7rhf2P8Xonh4yaIhahC7tKjI4ljn8ICIncYuN2Pk/X5NSPq9qBYyra6pP6lcq6YoLUDh tP2Q== X-Forwarded-Encrypted: i=1; AJvYcCWWFurnIxBJvA0at7mXQ9BemLIhOn5BBSNjm3G77UL7ZfdCXtkEMUjOmEZuElC6aca9Cz4k9vR8/RUM9/fZ2jEC6zmfg+Q1RnaE9C9Mdaze X-Gm-Message-State: AOJu0YxK0ZsFPmZxkli9qU7xwCUIlGzskQ6Z1UoThGOk5bqSOPFpEuL+ +SseXYyI7sMx/3GVbvWE/+qZfY3BIc+7zOmiUeK5yHLKtcHPrMmxOhj1Yp/MlDKeXPnJpfRU6Ix vwPorMA== X-Google-Smtp-Source: AGHT+IHgDNWM+Z4QXgFMm7GizvEhHToqcLHuZHJtXyYeO1MzHp7huAG4ihDQbMUHqCDQpOBGjLQSGQDO0YZe X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:a63d:1b65:e810:3ad3]) (user=irogers job=sendgmr) by 2002:a0d:d7cd:0:b0:608:72fe:b8a1 with SMTP id z196-20020a0dd7cd000000b0060872feb8a1mr953360ywd.4.1710036336387; Sat, 09 Mar 2024 18:05:36 -0800 (PST) Date: Sat, 9 Mar 2024 18:04:57 -0800 In-Reply-To: <20240310020509.647319-1-irogers@google.com> Message-Id: <20240310020509.647319-3-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240310020509.647319-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Subject: [PATCH v1 02/13] libbpf: Make __printf define conditional From: Ian Rogers To: Arnd Bergmann , Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Ian Rogers , Adrian Hunter , Paolo Bonzini , Shuah Khan , Kees Cook , "Gustavo A. R. Silva" , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Andrew Morton , Liam Howlett , Miguel Ojeda , Will Deacon , Mark Brown , David Laight , "Michael S. Tsirkin" , Shunsuke Mie , Yafang Shao , Kui-Feng Lee , James Clark , Nick Forrington , Leo Yan , German Gomez , Rob Herring , John Garry , Sean Christopherson , Anup Patel , Fuad Tabba , Andrew Jones , Chao Peng , Haibo Xu , Peter Xu , Vishal Annapurve , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-hardening@vger.kernel.org, llvm@lists.linux.dev libbpf depends upon linux/err.h which has a linux/compiler.h dependency. In the kernel includes, as opposed to the tools version, linux/compiler.h includes linux/compiler_attributes.h which defines __printf. As the libbpf.c __printf definition isn't guarded by an ifndef, this leads to a duplicate definition compilation error when trying to update the tools/include/linux/compiler.h. Fix this by adding the missing ifndef. Signed-off-by: Ian Rogers Acked-by: Andrii Nakryiko --- tools/lib/bpf/libbpf.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index afd09571c482..2152360b4b18 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -66,7 +66,9 @@ */ #pragma GCC diagnostic ignored "-Wformat-nonliteral" -#define __printf(a, b) __attribute__((format(printf, a, b))) +#ifndef __printf +# define __printf(a, b) __attribute__((format(printf, a, b))) +#endif static struct bpf_map *bpf_object__add_map(struct bpf_object *obj); static bool prog_is_subprog(const struct bpf_object *obj, const struct bpf_program *prog); From patchwork Sun Mar 10 02:04:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13587953 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 2BEF0C128 for ; Sun, 10 Mar 2024 02:05:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710036342; cv=none; b=sVllwa2460X4e2zuydNS2V21+QYpY0Wa40XeZBlXokZ+Adakns1B9W4ZsToXxXpUeGC9jp/zIzXHcIvLVdan2UrSegpPQ7GOJPicFFKTN+44t8G/IWKbWOnqAGC+PAE24S0aQh/8OoWZJ+8djImX79i/6Tc4NoXyF+NjSycjkbo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710036342; c=relaxed/simple; bh=RGHR+QiLceocR0H7Go2J+IFsQikYIqGpUdA5u3bRq6I=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=ewEwTIGjWawV8bpfINtTvhJpi6JS3Lf7aMl/xTbsWBmQJGa774zYY+c3Gxy5WYeIEWOk8nzoL+K+bOO9vWpeVoOhZ4u1cLBBiSpPv5XrecSCmQ0ueyv/9pzseYcU6L95U2F5nxF8SFWxZ46PW5Y/pfJCAe+7H+Lgi2UGSRn8dic= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=VRsNZPe0; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="VRsNZPe0" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60a08eb0956so24606747b3.3 for ; Sat, 09 Mar 2024 18:05:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710036339; x=1710641139; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=lEogdjVExxayJMRv1u0mjZw+1C1F2zoHt9ebGCOCyUE=; b=VRsNZPe08ukQkLbC8cLeYP0BRexi0H/ytB079Ek1//YKN6get16huQfO+BpiG1tXOD /DfXJJsAhbpa41MJSgaY2NShFvyfGKd41kr50rONuG+9vGjXxf92ch8Hl6eGAPWS0hw7 V3PejFFmfmrU5vPpGLAigL7iSv4mZImqptxoFxJQ4OjxVvG0ERXdGOpP+Lgn2PtK9AWA 0g0yb0s9m2oHNGuLPm57TNOEk03to2Zrwt1BJs6TA32/yB8FdcS9VHIy8Wq9TRzx0jSD Bgqc+g/01i/CxnEOjKXp+j/RC3Las1cviN75DkghO3v1bmFnfAoqbBTNS/IAQpDlv+tN PkEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710036339; x=1710641139; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lEogdjVExxayJMRv1u0mjZw+1C1F2zoHt9ebGCOCyUE=; b=ljjIXImEafSzFpC7mQtFssaBm7lQY9Sk3J//BMe/I2oYOUhV8mrWaqR28y3d4sQwUg 1EOiSmYnhSrcW6YLtjkLOR946RZ8bUldgAt3u5s+pqBCPEXbsCmQ9IY1XGaAZ4jjDpUd jEijIrxEkURI9bD4X1vUZxBUh+cmqZuS6ZZm1mGdh3XiBLDPx/QVpU4L9/1LNA0dlPIk bm5y1JZo/VgiP6ZXYCrhwnFRqYUliwV8JiIF8F6KD0rkWwYQAmNv9mCvdHTASQ7gMAyj kI25V9FS77b7lzI88caMl5dWsm2bfukdgwTtS5UKSWkmQ6lmM+WWTSrtTtESK4QP+jME L+fQ== X-Forwarded-Encrypted: i=1; AJvYcCX5KkNvozJoqdzrGqEr+PHAvQ+bThSQDDWxLuIiBVn7QQrKHGry3GDuGtP+XFkaJ+Oqg45jHAxtIZAuIA5fS/svwib19GoortJp3GFGVtnM X-Gm-Message-State: AOJu0YyWw8RcbAnkIxpjcYOu3rUxK+5A1U4xRp1VWwZbgYT5HFrXdHq/ Up5uTO/VfUdj2Pj/sWw6hsJr+sVhZ8tzHEy3evZN99hpP158QZUxpEMZOg7a24qzuZEArmniUBD yD0od3g== X-Google-Smtp-Source: AGHT+IEyM3cHgr9ZVgnZoKCZ0SYCN/4S3200GAqNBDyFBPz9iTsTIsAdJdgR5M7Dk98A1ko/gir8jVGY1z12 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:a63d:1b65:e810:3ad3]) (user=irogers job=sendgmr) by 2002:a0d:e84c:0:b0:609:d325:5826 with SMTP id r73-20020a0de84c000000b00609d3255826mr678752ywe.7.1710036339213; Sat, 09 Mar 2024 18:05:39 -0800 (PST) Date: Sat, 9 Mar 2024 18:04:58 -0800 In-Reply-To: <20240310020509.647319-1-irogers@google.com> Message-Id: <20240310020509.647319-4-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240310020509.647319-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Subject: [PATCH v1 03/13] libperf xyarray: Use correct stddef.h include From: Ian Rogers To: Arnd Bergmann , Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Ian Rogers , Adrian Hunter , Paolo Bonzini , Shuah Khan , Kees Cook , "Gustavo A. R. Silva" , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Andrew Morton , Liam Howlett , Miguel Ojeda , Will Deacon , Mark Brown , David Laight , "Michael S. Tsirkin" , Shunsuke Mie , Yafang Shao , Kui-Feng Lee , James Clark , Nick Forrington , Leo Yan , German Gomez , Rob Herring , John Garry , Sean Christopherson , Anup Patel , Fuad Tabba , Andrew Jones , Chao Peng , Haibo Xu , Peter Xu , Vishal Annapurve , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-hardening@vger.kernel.org, llvm@lists.linux.dev sys/types.h may not define both NULL and size_t used in this file. Change the dependency to the correct stddef.h one. Signed-off-by: Ian Rogers --- tools/lib/perf/include/internal/xyarray.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/lib/perf/include/internal/xyarray.h b/tools/lib/perf/include/internal/xyarray.h index f10af3da7b21..947804fb8c85 100644 --- a/tools/lib/perf/include/internal/xyarray.h +++ b/tools/lib/perf/include/internal/xyarray.h @@ -3,7 +3,7 @@ #define __LIBPERF_INTERNAL_XYARRAY_H #include -#include +#include struct xyarray { size_t row_size; From patchwork Sun Mar 10 02:04:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13587954 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 E2884F9FF for ; Sun, 10 Mar 2024 02:05:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710036344; cv=none; b=Uehs1j1n2PxqewZacdS3/9mnh/x6XQ0vwglwskyEzMuGmsCTDfi+Jdv10D3C3/UCsmqG2hMoKy2FwpdQF74K2N35fpHnLPk0lildP8xw7/jnvXEVrWhSISsquCavUPwVcFBJVEmEFOamUHkmO+cfkun08CnB9I883YnVmNvemgY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710036344; c=relaxed/simple; bh=xr9hx9bRTXredcOnZvT9aTZmO8EItvyRPuWwawu0cX0=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=Y0LCT7BFOxOZR5P/oa97ZVbmu1c4kh79XFExGeE+JRtJYkZIAxlhp11qv8N5OqDXi2DsODkgyexK75WJ+4qPDRhR8mc5CqnWHydLW16af0O72XeVULDTy9+ifoKYso8DX/eaCteYfJ/Hz6xzuVc4cv8HAmhozkG/AaeMB24reb4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=GDFA5/1S; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="GDFA5/1S" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-60a0151f194so40237227b3.1 for ; Sat, 09 Mar 2024 18:05:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710036342; x=1710641142; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=4OaMyUQu371uaOuekdLYCxktVf9TU0U4kdxUUW/XeAo=; b=GDFA5/1SAcDvh5wHDztVT4fdrpGGN0qq+wpmeK16nZfyhHocB7oKXyTmzVAjzmV6VQ 5efsx7rWgkIJt9XTz3UTXv0jUKjDM44630OfMOWCL+/MX2eTAFoiJOGBI13uUTGVPtTz NDN+lhd3oRLxtTVbRD4XZr/lLDtewndKru+9BgwwM7FlnwBteO5LxseGlOoFtQxEBNkx mrP9DMhE3682KLijmsAxz1fyTIHq0zDD5ZT8yJohRFnrcvMiz/QlvnRqfLRzwk5Rj2yS 7y4iNFQSZiHWgNU0RM9VoGK+Gh9T6Fkg3yOEDCSxbtF+obf/+2LqKuC/0FUrQ6sd1l60 veaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710036342; x=1710641142; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4OaMyUQu371uaOuekdLYCxktVf9TU0U4kdxUUW/XeAo=; b=MwjIs26Khqr3jr5tjIquSqPPgUQm2cBbvGWCLKobNjkfhBErTjEFtnaTm08woY8r6v P1RmPRY4fV8nxR9aMN1AEYF72yF6eh/n8Ph8phfXqycXZ82wjqrODW2xLKiNk7QGkD8F mBd00cFh1311Pe9H3y9RmQtB+ySFBYxzF9NcK8RXmM/L3mdWWm7i4wZHuEn1VJR2t5kP 0m2i5oQ80PR8CYIiLVIBBP98Mzvg4Zo1iiNi+4WfLDaWnNDd4SSlB5NoMM27maEKv8cD umpSBBA1ngFSx6nXnQrOivEWvAkpDEseuvDS0ZKFTIRzdMDtkUTnkeFX9XnLGAdbhON3 jBWQ== X-Forwarded-Encrypted: i=1; AJvYcCWjKsIftbK0BuxBN97s1YD6+hyzkfW8jG73droLHD6Ng1ec2sj5Hw9vGghtSDmzArbVHnZnY0RG/DQZVfDBLtH7ye9S6tk4/wEZtTGygn8R X-Gm-Message-State: AOJu0YzeEAHucrxP7zXFBr1I/Knmqy7TV9zxEdPHi7qBhLfHaLOiCXeX TBXQgm8nMfSHdr44LE8GZbalV+rAVpl62qVUgOCG3ZZQadAXwfHEc7fXoUP6XBcEJdqFB4guqCu 0qcEfqw== X-Google-Smtp-Source: AGHT+IGxAKGLHfU5lr4cLxfntoHY/lII821Bv6GcWrrnRg5nZbXZHQCblMErp4nOuwdOu0LpnsGeX3qwWfLp X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:a63d:1b65:e810:3ad3]) (user=irogers job=sendgmr) by 2002:a05:6902:1889:b0:dc6:dfc6:4207 with SMTP id cj9-20020a056902188900b00dc6dfc64207mr903918ybb.10.1710036341778; Sat, 09 Mar 2024 18:05:41 -0800 (PST) Date: Sat, 9 Mar 2024 18:04:59 -0800 In-Reply-To: <20240310020509.647319-1-irogers@google.com> Message-Id: <20240310020509.647319-5-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240310020509.647319-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Subject: [PATCH v1 04/13] perf expr: Add missing stdbool.h include From: Ian Rogers To: Arnd Bergmann , Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Ian Rogers , Adrian Hunter , Paolo Bonzini , Shuah Khan , Kees Cook , "Gustavo A. R. Silva" , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Andrew Morton , Liam Howlett , Miguel Ojeda , Will Deacon , Mark Brown , David Laight , "Michael S. Tsirkin" , Shunsuke Mie , Yafang Shao , Kui-Feng Lee , James Clark , Nick Forrington , Leo Yan , German Gomez , Rob Herring , John Garry , Sean Christopherson , Anup Patel , Fuad Tabba , Andrew Jones , Chao Peng , Haibo Xu , Peter Xu , Vishal Annapurve , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-hardening@vger.kernel.org, llvm@lists.linux.dev bool is used in this header and so stdbool.h is necessary. Add to avoid compilation errors that aren't currently seen due to transitive dependencies. Signed-off-by: Ian Rogers --- tools/perf/util/expr.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/perf/util/expr.h b/tools/perf/util/expr.h index c0cec29ddc29..d4166b3eb654 100644 --- a/tools/perf/util/expr.h +++ b/tools/perf/util/expr.h @@ -2,6 +2,8 @@ #ifndef PARSE_CTX_H #define PARSE_CTX_H 1 +#include + struct hashmap; struct metric_ref; From patchwork Sun Mar 10 02:05:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13587955 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 645F01DDC9 for ; Sun, 10 Mar 2024 02:05:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710036347; cv=none; b=TrRD9KpScQJCulaP1DQby5IsUfzqqfmurq+RezyMRwuLlX9LX1r1/dZ5K+RpLaz+OfBVuSCMR2p9qsW4mhORehyfBpL7qa3SNGb8EgccBU44CCujxBJn6Th2kykD+Lllox+mplGuXsc3ZAyk6aHWdlV5rpVAywuxlEM5Yo+5BvI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710036347; c=relaxed/simple; bh=6Ap0HyfNfUIjggJWxJHCU3eDXgcXlw9rod9BkywTOBU=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=tsvyuUaDqUfpH/cbpwpPXnzngl0zJWj4wrLW8LZpX3HZ9k2pfmtTwZhrHyFmRlG57C+tieax40QCK/m69MNMxIP1KopSHAzEPpOspggiiJMoKWypUWsYMkvRNEwui1MT42kNoSE5z5erS2dTBMZOR4TVx7Y6wmQAbk13/c2lVU8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=0p4sSbDK; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="0p4sSbDK" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6047fed0132so54453497b3.1 for ; Sat, 09 Mar 2024 18:05:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710036344; x=1710641144; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=LWN/JVLNlztmw39JaEsdXVzONxn2KraPuSeDAn+uvDI=; b=0p4sSbDK+xbwGajxOc/9NHGc3pECJbuzXz2qTm4o3nPD+bK3UfXwNOWVstRLgTD5lM W1KWojx/Z/ntmDsARJ6GVG3ZyPG3ZSem43s6PK3oplE3hM18e9BWUGaJ22QqnalSD+/J SgO8y5dlhUbs7PvVnaYHvvN4nCxD5uQfbPSrH/N4ERh2ZGXpESwBtS4rIhLtPkA+L6Pw /PtVXuiqCfY1Iiq9AynkPUGfmoAeduUGfqJ4WBBAeG+bbUaRRbzDGKrCEnZGeHjab6Qn WJx2G8P33hTyuS8Ye4sV/dWLfrlFSLuFsIW3FSZ7xFMzEtvGXTWR//ixPnk3c3uih6M5 gwGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710036344; x=1710641144; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LWN/JVLNlztmw39JaEsdXVzONxn2KraPuSeDAn+uvDI=; b=Z/2+LxBTGbGwhyLWA5gn4x8acqM4NaycsIp8dN9hrOr72F82au2JwOhHvoSgQfeDev Hx8MAABQey1o55Gtk/7xwdJMGljfVLep1L6FY3Kjf1pt55AZnEBgWobemBgHFvLYeomd tzw/BzKzhD2ZtOxF/k/T+BVE8tcblXhExcmOorUW/zhNm1aLqRkRgHT7hYBxOiNfJ9lQ ttaoV+D3kOrTnlZc4/AwdcrEvfyG2xtMSDmvJtFhiSQaR6+lQH2RkxphKEOJrDVxZlMO 4weIAJDIhXxxyoz6MStrAbhCsimfUEhuyfeQf0rH8x+a5ll8/Mn77fDzgomkO58mFJJC UBhA== X-Forwarded-Encrypted: i=1; AJvYcCUMr36n9ZhZxeOdXLEhLjwM9P+PPubm8XTpSzW7JoHdExxZXJjvqDorJ0csflUS6t1t/xEPiH36GLpkOuLQrJNFbySa+rSjgIPhkc7nSAXH X-Gm-Message-State: AOJu0YxowjOVHK+Sa/d/8DFu16oMEiyLkqMnpMEwJro8jjZ39mSo/pO0 a53nxTlE8IY5xkbvBI47y/N/0NEUzsQmtjfK3PRAYk6BsZfMFQxxI8rST939m9TQaHHJdowmrEM Nj7ImHw== X-Google-Smtp-Source: AGHT+IGdHS2QsdL4lo4wwM/5ksoTAkI5r0dtMhbFMCM7lkSFe3H0TlXafv3xzq/LQr021fLnWjD7VJ9M/wIG X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:a63d:1b65:e810:3ad3]) (user=irogers job=sendgmr) by 2002:a81:a04e:0:b0:5e6:1e40:e2e3 with SMTP id x75-20020a81a04e000000b005e61e40e2e3mr729292ywg.5.1710036344368; Sat, 09 Mar 2024 18:05:44 -0800 (PST) Date: Sat, 9 Mar 2024 18:05:00 -0800 In-Reply-To: <20240310020509.647319-1-irogers@google.com> Message-Id: <20240310020509.647319-6-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240310020509.647319-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Subject: [PATCH v1 05/13] perf expr: Tidy up header guard From: Ian Rogers To: Arnd Bergmann , Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Ian Rogers , Adrian Hunter , Paolo Bonzini , Shuah Khan , Kees Cook , "Gustavo A. R. Silva" , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Andrew Morton , Liam Howlett , Miguel Ojeda , Will Deacon , Mark Brown , David Laight , "Michael S. Tsirkin" , Shunsuke Mie , Yafang Shao , Kui-Feng Lee , James Clark , Nick Forrington , Leo Yan , German Gomez , Rob Herring , John Garry , Sean Christopherson , Anup Patel , Fuad Tabba , Andrew Jones , Chao Peng , Haibo Xu , Peter Xu , Vishal Annapurve , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-hardening@vger.kernel.org, llvm@lists.linux.dev Make the header guard reflect the name of the file and add a comment to the terminating endif. Signed-off-by: Ian Rogers --- tools/perf/util/expr.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/expr.h b/tools/perf/util/expr.h index d4166b3eb654..cd53ee7989fd 100644 --- a/tools/perf/util/expr.h +++ b/tools/perf/util/expr.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0 */ -#ifndef PARSE_CTX_H -#define PARSE_CTX_H 1 +#ifndef __PERF_EXPR_H +#define __PERF_EXPR_H 1 #include @@ -59,4 +59,4 @@ double expr__get_literal(const char *literal, const struct expr_scanner_ctx *ctx double expr__has_event(const struct expr_parse_ctx *ctx, bool compute_ids, const char *id); double expr__strcmp_cpuid_str(const struct expr_parse_ctx *ctx, bool compute_ids, const char *id); -#endif +#endif /* __PERF_EXPR_H */ From patchwork Sun Mar 10 02:05:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13587956 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 C584420DCB for ; Sun, 10 Mar 2024 02:05:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710036349; cv=none; b=SNKJCn09H/KWhdr/pvGzFl6KYIdNrjCuPm4ktlQCxfLHpp3FpeuFcDFTO78Bnw1dkVs1ihTk+vX4KDVzUghucyWw5uVEZeJpH5W3K54P862E/PTP0iWDu9xJ7yjIdOvRo8BGyFyDw8VPWsDP1WUNJ4ieivVVqrFz0Ja8lmEKGhU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710036349; c=relaxed/simple; bh=I32YjdeuPxEte3yHw53IzkVFz3QD1fvyYmVpmCiJgX0=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=VRc4M+7Kod025CgGoUX7XMokkTzKErvlZgJUz5IDdx60A1Yz9gMW9HcPVBWrfw6NtuxB2BEWtS77BghFlR7p/9kHBsVxy8nj/MjkE43NDg0f6WrDfe0EfSTrtH79MusVQrs1lJailoIvxYkgJVJ/GqyZTnh24hRLGN4j6Kr9OZA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Yr9lT8nT; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Yr9lT8nT" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-60a0151f194so40238107b3.1 for ; Sat, 09 Mar 2024 18:05:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710036347; x=1710641147; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=JkunXUX2uPJsD4ImBjWANLyZP2gzb7/4b4n3BxJNzzE=; b=Yr9lT8nT4flnIbHVDVMM+eBJx6uxDD/x6Fei9lIsf/OFxtudgFe5niqUap4uxkpmBJ NdJg6H1zNWCcD+72LOjZyUPUYgcVeP6w8WMugyXDr4b6oTkA/Iir4ST2hIa0guzAV7Di JY5SoHkpo/cZJ9cCV7lAC0cNRnzMCkU392Aqcvc7xZcZK7VPBPKFdVVKmnYOthlQCSO9 WQ6FT71i5pWYRIZs+7dcRVFoi8M3V9OPRagie2AfLoCJA/cwPgtG81ZAikEInxUZxsXR qU3zkxlUA28IzlB9dIDnjTEzcj4r3SwT9eZWH4JbhP+r25Jo7fUwPInmb4wEpoFDObPw ZvjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710036347; x=1710641147; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JkunXUX2uPJsD4ImBjWANLyZP2gzb7/4b4n3BxJNzzE=; b=OUBwiHWQXu9kzMicR6I68KT8ZtNzZOB/trMOdGr+jvqkXNeNmxf9aR5ct+r2rUMHBi 1JGwovxNhbFIei0/Xv86l0GSxvpvCOlgwQBsHy9oMrEt45c69lktWud8t22JYk4ICQGU xmRtoTuALR2v5A2k3Gu6Oc2/Bqul54dNs92eT0LSZulJcd0X8K4QFJJfwUkIStUL9vWV oWv6ruC3ezoqLKCxrQ+DtSQyOcRlGuh7cuZRvfFsZdoLKL375ohJQ81jfBKzgfzxGlbK xyyAu36oQGWFdJElxV/bNrZSv2WuE5C1U4o603+/k1/oMlY6E08RT73kql8H2RqM1Tap a40Q== X-Forwarded-Encrypted: i=1; AJvYcCW2MOEfuwWaGPibkt1wTtR4vDoS7qFYCRLgBGyEHZldW0JSr5xlkqoT6TTp6ATqmI9m0zeDa3mBjSXOhBdJX2EFd2DF1JwZhssLoc6MHhrx X-Gm-Message-State: AOJu0Yxx3dFHDXFMk3FMHNT5okoH/T94+q/jeNqidOtdHMCS8RnlWsLw ynBgHClo3O0jeMOMkTT1DE96VIKr3eN5LgZztaut4NGxwPuK4YxI7SYoJE3Y5n6KgcAgEKIaJCO vSjPDUQ== X-Google-Smtp-Source: AGHT+IHC63LoVrlmn41wG0ObqneUHLqshrWIHBHCNg+aleXCyzso595+j1kkp1p9OAmoHd0xeF3N4e9YCjv3 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:a63d:1b65:e810:3ad3]) (user=irogers job=sendgmr) by 2002:a81:83d1:0:b0:609:f088:cf9c with SMTP id t200-20020a8183d1000000b00609f088cf9cmr962327ywf.1.1710036346612; Sat, 09 Mar 2024 18:05:46 -0800 (PST) Date: Sat, 9 Mar 2024 18:05:01 -0800 In-Reply-To: <20240310020509.647319-1-irogers@google.com> Message-Id: <20240310020509.647319-7-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240310020509.647319-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Subject: [PATCH v1 06/13] perf debug: Add missing linux/types.h include From: Ian Rogers To: Arnd Bergmann , Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Ian Rogers , Adrian Hunter , Paolo Bonzini , Shuah Khan , Kees Cook , "Gustavo A. R. Silva" , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Andrew Morton , Liam Howlett , Miguel Ojeda , Will Deacon , Mark Brown , David Laight , "Michael S. Tsirkin" , Shunsuke Mie , Yafang Shao , Kui-Feng Lee , James Clark , Nick Forrington , Leo Yan , German Gomez , Rob Herring , John Garry , Sean Christopherson , Anup Patel , Fuad Tabba , Andrew Jones , Chao Peng , Haibo Xu , Peter Xu , Vishal Annapurve , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-hardening@vger.kernel.org, llvm@lists.linux.dev u64 is used in this header for eprintf_time and so linux/types.h is necessary. Add to avoid compilation errors that aren't currently seen due to transitive dependencies. Signed-off-by: Ian Rogers --- tools/perf/util/debug.h | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/perf/util/debug.h b/tools/perf/util/debug.h index 35a7a5ae762e..4160e633311d 100644 --- a/tools/perf/util/debug.h +++ b/tools/perf/util/debug.h @@ -7,6 +7,7 @@ #include #include #include +#include extern int verbose; extern int debug_kmaps; From patchwork Sun Mar 10 02:05:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13587957 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 3B2B227471 for ; Sun, 10 Mar 2024 02:05:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710036351; cv=none; b=axCBPxcCPG8QwT0jhygPr41rvxceI6C4w5wOn+CsWkOcTwMzEhA3p3enLZqa7rH0ZLO/lEYHdlAv9GFfv1KD+fbJL0CIQrJ+nkliScCOHzddTY8bCzG2gW2YeuSVDym8en/5GO4CXxBoKOCFk0oAqbBp+rQbJid6Qg1TeL7WnKk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710036351; c=relaxed/simple; bh=gXS4/PmUcr/u98E5bD8fZ0t4D/xMUtOLNVIZOZ/mooI=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=OBdRUnrwuwL0XREPPQtpERZ7Nb1Z82ZIywV+RiGTQWRywGfd7kE4kM8/nJuIOLIzyELEH2/1gq46dzZO+0+pxacYDRClju6lirp1J/nGEV8er0BApZTfn01hpMS9wvUimBu+5GJrAstEMXHgPc0Td45CjcwRny6UUlX225/maRM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=4RRJfEVF; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="4RRJfEVF" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dced704f17cso5578996276.1 for ; Sat, 09 Mar 2024 18:05:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710036349; x=1710641149; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=vgONc26lvm/9ZOmPonAKLBWVK7kvQvvNgc4EWpL/eBk=; b=4RRJfEVFPtrJeHkpe6FwktJhu6hedW8U/v/FPR5lEZLhqQphPs7rfv16DpEvOLsq3p uJY87zLQNSikrSGbJjnZmvv3SXwvszzrcdKMS+PKtWJIUZtpzl7R0QEuJARFoL8xscwU rLXoSBMrzfFNivUw+I2NtMiETimmNkJd6cd7MXkpMcOn3sAm3xhnGlM7JJ0agY8uLr+f aziq4Fo6IxHBXY0idncI9OQeKuvL/Oh585fTQgef3OOR+7L7BZeWsnsPOiZaR5WeSN0K OthKQCtrXWr5CHwo2KSZJcHxH72A5++tGB32b3HTV7eIH7HP5uHRbMBhpcBc9t59/bku QaZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710036349; x=1710641149; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=vgONc26lvm/9ZOmPonAKLBWVK7kvQvvNgc4EWpL/eBk=; b=ueyyc0uHHKadomLC6HRCv6+m6H8GPCgy9Qc2mJMzAIrMgrFZsqj89chz7tF/0HJXBq 1N1p0pLWw1DfckURmE7qRIHQnO7/6xRY7oZuOy/8wUCxHf5V9M7/Ob3wPzuKtgtvk4f3 hYa9DLni6l/1FuBW3Z5LnFOpGLW+ks2mjExuqTgt9q2hS3v2TAQFerxBhmKIw111uain TwePMd/VASmmlX/tA6uiPkpX3syd9ScK867KWXL1UaToiUjxDcVuPGxNQRijoLCby6uD dndW8zC5mz8mIVGMME11KcRcGwDVwQRVbBQcPYsVYLLOF4PxvADyR1VGTpLSPzhErhyo yGaA== X-Forwarded-Encrypted: i=1; AJvYcCVzG26vi2H/e8vHPU/5Tiw19u7w7veTjjRTkK+96dzsBqvCBaMrp8BDYVr32PcAGtalS0VhGNjftkVCp+Ufrqfw9G8O4HHW+AGU2FKBVRko X-Gm-Message-State: AOJu0YwGjn5b6n83e4JZDo5PmdaAXj4EXrjjnGLQUnPyaRFwCVShrUEK z+3iwx4rFYgU/SQc9fLuqk9eRQZEu3q2bsjNBdsaxby0frNuW5pBk0olLRLcOEHvC/xO+iPF7hZ i+3Iulg== X-Google-Smtp-Source: AGHT+IEHSaymlJ72bm2wFBwRFlyvHmM501SMsBRHMdMGbeCTQVSAZx2WeXRxeWUBMJJSsrdAYYWs4TJGUV9K X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:a63d:1b65:e810:3ad3]) (user=irogers job=sendgmr) by 2002:a25:ab6f:0:b0:dcd:3a37:65 with SMTP id u102-20020a25ab6f000000b00dcd3a370065mr144117ybi.7.1710036348960; Sat, 09 Mar 2024 18:05:48 -0800 (PST) Date: Sat, 9 Mar 2024 18:05:02 -0800 In-Reply-To: <20240310020509.647319-1-irogers@google.com> Message-Id: <20240310020509.647319-8-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240310020509.647319-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Subject: [PATCH v1 07/13] perf cacheline: Add missing linux/types.h include From: Ian Rogers To: Arnd Bergmann , Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Ian Rogers , Adrian Hunter , Paolo Bonzini , Shuah Khan , Kees Cook , "Gustavo A. R. Silva" , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Andrew Morton , Liam Howlett , Miguel Ojeda , Will Deacon , Mark Brown , David Laight , "Michael S. Tsirkin" , Shunsuke Mie , Yafang Shao , Kui-Feng Lee , James Clark , Nick Forrington , Leo Yan , German Gomez , Rob Herring , John Garry , Sean Christopherson , Anup Patel , Fuad Tabba , Andrew Jones , Chao Peng , Haibo Xu , Peter Xu , Vishal Annapurve , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-hardening@vger.kernel.org, llvm@lists.linux.dev u64 is used in this header for cl_address and cl_offset, so linux/types.h is necessary. Add to avoid compilation errors that aren't currently seen due to transitive dependencies. Signed-off-by: Ian Rogers --- tools/perf/util/cacheline.h | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/perf/util/cacheline.h b/tools/perf/util/cacheline.h index fe6d5b60a031..50b77129e1a4 100644 --- a/tools/perf/util/cacheline.h +++ b/tools/perf/util/cacheline.h @@ -3,6 +3,7 @@ #define PERF_CACHELINE_H #include +#include int __pure cacheline_size(void); From patchwork Sun Mar 10 02:05:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13587958 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 585632BAEA for ; Sun, 10 Mar 2024 02:05:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710036354; cv=none; b=kdztI6EaLTAH4SQEyYrdpHT+gkZXWNtQuFEElohyV7UktbovoEzpvBxOCCrTNhF8F0JogcFdz6d0YgVuH3dimPaEB2ZiR2xp75RoJPsNyDGw7wu9Mib46bMzoyZUz82Fuo754l6pFVP/l+QzTRRZ4Fya2mkuxl/fP2nTPzIS+bE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710036354; c=relaxed/simple; bh=nyI9dgaoU2HMw/TgIDnIDYrLQif8D0L3I6qaHvxp6Ug=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=s5T2jCP5y4z3koDbB3DpKXqkfXuh2Bcx0kJAVSbXq65v5xULlilq1GE/7vL8WFJW1bbKjK9Iq6Lut11LIxrNmTUh3vH3Ti/xvkFTxjL5rcNyCH08W8SAkS8MYZ2jdJInWgu+iV+vTWl8vXHNvnv2HWAO3Iv4OG/vQf+gEQbtqYo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=wez/FaFs; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="wez/FaFs" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-609ff3206c3so40643897b3.2 for ; Sat, 09 Mar 2024 18:05:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710036351; x=1710641151; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=/s3J+Sp6Nwm5vYKq4/rEI+V8C3zBszpK/wcDil3Uhsk=; b=wez/FaFsRjHRkv0PxDcesvwFad++DgjbL5QV9cfERctSQJoTj2UXGQ9UA0SVyrBMS1 MmWpxfWDlUlmdFQZzAEfEc9cequA/fJUA24J4wmP1XJuT86NqcIMF3zamj22F9LCMRB2 2ZcKcGrrMeu8Ya8Icq9g9DKOhaG/tIwJ17Qjsw46RzsTNDBEkfF//4FHu1n0YJxEgIbx 41qP3ACy74XDqDuHmaSaQOMGeDw20pQSVKcAD4QAAalvxoCkw4TvMsv/sgdx2Hl3rQYa UX70j7T0A8KWX512RuVd3u3LTJvu/rcq5dYIpQYApfjWtnlGgWDhMvKiMDR08SBCjXeC U2Wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710036351; x=1710641151; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/s3J+Sp6Nwm5vYKq4/rEI+V8C3zBszpK/wcDil3Uhsk=; b=rLH7lVH4MHRYxjh3XD7wJh7jl4LnuyAgODOsNUkywzmV+rhOcoIMF3VTqMEboN/tBD PNZJnSW4QDVcPlj4RiKrw6a08mAk930wdtqyfSK7qIcUI2dVO10Y/l5dXZPid9qCELMO SEf/2+yHMouFvOjBUh8mzXxUcIXcfqQXpzqeLnG4w6WO1OTGtdApJ5a0+Svd5NomkucX X1e31HMnKO72lE9H9X+2iI9CfffYre6SRaJS+iX8b0Er8Q5NnLhrUwdZFwa17G39akNS T92SM2E/t6o5LQt+Sjd8PbrESqtgJUjA9z/r0mH4Zlro6vMpu9u219q3ckK83+j5wCvW 41YA== X-Forwarded-Encrypted: i=1; AJvYcCUoiu936PCRqrN53QPTxQENja4x1Get5jG06SBvkyjLc3nM7Z8es+pzDOoA276QnbqSti6gKKTGxmUqgOpPBTX++gPToEmxomEVK2pCrRbg X-Gm-Message-State: AOJu0YxKVSlsNNcfg6e2BddRDAWTDd7gPLBOGeU3gEQYLk0tJN0Um1Dg oaN6zWzxVbhbq262eCtA7yYSbdJ27bL+qH2kck26SIwixklao8mXlJtIw1YZH7Y2TQDathSQe+M +z9WRBA== X-Google-Smtp-Source: AGHT+IHPD3AdhB6c0T/TfiXMF4uI00y32OTKxm5DEXBOiPnGnfJTzAmtckpif5kyd4Qr/BOAcbdh5KWG2LgR X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:a63d:1b65:e810:3ad3]) (user=irogers job=sendgmr) by 2002:a0d:dd04:0:b0:60a:25ce:c165 with SMTP id g4-20020a0ddd04000000b0060a25cec165mr362319ywe.6.1710036351589; Sat, 09 Mar 2024 18:05:51 -0800 (PST) Date: Sat, 9 Mar 2024 18:05:03 -0800 In-Reply-To: <20240310020509.647319-1-irogers@google.com> Message-Id: <20240310020509.647319-9-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240310020509.647319-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Subject: [PATCH v1 08/13] perf arm-spe: Add missing linux/types.h include From: Ian Rogers To: Arnd Bergmann , Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Ian Rogers , Adrian Hunter , Paolo Bonzini , Shuah Khan , Kees Cook , "Gustavo A. R. Silva" , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Andrew Morton , Liam Howlett , Miguel Ojeda , Will Deacon , Mark Brown , David Laight , "Michael S. Tsirkin" , Shunsuke Mie , Yafang Shao , Kui-Feng Lee , James Clark , Nick Forrington , Leo Yan , German Gomez , Rob Herring , John Garry , Sean Christopherson , Anup Patel , Fuad Tabba , Andrew Jones , Chao Peng , Haibo Xu , Peter Xu , Vishal Annapurve , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-hardening@vger.kernel.org, llvm@lists.linux.dev u64 is used for various structs in arm-spe-decoder.h, while uint64_t is used in arm-spe-pkt-decoder.h. Avoid transitive dependencies bringing in linux/types.h and directly depend upon it in arm-spe-decoder.h. Fix arm-spe-decoder.c to use uint64_t, as the header file does. Signed-off-by: Ian Rogers --- tools/perf/util/arm-spe-decoder/arm-spe-decoder.h | 1 + tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/arm-spe-decoder/arm-spe-decoder.h b/tools/perf/util/arm-spe-decoder/arm-spe-decoder.h index 1443c28545a9..da5c5816c948 100644 --- a/tools/perf/util/arm-spe-decoder/arm-spe-decoder.h +++ b/tools/perf/util/arm-spe-decoder/arm-spe-decoder.h @@ -10,6 +10,7 @@ #include #include #include +#include #include "arm-spe-pkt-decoder.h" diff --git a/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c b/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c index a454c6737563..e035f49f28ad 100644 --- a/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c +++ b/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c @@ -292,7 +292,7 @@ static int arm_spe_pkt_out_string(int *err, char **buf_p, size_t *blen, static int arm_spe_pkt_desc_event(const struct arm_spe_pkt *packet, char *buf, size_t buf_len) { - u64 payload = packet->payload; + uint64_t payload = packet->payload; int err = 0; arm_spe_pkt_out_string(&err, &buf, &buf_len, "EV"); @@ -332,7 +332,7 @@ static int arm_spe_pkt_desc_event(const struct arm_spe_pkt *packet, static int arm_spe_pkt_desc_op_type(const struct arm_spe_pkt *packet, char *buf, size_t buf_len) { - u64 payload = packet->payload; + uint64_t payload = packet->payload; int err = 0; switch (packet->index) { @@ -429,7 +429,7 @@ static int arm_spe_pkt_desc_addr(const struct arm_spe_pkt *packet, { int ns, el, idx = packet->index; int ch, pat; - u64 payload = packet->payload; + uint64_t payload = packet->payload; int err = 0; static const char *idx_name[] = {"PC", "TGT", "VA", "PA", "PBT"}; @@ -469,7 +469,7 @@ static int arm_spe_pkt_desc_addr(const struct arm_spe_pkt *packet, static int arm_spe_pkt_desc_counter(const struct arm_spe_pkt *packet, char *buf, size_t buf_len) { - u64 payload = packet->payload; + uint64_t payload = packet->payload; const char *name = arm_spe_pkt_name(packet->type); int err = 0; From patchwork Sun Mar 10 02:05:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13587959 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 23AFA37719 for ; Sun, 10 Mar 2024 02:05:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710036357; cv=none; b=W6R4bWRvKph4V0ZCy8oI4F0HUPIXNEQPPSD8AnaxjQDEoqh7hWNdYBtZW082tNzAeeBvScdlKq4nL1SSNzYYMTxy4uaAEGUSAM8QuNYx0jZwUrIeISS9Cqj05TlXSl5V5AjbEApeOciwbuQ2o+pw4EhvRaTXH//5ZiazK4K030c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710036357; c=relaxed/simple; bh=Fq4lcFad9HT9JmjkJEm98VVUDFCHd+jm9iRP80ik0Qk=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=aa3NnH4BSyhXl02hSxtq7kBuiTk1hBAz+wWV30exSLDlb7H3Xm1gopirwyJ0oOOguti1tFcSXGJU82ZDanJkzP/qqFOlF0adu+Z9GLozIJhgNc/illTGr28wCtekfUScVUPxAO7Bq17LC8oex8XTVDXtRZVe937fRA53FnamVwU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Et8oLd0U; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Et8oLd0U" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dd0ae66422fso6702852276.0 for ; Sat, 09 Mar 2024 18:05:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710036354; x=1710641154; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=EfWQCgRQvC61dW45rBVZGuz4IKfn5r36xpIYwQ99OM0=; b=Et8oLd0Uuwwe4+7kI3T6ViWYA6cGKXI7GR4TrQvRkiTDQYe/9R5M+ZfD2kWjDZvRbh X9CZYfs9El9ORL0q4RbfIWLW0QB4VriOmBvSW5cm9KsvKdimt3+rxA+ILZyat14alDI+ kdBPW1hPBca7cHrzJeFFsZ47zB3LuwqJjoGY+xMp1SFZIACbxh+P9x4u6vGiqqs2UKnn Tm2EscMTADk8ui3t0JiF0wxcs0P9EvfiH/VoRFLrT4dm6T4pbP+WZf+FPL0m/lZe0Utc JT6jgNebAvTjy9xU8z4MQmxi5+4xZ4dh461NZ30LZ76+3AXvAOpZcEsV6kOiWkuUhk4Z 1dvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710036354; x=1710641154; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=EfWQCgRQvC61dW45rBVZGuz4IKfn5r36xpIYwQ99OM0=; b=pc37GU6Djx9yUsarQGjgZSF8FPlfE6Wz4x7rypLDBjHdx0ECuso4iSfhsIW46lqQbe L8HNU1YCj6Qc7YcBaZsfLZ276kPuk7d0Qtt3kM1esBaLjuBW7WQocOEWSJPrq9BACnJL ghdwzktNDnG/efWmsqx87neIWLqlZQInpmz04eXsifSFK9ZftCv1PYnADjbqePZdnk1C 1loQhVHZgyI8mvmD3CO6SoftWI5M8pLBvsTeifHUiAt6PrJE+cmfJEk7tedWgqsqi3S7 zh15Qyc14r87rZJHeH8ytPoKTn8FhQTsMaCzVbft0hkNxGUAgBmsWn4wX+PshoKOJImZ Qxgw== X-Forwarded-Encrypted: i=1; AJvYcCVIpu6kVQ3F/IAtgnJamYs3MEdSNHmir6HA7qMQpoXBahkOLkFaVcLRYmKVebUXiyuzdsqIa9M6l1j8sySbg1/K4x6HFietQiB8KfJvF07K X-Gm-Message-State: AOJu0YwvNkNHRj3lVggi/qnqw4OWc+cbeb1021QHS2F2HcvMrqckM5NE bBH00w7LMa3KZ+FOB3Aye90PK0Z3SYblbVLoEtFd0nVLZH2YUE8B4i2z8aH/NDJCYheCdFAYLy3 aJ5NOIQ== X-Google-Smtp-Source: AGHT+IEbgF9/L10MqEQsfT/YgldjotiYAys6nVxOfaOObgpu5qrtCsaN68T0Sw/VHfW+vmC7K4OzTmNsXC8h X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:a63d:1b65:e810:3ad3]) (user=irogers job=sendgmr) by 2002:a05:6902:10c2:b0:dbd:b4e8:1565 with SMTP id w2-20020a05690210c200b00dbdb4e81565mr1091906ybu.4.1710036354130; Sat, 09 Mar 2024 18:05:54 -0800 (PST) Date: Sat, 9 Mar 2024 18:05:04 -0800 In-Reply-To: <20240310020509.647319-1-irogers@google.com> Message-Id: <20240310020509.647319-10-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240310020509.647319-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Subject: [PATCH v1 09/13] tools headers: Rewrite linux/atomic.h using C11's stdatomic.h From: Ian Rogers To: Arnd Bergmann , Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Ian Rogers , Adrian Hunter , Paolo Bonzini , Shuah Khan , Kees Cook , "Gustavo A. R. Silva" , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Andrew Morton , Liam Howlett , Miguel Ojeda , Will Deacon , Mark Brown , David Laight , "Michael S. Tsirkin" , Shunsuke Mie , Yafang Shao , Kui-Feng Lee , James Clark , Nick Forrington , Leo Yan , German Gomez , Rob Herring , John Garry , Sean Christopherson , Anup Patel , Fuad Tabba , Andrew Jones , Chao Peng , Haibo Xu , Peter Xu , Vishal Annapurve , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-hardening@vger.kernel.org, llvm@lists.linux.dev Code in tools tries to follow the patterns of the kernel, so the atomic functions names match. However, having include/linux/atomic.h in tools complicates building code in tools as assembly and other functions are necessary - these are often configured in the kernel using CONFIG options. As tools C code is compiled with the -std=gnu11 flag, it is possible to use stdatomic.h and move the build and other complications to the compiler/libc. Signed-off-by: Ian Rogers --- tools/arch/x86/include/asm/atomic.h | 84 -------------- tools/include/asm-generic/atomic-gcc.h | 95 ---------------- tools/include/asm/atomic.h | 11 -- tools/include/linux/atomic.h | 107 ++++++++++++++++-- tools/include/linux/types.h | 15 ++- .../selftests/kvm/include/kvm_util_base.h | 3 +- 6 files changed, 110 insertions(+), 205 deletions(-) delete mode 100644 tools/arch/x86/include/asm/atomic.h delete mode 100644 tools/include/asm-generic/atomic-gcc.h delete mode 100644 tools/include/asm/atomic.h diff --git a/tools/arch/x86/include/asm/atomic.h b/tools/arch/x86/include/asm/atomic.h deleted file mode 100644 index 365cf182df12..000000000000 --- a/tools/arch/x86/include/asm/atomic.h +++ /dev/null @@ -1,84 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _TOOLS_LINUX_ASM_X86_ATOMIC_H -#define _TOOLS_LINUX_ASM_X86_ATOMIC_H - -#include -#include -#include "rmwcc.h" - -#define LOCK_PREFIX "\n\tlock; " - -#include -#include - -/* - * Atomic operations that C can't guarantee us. Useful for - * resource counting etc.. - */ - -#define ATOMIC_INIT(i) { (i) } - -/** - * atomic_read - read atomic variable - * @v: pointer of type atomic_t - * - * Atomically reads the value of @v. - */ -static inline int atomic_read(const atomic_t *v) -{ - return READ_ONCE((v)->counter); -} - -/** - * atomic_set - set atomic variable - * @v: pointer of type atomic_t - * @i: required value - * - * Atomically sets the value of @v to @i. - */ -static inline void atomic_set(atomic_t *v, int i) -{ - v->counter = i; -} - -/** - * atomic_inc - increment atomic variable - * @v: pointer of type atomic_t - * - * Atomically increments @v by 1. - */ -static inline void atomic_inc(atomic_t *v) -{ - asm volatile(LOCK_PREFIX "incl %0" - : "+m" (v->counter)); -} - -/** - * atomic_dec_and_test - decrement and test - * @v: pointer of type atomic_t - * - * Atomically decrements @v by 1 and - * returns true if the result is 0, or false for all other - * cases. - */ -static inline int atomic_dec_and_test(atomic_t *v) -{ - GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e"); -} - -static __always_inline int atomic_cmpxchg(atomic_t *v, int old, int new) -{ - return cmpxchg(&v->counter, old, new); -} - -static inline int test_and_set_bit(long nr, unsigned long *addr) -{ - GEN_BINARY_RMWcc(LOCK_PREFIX __ASM_SIZE(bts), *addr, "Ir", nr, "%0", "c"); -} - -static inline int test_and_clear_bit(long nr, unsigned long *addr) -{ - GEN_BINARY_RMWcc(LOCK_PREFIX __ASM_SIZE(btc), *addr, "Ir", nr, "%0", "c"); -} - -#endif /* _TOOLS_LINUX_ASM_X86_ATOMIC_H */ diff --git a/tools/include/asm-generic/atomic-gcc.h b/tools/include/asm-generic/atomic-gcc.h deleted file mode 100644 index 9b3c528bab92..000000000000 --- a/tools/include/asm-generic/atomic-gcc.h +++ /dev/null @@ -1,95 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef __TOOLS_ASM_GENERIC_ATOMIC_H -#define __TOOLS_ASM_GENERIC_ATOMIC_H - -#include -#include -#include - -/* - * Atomic operations that C can't guarantee us. Useful for - * resource counting etc.. - * - * Excerpts obtained from the Linux kernel sources. - */ - -#define ATOMIC_INIT(i) { (i) } - -/** - * atomic_read - read atomic variable - * @v: pointer of type atomic_t - * - * Atomically reads the value of @v. - */ -static inline int atomic_read(const atomic_t *v) -{ - return READ_ONCE((v)->counter); -} - -/** - * atomic_set - set atomic variable - * @v: pointer of type atomic_t - * @i: required value - * - * Atomically sets the value of @v to @i. - */ -static inline void atomic_set(atomic_t *v, int i) -{ - v->counter = i; -} - -/** - * atomic_inc - increment atomic variable - * @v: pointer of type atomic_t - * - * Atomically increments @v by 1. - */ -static inline void atomic_inc(atomic_t *v) -{ - __sync_add_and_fetch(&v->counter, 1); -} - -/** - * atomic_dec_and_test - decrement and test - * @v: pointer of type atomic_t - * - * Atomically decrements @v by 1 and - * returns true if the result is 0, or false for all other - * cases. - */ -static inline int atomic_dec_and_test(atomic_t *v) -{ - return __sync_sub_and_fetch(&v->counter, 1) == 0; -} - -#define cmpxchg(ptr, oldval, newval) \ - __sync_val_compare_and_swap(ptr, oldval, newval) - -static inline int atomic_cmpxchg(atomic_t *v, int oldval, int newval) -{ - return cmpxchg(&(v)->counter, oldval, newval); -} - -static inline int test_and_set_bit(long nr, unsigned long *addr) -{ - unsigned long mask = BIT_MASK(nr); - long old; - - addr += BIT_WORD(nr); - - old = __sync_fetch_and_or(addr, mask); - return !!(old & mask); -} - -static inline int test_and_clear_bit(long nr, unsigned long *addr) -{ - unsigned long mask = BIT_MASK(nr); - long old; - - addr += BIT_WORD(nr); - - old = __sync_fetch_and_and(addr, ~mask); - return !!(old & mask); -} - -#endif /* __TOOLS_ASM_GENERIC_ATOMIC_H */ diff --git a/tools/include/asm/atomic.h b/tools/include/asm/atomic.h deleted file mode 100644 index 8c9bfffd4191..000000000000 --- a/tools/include/asm/atomic.h +++ /dev/null @@ -1,11 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef __TOOLS_LINUX_ASM_ATOMIC_H -#define __TOOLS_LINUX_ASM_ATOMIC_H - -#if defined(__i386__) || defined(__x86_64__) -#include "../../arch/x86/include/asm/atomic.h" -#else -#include -#endif - -#endif /* __TOOLS_LINUX_ASM_ATOMIC_H */ diff --git a/tools/include/linux/atomic.h b/tools/include/linux/atomic.h index 01907b33537e..2cf4791ddd5d 100644 --- a/tools/include/linux/atomic.h +++ b/tools/include/linux/atomic.h @@ -2,14 +2,107 @@ #ifndef __TOOLS_LINUX_ATOMIC_H #define __TOOLS_LINUX_ATOMIC_H -#include +#include +#include // For atomic_t -void atomic_long_set(atomic_long_t *v, long i); +/* + * Reimplementation of the kernel's atomic.h using C11's stdatomic.h to avoid + * build logic around compilers, inline assembler, etc. + */ -/* atomic_cmpxchg_relaxed */ -#ifndef atomic_cmpxchg_relaxed -#define atomic_cmpxchg_relaxed atomic_cmpxchg -#define atomic_cmpxchg_release atomic_cmpxchg -#endif /* atomic_cmpxchg_relaxed */ +#define ATOMIC_OP(op, c_op) \ +static inline void generic_atomic_##op(int i, atomic_t *v) \ +{ \ + atomic_fetch_##op(v, i); \ +} + +#define ATOMIC_OP_RETURN(op, c_op) \ +static inline int generic_atomic_##op##_return(int i, atomic_t *v) \ +{ \ + int c = atomic_fetch_##op(v, i); \ + \ + return c c_op i; \ +} + +#define ATOMIC_FETCH_OP(op, c_op) \ +static inline int generic_atomic_fetch_##op(int i, atomic_t *v) \ +{ \ + return atomic_fetch_##op(v, i); \ +} + +static inline int generic_atomic_read(const atomic_t *v) +{ + return atomic_load(v); +} + +static inline void generic_atomic_set(atomic_t *v, int i) +{ + atomic_store(v, i); +} + +static inline int generic_atomic_cmpxchg_relaxed(atomic_t *v, int old, int new) +{ + int expected = old; + + atomic_compare_exchange_weak_explicit(v, &expected, new, + memory_order_relaxed, memory_order_relaxed); + return expected; +} + +static inline int generic_atomic_cmpxchg_release(atomic_t *v, int old, int new) +{ + int expected = old; + + /* + * Note, the stricter memory_order_seq_cst is used as + * memory_order_release fails with an invalid-memory-model error. + */ + atomic_compare_exchange_weak_explicit(v, &expected, new, + memory_order_seq_cst, memory_order_seq_cst); + return expected; +} + +ATOMIC_OP_RETURN(add, +) +ATOMIC_OP_RETURN(sub, -) + +ATOMIC_FETCH_OP(add, +) +ATOMIC_FETCH_OP(sub, -) +ATOMIC_FETCH_OP(and, &) +ATOMIC_FETCH_OP(or, |) +ATOMIC_FETCH_OP(xor, ^) + +ATOMIC_OP(add, +) +ATOMIC_OP(sub, -) +ATOMIC_OP(and, &) +ATOMIC_OP(or, |) +ATOMIC_OP(xor, ^) + +#undef ATOMIC_FETCH_OP +#undef ATOMIC_OP_RETURN +#undef ATOMIC_OP + +#define arch_atomic_add_return generic_atomic_add_return +#define arch_atomic_sub_return generic_atomic_sub_return + +#define arch_atomic_fetch_add generic_atomic_fetch_add +#define arch_atomic_fetch_sub generic_atomic_fetch_sub +#define arch_atomic_fetch_and generic_atomic_fetch_and +#define arch_atomic_fetch_or generic_atomic_fetch_or +#define arch_atomic_fetch_xor generic_atomic_fetch_xor + +#define arch_atomic_add generic_atomic_add +#define arch_atomic_sub generic_atomic_sub +#define arch_atomic_and generic_atomic_and +#define arch_atomic_or generic_atomic_or +#define arch_atomic_xor generic_atomic_xor + +#define arch_atomic_read(v) generic_atomic_read(v) +#define arch_atomic_set(v, i) generic_atomic_set(v, i) +#define atomic_set(v, i) generic_atomic_set(v, i) +#define atomic_read(v) generic_atomic_read(v) +#define atomic_cmpxchg_relaxed(v, o, n) generic_atomic_cmpxchg_relaxed(v, o, n) +#define atomic_cmpxchg_release(v, o, n) generic_atomic_cmpxchg_release(v, o, n) +#define atomic_inc(v) generic_atomic_add(1, v) +#define atomic_dec(v) generic_atomic_sub(1, v) #endif /* __TOOLS_LINUX_ATOMIC_H */ diff --git a/tools/include/linux/types.h b/tools/include/linux/types.h index 8519386acd23..cb1f44f1ed5e 100644 --- a/tools/include/linux/types.h +++ b/tools/include/linux/types.h @@ -74,13 +74,16 @@ typedef u64 phys_addr_t; typedef u32 phys_addr_t; #endif -typedef struct { - int counter; -} atomic_t; +#ifndef __cplusplus +/* C++17 doesn't support stdatomic.h but C++23 does. */ +#include -typedef struct { - long counter; -} atomic_long_t; +typedef atomic_int atomic_t; + +#define ATOMIC_INIT(i) (i) + +typedef atomic_long atomic_long_t; +#endif #ifndef __aligned_u64 # define __aligned_u64 __u64 __attribute__((aligned(8))) diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h index 9e5afc472c14..7c81da425abc 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -9,6 +9,7 @@ #include "test_util.h" +#include #include #include "linux/hashtable.h" #include "linux/list.h" @@ -17,8 +18,6 @@ #include "linux/rbtree.h" #include -#include - #include #include "sparsebit.h" From patchwork Sun Mar 10 02:05:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13587960 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 A70CD39847 for ; Sun, 10 Mar 2024 02:05:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710036360; cv=none; b=XPlBuTbPq4q3+R8X/aKhh8IUnkH4n1QtCmr80g6RPpAw9Bcrk3QwlAh3Nt2KN1gPR2R7l5wMOct73iUK6bu67kopMHaKsjrvdc4bLC1H4p5GqvFNHDvUNqdbr1xdoUQC5H7h3Mq/f4yDHIUbxwF5eHI4cAwCwKXAwIZvtPZ5PFc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710036360; c=relaxed/simple; bh=ZWL6CpbSDkoHT9bHTSvzN2HvMNxtU4EmDh1g2wTW1tQ=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=JzUPnJSWF5wGOZQxQc1qOK/8XnjIc0a1UQRM0SZ6UJ3OKQ96WBBIbzbi2l3olKwZltCpNQWatqGFrzzfit1uFjuHhlf1DSD7uYd5zbdzJcncGfClAwqNk2P93l4LRUcY8QU+JwD7x3ADw7MUvTnH6gpYqITP2CFYoOgonQp65z4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=LlVbaPzg; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="LlVbaPzg" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc6b267bf11so2361889276.2 for ; Sat, 09 Mar 2024 18:05:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710036357; x=1710641157; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=YcbTXn+GZg98Vv/BPAp4vRUPCLHW4NXMPZPsnrVHKvg=; b=LlVbaPzg3SZLzeFq+0upg5FmL3naDuQtNeVRRATjaVIr2Ao293gZStjMay0I88luJb REZWEdtqNVjNwvVaG85n0qI61sVPKbW71X5dQN4+gbn7LnuOkPQsUhzejb/2OF2y6b13 G7KKYmjBXkkujaU+hIErFoa0+02M3n4FD+uhgeaOZtQVLT4NjD4xAK1VcIR7DWWwdFP6 tOqhUI//yL8wD8dNPA6Q9gXmA5Xkc+LXyrE2mrZ+3M9kQm0LEN8W70xqqiVI/uaArFXI h5jGKEiwZOhtgM4DmUMMXktvWALZTepJakcPvqdRTTHbDTMQ1+lUtXQXtOkyznvsVOIl 07/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710036357; x=1710641157; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=YcbTXn+GZg98Vv/BPAp4vRUPCLHW4NXMPZPsnrVHKvg=; b=rugF8bPnzFXGdTs1+W+CAdw8cRCRblfPfaTuNbxlkt4lHp7JJ3AWv24msCHPcso6gl HOOmK53nPpNsseCu0c0+SUvf3qIKwi73UJ6JWIP8bCYoYZFBZbJZiqIRlxb/WpYpDnJ/ JAzhbtvJXKyHVEytcf6Y6NWDv23DawQVIXzvxo73n7mreOQQS6zN+eRiHkI0MD2I+wEq QVR9GRD667V+y9y+BxZkisdaicsWk3zOpYrTYu8wbxMGl2uY2s7EXzJNvLKLzyAN/j5x r8KROimmDdrErrso0kgMZ9nDBCja1abUau3Jjdoc8huxL0SU4JSerC5V7gwMw42GazjR RY5A== X-Forwarded-Encrypted: i=1; AJvYcCXv00noWxQfDTyLqJRfiDRCUsQCMCqXcJ9l++tzph626ZXH7Ts6G/yRHeyE9HmPbNGk1rJoYzSNR9P2tvLuNG30Nk2kSr1LaFSCllAWQl+I X-Gm-Message-State: AOJu0YyMj1QpcoAdSJ705lpzkCv8GN6uveb6X2Eirl23OlUZYkwoR5iM 8ttCfkhlptX6w6GhmAGalQhLzmqLn5CyPnsh81ZsE8JaAlT99L6NZ45w7Wh6IDlqYalUQ26m5YS LvcC7TA== X-Google-Smtp-Source: AGHT+IFh+Pg/vPJRzp3HY0EtlqFR8c7TCYxcMdD2zR5o/IcNrp2JWb8OldTiph3/7rY2TpwrRD4D5cJe7AWq X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:a63d:1b65:e810:3ad3]) (user=irogers job=sendgmr) by 2002:a05:6902:b06:b0:dc6:b982:cfa2 with SMTP id ch6-20020a0569020b0600b00dc6b982cfa2mr183760ybb.8.1710036356770; Sat, 09 Mar 2024 18:05:56 -0800 (PST) Date: Sat, 9 Mar 2024 18:05:05 -0800 In-Reply-To: <20240310020509.647319-1-irogers@google.com> Message-Id: <20240310020509.647319-11-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240310020509.647319-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Subject: [PATCH v1 10/13] asm-generic: Avoid transitive dependency for unaligned.h From: Ian Rogers To: Arnd Bergmann , Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Ian Rogers , Adrian Hunter , Paolo Bonzini , Shuah Khan , Kees Cook , "Gustavo A. R. Silva" , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Andrew Morton , Liam Howlett , Miguel Ojeda , Will Deacon , Mark Brown , David Laight , "Michael S. Tsirkin" , Shunsuke Mie , Yafang Shao , Kui-Feng Lee , James Clark , Nick Forrington , Leo Yan , German Gomez , Rob Herring , John Garry , Sean Christopherson , Anup Patel , Fuad Tabba , Andrew Jones , Chao Peng , Haibo Xu , Peter Xu , Vishal Annapurve , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-hardening@vger.kernel.org, llvm@lists.linux.dev unaligned.h uses types from linux/types.h such as u64, but doesn't directly import linux/types.h. This can cause breakages when the declarations of the types is reliant on a transitive dependency and the dependencies change. Add the missing header file to avoid this. Signed-off-by: Ian Rogers --- include/asm-generic/unaligned.h | 2 ++ tools/include/asm-generic/unaligned.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/include/asm-generic/unaligned.h b/include/asm-generic/unaligned.h index a84c64e5f11e..0cbe118e25db 100644 --- a/include/asm-generic/unaligned.h +++ b/include/asm-generic/unaligned.h @@ -2,6 +2,8 @@ #ifndef __ASM_GENERIC_UNALIGNED_H #define __ASM_GENERIC_UNALIGNED_H +#include + /* * This is the most generic implementation of unaligned accesses * and should work almost anywhere. diff --git a/tools/include/asm-generic/unaligned.h b/tools/include/asm-generic/unaligned.h index cdd2fd078027..768cafe6702e 100644 --- a/tools/include/asm-generic/unaligned.h +++ b/tools/include/asm-generic/unaligned.h @@ -2,6 +2,8 @@ #ifndef __ASM_GENERIC_UNALIGNED_H #define __ASM_GENERIC_UNALIGNED_H +#include + /* * This is the most generic implementation of unaligned accesses * and should work almost anywhere. From patchwork Sun Mar 10 02:05:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13587961 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 711A03A1A8 for ; Sun, 10 Mar 2024 02:06:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710036363; cv=none; b=qrZoYyTKoyxCwHPVKraqowcq4rn7lb6IPOh9+8rKJKXoeDo9TP+GUzwHWy8A/HgpMImGe+dtGUCL/0gThSM2cPKNc+ZN7VJYslFGJT8motijd5qSs5AcW2henefBvExNjqS2N+8SR3DLXSQPce/BDNI25lgyj8XRJefqA4u1hgM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710036363; c=relaxed/simple; bh=5SZh2mNEl5n+h2lF7KiTxzvDIwYjug3hRJqLAmoNhNQ=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=EMvDNGZ4/kye+swt0HLbsAZqvZo60Lau9E5JiuCoVCuviRu9kpXFvXKJR5kfTaevGfBE5ICZzl/Uf1t3c2fMg6xkxvbFxwAUDOPr23IOYP7MND9+KAJ3XZb2Twf/XuKmF7w8mV6ei36MOuM41xXlUXERJomyWsHjG8NItYLZkCY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Di6pDk6N; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Di6pDk6N" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-609f2920b53so48012727b3.0 for ; Sat, 09 Mar 2024 18:06:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710036359; x=1710641159; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=Hl1/umpZGVsczLzrKS1GZCeAFysDY04buU8ZoM+JBKw=; b=Di6pDk6NePavMF2yALztmcFiJt+x7tbKH41g7V7tmKXpI1KI8Xp6mAzitCxmfo9DcO 6raBeb+eQk7G9fIGxVMs/sYQblO2BRyfy90v+WkYhzFg1GGiizQv742FDU8EK+ZFwRwU vfGTaQ7N0pXROHAxr6tk9DokTsKmKfe1AQ8N86r+BqVYtjAC2Gtzli84MJerVNK2z188 EBaQWSa+L2Dp9j/wtYynGlH/igpaNvLsz7UviGOx9PDXXU3IblAnGvrUmlr7IYjXhR9O P91Fwx4+QnSkrZeNQIXzDa/cwZaDOYB/XdM/pdVfwu8y36kr+LbfT0iQGnEcKivrpxaw odaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710036359; x=1710641159; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Hl1/umpZGVsczLzrKS1GZCeAFysDY04buU8ZoM+JBKw=; b=TSb0L/rAHGbK1lE/dVe1mD+U2Nfw3eZ1fmCGxu7PqLWCfDWiY5BV24hjBWN1MJvknV cAM1XjbUQ6Rp/QNlOGHmMsXzQaQ52on+XtZbq1Ekw2pCYwqgUMBDEQml6rWTkOndBK60 RBULuCTInsji2K2sHlA2hbKTXn2oduCLma6PKZGZpvUkmmPiqTvyWUzMtA0l8m3Ef1KK ewRR+9DMZ5E49i+QXPmoyGS2EhoxxGHqVrlUjPsJ3HmV3+81njDI/JU3IKI44FW8AqsS 8kUVOY7ypgshseElpr1RSF/ri4mlqjQizjlSatbZwjXyBntHCdxPmfFT6xyvanLn/LTn +Elg== X-Forwarded-Encrypted: i=1; AJvYcCXErC4e8PAhBGk6+JOBca+vkGcVXnSc1VgA7zjroqB+Lzd6nfaOFIC7gj5fTYPLAR+AxCupkBsQd/zPuk1NcCjM/JF3/5ys9rKJgAbkELIb X-Gm-Message-State: AOJu0Yy979NY6cZ8qMAw3m/uFISmRQLXIJENae9NrxncAoMHQYeR2e3F KGM80GcQ1rCPTcyWIUFs8N0Vp4i414rezYCSBfiNjJrDRG/eXhXo25yKYbnYGl2hIbCjOjVOQyl BSmPCvg== X-Google-Smtp-Source: AGHT+IFPbWB3/192KGdZtIg9F9X7CoqlPRJZXE+414zWtjFld4XzM0pldNt12CDgHpD/F24xaEQHAI0MEqre X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:a63d:1b65:e810:3ad3]) (user=irogers job=sendgmr) by 2002:a05:6902:1820:b0:dc2:5456:d9ac with SMTP id cf32-20020a056902182000b00dc25456d9acmr147760ybb.5.1710036359574; Sat, 09 Mar 2024 18:05:59 -0800 (PST) Date: Sat, 9 Mar 2024 18:05:06 -0800 In-Reply-To: <20240310020509.647319-1-irogers@google.com> Message-Id: <20240310020509.647319-12-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240310020509.647319-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Subject: [PATCH v1 11/13] tools headers: Sync linux/overflow.h From: Ian Rogers To: Arnd Bergmann , Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Ian Rogers , Adrian Hunter , Paolo Bonzini , Shuah Khan , Kees Cook , "Gustavo A. R. Silva" , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Andrew Morton , Liam Howlett , Miguel Ojeda , Will Deacon , Mark Brown , David Laight , "Michael S. Tsirkin" , Shunsuke Mie , Yafang Shao , Kui-Feng Lee , James Clark , Nick Forrington , Leo Yan , German Gomez , Rob Herring , John Garry , Sean Christopherson , Anup Patel , Fuad Tabba , Andrew Jones , Chao Peng , Haibo Xu , Peter Xu , Vishal Annapurve , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-hardening@vger.kernel.org, llvm@lists.linux.dev Bring in the changes: 26dd68d293fd overflow: add DEFINE_FLEX() for on-stack allocs d67790ddf021 overflow: Add struct_size_t() helper 4b21d25bf519 overflow: Introduce overflows_type() and castable_to_type() 31970608a6d3 overflow: Fix kern-doc markup for functions d219d2a9a92e overflow: Allow mixed type arguments 92d23c6e9415 overflow, tracing: Define the is_signed_type() macro once 230f6fa2c1db overflow: Provide constant expression struct_size e1be43d9b5d0 overflow: Implement size_t saturating arithmetic helpers Add file to check-headers.sh, so there is a warning if the tools version of the file drifts from the kernel's version. Signed-off-by: Ian Rogers --- tools/include/linux/overflow.h | 331 ++++++++++++++++++++++++++------- tools/perf/check-headers.sh | 1 + 2 files changed, 268 insertions(+), 64 deletions(-) diff --git a/tools/include/linux/overflow.h b/tools/include/linux/overflow.h index dcb0c1bf6866..7b5cf4a5cd19 100644 --- a/tools/include/linux/overflow.h +++ b/tools/include/linux/overflow.h @@ -3,6 +3,8 @@ #define __LINUX_OVERFLOW_H #include +#include +#include /* * We need to compute the minimum and maximum values representable in a given @@ -28,117 +30,318 @@ * https://mail-index.netbsd.org/tech-misc/2007/02/05/0000.html - * credit to Christian Biere. */ -#define is_signed_type(type) (((type)(-1)) < (type)1) #define __type_half_max(type) ((type)1 << (8*sizeof(type) - 1 - is_signed_type(type))) #define type_max(T) ((T)((__type_half_max(T) - 1) + __type_half_max(T))) #define type_min(T) ((T)((T)-type_max(T)-(T)1)) /* - * For simplicity and code hygiene, the fallback code below insists on - * a, b and *d having the same type (similar to the min() and max() - * macros), whereas gcc's type-generic overflow checkers accept - * different types. Hence we don't just make check_add_overflow an - * alias for __builtin_add_overflow, but add type checks similar to - * below. - */ -#define check_add_overflow(a, b, d) ({ \ - typeof(a) __a = (a); \ - typeof(b) __b = (b); \ - typeof(d) __d = (d); \ - (void) (&__a == &__b); \ - (void) (&__a == __d); \ - __builtin_add_overflow(__a, __b, __d); \ -}) + * Avoids triggering -Wtype-limits compilation warning, + * while using unsigned data types to check a < 0. + */ +#define is_non_negative(a) ((a) > 0 || (a) == 0) +#define is_negative(a) (!(is_non_negative(a))) -#define check_sub_overflow(a, b, d) ({ \ - typeof(a) __a = (a); \ - typeof(b) __b = (b); \ - typeof(d) __d = (d); \ - (void) (&__a == &__b); \ - (void) (&__a == __d); \ - __builtin_sub_overflow(__a, __b, __d); \ -}) +/* + * Allows for effectively applying __must_check to a macro so we can have + * both the type-agnostic benefits of the macros while also being able to + * enforce that the return value is, in fact, checked. + */ +static inline bool __must_check __must_check_overflow(bool overflow) +{ + return unlikely(overflow); +} + +/** + * check_add_overflow() - Calculate addition with overflow checking + * @a: first addend + * @b: second addend + * @d: pointer to store sum + * + * Returns 0 on success. + * + * *@d holds the results of the attempted addition, but is not considered + * "safe for use" on a non-zero return value, which indicates that the + * sum has overflowed or been truncated. + */ +#define check_add_overflow(a, b, d) \ + __must_check_overflow(__builtin_add_overflow(a, b, d)) + +/** + * check_sub_overflow() - Calculate subtraction with overflow checking + * @a: minuend; value to subtract from + * @b: subtrahend; value to subtract from @a + * @d: pointer to store difference + * + * Returns 0 on success. + * + * *@d holds the results of the attempted subtraction, but is not considered + * "safe for use" on a non-zero return value, which indicates that the + * difference has underflowed or been truncated. + */ +#define check_sub_overflow(a, b, d) \ + __must_check_overflow(__builtin_sub_overflow(a, b, d)) + +/** + * check_mul_overflow() - Calculate multiplication with overflow checking + * @a: first factor + * @b: second factor + * @d: pointer to store product + * + * Returns 0 on success. + * + * *@d holds the results of the attempted multiplication, but is not + * considered "safe for use" on a non-zero return value, which indicates + * that the product has overflowed or been truncated. + */ +#define check_mul_overflow(a, b, d) \ + __must_check_overflow(__builtin_mul_overflow(a, b, d)) + +/** + * check_shl_overflow() - Calculate a left-shifted value and check overflow + * @a: Value to be shifted + * @s: How many bits left to shift + * @d: Pointer to where to store the result + * + * Computes *@d = (@a << @s) + * + * Returns true if '*@d' cannot hold the result or when '@a << @s' doesn't + * make sense. Example conditions: + * + * - '@a << @s' causes bits to be lost when stored in *@d. + * - '@s' is garbage (e.g. negative) or so large that the result of + * '@a << @s' is guaranteed to be 0. + * - '@a' is negative. + * - '@a << @s' sets the sign bit, if any, in '*@d'. + * + * '*@d' will hold the results of the attempted shift, but is not + * considered "safe for use" if true is returned. + */ +#define check_shl_overflow(a, s, d) __must_check_overflow(({ \ + typeof(a) _a = a; \ + typeof(s) _s = s; \ + typeof(d) _d = d; \ + u64 _a_full = _a; \ + unsigned int _to_shift = \ + is_non_negative(_s) && _s < 8 * sizeof(*d) ? _s : 0; \ + *_d = (_a_full << _to_shift); \ + (_to_shift != _s || is_negative(*_d) || is_negative(_a) || \ + (*_d >> _to_shift) != _a); \ +})) -#define check_mul_overflow(a, b, d) ({ \ - typeof(a) __a = (a); \ - typeof(b) __b = (b); \ - typeof(d) __d = (d); \ - (void) (&__a == &__b); \ - (void) (&__a == __d); \ - __builtin_mul_overflow(__a, __b, __d); \ +#define __overflows_type_constexpr(x, T) ( \ + is_unsigned_type(typeof(x)) ? \ + (x) > type_max(typeof(T)) : \ + is_unsigned_type(typeof(T)) ? \ + (x) < 0 || (x) > type_max(typeof(T)) : \ + (x) < type_min(typeof(T)) || (x) > type_max(typeof(T))) + +#define __overflows_type(x, T) ({ \ + typeof(T) v = 0; \ + check_add_overflow((x), v, &v); \ }) /** - * array_size() - Calculate size of 2-dimensional array. + * overflows_type - helper for checking the overflows between value, variables, + * or data type * - * @a: dimension one - * @b: dimension two + * @n: source constant value or variable to be checked + * @T: destination variable or data type proposed to store @x * - * Calculates size of 2-dimensional array: @a * @b. + * Compares the @x expression for whether or not it can safely fit in + * the storage of the type in @T. @x and @T can have different types. + * If @x is a constant expression, this will also resolve to a constant + * expression. * - * Returns: number of bytes needed to represent the array or SIZE_MAX on - * overflow. + * Returns: true if overflow can occur, false otherwise. + */ +#define overflows_type(n, T) \ + __builtin_choose_expr(__is_constexpr(n), \ + __overflows_type_constexpr(n, T), \ + __overflows_type(n, T)) + +/** + * castable_to_type - like __same_type(), but also allows for casted literals + * + * @n: variable or constant value + * @T: variable or data type + * + * Unlike the __same_type() macro, this allows a constant value as the + * first argument. If this value would not overflow into an assignment + * of the second argument's type, it returns true. Otherwise, this falls + * back to __same_type(). */ -static inline __must_check size_t array_size(size_t a, size_t b) +#define castable_to_type(n, T) \ + __builtin_choose_expr(__is_constexpr(n), \ + !__overflows_type_constexpr(n, T), \ + __same_type(n, T)) + +/** + * size_mul() - Calculate size_t multiplication with saturation at SIZE_MAX + * @factor1: first factor + * @factor2: second factor + * + * Returns: calculate @factor1 * @factor2, both promoted to size_t, + * with any overflow causing the return value to be SIZE_MAX. The + * lvalue must be size_t to avoid implicit type conversion. + */ +static inline size_t __must_check size_mul(size_t factor1, size_t factor2) { size_t bytes; - if (check_mul_overflow(a, b, &bytes)) + if (check_mul_overflow(factor1, factor2, &bytes)) return SIZE_MAX; return bytes; } /** - * array3_size() - Calculate size of 3-dimensional array. + * size_add() - Calculate size_t addition with saturation at SIZE_MAX + * @addend1: first addend + * @addend2: second addend * - * @a: dimension one - * @b: dimension two - * @c: dimension three - * - * Calculates size of 3-dimensional array: @a * @b * @c. - * - * Returns: number of bytes needed to represent the array or SIZE_MAX on - * overflow. + * Returns: calculate @addend1 + @addend2, both promoted to size_t, + * with any overflow causing the return value to be SIZE_MAX. The + * lvalue must be size_t to avoid implicit type conversion. */ -static inline __must_check size_t array3_size(size_t a, size_t b, size_t c) +static inline size_t __must_check size_add(size_t addend1, size_t addend2) { size_t bytes; - if (check_mul_overflow(a, b, &bytes)) - return SIZE_MAX; - if (check_mul_overflow(bytes, c, &bytes)) + if (check_add_overflow(addend1, addend2, &bytes)) return SIZE_MAX; return bytes; } -static inline __must_check size_t __ab_c_size(size_t n, size_t size, size_t c) +/** + * size_sub() - Calculate size_t subtraction with saturation at SIZE_MAX + * @minuend: value to subtract from + * @subtrahend: value to subtract from @minuend + * + * Returns: calculate @minuend - @subtrahend, both promoted to size_t, + * with any overflow causing the return value to be SIZE_MAX. For + * composition with the size_add() and size_mul() helpers, neither + * argument may be SIZE_MAX (or the result with be forced to SIZE_MAX). + * The lvalue must be size_t to avoid implicit type conversion. + */ +static inline size_t __must_check size_sub(size_t minuend, size_t subtrahend) { size_t bytes; - if (check_mul_overflow(n, size, &bytes)) - return SIZE_MAX; - if (check_add_overflow(bytes, c, &bytes)) + if (minuend == SIZE_MAX || subtrahend == SIZE_MAX || + check_sub_overflow(minuend, subtrahend, &bytes)) return SIZE_MAX; return bytes; } /** - * struct_size() - Calculate size of structure with trailing array. + * array_size() - Calculate size of 2-dimensional array. + * @a: dimension one + * @b: dimension two + * + * Calculates size of 2-dimensional array: @a * @b. + * + * Returns: number of bytes needed to represent the array or SIZE_MAX on + * overflow. + */ +#define array_size(a, b) size_mul(a, b) + +/** + * array3_size() - Calculate size of 3-dimensional array. + * @a: dimension one + * @b: dimension two + * @c: dimension three + * + * Calculates size of 3-dimensional array: @a * @b * @c. + * + * Returns: number of bytes needed to represent the array or SIZE_MAX on + * overflow. + */ +#define array3_size(a, b, c) size_mul(size_mul(a, b), c) + +/** + * flex_array_size() - Calculate size of a flexible array member + * within an enclosing structure. * @p: Pointer to the structure. + * @member: Name of the flexible array member. + * @count: Number of elements in the array. + * + * Calculates size of a flexible array of @count number of @member + * elements, at the end of structure @p. + * + * Return: number of bytes needed or SIZE_MAX on overflow. + */ +#define flex_array_size(p, member, count) \ + __builtin_choose_expr(__is_constexpr(count), \ + (count) * sizeof(*(p)->member) + __must_be_array((p)->member), \ + size_mul(count, sizeof(*(p)->member) + __must_be_array((p)->member))) + +/** + * struct_size() - Calculate size of structure with trailing flexible array. + * @p: Pointer to the structure. + * @member: Name of the array member. + * @count: Number of elements in the array. + * + * Calculates size of memory needed for structure of @p followed by an + * array of @count number of @member elements. + * + * Return: number of bytes needed or SIZE_MAX on overflow. + */ +#define struct_size(p, member, count) \ + __builtin_choose_expr(__is_constexpr(count), \ + sizeof(*(p)) + flex_array_size(p, member, count), \ + size_add(sizeof(*(p)), flex_array_size(p, member, count))) + +/** + * struct_size_t() - Calculate size of structure with trailing flexible array + * @type: structure type name. * @member: Name of the array member. - * @n: Number of elements in the array. + * @count: Number of elements in the array. * - * Calculates size of memory needed for structure @p followed by an - * array of @n @member elements. + * Calculates size of memory needed for structure @type followed by an + * array of @count number of @member elements. Prefer using struct_size() + * when possible instead, to keep calculations associated with a specific + * instance variable of type @type. * * Return: number of bytes needed or SIZE_MAX on overflow. */ -#define struct_size(p, member, n) \ - __ab_c_size(n, \ - sizeof(*(p)->member) + __must_be_array((p)->member),\ - sizeof(*(p))) +#define struct_size_t(type, member, count) \ + struct_size((type *)NULL, member, count) + +/** + * _DEFINE_FLEX() - helper macro for DEFINE_FLEX() family. + * Enables caller macro to pass (different) initializer. + * + * @type: structure type name, including "struct" keyword. + * @name: Name for a variable to define. + * @member: Name of the array member. + * @count: Number of elements in the array; must be compile-time const. + * @initializer: initializer expression (could be empty for no init). + */ +#define _DEFINE_FLEX(type, name, member, count, initializer) \ + _Static_assert(__builtin_constant_p(count), \ + "onstack flex array members require compile-time const count"); \ + union { \ + u8 bytes[struct_size_t(type, member, count)]; \ + type obj; \ + } name##_u initializer; \ + type *name = (type *)&name##_u + +/** + * DEFINE_FLEX() - Define an on-stack instance of structure with a trailing + * flexible array member. + * + * @type: structure type name, including "struct" keyword. + * @name: Name for a variable to define. + * @member: Name of the array member. + * @count: Number of elements in the array; must be compile-time const. + * + * Define a zeroed, on-stack, instance of @type structure with a trailing + * flexible array member. + * Use __struct_size(@name) to get compile-time size of it afterwards. + */ +#define DEFINE_FLEX(type, name, member, count) \ + _DEFINE_FLEX(type, name, member, count, = {}) #endif /* __LINUX_OVERFLOW_H */ diff --git a/tools/perf/check-headers.sh b/tools/perf/check-headers.sh index 64dbf199dff9..272a37d8e1c4 100755 --- a/tools/perf/check-headers.sh +++ b/tools/perf/check-headers.sh @@ -35,6 +35,7 @@ FILES=( "include/vdso/const.h" "include/linux/hash.h" "include/linux/list-sort.h" + "include/linux/overflow.h" "include/uapi/linux/hw_breakpoint.h" "arch/x86/include/asm/disabled-features.h" "arch/x86/include/asm/required-features.h" From patchwork Sun Mar 10 02:05:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13587962 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 ADE713A8D2 for ; Sun, 10 Mar 2024 02:06:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710036368; cv=none; b=D5a1AcXkG46/FLOgRh+HbE0S3hwJjbxK84p6bkVLFQt62dWLdFb/brrC9HGETWEQFFxqTBE7MwxK6eVF34kc+HA/d32DTZPa7dam4NQ/YmO3D/zRwDXhEqhZGyGGyfGTucTfS4FXeBcO79E7gBBdyF7740AyKczchx7/Sm8jT30= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710036368; c=relaxed/simple; bh=D+WVQMhwRypD8nl8dEaKGNc4FgLhg4MD7Y3hz1hpLdc=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=GZsszM01lFC8ol23CDy5sG0D4z18qq+79X7NP0va12HaB15kb4v/h1RxBqbxmPKaD5ai4gQ9rL4SaAbOrux7vf2zEtrx0SsJOSbmyz6ubP9WcqxT0hsLOrpoSRf+pTS7hi9+xsKIjPxTaXo8xd01Kjd0UtWe6K8ectSsovFS5RU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=eYGgxAod; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="eYGgxAod" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-609fe93b5cfso32259007b3.0 for ; Sat, 09 Mar 2024 18:06:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710036363; x=1710641163; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=iRqsfboWv5Zh6OH/JuRhFYk4oui3DIZMw9JEaY/sNCw=; b=eYGgxAodmEMN8sV+P3coMLUDPJsg2JJyffk8MlIl6PX6OmDVo6oHqWh7gUL5459SPo I79aCyu/FqPyqDz+sQhRGCkDAr0PKOI+qwr3CTV5CvuGsulOQ+p8i47OJG2MklTRK3ea FeR8WVkYW28zsEkooMAnR7dzyGGo/kGASO0zI2cXmjLU4lo1B9r6VIforrCXThC9XF4S dp2y5pYFS3oARNS5foTAQVrCScrC6gqv81CA8SNU5ZFrnt+O/TdkP0cDO0iyNVAxzj/E vfby3thyryEjSK/hS3Fm7bA8G34pxcNsiO7iQ2r00dkRW0hB6mZ1GeAMsl9h7/CYLC6a bHJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710036363; x=1710641163; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=iRqsfboWv5Zh6OH/JuRhFYk4oui3DIZMw9JEaY/sNCw=; b=Uwbv8bAMEn9yDVAKv1fliP/2csC8cyNXxm7+A7MJUpJq7b+ghT78H69z8axNZa5kVy psRa/en9ABFH6LE7NssIaH4kLZquKET5kWP3TuI0Pr9cP9INgk9uh3znEPMnaZdkCb0+ snJNdAyxjB1/SVDNYmPr7UOCkYL0i7WeknRXg/XjKt0d34WTydDg9N+dxxxLwJHt/yyu xjCcjV3bvKj1LbWvRExptSuYhXKtthG7085l7vh5ekiKto7ZNyG16641DDRGA96TWZaY 7DoI2aJ/1bbtDMspV1WGjeOVNIQ+fc474ue+eY8/dl+3uX3RrvzTbyWi3S+R0/n0MYCD jQdg== X-Forwarded-Encrypted: i=1; AJvYcCWIqaQGXYQ0n51G2ccYsRIBcjm2MesDLOdaV48rliTCMjsk4/5AbrCI9qnRJRDrdAKp2UdatKjsGmqdd7a1VZa/4t+AzDoXkVH2iMXhSuf8 X-Gm-Message-State: AOJu0Yylx8EwhE+VStHorZaxpiaGwSfWmz8eRt0Y3Ae1jq7bqNWejMql JcLtUWrAuFMb/6m29pTcqmlRsL7iQUM4jQgNpyTugSswHMfSOYOOpxXkihzoejHhGFi0KscNHur XnLLhUA== X-Google-Smtp-Source: AGHT+IGwpyvJDe4STLMxiIjv/94D/Vemn22ewF6Ekh50t8w85TdxO+eKEEet39Wy/WMstNvxkG1x6+NrSLj4 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:a63d:1b65:e810:3ad3]) (user=irogers job=sendgmr) by 2002:a81:6cc8:0:b0:608:4cec:3e65 with SMTP id h191-20020a816cc8000000b006084cec3e65mr792184ywc.5.1710036362654; Sat, 09 Mar 2024 18:06:02 -0800 (PST) Date: Sat, 9 Mar 2024 18:05:07 -0800 In-Reply-To: <20240310020509.647319-1-irogers@google.com> Message-Id: <20240310020509.647319-13-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240310020509.647319-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Subject: [PATCH v1 12/13] tools headers: Sync compiler.h headers From: Ian Rogers To: Arnd Bergmann , Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Ian Rogers , Adrian Hunter , Paolo Bonzini , Shuah Khan , Kees Cook , "Gustavo A. R. Silva" , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Andrew Morton , Liam Howlett , Miguel Ojeda , Will Deacon , Mark Brown , David Laight , "Michael S. Tsirkin" , Shunsuke Mie , Yafang Shao , Kui-Feng Lee , James Clark , Nick Forrington , Leo Yan , German Gomez , Rob Herring , John Garry , Sean Christopherson , Anup Patel , Fuad Tabba , Andrew Jones , Chao Peng , Haibo Xu , Peter Xu , Vishal Annapurve , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-hardening@vger.kernel.org, llvm@lists.linux.dev compiler.h - synced from include/linux/compiler.h, guards were added to definitions to avoid redefinition of macros in libc. ftrace, CONFIG_OBJTOOL and kentry logic was removed as redundant. compiler-gcc.h - synced from include/linux/compiler-gcc.h compiler-clang.h - added from include/linux/compiler-gcc.h compiler_attributes.h - added from include/linux/compiler_attributes.h, guards were added to definitions to avoid redefinition of macros in libc. compiler_types.h - added from include/linux/compiler_types.h, guards were added to definitions to avoid redefinition of macros in libc. asm/rwonce.h - added as dependency of compiler.h but added from asm-generic/rwonce.h. asm-generic/bitops/non-atomic.h - add linux/types.h so that bool is defined. This file is heavily forked from the kernel one and so synchronizing with the kernel version was infeasible. rbtree.h - add linux/types.h so that bool is defined. This file is heavily forked from the kernel one and so synchronizing with the kernel version was infeasible. string.h - add compiler.h include as definitions from types.h were removed to avoid compiler.h collisions. This file is heavily forked from the kernel one and so synchronizing with the kernel version was infeasible. types.h - remove __must_check definition that conflicts with compiler.h. Signed-off-by: Ian Rogers --- tools/include/asm-generic/bitops/non-atomic.h | 1 + tools/include/asm/rwonce.h | 63 +++ tools/include/linux/compiler-clang.h | 124 +++++ tools/include/linux/compiler-gcc.h | 145 +++++- tools/include/linux/compiler.h | 221 ++------- tools/include/linux/compiler_attributes.h | 449 ++++++++++++++++++ tools/include/linux/compiler_types.h | 171 ++++++- tools/include/linux/rbtree.h | 1 + tools/include/linux/string.h | 1 + tools/include/linux/types.h | 2 +- 10 files changed, 968 insertions(+), 210 deletions(-) create mode 100644 tools/include/asm/rwonce.h create mode 100644 tools/include/linux/compiler-clang.h create mode 100644 tools/include/linux/compiler_attributes.h diff --git a/tools/include/asm-generic/bitops/non-atomic.h b/tools/include/asm-generic/bitops/non-atomic.h index 0c472a833408..5266796df48c 100644 --- a/tools/include/asm-generic/bitops/non-atomic.h +++ b/tools/include/asm-generic/bitops/non-atomic.h @@ -3,6 +3,7 @@ #define _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ #include +#include /* for bool */ /** * ___set_bit - Set a bit in memory diff --git a/tools/include/asm/rwonce.h b/tools/include/asm/rwonce.h new file mode 100644 index 000000000000..9d61f0c87371 --- /dev/null +++ b/tools/include/asm/rwonce.h @@ -0,0 +1,63 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Prevent the compiler from merging or refetching reads or writes. The + * compiler is also forbidden from reordering successive instances of + * READ_ONCE and WRITE_ONCE, but only when the compiler is aware of some + * particular ordering. One way to make the compiler aware of ordering is to + * put the two invocations of READ_ONCE or WRITE_ONCE in different C + * statements. + * + * These two macros will also work on aggregate data types like structs or + * unions. + * + * Their two major use cases are: (1) Mediating communication between + * process-level code and irq/NMI handlers, all running on the same CPU, + * and (2) Ensuring that the compiler does not fold, spindle, or otherwise + * mutilate accesses that either do not require ordering or that interact + * with an explicit memory barrier or atomic instruction that provides the + * required ordering. + */ +#ifndef __ASM_GENERIC_RWONCE_H +#define __ASM_GENERIC_RWONCE_H + +#ifndef __ASSEMBLY__ + +#include + +/* + * Yes, this permits 64-bit accesses on 32-bit architectures. These will + * actually be atomic in some cases (namely Armv7 + LPAE), but for others we + * rely on the access being split into 2x32-bit accesses for a 32-bit quantity + * (e.g. a virtual address) and a strong prevailing wind. + */ +#define compiletime_assert_rwonce_type(t) \ + compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \ + "Unsupported access size for {READ,WRITE}_ONCE().") + +/* + * Use __READ_ONCE() instead of READ_ONCE() if you do not require any + * atomicity. Note that this may result in tears! + */ +#ifndef __READ_ONCE +#define __READ_ONCE(x) (*(const volatile __unqual_scalar_typeof(x) *)&(x)) +#endif + +#define READ_ONCE(x) \ +({ \ + compiletime_assert_rwonce_type(x); \ + __READ_ONCE(x); \ +}) + +#define __WRITE_ONCE(x, val) \ +do { \ + *(volatile typeof(x) *)&(x) = (val); \ +} while (0) + +#define WRITE_ONCE(x, val) \ +do { \ + compiletime_assert_rwonce_type(x); \ + __WRITE_ONCE(x, val); \ +} while (0) + +#endif /* __ASSEMBLY__ */ +#endif /* __ASM_GENERIC_RWONCE_H */ diff --git a/tools/include/linux/compiler-clang.h b/tools/include/linux/compiler-clang.h new file mode 100644 index 000000000000..ddab1ef22bee --- /dev/null +++ b/tools/include/linux/compiler-clang.h @@ -0,0 +1,124 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LINUX_COMPILER_TYPES_H +#error "Please don't include directly, include instead." +#endif + +/* Compiler specific definitions for Clang compiler */ + +/* + * Clang prior to 17 is being silly and considers many __cleanup() variables + * as unused (because they are, their sole purpose is to go out of scope). + * + * https://reviews.llvm.org/D152180 + */ +#undef __cleanup +#define __cleanup(func) __maybe_unused __attribute__((__cleanup__(func))) + +/* all clang versions usable with the kernel support KASAN ABI version 5 */ +#define KASAN_ABI_VERSION 5 + +/* + * Note: Checking __has_feature(*_sanitizer) is only true if the feature is + * enabled. Therefore it is not required to additionally check defined(CONFIG_*) + * to avoid adding redundant attributes in other configurations. + */ + +#if __has_feature(address_sanitizer) || __has_feature(hwaddress_sanitizer) +/* Emulate GCC's __SANITIZE_ADDRESS__ flag */ +#define __SANITIZE_ADDRESS__ +#define __no_sanitize_address \ + __attribute__((no_sanitize("address", "hwaddress"))) +#else +#define __no_sanitize_address +#endif + +#if __has_feature(thread_sanitizer) +/* emulate gcc's __SANITIZE_THREAD__ flag */ +#define __SANITIZE_THREAD__ +#define __no_sanitize_thread \ + __attribute__((no_sanitize("thread"))) +#else +#define __no_sanitize_thread +#endif + +#if defined(CONFIG_ARCH_USE_BUILTIN_BSWAP) +#define __HAVE_BUILTIN_BSWAP32__ +#define __HAVE_BUILTIN_BSWAP64__ +#define __HAVE_BUILTIN_BSWAP16__ +#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */ + +#if __has_feature(undefined_behavior_sanitizer) +/* GCC does not have __SANITIZE_UNDEFINED__ */ +#define __no_sanitize_undefined \ + __attribute__((no_sanitize("undefined"))) +#else +#define __no_sanitize_undefined +#endif + +#if __has_feature(memory_sanitizer) +#define __SANITIZE_MEMORY__ +/* + * Unlike other sanitizers, KMSAN still inserts code into functions marked with + * no_sanitize("kernel-memory"). Using disable_sanitizer_instrumentation + * provides the behavior consistent with other __no_sanitize_ attributes, + * guaranteeing that __no_sanitize_memory functions remain uninstrumented. + */ +#define __no_sanitize_memory __disable_sanitizer_instrumentation + +/* + * The __no_kmsan_checks attribute ensures that a function does not produce + * false positive reports by: + * - initializing all local variables and memory stores in this function; + * - skipping all shadow checks; + * - passing initialized arguments to this function's callees. + */ +#define __no_kmsan_checks __attribute__((no_sanitize("kernel-memory"))) +#else +#define __no_sanitize_memory +#define __no_kmsan_checks +#endif + +/* + * Support for __has_feature(coverage_sanitizer) was added in Clang 13 together + * with no_sanitize("coverage"). Prior versions of Clang support coverage + * instrumentation, but cannot be queried for support by the preprocessor. + */ +#if __has_feature(coverage_sanitizer) +#define __no_sanitize_coverage __attribute__((no_sanitize("coverage"))) +#else +#define __no_sanitize_coverage +#endif + +#if __has_feature(shadow_call_stack) +# define __noscs __attribute__((__no_sanitize__("shadow-call-stack"))) +#endif + +#if __has_feature(kcfi) +/* Disable CFI checking inside a function. */ +#define __nocfi __attribute__((__no_sanitize__("kcfi"))) +#endif + +/* + * Turn individual warnings and errors on and off locally, depending + * on version. + */ +#define __diag_clang(version, severity, s) \ + __diag_clang_ ## version(__diag_clang_ ## severity s) + +/* Severity used in pragma directives */ +#define __diag_clang_ignore ignored +#define __diag_clang_warn warning +#define __diag_clang_error error + +#define __diag_str1(s) #s +#define __diag_str(s) __diag_str1(s) +#define __diag(s) _Pragma(__diag_str(clang diagnostic s)) + +#if CONFIG_CLANG_VERSION >= 110000 +#define __diag_clang_11(s) __diag(s) +#else +#define __diag_clang_11(s) +#endif + +#define __diag_ignore_all(option, comment) \ + __diag_clang(11, ignore, option) diff --git a/tools/include/linux/compiler-gcc.h b/tools/include/linux/compiler-gcc.h index 62e7c901ac28..aebb65bf95a7 100644 --- a/tools/include/linux/compiler-gcc.h +++ b/tools/include/linux/compiler-gcc.h @@ -1,42 +1,147 @@ /* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _TOOLS_LINUX_COMPILER_H_ +#ifndef __LINUX_COMPILER_TYPES_H #error "Please don't include directly, include instead." #endif /* * Common definitions for all gcc versions go here. */ -#ifndef GCC_VERSION #define GCC_VERSION (__GNUC__ * 10000 \ + __GNUC_MINOR__ * 100 \ + __GNUC_PATCHLEVEL__) + +/* + * This macro obfuscates arithmetic on a variable address so that gcc + * shouldn't recognize the original var, and make assumptions about it. + * + * This is needed because the C standard makes it undefined to do + * pointer arithmetic on "objects" outside their boundaries and the + * gcc optimizers assume this is the case. In particular they + * assume such arithmetic does not wrap. + * + * A miscompilation has been observed because of this on PPC. + * To work around it we hide the relationship of the pointer and the object + * using this macro. + * + * Versions of the ppc64 compiler before 4.1 had a bug where use of + * RELOC_HIDE could trash r30. The bug can be worked around by changing + * the inline assembly constraint from =g to =r, in this particular + * case either is valid. + */ +#define RELOC_HIDE(ptr, off) \ +({ \ + unsigned long __ptr; \ + __asm__ ("" : "=r"(__ptr) : "0"(ptr)); \ + (typeof(ptr)) (__ptr + (off)); \ +}) + +#ifdef CONFIG_RETPOLINE +#define __noretpoline __attribute__((__indirect_branch__("keep"))) +#endif + +#if defined(LATENT_ENTROPY_PLUGIN) && !defined(__CHECKER__) +#define __latent_entropy __attribute__((latent_entropy)) #endif -#if __has_attribute(__fallthrough__) -# define fallthrough __attribute__((__fallthrough__)) +/* + * calling noreturn functions, __builtin_unreachable() and __builtin_trap() + * confuse the stack allocation in gcc, leading to overly large stack + * frames, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82365 + * + * Adding an empty inline assembly before it works around the problem + */ +#define barrier_before_unreachable() asm volatile("") + +/* + * Mark a position in code as unreachable. This can be used to + * suppress control flow warnings after asm blocks that transfer + * control elsewhere. + */ +#define unreachable() \ + do { \ + annotate_unreachable(); \ + barrier_before_unreachable(); \ + __builtin_unreachable(); \ + } while (0) + +#if defined(CONFIG_ARCH_USE_BUILTIN_BSWAP) +#define __HAVE_BUILTIN_BSWAP32__ +#define __HAVE_BUILTIN_BSWAP64__ +#define __HAVE_BUILTIN_BSWAP16__ +#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */ + +#if GCC_VERSION >= 70000 +#define KASAN_ABI_VERSION 5 #else -# define fallthrough do {} while (0) /* fallthrough */ +#define KASAN_ABI_VERSION 4 #endif -#if __has_attribute(__error__) -# define __compiletime_error(message) __attribute__((error(message))) +#ifdef CONFIG_SHADOW_CALL_STACK +#define __noscs __attribute__((__no_sanitize__("shadow-call-stack"))) #endif -/* &a[0] degrades to a pointer: a different type from an array */ -#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0])) +#define __no_sanitize_address __attribute__((__no_sanitize_address__)) -#ifndef __pure -#define __pure __attribute__((pure)) +#if defined(__SANITIZE_THREAD__) +#define __no_sanitize_thread __attribute__((__no_sanitize_thread__)) +#else +#define __no_sanitize_thread #endif -#define noinline __attribute__((noinline)) -#ifndef __packed -#define __packed __attribute__((packed)) + +#define __no_sanitize_undefined __attribute__((__no_sanitize_undefined__)) + +/* + * Only supported since gcc >= 12 + */ +#if defined(CONFIG_KCOV) && __has_attribute(__no_sanitize_coverage__) +#define __no_sanitize_coverage __attribute__((__no_sanitize_coverage__)) +#else +#define __no_sanitize_coverage #endif -#ifndef __noreturn -#define __noreturn __attribute__((noreturn)) + +/* + * Treat __SANITIZE_HWADDRESS__ the same as __SANITIZE_ADDRESS__ in the kernel, + * matching the defines used by Clang. + */ +#ifdef __SANITIZE_HWADDRESS__ +#define __SANITIZE_ADDRESS__ +#endif + +/* + * GCC does not support KMSAN. + */ +#define __no_sanitize_memory +#define __no_kmsan_checks + +/* + * Turn individual warnings and errors on and off locally, depending + * on version. + */ +#define __diag_GCC(version, severity, s) \ + __diag_GCC_ ## version(__diag_GCC_ ## severity s) + +/* Severity used in pragma directives */ +#define __diag_GCC_ignore ignored +#define __diag_GCC_warn warning +#define __diag_GCC_error error + +#define __diag_str1(s) #s +#define __diag_str(s) __diag_str1(s) +#define __diag(s) _Pragma(__diag_str(GCC diagnostic s)) + +#if GCC_VERSION >= 80000 +#define __diag_GCC_8(s) __diag(s) +#else +#define __diag_GCC_8(s) #endif -#ifndef __aligned -#define __aligned(x) __attribute__((aligned(x))) + +#define __diag_ignore_all(option, comment) \ + __diag(__diag_GCC_ignore option) + +/* + * Prior to 9.1, -Wno-alloc-size-larger-than (and therefore the "alloc_size" + * attribute) do not work, and must be disabled. + */ +#if GCC_VERSION < 90100 +#undef __alloc_size__ #endif -#define __printf(a, b) __attribute__((format(printf, a, b))) -#define __scanf(a, b) __attribute__((format(scanf, a, b))) diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h index 7b65566f3e42..968d025ca8c1 100644 --- a/tools/include/linux/compiler.h +++ b/tools/include/linux/compiler.h @@ -4,65 +4,49 @@ #include -#ifndef __compiletime_error -# define __compiletime_error(message) +#ifndef likely +# define likely(x) __builtin_expect(!!(x), 1) #endif - -#ifdef __OPTIMIZE__ -# define __compiletime_assert(condition, msg, prefix, suffix) \ - do { \ - extern void prefix ## suffix(void) __compiletime_error(msg); \ - if (!(condition)) \ - prefix ## suffix(); \ - } while (0) -#else -# define __compiletime_assert(condition, msg, prefix, suffix) do { } while (0) +#ifndef unlikely +# define unlikely(x) __builtin_expect(!!(x), 0) #endif -#define _compiletime_assert(condition, msg, prefix, suffix) \ - __compiletime_assert(condition, msg, prefix, suffix) - -/** - * compiletime_assert - break build and emit msg if condition is false - * @condition: a compile-time constant condition to check - * @msg: a message to emit if condition is false - * - * In tradition of POSIX assert, this macro will break the build if the - * supplied condition is *false*, emitting the supplied error message if the - * compiler has support to do so. - */ -#define compiletime_assert(condition, msg) \ - _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__) - /* Optimization barrier */ +#ifndef barrier /* The "volatile" is due to gcc bugs */ -#define barrier() __asm__ __volatile__("": : :"memory") - -#ifndef __always_inline -# define __always_inline inline __attribute__((always_inline)) -#endif - -#ifndef __always_unused -#define __always_unused __attribute__((__unused__)) +# define barrier() __asm__ __volatile__("": : :"memory") #endif -#ifndef __noreturn -#define __noreturn __attribute__((__noreturn__)) +#ifndef barrier_data +/* + * This version is i.e. to prevent dead stores elimination on @ptr + * where gcc and llvm may behave differently when otherwise using + * normal barrier(): while gcc behavior gets along with a normal + * barrier(), llvm needs an explicit input variable to be assumed + * clobbered. The issue is as follows: while the inline asm might + * access any memory it wants, the compiler could have fit all of + * @ptr into memory registers instead, and since @ptr never escaped + * from that, it proved that the inline asm wasn't touching any of + * it. This version works well with both compilers, i.e. we're telling + * the compiler that the inline asm absolutely may see the contents + * of @ptr. See also: https://llvm.org/bugs/show_bug.cgi?id=15495 + */ +# define barrier_data(ptr) __asm__ __volatile__("": :"r"(ptr) :"memory") #endif #ifndef unreachable -#define unreachable() __builtin_unreachable() -#endif - -#ifndef noinline -#define noinline +# define unreachable() do { \ + annotate_unreachable(); \ + __builtin_unreachable(); \ +} while (0) #endif -/* Are two types/vars the same type (ignoring qualifiers)? */ -#ifndef __same_type -# define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b)) +#ifndef __must_be_array +/* &a[0] degrades to a pointer: a different type from an array */ +# define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0])) #endif +#ifndef __is_constexpr /* * This returns a constant expression while determining if an argument is * a constant expression, most importantly without evaluating the argument. @@ -70,150 +54,19 @@ */ #define __is_constexpr(x) \ (sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8))) +#endif -#ifdef __ANDROID__ /* - * FIXME: Big hammer to get rid of tons of: - * "warning: always_inline function might not be inlinable" - * - * At least on android-ndk-r12/platforms/android-24/arch-arm + * Whether 'type' is a signed type or an unsigned type. Supports scalar types, + * bool and also pointer types. */ -#undef __always_inline -#define __always_inline inline -#endif - -#define __user -#define __rcu -#define __read_mostly - -#ifndef __attribute_const__ -# define __attribute_const__ -#endif - -#ifndef __maybe_unused -# define __maybe_unused __attribute__((unused)) -#endif - -#ifndef __used -# define __used __attribute__((__unused__)) -#endif - -#ifndef __packed -# define __packed __attribute__((__packed__)) -#endif - -#ifndef __force -# define __force -#endif - -#ifndef __weak -# define __weak __attribute__((weak)) -#endif - -#ifndef likely -# define likely(x) __builtin_expect(!!(x), 1) +#ifndef is_signed_type +# define is_signed_type(type) (((type)(-1)) < (__force type)1) #endif - -#ifndef unlikely -# define unlikely(x) __builtin_expect(!!(x), 0) -#endif - -#ifndef __init -# define __init +#ifndef is_unsigned_type +# define is_unsigned_type(type) (!is_signed_type(type)) #endif -#include - -/* - * Following functions are taken from kernel sources and - * break aliasing rules in their original form. - * - * While kernel is compiled with -fno-strict-aliasing, - * perf uses -Wstrict-aliasing=3 which makes build fail - * under gcc 4.4. - * - * Using extra __may_alias__ type to allow aliasing - * in this case. - */ -typedef __u8 __attribute__((__may_alias__)) __u8_alias_t; -typedef __u16 __attribute__((__may_alias__)) __u16_alias_t; -typedef __u32 __attribute__((__may_alias__)) __u32_alias_t; -typedef __u64 __attribute__((__may_alias__)) __u64_alias_t; - -static __always_inline void __read_once_size(const volatile void *p, void *res, int size) -{ - switch (size) { - case 1: *(__u8_alias_t *) res = *(volatile __u8_alias_t *) p; break; - case 2: *(__u16_alias_t *) res = *(volatile __u16_alias_t *) p; break; - case 4: *(__u32_alias_t *) res = *(volatile __u32_alias_t *) p; break; - case 8: *(__u64_alias_t *) res = *(volatile __u64_alias_t *) p; break; - default: - barrier(); - __builtin_memcpy((void *)res, (const void *)p, size); - barrier(); - } -} - -static __always_inline void __write_once_size(volatile void *p, void *res, int size) -{ - switch (size) { - case 1: *(volatile __u8_alias_t *) p = *(__u8_alias_t *) res; break; - case 2: *(volatile __u16_alias_t *) p = *(__u16_alias_t *) res; break; - case 4: *(volatile __u32_alias_t *) p = *(__u32_alias_t *) res; break; - case 8: *(volatile __u64_alias_t *) p = *(__u64_alias_t *) res; break; - default: - barrier(); - __builtin_memcpy((void *)p, (const void *)res, size); - barrier(); - } -} - -/* - * Prevent the compiler from merging or refetching reads or writes. The - * compiler is also forbidden from reordering successive instances of - * READ_ONCE and WRITE_ONCE, but only when the compiler is aware of some - * particular ordering. One way to make the compiler aware of ordering is to - * put the two invocations of READ_ONCE or WRITE_ONCE in different C - * statements. - * - * These two macros will also work on aggregate data types like structs or - * unions. If the size of the accessed data type exceeds the word size of - * the machine (e.g., 32 bits or 64 bits) READ_ONCE() and WRITE_ONCE() will - * fall back to memcpy and print a compile-time warning. - * - * Their two major use cases are: (1) Mediating communication between - * process-level code and irq/NMI handlers, all running on the same CPU, - * and (2) Ensuring that the compiler does not fold, spindle, or otherwise - * mutilate accesses that either do not require ordering or that interact - * with an explicit memory barrier or atomic instruction that provides the - * required ordering. - */ - -#define READ_ONCE(x) \ -({ \ - union { typeof(x) __val; char __c[1]; } __u = \ - { .__c = { 0 } }; \ - __read_once_size(&(x), __u.__c, sizeof(x)); \ - __u.__val; \ -}) - -#define WRITE_ONCE(x, val) \ -({ \ - union { typeof(x) __val; char __c[1]; } __u = \ - { .__val = (val) }; \ - __write_once_size(&(x), __u.__c, sizeof(x)); \ - __u.__val; \ -}) - - -/* Indirect macros required for expanded argument pasting, eg. __LINE__. */ -#define ___PASTE(a, b) a##b -#define __PASTE(a, b) ___PASTE(a, b) - -#ifndef OPTIMIZER_HIDE_VAR -/* Make the optimizer believe the variable can be manipulated arbitrarily. */ -#define OPTIMIZER_HIDE_VAR(var) \ - __asm__ ("" : "=r" (var) : "0" (var)) -#endif +#include #endif /* _TOOLS_LINUX_COMPILER_H */ diff --git a/tools/include/linux/compiler_attributes.h b/tools/include/linux/compiler_attributes.h new file mode 100644 index 000000000000..9bfaec783e48 --- /dev/null +++ b/tools/include/linux/compiler_attributes.h @@ -0,0 +1,449 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LINUX_COMPILER_ATTRIBUTES_H +#define __LINUX_COMPILER_ATTRIBUTES_H + +/* + * The attributes in this file are unconditionally defined and they directly + * map to compiler attribute(s), unless one of the compilers does not support + * the attribute. In that case, __has_attribute is used to check for support + * and the reason is stated in its comment ("Optional: ..."). + * + * Note, in the tools/include version the definitions are conditional to avoid + * conflicts with libc. + * + * Any other "attributes" (i.e. those that depend on a configuration option, + * on a compiler, on an architecture, on plugins, on other attributes...) + * should be defined elsewhere (e.g. compiler_types.h or compiler-*.h). + * The intention is to keep this file as simple as possible, as well as + * compiler- and version-agnostic (e.g. avoiding GCC_VERSION checks). + * + * This file is meant to be sorted (by actual attribute name, + * not by #define identifier). Use the __attribute__((__name__)) syntax + * (i.e. with underscores) to avoid future collisions with other macros. + * Provide links to the documentation of each supported compiler, if it exists. + */ + +/* + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-alias-function-attribute + */ +#ifndef __alias +# define __alias(symbol) __attribute__((__alias__(#symbol))) +#endif + +/* + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-aligned-function-attribute + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-aligned-type-attribute + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-aligned-variable-attribute + */ +#ifndef __aligned +# define __aligned(x) __attribute__((__aligned__(x))) +#endif +#ifndef __aligned_largest +# define __aligned_largest __attribute__((__aligned__)) +#endif + +/* + * Note: do not use this directly. Instead, use __alloc_size() since it is conditionally + * available and includes other attributes. For GCC < 9.1, __alloc_size__ gets undefined + * in compiler-gcc.h, due to misbehaviors. + * + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-alloc_005fsize-function-attribute + * clang: https://clang.llvm.org/docs/AttributeReference.html#alloc-size + */ +//#ifndef __alloc_size__ +//# define __alloc_size__(x, ...) __attribute__((__alloc_size__(x, ## __VA_ARGS__))) +//#endif + +/* + * Note: users of __always_inline currently do not write "inline" themselves, + * which seems to be required by gcc to apply the attribute according + * to its docs (and also "warning: always_inline function might not be + * inlinable [-Wattributes]" is emitted). + * + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-always_005finline-function-attribute + * clang: mentioned + */ +#ifndef __always_inline +# define __always_inline inline __attribute__((__always_inline__)) +#endif + +/* + * The second argument is optional (default 0), so we use a variadic macro + * to make the shorthand. + * + * Beware: Do not apply this to functions which may return + * ERR_PTRs. Also, it is probably unwise to apply it to functions + * returning extra information in the low bits (but in that case the + * compiler should see some alignment anyway, when the return value is + * massaged by 'flags = ptr & 3; ptr &= ~3;'). + * + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-assume_005faligned-function-attribute + * clang: https://clang.llvm.org/docs/AttributeReference.html#assume-aligned + */ +#ifndef __assume_aligned +# define __assume_aligned(a, ...) __attribute__((__assume_aligned__(a, ## __VA_ARGS__))) +#endif + +/* + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-cleanup-variable-attribute + * clang: https://clang.llvm.org/docs/AttributeReference.html#cleanup + */ +#ifndef __cleanup +# define __cleanup(func) __attribute__((__cleanup__(func))) +#endif + +/* + * Note the long name. + * + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-const-function-attribute + */ +#ifndef __attribute_const__ +# define __attribute_const__ __attribute__((__const__)) +#endif + +/* + * Optional: only supported since gcc >= 9 + * Optional: not supported by clang + * + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-copy-function-attribute + */ +#if __has_attribute(__copy__) +# define __copy(symbol) __attribute__((__copy__(symbol))) +#else +# define __copy(symbol) +#endif + +/* + * Optional: only supported since gcc >= 14 + * Optional: only supported since clang >= 18 + * + * gcc: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108896 + * clang: https://reviews.llvm.org/D148381 + */ +#if __has_attribute(__counted_by__) +# define __counted_by(member) __attribute__((__counted_by__(member))) +#else +# define __counted_by(member) +#endif + +/* + * Optional: not supported by gcc + * Optional: only supported since clang >= 14.0 + * + * clang: https://clang.llvm.org/docs/AttributeReference.html#diagnose_as_builtin + */ +#if __has_attribute(__diagnose_as_builtin__) +# define __diagnose_as(builtin...) __attribute__((__diagnose_as_builtin__(builtin))) +#else +# define __diagnose_as(builtin...) +#endif + +/* + * Don't. Just don't. See commit 771c035372a0 ("deprecate the '__deprecated' + * attribute warnings entirely and for good") for more information. + * + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-deprecated-function-attribute + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-deprecated-type-attribute + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-deprecated-variable-attribute + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Enumerator-Attributes.html#index-deprecated-enumerator-attribute + * clang: https://clang.llvm.org/docs/AttributeReference.html#deprecated + */ +#ifndef __deprecated +# define __deprecated +#endif + +/* + * Optional: not supported by clang + * + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-designated_005finit-type-attribute + */ +#if __has_attribute(__designated_init__) +# define __designated_init __attribute__((__designated_init__)) +#else +# define __designated_init +#endif + +/* + * Optional: only supported since clang >= 14.0 + * + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-error-function-attribute + */ +#if __has_attribute(__error__) +# define __compiletime_error(msg) __attribute__((__error__(msg))) +#else +# define __compiletime_error(msg) +#endif + +/* + * Optional: not supported by clang + * + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-externally_005fvisible-function-attribute + */ +#if __has_attribute(__externally_visible__) +# define __visible __attribute__((__externally_visible__)) +#else +# define __visible +#endif + +/* + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-format-function-attribute + * clang: https://clang.llvm.org/docs/AttributeReference.html#format + */ +#ifndef __printf +# define __printf(a, b) __attribute__((__format__(printf, a, b))) +#endif +#ifndef __scanf +# define __scanf(a, b) __attribute__((__format__(scanf, a, b))) +#endif + +/* + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-gnu_005finline-function-attribute + * clang: https://clang.llvm.org/docs/AttributeReference.html#gnu-inline + */ +#ifndef __gnu_inline +# define __gnu_inline __attribute__((__gnu_inline__)) +#endif + +/* + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-malloc-function-attribute + * clang: https://clang.llvm.org/docs/AttributeReference.html#malloc + */ +#ifndef __malloc +# define __malloc __attribute__((__malloc__)) +#endif + +/* + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-mode-type-attribute + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-mode-variable-attribute + */ +#ifndef __mode +# define __mode(x) __attribute__((__mode__(x))) +#endif + +/* + * Optional: only supported since gcc >= 7 + * + * gcc: https://gcc.gnu.org/onlinedocs/gcc/x86-Function-Attributes.html#index-no_005fcaller_005fsaved_005fregisters-function-attribute_002c-x86 + * clang: https://clang.llvm.org/docs/AttributeReference.html#no-caller-saved-registers + */ +#if __has_attribute(__no_caller_saved_registers__) +# define __no_caller_saved_registers __attribute__((__no_caller_saved_registers__)) +#else +# define __no_caller_saved_registers +#endif + +/* + * Optional: not supported by clang + * + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-noclone-function-attribute + */ +#if __has_attribute(__noclone__) +# define __noclone __attribute__((__noclone__)) +#else +# define __noclone +#endif + +/* + * Add the pseudo keyword 'fallthrough' so case statement blocks + * must end with any of these keywords: + * break; + * fallthrough; + * continue; + * goto