Received: by 10.223.185.116 with SMTP id b49csp7027715wrg; Wed, 28 Feb 2018 21:24:26 -0800 (PST) X-Google-Smtp-Source: AG47ELsX4w1FuUzkoGtoTol4Km3xOP96dfYIuHB8QpSRzMm2SnyOpxb6I1Wjwu9QK874tc8mocCi X-Received: by 10.101.72.2 with SMTP id h2mr582159pgs.240.1519881866664; Wed, 28 Feb 2018 21:24:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519881866; cv=none; d=google.com; s=arc-20160816; b=QS1Fic2E5rxd5Wqx+ukcgIK2LK5AbhBAdA6k50xdDaCk8r6eJpOlu3YxNxKdzoqr9a tjvYvidnsSBzjNoG3wjmWBeo3Q7HTQHLqd+ZaRarADDhQ7EW9mA3N2YA8vG5r2sCQB0F /dDUBXhrfyeL8Izv4ZUOFpGMTl41r+fdnsvTC2iClJNegWZ6R5L4lFGcxgWzeTwc5yZQ h29uEvmwbgws88QQV1m0FDz9THPso5ogl9FXBEPLWpleRaHDinzidVYAFfry/92ksadL ZcjgbMwNF/gyllcXsQllWGZMGqILj2m7MfSGAB8NJ+qjKiyqTcgaw+F3BoKjDiVRAyJi Y0OQ== 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 :references:cc:to:subject:from:arc-authentication-results; bh=a7O5sZ7Yq/wFUDUu5YeRQtbgJSIJ3gmPYkh328A10og=; b=ZR2w0xf3hlD5Hse2EKcjGs3JxN10CVkuPY2rTbXfcki/eoDwKKivQh4FAdYxS7OUr4 whAWo5KPezg4PYzRcZkkawvtXymz+DSu6dQo3RoIrs4feBexyV+auE1btyIXpurcaIDw bc9aimTQfIkPKXCkF7jCYSSRRHrZVBTfmIgT9IcCs6UqVQDRJjHZcTqwC7EZP3kXz8jl PZiIlvwwfcyg241peg2Gc1cD/l65vcCRcPukmlGQPaDG+6anPmOZDnrLnB8Mq59ryJW2 r/NenE9+N7HBmR36oZjXuB6c7aShcvb9s0CgQWddRusCIkGzL5zQqSM8+obHkUqgN9zA W3rg== 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 r1-v6si2492479plb.102.2018.02.28.21.24.11; Wed, 28 Feb 2018 21:24:26 -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; 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 S966041AbeCAFXH (ORCPT + 99 others); Thu, 1 Mar 2018 00:23:07 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:35160 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966016AbeCAFXG (ORCPT ); Thu, 1 Mar 2018 00:23:06 -0500 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w215Kqbl142016 for ; Thu, 1 Mar 2018 00:23:05 -0500 Received: from e06smtp11.uk.ibm.com (e06smtp11.uk.ibm.com [195.75.94.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ge97cm0h7-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 01 Mar 2018 00:23:05 -0500 Received: from localhost by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 1 Mar 2018 05:23:03 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp11.uk.ibm.com (192.168.101.141) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 1 Mar 2018 05:22:58 -0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w215Mwnm33226986; Thu, 1 Mar 2018 05:22:58 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E5A914C04E; Thu, 1 Mar 2018 05:16:26 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 308B84C046; Thu, 1 Mar 2018 05:16:24 +0000 (GMT) Received: from [9.124.31.169] (unknown [9.124.31.169]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 1 Mar 2018 05:16:24 +0000 (GMT) From: Ravi Bangoria Subject: Re: [RFC 2/4] Uprobe: Export few functions / data structures To: Srikar Dronamraju Cc: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, linux-kernel@vger.kernel.org, rostedt@goodmis.org, mhiramat@kernel.org, ananth@linux.vnet.ibm.com, naveen.n.rao@linux.vnet.ibm.com, oleg@redhat.com, Ravi Bangoria , linux-mm@kvack.org, Michal Hocko , Andrew Morton References: <20180228075345.674-1-ravi.bangoria@linux.vnet.ibm.com> <20180228075345.674-3-ravi.bangoria@linux.vnet.ibm.com> <20180228122440.GC63063@linux.vnet.ibm.com> Date: Thu, 1 Mar 2018 10:55:07 +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: <20180228122440.GC63063@linux.vnet.ibm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-US X-TM-AS-GCONF: 00 x-cbid: 18030105-0040-0000-0000-00000439461C X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18030105-0041-0000-0000-000020DC4893 Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-03-01_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=2 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-1803010067 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02/28/2018 05:54 PM, Srikar Dronamraju wrote: >> @@ -149,6 +155,11 @@ struct uprobes_state { >> extern bool arch_uprobe_ignore(struct arch_uprobe *aup, struct pt_regs *regs); >> extern void arch_uprobe_copy_ixol(struct page *page, unsigned long vaddr, >> void *src, unsigned long len); >> +unsigned long offset_to_vaddr(struct vm_area_struct *vma, loff_t offset); >> +void copy_from_page(struct page *page, unsigned long vaddr, void *dst, int len); >> +void copy_to_page(struct page *page, unsigned long vaddr, const void *src, int len); >> +struct uprobe_map_info *free_uprobe_map_info(struct uprobe_map_info *info); >> + >> #else /* !CONFIG_UPROBES */ > If we have to export the above, we might have to work with mm maintainers and > see if we can move them there. Adding     linux-mm@kvack.org     Michal Hocko     Andrew Morton in the cc. >> -static inline struct uprobe_map_info * >> -free_uprobe_map_info(struct uprobe_map_info *info) >> +struct uprobe_map_info *free_uprobe_map_info(struct uprobe_map_info *info) >> { >> struct uprobe_map_info *next = info->next; >> kfree(info); >> return next; >> } >> >> -static struct uprobe_map_info * >> -build_uprobe_map_info(struct address_space *mapping, loff_t offset, >> - bool is_register) >> +struct uprobe_map_info *build_uprobe_map_info(struct address_space *mapping, >> + loff_t offset, bool is_register) >> { >> unsigned long pgoff = offset >> PAGE_SHIFT; >> struct vm_area_struct *vma; > Instead of exporting, did you look at extending the uprobe consumer with > ops. i.e if the consumer detects that a probe is a semaphore and exports > a set of callbacks which can them be called from uprobe > insertion/deletion time. With such a thing, incrementing/decrementing > the semaphore and the insertion/deletion of the breakpoint can be done > at one shot. No? Yes, we tried that approach as well. Basically, when install_breakpoint() get called, notify consumer about that. We can either use consumer_filter function or add a new callback into uprobe_consumer which will get called if install_breakpoint() succeeds. something like:      if (install_breakpoint()) {          /* Notify consumers right after patching instruction. */          consumer->post_prepare();      } There are different problem with that approach. install_breakpoint() gets called in very early stage of binary loading and vma that holds the semaphore won't be present in the mm yet. I also tried to solve this by creating a task_work in consumer callback. task_work handler will get called when process virtual memory map is fully prepared and we are going back to userspace. But it will make design quite complicated. Also, there is no way to know if mm_struct we got in task_work handler is _still_ valid. With unregister also, we first remove the "caller" consumer and then re-patch original instruction. i.e.      __uprobe_unregister()      {          if (WARN_ON(!consumer_del(uprobe, uc)))              return;          err = register_for_each_vma(uprobe, NULL); We don't callback "caller" consumer at unregistration. Our idea is to make changes in core uprobe as less as possible. And IMHO, exporting build_map_info() helps to simplifies the implementation. Let me know if I'm missing something. Thanks for the review, Ravi