From patchwork Tue Nov 19 13:18:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Ryabinin X-Patchwork-Id: 11251935 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7925614E5 for ; Tue, 19 Nov 2019 13:19:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5007B222C2 for ; Tue, 19 Nov 2019 13:19:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5007B222C2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5E93E6B000A; Tue, 19 Nov 2019 08:19:24 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 571A36B000C; Tue, 19 Nov 2019 08:19:24 -0500 (EST) 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 461EB6B000D; Tue, 19 Nov 2019 08:19:24 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0069.hostedemail.com [216.40.44.69]) by kanga.kvack.org (Postfix) with ESMTP id 2DA496B000A for ; Tue, 19 Nov 2019 08:19:24 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id D6AFF180AD815 for ; Tue, 19 Nov 2019 13:19:23 +0000 (UTC) X-FDA: 76173083406.13.sort73_51fb438191a41 X-Spam-Summary: 2,0,0,9fcfd131984b4422,d41d8cd98f00b204,aryabinin@virtuozzo.com,:akpm@linux-foundation.org:hughd@google.com:aarcange@redhat.com::linux-kernel@vger.kernel.org:aryabinin@virtuozzo.com:stable@vger.kernel.org,RULES_HIT:41:355:379:541:800:960:968:973:988:989:1260:1311:1314:1345:1431:1437:1515:1534:1541:1711:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3352:3865:3867:3868:3870:3871:3872:3874:4321:4419:5007:6119:6261:7875:7903:8660:10004:11026:11473:11658:11914:12043:12114:12296:12297:12438:12555:12679:12895:13069:13148:13230:13311:13357:13894:14093:14096:14181:14384:14394:14721:21063:21080:21451:21627,0,RBL:185.231.240.75:@virtuozzo.com:.lbl8.mailshell.net-62.2.3.100 64.100.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: sort73_51fb438191a41 X-Filterd-Recvd-Size: 2576 Received: from relay.sw.ru (relay.sw.ru [185.231.240.75]) by imf47.hostedemail.com (Postfix) with ESMTP for ; Tue, 19 Nov 2019 13:19:23 +0000 (UTC) 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 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: 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: Acked-by: Hugh Dickins --- 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