From patchwork Wed Aug 15 18:49:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 10566753 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7EE62921 for ; Wed, 15 Aug 2018 18:50:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 557E42AF5F for ; Wed, 15 Aug 2018 18:50:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 52A232AF34; Wed, 15 Aug 2018 18:50:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A1E922AF36 for ; Wed, 15 Aug 2018 18:50:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 673276B0269; Wed, 15 Aug 2018 14:50:36 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6203F6B026A; Wed, 15 Aug 2018 14:50:36 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4C2AB6B026B; Wed, 15 Aug 2018 14:50:36 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by kanga.kvack.org (Postfix) with ESMTP id 01A946B0269 for ; Wed, 15 Aug 2018 14:50:36 -0400 (EDT) Received: by mail-pf1-f198.google.com with SMTP id d22-v6so924634pfn.3 for ; Wed, 15 Aug 2018 11:50:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=LJTorXFucv5v4F07S1owqMgoSIlym/JkIF2Oybwf2xo=; b=PJs8D1wEjjmsPY8oOcioJA/2xjRgOpKhQWxVekDr7ql9g+gBE8EM4hLBUIxokMcQHh FXeZUmHYrnxaUcFIfN3PO+UlLjgfN18PSHNsaVaOTdgqTfMybc+lhoDKAcnRaHBqPQdZ DbItAtUXshpBmTlUOLSU50BEh4zZvic2pd9/RcGA5tYWJY3eyps3JESnJ1t4NLu6tfUO /TQZAOmsLWIRNNPzkKtymyzkrQKwtu3ZJ2Q9N2lPJY0RMKdCxhTRvhHYLSUnL62zPUUe HQI8r5MOXp/QYck73PlqjevCON285Y7A1jty0fdQdRL2r++CUIzspL0VqVD231fARCqS FbAQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Gm-Message-State: AOUpUlFLhbKQVBUAIg1OxSJaGrNQgMVfAtQQkBI1hNk06HKh4SFW9XJ9 21eUoKn+ccXbKMZHtSQJrX6bLrKCWSuvA1mBeF3LNb8TMr3CbOdOFHpZMPN5zMyuQWZMNRBa5+1 E9358aJy+Flb7C4Q0jZ2f5bNaK4tUQPLGe0ijV5lO4aRf6CubG508UneXMfIsj0Oo/A== X-Received: by 2002:a17:902:6f16:: with SMTP id w22-v6mr6454312plk.127.1534359035677; Wed, 15 Aug 2018 11:50:35 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxtKOp7WGNSaUCDdwC1XSif+Rzqt/J9RCIsNrBuh632FxYlSvWuUeEK3bx6zYygI5EorwkZ X-Received: by 2002:a17:902:6f16:: with SMTP id w22-v6mr6454269plk.127.1534359034627; Wed, 15 Aug 2018 11:50:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534359034; cv=none; d=google.com; s=arc-20160816; b=HJl/+DtxchqJx1aqCcaipQiIu3ic3PknjOWdPJLxBsbfW7yK1KFTR2h8EHyHQW5HLW 7kAjxOJiEu/ZszZ0SXdxNYrf+sfN59cNU4kxx7wFWsUKVAZr/ab5oRSMn+nXpYx/ZFWq ZsWMgA94w7oFfOZQDccmGqxLjFSdyROJf1owKC8Z2UF3HD6kR3uRzJAF1z5T2ALe8/xo jbFxopwliqUj4L/fmFiMTMU8SIo9kqFveTVHZMidkOa6BNGuFzjpJPdFLa0gvId5bNNT hcqsQGfOxeo0+ndm9wVRbXSrpsswmvRZnWHN7JJ3cL64SVFDs0FI0OfqGG/q6LhE2s/9 AFgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=LJTorXFucv5v4F07S1owqMgoSIlym/JkIF2Oybwf2xo=; b=zXUBrb/Wl0Zb0Qd7k3mLUO3GN/QWl0jzQ48i0KMg0B9S7gQxq7mLg4CjzBLfKK/sws EuvOyW2KxffFxTvLiSNhROF9B/16eYIQyfQhw3NELnsXhnH0+zkT0mvoMIodKD1EVOZY PagQLjHwJVTJYZtirqENa2NxLzPK//mRhC4vQDtq9vEqr5NAjnD929bpSGzA6m13HqVF GGitfwcN1iZiKXdWgcVryU2Q0zGqladUtoLcG6wFXmTaX0jGmkkNmyOIlDvf2AyFrlL0 12ZxRYRQyxBa9Le1zUaTg8IYqSUeOAaQxqk3T4/mQn696PaGBmXGcUDFoyp/Ezo8j8pt zbAA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out4436.biz.mail.alibaba.com (out4436.biz.mail.alibaba.com. [47.88.44.36]) by mx.google.com with ESMTPS id d9-v6si20206719pgo.470.2018.08.15.11.50.33 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Aug 2018 11:50:34 -0700 (PDT) Received-SPF: pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 as permitted sender) client-ip=47.88.44.36; Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R181e4;CH=green;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e01422;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=15;SR=0;TI=SMTPD_---0T6gJtNa_1534358999; Received: from e19h19392.et15sqa.tbsite.net(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0T6gJtNa_1534358999) by smtp.aliyun-inc.com(127.0.0.1); Thu, 16 Aug 2018 02:50:07 +0800 From: Yang Shi To: mhocko@kernel.org, willy@infradead.org, ldufour@linux.vnet.ibm.com, kirill@shutemov.name, vbabka@suse.cz, akpm@linux-foundation.org, peterz@infradead.org, mingo@redhat.com, acme@kernel.org, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org Cc: yang.shi@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC v8 PATCH 2/5] uprobes: introduce has_uprobes helper Date: Thu, 16 Aug 2018 02:49:47 +0800 Message-Id: <1534358990-85530-3-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1534358990-85530-1-git-send-email-yang.shi@linux.alibaba.com> References: <1534358990-85530-1-git-send-email-yang.shi@linux.alibaba.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP We need check if mm or vma has uprobes in the following patch to check if a vma could be unmapped with holding read mmap_sem. The checks and pre-conditions used by uprobe_munmap() look just suitable for this purpose. Extracting those checks into a helper function, has_uprobes(). Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Arnaldo Carvalho de Melo Cc: Alexander Shishkin Cc: Jiri Olsa Cc: Namhyung Kim Cc: Vlastimil Babka Signed-off-by: Yang Shi --- include/linux/uprobes.h | 7 +++++++ kernel/events/uprobes.c | 23 ++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/include/linux/uprobes.h b/include/linux/uprobes.h index 0a294e9..418764e 100644 --- a/include/linux/uprobes.h +++ b/include/linux/uprobes.h @@ -149,6 +149,8 @@ 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); +extern bool has_uprobes(struct vm_area_struct *vma, unsigned long start, + unsigned long end); #else /* !CONFIG_UPROBES */ struct uprobes_state { }; @@ -203,5 +205,10 @@ static inline void uprobe_copy_process(struct task_struct *t, unsigned long flag static inline void uprobe_clear_state(struct mm_struct *mm) { } +static inline bool has_uprobes(struct vm_area_struct *vma, unsigned long start, + unsgined long end) +{ + return false; +} #endif /* !CONFIG_UPROBES */ #endif /* _LINUX_UPROBES_H */ diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c index aed1ba5..568481c 100644 --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c @@ -1114,22 +1114,31 @@ int uprobe_mmap(struct vm_area_struct *vma) return !!n; } -/* - * Called in context of a munmap of a vma. - */ -void uprobe_munmap(struct vm_area_struct *vma, unsigned long start, unsigned long end) +bool +has_uprobes(struct vm_area_struct *vma, unsigned long start, unsigned long end) { if (no_uprobe_events() || !valid_vma(vma, false)) - return; + return false; if (!atomic_read(&vma->vm_mm->mm_users)) /* called by mmput() ? */ - return; + return false; if (!test_bit(MMF_HAS_UPROBES, &vma->vm_mm->flags) || test_bit(MMF_RECALC_UPROBES, &vma->vm_mm->flags)) - return; + return false; if (vma_has_uprobes(vma, start, end)) + return true; + + return false; +} + +/* + * Called in context of a munmap of a vma. + */ +void uprobe_munmap(struct vm_area_struct *vma, unsigned long start, unsigned long end) +{ + if (has_uprobes(vma, start, end)) set_bit(MMF_RECALC_UPROBES, &vma->vm_mm->flags); }