From patchwork Mon Feb 24 20:30:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michel Lespinasse X-Patchwork-Id: 11401529 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 0A68B14BC for ; Mon, 24 Feb 2020 20:32:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CBBC720675 for ; Mon, 24 Feb 2020 20:32:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="UA7u4tIC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CBBC720675 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 65DA06B00AB; Mon, 24 Feb 2020 15:31:58 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5E52E6B00AE; Mon, 24 Feb 2020 15:31:58 -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 4DF096B00AB; Mon, 24 Feb 2020 15:31:58 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0140.hostedemail.com [216.40.44.140]) by kanga.kvack.org (Postfix) with ESMTP id 2FEB36B00AB for ; Mon, 24 Feb 2020 15:31:58 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id E20F8282A for ; Mon, 24 Feb 2020 20:31:57 +0000 (UTC) X-FDA: 76526167074.24.tent33_2e32cc1f7170d X-Spam-Summary: 2,0,0,7d51ec93644d8b72,d41d8cd98f00b204,3vdjuxgykcgsfjutnwpxxpun.lxvurwdg-vvtejlt.xap@flex--walken.bounces.google.com,,RULES_HIT:41:69:152:355:379:541:800:960:966:973:988:989:1260:1277:1313:1314:1345:1359:1437:1516:1518:1535:1542:1593:1594:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:3138:3139:3140:3141:3142:3152:3353:3865:3866:3867:3868:3870:3872:4321:4385:5007:6120:6261:6653:8603:8660:9165:9592:9969:10004:10400:11026:11232:11658:11914:12043:12048:12296:12297:12438:12555:12895:12986:13148:13149:13230:13255:14181:14659:14721:21080:21444:21451:21627:21990:30003:30054:30056:30070,0,RBL:209.85.210.201:@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:24,LUA_SUMMARY:none X-HE-Tag: tent33_2e32cc1f7170d X-Filterd-Recvd-Size: 5086 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) by imf16.hostedemail.com (Postfix) with ESMTP for ; Mon, 24 Feb 2020 20:31:57 +0000 (UTC) Received: by mail-pf1-f201.google.com with SMTP id z17so7344668pfq.16 for ; Mon, 24 Feb 2020 12:31:57 -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=REgCThCDWq7ccS+cRBe2pbrHo45LO9EQeYdXqBBKYdY=; b=UA7u4tICRASavlBwCUStg6iBKNRYv85cDJ14hT+Xnuzt+XeJDkUhAw5Pl/wXXnkTPr RKReQqooWpJZOyinqnAC1zgNyn7/whRIF1sDCc1CHGddoc5rJXTZvPVrr5269BBc061G TfbTXB2I3fWeRncbsnHFPveA/HOUXu4vBlWg01gUTEot00fttl+s/npjUhVw8pw/Kv3P T6gwDiWdL48X180YI3nX4XoOSCMHYmIfYP8uTauDpZs4BYal0FNJQi7Ex65NFKxRoj4H UZLOeUjahdfbTBdKT5MfhWrqhqM+izZgI6Tn62O5nVdeugrjtGi/6FvRzxAkYnRF/Vio bdoQ== 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=REgCThCDWq7ccS+cRBe2pbrHo45LO9EQeYdXqBBKYdY=; b=c40+hySKwqKVpC6cUVotHz2e2YP1iWIh9tw/FlCD2Y5Yi9LnF3Jz9ySe2nBNcm+Rha 8oUSNHdwUPRDgR1zLp48sT633wVui37pBf/vRHdw276JkWMvNEAYa5A3X8W7Wswwbuqs TzvL8FzMVdDukH4VJbJYpX8CgNfqWVuXoVUahlbLLZG0DMm+LnmXNA+dpP6vvWAmfb/0 E6Lqe+yh2wYEoIASXg0GicirVmUd4iH7bnsOfRvLaOkrx1D7rlr9c7R7tf0qjV6nX3e2 froStxAPIcemefW7xBBXL06IoC1iwuAcojQ2OrmEqIM6ZEKM7o8i8dr3HSCEMBs9/oY5 IPHA== X-Gm-Message-State: APjAAAXW8bDRaYmxA7dIWKPXkPOPFgAqp10Ii6UeW2SU8+54NQV1CPW1 ppxjrwM7asPIPySVGXY9/xZYWwbONY0= X-Google-Smtp-Source: APXvYqwgWly6jv9EPzUcyfG3/0kqhwOdTKLCfiAZAEag43KB7xIqFF4Fda3ljNYYu+RpN3XWENvOTZ5c9yo= X-Received: by 2002:a65:60d9:: with SMTP id r25mr12674964pgv.29.1582576316410; Mon, 24 Feb 2020 12:31:56 -0800 (PST) Date: Mon, 24 Feb 2020 12:30:56 -0800 In-Reply-To: <20200224203057.162467-1-walken@google.com> Message-Id: <20200224203057.162467-24-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 23/24] do_mmap: use locked=false in vm_mmap_pgoff() and aio_setup_ring() 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: Change vm_mmap_pgoff() and aio_setup_ring() to call do_mmap() with locked=false. Moving the mmap_sem acquisition to within do_mmap() enables it to acquire a fine grained lock in the future. Signed-off-by: Michel Lespinasse --- fs/aio.c | 12 ++---------- mm/util.c | 8 +++----- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git fs/aio.c fs/aio.c index 018bd24d6204..0092855326eb 100644 --- fs/aio.c +++ fs/aio.c @@ -460,7 +460,6 @@ static const struct address_space_operations aio_ctx_aops = { static int aio_setup_ring(struct kioctx *ctx, unsigned int nr_events) { struct aio_ring *ring; - struct mm_struct *mm = current->mm; unsigned long size, unused; int nr_pages; int i; @@ -519,20 +518,13 @@ static int aio_setup_ring(struct kioctx *ctx, unsigned int nr_events) ctx->mmap_size = nr_pages * PAGE_SIZE; pr_debug("attempting mmap of %lu bytes\n", ctx->mmap_size); - if (mm_write_lock_killable(mm)) { - ctx->mmap_size = 0; - aio_free_ring(ctx); - return -EINTR; - } - ctx->mmap_base = do_mmap(ctx->aio_ring_file, 0, ctx->mmap_size, PROT_READ | PROT_WRITE, - MAP_SHARED, 0, 0, true, &unused, NULL); - mm_write_unlock(mm); + MAP_SHARED, 0, 0, false, &unused, NULL); if (IS_ERR((void *)ctx->mmap_base)) { ctx->mmap_size = 0; aio_free_ring(ctx); - return -ENOMEM; + return (ctx->mmap_base == -EINTR) ? -EINTR : -ENOMEM; } pr_debug("mmap address: 0x%08lx\n", ctx->mmap_base); diff --git mm/util.c mm/util.c index 337b006aef6d..916bc7ac9bf2 100644 --- mm/util.c +++ mm/util.c @@ -501,12 +501,10 @@ unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr, ret = security_mmap_file(file, prot, flag); if (!ret) { - if (mm_write_lock_killable(mm)) - return -EINTR; ret = do_mmap(file, addr, len, prot, flag, 0, pgoff, - true, &populate, &uf); - mm_write_unlock(mm); - userfaultfd_unmap_complete(mm, &uf); + false, &populate, &uf); + if (ret != -EINTR) + userfaultfd_unmap_complete(mm, &uf); if (populate) mm_populate(ret, populate); }