From nobody Wed Dec 17 16:11:07 2025 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 41B25192B86 for ; Fri, 13 Dec 2024 21:04:35 +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=1734123876; cv=none; b=na2emgqPYmvaa9rYOeMwIANjTg4ZzcWHjQZCgWxxd00lhODEXiBHrAyzhq1YaMkG//B2QYGOsIHucHtZz/vzjJWR9XiEivDFj70PXAceplBMVOrwfi9ptM4wNss6YlcTCH/TKDU281hQBLpGwJbNsyOy9HhLEV8znPQID0Sh/7M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734123876; c=relaxed/simple; bh=S9oJ5nvUyNCQs4RFbbxftBNA4JqtJFj0IOYK/XGlb40=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=tIzyx+uVoPBmh4aZaMLw7HvOuGKjxD3PItGScjf8Y3CbbP/FxnAhoPWlQmVvY9afBfP5DSfWWYLC6WAOtdBOzTKDg1UOtHIY15/8K11zNudTkowpzSVpQPtziYDK5kzH524woFT0q60vCKB5ytEq9g6nmVhzvDGsYryCRtVow78= 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=2qHJyB/z; 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="2qHJyB/z" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6ef4e426a3fso20029327b3.0 for ; Fri, 13 Dec 2024 13:04:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734123874; x=1734728674; 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=WNAmP2QIXRRPXgUvgn+lR3CXU9fGdjYzcf/lM/XtA7E=; b=2qHJyB/zv4Oyn0C4mqJFE9mlyfic4e2cQ0tlgxsGa/qQ7gXdd7os3eZ+PUP8rz0BQA UslPypsbr1ifJMqZuBzYJtJo56yW3n7DMdkFPbIPHh7IQ8hCZaNRVsl4X8m1yBeC418T JS4Ro+OVSPjOnLcC3sJC7xLIUrwHZe1Ip7/n65Lrf+IyH54dYv2xVCi/k0P6PxkeJlo3 RWENxBvr3FN/4ZOSkPTyTD0srt1VmpHl/Z6rz4P2vAIiNRRY3TZHi7LvQ0N8KNZxE5Om hRyZAFqsG7xvbhyzDzXAnpN9EoiEyPpl3y2Dik3nlJ8kf1YHXrv+YWVZlfcEolphossg ViXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734123874; x=1734728674; 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=WNAmP2QIXRRPXgUvgn+lR3CXU9fGdjYzcf/lM/XtA7E=; b=PDA1u+Sy3zrvwboS+F3qqCZrj6Ii/Fnh7xu2hWqnpmYJyf4wWxqp1FhTaQbf5aj8Nd WSBJNd6DWLjrD99SD4kJN2m0R/py7OENOpCi4jiULiP+i4gMS92PATUdXmyiWCTcxn7D uGiSgh0tAiYDwrkbNW0tWXccDM2icGrT0/Uv87lPa9lDR8ItDmrISF2z+IbnMiVNrOgg at3Ik1njsvxODNWQo2UIyyhGyXxZcnYRPKeEY8MByTzgQoE6IFIUl+XQL9xBSprL1fE1 SjpZxhUewcc1VpXgcEYg170L7Ikox3u9fk5Ex4Fas7IRXCqgnP+B2Xk13p3qrJC29UL8 wdUA== X-Forwarded-Encrypted: i=1; AJvYcCUGo+uh8TdPSsY81K54FTfeCgjIUY9xFXQ9RhMLBeuUvwSBk5tnHdu2TQyMmI206EqOgcAXXfBDd5GnJSg=@vger.kernel.org X-Gm-Message-State: AOJu0Yw3HicgYoN451YR2WPEuOnHh0aRtmC0S0wAkmXp5H58omCeET5Q jDDxFWqXkEjiml3b8dqJL51kXHVLNFE4w6v5M4yM47u1hXhGeZwKzx1aeZMIuC38Onwy2aEz2uN PFimuQg== X-Google-Smtp-Source: AGHT+IHQnJ8AwzFR+/gCmsmiNG9OlGzkCbBAFmQ5ZaR8gDuemwKOAK/7yUyedwJUi8XDw10fkhpSLVZKmo8q X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:9a50:5183:644a:3472]) (user=irogers job=sendgmr) by 2002:a05:690c:2008:b0:6ea:1f5b:1f54 with SMTP id 00721157ae682-6f2798ef726mr136197b3.0.1734123874200; Fri, 13 Dec 2024 13:04:34 -0800 (PST) Date: Fri, 13 Dec 2024 13:04:18 -0800 In-Reply-To: <20241213210425.526512-1-irogers@google.com> Message-Id: <20241213210425.526512-2-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241213210425.526512-1-irogers@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Subject: [PATCH v1 1/8] perf disasm: Avoid undefined behavior in incrementing NULL From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , "Mike Rapoport (IBM)" , Wei Yang , James Clark , Howard Chu , Kajol Jain , Athira Rajeev , Ze Gao , Weilin Wang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Incrementing NULL is undefined behavior and triggers ubsan during the perf annotate test. Split a compound statement over two lines to avoid this. Fixes: 98f69a573c66 ("perf annotate: Split out util/disasm.c") Signed-off-by: Ian Rogers Acked-by: Namhyung Kim Reviewed-by: Kuan-Wei Chiu --- tools/perf/util/disasm.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c index 2c8063660f2e..e8e7a8257007 100644 --- a/tools/perf/util/disasm.c +++ b/tools/perf/util/disasm.c @@ -389,13 +389,16 @@ static int jump__parse(struct arch *arch, struct ins_= operands *ops, struct map_s * skip over possible up to 2 operands to get to address, e.g.: * tbnz w0, #26, ffff0000083cd190 */ - if (c++ !=3D NULL) { + if (c !=3D NULL) { + c++; ops->target.addr =3D strtoull(c, NULL, 16); if (!ops->target.addr) { c =3D strchr(c, ','); c =3D validate_comma(c, ops); - if (c++ !=3D NULL) + if (c !=3D NULL) { + c++; ops->target.addr =3D strtoull(c, NULL, 16); + } } } else { ops->target.addr =3D strtoull(ops->raw, NULL, 16); --=20 2.47.1.613.gc27f4b7a9f-goog From nobody Wed Dec 17 16:11:07 2025 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 6F1D7194AC7 for ; Fri, 13 Dec 2024 21:04:37 +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=1734123878; cv=none; b=pb5ugkUdjPqFZFy5x38wUThk7OfXbmIiKni4lNP9ApM5JdOc9sCUcjftEemjWumYCR+0xsjwfCBDw+MLNoJegaeHy9Ry+03T1gaqwcwl4+FXeS0G6/9rEfaePMDbnxFL1d8mQPy+JT3SHN3dgrJEJVIbfC31tYPPFUOZEPFQ5iY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734123878; c=relaxed/simple; bh=4pKzkTV7w7BbOGxOqcD1NuW63SK6U/7k+L92iQDdz8k=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=A/vpYoMeQuXE3r24ic7eTqIBmV8C0F3hNFaCX+L9v9XLN82OMmeC5tC3UXLNLMCPQfQlhsyiMFePM8Cd3TYXtX4UTlB+WQQgJyZd5EGyeUCe5p0JhvWg7yX2xyCnnhEbXQkhe2P+ZYdapkcOESxyem1fmo07uJdD+VMyCIVROII= 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=yQu0MsXu; 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="yQu0MsXu" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e38d8aaeb4aso3133940276.1 for ; Fri, 13 Dec 2024 13:04:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734123876; x=1734728676; 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=vioVLOwmrwPBoDuHBo/JSaFU3XJwmvCOkzBZLpYE96Q=; b=yQu0MsXuMk7sRRsTYFtqEO+sATyce382HPFl86s837Dq2rvhpaBSqjExIiEIzo2Efh 2OpJP65Z0u963yd3ZSTCLgUT0s5iOek26u7EhFwDJ9JgnzYRtvk3Lg+vREDKwcGUvkkM DN1UGnl7rHA06II6CbxFy4t+o4D60RBmcLZpUTBM539E/+3V3kq54B633bBjSReG+P4p uXMmicUgmCdaKQJ7mIRyLiQSWjSl8LrRBoa3qs2Xizz13iFUKojDx+5bFvrEVESVegMy xicltQjMLPAGQYY+wXXhSEthWwwhYYit2fpUQr1mspA0dNjQJvNOJjWecOjJaNXpoLMA lbTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734123876; x=1734728676; 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=vioVLOwmrwPBoDuHBo/JSaFU3XJwmvCOkzBZLpYE96Q=; b=vqszeWcsJgLRl2maDV6kyOxCafURm00vM2g6nH+lUhqWiIPhn9sZvNWl4voql09AIu LtsDTB/k/o3Fj6D49SYL9a/GcviZTXYZZV/wMi5hVDCHMwkPbg5L9VXgwtGFx8IICfte 2v310tkLGrE2blK/XEIX1ale6SyBbwJ0Qd7SQHQrqEwRKLo6IYrn9QwF3nZq3kMUn/gC 0x9OSAiCHsBU6+9o9+OW3gnXGQPIYwElMT4GsuEp7dG4qSSJmTV+qSjbHXnfVQ/Bp9PK gdzSoeEPFvAhi7IZuHKDgVYrVarxO0t/NwXReCYnVsy3PFWzeOCJupAbrdm+2p0OPW56 0Psw== X-Forwarded-Encrypted: i=1; AJvYcCW4YJVwtRsj1k/HCaqrMrRYHKm+8YDwkdneLBd91J6jYul9ka1yIF7rOqy9uxUaq+QL5sDivWXpEzZmqa8=@vger.kernel.org X-Gm-Message-State: AOJu0Yy8FpP9Nsg9uI4VrvSccJ55A4jH/GElWYHg/YRZjVms+OskiPYs TjqX6Vugs+IoM3nVTypbESY24S7eNQp+ti29Jr9seQ5g6x/W2xthl0tQjz3NW/arX47h7WMqMfF lDduipA== X-Google-Smtp-Source: AGHT+IFJoR+VUIap2R8w7wBB5lIJC6iiEWzTJTmaxzdCenTqSqXLAehauJytbWIoze/wqOYJJA/lOzwErMku X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:9a50:5183:644a:3472]) (user=irogers job=sendgmr) by 2002:a25:a34a:0:b0:e39:8650:5cff with SMTP id 3f1490d57ef6-e434a06de27mr1841276.4.1734123876288; Fri, 13 Dec 2024 13:04:36 -0800 (PST) Date: Fri, 13 Dec 2024 13:04:19 -0800 In-Reply-To: <20241213210425.526512-1-irogers@google.com> Message-Id: <20241213210425.526512-3-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241213210425.526512-1-irogers@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Subject: [PATCH v1 2/8] perf test trace_btf_enum: Skip if permissions are insufficient From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , "Mike Rapoport (IBM)" , Wei Yang , James Clark , Howard Chu , Kajol Jain , Athira Rajeev , Ze Gao , Weilin Wang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Modify test behavior to skip if BPF calls fail with "Operation not permitted". Fixes: d66763fed30f ("perf test trace_btf_enum: Add regression test for the= BTF augmentation of enums in 'perf trace'") Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/tests/shell/trace_btf_enum.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/perf/tests/shell/trace_btf_enum.sh b/tools/perf/tests/sh= ell/trace_btf_enum.sh index 5a3b8a5a9b5c..737da3113966 100755 --- a/tools/perf/tests/shell/trace_btf_enum.sh +++ b/tools/perf/tests/shell/trace_btf_enum.sh @@ -23,6 +23,14 @@ check_vmlinux() { fi } =20 +check_permissions() { + if perf trace -e $syscall $TESTPROG 2>&1 | grep -q "Operation not permit= ted" + then + echo "trace+enum test [Skipped permissions]" + err=3D2 + fi +} + trace_landlock() { echo "Tracing syscall ${syscall}" =20 @@ -50,6 +58,9 @@ trace_non_syscall() { } =20 check_vmlinux +if [ $err =3D 0 ]; then + check_permissions +fi =20 if [ $err =3D 0 ]; then trace_landlock --=20 2.47.1.613.gc27f4b7a9f-goog From nobody Wed Dec 17 16:11:07 2025 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 CD811198836 for ; Fri, 13 Dec 2024 21:04:39 +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=1734123881; cv=none; b=DNkBQg3mgV8H7KvDZFST0ymNqXMQsHbagbJVYqZ3ohNOS6k1ze7xe7t6n+dSyCtWFNKK0dw3VNUVNSwB9K5Ha3PXgvG7V+pNYLgwrPtJ3tMnVKivVMaP+Eglg0VbldI7j+h350UAgyEqf2xSstkhA8ssySuQu44oNfK5m0abY8c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734123881; c=relaxed/simple; bh=2AeeJI7hTLZBkAiyK/DWI/sFdQ+nhO6KpS8lk3LdjMw=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=ZG1WKkRAzdXZTnvnNSNQnatTofh5ULLNAcRiyax/4qhyFwuQLWElyubpPdMKjwY9Fwql9ce4VxqNuDtq0hiTIyvYQCCT16PiXJDPzadiuj5omxROUCkQWLJhst49HV0HCMiKuPb/o6RPduw58pbkwaYOT1gzDMXwEH9h5Xdr8FA= 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=Ywx6XmXO; 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="Ywx6XmXO" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e38dbc5d05bso3365824276.1 for ; Fri, 13 Dec 2024 13:04:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734123879; x=1734728679; 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=BO6MitYTG3PPlOm9eDgi+DN2s8ThN2cAWOELNwnMFAI=; b=Ywx6XmXOlGyb2ROuRL5cX+rWOMyxHMIt+9ORbsIOOAzXmhzkC7ppw0YX/mh3jIELFn uIw7zWokZk0e81aaAIs0ttHziMaN77lMvDAxstfFMKD6fkCz896sg8Lw09T2L0PD2pnn XsqVM+J0D/KLFpKBz8hcym1D0bXI/pJwDIHFvY3kImtyQU8RbtnE5E2jMf2t6TOMYBw3 kXjZCmCTfx2Cp7xUQh0Gz39SWphyD92GJmw1fq5+ET+JIOJnZat5NSfQkeE688/3aTDM A2CnxGjmBQhBXeBGCGsHw9bmiCIv5DUZpXUSmYt3Auy5gOFVGCr8uALtQEZB8VdZUdo2 EY/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734123879; x=1734728679; 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=BO6MitYTG3PPlOm9eDgi+DN2s8ThN2cAWOELNwnMFAI=; b=DfdlIkrE3/IzU2qZmpyRj09Kb342tS9vcG5eyI62+N5W1gcCDU9lO7CE6brQ//iN3+ hracKIsGGD3/gqT46tZtwXeoJVO60yjSl7NmtAjNBaIDL7NK1Z9ym6wt4+mfXs3WboSf phzOv2lKdECir/V/Km6jt9qJYWjxIIXfVc1xV4hS8JfqY5pyJzwKjy46SC9XckNSVx6E 0BQe6Qe6k2Y4dnRlKWUlDD/8nIpx/iHlfzejWx9dpVYZNiwV4J0kPtU3oWWQcTeb/MKu ZHJBQNPGcLjm5p/wMglf2qcpvQciXAvjhf0s/fA33qJ6qSm2ELLjH0t4GQFDi7G56653 1dww== X-Forwarded-Encrypted: i=1; AJvYcCVTWzy84FwQs7Y2cf5cqRNU94EOrNr+3kymWViECYgal5tsPgQK57yA4G9QQkgRx3+F+dXFsbURtM0Iajg=@vger.kernel.org X-Gm-Message-State: AOJu0YwGVRqzzjKeLl/sKf4sBySbi7rQ2SBq/EsRuukTCzV2fW0LdpSW F6N60YA1uOwVmez0DFCq+H4mRvfPQhfpxIvXU4LMjd1tf+wEKZxAwrecD0WuOtl0pkahDtPo28o mQ/5SSQ== X-Google-Smtp-Source: AGHT+IG14QG/FvZm1o/zP6GcRY5++gc+EhOPsoB8hincRJ7FgCV5ULq+tkuBgEV+o3KlfVnsbI/svufofT6h X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:9a50:5183:644a:3472]) (user=irogers job=sendgmr) by 2002:a25:aab4:0:b0:e39:fc33:e15e with SMTP id 3f1490d57ef6-e434f94c734mr1534276.8.1734123878723; Fri, 13 Dec 2024 13:04:38 -0800 (PST) Date: Fri, 13 Dec 2024 13:04:20 -0800 In-Reply-To: <20241213210425.526512-1-irogers@google.com> Message-Id: <20241213210425.526512-4-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241213210425.526512-1-irogers@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Subject: [PATCH v1 3/8] tools headers: Update offsetof and container_of From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , "Mike Rapoport (IBM)" , Wei Yang , James Clark , Howard Chu , Kajol Jain , Athira Rajeev , Ze Gao , Weilin Wang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Update to match kernel definitions in `include/linux/stddef.h` and `include/linux/container_of.h`. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim Reviewed-by: Kuan-Wei Chiu --- tools/include/linux/kernel.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tools/include/linux/kernel.h b/tools/include/linux/kernel.h index 07cfad817d53..10f74f021d55 100644 --- a/tools/include/linux/kernel.h +++ b/tools/include/linux/kernel.h @@ -21,9 +21,8 @@ #define PERF_ALIGN(x, a) __PERF_ALIGN_MASK(x, (typeof(x))(a)-1) #define __PERF_ALIGN_MASK(x, mask) (((x)+(mask))&~(mask)) =20 -#ifndef offsetof -#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) -#endif +#undef offsetof +#define offsetof(TYPE, MEMBER) __builtin_offsetof(TYPE, MEMBER) =20 #ifndef container_of /** @@ -32,10 +31,14 @@ * @type: the type of the container struct this is embedded in. * @member: the name of the member within the struct. * + * WARNING: any const qualifier of @ptr is lost. */ -#define container_of(ptr, type, member) ({ \ - const typeof(((type *)0)->member) * __mptr =3D (ptr); \ - (type *)((char *)__mptr - offsetof(type, member)); }) +#define container_of(ptr, type, member) ({ \ + void *__mptr =3D (void *)(ptr); \ + static_assert(__same_type(*(ptr), ((type *)0)->member) || \ + __same_type(*(ptr), void), \ + "pointer type mismatch in container_of()"); \ + ((type *)(__mptr - offsetof(type, member))); }) #endif =20 #ifndef max --=20 2.47.1.613.gc27f4b7a9f-goog From nobody Wed Dec 17 16:11:07 2025 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 EFE5F1990D3 for ; Fri, 13 Dec 2024 21:04:41 +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=1734123884; cv=none; b=sApMu+X1IwQavy2I/tphXHkcRv/+b8MGudnTj2Ne0nNrFVnoZ/o4O0OnOKR3lURmakqwX35ZazxUxIDf0dymun2lZWHF91mUMBLlrAM2t00p2q0pTgYLihJvRHrPlJkhP9eQShYudQkVgvvihprzcAx6foMFj2qp5DA2Tm8f/18= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734123884; c=relaxed/simple; bh=i5e1b7t1EPpevqJjKlGFUSU+o5EL+PeGA8k4xzs8Loo=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=tX2JWkArf1kvTMCcbAv4JvmBTz2ciTkIX+OPlQ06+JAxunHKeiBu9QiRrO9I7GZ05p+55fSn334Hrv9yZufoDEqElNuBGiDhOt36e4NvQgt7ctPhTYbHKAnCWHvb4F5lqKGaBeOmw4P3DpnMlO55kNUdCn4DtdSqcR9i8ZO06Yc= 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=q/AW9b31; 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="q/AW9b31" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e39993d8594so3270614276.3 for ; Fri, 13 Dec 2024 13:04:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734123881; x=1734728681; 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=jve5UrRFX8lUtfG0zKrFxVw3qJ0NTFZjVOZjxLZ9cVg=; b=q/AW9b31AwzdF2MPgZyiRCOZm8jMoycmBbP8bwFiuQ4KVPGi8yRxHagzUmPfUsI/rv nkdhfz0LVHxaP5Ju+TUZ9vynOea+c7Ij3cOKDJfIbK3t/q9nt2ulCevkt8akkGoaIDM1 V27Gf2ISysII2zr4AX7ZzDhi8NpJYb7ehdWZxj0ZoRJTIm/pn4w6/aja3y6GOk5a6/hD ifaMASLDHl/F4b04rbC1POX6yc5MRf02nebueSZ/wgysXEq99ChiR1VBGcRxXnao1CvT +qnB1oCMGYpxOTqrRXt0AyS3VKitm9dvGnrCpNk2KC/mx5VEmi7eBEB4n6YLxV0dq+6P lW9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734123881; x=1734728681; 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=jve5UrRFX8lUtfG0zKrFxVw3qJ0NTFZjVOZjxLZ9cVg=; b=Y+7EZ5jqCU41ayki46L7MBopaxlzL3LofUie8ZVVdljzoZVIOJmpUE9zad40jbbTQ/ y59oYhbLvFAizxAuwbpNKoTDoZDWlx3BehCoGcRcO+68NavVZf3WN9JnC9gjIjSGrjzK VrmcyzHEvhUxkdefjcDUAIGJladp2TuePiOR9XrsMP4dda87AacRAH/ib0cELfOOA0FO 9AWzhfaiWsabPsUzWKUfDSoJatkKQVyHOiOnngRcl6/2Wcnr1Hj4noOO2InFTm0An7QU O7NCw/T2jLLzauNjHXs2ImDno6KLIQ95H2rb0IMLRbt/kplStaT2mHnCbNNAyCvWF7QF 5dLQ== X-Forwarded-Encrypted: i=1; AJvYcCWQiQs0ERIUqFFCOsDnXfaSPOST84yIH6rc6FqlWrR3lB9j0PHKSATgWc7bOL/9JmkWXda7+xHB3xYVYjs=@vger.kernel.org X-Gm-Message-State: AOJu0YzRAQuU+giiR1B12eSo0tbkAjhC2fOPKmWXptbCghkUHj8CSKvo grSvK/Sj8BGrYrFzClcrwGAjdJTe3gAJmIyIO8MiN6g03CRYDewxncRwXts+Wv1caW5//gDVFlI WNJ+HAQ== X-Google-Smtp-Source: AGHT+IHENPzULra0CGF12H7jvOCHRuu8SzpjakUA14QaljJ4wh60e2ID3JmDlWJVD01OmUAMdsqmIhpWRjOY X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:9a50:5183:644a:3472]) (user=irogers job=sendgmr) by 2002:a25:aa2c:0:b0:e39:b4ca:3dc7 with SMTP id 3f1490d57ef6-e434a259f73mr12504276.4.1734123880992; Fri, 13 Dec 2024 13:04:40 -0800 (PST) Date: Fri, 13 Dec 2024 13:04:21 -0800 In-Reply-To: <20241213210425.526512-1-irogers@google.com> Message-Id: <20241213210425.526512-5-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241213210425.526512-1-irogers@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Subject: [PATCH v1 4/8] perf evsel: Avoid container_of on a NULL leader From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , "Mike Rapoport (IBM)" , Wei Yang , James Clark , Howard Chu , Kajol Jain , Athira Rajeev , Ze Gao , Weilin Wang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" An evsel should typically have a leader of itself, however, in tests like 'Sample parsing' a NULL leader may occur and the container_of will return a corrupt pointer. Avoid this with an explicit NULL test. Signed-off-by: Ian Rogers Fixes: fba7c86601e2 ("libperf: Move 'leader' from tools/perf to perf_evsel:= :leader") Acked-by: Namhyung Kim --- tools/perf/util/evsel.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index cb6952b6d9d9..dc427eafca6c 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -3327,6 +3327,8 @@ bool evsel__is_hybrid(const struct evsel *evsel) =20 struct evsel *evsel__leader(const struct evsel *evsel) { + if (evsel->core.leader =3D=3D NULL) + return NULL; return container_of(evsel->core.leader, struct evsel, core); } =20 --=20 2.47.1.613.gc27f4b7a9f-goog From nobody Wed Dec 17 16:11:07 2025 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 439B21A76CC for ; Fri, 13 Dec 2024 21:04:44 +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=1734123885; cv=none; b=HKgEIWn/Vd9PcJCuBgO+yYvF6i0bEUofuPWdXz54z8sjN/0OtsTzYrctSRQ8RcCcHBS/Mw+XyZjTPCFVtwCi0DxEGxJAZO+v1m8YBILcJa+6gpE9Yqg4HpdL4NAHEQmqPqA7DZLgJgjzcMx5sV1+k1jaNk95j9NPEDw79fgr7DI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734123885; c=relaxed/simple; bh=9WsK29GipO9NFsc3hIC2PewS3A5xwy+nUOe36/bHbco=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=iLhfYa9rkPs1NN2+MYU1MOczEFHrfkH4ekWP76C2tEn6Yo7OP4xMW+NNDht+mZ4rwQ+Dy72jx4dFfzEUE6OPQRQYxpDf10nZbl1TR+FZ6AywR909Hy/FE1rTGUz59uwzVeZdd1MeWz6duvjOxMQPeGUOJcZmfENKVAQWqA1NaCk= 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=fVw56T1W; 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="fVw56T1W" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6f013249180so42998557b3.0 for ; Fri, 13 Dec 2024 13:04:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734123883; x=1734728683; 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=ZmmTceEXI49vAlTZsXzZ0kDXlU3YmEJweJHtvtDSTLk=; b=fVw56T1Wn/gfOSCeDetmk4e6M794RU3h6CkdCEk7SKpqbgtdChuB2kX7kwrwz58hlg NzAkhu/v4G96mrxYwcMMgSBeW05ZY5neAnmIZhDfyshBywal8jcbz18eGy2xT1q6VbYK SY0w9Nf6g6l4hvQGqv8QWmP0Pt2dWPBlUr+dfM41LJ1aGOUH6x4rnDQxHYwax8KPgi6t 5JQ7bNYd1+JwF4O6HpbAxSzszpK/P/L8eDpvit2n9+ggh230OgR4ZvBQMX8UwKywLbPH E5YmxEc5w9HxE34WxeyRTW5rIXm3YlLrCErRc5Cj/KBs2l3ReMTzbiuP8hn8tuGnaGKg 9ecQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734123883; x=1734728683; 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=ZmmTceEXI49vAlTZsXzZ0kDXlU3YmEJweJHtvtDSTLk=; b=J/PpVAde/6vcEm5gVKQR6hqZm+obAYlb2wJlGoi8I/xNrnpX8blTl3KtLHtbtNFDb+ cYRnX3IrDNDp42bHyozuJeD9RDpnSs73Iav1iaN8mDjqBkDLKf+l69bohMScPu52zgUB 00Xen8LGiPjxaZXFUcm3h0eyBbPVjGDoXl/894NXun7xICPoNjYPJ/iZvaSUL0OGBCy7 AX9r/Mr15GZoWNLCKPod3lih3neY01NgSADQDzx6Tz8PBuMbSM/qYtctEEE2P3EwZ61l toCPoI05i6cIidKuHUPHJZZBLmMCFLvDIQjwkNZv5WIWdwoiMBfzJdkJ1Nr4wEd1mEDH t60w== X-Forwarded-Encrypted: i=1; AJvYcCWmA/s+5kZaVWzu8VvkAIURDkCrerHP0hw8vqcrc188pxXRPat+4s/os+jJQMqDt6tyvYHhNxOeS4bu77U=@vger.kernel.org X-Gm-Message-State: AOJu0YyRL4lI/l0DghoAuUXDSsABfiPLWNGe9F8lwuQoYO1fvWiA1z9s oRU5NSmlg8BgVsme0TM98MGnWLxKO8LiB3pWZBOFoC4Vz4rJQCBgwjPz2YtCq046fowJwEzXak6 JlAn9xA== X-Google-Smtp-Source: AGHT+IHpiKviovMECOth7u4kOhfEglD8RAZ2s+tFKqdgpPkBwtpkcy8GbhxAXictuSVtrav/UTjOTS2cR59l X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:9a50:5183:644a:3472]) (user=irogers job=sendgmr) by 2002:a05:690c:26ca:b0:6ee:61ea:a40e with SMTP id 00721157ae682-6f275c1849amr58497b3.2.1734123883146; Fri, 13 Dec 2024 13:04:43 -0800 (PST) Date: Fri, 13 Dec 2024 13:04:22 -0800 In-Reply-To: <20241213210425.526512-1-irogers@google.com> Message-Id: <20241213210425.526512-6-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241213210425.526512-1-irogers@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Subject: [PATCH v1 5/8] tools headers: Add non-NULL assert to container_of From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , "Mike Rapoport (IBM)" , Wei Yang , James Clark , Howard Chu , Kajol Jain , Athira Rajeev , Ze Gao , Weilin Wang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" container_of on a NULL may yield a non-NULL, confusion and errors. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim Reviewed-by: Kuan-Wei Chiu --- tools/include/linux/kernel.h | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/include/linux/kernel.h b/tools/include/linux/kernel.h index 10f74f021d55..8d617467c5c5 100644 --- a/tools/include/linux/kernel.h +++ b/tools/include/linux/kernel.h @@ -38,6 +38,7 @@ static_assert(__same_type(*(ptr), ((type *)0)->member) || \ __same_type(*(ptr), void), \ "pointer type mismatch in container_of()"); \ + assert(ptr !=3D NULL); \ ((type *)(__mptr - offsetof(type, member))); }) #endif =20 --=20 2.47.1.613.gc27f4b7a9f-goog From nobody Wed Dec 17 16:11:07 2025 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 600A61A9B5D for ; Fri, 13 Dec 2024 21:04:46 +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=1734123888; cv=none; b=cJfxnHLHdK7c/G67d1gHf8zIL4aj9eYtVEsgUI/P5eKIGhALAz/IdoqXwkMuZgm/Jcem66jBOxciXnAZ4hVb2Kqfb+YsUSwiZw2SDxjaX/K0Mj/LU025BoZUpBX+gvrUc7kaBhLKt9w1AEA8z/fhs0d5xxLme6mcpEpS4drmgZc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734123888; c=relaxed/simple; bh=5BfNct9byh0W7AC8JMgEtJwAR7Xw+iCYGpMPgd4MCTk=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=InKY8QJhUfVk5HWi1QRiJ9RF+GvepqwSghGIgKSpHTEBpIlPptAsh4qGTN65knm4p8szc38qRct+j/xnkcraO83n0UeutIcamkbu6Hq4/yPQZMvoUHku6d7FuTU6gDIy2QJ2SXYaXdCuOiH5FE9uAIvqxOgJhYwx75pOSYGUpaY= 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=XA48kZVA; 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="XA48kZVA" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6ef66fd6e78so26784467b3.0 for ; Fri, 13 Dec 2024 13:04:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734123885; x=1734728685; 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=qacuxPXKAwtJm5TN79eg+JxRwsGOSsBYxYDQ++eqYog=; b=XA48kZVAUrfWTBDXjz0jXrBBzFbDknSBz9MSMzV17wcTW5cBoomstUvDr4fXk9qLHE Obp1zaBIPtdK9UxUsBvezfR98ALdmz7bHv0EusHE5Z2qO+BRGPjFr/jAVBa4YxLzMak3 Bq79DQIUVm7yll7HFmrbBAYZzOf36+KkNnrgvauJTbCh6M/4tFQLUV5d7ddzXDE0zpt8 0MrRE65swRWmKon/Z7hMX6ERxCQoffIgYCMkLbmBdmDasrknJWidDce5tVcIxUVfHcqo 2P1o3FY9rh2x2f0bVP2jXQrxYLR4/joHyk5YUBm4NIPU8l61pEnXXq9afxB4trXVaT5H Vkqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734123885; x=1734728685; 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=qacuxPXKAwtJm5TN79eg+JxRwsGOSsBYxYDQ++eqYog=; b=tteKyDzjWrxGQ9+MMAp3QqfcG4kB3Tt2DnB0dzSDiUqclvn8uxGzgamjAep6H+6kuI 96FbpoAqQLGX5rHRONRi0fWs1vzk764rEM18kvY4sfve/BnZBoq+AEiLjSH0kMLIzNLe 62fTSQev/V+0Qk42eDXamCpk8ijk+u4s2pfh0ASZasg0trAaRRvn52IzbdYf248q4NBf YtMx+JlKu/fkZoAemG37SDVIuujiea5UuYKoK7qqDNivL2QhCGfnPXMZWzQsoO256Pbn WRzv01KYbMGJSw2kWEu3DJQ8cjszw38m2HfxmO3jrQ5WhcSJtM0TdUXTWI+E18x5/opA oYvg== X-Forwarded-Encrypted: i=1; AJvYcCUPN21vtcQEFUK+l93B8F/oNQpW0rgk01wyP5cKLEoj2WKF23dBmPgFYsNhE+P4+MUQtGpNXrwRVEYwDh0=@vger.kernel.org X-Gm-Message-State: AOJu0Yzu58YzYvRHhCs3VcTDkCucSXFO50rIdh4LSKCd6WKH3HvSzG/M NWGh64n5m7sA8StlfmGuWcQcfMqJBBRBgljVptkJkwjh+w42Wa9f5fgzE18DYAR9Ny/zEMqSKO3 5rfa9gQ== X-Google-Smtp-Source: AGHT+IGqgycsnZKrksHy4v4iYMpl2ufouZips63Cp16d5p+/jtwg0UiMEdUsO1fDqochqw+p2D+Qij9DCsMk X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:9a50:5183:644a:3472]) (user=irogers job=sendgmr) by 2002:a05:690c:2b83:b0:620:32ea:e1d4 with SMTP id 00721157ae682-6f27a84e636mr66297b3.0.1734123885537; Fri, 13 Dec 2024 13:04:45 -0800 (PST) Date: Fri, 13 Dec 2024 13:04:23 -0800 In-Reply-To: <20241213210425.526512-1-irogers@google.com> Message-Id: <20241213210425.526512-7-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241213210425.526512-1-irogers@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Subject: [PATCH v1 6/8] perf maps: Avoid UB passing NULL to bsearch From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , "Mike Rapoport (IBM)" , Wei Yang , James Clark , Howard Chu , Kajol Jain , Athira Rajeev , Ze Gao , Weilin Wang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If maps_by_address is NULL it is UB to pass it to bsearch, and will trigger ubsan, even if the nr_maps is 0. Fixes: 659ad3492b91 ("perf maps: Switch from rbtree to lazily sorted array = for addresses") Signed-off-by: Ian Rogers Acked-by: Namhyung Kim Reviewed-by: Kuan-Wei Chiu --- tools/perf/util/maps.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/maps.c b/tools/perf/util/maps.c index 432399cbe5dd..1830ae776052 100644 --- a/tools/perf/util/maps.c +++ b/tools/perf/util/maps.c @@ -1042,10 +1042,13 @@ struct map *maps__find(struct maps *maps, u64 ip) while (!done) { down_read(maps__lock(maps)); if (maps__maps_by_address_sorted(maps)) { - struct map **mapp =3D - bsearch(&ip, maps__maps_by_address(maps), maps__nr_maps(maps), - sizeof(*mapp), map__addr_cmp); + struct map **mapp =3D NULL; =20 + if (maps__maps_by_address(maps)) { + mapp =3D bsearch(&ip, maps__maps_by_address(maps), + maps__nr_maps(maps), sizeof(*mapp), + map__addr_cmp); + } if (mapp) result =3D map__get(*mapp); done =3D true; --=20 2.47.1.613.gc27f4b7a9f-goog From nobody Wed Dec 17 16:11:07 2025 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 EC1F8191F77 for ; Fri, 13 Dec 2024 21:04:48 +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=1734123890; cv=none; b=FT67UedCMZS/TjhvlsAKy6/heHsXj2f/Mj/N81/4RBy4pASEwA4zrb9Wn6sGYhFne218oLTfNUsh0hsJHq4H0clcKIgBNa0qBQtcCKbuX6PP8/XNiFeKLqnCIWfcla4lwz2hXkWrlpKPc4JED22OHIeqZDyVnKGVMkYafj8BJFY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734123890; c=relaxed/simple; bh=d9YNPgdNgMkETeghBcHzn0sIBvBbcXrmt5TQaVmypKQ=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=AuCy0Cmc+DkNKuYgClOY+6CQ2VDQOpnpNkU+/YtyROPhu4ysTnu+Vpj1RZ9u5Zp+MWMD80+lNS9CLstNxVRxoceKRVYlR27MbE+9LZTUo8aqxOIAf7Uc13erddI62vfCOifm9PgMF7Qe+wTXzJa1u0gG8Th0ipRJD4dgQVRk574= 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=lvuqtUql; 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="lvuqtUql" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6ef66fd6e78so26784947b3.0 for ; Fri, 13 Dec 2024 13:04:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734123888; x=1734728688; 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=roSkHT8n0+uAYrLbv39Z3QAFR3sxRwlfuGzkTHlXRxc=; b=lvuqtUqlmgWa7/fzymT90c8I6mBTAEZ2cGa/YA7F5wuIWqrM8D6hTbXc7B/h89Ft3S +qUaNv7wFYA/NeB/lav4npWJBio1g8SFCim8Jn3FMMY6FFhtt2HRGeNda2QGSw3gE8Tv lVEfdh5dR4HfhhKW//BhU+diuL7Dy8wdmxMq6cAiNKn4PM0WZuiaxa4Q4HFpr9UNvmtL d+7F47LnrYPqefHNJIJR+Sco6M6U0F/vfcLH0yYCiq0/NZovIuhmO5He/z/cQbiPSibz nQSd+O/K9ZMMz0DDdfl9LJ8Kdj1QZioDDQQByOGk5WF90LQXyj2sR2B6Veh4KgwXUdYP hMBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734123888; x=1734728688; 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=roSkHT8n0+uAYrLbv39Z3QAFR3sxRwlfuGzkTHlXRxc=; b=RZ/8lggcABk+8LZ8226jCNJ6iu7AjaMykmPls5IrcAhR5I9a8dmAgE1wR1t/rrvqud zMmvpqnsmzmpOPmsaL5DxrSL7Lh9oPxtbGJrF6tlD+//nGV4P57E64l1cyOYlsGWYMtU 0MZqsxG1sHYOJZ7VHnVfZQQnMhS0wwvQvYppbKjFxQ2LPiYJ+WqnlYc1vkj5qdjFVsSR mSxiQPsTsFFc/aL7x6u55xhWUZEYSTEjzW8CV5bbRamiQmSlGVESaRW2ZMMp23NqfHLr ZWypoBvv4yoZsQkoFH3Fn/TsfDzcqxXJEVyN3V8M+gjyqTsVQveukESngtRJloY48Qr5 2lqA== X-Forwarded-Encrypted: i=1; AJvYcCXu3gx26NFvQSrxFFiLm6KWHLRT3jIkkVxYo/przrdnn3m6IWcOXq/rHSVhvBvwkb5+XbMa8UdjCtT4G7s=@vger.kernel.org X-Gm-Message-State: AOJu0Yz1LHGZWzLsODUJ7U0UolsARivkPdyI1PfXoIod8VqA6k8dFOI3 bz4DP1DCFnf+Aqo3XxuE+7aO6/gytt5DdUOg1/f1VY4RAiTdodBA0sJAPlnQVZ4okBAXTBKlf2Q 1pJUgKg== X-Google-Smtp-Source: AGHT+IFVRH25Ty7/gcF0OCXM4vzVNYQqfUZNnDO6SypfEDqFwa9uz2AGIDtUMgRBkV7aLsTJ7xtnSYXokZj+ X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:9a50:5183:644a:3472]) (user=irogers job=sendgmr) by 2002:a05:690c:26ca:b0:6ee:61ea:a40e with SMTP id 00721157ae682-6f275c1849amr58517b3.2.1734123887634; Fri, 13 Dec 2024 13:04:47 -0800 (PST) Date: Fri, 13 Dec 2024 13:04:24 -0800 In-Reply-To: <20241213210425.526512-1-irogers@google.com> Message-Id: <20241213210425.526512-8-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241213210425.526512-1-irogers@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Subject: [PATCH v1 7/8] perf test shell lock_contention: Extra debug diagnostics From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , "Mike Rapoport (IBM)" , Wei Yang , James Clark , Howard Chu , Kajol Jain , Athira Rajeev , Ze Gao , Weilin Wang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In test_record_concurrent, as stderr is sent to /dev/null, error messages are hidden. Change this to gather the error messages and dump them on failure. Some minor sh->bash changes to add some more diagnostics in trap_cleanup. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/tests/shell/lock_contention.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/perf/tests/shell/lock_contention.sh b/tools/perf/tests/s= hell/lock_contention.sh index c1ec5762215b..43c2438f6153 100755 --- a/tools/perf/tests/shell/lock_contention.sh +++ b/tools/perf/tests/shell/lock_contention.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # kernel lock contention analysis test # SPDX-License-Identifier: GPL-2.0 =20 @@ -7,14 +7,17 @@ set -e err=3D0 perfdata=3D$(mktemp /tmp/__perf_test.perf.data.XXXXX) result=3D$(mktemp /tmp/__perf_test.result.XXXXX) +errout=3D$(mktemp /tmp/__perf_test.errout.XXXXX) =20 cleanup() { rm -f ${perfdata} rm -f ${result} + rm -f ${errout} trap - EXIT TERM INT } =20 trap_cleanup() { + echo "Unexpected signal in ${FUNCNAME[1]}" cleanup exit ${err} } @@ -75,10 +78,12 @@ test_bpf() test_record_concurrent() { echo "Testing perf lock record and perf lock contention at the same time" - perf lock record -o- -- perf bench sched messaging 2> /dev/null | \ + perf lock record -o- -- perf bench sched messaging 2> ${errout} | \ perf lock contention -i- -E 1 -q 2> ${result} if [ "$(cat "${result}" | wc -l)" !=3D "1" ]; then echo "[Fail] Recorded result count is not 1:" "$(cat "${result}" | wc -l= )" + cat ${errout} + cat ${result} err=3D1 exit fi --=20 2.47.1.613.gc27f4b7a9f-goog From nobody Wed Dec 17 16:11:07 2025 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 C71DC1EBA0B for ; Fri, 13 Dec 2024 21:04:50 +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=1734123892; cv=none; b=oHzFbLqI/LtsBEUISW0jfkKnjCRpoNTRd4mGhlr6BpxcumRpPvpWdM4b93fRaYvfhlCWWOL84Rij0MJNF7RRG/ANO052tB0zykSsKxdwBxnn3/r6eXZVlRKfswpjeGVMAN9JiIFlQVcPgF2gV9/W0kLppo+PkAgfebfVuVDt6iM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734123892; c=relaxed/simple; bh=mEVKQkxWRXJdiQoRyQuxChdbGiNav5HSCWY6DgzLwTc=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=OVRFBbbSVqzHdiu+XEs4ricpioCQV3nSXgn8Ity1w0FL/8Fm4xTpUBiMIRWBP3XUeoHzpnrj0ELzNOrfG55Yu9bmcI8BciJ3Xz5M5IBp6RqM1r0s+m9zww5x28Il/tVe8y//CzfmS7KBFFfOuSSxKfEEEUsLnogiFZfuezc5/wk= 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=qvTYisBc; 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="qvTYisBc" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6ef7c67eeb8so26859117b3.3 for ; Fri, 13 Dec 2024 13:04:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734123890; x=1734728690; 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=iJDiQRFCSz2pV8y7FxqzQDhy9JPoVRfT99ZbYeMgH0I=; b=qvTYisBcnfvpD/6+tR+dI7nxRScD5uSVyt9vrYXk0zc5UXaHZ4/JGVG0FYaNQAJGA1 3z2bQQY1X9DpjuwAl/72Q/xy5dWPaDtCDe4eJLQozNZ5j0vqyXulVl02WgvJtB3yE4FV DvDmAgRvICpvsJcsxrQzq3sjPzV6+I7Ni3Ex1e97CGiFhCTw3Y/GGoX7MiCwckiUTwM1 0WO5F7GJz9+PLL9jsNoAjPW2i5viRN9hG/V8LEH97yIUJuPdCGtT3R3pTM84ScCG8yS5 kBfBC6SaZfm80pszmVWqQX/jDtCWPIxwQwBrmmgKwxs5xyeQbQUUza26gIoKpf/Y63uE aOMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734123890; x=1734728690; 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=iJDiQRFCSz2pV8y7FxqzQDhy9JPoVRfT99ZbYeMgH0I=; b=vGuH9VsGpIh2ph7Z0GruotOQJSH34mF0XxdPhXlSBmVQtbAbu97jxIkhVL99OrY8qR m0unh385S1BVeCmw80pdWClj0TQefGKVFG6GNRCNs7LU0QvQU7qoGgY8961Nt94vF9jX gOHG4pc0Ie6rKpFps+r7CpjDQkKKbiCEM7E8+ZJbQBbjvaDuxJkwXohmRNXegIGZVo0t aNkiEvO+jY09xWKordO9cfZDunQq5YyA9XK1lZkRwU/8dS8/CiWbc0o3iinzZzUieBMZ nNK5ty8wE4QahD3JmSTvEWPiD7oekPb7bVr0DU7etipcOJhd7vERvQneHs9Ps0/N0tkp uAOA== X-Forwarded-Encrypted: i=1; AJvYcCUxgWjgjqs2C72bKv8PpS86uNSVW9v11tYun4Qt6sM1nm50edIByl9h3IcRZL8IJCxiPf2AjQqDBk1i320=@vger.kernel.org X-Gm-Message-State: AOJu0YxSsVuvHiU5PEH/kL6U5YWKWF8TcGzRvdI/9XOOMbeHLYy1yQdq xZ4gP26BfCFRv5UpyTqJq6obkCHg1cQgAfSfcI6VqIB4mWtt0ZYrFzroFE7/ZSTO3HT+ZFHq+hx LaIdiOw== X-Google-Smtp-Source: AGHT+IHs+WAfXli6hbB79/PjfvyzF4H7kHc4JY48mxpcyZssQCRvhWFB5cQ1OWLUaDs/bXboaKHIfiq3EJXP X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:9a50:5183:644a:3472]) (user=irogers job=sendgmr) by 2002:a05:690c:245:b0:6ef:e0ce:df9f with SMTP id 00721157ae682-6f279b74b43mr118527b3.4.1734123889783; Fri, 13 Dec 2024 13:04:49 -0800 (PST) Date: Fri, 13 Dec 2024 13:04:25 -0800 In-Reply-To: <20241213210425.526512-1-irogers@google.com> Message-Id: <20241213210425.526512-9-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241213210425.526512-1-irogers@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Subject: [PATCH v1 8/8] libperf event: Ensure tracing data is multiple of 8 sized From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , "Mike Rapoport (IBM)" , Wei Yang , James Clark , Howard Chu , Kajol Jain , Athira Rajeev , Ze Gao , Weilin Wang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Perf's synthetic-events.c will ensure 8-byte alignment of tracing data, writing it after a perf_record_header_tracing_data event. Add padding to struct perf_record_header_tracing_data to make it 16-byte rather than 12-byte sized. Fixes: 055c67ed3988 ("perf tools: Move event synthesizing routines to separ= ate .c file") Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/lib/perf/include/perf/event.h | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/lib/perf/include/perf/event.h b/tools/lib/perf/include/p= erf/event.h index 37bb7771d914..32b75c0326c9 100644 --- a/tools/lib/perf/include/perf/event.h +++ b/tools/lib/perf/include/perf/event.h @@ -291,6 +291,7 @@ struct perf_record_header_event_type { struct perf_record_header_tracing_data { struct perf_event_header header; __u32 size; + __u32 pad; }; =20 #define PERF_RECORD_MISC_BUILD_ID_SIZE (1 << 15) --=20 2.47.1.613.gc27f4b7a9f-goog