Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1891202ybh; Thu, 23 Jul 2020 22:07:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGLn9JzBiKAbljHjqeT+Mt35VmPFfrrnDxcKBrMZl6henptLuykTdmHnqcoOlmE4xIYExO X-Received: by 2002:a17:906:ca4e:: with SMTP id jx14mr7898756ejb.544.1595567241261; Thu, 23 Jul 2020 22:07:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595567241; cv=none; d=google.com; s=arc-20160816; b=PYyR0TKeSKEQNSMkyZXGC2xph1lW2zubpS2Nr+qnUISVV4Ktq7wwxuiVMI2OcfCggC xdOxFSHmCClBHWg6MTlyEIUWt5IqWss9JPK/it5QCOjfxTL4ZYFTN9DJu0zQwahLSVGp JmmvtswgslgqUXrVJKXAAxHG5dwektSLW3jO8QG/kD3OCmnD6qJRAmTCXbAVZ26p4bhA OWmimgLvJ3rKC34TeMW6vSd0GMmI1Iej6DiXAnG0Sruv9C0DFSZtEY8YEFEi1zNBIpHP Dh79XV4Kgo7Us+q1S03BB4c/WfE2yhm3wXVKbKKW7nwxxRx2YK6thB31OJ90uXoxxU10 /79g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=FYdzHtmSSZkYriD1WTs1sy1inDWOttE3abYGUTZA6g0=; b=T70AdYjT/zdLNlb5fadzalSuMczsIOTWIc2AMFAWA3Ivq+xfHn2Zuo9oV7l7btDbTv FAR0utGj+um5rHNw2+/PFkEC5z9Kyi6/Zk58tGgIkJTdc6ppkF+wZTY/GkHAxUsb/W81 axSlIsk43HERdRCZYg4A3yoiAGFqIYldI9OamsKmCxiLVd4FNhdqzOC6cdBPGx3nvlEO NOUG39sWXgBe15Vung8HwU1ftAWf1k/1KX+5nvnjgsJgXyCZlOBSSRz7kzxjTaxxgv8m wofMtkYpLyEmdK2whMHdgkUsYgU4Ktd/xvs54svB/bZj/UTJUX52PYihSiLKtuZT0r25 Oljg== 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 qo28si3338849ejb.527.2020.07.23.22.06.59; Thu, 23 Jul 2020 22:07:21 -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 S1726742AbgGXFGG (ORCPT + 99 others); Fri, 24 Jul 2020 01:06:06 -0400 Received: from mga12.intel.com ([192.55.52.136]:61443 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725929AbgGXFGG (ORCPT ); Fri, 24 Jul 2020 01:06:06 -0400 IronPort-SDR: DNTCOiTUyXRbpktxTMvgrII2lz4bPd/mgZ3CZWzHbVvoPFy3A+WwBO/Hccg5zztkBeXvAoas+3 HpVr/NDtr5kw== X-IronPort-AV: E=McAfee;i="6000,8403,9691"; a="130222556" X-IronPort-AV: E=Sophos;i="5.75,389,1589266800"; d="scan'208";a="130222556" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jul 2020 22:06:05 -0700 IronPort-SDR: 7owJROGHpzz36HEmItdzDw0Nw/3DyF5BMdpr4J5OS4IUULuD9RpGDHGje9y10GjxxnbM3VRlJl oN5UfQdTdVQA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,389,1589266800"; d="scan'208";a="302553454" Received: from itopinsk-mobl1.ccr.corp.intel.com (HELO localhost) ([10.249.36.179]) by orsmga002.jf.intel.com with ESMTP; 23 Jul 2020 22:05:59 -0700 From: Jarkko Sakkinen To: linux-kernel@vger.kernel.org Cc: Jarkko Sakkinen , linux-mm@kvack.org, Andi Kleen , Peter Zijlstra , Masami Hiramatsu , Jessica Yu , "Naveen N. Rao" , Anil S Keshavamurthy , "David S. Miller" , Steven Rostedt , Ingo Molnar Subject: [PATCH v5 1/6] kprobes: Remove dependency to the module_mutex Date: Fri, 24 Jul 2020 08:05:48 +0300 Message-Id: <20200724050553.1724168-2-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200724050553.1724168-1-jarkko.sakkinen@linux.intel.com> References: <20200724050553.1724168-1-jarkko.sakkinen@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add lock_modules() and unlock_modules() wrappers for acquiring module_mutex in order to remove the compile time dependency to it. Cc: linux-mm@kvack.org Cc: Andi Kleen Cc: Peter Zijlstra Suggested-by: Masami Hiramatsu Signed-off-by: Jarkko Sakkinen --- include/linux/module.h | 18 ++++++++++++++++++ kernel/kprobes.c | 4 ++-- kernel/trace/trace_kprobe.c | 4 ++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/include/linux/module.h b/include/linux/module.h index 2e6670860d27..8850b9692b8f 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -705,6 +705,16 @@ static inline bool is_livepatch_module(struct module *mod) bool is_module_sig_enforced(void); void set_module_sig_enforced(void); +static inline void lock_modules(void) +{ + mutex_lock(&module_mutex); +} + +static inline void unlock_modules(void) +{ + mutex_unlock(&module_mutex); +} + #else /* !CONFIG_MODULES... */ static inline struct module *__module_address(unsigned long addr) @@ -852,6 +862,14 @@ void *dereference_module_function_descriptor(struct module *mod, void *ptr) return ptr; } +static inline void lock_modules(void) +{ +} + +static inline void unlock_modules(void) +{ +} + #endif /* CONFIG_MODULES */ #ifdef CONFIG_SYSFS diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 2e97febeef77..4e46d96d4e16 100644 --- 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(); diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index aefb6065b508..710ec6a6aa8f 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c @@ -122,9 +122,9 @@ static nokprobe_inline bool trace_kprobe_module_exist(struct trace_kprobe *tk) if (!p) return true; *p = '\0'; - mutex_lock(&module_mutex); + lock_modules(); ret = !!find_module(tk->symbol); - mutex_unlock(&module_mutex); + unlock_modules(); *p = ':'; return ret; -- 2.25.1