From patchwork Sun Nov 29 00:45:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nadav Amit X-Patchwork-Id: 11938885 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F192C63777 for ; Sun, 29 Nov 2020 00:50:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3733720731 for ; Sun, 29 Nov 2020 00:50:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Uq3Na595" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3733720731 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 67FCF6B006E; Sat, 28 Nov 2020 19:50:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5E3DC6B0070; Sat, 28 Nov 2020 19:50:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3BE536B0071; Sat, 28 Nov 2020 19:50:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0039.hostedemail.com [216.40.44.39]) by kanga.kvack.org (Postfix) with ESMTP id 233AC6B006E for ; Sat, 28 Nov 2020 19:50:02 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id CAD0F181AEF3F for ; Sun, 29 Nov 2020 00:50:01 +0000 (UTC) X-FDA: 77535623802.07.taste30_2e13d8227395 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin07.hostedemail.com (Postfix) with ESMTP id A5AA2180260D3 for ; Sun, 29 Nov 2020 00:50:01 +0000 (UTC) X-HE-Tag: taste30_2e13d8227395 X-Filterd-Recvd-Size: 5223 Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by imf45.hostedemail.com (Postfix) with ESMTP for ; Sun, 29 Nov 2020 00:50:01 +0000 (UTC) Received: by mail-pf1-f195.google.com with SMTP id b63so7728583pfg.12 for ; Sat, 28 Nov 2020 16:50:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pLO/Dm5aFg8h/isH2BDIjhNLAvIImEOy4o6l0iht6RI=; b=Uq3Na5959zjHT7zlMKGk03UxrU8zJxP7eRY742Q33BmNMujMif/ZsQnVVaWeZE8I0B TUUMUVhsGOUUj1IGJAY+A/VqbT330oGghAQqZbr8EQMFzkYwpGBecRM4VkBfAKEVNY/D 50xUF4uQxyWN0SG+snoLEuPHMi/X9IEthoWmsLGlC4stOdIh+Z+natl07aqHeaDinAsE K5nkqAOIB+SPkEIpZgkC1B7573INdvewtxEmAsrPOEmqxtjD22S9S1X1VnL67PFle+ei CY8lCbvTZ223ZsuxSU/4XsGE3qjZZY30qHZ/yg9AscOe6JQQjzdjjhKOIgFBj2fR17cM gjEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pLO/Dm5aFg8h/isH2BDIjhNLAvIImEOy4o6l0iht6RI=; b=JLH5/GT6PZL/JBEz9/FodTDwaQg95L5jspPxDPLGc477iBmy/hyR6/OGlKx1uQMLOu MW0nk3dpseMvHrG+yVpW1+bkW9KoqwIO/o0IF5vUMG5T8ksrVuVOZghPCKgaI7RbobIE diec0rDo1Ox+jRlVkuNgZHRAgH5vvzT2PRAxNbPD0OQF71e9g7CrMxkfAbnRyf1azra5 we6okXIiJQWn4mXluanRd2vhGpvXjVSqts050vVwsC4BJWh/zBKl11L8TZqud7xMQiVX pbW0QGt09lMtVpmRKgLRMKf8/RNOuxbwXfg/nGEk37X1w/sWJzRlMmwf8ihKZbH4wV/a ZmNQ== X-Gm-Message-State: AOAM530uSoOcr5dQUXjetW0+lNEGMooM5u5sWCbRA3ij2f/AgMwUmrcO CoMiUzYS8AyTuVtaewqM+9k= X-Google-Smtp-Source: ABdhPJxaY9DxLDKGnkGFs9A9oqkbO/fjTGIBVHcLBTu9hXYx/XXtNjBNR1mCzr6//0a7w+5LsYbWMw== X-Received: by 2002:a63:eb4b:: with SMTP id b11mr12181060pgk.351.1606611000280; Sat, 28 Nov 2020 16:50:00 -0800 (PST) Received: from sc2-haas01-esx0118.eng.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id gg19sm16444871pjb.21.2020.11.28.16.49.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Nov 2020 16:49:59 -0800 (PST) From: Nadav Amit X-Google-Original-From: Nadav Amit To: linux-fsdevel@vger.kernel.org Cc: Nadav Amit , Jens Axboe , Andrea Arcangeli , Peter Xu , Alexander Viro , io-uring@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 04/13] fs/userfaultfd: simplify locks in userfaultfd_ctx_read Date: Sat, 28 Nov 2020 16:45:39 -0800 Message-Id: <20201129004548.1619714-5-namit@vmware.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201129004548.1619714-1-namit@vmware.com> References: <20201129004548.1619714-1-namit@vmware.com> MIME-Version: 1.0 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: From: Nadav Amit Small refactoring to reduce the number of locations in which locks are released in userfaultfd_ctx_read(), as this makes the understanding of the code and its changes harder. No functional change intended. Cc: Jens Axboe Cc: Andrea Arcangeli Cc: Peter Xu Cc: Alexander Viro Cc: io-uring@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org Signed-off-by: Nadav Amit --- fs/userfaultfd.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index 4fe07c1a44c6..fedf7c1615d5 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -1039,6 +1039,7 @@ static ssize_t userfaultfd_ctx_read(struct userfaultfd_ctx *ctx, int no_wait, set_current_state(TASK_INTERRUPTIBLE); spin_lock(&ctx->fault_pending_wqh.lock); uwq = find_userfault(ctx); + ret = -EAGAIN; if (uwq) { /* * Use a seqcount to repeat the lockless check @@ -1077,11 +1078,11 @@ static ssize_t userfaultfd_ctx_read(struct userfaultfd_ctx *ctx, int no_wait, /* careful to always initialize msg if ret == 0 */ *msg = uwq->msg; - spin_unlock(&ctx->fault_pending_wqh.lock); ret = 0; - break; } spin_unlock(&ctx->fault_pending_wqh.lock); + if (!ret) + break; spin_lock(&ctx->event_wqh.lock); uwq = find_userfault_evt(ctx); @@ -1099,17 +1100,14 @@ static ssize_t userfaultfd_ctx_read(struct userfaultfd_ctx *ctx, int no_wait, * reference on it. */ userfaultfd_ctx_get(fork_nctx); - spin_unlock(&ctx->event_wqh.lock); - ret = 0; - break; + } else { + userfaultfd_event_complete(ctx, uwq); } - - userfaultfd_event_complete(ctx, uwq); - spin_unlock(&ctx->event_wqh.lock); ret = 0; - break; } spin_unlock(&ctx->event_wqh.lock); + if (!ret) + break; if (signal_pending(current)) { ret = -ERESTARTSYS;