Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp278047rwl; Tue, 4 Apr 2023 23:53:42 -0700 (PDT) X-Google-Smtp-Source: AKy350ahPfjV+40TumMpVI31UaH/YfSKZj2ceAs13BAFUPtsjpoyqolUrDcYXrzevYC30H9y+44c X-Received: by 2002:a17:907:6e25:b0:931:b34:4172 with SMTP id sd37-20020a1709076e2500b009310b344172mr2602950ejc.3.1680677622546; Tue, 04 Apr 2023 23:53:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680677622; cv=none; d=google.com; s=arc-20160816; b=RgJMGMg0hmYFC5x26W5zuq2r1IsBj4Vp2wHH7WNjSJNlNaerCHVzpMoSCXHaT32AUa PcRI0pT7TyFUvEt0T7uYE0gKAwMpsqL+bvaAMOXp+VHy9iKj+PmIUq3iCVBnpFWxKHlc AxbHPPjy/OrV1e9C2M96/fMaVPqaVYGD+f4tNEm4jUQ/xepwsdtkjY0qusMIJiklQx4x shBcnF2N6mkq13b7xFrcvPmaE+8H52HNzR2OG41jBrqtz/wDoHcgTRZ3o1diwiYa2E3f VwFDuRyQ1tuOE6g5l2wvnd7wt3KDGJSNUbyymLItm1yJhCNtwMXeDKn02mk6Qb18xdlK 7IeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id; bh=il0uAFHDKDYLRhMfO0R2H8qEnGZStihLGm/EoXqx4fI=; b=TDgpdHvHVLIvxEphxfoOQDbYjqpAVTnUiacJoRIKPMgquXzCXLr+N36DYNvd/SGNA9 HhibAru3YzukrS7ZbYEalBnqC06vDKgpnHgvYq/MPed63yFgoGQtpzO6MbuUpRLx/C4a E1+RjQzCTfRVzhUkhG5EOsUuq9Ss7z/R3535OYh8aGS65H290gSRpmz5PIMBHOzFpqhK P/sNh5lkyATpro6qVJcD5VtFzzM+kehVRPtPa5VmMNbTR8sHZzZ6Suowm682PVYRg/bp TJuzVlaKPxezd7zZJ0tTAws4EMzdkxXr54mO+iGoSG6TEtaWMx/p3JABjcWRP/XvY+TT gFHQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qo3-20020a170907212300b00930371d2698si6439016ejb.894.2023.04.04.23.53.16; Tue, 04 Apr 2023 23:53:42 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236940AbjDEGuD (ORCPT + 99 others); Wed, 5 Apr 2023 02:50:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237111AbjDEGt4 (ORCPT ); Wed, 5 Apr 2023 02:49:56 -0400 Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 686B14693; Tue, 4 Apr 2023 23:49:54 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R211e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=rongwei.wang@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0VfOIfDC_1680677388; Received: from 30.221.128.100(mailfrom:rongwei.wang@linux.alibaba.com fp:SMTPD_---0VfOIfDC_1680677388) by smtp.aliyun-inc.com; Wed, 05 Apr 2023 14:49:49 +0800 Message-ID: <527978d9-3f6f-b507-5f0f-b24311ff78e4@linux.alibaba.com> Date: Wed, 5 Apr 2023 14:49:48 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] mm/swap: fix swap_info_struct race between swapoff and get_swap_pages() To: Andrew Morton Cc: bagasdotme@gmail.com, willy@infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Aaron Lu References: <20230401221920.57986-1-rongwei.wang@linux.alibaba.com> <20230404154716.23058-1-rongwei.wang@linux.alibaba.com> <20230404122600.88257a623c7f72e078dcf705@linux-foundation.org> Content-Language: en-US From: Rongwei Wang In-Reply-To: <20230404122600.88257a623c7f72e078dcf705@linux-foundation.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-8.0 required=5.0 tests=ENV_AND_HDR_SPF_MATCH, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=unavailable 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 Hi Andrew On 4/5/23 3:26 AM, Andrew Morton wrote: > On Tue, 4 Apr 2023 23:47:16 +0800 Rongwei Wang wrote: > >> The si->lock must be held when deleting the si from >> the available list. >> >> ... >> >> --- a/mm/swapfile.c >> +++ b/mm/swapfile.c >> @@ -679,6 +679,7 @@ static void __del_from_avail_list(struct swap_info_struct *p) >> { >> int nid; >> >> + assert_spin_locked(&p->lock); >> for_each_node(nid) >> plist_del(&p->avail_lists[nid], &swap_avail_heads[nid]); >> } >> @@ -2434,8 +2435,8 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile) >> spin_unlock(&swap_lock); >> goto out_dput; >> } >> - del_from_avail_list(p); >> spin_lock(&p->lock); >> + del_from_avail_list(p); >> if (p->prio < 0) { >> struct swap_info_struct *si = p; >> int nid; > So we have > > swap_avail_lock > swap_info_struct.lock > swap_cluster_info.lock > > Is the ranking of these three clearly documented somewhere? It seems have swap_lock swap_info_struct.lock swap_avail_lock I just summary the ranking of these three locks by reading code, not find any documents (maybe have). > > > Did you test this with lockdep fully enabled? > > > I'm thinking that Aaron's a2468cc9bfdff ("swap: choose swap device > according to numa node") is the appropriate Fixes: target - do you > agree? Yes, I'm sure my latest test version has included Aaron's a2468cc9bfdff, and my test .config has enabled CONFIG as below: CONFIG_LOCK_DEBUGGING_SUPPORT=y CONFIG_PROVE_LOCKING=y CONFIG_DEBUG_SPINLOCK=y CONFIG_DEBUG_LOCK_ALLOC=y CONFIG_LOCKDEP=y CONFIG_DEBUG_LOCKDEP=y CONFIG_DEBUG_ATOMIC_SLEEP=y > > > These functions use identifier `p' for the swap_info_struct*, whereas > most other code uses the much more sensible `si'. That's just rude. > But we shouldn't change that within this fix. Indeed, It's confusing more or less to use both 'si' and 'p'. I can ready for another patch to replace 'p' with 'si'. Thanks.