From patchwork Wed May 24 08:24:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13253452 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 E45F3C77B73 for ; Wed, 24 May 2023 08:24:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3CCA26B0074; Wed, 24 May 2023 04:24:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 37CCD900002; Wed, 24 May 2023 04:24:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 244706B0078; Wed, 24 May 2023 04:24:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 15FFF6B0074 for ; Wed, 24 May 2023 04:24:32 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id E0C10A08C5 for ; Wed, 24 May 2023 08:24:31 +0000 (UTC) X-FDA: 80824461942.23.DA42A59 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) by imf04.hostedemail.com (Postfix) with ESMTP id 07BAF40012 for ; Wed, 24 May 2023 08:24:29 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b="B5xRig/b"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf04.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.41 as permitted sender) smtp.mailfrom=lstoakes@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684916670; a=rsa-sha256; cv=none; b=qwSjWLYiXaZE26v1iYuJf2dBdTrz0OyAGfT/KEYOlCXxEVGhXfhW64LeCpaDnFzdUENb5Y XKuAbp4mUQtQUxswan1C25HAGVevk35PHKjWxafjDm14uzeTk+lU22zSj3EYerLrMl2Kij y8d/sMZwHRAYtgkNtb/T9WUR2WAoqwg= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b="B5xRig/b"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf04.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.41 as permitted sender) smtp.mailfrom=lstoakes@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684916670; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=7S8YiFtaRj/FEKOy7ugtwuuXH8gMTMGNxbGTnZXrWWI=; b=e/wOv25JWzDikfhmQV698/P8m4aRa2dHxlV8isaOY4Jj+w0cPePf0Kqz5El6qh7tU9yutz fc+s6vojJ9VXqgUZVE3errJ+ctuNmU/rhYzxId55HhgRpTABQoNPsyGbe4RS4E6cFkZoX3 OQL1IFqDn6+vtgCt8oCuMby4uF+X5sE= Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-3f611ccd08cso5320365e9.1 for ; Wed, 24 May 2023 01:24:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684916668; x=1687508668; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=7S8YiFtaRj/FEKOy7ugtwuuXH8gMTMGNxbGTnZXrWWI=; b=B5xRig/b/0O5ZspeIVwHcd2M9muwN88/QZRDW59sLhCQYsBHlIcilk7vC/3SmMOjRU mI1attXluGofNHO3o6zqrKvE3BmGB5S/5zYDmbiuXBaCaXImX0+to+5MTi4kqnVcc9QD 3aqeFqty+0UtS3XO637GAT+m3befp2T36c7i4PTWoxC+JIku2s1alA6g0csYQL1upeGT G9xOnmWDmyDhOTsPZ3JwulfFUvpfaWlNuJbAIoa8XZpcUxS1owE5hKXG5wPfWi6XO7jE 9DeVb2J43woXjJH4G8/ZCAcbl8x89gq4Iuvvka8TWcU6RAuIkdwOYhY8iEQTUFUj9KxJ 6v5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684916668; x=1687508668; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7S8YiFtaRj/FEKOy7ugtwuuXH8gMTMGNxbGTnZXrWWI=; b=gteZ5F7qf6CsoKZhuEpnRpL7LeWCvtwqUcLhNB8D8DIBY785JyDNHcmm1/6V3Q0jBi X4xfJgiis3zN0KNCSIiEwpb282vTRlAPfwOKQYc267rEtCY7KojpZ4rKzfkOFON1B6Ag ZWsVNH0JuBrOodoAjRHrI8Ya+EsARsCEbGLxN3a4d9rZM7xx3i9Wh8fgxrTnzC19/Gki MzctK5Nei2fFJO9qMU2T0hrE04mnQDgPRaqgZgFGPGRctUe6ZkdGqGwLLRnVBtIlb5bM QvOuT8tIvhRNgdupUI2P4dGc68A7K0TtKmZLDrUSk/OgVB36dSrwfclb+E+Gs+njxoot 4HYA== X-Gm-Message-State: AC+VfDwEYB9BtV1Ry79XupKZliV+pPwOxfaYGIyol3s021hZ1fJjncjD BtVztn5jpvY0x0Wiwiy899Fc8qMrahw= X-Google-Smtp-Source: ACHHUZ5ZmbHPHGD6ALC2KbVxj8uSXpU83tkbIWRAvSFK1QMXXPAx3969ZTiAxeTn9+lcd3dwirOrlw== X-Received: by 2002:a7b:c385:0:b0:3f6:8ba:6ea2 with SMTP id s5-20020a7bc385000000b003f608ba6ea2mr4775407wmj.15.1684916667799; Wed, 24 May 2023 01:24:27 -0700 (PDT) Received: from lucifer.home (host81-154-179-160.range81-154.btcentralplus.com. [81.154.179.160]) by smtp.googlemail.com with ESMTPSA id s4-20020a5d4244000000b00307bc4e39e5sm13467258wrr.117.2023.05.24.01.24.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 01:24:26 -0700 (PDT) From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: Baoquan He , Christoph Hellwig , Uladzislau Rezki , Lorenzo Stoakes Subject: [PATCH] lib/test_vmalloc.c: avoid garbage in page array Date: Wed, 24 May 2023 09:24:24 +0100 Message-Id: <20230524082424.10022-1-lstoakes@gmail.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 07BAF40012 X-Stat-Signature: qpsyjoptqazcenq6a4674tstttj46uxw X-HE-Tag: 1684916669-565524 X-HE-Meta: U2FsdGVkX193zIM/nSlT/Y5eRlFZ5ahz17cmf1iGsCJ6iwi4So8rfjxg0DEbv08LvKRVzgPLeRMnsUbIKbd9nmuEU2Ql0S8Dijh0AiNwtZK4A40E5Sua5Ruvav+vMtJJYM7v0k2tG299FcTZ6x3iQtBHeI5F258qZthv5k1ZhioqrYaT80vzB/0qzzRXz/FGPh2cDDQ3An/wSSiGJ7YOkEC+d63eC/UybhscMPQcUHdfgR1/RtPHEFzMnreXI8sYl5dUmf63aF3y2PgEEmqCLRvQ9C7f6UGCrWyPgsaMM2qppKsRoQzuUbXQA2ac7eZDzG/Lw4nmCEk7WdNuBeeeEoGfNH93YwvPwvR8HjrLt+JLCOnq75WX43rPdD98IwZ+unRW/Dh1nqAv1zEknN+mm8A6H4aU5cdLuSv5xduBSvdKKFr1Ohp3UxOKnD9e9nW4TnexroAwjbiufzApoO9mZLgFPd4M8agGHhfxnAyHmd6MhU7xSQmQPWh0gP5N119ofe2vt7SriyR4uohAJxUkes638POYeBscSbX/fbs8JIAB45w2AlaDqO1X0cBumEqeo0nqLS1m164iL70e91TWj0e5ehYdqudNiye9lCyCatCiWK/YL9kKMHTWAylLk98OVFW6wef2ujzZqLrZr9ln8/GPHERRdi0dr+7E6uRUxzWUpH/hi69AbgysFu8dwn8Hz1LmkfMb2CVa4LvKjgNI+17coJLDpPbkW938ph3b6ZJwjC7BRF+8lt7nBFBUc5t/tgcL7IcuAkUZ7HNJOrbwDYM0FjROjT31vkALshI8Vd1X1OEQRi42ZkNQJN08bnxRskNVBoQ1XL8oCutauUirItX1wuM+8m+mG7oD03sMJKT0/P0tW6XR//d4q/1Fx+6GQFFdCW+0mY+uPuuGNFZuAoJCiluQSnXRJvgfZdR1SB/06F0Oi2qWJE9LZwTluP5tWq4YZyt4+/k3OlijEtu FEFmFXEi rUwLMnIOGBgQTCnktjieSa3SETuxhaZwHj704gvBjqgqhmPVAaYjLe9NfJkMrzLRc8gQuJdGRJomaF5oamJscmVN9g19WHuap6F4KfPdc3SUNju/N806pwbcUkGritw1Fe15RcInfBX+jApm4H3tKbC7tMLyg/YKPT7JM0hWmeldZK+cRL3wMYokIZOQVBHDD9N5QK+LAb8VgmzcIHdxGtxtLojW18c39Hd5Xvg2EjFmbTSzQ8lHucriA5vnE1ctpJbLNtNrl0wAXhGimqjnMATTViQXTZZbzM0tyrrfS/JtZyd3ZXh3VqNJ+5jrreGuldh1bMw/So9nkhFcKY9biiHlbibK/PD62ImmP96PazA0db+CMgNqjPbQffizmjsAmoFsusrQ9FEU2hcKoFgOXMLtbYo7hRfomfNLSilaIB9O+/xziRZucn5DUrYQgoiLlAdQAvkttb/BodPP0Uf2RbmiU0gFCYKBc8u9+7ZyajDxhlfw= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Reviewed-by: Uladzislau Rezki (Sony) Reviewed-by: Baoquan He --- 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;