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: 149100 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp73573vqo; Thu, 5 Oct 2023 21:02:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHqwpNNflkcuB/CqBUT1o9kcUCIfj4YyJe7JlxJdNgBtzohFchrBOJlHRb8nDGFNzmj00Jk X-Received: by 2002:a05:6808:144d:b0:3ad:c5f3:36c6 with SMTP id x13-20020a056808144d00b003adc5f336c6mr8326546oiv.38.1696564924201; Thu, 05 Oct 2023 21:02:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696564924; cv=none; d=google.com; s=arc-20160816; b=ocnQmKmQFU1oRCOQXtxKqyd11H6LN/f0Vbmkey7S7vxs/r2vRcne6hVkhSnoEXZPSx grXjVuuGv/K9l5NWeZ/fG5+T5i4Ztrw8e/OSlUu4AAaRWumTh3101cxbW2HesXbPaDp+ SvpXB6TmPou0L8d61Wy0HJO+OlY0DFwZJukLcNOBA3QG6iKb+7Xa/59Rrm3G5glxihSh agT+meY8zrMko5tvFg6CVxdXYyg4jC/OphsI04Uu0w+yvOhy5XPVoZukSE8nH8JDUp9A 22cHaNpFj3KMB4yqMZ3LavlzoWnnX6HEQU6xiw1bxjmOpSZ2kcbb+VHLTvBTaa7K0h/1 58vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=lMYt1hzc7neBOOFFKz2Z0tvjBs1Evq5ZqJufYut5E7A=; fh=I/h4tovFNOTYy2rLfmT/pQITjXfovn9+/UZ+7fRaNYU=; b=fmiME3wFeGtnT5JL13PMXuN3MF7WL7P/ie3zTIhuGaYHWq4K9btM/NSh9QWzT2nHkV 9QfPbuGyuCotWgXBZoROTxIBGNdOY/+XXRmRaHJj0GHITy8qoBJ7QUDuKwQkivVVLT5J yyPQO4ycB380hSxkQLO8o8DUZVa2cccY1UqYwXg4JwMvE/wUwJql9klwjYF2TmVLFKG1 Njs2PJjDcbLkxUK4+aAHzuY7M2sE4RZeUVr68OT/J1izb81UhkH3Qv37EFXAtD9Eu8S1 AaAETdD9qNr/a8Z1OH6rnkUhFfE5fRnQoCalJn6mdUVFCk16N+4UNuPJULODDFLC+pHa KWcQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id a22-20020a637f16000000b0055fce913d52si2727060pgd.761.2023.10.05.21.02.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 21:02:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 68EC8805EAE9; Thu, 5 Oct 2023 21:00:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230005AbjJFEAo (ORCPT + 18 others); Fri, 6 Oct 2023 00:00:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229968AbjJFEAj (ORCPT ); Fri, 6 Oct 2023 00:00:39 -0400 Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2789CE7 for ; Thu, 5 Oct 2023 21:00:36 -0700 (PDT) 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 Sender: riel@surriel.com X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 05 Oct 2023 21:01:01 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778977261940555710 X-GMAIL-MSGID: 1778977261940555710 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; }