All of lore.kernel.org
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: "Schmid, Carsten" <Carsten_Schmid@mentor.com>
Cc: "bp@suse.de" <bp@suse.de>,
	"dan.j.williams@intel.com" <dan.j.williams@intel.com>,
	"mingo@kernel.org" <mingo@kernel.org>,
	"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"bhelgaas@google.com" <bhelgaas@google.com>,
	"osalvador@suse.de" <osalvador@suse.de>,
	"rdunlap@infradead.org" <rdunlap@infradead.org>,
	"richardw.yang@linux.intel.com" <richardw.yang@linux.intel.com>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>
Subject: Re: Resend [PATCH] kernel/resource.c: invalidate parent when freed resource has childs
Date: Fri, 9 Aug 2019 13:09:58 -0700	[thread overview]
Message-ID: <CAHk-=wi=3y4XW1RA15crZpbDy8Z0pgQL7nHeTn69MX1xm3J4yw@mail.gmail.com> (raw)
In-Reply-To: <1565358624103.3694@mentor.com>

On Fri, Aug 9, 2019 at 6:50 AM Schmid, Carsten
<Carsten_Schmid@mentor.com> wrote:
>
> @@ -1200,6 +1200,15 @@ void __release_region(struct resource *parent, resource_size_t start,
>                         write_unlock(&resource_lock);
>                         if (res->flags & IORESOURCE_MUXED)
>                                 wake_up(&muxed_resource_wait);
> +
> +                       write_lock(&resource_lock);
> +                       if (res->child) {
> +                               printk(KERN_WARNING "__release_region: %s has child %s,"
> +                                               "invalidating childs parent\n",
> +                                               res->name, res->child->name);
> +                               res->child->parent = NULL;
> +                       }
> +                       write_unlock(&resource_lock);
>                         free_resource(res);

So I think that this should be inside the previous resource_lock, and
before the whole "wake up muxed resource".

Also, a few other issues:

 - what about other freeing cases?  I'm looking at

        release_mem_region_adjustable()

   which has the same pattern where a resource may be freed.

 - what about multiple children? Your patch sets res->child->parent to
NULL, but what about possible other children (iow, the
res->child->sibling list)

 - releasing a resource without having released its children is a
nasty bug, but the bug is now here in release_region, it is in the
*caller*. The printk() (or pr_warn()) doesn't really help find that.

So my gut feel is that this patch is a symptom of a real bug, and a
warning is worthwhile to fix that bug, but more thought is needed.

Maybe something more along the line of

    diff --git a/kernel/resource.c b/kernel/resource.c
    index 7ea4306503c5..ebe06d77b06a 100644
    --- a/kernel/resource.c
    +++ b/kernel/resource.c
    @@ -1211,6 +1211,8 @@ void __release_region(struct resource
*parent, resource_size_t start,
                        }
                        if (res->start != start || res->end != end)
                                break;
    +                   if (WARN_ON_ONCE(res->child))
    +                           break;
                        *p = res->sibling;
                        write_unlock(&resource_lock);
                        if (res->flags & IORESOURCE_MUXED)

would be more appropriate? It simply refuses to free a resource that
has children, and gives a warning (with a backtrace) for the situation
(since clearly we now end up with a resource leak).

                Linus

  parent reply	other threads:[~2019-08-09 20:10 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-08 15:40 [PATCH] kernel/resource.c: invalidate parent when freed resource has childs Schmid, Carsten
2019-08-09 13:50 ` Resend " Schmid, Carsten
2019-08-09 16:59   ` Dan Williams
2019-08-09 18:37   ` Joe Perches
2019-08-09 18:54     ` [PATCH] kernel/resource.c: Convert printks to pr_<level> Joe Perches
2019-08-09 20:09   ` Linus Torvalds [this message]
2019-08-09 22:38   ` Resend [PATCH] kernel/resource.c: invalidate parent when freed resource has childs Wei Yang
2019-08-09 22:45     ` Linus Torvalds
2019-08-10  0:44       ` Wei Yang
2019-08-12  8:39         ` AW: " Schmid, Carsten
2019-08-13  8:09       ` Schmid, Carsten
2019-08-14 14:48       ` [PATCH v2] " Schmid, Carsten
2019-08-14 16:29         ` Wei Yang
2019-08-15  8:18           ` AW: " Schmid, Carsten
2019-08-15 13:03             ` Wei Yang
2019-08-15 13:17               ` AW: " Schmid, Carsten
2019-08-16 10:18                 ` [PATCH] kernel/resource.c: warn if released region has children Schmid, Carsten

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHk-=wi=3y4XW1RA15crZpbDy8Z0pgQL7nHeTn69MX1xm3J4yw@mail.gmail.com' \
    --to=torvalds@linux-foundation.org \
    --cc=Carsten_Schmid@mentor.com \
    --cc=bhelgaas@google.com \
    --cc=bp@suse.de \
    --cc=dan.j.williams@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=osalvador@suse.de \
    --cc=rdunlap@infradead.org \
    --cc=richardw.yang@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.