Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5241796imu; Wed, 19 Dec 2018 07:55:04 -0800 (PST) X-Google-Smtp-Source: AFSGD/XuY0Epo1PU4tXelPT7tta5tMVStFcrxFDYUvtVUj1Ro8GUh+qVWhT4BqpnpMbch0HF1UIC X-Received: by 2002:a62:9719:: with SMTP id n25mr7290874pfe.240.1545234904826; Wed, 19 Dec 2018 07:55:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545234904; cv=none; d=google.com; s=arc-20160816; b=E2OpmGfYUHvBmG6pluMBdDgTCcXUdSi+tOf8XDBElbZs+zKoT1scWSZqNI9Zhmojrd pPFu2UMkzKNtYYSar1FmTIwtaJl197k8WHG1amkdNDhzxeQG+puexMPlk5S1fjcYZfA8 SW6SK17lsuQtNw5SM+I6l+9vrNPK4L57IJVAltduk0UplLiDvaesl+UKq+V3WAwbxVF8 mvG+W/gdVO7i93sYk72CdW9D3WxnagfIw3CycxTC70rm10j7lG49KAIpOp6KegBKNxVt YnOjst+9QuMKr9p5nFaS71rQflybsJ6MEzaQaxTwLQWlK9n4j11e6hIMO/aRNgZYilD+ 8t9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=OtCtqnQFcaJcuPDm4e+SywOcjI8goP1g5k5lke8q0/8=; b=MxC+CAnBmVTt65OoEjRST5Y35KqgvwsoEm9s7z2tjYHvSwuk4Rp+9NdwpPwYaEhmhd WRmGM1MoT4D4aS3s1S3tJboRG8TdPoT0vSyQVLCEY6ZGKNDWI18f2ShCXrQ9WBx9hST4 ieGwWbQPUgf7/S3l42V/pt6uVKi7lRw1nOfqfXPNqoZqI2kMEJPJ0tgV4tKiRX1nnF5J OTadO0vK4CTH4CpQqB94FGIZ4rhCYMx6tvfs23XahLXfAVPerCbvqleOLO4thM23+U4U jYA9tS8PaS/fE/IaPFage3TOXnqhvPNw7AsMElj5c7Qtfkpn6gCDn3GOMc9Q0a85v9UI vsSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mWHX114T; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b27si15975407pgb.107.2018.12.19.07.54.47; Wed, 19 Dec 2018 07:55:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=@gmail.com header.s=20161025 header.b=mWHX114T; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729384AbeLSOZc (ORCPT + 99 others); Wed, 19 Dec 2018 09:25:32 -0500 Received: from mail-ed1-f68.google.com ([209.85.208.68]:35692 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727079AbeLSOZc (ORCPT ); Wed, 19 Dec 2018 09:25:32 -0500 Received: by mail-ed1-f68.google.com with SMTP id x30so17131303edx.2 for ; Wed, 19 Dec 2018 06:25:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:reply-to:references:mime-version :content-disposition:in-reply-to:user-agent; bh=OtCtqnQFcaJcuPDm4e+SywOcjI8goP1g5k5lke8q0/8=; b=mWHX114TMQ1HpDRuOZTW7SQg+v4An4jvyAkxDZWoxyKSnWDjX++pU1P72CGOe+IF2Q QGbMjBWlfPwd1yy/ES/mf8mQlxY7EnpPfxqmvAR3Mxamdw9KzAyKzWk01N85GxMlrLpR JjJZm9sfOeucRph45ASFPnT+hGCzTcqwHCzeb/fEyhpmhWYVqUCBHDlIXKSonY4m1uEP wR3k4TmQnUAxxBhxv8+WuX7tkHgDikLsh45+esnMYCXMqfEGmR2lQIHqLRc73go5Bbp4 GiCj6P8ECs0u6lru/jcxk/XGzuciap4Pu/XrE6TmGGAQjmDQ2eorHEmA9bLjWRb6n+SZ 012w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:reply-to :references:mime-version:content-disposition:in-reply-to:user-agent; bh=OtCtqnQFcaJcuPDm4e+SywOcjI8goP1g5k5lke8q0/8=; b=J3w8ONv8OxLK5775gzme7ucuHpbRG1+eyrhisG0Z7LDVlJls/AVsrUs9D04gXYNLxV sCjRuLZrPpfg0ceoZfpUYF29qPakUSKkvEEq8Je5TZ6S3YRZ42a7NY2nrgxte2M3Ib1B o1Rye7YOz6IVimgX7d0WrkFv/sqoSKhT/3FMq4TA7vBM+O3thLK68JDMHjMhB4Q7esj+ L7UIf9gwycxLcV9EV+AQgYqddFGMtPsOLtcC8F1EsJi//9tC/6+gah4ks3/GO4Ett1R6 jAsB4lcKKL5T4fmFOTBRDgX+yFWaiDvExGEHXvLhcGUwfaDtJ9QH3XadiCCc04S0mHSB 6W/g== X-Gm-Message-State: AA+aEWYv8hc6Tin/6cCrV2iocdTc9cJ606/ny+65hV2VG0ScmkZUHof3 XaFogq8J8Nn+8Y8h/zDbVGg= X-Received: by 2002:a50:b5a5:: with SMTP id a34mr19915229ede.52.1545229529579; Wed, 19 Dec 2018 06:25:29 -0800 (PST) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id o6-v6sm1529236ejs.32.2018.12.19.06.25.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Dec 2018 06:25:28 -0800 (PST) Date: Wed, 19 Dec 2018 14:25:28 +0000 From: Wei Yang To: Oscar Salvador Cc: akpm@linux-foundation.org, mhocko@suse.com, vbabka@suse.cz, pavel.tatashin@microsoft.com, rppt@linux.vnet.ibm.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm, page_alloc: Fix has_unmovable_pages for HugePages Message-ID: <20181219142528.yx6ravdyzcqp5wtd@master> Reply-To: Wei Yang References: <20181217225113.17864-1-osalvador@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181217225113.17864-1-osalvador@suse.de> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 17, 2018 at 11:51:13PM +0100, Oscar Salvador wrote: >v1 -> v2: > - Fix the logic for skipping pages by Michal > >--- >>From e346b151037d3c37feb10a981a4d2a25018acf81 Mon Sep 17 00:00:00 2001 >From: Oscar Salvador >Date: Mon, 17 Dec 2018 14:53:35 +0100 >Subject: [PATCH] mm, page_alloc: Fix has_unmovable_pages for HugePages > >While playing with gigantic hugepages and memory_hotplug, I triggered >the following #PF when "cat memoryX/removable": > ><--- >kernel: BUG: unable to handle kernel NULL pointer dereference at 0000000000000008 >kernel: #PF error: [normal kernel read fault] >kernel: PGD 0 P4D 0 >kernel: Oops: 0000 [#1] SMP PTI >kernel: CPU: 1 PID: 1481 Comm: cat Tainted: G E 4.20.0-rc6-mm1-1-default+ #18 >kernel: Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.0.0-prebuilt.qemu-project.org 04/01/2014 >kernel: RIP: 0010:has_unmovable_pages+0x154/0x210 >kernel: Code: 1b ff ff ff eb 32 48 8b 45 00 bf 00 10 00 00 a9 00 00 01 00 74 07 0f b6 4d 51 48 d3 e7 e8 c4 81 05 00 48 85 c0 49 89 c1 75 7e <41> 8b 41 08 83 f8 09 74 41 83 f8 1b 74 3c 4d 2b 64 24 58 49 81 ec >kernel: RSP: 0018:ffffc90000a1fd30 EFLAGS: 00010246 >kernel: RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000009 >kernel: RDX: ffffffff82aed4f0 RSI: 0000000000001000 RDI: 0000000000001000 >kernel: RBP: ffffea0001800000 R08: 0000000000200000 R09: 0000000000000000 >kernel: R10: 0000000000001000 R11: 0000000000000003 R12: ffff88813ffd45c0 >kernel: R13: 0000000000060000 R14: 0000000000000001 R15: ffffea0000000000 >kernel: FS: 00007fd71d9b3500(0000) GS:ffff88813bb00000(0000) knlGS:0000000000000000 >kernel: CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 >kernel: CR2: 0000000000000008 CR3: 00000001371c2002 CR4: 00000000003606e0 >kernel: DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 >kernel: DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 >kernel: Call Trace: >kernel: is_mem_section_removable+0x7d/0x100 >kernel: removable_show+0x90/0xb0 >kernel: dev_attr_show+0x1c/0x50 >kernel: sysfs_kf_seq_show+0xca/0x1b0 >kernel: seq_read+0x133/0x380 >kernel: __vfs_read+0x26/0x180 >kernel: vfs_read+0x89/0x140 >kernel: ksys_read+0x42/0x90 >kernel: do_syscall_64+0x5b/0x180 >kernel: entry_SYSCALL_64_after_hwframe+0x44/0xa9 >kernel: RIP: 0033:0x7fd71d4c8b41 >kernel: Code: fe ff ff 48 8d 3d 27 9e 09 00 48 83 ec 08 e8 96 02 02 00 66 0f 1f 44 00 00 8b 05 ea fc 2c 00 48 63 ff 85 c0 75 13 31 c0 0f 05 <48> 3d 00 f0 ff ff 77 57 f3 c3 0f 1f 44 00 00 55 53 48 89 d5 48 89 >kernel: RSP: 002b:00007ffeab5f6448 EFLAGS: 00000246 ORIG_RAX: 0000000000000000 >kernel: RAX: ffffffffffffffda RBX: 0000000000020000 RCX: 00007fd71d4c8b41 >kernel: RDX: 0000000000020000 RSI: 00007fd71d809000 RDI: 0000000000000003 >kernel: RBP: 0000000000020000 R08: ffffffffffffffff R09: 0000000000000000 >kernel: R10: 000000000000038b R11: 0000000000000246 R12: 00007fd71d809000 >kernel: R13: 0000000000000003 R14: 00007fd71d80900f R15: 0000000000020000 >kernel: Modules linked in: af_packet(E) xt_tcpudp(E) ipt_REJECT(E) xt_conntrack(E) nf_conntrack(E) nf_defrag_ipv4(E) ip_set(E) nfnetlink(E) ebtable_nat(E) ebtable_broute(E) bridge(E) stp(E) llc(E) iptable_mangle(E) iptable_raw(E) iptable_security(E) ebtable_filter(E) ebtables(E) iptable_filter(E) ip_tables(E) x_tables(E) kvm_intel(E) kvm(E) irqbypass(E) crct10dif_pclmul(E) crc32_pclmul(E) ghash_clmulni_intel(E) bochs_drm(E) ttm(E) drm_kms_helper(E) drm(E) aesni_intel(E) virtio_net(E) syscopyarea(E) net_failover(E) sysfillrect(E) failover(E) aes_x86_64(E) crypto_simd(E) sysimgblt(E) cryptd(E) pcspkr(E) glue_helper(E) parport_pc(E) fb_sys_fops(E) i2c_piix4(E) parport(E) button(E) btrfs(E) libcrc32c(E) xor(E) zstd_decompress(E) zstd_compress(E) raid6_pq(E) sd_mod(E) ata_generic(E) ata_piix(E) ahci(E) libahci(E) serio_raw(E) crc32c_intel(E) virtio_pci(E) virtio_ring(E) virtio(E) libata(E) sg(E) scsi_mod(E) autofs4(E) >kernel: CR2: 0000000000000008 >kernel: ---[ end trace 49cade81474e40e7 ]--- >kernel: RIP: 0010:has_unmovable_pages+0x154/0x210 >kernel: Code: 1b ff ff ff eb 32 48 8b 45 00 bf 00 10 00 00 a9 00 00 01 00 74 07 0f b6 4d 51 48 d3 e7 e8 c4 81 05 00 48 85 c0 49 89 c1 75 7e <41> 8b 41 08 83 f8 09 74 41 83 f8 1b 74 3c 4d 2b 64 24 58 49 81 ec >kernel: RSP: 0018:ffffc90000a1fd30 EFLAGS: 00010246 >kernel: RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000009 >kernel: RDX: ffffffff82aed4f0 RSI: 0000000000001000 RDI: 0000000000001000 >kernel: RBP: ffffea0001800000 R08: 0000000000200000 R09: 0000000000000000 >kernel: R10: 0000000000001000 R11: 0000000000000003 R12: ffff88813ffd45c0 >kernel: R13: 0000000000060000 R14: 0000000000000001 R15: ffffea0000000000 >kernel: FS: 00007fd71d9b3500(0000) GS:ffff88813bb00000(0000) knlGS:0000000000000000 >kernel: CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 >kernel: CR2: 0000000000000008 CR3: 00000001371c2002 CR4: 00000000003606e0 >kernel: DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 >kernel: DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 >---> > >The reason is we do not pass the Head to page_hstate(), and so, >the call to compound_order() in page_hstate() returns 0, so >we end up checking all hstates's size to match PAGE_SIZE. > >Obviously, we do not find any hstate matching that size, and we >return NULL. >Then, we dereference that NULL pointer in hugepage_migration_supported() >and we got the #PF from above. > >Fix that by getting the head page before calling page_hstate(). > >Also, since gigantic pages span several pageblocks, re-adjust the logic >for skipping pages. > >Signed-off-by: Oscar Salvador >--- > mm/page_alloc.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > >diff --git a/mm/page_alloc.c b/mm/page_alloc.c >index a6e7bfd18cde..90ad281f750c 100644 >--- a/mm/page_alloc.c >+++ b/mm/page_alloc.c >@@ -8038,11 +8038,14 @@ bool has_unmovable_pages(struct zone *zone, struct page *page, int count, > * handle each tail page individually in migration. > */ > if (PageHuge(page)) { >+ struct page *head = compound_head(page); >+ unsigned int skip_pages; > >- if (!hugepage_migration_supported(page_hstate(page))) >+ if (!hugepage_migration_supported(page_hstate(head))) > goto unmovable; > >- iter = round_up(iter + 1, 1<+ skip_pages = (1 << compound_order(head)) - (page - head); >+ iter = round_up(iter + 1, skip_pages) - 1; The comment of round_up says round up to next specified power of 2. And second parameter must be a power of 2. Look skip_pages not satisfy this. > continue; > } > >-- >2.13.7 -- Wei Yang Help you, Help me