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 B0C61C43334 for ; Mon, 20 Jun 2022 13:46:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 378E66B0071; Mon, 20 Jun 2022 09:46:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 328B06B0073; Mon, 20 Jun 2022 09:46:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1C9EA8E0001; Mon, 20 Jun 2022 09:46:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 093E36B0071 for ; Mon, 20 Jun 2022 09:46:56 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id CD12380D58 for ; Mon, 20 Jun 2022 13:46:55 +0000 (UTC) X-FDA: 79598739990.07.A4131F7 Received: from alexa-out-sd-01.qualcomm.com (alexa-out-sd-01.qualcomm.com [199.106.114.38]) by imf21.hostedemail.com (Postfix) with ESMTP id 001D51C00AF for ; Mon, 20 Jun 2022 13:46:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1655732815; x=1687268815; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=tVd1abrCAVnuoDG/6O1kOukir1U0Iwq3YTDWJ+4jDh8=; b=wek956gr9RuRA3fbAf1DChPZmKhkyp8rD+0mzYoVz3CaTk3723jzZPqX kGpjsbhgCLQChQsnZM5PVlOij2SS9o8PiZGfDZBLknayHemKlpCVUe1KP YES4tUroiAQCrXticVB9MhbKH5zT5QfEP1DqgMLl4vhzLadkpBA/OBrao E=; Received: from unknown (HELO ironmsg05-sd.qualcomm.com) ([10.53.140.145]) by alexa-out-sd-01.qualcomm.com with ESMTP; 20 Jun 2022 06:46:53 -0700 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg05-sd.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jun 2022 06:46:51 -0700 Received: from nalasex01a.na.qualcomm.com (10.47.209.196) by nasanex01c.na.qualcomm.com (10.47.97.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Mon, 20 Jun 2022 06:46:51 -0700 Received: from qian (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Mon, 20 Jun 2022 06:46:49 -0700 Date: Mon, 20 Jun 2022 09:46:47 -0400 From: Qian Cai To: Miaohe Lin CC: Muchun Song , "Huang, Ying" , , , , Subject: Re: [PATCH v2 2/3] mm/swapfile: fix possible data races of inuse_pages Message-ID: References: <20220608144031.829-1-linmiaohe@huawei.com> <20220608144031.829-3-linmiaohe@huawei.com> <87edzjrcq8.fsf@yhuang6-desk2.ccr.corp.intel.com> <13414d6a-9e72-fb6c-f0a8-8b83ba0455de@huawei.com> <09ffac27-7fe9-0977-cb33-30433e78e662@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01a.na.qualcomm.com (10.47.209.196) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655732815; a=rsa-sha256; cv=none; b=o0y2szLUYC5oMZlZJs4zksWOjbF6DabEaUZeDfAMSTuYrVq9y4hO0m340dmgexCEc86ZJf NQveCMRh2a+GUCiFTq1QPOxwKsuTQwh6A/7yY4Nv4GnUlfIGLB5EOJqxnP/0LwmiZ2U2az b4rJmLarqT51P4a9AoXjyGTl2DlWIjY= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcdkim header.b=wek956gr; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf21.hostedemail.com: domain of quic_qiancai@quicinc.com designates 199.106.114.38 as permitted sender) smtp.mailfrom=quic_qiancai@quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655732815; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=tVd1abrCAVnuoDG/6O1kOukir1U0Iwq3YTDWJ+4jDh8=; b=NuW7v0XUH+4S++QzZz711+TBiH8Ygh3nH+NITaVMcim63MGsK6Vnfwd8SWeV2U3LzdPWoy XjK0knXjQVTi/pCYxX1RxqFIc7MMEd5ynqrkJ8AFu/hdWUkREoLkaUcFSjzPruACfW9USG +yDZcR6BIxygGbzEGij+nURRplT9iNM= Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcdkim header.b=wek956gr; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf21.hostedemail.com: domain of quic_qiancai@quicinc.com designates 199.106.114.38 as permitted sender) smtp.mailfrom=quic_qiancai@quicinc.com X-Stat-Signature: yees7d8xoh3xcqtz3ch4nnabp8w7w9r8 X-Rspamd-Queue-Id: 001D51C00AF X-Rspam-User: X-Rspamd-Server: rspam03 X-HE-Tag: 1655732814-560729 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, Jun 20, 2022 at 08:32:27PM +0800, Miaohe Lin wrote: > >>>>> --- a/mm/swapfile.c > >>>>> +++ b/mm/swapfile.c > >>>>> @@ -2646,7 +2646,7 @@ static int swap_show(struct seq_file *swap, void *v) > >>>>> } > >>>>> > >>>>> bytes = si->pages << (PAGE_SHIFT - 10); > >>>>> - inuse = si->inuse_pages << (PAGE_SHIFT - 10); > >>>>> + inuse = READ_ONCE(si->inuse_pages) << (PAGE_SHIFT - 10); > >>>>> > >>>>> file = si->swap_file; > >>>>> len = seq_file_path(swap, file, " \t\n\\"); > >>>>> @@ -3265,7 +3265,7 @@ void si_swapinfo(struct sysinfo *val) > >>>>> struct swap_info_struct *si = swap_info[type]; > >>>>> > >>>>> if ((si->flags & SWP_USED) && !(si->flags & SWP_WRITEOK)) > >>>>> - nr_to_be_unused += si->inuse_pages; > >>>>> + nr_to_be_unused += READ_ONCE(si->inuse_pages); > >>>>> } > >>>>> val->freeswap = atomic_long_read(&nr_swap_pages) + nr_to_be_unused; > >>>>> val->totalswap = total_swap_pages + nr_to_be_unused; > >>>> > >>>> READ_ONCE() should be paired with WRITE_ONCE(). So, change the writer > >>>> side too? > >>> > >>> READ_ONCE() is used to fix the complaint of concurrent accessing to si->inuse_pages from KCSAN here. > >>> The similar commit is 218209487c3d ("mm/swapfile: fix data races in try_to_unuse()"). IMHO, it's fine > >> > >> I think the fix 218209487c3d is incomplete. The write side in swap_range_free() should > >> also be fixed. Otherwise, IIUC, it cannot stop KCSAN complaining. > > > > I tend to agree with you. READ_ONCE() should be paired with WRITE_ONCE() theoretically. But WRITTE_ONCE() > > is ignored while the commit is introduced. Add Qian Cai for helping verify it. It's very kind of @Qian Cai > > if he could tell us whether WRITTE_ONCE() is ignored deliberately. The write side should be protected by the lock swap_info_struct::lock. Is that not the case here?