From patchwork Mon Feb 4 23:04:17 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [v6, 08/15] memory-hotplug: Common APIs to support page tables hot-remove Date: Mon, 04 Feb 2013 13:04:17 -0000 From: Andrew Morton X-Patchwork-Id: 218111 Message-Id: <20130204150417.2b1256b1.akpm@linux-foundation.org> To: Tang Chen Cc: linux-ia64@vger.kernel.org, linux-sh@vger.kernel.org, linux-mm@kvack.org, paulus@samba.org, hpa@zytor.com, sparclinux@vger.kernel.org, cl@linux.com, linux-s390@vger.kernel.org, x86@kernel.org, linux-acpi@vger.kernel.org, isimatu.yasuaki@jp.fujitsu.com, linfeng@cn.fujitsu.com, mgorman@suse.de, kosaki.motohiro@jp.fujitsu.com, rientjes@google.com, len.brown@intel.com, wency@cn.fujitsu.com, cmetcalf@tilera.com, glommer@parallels.com, wujianguo@huawei.com, yinghai@kernel.org, laijs@cn.fujitsu.com, linux-kernel@vger.kernel.org, minchan.kim@gmail.com, linuxppc-dev@lists.ozlabs.org On Wed, 9 Jan 2013 17:32:32 +0800 Tang Chen wrote: > +static void __meminit > +remove_pagetable(unsigned long start, unsigned long end, bool direct) > +{ > + unsigned long next; > + pgd_t *pgd; > + pud_t *pud; > + bool pgd_changed = false; > + > + for (; start < end; start = next) { > + pgd = pgd_offset_k(start); > + if (!pgd_present(*pgd)) > + continue; > + > + next = pgd_addr_end(start, end); > + > + pud = (pud_t *)map_low_page((pud_t *)pgd_page_vaddr(*pgd)); > + remove_pud_table(pud, start, next, direct); > + if (free_pud_table(pud, pgd)) > + pgd_changed = true; > + unmap_low_page(pud); > + } > + > + if (pgd_changed) > + sync_global_pgds(start, end - 1); > + > + flush_tlb_all(); > +} This generates a compiler warning saying that `next' may be used uninitialised. The warning is correct. If we take that `continue' on the first pass through the loop, the "start = next" will copy uninitialised data into `start'. Is this the correct fix? --- a/arch/x86/mm/init_64.c~memory-hotplug-common-apis-to-support-page-tables-hot-remove-fix-fix-fix-fix-fix-fix-fix +++ a/arch/x86/mm/init_64.c @@ -993,12 +993,12 @@ remove_pagetable(unsigned long start, un bool pgd_changed = false; for (; start < end; start = next) { + next = pgd_addr_end(start, end); + pgd = pgd_offset_k(start); if (!pgd_present(*pgd)) continue; - next = pgd_addr_end(start, end); - pud = (pud_t *)pgd_page_vaddr(*pgd); remove_pud_table(pud, start, next, direct); if (free_pud_table(pud, pgd))