From patchwork Thu Mar 26 07:02:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michel Lespinasse X-Patchwork-Id: 11459397 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 D9354913 for ; Thu, 26 Mar 2020 07:03:01 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A69D4207FC for ; Thu, 26 Mar 2020 07:03:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="n+aTmufP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A69D4207FC 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 9C6CA6B0036; Thu, 26 Mar 2020 03:02:55 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 977B76B0037; Thu, 26 Mar 2020 03:02:55 -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 88B4D6B006C; Thu, 26 Mar 2020 03:02:55 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0179.hostedemail.com [216.40.44.179]) by kanga.kvack.org (Postfix) with ESMTP id 701336B0036 for ; Thu, 26 Mar 2020 03:02:55 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 693F45853 for ; Thu, 26 Mar 2020 07:02:55 +0000 (UTC) X-FDA: 76636621110.17.move72_197a3f0670b08 X-Spam-Summary: 2,0,0,5d6d65345b0ee81f,d41d8cd98f00b204,3nvn8xgykcdaimxwqzsaasxq.oayxuzgj-yywhmow.ads@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.202:@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: move72_197a3f0670b08 X-Filterd-Recvd-Size: 5528 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) by imf24.hostedemail.com (Postfix) with ESMTP for ; Thu, 26 Mar 2020 07:02:54 +0000 (UTC) Received: by mail-pg1-f202.google.com with SMTP id v11so4008708pgs.10 for ; Thu, 26 Mar 2020 00:02:54 -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=DpjYosebPVpuPQwYrgnmEYhswUaFUaz4jId1cdbBdEg=; b=n+aTmufP6JMctYFU46YmDT0hJMNBwCoGeQ2H4e1Y87B+NthqtKUlorXmg3J9jwPZSs Ypc/TZCr5rq/49yZbePRrlndFCIHAsT0y3visA2ncO3JloeeHZaGM01yv7oqY2ZnAs87 uL1BKaOmjXgdyE3bFI339A3v0yGXMoP218gWE4JgTrwJc41oZfto4Pnj8LAnHyva7OWM jZm9JOA6/9wn6Rzab1gJcMc4UqT3i1tgXmqv6eVUEk8xArcYCSESF3U3JaqArLXTx1po 0YYgzzgL+7zDLiLPiXFd+vBdrYPNNlZiDk/eU8OlSBcdxgiAhT7kUSOIPX9kgZ+F4yNX +9aw== 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=DpjYosebPVpuPQwYrgnmEYhswUaFUaz4jId1cdbBdEg=; b=HM87KeMYh+K6MkgV+jhMI9V/HA5R2D/il4SnyOSE53iRv1TI31kY65XZIAxe8BrHcX Zr7mr2dXUcO7st/kO3plUHTJMnRHtGfyAL/3YZ4cwzDzWEiq/r4RDCZHtVHs9UtzM7XU c77guc0+QiDxAvUT2JgJbd/BC2MfkUqpIFPVUlwsGusECg/eQO3x3q+EbN8gzmIvtheC PYcf16gI/2RZ0RbGUTnDEXTl1S4KayBVwQaQodM+F/+OKxBjBeYWMPoLAmFjGjvQzLy7 lOn0ukVgGfo1hUDYZryLYD1LJU2gvKteyCuLu0+JI6ZcZ+Yvl7x9CP7VHN/1h13nrelT 04OA== X-Gm-Message-State: ANhLgQ1EhVY0UAyntwlTmQBEbapY7FOh3GxjNrzXG9sWHKVguez2331o GsKiaF2wURRemlqLwSTsSP1fz37hn0w= X-Google-Smtp-Source: ADFU+vsBGhjPN1+jWZAin0MSjTA//3xgFIkfN//a4ht+5wmtVuoYamcyNWXv7PgVPkU7CJSVWKZzA7QUhb0= X-Received: by 2002:a17:90a:4809:: with SMTP id a9mr1536611pjh.73.1585206173836; Thu, 26 Mar 2020 00:02:53 -0700 (PDT) Date: Thu, 26 Mar 2020 00:02:34 -0700 In-Reply-To: <20200326070236.235835-1-walken@google.com> Message-Id: <20200326070236.235835-7-walken@google.com> Mime-Version: 1.0 References: <20200326070236.235835-1-walken@google.com> X-Mailer: git-send-email 2.25.1.696.g5e7596f4ac-goog Subject: [PATCH 6/8] 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 , 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_); } }