Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3560547pxb; Mon, 1 Mar 2021 13:22:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJxQ4369Q+FEyOmsXN0T27SoGxi+eZY5tcA43va5eReHldCK+59KK9s+d+sElhSCz84oA+3n X-Received: by 2002:a05:6402:b48:: with SMTP id bx8mr7495026edb.162.1614633733381; Mon, 01 Mar 2021 13:22:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614633733; cv=none; d=google.com; s=arc-20160816; b=q/FABFcjz3cXqW8PHOjc95bM68YYagqAdkknB1iD8+Rrd0VqvrBrftAO6KVji1iP0q 8KngGWvjxUfkI+lGtTaGebFZW8oAn3MBDxBC/eRK9k3CnzkJHs8XFRmNelDttmwAZn6j /5oXb476XjzhC0l4/XawvXWrCN4IS3uSb55UzwDKpm2hSuRRb4uZ53AQMtAbMDDu/4Nc B7piAvGI/9t7WpwV9NOluRqKSfrveQ8SZdn8Qlu6uoUgxZ5/GH1WIzqByXkac0d896Q0 EmLQaVtLHol3XeFdWSWyT/LJ3lY9t1y73tHBNwX2m1nUmdRT4A37gYvYhFloBK4o6pfA YTxg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=uKPHOWfOWV3g/pGx6KzZg5UwUaWj13vTnqETdqnHdug=; b=L66LOoQcqzW27LeqFx2U1se4wPI2vNIti/WiG2wP6rwE8rrGYYScuTIYzOFjhu5OpN vff8sDLNNevU6cM5F8dM31RRVezsgmiWpjWQmUKGE4fEWSwLFtVi2khbYEyvS8H5QRsr wBDXtxfiRSeADBIOPfTYuTSDPuUDmyoLEIfYJZXETg+SGNCEoCRZpkJtb68q5aPbswDC gsjiyB2zminoxzKSUar8z9dLEmM3G2sTm/XzSrSXZhbx72c5PI/KFQiqrQNM9mIkQEv8 6mbtFbxA7J2qt4FfaCQSry5BIA4FS+whbrb9IGvkSgf+NTfoJjViSWdtSBKpRIzsx1Uc vfrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kFyiccAW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y11si12096790ejd.56.2021.03.01.13.21.50; Mon, 01 Mar 2021 13:22:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kFyiccAW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244415AbhCAVTL (ORCPT + 99 others); Mon, 1 Mar 2021 16:19:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:48318 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237016AbhCARPp (ORCPT ); Mon, 1 Mar 2021 12:15:45 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id B74026503F; Mon, 1 Mar 2021 16:45:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614617151; bh=Dy1QB3L/oD1DT+cDMjob5PukAlH0zJAM5AmLoj9jd8A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kFyiccAWvxVoz0NZ7PBAzXdsuidx2HESPtRJR3AkjHdJodo79rse4T/WVfClC6TO7 YnISmRWnNfBeIKJQ0Me1jD9v/R/rKLVMq3nzOTW+E4A3qelhaZFyBM4qDsXclr2L6i LWUmSck/gbVBv0xXshV93GsUUnvPNH73SCuwrPBw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, NeilBrown , Xin Long , Alexander Viro , Jonathan Corbet , Ingo Molnar , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Vlad Yasevich , Neil Horman , Marcelo Ricardo Leitner , "David S. Miller" , Andrew Morton , Linus Torvalds Subject: [PATCH 4.19 219/247] seq_file: document how per-entry resources are managed. Date: Mon, 1 Mar 2021 17:13:59 +0100 Message-Id: <20210301161042.397243992@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161031.684018251@linuxfoundation.org> References: <20210301161031.684018251@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: NeilBrown commit b3656d8227f4c45812c6b40815d8f4e446ed372a upstream. Patch series "Fix some seq_file users that were recently broken". A recent change to seq_file broke some users which were using seq_file in a non-"standard" way ... though the "standard" isn't documented, so they can be excused. The result is a possible leak - of memory in one case, of references to a 'transport' in the other. These three patches: 1/ document and explain the problem 2/ fix the problem user in x86 3/ fix the problem user in net/sctp This patch (of 3): Users of seq_file will sometimes find it convenient to take a resource, such as a lock or memory allocation, in the ->start or ->next operations. These are per-entry resources, distinct from per-session resources which are taken in ->start and released in ->stop. The preferred management of these is release the resource on the subsequent call to ->next or ->stop. However prior to Commit 1f4aace60b0e ("fs/seq_file.c: simplify seq_file iteration code and interface") it happened that ->show would always be called after ->start or ->next, and a few users chose to release the resource in ->show. This is no longer reliable. Since the mentioned commit, ->next will always come after a successful ->show (to ensure m->index is updated correctly), so the original ordering cannot be maintained. This patch updates the documentation to clearly state the required behaviour. Other patches will fix the few problematic users. [akpm@linux-foundation.org: fix typo, per Willy] Link: https://lkml.kernel.org/r/161248518659.21478.2484341937387294998.stgit@noble1 Link: https://lkml.kernel.org/r/161248539020.21478.3147971477400875336.stgit@noble1 Fixes: 1f4aace60b0e ("fs/seq_file.c: simplify seq_file iteration code and interface") Signed-off-by: NeilBrown Cc: Xin Long Cc: Alexander Viro Cc: Jonathan Corbet Cc: Ingo Molnar Cc: Dave Hansen Cc: Andy Lutomirski Cc: Peter Zijlstra Cc: Vlad Yasevich Cc: Neil Horman Cc: Marcelo Ricardo Leitner Cc: "David S. Miller" Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- Documentation/filesystems/seq_file.txt | 6 ++++++ 1 file changed, 6 insertions(+) --- a/Documentation/filesystems/seq_file.txt +++ b/Documentation/filesystems/seq_file.txt @@ -192,6 +192,12 @@ between the calls to start() and stop(), is a reasonable thing to do. The seq_file code will also avoid taking any other locks while the iterator is active. +The iterater value returned by start() or next() is guaranteed to be +passed to a subsequent next() or stop() call. This allows resources +such as locks that were taken to be reliably released. There is *no* +guarantee that the iterator will be passed to show(), though in practice +it often will be. + Formatted output