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=-5.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 F22B3C12002 for ; Mon, 19 Jul 2021 11:13:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DBC18610FB for ; Mon, 19 Jul 2021 11:13:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236478AbhGSKcV (ORCPT ); Mon, 19 Jul 2021 06:32:21 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:11448 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236330AbhGSKcV (ORCPT ); Mon, 19 Jul 2021 06:32:21 -0400 Received: from dggeme703-chm.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4GSzdG1B1WzcfkS; Mon, 19 Jul 2021 19:09:38 +0800 (CST) Received: from [10.174.177.180] (10.174.177.180) by dggeme703-chm.china.huawei.com (10.1.199.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Mon, 19 Jul 2021 19:12:58 +0800 Subject: Re: linux-5.13.2: warning from kernel/rcu/tree_plugin.h:359 To: Boqun Feng CC: Zhouyi Zhou , , Oleksandr Natalenko , linux-kernel , , Chris Clayton , Chris Rankin , Josh Triplett , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Joel Fernandes , rcu , Andrew Morton , Linux-MM , "Huang, Ying" , Matthew Wilcox References: <2245518.LNIG0phfVR@natalenko.name> <6698965.kvI7vG0SvZ@natalenko.name> <20210718215914.GQ4397@paulmck-ThinkPad-P17-Gen-1> <20210719015313.GS4397@paulmck-ThinkPad-P17-Gen-1> From: Miaohe Lin Message-ID: <08803f78-3e99-6b3f-e809-5828fe47cf06@huawei.com> Date: Mon, 19 Jul 2021 19:12:58 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.180] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggeme703-chm.china.huawei.com (10.1.199.99) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org On 2021/7/19 18:14, Boqun Feng wrote: > On Mon, Jul 19, 2021 at 03:43:00AM +0100, Matthew Wilcox wrote: >> On Mon, Jul 19, 2021 at 10:24:18AM +0800, Zhouyi Zhou wrote: >>> Meanwhile, I examined the 5.12.17 by naked eye, and found a suspicious place >>> that could possibly trigger that problem: >>> >>> struct swap_info_struct *get_swap_device(swp_entry_t entry) >>> { >>> struct swap_info_struct *si; >>> unsigned long offset; >>> >>> if (!entry.val) >>> goto out; >>> si = swp_swap_info(entry); >>> if (!si) >>> goto bad_nofile; >>> >>> rcu_read_lock(); >>> if (data_race(!(si->flags & SWP_VALID))) >>> goto unlock_out; >>> offset = swp_offset(entry); >>> if (offset >= si->max) >>> goto unlock_out; >>> >>> return si; >>> bad_nofile: >>> pr_err("%s: %s%08lx\n", __func__, Bad_file, entry.val); >>> out: >>> return NULL; >>> unlock_out: >>> rcu_read_unlock(); >>> return NULL; >>> } >>> I guess the function "return si" without a rcu_read_unlock. >> >> Yes, but the caller is supposed to call put_swap_device() which >> calls rcu_read_unlock(). See commit eb085574a752. > > Right, but we need to make sure there is no sleepable function called > before put_swap_device() called, and the call trace showed the following > happened: > > do_swap_page(): > si = get_swap_device(): > rcu_read_lock(); > lock_page_or_retry(): > might_sleep(); // call a sleepable function inside RCU read-side c.s. > __lock_page_or_retry(): > wait_on_page_bit_common(): > schedule(): > rcu_note_context_switch(); > // Warn here > put_swap_device(); > rcu_read_unlock(); > > , which introduced by commit 2799e77529c2a When in the commit 2799e77529c2a, we're using the percpu_ref to serialize against concurrent swapoff, i.e. there's percpu_ref inside get_swap_device() instead of rcu_read_lock(). Please see commit 63d8620ecf93 ("mm/swapfile: use percpu_ref to serialize against concurrent swapoff") for detail. Thanks. > > [Copy the author] > > Regards, > Boqun > > . >