Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp530920ybc; Tue, 19 Nov 2019 05:21:40 -0800 (PST) X-Google-Smtp-Source: APXvYqzU4t26Yz/ACnXhVPOdL2mlXEOt404Lh23Md7x2PUbM1JWtl0ZXpVM2xRUKt5vhhjp+j9Ag X-Received: by 2002:a17:906:b25a:: with SMTP id ce26mr35012923ejb.13.1574169700652; Tue, 19 Nov 2019 05:21:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574169700; cv=none; d=google.com; s=arc-20160816; b=dNZY0ciLMBN65veZkuJCK5zrtXjjZs6hB/v2Ani0B1G/95VEmKH6SWz8r9ON9xjI7s hwS0rIjl2awiqyNqtBOtR6OLVPqyzUnSMeIP9XcAFqrEgEfQB+5Oz8kq6NTdl1zREGtt 3nPDulGKuD9Ez+N3M4TYbYKpU5klfIJsZu9PD08WkOKTKW2Udep88agAyiXalPXJK+Yx lCaaFuFTw4k2pWSyEw13C6Bk7qwXSJYQw8A7zE2EXqbm+TgN3cx2qRr3MGY581v0YGJ2 2eOZ0RCF50t03TYkAW5YNUkgpsjQwlomde9Bh764wEqK0i35qGG6mRHZezQWoZ9g7Sqf RzLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=7sP1vXv48E60qpTt+WB+gsu2Bpo7dWZK0IMAM5BSIgg=; b=fFj2TEHhNlyPAmTv7rhqx7RUZupCy6qwKeqfPL6AjvVUD7QXEaeyQYm8wStyLtAqyB pq/VhZxrjqMlWiRXa699lwNUq9/cjW7YO817VJDtijWkX3NfJ/ULsBuaDuD5sVFc6yu7 J4z8Xx6kukzhaMbScHg+XFya2AjJ7hOebkqa4Jpb3p9IBaNPqEaIiPHvx8cF3cx55G2F jhs+ExlgNG1Ylia3v++QN4cdGz2P2Ndai+XALJ5pGF/YCyK3mcGvAKC957ZkZj+ENYx/ t/GxkRlJ4MwBceuWwTYhpDXPslipVUI/LpafARU4tp51bsWZfN6YRvadFzcNSpUZ4Gzg d5Qw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q18si15679166eju.333.2019.11.19.05.21.16; Tue, 19 Nov 2019 05:21:40 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727805AbfKSNT0 (ORCPT + 99 others); Tue, 19 Nov 2019 08:19:26 -0500 Received: from relay.sw.ru ([185.231.240.75]:37432 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726378AbfKSNT0 (ORCPT ); Tue, 19 Nov 2019 08:19:26 -0500 Received: from dhcp-172-16-25-5.sw.ru ([172.16.25.5] helo=i7.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1iX3PT-0007Sl-0S; Tue, 19 Nov 2019 16:19:11 +0300 From: Andrey Ryabinin To: Andrew Morton Cc: Hugh Dickins , Andrea Arcangeli , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Ryabinin , stable@vger.kernel.org Subject: [PATCH] mm/ksm: Don't WARN if page is still mapped in remove_stable_node() Date: Tue, 19 Nov 2019 16:18:50 +0300 Message-Id: <20191119131850.5675-1-aryabinin@virtuozzo.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It's possible to hit the WARN_ON_ONCE(page_mapped(page)) in remove_stable_node() when it races with __mmput() and squeezes in between ksm_exit() and exit_mmap(). WARNING: CPU: 0 PID: 3295 at mm/ksm.c:888 remove_stable_node+0x10c/0x150 Call Trace: remove_all_stable_nodes+0x12b/0x330 run_store+0x4ef/0x7b0 kernfs_fop_write+0x200/0x420 vfs_write+0x154/0x450 ksys_write+0xf9/0x1d0 do_syscall_64+0x99/0x510 entry_SYSCALL_64_after_hwframe+0x49/0xbe Remove the warning as there is nothing scary going on. Fixes: cbf86cfe04a6 ("ksm: remove old stable nodes more thoroughly") Signed-off-by: Andrey Ryabinin Cc: --- mm/ksm.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index dbee2eb4dd05..7905934cd3ad 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -885,13 +885,13 @@ static int remove_stable_node(struct stable_node *stable_node) return 0; } - if (WARN_ON_ONCE(page_mapped(page))) { - /* - * This should not happen: but if it does, just refuse to let - * merge_across_nodes be switched - there is no need to panic. - */ - err = -EBUSY; - } else { + /* + * Page could be still mapped if this races with __mmput() running in + * between ksm_exit() and exit_mmap(). Just refuse to let + * merge_across_nodes/max_page_sharing be switched. + */ + err = -EBUSY; + if (!page_mapped(page)) { /* * The stable node did not yet appear stale to get_ksm_page(), * since that allows for an unmapped ksm page to be recognized -- 2.23.0