Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6670950rdb; Fri, 15 Dec 2023 05:27:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IH+p7MvmyEpJ+Ed4H1wm8rNBfycXYNrnNLaXu5aFE+9L2gMHxRY35ykjlM3gjH3unsZtJ0K X-Received: by 2002:a05:6e02:3891:b0:35f:7df4:ceac with SMTP id cn17-20020a056e02389100b0035f7df4ceacmr3281546ilb.13.1702646858983; Fri, 15 Dec 2023 05:27:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702646858; cv=none; d=google.com; s=arc-20160816; b=fY/N52MIyWQ2J5tYa+EF1Pa/OFTCOy59T/NKnTMRDr/tfMhDH2imdnZhr3P9JFR5R0 LCZBSnWl0Qo2e0OscLHbWQfPOm7sm8Ox3xONksSqnCzeeEjM71U9Sm4hDa8a96yi5Pom JSPo+Txr1P0HF2Pd678zy67h05woYkRhpeczG29JvsiFnxZEeLGx3iDVPN52Lq8PC85H 6SSiv7/COiF7lDyBCYFb/xn8sM6KejCv2uAXJyQy+F70ve+BJRv2PA5QnnuITThchW1z LzKCtXRRIAPDq0Igj+btwG+5176nS0FIFvJgzPnRLlkT60eTjbYohmYq5XYucmOfCLsP fRlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:cc:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=F4aon9QkSBYTTFNwX2B9FJ2vFuiQBoGLMmaaz102rSc=; fh=ASHZUtBHRDoMuHDygpTG7mbTJYPG5MKpWbc8P8NnSgY=; b=xJ1fwL6Qo8dM4INc683L6aPCGZV9aU6vE3nA/EvxY71X4j6NSGjwRnvZejt7VijKnn 4Xpu1/pbXypYIiMQb0amoh1RBc8+ZnTAxQi4PI564E6n00nBKaKJPZM8dxj3dBRW2isp tDgwqoWtXBoq9pSKe8C/qSGf32NUL/2ojjm1OdaYVAWwgtaNW7RX6qiv07cd7H4V4kJ+ 6fbHqjc0ljpTE/wTg6d2ndxMOWr3iPqfQcHAlm6w6dsFC7o2ZhwiHQyKyTldd/kwiotF AV1LO/qPgbdrgWOzFWj3pd6WZ+E1RbNrS9lx1seXFbphpHxLiqRrnvkEnRmjOE7lCeSy Ae6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=uDr6Wazg; spf=pass (google.com: domain of linux-kernel+bounces-1009-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1009-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id y20-20020a63e254000000b005c1ce3c9617si12723156pgj.901.2023.12.15.05.27.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 05:27:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-1009-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=uDr6Wazg; spf=pass (google.com: domain of linux-kernel+bounces-1009-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1009-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 03748B23605 for ; Fri, 15 Dec 2023 13:26:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2ED572DB6D; Fri, 15 Dec 2023 13:26:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="uDr6Wazg" X-Original-To: linux-kernel@vger.kernel.org Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 102562C688; Fri, 15 Dec 2023 13:26:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1702646799; bh=WMPnWsUlFFgO2rziKdOQefwB/ccC+zfLPtfvmvBwKqY=; h=Date:Cc:Subject:To:References:From:In-Reply-To:From; b=uDr6WazgLau8fLePhmRCMl5xT4wm8MODt32jt91i1Pk5o2yrRk2Tcy7Cl+QQfBNXz uDt5UVsvgQ3txgNqRNXmARNokg5lIJpn0KXyWYKptMjFzHgSV+JmhsnFvCCnEyeWfK xMxX1FFQvI2vcINV69z5KoK5mO/8Y3skD62UY1TZrkhdEaeMsvJ+yli7IBg1+Ii6HU ce92YICdeOLZvBnbfmIaLOf6uF5mx9fc4EMTYJ0XS8a9GduCNwt14glp1xEKve9HUM utb7HLqBnT/HF4yqZyNrQJRVq7sEjVWQsCIXdUiUdOQZVOSB2NqTDubWMGkpYLKtnO +VE6OvLK8gp7A== Received: from [100.96.234.34] (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 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 A80CA3781FB2; Fri, 15 Dec 2023 13:26:34 +0000 (UTC) Message-ID: <71a3274c-a51a-4660-a7cf-679e779af6ad@collabora.com> Date: Fri, 15 Dec 2023 18:26:30 +0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: Muhammad Usama Anjum , Andrew Morton , Shuah Khan , James Bottomley , kernel@collabora.com, "kernelci.org bot" , linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] selftests: secretmem: Floor the memory size to the multiple of page_size To: Mike Rapoport References: <20231214101931.1155586-1-usama.anjum@collabora.com> <20231215105933.GO636165@kernel.org> Content-Language: en-US From: Muhammad Usama Anjum In-Reply-To: <20231215105933.GO636165@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 12/15/23 3:59 PM, Mike Rapoport wrote: > On Thu, Dec 14, 2023 at 03:19:30PM +0500, Muhammad Usama Anjum wrote: >> 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; >> + > > With mlock limit smaller than a page we get zero length here and mmap will > fail with -EINVAL because of it. This test has a initialization step in prepare() where it increases the limit to at least a page if it is less than a page. Hence we'll never get len = 0 here. > In this case I think we can just skip the first mmap and only check that > mmaping more than mlock limit fails. > >> mem = mmap(NULL, len, prot, mode, fd, 0); >> if (mem == MAP_FAILED) { >> fail("unable to mmap secret memory\n"); >> -- >> 2.42.0 >> > -- BR, Muhammad Usama Anjum