From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (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 70F36474275 for ; Fri, 7 Aug 2026 12:19:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786105152; cv=none; b=rAWPmW5RUv+qGaGBkT2HP9FhlNfGiHkBQy3Nzb3lgMy3jO+fs0CE5e0uCr3zu2wpdQWe6VMCrjZeHaDnxXsUS7QzS1iKTruQUW6mHPFOlowEAdR/qI/p68DVemTF7fmWzmdok6WrjdMyt2nYP0YLVFcDxaqq6V9DrRH3YUBenro= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786105152; c=relaxed/simple; bh=q9kUnINnzM2h1qOmbQdjZo4Rw0F8JxCi2/foS2zgXWo=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=rnRtGJF4ijVt6OtV0UmK0fuXBG3S7n5HtgpCgvh44mA9WiZnw2+fKlrdNlcVmzPSyqSPafR53ZNXy85UUMhEtZKF9upFrIB+YMrGVaYgXD2t8cLZs/P+Bn2w8Zea5TRycl65xEH/liQt5wACjNguJEe+t6QFdXIZcB5cvWkixOY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=fpHij9fd; arc=none smtp.client-ip=209.85.221.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="fpHij9fd" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-480033bdcf4so289025f8f.2 for ; Fri, 07 Aug 2026 05:19:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1786105141; x=1786709941; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=b6ARJxBgnBxK+6NZln3mP3Z60UK181/qnNyKgABn96o=; b=fpHij9fd/n1vvKu2ltWtxpzd1ntXCE1fCNezIas5V2lXQXANM14dGxAsLqRr+dAYxn Iw1RiQmEsRdEDj+UOOU5QtjeqtqKJLjQ/jBWJNGk/jxjnRdqHbEulWuw2fM3zPeDr7j6 rNLPA37yK8BLrdi/aSz82b7AICpIrSs+DIx3J354eIqhYwMpdcfe8Pxpeeyw3q3lk/0x tAwML/8+gU+oHtBfkcJi1NyZxBoCFDgBkwb9QfcWEqa2GDB40co79YH8Js3OskIX1UNQ g56pIG0ABk8/H3bIhLAWCnPCLCMczDxae1++GDZvnZzFAIYfvoIdtXQgdLB8XJ4ngjaZ FjoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786105141; x=1786709941; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=b6ARJxBgnBxK+6NZln3mP3Z60UK181/qnNyKgABn96o=; b=V9EnbrY0RZpD6oCl6K4WzBhAMOKy4XLEzYIf83tGtbDNwq8N+qHEM9WAvRvR/lAbnM 6X2PavnSRG/7Uf3FbnWt5L1VvcPNmnBDjAkHouUVu41P12TAqAI43i+Cc3WYmutKPRU+ 4X1Qmzcsafd7lXtZfWixVgaYdHqYXWSIlr4pjWk6YPsL+S5xla0lIaPWVLyrCNT9JT6x iV5wLZLF2lelUhnGbsph4zZh4IEPDDDv+kXtOFg5ddIvzlgOHHekjrkEK2ZwoK4T3NlJ rC9QYOY2FUMx7jUDetiFlT2CzJoxrz3WUg4YQtyJBMXndlu4w23bJ4TcsGc1YR35M7iB z6JQ== X-Forwarded-Encrypted: i=1; AHgh+Rox0D4+bs+k/e1DnlcO+4vHpRqHPtLThky8HBFKHNj8ndXLHZT195vs4XgoMsus8e6X8lBUEkEF4FzHGFE=@vger.kernel.org X-Gm-Message-State: AOJu0YyWIz2G6/2QQGyzv4AybK8WE8bh946NC2XX05wpypmwjmusWUTd txvE9lzV29phgmX4Fb8eR5RI8sqr8wt5oG3MA3D5jWqFHftm93ojAiE+TPt2jXsYWb2FgXkqGPv 62/rVpYg= X-Gm-Gg: AR+sD13n2QIdVpaN7mhmP3bSKdfVIGu5/sdDaoBvc/dYVftosNIXi9RtjWqnpJIfbTX 6dwlgEKugPWosCkDQsQILBmK/rKMLOG5c6CBSH+L149HI9ka8WSzssRxOrLYXL931JVd9bWZgCP +a/6YFjXifI+SdlMyO3q+6cPfnpKuWHp1SdK/ZJajxPVaPXlZJhFYvsQVPF12ADn3bdxNb2B7hf zW6zZeI1c79Z7LCCd2cpHAodMeRgEFiVw4KXauX9nRrpotxrfqUFPAt4cDSk6QbZzo14D93M5Nz zRKplPyC/e/Cn6KFv1sMLICsC1NDJ2G5s6y/tAYjdEgcnl45bPEuLuYG2VStVywjQ63uImpWfx1 Yl5jX/xX2WLoeJ31Gmn1ckS5drSjQlKu0+wGYLUVJXyVkR+zW+LWswyQgnMg62pxLS0qY2w6+ch bxiUlBfBd10osjoomzUPO1KJw1O/GckDeuyFHaBE4+muEjna2+ZP+JOmR68z+pYgMo5w== X-Received: by 2002:a05:6000:4715:b0:47f:9752:3277 with SMTP id ffacd0b85a97d-47fec509a9fmr38796349f8f.2.1786105140913; Fri, 07 Aug 2026 05:19:00 -0700 (PDT) Received: from [192.168.1.3] ([37.18.141.193]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-480021f8b9bsm6038188f8f.25.2026.08.07.05.18.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 07 Aug 2026 05:19:00 -0700 (PDT) Message-ID: <66590828-a571-45eb-8e67-a55bebea1b97@linaro.org> Date: Fri, 7 Aug 2026 13:18:59 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] perf: arm_pmuv3: Zero initialize hw_id branch stack field To: Anshuman Khandual Cc: linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Will Deacon , Mark Rutland , "Rob Herring (Arm)" , Leo Yan , Suzuki Poulose References: <20260807-james-brbe-init-hw-idx-v1-1-009d1843960a@linaro.org> Content-Language: en-US From: James Clark In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 07/08/2026 11:44, Anshuman Khandual wrote: > On 07/08/26 2:44 PM, James Clark wrote: >> PERF_SAMPLE_BRANCH_HW_INDEX is supported by BRBE so hw_id is passed to >> userspace, but it's never set by the BRBE driver. Zero initialize it as >> it should be according to the docs: >> >> * For the architectures whose raw branch records are >> * already stored in age order, the hw_idx should be 0. > > The in code documentation while defining perf_branch_stack. > Probably a good idea to specify the same above. > > * For the architectures whose raw branch records are > * already stored in age order, the hw_idx should be 0. > */ > struct perf_branch_stack { > u64 nr; > u64 hw_idx; > struct perf_branch_entry entries[]; > }; > I found it easily enough. I wouldn't want to put the same comment in two places and risk one of them going stale. And if I take it away from one place and move it to the struct then it's just missing from somewhere else instead. So I think I'd rather leave this one. >> >> It's probably too risky to remove PERF_SAMPLE_BRANCH_HW_INDEX from BRBE >> now in case anyone is setting it and reading the value, but zero >> initializing the whole struct also protects against the same issue with >> new fields that are added in the future. > > Agreed. Because PERF_SAMPLE_BRANCH_HW_INDEX is supported in BRBE, > hw_idx pushed to the userspace should be zero if HW never updates. > This is definitely better than dropping PERF_SAMPLE_BRANCH_HW_INDEX > flag all together to avoid breaking current users (if any). >> >> Fixes: 58074a0fce66 ("perf: arm_pmuv3: Add support for the Branch Record Buffer Extension (BRBE)") >> Signed-off-by: James Clark > > Reviewed-by: Anshuman Khandual > Thanks >> --- >> Very small fix spotted by Sashiko. It was probably always zero during >> testing or never looked at. >> --- >> drivers/perf/arm_pmuv3.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/drivers/perf/arm_pmuv3.c b/drivers/perf/arm_pmuv3.c >> index 8014ff766cff..b9a8592bf112 100644 >> --- a/drivers/perf/arm_pmuv3.c >> +++ b/drivers/perf/arm_pmuv3.c >> @@ -1361,7 +1361,7 @@ static int branch_records_alloc(struct arm_pmu *armpmu) >> struct pmu_hw_events *events_cpu; >> >> events_cpu = per_cpu_ptr(armpmu->hw_events, cpu); >> - events_cpu->branch_stack = kmalloc(size, GFP_KERNEL); >> + events_cpu->branch_stack = kzalloc(size, GFP_KERNEL); >> if (!events_cpu->branch_stack) >> return -ENOMEM; >> } >> >> --- >> base-commit: f9a2394a23482bfd330911e9c8295b71724feacd >> change-id: 20260807-james-brbe-init-hw-idx-53dec54fe266 >> >> Best regards, >> -- >> James Clark >> >