From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,T_DKIMWL_WL_HIGH,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C419DC04AB6 for ; Tue, 28 May 2019 17:51:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9D8C221871 for ; Tue, 28 May 2019 17:51:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559065867; bh=DsYg7AzSvHFuFdz1+CG0RxTB+NMpLarMplA0DbFOavM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=GYj20a2CdedekQvC6quaVjMmTZ3DRpg2sk4mIrPo+etPLn74LB1PlhMJZUT+o5Rxz FRRt5yf8jw7pW4mwAFu26ja14r3Sx+U0Cf4suLWLDXYEFM/mXO9YvH+BahbMARsf/r WH4f9X1sDzfMFv7R5lwMIzzYFeDTKT7VEMyFh6wk= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727786AbfE1RvG (ORCPT ); Tue, 28 May 2019 13:51:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:54802 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726827AbfE1RvF (ORCPT ); Tue, 28 May 2019 13:51:05 -0400 Received: from quaco.ghostprotocols.net (unknown [179.97.35.11]) (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 EBBBB2189F; Tue, 28 May 2019 17:51:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559065864; bh=DsYg7AzSvHFuFdz1+CG0RxTB+NMpLarMplA0DbFOavM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kfrukAQ8tCRy4O98o8gI4NYU2wQ0GGu4DlqXdDKGLqyx8XmBOI5HaJTj0AcLAUPiC eXk2WsIZr5uSijep5RwaPA2LIwfPdhh6G/nuGWwxKIDLh9pRvKFM0ruGWo4TAh+Y72 rHcSa6KWyScaQpQ1Nje4+RsryoypuHsRqsEeHiX8= From: Arnaldo Carvalho de Melo To: Ingo Molnar , Thomas Gleixner Cc: Jiri Olsa , Namhyung Kim , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Hari Bathini , Jiri Olsa , Krister Johansen , Arnaldo Carvalho de Melo Subject: [PATCH 09/14] perf namespace: Protect reading thread's namespace Date: Tue, 28 May 2019 14:50:15 -0300 Message-Id: <20190528175020.13343-10-acme@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190528175020.13343-1-acme@kernel.org> References: <20190528175020.13343-1-acme@kernel.org> 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 From: Namhyung Kim It seems that the current code lacks holding the namespace lock in thread__namespaces(). Otherwise it can see inconsistent results. Signed-off-by: Namhyung Kim Cc: Hari Bathini Cc: Jiri Olsa Cc: Krister Johansen Link: http://lkml.kernel.org/r/20190522053250.207156-2-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/thread.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c index 403045a2bbea..b413ba5b9835 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c @@ -133,7 +133,7 @@ void thread__put(struct thread *thread) } } -struct namespaces *thread__namespaces(const struct thread *thread) +static struct namespaces *__thread__namespaces(const struct thread *thread) { if (list_empty(&thread->namespaces_list)) return NULL; @@ -141,10 +141,21 @@ struct namespaces *thread__namespaces(const struct thread *thread) return list_first_entry(&thread->namespaces_list, struct namespaces, list); } +struct namespaces *thread__namespaces(const struct thread *thread) +{ + struct namespaces *ns; + + down_read((struct rw_semaphore *)&thread->namespaces_lock); + ns = __thread__namespaces(thread); + up_read((struct rw_semaphore *)&thread->namespaces_lock); + + return ns; +} + static int __thread__set_namespaces(struct thread *thread, u64 timestamp, struct namespaces_event *event) { - struct namespaces *new, *curr = thread__namespaces(thread); + struct namespaces *new, *curr = __thread__namespaces(thread); new = namespaces__new(event); if (!new) -- 2.20.1