From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753937Ab1KZDor (ORCPT ); Fri, 25 Nov 2011 22:44:47 -0500 Received: from mga03.intel.com ([143.182.124.21]:4740 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750920Ab1KZDoq (ORCPT ); Fri, 25 Nov 2011 22:44:46 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.69,575,1315206000"; d="scan'208";a="79261265" From: Youquan Song To: linux-kernel@vger.kernel.org, akpm@linux-foundation.org, aarcange@redhat.com Cc: stable@vger.kernel.org, david.woodhouse@intel.com, allen.m.kay@intel.com, mtosatti@redhat.com, chrisw@redhat.com, andi@firstfloor.org, chaohong.guo@intel.com, Youquan Song , Youquan Song Subject: [PATCH 1/2] thp: Add compound tail page _mapcount when mapped Date: Sat, 26 Nov 2011 11:23:52 +0800 Message-Id: <1322277833-31798-1-git-send-email-youquan.song@intel.com> X-Mailer: git-send-email 1.6.4.2 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With 3.2-rc kernel, the IOMMU 2MiB page in KVM works. While I try to us IOMMU 1GiB page in KVM, I encounter a oops and 1GiB page total fail to be used. The root cause is that 1GiB page allocation calls gup_huge_pud() while 2MiB page calls gup_huge_pmd. If compound pages are used and the page is tail page, gup_huge_pmd increase _mapcount to record tail page are mapped while gup_huge_pud does not include this process. So when the mapped page is relesed, it will result in kernel oops because the page does not mark mapped. This patch add tail process for compound page in 1GiB huge page which keeps the same process as 2MiB page. Reproduce like: 1. Add grub boot option: hugepagesz=1G hugepages=8 2. mount -t hugetlbfs -o pagesize=1G hugetlbfs /dev/hugepages 3.qemu-kvm -m 2048 -hda os-kvm.img -cpu kvm64 -smp 4 -mem-path /dev/hugepages -net none -device pci-assign,host=07:00.1 kernel BUG at mm/swap.c:114! invalid opcode: 0000 [#1] SMP Call Trace: [] put_page+0x15/0x37 [] kvm_release_pfn_clean+0x31/0x36 [] kvm_iommu_put_pages+0x94/0xb1 [] kvm_iommu_unmap_memslots+0x80/0xb6 [] ? kvm_iommu_put_pages+0xb1/0xb1 [] ? intel_iommu_attach_device+0x13b/0x144 [] kvm_assign_device+0xba/0x117 [] kvm_vm_ioctl_assigned_device+0x301/0xa47 [] ? kvm_vm_ioctl_assigned_device+0xac/0xa47 [] ? native_sched_clock+0x32/0x6b [] ? sched_clock_cpu+0x45/0xd4 [] ? trace_hardirqs_off+0xd/0xf [] ? local_clock+0x41/0x5a [] ? lock_release_holdtime+0x2c/0x129 [] ? cmpxchg_double_slab+0xd0/0x12b [] ? avc_has_perm_noaudit+0x388/0x399 [] ? native_sched_clock+0x32/0x6b [] ? sched_clock+0x9/0xd [] kvm_vm_ioctl+0x36c/0x3a2 [] ? native_sched_clock+0x32/0x6b [] ? sched_clock+0x9/0xd [] do_vfs_ioctl+0x49e/0x4e4 [] sys_ioctl+0x5a/0x7c [] system_call_fastpath+0x16/0x1b RIP [] put_compound_page+0xd4/0x168 Reviewed-by: Andrea Arcangeli Cc: # 3.0.x Signed-off-by: Youquan Song --- arch/x86/mm/gup.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c index ea30585..dd74e46 100644 --- a/arch/x86/mm/gup.c +++ b/arch/x86/mm/gup.c @@ -201,6 +201,8 @@ static noinline int gup_huge_pud(pud_t pud, unsigned long addr, do { VM_BUG_ON(compound_head(page) != head); pages[*nr] = page; + if (PageTail(page)) + get_huge_page_tail(page); (*nr)++; page++; refs++; -- 1.6.4.2