From patchwork Fri Oct 6 03:59:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rik van Riel X-Patchwork-Id: 13410941 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 3CAC6E92FCD for ; Fri, 6 Oct 2023 04:00:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 83DF9940012; Fri, 6 Oct 2023 00:00:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7ED0194000B; Fri, 6 Oct 2023 00:00:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6B4F9940012; Fri, 6 Oct 2023 00:00:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 5A58E94000B for ; Fri, 6 Oct 2023 00:00:38 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 28FECA0155 for ; Fri, 6 Oct 2023 04:00:38 +0000 (UTC) X-FDA: 81313684956.20.232EF30 Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by imf23.hostedemail.com (Postfix) with ESMTP id 7C3A4140007 for ; Fri, 6 Oct 2023 04:00:36 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=none; dmarc=none; spf=none (imf23.hostedemail.com: domain of riel@shelob.surriel.com has no SPF policy when checking 96.67.55.147) smtp.mailfrom=riel@shelob.surriel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696564836; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lMYt1hzc7neBOOFFKz2Z0tvjBs1Evq5ZqJufYut5E7A=; b=6hTcstH4Mt3gA8yykEpN25ga2Y+ljxaKORNz/Cbu4u6jS7KJBNuQdBJ39/bWoikg5SNvk0 WEbUwjvEIFI1tJp95Qq5qukG5gxV5jvJ+rr3EFCO2Z3F34/ces5AuXbihKPmncBFlGy4gi Ww3Jv9OPdIFobG8IQVJUEcQodRO6jT4= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; dmarc=none; spf=none (imf23.hostedemail.com: domain of riel@shelob.surriel.com has no SPF policy when checking 96.67.55.147) smtp.mailfrom=riel@shelob.surriel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696564836; a=rsa-sha256; cv=none; b=IzEJNagWcwk+f493fPVwPY33OwgMULL83W1L/n37DbiVkrebJ6PDc1oQmEuquGwTflZLds mokh7q5qGr4Fg8PYPIEqAUcD2l3svCUW/voUHETieLcDabv0afdWP9BwPYgeduE20vvOkf TIU78WcZ9xrYDqoQbVNENA7Wi67HL/Q= Received: from imladris.home.surriel.com ([10.0.13.28] helo=imladris.surriel.com) by shelob.surriel.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1qoc0k-0000mf-30; Fri, 06 Oct 2023 00:00:22 -0400 From: riel@surriel.com To: linux-kernel@vger.kernel.org Cc: kernel-team@meta.com, linux-mm@kvack.org, akpm@linux-foundation.org, muchun.song@linux.dev, mike.kravetz@oracle.com, leit@meta.com, willy@infradead.org, Rik van Riel , stable@kernel.org Subject: [PATCH 1/4] hugetlbfs: clear resv_map pointer if mmap fails Date: Thu, 5 Oct 2023 23:59:06 -0400 Message-ID: <20231006040020.3677377-2-riel@surriel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231006040020.3677377-1-riel@surriel.com> References: <20231006040020.3677377-1-riel@surriel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 7C3A4140007 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 5xfpdi66yn4iitp8ytdmbqs3ftmkqst5 X-HE-Tag: 1696564836-400510 X-HE-Meta: U2FsdGVkX1+EOtXBd+8AriZswVIdY/YMlNh02vBQosQIbpR8UYFYuMnhOzgCZfBeYlHrYxRU40HS43H76QFh87AskwmtLnDoWDE0CZLrvdXhTXz8yVDGrPqIxUzqUugvmu7BivHtAucmB4+LrBDdD6z5J58caZKmbvtAWiEjHi7nOGWGOyq5iQfaWJbA8ATllnMVuu+cDluXAj2SYvC2Jr5fIrjNXTj3ZD6kSyMdZcyaA8fHUo4m4Dx1OayMUy1szka623V3Fm/y1MTThpaA7iMa+7b1OEJhtrVq9kBwmNJPqgYnPJJjgYTSNqnJcPCMCAqeBt/0d386HKpO+6X5dz6Q+NCxy6IF4kPdNDpAAEtFQvw27DPuYmvTIL2pA2L0eyJgvjl1sjrreJCGyTx4VsYITaY2MkTjBGUJlKlAqgwtT6+qtdsxI0MPNqIQD08HF/zyTrZN137VCEAHbU6f+dIjKJcZJsK+iNiqB/MxTfhjoIq5BScKaRgBEj4boTuQeUcO0TBaRYIpTLSIsV99IXaEmvi5qILYtzuVO1XjanREe3n/uVItYDhDBJYmygOhbH/K2UvMhgszJASGgMZDYecHJmNa185uLoYZCMBnbSLCqPjiBSDPVgQx9EaWcAieLljKST96qA7gJhtNLIz6Thgs0n59iChaA5l3ti/KCJYv0Oe8E3fx1ov2TRO8BNGAi6mXDd4WNrlEEw9oAQHp6quo1mhw09PiIURgIFpq5b7zgdBZWvQddJ4gAYUVm+FhXErC8zeWczjbcAeFNNRjcKetBYjl5hXZ7Hbi2bWl3edU17cgcIBgfwdj6KrsYz53yI3RbfUrMcDwSlQwRLG4QUfNu3hsTh+92PesxbalRsgmNAeFirrkH75rPIepNsiMpM17dxTocPiyY6NasnR4OyNar1Hw+62a+d7L6ZATqOdtJlEsXbqoP0URpQuSe7q2I0HWW76zLwCeIsuZ8R1 v+VHP2YB df05kx5xHPtQ+C3QMU41QFISTIIKvnYAo0TZrJHPd0GhTZjbmU43KuEtVd9lt3c6L7w01wpQWlNxsy9Uudh2bv+UrE8vTwcYt9HeZXLq9EMrbUTugm36xssX53/DgMwCJWTfQAmt9lwWFJMr2m8HZ+2AsgWtQayGwRKEC03sSawRuiTfvkc9/nT1+x9wtgaP+I2nqr794vI4yY4niOoZiO4PMS3zuRzYeZL0u8rO6TgvqrOCLbn+nhRTj5JF5p4QITIONX8BPRLzOb6fx8M3TNKNIxhb/iGMfQyXn/MuIU+oXF3i0G/ICn69CZxJUMiR/G0dNIQs8bhMXgDt1lKi5hiJYytbFY4FZ+l141iPvQkeMWSFu+OvFEtOn/R6JKhN2+zb+2uHa+LInjqQQ+K3zL5J4+gaZo351Zcc6 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: Rik van Riel Hugetlbfs leaves a dangling pointer in the VMA if mmap fails. This has not been a problem so far, but other code in this patch series tries to follow that pointer. Signed-off-by: Mike Kravetz Signed-off-by: Rik van Riel Cc: stable@kernel.org Fixes: 04ada095dcfc ("hugetlb: don't delete vma_lock in hugetlb MADV_DONTNEED processing") --- mm/hugetlb.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index ba6d39b71cb1..a86e070d735b 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1138,8 +1138,7 @@ static void set_vma_resv_map(struct vm_area_struct *vma, struct resv_map *map) VM_BUG_ON_VMA(!is_vm_hugetlb_page(vma), vma); VM_BUG_ON_VMA(vma->vm_flags & VM_MAYSHARE, vma); - set_vma_private_data(vma, (get_vma_private_data(vma) & - HPAGE_RESV_MASK) | (unsigned long)map); + set_vma_private_data(vma, (unsigned long)map); } static void set_vma_resv_flags(struct vm_area_struct *vma, unsigned long flags) @@ -6806,8 +6805,10 @@ bool hugetlb_reserve_pages(struct inode *inode, */ if (chg >= 0 && add < 0) region_abort(resv_map, from, to, regions_needed); - if (vma && is_vma_resv_set(vma, HPAGE_RESV_OWNER)) + if (vma && is_vma_resv_set(vma, HPAGE_RESV_OWNER)) { kref_put(&resv_map->refs, resv_map_release); + set_vma_resv_map(vma, NULL); + } return false; }