Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5883622rdb; Thu, 14 Dec 2023 02:20:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IEFlCBFzdVZQHduqR8bCWzlZgZcO+YYYZrSjnw9e9jIRU6u2s54v5QC2X7bQDEVyImgRHDI X-Received: by 2002:a17:902:ecce:b0:1d0:c849:780 with SMTP id a14-20020a170902ecce00b001d0c8490780mr5941492plh.70.1702549207706; Thu, 14 Dec 2023 02:20:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702549207; cv=none; d=google.com; s=arc-20160816; b=YwSqoocvWu5obic+wjNJasaJU3zjtqhoEsO0/ubk0U4g1NA1Vw0+8wKIX5DnAQc9dF IL93bNwnPjo/gZcHv3fq2dHoNRct2mf1c8grNY1Wz7yyv2UV0X5NlOgkmspKQTvoqmzQ 16LBc7XTi82Iq5/E7gxjYj06du5wpp4/oSovWKwvX0kEneSIFanOIg9fpiJ7r6PQe1Fp WgK0AP0zMaZ7gPatUAytyFxBLB3Afmu9HQP/x+znTif7w+PIEOjBA/NQzxtR+UMAw7Zo CGhIXtgQDugmkgJ/7D6nF6XKfYhzUD7X+ifaSadFi6BgOExwsS4QnCg4Xul1cpj2NNk0 K35Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=X2vDUFx7i5Dl2rPMDZU06vX/Imo4IhO/38H755HgPRo=; fh=if72FA2J+4nFryHMCVgJxAGR3e/xUADBLOvFTVrJeus=; b=ON7jIH2vDZ4SYY0i2AZf8EdO06rc0Q29uHtjLWCjdR2UN2OY0CORMTaK2iAhXmX+2y oulNOo62Hw27OYeEqsogYzxB8TBJbEzXlDvyWUYVLziV35TDK6cA3jgYFDRKG/NvhVUu IH13RlR9NjXC9KmIzZAA8ZjYCZ03ujHaWEqTyBJNgnuCRa/HUmddMBRBYJP/36qubAbK PBn7qjuCnMfNFyksCMTVbXV7yiGvJA2O4q27quHjkC76OaiM/rNl7NGp3pFeum8a8P+v IzLTAqU++1U6kaTzDstnV9CLVQpcro3gcA1IyX15MDRrhv+LnXNg5q2ySgwH74dBlOQe UyFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=oP+MrIZc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id jf17-20020a170903269100b001d377a99764si7494plb.582.2023.12.14.02.20.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 02:20:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=oP+MrIZc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 4BC2882B8A7D; Thu, 14 Dec 2023 02:20:05 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443583AbjLNKTu (ORCPT + 99 others); Thu, 14 Dec 2023 05:19:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1443555AbjLNKTt (ORCPT ); Thu, 14 Dec 2023 05:19:49 -0500 Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [IPv6:2a00:1098:ed:100::25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC788106; Thu, 14 Dec 2023 02:19:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1702549194; bh=pjC6AgncqA69AxQ0TJR0swcPyuKAW1TG7xIWc+P76j8=; h=From:To:Cc:Subject:Date:From; b=oP+MrIZcGjD6oX9TyNQE6+NQ/JFU1CVpxFDvx6nr7YJl7+DRT3PdKJiuepIyJDaUf MbM0byta1XsLrImto2gzclOwmEtBn/k9ODy4gMG5FaP8B/P0h4Peop4B18SkusUFWS 7BZuCmrkhFBwPo1acs4NWLmZbk/fMmlF6Phu8J3W/uxeQ9Wjnxd1UMPnMwZLBFB4/D XEA8yUvcuOU36g5zm3l8G8dCihrtnYUzHMhKA5JmDGsO+U/xX/0URnf7sx0xDLhVsm VPCZ73AYN37QJZdK2p9+LkAnbVz/lgw5b4VmRmsoO5momu+h13m5z0xcannUzrdoeG wLIYBrpwEPVzQ== Received: from localhost.localdomain (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: usama.anjum) by madrid.collaboradmins.com (Postfix) with ESMTPSA id E1EE7378000B; Thu, 14 Dec 2023 10:19:49 +0000 (UTC) From: Muhammad Usama Anjum To: Andrew Morton , Shuah Khan , Mike Rapoport , James Bottomley Cc: Muhammad Usama Anjum , kernel@collabora.com, "kernelci.org bot" , linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] selftests: secretmem: Floor the memory size to the multiple of page_size Date: Thu, 14 Dec 2023 15:19:30 +0500 Message-ID: <20231214101931.1155586-1-usama.anjum@collabora.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 14 Dec 2023 02:20:05 -0800 (PST) The "locked-in-memory size" limit per process can be non-multiple of page_size. The mmap() fails if we try to allocate locked-in-memory with same size as the allowed limit if it isn't multiple of the page_size because mmap() rounds off the memory size to be allocated to next multiple of page_size. Fix this by flooring the length to be allocated with mmap() to the previous multiple of the page_size. Fixes: 76fe17ef588a ("secretmem: test: add basic selftest for memfd_secret(2)") Reported-by: "kernelci.org bot" Signed-off-by: Muhammad Usama Anjum --- tools/testing/selftests/mm/memfd_secret.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/testing/selftests/mm/memfd_secret.c b/tools/testing/selftests/mm/memfd_secret.c index 957b9e18c729..9b298f6a04b3 100644 --- a/tools/testing/selftests/mm/memfd_secret.c +++ b/tools/testing/selftests/mm/memfd_secret.c @@ -62,6 +62,9 @@ static void test_mlock_limit(int fd) char *mem; len = mlock_limit_cur; + if (len % page_size != 0) + len = (len/page_size) * page_size; + mem = mmap(NULL, len, prot, mode, fd, 0); if (mem == MAP_FAILED) { fail("unable to mmap secret memory\n"); -- 2.42.0