From patchwork Mon May 22 05:07:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 13249773 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB2B9C7EE23 for ; Mon, 22 May 2023 05:07:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B81D090000E; Mon, 22 May 2023 01:07:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B316D900002; Mon, 22 May 2023 01:07:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A52A090000E; Mon, 22 May 2023 01:07:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 9502E900002 for ; Mon, 22 May 2023 01:07:42 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 6EA7F1A0726 for ; Mon, 22 May 2023 05:07:42 +0000 (UTC) X-FDA: 80816708364.03.793A5BC Received: from mail-yb1-f182.google.com (mail-yb1-f182.google.com [209.85.219.182]) by imf06.hostedemail.com (Postfix) with ESMTP id AC43C180005 for ; Mon, 22 May 2023 05:07:40 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b="X1s37wb/"; spf=pass (imf06.hostedemail.com: domain of hughd@google.com designates 209.85.219.182 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684732060; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Po1SIcw5OHs73xEeyHWdahQyrrpxMX/55AnymOheHdY=; b=YlVDMQolqrTUTUTWEkW+u3Ip4QAkbahbYGFVG34Z/vZLlayv+i7dq0qRzrf46xopv3TJ2E CZMfXaahLwIsp2K7OYSlQnEbWg5tIY+fE1EBhJU9Hszl3jQb6hK1qj25LUxEnI4K3gSvf8 c4ODYJ0B8DqbI/tZVVj2Nlqnyl9S524= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684732060; a=rsa-sha256; cv=none; b=H+g+gvnZlO9A7ZZXKAuvJ92Ii41sSwQTnALhxA5oFMSaNcZCFPlsnY5dxxSlv7v8/f78Tr BbBPNvbChUBuCpawpaGVyQpz0cBKTAonsQrCMG8Bzl9tE3ulYWm6OEVf+3/odFGmceIpO0 X/7KxhR5m/OaWU1B/CVB3bVqK1vddy4= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b="X1s37wb/"; spf=pass (imf06.hostedemail.com: domain of hughd@google.com designates 209.85.219.182 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yb1-f182.google.com with SMTP id 3f1490d57ef6-ba81ded8d3eso8293228276.3 for ; Sun, 21 May 2023 22:07:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684732060; x=1687324060; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=Po1SIcw5OHs73xEeyHWdahQyrrpxMX/55AnymOheHdY=; b=X1s37wb/ZRQK8wa5+7zJo8XqZvsoUBqIupbv2SaB+ZkVVeDTKpZ6QwcA2MkTOMLEB+ 04+Q8P7ixkmjr6uwabC/0/ae97Qd5WveKlzurD1MAgzXnZwGQUxZxpHSVC8+zTNRnrGz B25LFLPiXAeO2lmTa2nGOh3byiRj1pPd9axpciE/w6NeKi2mf190/nRmiWsGvrzrjmHJ BrIU26NxEn1SYQ6fIj/oe5nh1dTbf52uokYOvkdRrgGB7gx9TyZLzNcc0cxaPpUUftSN OOa+c2VRhh36Ov2ACw9ZnfHmqo02gnQWpWPgzuF/jjyarh/c5k63hfhpLNkRYyQl2O8o ZaQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684732060; x=1687324060; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Po1SIcw5OHs73xEeyHWdahQyrrpxMX/55AnymOheHdY=; b=R2n4SxLQXPtrvDBQXfq4wwrdhqyZaC7tDK8vs+vaWMj1GGnEMRO6PKAAITYOQSxzUQ K9qOWoDyTGvpqdzv29kJzzPyX1Pr0onZMIX1GxLvWdy9KfZbbfQE3cd7BJWC93scujgc TGpJoH6mHMW97yjW2uphgpog9GJ3gns1JzaMc6G/Ae4ug3EjuUm9+Hdbch//FnaY4s9p 8v1ic0N87n9g/wFLCnOhQefDeKuY0eaA+6Alk4cnaRyk1aNtYiLoGhzbKXcWH+7BAR2z qcTfKydgN4dD77RhZYgbu0QukaL0RTdZ/irePYQ7nRRn0HOunL0arLGChsTLVuJbKtlX W7Zg== X-Gm-Message-State: AC+VfDyTBuS7YypsHWYOQKSVo5Uh0RIAcg/6ygZp4p8giJ+Tk7j5uqOV +qJNZLwxNtgYeIQey6zV6p68/w== X-Google-Smtp-Source: ACHHUZ4m3WCKHCRUDIqxwtJbDgKim2PjP4Uj/Gl/wyaY7gpZzCtLpfaCmSlMhzQlWiwCXodOnzTDfw== X-Received: by 2002:a25:ada2:0:b0:ba8:fe6:8e3f with SMTP id z34-20020a25ada2000000b00ba80fe68e3fmr8924520ybi.5.1684732059390; Sun, 21 May 2023 22:07:39 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id r10-20020a0de80a000000b0054662f7b42dsm1801064ywe.63.2023.05.21.22.07.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 May 2023 22:07:39 -0700 (PDT) Date: Sun, 21 May 2023 22:07:35 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Andrew Morton cc: Mike Kravetz , Mike Rapoport , "Kirill A. Shutemov" , Matthew Wilcox , David Hildenbrand , Suren Baghdasaryan , Qi Zheng , Yang Shi , Mel Gorman , Peter Xu , Peter Zijlstra , Will Deacon , Yu Zhao , Alistair Popple , Ralph Campbell , Ira Weiny , Steven Price , SeongJae Park , Naoya Horiguchi , Christophe Leroy , Zack Rusin , Jason Gunthorpe , Axel Rasmussen , Anshuman Khandual , Pasha Tatashin , Miaohe Lin , Minchan Kim , Christoph Hellwig , Song Liu , Thomas Hellstrom , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 15/31] mm/userfaultfd: allow pte_offset_map_lock() to fail In-Reply-To: <68a97fbe-5c1e-7ac6-72c-7b9c6290b370@google.com> Message-ID: <49d92b15-3442-4e84-39bd-c77c316bf844@google.com> References: <68a97fbe-5c1e-7ac6-72c-7b9c6290b370@google.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: AC43C180005 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: t6z7q6t3mcccy9aaxd8oixkjw69okgma X-HE-Tag: 1684732060-671223 X-HE-Meta: U2FsdGVkX1+f1fuxdIXjFzhkvRGlbU9n4EUbdH7301GqRmou/ph20RwHP96odIyw7BqwqLZFdNngPohrrreq4n/dfFxExDAtJfMpCdLVg/q6Rw8s8ZxPaN/9Pk2lkB3LeMvE9gc71t+xTadJ269gzae3Qhf0peMmGoxGP03gpYYf8HapNOgrKO4OqyWpPfL08pfiRP/sTE5ELcyd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kOTObG7+Qk6GR9mRyEXqI4tRmVtQgRRQ/QctfIT/rPaVPy5sWEwJS0d5jr/l7epMqQy3d5t3g5HOLrdjaIlinmqnlLofJ9TP6QWmm0EQpUOBX751OFLpDQXfsYLJ8DAnziFUbvLb11hTioNYMRqmQ== 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: mfill_atomic_install_pte() and mfill_atomic_pte_zeropage() treat failed pte_offset_map_lock() as -EFAULT, with no attempt to retry. Signed-off-by: Hugh Dickins --- mm/userfaultfd.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index e97a0b4889fc..b1554286a31c 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -76,14 +76,16 @@ int mfill_atomic_install_pte(pmd_t *dst_pmd, if (flags & MFILL_ATOMIC_WP) _dst_pte = pte_mkuffd_wp(_dst_pte); + ret = -EFAULT; dst_pte = pte_offset_map_lock(dst_mm, dst_pmd, dst_addr, &ptl); + if (!dst_pte) + goto out; if (vma_is_shmem(dst_vma)) { /* serialize against truncate with the page table lock */ inode = dst_vma->vm_file->f_inode; offset = linear_page_index(dst_vma, dst_addr); max_off = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE); - ret = -EFAULT; if (unlikely(offset >= max_off)) goto out_unlock; } @@ -121,6 +123,7 @@ int mfill_atomic_install_pte(pmd_t *dst_pmd, ret = 0; out_unlock: pte_unmap_unlock(dst_pte, ptl); +out: return ret; } @@ -212,13 +215,15 @@ static int mfill_atomic_pte_zeropage(pmd_t *dst_pmd, _dst_pte = pte_mkspecial(pfn_pte(my_zero_pfn(dst_addr), dst_vma->vm_page_prot)); + ret = -EFAULT; dst_pte = pte_offset_map_lock(dst_vma->vm_mm, dst_pmd, dst_addr, &ptl); + if (!dst_pte) + goto out; if (dst_vma->vm_file) { /* the shmem MAP_PRIVATE case requires checking the i_size */ inode = dst_vma->vm_file->f_inode; offset = linear_page_index(dst_vma, dst_addr); max_off = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE); - ret = -EFAULT; if (unlikely(offset >= max_off)) goto out_unlock; } @@ -231,6 +236,7 @@ static int mfill_atomic_pte_zeropage(pmd_t *dst_pmd, ret = 0; out_unlock: pte_unmap_unlock(dst_pte, ptl); +out: return ret; }