Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp492413pxb; Wed, 3 Mar 2021 08:10:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJyFaYF7I2C/B0nV+B7hmaGoXxPV2CVlLMAhPd4elQDLowEZosSUaVY6YCEldCElNi1wXVTG X-Received: by 2002:a05:6402:124a:: with SMTP id l10mr12449edw.122.1614787856671; Wed, 03 Mar 2021 08:10:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614787856; cv=none; d=google.com; s=arc-20160816; b=u7EWcukx++rTYBNEDFlFJmmlNrSm1AF9dM6977UEIjrIQ1dQw5iz+gHw6nGHXJnbaW PUrSXTkoa3s18/SpkPyGuV9fQECIFORnbwNZ27+Lh24hkW6Uzmt3+eSwqOhxIfL0dFVH J/ELYqiu/mglhUNfoHO3AyH5idTkOgv9mPhHYSsxk9c+J/u2C6Aa0l+Vb5Mmb2BTmJlH VMGMYdkDfGnr3VwmBg9S4/0YQl+iRq9uy7eqly1gNVkrIhI3vSv8R0mEqGMvNrCfvrdN pvwZk56RfUOsFK3RckrJ7x8n66w6zYgUV7nP/WqKYI8tLvyJO9khJnTnDNo3eevZKe/v RgPA== 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=ei4G8HICU/tyGPclObWf+u6fENUhFFSyCJPlUH7DuvM=; b=TNlB6MJeh+J6wVK6WdclvWcXdqV/nrY1t0vrDRorulduIxwuKmyspL1tpFwcsbwGKl TtCkalWQASIm0Mg4UOmK6VP8sGWGdC157U6TFurUFmwL00dRlethdKAGhlOiwU6Yktcg HEjp/IcFnz2aLoti+BJ079F8rchreuF/myvPJ21bxuhdjXH/RuRVmGU/nUKVqA1XmF0B 3B6mk017BNZBvmEQ+WwIuRtDKvBCuksrmDrXy0yhgEcvXKU64ISsNkNc/q4knt2WZSON jmEQQCQWEsnkgK+hrNK+zOKxusVnkMbJmC3qeKt6011SJ7UdECLjc0xlAjSRMno7OfRQ UnNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wxmUe2Gh; 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 c12si15780114edx.585.2021.03.03.08.10.19; Wed, 03 Mar 2021 08:10:56 -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=wxmUe2Gh; 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 S1346326AbhCAXoo (ORCPT + 99 others); Mon, 1 Mar 2021 18:44:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:58158 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239435AbhCASIo (ORCPT ); Mon, 1 Mar 2021 13:08:44 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1716964F14; Mon, 1 Mar 2021 17:31:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614619908; bh=u4SG6M3G1nmPeiSzVDW4d6z5jO1jgWECCeUY3HyZscE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wxmUe2GhN+qdMCHSRVnAT1Png6X1clBIwvm5u292JFXWyjIn8BGSwLmOBym1NMwjQ 8tm5d/ad+NsEm1PsHWnw4Akedi2AdLPHPffoeMsvkp8maNk7XcP2PNzO210cxkVPHt kCL3J7VZAvi9+y8H1fJ8RSPPxGm3aukN6ge0ydKU= 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 5.10 594/663] seq_file: document how per-entry resources are managed. Date: Mon, 1 Mar 2021 17:14:02 +0100 Message-Id: <20210301161211.252031302@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161141.760350206@linuxfoundation.org> References: <20210301161141.760350206@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.rst | 6 ++++++ 1 file changed, 6 insertions(+) --- a/Documentation/filesystems/seq_file.rst +++ b/Documentation/filesystems/seq_file.rst @@ -217,6 +217,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 ================