Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2669136pxa; Mon, 17 Aug 2020 16:05:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxiH4+osHXLzlWskVyXDz5cCq+uuOwSmjTFWCqI80AUP+z8niYj1eIlb3u2HRbKu8rosSvO X-Received: by 2002:a17:906:4aca:: with SMTP id u10mr17187674ejt.320.1597705552693; Mon, 17 Aug 2020 16:05:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597705552; cv=none; d=google.com; s=arc-20160816; b=DKzB1Mav0ooNgpNczPDeLsVrRc12gTZU8NxCYmVZqBxE6vFkUXPySz7fvikvCZRaCN YGCz9JroFBN8Q4eMbTnJMsGG0Zox356CY2GsNaUykFuUTduWkQRZS2Wf5teT8lP6BzdA fhe+kbRIIa4CWssJNsSSQt+zcbQVRX8HNqx/nJ8+ybXberFMu158E+ztpa3KyfCJfch4 hZS4CwRFfi7MvY9s/KkYYLJ0qpGYhlEc9zp0APi+ibxpFdNj6pHkiQARzhxc1b02L4aF DyuhQ6GTvDWvCWkzXHT60Tbu2pUNYnPMY77RTZlCw20MzivOMor/JZsuDqCNTVMutXxj mhpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:ironport-sdr:ironport-sdr; bh=fXGigAYOnLbrvDvCqaPio9uaiH61bDn2d5rKdT6OtQQ=; b=ptyotJhMb+sqZwiYYXRC67emrZfDiMEZyHyDzwSsJWCU1h3sfq1+SwU1GV1f7xsjTn fzOBDo7A4hHGsGjhrkR+aasVb3JWxpYGcslm6zOFSaniSz1XCtaeCTKEx4PnadxMXZpM +uaLZFOQlK0ikWAR4jpDtFUAH/GU5SItgwESKO4YpQcwfwM5rdI/ZsIm+ysyb7aF1bgx 1fiHYCW/uhcgG7wNbwVRVZI7H5Bb3OWpMCRTZmBtabtWwb0LktrT47T1zCnjR30AdCtq /LODupVfFc2RMIaiMnn2usTiRb5B96q2hkDlDwOLPvN8lWIt/Dk7NNsdhBe1OaS/HwOW DVQw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f9si11597870edw.239.2020.08.17.16.05.29; Mon, 17 Aug 2020 16:05:52 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728182AbgHQVXF (ORCPT + 99 others); Mon, 17 Aug 2020 17:23:05 -0400 Received: from mga04.intel.com ([192.55.52.120]:35087 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728167AbgHQVXE (ORCPT ); Mon, 17 Aug 2020 17:23:04 -0400 IronPort-SDR: W3flPG1+0k8WcFNbgeYEaXclQ56g8lkx9idnzmNJDKNzZB/q3GrGP1riAgKhF7jiqZaEsEPIN9 trAmjoZDdG+A== X-IronPort-AV: E=McAfee;i="6000,8403,9716"; a="152201291" X-IronPort-AV: E=Sophos;i="5.76,324,1592895600"; d="scan'208";a="152201291" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Aug 2020 14:23:02 -0700 IronPort-SDR: bNgMPOd0bydM3J0KCY8Xabznvg129yOoxk2IAxZVPZUY24Y7HV5WW6eocNjxK2I47PAk1scGq6 KefseTSFyr0g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,324,1592895600"; d="scan'208";a="471561454" Received: from bbartede-mobl.ger.corp.intel.com (HELO localhost) ([10.249.32.24]) by orsmga005.jf.intel.com with ESMTP; 17 Aug 2020 14:22:59 -0700 Date: Tue, 18 Aug 2020 00:22:58 +0300 From: Jarkko Sakkinen To: Masami Hiramatsu Cc: Ingo Molnar , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andi Kleen , Peter Zijlstra , Jessica Yu , "Naveen N. Rao" , Anil S Keshavamurthy , "David S. Miller" , Steven Rostedt , Ingo Molnar Subject: Re: [PATCH v5 1/6] kprobes: Remove dependency to the module_mutex Message-ID: <20200817212258.GD44714@linux.intel.com> References: <20200724050553.1724168-1-jarkko.sakkinen@linux.intel.com> <20200724050553.1724168-2-jarkko.sakkinen@linux.intel.com> <20200724091711.GB517988@gmail.com> <20200725030107.GF17052@linux.intel.com> <20200725102110.GA757173@gmail.com> <20200728163400.e00b09c594763349f99ce6cb@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200728163400.e00b09c594763349f99ce6cb@kernel.org> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 28, 2020 at 04:34:00PM +0900, Masami Hiramatsu wrote: > On Sat, 25 Jul 2020 12:21:10 +0200 > Ingo Molnar wrote: > > > > > * Jarkko Sakkinen wrote: > > > > > On Fri, Jul 24, 2020 at 11:17:11AM +0200, Ingo Molnar wrote: > > > > > > > > * Jarkko Sakkinen wrote: > > > > > > > > > --- a/kernel/kprobes.c > > > > > +++ b/kernel/kprobes.c > > > > > @@ -564,7 +564,7 @@ static void kprobe_optimizer(struct work_struct *work) > > > > > cpus_read_lock(); > > > > > mutex_lock(&text_mutex); > > > > > /* Lock modules while optimizing kprobes */ > > > > > - mutex_lock(&module_mutex); > > > > > + lock_modules(); > > > > > > > > > > /* > > > > > * Step 1: Unoptimize kprobes and collect cleaned (unused and disarmed) > > > > > @@ -589,7 +589,7 @@ static void kprobe_optimizer(struct work_struct *work) > > > > > /* Step 4: Free cleaned kprobes after quiesence period */ > > > > > do_free_cleaned_kprobes(); > > > > > > > > > > - mutex_unlock(&module_mutex); > > > > > + unlock_modules(); > > > > > mutex_unlock(&text_mutex); > > > > > cpus_read_unlock(); > > > > > > > > BTW., it would be nice to expand on the comments above - exactly which > > > > parts of the modules code is being serialized against and why? > > > > > > > > We already hold the text_mutex here, which should protect against most > > > > kprobes related activities interfering - and it's unclear (to me) > > > > which part of the modules code is being serialized with here, and the > > > > 'lock modules while optimizing kprobes' comments is unhelpful. :-) > > > > > > > > Thanks, > > > > > > > > Ingo > > > > > > AFAIK, only if you need to call find_module(), you ever need to acquire > > > this mutex. 99% of time it is internally taken care by kernel/module.c. > > > > > > I cannot make up any obvious reason to acquire it here. > > > > If it's unnecessary, then it needs to be removed. > > > > If it's necessary, then it needs to be documented better. > > Good catch! This is not needed anymore. > It has been introduced to avoid conflict with text modification, at that > point we didn't get text_mutex. But after commit f1c6ece23729 ("kprobes: Fix > potential deadlock in kprobe_optimizer()") moved the text_mutex in the current > position, we don't need it. (and anyway, keeping kprobe_mutex locked means > any module unloading will be stopped inside kprobes_module_callback()) > > This may help? Hey, thanks a lot. This will help to clean my patch set. I'll send a follow up version as soon I'm on track with my work. I have to recall my set of changes and backtrack some of the discussion. I was two weeks in vacation and last week had bunch of network connectivity issues last week. Anyway, enough time for details to fade away :-) /Jarkko > > From 2355ecd941c3234b12a6de7443592848ed4e2087 Mon Sep 17 00:00:00 2001 > From: Masami Hiramatsu > Date: Tue, 28 Jul 2020 16:32:34 +0900 > Subject: [PATCH] kprobes: Remove unneeded module_mutex lock from the optimizer > > Remove unneeded module_mutex locking from the optimizer. Since > we already locks both kprobe_mutex and text_mutex in the optimizer, > text will not be changed and the module unloading will be stopped > inside kprobes_module_callback(). > > Suggested-by: Ingo Molnar > Signed-off-by: Masami Hiramatsu > --- > kernel/kprobes.c | 3 --- > 1 file changed, 3 deletions(-) > > diff --git a/kernel/kprobes.c b/kernel/kprobes.c > index 4a904cc56d68..d1b02e890793 100644 > --- a/kernel/kprobes.c > +++ b/kernel/kprobes.c > @@ -563,8 +563,6 @@ static void kprobe_optimizer(struct work_struct *work) > mutex_lock(&kprobe_mutex); > cpus_read_lock(); > mutex_lock(&text_mutex); > - /* Lock modules while optimizing kprobes */ > - mutex_lock(&module_mutex); > > /* > * Step 1: Unoptimize kprobes and collect cleaned (unused and disarmed) > @@ -589,7 +587,6 @@ static void kprobe_optimizer(struct work_struct *work) > /* Step 4: Free cleaned kprobes after quiesence period */ > do_free_cleaned_kprobes(); > > - mutex_unlock(&module_mutex); > mutex_unlock(&text_mutex); > cpus_read_unlock(); > > -- > 2.25.1 > -- > Masami Hiramatsu