From patchwork Wed Jun 7 08:12:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chunyan Zhang X-Patchwork-Id: 103213 Delivered-To: patch@linaro.org Received: by 10.182.29.35 with SMTP id g3csp1640683obh; Wed, 7 Jun 2017 01:13:30 -0700 (PDT) X-Received: by 10.84.232.71 with SMTP id f7mr26260229pln.252.1496823210844; Wed, 07 Jun 2017 01:13:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496823210; cv=none; d=google.com; s=arc-20160816; b=z5uvxuD7VlHiEl/8LnuNMXF0FOalr3CuzUmJHnfbvpKNEdc9kfZfvQDTqYB/Vsc80k Hug4MaSVth/SDLtezWfidnMjKWu8lJlIZ8Vzb7/awTMi4gOE3hjxBeJ7ccBwk7rTdUfF IE5JQ+H1xHEyBlbdYgXU/fAaAIq3vRS4ZUtXT+SCb5+Oo6GTluNBFp6bZXxJDdhJMgXQ LKBCPBC+mc4qS7ar3G/XAWkCxgP+6bvuLRKBIrJ35USzExX1LrECK/iUzPPEI5SnVazA /bPcEC1sBMbfH/jlTmNSJUaADwq5F6iqcwntqjM7ZjkH/YQWa85g3A4Mi1LpGHGUA82d MepQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=4pLQOU07Gfckxcl1eg5REPgsrYGg9KM3+RPBzeeQ4Y4=; b=cZybFH6I3W8YQ44qmpFYDfLGrR+h4wtmejEiKDBoPVW50TAgLxNu2bZhDbeGS9Mlm9 iV2Jnlc5XIKBIkjcg5AR8zGyXCOhStEh/cxNSUL0UZc5kmjEj9UAUKYUeIVwpTLTGo7l KULyLK46eh5roWsrFZHqRyOrmOf7kMOm30qllRRTWuKJhBfkGh4ReWhddHWt7OsK0rKK xlFDAw6HYla80gF40dTtSVJ58aq/87wB/jndZRG3ZZoiY2m4qWKW8WEjelzuaXFKJ5f6 +R/rqZgEU5HWl0xhqUCGU6sPkAfhQpI4XH+Pci5k03LEPW4YDkjAtELnQQtTM5eOI1Bb QnHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 67si1129245pfe.140.2017.06.07.01.13.30; Wed, 07 Jun 2017 01:13:30 -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=@linaro.org; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751501AbdFGINL (ORCPT + 25 others); Wed, 7 Jun 2017 04:13:11 -0400 Received: from mail-pg0-f46.google.com ([74.125.83.46]:33483 "EHLO mail-pg0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751020AbdFGINF (ORCPT ); Wed, 7 Jun 2017 04:13:05 -0400 Received: by mail-pg0-f46.google.com with SMTP id f185so2873258pgc.0 for ; Wed, 07 Jun 2017 01:13:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=4pLQOU07Gfckxcl1eg5REPgsrYGg9KM3+RPBzeeQ4Y4=; b=Z0e+4dO25EKpVvtOD21sBvSHbCb9/O4/OYQDmiQ4OJLCHKEun4EwlL8OF34Jas+zER mg6sXNnO43K98KDVA69LwjpoVfOrfCOjexaG0qvSAXVssxmTgiaI6ynKDqrjIgYtT+mF nLSIZy+Tisn4KtiKQPhtoiyfHwq23Tdd8wkGg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=4pLQOU07Gfckxcl1eg5REPgsrYGg9KM3+RPBzeeQ4Y4=; b=kISeZcI/wuh+BnjFXnHVnvkGnsEC6cZeo4t0ubbHaEUTAJ5vpkLHfeVW3+DP3fLa8K 60Xk617/CpRIhJO01+Po4PfgrT/AbY50uANImOXMm2x0JZzzuXfhMFzeAnpEmyrJmn0V LVoBpKPIAPHApP/JrECMP/bepXqT/2jsRzLdfLumFBGQAKfC8xpY483mnXrzMlHuxfzV ZdJmX9LFtfo+ukwKtEKHwfflsWloy4jGdwph+bQWbz5oY3Yvvw3uOm052s7Zmm/CLnkV uPKyppROgcH6OeohZVoT+kTzDy0PWHvED1eimfbnbno7vfK5Mm9f6rsyrEHTgbM9LN7Y nXMA== X-Gm-Message-State: AODbwcAqJ+fO0woOle8mtcv4ipyyYPYVo2Y2Vagh7D4y90u+5ZLHMTvQ Dpzy2g9rJmKI11UOssNJpg== X-Received: by 10.84.138.1 with SMTP id 1mr26865368plo.188.1496823184879; Wed, 07 Jun 2017 01:13:04 -0700 (PDT) Received: from ubuntu16.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id y28sm2425924pfd.32.2017.06.07.01.13.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 07 Jun 2017 01:13:04 -0700 (PDT) From: Chunyan Zhang To: rostedt@goodmis.org, mingo@redhat.com Cc: linux-kernel@vger.kernel.org, zhang.lyra@gmail.com Subject: [RESEND PATCH v2] trace: fix the errors caused by incompatible type of RCU variables Date: Wed, 7 Jun 2017 16:12:51 +0800 Message-Id: <1496823171-7758-1-git-send-email-zhang.chunyan@linaro.org> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The variables which are processed by RCU functions should be annotated as RCU, otherwise sparse will report the errors like below: "error: incompatible types in comparison expression (different address spaces)" Signed-off-by: Chunyan Zhang --- Changes in v2: * Addressed Steven's comments - Use rcu_dereference_protected() instead of rcu_dereference_raw_notrace() * Rebased on v4.12-rc1 include/linux/ftrace.h | 6 +++--- include/linux/trace_events.h | 2 +- kernel/trace/ftrace.c | 42 ++++++++++++++++++++++++++++-------------- kernel/trace/trace.h | 6 +++--- 4 files changed, 35 insertions(+), 21 deletions(-) -- 2.7.4 diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index 473f088..056395c7 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -142,8 +142,8 @@ enum { #ifdef CONFIG_DYNAMIC_FTRACE /* The hash used to know what functions callbacks trace */ struct ftrace_ops_hash { - struct ftrace_hash *notrace_hash; - struct ftrace_hash *filter_hash; + struct ftrace_hash __rcu *notrace_hash; + struct ftrace_hash __rcu *filter_hash; struct mutex regex_lock; }; @@ -165,7 +165,7 @@ static inline void ftrace_free_init_mem(void) { } */ struct ftrace_ops { ftrace_func_t func; - struct ftrace_ops *next; + struct ftrace_ops __rcu *next; unsigned long flags; void *private; ftrace_func_t saved_func; diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h index a556805..89f7bd5d 100644 --- a/include/linux/trace_events.h +++ b/include/linux/trace_events.h @@ -327,7 +327,7 @@ enum { struct trace_event_file { struct list_head list; struct trace_event_call *event_call; - struct event_filter *filter; + struct event_filter __rcu *filter; struct dentry *dir; struct trace_array *tr; struct trace_subsystem_dir *system; diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 39dca4e..116742b 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -113,7 +113,8 @@ static int ftrace_disabled __read_mostly; static DEFINE_MUTEX(ftrace_lock); -static struct ftrace_ops *ftrace_ops_list __read_mostly = &ftrace_list_end; +static struct ftrace_ops __rcu * + ftrace_ops_list __read_mostly = &ftrace_list_end; ftrace_func_t ftrace_trace_function __read_mostly = ftrace_stub; static struct ftrace_ops global_ops; @@ -169,8 +170,11 @@ int ftrace_nr_registered_ops(void) mutex_lock(&ftrace_lock); - for (ops = ftrace_ops_list; - ops != &ftrace_list_end; ops = ops->next) + for (ops = rcu_dereference_protected(ftrace_ops_list, + lockdep_is_held(&ftrace_lock)); + ops != &ftrace_list_end; + ops = rcu_dereference_protected(ops->next, + lockdep_is_held(&ftrace_lock))) cnt++; mutex_unlock(&ftrace_lock); @@ -275,10 +279,11 @@ static void update_ftrace_function(void) * If there's only one ftrace_ops registered, the ftrace_ops_list * will point to the ops we want. */ - set_function_trace_op = ftrace_ops_list; + set_function_trace_op = rcu_dereference_protected(ftrace_ops_list, + lockdep_is_held(&ftrace_lock)); /* If there's no ftrace_ops registered, just call the stub function */ - if (ftrace_ops_list == &ftrace_list_end) { + if (set_function_trace_op == &ftrace_list_end) { func = ftrace_stub; /* @@ -286,7 +291,8 @@ static void update_ftrace_function(void) * recursion safe and not dynamic and the arch supports passing ops, * then have the mcount trampoline call the function directly. */ - } else if (ftrace_ops_list->next == &ftrace_list_end) { + } else if (rcu_dereference_protected(ftrace_ops_list->next, + lockdep_is_held(&ftrace_lock)) == &ftrace_list_end) { func = ftrace_ops_get_list_func(ftrace_ops_list); } else { @@ -348,9 +354,11 @@ int using_ftrace_ops_list_func(void) return ftrace_trace_function == ftrace_ops_list_func; } -static void add_ftrace_ops(struct ftrace_ops **list, struct ftrace_ops *ops) +static void add_ftrace_ops(struct ftrace_ops __rcu **list, + struct ftrace_ops *ops) { - ops->next = *list; + rcu_assign_pointer(ops->next, *list); + /* * We are entering ops into the list but another * CPU might be walking that list. We need to make sure @@ -360,7 +368,8 @@ static void add_ftrace_ops(struct ftrace_ops **list, struct ftrace_ops *ops) rcu_assign_pointer(*list, ops); } -static int remove_ftrace_ops(struct ftrace_ops **list, struct ftrace_ops *ops) +static int remove_ftrace_ops(struct ftrace_ops __rcu **list, + struct ftrace_ops *ops) { struct ftrace_ops **p; @@ -368,7 +377,10 @@ static int remove_ftrace_ops(struct ftrace_ops **list, struct ftrace_ops *ops) * If we are removing the last function, then simply point * to the ftrace_stub. */ - if (*list == ops && ops->next == &ftrace_list_end) { + if (rcu_dereference_protected(*list, + lockdep_is_held(&ftrace_lock)) == ops && + rcu_dereference_protected(ops->next, + lockdep_is_held(&ftrace_lock)) == &ftrace_list_end) { *list = &ftrace_list_end; return 0; } @@ -1513,8 +1525,8 @@ ftrace_ops_test(struct ftrace_ops *ops, unsigned long ip, void *regs) return 0; #endif - hash.filter_hash = rcu_dereference_raw_notrace(ops->func_hash->filter_hash); - hash.notrace_hash = rcu_dereference_raw_notrace(ops->func_hash->notrace_hash); + rcu_assign_pointer(hash.filter_hash, ops->func_hash->filter_hash); + rcu_assign_pointer(hash.notrace_hash, ops->func_hash->notrace_hash); if (hash_contains_ip(ip, &hash)) ret = 1; @@ -2784,7 +2796,8 @@ static int ftrace_shutdown(struct ftrace_ops *ops, int command) * If there's no more ops registered with ftrace, run a * sanity check to make sure all rec flags are cleared. */ - if (ftrace_ops_list == &ftrace_list_end) { + if (rcu_dereference_protected(ftrace_ops_list, + lockdep_is_held(&ftrace_lock)) == &ftrace_list_end) { struct ftrace_page *pg; struct dyn_ftrace *rec; @@ -6122,7 +6135,8 @@ ftrace_enable_sysctl(struct ctl_table *table, int write, if (ftrace_enabled) { /* we are starting ftrace again */ - if (ftrace_ops_list != &ftrace_list_end) + if (rcu_dereference_protected(ftrace_ops_list, + lockdep_is_held(&ftrace_lock)) != &ftrace_list_end) update_ftrace_function(); ftrace_startup_sysctl(); diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 291a1bc..60b26b4 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -1183,9 +1183,9 @@ struct ftrace_event_field { struct event_filter { int n_preds; /* Number assigned */ int a_preds; /* allocated */ - struct filter_pred *preds; - struct filter_pred *root; - char *filter_string; + struct filter_pred __rcu *preds; + struct filter_pred __rcu *root; + char *filter_string; }; struct event_subsystem {