From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-182.mta0.migadu.com (out-182.mta0.migadu.com [91.218.175.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 79E0F29B200 for ; Wed, 28 Jan 2026 02:42:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769568146; cv=none; b=kK0C+gaTxYJYhOpiPcNkz9eiCMD/xGHQDBGTaoSqGXZ3JSpD+Fg+/Ibg0IgdXpzZ2pEg7E7inY5WhlWsvmAC/GpjIxNNgLwiXqNxSFdz9BQbewjiuJSlMKuwMNY+BGwHHSPJeaf9beRrxPDruHazQGLu9f06WAJ+8o6Urn0c4hg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769568146; c=relaxed/simple; bh=Cjq8RdcGnO3/jam0fc49BXpAjOIyI2Rgw1wcMkMTdvc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=A0bweGsXAd4BqZL2NFMqfLIMZT11TDDoOOEwaT9SD5YZx1+PqMoZMhtm7Mo57vbyfGie/K+jfT43gn2Iqd5J/BybO2Zcw4Qu/Wp2AqSpXqkgRkdqR1X54trqiPofRdeCRsWgcwO3XsDyNz9jU9ieRwxnKwurMZ3j/CHbe1jMxqA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=fSg5rURw; arc=none smtp.client-ip=91.218.175.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="fSg5rURw" Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1769568131; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xonaJmIT0yV1XBtfNVuhqYC/x9FdVSimBWSLznJyOZc=; b=fSg5rURwIZ8v8fMO0XcDatAwgQCwjWAve3VyUUEpjQ4tJ4zIpX1QMaebTkWwKbwkDLLNtQ ssTxYtqdleoLis5VwZdo376QRUsTgpB9Hiy6BvgwGtoCbTwRKKGo5FLvJdXnomgW4CLGer mIPxfqSQggWmYB1d9RVbtq16rmL0Bds= Date: Wed, 28 Jan 2026 10:41:40 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH bpf-next v8 1/3] perf: Add rctx in perf_callchain_entry To: Andrii Nakryiko Cc: bot+bpf-ci@kernel.org, peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, kan.liang@linux.intel.com, song@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, martin.lau@kernel.org, clm@meta.com, ihor.solodrai@linux.dev References: <20260126074331.815684-2-chen.dylane@linux.dev> <89d94076412b6fc7e05e4d4884f3830601b390d3dcbee91aff2ec214117411fb@mail.kernel.org> <0b02943b-4ec7-4be3-b0e2-6c77531c4cbe@linux.dev> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Tao Chen In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT 在 2026/1/28 05:01, Andrii Nakryiko 写道: > On Mon, Jan 26, 2026 at 12:51 AM Tao Chen wrote: >> >> 在 2026/1/26 16:03, bot+bpf-ci@kernel.org 写道: >>>> diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h >>>> index 9ded2e582c60..0330f265173d 100644 >>>> --- a/include/linux/perf_event.h >>>> +++ b/include/linux/perf_event.h >>>> @@ -57,6 +57,7 @@ >>>> #include >>>> >>>> struct perf_callchain_entry { >>>> + int rctx; >>>> u64 nr; >>>> u64 ip[]; /* /proc/sys/kernel/perf_event_max_stack */ >>>> }; >>> >>> Adding rctx before nr changes the structure layout in a way that >>> appears to break the perf userspace ABI. >>> >>> In perf_output_sample() in kernel/events/core.c, when PERF_SAMPLE_CALLCHAIN >>> is set, the code does: >>> >>> int size = 1; >>> size += data->callchain->nr; >>> size *= sizeof(u64); >>> __output_copy(handle, data->callchain, size); >>> >>> This copies (1 + nr) * 8 bytes starting from the beginning of the >>> structure. Before this patch, offset 0 contained nr (u64), followed >>> by ip[]. After this patch, offset 0 contains rctx (int) + 4 bytes >>> padding, then nr at offset 8, then ip[] at offset 16. >>> >>> With the new layout, this copy sends the following to userspace: >>> - First 8 bytes: rctx + padding (kernel-internal data) instead of nr >>> - Remaining bytes: nr + ip[0..nr-2] instead of ip[0..nr-1] >>> >>> This means the callchain data sent to userspace is shifted by 8 bytes, >>> the last IP is truncated, and the rctx value is leaked to userspace. >>> >>> Is there a plan to update perf_output_sample() to output starting from >>> &entry->nr instead of the structure start? Or am I missing something >>> about how this structure is used for userspace output? >>> >> >> As AI said, this change shifts the memory layout, which effectively >> breaks the userspace ABI. >> >> Maybe we can use __output_copy(handle, &data->callchain->nr, size); > > yep, very impressive for AI to notice this. I agree that > &data->callchain->nr seems like the best way forward. > will fix it in v9. >> >>> [ ... ] >>> >>> >>> --- >>> AI reviewed your patch. Please fix the bug or email reply why it's not a bug. >>> See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md >>> >>> CI run summary: https://github.com/kernel-patches/bpf/actions/runs/21350234831 >> >> >> -- >> Best Regards >> Tao Chen -- Best Regards Tao Chen