Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp6422899rwl; Tue, 4 Apr 2023 12:28:08 -0700 (PDT) X-Google-Smtp-Source: AKy350Zo4aBFLICpZu+IDRTpaQR4aJBW/TrjVKrWQvKPLgXfYO8MPFMzWwEzdzAZZ5EPxQTP9V9g X-Received: by 2002:a05:6402:120a:b0:502:8f49:2552 with SMTP id c10-20020a056402120a00b005028f492552mr492757edw.27.1680636488423; Tue, 04 Apr 2023 12:28:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680636488; cv=none; d=google.com; s=arc-20160816; b=OUF7FRRkKLJkvluLTr5Jr3uys4noi+mITjy02tm6Hv7SIPibQGxbacAWHnpViKZ0Un 9VEdTR7A2ZbgQFoM6nDYap0OIyq4F3JvPi/DyxBBDk2ZapxT7p/RS+d+fxcHpCadPOV0 jJYdpmBuxDGyQV365upQTHRgF6maR8k42YvHTUBKSnaj25rvejG/fXYHYP74nhAa0XPI SVoNNyOldBPHaOW/IVIiT57u97pdSYT2Wr1yL7p2iVz8fDfO/xf85Qm5upkcbPJWj2y2 N3EuNYsBZsmsMZtPzU7kyp6NZzSrypiWfmzG2tSNhbnvQFIGR4C5pJoPZl/AR6zVIrjE 3zDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=6UDRnE/+SyVTI3fZAJtjXB98vPVMothKRQ1lB71UvEs=; b=Mvl8xB3a31M2+hlWNxVNTQBuLSfKw5Al9lV2IuD6Bn9sx8MG5a9Gdk74fAI80XBad7 KHBO/Y3iiWYegUKSrdmFXeU7DsOmkPOGIrwKaWuD1JRoXinQ0YYEVNJp/BiaqfB3eWJg /bD7kNoFS6AuRo9Fu1k8VDvQNvC9ASLSZ+8dHRIRfN7h2NTCBPKZzBePFvYnI1phbsFx H/dalSJGG/1Za9NVeDfwrz0EV2ZLgKO+ciWEUkCfMf/xwnOQzSRTyX8BHVjfmoKZAtpH AERIsZvlwYvONRePu/G86bvensJ96D3MnCdjXIZVOwZRwZgbvUZJeqaDeXRIDIHUEetg Ou4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=gk0Oo0mS; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g8-20020aa7c588000000b004abd2054781si9949996edq.92.2023.04.04.12.27.43; Tue, 04 Apr 2023 12:28:08 -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=@linux-foundation.org header.s=korg header.b=gk0Oo0mS; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235610AbjDDT0F (ORCPT + 99 others); Tue, 4 Apr 2023 15:26:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235505AbjDDT0D (ORCPT ); Tue, 4 Apr 2023 15:26:03 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 851782D79; Tue, 4 Apr 2023 12:26:02 -0700 (PDT) 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 21A6663913; Tue, 4 Apr 2023 19:26:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44CBFC433D2; Tue, 4 Apr 2023 19:26:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1680636361; bh=MGYgQ5Bh2P8Cc6or0I+ZKDCXT0ChcvmEjyPmkuyY6ZM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=gk0Oo0mSm++qDOHDzArLm/6KLAml4dXxc378kuLNpp6WlwW34I9ux+4rdH+D3wGfI /dsm74lRZT89ok+cPVq1VZ/vXmLAeBHXBn+WSwv1LlwPrDNwZZYPAYhtORxC4tmSWF BhRGjlOi6THsS1hSj5RHhhvb9gQLNciLUwiCKZBY= Date: Tue, 4 Apr 2023 12:26:00 -0700 From: Andrew Morton To: Rongwei Wang Cc: bagasdotme@gmail.com, willy@infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Aaron Lu Subject: Re: [PATCH v2] mm/swap: fix swap_info_struct race between swapoff and get_swap_pages() Message-Id: <20230404122600.88257a623c7f72e078dcf705@linux-foundation.org> In-Reply-To: <20230404154716.23058-1-rongwei.wang@linux.alibaba.com> References: <20230401221920.57986-1-rongwei.wang@linux.alibaba.com> <20230404154716.23058-1-rongwei.wang@linux.alibaba.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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 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? 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? 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.