Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2934270iog; Mon, 20 Jun 2022 07:47:56 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tlHrZpAyHncpuuDsReUmc9BsjoyIIFswf9CLJl4aZOKsdDSwWHH8QfnjJGWK7U439ineD+ X-Received: by 2002:a05:6a00:1481:b0:51c:4e9a:f618 with SMTP id v1-20020a056a00148100b0051c4e9af618mr25596282pfu.43.1655736475893; Mon, 20 Jun 2022 07:47:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655736475; cv=none; d=google.com; s=arc-20160816; b=ZUGo6mXX4FN1zFgLsLk9snOV+xCzvAfZvETtS3E5bM2PcLftNe4xKg79XveGOtDQ+o DjnzVnvXr6FSu1fIaNL3cKpWLPbiayARGjvDtJhFPOy+z66J2oKrhouBcVIIE3K1Q3pZ yMr87t1rlVd38hPpZhxvDt4TgHPhlJZtP3EbnG5eXHgMxVElP+DoErXBg+Yeucn2e+s1 k2LnbKdF3ffoTicx6/LfEUJHGVRR5US3Fs5Z3Ip6Yd8MaifUCkJYXIqbbcLKaK5tzVmC vSQgnDrkXiRoJvcSLyuSc0pYtMLJ2V7R/S0R5Hfj1ZM92qseWD/A5XrzUpGQP6vS58Nf xV5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=tVd1abrCAVnuoDG/6O1kOukir1U0Iwq3YTDWJ+4jDh8=; b=byXTANL7fJWVLkOD3nzJi8u/f0sqqcQvDEvGuAGvT+7EMqeOKCfZict5xnmncUjDxZ TUNsP9Gk0uRCmTYa4irbFcPDwoJyuVV6MMCCNYHQQ3RMo66pE+adZOB3eZxoQsH+6nr8 nrGND+jS95s56KLw+xMeawEoIl9Pzor3xolYn3R2G+TZ7ev9jBYGeHzNGCFiEr3LgUOy HXsmXIvENSpxJR8qTNI60rdu+XX6amDq5iimlpitUrl55F/9kx1gWCznTolO03DliiWD qkHJnsn1Q6m06gcrJVuXZzwItABbx2ogbsH7Svr1pFVv+qQFYFmkQART9ABbxC1HoVke 6beQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b=RA3qEnRO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j8-20020a62e908000000b0051c33c93262si15655948pfh.73.2022.06.20.07.47.43; Mon, 20 Jun 2022 07:47:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b=RA3qEnRO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241575AbiFTOcw (ORCPT + 99 others); Mon, 20 Jun 2022 10:32:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243578AbiFTOci (ORCPT ); Mon, 20 Jun 2022 10:32:38 -0400 Received: from alexa-out-sd-02.qualcomm.com (alexa-out-sd-02.qualcomm.com [199.106.114.39]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 206102DD4C for ; Mon, 20 Jun 2022 06:46:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1655732814; x=1687268814; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=tVd1abrCAVnuoDG/6O1kOukir1U0Iwq3YTDWJ+4jDh8=; b=RA3qEnRO4mbMvrfjkUXWV92JnZtThoJAq6QbehjQp3nbRbjzA0xNAGNi xxdqkrQSA3jpMEjju67ZonMZCpDDIpWC3sXRXkcVUxur/+HDI+VkR8kT1 2PB03QgDqAdYJrTsHgIGvpKD72GF17x0xT2a5cGJHLu87kUeL3VSzBujT g=; Received: from unknown (HELO ironmsg05-sd.qualcomm.com) ([10.53.140.145]) by alexa-out-sd-02.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) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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?