From patchwork Sat Jun 1 05:30:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 165560 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1692077ili; Fri, 31 May 2019 22:31:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqzxShl0hTCff42L6dG5OF1NHpNRXgKd5GaPcwSOvqKv1a9RBxdR5JZoK91qLzxciAQfDI5d X-Received: by 2002:a17:90a:cb0a:: with SMTP id z10mr13940516pjt.101.1559367062171; Fri, 31 May 2019 22:31:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559367062; cv=none; d=google.com; s=arc-20160816; b=GzcgsVUmOCKUOrFI7xhwWYQubZYS7G7/sYfwTqr2J3mrrC02ykrdOl6nrh3WvgeO+F oLzpZasNHmMalMlPfPIqdal1AMCzokRBFag30u9jr/zj/UJIiRMzG56kg6MUz2KAHtJ8 ox+0Oq8J5Dd+dV8hZRfoiIubxpMARFNsL7l6C+Ty8VA2jO1l+1m/GNmrH0gJdOKRS5pq v9n6GTQYU34rYa9MwFN2u98VHgZAwUEMgXY8xo/cU8DqxGwA5wBIkh5Rf+lKD6D7khpm mg3c9DnbNRpdXM5apfnCuTAIR7Pu1JrrqmUD8NbUZp9RxjzrRT4xs+HCHfhzXPJ/s8tz X0tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:message-id:subject:to:from :date:dkim-signature; bh=zL12Ww2o2DuinHiQYTohLAGYfM/aw69xYeF+sW3ywaE=; b=jJDJoWixXnFulNaHb6CO/4IQxsBzDdmeYyDtKQuTDm1mnPujj9Gf0ZpFA2vpyA5h99 5BUVB1UKijLOwahpUZb2I62vdpU9RiwUqQQftoND3EHhTizzw+oWyiXzW9XMvrqMBeYR c7WCZkZ0mf25S2xRDoBGYCQtaH9Tv0aShoTdwJ1Tl8IfdgCZkaQFiDgMb8HqzuUhVK1W /eUCgqYBIg3tHICcF+X3q0jF954aueIJvFiaAVVcibAeII1y3WRszl7DnBKbF+CrbTqA DG48iMueZLo8Whxmm6QIUrt0NtGH46dxDow18aangoKl75cGeIo+sdVbud+Bvq3WGomP wwgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WQwOvJas; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g2si8386322pgs.215.2019.05.31.22.31.01; Fri, 31 May 2019 22:31:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WQwOvJas; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726142AbfFAFbB (ORCPT + 14 others); Sat, 1 Jun 2019 01:31:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:46322 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725899AbfFAFbA (ORCPT ); Sat, 1 Jun 2019 01:31:00 -0400 Received: from localhost.localdomain (c-73-223-200-170.hsd1.ca.comcast.net [73.223.200.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AB51027135; Sat, 1 Jun 2019 05:30:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559367060; bh=PxJifK0YFDunxpYZJACTKHIBJa3sa198/Yk5NzmY3QU=; h=Date:From:To:Subject:From; b=WQwOvJasIBa41xQVbmAOVvy0JimynjJvEWEkHd0JwPgiV/RjHo9qeW3fTX8+w4hmf OmllTrf4qbnypGiC1GAqmfzQetb0mA4dqtYKmfH18IjNsYzquNB2+2NWml90VpKulK iIu/Dvq8GVUQAC1OpPsFEao5ZcuAZXQ2G1rZ8fYc= Date: Fri, 31 May 2019 22:30:59 -0700 From: akpm@linux-foundation.org To: akpm@linux-foundation.org, anshuman.khandual@arm.com, cai@lca.pw, marc.zyngier@arm.com, mgorman@techsingularity.net, mhocko@suse.com, mm-commits@vger.kernel.org, stable@vger.kernel.org, suzuki.poulose@arm.com, torvalds@linux-foundation.org Subject: [patch 20/21] mm, compaction: make sure we isolate a valid PFN Message-ID: <20190601053059.g7kZgiWJD%akpm@linux-foundation.org> User-Agent: s-nail v14.8.16 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Suzuki K Poulose Subject: mm, compaction: make sure we isolate a valid PFN When we have holes in a normal memory zone, we could endup having cached_migrate_pfns which may not necessarily be valid, under heavy memory pressure with swapping enabled ( via __reset_isolation_suitable(), triggered by kswapd). Later if we fail to find a page via fast_isolate_freepages(), we may end up using the migrate_pfn we started the search with, as valid page. This could lead to accessing NULL pointer derefernces like below, due to an invalid mem_section pointer. Unable to handle kernel NULL pointer dereference at virtual address 0000000000000008 [47/1825] Mem abort info: ESR = 0x96000004 Exception class = DABT (current EL), IL = 32 bits SET = 0, FnV = 0 EA = 0, S1PTW = 0 Data abort info: ISV = 0, ISS = 0x00000004 CM = 0, WnR = 0 user pgtable: 4k pages, 48-bit VAs, pgdp = 0000000082f94ae9 [0000000000000008] pgd=0000000000000000 Internal error: Oops: 96000004 [#1] SMP ... CPU: 10 PID: 6080 Comm: qemu-system-aar Not tainted 510-rc1+ #6 Hardware name: AmpereComputing(R) OSPREY EV-883832-X3-0001/OSPREY, BIOS 4819 09/25/2018 pstate: 60000005 (nZCv daif -PAN -UAO) pc : set_pfnblock_flags_mask+0x58/0xe8 lr : compaction_alloc+0x300/0x950 [...] Process qemu-system-aar (pid: 6080, stack limit = 0x0000000095070da5) Call trace: set_pfnblock_flags_mask+0x58/0xe8 compaction_alloc+0x300/0x950 migrate_pages+0x1a4/0xbb0 compact_zone+0x750/0xde8 compact_zone_order+0xd8/0x118 try_to_compact_pages+0xb4/0x290 __alloc_pages_direct_compact+0x84/0x1e0 __alloc_pages_nodemask+0x5e0/0xe18 alloc_pages_vma+0x1cc/0x210 do_huge_pmd_anonymous_page+0x108/0x7c8 __handle_mm_fault+0xdd4/0x1190 handle_mm_fault+0x114/0x1c0 __get_user_pages+0x198/0x3c0 get_user_pages_unlocked+0xb4/0x1d8 __gfn_to_pfn_memslot+0x12c/0x3b8 gfn_to_pfn_prot+0x4c/0x60 kvm_handle_guest_abort+0x4b0/0xcd8 handle_exit+0x140/0x1b8 kvm_arch_vcpu_ioctl_run+0x260/0x768 kvm_vcpu_ioctl+0x490/0x898 do_vfs_ioctl+0xc4/0x898 ksys_ioctl+0x8c/0xa0 __arm64_sys_ioctl+0x28/0x38 el0_svc_common+0x74/0x118 el0_svc_handler+0x38/0x78 el0_svc+0x8/0xc Code: f8607840 f100001f 8b011401 9a801020 (f9400400) ---[ end trace af6a35219325a9b6 ]--- The issue was reported on an arm64 server with 128GB with holes in the zone (e.g, [32GB@4GB, 96GB@544GB]), with a swap device enabled, while running 100 KVM guest instances. This patch fixes the issue by ensuring that the page belongs to a valid PFN when we fallback to using the lower limit of the scan range upon failure in fast_isolate_freepages(). Link: http://lkml.kernel.org/r/1558711908-15688-1-git-send-email-suzuki.poulose@arm.com Fixes: 5a811889de10f1eb ("mm, compaction: use free lists to quickly locate a migration target") Signed-off-by: Suzuki K Poulose Reported-by: Marc Zyngier Reviewed-by: Mel Gorman Reviewed-by: Anshuman Khandual Cc: Michal Hocko Cc: Qian Cai Cc: Marc Zyngier Cc: Signed-off-by: Andrew Morton --- mm/compaction.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/mm/compaction.c~mm-compaction-make-sure-we-isolate-a-valid-pfn +++ a/mm/compaction.c @@ -1399,7 +1399,7 @@ fast_isolate_freepages(struct compact_co page = pfn_to_page(highest); cc->free_pfn = highest; } else { - if (cc->direct_compaction) { + if (cc->direct_compaction && pfn_valid(min_pfn)) { page = pfn_to_page(min_pfn); cc->free_pfn = min_pfn; }