From patchwork Fri Jun 9 01:26:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 13273079 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 18A75C7EE29 for ; Fri, 9 Jun 2023 01:26:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A7CCF8E0002; Thu, 8 Jun 2023 21:26:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A2C938E0001; Thu, 8 Jun 2023 21:26:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 91B868E0002; Thu, 8 Jun 2023 21:26:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 825B28E0001 for ; Thu, 8 Jun 2023 21:26:12 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 50FE4AEEF5 for ; Fri, 9 Jun 2023 01:26:12 +0000 (UTC) X-FDA: 80881468584.04.7C8A165 Received: from mail-yw1-f175.google.com (mail-yw1-f175.google.com [209.85.128.175]) by imf22.hostedemail.com (Postfix) with ESMTP id 719A8C0020 for ; Fri, 9 Jun 2023 01:26:09 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=d+dKJf7M; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf22.hostedemail.com: domain of hughd@google.com designates 209.85.128.175 as permitted sender) smtp.mailfrom=hughd@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1686273969; 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=PmbbTemShg7dGpCJymh8ioCm9PQPk/gLwHXF7mQ6jbw=; b=w2JdmcKs84VlIRZJVtNXsca/Qzu5C7mokF5/6XVTt/HlhPC/Z2Uw7qdB2tS1qLgISS2qbj cdmS4yma6ZVqT7tGYLip5lopPf7Vew4TXkwKg91a1LHMWaVj02NpwJehhe+uCgZ2WfpNYV Kwon7BpztR4nXatDgNTAHYhGhRY74bo= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=d+dKJf7M; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf22.hostedemail.com: domain of hughd@google.com designates 209.85.128.175 as permitted sender) smtp.mailfrom=hughd@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686273969; a=rsa-sha256; cv=none; b=JB0CLb5XhlO1238D9x7DZyuc4a79eycltai3SLnhDHhnZIe0GSwZSofW+bKAWgZyFi4AKM udWmD3/lfV1ROGi5ERHqYecw3dYlIgiVi+bHZTJ2VZ+jOvZgOzYmnkpNkucTslV9Nygrut vGyXZR58lww/H8nLrrtdw1X+YRiuybA= Received: by mail-yw1-f175.google.com with SMTP id 00721157ae682-565c7399afaso11712147b3.1 for ; Thu, 08 Jun 2023 18:26:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686273968; x=1688865968; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=PmbbTemShg7dGpCJymh8ioCm9PQPk/gLwHXF7mQ6jbw=; b=d+dKJf7MYgGkbogFV5iJ0in/u8QWUjYLBAFmQ7ygcUpoTtYR38tV8VjHHRx79+tqC1 xHAi8VEI8udjhn0i6NXjlbZGM0curW/G09YDGBDO7uNeymgEDUutuEhY67dcv9e1JC3c Kr/lYteRhi8EZZ4ON3qgr8IZYbs22sar5cHF6pJ+hkjtIcaYivcyvRaJDrPKAoQHoxL4 78cmtQoJihNLnrWGPJ0/wzQ+Ft29PFAH7mols+/0p1qq115e8foXt7EV0WK2TTvZzAlK WTFccNgXKTckPziGTMxd+vfG4KkV3xlgmbe2/Bx5rx+kPXmMSxor6N0wIGRCDIqsVdI4 znJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686273968; x=1688865968; 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=PmbbTemShg7dGpCJymh8ioCm9PQPk/gLwHXF7mQ6jbw=; b=FAadle8gnUUi9OoNjhZo/bq9KFIHYgBkODYGFzU+XI51yp5gkMcfwtgcFt3JkJ0pTD u/JIJe1yVW4RkdFwVYbfrI/0mzSlSvf5Y5nk9Xbnf/RTS7tynhkw4NvU5pxV4MQ9NMLc afHl/9BLT8FC/OnMwpLOGT7D7HWaLQGN95ZZAroJKP88dl1TWUEJUtovY3BANMmIS7P4 QmCRwYua25/zPT5MBB7p6BagxwhOKG751fKZz4iT6NkqpXq04Q4xDLcAHPYfLZJasBg7 +A+d5WnWLXnNL18bOhfWJViejgtQCriTXMRq1iHtAHVhMHRSF8Mx00WekULjsH6EdO7D qIMQ== X-Gm-Message-State: AC+VfDwymYsh1QGOsSMUKa2tppA1kHx/7ZSAayW4fj2PqykSd/O/odlj jMrPUDMvi6DcRKalUvyN2gEHSg== X-Google-Smtp-Source: ACHHUZ7XTCguPhOybQY+LH+ypWpoP0kYFfabibD6+mqWrxXo7bpsKAzEBYkvZOCdhGRiVh3fVLiw0Q== X-Received: by 2002:a81:5b89:0:b0:560:eadc:3bc9 with SMTP id p131-20020a815b89000000b00560eadc3bc9mr1402433ywb.7.1686273968353; Thu, 08 Jun 2023 18:26:08 -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 p82-20020a815b55000000b00561e7639ee8sm296391ywb.57.2023.06.08.18.26.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jun 2023 18:26:07 -0700 (PDT) Date: Thu, 8 Jun 2023 18:26:04 -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 , Lorenzo Stoakes , Huang Ying , Naoya Horiguchi , Christophe Leroy , Zack Rusin , Jason Gunthorpe , Axel Rasmussen , Anshuman Khandual , Pasha Tatashin , Miaohe Lin , Minchan Kim , Christoph Hellwig , Song Liu , Thomas Hellstrom , Ryan Roberts , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 15/32] mm/userfaultfd: allow pte_offset_map_lock() to fail In-Reply-To: Message-ID: <50cf3930-1bfa-4de9-a079-3da47b7ce17b@google.com> References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 719A8C0020 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 3go8i8gx1ybp63pds9bbgibcrjm9hra5 X-HE-Tag: 1686273969-291014 X-HE-Meta: U2FsdGVkX1/bozcB7+7JZ2k/2+vmWq7K2k/El3mAQOUj2hDj1nTnoQMZ+lXRm+0GaCXq8OBtWnZZQpryLKk3QkKbmr++jrh1ZlZEDpBYPuW8slm1pmxadXeRz5HKs+7+9CDm99mPydOfCElSrxB2murjFxwYQ6kVWAM33VCmNBPbDT9jNaPZVxTepFCn5pPczX7b+MnJoU+dwk1BlmsDcAO10gFNFW7yZhTcK7Xmh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gJWvtomJDyK6QrSGM5eFSlxwFJ5Sg+btmShyTqCl0aJF3rLSrBzyr8NMCyYU4tEkzAYVInibBSaNFSOGtUVXXnGpjfMvVgmgLNa6/+vCHg== 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 -EAGAIN, which mfill_atomic() already returns to user for a similar race. Signed-off-by: Hugh Dickins --- mm/userfaultfd.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index e97a0b4889fc..5fd787158c70 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -76,7 +76,10 @@ int mfill_atomic_install_pte(pmd_t *dst_pmd, if (flags & MFILL_ATOMIC_WP) _dst_pte = pte_mkuffd_wp(_dst_pte); + ret = -EAGAIN; 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 */ @@ -121,6 +124,7 @@ int mfill_atomic_install_pte(pmd_t *dst_pmd, ret = 0; out_unlock: pte_unmap_unlock(dst_pte, ptl); +out: return ret; } @@ -212,7 +216,10 @@ 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 = -EAGAIN; 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; @@ -231,6 +238,7 @@ static int mfill_atomic_pte_zeropage(pmd_t *dst_pmd, ret = 0; out_unlock: pte_unmap_unlock(dst_pte, ptl); +out: return ret; }