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: 13587979 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 81AFB1FA0 for ; Sun, 10 Mar 2024 02:05:34 +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=1710036336; cv=none; b=ix2G1ulqk/FbNC2EGIUxLL6R+U4tQDQfdW6gyD3kfdYIp/GzhyrNj15tOG06vqMYduyPtVCEzj/WeyqOHbU9JfBeEr4XWQtsywWLUEaJZUbywY7lOSisUepDeSjvEg8Ok6xEKEE4gbx8QybU5rlU3qxS+DqiRttMJMNVk4fb54w= 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.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="BZG3qtOl" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dd0ae66422fso6702570276.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=lmLehClozGPM0h1RJRHWGlYB15rxgrxgcAPpj7S7cqafwYQYmPAMpfmybBHZ0JgzYH IW+kDxZ54UoQJWClmLjKUWTd/+7lN+dIuppytH0CFc5a4iYUmFrpHPVtUS4CB1QZ9KS0 eUk3pVbEPgYDThVrKaLkeBjQcyjxJT3kOhp7oOvlZXdls3vVNfjZqbfLIV4B3yuoCZ6X H030IVtnd8AYXqlGqfXKtXId0m5XftdQugAWlFPoIIlyC9B8UZPMTbEgWYTHfkMElxo4 UpPWNzm3oqz49ybGUZX3f6Hz5VtK+aqXIeK+WKnmi4gQC+SnJbdVdf+ql6iwclBkOVrB Du1Q== X-Forwarded-Encrypted: i=1; AJvYcCVPWrJ5M3FHpM+06NyQGqgwXRumr0Em4+oPBzlVvcaAEWcjkMadkLJrqWTaeQEuOiYzWTBKb5hxFH4LxA3gN2ztRImC X-Gm-Message-State: AOJu0YzRwL38IFmT/MBim/wHBijxxq4eZn+DJEvJPd/7a0Ah9DSRGr/L OFlJYmknKllIHFHfSIY20y8EDyUaHsRs5FgXk3y10OPM8KyavD34XLl8hrNHuV26O8SElBiTHYm +JlN1rw== 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: kvm@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: 13587980 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 415CE5663 for ; Sun, 10 Mar 2024 02:05:37 +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=1710036339; cv=none; b=E8de2gqM/yHmFsnThYPjlbMii2ZZ3eWOOMkEsXtQJIezJhWvyO2LoITrqc0aGjrl7QG8rikLLLfj7zwM2buXyVyBpBv6PFOG7RwptgTVCzs7KV/MaO2WZifj+6z5G5oXHojFX+RlONENiWFWZ8vaJlNYozKdCS7SymNRae0Eav8= 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.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="kMIRydFx" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60a0a5bf550so28760967b3.3 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=ca/P3Lbr4oMnjPmOFWlyOLRO4dCCMpAHT10wmpUn3It9i5a7R3I/iObARfXnSb16/q lfnuaXNPKr2bziOpVQdwICtjd8fHfAAiV2NETUHQn0BoSJ8FM0wp37QleFJKO8e7Tmmx 2XohMlYzocW3T0uiKOcIAXlWEuFEvMGTvdDnXDJtytr40sM5ooHQXpxudAnCasQqRqjS SkEZaC5P6BJfBaJi0X7Je46jFwAaejbD1DcmoIU10QqAKHZUi3AcqdhTJhFSsTvxJ0mI g0v7gTlvMeQOmV3on5qgzQTatPQSnC0kahxrSzg70CPuYs7kZ8UT6MUfdcOVrjry8xoY PlgA== X-Forwarded-Encrypted: i=1; AJvYcCV61YK7G/OX7EqgrgXIcq3OKFwCW+4ZNvOz5y+AA16saE6s1p2aO3e5r2x8NyTk9uRSi/FKjeCCasCOFTiYSSzHuJmF X-Gm-Message-State: AOJu0YyP2waOQItcIDvPdl6IAfaEnoZzpJC26Q9MwcIv8V7VFpO9VI2i qPzMcLb+mrvGfjY9IXJlveZBOOFBKJfqEvCMqkV30rs4od7UlWkvm4bbtZpUh0WimS/2QlRWoUv 8iO8YQA== 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: kvm@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: 13587981 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 2BEC9BE7E 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=1710036341; cv=none; b=WVS/WSysf81nqVr2MNazykDA6qyrWVHnF8vC6jMrirVVV/KmZn68DOR0Bv4Fl8MSmCamDGhS84UNLZvj4MNPI6fqOKgTbaOMOxpW78OSz2pdWrxJGSeBUBL6Ij0acXkjx0I82Vx5lnS7F4mPE3SvKGHSdF5f1vHqytrRAaTHfjc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710036341; c=relaxed/simple; bh=RGHR+QiLceocR0H7Go2J+IFsQikYIqGpUdA5u3bRq6I=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=hw0iFszpJYr9L7M4PpBI9d0ANyBkcKQmr0R/KwsrH86t6Jfe0IeDqv3hAEM5mcX0jpA/jgwYsg5QP4qYPR7DIxIcW5O71RYehXm+am/aNqEZYXMwJfjCnVWGNxtQltSBjEvzoQmNfJACQaP0ra6Nxne2gnjg9jZ9GOQ+aCDtxeQ= 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-609f2920b53so48009407b3.0 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=UUNeitPzmJ9ZXtyA+bbWYfWCzCOOnyfDQrLydsukQvIONP7EJwY0dqJEm9GqhggI2N RqlDmkRkDNKUDKY+SFxqCeXekcz3byvSg+gSBVTvsJxQ0aAMnu9Tok1d8MWqjmVr+nwK rEZvndOMltaUiZ89RRV5DFhumME+TTIZOSHnii9C7bxqRpWs8Pu8CWU6fV83Rs/S2kDJ 6Tkv5Licz6PQiJik5v6grFsuJdy7rZoJZOZOkJG8i19fKi/NtyXFiO+1mTmkaUZtB7AV /N3NYQfwcqxdRo3/B7hyBcViqKnQ7JqzoHPatt4b+3bvq1a5OIoCdewiMaPEmspw633S huew== X-Forwarded-Encrypted: i=1; AJvYcCUufxCH8WFUqurlhDfERRxwN7kgsBSNVKBfHUav1z/3YQ+k/7Sb0vdM6diYSe46fQnH3vdwnaKj3S4YWs01P1OcKOa+ X-Gm-Message-State: AOJu0Yxsw6eFKgmVB7uuy5HvdCQ/9iaFzVRYwJr1uzFqCearUviS1ZBX aBe2TzRD7zlKht04OF6gRLSV/AgUUsSnIwAvwZKlTSNUjpWny+Tvt63CNNNkFUqLurGCksFK71D h2hV1OQ== 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: kvm@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: 13587982 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 E28C5FBEE 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-608ad239f8fso54948257b3.0 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=P0mNtNrrs4xASb1gTjBVmwTWQOBQqRGcXf3D+iO7ths2vOOQ9fG2vzf6TO1LO1YsBs Q4sqRShLoVKi/C6CfmQL0Qb+bprZMbW3ruJA3f8mW2R5PPZ3y5OEofBSEfop9f0CvdNe EB1HBRNVJ//LbjknfdYadu/nOWVUPE2NCdmwOBA63vDl1sElXv0v/iw/3sOBmm3pkK2J 6zgk2Z3sjyQ/JjWyid6B9gEpbMZyWRPeDvZaJtaIGP4wAa5vfWY4XTj5ufRlkTWx40NF YQn7438j62255UdaVPM7XflhgwuoJ30n41u9UCMGVFcxhsABcVGe7jSNLo5zgryd+dLc dLGA== X-Forwarded-Encrypted: i=1; AJvYcCX7IYpONIg0vS2ZhqZSFDfWHszL0npiWJrfDVMSMR+7aavuwQXsbw68/T0YwhVgVAEdzuinLf9Tz+Y6ETTaygSp2hhW X-Gm-Message-State: AOJu0YyW2p4xqDFFkDkcPlr/pQ8dJ1l8K02o3EK7mBxE0EC26lvo5zSU svc1XUhKXRq3PTiXXf9X8k1/mxkUNg4aMM8BcipybzzY+YcBnwJgjpT2EVYSw3vbZbmcfU7x9ov I/wbqcw== 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: kvm@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: 13587983 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 381D31BF2A 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-60a0815e3f9so25389327b3.2 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=OB/busaBkSVbiIS1N1v3awzLwk/nwIdmbHiV36IJaCnUYKXiAUS3PLv5SnKtHpOHy+ Idd5T4NrX65OA7p/gvWrlOM465zwtuP9ojowD7S7KIFyJgJ1+8FtBsS7mT8i9sccKuuJ R1FrtS1fvOfO3asrQLODCXw7IUT+9N8Zt4TLr4odnRtFNNvVg3zu25/W2aErR21b0155 f3r8LpKAjZ4DRyZBNCiRUFhjSYfHbz6z52IfHn42VA6UV9X3REf2sB2lcSidAVwL8MRj aKCiz523Z2ccTgFPHwAC50L44KjKlJyHrGrGigGkXpXDkuX4k/ijaTBtvgJamwBkYF9s 9XhA== X-Forwarded-Encrypted: i=1; AJvYcCXpgGilXocAya7od7fW6/jWFDgLw4HJlm8oTUxeI1Eub3jj2kfeo4D32gXnvN7egcVqG3hUv7ZkIZZa9h3XwZ4R8nng X-Gm-Message-State: AOJu0YwxYuBWIJn+nFPa3AtY60KOouLXjq517ZaOEdCCmIynVZ76NvGt d3L9fmWssCKy9avyud++3Ok1h0j/RP7rpUFRrTo0q43r5XtjCZJT66geUsVdcXVObvXdXFUvDJI WCsDdng== 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: kvm@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: 13587984 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 7F04F200DD 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=1710036350; cv=none; b=rkuqZVnmOgO75Jxc3x4Iq/+fyaVr8z9O/IRELN8cq2sYy6cQi1k0rH44R/+p4g2eOd7w7p6jRUjTNv/pmvtbud1O3lXObvSdDEBP+Q1LBvoQ5topZDvfoEiHhPKdWwSyKZ630SR15hMqq/X5hw9IF9bkXOSp9Nyi9wPGh3r4Uhg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710036350; c=relaxed/simple; bh=I32YjdeuPxEte3yHw53IzkVFz3QD1fvyYmVpmCiJgX0=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=Hu25AzMjrxWAhtfxPCXZn9vtjGVnScV/NzdjEJw5u5+EQQgU9mfhREp2v+NQP1hSJgzhbxAYYKYLCCW62FvnVTC46YVxTLLw2dVIqMfFm8AmAuWMZvfglmSO3P34aA6AuE0Yr28+ObeDMd2LdEcyMP2PZtIpDl2TaTOt/Ns40os= 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-60a20c33f07so8479477b3.3 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=vpE52/eOaXPFkpM/Wp9sHQ9Nr/KH8+Di697TQRxWQwRQtAjOYW/qtVXg6bzGoyjeNa WpfJpIXjqy/c5vJ4HP8N/Am7GOoSErkqTzITdvk8KtppwUrkr5WiseIikBrtxWOUX9fI YLJr3P04jt/Fj18dn026i/Pd5PNC/ARErmQ0+5dU6/RuMsBx/YCN6Oippvq/a21Y6Vbs sE3tV3v3+Tslr4JhOA8EaZPNO6DrUm1G7FwEthRBAuh0Lg+6D7krMx0NHpKyDKQ3b486 tobUwBA22Sb2n9pra3+0v+YOqcRmtK7b4ZR6nqcr+NcoQtmr1T5H3AT7hxaaEh/rix97 KHKw== X-Forwarded-Encrypted: i=1; AJvYcCWvWbEpLK87G7gSvjytDlNQW1Zam11e/El2lbRr5S0j2Pq9PxZ/7asEBBU/u92D4p2SKlM9Kp9aBx2z0DggJHdeGpbP X-Gm-Message-State: AOJu0YwsR9BIj0Rr0UChDkrlF9F5y0J8+bXSEs8ulyvQth+D5RYNCIFT yrUdLw8b8Rle087cyxtIDqVpJHhlBH47al1aLje/BdyUOWDmf3movmgexCqPKQdaDzKmTKqwhGV hxvdghw== 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: kvm@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: 13587985 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 D1AD72744C for ; Sun, 10 Mar 2024 02:05:49 +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=1710036352; cv=none; b=g8+RWKs+A0/UHas7as9hERCbDAJwiHtBiR5Lze8OfZf5QbTlw2gboNSA9peFdYo5GSoIejSBLvCYWMakCIHqWjXv4U8ba8k2jV9Qvyxn9g80Hq2F3LTSvv0Ok1QFhUcy9sL5w0DrBcUeMn8pALr1dB2E+7s+7StPrTZaoD9IHXw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710036352; 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=C2iE2ireC4WgMQ8YQZuNbaxoOMo+TOed2/BDKDq1KThFM8ZZIRaIloCBeILXkuR+R0r37PU/VGYs/Lkh4c/wiIUnXvIrV4TOhQXjvstxOAwNsdyOf3mMG9RaaHs+MxuiUSnAWl1l30oFuCNjP3nT2kZ7ULEOe4bQsDSADOOUVSQ= 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.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="4RRJfEVF" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-609f2920b53so48010857b3.0 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=aZiVrf0yFBArJ7Kjlc/Uf43wj1NhJWyMBk3YB+2OXjx5GRUWlyK8IiSfpf3h8PqLeB xGPmD2wvlHs4uLv0SaLk9RdZrcdcEntH66tfdGIK1J7jFCQ1WFMo337lRk9e+OtjAqZK nY7U/wVx6oJw0/+59gobSH2Bxl0nsfqHLV04gg+Exz7T2rezzOj8Q81+lxhLt7y40/dP N5gGALosiL3a91pxsV11BgpJqfKp6+/OxeuZxpOoBjJmEMeUWbjt6/obl4UO+m69Kvfo nT22mcGMAWD3xC88skKdLyseXSz1/0qejDao++0Avf5fUewFzdeDvwvmsaaCMlTda/yH O29Q== X-Forwarded-Encrypted: i=1; AJvYcCVi5Vk0cg0hDvSXZERYmGjMvifTLYmMdBvxnGqMZ3b/829jGvmUEhjGB4qzyJX9leCTbMRM1Aurgs0P+gGCsOlUYf9Z X-Gm-Message-State: AOJu0YzjyE7uR/cFJsfjwS/m55mWz0ljj5PzFvgYSErGODVWgMxGdThF 4h2/PSpMwSuYkU2Rj9zWq9BNx6fFcwvrJ5vnZXu+/y1bFARcb/oY+De3dBBAMeJ9M/cbfMrgCEC 3l1sBcQ== 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: kvm@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: 13587986 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 A383E2CCA4 for ; Sun, 10 Mar 2024 02:05:52 +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=1710036354; cv=none; b=T8Fqc7VvsSi2vM84ZvyjZfEtJyT29kOYG0I63rDAwb0T0sKdUSHb7bI4wgcVej2hAlgNdDjGP9nXSIUx/BAiRbZ9hfO3uhuW7CCecaqeT9buYaM8UsgZwLODPAfNDNwkO3+Lp9v2GKCR/nAX73GGXujCft9+y5WgWKbg1gdPxr8= 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.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="wez/FaFs" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-60a0a5bf550so28763217b3.3 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=FW9+je8bvgI5IGuljBVh9GtxfFvnVku2grXbXSa0tgM65BcnlCtv7DyH0RFhz5SqeC Ah6NsQtcBmdpOoqqZUVIDRoVVuLU+Ng76O2dwRLO46ID6aKBN3XiQifOUfw0L/87N1/d aMkwSBjlITkZBCROkp1Mde1REfDTwcbR3afSqclmhaolc12VOLULxy3JCtsBOThWfLj1 AI2+YiNFelwOaABK5unJSiX6V5jGWibxGWLkghTmTgtaBqN/erEIh39ygN70EU9hqqXc FVfoiB63BCjINHalyWSngJVQIukdB7VwIbEBSdiDPieRYZkQVLYLTWLVQqCrKqLW4G51 gIqg== X-Forwarded-Encrypted: i=1; AJvYcCXX2qVLnFS++eEMHhQVBeiL0U3Vr4Wn5PTeb0kP4POZ/usgfotEpDBgVBueJiR020WOfkIrQ1IMzSFKsPYLByVeEdIa X-Gm-Message-State: AOJu0YxC0DXauCYy3wZ1gCgyA7kFV83v/qTavdq4kh0al3Hb3ScbEA63 KPDKOSqvy4Q7IivS0ietgrDlfUfCQ9WnVId700KGFiD8aMnauRfMjbflOE4zusd1c5FXneuCzbG 36TMyIg== 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: kvm@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: 13587987 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 23713376FE for ; Sun, 10 Mar 2024 02:05:55 +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=1710036357; cv=none; b=F6WteHlYrIEanFVP7awZUTm5MZio2HmB3x5WBPWMQYAln1xNp0K8IHiUSoCDk3MbHsbGk/V2Q+YnXCVeflDP9IoLT+EUlCPM/CLOe/nVf3MCZR/XaF/2bB4/UniYupnBKBtTwT2RKy/N+Ptw97XvrjP8WgAwZxh+MQBiCsYZFdo= 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.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="Et8oLd0U" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc6b5d1899eso5900390276.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=MsQekrIB1cGYfsoQn5DPYJDSNpDtf2V7bQmnMvdArgtKkplIk8zU/KxoXH5MuVxgaP B7QF1ChRDYEvRBRBhpTFxlQFtOIP1WiuGEKBlg5DVwS0lBx+Nv+lrPk7dK3UebgRbNQR FtnHsHTxm32sXvV5o3wXiAJ+IhX7ioy7jGOCD0E8sSGlWT+QVSqOui+bngCCQj3pMlz+ GpH4Bj2A2jp5fMhX98C3o9JjmrsfQeWHf5ahCRE4nQuWF0wodiXQa6/IHHK06JKFfP1V i4iGAz3Z+khLfpTI7t69+z6CaRsd/auPshqHQWwX6SdwOC97hi3IfTSXbBMfb9EQOYaP AoHw== X-Forwarded-Encrypted: i=1; AJvYcCX0+iJdxKf+ryb3mVCbYatmHAlg5d3RCgPNvqKZE8Q2STuViHQClp0tplrOeLD/WeHDvkNG1/f9IY0D3yRFvtKZ3nWe X-Gm-Message-State: AOJu0YwJAR3YXoAaAzQ4eyFtBSC+7UhD6t9+pN68/lsWPcsO9Wak4nmO G5LiCr+XfK3AQTKF2xC8ikWOuOgZIpKUrQWeYyVLjwHJ2pTDKTR49ZhWbpZgQDKmKji84yN2glB DAqxWxA== 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: kvm@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: 13587988 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 960FB38F84 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=1710036359; cv=none; b=IMsW/ttoKMpnnomQeoxNu8bUtiytSt2/hg5VeEKj+hb0LezHA1RaMipQ6uWlxYCu/bmduAYISmnJEYSqnYGT7d+qStxrF0QA8KndK5uJ1FfUn1wqe73y6xtCPZis9mV7/2dv0G2CPbHwM3JL8Y6Lz3+jEc+FFGJlTlTkbeL0+S8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710036359; c=relaxed/simple; bh=ZWL6CpbSDkoHT9bHTSvzN2HvMNxtU4EmDh1g2wTW1tQ=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=o0MBg5+JCornX/0G1bJsrC3TR1HFZpkLrHd5VC7h520sPJdNNOpjhLwGWqBPGHw1QR1VhQJOS5QbDsYlJT1qDR1JuNaZizJ4qWff0KbGxatkoExj4yV0efaab3+WtiyopIVDRFG0/5e7KdQWuX8FK35woH09c0z24Z7+emaMnmE= 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-dcc0bcf9256so2745802276.3 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=PB4LdFSUVU/dLWOkwFET1rbtnhm7vsRXiJ36F/P0eSqOPRtI5YhNo6IL41RIW3luKC O6rP6lkz+B6vuRKhX1beXn1Rx9TgrQOhrwpwPYeq9eBlM+r40EbHwWQ7ZXHfjtN0idsj 9/RtnAw2MCacMgEOlXYf5+Ip3ijXxcS0HVU2GG2mK0zQpRqUoIp0mJaBH7Gesnm+zHeD tzR/YzgCg6sVBL+a/ZnP9oScucPRjc02SXooepSBRsR321w8P6OjDK8IF24y+rHrfwE5 Z6Ja155AMnv0cUr+2NxV2bDiwsdi32yqgAGoX+h6naCrgiP+lG3XnDSuhNl3wvX4wGp6 7Trg== X-Forwarded-Encrypted: i=1; AJvYcCXAiHQtoOH1ZNt4NhmbjTxciCs1Dx2p/9rr/ge/exZYC09G5liDT7WmcVrZm35rrEY4uiwWyElOE92wM4Vb3Uz1Ri3B X-Gm-Message-State: AOJu0YxGcfremHzfAAxLwyA6R3CUlG1GLFUgk2A9IYZgl7FE/LLZYzBk S4Cu/cFQnSG5efhq5wY42E2sxcOJ8Tftirky4KjtTx2HU9Rvdu841sI1Tj579RmzoR8YG2EmoTr 1xpZ0Fg== 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: kvm@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: 13587989 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 60FC238FAD 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-60832a48684so51576057b3.1 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=fZVAp3nvcsohemBn8Y5Bb2VfQJKbHEvPR/Rbb826m6XLt1JHS639GM7pQqalPodg5R cq1GOIjzuyS8idltQSSETC8f/HiuA90TUW4V+mBlntrjFd+nEeYEuv0ObragDthF0whQ LxVMFE/QlcIo38zYv1o4M5UjGmWhW8JBqBQBLq8zH5rE3o/NmixRj4KIXtSq3nhwbYen V/0i+aVecFksDyGtpLyOjclEufyS2vVxc6dFjPovtqJkZolIW95ylTC0sNJOY1J2OUxm 577C1IovqX+tWL8p9qwa9rhXYnmFNMGF4vguq9KjnKaueMJYz6tmB/cfFneGjsHOMwLX V/Tw== X-Forwarded-Encrypted: i=1; AJvYcCVq4SdFPzESF5rVK1yuqQ4vsTKVxl5KLtrysn8knKD42uymeAF9pQZNigXNpmstlFz7LQwwihMIhUIrdcQo8QdHTvZ0 X-Gm-Message-State: AOJu0YzSD/Sg8d1HsdLc+r1y8y+kAUv7QaO9dKW0TRQ3EX4M3fv4nYja a9wJGNQLJItWitYvEqMNgSdK/FgbijDqW5hY/LDNOI+c8NnLiR1tXh1SBC1aQz2Ap/T1miubYUA 6F3XFvA== 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: kvm@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: 13587990 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 8A37639FFF for ; Sun, 10 Mar 2024 02:06:03 +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=1710036368; cv=none; b=H2t1g2Z4C4z9dfSqO7VlJoBrBSxqfQZLV4Mp4XeMeBEOx1ARcjsuqjRqEmGiEI0Eteyak9dZOG9LDDg7XWs2/HhCkQnPDpNe2ThOFrH/+ILhysemSPoN4CJlWUr2WDBQn2EQdzrr0P09BPZjLyTofsRD4dqSvufPt2pp3iPZQbw= 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.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="eYGgxAod" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-609fe434210so35619517b3.1 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=U+rBObsq6X+gJya3K0iQkBWpT1l4+Q2Crm9raI4uBaGHp/PCeLre7uzBn0ytdyPjKn XrPsJl5Cbrp1HkHLecUw3dVEDZoHw6I8oYV7/ZHGfZNo+PdMVWgOYG5OkA6+JrGv6Wb0 qWkxHk+gelcmYRIqHTARzT9URVb9mdFVLC+ASOBxYDOdUQgXHuxfJGs+VBvcdEBSc9g5 lOg68hvEF0/kQCIpt+HrLGUL1iXNuUKyf9cperG4gBuJiljXFpS9o9jLec17wXtPcTFE TS9eiz0HVTbfqR7I/X/3LQSOn3g8vuX+F4dgtUow1xkVUC09EVjMc5el/Mmt5DahUZoz HWPg== X-Forwarded-Encrypted: i=1; AJvYcCVlrPH4RqpjM0SJILcQbefl0jCo1sDlhrttuje34p/joBdb75p9Tv6RkrB0eMIipK2yrnUvkVJf7njIj1egBD/A8f/K X-Gm-Message-State: AOJu0Yx+8EZXio5mr3BfOnW/ljvLHXcAUKjGnuhj0ssC+Cp99ho5972Z mm64ckN1Naj9VwrXXPpwmuRzMd8fFz8t9oK0hS4GhEit3oN5wQpVYdK1NLqn8sHfKh2dEL+Z9qX 4ieUdFQ== 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: kvm@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