Message ID | 20210608175931.337829867@linuxfoundation.org |
---|---|
State | New |
Headers | show
Return-Path: <stable-owner@kernel.org> 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=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, 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 0B9B7C47082 for <stable@archiver.kernel.org>; Tue, 8 Jun 2021 18:33:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E722761406 for <stable@archiver.kernel.org>; Tue, 8 Jun 2021 18:33:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234809AbhFHSfG (ORCPT <rfc822;stable@archiver.kernel.org>); Tue, 8 Jun 2021 14:35:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:57600 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233360AbhFHSdg (ORCPT <rfc822;stable@vger.kernel.org>); Tue, 8 Jun 2021 14:33:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A7C1E613DD; Tue, 8 Jun 2021 18:31:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623177083; bh=AV02ipyOdh3kjpYE7YbxqgoBr8BU02OKe5XbkPla8F4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eFZkt/Q/z0o7DFKPBsbzI18ednjJ/7SHwZ7mjRP2mXhsXqFScEsOdxDQt/kXKY3EC OhukBYcY6oAL12s2+KBHW20ymAtZ0f/IcH7Ofc0v3cHE3GTZXdbBJGukJdVcmhkwQO Oxd/iXHWINSLpgHQvkL2NC0LQn0MOyBcqAez3HjI= From: Greg Kroah-Hartman <gregkh@linuxfoundation.org> To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>, stable@vger.kernel.org, Mina Almasry <almasrymina@google.com>, Mike Kravetz <mike.kravetz@oracle.com>, Axel Rasmussen <axelrasmussen@google.com>, Peter Xu <peterx@redhat.com>, Andrew Morton <akpm@linux-foundation.org>, Linus Torvalds <torvalds@linux-foundation.org>, Sasha Levin <sashal@kernel.org> Subject: [PATCH 4.14 26/47] mm, hugetlb: fix simple resv_huge_pages underflow on UFFDIO_COPY Date: Tue, 8 Jun 2021 20:27:09 +0200 Message-Id: <20210608175931.337829867@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175930.477274100@linuxfoundation.org> References: <20210608175930.477274100@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: <stable.vger.kernel.org> X-Mailing-List: stable@vger.kernel.org |
Series |
None
|
expand
|
diff --git a/mm/hugetlb.c b/mm/hugetlb.c index e59e0f7ed562..0dc181290d1f 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4099,10 +4099,20 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, struct page *page; if (!*pagep) { - ret = -ENOMEM; + /* If a page already exists, then it's UFFDIO_COPY for + * a non-missing case. Return -EEXIST. + */ + if (vm_shared && + hugetlbfs_pagecache_present(h, dst_vma, dst_addr)) { + ret = -EEXIST; + goto out; + } + page = alloc_huge_page(dst_vma, dst_addr, 0); - if (IS_ERR(page)) + if (IS_ERR(page)) { + ret = -ENOMEM; goto out; + } ret = copy_huge_page_from_user(page, (const void __user *) src_addr,