From patchwork Sat Oct 17 15:30:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 11842839 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 63E4C1752 for ; Sat, 17 Oct 2020 15:31:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id ACDAD20758 for ; Sat, 17 Oct 2020 15:31:05 +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="D87MhGKG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ACDAD20758 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 7A1FB940007; Sat, 17 Oct 2020 11:31:04 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 72D8C900002; Sat, 17 Oct 2020 11:31:04 -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 5F3ED940007; Sat, 17 Oct 2020 11:31:04 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0136.hostedemail.com [216.40.44.136]) by kanga.kvack.org (Postfix) with ESMTP id 2E61D900002 for ; Sat, 17 Oct 2020 11:31:04 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id C8B848249980 for ; Sat, 17 Oct 2020 15:31:03 +0000 (UTC) X-FDA: 77381805606.23.skate50_4d08e9527226 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id A4AF737604 for ; Sat, 17 Oct 2020 15:31:03 +0000 (UTC) X-Spam-Summary: 1,0,0,dd8a32819ae9482a,d41d8cd98f00b204,axboe@kernel.dk,,RULES_HIT:41:152:355:379:800:854:960:973:988:989:1260:1261:1277:1311:1313:1314:1345:1381:1431:1437:1515:1516:1518:1535:1542:1593:1594:1711:1730:1747:1777:1792:2194:2198:2199:2200:2393:2559:2562:3138:3139:3140:3141:3142:3354:3865:3866:3867:3868:3870:3871:3872:3874:4250:4605:5007:6119:6261:6653:7514:7652:7903:8634:10004:10400:11026:11232:11473:11658:11914:12043:12048:12295:12296:12297:12438:12517:12519:12555:12679:12760:12895:13221:13229:13869:14096:14097:14181:14394:14721:21080:21324:21444:21451:21627:21966:21990:30005:30054,0,RBL:209.85.216.66:@kernel.dk:.lbl8.mailshell.net-62.14.0.100 66.201.201.201;04yrga36mtgc3dssk9xjyfprg41groptcqwgn13ykuse5xroqfs8x5hn9uz7cxs.ej1gdbiufhf4ni4trnsu6ebriezx84w5wccy5m8aye41ieio4iq6ptbkd3qmrkb.1-lbl8.mailshell.net-223.238.255.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:31,LUA_SUMMARY: none X-HE-Tag: skate50_4d08e9527226 X-Filterd-Recvd-Size: 5405 Received: from mail-pj1-f66.google.com (mail-pj1-f66.google.com [209.85.216.66]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Sat, 17 Oct 2020 15:31:03 +0000 (UTC) Received: by mail-pj1-f66.google.com with SMTP id a17so2941620pju.1 for ; Sat, 17 Oct 2020 08:31:02 -0700 (PDT) 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=PBkqHavr+qAOrlyM/a1qDkUFOBA3jStimLVGMiCE5M0=; b=D87MhGKGS6MTHO42O23ScbDh0xSvAV70wM+sQxnZANrB+5/vihDF9k4+w/ArZdWG1U V3GaoNLlFW2YFx3fDrWeerjI/PS0lRlPatZJGe8GM2mwc3EDZk4+M8FxPcnxAGaE4Bn+ NtxD3oV0Ojp628OQ0tIqxpv5rBDWTm/gbW+cr2xsxd2h6rbzqdqLKdWU1aAG015KRk6k 3fAz7OHyphXOM4FzGVdsYew/noimpuGHoQOkbtECYOsCfYMjORpYXNVogTuI6GZXmJgy v++C7u5+zRDwmVKxgdL/audhUmEVNNW0QyyYMADroTpjPW7N5Wv6DxCfHvP+9afRBGQD ny6A== 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=PBkqHavr+qAOrlyM/a1qDkUFOBA3jStimLVGMiCE5M0=; b=Zpy6x6jyL6NMROXBVER3qymYBl3+6Ibst6ESOiH01yvRneMZE8FVMQEImjJfecAV0W 3C10gt6V47EUqgl84QxOBTZPLIDCGbG74aa6HuvqUhBUISRBMldKXEg3266Qz79vatRp cVa4k3RXZcHbiM4vfFFnXPSKpLDZpO8/R5tL2fLNIiXP1F/lqr75vv0uMWqNxNvUlkNY lH3JT8aT20cHuMb4UvzVU/rkFsvlyp5Uz/iGNBvtmVY9eZr7alNOQHqjgn2quE3yXLvx 9+lR736Lv3DwRiT4dsLKfUxkKXEDxHuSm7FDewkKYq3hjNQLtYsQ1qeDAy8RF6CaV1Dx 8IlA== X-Gm-Message-State: AOAM531i2K1LrUVbM2c1zps6cwD7cGXTVW0GdZp6kROP4h7KHoVRxBkK 2X3ae8Sr6Z1sCnmoGY1OVwpKkQ== X-Google-Smtp-Source: ABdhPJyA9W0Y0WP8uPU1net1u0JX4baYp1FcLq6aoYsFFV9idUfAwZylBMk46tUEL9oA0MWeaHjbRw== X-Received: by 2002:a17:90b:512:: with SMTP id r18mr9384300pjz.49.1602948661757; Sat, 17 Oct 2020 08:31:01 -0700 (PDT) Received: from [192.168.1.134] ([66.219.217.173]) by smtp.gmail.com with ESMTPSA id j6sm6100616pfi.129.2020.10.17.08.31.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 17 Oct 2020 08:31:01 -0700 (PDT) To: linux-mm , Andrew Morton , Johannes Weiner , Kent Overstreet From: Jens Axboe Subject: [PATCH] mm: mark async iocb read as NOWAIT once some data has been, copied Message-ID: <59eae433-9b30-f094-534d-eb5cf0a40a80@kernel.dk> Date: Sat, 17 Oct 2020 09:30:59 -0600 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.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Once we've copied some data for an iocb that is marked with IOCB_WAITQ, we should no longer attempt to async lock a new page. Instead make sure we return the copied amount, and let the caller retry, instead of returning -EIOCBQUEUED for a new page. This should only be possible with read-ahead disabled on the below device, and multiple threads racing on the same file. Haven't been able to reproduce on anything else. Cc: stable@vger.kernel.org # v5.9 Fixes: 1a0a7853b901 ("mm: support async buffered reads in generic_file_buffered_read()") Reported-by: Kent Overstreet Signed-off-by: Jens Axboe --- mm/filemap.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 1a6beaf69f49..029787fda56b 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2185,6 +2185,7 @@ ssize_t generic_file_buffered_read(struct kiocb *iocb, pgoff_t index; pgoff_t last_index; pgoff_t prev_index; + ssize_t this_written = 0; unsigned long offset; /* offset into pagecache page */ unsigned int prev_offset; int error = 0; @@ -2207,6 +2208,14 @@ ssize_t generic_file_buffered_read(struct kiocb *iocb, cond_resched(); find_page: + /* + * If we've already successfully copied some data, then we + * can no longer safely return -EIOCBQUEUED. Hence mark + * an async read NOWAIT at that point. + */ + if (this_written && (iocb->ki_flags & IOCB_WAITQ)) + iocb->ki_flags |= IOCB_NOWAIT; + if (fatal_signal_pending(current)) { error = -EINTR; goto out; @@ -2239,7 +2248,7 @@ ssize_t generic_file_buffered_read(struct kiocb *iocb, * serialisations and why it's safe. */ if (iocb->ki_flags & IOCB_WAITQ) { - if (written) { + if (this_written) { put_page(page); goto out; } @@ -2328,7 +2337,7 @@ ssize_t generic_file_buffered_read(struct kiocb *iocb, prev_offset = offset; put_page(page); - written += ret; + this_written += ret; if (!iov_iter_count(iter)) goto out; if (ret < nr) { @@ -2448,6 +2457,7 @@ ssize_t generic_file_buffered_read(struct kiocb *iocb, *ppos = ((loff_t)index << PAGE_SHIFT) + offset; file_accessed(filp); + written += this_written; return written ? written : error; } EXPORT_SYMBOL_GPL(generic_file_buffered_read);