From patchwork Mon Nov 16 20:39:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 11910787 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=-11.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 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 C20EDC2D0A3 for ; Mon, 16 Nov 2020 20:39:15 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EC4E720B80 for ; Mon, 16 Nov 2020 20:39:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20150623.gappssmtp.com header.i=@kernel-dk.20150623.gappssmtp.com header.b="aXMnuKqU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EC4E720B80 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 747956B0036; Mon, 16 Nov 2020 15:39:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6FA3A6B005C; Mon, 16 Nov 2020 15:39:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5C2116B005D; Mon, 16 Nov 2020 15:39:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0147.hostedemail.com [216.40.44.147]) by kanga.kvack.org (Postfix) with ESMTP id 2F7C96B0036 for ; Mon, 16 Nov 2020 15:39:14 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id CC9D18249980 for ; Mon, 16 Nov 2020 20:39:13 +0000 (UTC) X-FDA: 77491446186.08.crown82_250ce682732b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id B73361819E629 for ; Mon, 16 Nov 2020 20:39:13 +0000 (UTC) X-HE-Tag: crown82_250ce682732b X-Filterd-Recvd-Size: 4518 Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) by imf26.hostedemail.com (Postfix) with ESMTP for ; Mon, 16 Nov 2020 20:39:13 +0000 (UTC) Received: by mail-pl1-f194.google.com with SMTP id t18so8999990plo.0 for ; Mon, 16 Nov 2020 12:39:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=to:from:subject:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=o54PSEF2bsVyACt0vUuURhxMiMEZUQGdAmhiWd7OQws=; b=aXMnuKqUqcGEuH7huh+3Kx/SIfcQ15GOu8oJar3VwLL//u508skOnRXH0SBHMfn4GZ dTIcyCk3ByeFXPfMXIfmJVaehp+vZTL6hnb6PSV6jAz7ysQkck6c5n3W/VeuQz1xZQ9O ngFTBC7phhK6vS+JUynZrBZGRspam9V7aQXIpbp1iO4ymFWNFT8WMyRyyxrIw5BgS823 IAgOZmxt/TooQAqB/merEI+02OWWcYnXGNbEgf8Fhh9UuK6eOul9akAfzoYdVGfRS6qY bQQVfrsSG6y87l4bwC80AfBCxxq6b0dGEMQuLIXl2YNZDcJgAmgLbmqKPDCjxUc09Ifw 8pvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=o54PSEF2bsVyACt0vUuURhxMiMEZUQGdAmhiWd7OQws=; b=j5vjvja1tKLgL1lexoOAOq9iH/XaXRN+ZtAHItA0At6R6YKDFKRwVrPulxJCMax5f4 vC/REXWo2z00h9zgQLvC8bKHzgMYqinrP4mCXv5l5G/bC7k1Q4sjxg7+ZQySO9a7WhvQ b+pnDkDWk1mKnkDNZN3eORRZBO+2PkG335efxBD9KYxiaerRWtdZ/h6wGyOm2LVAo/oG KOgCsRvAKGKHsKfPDPwWKkrJsuPp5AKMI8EL3kizL+jEYvFnUHwtIjyapgcRep3wr5IC rLcC3ToWm+8WOkohPEHa+GPbXZf9tmhx2vvC0ezgavVxRYQTQWGlqRkGUDQrEIFP5uOJ LEdQ== X-Gm-Message-State: AOAM532lsp8iJeODMPLNVuYjqZK1KlLouvHhu8LBOiIoBpy19BwRNL3m dd5fMsmt8opqKMV026P0VHZvoA9cVLRwlQ== X-Google-Smtp-Source: ABdhPJwaO8JhK0xUrUzMom1iwoj6h5PBiRQQS7xN+Es8Y8R83V9/gXTqBiXKGNcqENt/BpEirzBgPQ== X-Received: by 2002:a17:902:d908:b029:d8:d387:3c2b with SMTP id c8-20020a170902d908b02900d8d3873c2bmr13633014plz.53.1605559151371; Mon, 16 Nov 2020 12:39:11 -0800 (PST) Received: from [192.168.1.134] ([66.219.217.173]) by smtp.gmail.com with ESMTPSA id 194sm18798992pfz.142.2020.11.16.12.39.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 16 Nov 2020 12:39:10 -0800 (PST) To: io-uring , linux-mm From: Jens Axboe Subject: [PATCH] mm: never attempt async page lock if we've transferred data already Message-ID: <313ab88b-33d5-5c19-11d3-b8bad7980685@kernel.dk> Date: Mon, 16 Nov 2020 13:39:07 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 Content-Language: en-US X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: We catch the case where we enter generic_file_buffered_read() with data already transferred, but we also need to be careful not to allow an async page lock if we're looping transferring data. If not, we could be returning -EIOCBQUEUED instead of the transferred amount, and it could result in double waitqueue additions as well. Cc: stable@vger.kernel.org # v5.9 Fixes: 1a0a7853b901 ("mm: support async buffered reads in generic_file_buffered_read()") Signed-off-by: Jens Axboe diff --git a/mm/filemap.c b/mm/filemap.c index d5e7c2029d16..3ebbe64a0106 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2347,10 +2347,15 @@ ssize_t generic_file_buffered_read(struct kiocb *iocb, page_not_up_to_date: /* Get exclusive access to the page ... */ - if (iocb->ki_flags & IOCB_WAITQ) + if (iocb->ki_flags & IOCB_WAITQ) { + if (written) { + put_page(page); + goto out; + } error = lock_page_async(page, iocb->ki_waitq); - else + } else { error = lock_page_killable(page); + } if (unlikely(error)) goto readpage_error; @@ -2393,10 +2398,15 @@ ssize_t generic_file_buffered_read(struct kiocb *iocb, } if (!PageUptodate(page)) { - if (iocb->ki_flags & IOCB_WAITQ) + if (iocb->ki_flags & IOCB_WAITQ) { + if (written) { + put_page(page); + goto out; + } error = lock_page_async(page, iocb->ki_waitq); - else + } else { error = lock_page_killable(page); + } if (unlikely(error)) goto readpage_error;