Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1719682rwd; Thu, 25 May 2023 17:31:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5cgV6wJSlOLbcdEpE6mQTO+q8HuxkN2SxUIZBuJsQSawMRn+ebTm7KiLeh1Fw0DvAsHel2 X-Received: by 2002:a05:6a21:998f:b0:105:63b0:5bf8 with SMTP id ve15-20020a056a21998f00b0010563b05bf8mr39407pzb.18.1685061103928; Thu, 25 May 2023 17:31:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685061103; cv=none; d=google.com; s=arc-20160816; b=UDItqGpDxxID4NYZnoOyeBDQBCQKBi6JH57X9ZmG6vfhTSle6uAdLnj5aaZrxV67yX RZ9J6YWcxFQpvx1zvUrVX/VOwLWGw866XuZlHw8RUS1Roy6kJBNlmWZlEADjnDKtwURT Tk1JEfNsQ+HeEChgJ6bZ7RFQSqcUc1RrkMUOOK8cEwWpw0/tqba1uMFJRPoAspLmcFsx qS0iJkIPjEjmEc149jDGQwPnN4HFO5IPJBmcfJQGlmEMl4aWVItiIydSpqeWuE7prOi9 2KLj4ogL1AGBlzlJwIf+TSDk9B912GfyfQ5R+TSE0it9OapEp+ZeZ6fzQid9GsHn/ghH /GwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=FeebMAbW/EDnlt2w9SPLduRDA/kIrZ2NE56FX/nkNSU=; b=g+zMh19Sk9ernTlOdbtWaSMUgXg2a4+Pmd81PlXhdvDNbySUupMYyUF9feFXpQnCVb BGx70cFXohAd3oCJmeRZq+MkUSAp+IOMFbuhwZIbvKNs3nQzZohaUvPGy1jqKqHn3U0n v2FzvVJjzs7vlTKDPZe9u78Qrsp9Egode/57yf6KOoHLx14H5QiMQb/RO+SiGit4s5qG d9fs104Ui3v78AyxU9XCeI/UmmWvyGHVSt+BdN/6glY0v+u8Y+YC54vLI/EJz1XIFZvR SxfHbN5WCScDaJK4VLfmDoNS79ffR47DmSk6blUxJiJquGFjXUQ1W0zguPB0Ei79whg7 xdIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cPYBR3hW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m2-20020a637d42000000b00534784002c0si2235270pgn.424.2023.05.25.17.31.31; Thu, 25 May 2023 17:31:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cPYBR3hW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230126AbjEZAJ2 (ORCPT + 99 others); Thu, 25 May 2023 20:09:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229567AbjEZAJ0 (ORCPT ); Thu, 25 May 2023 20:09:26 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE9F59C for ; Thu, 25 May 2023 17:08:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685059721; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=FeebMAbW/EDnlt2w9SPLduRDA/kIrZ2NE56FX/nkNSU=; b=cPYBR3hW2YuYk01qxqNNozwflXqtzwLx/dKR9iJFrHrGxeiJLaMtwbsPs+xe2yXftkCz5a wlbjC3ZQ9zqiBvblWEz/vigodjKJvEA2+FR1MXGVrKjR2K+9UebpRCnZvD+HkkhFlOBIgQ HfmeAuhxki3KBGWglEMaNy9Flz4f2CI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-508-a6WU9cGBPTaDp5KwnjD3Hg-1; Thu, 25 May 2023 20:08:37 -0400 X-MC-Unique: a6WU9cGBPTaDp5KwnjD3Hg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 06401811E7C; Fri, 26 May 2023 00:08:37 +0000 (UTC) Received: from localhost (ovpn-12-35.pek2.redhat.com [10.72.12.35]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4B1821121314; Fri, 26 May 2023 00:08:35 +0000 (UTC) Date: Fri, 26 May 2023 08:08:33 +0800 From: Baoquan He To: Lorenzo Stoakes Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Christoph Hellwig , Uladzislau Rezki Subject: Re: [PATCH] lib/test_vmalloc.c: avoid garbage in page array Message-ID: References: <20230524082424.10022-1-lstoakes@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230524082424.10022-1-lstoakes@gmail.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/24/23 at 09:24am, Lorenzo Stoakes wrote: > It turns out that alloc_pages_bulk_array() does not treat the page_array > parameter as an output parameter, but rather reads the array and skips any > entries that have already been allocated. I read __alloc_pages_bulk() carefully, it does store the allocated page pointers into page_array[] and pass out, not just reads the array and skips entry alreay allocated. For the issue this patch is trying to fix, you mean __alloc_pages_bulk() doesn't initialize page_array intentionally if it doesn't successfully allocate desired number of pages. we may need add one sentence to notice user that page_array need be initialized explicitly. By the way, could you please tell in which line the test was referencing uninitialized data and causing the PFN to not be valid and trigger the WANR_ON? Please forgive my dumb head. > > This is somewhat unexpected and breaks this test, as we allocate the pages > array uninitialised on the assumption it will be overwritten. > > As a result, the test was referencing uninitialised data and causing the > PFN to not be valid and thus a WARN_ON() followed by a null pointer deref > and panic. > > In addition, this is an array of pointers not of struct page objects, so we > need only allocate an array with elements of pointer size. > > We solve both problems by simply using kcalloc() and referencing > sizeof(struct page *) rather than sizeof(struct page). > > Signed-off-by: Lorenzo Stoakes > --- > lib/test_vmalloc.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/lib/test_vmalloc.c b/lib/test_vmalloc.c > index 9dd9745d365f..3718d9886407 100644 > --- a/lib/test_vmalloc.c > +++ b/lib/test_vmalloc.c > @@ -369,7 +369,7 @@ vm_map_ram_test(void) > int i; > > map_nr_pages = nr_pages > 0 ? nr_pages:1; > - pages = kmalloc(map_nr_pages * sizeof(struct page), GFP_KERNEL); > + pages = kcalloc(map_nr_pages, sizeof(struct page *), GFP_KERNEL); > if (!pages) > return -1; > > -- > 2.40.1 >