Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2580029ybv; Sun, 9 Feb 2020 02:33:21 -0800 (PST) X-Google-Smtp-Source: APXvYqz0C//MIA++rED4ShBUSZd/pu6J4GzZ8TMa740UmCF6eMGSZlwrtiYNM0tW3w9MUyk8Z6tU X-Received: by 2002:a05:6830:1149:: with SMTP id x9mr6595563otq.156.1581244401274; Sun, 09 Feb 2020 02:33:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581244401; cv=none; d=google.com; s=arc-20160816; b=EVS4Yl37enpQ2/EV9cAXq7lA7QQ1jykQ3Ih1qmy1vu6cdF7eb2+CxP4gCzMF3bSo2s nkDxe2jhhrlbZq5HZZRKGO2sFXxLsH8MyQR/7keenm4j6vkABbbXGqn916AiBz9PmKmY g/KRKcGtdxmwPrJAmDrvSHFiFqDzPlT45H0UaD6nVN2/xnN78G2WapwBXrhAVoNi+f8U C90WzHF4yYW+c7trbjLhszMPp4MyVEx47QAlkNbBTvmmRbiafqmQ5Ex2XeTr7PCD8fTf nc11Cy0WkcWIcaKqKj8LbfhP+uK4MxD+av1NLiYGh4I2n9XE/hzK8MV6NJ7qjoVcxaOq kqUw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=jCjPuJNh7y163fuH52924U0TilCQIyk7AKarrYQwMlU=; b=o8vXZPQJDgYufprVGbk++yaGIID5ptxn08EoTfkfDAF08nUXRNOU7B9im0vdoCtF2i uKGBOby1bdyl0dv4Z2ixLbG6Xur8SeKu/T4J4lUoHRNj/8Kxp0trHYfUCW+dbHA9tfKF ALzp159MndqbKRYs4UbZzV/EQJ6n9H0HfY59hBVREdgzRBfXQjRAO4IXv2t802fv5q3+ ghnptmwwtcFPwRNZrLw04DHnOPhwOD706lrcVZ6f/9RR8EU/JLkr47AbcIer57ax981T TzgARsV284lryDsmsZzhIaQPOkVPlStYr2QGFL61vQRQM8b7owr3H5aBo9DIv1n93ebG Dccg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=UMTyRY67; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q5si2997404otc.104.2020.02.09.02.32.46; Sun, 09 Feb 2020 02:33:21 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=UMTyRY67; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727665AbgBIK1p (ORCPT + 99 others); Sun, 9 Feb 2020 05:27:45 -0500 Received: from mail-pj1-f68.google.com ([209.85.216.68]:52446 "EHLO mail-pj1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727653AbgBIK1p (ORCPT ); Sun, 9 Feb 2020 05:27:45 -0500 Received: by mail-pj1-f68.google.com with SMTP id ep11so2889130pjb.2 for ; Sun, 09 Feb 2020 02:27:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=jCjPuJNh7y163fuH52924U0TilCQIyk7AKarrYQwMlU=; b=UMTyRY67J7q7nfTqxlM+hkep+sBdWFUkE55jCan1M80XHmn203vz9vk5ErmbaX2l0G E6z3iMi11iNM4IUbmzW3ohn8C6QvP5+B81q8W5gl3Vzr1zjVh5f3NnMvV+QACnobO9rC 2kLOKI4lqVfAoUT/cydVRvLqDx6azKixg6UqwepYix+Qo7koYT17LUa3Zm3wVncGCT7G 3UJUKswtdkuOD93WyGTWUDNKWmxRI3HFKlFHPW27WMzIH2WzsueIoRQiVEYpQc8ZXtzF d8ZMAZTkf2Xt1XQSEPe8OOO3ZeJui6y8XcWeKxBFFrcaeeMEM+QpOtpOMOZ1VECJItc3 qe4A== 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:mime-version :content-transfer-encoding; bh=jCjPuJNh7y163fuH52924U0TilCQIyk7AKarrYQwMlU=; b=EiYEswYLScRzmbBWOQdCwDtZF2QohhbXJW3Qe28D85wdcELWi6oxWlB/m2Qnz/tFXe nIxVe+B3VgHuy/eUWSdRby4+TVbdXPzweUra+ZQEmYDW7/1IZiqzJddkC7Qzcf9Tbl10 uRN1j6ZKXNKjAoWo6XROstCsE9eDxbLgNbQgT/jsDC7YrclYmqA0Zn1rLzOphXSSKSe0 mbM0yYucuxshq/5LvvjKz4Z1em1Fe0nlp7zBoAQTTxt2YtUYy2B8bqGm7jPLQcP3GES7 n6Jh6upcA0ifXZRsfMFuE6QKN8XP/pCgAF9SUyoQhHjbSVuGM55f2upPEFTo+Qnd1l5q TOUA== X-Gm-Message-State: APjAAAV+WDk9KAieI6sDN5wCx5AHmAwJlZUuIedacW6t1PHH6SvbTMhD TjUIBU6uj/wbKhUXL75p7xVWjhoBiDg= X-Received: by 2002:a17:902:34a:: with SMTP id 68mr7332999pld.250.1581244064528; Sun, 09 Feb 2020 02:27:44 -0800 (PST) Received: from localhost.localdomain ([146.196.37.155]) by smtp.googlemail.com with ESMTPSA id 196sm9030786pfy.86.2020.02.09.02.27.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Feb 2020 02:27:43 -0800 (PST) From: Amol Grover To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim Cc: linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, Joel Fernandes , Madhuparna Bhowmik , "Paul E . McKenney" , Amol Grover Subject: [PATCH] perf_event: Annotate rb pointer with __rcu Date: Sun, 9 Feb 2020 15:55:31 +0530 Message-Id: <20200209102530.26115-1-frextrite@gmail.com> X-Mailer: git-send-email 2.24.1 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 perf_event::rb is used in RCU context, tell sparse about it aswell to eliminate false-positives. Fixes the following instances of sparse error: incompatible types in comparison expression (different address spaces) kernel/events/core.c:5596:9 kernel/events/core.c:5302:22 kernel/events/core.c:5438:14 kernel/events/core.c:5471:14 kernel/events/core.c:5528:14 kernel/events/core.c:5614:14 kernel/events/core.c:5627:14 kernel/events/core.c:7182:13 kernel/events/ring_buffer.c:169:14 kernel/events/ring_buffer.c:169:14 kernel/events/ring_buffer.c:169:14 This introduces the following 2 new sparse errors: kernel/events/core.c:7212:9 kernel/events/core.c:5749:31 which are fixed by using RCU primitives, rcu_dereference() and rcu_access_pointer() on perf_event::rb. Signed-off-by: Amol Grover --- include/linux/perf_event.h | 2 +- kernel/events/core.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 6d4c22aee384..1691107d2800 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -694,7 +694,7 @@ struct perf_event { struct mutex mmap_mutex; atomic_t mmap_count; - struct ring_buffer *rb; + struct ring_buffer __rcu *rb; struct list_head rb_entry; unsigned long rcu_batches; int rcu_pending; diff --git a/kernel/events/core.c b/kernel/events/core.c index 2173c23c25b4..7b9411d21165 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -5746,7 +5746,7 @@ static void perf_mmap_close(struct vm_area_struct *vma) * still restart the iteration to make sure we're not now * iterating the wrong list. */ - if (event->rb == rb) + if (rcu_access_pointer(event->rb) == rb) ring_buffer_attach(event, NULL); mutex_unlock(&event->mmap_mutex); @@ -7209,7 +7209,8 @@ static void perf_pmu_output_stop(struct perf_event *event) restart: rcu_read_lock(); - list_for_each_entry_rcu(iter, &event->rb->event_list, rb_entry) { + list_for_each_entry_rcu(iter, &rcu_dereference(event->rb)->event_list, + rb_entry) { /* * For per-CPU events, we need to make sure that neither they * nor their children are running; for cpu==-1 events it's -- 2.24.1