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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB2CCC25B08 for ; Sat, 20 Aug 2022 20:59:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E13158D0001; Sat, 20 Aug 2022 16:59:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DC1FA6B0074; Sat, 20 Aug 2022 16:59:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CB0F88D0001; Sat, 20 Aug 2022 16:59:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id BCFAB6B0073 for ; Sat, 20 Aug 2022 16:59:58 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 878C0140ED2 for ; Sat, 20 Aug 2022 20:59:58 +0000 (UTC) X-FDA: 79821188076.25.15DD350 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf04.hostedemail.com (Postfix) with ESMTP id 2A62240097 for ; Sat, 20 Aug 2022 20:59:58 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5159F60BCA; Sat, 20 Aug 2022 20:59:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 83510C433D6; Sat, 20 Aug 2022 20:59:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1661029196; bh=4kMwix/69G0yBDqqAuHOdMHB6BeNOUzbJJVBoUshEGw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=dax9WBA4KxTo8O+AzNPL8dtJUe842xz2gni616L+RuzIX5davGJLQkR0b5mCPsRAQ gScqAN8NMjFrqV7jCJAEvkQh1z/CSy30FHrdRnsy9wh0xYTH3KQEJveO9h+4JdW0ua aINb5hwWT4nXDRvfAJsR3j9WQPqJTjgl9EwO/5Dw= Date: Sat, 20 Aug 2022 13:59:55 -0700 From: Andrew Morton To: Muchun Song Cc: Kefeng Wang , Linux MM , Qian Cai , linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm: fix pgdat->kswap accessed concurrently Message-Id: <20220820135955.1520aa480fe04ab31d4fce1f@linux-foundation.org> In-Reply-To: <1E87F09C-4904-49E2-B45C-C408DD5F6F62@linux.dev> References: <20220820032506.126860-1-wangkefeng.wang@huawei.com> <1E87F09C-4904-49E2-B45C-C408DD5F6F62@linux.dev> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661029198; a=rsa-sha256; cv=none; b=xLJj6HkXVioyOll7l1ldoIdONeJrpmYyNWC7ArLnAv4ienMKmMpMUgLrk9n7IA+nYEvf6x NHflaLG3q8PN85956wxpfjNp28HuzldyVvwwo5TQBWGyyhBf0Yr+Mp47jSTPRrOD6gmfW9 BG/XonwSZtg57PLK+GHPf+waFbNQ5H4= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=dax9WBA4; dmarc=none; spf=pass (imf04.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661029198; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=GMNc3szKafnGkJL0wxxgpNA0cpaXkz16YxNoCuhVs+w=; b=Aflit8hiL5BryxJ4smohVEUYK0Sa85VySZYOIpX8TlD8vzwK7nOMRQaXLfojasHfooeNki kuUbPrN08KBtgcFInhLDAgtAS+RzOlvvF4t7e10lx0D6xMYUMGTq0lwfwI9EirfGKWOkaL G3yUhSudTnX21YGYyow7yrm5rwLSIyI= X-Rspamd-Queue-Id: 2A62240097 X-Stat-Signature: 3ohjnsi3y1m9btcoef5zb8ns3ei6f9as Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=dax9WBA4; dmarc=none; spf=pass (imf04.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1661029198-4649 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 Sat, 20 Aug 2022 15:33:04 +0800 Muchun Song wrote: > > > > + if (IS_ERR(t)) { > > /* failure at boot is fatal */ > > BUG_ON(system_state < SYSTEM_RUNNING); > > pr_err("Failed to start kswapd on node %d\n", nid); > > - pgdat->kswapd = NULL; > > + WRITE_ONCE(pgdat->kswapd, NULL); > > + } else { > > + WRITE_ONCE(pgdat->kswapd, t); > > } > > } > > IIUC, the race is like the followings: > > CPU 0: CPU 1: > > kswapd_run() > pgdat->kswapd = kthread_run() > if (IS_ERR(pgdat->kswapd)) > kswapd_is_running > // load pgdat->kswapd and it is NOT NULL. > pgdat->kswapd = NULL > task_is_running(pgdat->kswapd); // NULL pointer dereference > But don't we still have a bug? Sure, kswapd_is_running() will no longer deref a null pointer. But it now runs kswapd_is_running() against a task which has exited - a use-after-free?