Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1874970imm; Thu, 7 Jun 2018 01:35:15 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJRFFyEbQtY9RQpQAsn6ZKm4qAF7nF1zzwhvZKjDNiEwx1bJQZlAhrayhr8B/tkRA8o7ajR X-Received: by 2002:a65:468e:: with SMTP id h14-v6mr786075pgr.89.1528360515680; Thu, 07 Jun 2018 01:35:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528360515; cv=none; d=google.com; s=arc-20160816; b=Sdo524HgsPkp0d8jz+AlRPdRk4NcJ0QsGsO8DyuZRng+ycELJG3BtJLnK37eh/X5oa Ub4IARo9VVUEmeoQcwHLf2uCbdXz7duIfz7a/HKg6ynzYrJxTYsT2TacB4H/YxZsOI8D 3NGP5pzU5VVkBiLC0a/y78BBaIYxEAEm6ClzLgR8RNTy8gMoviBCnkKEHnBMm81DozAG HwYf/OkMrejs3YOclnAvOVzlV4+zGxc+DzaDN3CS4AGYDsXuJ+vGBqZZyIBP7YE48cZ2 1BBVXjk4cU6hKpyM/KjmTe4VUuyYsVH4wFclLeFSRV7vHWi+lDCBkqLWtnTLXUzZj/3c ahlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=9A5dN0QjL00fcNXWqv1b9cOIwJhvJ+gWV7HKCjxtWsM=; b=1F1eBNUlwUROjbXBm+vzbxPSKBz2AnXtUTyCZXESWDlEuYmUXIwNVy8Ghiqh+U3jBa MYZ5Qywl4REzp19w3JkmR3Owymir0Y4BAPcWTYK5oHbkCKT1vXk8f5fOz96bI37iA0EK lFbnwR2GHl8S3qcIivV6vRmllySvJMZ+WNf2I5+3FeN78Srb5lntsoFHQk+plIP6AUI9 2WjsS80N070qD+a+wL6wnY4jp66Lwp4QjNqr+qy5swbaBkrT6p/3395F51gpcLNJ9rqE YtihE68VeY1htMygqEkyuPuP6FTfY6GTRMYp8DkgsCItzUZz95qKzEhel87M4zjl+3W9 zEOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=b3fN0R5n; 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 d12-v6si41942327pgq.154.2018.06.07.01.35.00; Thu, 07 Jun 2018 01:35:15 -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=@kernel.org header.s=default header.b=b3fN0R5n; 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 S932589AbeFGIe2 (ORCPT + 99 others); Thu, 7 Jun 2018 04:34:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:60856 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752570AbeFGIe0 (ORCPT ); Thu, 7 Jun 2018 04:34:26 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EA1D020874; Thu, 7 Jun 2018 08:34:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1528360465; bh=P5WJNCsKG9nw3u6hXhYyXT9BaBN8VsWkuwVqXsD7UWs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=b3fN0R5nxzJ2zrG/0z7eO452gv95RZkzspMkV0QohmtFbeUbi9kbxFOhLWB/A1CJ5 Q02A4KezgI9kifOqwsBHDaqqXwxJqkwGXeV+1jUMXlMfeiRfMHvyslDI6ffs/NvVVV 6GEbt0miuDg4V+n54N6XFpSuP58AiXckY2u7YJ7Y= Date: Thu, 7 Jun 2018 10:34:01 +0200 From: Greg Kroah-Hartman To: Kim Phillips Cc: Suzuki K Poulose , Mathieu Poirier , Leo Yan , Alexander Shishkin , Alex Williamson , Andrew Morton , David Howells , Eric Auger , Eric Biederman , Gargi Sharma , Geert Uytterhoeven , Kefeng Wang , Kirill Tkhai , Mike Rapoport , Oleg Nesterov , Pavel Tatashin , Rik van Riel , Robin Murphy , Russell King , Thierry Reding , Todd Kjos , Randy Dunlap , linux-arm-kernel , Linux Kernel Mailing List Subject: Re: [PATCH v4 05/14] coresight: get/put module in coresight_build/release_path Message-ID: <20180607083401.GE16651@kroah.com> References: <20180605210710.22227-1-kim.phillips@arm.com> <20180605210710.22227-6-kim.phillips@arm.com> <20180606082422.GB19727@kroah.com> <20180606155501.704583e1412996a1a2c6fa61@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180606155501.704583e1412996a1a2c6fa61@arm.com> User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 06, 2018 at 03:55:01PM -0500, Kim Phillips wrote: > On Wed, 6 Jun 2018 10:46:36 +0100 > Suzuki K Poulose wrote: > > > On 06/06/2018 09:24 AM, Greg Kroah-Hartman wrote: > > > On Tue, Jun 05, 2018 at 04:07:01PM -0500, Kim Phillips wrote: > > >> Increment the refcnt for driver modules in current use by calling > > >> module_get in coresight_build_path and module_put in release_path. > > >> > > >> This prevents driver modules from being unloaded when they are in use, > > >> either in sysfs or perf mode. > > > > > > Why does it matter? Shouldn't you be allowed to remove any module at > > > any point in time, much like a networking driver? > > > > > > > > >> > > >> Cc: Mathieu Poirier > > >> Cc: Leo Yan > > >> Cc: Alexander Shishkin > > >> Cc: Randy Dunlap > > >> Cc: Suzuki K Poulose > > >> Cc: Greg Kroah-Hartman > > >> Cc: Russell King > > >> Signed-off-by: Kim Phillips > > >> --- > > >> drivers/hwtracing/coresight/coresight.c | 9 +++++++++ > > >> 1 file changed, 9 insertions(+) > > >> > > >> diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c > > >> index 338f1719641c..1c941351f1d1 100644 > > >> --- a/drivers/hwtracing/coresight/coresight.c > > >> +++ b/drivers/hwtracing/coresight/coresight.c > > >> @@ -465,6 +465,12 @@ static int _coresight_build_path(struct coresight_device *csdev, > > >> > > >> node->csdev = csdev; > > >> list_add(&node->link, path); > > >> + > > >> + if (!try_module_get(csdev->dev.parent->driver->owner)) { > > > > > > What is to keep parent->driver from going away right here? What keeps > > > parent around? This feels very fragile to me, I don't see any locking > > > anywhere around this code path to try to keep things in place. > > > > You're right. We do have coresight_mutex, which is held across the build > > path and the csdev is removed when a device is unregistered. However, I > > see that we don't hold the mutex while removing the connections from > > coresight_unregister(). Holding the mutex should protect us from the > > csdev being removed, while we build the path. > > OK, I'll add this for the next version: > > diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c > index f96258de1e9b..da702507a55c 100644 > --- a/drivers/hwtracing/coresight/coresight-core.c > +++ b/drivers/hwtracing/coresight/coresight-core.c > @@ -1040,8 +1040,12 @@ EXPORT_SYMBOL_GPL(coresight_register); > > void coresight_unregister(struct coresight_device *csdev) > { > + mutex_lock(&coresight_mutex); > + Locks are to protect data, not code, be careful here please. That's the big issue with the module reference counting, it "protects" code, not data. If at all possible, never grab a module reference count, as you should always be able to unload a module, unless you have a file handle open, and if you have that, the kernel core will properly protect you. thanks, greg k-h