Received: by 10.213.65.68 with SMTP id h4csp1053528imn; Wed, 14 Mar 2018 08:14:33 -0700 (PDT) X-Google-Smtp-Source: AG47ELuUchTpH6aiRgRKjH30mT4MMSNcBzHM7oAmQ2ABayXMsMHDcoYxx7M043LMWtIXnZVEZ0W1 X-Received: by 10.99.149.15 with SMTP id p15mr4064434pgd.154.1521040473202; Wed, 14 Mar 2018 08:14:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521040473; cv=none; d=google.com; s=arc-20160816; b=LXAjL3b8Y4rEd8e98fME9k2O61XUKJx5a6jm8tZR7NPCcvgqXP9+7qmxtXrByLe7gq RLNlEf76lLUiwYk/y+L9qNc8DZ2ur8ArZHX0uDL1CdwElBG5efX6QXeOUHG/rkYW+ouo /OpdkhoLAmgbsYy64aHCUyiexHBzsw6WDG0vlFg10PU4An+vtxAsW16YBAz04MLoLozP 9Sp2WnUO4qsvjZtgPgo8F7zwkkH+VFNoCALVpDjuZaSCH+mJG/9X/4492K6/SvOSkmUh XkXUSQSBrziQLGsjygOygR11lTPkrf/oKTL6gMeQp3TuTrrUnMr4iOt+jek3FYd7//qB OmIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :from:references:cc:to:subject:arc-authentication-results; bh=Gpl99H+g+4NLnAIRi1cPvUOcZIHoCgO9Icw0mI8vTMQ=; b=WtvoXjZXsSwUv1695sqRp+XhE230TWmnb9WU8wciI+7sA2u6IK/1GYkM2SHTOltonF xMFsXBBNfv99RiUcML7QmNU822mJeU52vOVOFZaI3X6lV5omK6tkht+ohAg6tzGVVNkn tDXPWSW6DBDVfsUvTRAqoATjLXbUi7NvjVx4HjrpgvvF+Q2ceWQdfl1RQ32XEJJz1E3B 3GNlAGxHMMQNZiFlwNEX+zJDxxRPZqAO7ogP/ChME7b4hiNjtyhNurai1+voP7voe3QY NQihI6NK3w9b/yvpnivcpFcVlx5JAaklpYiQvp2CJUjPLyR9uGT2ED5NGnfAZq94XfNr xazw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j88si2230957pfe.324.2018.03.14.08.14.09; Wed, 14 Mar 2018 08:14:33 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751480AbeCNPNQ (ORCPT + 99 others); Wed, 14 Mar 2018 11:13:16 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:54566 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751362AbeCNPNO (ORCPT ); Wed, 14 Mar 2018 11:13:14 -0400 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w2EFAsIq058271 for ; Wed, 14 Mar 2018 11:13:14 -0400 Received: from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com [195.75.94.106]) by mx0a-001b2d01.pphosted.com with ESMTP id 2gq5bctsaw-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Wed, 14 Mar 2018 11:13:13 -0400 Received: from localhost by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 14 Mar 2018 15:13:10 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp10.uk.ibm.com (192.168.101.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 14 Mar 2018 15:13:03 -0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w2EFD2G9131490; Wed, 14 Mar 2018 15:13:02 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 30FCD5204C; Wed, 14 Mar 2018 14:04:33 +0000 (GMT) Received: from [9.77.194.179] (unknown [9.77.194.179]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 2FF9C5203F; Wed, 14 Mar 2018 14:04:20 +0000 (GMT) Subject: Re: [PATCH 6/8] trace_uprobe/sdt: Fix multiple update of same reference counter To: Masami Hiramatsu Cc: oleg@redhat.com, peterz@infradead.org, srikar@linux.vnet.ibm.com, acme@kernel.org, ananth@linux.vnet.ibm.com, akpm@linux-foundation.org, alexander.shishkin@linux.intel.com, alexis.berlemont@gmail.com, corbet@lwn.net, dan.j.williams@intel.com, gregkh@linuxfoundation.org, huawei.libin@huawei.com, hughd@google.com, jack@suse.cz, jglisse@redhat.com, jolsa@redhat.com, kan.liang@intel.com, kirill.shutemov@linux.intel.com, kjlx@templeofstupid.com, kstewart@linuxfoundation.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhocko@suse.com, milian.wolff@kdab.com, mingo@redhat.com, namhyung@kernel.org, naveen.n.rao@linux.vnet.ibm.com, pc@us.ibm.com, pombredanne@nexb.com, rostedt@goodmis.org, tglx@linutronix.de, tmricht@linux.vnet.ibm.com, willy@infradead.org, yao.jin@linux.intel.com, fengguang.wu@intel.com, Ravi Bangoria References: <20180313125603.19819-1-ravi.bangoria@linux.vnet.ibm.com> <20180313125603.19819-7-ravi.bangoria@linux.vnet.ibm.com> <20180314231540.b98c74a153255f59f54ebc46@kernel.org> From: Ravi Bangoria Date: Wed, 14 Mar 2018 20:45:14 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20180314231540.b98c74a153255f59f54ebc46@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US X-TM-AS-GCONF: 00 x-cbid: 18031415-0040-0000-0000-000004206C0F X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18031415-0041-0000-0000-0000262370F8 Message-Id: <1e51042b-d05b-dd55-82e6-818bb5be03d1@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-03-14_07:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1803140171 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/14/2018 07:45 PM, Masami Hiramatsu wrote: > On Tue, 13 Mar 2018 18:26:01 +0530 > Ravi Bangoria wrote: > >> For tiny binaries/libraries, different mmap regions points to the >> same file portion. In such cases, we may increment reference counter >> multiple times. But while de-registration, reference counter will get >> decremented only by once leaving reference counter > 0 even if no one >> is tracing on that marker. >> >> Ensure increment and decrement happens in sync by keeping list of >> mms in trace_uprobe. Increment reference counter only if mm is not >> present in the list and decrement only if mm is present in the list. >> >> Example >> >> # echo "p:sdt_tick/loop2 /tmp/tick:0x6e4(0x10036)" > uprobe_events >> >> Before patch: >> >> # perf stat -a -e sdt_tick:loop2 >> # /tmp/tick >> # dd if=/proc/`pgrep tick`/mem bs=1 count=1 skip=$(( 0x10020036 )) 2>/dev/null | xxd >> 0000000: 02 . >> >> # pkill perf >> # dd if=/proc/`pgrep tick`/mem bs=1 count=1 skip=$(( 0x10020036 )) 2>/dev/null | xxd >> 0000000: 01 . >> >> After patch: >> >> # perf stat -a -e sdt_tick:loop2 >> # /tmp/tick >> # dd if=/proc/`pgrep tick`/mem bs=1 count=1 skip=$(( 0x10020036 )) 2>/dev/null | xxd >> 0000000: 01 . >> >> # pkill perf >> # dd if=/proc/`pgrep tick`/mem bs=1 count=1 skip=$(( 0x10020036 )) 2>/dev/null | xxd >> 0000000: 00 . >> >> Signed-off-by: Ravi Bangoria >> --- >> kernel/trace/trace_uprobe.c | 105 +++++++++++++++++++++++++++++++++++++++++++- >> 1 file changed, 103 insertions(+), 2 deletions(-) >> >> diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c >> index b6c9b48..9bf3f7a 100644 >> --- a/kernel/trace/trace_uprobe.c >> +++ b/kernel/trace/trace_uprobe.c >> @@ -50,6 +50,11 @@ struct trace_uprobe_filter { >> struct list_head perf_events; >> }; >> >> +struct sdt_mm_list { >> + struct mm_struct *mm; >> + struct sdt_mm_list *next; >> +}; > Oh, please use struct list_head instead of defining your own pointer-chain :( Sure, will change it. >> + >> /* >> * uprobe event core functions >> */ >> @@ -61,6 +66,8 @@ struct trace_uprobe { >> char *filename; >> unsigned long offset; >> unsigned long ref_ctr_offset; >> + struct sdt_mm_list *sml; >> + struct rw_semaphore sml_rw_sem; > BTW, is there any reason to use rw_semaphore? (mutex doesn't fit?) Hmm.. No specific reason.. will use a mutex instead. Thanks for the review :) Ravi