Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1213681ybl; Fri, 30 Aug 2019 13:51:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqxrsY/Ut8MnNsokyO0iKiD5vo3L6/ZRKzXrs99WVC1yC4agg7f9E6kU9KbGsdcIpKpdYtZ/ X-Received: by 2002:a63:2887:: with SMTP id o129mr14293931pgo.179.1567198281550; Fri, 30 Aug 2019 13:51:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567198281; cv=none; d=google.com; s=arc-20160816; b=J1PPXOW0/Gd8oYoa+lwXnWEZydDnpXe5sHiXNxJz+jJqtsDr2PA7mfrzSo5jmozrDt PoUozmMj/3f34F7uPDQI6Iv1VY1finnBCZWE+1ZTKCygJTfCNNwiq+bYyAzgmb+VJogQ 5Q20DZbm3XoifUWMeqs0HIXV5jzpdhccIHps7dUXJ4LD1Ydqk2dGmaGldnPXCefJ+IIY NpNwKWibt9ZxXo3n3An7C/UNqKHMTAlfW0/UfzuWjR4xExkhoIc21aOiBjAO4rCdjAPL hmJcA0oeNqMXnqkb1v62lkehmQoLiYDukvd0UxH56C3NL0tAsFBTJgh1o7+MX0pIP3H2 aZaw== 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:subject:cc:to:from:date :dkim-signature; bh=BiHyB17E6H9zeBFagKEYwB/+usB94SSAyCkjXVOTYuM=; b=dUS92SIAzjtq+hg/ZQ6pKkMRX8U6sff0GCoc8Q4kYCzhUU53f39/a3nT15rt+LCrM0 VVTH3O3lV0pnjDi4bh1mk+XMT1kCQANuPDJRCa3Omh0wmZSDqifrqGpjLAE7i0IGNHjA J9Aa4BoMGaAmfqYQAPB34OcnG3JkKauVKcAH+b3M2GLv155+nnuQnJ6Sh2YtPu6wHhc1 JnPonISmTJOwBaPQ8pUffgbrA7ZajTtYQIDokwS4hglND+eV7vNtbIuqfWf2Gerkb1EJ mFvUOHc/BjXEdo4rHoIJWkGOxDaqcl9F5Nc6bsIqJAOSH96h/TZ8l0iYmT9qkCFRAxOD Firw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2d7DVqD9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m19si4939040pls.146.2019.08.30.13.51.05; Fri, 30 Aug 2019 13:51:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2d7DVqD9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728117AbfH3UuJ (ORCPT + 99 others); Fri, 30 Aug 2019 16:50:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:56504 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727246AbfH3UuJ (ORCPT ); Fri, 30 Aug 2019 16:50:09 -0400 Received: from akpm3.svl.corp.google.com (unknown [104.133.8.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 258C123439; Fri, 30 Aug 2019 20:50:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567198208; bh=+F7ljiSg6p5FWNKeDI6T/1PPD+xSpDlAYKC1QB46hI0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=2d7DVqD9TskavURNZTbEB1iY1v0A5qusBehdR9V9DI2GTRw1T9+qOWAhs5lRRkDuN 8/s1Z64FbnjVvdSZO8S7ndWxbXSBfupq+SQ6/57SQ3/F0j/M8ygAy0TvGdy81uPh41 LrAPQ5tECRaUSOjvulcECL1rd1t31LTP5Fk6pAOg= Date: Fri, 30 Aug 2019 13:50:07 -0700 From: Andrew Morton To: Austin Kim Cc: urezki@gmail.com, guro@fb.com, rpenyaev@suse.de, mhocko@suse.com, rick.p.edgecombe@intel.com, rppt@linux.ibm.com, aryabinin@virtuozzo.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm/vmalloc: move 'area->pages' after if statement Message-Id: <20190830135007.8b5949bd57975d687ff0a3f8@linux-foundation.org> In-Reply-To: <20190830035716.GA190684@LGEARND20B15> References: <20190830035716.GA190684@LGEARND20B15> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 30 Aug 2019 12:57:16 +0900 Austin Kim wrote: > If !area->pages statement is true where memory allocation fails, > area is freed. > > In this case 'area->pages = pages' should not executed. > So move 'area->pages = pages' after if statement. > > ... > > --- a/mm/vmalloc.c > +++ b/mm/vmalloc.c > @@ -2416,13 +2416,15 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask, > } else { > pages = kmalloc_node(array_size, nested_gfp, node); > } > - area->pages = pages; > - if (!area->pages) { > + > + if (!pages) { > remove_vm_area(area->addr); > kfree(area); > return NULL; > } > > + area->pages = pages; > + > for (i = 0; i < area->nr_pages; i++) { > struct page *page; > Fair enough. But we can/should also do this? --- a/mm/vmalloc.c~mm-vmalloc-move-area-pages-after-if-statement-fix +++ a/mm/vmalloc.c @@ -2409,7 +2409,6 @@ static void *__vmalloc_area_node(struct nr_pages = get_vm_area_size(area) >> PAGE_SHIFT; array_size = (nr_pages * sizeof(struct page *)); - area->nr_pages = nr_pages; /* Please note that the recursion is strictly bounded. */ if (array_size > PAGE_SIZE) { pages = __vmalloc_node(array_size, 1, nested_gfp|highmem_mask, @@ -2425,6 +2424,7 @@ static void *__vmalloc_area_node(struct } area->pages = pages; + area->nr_pages = nr_pages; for (i = 0; i < area->nr_pages; i++) { struct page *page; _