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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9CF6EE4996 for ; Mon, 21 Aug 2023 06:35:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233452AbjHUGfj (ORCPT ); Mon, 21 Aug 2023 02:35:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229734AbjHUGfh (ORCPT ); Mon, 21 Aug 2023 02:35:37 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5D10A7 for ; Sun, 20 Aug 2023 23:35:35 -0700 (PDT) Received: from kwepemm600017.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4RTjMK3mXqzLp90; Mon, 21 Aug 2023 14:32:29 +0800 (CST) Received: from [10.174.179.234] (10.174.179.234) by kwepemm600017.china.huawei.com (7.193.23.234) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Mon, 21 Aug 2023 14:35:31 +0800 Message-ID: <132f7a1a-3219-bdac-5ca4-ad5a54b09616@huawei.com> Date: Mon, 21 Aug 2023 14:35:30 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: [PATCH] mm: memory-failure: use rcu lock instead of tasklist_lock when collect_procs() To: Matthew Wilcox CC: Andrew Morton , Naoya Horiguchi , Miaohe Lin , , , References: <20230821022534.1381092-1-tongtiangen@huawei.com> From: Tong Tiangen In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.179.234] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm600017.china.huawei.com (7.193.23.234) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2023/8/21 12:34, Matthew Wilcox 写道: > On Mon, Aug 21, 2023 at 10:25:34AM +0800, Tong Tiangen wrote: >> +++ b/mm/memory-failure.c >> @@ -546,24 +546,26 @@ static void kill_procs(struct list_head *to_kill, int forcekill, bool fail, >> * Find a dedicated thread which is supposed to handle SIGBUS(BUS_MCEERR_AO) >> * on behalf of the thread group. Return task_struct of the (first found) >> * dedicated thread if found, and return NULL otherwise. >> - * >> - * We already hold read_lock(&tasklist_lock) in the caller, so we don't >> - * have to call rcu_read_lock/unlock() in this function. >> */ >> static struct task_struct *find_early_kill_thread(struct task_struct *tsk) >> { >> struct task_struct *t; >> >> + rcu_read_lock(); >> for_each_thread(tsk, t) { >> if (t->flags & PF_MCE_PROCESS) { >> if (t->flags & PF_MCE_EARLY) >> - return t; >> + goto found; >> } else { >> if (sysctl_memory_failure_early_kill) >> - return t; >> + goto found; >> } >> } >> - return NULL; >> + >> + t = NULL; >> +found: >> + rcu_read_unlock(); >> + return t; >> } > > I don't understand why you need to modify find_early_kill_thread() at > all. It's still true that the caller holds _a_ lock protecting it; the > comment needs to be updated to reflect that it might be the RCU lock > or the tasklist_lock (or did you change all callers?), but there's no > need for this function to take the RCU lock itself, afaics? > > . I've checked that all the paths that call find_early_kill_thread() already hold the rcu lock, and there's really no need to hold the rcu lock here. In the next patch version, here only the comments are modified. Thanks, Tong.