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 5BD59C77B7A for ; Fri, 26 May 2023 00:08:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 61BA3900003; Thu, 25 May 2023 20:08:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5A37E900002; Thu, 25 May 2023 20:08:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4446F900003; Thu, 25 May 2023 20:08:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 304E6900002 for ; Thu, 25 May 2023 20:08:46 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E84FDAE8E5 for ; Fri, 26 May 2023 00:08:45 +0000 (UTC) X-FDA: 80830470210.01.2B82116 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 C09D920008 for ; Fri, 26 May 2023 00:08:43 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=VfyokY3B; spf=pass (imf13.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685059724; a=rsa-sha256; cv=none; b=E67d4K2WUaIT3kC29O+72wL4YR0HAhSrNX7JR/vJCPnDapS4YgZABmxcUnD546WJNCeZD5 3kVEG/Vdwz3BXS5oDi6xezu6xAPhN/x4Elb//I8F42Ky4yYm0bWfDiiN9kNv1vtAR6i3rU YJlLfk8QCfYjX6Tw7bSNOl5JlN2A1qE= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=VfyokY3B; spf=pass (imf13.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685059724; 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=FeebMAbW/EDnlt2w9SPLduRDA/kIrZ2NE56FX/nkNSU=; b=G6X9UEHHKXigZojDR8AlZ75wByOHqX01Ul/7/7/spc9Ais4y6o+CmGiUiBEC+6LY9qw/nj Paw1U6ukb5DOh+tXWu2OBD9HmhG7yDB2H43R9p+O1a/kto1jOu5yDF25pKIM9nGQtLmuSK S496DezImrfOhFFHm5cmDYCojFpNwWY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685059723; 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=VfyokY3BDV2mVifj83A+mZ6M+1mETF8IcS0f4+EgWnipqOJNW9+TztVWk/ZhnXo6tpIbw+ GAMU97cG5v+dnxeZU5ANM69ZZCjf4guy6D3G0shDZpinY2umdtO1cDRcIvFm14gN8PgQUC 9eRLaFZw9Ckez4irGgaf0EXi+yXcMFM= 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-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: C09D920008 X-Stat-Signature: 3gux4df8ijqmstc3rx5m1g7pz9cs4puo X-Rspam-User: X-HE-Tag: 1685059723-592217 X-HE-Meta: U2FsdGVkX1/hWyIZJgvNGeH7hJKFXw0l+t5Ke54TLs8/hC+ERH3pBSBJgw9OWk0Eid9RLxtZf8Pzkh+q/V9szYT/G2e5DyzO5jy5qWszhjhpSHRn13IgjipTfl19MDI+3kxyWLg9cHbDFC0bs66kN4+EaSSKdTsjBJcy7y9rTVUvdLSQr3t1B0HxPVFsasVSs2fbNzsiexdQzH7/EmEtHoZtPhgP1S6woVkoccgDqU9PJdX4N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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. 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 >