From mboxrd@z Thu Jan 1 00:00:00 1970 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=-3.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 6D82DC433E0 for ; Thu, 14 May 2020 00:50:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6021320659 for ; Thu, 14 May 2020 00:50:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="WvE4hENC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6021320659 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id AC3268003F; Wed, 13 May 2020 20:50:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A6F628003E; Wed, 13 May 2020 20:50:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9AC188003F; Wed, 13 May 2020 20:50:43 -0400 (EDT) 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 7E8EC8003E for ; Wed, 13 May 2020 20:50:43 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 40F79442A for ; Thu, 14 May 2020 00:50:43 +0000 (UTC) X-FDA: 76813494366.01.base24_40737a2acd401 X-HE-Tag: base24_40737a2acd401 X-Filterd-Recvd-Size: 3402 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Thu, 14 May 2020 00:50:42 +0000 (UTC) Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F1466206DA; Thu, 14 May 2020 00:50:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589417442; bh=zsXEwmzGtf4wXdqyCOOFqDksJ4KM0OvL+dxNZnlDBOI=; h=Date:From:To:Subject:In-Reply-To:From; b=WvE4hENC0eXkDiCNdH6VtUUtPiucQYJPmLhkg+LldYip/uIUqhFKsyznM7jAOLUHy /0PLuml2TbB3vT1bz++hxxciPH7UbCm9QPyDBHHL0Q5igm8iQ/jQPCa5jAeP2viqtp P/EUItPdl/RI3w437zSh0Jnmj5GKl0+byOi0adno= Date: Wed, 13 May 2020 17:50:41 -0700 From: Andrew Morton To: akpm@linux-foundation.org, alex.williamson@redhat.com, bgeffon@google.com, linux-mm@kvack.org, mm-commits@vger.kernel.org, peterx@redhat.com, torvalds@linux-foundation.org Subject: [patch 3/7] mm/gup: fix fixup_user_fault() on multiple retries Message-ID: <20200514005041.Biir9x7Bl%akpm@linux-foundation.org> In-Reply-To: <20200513175005.1f4839360c18c0238df292d1@linux-foundation.org> User-Agent: s-nail v14.8.16 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: Peter Xu Subject: mm/gup: fix fixup_user_fault() on multiple retries This part is overlooked when reworking the gup code on multiple retries. When we get the 2nd+ retry, we'll be with TRIED flag set. Current code will bail out on the 2nd retry because the !TRIED check will fail so the retry logic will be skipped. What's worse is that, it will also return zero which errornously hints the caller that the page is faulted in while it's not. The !TRIED flag check seems to not be needed even before the mutliple retries change because if we get a VM_FAULT_RETRY, it must be the 1st retry, and we should not have TRIED set for that. Fix it by removing the !TRIED check, at the meantime check against fatal signals properly before the page fault so we can still properly respond to the user killing the process during retries. Link: http://lkml.kernel.org/r/20200502003523.8204-1-peterx@redhat.com Fixes: 4426e945df58 ("mm/gup: allow VM_FAULT_RETRY for multiple times") Signed-off-by: Peter Xu Cc: Alex Williamson Cc: Brian Geffon Signed-off-by: Andrew Morton --- mm/gup.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) --- a/mm/gup.c~mm-gup-fix-fixup_user_fault-on-multiple-retries +++ a/mm/gup.c @@ -1218,6 +1218,10 @@ retry: if (!vma_permits_fault(vma, fault_flags)) return -EFAULT; + if ((fault_flags & FAULT_FLAG_KILLABLE) && + fatal_signal_pending(current)) + return -EINTR; + ret = handle_mm_fault(vma, address, fault_flags); major |= ret & VM_FAULT_MAJOR; if (ret & VM_FAULT_ERROR) { @@ -1230,11 +1234,9 @@ retry: if (ret & VM_FAULT_RETRY) { down_read(&mm->mmap_sem); - if (!(fault_flags & FAULT_FLAG_TRIED)) { - *unlocked = true; - fault_flags |= FAULT_FLAG_TRIED; - goto retry; - } + *unlocked = true; + fault_flags |= FAULT_FLAG_TRIED; + goto retry; } if (tsk) { _