Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6587184rdb; Fri, 15 Dec 2023 02:59:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IFn9GALphYbuEgMn4BTkDS60AnCpkbBHKVA9mtDmoFzF4RFjNW5zuVzU9jEgHAA/zWO9MmI X-Received: by 2002:a05:6808:128e:b0:3b9:dfae:9f87 with SMTP id a14-20020a056808128e00b003b9dfae9f87mr16332788oiw.10.1702637990060; Fri, 15 Dec 2023 02:59:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702637990; cv=none; d=google.com; s=arc-20160816; b=nqGjGO0Pk45EPLnhhe0htnJZsVDrf0f5Fv/gnvCDJKlRgvSOos81nqLG9e9p7ESG43 vNnvXcff50pa5Kpn49FYGtGvz4EYQkJHN5R/p4cafkZdBgUvHIDrmDh6gMuJ2hp1zo/M ySW8b5nX6sPxFDEYXJ6csUCrXvk/FrimRYOjjBWCRQlHXgjwWUeL4A84pyp+OXYSdnNR 9U3lmNqiySwH1CIPrIKu1feCw9ebrK9qDwIh/2NWSKYlnm9rctIEXqXDhywyzKxtlh/M nSjjwYCR1PXSTLNe+Axcxv2EcSvVRx0eEtGyy0DCvbnL2TVtMH+0Wzs2bTr9Z5s6dQya v4TQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=3fP304Wq/YPzSN9GthH0mbpuLLv3QBh4NFHF7pyIESo=; fh=4BLoB1LarVV+mmgp+8lAKFBBoKppE5GUdpfYZxjFRys=; b=Uw3IFCrDIhi/La+0ydHXBJWJLgwOlflgSCLL9yy2jxqETDFJaNq9mp3v/lcK1EzPwA t9f64MBPdAl2jGHvI+vyDtvRei/uiOG7NFrGoWIgHbizbyuIY+zd0k8ABem/W/uBIqd0 4WP76EsJIq7OV2ctAgPYIxXNAIV9Iy1SuBY56VvtdjtBqTyXaEFFBkD7GxmjkvV21Pxm nQeq8thTo53eYX1p6zLwsgaqMdOtLy85hc4jdVaqSoKzoRhN7CdTNviejSWdnnNydfrz Lc3jaG22tEIL1CGG0Qc2MPanELxuWdeG1UX6F3fyiYpAyHk2UFXJFNmEHk48Ox6pwOUg 2uxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ho64YXa4; spf=pass (google.com: domain of linux-kernel+bounces-791-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-791-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id n123-20020a632781000000b005b91192c628si13252707pgn.369.2023.12.15.02.59.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 02:59:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-791-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ho64YXa4; spf=pass (google.com: domain of linux-kernel+bounces-791-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-791-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id A530F28597B for ; Fri, 15 Dec 2023 10:59:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D59E11CAA4; Fri, 15 Dec 2023 10:59:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ho64YXa4" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 07B1524B42; Fri, 15 Dec 2023 10:59:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1D609C433C8; Fri, 15 Dec 2023 10:59:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702637983; bh=uVJe/DTjd8KQzGT75ENPY5rY557S9U+xVVo21+MUWRk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ho64YXa4J0j5IN/OXDI+PqoCnLRNHzJ37iR3IM91OtCvs+V+BzOBIVogw7EGmomo+ 0flnx6RBmP6oJzBqPgCf5Hfr42l9adpEkzjVeYKwd2CGqevKc6dYczirngVTRTieGf 9eymHer16CCD3BghBPVT/gkbQ9q4FIS/KHsWy7wx7d+gu8EpgZon7oipgD7uGUCGz+ c336oRnLff/rUQKMni9+7AEQk4qL4k7ZiTQhchtF7kuUrzUC2vkeBvNEwsRc8FeLGq JCQUqgQQPSbu4mz4yRzTMHfYlBmKSJMlMcMgmFtVhaNTIOTJNqa6pNXcdPmQ1IlqR7 ZmO9LYK30DKQg== Date: Fri, 15 Dec 2023 12:59:33 +0200 From: Mike Rapoport To: Muhammad Usama Anjum Cc: 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 Message-ID: <20231215105933.GO636165@kernel.org> References: <20231214101931.1155586-1-usama.anjum@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231214101931.1155586-1-usama.anjum@collabora.com> 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. 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 > -- Sincerely yours, Mike.