From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E32EC77B7E for ; Sat, 27 May 2023 10:14:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EDBA66B0071; Sat, 27 May 2023 06:14:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E8C2F900003; Sat, 27 May 2023 06:14:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D7A8B900002; Sat, 27 May 2023 06:14:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C8DEE6B0071 for ; Sat, 27 May 2023 06:14:04 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 9661BA0226 for ; Sat, 27 May 2023 10:14:04 +0000 (UTC) X-FDA: 80835624408.26.BB58E02 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf13.hostedemail.com (Postfix) with ESMTP id 8A9D020002 for ; Sat, 27 May 2023 10:14:02 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=g4yrbCk4; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf13.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685182442; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=sYfYEtxRweEUrfz7BnN+YH4py14mH8rXqyvSp3hBE9s=; b=kzSqEK0CsCp9EGtAV0d+qc+pCdvZkWZRrV8nTOqU7z/x7gCm5AXW+9iW8HUi5mgCjnN8bZ uSBj9Uj0WVtF7GD6RGRWCqKuuPx5DwvYpQm2WX/0vaid9e1UC/5rHLcPd6dnZl06Pb1Ft1 rtIxSTOi4Wdt8ev+gyIfKQ5fimKxpYY= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=g4yrbCk4; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf13.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685182442; a=rsa-sha256; cv=none; b=uzLwDn7Wom0q0dxDh7dbCo8+YX6hZt+irgD86g86ZcU+rl0jPpVSyuMwzZHc+p5JGMQiVe A2Fv3qgzRIGN0h7h3Bz8kCXJti7mWgxxsg4NVWTd9X0mViGDU+b+Cggl76ZSlslhbJ/29b sazsHdgvs6WkUG/Gs4rPMfC0it7hA0Q= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685182441; 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=sYfYEtxRweEUrfz7BnN+YH4py14mH8rXqyvSp3hBE9s=; b=g4yrbCk4OXULC+pkicQsjQB7TCfVUePjyHPsHxs1wjYmqb5s6O4GjKNTpWTSamty0HLhy8 H+7zqFxtQrS6Ezct0HMPJyvMfuYDzvGx+2rZGMniSQg+y7zhWhTDu6CAAXfwoJHKyhH91x k2Bxw436zkitcjapfrP2bPGCvsi6riU= 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-258-f7bVrq7oMtOHMgkhrT6qhQ-1; Sat, 27 May 2023 06:13:58 -0400 X-MC-Unique: f7bVrq7oMtOHMgkhrT6qhQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EF6E985A5A8; Sat, 27 May 2023 10:13:57 +0000 (UTC) Received: from localhost (ovpn-12-70.pek2.redhat.com [10.72.12.70]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C5BE52166B2B; Sat, 27 May 2023 10:13:55 +0000 (UTC) Date: Sat, 27 May 2023 18:13:51 +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.6 X-Rspam-User: X-Stat-Signature: wsn664m9cszbu1i546ua4ifp65h1ddih X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 8A9D020002 X-HE-Tag: 1685182442-127582 X-HE-Meta: U2FsdGVkX19eatDWKYWeXSGLSB1twGaHqb+I8KS80gk55hZR+qfL8aiywaqnNpQDybfIfs9rM2rPZvtfJ4VqeZzkrenyedI2qQ5Pgs65EptC7I3/qWCBTsapfqxGDvnBYdA/FYiNdISYkd+Nu3l0nJcl497M0wZa7KCPkmyg21OKBuJBUf/Z7MoYSh1tFhUBL91i7qZp8HWWcE1dq8t67zsUmPb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=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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. > > 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); This is a great fix, ack. Reviewed-by: Baoquan He > if (!pages) > return -1; > > -- > 2.40.1 >