Subject: Re: [PATCH v2] powerpc: mm: fixup preempt undefflow with huge pages

From: "Aneesh Kumar K.V" <[email-masked]>
Date: Thu, 10 Mar 2016 01:04:24 +0530

Sebastian Andrzej Siewior <[email-masked]> writes:

> [ text/plain ]
> hugepd_free() used __get_cpu_var() once. Nothing ensured that the code
> accessing the variable did not migrate from one CPU to another and soon
> this was noticed by Tiejun Chen in 94b09d755462 ("powerpc/hugetlb:
> Replace __get_cpu_var with get_cpu_var"). So we had it fixed.
>
> Christoph Lameter was doing his __get_cpu_var() replaces and forgot
> PowerPC. Then he noticed this and sent his fixed up batch again which
> got applied as 69111bac42f5 ("powerpc: Replace __get_cpu_var uses").
>
> The careful reader will noticed one little detail: get_cpu_var() got
> replaced with this_cpu_ptr(). So now we have a put_cpu_var() which does
> a preempt_enable() and nothing that does preempt_disable() so we
> underflow the preempt counter.
>

Reviewed-by: Aneesh Kumar K.V <[email-masked]>

> Cc: Benjamin Herrenschmidt <[email-masked]>
> Cc: Christoph Lameter <[email-masked]>
> Cc: Michael Ellerman <[email-masked]>
> Cc: <[email-masked]>
> Signed-off-by: Sebastian Andrzej Siewior <[email-masked]>
> ---
> v1…v2: - use get_cpu_var() instead of get_cpu_ptr()
>        - correct indentation of put_cpu_var()
>
>  arch/powerpc/mm/hugetlbpage.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/powerpc/mm/hugetlbpage.c b/arch/powerpc/mm/hugetlbpage.c
> index 744e24bcb85c..4a811ca7ac9d 100644
> --- a/arch/powerpc/mm/hugetlbpage.c
> +++ b/arch/powerpc/mm/hugetlbpage.c
> @@ -414,13 +414,13 @@ static void hugepd_free(struct mmu_gather *tlb, void *hugepte)
>  {
>  	struct hugepd_freelist **batchp;
>  
> -	batchp = this_cpu_ptr(&hugepd_freelist_cur);
> +	batchp = &get_cpu_var(hugepd_freelist_cur);
>  
>  	if (atomic_read(&tlb->mm->mm_users) < 2 ||
>  	    cpumask_equal(mm_cpumask(tlb->mm),
>  			  cpumask_of(smp_processor_id()))) {
>  		kmem_cache_free(hugepte_cache, hugepte);
> -        put_cpu_var(hugepd_freelist_cur);
> +		put_cpu_var(hugepd_freelist_cur);
>  		return;
>  	}
>  
> -- 
> 2.7.0