linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Petr Tesarik <ptesarik@suse.cz>
To: Cong Wang <xiyou.wangcong@gmail.com>
Cc: linux-mm@kvack.org, LKML <linux-kernel@vger.kernel.org>,
	Vivek Goyal <vgoyal@redhat.com>
Subject: Re: Is per_cpu_ptr_to_phys broken?
Date: Thu, 15 Dec 2011 11:39:31 +0100	[thread overview]
Message-ID: <201112151139.32224.ptesarik@suse.cz> (raw)
In-Reply-To: <CAM_iQpUr3MqwWzeD4Z8KzyErEM4utT=CkpbyecPu75-QDDznHQ@mail.gmail.com>

Dne St 14. prosince 2011 17:17:15 Cong Wang napsal(a):
> On Wed, Dec 14, 2011 at 7:33 AM, Petr Tesarik <ptesarik@suse.cz> wrote:
> > Hi folks,
> 
> ...
> 
> > Now, the per_cpu_ptr_to_phys() function aligns all vmalloc addresses to a
> > page boundary. This was probably right when Vivek Goyal introduced that
> > function (commit 3b034b0d084221596bf35c8d893e1d4d5477b9cc), because
> > per-cpu addresses were only allocated by vmalloc if booted with
> > percpu_alloc=page, but this is no longer the case, because per-cpu
> > variables are now always allocated that way AFAICS.
> > 
> > So, shouldn't we add the offset within the page inside
> > per_cpu_ptr_to_phys?
> 
> Hi,
> 
> Tejun already fixed this, see:
> 
> commit	a855b84c3d8c73220d4d3cd392a7bee7c83de70e
> percpu: fix chunk range calculation
> author	Tejun Heo <tj@kernel.org>

Thanks for looking, but AFAICS this was a different issue. Maybe I'm missing 
something, but even with Tejun's fix, the first chunk gets allocated by 
vmalloc, and pcpu objects may not be page-aligned (as is the case with crash 
notes, which are only aligned to a word boundary).

In particular, the x86 architecture defines NEED_PER_CPU_PAGE_FIRST_CHUNK, so 
the first chunk gets allocated in pcpu_page_first_chunk():

	vm.flags = VM_ALLOC;
	vm.size = num_possible_cpus() * ai->unit_size;
	vm_area_register_early(&vm, PAGE_SIZE);

This allocates a vmalloc address which is then used to set up the first chunk:

	rc = pcpu_setup_first_chunk(ai, vm.addr);

Later on, crash notes get allocated with:

	crash_notes = alloc_percpu(note_buf_t);

which translates to
	__alloc_percpu(sizeof(note_buf_t), __alignof__(note_buf_t))

Alignment of note_buf_t is 4 bytes (it is an array of u32), so the resulting 
address may not be page-aligned. However, show_crash_notes() contains:

	addr = per_cpu_ptr_to_phys(per_cpu_ptr(crash_notes, cpunum));
	rc = sprintf(buf, "%Lx\n", addr);

Now, per_cpu_ptr() gives the correct virtual address, but 
per_cpu_ptr_to_phys() gets the result wrong, regardless whether it thinks that 
the address is in the first chunk or not:

	if (in_first_chunk) {
		if (!is_vmalloc_addr(addr))
			return __pa(addr);
		else
			return page_to_phys(vmalloc_to_page(addr));
	} else
		return page_to_phys(pcpu_addr_to_page(addr));

For anything except a non-vmalloc address, this will always round the result 
down to a page boundary. I thought this was obvious...

Petr Tesarik

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2011-12-15 10:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-13 23:33 Petr Tesarik
2011-12-14 16:17 ` Cong Wang
2011-12-15 10:39   ` Petr Tesarik [this message]
2011-12-15 18:40     ` Tejun Heo
2011-12-16  8:04       ` [PATCH] Do not round per_cpu_ptr_to_phys to page boundary Petr Tesarik
2011-12-16  8:40         ` Petr Tesarik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201112151139.32224.ptesarik@suse.cz \
    --to=ptesarik@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=vgoyal@redhat.com \
    --cc=xiyou.wangcong@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox