Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp516186pxb; Wed, 3 Mar 2021 08:41:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJzUJGzxDCEYDPbN2DN3clkxztOpZOqFCiAJWVTsP2TOWCX/0ZCc8akqSKRtyowExQ6PkCTX X-Received: by 2002:aa7:d954:: with SMTP id l20mr122853eds.1.1614789694349; Wed, 03 Mar 2021 08:41:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614789694; cv=none; d=google.com; s=arc-20160816; b=nNcUQf6bRsKnSQHIurOghRyNwNgxn2wKbUN2eO3iWo5eFa29twtVclCcSDROyeGdA6 a6KHVeMrUflF61ujo3f9iXNRItMygZ2Lc7NV5yzzE5cnFAxoq/LMNAmBAt3li/CahtTd R2+rCEeZxzreQzoHsh7XlolVeMODNfr7UdJW914r7yROyCytsSwhHYTim+kvVsK/cdHz wAyTCs7A+g/XI+C8nPTZDuzqwu5Sb9RruSEWBpvO5dTrcRbFPRBeDzkEeBecHuG9CRBg UZ59DUWxdol2Q049sUnz5Q3ZlEc5eqXZ6Ktc/t5FRZBIQ9CzIvScqBccGxeyujOKdAt7 zHoA== 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=aDDWHrQCfWsH4LCbwAVln1ouRBp+gpQi9P+j0GWxZxbOlWXBMScflqUcAwaC32twl/ UbjD47cL7CgaKoQdS7oN67z1DhypGA17EflbE5shXiXNYeFormMD56U9lFniFKHzVB+/ kZJiqD3AiGrMtIWwYs8CpaLTq9Nf9praQm4SSbvBB6FEx3Z/fdstplmtLuVbxX7y0l5l LLsadZ58pz6lHRKhGuXrKpvDMXFrW9QCDKSujvTx7XFn3C+tYKrtCmkO8bWC5brVg8sy Im3ntBkhyW0kV/OsCEwObRkXW902GzQYhcXfy3oH/riqGCgWJciqYECq9zRPdAwv8E7x HxiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ymS+Pxwz; 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 dm10si15550543ejc.64.2021.03.03.08.41.02; Wed, 03 Mar 2021 08:41:34 -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=ymS+Pxwz; 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 S239249AbhCAX7y (ORCPT + 99 others); Mon, 1 Mar 2021 18:59:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:37550 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239465AbhCASSr (ORCPT ); Mon, 1 Mar 2021 13:18:47 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3CA2964FE4; Mon, 1 Mar 2021 17:01:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614618083; bh=Dy1QB3L/oD1DT+cDMjob5PukAlH0zJAM5AmLoj9jd8A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ymS+PxwzCojgzsR+LAawXwzrnJxS1JM0redzD8FAFPQII1tKHh0WGuI1tu9qZwRYY yLlKq8QJkxE4aSUjhKhEC6Tn8DHVspOH8eIREuzgLKpUZrzCt7oC72dpXQy60NpeoH FBvZWOlXBaf5aqPdzMYWOP0JHmLKmgNRI423Z2xM= 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.4 301/340] seq_file: document how per-entry resources are managed. Date: Mon, 1 Mar 2021 17:14:05 +0100 Message-Id: <20210301161103.091459740@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161048.294656001@linuxfoundation.org> References: <20210301161048.294656001@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