From patchwork Fri May 4 03:11:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia He X-Patchwork-Id: 10379767 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 2940760353 for ; Fri, 4 May 2018 03:12:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 163CE29281 for ; Fri, 4 May 2018 03:12:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 09E3C2928C; Fri, 4 May 2018 03:12:25 +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 0325729281 for ; Fri, 4 May 2018 03:12:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6DA416B0011; Thu, 3 May 2018 23:12:22 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 68AD46B0012; Thu, 3 May 2018 23:12:22 -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 52CCD6B0022; Thu, 3 May 2018 23:12:22 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f197.google.com (mail-pf0-f197.google.com [209.85.192.197]) by kanga.kvack.org (Postfix) with ESMTP id 0C57C6B0011 for ; Thu, 3 May 2018 23:12:22 -0400 (EDT) Received: by mail-pf0-f197.google.com with SMTP id b25so16529194pfn.10 for ; Thu, 03 May 2018 20:12:22 -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:in-reply-to:references; bh=yY1+fBCUxJjFmKwZ5ArZPoxDidXqhoPx0exBqaxF1j8=; b=djbgrqkcDQUUH3zrBavQAeGzAeycyLn77l2aO0taBwyiPbKxueYaLzkoQrLePi+h8h J++2A6/zh9YcMFofTIrw3rOxWLpma+SiRMMMAgh0FNpyyxyrS1paDnfgmTS701y8vQ2m SyZtTEOHMcDTKNU6uP6zWSIYcAqa+GuFK6QFqTdH6rrlXYR6iAZUADviQtN5lCpdAOaB qHWwtejgzWDWvWXoeX/ugtELkIB7fljOZFe4HO+MlCRsn8827FN78VGbde8S+dMi50v9 XcOuaqLxiK0tKmOamst2x7j2153vMvmXQ9BH7LmfUDMKtKO73HCqZIJmuHKBLcqMYdWG SYOQ== X-Gm-Message-State: ALQs6tB+kIuk4SUoqLhjWnaS0JO0BVtUN+wtLdPDP+OCJq/TNDKGwHHU p7Fd8dqfyC82tLl4qT5gzziNrkK5iavlH0Sb1PmaFeC6Qi+H/RCaYYj9kgzUNcq0qIz4y1nyxvE /jFL7GZF1ZaKluNM5ovTYHE2Ooh3oa6nioD5DLFpgYTpmozzrgOkegXIeNPxyUm3Uvru7Rh7Xbc w63LHPnULIrYGwBWLtLWTA8ZILG1WzpDlUvS1kPbqzJfLSU4ORW8Uh+++Tfsr8klYHY2KdSdtJq VstzjrFWCgGG4MSetrH464RTCJZVSynZDnCzoEnC8uzu11LYufWB5agM26RdmntqC62s93WoiFM NWXaxJG5SMdEe0Z8Z8D9cz7j3ktVYX7/G0r5ByXDgjISxm9Lx8mDUiGXBuX51fbj4nuIY9Zv5Xm C X-Received: by 10.167.134.20 with SMTP id p20mr25286807pfn.159.1525403541681; Thu, 03 May 2018 20:12:21 -0700 (PDT) X-Received: by 10.167.134.20 with SMTP id p20mr25286768pfn.159.1525403540604; Thu, 03 May 2018 20:12:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525403540; cv=none; d=google.com; s=arc-20160816; b=bCfIQ0AmYswXSp+Uc8RCLIkadDW4MmoRmC0gGZL3tsP3I7nhSVVpBlSUtRIHLCUF2s Q2uNKrcjtriyrtBhcgbtNbh1Ip9jyg7HPPDbfM4etBYh7tekqI7+VzkkiMLjHGQ1q30U BR8sWqrBwwAIOg9WoTT2RMz+9j3nORJ+m1bh+vSVdA78Dafb25AnlVZnuX6FhJ0I3W69 2aPFfeHn1//1bJxQml7b33YLRByqYa5jp/ZolNUn01E39XFtCT8KQrpGgYZ+9EZ4qh/2 bR+sJSN2wFWPG1uZ6KUH93crhzJmv7o/yqyDM+OWF9A8VoQdWDUYgc/wyLgktV2grzB3 2WGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=yY1+fBCUxJjFmKwZ5ArZPoxDidXqhoPx0exBqaxF1j8=; b=N6jpbQ3xVyzLpz0qj08mEMG3zSRLRpV0OXPyQYm0wJ3dajpZ0WzP81lf/on242n6tz YJMIzVLTJs1Pjp81zOfZuBdwI+pFkX30Y2mQNc6uc08OvbT8KEiFE9tG1WLY2cG+ta6v hzmUvzCI42rCP1vx3jChXMR3QsiO/ysDllgz3moRP4M4xWGsBPdC0AKEjHIn9J0oLJWq bvxXFqFGiAdc6KN7F2dSiNEp6xX7oHDVDYq1SVVOs0uZeUiVq695hE8OVmqnxhZtavXM BPKpMMBJzInTUg0Cz0xMjZu+oNTq8LQveWGDfukFJN85FhHCCZ5ZqQwtvdVdKvrk8XIE XO/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=GXtjzOL5; 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 s21-v6sor6246718plp.3.2018.05.03.20.12.20 for (Google Transport Security); Thu, 03 May 2018 20:12:20 -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=GXtjzOL5; 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:in-reply-to:references; bh=yY1+fBCUxJjFmKwZ5ArZPoxDidXqhoPx0exBqaxF1j8=; b=GXtjzOL5CuU43H4ZH3mLmsa++AsTrrgxbJONf0qCji/3QlZ0iu1ttm80uglD1LxUvl cM0D+6kF0htmJZTByb+zD3Xx1hwdvjj7c6CUpP6Mz3k7yMuVh/1CGWwEzfOl27b4Qaor 0XYHqK8ITrwE2s4NyQoFDNwyFg0iUGh85ev5JT2tfrc9sqcLjgJPwmxlUNdPUpjz6OFq gmqms3XmILfL08oA2OHt1XGpihwyYe8G7/DTNnBZpqR+Ji0ZmYAMcfWJkcHTLF62wM4T ecSEaqEDsb+hSED8CbaUtg6hZ6Akrl7oWTC/tKe+5f2Dq/PqAVMExi1exqWU2Mp4ciQP J/IQ== X-Google-Smtp-Source: AB8JxZpat++gS23N089WqJI/pmz4VlaQ41j3IVDckxDdPA3lIdD/p+K3P82th6U2fmEMYhhInlbSPw== X-Received: by 2002:a17:902:680c:: with SMTP id h12-v6mr26698926plk.113.1525403540147; Thu, 03 May 2018 20:12:20 -0700 (PDT) Received: from ct7host.localdomain ([38.106.11.25]) by smtp.gmail.com with ESMTPSA id j9sm25571495pff.46.2018.05.03.20.12.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 May 2018 20:12:19 -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 v2] mm/ksm: ignore STABLE_FLAG of rmap_item->address in rmap_walk_ksm Date: Fri, 4 May 2018 11:11:46 +0800 Message-Id: <1525403506-6750-1-git-send-email-hejianet@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <20180503124415.3f9d38aa@p-imbrenda.boeblingen.de.ibm.com> References: <20180503124415.3f9d38aa@p-imbrenda.boeblingen.de.ibm.com> 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 lots of WARN_ON caused by PAGE_SIZE unaligned for rmap_item->address under memory pressure tests(start 20 guests and run memhog in the host). --------------------------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 will cause exceptions in handle_hva_to_gpa on arm64. This patch fixes it by ignoring(not removing) the low bits of address when doing rmap_walk_ksm. Signed-off-by: jia.he@hxt-semitech.com --- v2: refine the codes as suggested by Claudio Imbrenda mm/ksm.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index e3cbf9a..e6a9640 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,15 @@ 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) + + /* Ignore the stable/unstable/sqnr flags */ + addr = rmap_item->address & ~KSM_FLAG_MASK; + + if (addr < vma->vm_start || addr >= vma->vm_end) continue; /* * Initially we examine only the vma which covers this @@ -2587,8 +2594,7 @@ 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 (!rwc->rmap_one(page, vma, addr, rwc->arg)) { anon_vma_unlock_read(anon_vma); return; }