From patchwork Mon Feb 24 20:30:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michel Lespinasse X-Patchwork-Id: 11401493 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 AAD60924 for ; Mon, 24 Feb 2020 20:31:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 786F520675 for ; Mon, 24 Feb 2020 20:31:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="t2VOfWpc" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 786F520675 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 A2C7B6B0074; Mon, 24 Feb 2020 15:31:13 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9D9EB6B0078; Mon, 24 Feb 2020 15:31:13 -0500 (EST) 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 8CDE86B007B; Mon, 24 Feb 2020 15:31:13 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0058.hostedemail.com [216.40.44.58]) by kanga.kvack.org (Postfix) with ESMTP id 6D4FF6B0074 for ; Mon, 24 Feb 2020 15:31:13 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 1A2CF442C for ; Mon, 24 Feb 2020 20:31:13 +0000 (UTC) X-FDA: 76526165226.15.base21_27b0b299e9a2f X-Spam-Summary: 2,0,0,c955cc5fcab7dc60,d41d8cd98f00b204,3jzjuxgykcd41fqpjslttlqj.htrqnsz2-rrp0fhp.twl@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:2553:2559:2562:2693:2897:2901:3138:3139:3140:3141:3142:3152:3353:3865:3867:3868:3871:3874:4250:4321:4605:5007:6120:6261:6653:7875:7901:9969:10004:10400:11026:11658:11914:12043:12048:12296:12297:12438:12555:12895:14096:14097:14181:14659:14721:21080:21324:21444:21451:21627:21740:21795:30051:30054:30070:30090,0,RBL:209.85.215.202:@flex--walken.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.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:25,LUA_SUMMARY:none X-HE-Tag: base21_27b0b299e9a2f X-Filterd-Recvd-Size: 5670 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Mon, 24 Feb 2020 20:31:12 +0000 (UTC) Received: by mail-pg1-f202.google.com with SMTP id x16so7381080pgg.5 for ; Mon, 24 Feb 2020 12:31:12 -0800 (PST) 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=8VmscI1RCghYUOSCVKk9VfVci8C2tHLrU7umlD+2RaE=; b=t2VOfWpcqOZOobAGdy/o6QvSPodpKwhAJEApkkcuzmy8HfCurQxGCSYCoOY8/S8MTn ZCuNm8dzrQgTCDkv1FQPRnHEDHlvJ1aOTaCkt7jW3VllJoac4HzXDS6DUfeLlp0QKeeY PILy38L1aGhdXYbtdhH0kGUMe2UKjefHwWlmuhzCzFqKJdYXzQwQ1gQQG9N6MKGZUXRS GSCmTkfB9f41xW7rKC0JwpmDXhbmysjtkEWfd/ZP2w9P7Nj99EtqGgooDwBTLkC3pMCP e6P/MVO4HnWQ3EJiL1kS/iRxemSMtD+uo6GKCOJqTDCOlRLs4MWSJMzVlDg6wmQNzKg0 dmvg== 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=8VmscI1RCghYUOSCVKk9VfVci8C2tHLrU7umlD+2RaE=; b=AyErA+0gZwmj1IpjhN4DjiD2s0M6MwmFUu65VeF75OPkDLFSaIDy4ARjzpAwSRCPdd CPc2uzc3nXS8Fw9e6HwVSSYHBlEVEAPe9Tve+lC+wH8XUiCDTEcCYyaRu95Ky8fg25XD Tz45P4Tg4Qr3TnHJKOsfixGQsSFxr8zuW3VYQ9pNhcJkA42+KyhcrMGacDQrhQJ1VMNy SvfnxcJ+3zt0zm38r4Ph1blrnMLJFSiSiytgucH6rgpjisPj0TLN7lmi0DQwySZNKREC Xrni7+puJgc1VMI0rF+SNiMnUJH5+jQ1oESzrprQ5Xz0Pydoo7BIGUJF+A9b4IzmnN/o oTBg== X-Gm-Message-State: APjAAAWDOobpLNzJMIIgLEcnynbfuPBsAbu/ol2bdC/ow6nNYhGNdQRU 62SjgD5DaufLRYnrAIF6gz1n3XgoPRg= X-Google-Smtp-Source: APXvYqzDyvrL083Ast9HtZkqcCrhFmRXxvU6atNDwBwFAVlWdeDyNFz+fzCLVAtl4GwBgFp58+68qOnYjEA= X-Received: by 2002:a63:2842:: with SMTP id o63mr56173049pgo.317.1582576271751; Mon, 24 Feb 2020 12:31:11 -0800 (PST) Date: Mon, 24 Feb 2020 12:30:38 -0800 In-Reply-To: <20200224203057.162467-1-walken@google.com> Message-Id: <20200224203057.162467-6-walken@google.com> Mime-Version: 1.0 References: <20200224203057.162467-1-walken@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [RFC PATCH 05/24] MM locking API: allow for sleeping during unlock From: Michel Lespinasse To: Peter Zijlstra , Andrew Morton , Laurent Dufour , Vlastimil Babka , Matthew Wilcox , "Liam R . Howlett" , Jerome Glisse , Davidlohr Bueso , David Rientjes Cc: linux-mm , 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: Following changes will implement fine-grained range locks for the MM locking API, using a data structure to represent the existing locks, and a mutex to protect that data structure. As a result, we need to prepare for the possibility that unlocking a memory range may need to sleep when acquiring that mutex. Signed-off-by: Michel Lespinasse --- kernel/bpf/stackmap.c | 6 +++++- kernel/exit.c | 2 +- mm/mm_lock_rwsem_checked.c | 3 +++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git kernel/bpf/stackmap.c kernel/bpf/stackmap.c index ba2399ce00e4..0f483abeb94c 100644 --- kernel/bpf/stackmap.c +++ kernel/bpf/stackmap.c @@ -308,8 +308,12 @@ static void stack_map_get_build_id_offset(struct bpf_stack_build_id *id_offs, * * Same fallback is used for kernel stack (!user) on a stackmap * with build_id. + * + * FIXME - currently disabling the build_id lookup feature + * as mm_read_range_unlock() may block, which is not always + * possible to do here. */ - if (!user || !current || !current->mm || irq_work_busy || + if (true || !user || !current || !current->mm || irq_work_busy || !mm_read_range_trylock(current->mm, mm_range_ptr)) { /* cannot access current->mm, fall back to ips */ for (i = 0; i < trace_nr; i++) { diff --git kernel/exit.c kernel/exit.c index 9a0b72562adb..60ec6efb4e2c 100644 --- kernel/exit.c +++ kernel/exit.c @@ -478,9 +478,9 @@ static void exit_mm(void) /* more a memory barrier than a real lock */ task_lock(current); current->mm = NULL; - mm_read_unlock(mm); enter_lazy_tlb(mm, current); task_unlock(current); + mm_read_unlock(mm); mm_update_next_owner(mm); mmput(mm); if (test_thread_flag(TIF_MEMDIE)) diff --git mm/mm_lock_rwsem_checked.c mm/mm_lock_rwsem_checked.c index 3551deb85e3d..e45d1a598c87 100644 --- mm/mm_lock_rwsem_checked.c +++ mm/mm_lock_rwsem_checked.c @@ -61,6 +61,7 @@ EXPORT_SYMBOL(mm_write_range_trylock); void mm_write_range_unlock(struct mm_struct *mm, struct mm_lock_range *range) { + might_sleep(); if (range->mm != mm) mm_lock_dump("mm_write_range_unlock"); range->mm = NULL; @@ -113,6 +114,7 @@ EXPORT_SYMBOL(mm_read_range_trylock); void mm_read_range_unlock(struct mm_struct *mm, struct mm_lock_range *range) { + might_sleep(); if (range->mm != mm) mm_lock_dump("mm_read_range_unlock"); range->mm = NULL; @@ -123,6 +125,7 @@ EXPORT_SYMBOL(mm_read_range_unlock); void mm_read_range_unlock_non_owner(struct mm_struct *mm, struct mm_lock_range *range) { + might_sleep(); if (range->mm != mm) mm_lock_dump("mm_read_range_unlock_non_owner"); range->mm = NULL;