[DTrace-devel] [PATCH 5/5] bpf: ensure cpuinfo can handle non-sequential CPU ids

Kris Van Hees kris.van.hees at oracle.com
Tue May 2 05:20:06 UTC 2023


On Mon, May 01, 2023 at 06:24:06PM -0400, Eugene Loh via DTrace-devel wrote:
> Reviewed-by: Eugene Loh <eugene.loh at oracle.com>
> but data seems like a memory leak and a test would be great (though probably
> impractical).

Yes, data is a memleak...  Fixed.
Testing this is extremely difficult because you need to create a setup where
yu have non-sequential CPU ids.
> 
> On 5/1/23 15:53, Kris Van Hees via DTrace-devel wrote:
> > The 'cpuinfo' BPF map (a per-cpu map) was populated assuming that CPU
> > ids are always strictly sequential, i.e. that no gaps in the numbering
> > can occur.  That is not a valid assumption.  We need to populate the
> > cpuinfo entries referenced by the cpu_id of each online CPU.
> > 
> > Signed-off-by: Kris Van Hees<kris.van.hees at oracle.com>
> > ---
> >   libdtrace/dt_bpf.c | 15 +++++++++++++--
> >   1 file changed, 13 insertions(+), 2 deletions(-)
> > 
> > diff --git a/libdtrace/dt_bpf.c b/libdtrace/dt_bpf.c
> > index e19833bd..d0487759 100644
> > --- a/libdtrace/dt_bpf.c
> > +++ b/libdtrace/dt_bpf.c
> > @@ -607,15 +607,26 @@ gmap_create_buffers(dtrace_hdl_t *dtp)
> >   static int
> >   gmap_create_cpuinfo(dtrace_hdl_t *dtp)
> >   {
> > -	int		fd;
> > +	int		i, fd;
> >   	uint32_t	key = 0;
> > +	dtrace_conf_t	*conf = &dtp->dt_conf;
> > +	size_t		ncpus = conf->max_cpuid + 1;
> > +	cpuinfo_t	*data;
> > +	cpuinfo_t	*ci;
> > +
> > +	data = dt_zalloc(dtp, ncpus * sizeof(cpuinfo_t));
> > +	if (data == NULL)
> > +		return dt_set_errno(dtp, EDT_NOMEM);
> > +
> > +	for (i = 0, ci = &conf->cpus[0]; i < ncpus; i++, ci++)
> > +		memcpy(&data[ci->cpu_id], ci, sizeof(cpuinfo_t));
> >   	fd = create_gmap(dtp, "cpuinfo", BPF_MAP_TYPE_PERCPU_ARRAY,
> >   			 sizeof(uint32_t), sizeof(cpuinfo_t), 1);
> >   	if (fd == -1)
> >   		return -1;
> > -	if (dt_bpf_map_update(fd, &key, dtp->dt_conf.cpus) == -1)
> > +	if (dt_bpf_map_update(fd, &key, data) == -1)
> >   		return dt_bpf_error(dtp,
> >   				    "cannot update BPF map 'cpuinfo': %s\n",
> >   				    strerror(errno));
> > -- 2.39.1
> 
> _______________________________________________
> DTrace-devel mailing list
> DTrace-devel at oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/dtrace-devel



More information about the DTrace-devel mailing list