Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp722527lqb; Wed, 29 May 2024 08:43:35 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUxk/uphhR4H9oETL/XFY5SpKrz3EHoucpT9foU/8TgMxAWcVF+4ae20e5JblF+6QX8xALn8avIf92VYEyBmllYatF0g5LR3cqQDloIxQ== X-Google-Smtp-Source: AGHT+IEOtfrRX3mZfM8vDK/4L6qBfZCYjXL9rHi4fL1DZVSixhvgE8lGoqbu8xvhgZRtSDD8DWxD X-Received: by 2002:a17:902:eb85:b0:1f4:698b:7a0b with SMTP id d9443c01a7336-1f4698b7cbdmr168707855ad.8.1716997415359; Wed, 29 May 2024 08:43:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716997415; cv=pass; d=google.com; s=arc-20160816; b=eJTX5dhsxGCxQl4BWAvH8AG2s8wBKXtzYg/UInS59eIxnktOj2HrGUXG5HAbrMOVg7 5K48NU4FtoYlR2ynGV6IZpChnNtcEduVrcYKXDn8EfNgyu/GhE8dMRvy78wfkac+cWlZ fo2qh6voyx6qHOQoqrzsRjkukICK53LsQmgImW1kKkDIeffbe5PpyZJIaJuJ7Oeim8fx tEw/BtEvw4XNLmN9s6i7GmhaSGOjJWcPzq/4s6YDSEsGk4HUYVysECFhTQ2zafPphPPj alQrcSQE5lSKXM/N/Q87ev21GYniGCLthsXbpRMUIy9uIp80qXvMNEeC87L+rtFQKK+K eaGg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=w5A6Owu5nCCfigxsQSQjSW3E/HUi1TirfJVySwzCRU4=; fh=aLOtgbiFzIGECLBa+0azK52IS/OXiOO5DfI/Gsw9z/I=; b=JBZGgq5LtJAzIKWaGKnwG8r53hUiNCKc/sJ1J271W+sdGL3mvVZOnT2SCIXQTCT1f/ Mg6mMjAGEJpAWrLujzTM/4HBWGcNQKMd6dertvhoxd567e6VwN4ixJROmbMc/pqqapVe JNN95de+ZCeYnMJ3NQVHJt7ol0nct7m1Q6NyHUJpgRA7isNRq1K3tBD8MYXDoGiXhxO4 A0CSPC3NN2FnDaEGdY0yCMUwmPiradozRlbZ5LsXqCmcRAFb/46Y5lAWhrZhkeWsoQrm T9pmy5y9i0MqN2Jehnxwfx989KSPx2QPr+VOF9GEGu2cPonGLrey3d0j+JXAUep5DFeW 9axA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-194379-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194379-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1f44c997453si101522905ad.349.2024.05.29.08.43.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 08:43:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-194379-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-194379-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194379-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id DC58328A19F for ; Wed, 29 May 2024 15:43:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 17326181CEB; Wed, 29 May 2024 15:43:13 +0000 (UTC) Received: from mail-lj1-f171.google.com (mail-lj1-f171.google.com [209.85.208.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CDC211B947 for ; Wed, 29 May 2024 15:43:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716997392; cv=none; b=C2jlP3yQnr0/a4SxBGm5meJ+Kz3otZY66ofrnxFibQYXZ03kphzx7ZhCnSWwEFtwdfcnVLv7ydMIoe+uggQJcRa65NaTvl1rvlmGRpMGerFilM/A2tzfOUiXiQAfDkYE5ys7loW8BJTQKqRK+rqOwssfvhsx5gWyPlBzxjFRJzw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716997392; c=relaxed/simple; bh=gJ64NPAH8gOQD4B7kGLZJDpKEjS1FPsyFxnDrdzTq2E=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=lInrIGu4klfqfdFzI03mLFvuvT89J9XtRF4CxjkabhZYGLHmKgIloQNFDx3SnKIbNgJrG8e2lSqqpw1ZR+BnCMKNyg+9IB3kP1ZQuWlujfKycCYvzuHok0FDKZSopbiXE7HkNzYiFIdUX1ExpgXMppK4A3JN9+5LTsPkjOvkZJQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-f171.google.com with SMTP id 38308e7fff4ca-2e9819a6327so26472971fa.1 for ; Wed, 29 May 2024 08:43:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716997389; x=1717602189; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=w5A6Owu5nCCfigxsQSQjSW3E/HUi1TirfJVySwzCRU4=; b=xDqbMeFqNHfvRD3pc9XCyNpKtX6VpZzrLlioMfmRxj91j3GTGbMI6ssD21qPkAkHU9 wJUht9BtDgrtdvr/WT4dg916lfCEcLtKvsij7RZT/Y+RKlKlwI7hKLfMivxBMLok6ndZ a2Ne1kUkoYcgS9b4FULu/90B9He4PhhodiMpR9db8FLhVwLAx/WWjho/90L5bcz3BTTd ipJUdq3h6JwrdXBt8dd1o+X5A10UM+F5xKUNg5a8q5D60ia9hggTm1FQtOY+G0BunGUS lXDIu9XcnDEfKQPzBlMT6ZKY/cEbNX7/htbweFUijwvhTHYwm3gKxSr7y35jyQwigGpF +Dug== X-Forwarded-Encrypted: i=1; AJvYcCXTvcJ0k0LBKfbLg7Jy9y4YWkHsOB3IlAJx+cWnvrgv+rib1V29hOHyGicKB/noyvvtBhNop4K/f8FX9D9VYdwpjAevAeUL9+CiiqOW X-Gm-Message-State: AOJu0YzYfGOtM7dRBZKerbZqFAaYxOA7CrXjrjjh8gJYMGH3qneokyzz FDhmRLREw5UWpNxFhNWCufg+DBeg9non7kfECHLuebrkZKk5BWZE X-Received: by 2002:a2e:2c12:0:b0:2ea:7e50:6c94 with SMTP id 38308e7fff4ca-2ea7e506d11mr11694151fa.16.1716997388651; Wed, 29 May 2024 08:43:08 -0700 (PDT) Received: from gmail.com (fwdproxy-lla-116.fbsv.net. [2a03:2880:30ff:74::face:b00c]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-579cf481a7fsm4776859a12.52.2024.05.29.08.43.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 08:43:08 -0700 (PDT) Date: Wed, 29 May 2024 08:43:06 -0700 From: Breno Leitao To: Oscar Salvador Cc: Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Muchun Song , syzbot+d3fe2dc5ffe9380b714b@syzkaller.appspotmail.com Subject: Re: [PATCH] mm/hugetlb: Do not call vma_add_reservation upon ENOMEM Message-ID: References: <20240528205323.20439-1-osalvador@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240528205323.20439-1-osalvador@suse.de> On Tue, May 28, 2024 at 10:53:23PM +0200, Oscar Salvador wrote: > sysbot reported a splat [1] on __unmap_hugepage_range(). > This is because vma_needs_reservation() can return -ENOMEM if > allocate_file_region_entries() fails to allocate the file_region struct for > the reservation. > Check for that and do not call vma_add_reservation() if that is the case, > otherwise region_abort() and region_del() will see that we do not have any > file_regions. > > If we detect that vma_needs_reservation() returned -ENOMEM, we clear the > hugetlb_restore_reserve flag as if this reservation was still consumed, > so free_huge_folio() will not increment the resv count. > > [1] https://lore.kernel.org/linux-mm/0000000000004096100617c58d54@google.com/T/#ma5983bc1ab18a54910da83416b3f89f3c7ee43aa > > Fixes: df7a6d1f6405 ("mm/hugetlb: restore the reservation if needed") > Reported-and-tested-by: syzbot+d3fe2dc5ffe9380b714b@syzkaller.appspotmail.com > Closes: https://lore.kernel.org/linux-mm/0000000000004096100617c58d54@google.com/ > Signed-off-by: Oscar Salvador > --- > mm/hugetlb.c | 16 ++++++++++++++-- > 1 file changed, 14 insertions(+), 2 deletions(-) > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index 6be78e7d4f6e..f35abff8be60 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -5768,8 +5768,20 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma, > * do_exit() will not see it, and will keep the reservation > * forever. > */ > - if (adjust_reservation && vma_needs_reservation(h, vma, address)) > - vma_add_reservation(h, vma, address); > + if (adjust_reservation) { > + int rc = vma_needs_reservation(h, vma, address); vma_needs_reservation returns a long. static long vma_needs_reservation(struct hstate *h, struct vm_area_struct *vma, unsigned long addr) Other than that, this is reviewed. Reviewed-by: Breno Leitao Thanks for fixing it.