From patchwork Thu May 3 08:34:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia He X-Patchwork-Id: 10377291 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DC78460353 for ; Thu, 3 May 2018 08:35:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C7CCD2884C for ; Thu, 3 May 2018 08:35:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BC2BE28DB1; Thu, 3 May 2018 08:35:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 890EE2884C for ; Thu, 3 May 2018 08:35:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9D5566B000A; Thu, 3 May 2018 04:35:08 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 95DD36B000C; Thu, 3 May 2018 04:35:08 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 826F96B000E; Thu, 3 May 2018 04:35:08 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg0-f70.google.com (mail-pg0-f70.google.com [74.125.83.70]) by kanga.kvack.org (Postfix) with ESMTP id 3BE7B6B000A for ; Thu, 3 May 2018 04:35:08 -0400 (EDT) Received: by mail-pg0-f70.google.com with SMTP id f19-v6so11690167pgv.4 for ; Thu, 03 May 2018 01:35:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id; bh=B+b+fiLLrDfozsXtbCMQc7SuPT9qfO4K3AW9tbxNpiA=; b=HUx0TWHYFC4LX3beGTvD0IWSB2LQWZO4UoNS/5UFovM959iHIxQ7cDXm1Swd/Oo9pY //pQEoWfo6J7vrjZAInQG+0nyrrZLSn2p9/WLcEUFmW2z1NuBAUU8IXFtyoLmtuaZhfs 0iRfE6npl3d90o9Cl0Ra0OzpDe2jMVw0SMP2DxUhTeI+DX37H+0k0h8VO5SBGoLmiaUb 9C7sUE9kdhV5i9VizMcdNuCiQqTy5bYoIn610u0BSwzIEcLOvhztxhAm98ZBMU6ISfyv FU8cEbfWW+zu04MCQxgh4eJAVAMUwwPo4xJ42w70C3IdNaemfXTmPMD7qc+Vre1RIYvX f2tg== X-Gm-Message-State: ALQs6tCcqIGcq4WxMSk30ZAvKJcnPjrHeRTWLkHrhLfqUiZh+bu0vNqs pHpdPmxVC1otICEXKz62D/lYe2Gs3qNvWaGbOXW4B3hTp+t0UgyzZ3u+bmbbqqCFCTWkCnSHBAp PK4aO1l41OJPhxKMuj7Y9chFB/ho91ZcVlzhv8KbJNmQa8v0IOZrSsEkmQZLplRJHD9gv3DFIvd uR+02LSWelbP7C5P+h+kAAcZ7bBA46I5jEDuAJCxXH5WFF8goMvpiVtfFAE8uluwv168chM0d+/ XR/VQf4zB3EwOKwggixLVx3/hcVOpf+FOtPOPrtxo0Ul2rFOmohMFY+CJsiSc/tw3NUCEff4qMw 909gkpX991id1P6qPG1uAAKuD+pGEItCyjPCJiQfj7uRzyocvQu6Q6aoOaJ0KuXGCZDZJRNM3w+ c X-Received: by 2002:a63:a50a:: with SMTP id n10-v6mr18807639pgf.141.1525336507878; Thu, 03 May 2018 01:35:07 -0700 (PDT) X-Received: by 2002:a63:a50a:: with SMTP id n10-v6mr18807604pgf.141.1525336506835; Thu, 03 May 2018 01:35:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525336506; cv=none; d=google.com; s=arc-20160816; b=WttsXXc49fHIFo0+29m1t3z07QEdmGKif9jmV7e8EfZ8rjlTAs1YBZ/91p7vx17jVf 0jG66NoAKs2aObRrL36mWsQ1I4RaHiIaRmucEllU2GR4Y+3hLHasYLUaqrveV64Bkdd3 H/0un1RhIKBLokeOp9XNODPbzPlJuPMr5FgiKy3ZpWK6Le5qR9HOPMrigMV+/hEqrUpe nsjl1R+WJDFWyKsnoy8LQ9wNU+xoUmxYgTShF+hvMP53H5xUwWAkrUVUw+4C73WbyD1D z0qoWXe6oKV4DUm7QMALtm/tDxN3wzCKE9U9ppAhCv4DoojYDgxA/SAqcXf8GscGJf9j 9tqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=B+b+fiLLrDfozsXtbCMQc7SuPT9qfO4K3AW9tbxNpiA=; b=xre1mssQTZmIDW0dUD6UavUxAW3aG2A1TMogZ5bSRrf44RGjEbO2deMYWsVId8qZxW BTht+vy9G4+PPzcNx+49yDSyCviHD3KNWPkf6bWkaPSQkhdtz+VRbfSoOi17eU15mJC8 DgzjBpMKib22RTKSB9M3jWhnUv9VORPK1yilTjZUbT+dpFyiLkpbxrcnSkcBbHjtmidm DfB/dcV0fpwPYvHmKmCtZPD+dkauCvlTZnryUDiZr7IpTqEMqCEr5kJnEKD3MhSp7xI3 3TDz3DIk0C32LrHMvgRya2I03o5zmNeCDfhmlaEOEdumMJ2GEQnjaZQhGkOWaHLFX6bb EK6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ptqdpIib; spf=pass (google.com: domain of hejianet@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=hejianet@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id d22-v6sor4926805plr.18.2018.05.03.01.35.06 for (Google Transport Security); Thu, 03 May 2018 01:35:06 -0700 (PDT) Received-SPF: pass (google.com: domain of hejianet@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ptqdpIib; spf=pass (google.com: domain of hejianet@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=hejianet@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=B+b+fiLLrDfozsXtbCMQc7SuPT9qfO4K3AW9tbxNpiA=; b=ptqdpIibAFHQyl3kvDQiI8N4LN8sIRVKDoPEZxGtnMkFEItG8UIiu9hM9zTQ1DbwT/ x6xBAws9TF0uo58MZV2AW9n9eH49IM9NUMCfcPgZ50cCdTYJ9CbwPlPLiO1j1xDw/4+9 UyVzfsLKIcrNDIC4TaAarkDiQohYPeIqw2gkC8yrUXJUrlwymT0tAt9EECjGBHTq6Inr 8yZM+KRT4OXRHj/27OyaSYZZp9Bc34++RPnG0ZJn+FfaMVj+eFKGmWukNnN/WrD6/ivC cMqSZBuT3vgSq6yRpPzc5o2X0ULZMnCWvnjgRwiMyNy+6uhi9dM4npQyT6iTddkGXmf+ +Vww== X-Google-Smtp-Source: AB8JxZp2nhaTsTGgmf/aCfY2+AWssxeABmeYCTAaeXmAlbOYu4PTr9rJEOREDBl61U4CwOjMKMEMRA== X-Received: by 2002:a17:902:a70b:: with SMTP id w11-v6mr22886728plq.342.1525336506492; Thu, 03 May 2018 01:35:06 -0700 (PDT) Received: from ct7host.localdomain ([38.106.11.25]) by smtp.gmail.com with ESMTPSA id x84sm39033698pfi.160.2018.05.03.01.35.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 May 2018 01:35:05 -0700 (PDT) From: Jia He To: Andrew Morton , Andrea Arcangeli , Minchan Kim , Claudio Imbrenda , Arvind Yadav , Mike Rapoport , linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Jia He , jia.he@hxt-semitech.com Subject: [PATCH] mm/ksm: ignore STABLE_FLAG of rmap_item->address in rmap_walk_ksm Date: Thu, 3 May 2018 16:34:48 +0800 Message-Id: <1525336488-25447-1-git-send-email-hejianet@gmail.com> X-Mailer: git-send-email 1.8.3.1 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP In our armv8a server(QDF2400), I noticed a WARN_ON caused by PAGE_SIZE unaligned for rmap_item->address. --------------------------begin-------------------------------------- [ 410.853828] WARNING: CPU: 4 PID: 4641 at arch/arm64/kvm/../../../virt/kvm/arm/mmu.c:1826 kvm_age_hva_handler+0xc0/0xc8 [ 410.864518] Modules linked in: vhost_net vhost tap xt_CHECKSUM ipt_MASQUERADE nf_nat_masquerade_ipv4 ip6t_rpfilter ipt_REJECT nf_reject_ipv4 ip6t_REJECT nf_reject_ipv6 xt_conntrack ip_set nfnetlink ebtable_nat ebtable_broute bridge stp llc ip6table_nat nf_conntrack_ipv6 nf_defrag_ipv6 nf_nat_ipv6 ip6table_mangle ip6table_security ip6table_raw iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4 nf_nat nf_conntrack iptable_mangle iptable_security iptable_raw ebtable_filter ebtables ip6table_filter ip6_tables iptable_filter rpcrdma ib_isert iscsi_target_mod ib_iser libiscsi scsi_transport_iscsi ib_srpt target_core_mod ib_srp scsi_transport_srp ib_ipoib rdma_ucm ib_ucm ib_umad rdma_cm ib_cm iw_cm mlx5_ib vfat fat ib_uverbs dm_mirror dm_region_hash ib_core dm_log dm_mod crc32_ce ipmi_ssif sg nfsd [ 410.935101] auth_rpcgss nfs_acl lockd grace sunrpc ip_tables xfs libcrc32c mlx5_core ixgbe mlxfw devlink mdio ahci_platform libahci_platform qcom_emac libahci hdma hdma_mgmt i2c_qup [ 410.951369] CPU: 4 PID: 4641 Comm: memhog Tainted: G W 4.17.0-rc3+ #8 [ 410.959104] Hardware name: [ 410.969791] pstate: 80400005 (Nzcv daif +PAN -UAO) [ 410.974575] pc : kvm_age_hva_handler+0xc0/0xc8 [ 410.979012] lr : handle_hva_to_gpa+0xa8/0xe0 [ 410.983274] sp : ffff801761553290 [ 410.986581] x29: ffff801761553290 x28: 0000000000000000 [ 410.991888] x27: 0000000000000002 x26: 0000000000000000 [ 410.997195] x25: ffff801765430058 x24: ffff0000080b5608 [ 411.002501] x23: 0000000000000000 x22: ffff8017ccb84000 [ 411.007807] x21: 0000000003ff0000 x20: ffff8017ccb84000 [ 411.013113] x19: 000000000000fe00 x18: ffff000008fb3c08 [ 411.018419] x17: 0000000000000000 x16: 0060001645820bd3 [ 411.023725] x15: ffff80176aacbc08 x14: 0000000000000000 [ 411.029031] x13: 0000000000000040 x12: 0000000000000228 [ 411.034337] x11: 0000000000000000 x10: 0000000000000000 [ 411.039643] x9 : 0000000000000010 x8 : 0000000000000004 [ 411.044949] x7 : 0000000000000000 x6 : 00008017f0770000 [ 411.050255] x5 : 0000fffda59f0200 x4 : 0000000000000000 [ 411.055561] x3 : 0000000000000000 x2 : 000000000000fe00 [ 411.060867] x1 : 0000000003ff0000 x0 : 0000000020000000 [ 411.066173] Call trace: [ 411.068614] kvm_age_hva_handler+0xc0/0xc8 [ 411.072703] handle_hva_to_gpa+0xa8/0xe0 [ 411.076619] kvm_age_hva+0x4c/0xe8 [ 411.080014] kvm_mmu_notifier_clear_flush_young+0x54/0x98 [ 411.085408] __mmu_notifier_clear_flush_young+0x6c/0xa0 [ 411.090627] page_referenced_one+0x154/0x1d8 [ 411.094890] rmap_walk_ksm+0x12c/0x1d0 [ 411.098632] rmap_walk+0x94/0xa0 [ 411.101854] page_referenced+0x194/0x1b0 [ 411.105770] shrink_page_list+0x674/0xc28 [ 411.109772] shrink_inactive_list+0x26c/0x5b8 [ 411.114122] shrink_node_memcg+0x35c/0x620 [ 411.118211] shrink_node+0x100/0x430 [ 411.121778] do_try_to_free_pages+0xe0/0x3a8 [ 411.126041] try_to_free_pages+0xe4/0x230 [ 411.130045] __alloc_pages_nodemask+0x564/0xdc0 [ 411.134569] alloc_pages_vma+0x90/0x228 [ 411.138398] do_anonymous_page+0xc8/0x4d0 [ 411.142400] __handle_mm_fault+0x4a0/0x508 [ 411.146489] handle_mm_fault+0xf8/0x1b0 [ 411.150321] do_page_fault+0x218/0x4b8 [ 411.154064] do_translation_fault+0x90/0xa0 [ 411.158239] do_mem_abort+0x68/0xf0 [ 411.161721] el0_da+0x24/0x28 ---------------------------end--------------------------------------- In rmap_walk_ksm, the rmap_item->address might still have the STABLE_FLAG, then the start and end in handle_hva_to_gpa might not be PAGE_SIZE aligned. Thus it causes exceptions in handle_hva_to_gpa on arm64. This patch fixes it by ignoring the low bits of rmap_item->address when doing rmap_walk_ksm. Signed-off-by: jia.he@hxt-semitech.com --- mm/ksm.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index e3cbf9a..3f0d980 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -199,6 +199,8 @@ struct rmap_item { #define SEQNR_MASK 0x0ff /* low bits of unstable tree seqnr */ #define UNSTABLE_FLAG 0x100 /* is a node of the unstable tree */ #define STABLE_FLAG 0x200 /* is listed from the stable tree */ +#define KSM_FLAG_MASK (SEQNR_MASK|UNSTABLE_FLAG|STABLE_FLAG) + /* to mask all the flags */ /* The stable and unstable tree heads */ static struct rb_root one_stable_tree[1] = { RB_ROOT }; @@ -2570,10 +2572,13 @@ void rmap_walk_ksm(struct page *page, struct rmap_walk_control *rwc) anon_vma_lock_read(anon_vma); anon_vma_interval_tree_foreach(vmac, &anon_vma->rb_root, 0, ULONG_MAX) { + unsigned long addr; + cond_resched(); vma = vmac->vma; - if (rmap_item->address < vma->vm_start || - rmap_item->address >= vma->vm_end) + + addr = rmap_item->address; + if (addr < vma->vm_start || addr >= vma->vm_end) continue; /* * Initially we examine only the vma which covers this @@ -2587,8 +2592,10 @@ void rmap_walk_ksm(struct page *page, struct rmap_walk_control *rwc) if (rwc->invalid_vma && rwc->invalid_vma(vma, rwc->arg)) continue; - if (!rwc->rmap_one(page, vma, - rmap_item->address, rwc->arg)) { + if (addr & STABLE_FLAG) + addr &= ~KSM_FLAG_MASK; + + if (!rwc->rmap_one(page, vma, addr, rwc->arg)) { anon_vma_unlock_read(anon_vma); return; }