Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp745125ybl; Fri, 9 Aug 2019 13:12:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqxD6FfzoyM+zzCt1CQCWP816HTJRuXuiaRAC5qx4TpS4LXFLUI5xSVqcKxAfBwUIcLdj1tf X-Received: by 2002:a17:902:2ac8:: with SMTP id j66mr19816236plb.273.1565381559681; Fri, 09 Aug 2019 13:12:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565381559; cv=none; d=google.com; s=arc-20160816; b=wZHD8gdzaexUm4R7/+s8TYq8cAeIwo/CymmLRvCjrTdNz9g049HmQXoWtUlRrJw7JF HIPa6howAtl7VM5JsfZBoE6hPWA4hluFNWx66RwFI8EGUdZWP33kxVW0B5jtCT1FUlnx 8p67E9xA/MBVsAj9iMOwlZwBnSu9ghEE3aWgOC2L1hNhN9ZPBlvH8kJ0oaEynvxSYlvD QzN8Zls/wOKkkvIZWybhDclkVk8SF6jjB2/FyQqczWCm8Kf+cQu49u97tpqGE3kOy4tn oivHlWS0yvzQsl2JWd3Am+EOyzq3Fvma7w3agZKIi1gP6u48ht1IlXxEhWYFGzycm4Tj tqIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=dBdWC4SLK43cJm7C5kXT86oBHUFmnxpYuPcIVtB99mc=; b=ytSGNhHUh94So2KHiWbYZNt/AVAWkxKBC5qZry7p9Qbdu8tuIQnZZNWFCoMVo+Bti2 zZJY3knwA0freZOxcnFngQMzzm/zc1Fh65xDTpts/QHkKNxHOB3ZHNnYu9ZBQJlr87Uf RnVr9pGzjiaOd4bkQSLtbgwglb0PxdYYjs56Ft0ERWRDzbAXX9ZbvHxB/omjAkRDvoc3 EZXGcdxvACy1dWa9DYzTLEjCI8WkAYBBzgSUp4PdhTfpF1DmDFK2+ADeXgFCL36fQEAr bb7e5BLN/e3pGz3vYRh4HX65ZkPnQmurPvoAlBkbs8KIPv6DdHKrN6lwXrFtwC5+A+J/ skSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=JVc0EHvA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x20si16072323plm.61.2019.08.09.13.12.23; Fri, 09 Aug 2019 13:12:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=JVc0EHvA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726216AbfHIUKT (ORCPT + 99 others); Fri, 9 Aug 2019 16:10:19 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:41057 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725943AbfHIUKS (ORCPT ); Fri, 9 Aug 2019 16:10:18 -0400 Received: by mail-lj1-f196.google.com with SMTP id d24so93131436ljg.8 for ; Fri, 09 Aug 2019 13:10:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=dBdWC4SLK43cJm7C5kXT86oBHUFmnxpYuPcIVtB99mc=; b=JVc0EHvAHwkTfE7HKrRMTfrqQ3F1FR90NTPgXHMu4aQ3bug1s5Oq7i7I3MwvxsOzYz Ds3mXSofmqFR8MPI89sCmpadOqxRvPkVt8yWLecPUd6B9f29LLMOWf1Kf6+eHrHvOK8F yhy28UequyRQjITaPVvwgcAbxYddRjr7djxq0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=dBdWC4SLK43cJm7C5kXT86oBHUFmnxpYuPcIVtB99mc=; b=gg8zYG1oT9e5pKYmFxKbw6QT8FhG6nMk91yFI1VNxWuqx/PeBNY//V6e9plppDZc9m Q/XlEP/L2QWaMQUjwaFsIn0ILjXAX57764iwyOLZVM9Vg9WIHzRqwuBWj+zuIjSh2ASX NhVhB9KkzXj/nPa1XawlKbTA79dpxKywAy5LLOyCl1p7D7Cz9LkMm3r06k5djJgpmkM1 D4GGQZjRv415On/nebfjyI9Dd9mBsuapH+cmp8NdMP6ynjSn34NC8/td9fMisTHxbckR M3w+6M28g6s3DrOQen9UJsnrDGvBMdXH0JY0I7XoH46/kYh7uOj9LJaOqmxdEpUfAqc/ NLpQ== X-Gm-Message-State: APjAAAU9suTEeuytXIG9GxEdyl5VCvU3csesAJ+wyTJWd+kY4fRqfzdK X64kY301iaWj8kEJtzHmoHer8WfHtR8= X-Received: by 2002:a2e:8559:: with SMTP id u25mr3026295ljj.224.1565381415837; Fri, 09 Aug 2019 13:10:15 -0700 (PDT) Received: from mail-lj1-f170.google.com (mail-lj1-f170.google.com. [209.85.208.170]) by smtp.gmail.com with ESMTPSA id k124sm17748603lfd.60.2019.08.09.13.10.14 for (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Fri, 09 Aug 2019 13:10:14 -0700 (PDT) Received: by mail-lj1-f170.google.com with SMTP id r9so93147079ljg.5 for ; Fri, 09 Aug 2019 13:10:14 -0700 (PDT) X-Received: by 2002:a2e:9a58:: with SMTP id k24mr12475455ljj.165.1565381414234; Fri, 09 Aug 2019 13:10:14 -0700 (PDT) MIME-Version: 1.0 References: <1565278859475.1962@mentor.com> <1565358624103.3694@mentor.com> In-Reply-To: <1565358624103.3694@mentor.com> From: Linus Torvalds Date: Fri, 9 Aug 2019 13:09:58 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Resend [PATCH] kernel/resource.c: invalidate parent when freed resource has childs To: "Schmid, Carsten" Cc: "bp@suse.de" , "dan.j.williams@intel.com" , "mingo@kernel.org" , "dave.hansen@linux.intel.com" , "linux-kernel@vger.kernel.org" , "bhelgaas@google.com" , "osalvador@suse.de" , "rdunlap@infradead.org" , "richardw.yang@linux.intel.com" , "gregkh@linuxfoundation.org" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 9, 2019 at 6:50 AM Schmid, Carsten 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