Re: [PATCH] x86_64: Fix check for __per_cpu_offset initialisation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----Original Message-----
> -----Original Message-----
> > Since at least kernel v2.6.30 the __per_cpu_offset gets initialized to
> > __per_cpu_load. So first check if the __per_cpu_offset was set to a
> > proper value before reading any per cpu variable to prevent potential
> > bugs.
> >
> > Signed-off-by: Philipp Rudo <prudo@xxxxxxxxxx>
> 
> Thanks for the fix.
> 
> Acked-by: Kazuhito Hagio <k-hagio-ab@xxxxxxx>
> 
> Kazu
> 
> > ---
> >  x86_64.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/x86_64.c b/x86_64.c
> > index 6eb7d67..0bb8705 100644
> > --- a/x86_64.c
> > +++ b/x86_64.c
> > @@ -1327,6 +1327,8 @@ x86_64_per_cpu_init(void)
> >  		ms->stkinfo.isize = 16384;
> >
> >  	for (i = cpus = 0; i < NR_CPUS; i++) {
> > +		if (kt->__per_cpu_offset[i] == symbol_value("__per_cpu_load"))
> > +			break;

Rethought this, if __per_cpu_load is gone or renamed, crash cannot
even start.  This check is not essential, so I will modify both hunks
as follows and apply.

--- a/x86_64.c
+++ b/x86_64.c
@@ -1285,6 +1285,7 @@ x86_64_per_cpu_init(void)
 	struct machine_specific *ms;
 	struct syment *irq_sp, *curr_sp, *cpu_sp, *hardirq_stack_ptr_sp;
 	ulong hardirq_stack_ptr;
+	ulong __per_cpu_load = 0;
 
 	ms = machdep->machspec;
 
@@ -1326,8 +1327,11 @@ x86_64_per_cpu_init(void)
 	else if (!ms->stkinfo.isize)
 		ms->stkinfo.isize = 16384;
 
+	if (kernel_symbol_exists("__per_cpu_load"))
+		__per_cpu_load = symbol_value("__per_cpu_load");
+
 	for (i = cpus = 0; i < NR_CPUS; i++) {
-		if (kt->__per_cpu_offset[i] == symbol_value("__per_cpu_load"))
+		if (__per_cpu_load && kt->__per_cpu_offset[i] == __per_cpu_load)
 			break;
 		if (!readmem(cpu_sp->value + kt->__per_cpu_offset[i],
 		    KVADDR, &cpunumber, sizeof(int),

Thanks,
Kazu

> >  		if (!readmem(cpu_sp->value + kt->__per_cpu_offset[i],
> >  		    KVADDR, &cpunumber, sizeof(int),
> >  		    "cpu number (per_cpu)", QUIET|RETURN_ON_ERROR))
> > @@ -5602,7 +5604,7 @@ x86_64_get_smp_cpus(void)
> >  			return 1;
> >
> >  		for (i = cpus = 0; i < NR_CPUS; i++) {
> > -			if (kt->__per_cpu_offset[i] == 0)
> > +			if (kt->__per_cpu_offset[i] == symbol_value("__per_cpu_load"))
> >  				break;
> >  			if (!readmem(sp->value + kt->__per_cpu_offset[i],
> >  			    KVADDR, &cpunumber, sizeof(int),
> > --
> > 2.31.1
> >
> > --
> > Crash-utility mailing list
> > Crash-utility@xxxxxxxxxx
> > https://listman.redhat.com/mailman/listinfo/crash-utility
> 
> 
> --
> Crash-utility mailing list
> Crash-utility@xxxxxxxxxx
> https://listman.redhat.com/mailman/listinfo/crash-utility


--
Crash-utility mailing list
Crash-utility@xxxxxxxxxx
https://listman.redhat.com/mailman/listinfo/crash-utility




[Index of Archives]     [Fedora Development]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]     [Fedora Tools]

 

Powered by Linux