Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp4427128pxv; Tue, 29 Jun 2021 06:52:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwGZ6OApXwZ4dkibpsseN2viLJcbldOSSdCe0l0beCswUuf+eO1XANJ3EavLwyWSgoX7WzS X-Received: by 2002:a92:7d07:: with SMTP id y7mr22386701ilc.68.1624974743202; Tue, 29 Jun 2021 06:52:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624974743; cv=none; d=google.com; s=arc-20160816; b=gjBcP/3aVVQ9XFHmr7JWnyhlrpJyGk4pB/yXAmIfotI952Mq+mR4QWlAZXSaT3WjVs GkA7NNpvufNA17mJpPPeiuVtPpEPJdzY+HQ7z1/CtHH6wyS+ZtqPNmzNYqydeg8E6LG7 awi9d+/Hf1FR8QpzIWzGbo6veDkdmSpRHSeGUPr0iZ+MQ152roR4W49kPX2tH45CRRum 0Qoa+iYuRvcjXmOXBmFSAOIM8HjUDn07nD9kARqv93/+eTeIKYRgOT5jYeg5s61SYe2h tLEAlz0EvRlIQm7aY/LxEF/nb6TayBlftLXKus0OtwKpR+RklTvE+cK8zWmnvoUEwPnj XwMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:message-id:date:cc:to:from:subject; bh=uz1olcYG7J6PRsJUeUr9BpeFzJEtxgLuexSec6U1Q2E=; b=M5Oz2dMwHZwvSKTAL1EOWQVJvuQnwWxwbXqIZaHBA5w3OrkGNhAAHhe0LKl7ILp7ay 97Ze1N0VhQr4DLipcv0f2YX4G5DeKHtfhBpg35frpc88+36XOb2I2QmFvGgqTGeNmykH XBuCaSyYts/TAUtGiAjDkG2ftpJzlmHHyiJ4AiMc/ZjZnjOP3XllgRrLygtLs3EQcVVO K4ng9qaT797h21s75kPnsaf/702yepWLmHFqHn+0eaEUrB0ZCqjwjGYrp4R98/INVDv9 Xp3cX839IypxKcL/d1sJgdXRWAaJiuaS/PS8E06NpEG6l9wCTCaFJ3ZaVIUezs3K44dW +Ykg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l13si17884413jaj.24.2021.06.29.06.52.10; Tue, 29 Jun 2021 06:52:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233605AbhF2Nuo (ORCPT + 99 others); Tue, 29 Jun 2021 09:50:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:60368 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233050AbhF2Nun (ORCPT ); Tue, 29 Jun 2021 09:50:43 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E360761D8B; Tue, 29 Jun 2021 13:48:15 +0000 (UTC) Subject: [PATCH v3] mm/page_alloc: Further fix __alloc_pages_bulk() return value From: Chuck Lever To: mgorman@techsingularity.net Cc: linux-nfs@vger.kernel.org, linux-mm@kvack.org, brouer@redhat.com Date: Tue, 29 Jun 2021 09:48:15 -0400 Message-ID: <162497449506.16614.7781489905877008435.stgit@klimt.1015granger.net> User-Agent: StGit/1.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org The author of commit b3b64ebd3822 ("mm/page_alloc: do bulk array bounds check after checking populated elements") was possibly confused by the mixture of return values throughout the function. The API contract is clear that the function "Returns the number of pages on the list or array." It does not list zero as a unique return value with a special meaning. Therefore zero is a plausible return value only if @nr_pages is zero or less. Clean up the return logic to make it clear that the returned value is always the total number of pages in the array/list, not the number of pages that were allocated during this call. The only change in behavior with this patch is the value returned if prepare_alloc_pages() fails. To match the API contract, the number of pages currently in the array/list is returned in this case. The call site in __page_pool_alloc_pages_slow() also seems to be confused on this matter. It should be attended to by someone who is familiar with that code. Signed-off-by: Chuck Lever --- mm/page_alloc.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index e7af86e1a312..49eb2e134f9d 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5059,7 +5059,7 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid, int nr_populated = 0; if (unlikely(nr_pages <= 0)) - return 0; + goto out; /* * Skip populated array elements to determine if any pages need @@ -5070,7 +5070,7 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid, /* Already populated array? */ if (unlikely(page_array && nr_pages - nr_populated == 0)) - return nr_populated; + goto out; /* Use the single page allocator for one page. */ if (nr_pages - nr_populated == 1) @@ -5080,7 +5080,7 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid, gfp &= gfp_allowed_mask; alloc_gfp = gfp; if (!prepare_alloc_pages(gfp, 0, preferred_nid, nodemask, &ac, &alloc_gfp, &alloc_flags)) - return 0; + goto out; gfp = alloc_gfp; /* Find an allowed local zone that meets the low watermark. */ @@ -5153,6 +5153,7 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid, local_irq_restore(flags); +out: return nr_populated; failed_irq: @@ -5168,7 +5169,7 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid, nr_populated++; } - return nr_populated; + goto out; } EXPORT_SYMBOL_GPL(__alloc_pages_bulk);