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=-9.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,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 35FC6C47256 for ; Sat, 2 May 2020 00:35:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E143B208C3 for ; Sat, 2 May 2020 00:35:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="BhZG1zeG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E143B208C3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 654488E0005; Fri, 1 May 2020 20:35:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 603FA8E0001; Fri, 1 May 2020 20:35:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4A4C68E0005; Fri, 1 May 2020 20:35:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0128.hostedemail.com [216.40.44.128]) by kanga.kvack.org (Postfix) with ESMTP id 2ED258E0001 for ; Fri, 1 May 2020 20:35:30 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id D54012485 for ; Sat, 2 May 2020 00:35:29 +0000 (UTC) X-FDA: 76769910378.18.toys18_6a25875e97a2b X-HE-Tag: toys18_6a25875e97a2b X-Filterd-Recvd-Size: 5497 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Sat, 2 May 2020 00:35:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588379728; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=zNpajFhi1zb0cEYkerlgfRfZwrczwiF8kYJD1j4KXvw=; b=BhZG1zeGoe9lwaDICKnPKacLgC/iGqfvk5uDnYZrUdmoFDbzZGjI+oWPnbjkgd8YjXcEvo nG/r7KJ2oTfQWMDVG/i1lZ6/z2otHGnYzJ3yJn8X9JYubJmwUsHlDaBrjYAvWtc4vclF+a J3nxVso5yb4rz2b+UojqPymngMtZlm8= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-141-SqdG3NYJNwu3nC9qoyPY1w-1; Fri, 01 May 2020 20:35:27 -0400 X-MC-Unique: SqdG3NYJNwu3nC9qoyPY1w-1 Received: by mail-qk1-f200.google.com with SMTP id f11so11937504qkk.16 for ; Fri, 01 May 2020 17:35:27 -0700 (PDT) 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:mime-version :content-transfer-encoding; bh=Ujwsyw/O/+AeBjWrVJ65oHPAkvklfR2fQlh0BfXvrl8=; b=COCdaxwOwJPQaKG+NsyhtAwHutHSZNm1/Ked4Db5uZDLqMCIY7/0l0uh3ZRrkUZDN5 chUZZcESAKZ4KBFji2LCA3tXWVG7l7H+6hogRNsHrbg5bfN1TX90tKUxyfDnFHSrA7k4 TWjc3ZI36H8Zl8uPKsSzCfbHt/7FxfDfNGbbLOq9bI4/cniKoHLVb0BodCtEV+nanywu ujPzqzKzFvHl47kz1/U7U+QsYMrJGZPW5cQwQKEupqmK3m+l3ouxXjI9ONyv1x1/b9hu gvwyJen5Xpwk45K39XY9TxtoyDcsOHNcJMqfPS0qT8TzKHlzwMYt8T7KZQiRqszvS4Sq h4aw== X-Gm-Message-State: AGi0PuY+ifdsXGxK8zRZ+xN5rJcIgwYuiHRaQSxHnHn0/qPAqsEi/gp4 Ok6AjCV8VJjvJbi0ZrOp0+kTFtA45SXplHlaJtNoVY8pqZMPz8Uttl/q8R+nJkdiRvW+IewiEPI QhppysLwZPgA= X-Received: by 2002:a0c:e305:: with SMTP id s5mr6695555qvl.234.1588379726266; Fri, 01 May 2020 17:35:26 -0700 (PDT) X-Google-Smtp-Source: APiQypIKjxGjbQD1Flb1NGYaaAesLEVchYYS9XDerFgmnbjkuTL/GCEnpwLpmoav+xBLnP8sNFxrUw== X-Received: by 2002:a0c:e305:: with SMTP id s5mr6695538qvl.234.1588379725927; Fri, 01 May 2020 17:35:25 -0700 (PDT) Received: from xz-x1.hitronhub.home ([2607:9880:19c0:32::2]) by smtp.gmail.com with ESMTPSA id g123sm4044892qkd.95.2020.05.01.17.35.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 May 2020 17:35:24 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: peterx@redhat.com, Alex Williamson , Michal Hocko , Andrea Arcangeli , Andrew Morton Subject: [PATCH] mm/gup: Fix fixup_user_fault() on multiple retries Date: Fri, 1 May 2020 20:35:23 -0400 Message-Id: <20200502003523.8204-1-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable 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: This part is overlooked when reworking the gup code on multiple retries. W= hen we get the 2nd+ retry, we'll be with TRIED flag set. Current code will bai= l 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 errornous= ly 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 retri= es 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. CC: Alex Williamson Fixes: 4426e945df58 ("mm/gup: allow VM_FAULT_RETRY for multiple times") Signed-off-by: Peter Xu --- I don't have a case to trigger the problem, so I only smoke tested the patc= h. However I think this should be the right thing to do... Please have a look= , thanks. --- mm/gup.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 50681f0286de..87a6a59fe667 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1218,6 +1218,10 @@ int fixup_user_fault(struct task_struct *tsk, struct= mm_struct *mm, =09if (!vma_permits_fault(vma, fault_flags)) =09=09return -EFAULT; =20 +=09if ((fault_flags & FAULT_FLAG_KILLABLE) && +=09 fatal_signal_pending(current)) +=09=09return -EINTR; + =09ret =3D handle_mm_fault(vma, address, fault_flags); =09major |=3D ret & VM_FAULT_MAJOR; =09if (ret & VM_FAULT_ERROR) { @@ -1230,11 +1234,9 @@ int fixup_user_fault(struct task_struct *tsk, struct= mm_struct *mm, =20 =09if (ret & VM_FAULT_RETRY) { =09=09down_read(&mm->mmap_sem); -=09=09if (!(fault_flags & FAULT_FLAG_TRIED)) { -=09=09=09*unlocked =3D true; -=09=09=09fault_flags |=3D FAULT_FLAG_TRIED; -=09=09=09goto retry; -=09=09} +=09=09*unlocked =3D true; +=09=09fault_flags |=3D FAULT_FLAG_TRIED; +=09=09goto retry; =09} =20 =09if (tsk) { --=20 2.26.2