From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.9 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C6D6C43141 for ; Fri, 15 Nov 2019 17:56:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 03FAC20732 for ; Fri, 15 Nov 2019 17:56:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="le2OgXjL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 03FAC20732 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 6DD5F6B0006; Fri, 15 Nov 2019 12:56:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 68CF66B0008; Fri, 15 Nov 2019 12:56:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5A3736B000A; Fri, 15 Nov 2019 12:56:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0240.hostedemail.com [216.40.44.240]) by kanga.kvack.org (Postfix) with ESMTP id 500A66B0006 for ; Fri, 15 Nov 2019 12:56:01 -0500 (EST) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 0AF8A181AEF1F for ; Fri, 15 Nov 2019 17:56:01 +0000 (UTC) X-FDA: 76159265322.02.sail89_5196e7371e845 X-HE-Tag: sail89_5196e7371e845 X-Filterd-Recvd-Size: 6109 Received: from mail-pl1-f196.google.com (mail-pl1-f196.google.com [209.85.214.196]) by imf07.hostedemail.com (Postfix) with ESMTP for ; Fri, 15 Nov 2019 17:56:00 +0000 (UTC) Received: by mail-pl1-f196.google.com with SMTP id az9so5157788plb.11 for ; Fri, 15 Nov 2019 09:56:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=f1Oh1RF8Ut5xfZg2ksqYtAu0PSRZLhofY5NfDnVJV1E=; b=le2OgXjLuxKOzGanxn690BYFbpSWFpbYsCAtepodK3Nppn99TktillXTJ3pTaoaS0b p5G0nIrWIC3UyFh6Q+lQmLk8L3n/FO+3mCYs9DPd+e7q3JeUINwprkOOXD7QDvRrDKYp DQWke5NnA3d/K+VJXND/cneNY+NW1Diq6zUfTceC0PhqmWZ9RhJqXPk5fFRm2a+vhnkY mftZjzzCvwuJoFAAwdNuD6Ppn/JuL5pF34UUe16ySj4tVAhtH0VhH4Cc6QlGVIFuGSbT /NcxCkkvR1Gxz7JHOgTe4FVkUPZkmkUi+BaUun16tPmTWsaele0h0izQ4ujuiKd2rX/V il6Q== 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:in-reply-to:message-id :references:user-agent:mime-version; bh=f1Oh1RF8Ut5xfZg2ksqYtAu0PSRZLhofY5NfDnVJV1E=; b=iUM1JW2eE1yODgUXJqjRj47C52rmSkJxGMkIzhC3v+dQdxsCp4jtmIHYn15A6Yf/8T cjC3fsEHQvOXKVvp12zRRWOYUljYrWkrIeFYAu/5+Ph1Y06iIDuFSP6XKQY+CCjELA/Y 1PJsMMgctdIZJ2XFFjX23DZ/+yZuO+AG4vEFvsHLx14mU3LnWEnZrdHqTcGUbkdt40Ak A8bdI2SWk4CQHCykEvJciD9OhDUfwBZ6e8e7dUfm6xvi7/rp/DXvGOJgyi5qYpt+PM7o EkD6I6sHR9mzWgdfuR7JwaDttwbzC3WhN3tETSAB4/V/XrUm+59tLese/jcrJ8hJbq0F kGdw== X-Gm-Message-State: APjAAAWxDodkdoO2q0iMNB7jpu4qQGBb+eFXlvE+ZJYHf+oPnPfHp1sl gFaZGYs0DEiOsqh2ob5gxcG1ww== X-Google-Smtp-Source: APXvYqyefeVAz2G2+zRKTSTu2O2jadp+GWGI2fXpqPMSN02L0BFi23Fmcs24YcE9GXazUctq3iNwlg== X-Received: by 2002:a17:902:b416:: with SMTP id x22mr16514918plr.12.1573840558821; Fri, 15 Nov 2019 09:55:58 -0800 (PST) Received: from [100.112.92.218] ([104.133.9.106]) by smtp.gmail.com with ESMTPSA id y6sm9357412pfm.12.2019.11.15.09.55.57 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 15 Nov 2019 09:55:58 -0800 (PST) Date: Fri, 15 Nov 2019 09:55:46 -0800 (PST) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Andrey Ryabinin cc: Hugh Dickins , Andrea Arcangeli , "linux-mm@kvack.org" , LKML Subject: Re: KSM WARN_ON_ONCE(page_mapped(page)) in remove_stable_node() In-Reply-To: Message-ID: References: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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: On Wed, 13 Nov 2019, Andrey Ryabinin wrote: > When remove_stable_node() races with __mmput() and squeezes in between ksm_exit() and exit_mmap(), > the WARN_ON_ONCE(page_mapped(page)) in remove_stable_node() could be triggered. Thanks for doing the work on that. > > Should we just remove the warning? It seems to be safe to do, all callers are able to handle -EBUSY, > or there is a better way to fix this? Please just remove the warning and update the comment. At first I thought it would still be worth leaving the warning in, to explain rare EBUSY; but after looking (as you did) at exactly how remove_stable_node() gets to be called, the places that care about its failure already expect KSM to be quiesced, and tell the admin EBUSY if not. This case is not different, just slightly delayed. So there's no need to try to be any cleverer about it. Though now that you have found the case to be a real one, I do think it would be an improvement for remove_stable_node_chain() not to give up at the first -EBUSY, but remove as much as it can before finishing. But perhaps there's a subtlety that prevents that - I'm not familiar with the stable node chains. Hugh > > > > It's easily reproducible with the following script: > (ksm_test.c attached) > > #!/bin/bash > > gcc -lnuma -O2 ksm_test.c -o ksm_test > echo 1 > /sys/kernel/mm/ksm/run > ./ksm_test & > sleep 1 > echo 2 > /sys/kernel/mm/ksm/run > > and the patch bellow which provokes that race. > > --- > include/linux/ksm.h | 4 +++- > include/linux/mm_types.h | 1 + > kernel/fork.c | 4 ++++ > 3 files changed, 8 insertions(+), 1 deletion(-) > > diff --git a/include/linux/ksm.h b/include/linux/ksm.h > index e48b1e453ff5..18384ea472f8 100644 > --- a/include/linux/ksm.h > +++ b/include/linux/ksm.h > @@ -33,8 +33,10 @@ static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm) > > static inline void ksm_exit(struct mm_struct *mm) > { > - if (test_bit(MMF_VM_MERGEABLE, &mm->flags)) > + if (test_bit(MMF_VM_MERGEABLE, &mm->flags)) { > __ksm_exit(mm); > + mm->ksm_wait = 1; > + } > } > > /* > diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h > index 270aa8fd2800..3df8290528c2 100644 > --- a/include/linux/mm_types.h > +++ b/include/linux/mm_types.h > @@ -463,6 +463,7 @@ struct mm_struct { > > /* Architecture-specific MM context */ > mm_context_t context; > + unsigned long ksm_wait; > > unsigned long flags; /* Must use atomic bitops to access */ > > diff --git a/kernel/fork.c b/kernel/fork.c > index 5fb7e1fa0b05..be6ef4e046f0 100644 > --- a/kernel/fork.c > +++ b/kernel/fork.c > @@ -1074,6 +1074,10 @@ static inline void __mmput(struct mm_struct *mm) > uprobe_clear_state(mm); > exit_aio(mm); > ksm_exit(mm); > + > + if (mm->ksm_wait) > + schedule_timeout_uninterruptible(10*HZ); > + > khugepaged_exit(mm); /* must run before exit_mmap */ > exit_mmap(mm); > mm_put_huge_zero_page(mm); > -- > 2.23.0 >