* [PATCH 01/15] percpu: fix pcpu_alloc_pages() failure path
[not found] <1408726399-4436-1-git-send-email-tj@kernel.org>
@ 2014-08-22 16:53 ` Tejun Heo
2014-08-23 15:38 ` Christoph Lameter
2014-08-22 16:53 ` [PATCH 02/15] percpu: perform tlb flush after pcpu_map_pages() failure Tejun Heo
1 sibling, 1 reply; 5+ messages in thread
From: Tejun Heo @ 2014-08-22 16:53 UTC (permalink / raw)
To: akpm, cl; +Cc: laijs, linux-kernel, vgoyal, Tejun Heo, stable
When pcpu_alloc_pages() fails midway, pcpu_free_pages() is invoked to
free what has already been allocated. The invocation is across the
whole requested range and pcpu_free_pages() will try to free all
non-NULL pages; unfortunately, this is incorrect as
pcpu_get_pages_and_bitmap(), unlike what its comment suggests, doesn't
clear the pages array and thus the array may have entries from the
previous invocations making the partial failure path free incorrect
pages.
Fix it by open-coding the partial freeing of the already allocated
pages.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: stable@vger.kernel.org
---
mm/percpu-vm.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/mm/percpu-vm.c b/mm/percpu-vm.c
index 3707c71..8d9bb2c 100644
--- a/mm/percpu-vm.c
+++ b/mm/percpu-vm.c
@@ -108,7 +108,7 @@ static int pcpu_alloc_pages(struct pcpu_chunk *chunk,
int page_start, int page_end)
{
const gfp_t gfp = GFP_KERNEL | __GFP_HIGHMEM | __GFP_COLD;
- unsigned int cpu;
+ unsigned int cpu, tcpu;
int i;
for_each_possible_cpu(cpu) {
@@ -116,14 +116,23 @@ static int pcpu_alloc_pages(struct pcpu_chunk *chunk,
struct page **pagep = &pages[pcpu_page_idx(cpu, i)];
*pagep = alloc_pages_node(cpu_to_node(cpu), gfp, 0);
- if (!*pagep) {
- pcpu_free_pages(chunk, pages, populated,
- page_start, page_end);
- return -ENOMEM;
- }
+ if (!*pagep)
+ goto err;
}
}
return 0;
+
+err:
+ while (--i >= page_start)
+ __free_page(pages[pcpu_page_idx(cpu, i)]);
+
+ for_each_possible_cpu(tcpu) {
+ if (tcpu == cpu)
+ break;
+ for (i = page_start; i < page_end; i++)
+ __free_page(pages[pcpu_page_idx(tcpu, i)]);
+ }
+ return -ENOMEM;
}
/**
--
1.9.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 02/15] percpu: perform tlb flush after pcpu_map_pages() failure
[not found] <1408726399-4436-1-git-send-email-tj@kernel.org>
2014-08-22 16:53 ` [PATCH 01/15] percpu: fix pcpu_alloc_pages() failure path Tejun Heo
@ 2014-08-22 16:53 ` Tejun Heo
2014-08-23 15:40 ` Christoph Lameter
1 sibling, 1 reply; 5+ messages in thread
From: Tejun Heo @ 2014-08-22 16:53 UTC (permalink / raw)
To: akpm, cl; +Cc: laijs, linux-kernel, vgoyal, Tejun Heo, stable
If pcpu_map_pages() fails midway, it unmaps the already mapped pages.
Currently, it doesn't flush tlb after the partial unmapping. This may
be okay in most cases as the established mapping hasn't been used at
that point but it can go wrong and when it goes wrong it'd be
extremely difficult to track down.
Flush tlb after the partial unmapping.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: stable@vger.kernel.org
---
mm/percpu-vm.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/mm/percpu-vm.c b/mm/percpu-vm.c
index 8d9bb2c..5110816 100644
--- a/mm/percpu-vm.c
+++ b/mm/percpu-vm.c
@@ -272,6 +272,7 @@ err:
__pcpu_unmap_pages(pcpu_chunk_addr(chunk, tcpu, page_start),
page_end - page_start);
}
+ pcpu_post_unmap_tlb_flush(chunk, page_start, page_end);
return err;
}
--
1.9.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 01/15] percpu: fix pcpu_alloc_pages() failure path
2014-08-22 16:53 ` [PATCH 01/15] percpu: fix pcpu_alloc_pages() failure path Tejun Heo
@ 2014-08-23 15:38 ` Christoph Lameter
0 siblings, 0 replies; 5+ messages in thread
From: Christoph Lameter @ 2014-08-23 15:38 UTC (permalink / raw)
To: Tejun Heo; +Cc: akpm, laijs, linux-kernel, vgoyal, stable
On Fri, 22 Aug 2014, Tejun Heo wrote:
> Fix it by open-coding the partial freeing of the already allocated
> pages.
Acked-by: Christoph Lameter <cl@linux.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 02/15] percpu: perform tlb flush after pcpu_map_pages() failure
2014-08-22 16:53 ` [PATCH 02/15] percpu: perform tlb flush after pcpu_map_pages() failure Tejun Heo
@ 2014-08-23 15:40 ` Christoph Lameter
2014-08-23 17:10 ` Tejun Heo
0 siblings, 1 reply; 5+ messages in thread
From: Christoph Lameter @ 2014-08-23 15:40 UTC (permalink / raw)
To: Tejun Heo; +Cc: akpm, laijs, linux-kernel, vgoyal, stable
On Fri, 22 Aug 2014, Tejun Heo wrote:
> If pcpu_map_pages() fails midway, it unmaps the already mapped pages.
> Currently, it doesn't flush tlb after the partial unmapping. This may
> be okay in most cases as the established mapping hasn't been used at
> that point but it can go wrong and when it goes wrong it'd be
> extremely difficult to track down.
So why is this separate? You added the unmapping in the last patch without
the flushing and this is a fixup for the patch before?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 02/15] percpu: perform tlb flush after pcpu_map_pages() failure
2014-08-23 15:40 ` Christoph Lameter
@ 2014-08-23 17:10 ` Tejun Heo
0 siblings, 0 replies; 5+ messages in thread
From: Tejun Heo @ 2014-08-23 17:10 UTC (permalink / raw)
To: Christoph Lameter; +Cc: akpm, laijs, linux-kernel, vgoyal, stable
On Sat, Aug 23, 2014 at 10:40:29AM -0500, Christoph Lameter wrote:
> On Fri, 22 Aug 2014, Tejun Heo wrote:
>
> > If pcpu_map_pages() fails midway, it unmaps the already mapped pages.
> > Currently, it doesn't flush tlb after the partial unmapping. This may
> > be okay in most cases as the established mapping hasn't been used at
> > that point but it can go wrong and when it goes wrong it'd be
> > extremely difficult to track down.
>
> So why is this separate? You added the unmapping in the last patch without
> the flushing and this is a fixup for the patch before?
This was originally separated out so that flushes can be done once per
chunk as some of the flushes involve sending IPIs to all CPUs. After
this patchset, more of alloc/free logic is implemented in the percpu
core so it probably would be better to expose the flush interface too
so that all can be driven from the core.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-08-23 17:10 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1408726399-4436-1-git-send-email-tj@kernel.org>
2014-08-22 16:53 ` [PATCH 01/15] percpu: fix pcpu_alloc_pages() failure path Tejun Heo
2014-08-23 15:38 ` Christoph Lameter
2014-08-22 16:53 ` [PATCH 02/15] percpu: perform tlb flush after pcpu_map_pages() failure Tejun Heo
2014-08-23 15:40 ` Christoph Lameter
2014-08-23 17:10 ` Tejun Heo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox