From nobody Sun May 24 20:33:24 2026 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (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 976A025B098 for ; Sat, 23 May 2026 01:19:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779499165; cv=none; b=DusYnKblDdCIwmfyZZODJIhlt3Lfd+zv0y8q9LYUlDlRwauCiqJRNldiAC612HSxS/ctEZN7W27T7v4r4UJ3rsnCKOk09d5WNvxRaYIDFeERNKdoDmfvmexe4hj3OA7xqQIzsNL8Ou3FtkFtcSq/h796wu5piYtWCIoNGsLVapw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779499165; c=relaxed/simple; bh=DzzFqOliTYt+AVUs3TQyRDSDH8E27xB3aEdwmPGAlgw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=thiKxBZeepoDwtN7bx0qPdrioSx9p8Gw4/1q6iAdR24HyuNZIt3ybe+wTudxGbJDrATm6BfLGm+rB559xcmP/gIJM4P8KnCaxDGGOmzHWmf8e343E8KR3k/RJZt5Dz0vli+dZlu4knb8A7jhybNlnQtLz3JRK8C8mPeUG4u24Hs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mYxfusMY; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mYxfusMY" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2b458ca2296so57745515ad.0 for ; Fri, 22 May 2026 18:19:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779499163; x=1780103963; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=EHhj9hY1DpnCN0woSlOTUtwUQw1k2Y+/7qDhFgxma3E=; b=mYxfusMYC36G4Q+JXXjTf2V5j0GcFaAxgQoQcvMW4YrVY87mtJDExgSTKfIGhevqE/ /j35W0gvpN7CPvh9VVYXwAN0gC34RcFAEX2IqSrqavZpocHR931z5c2IJV2ENmUIhxaz VweNM5zgNxz56hu0iDK/uQ4FfWp66LCg9klnp5UaNiWG5BAcLknlB+1JCHwTpPLOMEKq m+pQJ4MKu7au5+hz7dKNVtbsGv0LOl656utEH3GbeO43vFrtP2O4R460NAF9rg3IAnCs 8YDq4V3JUGmvTD5cAhWUhVZ33nFeuxQ0xJpULlhuxOy9cOjsoGGgqYu8j7KKYdtvBBgt gJ3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779499163; x=1780103963; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=EHhj9hY1DpnCN0woSlOTUtwUQw1k2Y+/7qDhFgxma3E=; b=GZ/UOoKWpDEhI0ncqDpEPxWSOMHfPKBsgATcMWVgHQXLsbqDSfLKFMF7pYTxNK1eDx MuFf8g9gPhgEOMBCHmchzS9XciHCLAwkEyJTCMXasLeu4srqSQn2NayjvtqdZWIqrBGV deae74IhxbCZIHxznf9y7mVZWYjzBH27ddUf7m7MiprHm760DainnAEO8LeQw7W4WM3s H48VEQemFZXhD8k1YFhMmpHZU46WlWc4lweRZY82KcCEbyI62n8na8PDGhMJIQY4wnD+ PCYIoTJfh+SNSjX5aM+qpcAqWu6cPvwLigQ8cUDfj3ksyYYK/RC4O90m9VWpSFd/LuDS ncAA== X-Forwarded-Encrypted: i=1; AFNElJ9PwevurxNEPWp7A6Gu5Wpesm7H+Gs0uBHS+WYWDKjP1zKaJbG9DXLtF2hKsd4iF+94Y6KvUAwFxIEsNBQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzZJY+8+hoJcke5TxVkTzMhrlT2rZoV3tVCPD155q011IDhDZGK /4vd3pSdnDnVaMc09ZVx8LW4M1r7QjmgFqJldQ9/SQDCdnGy+1w8HBmI X-Gm-Gg: Acq92OH2W4CQ5oZorkgzhua+IxKcWQ6KJP0jbltOpKdsDIx4BVX3jY13rYLatumIeCG H5nCF9GAlHq9G/ysfFqQGIT1rUV7/nqbs+IHjmfkJyQuu0q5kMea9gkFqlhN6kI0ffUtb/YfFyg Uj1AfL9AWg4cwCl1AGSvAOAeG6Lhl9fi3JESkX7LErRDLTvaP1mbT/KF5cODv4Cd+9O3YL+ikvu 2Vi5E2tBUh74qpa8twhT+f46zeFpzPJPc698Rr8OkcjgkoIu8ODInEJyklZjCooPkkD9gX2HihK UHehCPibbWQ0uCdM/zVkgtSPfEFdav7fSKzLdo7dat07bp0A3JbPNEb5iR5+UPWRH/y+GBIsXze pK+qFrQhGZIBiP9tvnaTbPbo5ZdmyLnUiKs558pIX7r3QwyJPF0BlpgX0uKBIHZBjttiPnoJu/p mo/03LBJBzLbjUtFcDkDgnKEDF8uZvBkrDEz7SoSKm+H9gtKPdpNn2+bRvPqf+WCITgY2olaF+j L9phBeleRouX7nxS1fppi3foinHbgUdgzmytP1JglileQ== X-Received: by 2002:a17:903:4405:b0:2bd:8822:d8c2 with SMTP id d9443c01a7336-2beb06bc0a9mr60851405ad.36.1779499162766; Fri, 22 May 2026 18:19:22 -0700 (PDT) Received: from ryzen ([2601:644:8000:5b5d:7285:c2ff:fe45:8a32]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2beb56ce4easm27209615ad.30.2026.05.22.18.19.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2026 18:19:22 -0700 (PDT) From: Rosen Penev To: linux-perf-users@vger.kernel.org Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Thomas Gleixner , Borislav Petkov , Dave Hansen , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), "H. Peter Anvin" , linux-kernel@vger.kernel.org (open list:PERFORMANCE EVENTS SUBSYSTEM) Subject: [PATCH] perf/x86/amd/uncore: turn amd_uncore_ctx events into a flexible array Date: Fri, 22 May 2026 18:19:04 -0700 Message-ID: <20260523011904.101720-1-rosenp@gmail.com> X-Mailer: git-send-email 2.54.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The events pointer was kzalloc_node()'d immediately after the parent struct allocation, with the count (pmu->num_counters) trivially available beforehand. Move events to the struct tail as a flexible array member and fold the two allocations into a single kzalloc_node() with struct_size(), dropping the separate kfree(ctx->events) in the free path. Assisted-by: Claude:Opus-4.7 Signed-off-by: Rosen Penev --- arch/x86/events/amd/uncore.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/arch/x86/events/amd/uncore.c b/arch/x86/events/amd/uncore.c index 05cff39968ec..0e265fc1fef8 100644 --- a/arch/x86/events/amd/uncore.c +++ b/arch/x86/events/amd/uncore.c @@ -39,11 +39,11 @@ static int pmu_version; struct amd_uncore_ctx { int refcnt; int cpu; - struct perf_event **events; unsigned long active_mask[BITS_TO_LONGS(NUM_COUNTERS_MAX)]; int nr_active; struct hrtimer hrtimer; u64 hrtimer_duration; + struct perf_event *events[]; }; =20 struct amd_uncore_pmu { @@ -488,10 +488,8 @@ static void amd_uncore_ctx_free(struct amd_uncore *unc= ore, unsigned int cpu) if (cpu =3D=3D ctx->cpu) cpumask_clear_cpu(cpu, &pmu->active_mask); =20 - if (!--ctx->refcnt) { - kfree(ctx->events); + if (!--ctx->refcnt) kfree(ctx); - } =20 *per_cpu_ptr(pmu->ctx, cpu) =3D NULL; } @@ -536,18 +534,11 @@ static int amd_uncore_ctx_init(struct amd_uncore *unc= ore, unsigned int cpu) /* Allocate context if sibling does not exist */ if (!curr) { node =3D cpu_to_node(cpu); - curr =3D kzalloc_node(sizeof(*curr), GFP_KERNEL, node); + curr =3D kzalloc_node(struct_size(curr, events, pmu->num_counters), GFP= _KERNEL, node); if (!curr) goto fail; =20 curr->cpu =3D cpu; - curr->events =3D kzalloc_node(sizeof(*curr->events) * - pmu->num_counters, - GFP_KERNEL, node); - if (!curr->events) { - kfree(curr); - goto fail; - } =20 amd_uncore_init_hrtimer(curr); curr->hrtimer_duration =3D (u64)update_interval * NSEC_PER_MSEC; --=20 2.54.0