From patchwork Fri Mar 27 02:10:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michel Lespinasse X-Patchwork-Id: 11461559 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4AF7314B4 for ; Fri, 27 Mar 2020 02:11:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0BCAA2074D for ; Fri, 27 Mar 2020 02:11:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="kbnRZ3EQ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0BCAA2074D Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 94E056B0071; Thu, 26 Mar 2020 22:11:20 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8AE286B0072; Thu, 26 Mar 2020 22:11:20 -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 7BCB26B0073; Thu, 26 Mar 2020 22:11:20 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0153.hostedemail.com [216.40.44.153]) by kanga.kvack.org (Postfix) with ESMTP id 5BF586B0071 for ; Thu, 26 Mar 2020 22:11:20 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 407F54DA9 for ; Fri, 27 Mar 2020 02:11:20 +0000 (UTC) X-FDA: 76639515120.20.slip06_b9e6e55ad818 X-Spam-Summary: 2,0,0,c039729339563cd0,d41d8cd98f00b204,3xmb9xgykchcrvgfzibjjbgz.xjhgdips-hhfqvxf.jmb@flex--walken.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1260:1277:1313:1314:1345:1359:1437:1516:1518:1535:1542:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2693:3138:3139:3140:3141:3142:3152:3353:3865:3867:3870:3871:3874:5007:6261:6653:6742:7875:7903:9969:10004:10400:11026:11473:11658:11914:12043:12114:12296:12297:12438:12555:12895:12986:13161:13229:13255:14096:14097:14181:14394:14659:14721:21080:21324:21433:21444:21451:21627:21740:21987:21990:30054,0,RBL:209.85.215.201:@flex--walken.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: slip06_b9e6e55ad818 X-Filterd-Recvd-Size: 5616 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Fri, 27 Mar 2020 02:11:19 +0000 (UTC) Received: by mail-pg1-f201.google.com with SMTP id 33so6651235pgn.0 for ; Thu, 26 Mar 2020 19:11:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=mRGmq46YXMyZu9YZdo8naIlt7nPQjUFxl7dVtsp0NXQ=; b=kbnRZ3EQIaNtTYf2H3t1YorayOkyCZ9RKdvA96rIRVACHiJYkE08MrUDp6wpCuKLg0 IJX1a7Cu6yG8fQZc5PNMZahlhte37pb5bkOh1YX7gBncLU/bj70C28XMOSivokGDBT42 E5rJaG5tC4l0mdJiRei2Legye/R4vTo8D3kCVijBKJN6KJzrpKSVPvUDxOa6Gmq1ErbN hAv4PpkaMDVCtWklbxaCdrZK9PllMcn3SovnPybqqORINUSD2kKNtBQ7BlM2eI1aP5FS LrVM3iaDYcWFGtIvwR6ZfQX8mepmZm30fcYAFIWmZgphD/qrGf7UYa5Fivig6VqH4UyV a2Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=mRGmq46YXMyZu9YZdo8naIlt7nPQjUFxl7dVtsp0NXQ=; b=tEMsWTfQRozFKUwo6vPD9ESTb5Cm89tewp/DSgcmLW4Es94fR1RdYeZIOopOGReFL2 zm0WWy+95J/jhEUx3iS6eedqyoCq6hMLSuY7dXKCPgaK6GgkNyGFyAAhxTUIQfeAmeYW IJLz6/J19SyX+7R2QNGKdYkh1O2HMaNYOXl0iQI8BS3QhCTSpN57j9mjnR/Et6BC5SKJ huNFALeB5e8G2hSwAeHhHQ0hDNFNWaUMlV5fcydouzI3AcuW/K9UODMHHKZe8HkPTFLI XmV8srNo3HYW5i+YIJB3fdZQP75pfX8SwcAMR7NzFPpeGMNFs1f7rp3GVOg/bL6I+zpl 6L8w== X-Gm-Message-State: ANhLgQ2GtitEXWo4C8voI7W6Hp4mXxxOMZid0B+oGWAvO1B6ConONEUf csvwhy6NUSSgyAGu16p6NgzsRoSyFdk= X-Google-Smtp-Source: ADFU+vvoIGgQXc+TUhUHzmVFdOtuACoigyqHXdt16UNQbmfXwVGrE2GzUA0KzToVG+3fgq7V/E1YO4PHmD4= X-Received: by 2002:a17:90a:b78e:: with SMTP id m14mr3206364pjr.135.1585275078640; Thu, 26 Mar 2020 19:11:18 -0700 (PDT) Date: Thu, 26 Mar 2020 19:10:55 -0700 In-Reply-To: <20200327021058.221911-1-walken@google.com> Message-Id: <20200327021058.221911-8-walken@google.com> Mime-Version: 1.0 References: <20200327021058.221911-1-walken@google.com> X-Mailer: git-send-email 2.26.0.rc2.310.g2932bb562d-goog Subject: [PATCH v2 07/10] mmap locking API: add mmap_read_release() and mmap_read_unlock_non_owner() From: Michel Lespinasse To: Andrew Morton , linux-mm Cc: LKML , Peter Zijlstra , Laurent Dufour , Vlastimil Babka , Matthew Wilcox , Liam Howlett , Jerome Glisse , Davidlohr Bueso , David Rientjes , Hugh Dickins , Ying Han , Jason Gunthorpe , Markus Elfring , Michel Lespinasse 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: Add a couple APIs to allow splitting mmap_read_unlock() into two calls: - mmap_read_release(), called by the task that had taken the mmap lock; - mmap_read_unlock_non_owner(), called from a work queue. These apis are used by kernel/bpf/stackmap.c only. Signed-off-by: Michel Lespinasse --- include/linux/mmap_lock.h | 10 ++++++++++ kernel/bpf/stackmap.c | 9 ++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/include/linux/mmap_lock.h b/include/linux/mmap_lock.h index 40a972a26857..00d6cc02581d 100644 --- a/include/linux/mmap_lock.h +++ b/include/linux/mmap_lock.h @@ -62,6 +62,16 @@ static inline void mmap_read_unlock(struct mm_struct *mm) up_read(&mm->mmap_sem); } +static inline void mmap_read_release(struct mm_struct *mm, unsigned long ip) +{ + rwsem_release(&mm->mmap_sem.dep_map, ip); +} + +static inline void mmap_read_unlock_non_owner(struct mm_struct *mm) +{ + up_read_non_owner(&mm->mmap_sem); +} + static inline bool mmap_is_locked(struct mm_struct *mm) { return rwsem_is_locked(&mm->mmap_sem) != 0; diff --git a/kernel/bpf/stackmap.c b/kernel/bpf/stackmap.c index f2115f691577..413b512a99eb 100644 --- a/kernel/bpf/stackmap.c +++ b/kernel/bpf/stackmap.c @@ -33,7 +33,7 @@ struct bpf_stack_map { /* irq_work to run up_read() for build_id lookup in nmi context */ struct stack_map_irq_work { struct irq_work irq_work; - struct rw_semaphore *sem; + struct mm_struct *mm; }; static void do_up_read(struct irq_work *entry) @@ -41,8 +41,7 @@ static void do_up_read(struct irq_work *entry) struct stack_map_irq_work *work; work = container_of(entry, struct stack_map_irq_work, irq_work); - up_read_non_owner(work->sem); - work->sem = NULL; + mmap_read_unlock_non_owner(work->mm); } static DEFINE_PER_CPU(struct stack_map_irq_work, up_read_work); @@ -332,14 +331,14 @@ static void stack_map_get_build_id_offset(struct bpf_stack_build_id *id_offs, if (!work) { mmap_read_unlock(current->mm); } else { - work->sem = ¤t->mm->mmap_sem; + work->mm = current->mm; irq_work_queue(&work->irq_work); /* * The irq_work will release the mmap_sem with * up_read_non_owner(). The rwsem_release() is called * here to release the lock from lockdep's perspective. */ - rwsem_release(¤t->mm->mmap_sem.dep_map, _RET_IP_); + mmap_read_release(current->mm, _RET_IP_); } }