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=-24.8 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,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 0D9F1C433B4 for ; Mon, 10 May 2021 23:43:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 911C161466 for ; Mon, 10 May 2021 23:43:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 911C161466 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 095138E0003; Mon, 10 May 2021 19:43:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 044B48E0001; Mon, 10 May 2021 19:43:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E00A38E0003; Mon, 10 May 2021 19:43:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0211.hostedemail.com [216.40.44.211]) by kanga.kvack.org (Postfix) with ESMTP id C26EE8E0001 for ; Mon, 10 May 2021 19:43:08 -0400 (EDT) Received: from smtpin33.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 7AAF48778 for ; Mon, 10 May 2021 23:43:08 +0000 (UTC) X-FDA: 78126949656.33.DCAC2D4 Received: from mail-ot1-f41.google.com (mail-ot1-f41.google.com [209.85.210.41]) by imf27.hostedemail.com (Postfix) with ESMTP id 1729180192E4 for ; Mon, 10 May 2021 23:43:06 +0000 (UTC) Received: by mail-ot1-f41.google.com with SMTP id f75-20020a9d03d10000b0290280def9ab76so15977469otf.12 for ; Mon, 10 May 2021 16:43:07 -0700 (PDT) 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=nI6OyGK/NDS5KWwyMcxjHYV++Bw+P/38diaFjV4zBiw=; b=XkLmCEA2tZEsOS/on3p917VhWFUcl7NKtWoH8X+5ICOWQA9u6LahaURWjQ9oOX7lQs nZ4hLFWGHFpyLxjIo5yX1Cl/shVaT50CuVuZoAU282yqDKC0ENPL2X8mCH/PmhLWatm4 73PtM05PUCWd+CFi2fqAg94B9RoBKdViq10QhRWMxkCuWc3Z/iVsKLG+J8IIUetA+6QL 0yBKuttVB/+qHl2Nl/1ghdNfRDN3D9BaObcHMn4HSKndwBx4t/SwllWik37yjCJZgeUa W2QyvCdI82v7AGB9qAlntdxswXFb40aSMghDoxeq4EwFTMmrJ4iKjx5c9BC+k9Su8/qM 8VLQ== 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=nI6OyGK/NDS5KWwyMcxjHYV++Bw+P/38diaFjV4zBiw=; b=RBMoZJ1hp9S03R7FGrvN7JaDJuZ5bujmYdLy7OQmdb3C2FL8VAnjI+j+X6DRUW9u8i 2HL/3Xx55TerumJD8WjGQr9HjSoIRF8icBNmHpk/fUAR6eRKOKhK7H4RTlYuvFHSUCkq 3hAbd+f8SJ2LcQNbrHPqmtbE1x/OdktPkQglFXIjUpMgn+dvgdbqiy82dMuvqtncHPgF xmCIJKryrwAGU50/h2qPKpvkAna/bdKJx4HNkxplSgF9pxqdfLVM6o70a2q84tZyvYo0 XQY8CzYx2Tth5y45zzG9NDEm18N0uJRqay9F0ZB83ATkvWJce/fOnfoET88ezng7h949 Abiw== X-Gm-Message-State: AOAM5306Y4AEACSBqjc2Nf/Fc7JAbBcOuBk+JRSSTt6HaNKI0XkiG2o4 ArVOncgwTEVfAblpNeSSy/2Whw== X-Google-Smtp-Source: ABdhPJwc7k8WryWRBA8BZ3WaBx9TJKkdH+Q2Mb1JowR0hD3dnCw13CNL/cexiLI7pDcx9SPE7hQxlw== X-Received: by 2002:a05:6830:1b6e:: with SMTP id d14mr6931963ote.65.1620690187161; Mon, 10 May 2021 16:43:07 -0700 (PDT) Received: from eggly.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id n98sm3446769ota.24.2021.05.10.16.43.05 (version=TLS1 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Mon, 10 May 2021 16:43:06 -0700 (PDT) Date: Mon, 10 May 2021 16:42:48 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Miaohe Lin cc: Hugh Dickins , Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH] ksm: Revert "use GET_KSM_PAGE_NOLOCK to get ksm page in remove_rmap_item_from_tree()" In-Reply-To: <0e04877c-5b2d-b810-7464-108e793b84d3@huawei.com> Message-ID: References: <0e04877c-5b2d-b810-7464-108e793b84d3@huawei.com> User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=XkLmCEA2; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf27.hostedemail.com: domain of hughd@google.com designates 209.85.210.41 as permitted sender) smtp.mailfrom=hughd@google.com X-Stat-Signature: 8wtyzyosyzgf6ki4dkfoffg9k796pgd1 X-Rspamd-Queue-Id: 1729180192E4 X-Rspamd-Server: rspam02 Received-SPF: none (google.com>: No applicable sender policy available) receiver=imf27; identity=mailfrom; envelope-from=""; helo=mail-ot1-f41.google.com; client-ip=209.85.210.41 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1620690186-729683 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 Mon, 10 May 2021, Miaohe Lin wrote: > On 2021/5/10 13:59, Hugh Dickins wrote: > > This reverts commit 3e96b6a2e9ad929a3230a22f4d64a74671a0720b. > > General Protection Fault in rmap_walk_ksm() under memory pressure: > > remove_rmap_item_from_tree() needs to take page lock, of course. > > > > I'am really sorry about it! And many thanks for this bugfix! > It seems rmap_walk_ksm() relies on the page lock to protect against > concurrent modifications to that page's node of the stable tree. > Could you please add a comment in remove_rmap_item_from_tree() to > clarify this in case similar trouble again? Many thanks! Sorry, no. Page lock is held by callers of stable_tree_append() when adding an rmap_item to the tree, and held by callers of rmap_walk_ksm() (see VM_BUG_ON_PAGE there) when walking the tree: you would surely expect some kind of locking when removing an rmap_item from the tree, and the appropriate page lock is what GET_KSM_PAGE_LOCK provided. I do not want us to go through the kernel source adding a comment /* We really mean to take this lock: it protects against concurrency */ every time we take a lock in the kernel: you should generally assume that if a lock is taken, then the writer intended it to be taken. There are sure to be some exceptions, where a lock is taken pointlessly: but please look deeper before assuming that is the case. Hugh > > > Signed-off-by: Hugh Dickins > > --- > > > > mm/ksm.c | 3 ++- > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > --- 5.13-rc1/mm/ksm.c 2021-05-09 17:03:44.010422188 -0700 > > +++ linux/mm/ksm.c 2021-05-09 22:12:39.403008350 -0700 > > @@ -776,11 +776,12 @@ static void remove_rmap_item_from_tree(s > > struct page *page; > > > > stable_node = rmap_item->head; > > - page = get_ksm_page(stable_node, GET_KSM_PAGE_NOLOCK); > > + page = get_ksm_page(stable_node, GET_KSM_PAGE_LOCK); > > if (!page) > > goto out; > > > > hlist_del(&rmap_item->hlist); > > + unlock_page(page); > > put_page(page); > > > > if (!hlist_empty(&stable_node->hlist))