From patchwork Wed Apr 12 16:38:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209339 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 4EEBDC77B6F for ; Wed, 12 Apr 2023 16:41:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BDD98900006; Wed, 12 Apr 2023 12:41:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B17C1900005; Wed, 12 Apr 2023 12:41:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9B9E0900006; Wed, 12 Apr 2023 12:41:28 -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 86480900005 for ; Wed, 12 Apr 2023 12:41:28 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 5A93E1C4795 for ; Wed, 12 Apr 2023 16:41:28 +0000 (UTC) X-FDA: 80673304656.28.02F188A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf02.hostedemail.com (Postfix) with ESMTP id 219FA80006 for ; Wed, 12 Apr 2023 16:41:25 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=L1WtCURk; spf=pass (imf02.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@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=1681317686; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=09jtKKMdBkZ99/jQ3MHG3Gpu4kZKeE61xD5S9ADSCnE=; b=Hel6t+yBJOr+BO4whyQhzwzRP4UN4z+a415tTaeNA70zwXzsh97KAGoZaz8ANDNEwwr4X9 pNBqPdVCcIvjg1Udu1+ihC6I0iuHt/y2EPWoMRVhVqQTYYcdl5RT8Q4NpyVAqIN8JT6BgE m5yxtoceeLjQQEuxQ8QhIg4bGmPRwKY= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=L1WtCURk; spf=pass (imf02.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681317686; a=rsa-sha256; cv=none; b=VWDwJi5za/t//uizKwriJTf5k9uIbrdEzN37p+/KMIeuvXoPODavxOPYSIIhK1yxvkDSQa +tHxwYm9gI45Gbjy3EA2cHBRuzZb+K0n02NXOFmNzLbVNJLxV0LzxV//WHDiH6POGqILrU u0+NbT8K5jTG1Wt/dU6P0ZG8XOkwc/0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317685; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=09jtKKMdBkZ99/jQ3MHG3Gpu4kZKeE61xD5S9ADSCnE=; b=L1WtCURkVmmrnaVbrSh3rk+PeoTcvFQO3r9RR4E3kVnwaD58gkAoHTvzQ94WGNtcm25Q4C bhXhYlUFeZwoIQQ1CEU1B6DDjYUzLlKLFa3XaU2ZUaLyF3TW45SxROiyliKDy+ICmWK9iI iz+09Ti5Q6ltKHiGnlwUXy/smJyk4MI= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-342-2fG4ityJM2GIPJ2hvl6AIQ-1; Wed, 12 Apr 2023 12:39:31 -0400 X-MC-Unique: 2fG4ityJM2GIPJ2hvl6AIQ-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-74a25fcda05so77557285a.1 for ; Wed, 12 Apr 2023 09:39:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317565; x=1683909565; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=09jtKKMdBkZ99/jQ3MHG3Gpu4kZKeE61xD5S9ADSCnE=; b=iXeIvBXGsM6aPmocEWkgAnkccSF5HMkqx4t/OwW96uPUk7dCVgwKBwzgoNHEvW5TE/ kzgndShzn6pMEp1qIOVX+ojRrO/sRfpkrgXgjFiQvKBHLW588rhk7ad2yZKyQRxDgHUM bT3fib3ZzLUUYUBO5EPlPLQEZdHv8pW8duNc/vdQAd+TLwdf7+DxrHKaGv+PX61WmAR6 oBai3cs0hxPZWBhMzYmEc2kEAiz5n7xcp2OietXGgMhu6u4z8LCdpag5WHlg5vl38/th jUYoZyhwNRf6zaRfqcwfoeVKJ57HSEF130x1YrdA8sntPqqcjDyO4OhwVDhk6jkKS4TW ZYag== X-Gm-Message-State: AAQBX9f7kaki1U13hJuOIdrZcsYer5X/hIzFrI7/TtV1yVhteCMIcTQS DoDxFflXzFmvaKL37GsxVNqkwehZYE1CPPLbsrhPyXpTpqZ/FNTnoE6pZ66Jk/bfWjg5po8CcBJ vNVT1EwcDx0SYdDITmdwXupLg3b+Ah3KnyyLXCjrNYfq9AwkjNb2ldsuZ3dDu278GWorS X-Received: by 2002:a05:6214:401a:b0:5ea:a212:3fe1 with SMTP id kd26-20020a056214401a00b005eaa2123fe1mr4433909qvb.4.1681317565796; Wed, 12 Apr 2023 09:39:25 -0700 (PDT) X-Google-Smtp-Source: AKy350Yg5QWvOjiNFwdYfa/fZm9pN7qYxhapB7GAqOu9LrBAaJTeYn6HJOMM2S2srwUeyNYUeY/ZiA== X-Received: by 2002:a05:6214:401a:b0:5ea:a212:3fe1 with SMTP id kd26-20020a056214401a00b005eaa2123fe1mr4433881qvb.4.1681317565461; Wed, 12 Apr 2023 09:39:25 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id u13-20020a0cc48d000000b005ead602acfesm2669536qvi.35.2023.04.12.09.39.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:39:24 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Leonardo Bras Soares Passos , Andrea Arcangeli , Axel Rasmussen , Nadav Amit , Andrew Morton , Mike Rapoport , Mike Kravetz , David Hildenbrand , peterx@redhat.com, Dmitry Safonov <0x7f454c46@gmail.com>, linux-stable Subject: [PATCH v2 01/31] Revert "userfaultfd: don't fail on unrecognized features" Date: Wed, 12 Apr 2023 12:38:52 -0400 Message-Id: <20230412163922.327282-2-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 219FA80006 X-Stat-Signature: gje9mac5oqi7prhu9xknobsjbajgk7ih X-HE-Tag: 1681317685-919997 X-HE-Meta: U2FsdGVkX18RbcNT8XPrnIpQRwllGvLpKAuxpMWVMMFZnrh0WKdNXPoMgSiK+fjNR65S7N/hDOtjruxfA+DMyd4Dp7yapLbjmMEXLENR51Hvk2VpHodGqDBi58997ayuivyhxvpG0cvRrfqECgwUc157BfFbbSZT+7TrelnFKlhTsyv7QrBnP01BNVH1QWjOPvDjGDFC0j6ESz7m/XDQ8tyX+0WiAT8kVW8ouaNMKNHrMCYAvGBrzVrOF4c/9a4MKiyAVhH5zqNu3ExrqiTKv8ebFO8B//4qylD/Fto+Ie8YvfpXapkxWIRz13kCtDOxqdULCqKKe7bwY1KyKSAPii0PThTOGFgZJa9kDwh1tabEVNLh1W/PRzSU5I2ChaV2OCNCKRfqlkT64bVmIbOjcdAHF/A3mLfXhxEx/9+SRqLHtQE/Q193CmkXGriRL8zFiVjnB+40eNFnl0jUFJNkw5LH4spEDuEZb9qawBNPKAN4v0G6JyDRr4MngcI2m3UrUxX9gml/Y5FXpd8hjvA+C5mDZGowUyb8ByNH62rfUo3RtdqSgWCs0hK5xIwI1QOoYwg/FviV9REKhwb00dFgVymbNMRM3sFcjOygy+NLIb3OPC7WfjaFNAquLVdV5msphPKbNj50PCM47WjsJJOEqYgYFa4OfxZT30UtEHWLG4CeTD968E0AW/ZJC1S3EdXSj2G9ggO9lnCgUzf+KhBqGBw57SKTydV8ZM+KtNbDwB2x6nhhwrWH+yK9gnQ/+zAromHky4bunzXW5keBT3si1MFwLWoYWw9zDroHJPAkOUGKIEVZLDTS/hve9nPCAY7UD8Rwec3xh+Ii6lQvs68cO0bVje31Iz/PeoigAMA2Ck+f6FvRgx66Qca6SArCRL+l4Sy7FWq2K9Zk3fDrDUFtsZiRtIEveGhAOTcq7wXyKNypPbZRIX0DvLW6mi64vGV0jNWcV9mnyJBeGLM2QGz VT6nZnmC baQERl5o12I8zpwdUNF19q/xt8iQL4xNVzpmSC2XfpfkUmmgbDU4nWWX9P0Os6M0fK2Gf5FUje7MfVnhdT3p+xIwKBD/GxHXIu7EmUf3S6WtskJhQP0PRnXFWQJbDzJmWU77Y28nbVTZmsGyDSDJ0zgy94142atL/wUAYzI3lCWEW2+7VDCv2s08XCeoc80pJLcy0XK6dvos7uq7jNONbU2qx6cYT7PDrrXnSswb0YWGleXKW2te/oldmYajITu4wY6xDdq4TmQMLL0qJIxqt1PDy34fA1ozBkySdnUb6apm8Odgk9mLhvZTr4UFkSpZboMbnDlTYdHx1qsCJoZZ3EaZgFlGlwdoxi0eH/Cf6TZqij9ZYwTDRH6sAImetUmqOYlaHOxnJRnPkj606Y1758mlAjhaPgfmlYsPIiyXqh/vPWYHgvEaLPIrN+/jDtOdYseHfApoGSufa17vAXble3TNoYGHSCQB9iWGcD+WxtZkkXUFEgDI8h/HSZtSRPe4McmOzXSxWjz2kdohYGCZckiWoziL3V4fnhyCC8oMdWkhpOX1RYXAm8k10/DKfbbDQnxmfulnRPVTsZdMouGZnaW/YsmddGs7N3qAY X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This is a proposal to revert commit 914eedcb9ba0ff53c33808. I found this when writting a simple UFFDIO_API test to be the first unit test in this set. Two things breaks with the commit: - UFFDIO_API check was lost and missing. According to man page, the kernel should reject ioctl(UFFDIO_API) if uffdio_api.api != 0xaa. This check is needed if the api version will be extended in the future, or user app won't be able to identify which is a new kernel. - Feature flags checks were removed, which means UFFDIO_API with a feature that does not exist will also succeed. According to the man page, we should (and it makes sense) to reject ioctl(UFFDIO_API) if unknown features passed in. Link: https://lore.kernel.org/r/20220722201513.1624158-1-axelrasmussen@google.com Fixes: 914eedcb9ba0 ("userfaultfd: don't fail on unrecognized features") Cc: Axel Rasmussen Cc: Dmitry Safonov <0x7f454c46@gmail.com> Cc: Mike Rapoport Cc: linux-stable Acked-by: David Hildenbrand Signed-off-by: Peter Xu --- fs/userfaultfd.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index 8395605790f6..3b2a41c330e6 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -1977,8 +1977,10 @@ static int userfaultfd_api(struct userfaultfd_ctx *ctx, ret = -EFAULT; if (copy_from_user(&uffdio_api, buf, sizeof(uffdio_api))) goto out; - /* Ignore unsupported features (userspace built against newer kernel) */ - features = uffdio_api.features & UFFD_API_FEATURES; + features = uffdio_api.features; + ret = -EINVAL; + if (uffdio_api.api != UFFD_API || (features & ~UFFD_API_FEATURES)) + goto err_out; ret = -EPERM; if ((features & UFFD_FEATURE_EVENT_FORK) && !capable(CAP_SYS_PTRACE)) goto err_out; From patchwork Wed Apr 12 16:41:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209337 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 AA9AAC7619A for ; Wed, 12 Apr 2023 16:41:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 37706900004; Wed, 12 Apr 2023 12:41:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3289D900003; Wed, 12 Apr 2023 12:41:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1EED3900004; Wed, 12 Apr 2023 12:41:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 0FE82900003 for ; Wed, 12 Apr 2023 12:41:26 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id A5C85A01BF for ; Wed, 12 Apr 2023 16:41:25 +0000 (UTC) X-FDA: 80673304530.28.DAED688 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf01.hostedemail.com (Postfix) with ESMTP id 743E540013 for ; Wed, 12 Apr 2023 16:41:23 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SG8pj7bw; spf=pass (imf01.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@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=1681317683; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=w5yugiaVpJpS0wWKD2pcIMAyJ75fmPDFVn927vHr9+E=; b=i4LpTA5+4tYMuRYxrRMmnPVg0GzMVU3oiMMYD1+lcEvphk5qxUDBFAytflsfNZ0/r1MhHG 3kzsovGFjRnRyBpj9YkwqmKxczgzKmaJv1DOfVzWnz0VyxB0ZVpo496BuIEe9sFMTD62AE bDxBg3St2u5K+78Zne6woFym6N9EoeM= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SG8pj7bw; spf=pass (imf01.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681317683; a=rsa-sha256; cv=none; b=kAUCu9RL/PVR1BlrpFL4XKf62ZPOXobTUEBEK9v9wW9yo9aSBfICqZ+k8LVycM45voxE6h gQtGaWMrQsA9FuLkM5Q0m4C/DsN2sdQiexwgdgQ51O4h6ErvRGFovi/Seho266dyX0xSP4 eho8MYV+VNyEdYlcBXxtwMeA9XNPWno= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317682; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w5yugiaVpJpS0wWKD2pcIMAyJ75fmPDFVn927vHr9+E=; b=SG8pj7bwVwmnRqQ7nY85/hpIw7i7bmJxK+D4hpBCrB3CPBo5Uh7qIsp60+WdwkWWjvI8on DkOzVv1tAspD8rJGpALxwr6pG+hvA4FZgPyCIiYIde0ecC0w6JCG9HevHK1hewBy6VIn8n +ywyukubGJVhKtpfLl3KUf9/TQdR3ew= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-675-r_wQWWGcMTWNZ7DO8cIpvw-1; Wed, 12 Apr 2023 12:41:18 -0400 X-MC-Unique: r_wQWWGcMTWNZ7DO8cIpvw-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-74a90355636so62093085a.0 for ; Wed, 12 Apr 2023 09:41:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317677; x=1683909677; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=w5yugiaVpJpS0wWKD2pcIMAyJ75fmPDFVn927vHr9+E=; b=Wxr/8rskOwx1nWambguFjYuSwBRBK5oU1MHQNnr78qwZzqcHWkoMgjk6qewqe2Si9U 64s/mrA+JXKIksyIi+EoNQ8I/dAe9N/2IlDkBwFz14NTtHs/WnYEi7haxhfb7AQleEEC pZnnENru2ohBcxNgoV3I+vVvK9ZbQjn337z1SuidH+E/Mjyk5yB/9qTxX318dHTHhHi4 hqALvmQHkzAGgJifvkvohwbmsPll4UsAQ5zJYW3W/sqvzQtCwKzgPnzaba6yzZLvi87j NowLRgDr1UDT/7uKPMSB6Hylb/qbPxqjv0Q85d9LxEgS8I44ALtZ2YxXJLh/lbogHXAe ZgeQ== X-Gm-Message-State: AAQBX9ftAkeBix4y+Jp9P3j1GObJFl81zScv0w4AVftgL3EKaul11VSz ID+RKl00DBX4WGojD7I3vwTuDNe1LvEfmJ6WnMLMGUchHvi4F0Nc5gMjbElIB4fyUFM7ZXeatME lS3/z/tYB/Re2igLectY= X-Received: by 2002:a05:622a:1a90:b0:3e6:3af1:de7a with SMTP id s16-20020a05622a1a9000b003e63af1de7amr29098338qtc.4.1681317677517; Wed, 12 Apr 2023 09:41:17 -0700 (PDT) X-Google-Smtp-Source: AKy350bD6Pmxf/AxQhIwMuyaltxKV9vhvPtNoQ3AUSJK9HVNe+thswQyIiI14+qGQAnxvBEVwKx7FA== X-Received: by 2002:a05:622a:1a90:b0:3e6:3af1:de7a with SMTP id s16-20020a05622a1a9000b003e63af1de7amr29098310qtc.4.1681317677196; Wed, 12 Apr 2023 09:41:17 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id p9-20020a05620a22e900b007486d9fa1d7sm4785768qki.95.2023.04.12.09.41.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:41:16 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Axel Rasmussen , David Hildenbrand , Andrea Arcangeli , Mike Rapoport , Nadav Amit , peterx@redhat.com, Mike Kravetz , Andrew Morton , Leonardo Bras Soares Passos , Mike Rapoport Subject: [PATCH v2 02/31] selftests/mm: Update .gitignore with two missing tests Date: Wed, 12 Apr 2023 12:41:14 -0400 Message-Id: <20230412164114.327709-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 743E540013 X-Rspam-User: X-Stat-Signature: mueochfp1hmmdx9hj5b9izbuwzabuxia X-HE-Tag: 1681317683-483122 X-HE-Meta: U2FsdGVkX1+HJMFLtSNqKU0DFzmtSfNZrFf31nUuH+3QRNc3UaxOQgA+OWuZUcySlxkulPUTFMzEyuzlroFD75wJvN4y10aldZtwG9VdNGLUKzzXtGnsRzBFP83zxrr5R7r4uLIZ+JDuoyvXL+mNfAgr73vX7B+dWlN/dpiXCZdIymtc9wEOYSXz7xLWwPXtXWEdrgunfcK/9kVeae2fwz5iF0ekXOzPjV57UEoHLOkSW0umDGW81rwzFYoFHxMnTg8qoz3g4QmkFSRHwkc1ndz5jxv7b2o1JSeoGcOBvnMbUj/rOBbJoNuXuuK49H4Vxi8TkFriMpjvUhwQ/ZQ/9MUfBwEaPrMWJ5n0sBXyn7VsSCT8h6vwwJcmgl/DCsfqLfXjnzccNrMD+TyhiCw6fhnczW1xdbRwlgASZMWdDcIJWL0jauvqnHJg2SgXOVuK2BpZKzQrFgZReJZC347thlxNm3hEuSbq0N8WAnVeSuR79UM70fNKaBiEepGFlYumyXbIryYjzpTHesxYQM2FQR48JjcbdQFf7OhELEN/jAUOCnhtWd9/7ixMz5fJh8AAuGWM3HQppaCcHf71CnUTJhYsuUMtcsTBArtGetJ+iurIpH7eX2U3cu3oC5r22VA8wbsXlKvLVUat1INZ09hMwUiBlhW8dttD6UHDqhIzP1ddDZdYcHxlLeyCSb8Zd9Sg8vRyVEFcAAyvzdSGygql9Wk8yRLocPmOh1b6fEncV39aurlqEyD/hESMfTrH4cY62pBZz9spMaNJ7nRK1Zmjhx2oLmpn8xlmU1lf3A4XudEJqthbSZu3EAoRmHQza+EC9H5Jd+7Tcj9Jc53sOC5uhuttX4l9C3QAiGTb2DyCBzoN/t0txNeMVc79PMYddsfWSfIufUZJlXAYc8GP27Q5dXaxQpijtMWV/iwcyzQha02VFTsHtv+fUcECV8ucd2wdALUFn/hOGot90QCVvzT kYyyHR+e 7Q80Dua16dllNwYHIiLERDuvl3jaDuI2YkBme8BJjXV8dMauBplpb5i7Y5V1xNV9aLWjPuyWsGqVX+nExJBdZQtM19FlkVh+ePeJOm4JPnH9zXnMYiZalcWphpXeyIG7JQDq50zvg0fT0wKt2VEn5Jn7mI6zqHNecaVwBgzsjqacUr39Z4oN72n+9vTZpdEyO0krKX+Kn+ckkemysPL/vmgeuofjXw2PaEr06DD0SylLDaHpICk8ejVYRmSzwhtNvi1Qple+W1uwN7/NVSWntR69JPbOOvyvi4W3uLf+TIxufMt8VNgnRm5bVZAi3jTzCe6FEDUklEjBBKdTIqfM4o+Eo80lzU1VJo2bRiK8QmtX5Gc4mCPfUzcPG9xLyjsfEDw6LGY+evehxRorU/plHMfLZl7WtenKeFJ6aNGaFOgecdie0/vyfH8euKKGIdWhL42QLTMVIDwpSX9ohXd9qHgeLYkeZHZws56lrJI3V8jT0RAiAI3VgdLzFZ5HYGOlSMG1WTEEDXrwARFMdNoQ13XCZLw== 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: Reviewed-by: David Hildenbrand Reviewed-by: Mike Rapoport (IBM) Signed-off-by: Peter Xu --- tools/testing/selftests/mm/.gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/selftests/mm/.gitignore b/tools/testing/selftests/mm/.gitignore index 1f8c36a9fa10..347277f2adc3 100644 --- a/tools/testing/selftests/mm/.gitignore +++ b/tools/testing/selftests/mm/.gitignore @@ -36,3 +36,5 @@ split_huge_page_test ksm_tests local_config.h local_config.mk +ksm_functional_tests +mdwe_test From patchwork Wed Apr 12 16:41:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209338 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 8745DC77B6E for ; Wed, 12 Apr 2023 16:41:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7E3EC900003; Wed, 12 Apr 2023 12:41:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7BB4C900005; Wed, 12 Apr 2023 12:41:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 65C6F900003; Wed, 12 Apr 2023 12:41:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 460DC900005 for ; Wed, 12 Apr 2023 12:41:26 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id AA46A12019B for ; Wed, 12 Apr 2023 16:41:25 +0000 (UTC) X-FDA: 80673304530.27.A4929C8 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf30.hostedemail.com (Postfix) with ESMTP id 6A4048000B for ; Wed, 12 Apr 2023 16:41:23 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Xvig++nJ; spf=pass (imf30.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@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=1681317683; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=UoyMoOjoICnnEVcPuqz2r5voAg7rax1INu5Vpam+Fw4=; b=5dp7V3get0DeuPv/ogn3EOM7bMcFUZi2gMydzAyS9i5DW/V5qEqWbdj9mIB1M2VucS3/kr pRHWlNkayWP7teyNphNyQS8A2i4TUxFIoFtCTawTtT3jJbfUL6rTp1AMugese/d04s8uQO 7fbeXwQlk4+ZqizGYj3S0x3x8n/WZNk= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Xvig++nJ; spf=pass (imf30.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681317683; a=rsa-sha256; cv=none; b=sLzZanrJpBj8g2FjDwfnEDykm4t3YcFvhd61o31o454DO0F07xVFJsJB7tcKGQ97WsljbP n8xqmrfDffn2YYC5yi4068XmQupu+NuYaEBzI/VEjLdOVGyHti1o148FbNIcT3scvn/BXx 1PXU7CTq8THwHPHZBOw/Z7sxG8T0SM0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317682; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UoyMoOjoICnnEVcPuqz2r5voAg7rax1INu5Vpam+Fw4=; b=Xvig++nJ7ALUcZy1FvRIYnHiXcI5HPTgmmpTtfILR0+XxzNHvgU/Vc9MIlukUlfpLqy611 OH24E3ReNABmWmGHakAVGv6YJwwG6mM3NqThbsZZ8gSvugcLqFgTzAkZIt7AIoTlO941EA jm+oFh50GpIvkQlsrTTJ6SjM64EL310= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-122-aE3FDXS4PPyHkBakXu5gmg-1; Wed, 12 Apr 2023 12:41:21 -0400 X-MC-Unique: aE3FDXS4PPyHkBakXu5gmg-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-5ea572ef499so7654566d6.1 for ; Wed, 12 Apr 2023 09:41:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317681; x=1683909681; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UoyMoOjoICnnEVcPuqz2r5voAg7rax1INu5Vpam+Fw4=; b=Pgo6g80DZeuefIpFkiTM3eT4vSgSEIp25mNslLVrik+OCMmKy3smsncvjEVKv/Ew3S vFUjrFmsIw0ZSevDtvwimvxZhnjGP1KXVtm18h67z+I3312fh2xcfU814MVZcssISKpE T4uFS3aqZ/ro8xybpf36Ky1xiPmAV8nCHHfDI/fRWvO3DHcY2MrouK/HQrB55PvYdmkI CV8Mezee2OuWwsR9q62PXAKt7tNiSzR+0UXb6jgM242GaMs8bIoUnCNj0Fck2/Nj7Wru 02zEpc5MRH3VEqVo2+6eise/N8mUjPiPWmEk5eZhar1Fel6EDPhKYgmcnQH1yRwWPkdw BsLw== X-Gm-Message-State: AAQBX9cXZpOZvKPiWkHJm9bRgFGthikuiOBPScksSZPkuZFcPfQEBGL9 GdP4RU7GSMV1+D221/YIDKwJ9Vd/nw45VNhE/+6px0buzII+2S2mqE4Zxa0mOULyJ3oOz/fQRKT Y3P7LLnaGFiU= X-Received: by 2002:a05:6214:5290:b0:5ed:c96e:ca4a with SMTP id kj16-20020a056214529000b005edc96eca4amr14516818qvb.1.1681317680975; Wed, 12 Apr 2023 09:41:20 -0700 (PDT) X-Google-Smtp-Source: AKy350Y/BM9d0qYWbe4XaYzBW72Y+CI5qbpGOBnAbMVn6e6u5jNfJhaRd9I8cUGoJsnTVOpur+A1Jw== X-Received: by 2002:a05:6214:5290:b0:5ed:c96e:ca4a with SMTP id kj16-20020a056214529000b005edc96eca4amr14516789qvb.1.1681317680716; Wed, 12 Apr 2023 09:41:20 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id d125-20020a37b483000000b007426ec97253sm4741159qkf.111.2023.04.12.09.41.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:41:19 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Axel Rasmussen , David Hildenbrand , Andrea Arcangeli , Mike Rapoport , Nadav Amit , peterx@redhat.com, Mike Kravetz , Andrew Morton , Leonardo Bras Soares Passos , Mike Rapoport Subject: [PATCH v2 03/31] selftests/mm: Dump a summary in run_vmtests.sh Date: Wed, 12 Apr 2023 12:41:17 -0400 Message-Id: <20230412164117.327720-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 6A4048000B X-Stat-Signature: 4jnsm9bpcuw7pfmhz5yfebwco9yww8i1 X-Rspam-User: X-HE-Tag: 1681317683-406882 X-HE-Meta: U2FsdGVkX19c7Rda8qfBCqlfpYgjlmokPmhy5eVgwYwMPDqlzGspO7HKjJIv56OQQbqHWFx6RwwUwp7p1Bmr1ufOomqtSAxA90VKeyraCrnVVemJiajr5dLg3sh8j9Lm45dZc3DuQAYeX2fCaF16NJdnu2dVIa4Zyx8ICqZ/NxUfWs5xIZM89vjY1aqI9EXHJvI+zxAQpGY4BuRxK9sm1x7KM2UOiKacPvDvyDpF9PGOy1R9ONL2J/g/qmLpeOTXBKfHYuq14iN1la/YKJw8wt5bZjFs/gpJ4XG5RvTqYBP9+b3InP7mHHJvButDZL0S2QiBUnfAJqbSe9BxUbA33m2dxQdXBs6wV47zSSsa7rDODaMZ0//9VGako6DxsBhG/FYeqkYeATdiPO3jZHE7erPNmwfr69VDLkitCE7YzVrG2tx9LGaVFsVNswI3VdlEcT1PpjI5QNrR1HG4Tx90/knqNO3kus1ZC8WGgf4UUjzZ8CGE1GE0b9qljdW6gbK6+R+JVJk1dFCF5N2fqy8v3x82AI+s8tJ9/+IN4y4VIyOPLvFKi65PU27nMLoBj97EA6HsnxtPwTFI7uzd1en7lEJqWOcMxBzrLGCoZDoT7PFNBZCFRmy7n7cSZ/jNL7PK6AT/MWFCBlU8p7degnJu9JXcTFcMkME4yy9apfs5K2Yo8O4SJtAYVnL0wMzO7I+a/EZ25hKIhvyRl8hIOXxgPBFaVBRjVSS93ktzzLFPxcKt+QJE3oOJUywIV8dQh2vUXrOYXucjzfR+fV7ZeQrHNa8ypWow7g9xQiJeLJMOQYgXndm1x4pa2yPzxZ9Cesxn9CbJTFu1zDxk9CzkiNw/6g8+3zopztk5KMmZwZ5vFzZ7YPS/ydDZvlnYDmqJXBTHfXsdPjpQxLk62esR7GXqHmYq7gYY9hnXiTjvnK7K2AuDNeFr2o59Qjg7id/87aj5IDN/t9ugIRHVIh9/Uac mais79Ex 79XyUewRjmFgAT3rI8wacAhwrPaUm4pabmxNbMojGu7B7RCOZWD9UX7COtJm2wd4+3ane06jFhDsuQYjcj5P4uNJ7G2ywShdugDe2rMB+loNkNqbskAqPQJmbr6SUtISanmg2/XjEPQV2Jpf8EFO2KxQVlZOdoPvg2lwEIIZovVzb1TZBUN72gypDbw+2n59jvtv06hu2eZBxcXQULFpNhcd2w80tcNKsigZB/ntKHG7XTYTm/84mxQ2V5t0IfXDixKp6YsRofmTfERLCHelPNU8yMe+0pyKOJREZJQ2/E3OUiOtGuBsZdcFcDDucgFOzC8u5w7BB2eckHE2+qTVYcSlBLdrpDPnwYccwCNZoXwZUfDdc+dEDZ9DKN6bBQws6aY6+sOyKRKbEDNDEpHXDwyg98MfTer0TMMrrz93C5Qc4btor/xtcosZcAyA9zt/aXlJtY1S2RfGRFBGyK54OrSAE+NFpSWGJq0xLh9DMDIUuu2tRMfDh9aB2djf9xTFsRsZb/Qk11nSUJp7u7yIloYm/ANKtlc1NXGprOWrGQ92hlRBfHEHRMuig1DTKInQj2DN+RqQW8GNhfvaMMwzHHm6S3i+zWlWtkDZ0 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: Dump a summary after running whatever test specified. Useful for human runners to identify any kind of failures (besides exit code). Reviewed-by: Axel Rasmussen Reviewed-by: David Hildenbrand Reviewed-by: Mike Rapoport (IBM) Signed-off-by: Peter Xu --- tools/testing/selftests/mm/run_vmtests.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/selftests/mm/run_vmtests.sh index c0f93b668c0c..ddf40f883747 100644 --- a/tools/testing/selftests/mm/run_vmtests.sh +++ b/tools/testing/selftests/mm/run_vmtests.sh @@ -5,6 +5,9 @@ # Kselftest framework requirement - SKIP code is 4. ksft_skip=4 +count_pass=0 +count_fail=0 +count_skip=0 exitcode=0 usage() { @@ -149,11 +152,14 @@ run_test() { "$@" local ret=$? if [ $ret -eq 0 ]; then + count_pass=$(( count_pass + 1 )) echo "[PASS]" elif [ $ret -eq $ksft_skip ]; then + count_skip=$(( count_skip + 1 )) echo "[SKIP]" exitcode=$ksft_skip else + count_fail=$(( count_fail + 1 )) echo "[FAIL]" exitcode=1 fi @@ -279,4 +285,6 @@ CATEGORY="soft_dirty" run_test ./soft-dirty # COW tests CATEGORY="cow" run_test ./cow +echo "SUMMARY: PASS=${count_pass} SKIP=${count_skip} FAIL=${count_fail}" + exit $exitcode From patchwork Wed Apr 12 16:41:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209340 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 DCC2BC77B6E for ; Wed, 12 Apr 2023 16:41:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 54C7C280002; Wed, 12 Apr 2023 12:41:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4FC68280001; Wed, 12 Apr 2023 12:41:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 39D03280002; Wed, 12 Apr 2023 12:41:33 -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 28C3E280001 for ; Wed, 12 Apr 2023 12:41:33 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id DD3FB1201AA for ; Wed, 12 Apr 2023 16:41:32 +0000 (UTC) X-FDA: 80673304824.07.B4CC854 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf02.hostedemail.com (Postfix) with ESMTP id CF6B680024 for ; Wed, 12 Apr 2023 16:41:30 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="KB+9/CEO"; spf=pass (imf02.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@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=1681317690; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=wXTqxDSTsrRiAkVZ6NC5Z+aMCLpRXkWfeIKb5BVB8IM=; b=kbNF3DjzoaAl2F8mQBhLTQJ0NumoZt7Xpeu3OZJGto/1X5/Ul4MNGsGCdDsQ8pwbJHgnau SJ1URei/9x2/ofeV1CZuHfGq1gzWP90FxPruvewqLFCgCwV3x09xMQhmIt8cxfe/roxAAM Gw4Yv/dK5pVpemOth17s4mTIE3gtpg8= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="KB+9/CEO"; spf=pass (imf02.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681317690; a=rsa-sha256; cv=none; b=2B71TKAqhdUSG8ssc03UP2gbpQNt40/3hoQm/ngQVu/knR8lYnxpSHZjY5y8QYbpCTXVk8 7qNrnDcvKQES/0hL8+5cjpvdmI51+tMEy62nzdT1U0yE1hMaatY0rxYVpeePYVP+ln4lHr 0t4CCvV/K376FpejWFKyMwWfOLGGsOk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317690; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wXTqxDSTsrRiAkVZ6NC5Z+aMCLpRXkWfeIKb5BVB8IM=; b=KB+9/CEOoHrCrP8imfN76Jj8Rdeh3DAQAD55o6408eRCFIvRh4atw2UaU24q7y6YxtuQjA uxdG5afDPRj8z55wNHEPIijQ8xeg0b3NaA+81F96X1B85pHoe+/8brceoUpHJS1PPHbsOx +52g5zdc73eGlrsUI0RpMz+QksaiEYA= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-262-WkMgNWWtN2-mxUmS4tsiUw-1; Wed, 12 Apr 2023 12:41:29 -0400 X-MC-Unique: WkMgNWWtN2-mxUmS4tsiUw-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-74a90355636so62095885a.0 for ; Wed, 12 Apr 2023 09:41:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317685; x=1683909685; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wXTqxDSTsrRiAkVZ6NC5Z+aMCLpRXkWfeIKb5BVB8IM=; b=WsFo/W0kCs7xAVp58Z0eHkQ2A2x1tyzR+W74ue45QAYq1OfHq5GmzyJ3aln3wmuCF5 OwyjYFOnXtD6O39jlNetu7QSpO/a72zy8MlquX0tm+51cL+RTafzqR444Zdtd/NSnuh4 NK53aq+b4n1odkJQUupn1/wT64fgjM6mmVDeUtl36MnfN3hDZ4d760EsANOYLdv7NX6a v623T0rdAdPSq9SIJZWMa5ihSTb9wi4GeaFR8vRc2/eWwJ2Qn49YxVQSHiZicsuPKczT /9156MDK8uaa6VSHpMOVRlBzBavXtPbRHtbAF/r4frjF0R/aUbeCYM4LmFI+EDsZPM1T 1Bpw== X-Gm-Message-State: AAQBX9dsQ+4eeb8ESvd2GBjqB7t815o4di6Hw/TbKa0KDMOIQ/V7e7DZ xruYPAhv7N1gWB0qtpbLuHkDuN2vuofo3f+GUSMRUPJh0QiM+RzpNOUIFBgpFMDiIwqfuWNnOG3 CGAJ19oQ9V0Q= X-Received: by 2002:ad4:5de6:0:b0:5da:b965:1efd with SMTP id jn6-20020ad45de6000000b005dab9651efdmr27656361qvb.2.1681317684872; Wed, 12 Apr 2023 09:41:24 -0700 (PDT) X-Google-Smtp-Source: AKy350ajUEBNrrqlo7NLbMBFZBxhABZNBWjNLqBWj6Qhq7WnBXzPQ9lMhNrGPdDfuPO/IRJuRxGCtQ== X-Received: by 2002:ad4:5de6:0:b0:5da:b965:1efd with SMTP id jn6-20020ad45de6000000b005dab9651efdmr27656333qvb.2.1681317684546; Wed, 12 Apr 2023 09:41:24 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id m10-20020ad44b6a000000b005e1075e21b7sm5013110qvx.15.2023.04.12.09.41.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:41:23 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Axel Rasmussen , David Hildenbrand , Andrea Arcangeli , Mike Rapoport , Nadav Amit , peterx@redhat.com, Mike Kravetz , Andrew Morton , Leonardo Bras Soares Passos , Mike Rapoport Subject: [PATCH v2 04/31] selftests/mm: Merge util.h into vm_util.h Date: Wed, 12 Apr 2023 12:41:20 -0400 Message-Id: <20230412164120.327731-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: CF6B680024 X-Stat-Signature: 9i4qxuk4nfku6smbfurmk4xfyi1ne6ac X-HE-Tag: 1681317690-152722 X-HE-Meta: U2FsdGVkX18Uk1E+XG81GpL+/3f2/nUD+7Zl6y6INdbJWNn5qZxX6lhUtUK3ckScRm2Mdkll82mxp5OtJUsTQKkEpAi0xMwe6ICtc8b4twDMtQO9KhIKcXFhzsQUnAaAVmEFdNyLPneK++coxB+/znXkYxtjwW4SwcDyNkdfkhLvLGVvxnlFnJK883UIC4KQNIjFjDzuE/yMBy1uCZ916tNQ+BrsSu9v3lZdz7b8IulEK8tYdlr4PKdKAXyRd2tRR8wNlc7uJZ/Th8fv7iFR8i8sdB+DEbhsMMTw4lYsND6SLFdvaCZmdlQMd6L7WCCXvw82XgPJ22mRr/Ncv01pfNhnDTjsftZlopG7liNugID6TzgIyq6ZlDupNUyH95kGJVgi8tDQmz86KtNIBXH/SAXgX6gjL4TAiO254hcnm0kzYT1M/Wd5A990VmqssjPAOpRkcBcKbpBeCAYxnSJ80DgsGhhFNgI5YaCS+Xf01WY2xmqXJ8y+/9nF/QZBkCoVQFT5QnCMd8p02tI+HC/EEHEtP0mHJBKq/b36LhBap6qjtL/EkzSOF8Ikp+cunNfMtm6wuOdrbKNnL5YDOpZrFQC2SxdyUpeqAlCwJeiM6gUEnfMhfHieUQWzXBcVdX6GQu3Vd0D+KITD3p3f7xci2ysCINTwAl3j3GxxQTMYyHDFzkCMqg0xSrVIpmZy4vVktHZsWi4tJzMfW6+A0MX82Py2yUnNEEuGXV7hesi54pFo9I6GLpXZoY+hxH/OcHR1aCipEj7rWusC8RguoNs+4I5hBHFLft+VSE7enxhD6py8OBahUanbcOA8i4UdREUK8Vr9eJ8otsin/Sda8h1CfhhbkGs9iNoqAaSc1cz0oTgCMwTD6oAkDBwIyJe1ov+awPlB3a4ypTox9Zk+B0lf4ZTHGJLH0HJesB/47itMgn3XuPMfQD5aqqRRIbzoi7fEmOKETGoHREs68GiB/aL qqC1+CWy cBKsgeLbzBXhIbCTPoQBTZ8vLOwisElVqrUB6/r//Ye7T9n7Zw7AkMlzkDGPFHzESvDHcY3IRPuQeS4F5DLWpbn3OQy02FZtdZdKli7U92YlfmAzxWy8ZFH2ArQgeI7ciNm8DjdjU1/0abbh2d4fZ7YbBFSyEOyQwcq1rTq4zpvOLv6eNtaYSqnnAY72mSEOXAMaKpk2BflbuX0NpuklQKNuKpo5Uv6BsoRL3DqdgDTf9XEic0mkkRr12+FzYZ2A7UyRfGN0+4tt6ThMno28xzM4N5wUgpuL2IwgwYqyEcUqT2JY8J2LatcdRWoJtNsV1zCXWOmgSz9uU/Yj8RZAKlBcm2vTQMj8+J2zLvULJthN132A/ERvaSMAjoERmJ73GRYFB6xj1ijYFuF/up38GjevH/2qoy6WuirsL1aXM7D/4l8B1wO7EYvW9G5fkOINmTHx5M4rVB0n5n1jivAl5FUxbf7khMdasPPRfBktRMYV6kaQzLvBzEpi4lncuIUbSjNFIqK05A2E0cv6HsaMtJ6h5VRUD+p4uJ9cMULBnEAcIgg6R32tcJKNOJWU9MjsYRo/SN1EiFBXi1SlHMutO/DhxXfhXTLv/piIF 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: There're two util headers under mm/ kselftest. Merge one with another. It turns out util.h is the easy one to move. When merging, drop PAGE_SIZE / PAGE_SHIFT because they're unnecessary wrappers to page_size() / page_shift(), meanwhile rename them to psize() and pshift() so as to not conflict with some existing definitions in some test files that includes vm_util.h. Reviewed-by: Axel Rasmussen Reviewed-by: David Hildenbrand Reviewed-by: Mike Rapoport (IBM) Signed-off-by: Peter Xu --- tools/testing/selftests/mm/Makefile | 4 ++ tools/testing/selftests/mm/gup_test.c | 5 +- tools/testing/selftests/mm/ksm_tests.c | 2 +- tools/testing/selftests/mm/mrelease_test.c | 11 ++- tools/testing/selftests/mm/transhuge-stress.c | 12 ++-- tools/testing/selftests/mm/util.h | 69 ------------------- tools/testing/selftests/mm/vm_util.c | 31 +++++++++ tools/testing/selftests/mm/vm_util.h | 31 +++++++++ 8 files changed, 80 insertions(+), 85 deletions(-) delete mode 100644 tools/testing/selftests/mm/util.h diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/mm/Makefile index 8235dddbbbc6..9d9822b4bf24 100644 --- a/tools/testing/selftests/mm/Makefile +++ b/tools/testing/selftests/mm/Makefile @@ -113,6 +113,10 @@ $(OUTPUT)/mkdirty: vm_util.c $(OUTPUT)/soft-dirty: vm_util.c $(OUTPUT)/split_huge_page_test: vm_util.c $(OUTPUT)/userfaultfd: vm_util.c +$(OUTPUT)/gup_test: vm_util.c +$(OUTPUT)/mrelease_test: vm_util.c +$(OUTPUT)/transhuge-stress: vm_util.c +$(OUTPUT)/ksm_tests: vm_util.c ifeq ($(MACHINE),x86_64) BINARIES_32 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_32)) diff --git a/tools/testing/selftests/mm/gup_test.c b/tools/testing/selftests/mm/gup_test.c index e43879291dac..ec2229136384 100644 --- a/tools/testing/selftests/mm/gup_test.c +++ b/tools/testing/selftests/mm/gup_test.c @@ -12,8 +12,7 @@ #include #include #include "../kselftest.h" - -#include "util.h" +#include "vm_util.h" #define MB (1UL << 20) @@ -251,7 +250,7 @@ int main(int argc, char **argv) if (touch) { gup.gup_flags |= FOLL_TOUCH; } else { - for (; (unsigned long)p < gup.addr + size; p += PAGE_SIZE) + for (; (unsigned long)p < gup.addr + size; p += psize()) p[0] = 0; } diff --git a/tools/testing/selftests/mm/ksm_tests.c b/tools/testing/selftests/mm/ksm_tests.c index f9eb4d67e0dd..74281593a124 100644 --- a/tools/testing/selftests/mm/ksm_tests.c +++ b/tools/testing/selftests/mm/ksm_tests.c @@ -12,7 +12,7 @@ #include "../kselftest.h" #include -#include "util.h" +#include "vm_util.h" #define KSM_SYSFS_PATH "/sys/kernel/mm/ksm/" #define KSM_FP(s) (KSM_SYSFS_PATH s) diff --git a/tools/testing/selftests/mm/mrelease_test.c b/tools/testing/selftests/mm/mrelease_test.c index 6c62966ab5db..37b6d33b9e84 100644 --- a/tools/testing/selftests/mm/mrelease_test.c +++ b/tools/testing/selftests/mm/mrelease_test.c @@ -9,8 +9,7 @@ #include #include #include - -#include "util.h" +#include "vm_util.h" #include "../kselftest.h" @@ -32,7 +31,7 @@ static int alloc_noexit(unsigned long nr_pages, int pipefd) unsigned long i; char *buf; - buf = (char *)mmap(NULL, nr_pages * PAGE_SIZE, PROT_READ | PROT_WRITE, + buf = (char *)mmap(NULL, nr_pages * psize(), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, 0, 0); if (buf == MAP_FAILED) { perror("mmap failed, halting the test"); @@ -40,7 +39,7 @@ static int alloc_noexit(unsigned long nr_pages, int pipefd) } for (i = 0; i < nr_pages; i++) - *((unsigned long *)(buf + (i * PAGE_SIZE))) = i; + *((unsigned long *)(buf + (i * psize()))) = i; /* Signal the parent that the child is ready */ if (write(pipefd, "", 1) < 0) { @@ -54,7 +53,7 @@ static int alloc_noexit(unsigned long nr_pages, int pipefd) timeout--; } - munmap(buf, nr_pages * PAGE_SIZE); + munmap(buf, nr_pages * psize()); return (timeout > 0) ? KSFT_PASS : KSFT_FAIL; } @@ -87,7 +86,7 @@ static int child_main(int pipefd[], size_t size) /* Allocate and fault-in memory and wait to be killed */ close(pipefd[0]); - res = alloc_noexit(MB(size) / PAGE_SIZE, pipefd[1]); + res = alloc_noexit(MB(size) / psize(), pipefd[1]); close(pipefd[1]); return res; } diff --git a/tools/testing/selftests/mm/transhuge-stress.c b/tools/testing/selftests/mm/transhuge-stress.c index e3f00adb1b82..ba9d37ad3a89 100644 --- a/tools/testing/selftests/mm/transhuge-stress.c +++ b/tools/testing/selftests/mm/transhuge-stress.c @@ -15,7 +15,7 @@ #include #include #include -#include "util.h" +#include "vm_util.h" int backing_fd = -1; int mmap_flags = MAP_ANONYMOUS | MAP_NORESERVE | MAP_PRIVATE; @@ -34,10 +34,10 @@ int main(int argc, char **argv) int pagemap_fd; ram = sysconf(_SC_PHYS_PAGES); - if (ram > SIZE_MAX / sysconf(_SC_PAGESIZE) / 4) + if (ram > SIZE_MAX / psize() / 4) ram = SIZE_MAX / 4; else - ram *= sysconf(_SC_PAGESIZE); + ram *= psize(); len = ram; while (++i < argc) { @@ -58,7 +58,7 @@ int main(int argc, char **argv) warnx("allocate %zd transhuge pages, using %zd MiB virtual memory" " and %zd MiB of ram", len >> HPAGE_SHIFT, len >> 20, - ram >> (20 + HPAGE_SHIFT - PAGE_SHIFT - 1)); + ram >> (20 + HPAGE_SHIFT - pshift() - 1)); pagemap_fd = open("/proc/self/pagemap", O_RDONLY); if (pagemap_fd < 0) @@ -92,7 +92,7 @@ int main(int argc, char **argv) if (pfn < 0) { nr_failed++; } else { - size_t idx = pfn >> (HPAGE_SHIFT - PAGE_SHIFT); + size_t idx = pfn >> (HPAGE_SHIFT - pshift()); nr_succeed++; if (idx >= map_len) { @@ -108,7 +108,7 @@ int main(int argc, char **argv) } /* split transhuge page, keep last page */ - if (madvise(p, HPAGE_SIZE - PAGE_SIZE, MADV_DONTNEED)) + if (madvise(p, HPAGE_SIZE - psize(), MADV_DONTNEED)) err(2, "MADV_DONTNEED"); } clock_gettime(CLOCK_MONOTONIC, &b); diff --git a/tools/testing/selftests/mm/util.h b/tools/testing/selftests/mm/util.h deleted file mode 100644 index b27d26199334..000000000000 --- a/tools/testing/selftests/mm/util.h +++ /dev/null @@ -1,69 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ - -#ifndef __KSELFTEST_VM_UTIL_H -#define __KSELFTEST_VM_UTIL_H - -#include -#include -#include -#include /* ffsl() */ -#include /* _SC_PAGESIZE */ - -static unsigned int __page_size; -static unsigned int __page_shift; - -static inline unsigned int page_size(void) -{ - if (!__page_size) - __page_size = sysconf(_SC_PAGESIZE); - return __page_size; -} - -static inline unsigned int page_shift(void) -{ - if (!__page_shift) - __page_shift = (ffsl(page_size()) - 1); - return __page_shift; -} - -#define PAGE_SHIFT (page_shift()) -#define PAGE_SIZE (page_size()) -/* - * On ppc64 this will only work with radix 2M hugepage size - */ -#define HPAGE_SHIFT 21 -#define HPAGE_SIZE (1 << HPAGE_SHIFT) - -#define PAGEMAP_PRESENT(ent) (((ent) & (1ull << 63)) != 0) -#define PAGEMAP_PFN(ent) ((ent) & ((1ull << 55) - 1)) - - -static inline int64_t allocate_transhuge(void *ptr, int pagemap_fd) -{ - uint64_t ent[2]; - - /* drop pmd */ - if (mmap(ptr, HPAGE_SIZE, PROT_READ | PROT_WRITE, - MAP_FIXED | MAP_ANONYMOUS | - MAP_NORESERVE | MAP_PRIVATE, -1, 0) != ptr) - errx(2, "mmap transhuge"); - - if (madvise(ptr, HPAGE_SIZE, MADV_HUGEPAGE)) - err(2, "MADV_HUGEPAGE"); - - /* allocate transparent huge page */ - *(volatile void **)ptr = ptr; - - if (pread(pagemap_fd, ent, sizeof(ent), - (uintptr_t)ptr >> (PAGE_SHIFT - 3)) != sizeof(ent)) - err(2, "read pagemap"); - - if (PAGEMAP_PRESENT(ent[0]) && PAGEMAP_PRESENT(ent[1]) && - PAGEMAP_PFN(ent[0]) + 1 == PAGEMAP_PFN(ent[1]) && - !(PAGEMAP_PFN(ent[0]) & ((1 << (HPAGE_SHIFT - PAGE_SHIFT)) - 1))) - return PAGEMAP_PFN(ent[0]); - - return -1; -} - -#endif diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c index 8dc74dd022c2..85411ee7ff8b 100644 --- a/tools/testing/selftests/mm/vm_util.c +++ b/tools/testing/selftests/mm/vm_util.c @@ -8,6 +8,9 @@ #define SMAP_FILE_PATH "/proc/self/smaps" #define MAX_LINE_LENGTH 500 +unsigned int __page_size; +unsigned int __page_shift; + uint64_t pagemap_get_entry(int fd, char *start) { const unsigned long pfn = (unsigned long)start / getpagesize(); @@ -149,3 +152,31 @@ bool check_huge_shmem(void *addr, int nr_hpages, uint64_t hpage_size) { return __check_huge(addr, "ShmemPmdMapped:", nr_hpages, hpage_size); } + +int64_t allocate_transhuge(void *ptr, int pagemap_fd) +{ + uint64_t ent[2]; + + /* drop pmd */ + if (mmap(ptr, HPAGE_SIZE, PROT_READ | PROT_WRITE, + MAP_FIXED | MAP_ANONYMOUS | + MAP_NORESERVE | MAP_PRIVATE, -1, 0) != ptr) + errx(2, "mmap transhuge"); + + if (madvise(ptr, HPAGE_SIZE, MADV_HUGEPAGE)) + err(2, "MADV_HUGEPAGE"); + + /* allocate transparent huge page */ + *(volatile void **)ptr = ptr; + + if (pread(pagemap_fd, ent, sizeof(ent), + (uintptr_t)ptr >> (pshift() - 3)) != sizeof(ent)) + err(2, "read pagemap"); + + if (PAGEMAP_PRESENT(ent[0]) && PAGEMAP_PRESENT(ent[1]) && + PAGEMAP_PFN(ent[0]) + 1 == PAGEMAP_PFN(ent[1]) && + !(PAGEMAP_PFN(ent[0]) & ((1 << (HPAGE_SHIFT - pshift())) - 1))) + return PAGEMAP_PFN(ent[0]); + + return -1; +} diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h index 1995ee911ef2..6edeb531afc6 100644 --- a/tools/testing/selftests/mm/vm_util.h +++ b/tools/testing/selftests/mm/vm_util.h @@ -1,6 +1,27 @@ /* SPDX-License-Identifier: GPL-2.0 */ #include #include +#include +#include +#include /* ffsl() */ +#include /* _SC_PAGESIZE */ + +extern unsigned int __page_size; +extern unsigned int __page_shift; + +static inline unsigned int psize(void) +{ + if (!__page_size) + __page_size = sysconf(_SC_PAGESIZE); + return __page_size; +} + +static inline unsigned int pshift(void) +{ + if (!__page_shift) + __page_shift = (ffsl(psize()) - 1); + return __page_shift; +} uint64_t pagemap_get_entry(int fd, char *start); bool pagemap_is_softdirty(int fd, char *start); @@ -13,3 +34,13 @@ uint64_t read_pmd_pagesize(void); bool check_huge_anon(void *addr, int nr_hpages, uint64_t hpage_size); bool check_huge_file(void *addr, int nr_hpages, uint64_t hpage_size); bool check_huge_shmem(void *addr, int nr_hpages, uint64_t hpage_size); +int64_t allocate_transhuge(void *ptr, int pagemap_fd); + +/* + * On ppc64 this will only work with radix 2M hugepage size + */ +#define HPAGE_SHIFT 21 +#define HPAGE_SIZE (1 << HPAGE_SHIFT) + +#define PAGEMAP_PRESENT(ent) (((ent) & (1ull << 63)) != 0) +#define PAGEMAP_PFN(ent) ((ent) & ((1ull << 55) - 1)) From patchwork Wed Apr 12 16:42:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209341 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 9C4C6C7619A for ; Wed, 12 Apr 2023 16:42:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 37739900005; Wed, 12 Apr 2023 12:42:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 34E9C900003; Wed, 12 Apr 2023 12:42:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1EF17900005; Wed, 12 Apr 2023 12:42:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 0F459900003 for ; Wed, 12 Apr 2023 12:42:25 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id DE38EAADBF for ; Wed, 12 Apr 2023 16:42:24 +0000 (UTC) X-FDA: 80673307008.02.8398609 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf18.hostedemail.com (Postfix) with ESMTP id BCDB71C0017 for ; Wed, 12 Apr 2023 16:42:22 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=K3UyTm8P; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf18.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681317742; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=gGqh0HGkgoECYjM8JfbpdJ2gFcbvM7PfOwSnAOWQ14c=; b=o+vRzMvCsCMCARkEhgYZKiQJl/GPvm+/n7x67rDYpR/Llg/s5bq56gCh+mDbYJ+pZuBQnU k15SwlpzGg5ua7WxsjMEavBbasL8RcgnxcY5NRzagDPuq9rRt5N3zpx6ygnhYH3XBPtuYS ZzXVWT7e+8xzdAl8ERq79oNGREE3ZqM= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=K3UyTm8P; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf18.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681317742; a=rsa-sha256; cv=none; b=ajftDsmw+4Y1b5xPeoZe6nGVLX95LJ5+2TkEBpkDBaGSDxkdDxCieKqcVdPcuyI/yFF0AQ qCfaadVt6eZZCA62F5lU9GrRjvO1DK3H5FxzibEhTjtC2FUfHgZkH+dv6OdmOwur4FqIEt cWkHi693vLvrvwN5AzexA3ECKniTQXQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317742; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gGqh0HGkgoECYjM8JfbpdJ2gFcbvM7PfOwSnAOWQ14c=; b=K3UyTm8P2476gbRtGN8JkUOAyHJxuHJLAXZ+jUY258nkl5qbnbhURXChBrsfBScXg+cocf r2zV7lnQqxpSb/3nre6Qzq8jK1M5KBwmMI6/EJL1BP1Kj3Un47OFH6aKY9+Sl/I54bUCac rKlgKtEmSl0oWZijTrj42LYM7EJzdSI= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-363-JRrP-1r6NKWwQmrfm-u1hQ-1; Wed, 12 Apr 2023 12:42:20 -0400 X-MC-Unique: JRrP-1r6NKWwQmrfm-u1hQ-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-74a25fcda05so77593585a.1 for ; Wed, 12 Apr 2023 09:42:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317740; x=1683909740; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gGqh0HGkgoECYjM8JfbpdJ2gFcbvM7PfOwSnAOWQ14c=; b=YXoyf3d8fnvb5wfhyWIPpLeAfGyE2HKoJuPHOkPDF91sQ9lq3uAL7cD4Jc4ZjN5mqj DJ1CTIWoU75YUCccah5w32mvEqlZ3PUehx/lxUeHEOkI2wtboivVlR4wpWEx68jBZYnF 243ohOLRMkQBBwgHTL7tvRkhwUnQOKVN5NuDqzrsQVUQP1iP4GaJcCU2ZZfhNu3WziCr gqvxibFaPfZznG+L6s1QAuawjI6BPkHl8W7BIybewcagTos9cd6A9MU/ph3lIIDPtIZk 2ceZz47zsu5H9af8PpNROKJLreM7iKH6AR5oWFIHkmSlEo5iChqx0EmQk3pnDrJZQbwQ jEUA== X-Gm-Message-State: AAQBX9f07U5tAzHyQq+lJVnCBlHDanOJ9N3mOD2tax1TFEZXR6HxzuTN t2VczW1LWRk2Q4V5ZWpN1yErHfHdFjc6q7S5Are1gnz5M41lcIGLjlxaJx25MQGSnwFZQEEEXKa WZiiJFPalZxE= X-Received: by 2002:a05:622a:314:b0:3e8:e986:b20b with SMTP id q20-20020a05622a031400b003e8e986b20bmr2585178qtw.6.1681317740280; Wed, 12 Apr 2023 09:42:20 -0700 (PDT) X-Google-Smtp-Source: AKy350bkvTx9eAqSgNGgv+038c+tdv0QunwK9SW60Y4+A1DFmxnzTzQyPH/H2ogtGhLnE+aAF7AzBw== X-Received: by 2002:a05:622a:314:b0:3e8:e986:b20b with SMTP id q20-20020a05622a031400b003e8e986b20bmr2585158qtw.6.1681317740031; Wed, 12 Apr 2023 09:42:20 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id i18-20020ac860d2000000b003e45a39ed74sm4352477qtm.81.2023.04.12.09.42.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:42:19 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Andrea Arcangeli , Mike Kravetz , Nadav Amit , David Hildenbrand , Mike Rapoport , Axel Rasmussen , Leonardo Bras Soares Passos , peterx@redhat.com, Mike Rapoport Subject: [PATCH v2 05/31] selftests/mm: Use TEST_GEN_PROGS where proper Date: Wed, 12 Apr 2023 12:42:18 -0400 Message-Id: <20230412164218.328104-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: BCDB71C0017 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: e7s3x5phwtpkyabnsqn5nz4scwoxjfeu X-HE-Tag: 1681317742-643776 X-HE-Meta: U2FsdGVkX1/KZXnygK01ExXyDoG2egiLyIfLCBbxh5X8usgTgkXrlNYV8F+1ef84jHXBfK3DZmW/iR1en1h9JYBPhueYHYaDUsR+Bo0a8FvBXFOj7PgA3ynbk2GJAQCHkBsnFCLMGtbdSj1aDXGw3VMnXzTlGRxIStcK/fCOOO20vQggpMS5MY6ASdk5xr+GUI8oJpLarBRw0FvV7hi+XsbNrQ2kNHOikVpQ6wmIo5Sq/oVJjce3Y2lEau6vcOpOSoPnpIFM498d7zN/lDc/Fm1HHWtyRZg8IpWgftr/dL+Q6ZLoWSlAngkdz5+z8ugwo1bNhmiyV4mZv5g35nkbevDkKQPKq/qoaT5N3zsLxw1cdmme6T3MIO3Quihc+kUI7z+i11X3jARqqo0suIpdkhjwii0j1/+5HjHnGvooX/PJQrIC3Dfg4nJc4Nf2RYrhTPGtvh/efERNEfvv0r8qQ7OegMU+s30QQj65CQil3lDPKMxs4m89gFInQ5mTZsPRqzBIK13+0OIDe+6L1bOeMkAIeBb+bE2IAzliyZ5JqvkUtM0poiBmewjfzQqvlKrUcaAz7PBG/4f4glpBfJZ0v7NahUvRhev5eOeWvjKWosE8rMkNjOtFqVd+iXE/8iszk48jjaawOj3u7OeMRkJSeQdWKJiEEEpRj9Z3yjZ/11KU+QL133o9KQ79d529rkEDwQ+YtCJcsIjctl/KQkONVh7HBiya5eVTISx+9cEys/AGAz7U4YdcYAQSEWxwQkkzk+D+CkksqUt0e4fm0CpEgmDIuzs90sXK8+I7AoIk8RqXz7uJXFZfJdKMKeWhoy5Ljc6/VZ5RTV90LR5S8jTCDZN97TS6uqWaQUX45muF/ypJfaTEwbPUCPWbkZG7WRPxpPBwM6cgTnPz0EcMKQwNjJfoadEHyiag07mwtySxAhLS2JJJly7G8IEAccN68pJQo4kSc9dPj1PfydCp07P OSi0KSq0 2xBbI61UUe/7mmJmM74/hLo50PceZgnP4OrsBX4FiTiQp/GOGjE5Z0Iacg7wN6TMnqS5OvF59xEupAirzPcgG3vIVV4zzZSouHQHMMPFlnZYWsGTBLaYmET7wCrPs2j4uyjqXTJfFFxBhOPFq+gpXMuQahfGNJSp1uztV4Sg/jxFaRYVhytjYT7d/OZ2K9/fR/oTr16AFiyg6uGCVWV3eydRRtbxXoKsMiLj7oE78eznyJXNY0tV72DlMu52MM1Zt4FoIXlvHhJiksl3FEYIPMgjYGgUD7ptTroM5zquIt2wqeXdbN1cA0KofHHP6cducsTOl3tkvxZYL/2wK97DFXrcVpic2aaYLZV+7euVO3AT9bUqVEiG2pU+wB44maRDnqXvp93d4a2zYlsKwo08PpsfVcKFlQlN3omhRD75zoDMEmcKKFJC7yvKdJKprcS5oljQVvYvFaOxjHan3nsqwUuXL0AdPDvGw5ACCrUInftgaJbQEFmtZdwlXKUqw6y5/PANgNxgeS9SLg+AXzmikPJg13JsFApmu38gzTeCVXKjOGQE7Yeai9DYy8c3t7YtTkecbYQEMRrNg4rk= 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: TEST_GEN_PROGS and TEST_GEN_FILES are used randomly in the mm/Makefile to specify programs that need to build. Logically all these binaries should all fall into TEST_GEN_PROGS. Replace those TEST_GEN_FILES with TEST_GEN_PROGS, so that we can reference all the tests easily later. Reviewed-by: David Hildenbrand Reviewed-by: Mike Rapoport (IBM) Signed-off-by: Peter Xu --- tools/testing/selftests/mm/Makefile | 63 +++++++++++++++-------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/mm/Makefile index 9d9822b4bf24..74988f5adc5f 100644 --- a/tools/testing/selftests/mm/Makefile +++ b/tools/testing/selftests/mm/Makefile @@ -31,35 +31,36 @@ MAKEFLAGS += --no-builtin-rules CFLAGS = -Wall -I $(top_srcdir) $(EXTRA_CFLAGS) $(KHDR_INCLUDES) LDLIBS = -lrt -lpthread -TEST_GEN_FILES = cow -TEST_GEN_FILES += compaction_test -TEST_GEN_FILES += gup_test -TEST_GEN_FILES += hmm-tests -TEST_GEN_FILES += hugetlb-madvise -TEST_GEN_FILES += hugepage-mmap -TEST_GEN_FILES += hugepage-mremap -TEST_GEN_FILES += hugepage-shm -TEST_GEN_FILES += hugepage-vmemmap -TEST_GEN_FILES += khugepaged + +TEST_GEN_PROGS = cow +TEST_GEN_PROGS += compaction_test +TEST_GEN_PROGS += gup_test +TEST_GEN_PROGS += hmm-tests +TEST_GEN_PROGS += hugetlb-madvise +TEST_GEN_PROGS += hugepage-mmap +TEST_GEN_PROGS += hugepage-mremap +TEST_GEN_PROGS += hugepage-shm +TEST_GEN_PROGS += hugepage-vmemmap +TEST_GEN_PROGS += khugepaged TEST_GEN_PROGS = madv_populate -TEST_GEN_FILES += map_fixed_noreplace -TEST_GEN_FILES += map_hugetlb -TEST_GEN_FILES += map_populate -TEST_GEN_FILES += memfd_secret -TEST_GEN_FILES += migration +TEST_GEN_PROGS += map_fixed_noreplace +TEST_GEN_PROGS += map_hugetlb +TEST_GEN_PROGS += map_populate +TEST_GEN_PROGS += memfd_secret +TEST_GEN_PROGS += migration TEST_GEN_PROGS += mkdirty -TEST_GEN_FILES += mlock-random-test -TEST_GEN_FILES += mlock2-tests -TEST_GEN_FILES += mrelease_test -TEST_GEN_FILES += mremap_dontunmap -TEST_GEN_FILES += mremap_test -TEST_GEN_FILES += on-fault-limit -TEST_GEN_FILES += thuge-gen -TEST_GEN_FILES += transhuge-stress -TEST_GEN_FILES += userfaultfd +TEST_GEN_PROGS += mlock-random-test +TEST_GEN_PROGS += mlock2-tests +TEST_GEN_PROGS += mrelease_test +TEST_GEN_PROGS += mremap_dontunmap +TEST_GEN_PROGS += mremap_test +TEST_GEN_PROGS += on-fault-limit +TEST_GEN_PROGS += thuge-gen +TEST_GEN_PROGS += transhuge-stress +TEST_GEN_PROGS += userfaultfd TEST_GEN_PROGS += soft-dirty TEST_GEN_PROGS += split_huge_page_test -TEST_GEN_FILES += ksm_tests +TEST_GEN_PROGS += ksm_tests TEST_GEN_PROGS += ksm_functional_tests TEST_GEN_PROGS += mdwe_test @@ -77,24 +78,24 @@ CFLAGS += -no-pie endif ifeq ($(CAN_BUILD_I386),1) -TEST_GEN_FILES += $(BINARIES_32) +TEST_GEN_PROGS += $(BINARIES_32) endif ifeq ($(CAN_BUILD_X86_64),1) -TEST_GEN_FILES += $(BINARIES_64) +TEST_GEN_PROGS += $(BINARIES_64) endif else ifneq (,$(findstring $(MACHINE),ppc64)) -TEST_GEN_FILES += protection_keys +TEST_GEN_PROGS += protection_keys endif endif ifneq (,$(filter $(MACHINE),arm64 ia64 mips64 parisc64 ppc64 riscv64 s390x sh64 sparc64 x86_64)) -TEST_GEN_FILES += va_128TBswitch -TEST_GEN_FILES += virtual_address_range -TEST_GEN_FILES += write_to_hugetlbfs +TEST_GEN_PROGS += va_128TBswitch +TEST_GEN_PROGS += virtual_address_range +TEST_GEN_PROGS += write_to_hugetlbfs endif TEST_PROGS := run_vmtests.sh From patchwork Wed Apr 12 16:42:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209342 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 88D55C7619A for ; Wed, 12 Apr 2023 16:42:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 28C20280002; Wed, 12 Apr 2023 12:42:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 23D87280001; Wed, 12 Apr 2023 12:42:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1049C280002; Wed, 12 Apr 2023 12:42:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id F33B5280001 for ; Wed, 12 Apr 2023 12:42:28 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id BEBB4AADDF for ; Wed, 12 Apr 2023 16:42:28 +0000 (UTC) X-FDA: 80673307176.25.19821E0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf10.hostedemail.com (Postfix) with ESMTP id 57437C000A for ; Wed, 12 Apr 2023 16:42:26 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GeJPeNei; spf=pass (imf10.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@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=1681317746; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=AASukmt80WChuLSYpdLGBsnHxG2u2zyP4JySsjm2BSA=; b=1DMcAp4tt52BkTznXQkIg2RiTvgeBB0X7XI+UFtOD1cOKXpfcgPDLvJo6cI0X1RBAInbSf 5WjWj5N8qqKgzHby0IJ3wY+7pctp0bsJbL+5UjkxVGdO3BDoMWQHwplDjnNmWxzShcKBtH fNVD8mhfsVgqPcQCH8+YDyavg8Ohavk= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GeJPeNei; spf=pass (imf10.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681317746; a=rsa-sha256; cv=none; b=upgyvNak35wgNXNXIMB1xob1QD18KcNvq++iqq7od5xpxtPfi9R5yAB5olfi+HJap6fwSW rvTkOnwvw8CPrV/NPxxGRG+YeDylj2s2Qqe/vgHnSTxYZHSrIU8YiMSk2+NLUnCVvmFJPX Fz5E7N1hrNj20cUVUb5CQiosao5puh4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317745; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AASukmt80WChuLSYpdLGBsnHxG2u2zyP4JySsjm2BSA=; b=GeJPeNeip7mbZDDf+oMDfF8As8C3dP5KKVDXr92Iu/NjkeBbsdhDyFrhxihoPbBdlcW3hR ImCqiieuE+2DCzOQUYkVnOC9ANPX3mOFacxjU4+LbqlG6NnXLrK1oeyEC1Uu+DPOADpEgC 9d66GkU8QqF3ECCxPHKujyLlypwOlnM= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-557-F8clhZJ_NWunutzIUsoOcg-1; Wed, 12 Apr 2023 12:42:24 -0400 X-MC-Unique: F8clhZJ_NWunutzIUsoOcg-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-5ef4122d2dbso1350166d6.1 for ; Wed, 12 Apr 2023 09:42:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317743; x=1683909743; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AASukmt80WChuLSYpdLGBsnHxG2u2zyP4JySsjm2BSA=; b=Ka39rA7kyzKTSchZ90U3acid2SNMZf7WNZF2O1IuWGYHycQlTe3sTYROYT+/n7tPeB mbzl8jREDC+AwPFenZItBLijG8a8FOGNLZ6bw12LfVIT3TVmmms8rtdhj7ih+fqzMC+3 olV2J3O85oF7kGy29bW6gdxvKG4K/gD/OMswNU/lN1WiFmrNDs9KoyS2Jkq/no54W0VW 8sSS9Rsjh5woZnR1B8zMJeynTZ5tq+b/69uTgMl+nlos+6m3mHGoDeliR9Wi+6oSugaz c0qGFekmMMEpg+37uiX2HDtLj1MQUeyi3JFk5CUfl+b+Gs2Plp0RAxpMKL5Qj98rYRR7 LFFA== X-Gm-Message-State: AAQBX9dchVfhAXNvPAwLFtkd5ukyjrY3aTWy6RWYsiTC9CsKupwU5hyo KJ+7IqHxekzC1zeRKW2v7w3qQLu89qdnB6q3XCj1eslKlaepPyDe0TU8HofOk2PK+Pswzq0lpln hhHEPis3+CCI= X-Received: by 2002:a05:6214:5192:b0:5e8:e6ac:591a with SMTP id kl18-20020a056214519200b005e8e6ac591amr4456989qvb.2.1681317743645; Wed, 12 Apr 2023 09:42:23 -0700 (PDT) X-Google-Smtp-Source: AKy350ZUkH+8udPYM+p0M1Q9rt2RFeDUODTp4Lvra9E3t4UecH3AAez7Vq5YIMTGGOhtqw2IhIGH8Q== X-Received: by 2002:a05:6214:5192:b0:5e8:e6ac:591a with SMTP id kl18-20020a056214519200b005e8e6ac591amr4456960qvb.2.1681317743372; Wed, 12 Apr 2023 09:42:23 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id ei20-20020ad45a14000000b005e90a67a687sm3577922qvb.65.2023.04.12.09.42.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:42:22 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Andrea Arcangeli , Mike Kravetz , Nadav Amit , David Hildenbrand , Mike Rapoport , Axel Rasmussen , Leonardo Bras Soares Passos , peterx@redhat.com, Mike Rapoport Subject: [PATCH v2 06/31] selftests/mm: Link vm_util.c always Date: Wed, 12 Apr 2023 12:42:20 -0400 Message-Id: <20230412164220.328123-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Stat-Signature: 1ikgu4g8oegoupfwphber415t1y3kbo4 X-Rspam-User: X-Rspamd-Queue-Id: 57437C000A X-Rspamd-Server: rspam06 X-HE-Tag: 1681317746-973076 X-HE-Meta: U2FsdGVkX19yNDeWMqhU8C3KXMqhyqZvdlsfM/WFtwtX9PW039Z6Sm/cMoFN1WaKujjKAkkG9AOW1XLfIdCOtCzuZGnyhH1YAfO2tSYJBNjp2wr+V67W/xqFdv1v15TkZ8ZVy318u8tMsbjDikIdze428vq5oOw5Hz4Fu3Q/q8jSuawLUastldA7+MHbe/uJAyH0ZP0lNPOQC4nkYsOoSk7OnRqKQ8vdrKbkwWkI9zHDhrtAXgqOR0Io2TJE+WPm4GTkHjLsR7YI1y6ZlPfqRw+j4p0qpPFvw0kvLgTgnbJr3y042bzQBNxZOJ6SLFg1X/wsX9pGT1z8UD7NT1yA3V7d6toFPtDHpYRNCdKeQeT6Hvqf+is246bRgP3vIU4JvTlwps/fDdUlaNCFIAcYMqu4G4EPnSf+s1GUyV8maiBeCeD+wMRUGKMSL6cdowkUnFJ3WF4cxz4KNQLMvmqEbWb/wsLC9qGcmpcP1jfeUuiO7+AY76mF3koQe5AmWmEI3lEAAxfbH6k+3E5JLULmnJFCjJULU4yKUdD9G8PdME2wEOYI4CDp/ovlLsqvzNPcquQXBDXIJaU/DCjBH7lC3kDXjeq2h7ZA6YstskMBapiHRdJNGe8pHhwlASys5+ErbSHS+EQeGF20F2iU9Y8xmQ+KHhMEj21sDWcVDO3ytnXFvSdd80FUEQurl1iw4enGaEMmsM1g9O2+H2pkmCg9lRH/nmJm8rzHqkqME7f3zV9vByKO0Ejmpuw1clHq9GFOykh/hQPAYXc5lqpi6zhEYOLqsnrqkZf7BlQ7t+vrrN/nzIDkako6xc/scZ88YDFmMpINa42gFu21YQde9PrmwBTA36RecTC3VIER5rE7y5glrvruUtfSkU81MRlCwMV2c19qdE2kv8KKfOZnKy3xncyyz8McmrTW8UGD932rn2/pq3PB2m3AZysWzo30XiTfqTsikbtsMnxk1ebLL8X Mjk8Vqsc BXcRySkXP9PDhPT/bvhiTnPbaEC4Zd17Zfte+44wL6gO7SZiBOtcohVCVX0qZf/5Xp5MGKIjSMLSvIA7d5q2kIGKHtcXL2aFMnvROgsm7k4sRnn1PEymh9mni49iChsw60WlrDlevimoXxt/AmtwbedMHFAWo0mQXglBfTyvFQBxhb+vBgtfTr2kyGTWFmsGo5pdZH00Sig9+gPH8WLueiuIwrevIqYstt9FVYnjZoqYFDrWaD/yk38/UMeYcZlknuJNASg70dpJ5OGqWjA/B/qlQiQvaa47sNOyj6Zfgnvb/QG9MXUE33t2XeX4wPGqJmHyXAFsGXMt79QwBB7gXHixERlBADebf6cIDVy0gbMAbkPrU8+FvtPFy0ukp8O953UlJG6aPMfMMvpTanUM3hO9jWp8hk5ECG2yY68IfXmYkF0Y9trny/c3o9v08C260NGF9xXjZYQFOI+hQoEi5KwyoO86CD3ZvMEr24sosnS47cHKbEqJBL7mhpfKfhYi5zjvJs4SteNXy9o6GSGcpP7e7Lo6vNrx/sx0r6cykgPuQBSmcvjTwWlK13VfxZVZV+4YJFnP6iqj4nNM= 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: We do have plenty of files that want to link against vm_util.c. Just make it simple by linking it always. Reviewed-by: David Hildenbrand Reviewed-by: Mike Rapoport (IBM) Signed-off-by: Peter Xu --- tools/testing/selftests/mm/Makefile | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/mm/Makefile index 74988f5adc5f..5f7626550e5f 100644 --- a/tools/testing/selftests/mm/Makefile +++ b/tools/testing/selftests/mm/Makefile @@ -106,18 +106,7 @@ TEST_FILES += va_128TBswitch.sh include ../lib.mk -$(OUTPUT)/cow: vm_util.c -$(OUTPUT)/khugepaged: vm_util.c -$(OUTPUT)/ksm_functional_tests: vm_util.c -$(OUTPUT)/madv_populate: vm_util.c -$(OUTPUT)/mkdirty: vm_util.c -$(OUTPUT)/soft-dirty: vm_util.c -$(OUTPUT)/split_huge_page_test: vm_util.c -$(OUTPUT)/userfaultfd: vm_util.c -$(OUTPUT)/gup_test: vm_util.c -$(OUTPUT)/mrelease_test: vm_util.c -$(OUTPUT)/transhuge-stress: vm_util.c -$(OUTPUT)/ksm_tests: vm_util.c +$(TEST_GEN_PROGS): vm_util.c ifeq ($(MACHINE),x86_64) BINARIES_32 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_32)) From patchwork Wed Apr 12 16:42:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209343 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 006DFC77B6F for ; Wed, 12 Apr 2023 16:42:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 91D7F280003; Wed, 12 Apr 2023 12:42:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8A557280001; Wed, 12 Apr 2023 12:42:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7465E280003; Wed, 12 Apr 2023 12:42:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 62886280001 for ; Wed, 12 Apr 2023 12:42:32 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 152BF12019B for ; Wed, 12 Apr 2023 16:42:32 +0000 (UTC) X-FDA: 80673307344.19.EED080A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf11.hostedemail.com (Postfix) with ESMTP id DD1164000F for ; Wed, 12 Apr 2023 16:42:29 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TRLdUtfW; spf=pass (imf11.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@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=1681317750; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=9w4FTeM4b1xfAgG4y96DPCrYEWea1Mc83v+smBNR1Gs=; b=SENw2cL51uuomjQbVtae7py0A3K4znJDZSNtD/27ojlridTJmdLkJFwB+bgSQn/dOcppg3 29mALe2aOQwdWYecpbVXmzt+PFV1Oqysm/dSrHo6edP/4axN5fXe55FVthqPWQAEoX+m0a v8XvFSMpx0i9JAokcNjiALYofBdzjsg= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TRLdUtfW; spf=pass (imf11.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681317750; a=rsa-sha256; cv=none; b=HawW3jnH/uU4x7pKYuM2x8KIITGflTMRUQh6fWhtreKTJpHfc4M2lj80kSp6IcvnTESCoN H2rJ8cMFDcFEJbY+LmjmiEa0sErJtKkBoKEapZisHYyuBzVqFD7/DFXMrLN3RsqTJNhcON MvJbxg0SOiIgUIxV9bfq2Zor1l7Wi4w= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317749; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9w4FTeM4b1xfAgG4y96DPCrYEWea1Mc83v+smBNR1Gs=; b=TRLdUtfWznFfy8alUCMg8n4Bghq2QDBoZc1DHsQmlJtqmkWf1NSF+lqmUBjS+3rodHs9q8 hOomwb8+NM8R2VG2LAarKJ1NT9cQwQeCe5HWjgZAuducmwxyEH99sJy42NUi8ew9mPQbcU ZIVGib4d47jDVoWdQPepf1q5WzzTGQ4= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-296-nKj9ndCpPki6pFLRDWg3sQ-1; Wed, 12 Apr 2023 12:42:28 -0400 X-MC-Unique: nKj9ndCpPki6pFLRDWg3sQ-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-74a25fcda05so77595985a.1 for ; Wed, 12 Apr 2023 09:42:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317747; x=1683909747; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9w4FTeM4b1xfAgG4y96DPCrYEWea1Mc83v+smBNR1Gs=; b=ScZIQWoKVl/H2GThl0rZbyM1oaJ2+W0Dz/D84MIpwQKgE2Exs+rg8XjRdWoivcrr67 NpIDbaq4ltBpUWqt3sYhtvBxWoUIVar76mUzztap78nF9SsNlhUMWqjLoaFQy9yGOdrI P4RRKT4qJebnIb1V9nZBeyo9pRYfDS6hPVELH3alkGNFz14hHX2TPay7d6JEy0LJgZyy txE+wgWZUgJwsjdsFK1GZGK8FZyyON3W4wUlcjq/z6bWBrXq0DCOhIXqM2hbvxwFXmmz BanI8df+hIBPEqVBW/wMfWwi3/mH+eJfCsLXZPpGhySsorYFITUwc2AZxkzP/v8nYdEF mkvA== X-Gm-Message-State: AAQBX9fPjry1re8zL1xeJtWXvElXLkfvMIjyQ6s9E6EWITLDF6WmFF36 eOqMgt+4mj/JYJ1jVQu9VL7zASf+pXPhAJDWdTQTG3e7naf56cH+9Q8Y43/NmsIYyjyt55sLm1P wWABoHHc3az/zcxidoL8= X-Received: by 2002:ac8:5cc8:0:b0:3e6:707e:d3b1 with SMTP id s8-20020ac85cc8000000b003e6707ed3b1mr5012771qta.0.1681317747115; Wed, 12 Apr 2023 09:42:27 -0700 (PDT) X-Google-Smtp-Source: AKy350YVvSHn+CiNqMbEanS4Hm6vnJ4+dDPCuFu7aqhBaI35sD13aR8Lht4vPI828Te9foEW+WzjQg== X-Received: by 2002:ac8:5cc8:0:b0:3e6:707e:d3b1 with SMTP id s8-20020ac85cc8000000b003e6707ed3b1mr5012723qta.0.1681317746702; Wed, 12 Apr 2023 09:42:26 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id c24-20020ac85198000000b003e3c23dd2cfsm4353889qtn.84.2023.04.12.09.42.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:42:25 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Andrea Arcangeli , Mike Kravetz , Nadav Amit , David Hildenbrand , Mike Rapoport , Axel Rasmussen , Leonardo Bras Soares Passos , peterx@redhat.com, Mike Rapoport Subject: [PATCH v2 07/31] selftests/mm: Merge default_huge_page_size() into one Date: Wed, 12 Apr 2023 12:42:23 -0400 Message-Id: <20230412164223.328134-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: utsyhykkdwy59en5cyy6tdtecydbmuwh X-Rspamd-Queue-Id: DD1164000F X-HE-Tag: 1681317749-466198 X-HE-Meta: U2FsdGVkX19ABWDiKI1K7unG0r1rz83ieaui9wvImLZNd26RnBuPOx/mX0ZCpLtllVZrYPA76h97CR+gXHC8Zmqofzp1WM+0o9DnvlguiKCTEDDk52ThXIGffF6NoHCUjdPIHDD3WVOzNEqDcNEU4UdT95IS7wq0dRN+1QsJbLNTr0JgIQFo9TaC+dtVJzWzv7Q3tzCT5jynCCplxHNutEd+ASl+d8VQ3+l7CyBDKIziH+N5ZWPZ9ZvdD1vAyHDuKzYw8ZDVCf38TKUzqvN4su75+hU9I6xOCg0mVRMToFUUy6XyzmYplA0ZUvsUMsTW0CVvMYWDPLS7/8uNbcgf2x1pnWUtAmfA3Xdu9J+jPpyOHMUN61ox92dvxBD7cEmwuI9l6yKE80t8AgVSjIqSXOv+VzU0G9yp546uUSWqiiBOV+ckTLHHfGsdorg0+8dR+usE3UgiYkyDLD5p1kMZc8sQ4r5HZ90FULrdOfWcilEcIGCAz8t+M3E8eWz64H/+a88OGnqGedA/7LfsWg9uK2bL+IAtgldRwY38OQ7EiaTqLJ0Sf5KqiT+9rAhpzUaZmUlif3W3o3jZ7IwiHe7IUkNQ3ikpeSUrwku8dVDLS94W8wH4KDLXiQlZdY0f4eciT6T/Ualzn8FN60Av4ch14rOhqheDqENdGkXAxeVZ2n1Spd3gAkG8Oa456dg6qgHnyxSny2EiekPa1MbmFZLNqybCVX7ndHcNMHhOIy2wHl2gOisUbMTMkgHICZP6+amUjtOVLkeWGFnnmwtwweU4REDa63W8tjMe+MxdbHYLGddLIvklUeQZjfDImBj5Fvqmpo7w6G/GUXnBkmOyxfYqzC1/aviejlsZpp8CoFhRmhahSA28mfrnU3LyvVF0BrbLVkvEUCEOE7yU5fG1fBkozkloEpcxUYFupPtCHGcDPdiU/nHEUsdQwsHommgKR8YfIMy/FUSRaA3V7wRqD3p WFXi/JR9 89aFGc8h0QUgWcisFI5uPo4Bwz1WJ5mb7pwKco1ow94dbCzflBvCKcS7qbPvsJi2t7NO24t65hYjK3K/u8Hd3Ew5pijBjDtPoaWggo//EAXDfWd5GuIz10vAWrLvkFVUgLL/Yixo7vlaJp69iQtWMUimmgFZ4gQmc+QQv+73YjYY4kwnQoOf9d9Jz7qZYojA2I3Unbm+e5tFqpbPgyG4Y7vxZ2GZDcQcO3JGy8k+Oi2aVu1p2lp/HOeqG5sLGITgDl2MBALH8HEQg3OhMOxzZ4IMcigduVa80YD47cevfH7zL/1MBSWBfAwWgcUFWOrgrlb2eXdlgF8sKyDLN9S0z6fWeMpWBm9waxn3ok90Ka6hrODnvkM6fBqoW8EL/fC/4K9Elq0a45de44hTHFbkxVZTUFPbllHK2QJWFmBfO46VfmnQblBCUVdEFYjJ8Lgh0O+IFFkUZ5fxZeGeOXbS9VvRBE18X2ILKJ3+/fUjn207qQYP+aq4SsFdHMHQWZ/fpcCiVoYqmupyTx0TtDwoXSescMuDy9a3nBa0Kg98r0FAxtcUGZH2InpO4Xy47MrC6x7f18wj+pVoPPJdbQI0GvITVuGJ6LZHbc4m2PzYq3FBevnkkULaGxCBnLjtmuymMxYyx 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: There're already 3 same definitions of the three functions. Move it into vm_util.[ch]. Reviewed-by: Axel Rasmussen Reviewed-by: Mike Kravetz Reviewed-by: David Hildenbrand Reviewed-by: Mike Rapoport (IBM) Signed-off-by: Peter Xu --- tools/testing/selftests/mm/hugetlb-madvise.c | 25 +------------------- tools/testing/selftests/mm/thuge-gen.c | 19 +-------------- tools/testing/selftests/mm/userfaultfd.c | 24 ------------------- tools/testing/selftests/mm/vm_util.c | 21 ++++++++++++++++ tools/testing/selftests/mm/vm_util.h | 1 + 5 files changed, 24 insertions(+), 66 deletions(-) diff --git a/tools/testing/selftests/mm/hugetlb-madvise.c b/tools/testing/selftests/mm/hugetlb-madvise.c index 9a127a8fe176..28426e30d9bc 100644 --- a/tools/testing/selftests/mm/hugetlb-madvise.c +++ b/tools/testing/selftests/mm/hugetlb-madvise.c @@ -18,6 +18,7 @@ #include #include #include +#include "vm_util.h" #define MIN_FREE_PAGES 20 #define NR_HUGE_PAGES 10 /* common number of pages to map/allocate */ @@ -35,30 +36,6 @@ unsigned long huge_page_size; unsigned long base_page_size; -/* - * default_huge_page_size copied from mlock2-tests.c - */ -unsigned long default_huge_page_size(void) -{ - unsigned long hps = 0; - char *line = NULL; - size_t linelen = 0; - FILE *f = fopen("/proc/meminfo", "r"); - - if (!f) - return 0; - while (getline(&line, &linelen, f) > 0) { - if (sscanf(line, "Hugepagesize: %lu kB", &hps) == 1) { - hps <<= 10; - break; - } - } - - free(line); - fclose(f); - return hps; -} - unsigned long get_free_hugepages(void) { unsigned long fhp = 0; diff --git a/tools/testing/selftests/mm/thuge-gen.c b/tools/testing/selftests/mm/thuge-gen.c index 361ef7192cc6..380ab5f0a534 100644 --- a/tools/testing/selftests/mm/thuge-gen.c +++ b/tools/testing/selftests/mm/thuge-gen.c @@ -24,6 +24,7 @@ #include #include #include +#include "vm_util.h" #define err(x) perror(x), exit(1) @@ -74,24 +75,6 @@ void find_pagesizes(void) globfree(&g); } -unsigned long default_huge_page_size(void) -{ - unsigned long hps = 0; - char *line = NULL; - size_t linelen = 0; - FILE *f = fopen("/proc/meminfo", "r"); - if (!f) - return 0; - while (getline(&line, &linelen, f) > 0) { - if (sscanf(line, "Hugepagesize: %lu kB", &hps) == 1) { - hps <<= 10; - break; - } - } - free(line); - return hps; -} - void show(unsigned long ps) { char buf[100]; diff --git a/tools/testing/selftests/mm/userfaultfd.c b/tools/testing/selftests/mm/userfaultfd.c index a96d126cb40e..4cc80a0e8955 100644 --- a/tools/testing/selftests/mm/userfaultfd.c +++ b/tools/testing/selftests/mm/userfaultfd.c @@ -1703,30 +1703,6 @@ static int userfaultfd_stress(void) || userfaultfd_events_test() || userfaultfd_minor_test(); } -/* - * Copied from mlock2-tests.c - */ -unsigned long default_huge_page_size(void) -{ - unsigned long hps = 0; - char *line = NULL; - size_t linelen = 0; - FILE *f = fopen("/proc/meminfo", "r"); - - if (!f) - return 0; - while (getline(&line, &linelen, f) > 0) { - if (sscanf(line, "Hugepagesize: %lu kB", &hps) == 1) { - hps <<= 10; - break; - } - } - - free(line); - fclose(f); - return hps; -} - static void set_test_type(const char *type) { if (!strcmp(type, "anon")) { diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c index 85411ee7ff8b..7ffad87aa7e8 100644 --- a/tools/testing/selftests/mm/vm_util.c +++ b/tools/testing/selftests/mm/vm_util.c @@ -180,3 +180,24 @@ int64_t allocate_transhuge(void *ptr, int pagemap_fd) return -1; } + +unsigned long default_huge_page_size(void) +{ + unsigned long hps = 0; + char *line = NULL; + size_t linelen = 0; + FILE *f = fopen("/proc/meminfo", "r"); + + if (!f) + return 0; + while (getline(&line, &linelen, f) > 0) { + if (sscanf(line, "Hugepagesize: %lu kB", &hps) == 1) { + hps <<= 10; + break; + } + } + + free(line); + fclose(f); + return hps; +} diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h index 6edeb531afc6..d7163fff8fb7 100644 --- a/tools/testing/selftests/mm/vm_util.h +++ b/tools/testing/selftests/mm/vm_util.h @@ -35,6 +35,7 @@ bool check_huge_anon(void *addr, int nr_hpages, uint64_t hpage_size); bool check_huge_file(void *addr, int nr_hpages, uint64_t hpage_size); bool check_huge_shmem(void *addr, int nr_hpages, uint64_t hpage_size); int64_t allocate_transhuge(void *ptr, int pagemap_fd); +unsigned long default_huge_page_size(void); /* * On ppc64 this will only work with radix 2M hugepage size From patchwork Wed Apr 12 16:42:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209344 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 D39B0C77B6E for ; Wed, 12 Apr 2023 16:42:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6FA21280004; Wed, 12 Apr 2023 12:42:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6A934280001; Wed, 12 Apr 2023 12:42:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 54AA2280004; Wed, 12 Apr 2023 12:42:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 46563280001 for ; Wed, 12 Apr 2023 12:42:36 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C771CC01BA for ; Wed, 12 Apr 2023 16:42:35 +0000 (UTC) X-FDA: 80673307470.06.8ED29F4 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf05.hostedemail.com (Postfix) with ESMTP id C0261100017 for ; Wed, 12 Apr 2023 16:42:33 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=f6eWiZcP; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf05.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681317753; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=9VoJC4PMtOZChfNpsShin+Q92n+br8Q3f1O4OPEN8PE=; b=e16OKM0KNZMGjgxzPc8hfOy5tFCefYPc7aGBRRo5BnmgHmOw8eOCtybibiOAAjoB2CEci4 L1kY50fKa9JEXhYPjCZOqgAx6rqKPdSZsZfMakhlo1i7/BHyI/BcdhAiwVPK8BNrWcv9fw qFJmpCXUefqPjFXqQ9int525kVOxXmM= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=f6eWiZcP; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf05.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681317753; a=rsa-sha256; cv=none; b=wl984PpN2e1C9vuoWyWB/XzAMfm/5ADY+GPHeMCE6jZc+f+Zjb93XeSr6lRoMk0v+yNXpd E87NmEQ1Vmylhqvr8Gaa6qt+qbggFH19jGXF8H3LGb9V+8mltRCEOAKK7CnZ+HDMOPddYg x4/o1vdx0u/ba+LmKiQzqhcWboP10/U= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317753; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9VoJC4PMtOZChfNpsShin+Q92n+br8Q3f1O4OPEN8PE=; b=f6eWiZcPGQTMdX4Sy8cDb2AlBnfZrM/yD2w1TvIrZhKZneFjohfluRf0G2lxpcbceaKCCF nJSmS52cg0jk/ZkxINjOQIezI+4TsDaLhbjY7HPg7CRosNoGqHL/8WixATMA7rHSEpaFO7 yKhzT52FH6Adu1qAVc+sgJCBJsyC6dk= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-113-CN9vhb9oOWe0-Tx5uwLlLg-1; Wed, 12 Apr 2023 12:42:31 -0400 X-MC-Unique: CN9vhb9oOWe0-Tx5uwLlLg-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-5ef4122d2dbso1350386d6.1 for ; Wed, 12 Apr 2023 09:42:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317751; x=1683909751; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9VoJC4PMtOZChfNpsShin+Q92n+br8Q3f1O4OPEN8PE=; b=UDW5KY2Qu4d1I2xWbB+YcjDHKNecgsNUE2T0vlnW/NGJCFyFs455oOwA0oFhHaPUtt WcOlPxVidFO8hIFtE5iYUt/ll82EoQFuc3dLpF4MuZHdhw2Dp/68hvMvlbnc2mWipZSF 7RIIjNXMZjxYoG/Y3fNJ6gPBiqVDM3kMbytLG9GqIl+fs0BUy2Nz9bv1iWCSOdmgniUK OS98n5sT7Ws9bc6viHNKABr+vYJ1tw877705wBeH6SUsZ4PROgYTf8CTHJNx40K1H4nc 5FUqDoc6ixt94Fx86jbKZDWdmYBxUxtFJQ50387/tXKuNebytkmiNEiRHGpfV7fRFTL/ nxgg== X-Gm-Message-State: AAQBX9ciSx7CpvqCrF+E9fR7bSsxsAsP6m0aoQkolbN5BC9yR7dIGQ0r w9DoPfHGr8cSxc72Puum1O9yxuf6we4higxd9QF3O+CTrgCIqMd1K5F+OHooWxNf459sM2KgvcO Rdt+Cqn4M9FM= X-Received: by 2002:a05:6214:4105:b0:5de:5da:b873 with SMTP id kc5-20020a056214410500b005de05dab873mr4439628qvb.3.1681317751470; Wed, 12 Apr 2023 09:42:31 -0700 (PDT) X-Google-Smtp-Source: AKy350bKIhyvFE421MNKeiw66bcLbViwoq88DKthBLMNBPxf9F5dEOECVmGzHn09x9YPggLZEnerFA== X-Received: by 2002:a05:6214:4105:b0:5de:5da:b873 with SMTP id kc5-20020a056214410500b005de05dab873mr4439540qvb.3.1681317750348; Wed, 12 Apr 2023 09:42:30 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id j188-20020a3787c5000000b00749fa9e12e9sm4778767qkd.124.2023.04.12.09.42.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:42:29 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Andrea Arcangeli , Mike Kravetz , Nadav Amit , David Hildenbrand , Mike Rapoport , Axel Rasmussen , Leonardo Bras Soares Passos , peterx@redhat.com, Mike Rapoport Subject: [PATCH v2 08/31] selftests/mm: Use PM_* macros in vm_utils.h Date: Wed, 12 Apr 2023 12:42:27 -0400 Message-Id: <20230412164227.328145-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: C0261100017 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: fjftayifeght5k3mymtkotgu8cffe84e X-HE-Tag: 1681317753-954064 X-HE-Meta: U2FsdGVkX193mXIqy/Vh5dMAgg5VR2wqnwn7rb5a+8Qm6VM9ZuIUvoZrLZUSCAcCFq9+x6JOyEWNWZg9n1+5w8BGAwgzU0VEghNSRcz8SGEG/qpZ81612mfpO1uXz5uCgBIm9FW3IcxO4ne1/+GwPQSCrL+E9UNNyZr1DcM6TUB5YV0C+kW3k4TYOU4T7fTPWVoLtN64hNyPDABpQxCqy5pbCyyrveJ5ETWycK9OIEKarE21HsAC6hPWgSYQVo7a36e8hO/x2+y0eITnB+kDMZD5KxHZ2f/WWXR2BdFFQm0gnVR0dtqQklXeOBgBxlNMEjxFsmWEuRP2hHx9dZVxCGhF4D6bKaTxXCrYCR5ac29ugr2jWggs/TKoG1pJ9rCZVO/ET2UDza4tvi5fUthwTm81ztlk//843vO/4EIAil/RN5A/KiputYypC28MiXGDRRv1871bxteK88KHext5DEEp4tjn0JF3mhtBQSRWMbwzWy69/pYcY7j+mrimRAK2n6zJ5LN6i3T3xW7y3LGzyBFQAyOhbBQbJXcUKqzi22dbeodtAbKRwpBoffU2aNTByd0qt0MENPsNBsEGLh2JKEfGk79B5PzfTVTx5SVzfEjS8IuIRfTykbZqS8gAHRFJW5C0n9evznAhmWbZw56phyLUcfLwRnalbtcvwCeK7b7vbB7f6AM5JdeSWcEc+P8Yk7I3ehfqaH3FSRpKBjZpIkZYPHI7O1I61ZzlRkhFgJwBdLpatNHFm2SzSdHdYyN1eY08H6gKUhxFPS3OVWOX3OfUdys21ECZbJaYLY6GuYs38AZslFrgNqbrb8xGxQ/D/7ZnWFhCaQBASUcsEArfXh9Eg24l7oskf77c2V96FzIG3hydoXf/o/bv6l0/xlPe9fQO0Y8heec5tbpvxpCOpKyMx9IhKfW2sEnRNtMbLf6RD1Ky3B1t2GgPBe/APDFiBibGZNOvMGOxcC5nx1T pcUV1SYZ vZFyHNuIVQ3iDikY6S7X3fpRBq+3I8/At1NrJN+UvhsjvPvzwP2Y+q3UUDgamrmHhrNVXzFPt6taZyVsk3e3FJKMdkKAzPidPBuRrWRmQVPr7QsOF3BLywrSv7aYmHD9Srgw7jEtr+G+3dQWchYMEkBFbvXmAq9sZwLCnYKdGHuGDa1AsRKBE57SWTZjeLzZesx3b48iGoY/vCI2faD4luJ/4sIXtMNSaoUe97+rUcPHE6YLNHJAQpKNSAe81kVsGCt8tNr0zqddl06W46ra1xSp13kY0IQkP1LJLvmJzXuhWMZueK2i6WtzdrHUSE2Aq++fYboH44WFFFVvWdA0a6z9Cy/kvE8JrM9+UcjBKa6SIc2RPOMf9SyyICJb0m9lhuOvNHAETtmjO0yII6el4UMCSet6BVfp0vC+aQGR3LtCr73R8qa4CYtW/AQDzL+o8QiES/YOjlm6LkfBZTaNpUZtvLn6oHUWDquk/xwJ/gRA5ySubYT8HvCtRaYebYQUkj+9IOTydhrL6Ic8yNvQKIksw9oBHHLQQ3AE+0toE8QyPUjPaWsJJKUY3PNBwNgVaq9BTVuiW1oE3hsoFLbSeV0iBNpvmv2rt7P+r 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: We've got the macros in uffd-stress.c, move it over and use it in vm_util.h. Reviewed-by: Axel Rasmussen Reviewed-by: David Hildenbrand Reviewed-by: Mike Rapoport (IBM) Signed-off-by: Peter Xu --- tools/testing/selftests/mm/userfaultfd.c | 8 -------- tools/testing/selftests/mm/vm_util.c | 16 ++++------------ tools/testing/selftests/mm/vm_util.h | 8 ++++++++ 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/tools/testing/selftests/mm/userfaultfd.c b/tools/testing/selftests/mm/userfaultfd.c index 4cc80a0e8955..7e841f7e2884 100644 --- a/tools/testing/selftests/mm/userfaultfd.c +++ b/tools/testing/selftests/mm/userfaultfd.c @@ -1389,14 +1389,6 @@ static int userfaultfd_minor_test(void) return stats.missing_faults != 0 || stats.minor_faults != nr_pages; } -#define BIT_ULL(nr) (1ULL << (nr)) -#define PM_SOFT_DIRTY BIT_ULL(55) -#define PM_MMAP_EXCLUSIVE BIT_ULL(56) -#define PM_UFFD_WP BIT_ULL(57) -#define PM_FILE BIT_ULL(61) -#define PM_SWAP BIT_ULL(62) -#define PM_PRESENT BIT_ULL(63) - static int pagemap_open(void) { int fd = open("/proc/self/pagemap", O_RDONLY); diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c index 7ffad87aa7e8..54d227d6f70a 100644 --- a/tools/testing/selftests/mm/vm_util.c +++ b/tools/testing/selftests/mm/vm_util.c @@ -25,25 +25,17 @@ uint64_t pagemap_get_entry(int fd, char *start) bool pagemap_is_softdirty(int fd, char *start) { - uint64_t entry = pagemap_get_entry(fd, start); - - // Check if dirty bit (55th bit) is set - return entry & 0x0080000000000000ull; + return pagemap_get_entry(fd, start) & PM_SOFT_DIRTY; } bool pagemap_is_swapped(int fd, char *start) { - uint64_t entry = pagemap_get_entry(fd, start); - - return entry & 0x4000000000000000ull; + return pagemap_get_entry(fd, start) & PM_SWAP; } bool pagemap_is_populated(int fd, char *start) { - uint64_t entry = pagemap_get_entry(fd, start); - - /* Present or swapped. */ - return entry & 0xc000000000000000ull; + return pagemap_get_entry(fd, start) & (PM_PRESENT | PM_SWAP); } unsigned long pagemap_get_pfn(int fd, char *start) @@ -51,7 +43,7 @@ unsigned long pagemap_get_pfn(int fd, char *start) uint64_t entry = pagemap_get_entry(fd, start); /* If present (63th bit), PFN is at bit 0 -- 54. */ - if (entry & 0x8000000000000000ull) + if (entry & PM_PRESENT) return entry & 0x007fffffffffffffull; return -1ul; } diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h index d7163fff8fb7..d9fadddb5c69 100644 --- a/tools/testing/selftests/mm/vm_util.h +++ b/tools/testing/selftests/mm/vm_util.h @@ -6,6 +6,14 @@ #include /* ffsl() */ #include /* _SC_PAGESIZE */ +#define BIT_ULL(nr) (1ULL << (nr)) +#define PM_SOFT_DIRTY BIT_ULL(55) +#define PM_MMAP_EXCLUSIVE BIT_ULL(56) +#define PM_UFFD_WP BIT_ULL(57) +#define PM_FILE BIT_ULL(61) +#define PM_SWAP BIT_ULL(62) +#define PM_PRESENT BIT_ULL(63) + extern unsigned int __page_size; extern unsigned int __page_shift; From patchwork Wed Apr 12 16:42:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209345 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 13D71C77B6E for ; Wed, 12 Apr 2023 16:42:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A2DC3900005; Wed, 12 Apr 2023 12:42:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9DE1B900003; Wed, 12 Apr 2023 12:42:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 87EA3900005; Wed, 12 Apr 2023 12:42:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 789C7900003 for ; Wed, 12 Apr 2023 12:42:40 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 32ACE1C4843 for ; Wed, 12 Apr 2023 16:42:40 +0000 (UTC) X-FDA: 80673307680.20.024F34B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf03.hostedemail.com (Postfix) with ESMTP id D803320029 for ; Wed, 12 Apr 2023 16:42:37 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=BGIYY+ha; spf=pass (imf03.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@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=1681317757; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=WqDS6jtSapL9ifdeK9em1EDp4bv+6WCKRXbZ+q/xf6g=; b=Ym+wO7Ac4e/f62W0zbepnBypkQVG3WlZFv+0wso9PYVjxodmuIxXkZ9knziYkY/np2LTn6 yfh7OBSDPGioJ3KZuOuAlmUEuYQMvZPGvbdCzxDS/JWlWWAM5UVRXeFEAvdtTgUKsAd15V alberqDyaP6IU968M+B7pw+vhZNZ0SM= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=BGIYY+ha; spf=pass (imf03.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681317757; a=rsa-sha256; cv=none; b=CuO2lLF/9fBoL9/MmLS9FPl+B5DMFKyhiXHbOpB58xkoCpPD3U5SEam++0Bv2Xqg3kJ58j NxbM5C2IADoph/6nrOzA08pWs7O+ak0xkCI6GC0ZcQ/PkXrZBwZYnlbHclijxhcfTYN1R2 AjU6RabLSSuY+IEzxFHrv/hmCHU6Sh4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317757; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WqDS6jtSapL9ifdeK9em1EDp4bv+6WCKRXbZ+q/xf6g=; b=BGIYY+haPKQQBmcVZwQQSV0OOhzkr1h5L3iNSCZdqmETRyH9DzjGaICsXzrwawl1w6geju Rw1qjGk5pMSfbTfo9TE0t3to8bFj6j3dYThVBQY2kEl7yAnDjUGxHl4ulieOQuJL7wlJxK FCR6/UbPqX0va4JOeAviOlj2p7E+/eg= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-80-5O1tfVcZM1GN6F5FFHZAKA-1; Wed, 12 Apr 2023 12:42:35 -0400 X-MC-Unique: 5O1tfVcZM1GN6F5FFHZAKA-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-74a65b255beso53900585a.0 for ; Wed, 12 Apr 2023 09:42:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317755; x=1683909755; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WqDS6jtSapL9ifdeK9em1EDp4bv+6WCKRXbZ+q/xf6g=; b=bTLfD22BPV5O13/yMJ2CMau7/ZCOibppD+Hgkn+ff4kJKT+bzXJUt+MEzONpC/72GI DuEf8tj6wi64dqkb0M7ONhugUXwdtK+J97tyUp3CnxNGcuytIv4l68e9w5oty4qk1RFO aZCBvT/8japFzycSf21iBMQ/09l0falcOWK7vU6aO71qLz+acEWSVRdo6krDsBhXLCGc ieQqCe3/UaEBt0LfNAsJaK2TroLQ7C81stx0InjdTR+/FnPwsz/GDE4fJcnEZ+55VLB1 hX0nHG6m28G1lrzhT28M9fSEDu6hgBiXCjZ8Q+iqfxcN8balx8RUP1pf0BM6cuqyf8iw Mdvg== X-Gm-Message-State: AAQBX9duHU33jRXv1wdrlbshXnU9eizRq0z9O7Ud5oF6L1Bbs8LBorq4 vJqMVbOy1kE/2wlvlLKV3/MM6/QuqjAyUbcsIR44CTQBiTyU2K8lVWjyWaOow7wbq9jzL4QB8OS WogH1KUkOaJQ= X-Received: by 2002:a05:6214:4002:b0:5ac:463b:a992 with SMTP id kd2-20020a056214400200b005ac463ba992mr4597598qvb.0.1681317754971; Wed, 12 Apr 2023 09:42:34 -0700 (PDT) X-Google-Smtp-Source: AKy350ZccWUkGHYWZ2bzm1zWaJsqlvJFElNocxXwtSRv3N+papWfiGQIPvLDwhR7/K1RnRC+7EOELw== X-Received: by 2002:a05:6214:4002:b0:5ac:463b:a992 with SMTP id kd2-20020a056214400200b005ac463ba992mr4597570qvb.0.1681317754674; Wed, 12 Apr 2023 09:42:34 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id g14-20020a05620a218e00b0074a25a59667sm4749109qka.115.2023.04.12.09.42.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:42:33 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Andrea Arcangeli , Mike Kravetz , Nadav Amit , David Hildenbrand , Mike Rapoport , Axel Rasmussen , Leonardo Bras Soares Passos , peterx@redhat.com, Mike Rapoport Subject: [PATCH v2 09/31] selftests/mm: Reuse pagemap_get_entry() in vm_util.h Date: Wed, 12 Apr 2023 12:42:31 -0400 Message-Id: <20230412164231.328157-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Stat-Signature: 5geg5194j7pmxjrt968ajir6eskjkzou X-Rspam-User: X-Rspamd-Queue-Id: D803320029 X-Rspamd-Server: rspam06 X-HE-Tag: 1681317757-435925 X-HE-Meta: U2FsdGVkX1+iys3PMjp1azmp8SWPnIVwQ7z2DfRksGTGxYppsDUjD98GNboBEt4d6aVzYlhODNRJllMulHNIOQn2ZWPccGFzag8pm2pVKMw+7N5VjNdVbqvlJwEMRN3abMTuhaEUldNj43ozxmIERIXdugrVzssJx6ahF1G1sc8mW1pZ8EL5vZ1cMKmhaliac40TngkfzK/+C1ev9jD22T4lVYlOB2wtqotq6/sqSAIgAV+aua3Q75yAqxE+6V+MS4kDsVmYlu0MpgYwq6RVAfwoYr3kI/jGjcMMk1LwxoQN7KAkaxzhapG5bPZF5O6mPhuUOsCgz9ZXxVBdex+igq08S4Xxh8SpLUwyg6qvwWSDF4bff2ShSdwE0ZsWrODfWSA9WnWYY1lPmYWs8KNdW9qdSyLVQJedlDcGHF/WPz5/hii5WLRfprtdKosjTHychpK+CPR3f53bhTvg1XOMrA8gdBi9pgqjYSsrerbrzEAS2myAvyTKi45J/Hid+pL+MDGq4c9maKAeDWLW0rTdvqzAWeXXugC/7msNWVSLDJbT7K8XlMjqKKIzNjxbFilkTnxDBPcgW3ptAJ1zaoXsy0CepHPKDrmTiDJYp4ywpTxM6cx4a1oQwSNKlWz+K8798GaQ4FUH7qCSWwxe5IAulbLHkDbO2z2TMaZmxONIz2lP8yXXkKvJ/K1XDRUjkV5qa+M8NAYscGwPdhEaXj+I/s/T9Ub1iaS01+xMryGBYDAixG9znxD/QU3pC94ByiQFuH7jZz7oG7qcpAF8GnX008OEizO0/QeqUkFvkXtRx1NJ0vdIP6TNe8sOzPstBAS2nkorDyaePWYcvBkCyLalNK3Dq83uAcr1JI13MzhxuJCmoiv13ieOtJFQT+P9Na4eC6Z+Qz4efI+AUn4dm4TCYjEF0RQfSuSzb34l/Y8GYFWTneDL/HboUQ4OQDhp/sEKO86vRyAf+PWgsPSEp+o aJVv0oa6 ITs6//CL3OAcYSP+o+jmVMPkG0sklCMS7OfgQAdVJXvqRYS5UwDXIg9Y6rY7HGD4YpygwLafrReHVNtzbSmwt22MLexYw/5xqweLFN+IlYqbF3aZpPfhg6AXiiWM/gAyMBSoaDQcCcLO/Gcc9ipmF/U+zWyzHX3O7YAn+mjlkZWM5H1Zjzcns5hGQWirRoyZbgdhtY0rgXGxi0Uz+yTX1hvmQVgRB10nz/Pk/QXQO6VK1Z67VNRsBk4NVnp5joN+IPBcex+HNVHc25Ptofa/aohOq860soEl4VWW8jW3clWUa/N+W78C3dNtTN490RmejQYRgx9uruDSlAhC6oIWUrfNmfwHJv77oXcDPhoy9FimPqHrfUPMyFmEDU/O+lhZ3Lfe0NdQypHe3eLKEajEWlHTL/CjYgEipuObUH9RilaJ2OJKlZ++Vh+lnjPG1ecIgV+vfH23Zc+zEmJLwXtq8tiOKem/ZWj/ZAIvOQ4GlKyyWdN/VHWBE6cQXaP0wJvq9gYGvDKk1aMD4Gvz2xhvrKWoer7xFLmrU6+BN7rfjJrO9RFiqsuNTnRwgdIGL+rc5XXg9ZczswZxN6dPdvcV1eco8qNEVS+DtbDCX1UXsXdPUmf/uo+ADOAzPHA== 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: Meanwhile drop pagemap_read_vaddr(). Reviewed-by: Axel Rasmussen Reviewed-by: Mike Kravetz Reviewed-by: David Hildenbrand Reviewed-by: Mike Rapoport (IBM) Signed-off-by: Peter Xu --- tools/testing/selftests/mm/userfaultfd.c | 31 +++++++----------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/tools/testing/selftests/mm/userfaultfd.c b/tools/testing/selftests/mm/userfaultfd.c index 7e841f7e2884..795fbc4d84f8 100644 --- a/tools/testing/selftests/mm/userfaultfd.c +++ b/tools/testing/selftests/mm/userfaultfd.c @@ -1399,19 +1399,6 @@ static int pagemap_open(void) return fd; } -static uint64_t pagemap_read_vaddr(int fd, void *vaddr) -{ - uint64_t value; - int ret; - - ret = pread(fd, &value, sizeof(uint64_t), - ((uint64_t)vaddr >> 12) * sizeof(uint64_t)); - if (ret != sizeof(uint64_t)) - err("pread() on pagemap failed"); - - return value; -} - /* This macro let __LINE__ works in err() */ #define pagemap_check_wp(value, wp) do { \ if (!!(value & PM_UFFD_WP) != wp) \ @@ -1427,7 +1414,7 @@ static int pagemap_test_fork(bool present) if (!child) { /* Open the pagemap fd of the child itself */ fd = pagemap_open(); - value = pagemap_read_vaddr(fd, area_dst); + value = pagemap_get_entry(fd, area_dst); /* * After fork() uffd-wp bit should be gone as long as we're * without UFFD_FEATURE_EVENT_FORK @@ -1446,24 +1433,24 @@ static void userfaultfd_wp_unpopulated_test(int pagemap_fd) /* Test applying pte marker to anon unpopulated */ wp_range(uffd, (uint64_t)area_dst, page_size, true); - value = pagemap_read_vaddr(pagemap_fd, area_dst); + value = pagemap_get_entry(pagemap_fd, area_dst); pagemap_check_wp(value, true); /* Test unprotect on anon pte marker */ wp_range(uffd, (uint64_t)area_dst, page_size, false); - value = pagemap_read_vaddr(pagemap_fd, area_dst); + value = pagemap_get_entry(pagemap_fd, area_dst); pagemap_check_wp(value, false); /* Test zap on anon marker */ wp_range(uffd, (uint64_t)area_dst, page_size, true); if (madvise(area_dst, page_size, MADV_DONTNEED)) err("madvise(MADV_DONTNEED) failed"); - value = pagemap_read_vaddr(pagemap_fd, area_dst); + value = pagemap_get_entry(pagemap_fd, area_dst); pagemap_check_wp(value, false); /* Test fault in after marker removed */ *area_dst = 1; - value = pagemap_read_vaddr(pagemap_fd, area_dst); + value = pagemap_get_entry(pagemap_fd, area_dst); pagemap_check_wp(value, false); /* Drop it to make pte none again */ if (madvise(area_dst, page_size, MADV_DONTNEED)) @@ -1522,7 +1509,7 @@ static void userfaultfd_pagemap_test(unsigned int test_pgsize) /* Touch the page */ *area_dst = 1; wp_range(uffd, (uint64_t)area_dst, test_pgsize, true); - value = pagemap_read_vaddr(pagemap_fd, area_dst); + value = pagemap_get_entry(pagemap_fd, area_dst); pagemap_check_wp(value, true); /* Make sure uffd-wp bit dropped when fork */ if (pagemap_test_fork(true)) @@ -1536,7 +1523,7 @@ static void userfaultfd_pagemap_test(unsigned int test_pgsize) err("madvise(MADV_PAGEOUT) failed"); /* Uffd-wp should persist even swapped out */ - value = pagemap_read_vaddr(pagemap_fd, area_dst); + value = pagemap_get_entry(pagemap_fd, area_dst); pagemap_check_wp(value, true); /* Make sure uffd-wp bit dropped when fork */ if (pagemap_test_fork(false)) @@ -1544,12 +1531,12 @@ static void userfaultfd_pagemap_test(unsigned int test_pgsize) /* Unprotect; this tests swap pte modifications */ wp_range(uffd, (uint64_t)area_dst, page_size, false); - value = pagemap_read_vaddr(pagemap_fd, area_dst); + value = pagemap_get_entry(pagemap_fd, area_dst); pagemap_check_wp(value, false); /* Fault in the page from disk */ *area_dst = 2; - value = pagemap_read_vaddr(pagemap_fd, area_dst); + value = pagemap_get_entry(pagemap_fd, area_dst); pagemap_check_wp(value, false); close(pagemap_fd); From patchwork Wed Apr 12 16:42:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209346 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 B2C15C77B6F for ; Wed, 12 Apr 2023 16:42:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 52508280005; Wed, 12 Apr 2023 12:42:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4D468280001; Wed, 12 Apr 2023 12:42:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 327C5280005; Wed, 12 Apr 2023 12:42:43 -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 2422E280001 for ; Wed, 12 Apr 2023 12:42:43 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id E5AAFC01B5 for ; Wed, 12 Apr 2023 16:42:42 +0000 (UTC) X-FDA: 80673307764.22.84ED826 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf19.hostedemail.com (Postfix) with ESMTP id D77E51A0028 for ; Wed, 12 Apr 2023 16:42:40 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=VCcS3nYD; spf=pass (imf19.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681317760; a=rsa-sha256; cv=none; b=o77ugXq2s1kYjy+BNw5d4YZRCTBnQ9ee2dXRru0nl5ZMZkna8oYSWI9HIhhmbp7/vGm/TU 5aQD2aOIlLZy1BW3B9i02GU93szJG173ZVLcV5tx/CVNpjidNRWybvT5j04JkPVieHjndv soOqrzSBZXcEPIp89GrkMggywx6neaY= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=VCcS3nYD; spf=pass (imf19.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@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=1681317760; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ASfRfnQJTCdEglytu7DR/J7BYjWDsPlfNboYF8myg6I=; b=tI7rcaC4eNMLZ1GEtZTSqdtCm9dCIXlIql8oKSufpVOvbpZ0tOR0UVkC2bhdmjZzrbTw7A rRu2YJTXEhcipkXd/6sXy9DeDUFciGy//rmmzKkJK7JLnfh7lHmMWtpYG+XRuAINcztshO sstZpD9D+AZWXBpIBnfWSEf74epJEAc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317760; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ASfRfnQJTCdEglytu7DR/J7BYjWDsPlfNboYF8myg6I=; b=VCcS3nYDR9nmsZgRmzBl+Gwvu4KYnrjHIhGCa9duetgvxpaamht35p/uplnaVNUmjnHN3C qqGiPu7Vw6usS8o7fYKyByZZPdJXCi/AwL6RslR29P6yNhRT+hp9mIf8QCL3W7w0w5pRSe DEFysHBvjC5qOOtnbtZNpI92GENXFW0= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-501-n7c1JeUHMQquATxHDTOZJA-1; Wed, 12 Apr 2023 12:42:39 -0400 X-MC-Unique: n7c1JeUHMQquATxHDTOZJA-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-3e699011c0eso995241cf.0 for ; Wed, 12 Apr 2023 09:42:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317758; x=1683909758; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ASfRfnQJTCdEglytu7DR/J7BYjWDsPlfNboYF8myg6I=; b=DPj7+Lk77TDU5OIDH6Km/ToSj1OP24PW5IOiOJKTkqf5lgMkDp1G5QEJWnoFKv1nqh iWUNc1Jojqcbp3T1c1w0bzQ0r9wXsdmZKvPUYByhNebCeysPxEmjEDD7jdgqCcpOqRsh qkuomCAKyLv5p1qZa2lQeDpTxkmFz//lv13sJMjnoWgqClxA0IpUjKg2txgq7O9gKyLf tKncXSqx3vgjnTajlzZMKFlo6duo1o3vI+59xqhvQiDnJYregqCOIaMrS14S/oa8xti0 BPF36f/2mDCCjIvs1/TKFI3DGyVQHEiUbMIlhe+elxr1kC9Qav5HyjE5g1t8EvKM4s1x /xUw== X-Gm-Message-State: AAQBX9fXZBDOcssmCtGTIlsyWVIva4S1/7hvJGGavTI/3ARlD77/wDkr wLnuD4OEaVN4OmlUincmM7nchRrSFdppM3v/dscu8WXgNyH8mkHWYIdnYvHIxvWWMsYNvKN5Hwc 7wqj5X/t2V2o= X-Received: by 2002:a05:622a:1a16:b0:3e6:30c4:656f with SMTP id f22-20020a05622a1a1600b003e630c4656fmr31834191qtb.3.1681317758464; Wed, 12 Apr 2023 09:42:38 -0700 (PDT) X-Google-Smtp-Source: AKy350Y20Rk7NxXI1ENaDroyw/86rbNj0zbsfBVSdikymF4/GfJyJsnmj2oK5V1sNnQfT5FqPQ8k/w== X-Received: by 2002:a05:622a:1a16:b0:3e6:30c4:656f with SMTP id f22-20020a05622a1a1600b003e630c4656fmr31834180qtb.3.1681317758231; Wed, 12 Apr 2023 09:42:38 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id g26-20020ac8481a000000b003e38c9a2a22sm4334704qtq.92.2023.04.12.09.42.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:42:37 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Andrea Arcangeli , Mike Kravetz , Nadav Amit , David Hildenbrand , Mike Rapoport , Axel Rasmussen , Leonardo Bras Soares Passos , peterx@redhat.com Subject: [PATCH v2 10/31] selftests/mm: Test UFFDIO_ZEROPAGE only when !hugetlb Date: Wed, 12 Apr 2023 12:42:34 -0400 Message-Id: <20230412164234.328168-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Queue-Id: D77E51A0028 X-Rspamd-Server: rspam01 X-Stat-Signature: 8w69efidkhwsjdd6soap8cu5jrcgky9j X-HE-Tag: 1681317760-730870 X-HE-Meta: U2FsdGVkX1/yS3b+o7WUapN2yQ1qPgIwWXFZvShHZnL9FsAI6ZpgrZ4ny3nyUrqPyNbHu3PwXx0WVuQyH++95DgrmlvrpgJ2xc3qCALEmVPpshn1N7u+aI5w93KDlz+686v2Dry/fEsxM9hL7CJP1IBRPkeoBep17yJLfnVd9Dw/FR0ASaa10wnuuTXArYF51ULMZkNmTa639kQyspUDN+ZCxKuxbvxfIeoxWyDi0Q/qPR/M7L1p12kuT8QXhG3nX0uwNfq3LJsK5NhcgJMi600NUclTRc0IXQCwG6F8/Pb2kGPS5MqMTNGZrq1sv6SyYsAnPDMO9SViU+TecFaC63JrB+OiIiq60y4MdN78z25+WFSkMsfMBqGK018Zw8WU5uTxkfTYf+VZFoHxs+rliA0NGkKjbBkmbeUTR1ASzD0PkHw6Rq0+ro1fnb6PqHIk6l8rEoFS/R+oKPi6XujS32NP34dgbQ05TXgbv88jXkKUo1ugjJPzKPWW2L9IxcW/q5fV1R1OrZ6Z3TNJ9J5+TsLiLZGoYStDMt6MgFRCriRANoCDg2aIG7NJ8xpDFfnkRNBF/QG+26i5BS073wHJ30kU7Gfm98KI+xCW6dvp/EAG5hYxy6R6Ke4SlXktaYX4/TUr5NeWGWi8zWeUyR01SDsLIIpijeAkJt5UVXeXh7Vb3fr79xpWmzvVF+qZTJJzk7nZqZ4EkxhDHqxLeTaY3bKhRB4ID8OvcH2XCIsrV42Kn1eQzy6i4P36j3e7gMMpnGrJO017Prv8IdVyMRD6h1rI2sD53ZpQpUSxySOAVYUh3tWhyausuQD29KqjPJEEt8yMzm2BHmSYa41HmJEjOZUuVewRQ0+Hk9JLRUUY6g94Aa9wflPHU3jS7VxmXUg63xBH7//qWHh6O7Xbv+P0NDm9Uf0wF+7NtK4KiET1N4TgSTL4/4IXE50Bbjgrb7FoXyOllFPsr35ZBWT3gWN YJQdisf2 YRcMzRODupWnShhmWOAecXMsiBdBFVw3J/TPd9X1Gqy+/fnw8NKamUicGZpxSERH//4VFthMAnTn4cX+5QgN8Jh2IyVVJINCrYwalxMonezEZb359ny6Ap4AeRCTXieL+Tgk6bED9N0UazfSWhEDR+37h8Q4hPsafo5t16JDfuFtVXt2e6e8awK09x88imcroAgwsYgkNmaBY7kdxT+XvWEag8FIk6y84ZFmqy9vnJZ96dkJItiPdt3Ztol0eecuBRcTrw06pb9ofjlqDPtsojh4HBWiwfScKLkrWFxNRd/q4cKFk+yqR2abuJk3IV3IaiM9d5HTk9bJ6MhPZqa84IvraRqs6sTPhaJmhjgT4ZyGkEpX1Oam5Qoq7HzwNrB6ZVkZColitMIcs402VkFDOWOXzVVBWXRZH1fKrBOBfAQ5AdWtPpPoIeMqinZrQ9Jc4GSMtkwru0uE0emAvY2Bx7E11flUOYbXCMpOb/kmAgr3P751ckXslyn+gH5jXUzoMJyVx5ZTliYxkGorVqA0VIIEIPkTvecXO+pc5Pzw/uZa17R0QBxgVQy6mQA== 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: Make the check as simple as "test_type == TEST_HUGETLB" because that's the only mem that doesn't support ZEROPAGE. Signed-off-by: Peter Xu Reviewed-by: Axel Rasmussen --- tools/testing/selftests/mm/userfaultfd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/mm/userfaultfd.c b/tools/testing/selftests/mm/userfaultfd.c index 795fbc4d84f8..d724f1c78847 100644 --- a/tools/testing/selftests/mm/userfaultfd.c +++ b/tools/testing/selftests/mm/userfaultfd.c @@ -1118,7 +1118,7 @@ static int __uffdio_zeropage(int ufd, unsigned long offset, bool retry) { struct uffdio_zeropage uffdio_zeropage; int ret; - bool has_zeropage = get_expected_ioctls(0) & (1 << _UFFDIO_ZEROPAGE); + bool has_zeropage = !(test_type == TEST_HUGETLB); __s64 res; if (offset >= nr_pages * page_size) From patchwork Wed Apr 12 16:42:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209347 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 0ED3BC77B6E for ; Wed, 12 Apr 2023 16:42:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9B8CA280006; Wed, 12 Apr 2023 12:42:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 968A2280001; Wed, 12 Apr 2023 12:42:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8094D280006; Wed, 12 Apr 2023 12:42:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 713D6280001 for ; Wed, 12 Apr 2023 12:42:46 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 527CFC0159 for ; Wed, 12 Apr 2023 16:42:46 +0000 (UTC) X-FDA: 80673307932.13.261A154 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf19.hostedemail.com (Postfix) with ESMTP id 259331A0021 for ; Wed, 12 Apr 2023 16:42:43 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YL0AxIK7; spf=pass (imf19.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@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=1681317764; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=1TTsACSLiRja1XbqXldcznrpQfU/7XLsecI/fn7kMpU=; b=uRGyzeQKX1+Gj3goOMmHZ/O4ZY8bdt5nbBFiLCST6EzpEHlq/Q1sKgxWZAvaga4Xbn/SZT b9VEek2CTepgVt+8D0dmkNCfboK8uv3Z//DHdCrrTF95ViXb73CTzMOZhrqFSBekVuc1NG VZk0MsXZbUQNyjuOa3xVnAtPyDlDrAc= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YL0AxIK7; spf=pass (imf19.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681317764; a=rsa-sha256; cv=none; b=Q4sy6PgLdXDs8OXBtg6RbCrIt5e+FzjIwmhSONqdf3STOxajtP4zR/39F3PR6wdMi4aRDn su6ej1T3Gb3HSrjqZMXrSBT1Ci4eMtDpLX7d3d7QM4jKUQvdqLSs0xnahG2hnZ16ZBE2nq nSwzzWydb7bm158HYOLOotzfdSQxCrw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317763; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1TTsACSLiRja1XbqXldcznrpQfU/7XLsecI/fn7kMpU=; b=YL0AxIK7cBppSQ2s0I73bkAnUabf3cAzXss8/lbKNyhWq9AYs15QKbKR5ryIhwbCzXmEov jq5fea688DahipUX2T9GyQzBUKeiekpK0nvpLPMYSH9YIgM+5dbADjc+GeL8J5CuUcSYff V0XEZKj21JqkcTopdfYm7JzYu9dhk+c= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-193-wRBJIVOPP_2_LIfn0UB4-A-1; Wed, 12 Apr 2023 12:42:42 -0400 X-MC-Unique: wRBJIVOPP_2_LIfn0UB4-A-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-74a25fcda05so77598885a.1 for ; Wed, 12 Apr 2023 09:42:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317762; x=1683909762; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1TTsACSLiRja1XbqXldcznrpQfU/7XLsecI/fn7kMpU=; b=ErrvlNkoDJdfHq6S7vOoq6whFSu3jOhqaVIstf/GR27TPyQEUu7bD6fWirfRn7WtKM 6yM7ZS4D0x4V81rMdFxVAhXL2IR1SA+zXrdAyqz3vRLSdR/GNcEhjOftPwDpKbjUqTXH wvSctg+qGDKgMpgoCPYBKipjxo9PM6d1wEi9jgv2lamipcggKZ0IkELo8/OnJtmNZNMr vJFw3nnaIo153gqilxK2eg72PSTIYszfzlozq/BwdFNvERgcOTZtTWi61Wut5PvKg+Nc j5Ut8yTDnfzUIcZHWMB/ek1cZhhJ/iCU2jXHPOLx93KuG78iyHzOJsjvZeCJJe+DFSED NN7w== X-Gm-Message-State: AAQBX9eWWQ9Y1wRfHnh1CUvXOMmQCnfWfhgJQ8L8gv+MymhuZlCxKnrQ Sb+Xb6dj1w8tdG8z4LAhYQbGZHJ/OgNSexU2B7VAr6dNSz0j7p5lg3xPBMccwKfgwdA65TaebJP GOPox4NXA7KY= X-Received: by 2002:a05:6214:5192:b0:5e8:e6ac:591a with SMTP id kl18-20020a056214519200b005e8e6ac591amr4458276qvb.2.1681317761899; Wed, 12 Apr 2023 09:42:41 -0700 (PDT) X-Google-Smtp-Source: AKy350YBsQS6JYJjxqfbIX08K5h2eIXR2P+DncIxdAAKOWLtDWxM+vNCtIyUP4FvBHNvZ8jfexZ/kA== X-Received: by 2002:a05:6214:5192:b0:5e8:e6ac:591a with SMTP id kl18-20020a056214519200b005e8e6ac591amr4458247qvb.2.1681317761589; Wed, 12 Apr 2023 09:42:41 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id mf18-20020a0562145d9200b005dd8b934579sm3676547qvb.17.2023.04.12.09.42.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:42:40 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Andrea Arcangeli , Mike Kravetz , Nadav Amit , David Hildenbrand , Mike Rapoport , Axel Rasmussen , Leonardo Bras Soares Passos , peterx@redhat.com, Mike Rapoport Subject: [PATCH v2 11/31] selftests/mm: Drop test_uffdio_zeropage_eexist Date: Wed, 12 Apr 2023 12:42:38 -0400 Message-Id: <20230412164238.328238-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: rey5fagubkef8txbx1u4eay8bdpx7fz1 X-Rspamd-Queue-Id: 259331A0021 X-HE-Tag: 1681317763-998856 X-HE-Meta: U2FsdGVkX18m33q/q4GqfMLG31B9V1BO/5S65TQcqWUplVLgoAm+X1OujgwaHr/s/q6F5uX+VTCd06rSvx57IvU6/FNaxEo2NIvvTk/klr6X7a14rEgDdEmgcSi8tpaR+OPCNwanbwGHafL2vkZC1kC/3LidEowCmsBN7DTeHYyfhub+lVgBdrDiRsMsW2NxGGNhx2Aal+kLQtI1UK7wOyXMNuFf68iPkCI7QbISez8W7wQvT7E+UAQJHM9mSkCUwRVrNsmQQMJcm2CJ+/fO0em0OIEfBEU4hpeV6LpPhrrQN8t405S6MrV28TVdKllPkIbsE4iXi5+wiOLG4f0I7v8B5PHWS33huPHw0WqG5DGOGUpnn3KHPy2fREwjLgUZr2or9t03iRlMmBcWa7rpN6Iu8EGNofXGQvUTNAVKvCMbUH1heNn/nQyukTkbRyTyc4PK3UibrxVKlc9lIh20TzBVm0RuXeOCVAKHC35TYR4yhUJW2TaStJONY8XxEefThTfWAy9hysBunz6ZM0g6zJ4mKZdD4gzRt8UvKVBKoj3CMi3WSRL3UcvTdM2cShYKO4KgpnIgr2osMOyxiiZH/oY6uzKvPKItz3a5FkEVNl7b204yFULr9dqiZDHFH8SF0ruxXZFWKjfxJg8vfux3NVrwzQwk12M+lGlV1HuqSMxrBwJtxE8xUKg02dQvQpq63n3lTVJZprGZ1Xlnh+5sJKOlEHseopJ9al2/oY2heqckeux7+boO8uRl2rzDoSZm36CrjMQjNZkCh5eIOYmioADAVR2V+egbOA7VNGM5vRqKT9gSWLx/l4ZLu8y/UqKEDLBhkb0YTTdXsEoWg/J3CsxbGcivBemC4osQyEFQjhtPRw7C3f7dEZnJeORa/N3c96pm2CWdwsfmVuWDOfYuioJZbnBDSlNPfoZdvnli3M48JknAKlfCei44fI5VDV6EouF1iSjje1YCFJQh1cD 9vwTKQKc cbNZiYNh0XM8XmpHXdzil1/8CFdaCSiqmrCT6VXXSbjq8QqoN0d1rJQnbiAO2RByLjwkEFJo+buabw/YKNtb35EJfVFog32LBwdWuI0Bqx9x+ZEBC5BcJzwBbjktlgTT/RW5rsQ+zfZKO+sIu3iJknx0aSx0WvrPJ/jM8ouW2Mepq0eOUZSnGgbl0mvoNDcI5T1Cac3cmzIIbe5nRr+2JW7vZKiFG2BT0vXYjhKvs3+80+t+W7Shwnt6jqa3XEf63CvHCzFljPoErPhUcwvRyjTPj3lluqZ54UeBOIhNA5xmkB0MGX3iyBru5W5lRS5gidQR6hga1xFD1GJG3tvj/eV7A8B9bmkJmBjFfBS3/pbg31aX+3P8bS28sd1kxLlL6kUNgOGXpS9JU6vc2A87RxnAFj1DSQkZ/dGs1M5IIQtHxpQCMceFZKsx2cH7QOkhOMD+eiU4oZ06m5l1mMySq8IuI9Jb2Z88avqSfeI+SRLWdD+u7DIztr0J+5OUbklpb92WFToYzvWxYt/umW+KvaGUdnzd8Sds4E93y3ukGlqHPbLLRfdHF+tzZdVndM9cCMtwSuGEznPKhbB2x0L8afSYuvqdrV5YnC9vw 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: The idea was trying to flip this var in the alarm handler from time to time to test -EEXIST of UFFDIO_ZEROPAGE, but firstly it's only used in the zeropage test so probably only used once, meanwhile we passed "retry==false" so it'll never got tested anyway. Drop both sides so we always test UFFDIO_ZEROPAGE retries if has_zeropage is set (!hugetlb). One more thing to do is doing UFFDIO_REGISTER for the alias buffer too, because otherwise the test won't even pass! We were just lucky that this test never really got ran at all. Reviewed-by: Mike Kravetz Reviewed-by: David Hildenbrand Reviewed-by: Mike Rapoport (IBM) Signed-off-by: Peter Xu --- tools/testing/selftests/mm/userfaultfd.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/mm/userfaultfd.c b/tools/testing/selftests/mm/userfaultfd.c index d724f1c78847..3487ec0bfcc8 100644 --- a/tools/testing/selftests/mm/userfaultfd.c +++ b/tools/testing/selftests/mm/userfaultfd.c @@ -88,7 +88,6 @@ static bool test_dev_userfaultfd; /* exercise the test_uffdio_*_eexist every ALARM_INTERVAL_SECS */ #define ALARM_INTERVAL_SECS 10 static volatile bool test_uffdio_copy_eexist = true; -static volatile bool test_uffdio_zeropage_eexist = true; /* Whether to test uffd write-protection */ static bool test_uffdio_wp = true; /* Whether to test uffd minor faults */ @@ -1114,7 +1113,7 @@ static void retry_uffdio_zeropage(int ufd, } } -static int __uffdio_zeropage(int ufd, unsigned long offset, bool retry) +static int __uffdio_zeropage(int ufd, unsigned long offset) { struct uffdio_zeropage uffdio_zeropage; int ret; @@ -1138,11 +1137,8 @@ static int __uffdio_zeropage(int ufd, unsigned long offset, bool retry) if (res != page_size) { err("UFFDIO_ZEROPAGE unexpected size"); } else { - if (test_uffdio_zeropage_eexist && retry) { - test_uffdio_zeropage_eexist = false; - retry_uffdio_zeropage(ufd, &uffdio_zeropage, - offset); - } + retry_uffdio_zeropage(ufd, &uffdio_zeropage, + offset); return 1; } } else @@ -1153,7 +1149,7 @@ static int __uffdio_zeropage(int ufd, unsigned long offset, bool retry) static int uffdio_zeropage(int ufd, unsigned long offset) { - return __uffdio_zeropage(ufd, offset, false); + return __uffdio_zeropage(ufd, offset); } /* exercise UFFDIO_ZEROPAGE */ @@ -1177,6 +1173,13 @@ static int userfaultfd_zeropage_test(void) assert_expected_ioctls_present( uffdio_register.mode, uffdio_register.ioctls); + if (area_dst_alias) { + /* Needed this to test zeropage-retry on shared memory */ + uffdio_register.range.start = (unsigned long) area_dst_alias; + if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register)) + err("register failure"); + } + if (uffdio_zeropage(uffd, 0)) if (my_bcmp(area_dst, zeropage, page_size)) err("zeropage is not zero"); @@ -1763,7 +1766,6 @@ static void sigalrm(int sig) if (sig != SIGALRM) abort(); test_uffdio_copy_eexist = true; - test_uffdio_zeropage_eexist = true; alarm(ALARM_INTERVAL_SECS); } From patchwork Wed Apr 12 16:42:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209348 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 3BDA5C77B6E for ; Wed, 12 Apr 2023 16:42:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CC60F280007; Wed, 12 Apr 2023 12:42:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C7565280001; Wed, 12 Apr 2023 12:42:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA13D280007; Wed, 12 Apr 2023 12:42:52 -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 97341280001 for ; Wed, 12 Apr 2023 12:42:52 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 70FE414019C for ; Wed, 12 Apr 2023 16:42:52 +0000 (UTC) X-FDA: 80673308184.11.DD38AAB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf23.hostedemail.com (Postfix) with ESMTP id 340B7140018 for ; Wed, 12 Apr 2023 16:42:49 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bHOnD1C+; spf=pass (imf23.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@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=1681317770; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Iwj5fiaGmEkDB9ZI0G605C/zBaITILZ6MxIdOBed+Ok=; b=3qE7wkUHp/s8x8dooz4k3MEXL8pCEzezSB+1PEfqI196lXhFANjoCqqZwF0jXF0l8R7Sdv TRJS/1v1xVwQZu+xNYRiSWWRh+y9BMZKhkY3SnzXIjPFUEB/brZeqpW9drmDLPLHreSO1r Hx5K8kkIPiQmFl7zpHDHf3sfHGXraQg= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bHOnD1C+; spf=pass (imf23.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681317770; a=rsa-sha256; cv=none; b=k8nRsLvX7NT9KbPMgfbxybNwpWjteS5wUBgbTEW/CeCy5XSt6yWrg81KebXcnJdm1kl7fj A1g/bYeWIxYZ6eRsrYRyzmddRUGt93vR+aLUUX96EkbJRbHyDf7G/6vlNiHGGqMChbwJzz 4CKyi/VQ8niIli2u6tVTB+1JVaLvtag= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317769; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Iwj5fiaGmEkDB9ZI0G605C/zBaITILZ6MxIdOBed+Ok=; b=bHOnD1C+8XCX+L3BxDOPbn9+Csa4dK/t0PHGIzyFNZrUpQb4gl1eFQl3JAzpb/oaE3rjIN t0hx1zBWa0zh9wFxhYZXGJM5CzxXEUXyPDUeLAtuj9q5wqO8yTA6fOdv9d2pWzfX5xgOyq jXJWTrCg1NKtVCFjgjeFd8f2tuzhRkc= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-266-hh4Z1MmTOQWXHMFYXhZkdA-1; Wed, 12 Apr 2023 12:42:46 -0400 X-MC-Unique: hh4Z1MmTOQWXHMFYXhZkdA-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-74a904f38f3so86452185a.1 for ; Wed, 12 Apr 2023 09:42:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317765; x=1683909765; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Iwj5fiaGmEkDB9ZI0G605C/zBaITILZ6MxIdOBed+Ok=; b=f6qzU5S3rpyVGBdAVihP6MTfkTGE+rEPvJY3N4eCl1eAzOdDYmJ6sxO9LzsEalsBlh xV+veKU1euyEgkH+dxR5aoxKhy9nsh5Ht9mTAVOyPCtYxsrqEQJKB5iHgEXG699e8m9z Q8TntlbkcbwOFKM2hNsPAnkL2FEAU5gXhc/4z5SDB47gpBshH3/iAJX0oV3i3eTFS4QF PD154ToVG1asQjnfZmV8UM/cW/5vNBqGH6RlgReyUIqKFXEqrxv/0BEOFEUl3uEtH4lM 1A0rPyJcfA48XtI5/ywF6eE/q5y5k7dDcFERY3j5R5Ldb1I9NIVKBz+3P+fWkDiApS43 j9sA== X-Gm-Message-State: AAQBX9eIZC2LOO2JciehXx8qvhvXQ4DpwSJFVuAQLboFDRtXWzt0fVke dkpTPq0LnMWSGayb5TtEFBRbvyJiErLWIrs1ljB0YfuSE13Acui9pxH62N1sQdBJSZjioyBVlvl +EPKG7uvNg7w= X-Received: by 2002:a05:6214:401a:b0:5aa:14b8:e935 with SMTP id kd26-20020a056214401a00b005aa14b8e935mr4723919qvb.2.1681317765048; Wed, 12 Apr 2023 09:42:45 -0700 (PDT) X-Google-Smtp-Source: AKy350b/O29quWlktPD9M3fo4aXJn3Kc8eFWL+m7kGY2KWbOLrlZG10fVLuRCKr9uddI8KiL+rQRAg== X-Received: by 2002:a05:6214:401a:b0:5aa:14b8:e935 with SMTP id kd26-20020a056214401a00b005aa14b8e935mr4723882qvb.2.1681317764538; Wed, 12 Apr 2023 09:42:44 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id z2-20020a0cfec2000000b005ef48663f6csm178110qvs.112.2023.04.12.09.42.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:42:43 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Andrea Arcangeli , Mike Kravetz , Nadav Amit , David Hildenbrand , Mike Rapoport , Axel Rasmussen , Leonardo Bras Soares Passos , peterx@redhat.com, Mike Rapoport Subject: [PATCH v2 12/31] selftests/mm: Create uffd-common.[ch] Date: Wed, 12 Apr 2023 12:42:41 -0400 Message-Id: <20230412164241.328259-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 340B7140018 X-Rspam-User: X-Stat-Signature: md8o8xd8poe8ixojcnaceksps3xfkyd8 X-HE-Tag: 1681317769-525548 X-HE-Meta: U2FsdGVkX18nQN9LTKlaCWG8PmEsyfeXsAIhLFdz8nhIgTFdJ2CeoVmVjUDgFFFguyYXjkhd4c6lEzMaBTmbEwYpLRPhKaTkW11UpdJPMt1Z65qiSUyijj/lFndZhyNpOCbWLjgbCnucQCwdMYVVjbL28Y6fN1BsmQ2MI0HcsWNQarczYtjKxPP8hnVBLc6wf+NTBT70HoXVWNeAKcE4K4HHbDX1U/h5QsgRqSREZyI0yH3DBDNV+/QCoTYsOJCx1qvrhWQNhL0D84isYlk4Q6H4bp4eQKAn0MwUtgHjf73OH/79kpkcFg95+wgCB27YafFH6fdotlkI3UXHXys0ktoLEDjoItoXnlJ37IHHTBwVBpoLyRc+HMd3Ic2WYoj5CNjyCaeGpFukvFcif1Keotomfx8GK3sYmrPl8F8zQ9pEJcEYMMX5BHF5IpA3p5yeOfXWteQHimTHHzGncSdnHVxrXhZvax7jwSgVryv6FqnW131FJ4xbAUkHJGy5O3oj893BOeUnOLnBztBqsffaKMtCjIuzluNQFk6Y1cz8Ves5kOEJ5B4BbPXBTaOkTye+Xl0dVhur2OTE+AS1S8LzoW5PjGGiLgfX+USo7TrO8ApNE3Jq33eP0KXqgoT0yXlhXej0/AAK3x4APeoji0d1ahwE9t2NEMwmZd4/COZcF6Fim8KVwB2ukW0H8q/QeU2TEOoeYOCE5hlWLHV4NX589u7LWzlZZcLibtZW7og4NzTR/2jxiFwA7lYDG+j19VdHfLEeMkdLM+h+UBqQdBOnn+H/jE1Jd0MnwLWiQ128eIVECcAuW4qzVtzsQabFeQyyih7RDqnCs8dQPDkXrt4lzZ99wFpb41jsZcuuO6NeX6HBUYb4t5oyHqnHMhDHmaad+jLIqtEjyR6r3pIRlysmSzXQCcv4BMOoQuPuOCQxSL+V32z97LH800XIodAz0givZD39Q8Rnw7vNCCqRBu0 Xow3TXET dumFkZ4sdxsUdBZthxWuhp9BXsX3g95pzRzGStZY2LcJ0teeiwIqCgQjO9sKmPCnlFBFG4PcPQ3WLjC+2q195Euqjx1NEv1RX9yLeIGtMdF8Z7r06L9yyablWdqG7CxUp+Vy5NUTzVJsKnQiUgWjXNVBkqcPWKO4djJRTeJHPRk8KLxxxhQh7rodkz05QuW2wEaH9w5QWMHucidlWwMYuNxZEXrV+MVsTCcZEU2pCqbG0Y1CKAUPbmnjS7eTlCvTHTWOWryTrHHr/wEcRReK16o8KDjW1TogZSRklJvz/+G6605Mw+g3jTmWNRT6sL4VWPfBb35w7rqGz87ULBw5QM+OCZHto59i2S/Xnj6BKcRpTISo6JdGb4jcrmK6eIMPAo4b7Q5Yfx0+XFKDMZlGV0LFRcd/isHtZKci2ivpLCztUrf3Dx+IJMBvLamccvf0AC7UswXl/z4YHTaRmlleYndZuPF+Sp8ZHD4VcN5ShjqsywL5folvJXz81eipN7YQkUXP9XNh44MM3+tbzSvIlV2OD1whSqQG7guuY 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: Move common utility functions into uffd-common.[ch] files from the original userfaultfd.c. This prepares for a split of userfaultfd.c into two tests: one to only cover the old but powerful stress test, the other one covers all the functional tests. This movement is kind of a brute-force effort for now, with light touch-ups but nothing should really change. There's chances to optimize more, but let's leave that for later. Reviewed-by: Mike Rapoport (IBM) Signed-off-by: Peter Xu Reviewed-by: Axel Rasmussen --- tools/testing/selftests/mm/Makefile | 2 + tools/testing/selftests/mm/uffd-common.c | 611 ++++++++++++++++++++ tools/testing/selftests/mm/uffd-common.h | 117 ++++ tools/testing/selftests/mm/userfaultfd.c | 694 +---------------------- 4 files changed, 731 insertions(+), 693 deletions(-) create mode 100644 tools/testing/selftests/mm/uffd-common.c create mode 100644 tools/testing/selftests/mm/uffd-common.h diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/mm/Makefile index 5f7626550e5f..36467c15ca00 100644 --- a/tools/testing/selftests/mm/Makefile +++ b/tools/testing/selftests/mm/Makefile @@ -108,6 +108,8 @@ include ../lib.mk $(TEST_GEN_PROGS): vm_util.c +$(OUTPUT)/userfaultfd: uffd-common.c + ifeq ($(MACHINE),x86_64) BINARIES_32 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_32)) BINARIES_64 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_64)) diff --git a/tools/testing/selftests/mm/uffd-common.c b/tools/testing/selftests/mm/uffd-common.c new file mode 100644 index 000000000000..c57757c2a36f --- /dev/null +++ b/tools/testing/selftests/mm/uffd-common.c @@ -0,0 +1,611 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Userfaultfd tests util functions + * + * Copyright (C) 2015-2023 Red Hat, Inc. + */ + +#include "uffd-common.h" + +#define BASE_PMD_ADDR ((void *)(1UL << 30)) + +volatile bool test_uffdio_copy_eexist = true; +unsigned long nr_cpus, nr_pages, nr_pages_per_cpu, page_size, hpage_size; +char *area_src, *area_src_alias, *area_dst, *area_dst_alias, *area_remap; +int mem_fd, uffd = -1, uffd_flags, finished, *pipefd, test_type; +bool map_shared, test_collapse, test_dev_userfaultfd; +bool test_uffdio_wp = true, test_uffdio_minor = false; +unsigned long long *count_verify; +uffd_test_ops_t *uffd_test_ops; + +static void anon_release_pages(char *rel_area) +{ + if (madvise(rel_area, nr_pages * page_size, MADV_DONTNEED)) + err("madvise(MADV_DONTNEED) failed"); +} + +static void anon_allocate_area(void **alloc_area, bool is_src) +{ + *alloc_area = mmap(NULL, nr_pages * page_size, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); +} + +static void noop_alias_mapping(__u64 *start, size_t len, unsigned long offset) +{ +} + +static void hugetlb_release_pages(char *rel_area) +{ + if (!map_shared) { + if (madvise(rel_area, nr_pages * page_size, MADV_DONTNEED)) + err("madvise(MADV_DONTNEED) failed"); + } else { + if (madvise(rel_area, nr_pages * page_size, MADV_REMOVE)) + err("madvise(MADV_REMOVE) failed"); + } +} + +static void hugetlb_allocate_area(void **alloc_area, bool is_src) +{ + off_t size = nr_pages * page_size; + off_t offset = is_src ? 0 : size; + void *area_alias = NULL; + char **alloc_area_alias; + + *alloc_area = mmap(NULL, size, PROT_READ | PROT_WRITE, + (map_shared ? MAP_SHARED : MAP_PRIVATE) | + (is_src ? 0 : MAP_NORESERVE), + mem_fd, offset); + if (*alloc_area == MAP_FAILED) + err("mmap of hugetlbfs file failed"); + + if (map_shared) { + area_alias = mmap(NULL, size, PROT_READ | PROT_WRITE, + MAP_SHARED, mem_fd, offset); + if (area_alias == MAP_FAILED) + err("mmap of hugetlb file alias failed"); + } + + if (is_src) { + alloc_area_alias = &area_src_alias; + } else { + alloc_area_alias = &area_dst_alias; + } + if (area_alias) + *alloc_area_alias = area_alias; +} + +static void hugetlb_alias_mapping(__u64 *start, size_t len, unsigned long offset) +{ + if (!map_shared) + return; + + *start = (unsigned long) area_dst_alias + offset; +} + +static void shmem_release_pages(char *rel_area) +{ + if (madvise(rel_area, nr_pages * page_size, MADV_REMOVE)) + err("madvise(MADV_REMOVE) failed"); +} + +static void shmem_allocate_area(void **alloc_area, bool is_src) +{ + void *area_alias = NULL; + size_t bytes = nr_pages * page_size; + unsigned long offset = is_src ? 0 : bytes; + char *p = NULL, *p_alias = NULL; + + if (test_collapse) { + p = BASE_PMD_ADDR; + if (!is_src) + /* src map + alias + interleaved hpages */ + p += 2 * (bytes + hpage_size); + p_alias = p; + p_alias += bytes; + p_alias += hpage_size; /* Prevent src/dst VMA merge */ + } + + *alloc_area = mmap(p, bytes, PROT_READ | PROT_WRITE, MAP_SHARED, + mem_fd, offset); + if (*alloc_area == MAP_FAILED) + err("mmap of memfd failed"); + if (test_collapse && *alloc_area != p) + err("mmap of memfd failed at %p", p); + + area_alias = mmap(p_alias, bytes, PROT_READ | PROT_WRITE, MAP_SHARED, + mem_fd, offset); + if (area_alias == MAP_FAILED) + err("mmap of memfd alias failed"); + if (test_collapse && area_alias != p_alias) + err("mmap of anonymous memory failed at %p", p_alias); + + if (is_src) + area_src_alias = area_alias; + else + area_dst_alias = area_alias; +} + +static void shmem_alias_mapping(__u64 *start, size_t len, unsigned long offset) +{ + *start = (unsigned long)area_dst_alias + offset; +} + +static void shmem_check_pmd_mapping(void *p, int expect_nr_hpages) +{ + if (!check_huge_shmem(area_dst_alias, expect_nr_hpages, hpage_size)) + err("Did not find expected %d number of hugepages", + expect_nr_hpages); +} + +struct uffd_test_ops anon_uffd_test_ops = { + .allocate_area = anon_allocate_area, + .release_pages = anon_release_pages, + .alias_mapping = noop_alias_mapping, + .check_pmd_mapping = NULL, +}; + +struct uffd_test_ops shmem_uffd_test_ops = { + .allocate_area = shmem_allocate_area, + .release_pages = shmem_release_pages, + .alias_mapping = shmem_alias_mapping, + .check_pmd_mapping = shmem_check_pmd_mapping, +}; + +struct uffd_test_ops hugetlb_uffd_test_ops = { + .allocate_area = hugetlb_allocate_area, + .release_pages = hugetlb_release_pages, + .alias_mapping = hugetlb_alias_mapping, + .check_pmd_mapping = NULL, +}; + +void uffd_stats_report(struct uffd_stats *stats, int n_cpus) +{ + int i; + unsigned long long miss_total = 0, wp_total = 0, minor_total = 0; + + for (i = 0; i < n_cpus; i++) { + miss_total += stats[i].missing_faults; + wp_total += stats[i].wp_faults; + minor_total += stats[i].minor_faults; + } + + printf("userfaults: "); + if (miss_total) { + printf("%llu missing (", miss_total); + for (i = 0; i < n_cpus; i++) + printf("%lu+", stats[i].missing_faults); + printf("\b) "); + } + if (wp_total) { + printf("%llu wp (", wp_total); + for (i = 0; i < n_cpus; i++) + printf("%lu+", stats[i].wp_faults); + printf("\b) "); + } + if (minor_total) { + printf("%llu minor (", minor_total); + for (i = 0; i < n_cpus; i++) + printf("%lu+", stats[i].minor_faults); + printf("\b)"); + } + printf("\n"); +} + +static int __userfaultfd_open_dev(void) +{ + int fd, _uffd; + + fd = open("/dev/userfaultfd", O_RDWR | O_CLOEXEC); + if (fd < 0) + errexit(KSFT_SKIP, "opening /dev/userfaultfd failed"); + + _uffd = ioctl(fd, USERFAULTFD_IOC_NEW, UFFD_FLAGS); + if (_uffd < 0) + errexit(errno == ENOTTY ? KSFT_SKIP : 1, + "creating userfaultfd failed"); + close(fd); + return _uffd; +} + +void userfaultfd_open(uint64_t *features) +{ + struct uffdio_api uffdio_api; + + if (test_dev_userfaultfd) + uffd = __userfaultfd_open_dev(); + else { + uffd = syscall(__NR_userfaultfd, UFFD_FLAGS); + if (uffd < 0) + errexit(errno == ENOSYS ? KSFT_SKIP : 1, + "creating userfaultfd failed"); + } + uffd_flags = fcntl(uffd, F_GETFD, NULL); + + uffdio_api.api = UFFD_API; + uffdio_api.features = *features; + if (ioctl(uffd, UFFDIO_API, &uffdio_api)) + err("UFFDIO_API failed.\nPlease make sure to " + "run with either root or ptrace capability."); + if (uffdio_api.api != UFFD_API) + err("UFFDIO_API error: %" PRIu64, (uint64_t)uffdio_api.api); + + *features = uffdio_api.features; +} + +static inline void munmap_area(void **area) +{ + if (*area) + if (munmap(*area, nr_pages * page_size)) + err("munmap"); + + *area = NULL; +} + +static void uffd_test_ctx_clear(void) +{ + size_t i; + + if (pipefd) { + for (i = 0; i < nr_cpus * 2; ++i) { + if (close(pipefd[i])) + err("close pipefd"); + } + free(pipefd); + pipefd = NULL; + } + + if (count_verify) { + free(count_verify); + count_verify = NULL; + } + + if (uffd != -1) { + if (close(uffd)) + err("close uffd"); + uffd = -1; + } + + munmap_area((void **)&area_src); + munmap_area((void **)&area_src_alias); + munmap_area((void **)&area_dst); + munmap_area((void **)&area_dst_alias); + munmap_area((void **)&area_remap); +} + +void uffd_test_ctx_init(uint64_t features) +{ + unsigned long nr, cpu; + + uffd_test_ctx_clear(); + + uffd_test_ops->allocate_area((void **)&area_src, true); + uffd_test_ops->allocate_area((void **)&area_dst, false); + + userfaultfd_open(&features); + + count_verify = malloc(nr_pages * sizeof(unsigned long long)); + if (!count_verify) + err("count_verify"); + + for (nr = 0; nr < nr_pages; nr++) { + *area_mutex(area_src, nr) = + (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER; + count_verify[nr] = *area_count(area_src, nr) = 1; + /* + * In the transition between 255 to 256, powerpc will + * read out of order in my_bcmp and see both bytes as + * zero, so leave a placeholder below always non-zero + * after the count, to avoid my_bcmp to trigger false + * positives. + */ + *(area_count(area_src, nr) + 1) = 1; + } + + /* + * After initialization of area_src, we must explicitly release pages + * for area_dst to make sure it's fully empty. Otherwise we could have + * some area_dst pages be errornously initialized with zero pages, + * hence we could hit memory corruption later in the test. + * + * One example is when THP is globally enabled, above allocate_area() + * calls could have the two areas merged into a single VMA (as they + * will have the same VMA flags so they're mergeable). When we + * initialize the area_src above, it's possible that some part of + * area_dst could have been faulted in via one huge THP that will be + * shared between area_src and area_dst. It could cause some of the + * area_dst won't be trapped by missing userfaults. + * + * This release_pages() will guarantee even if that happened, we'll + * proactively split the thp and drop any accidentally initialized + * pages within area_dst. + */ + uffd_test_ops->release_pages(area_dst); + + pipefd = malloc(sizeof(int) * nr_cpus * 2); + if (!pipefd) + err("pipefd"); + for (cpu = 0; cpu < nr_cpus; cpu++) + if (pipe2(&pipefd[cpu * 2], O_CLOEXEC | O_NONBLOCK)) + err("pipe"); +} + +uint64_t get_expected_ioctls(uint64_t mode) +{ + uint64_t ioctls = UFFD_API_RANGE_IOCTLS; + + if (test_type == TEST_HUGETLB) + ioctls &= ~(1 << _UFFDIO_ZEROPAGE); + + if (!((mode & UFFDIO_REGISTER_MODE_WP) && test_uffdio_wp)) + ioctls &= ~(1 << _UFFDIO_WRITEPROTECT); + + if (!((mode & UFFDIO_REGISTER_MODE_MINOR) && test_uffdio_minor)) + ioctls &= ~(1 << _UFFDIO_CONTINUE); + + return ioctls; +} + +void assert_expected_ioctls_present(uint64_t mode, uint64_t ioctls) +{ + uint64_t expected = get_expected_ioctls(mode); + uint64_t actual = ioctls & expected; + + if (actual != expected) { + err("missing ioctl(s): expected %"PRIx64" actual: %"PRIx64, + expected, actual); + } +} + +void wp_range(int ufd, __u64 start, __u64 len, bool wp) +{ + struct uffdio_writeprotect prms; + + /* Write protection page faults */ + prms.range.start = start; + prms.range.len = len; + /* Undo write-protect, do wakeup after that */ + prms.mode = wp ? UFFDIO_WRITEPROTECT_MODE_WP : 0; + + if (ioctl(ufd, UFFDIO_WRITEPROTECT, &prms)) + err("clear WP failed: address=0x%"PRIx64, (uint64_t)start); +} + +static void continue_range(int ufd, __u64 start, __u64 len) +{ + struct uffdio_continue req; + int ret; + + req.range.start = start; + req.range.len = len; + req.mode = 0; + if (test_uffdio_wp) + req.mode |= UFFDIO_CONTINUE_MODE_WP; + + if (ioctl(ufd, UFFDIO_CONTINUE, &req)) + err("UFFDIO_CONTINUE failed for address 0x%" PRIx64, + (uint64_t)start); + + /* + * Error handling within the kernel for continue is subtly different + * from copy or zeropage, so it may be a source of bugs. Trigger an + * error (-EEXIST) on purpose, to verify doing so doesn't cause a BUG. + */ + req.mapped = 0; + ret = ioctl(ufd, UFFDIO_CONTINUE, &req); + if (ret >= 0 || req.mapped != -EEXIST) + err("failed to exercise UFFDIO_CONTINUE error handling, ret=%d, mapped=%" PRId64, + ret, (int64_t) req.mapped); +} + +int uffd_read_msg(int ufd, struct uffd_msg *msg) +{ + int ret = read(uffd, msg, sizeof(*msg)); + + if (ret != sizeof(*msg)) { + if (ret < 0) { + if (errno == EAGAIN || errno == EINTR) + return 1; + err("blocking read error"); + } else { + err("short read"); + } + } + + return 0; +} + +void uffd_handle_page_fault(struct uffd_msg *msg, struct uffd_stats *stats) +{ + unsigned long offset; + + if (msg->event != UFFD_EVENT_PAGEFAULT) + err("unexpected msg event %u", msg->event); + + if (msg->arg.pagefault.flags & UFFD_PAGEFAULT_FLAG_WP) { + /* Write protect page faults */ + wp_range(uffd, msg->arg.pagefault.address, page_size, false); + stats->wp_faults++; + } else if (msg->arg.pagefault.flags & UFFD_PAGEFAULT_FLAG_MINOR) { + uint8_t *area; + int b; + + /* + * Minor page faults + * + * To prove we can modify the original range for testing + * purposes, we're going to bit flip this range before + * continuing. + * + * Note that this requires all minor page fault tests operate on + * area_dst (non-UFFD-registered) and area_dst_alias + * (UFFD-registered). + */ + + area = (uint8_t *)(area_dst + + ((char *)msg->arg.pagefault.address - + area_dst_alias)); + for (b = 0; b < page_size; ++b) + area[b] = ~area[b]; + continue_range(uffd, msg->arg.pagefault.address, page_size); + stats->minor_faults++; + } else { + /* + * Missing page faults. + * + * Here we force a write check for each of the missing mode + * faults. It's guaranteed because the only threads that + * will trigger uffd faults are the locking threads, and + * their first instruction to touch the missing page will + * always be pthread_mutex_lock(). + * + * Note that here we relied on an NPTL glibc impl detail to + * always read the lock type at the entry of the lock op + * (pthread_mutex_t.__data.__type, offset 0x10) before + * doing any locking operations to guarantee that. It's + * actually not good to rely on this impl detail because + * logically a pthread-compatible lib can implement the + * locks without types and we can fail when linking with + * them. However since we used to find bugs with this + * strict check we still keep it around. Hopefully this + * could be a good hint when it fails again. If one day + * it'll break on some other impl of glibc we'll revisit. + */ + if (msg->arg.pagefault.flags & UFFD_PAGEFAULT_FLAG_WRITE) + err("unexpected write fault"); + + offset = (char *)(unsigned long)msg->arg.pagefault.address - area_dst; + offset &= ~(page_size-1); + + if (copy_page(uffd, offset)) + stats->missing_faults++; + } +} + +void *uffd_poll_thread(void *arg) +{ + struct uffd_stats *stats = (struct uffd_stats *)arg; + unsigned long cpu = stats->cpu; + struct pollfd pollfd[2]; + struct uffd_msg msg; + struct uffdio_register uffd_reg; + int ret; + char tmp_chr; + + pollfd[0].fd = uffd; + pollfd[0].events = POLLIN; + pollfd[1].fd = pipefd[cpu*2]; + pollfd[1].events = POLLIN; + + for (;;) { + ret = poll(pollfd, 2, -1); + if (ret <= 0) { + if (errno == EINTR || errno == EAGAIN) + continue; + err("poll error: %d", ret); + } + if (pollfd[1].revents) { + if (!(pollfd[1].revents & POLLIN)) + err("pollfd[1].revents %d", pollfd[1].revents); + if (read(pollfd[1].fd, &tmp_chr, 1) != 1) + err("read pipefd error"); + break; + } + if (!(pollfd[0].revents & POLLIN)) + err("pollfd[0].revents %d", pollfd[0].revents); + if (uffd_read_msg(uffd, &msg)) + continue; + switch (msg.event) { + default: + err("unexpected msg event %u\n", msg.event); + break; + case UFFD_EVENT_PAGEFAULT: + uffd_handle_page_fault(&msg, stats); + break; + case UFFD_EVENT_FORK: + close(uffd); + uffd = msg.arg.fork.ufd; + pollfd[0].fd = uffd; + break; + case UFFD_EVENT_REMOVE: + uffd_reg.range.start = msg.arg.remove.start; + uffd_reg.range.len = msg.arg.remove.end - + msg.arg.remove.start; + if (ioctl(uffd, UFFDIO_UNREGISTER, &uffd_reg.range)) + err("remove failure"); + break; + case UFFD_EVENT_REMAP: + area_remap = area_dst; /* save for later unmap */ + area_dst = (char *)(unsigned long)msg.arg.remap.to; + break; + } + } + + return NULL; +} + +static void retry_copy_page(int ufd, struct uffdio_copy *uffdio_copy, + unsigned long offset) +{ + uffd_test_ops->alias_mapping(&uffdio_copy->dst, + uffdio_copy->len, + offset); + if (ioctl(ufd, UFFDIO_COPY, uffdio_copy)) { + /* real retval in ufdio_copy.copy */ + if (uffdio_copy->copy != -EEXIST) + err("UFFDIO_COPY retry error: %"PRId64, + (int64_t)uffdio_copy->copy); + } else { + err("UFFDIO_COPY retry unexpected: %"PRId64, + (int64_t)uffdio_copy->copy); + } +} + +static void wake_range(int ufd, unsigned long addr, unsigned long len) +{ + struct uffdio_range uffdio_wake; + + uffdio_wake.start = addr; + uffdio_wake.len = len; + + if (ioctl(ufd, UFFDIO_WAKE, &uffdio_wake)) + fprintf(stderr, "error waking %lu\n", + addr), exit(1); +} + +int __copy_page(int ufd, unsigned long offset, bool retry) +{ + struct uffdio_copy uffdio_copy; + + if (offset >= nr_pages * page_size) + err("unexpected offset %lu\n", offset); + uffdio_copy.dst = (unsigned long) area_dst + offset; + uffdio_copy.src = (unsigned long) area_src + offset; + uffdio_copy.len = page_size; + if (test_uffdio_wp) + uffdio_copy.mode = UFFDIO_COPY_MODE_WP; + else + uffdio_copy.mode = 0; + uffdio_copy.copy = 0; + if (ioctl(ufd, UFFDIO_COPY, &uffdio_copy)) { + /* real retval in ufdio_copy.copy */ + if (uffdio_copy.copy != -EEXIST) + err("UFFDIO_COPY error: %"PRId64, + (int64_t)uffdio_copy.copy); + wake_range(ufd, uffdio_copy.dst, page_size); + } else if (uffdio_copy.copy != page_size) { + err("UFFDIO_COPY error: %"PRId64, (int64_t)uffdio_copy.copy); + } else { + if (test_uffdio_copy_eexist && retry) { + test_uffdio_copy_eexist = false; + retry_copy_page(ufd, &uffdio_copy, offset); + } + return 1; + } + return 0; +} + +int copy_page(int ufd, unsigned long offset) +{ + return __copy_page(ufd, offset, false); +} diff --git a/tools/testing/selftests/mm/uffd-common.h b/tools/testing/selftests/mm/uffd-common.h new file mode 100644 index 000000000000..d9430cfdcb19 --- /dev/null +++ b/tools/testing/selftests/mm/uffd-common.h @@ -0,0 +1,117 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Userfaultfd tests common header + * + * Copyright (C) 2015-2023 Red Hat, Inc. + */ +#ifndef __UFFD_COMMON_H__ +#define __UFFD_COMMON_H__ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../kselftest.h" +#include "vm_util.h" + +#define UFFD_FLAGS (O_CLOEXEC | O_NONBLOCK | UFFD_USER_MODE_ONLY) + +#define _err(fmt, ...) \ + do { \ + int ret = errno; \ + fprintf(stderr, "ERROR: " fmt, ##__VA_ARGS__); \ + fprintf(stderr, " (errno=%d, @%s:%d)\n", \ + ret, __FILE__, __LINE__); \ + } while (0) + +#define errexit(exitcode, fmt, ...) \ + do { \ + _err(fmt, ##__VA_ARGS__); \ + exit(exitcode); \ + } while (0) + +#define err(fmt, ...) errexit(1, fmt, ##__VA_ARGS__) + +/* pthread_mutex_t starts at page offset 0 */ +#define area_mutex(___area, ___nr) \ + ((pthread_mutex_t *) ((___area) + (___nr)*page_size)) +/* + * count is placed in the page after pthread_mutex_t naturally aligned + * to avoid non alignment faults on non-x86 archs. + */ +#define area_count(___area, ___nr) \ + ((volatile unsigned long long *) ((unsigned long) \ + ((___area) + (___nr)*page_size + \ + sizeof(pthread_mutex_t) + \ + sizeof(unsigned long long) - 1) & \ + ~(unsigned long)(sizeof(unsigned long long) \ + - 1))) + +/* Userfaultfd test statistics */ +struct uffd_stats { + int cpu; + unsigned long missing_faults; + unsigned long wp_faults; + unsigned long minor_faults; +}; + +struct uffd_test_ops { + void (*allocate_area)(void **alloc_area, bool is_src); + void (*release_pages)(char *rel_area); + void (*alias_mapping)(__u64 *start, size_t len, unsigned long offset); + void (*check_pmd_mapping)(void *p, int expect_nr_hpages); +}; +typedef struct uffd_test_ops uffd_test_ops_t; + +extern unsigned long nr_cpus, nr_pages, nr_pages_per_cpu, page_size, hpage_size; +extern char *area_src, *area_src_alias, *area_dst, *area_dst_alias, *area_remap; +extern int mem_fd, uffd, uffd_flags, finished, *pipefd, test_type; +extern bool map_shared, test_collapse, test_dev_userfaultfd; +extern bool test_uffdio_wp, test_uffdio_minor; +extern unsigned long long *count_verify; +extern volatile bool test_uffdio_copy_eexist; + +extern uffd_test_ops_t anon_uffd_test_ops; +extern uffd_test_ops_t shmem_uffd_test_ops; +extern uffd_test_ops_t hugetlb_uffd_test_ops; +extern uffd_test_ops_t *uffd_test_ops; + +void uffd_stats_report(struct uffd_stats *stats, int n_cpus); +void uffd_test_ctx_init(uint64_t features); +void userfaultfd_open(uint64_t *features); +uint64_t get_expected_ioctls(uint64_t mode); +void assert_expected_ioctls_present(uint64_t mode, uint64_t ioctls); +int uffd_read_msg(int ufd, struct uffd_msg *msg); +void wp_range(int ufd, __u64 start, __u64 len, bool wp); +void uffd_handle_page_fault(struct uffd_msg *msg, struct uffd_stats *stats); +int __copy_page(int ufd, unsigned long offset, bool retry); +int copy_page(int ufd, unsigned long offset); +void *uffd_poll_thread(void *arg); + +#define TEST_ANON 1 +#define TEST_HUGETLB 2 +#define TEST_SHMEM 3 + +#endif diff --git a/tools/testing/selftests/mm/userfaultfd.c b/tools/testing/selftests/mm/userfaultfd.c index 3487ec0bfcc8..c68a9aeefc41 100644 --- a/tools/testing/selftests/mm/userfaultfd.c +++ b/tools/testing/selftests/mm/userfaultfd.c @@ -34,96 +34,20 @@ * transfer (UFFDIO_COPY). */ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "../kselftest.h" -#include "vm_util.h" +#include "uffd-common.h" #ifdef __NR_userfaultfd -static unsigned long nr_cpus, nr_pages, nr_pages_per_cpu, page_size, hpage_size; - #define BOUNCE_RANDOM (1<<0) #define BOUNCE_RACINGFAULTS (1<<1) #define BOUNCE_VERIFY (1<<2) #define BOUNCE_POLL (1<<3) static int bounces; -#define TEST_ANON 1 -#define TEST_HUGETLB 2 -#define TEST_SHMEM 3 -static int test_type; - -#define UFFD_FLAGS (O_CLOEXEC | O_NONBLOCK | UFFD_USER_MODE_ONLY) - -#define BASE_PMD_ADDR ((void *)(1UL << 30)) - -/* test using /dev/userfaultfd, instead of userfaultfd(2) */ -static bool test_dev_userfaultfd; - /* exercise the test_uffdio_*_eexist every ALARM_INTERVAL_SECS */ #define ALARM_INTERVAL_SECS 10 -static volatile bool test_uffdio_copy_eexist = true; -/* Whether to test uffd write-protection */ -static bool test_uffdio_wp = true; -/* Whether to test uffd minor faults */ -static bool test_uffdio_minor = false; -static bool map_shared; -static int mem_fd; -static unsigned long long *count_verify; -static int uffd = -1; -static int uffd_flags, finished, *pipefd; -static char *area_src, *area_src_alias, *area_dst, *area_dst_alias, *area_remap; static char *zeropage; pthread_attr_t attr; -static bool test_collapse; - -/* Userfaultfd test statistics */ -struct uffd_stats { - int cpu; - unsigned long missing_faults; - unsigned long wp_faults; - unsigned long minor_faults; -}; - -/* pthread_mutex_t starts at page offset 0 */ -#define area_mutex(___area, ___nr) \ - ((pthread_mutex_t *) ((___area) + (___nr)*page_size)) -/* - * count is placed in the page after pthread_mutex_t naturally aligned - * to avoid non alignment faults on non-x86 archs. - */ -#define area_count(___area, ___nr) \ - ((volatile unsigned long long *) ((unsigned long) \ - ((___area) + (___nr)*page_size + \ - sizeof(pthread_mutex_t) + \ - sizeof(unsigned long long) - 1) & \ - ~(unsigned long)(sizeof(unsigned long long) \ - - 1))) #define swap(a, b) \ do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0) @@ -166,22 +90,6 @@ static void usage(void) exit(1); } -#define _err(fmt, ...) \ - do { \ - int ret = errno; \ - fprintf(stderr, "ERROR: " fmt, ##__VA_ARGS__); \ - fprintf(stderr, " (errno=%d, line=%d)\n", \ - ret, __LINE__); \ - } while (0) - -#define errexit(exitcode, fmt, ...) \ - do { \ - _err(fmt, ##__VA_ARGS__); \ - exit(exitcode); \ - } while (0) - -#define err(fmt, ...) errexit(1, fmt, ##__VA_ARGS__) - static void uffd_stats_reset(struct uffd_stats *uffd_stats, unsigned long n_cpus) { @@ -195,189 +103,6 @@ static void uffd_stats_reset(struct uffd_stats *uffd_stats, } } -static void uffd_stats_report(struct uffd_stats *stats, int n_cpus) -{ - int i; - unsigned long long miss_total = 0, wp_total = 0, minor_total = 0; - - for (i = 0; i < n_cpus; i++) { - miss_total += stats[i].missing_faults; - wp_total += stats[i].wp_faults; - minor_total += stats[i].minor_faults; - } - - printf("userfaults: "); - if (miss_total) { - printf("%llu missing (", miss_total); - for (i = 0; i < n_cpus; i++) - printf("%lu+", stats[i].missing_faults); - printf("\b) "); - } - if (wp_total) { - printf("%llu wp (", wp_total); - for (i = 0; i < n_cpus; i++) - printf("%lu+", stats[i].wp_faults); - printf("\b) "); - } - if (minor_total) { - printf("%llu minor (", minor_total); - for (i = 0; i < n_cpus; i++) - printf("%lu+", stats[i].minor_faults); - printf("\b)"); - } - printf("\n"); -} - -static void anon_release_pages(char *rel_area) -{ - if (madvise(rel_area, nr_pages * page_size, MADV_DONTNEED)) - err("madvise(MADV_DONTNEED) failed"); -} - -static void anon_allocate_area(void **alloc_area, bool is_src) -{ - *alloc_area = mmap(NULL, nr_pages * page_size, PROT_READ | PROT_WRITE, - MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); -} - -static void noop_alias_mapping(__u64 *start, size_t len, unsigned long offset) -{ -} - -static void hugetlb_release_pages(char *rel_area) -{ - if (!map_shared) { - if (madvise(rel_area, nr_pages * page_size, MADV_DONTNEED)) - err("madvise(MADV_DONTNEED) failed"); - } else { - if (madvise(rel_area, nr_pages * page_size, MADV_REMOVE)) - err("madvise(MADV_REMOVE) failed"); - } -} - -static void hugetlb_allocate_area(void **alloc_area, bool is_src) -{ - off_t size = nr_pages * page_size; - off_t offset = is_src ? 0 : size; - void *area_alias = NULL; - char **alloc_area_alias; - - *alloc_area = mmap(NULL, size, PROT_READ | PROT_WRITE, - (map_shared ? MAP_SHARED : MAP_PRIVATE) | - (is_src ? 0 : MAP_NORESERVE), - mem_fd, offset); - if (*alloc_area == MAP_FAILED) - err("mmap of hugetlbfs file failed"); - - if (map_shared) { - area_alias = mmap(NULL, size, PROT_READ | PROT_WRITE, - MAP_SHARED, mem_fd, offset); - if (area_alias == MAP_FAILED) - err("mmap of hugetlb file alias failed"); - } - - if (is_src) { - alloc_area_alias = &area_src_alias; - } else { - alloc_area_alias = &area_dst_alias; - } - if (area_alias) - *alloc_area_alias = area_alias; -} - -static void hugetlb_alias_mapping(__u64 *start, size_t len, unsigned long offset) -{ - if (!map_shared) - return; - - *start = (unsigned long) area_dst_alias + offset; -} - -static void shmem_release_pages(char *rel_area) -{ - if (madvise(rel_area, nr_pages * page_size, MADV_REMOVE)) - err("madvise(MADV_REMOVE) failed"); -} - -static void shmem_allocate_area(void **alloc_area, bool is_src) -{ - void *area_alias = NULL; - size_t bytes = nr_pages * page_size; - unsigned long offset = is_src ? 0 : bytes; - char *p = NULL, *p_alias = NULL; - - if (test_collapse) { - p = BASE_PMD_ADDR; - if (!is_src) - /* src map + alias + interleaved hpages */ - p += 2 * (bytes + hpage_size); - p_alias = p; - p_alias += bytes; - p_alias += hpage_size; /* Prevent src/dst VMA merge */ - } - - *alloc_area = mmap(p, bytes, PROT_READ | PROT_WRITE, MAP_SHARED, - mem_fd, offset); - if (*alloc_area == MAP_FAILED) - err("mmap of memfd failed"); - if (test_collapse && *alloc_area != p) - err("mmap of memfd failed at %p", p); - - area_alias = mmap(p_alias, bytes, PROT_READ | PROT_WRITE, MAP_SHARED, - mem_fd, offset); - if (area_alias == MAP_FAILED) - err("mmap of memfd alias failed"); - if (test_collapse && area_alias != p_alias) - err("mmap of anonymous memory failed at %p", p_alias); - - if (is_src) - area_src_alias = area_alias; - else - area_dst_alias = area_alias; -} - -static void shmem_alias_mapping(__u64 *start, size_t len, unsigned long offset) -{ - *start = (unsigned long)area_dst_alias + offset; -} - -static void shmem_check_pmd_mapping(void *p, int expect_nr_hpages) -{ - if (!check_huge_shmem(area_dst_alias, expect_nr_hpages, hpage_size)) - err("Did not find expected %d number of hugepages", - expect_nr_hpages); -} - -struct uffd_test_ops { - void (*allocate_area)(void **alloc_area, bool is_src); - void (*release_pages)(char *rel_area); - void (*alias_mapping)(__u64 *start, size_t len, unsigned long offset); - void (*check_pmd_mapping)(void *p, int expect_nr_hpages); -}; - -static struct uffd_test_ops anon_uffd_test_ops = { - .allocate_area = anon_allocate_area, - .release_pages = anon_release_pages, - .alias_mapping = noop_alias_mapping, - .check_pmd_mapping = NULL, -}; - -static struct uffd_test_ops shmem_uffd_test_ops = { - .allocate_area = shmem_allocate_area, - .release_pages = shmem_release_pages, - .alias_mapping = shmem_alias_mapping, - .check_pmd_mapping = shmem_check_pmd_mapping, -}; - -static struct uffd_test_ops hugetlb_uffd_test_ops = { - .allocate_area = hugetlb_allocate_area, - .release_pages = hugetlb_release_pages, - .alias_mapping = hugetlb_alias_mapping, - .check_pmd_mapping = NULL, -}; - -static struct uffd_test_ops *uffd_test_ops; - static inline uint64_t uffd_minor_feature(void) { if (test_type == TEST_HUGETLB && map_shared) @@ -388,171 +113,6 @@ static inline uint64_t uffd_minor_feature(void) return 0; } -static uint64_t get_expected_ioctls(uint64_t mode) -{ - uint64_t ioctls = UFFD_API_RANGE_IOCTLS; - - if (test_type == TEST_HUGETLB) - ioctls &= ~(1 << _UFFDIO_ZEROPAGE); - - if (!((mode & UFFDIO_REGISTER_MODE_WP) && test_uffdio_wp)) - ioctls &= ~(1 << _UFFDIO_WRITEPROTECT); - - if (!((mode & UFFDIO_REGISTER_MODE_MINOR) && test_uffdio_minor)) - ioctls &= ~(1 << _UFFDIO_CONTINUE); - - return ioctls; -} - -static void assert_expected_ioctls_present(uint64_t mode, uint64_t ioctls) -{ - uint64_t expected = get_expected_ioctls(mode); - uint64_t actual = ioctls & expected; - - if (actual != expected) { - err("missing ioctl(s): expected %"PRIx64" actual: %"PRIx64, - expected, actual); - } -} - -static int __userfaultfd_open_dev(void) -{ - int fd, _uffd; - - fd = open("/dev/userfaultfd", O_RDWR | O_CLOEXEC); - if (fd < 0) - errexit(KSFT_SKIP, "opening /dev/userfaultfd failed"); - - _uffd = ioctl(fd, USERFAULTFD_IOC_NEW, UFFD_FLAGS); - if (_uffd < 0) - errexit(errno == ENOTTY ? KSFT_SKIP : 1, - "creating userfaultfd failed"); - close(fd); - return _uffd; -} - -static void userfaultfd_open(uint64_t *features) -{ - struct uffdio_api uffdio_api; - - if (test_dev_userfaultfd) - uffd = __userfaultfd_open_dev(); - else { - uffd = syscall(__NR_userfaultfd, UFFD_FLAGS); - if (uffd < 0) - errexit(errno == ENOSYS ? KSFT_SKIP : 1, - "creating userfaultfd failed"); - } - uffd_flags = fcntl(uffd, F_GETFD, NULL); - - uffdio_api.api = UFFD_API; - uffdio_api.features = *features; - if (ioctl(uffd, UFFDIO_API, &uffdio_api)) - err("UFFDIO_API failed.\nPlease make sure to " - "run with either root or ptrace capability."); - if (uffdio_api.api != UFFD_API) - err("UFFDIO_API error: %" PRIu64, (uint64_t)uffdio_api.api); - - *features = uffdio_api.features; -} - -static inline void munmap_area(void **area) -{ - if (*area) - if (munmap(*area, nr_pages * page_size)) - err("munmap"); - - *area = NULL; -} - -static void uffd_test_ctx_clear(void) -{ - size_t i; - - if (pipefd) { - for (i = 0; i < nr_cpus * 2; ++i) { - if (close(pipefd[i])) - err("close pipefd"); - } - free(pipefd); - pipefd = NULL; - } - - if (count_verify) { - free(count_verify); - count_verify = NULL; - } - - if (uffd != -1) { - if (close(uffd)) - err("close uffd"); - uffd = -1; - } - - munmap_area((void **)&area_src); - munmap_area((void **)&area_src_alias); - munmap_area((void **)&area_dst); - munmap_area((void **)&area_dst_alias); - munmap_area((void **)&area_remap); -} - -static void uffd_test_ctx_init(uint64_t features) -{ - unsigned long nr, cpu; - - uffd_test_ctx_clear(); - - uffd_test_ops->allocate_area((void **)&area_src, true); - uffd_test_ops->allocate_area((void **)&area_dst, false); - - userfaultfd_open(&features); - - count_verify = malloc(nr_pages * sizeof(unsigned long long)); - if (!count_verify) - err("count_verify"); - - for (nr = 0; nr < nr_pages; nr++) { - *area_mutex(area_src, nr) = - (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER; - count_verify[nr] = *area_count(area_src, nr) = 1; - /* - * In the transition between 255 to 256, powerpc will - * read out of order in my_bcmp and see both bytes as - * zero, so leave a placeholder below always non-zero - * after the count, to avoid my_bcmp to trigger false - * positives. - */ - *(area_count(area_src, nr) + 1) = 1; - } - - /* - * After initialization of area_src, we must explicitly release pages - * for area_dst to make sure it's fully empty. Otherwise we could have - * some area_dst pages be errornously initialized with zero pages, - * hence we could hit memory corruption later in the test. - * - * One example is when THP is globally enabled, above allocate_area() - * calls could have the two areas merged into a single VMA (as they - * will have the same VMA flags so they're mergeable). When we - * initialize the area_src above, it's possible that some part of - * area_dst could have been faulted in via one huge THP that will be - * shared between area_src and area_dst. It could cause some of the - * area_dst won't be trapped by missing userfaults. - * - * This release_pages() will guarantee even if that happened, we'll - * proactively split the thp and drop any accidentally initialized - * pages within area_dst. - */ - uffd_test_ops->release_pages(area_dst); - - pipefd = malloc(sizeof(int) * nr_cpus * 2); - if (!pipefd) - err("pipefd"); - for (cpu = 0; cpu < nr_cpus; cpu++) - if (pipe2(&pipefd[cpu * 2], O_CLOEXEC | O_NONBLOCK)) - err("pipe"); -} - static int my_bcmp(char *str1, char *str2, size_t n) { unsigned long i; @@ -562,47 +122,6 @@ static int my_bcmp(char *str1, char *str2, size_t n) return 0; } -static void wp_range(int ufd, __u64 start, __u64 len, bool wp) -{ - struct uffdio_writeprotect prms; - - /* Write protection page faults */ - prms.range.start = start; - prms.range.len = len; - /* Undo write-protect, do wakeup after that */ - prms.mode = wp ? UFFDIO_WRITEPROTECT_MODE_WP : 0; - - if (ioctl(ufd, UFFDIO_WRITEPROTECT, &prms)) - err("clear WP failed: address=0x%"PRIx64, (uint64_t)start); -} - -static void continue_range(int ufd, __u64 start, __u64 len) -{ - struct uffdio_continue req; - int ret; - - req.range.start = start; - req.range.len = len; - req.mode = 0; - if (test_uffdio_wp) - req.mode |= UFFDIO_CONTINUE_MODE_WP; - - if (ioctl(ufd, UFFDIO_CONTINUE, &req)) - err("UFFDIO_CONTINUE failed for address 0x%" PRIx64, - (uint64_t)start); - - /* - * Error handling within the kernel for continue is subtly different - * from copy or zeropage, so it may be a source of bugs. Trigger an - * error (-EEXIST) on purpose, to verify doing so doesn't cause a BUG. - */ - req.mapped = 0; - ret = ioctl(ufd, UFFDIO_CONTINUE, &req); - if (ret >= 0 || req.mapped != -EEXIST) - err("failed to exercise UFFDIO_CONTINUE error handling, ret=%d, mapped=%" PRId64, - ret, (int64_t) req.mapped); -} - static void *locking_thread(void *arg) { unsigned long cpu = (unsigned long) arg; @@ -635,222 +154,11 @@ static void *locking_thread(void *arg) return NULL; } -static void retry_copy_page(int ufd, struct uffdio_copy *uffdio_copy, - unsigned long offset) -{ - uffd_test_ops->alias_mapping(&uffdio_copy->dst, - uffdio_copy->len, - offset); - if (ioctl(ufd, UFFDIO_COPY, uffdio_copy)) { - /* real retval in ufdio_copy.copy */ - if (uffdio_copy->copy != -EEXIST) - err("UFFDIO_COPY retry error: %"PRId64, - (int64_t)uffdio_copy->copy); - } else { - err("UFFDIO_COPY retry unexpected: %"PRId64, - (int64_t)uffdio_copy->copy); - } -} - -static void wake_range(int ufd, unsigned long addr, unsigned long len) -{ - struct uffdio_range uffdio_wake; - - uffdio_wake.start = addr; - uffdio_wake.len = len; - - if (ioctl(ufd, UFFDIO_WAKE, &uffdio_wake)) - fprintf(stderr, "error waking %lu\n", - addr), exit(1); -} - -static int __copy_page(int ufd, unsigned long offset, bool retry) -{ - struct uffdio_copy uffdio_copy; - - if (offset >= nr_pages * page_size) - err("unexpected offset %lu\n", offset); - uffdio_copy.dst = (unsigned long) area_dst + offset; - uffdio_copy.src = (unsigned long) area_src + offset; - uffdio_copy.len = page_size; - if (test_uffdio_wp) - uffdio_copy.mode = UFFDIO_COPY_MODE_WP; - else - uffdio_copy.mode = 0; - uffdio_copy.copy = 0; - if (ioctl(ufd, UFFDIO_COPY, &uffdio_copy)) { - /* real retval in ufdio_copy.copy */ - if (uffdio_copy.copy != -EEXIST) - err("UFFDIO_COPY error: %"PRId64, - (int64_t)uffdio_copy.copy); - wake_range(ufd, uffdio_copy.dst, page_size); - } else if (uffdio_copy.copy != page_size) { - err("UFFDIO_COPY error: %"PRId64, (int64_t)uffdio_copy.copy); - } else { - if (test_uffdio_copy_eexist && retry) { - test_uffdio_copy_eexist = false; - retry_copy_page(ufd, &uffdio_copy, offset); - } - return 1; - } - return 0; -} - static int copy_page_retry(int ufd, unsigned long offset) { return __copy_page(ufd, offset, true); } -static int copy_page(int ufd, unsigned long offset) -{ - return __copy_page(ufd, offset, false); -} - -static int uffd_read_msg(int ufd, struct uffd_msg *msg) -{ - int ret = read(uffd, msg, sizeof(*msg)); - - if (ret != sizeof(*msg)) { - if (ret < 0) { - if (errno == EAGAIN || errno == EINTR) - return 1; - err("blocking read error"); - } else { - err("short read"); - } - } - - return 0; -} - -static void uffd_handle_page_fault(struct uffd_msg *msg, - struct uffd_stats *stats) -{ - unsigned long offset; - - if (msg->event != UFFD_EVENT_PAGEFAULT) - err("unexpected msg event %u", msg->event); - - if (msg->arg.pagefault.flags & UFFD_PAGEFAULT_FLAG_WP) { - /* Write protect page faults */ - wp_range(uffd, msg->arg.pagefault.address, page_size, false); - stats->wp_faults++; - } else if (msg->arg.pagefault.flags & UFFD_PAGEFAULT_FLAG_MINOR) { - uint8_t *area; - int b; - - /* - * Minor page faults - * - * To prove we can modify the original range for testing - * purposes, we're going to bit flip this range before - * continuing. - * - * Note that this requires all minor page fault tests operate on - * area_dst (non-UFFD-registered) and area_dst_alias - * (UFFD-registered). - */ - - area = (uint8_t *)(area_dst + - ((char *)msg->arg.pagefault.address - - area_dst_alias)); - for (b = 0; b < page_size; ++b) - area[b] = ~area[b]; - continue_range(uffd, msg->arg.pagefault.address, page_size); - stats->minor_faults++; - } else { - /* - * Missing page faults. - * - * Here we force a write check for each of the missing mode - * faults. It's guaranteed because the only threads that - * will trigger uffd faults are the locking threads, and - * their first instruction to touch the missing page will - * always be pthread_mutex_lock(). - * - * Note that here we relied on an NPTL glibc impl detail to - * always read the lock type at the entry of the lock op - * (pthread_mutex_t.__data.__type, offset 0x10) before - * doing any locking operations to guarantee that. It's - * actually not good to rely on this impl detail because - * logically a pthread-compatible lib can implement the - * locks without types and we can fail when linking with - * them. However since we used to find bugs with this - * strict check we still keep it around. Hopefully this - * could be a good hint when it fails again. If one day - * it'll break on some other impl of glibc we'll revisit. - */ - if (msg->arg.pagefault.flags & UFFD_PAGEFAULT_FLAG_WRITE) - err("unexpected write fault"); - - offset = (char *)(unsigned long)msg->arg.pagefault.address - area_dst; - offset &= ~(page_size-1); - - if (copy_page(uffd, offset)) - stats->missing_faults++; - } -} - -static void *uffd_poll_thread(void *arg) -{ - struct uffd_stats *stats = (struct uffd_stats *)arg; - unsigned long cpu = stats->cpu; - struct pollfd pollfd[2]; - struct uffd_msg msg; - struct uffdio_register uffd_reg; - int ret; - char tmp_chr; - - pollfd[0].fd = uffd; - pollfd[0].events = POLLIN; - pollfd[1].fd = pipefd[cpu*2]; - pollfd[1].events = POLLIN; - - for (;;) { - ret = poll(pollfd, 2, -1); - if (ret <= 0) { - if (errno == EINTR || errno == EAGAIN) - continue; - err("poll error: %d", ret); - } - if (pollfd[1].revents & POLLIN) { - if (read(pollfd[1].fd, &tmp_chr, 1) != 1) - err("read pipefd error"); - break; - } - if (!(pollfd[0].revents & POLLIN)) - err("pollfd[0].revents %d", pollfd[0].revents); - if (uffd_read_msg(uffd, &msg)) - continue; - switch (msg.event) { - default: - err("unexpected msg event %u\n", msg.event); - break; - case UFFD_EVENT_PAGEFAULT: - uffd_handle_page_fault(&msg, stats); - break; - case UFFD_EVENT_FORK: - close(uffd); - uffd = msg.arg.fork.ufd; - pollfd[0].fd = uffd; - break; - case UFFD_EVENT_REMOVE: - uffd_reg.range.start = msg.arg.remove.start; - uffd_reg.range.len = msg.arg.remove.end - - msg.arg.remove.start; - if (ioctl(uffd, UFFDIO_UNREGISTER, &uffd_reg.range)) - err("remove failure"); - break; - case UFFD_EVENT_REMAP: - area_remap = area_dst; /* save for later unmap */ - area_dst = (char *)(unsigned long)msg.arg.remap.to; - break; - } - } - - return NULL; -} - pthread_mutex_t uffd_read_mutex = PTHREAD_MUTEX_INITIALIZER; static void *uffd_read_thread(void *arg) From patchwork Wed Apr 12 16:42:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209349 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 9E39EC7619A for ; Wed, 12 Apr 2023 16:42:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 41387280003; Wed, 12 Apr 2023 12:42:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3C391280001; Wed, 12 Apr 2023 12:42:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 26433280003; Wed, 12 Apr 2023 12:42:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 18659280001 for ; Wed, 12 Apr 2023 12:42:56 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E23031C3CAC for ; Wed, 12 Apr 2023 16:42:55 +0000 (UTC) X-FDA: 80673308310.01.CEA5002 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf29.hostedemail.com (Postfix) with ESMTP id B119912000E for ; Wed, 12 Apr 2023 16:42:53 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=AInr+zyd; spf=pass (imf29.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@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=1681317773; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=gEk7ts1lThyIvIfCL1IGZ4lKytmWVdDqEngQ3sxu8hg=; b=1pw2egvwpDkdVSQNa+S19LCbBxLkZk2vKm0u2Hl8NnVHcSR4WINQYJFPsprM6Q5LnrhDQ3 2pXR3dLRJJ/wIwzusPIqlDb9egQWUb0fYZ8//kCG+Q5MGpb49Hir9zDrPfMABWXULaqIAk ZGM2Rcm3nZmX4l1pblOJtVC+lQ6vLAQ= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=AInr+zyd; spf=pass (imf29.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681317773; a=rsa-sha256; cv=none; b=xFFxhd6bhIoEMsichMq/KqpQ5VfRYNQjsiyq2kQq1ufBzLKQ4Cx/vqJXlbDwzbmDXhej/6 jRpXCDTRdbl62/BPZizwpX7HbflQiCWn7sYeeda7JawO1vHbYH+GvK6eRYQrtBkL+fIhMc MQiQVzVCfXe6lj4McyhyHq2k1arSOsY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317773; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gEk7ts1lThyIvIfCL1IGZ4lKytmWVdDqEngQ3sxu8hg=; b=AInr+zydDLv8KMf+jGQgonCp27sa1TKqUvsKDrHUtdAD0hrlki7HnW2rXk/IkuYPMBia6f oDFjCD+3ern908DcmOUg5gQmHHsPkP6bnoxU/gZjyLvpCm/CNj/wG1qUTZZsRyE2XOgzVg /6OqPqtIGK7oHSmA4rpZ1LFGM1FK2/o= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-586-Pfpinnu6Mx-tXQ2b0d0P-g-1; Wed, 12 Apr 2023 12:42:52 -0400 X-MC-Unique: Pfpinnu6Mx-tXQ2b0d0P-g-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-74acb477be6so2296785a.1 for ; Wed, 12 Apr 2023 09:42:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317768; x=1683909768; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gEk7ts1lThyIvIfCL1IGZ4lKytmWVdDqEngQ3sxu8hg=; b=aouhSdmg4g29yyWTgh5SG3OSIO6apaYysyBF0+VdHNDPXWpVFi9tIwQI3F1k/lteOe 7/xGra7+7nin1yGc1UzRoah+liOCL6KvYga/ThRS4kKGyX0S9Cztj2MAAJr9hqMkbmap ARoIuW84mDBEpXI4BtqUL08awgvdZGgInBvmbs/AY08vnr867zUllZyg5NMjgD6scURs Jei92kslb7YxzT23oulRb6u0uWwTCQeKlzRMFUncIQjtLeMbb++h0ckF1IUHRVf3NGND ZJ0IixhGbs9xLdGu+BqSLUbjV9Mopt1BmISDiW+9UtlaGx+V2jsbDsTyDeBsBpsVyBnx YSqQ== X-Gm-Message-State: AAQBX9dI9MuN905EVkU9nszQquyBepPYi4tBCOfWvdb99pwrWMFj3jTd 3yDw5ac/cLg57zphoVnL+4F2Q17kobLExGRuf89D761CR/xzETfvw1MUAkCrIoRUw9C/wJCjtOL ynhEbIEDTWPeUdJ0v8RQ= X-Received: by 2002:a05:6214:4002:b0:5ac:463b:a992 with SMTP id kd2-20020a056214400200b005ac463ba992mr4598510qvb.0.1681317767835; Wed, 12 Apr 2023 09:42:47 -0700 (PDT) X-Google-Smtp-Source: AKy350a0pJ+/tI/6Rg99Rlojds2/BsXxwj8wuO3kxU6T8U2AdUZsBRqUPHcEr1eIDqvTv36rahRGqw== X-Received: by 2002:a05:6214:4002:b0:5ac:463b:a992 with SMTP id kd2-20020a056214400200b005ac463ba992mr4598491qvb.0.1681317767536; Wed, 12 Apr 2023 09:42:47 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id oe6-20020a056214430600b005e16003edc9sm4882592qvb.104.2023.04.12.09.42.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:42:46 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Andrea Arcangeli , Mike Kravetz , Nadav Amit , David Hildenbrand , Mike Rapoport , Axel Rasmussen , Leonardo Bras Soares Passos , peterx@redhat.com, Mike Rapoport Subject: [PATCH v2 13/31] selftests/mm: Split uffd tests into uffd-stress and uffd-unit-tests Date: Wed, 12 Apr 2023 12:42:44 -0400 Message-Id: <20230412164244.328270-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Stat-Signature: juhyaneihqbcmx5nrrszbqkjjjmdok5w X-Rspam-User: X-Rspamd-Queue-Id: B119912000E X-Rspamd-Server: rspam06 X-HE-Tag: 1681317773-372183 X-HE-Meta: U2FsdGVkX19/8VSEqyWRFElji+zbQGd3t9Z/WA7CwyUz8K99VtanxZJFPsNzMAoqPsXorOG9QbcTSM54Rr3Kk9PQnHvX+KwHaBcCCVFj8G9h+6xO+AU3wtnc2IQx0Y8B72uemA/4Te7sCD6uekwJWJWb+sv3D35R7KBhSWw5TiCbPvF/DYLvKeKOa/9D84HTxIYpk78znUr27QXri8v3DeCcfZzPAhSq5EXNn7Y7dMUxwjFl38r8bIUkM0+n+6dadcC/RVwWJfl6tPqj2yQNKpfFK5fxT3C0FLZHSmvuE3uAqskH9csTOhQ1qXaS+8Z9mWSTyyaLWtwmFnB+hr5dUhZbKv6wRPevYYknHsGvQbgxoNO5HeLwlzy0byjvJ2b56cwYC69ZaFeaX2Wcozm8KI5Oi2DQpQLrmInfy8f269iofDFLTQ6o3+HVM7cQvDYYZMm4d9+DC3jURkKQic+0gFSx54z21m0WP36QedBbZtymwVbJJAdIchHxcXLDyyamjfezPU3xmPiXs0osHFdRbmLV5ON/HeQcr3mjb6UM5wCBh6EAeF84CLkwrRYZCiTsP7mszpSWR5PN9X40wHPt2XFihOH2PSk5FFveIbXhqzTyv2EXB6Fjz+lMcrnHwv6xIUAYFSRWI7VRXL6Z7ZosuOlJucI88ZOwCsqsDFcBjBjnwVF3jhlW0zAEopvHQJ6f/nh/FKXiZ1c8Hu06+A3M8hLueQSHAtELh254zxhejjJsLe1dZRxrPnkmWYlgyQJBarHQHF17vyK5hRpzZpn5h11E++lsJWVmeJCM3iDOEOyUrhO9irrDaQAiwX6RZMMSALLdQZZKSTzcEFDhny1UpVqtuN3UXS8aU5bn3dn45bZv5TZzkdHx5l4AcnUFNIucS0i/uWWqEW0zIH6aw/vnMfprg5hsY893uASGKVLjbqghvab63F5MtawfyOKuZeOZdI1roqT9hJJnIELQEzP R62dLSle k6C55rT/CWH/spLFE6YgLbPlLTKKZCS5edVbCSp9an/+UfGljKM3h9XtEXPtD6veaIEOueH18nyZNFfkAG+TEOE5/CRwP1W7xXmTcyARK3g+3VUswml2wkGY4hJc4tpjvwU8SYnpDtE3Ck6hDJNoWHQs9YU+/P/opJNkGNYzWuDFny/6Lb52F+lPhK4yqqT4YbkgjzbVTPrgq90YZxSjJavlfPAE8qQu6YHhB9Y+T1e/Xj/GkVAgVceOXyyjBQba5BgvJ3E1sTRX6ahpj/inOoeBaOOlIp2pkgAUhr9EOvi722eVyFew2wqNEYLQwkk0WvaeOYxqqV54YGiD8yBu+Au8CpSxA2BDGrKuzAKtgMmRk+BhDTmNu6km0AcZPboBLR4uhUP2MAlgoFDDKah0T75cHsrYcYxud8vDuyf773xNTOBfBcTmdvKrvcs67EZedmZELeILYtCtNV7kyBCUUez3tC0DatZZgekIh1M6qkF1MvQ5phusXj3rCvbhOlYZ2z8rs6u9oJl+TCjXOi0Wu5ylUaRh9O6ue01o3 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: In many ways it's weird and unwanted to keep all the tests in the same userfaultfd.c at least when still in the current way. For example, it doesn't make much sense to run the stress test for each method we can create an userfaultfd handle (either via syscall or /dev/ node). It's a waste of time running this twice for the whole stress as the stress paths are the same, only the open path is different. It's also just weird to need to manually specify different types of memory to run all unit tests for the userfaultfd interface. We should be able to just run a single program and that should go through all functional uffd tests without running the stress test at all. The stress test was more for torturing and finding race conditions. We don't want to wait for stress to finish just to regress test a functional test. When we start to pile up more things on top of the same file and same functions, things start to go a bit chaos and the code is just harder to maintain too with tons of global variables. This patch creates a new test uffd-unit-tests to keep userfaultfd unit tests in the future, currently empty. Meanwhile rename the old userfaultfd.c test to uffd-stress.c. Reviewed-by: Mike Rapoport (IBM) Signed-off-by: Peter Xu Reviewed-by: Axel Rasmussen --- tools/testing/selftests/mm/.gitignore | 3 ++- tools/testing/selftests/mm/Makefile | 8 +++--- tools/testing/selftests/mm/run_vmtests.sh | 10 ++++--- .../mm/{userfaultfd.c => uffd-stress.c} | 0 tools/testing/selftests/mm/uffd-unit-tests.c | 27 +++++++++++++++++++ 5 files changed, 40 insertions(+), 8 deletions(-) rename tools/testing/selftests/mm/{userfaultfd.c => uffd-stress.c} (100%) create mode 100644 tools/testing/selftests/mm/uffd-unit-tests.c diff --git a/tools/testing/selftests/mm/.gitignore b/tools/testing/selftests/mm/.gitignore index 347277f2adc3..8917455f4f51 100644 --- a/tools/testing/selftests/mm/.gitignore +++ b/tools/testing/selftests/mm/.gitignore @@ -21,7 +21,8 @@ protection_keys protection_keys_32 protection_keys_64 madv_populate -userfaultfd +uffd-stress +uffd-unit-tests mlock-intersect-test mlock-random-test virtual_address_range diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/mm/Makefile index 36467c15ca00..5a3434419403 100644 --- a/tools/testing/selftests/mm/Makefile +++ b/tools/testing/selftests/mm/Makefile @@ -20,7 +20,7 @@ MACHINE ?= $(shell echo $(uname_M) | sed -e 's/aarch64.*/arm64/' -e 's/ppc64.*/p # Avoid accidental wrong builds, due to built-in rules working just a little # bit too well--but not quite as well as required for our situation here. # -# In other words, "make userfaultfd" is supposed to fail to build at all, +# In other words, "make $SOME_TEST" is supposed to fail to build at all, # because this Makefile only supports either "make" (all), or "make /full/path". # However, the built-in rules, if not suppressed, will pick up CFLAGS and the # initial LDLIBS (but not the target-specific LDLIBS, because those are only @@ -57,7 +57,8 @@ TEST_GEN_PROGS += mremap_test TEST_GEN_PROGS += on-fault-limit TEST_GEN_PROGS += thuge-gen TEST_GEN_PROGS += transhuge-stress -TEST_GEN_PROGS += userfaultfd +TEST_GEN_PROGS += uffd-stress +TEST_GEN_PROGS += uffd-unit-tests TEST_GEN_PROGS += soft-dirty TEST_GEN_PROGS += split_huge_page_test TEST_GEN_PROGS += ksm_tests @@ -108,7 +109,8 @@ include ../lib.mk $(TEST_GEN_PROGS): vm_util.c -$(OUTPUT)/userfaultfd: uffd-common.c +$(OUTPUT)/uffd-stress: uffd-common.c +$(OUTPUT)/uffd-unit-tests: uffd-common.c ifeq ($(MACHINE),x86_64) BINARIES_32 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_32)) diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/selftests/mm/run_vmtests.sh index ddf40f883747..efe22dc569f0 100644 --- a/tools/testing/selftests/mm/run_vmtests.sh +++ b/tools/testing/selftests/mm/run_vmtests.sh @@ -196,14 +196,16 @@ CATEGORY="gup_test" run_test ./gup_test -a # Dump pages 0, 19, and 4096, using pin_user_pages: CATEGORY="gup_test" run_test ./gup_test -ct -F 0x1 0 19 0x1000 +CATEGORY="userfaultfd" run_test ./uffd-unit-tests uffd_mods=("" ":dev") +uffd_stress_bin=./uffd-stress for mod in "${uffd_mods[@]}"; do - CATEGORY="userfaultfd" run_test ./userfaultfd anon${mod} 20 16 + CATEGORY="userfaultfd" run_test ${uffd_stress_bin} anon${mod} 20 16 # Hugetlb tests require source and destination huge pages. Pass in half # the size ($half_ufd_size_MB), which is used for *each*. - CATEGORY="userfaultfd" run_test ./userfaultfd hugetlb${mod} "$half_ufd_size_MB" 32 - CATEGORY="userfaultfd" run_test ./userfaultfd hugetlb_shared${mod} "$half_ufd_size_MB" 32 - CATEGORY="userfaultfd" run_test ./userfaultfd shmem${mod} 20 16 + CATEGORY="userfaultfd" run_test ${uffd_stress_bin} hugetlb${mod} "$half_ufd_size_MB" 32 + CATEGORY="userfaultfd" run_test ${uffd_stress_bin} hugetlb_shared${mod} "$half_ufd_size_MB" 32 + CATEGORY="userfaultfd" run_test ${uffd_stress_bin} shmem${mod} 20 16 done #cleanup diff --git a/tools/testing/selftests/mm/userfaultfd.c b/tools/testing/selftests/mm/uffd-stress.c similarity index 100% rename from tools/testing/selftests/mm/userfaultfd.c rename to tools/testing/selftests/mm/uffd-stress.c diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/selftests/mm/uffd-unit-tests.c new file mode 100644 index 000000000000..6857388783be --- /dev/null +++ b/tools/testing/selftests/mm/uffd-unit-tests.c @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Userfaultfd unit tests. + * + * Copyright (C) 2015-2023 Red Hat, Inc. + */ + +#include "uffd-common.h" + +#ifdef __NR_userfaultfd + +int main(int argc, char *argv[]) +{ + return KSFT_PASS; +} + +#else /* __NR_userfaultfd */ + +#warning "missing __NR_userfaultfd definition" + +int main(void) +{ + printf("Skipping %s (missing __NR_userfaultfd)\n", __file__); + return KSFT_SKIP; +} + +#endif /* __NR_userfaultfd */ From patchwork Wed Apr 12 16:42:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209350 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 5285BC77B6E for ; Wed, 12 Apr 2023 16:43:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E2678280008; Wed, 12 Apr 2023 12:42:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DD55D280001; Wed, 12 Apr 2023 12:42:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C4F69280008; Wed, 12 Apr 2023 12:42:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id B13B2280001 for ; Wed, 12 Apr 2023 12:42:59 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 8A129140180 for ; Wed, 12 Apr 2023 16:42:59 +0000 (UTC) X-FDA: 80673308478.27.8B8DC59 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf19.hostedemail.com (Postfix) with ESMTP id 676EE1A001B for ; Wed, 12 Apr 2023 16:42:57 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=a8IRY1Vg; spf=pass (imf19.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@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=1681317777; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ojqw0o6nNzx2NLPCFuTH85mteh7O3LjoH7u5kZisRAA=; b=rLiS4q7T3Prh0eBoPScWwJyTOMQjvR9ShdNFMzg0+GGQ8yAxd0GgX8WGzGNJ8wi6UDpply v71NUCHhdTRBfMXKvUUloMGXkvKIu3hkykFzk8oqeBn2Z60kf/bsZz2PZRb5VISYCBsExf Fa7TzmWJzyf7kY8d+xhJ9ntG4pmLGXQ= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=a8IRY1Vg; spf=pass (imf19.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681317777; a=rsa-sha256; cv=none; b=D+tO0ReXzJzriQqussU/8iDyfFEzrlbBnK/gWYpBRwxlngIUYas6oeZtgxdUK2DL4SlIzq Uy2z9oytHoG7hI2mnqDdvn9eIkgw18X43lauawUBTuL6RmqwXNyf8zGPbagDQdjwRZfVMb c8N9JtK/BjMQpaxyk1Zkd+2h9ybCEQQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317776; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ojqw0o6nNzx2NLPCFuTH85mteh7O3LjoH7u5kZisRAA=; b=a8IRY1VgBBUAswVlui6nvL/S3PrBOT6mPNdb0lGHQ8OLYHpBWcA9/oiVESYp3OGW+3DPpI cdFRQQkydBjwuzvQwB63/KS3Bg1xyol3B4uXPaq26SRt2w60xA7Az119cHB4y8RDc+8mmb S7587fRdEABwpTt80ZD91u2fNJgRQ6Q= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-373-hXdJIF6XOZatrOahsEcLEA-1; Wed, 12 Apr 2023 12:42:55 -0400 X-MC-Unique: hXdJIF6XOZatrOahsEcLEA-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-74acb477be6so2298085a.1 for ; Wed, 12 Apr 2023 09:42:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317774; x=1683909774; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ojqw0o6nNzx2NLPCFuTH85mteh7O3LjoH7u5kZisRAA=; b=FWMcGd+bRC/Rz3vt78KgAKWCqHMis8+9EUyuesV8QwXVri1Kqw/pA6U6qgHQ11ZMXe nHoaCJi94N0yQnUtjRRiRk/C+N6s9s4tf3qoY5f+nn1qZqSV90orHc6SqPpHLGvONNAg 8BFB/Z9aKopw10ddG63HYrNmL/8HRsm+C3a3UDTi24A62kuhhb9+RLmH1qXpzjs5qqAU pK5yZAR/4qQr10Xe1Q7t3JBPXEO/BPqKZAoCjDMB3xbut8YJpE+Z26/RS78zivFPNHW+ T772w3/+jipdXsJzW1FlBQaRBYQxbplrCX00SsqgRLcEhCuQI9Zyhoo4MoTpIugExDOL BxAA== X-Gm-Message-State: AAQBX9d7aX7Jm+XcfyS0yuXLbNGd5x/HfJvvnNioGiucNmGkz3wL1crB 6tfSca6sgOALQ48JJPuWrCIFL8bbvasoUv/cbQLw45Msze3YHeRpMsF5iK6xc3WWCrXzceieW5G dHmMDxQ3fmCk= X-Received: by 2002:a05:6214:529e:b0:532:141d:3750 with SMTP id kj30-20020a056214529e00b00532141d3750mr4507648qvb.2.1681317774388; Wed, 12 Apr 2023 09:42:54 -0700 (PDT) X-Google-Smtp-Source: AKy350ZZiNYvtLNaUrZK97U0yXiPXuXJq4154VRxXp1Kfb8XAq8hOWTf5d/hKo1brcX+fmf478dwLA== X-Received: by 2002:a05:6214:529e:b0:532:141d:3750 with SMTP id kj30-20020a056214529e00b00532141d3750mr4507612qvb.2.1681317774057; Wed, 12 Apr 2023 09:42:54 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id l11-20020ac84a8b000000b003e89e2b3c23sm410577qtq.58.2023.04.12.09.42.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:42:53 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Andrea Arcangeli , Mike Kravetz , Nadav Amit , David Hildenbrand , Mike Rapoport , Axel Rasmussen , Leonardo Bras Soares Passos , peterx@redhat.com Subject: [PATCH v2 14/31] selftests/mm: uffd_[un]register() Date: Wed, 12 Apr 2023 12:42:47 -0400 Message-Id: <20230412164247.328293-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 676EE1A001B X-Rspam-User: X-Stat-Signature: suwdrh5uc3tdjfe7b6habtzfadxsrdak X-HE-Tag: 1681317777-770784 X-HE-Meta: U2FsdGVkX1+dCSo70Ebiw/IVQgf2U4vaiX1BAy24I5XY8d+SvvyiW1i1hxKNLTdqfgselC7EXA13ZlFYFE5DqeTYVMAhv8ZBOD+PFKxgYJPetcA0Qz4jmaH5NjzBJzpgu4CyCzy0ibI7OfC/dT+2K26FPw3+gh1qgId2/5UE9e/9z8mScxhVEOuMYGaXj7XgAl33vsLDFTN9T7h3XhbYUryl5IC5J57NlXWwTKtlCYecRhp20Y1wQUs0mMb9PfyyMMWGikmSy0aJZSxw1xdIhF03KYHn5u0Dv3ssJF2wJfG/FTkOjk3zFqvQJ1E7uONhKq/ySogrRLJgSoj+xRsLWvvDJovGcNnw7b7rS6uUMN7Bdu2hZtIb9GRAytnXCzYNas1ZZakWUbCkT00xoAgsmOIOuZwWUaDUPUonnls9WODCFPGoPeCQKNgRbZh0Gtyx5hGUDGF+wpa+Oy1dGoc1mFbq8g17xlPn4aWnoGLIBuihPxWvgmAphNiS2JyZxNaRxUN37Zon0vZQydWOF2MwJTG/215QdoG9Wx5Tb8mtze/K61QGFeuMypqaagyqdjuE5Sc+p2nU9ImBWqGBI6vRBBiwCRHHiXaszwMLwP0rAbpeBKvMPAawpMlAZHgVWHOoJnIyoSMbE9g4V0JbGb9U/HgXGaDkKJdMsHtDxw5ctpQW3cw+8ix/+mZPeaEJgWBHaS0csI7ftQZtS1sSHS3cbCvEQy5taTiUol/z3ppstzK5UF7g3Bp1410F356aWBtkX9x/reINlN/iphPHFzO/Z5i95lnCb0HZ2LE7JV5clPtGPHdX+/CdihzHKqKIrEdlJc5BYjgkH8C+1T46JuU9OfBxkglnObppyEZZDGyDX/lbAhrQrm2Gwf+h1mUUUDZ/7zCJVN8C2Q5s0Y6tZAfnhP4Vxcz1YOmoFhJVUt3Q8YVCMhSaQ03z4tjywnuoz5aAxAwMy7GsrxAimp8k9Qc 4U50nuxc ex0aovgiBf5ikk4lwYpTQX3rE5IAvZAGcplVTCFL/IpEmGT0tNCRPb7rP0SjaW85lXTNuaxXR6zwDWf+Hx8wKDRJlgNhzddqo18HE/7dXjuXbS2Dkv3tJQlrKBK83DUFV2TlXVRi35GCUrezfBSuJKbnwOVWUAxJJBGhSjTHbRgr98W63+Dg0syqdhAf1TutU27g+qWauOdtWZ1tlazdCPujWjf839NjODsT7hLchxAicF6fDrAKZDacMmBn6fijf8iFrcCXszN+fj5O3O5IvZ1bWUFfFQDp27r8YbZ2SWTANtRdbcE2fbPLCsBaqGgs7gTCUfNmdQkFJCueBIUnR1yC1ttKsP7PekXcMrLGSmhstxx95BAVp7bmgObL6O3AT6ykBko4G8LHlIqSBgYPzAMh9r7NcdDEaOMqR4rLQC7pchIkE6vQhjhv34oFtw5/WzXvLXm/hHI/zu5ZoNDZj6u3lN0fdxZZTr6CWxOLcozRBdeOAvB1DY+B4q1chdLM/6E9ggCNNpNn3eydcXmmKs/uZyOiuJCpIjzxAvrgba/ZiiKM= 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: Add two helpers to register/unregister to an uffd. Use them to drop duplicate codes. This patch also drops assert_expected_ioctls_present() and get_expected_ioctls(). Reasons: - It'll need a lot of effort to pass test_type==HUGETLB into it from the upper, so it's the simplest way to get rid of another global var - The ioctls returned in UFFDIO_REGISTER is hardly useful at all, because any app can already detect kernel support on any ioctl via its corresponding UFFD_FEATURE_*. The check here is for sanity mostly but it's probably destined no user app will even use it. - It's not friendly to one future goal of uffd to run on old kernels, the problem is get_expected_ioctls() compiles against UFFD_API_RANGE_IOCTLS, which is a value that can change depending on where the test is compiled, rather than reflecting what the kernel underneath has. It means it'll report false negatives on old kernels so it's against our will. So let's make our live easier. Signed-off-by: Peter Xu Reviewed-by: Axel Rasmussen --- tools/testing/selftests/mm/hugepage-mremap.c | 7 +- .../selftests/mm/ksm_functional_tests.c | 6 +- tools/testing/selftests/mm/uffd-common.c | 27 ------ tools/testing/selftests/mm/uffd-common.h | 2 - tools/testing/selftests/mm/uffd-stress.c | 83 +++++-------------- tools/testing/selftests/mm/vm_util.c | 37 +++++++++ tools/testing/selftests/mm/vm_util.h | 4 + 7 files changed, 62 insertions(+), 104 deletions(-) diff --git a/tools/testing/selftests/mm/hugepage-mremap.c b/tools/testing/selftests/mm/hugepage-mremap.c index e53b5eaa8fce..2084692fe1c4 100644 --- a/tools/testing/selftests/mm/hugepage-mremap.c +++ b/tools/testing/selftests/mm/hugepage-mremap.c @@ -60,7 +60,6 @@ static void register_region_with_uffd(char *addr, size_t len) { long uffd; /* userfaultfd file descriptor */ struct uffdio_api uffdio_api; - struct uffdio_register uffdio_register; /* Create and enable userfaultfd object. */ @@ -96,11 +95,7 @@ static void register_region_with_uffd(char *addr, size_t len) * handling by the userfaultfd object. In mode, we request to track * missing pages (i.e., pages that have not yet been faulted in). */ - - uffdio_register.range.start = (unsigned long)addr; - uffdio_register.range.len = len; - uffdio_register.mode = UFFDIO_REGISTER_MODE_MISSING; - if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register) == -1) { + if (uffd_register(uffd, addr, len, true, false, false)) { perror("ioctl-UFFDIO_REGISTER"); exit(1); } diff --git a/tools/testing/selftests/mm/ksm_functional_tests.c b/tools/testing/selftests/mm/ksm_functional_tests.c index d8b5b4930412..d3f26050dfd7 100644 --- a/tools/testing/selftests/mm/ksm_functional_tests.c +++ b/tools/testing/selftests/mm/ksm_functional_tests.c @@ -178,7 +178,6 @@ static void test_unmerge_discarded(void) static void test_unmerge_uffd_wp(void) { struct uffdio_writeprotect uffd_writeprotect; - struct uffdio_register uffdio_register; const unsigned int size = 2 * MiB; struct uffdio_api uffdio_api; char *map; @@ -210,10 +209,7 @@ static void test_unmerge_uffd_wp(void) } /* Register UFFD-WP, no need for an actual handler. */ - uffdio_register.range.start = (unsigned long) map; - uffdio_register.range.len = size; - uffdio_register.mode = UFFDIO_REGISTER_MODE_WP; - if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register) < 0) { + if (uffd_register(uffd, map, size, false, true, false)) { ksft_test_result_fail("UFFDIO_REGISTER_MODE_WP failed\n"); goto close_uffd; } diff --git a/tools/testing/selftests/mm/uffd-common.c b/tools/testing/selftests/mm/uffd-common.c index c57757c2a36f..daa5b5781e7a 100644 --- a/tools/testing/selftests/mm/uffd-common.c +++ b/tools/testing/selftests/mm/uffd-common.c @@ -330,33 +330,6 @@ void uffd_test_ctx_init(uint64_t features) err("pipe"); } -uint64_t get_expected_ioctls(uint64_t mode) -{ - uint64_t ioctls = UFFD_API_RANGE_IOCTLS; - - if (test_type == TEST_HUGETLB) - ioctls &= ~(1 << _UFFDIO_ZEROPAGE); - - if (!((mode & UFFDIO_REGISTER_MODE_WP) && test_uffdio_wp)) - ioctls &= ~(1 << _UFFDIO_WRITEPROTECT); - - if (!((mode & UFFDIO_REGISTER_MODE_MINOR) && test_uffdio_minor)) - ioctls &= ~(1 << _UFFDIO_CONTINUE); - - return ioctls; -} - -void assert_expected_ioctls_present(uint64_t mode, uint64_t ioctls) -{ - uint64_t expected = get_expected_ioctls(mode); - uint64_t actual = ioctls & expected; - - if (actual != expected) { - err("missing ioctl(s): expected %"PRIx64" actual: %"PRIx64, - expected, actual); - } -} - void wp_range(int ufd, __u64 start, __u64 len, bool wp) { struct uffdio_writeprotect prms; diff --git a/tools/testing/selftests/mm/uffd-common.h b/tools/testing/selftests/mm/uffd-common.h index d9430cfdcb19..11f770391bd9 100644 --- a/tools/testing/selftests/mm/uffd-common.h +++ b/tools/testing/selftests/mm/uffd-common.h @@ -101,8 +101,6 @@ extern uffd_test_ops_t *uffd_test_ops; void uffd_stats_report(struct uffd_stats *stats, int n_cpus); void uffd_test_ctx_init(uint64_t features); void userfaultfd_open(uint64_t *features); -uint64_t get_expected_ioctls(uint64_t mode); -void assert_expected_ioctls_present(uint64_t mode, uint64_t ioctls); int uffd_read_msg(int ufd, struct uffd_msg *msg); void wp_range(int ufd, __u64 start, __u64 len, bool wp); void uffd_handle_page_fault(struct uffd_msg *msg, struct uffd_stats *stats); diff --git a/tools/testing/selftests/mm/uffd-stress.c b/tools/testing/selftests/mm/uffd-stress.c index c68a9aeefc41..e6d39a755082 100644 --- a/tools/testing/selftests/mm/uffd-stress.c +++ b/tools/testing/selftests/mm/uffd-stress.c @@ -463,28 +463,19 @@ static int uffdio_zeropage(int ufd, unsigned long offset) /* exercise UFFDIO_ZEROPAGE */ static int userfaultfd_zeropage_test(void) { - struct uffdio_register uffdio_register; - printf("testing UFFDIO_ZEROPAGE: "); fflush(stdout); uffd_test_ctx_init(0); - uffdio_register.range.start = (unsigned long) area_dst; - uffdio_register.range.len = nr_pages * page_size; - uffdio_register.mode = UFFDIO_REGISTER_MODE_MISSING; - if (test_uffdio_wp) - uffdio_register.mode |= UFFDIO_REGISTER_MODE_WP; - if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register)) + if (uffd_register(uffd, area_dst, nr_pages * page_size, + true, test_uffdio_wp, false)) err("register failure"); - assert_expected_ioctls_present( - uffdio_register.mode, uffdio_register.ioctls); - if (area_dst_alias) { /* Needed this to test zeropage-retry on shared memory */ - uffdio_register.range.start = (unsigned long) area_dst_alias; - if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register)) + if (uffd_register(uffd, area_dst_alias, nr_pages * page_size, + true, test_uffdio_wp, false)) err("register failure"); } @@ -498,7 +489,6 @@ static int userfaultfd_zeropage_test(void) static int userfaultfd_events_test(void) { - struct uffdio_register uffdio_register; pthread_t uffd_mon; int err, features; pid_t pid; @@ -514,17 +504,10 @@ static int userfaultfd_events_test(void) fcntl(uffd, F_SETFL, uffd_flags | O_NONBLOCK); - uffdio_register.range.start = (unsigned long) area_dst; - uffdio_register.range.len = nr_pages * page_size; - uffdio_register.mode = UFFDIO_REGISTER_MODE_MISSING; - if (test_uffdio_wp) - uffdio_register.mode |= UFFDIO_REGISTER_MODE_WP; - if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register)) + if (uffd_register(uffd, area_dst, nr_pages * page_size, + true, test_uffdio_wp, false)) err("register failure"); - assert_expected_ioctls_present( - uffdio_register.mode, uffdio_register.ioctls); - if (pthread_create(&uffd_mon, &attr, uffd_poll_thread, &stats)) err("uffd_poll_thread create"); @@ -550,7 +533,6 @@ static int userfaultfd_events_test(void) static int userfaultfd_sig_test(void) { - struct uffdio_register uffdio_register; unsigned long userfaults; pthread_t uffd_mon; int err, features; @@ -566,17 +548,10 @@ static int userfaultfd_sig_test(void) fcntl(uffd, F_SETFL, uffd_flags | O_NONBLOCK); - uffdio_register.range.start = (unsigned long) area_dst; - uffdio_register.range.len = nr_pages * page_size; - uffdio_register.mode = UFFDIO_REGISTER_MODE_MISSING; - if (test_uffdio_wp) - uffdio_register.mode |= UFFDIO_REGISTER_MODE_WP; - if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register)) + if (uffd_register(uffd, area_dst, nr_pages * page_size, + true, test_uffdio_wp, false)) err("register failure"); - assert_expected_ioctls_present( - uffdio_register.mode, uffdio_register.ioctls); - if (faulting_process(1)) err("faulting process failed"); @@ -629,7 +604,6 @@ void check_memory_contents(char *p) static int userfaultfd_minor_test(void) { unsigned long p; - struct uffdio_register uffdio_register; pthread_t uffd_mon; char c; struct uffd_stats stats = { 0 }; @@ -642,17 +616,10 @@ static int userfaultfd_minor_test(void) uffd_test_ctx_init(uffd_minor_feature()); - uffdio_register.range.start = (unsigned long)area_dst_alias; - uffdio_register.range.len = nr_pages * page_size; - uffdio_register.mode = UFFDIO_REGISTER_MODE_MINOR; - if (test_uffdio_wp) - uffdio_register.mode |= UFFDIO_REGISTER_MODE_WP; - if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register)) + if (uffd_register(uffd, area_dst_alias, nr_pages * page_size, + false, test_uffdio_wp, true)) err("register failure"); - assert_expected_ioctls_present( - uffdio_register.mode, uffdio_register.ioctls); - /* * After registering with UFFD, populate the non-UFFD-registered side of * the shared mapping. This should *not* trigger any UFFD minor faults. @@ -777,7 +744,6 @@ static void userfaultfd_wp_unpopulated_test(int pagemap_fd) static void userfaultfd_pagemap_test(unsigned int test_pgsize) { - struct uffdio_register uffdio_register; int pagemap_fd; uint64_t value; @@ -805,10 +771,8 @@ static void userfaultfd_pagemap_test(unsigned int test_pgsize) err("madvise(MADV_NOHUGEPAGE) failed"); } - uffdio_register.range.start = (unsigned long) area_dst; - uffdio_register.range.len = nr_pages * page_size; - uffdio_register.mode = UFFDIO_REGISTER_MODE_WP; - if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register)) + if (uffd_register(uffd, area_dst, nr_pages * page_size, + false, true, false)) err("register failed"); pagemap_fd = pagemap_open(); @@ -858,8 +822,8 @@ static int userfaultfd_stress(void) { void *area; unsigned long nr; - struct uffdio_register uffdio_register; struct uffd_stats uffd_stats[nr_cpus]; + uint64_t mem_size = nr_pages * page_size; uffd_test_ctx_init(UFFD_FEATURE_WP_UNPOPULATED); @@ -894,20 +858,13 @@ static int userfaultfd_stress(void) fcntl(uffd, F_SETFL, uffd_flags & ~O_NONBLOCK); /* register */ - uffdio_register.range.start = (unsigned long) area_dst; - uffdio_register.range.len = nr_pages * page_size; - uffdio_register.mode = UFFDIO_REGISTER_MODE_MISSING; - if (test_uffdio_wp) - uffdio_register.mode |= UFFDIO_REGISTER_MODE_WP; - if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register)) + if (uffd_register(uffd, area_dst, mem_size, + true, test_uffdio_wp, false)) err("register failure"); - assert_expected_ioctls_present( - uffdio_register.mode, uffdio_register.ioctls); if (area_dst_alias) { - uffdio_register.range.start = (unsigned long) - area_dst_alias; - if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register)) + if (uffd_register(uffd, area_dst_alias, mem_size, + true, test_uffdio_wp, false)) err("register failure alias"); } @@ -949,12 +906,10 @@ static int userfaultfd_stress(void) nr_pages * page_size, false); /* unregister */ - if (ioctl(uffd, UFFDIO_UNREGISTER, &uffdio_register.range)) + if (uffd_unregister(uffd, area_dst, mem_size)) err("unregister failure"); if (area_dst_alias) { - uffdio_register.range.start = (unsigned long) area_dst; - if (ioctl(uffd, UFFDIO_UNREGISTER, - &uffdio_register.range)) + if (uffd_unregister(uffd, area_dst_alias, mem_size)) err("unregister failure alias"); } diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c index 54d227d6f70a..bb633d050d71 100644 --- a/tools/testing/selftests/mm/vm_util.c +++ b/tools/testing/selftests/mm/vm_util.c @@ -1,6 +1,8 @@ // SPDX-License-Identifier: GPL-2.0 #include #include +#include +#include #include "../kselftest.h" #include "vm_util.h" @@ -193,3 +195,38 @@ unsigned long default_huge_page_size(void) fclose(f); return hps; } + +int uffd_register(int uffd, void *addr, uint64_t len, + bool miss, bool wp, bool minor) +{ + struct uffdio_register uffdio_register = { 0 }; + uint64_t mode = 0; + int ret = 0; + + if (miss) + mode |= UFFDIO_REGISTER_MODE_MISSING; + if (wp) + mode |= UFFDIO_REGISTER_MODE_WP; + if (minor) + mode |= UFFDIO_REGISTER_MODE_MINOR; + + uffdio_register.range.start = (unsigned long)addr; + uffdio_register.range.len = len; + uffdio_register.mode = mode; + + if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register) == -1) + ret = -errno; + + return ret; +} + +int uffd_unregister(int uffd, void *addr, uint64_t len) +{ + struct uffdio_range range = { .start = (uintptr_t)addr, .len = len }; + int ret = 0; + + if (ioctl(uffd, UFFDIO_UNREGISTER, &range) == -1) + ret = -errno; + + return ret; +} diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h index d9fadddb5c69..3a9762022efd 100644 --- a/tools/testing/selftests/mm/vm_util.h +++ b/tools/testing/selftests/mm/vm_util.h @@ -45,6 +45,10 @@ bool check_huge_shmem(void *addr, int nr_hpages, uint64_t hpage_size); int64_t allocate_transhuge(void *ptr, int pagemap_fd); unsigned long default_huge_page_size(void); +int uffd_register(int uffd, void *addr, uint64_t len, + bool miss, bool wp, bool minor); +int uffd_unregister(int uffd, void *addr, uint64_t len); + /* * On ppc64 this will only work with radix 2M hugepage size */ From patchwork Wed Apr 12 16:42:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209351 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 1147CC7619A for ; Wed, 12 Apr 2023 16:43:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A7B72280009; Wed, 12 Apr 2023 12:43:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A2BFE280001; Wed, 12 Apr 2023 12:43:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8CD56280009; Wed, 12 Apr 2023 12:43:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 782FC280001 for ; Wed, 12 Apr 2023 12:43:02 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 483C21C4843 for ; Wed, 12 Apr 2023 16:43:02 +0000 (UTC) X-FDA: 80673308604.26.6033DF2 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf01.hostedemail.com (Postfix) with ESMTP id 3CB414000F for ; Wed, 12 Apr 2023 16:43:00 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Fqt+253y; spf=pass (imf01.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@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=1681317780; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=AoupzZV60neLuDl2cXNTlifM0oGkfquzJdJQPjel9/o=; b=j5SKLkDoVMN+OG3hJJcI7DmbQRbifFTXTIIU7AGUhULZ4XLQrQ8pzhNhH2HsZtV6GF1r/x gl62qwzIId4HeKJcMnk/oTCW3baJKl431QxUWXk0zYNuSQurZ9d2WwqjfyHGhiC7c5g9Mx XGZlCJtg0anqFlkSoGKlWuim8tffy2U= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Fqt+253y; spf=pass (imf01.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681317780; a=rsa-sha256; cv=none; b=d97b5UcwJdin4fFHYhmsnODLn9+LzOdpxkdE4yYyoP6huRjmOmPjsKnkD9F2or0BdjHbZr vKr5077D/x1DpMVofSFFgUTa7ElkpBKUIylPPIa18ZinEp2A9uJSZE8eB+7787jDwPWaIh BM63s8dKwPL9ZkkSeANud/48QsBM+dM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317779; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AoupzZV60neLuDl2cXNTlifM0oGkfquzJdJQPjel9/o=; b=Fqt+253yEMSRCci++usohz4ZPLJQ7tz1q59G1I+5yPwxd66T0yAdDxjBZqCbYBtSrzM45t ojpfNHNlhNFL3jtx9/8ioxXO9hfv2e7y5MiY3aksvu5RLwrfKbH1yMkulY04gpiEqlJ7KN Tbuvo4oFuIpwD+blmZ80v+H27ryjNWQ= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-19-LE_4LeqFOFK63_7aV7twIw-1; Wed, 12 Apr 2023 12:42:58 -0400 X-MC-Unique: LE_4LeqFOFK63_7aV7twIw-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-5ea572ef499so7657286d6.1 for ; Wed, 12 Apr 2023 09:42:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317777; x=1683909777; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AoupzZV60neLuDl2cXNTlifM0oGkfquzJdJQPjel9/o=; b=lwLBIP4UGIyZdHeEd0gmeqRi5hnhs32bA0cGJ/lxs2Ni1cUASeqb8qnXHxQBhckOWq 62CPGi4l02DyBEtIZHcYsgsmz8e3QJ4rVy6hjlcHmGcTx/Rq3QrkXZJMEGwQUxGbnYbO ATTJPWW42ZRtsuQ8X5BOm+1yt9MqnOj0n4EqcJt8KfQlSQbnf3KRpUVt7nDDRhbrAP5a t261R3065MuIwhx7hDlE4XXfJ4Dbat9Ns2AaArmWLkU6ItJAMVZ+QaNTwzNssHooWaw/ 0LTFPhOAJOs/98eGY79AvFoYZpVVz7UgoPDk61iIIrg+Gy2hEccsy1eJ/DoLzhEa5Qpx my5w== X-Gm-Message-State: AAQBX9cuveaES9v45c8eMdJhUxgdGe3Bqy4/mcSzLps8viFWg5eXnL5v ZFOzsdtUAyVtXcA/nxy2vqBh/j16n49INpL1JtuHh0G2Ti6b6SnrQJgd9FCwNrLo7Ia7B8OdbX1 9UyUBDV2gbEW9x/jyeLs= X-Received: by 2002:a05:6214:5290:b0:5ed:c96e:ca4a with SMTP id kj16-20020a056214529000b005edc96eca4amr14523310qvb.1.1681317777450; Wed, 12 Apr 2023 09:42:57 -0700 (PDT) X-Google-Smtp-Source: AKy350bfOXnCx58JgZiPwX0xXvF0Ya2D7UIXCwQklBBts7OkUAc2gH540xRewo9GNFpZt0OMQoqV1g== X-Received: by 2002:a05:6214:5290:b0:5ed:c96e:ca4a with SMTP id kj16-20020a056214529000b005edc96eca4amr14523277qvb.1.1681317777138; Wed, 12 Apr 2023 09:42:57 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id o24-20020a05620a229800b00747d211536dsm4766694qkh.107.2023.04.12.09.42.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:42:56 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Andrea Arcangeli , Mike Kravetz , Nadav Amit , David Hildenbrand , Mike Rapoport , Axel Rasmussen , Leonardo Bras Soares Passos , peterx@redhat.com, Mike Rapoport Subject: [PATCH v2 15/31] selftests/mm: uffd_open_{dev|sys}() Date: Wed, 12 Apr 2023 12:42:54 -0400 Message-Id: <20230412164254.328335-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: 3CB414000F X-Stat-Signature: d696fow6gk8ii9ioi9uqgisgd8tdo8er X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1681317780-952691 X-HE-Meta: U2FsdGVkX197MnVXSptYhZaAbNphnJiXYGkEw+fMIBNTn0F9bBjfKur1jT1I4owB3WluevqMFGuMgFMN16df4RgSapTFwX9XmqIXiQiI7oI9CkJTcLAlUz8i3Juwej9dtYSLokMSR8ad3xIwCB3JsOxOi5tEPRZC+EMU9CLsS9Pj6JtHTpD110XQ0VOvfgRjllFAQa2ivKz+/J5QDAKSFc+Uy2Fu3w4YrGn76GDV87/lAfjZLNDlwkq8Z+2h5KLf34AunY9CxGx8EM/oeWwZayMN2UzM2iBebZiDxG0a6tlsWcoghvrQafefVV3wdUCsXhpUarkAplRBqsNjuHhR3kyxOD6/tzCD5qjfgDFQphr/GFvLQMovLGZmzdh+YYDupNcT1+US3tmQU57lVRldqabpRxdmOBRfe18+YsBRru4X0rKakbZy7PJilxpHiPU36ZUna13m/wBcdopfmlYh7MMIXv+bs/XWgODiBT3yQ/4VxHsdEbg2tfyTHk2ofWmz24/yOH17itSTBerHMVFX2D/fGJr/7VyLfkkthyhWHYmLOHRQ93ULdiZ7vRpXSsIVhJeoSO/GmBGSao/TPkkvNQDp8Kjut8wSSLM8FrBY0cAtWIzKMd6a3USKn52LaNu8Kcv/t9k3F3ifRj/EwR9sXPgKCzJ9HP6uld3CcQ3fWzdkmZbvK5wZYqo4SUGiiImoTA+9MDYIemXTilxWa9gMB9EAv85n9Q6NjEh7OtKSa1WpswQmzlA8nBBEcPMm6bsS7It0gRKIcdxiLViAocfvJEXiOdps9pFRFW9Bj75jp7kRete9PK7BGvXboP7EFm67Ofp35bnLlaXJdCGepluJ0hTRVM01xE1We3HFpqofPSBfMhxzStdvD1fTqDAtV3DSWwl3ADYn6pcbl0W0AH2+CEpGmXEiwjViBNdNOfhwl7saITXvhKn/KOJkJbQOfX7/np0WFjfVlVvhV5lmvvy FEd1Mu+M +8/sdd93XXhvLXhfakX7e3kYcanETVtSMTa6/ytYoA3LSN7AMjMu3F9nOw42PQSS4ebhC7TwB4A5zAnb/fH/MriQlkaoEqbzcMVjyxzLzEtuyo27vHzmrohkVcVBp6NvpGCMX2RSxNr9mAAjTSQKgCxl3q7wC3V2YQ4w9HWyNtqZAcfno+tngM73VHlmAPO/+uEWOy8vI65RCUM2FADc7hhWA/O4coTLXHHEEfWyG/GOmod6LmyfHB4K/h0pu3WGESz3GaGGqYioI2qzJxN2KbhVbZ46YYx7SqmyMkj5RZFQuCrYxzuea9e10jpwkQ/tGU9d4+NysbBQIjM9yGhunwVPS67VQIhYo0gkm95bw3/0NL0cTW5jSczpExBsMM5uU5vlv0IyjMIxtNgPFTuP/aVlYc5Ez6ItkfW87rHblXcKuLJeUeonhyWb5jR7VG2dzNM7kFw/KEZmOAHkz4gVz1i5O2lUpkTtMxOOkBMdzxq0qGJVlOBup61u4xCvUMcP95OHKPrCtkVnEhtBjAYeD4DIrF5Aoti8dwVsqaFM/CXuwiCWDIGAZy+c0btdGMAl2jOuWCUlnzO0beLA= 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: Provide two helpers to open an uffd handle. Drop the error checks around SKIPs because it's inside an errexit() anyway, which IMHO doesn't really help much if the test will not continue. Reviewed-by: David Hildenbrand Reviewed-by: Mike Rapoport (IBM) Signed-off-by: Peter Xu Reviewed-by: Axel Rasmussen --- tools/testing/selftests/mm/uffd-common.c | 28 +++++------------------- tools/testing/selftests/mm/vm_util.c | 24 ++++++++++++++++++++ tools/testing/selftests/mm/vm_util.h | 2 ++ 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-common.c b/tools/testing/selftests/mm/uffd-common.c index daa5b5781e7a..09ea24c5f02c 100644 --- a/tools/testing/selftests/mm/uffd-common.c +++ b/tools/testing/selftests/mm/uffd-common.c @@ -192,34 +192,16 @@ void uffd_stats_report(struct uffd_stats *stats, int n_cpus) printf("\n"); } -static int __userfaultfd_open_dev(void) -{ - int fd, _uffd; - - fd = open("/dev/userfaultfd", O_RDWR | O_CLOEXEC); - if (fd < 0) - errexit(KSFT_SKIP, "opening /dev/userfaultfd failed"); - - _uffd = ioctl(fd, USERFAULTFD_IOC_NEW, UFFD_FLAGS); - if (_uffd < 0) - errexit(errno == ENOTTY ? KSFT_SKIP : 1, - "creating userfaultfd failed"); - close(fd); - return _uffd; -} - void userfaultfd_open(uint64_t *features) { struct uffdio_api uffdio_api; if (test_dev_userfaultfd) - uffd = __userfaultfd_open_dev(); - else { - uffd = syscall(__NR_userfaultfd, UFFD_FLAGS); - if (uffd < 0) - errexit(errno == ENOSYS ? KSFT_SKIP : 1, - "creating userfaultfd failed"); - } + uffd = uffd_open_dev(UFFD_FLAGS); + else + uffd = uffd_open_sys(UFFD_FLAGS); + if (uffd < 0) + err("uffd open failed (dev=%d)", test_dev_userfaultfd); uffd_flags = fcntl(uffd, F_GETFD, NULL); uffdio_api.api = UFFD_API; diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c index bb633d050d71..5ee6c4688a7c 100644 --- a/tools/testing/selftests/mm/vm_util.c +++ b/tools/testing/selftests/mm/vm_util.c @@ -3,6 +3,8 @@ #include #include #include +#include +#include #include "../kselftest.h" #include "vm_util.h" @@ -230,3 +232,25 @@ int uffd_unregister(int uffd, void *addr, uint64_t len) return ret; } + +int uffd_open_dev(unsigned int flags) +{ + int fd, uffd; + + fd = open("/dev/userfaultfd", O_RDWR | O_CLOEXEC); + if (fd < 0) + return fd; + uffd = ioctl(fd, USERFAULTFD_IOC_NEW, flags); + close(fd); + + return uffd; +} + +int uffd_open_sys(unsigned int flags) +{ +#ifdef __NR_userfaultfd + return syscall(__NR_userfaultfd, flags); +#else + return -1; +#endif +} diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h index 3a9762022efd..481354141533 100644 --- a/tools/testing/selftests/mm/vm_util.h +++ b/tools/testing/selftests/mm/vm_util.h @@ -48,6 +48,8 @@ unsigned long default_huge_page_size(void); int uffd_register(int uffd, void *addr, uint64_t len, bool miss, bool wp, bool minor); int uffd_unregister(int uffd, void *addr, uint64_t len); +int uffd_open_dev(unsigned int flags); +int uffd_open_sys(unsigned int flags); /* * On ppc64 this will only work with radix 2M hugepage size From patchwork Wed Apr 12 16:42:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209352 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 1E8DDC77B6E for ; Wed, 12 Apr 2023 16:43:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B3EDE28000A; Wed, 12 Apr 2023 12:43:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AF23F280001; Wed, 12 Apr 2023 12:43:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 990E128000A; Wed, 12 Apr 2023 12:43:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 87FDF280001 for ; Wed, 12 Apr 2023 12:43:10 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 57987140198 for ; Wed, 12 Apr 2023 16:43:10 +0000 (UTC) X-FDA: 80673308940.05.D72B727 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf19.hostedemail.com (Postfix) with ESMTP id 28CE91A0011 for ; Wed, 12 Apr 2023 16:43:07 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=jApp4+VN; spf=pass (imf19.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@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=1681317788; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=j2X1citdDCADI79RLi2EG2irLSOXCvsNG1ixWpJWId4=; b=A8zURgVP3mpLWG4ZwE2Tz4JqCwctk1WjRdlNMTL789fc3mdpiy5Nh1yhjCyRy//QNrRuoX cIPKyxWCofWmZLQYXgEpCGW2JZnXyjBNFIMkx/OvQRvhMm0Up4MX8CSqYH0A283n9z5bWS EdcJrkWAfJXftz7GkGtr0KCfYg3c5/8= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=jApp4+VN; spf=pass (imf19.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681317788; a=rsa-sha256; cv=none; b=0GFdRdy8giXwormKyS8U9UIpaw6FCcdlxcQ2y/j7TDDHCiLGC9yilnBcdH7iAQl3t9czwa 0NmdEgB00Fh6/mymBZ9SXjW5ZPnNKLyvBf/FVvB2ONxqpPTtgIQ5cBmi1kBZnvD9iqG6Oc 1tbV2BzQhgEKS5ZDmRqTEcC9fR0OoiM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317786; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=j2X1citdDCADI79RLi2EG2irLSOXCvsNG1ixWpJWId4=; b=jApp4+VNGmttBsApY3dwbKuIvF0u9kCxIGCUqVYgExY6gdnlvcPgczc/yjywT4+kNf6gyA ZLaPOAl7iMqsQeihUqdamVUzNfcukThfzWZCSY2kJCrwJiY8Nn3Wn7Ky2a1EBocw3MCqN6 73ZYTwQHquNdukIkVjk7FG8JaUNrPX4= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-261--dYaohRqM9-WwbgOryCQMw-1; Wed, 12 Apr 2023 12:43:04 -0400 X-MC-Unique: -dYaohRqM9-WwbgOryCQMw-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-74a90355636so62117985a.0 for ; Wed, 12 Apr 2023 09:43:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317780; x=1683909780; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=j2X1citdDCADI79RLi2EG2irLSOXCvsNG1ixWpJWId4=; b=MFSvyECbNxJ5tqRgtmPc76fJ/BUwTVzcFdgUa/6o/Kx9gpqi5e6S8zO8hbOGE01H4l cEh62+F4oux/6YA6FuaTXMRaXqpD+dfbC3UjA21LD2VHJMKjSwQq2mV+ISkV6L/JU3W2 1m+Bduf92SVxkBErvCzUzVmqqm0YBZvG53AMjYPZpHl08vzBK/k5TWskSLOopt4OhjHG SED9YX/YM4S2bIJZfhopxuZNML+SmigKrNBDkgVd4x3ec8MT34JSZkhSWqhqE6F3wHx1 wOmSn50t/kR/ylk9gobeYbRbqZ2mPGR6wZg5JCxfL0jhCfpna95r2ApxO3SYddR2YzLG wbGg== X-Gm-Message-State: AAQBX9fwDJ96AqaXbBDdQF0DCO/Uj14hTnS0eEtI76sqrprva4t2EREq h8f4+TgN/eW2kCK8HWX4IdWhXhN/IxNA2dgt/6HS+Dv/SfFguYVlH3OEWI5XrsJHmPkKSRw+KaU dt6F0G7pA/Ss= X-Received: by 2002:a05:622a:189a:b0:3d1:16f4:ae58 with SMTP id v26-20020a05622a189a00b003d116f4ae58mr31197650qtc.2.1681317780504; Wed, 12 Apr 2023 09:43:00 -0700 (PDT) X-Google-Smtp-Source: AKy350aPP59fS6v/hiPCzvysroXh8Pq2l2mHvfmOO33uNBWw/uqCl3sAmpEBcvmZzo74rNrgkQNwyQ== X-Received: by 2002:a05:622a:189a:b0:3d1:16f4:ae58 with SMTP id v26-20020a05622a189a00b003d116f4ae58mr31197613qtc.2.1681317780186; Wed, 12 Apr 2023 09:43:00 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id p9-20020a05620a22e900b007486d9fa1d7sm4786784qki.95.2023.04.12.09.42.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:42:59 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Andrea Arcangeli , Mike Kravetz , Nadav Amit , David Hildenbrand , Mike Rapoport , Axel Rasmussen , Leonardo Bras Soares Passos , peterx@redhat.com Subject: [PATCH v2 16/31] selftests/mm: UFFDIO_API test Date: Wed, 12 Apr 2023 12:42:57 -0400 Message-Id: <20230412164257.328375-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 28CE91A0011 X-Stat-Signature: 3djibhsmp8eau8nynrjccuir7hpwj75w X-Rspam-User: X-HE-Tag: 1681317787-996606 X-HE-Meta: U2FsdGVkX18v01mJAccdNH0gXLO60/Wsnv2cQy4Q1Mea7j6ZEl6BMr8g+F/J3FtZo/lWkTOXA2GliJowVAT2icABOSlBG7RMQh6k+EqqwMhlan6GrFrlUo0eE2dmKqDaENCtfTQ0pfzDHkKcWeQbB5Hv8usWi2yBMy37ZY+DE1Acl6LeoCt/DTDyr6bNeQYfxOad/hBZ2cHJU1at27tUCXGCll/SYTgRXrq3yBoMzEUvDm8GZ4uFO/zi/ot0FxwOIJla/a1lXFDBBgBV/u5B6Wlxe16E3R7arwnpn1NGnHaTzfrHP8RhGRhkkV7d0uN6voOQAup/rEnIO/Pn7yKgoghe2UQ3AH6YC4bkHzBr9qP8PRR7IIiBsjmbDKvPrq1cWlc6+1JBRavXAjzOvAxTKK3ir4s+xHaztiquB73UrZgRzxqICNX//HRSxJU6WbrF745AuO4A3aUKL/Pbs8NqidRZHMu3eY5GyhdGvi7ghJmsRN4TTO4fSOddFZptJ1GL3guDmGoydDzpYGp7JwNSqgrbcgPMX4dDIDRR5aG4YL5EzKi7vMWFvytPtG9Fx1QBIULXIRW/XhtVy/XVJ8lSKIFRjuY6Qje2rFpMuhvHq3bRdbAVdFz/njnN3zcRBttaL3k+dgCvjvlQuYqgvKXVfsiQZUTSXbHSJg1g1BHaHJyfMLv2z4Q0q5qqxGSUfRDgFrVQwabKN17ZbNp7m++yLgmYcWqLH1NBjwTyrl4hyWYPBZMANssZyFyyr9f+gfvVYW9fEPFEQjFIDsN2lx9FrOaRdS11wj9D4rM2BDp3tcrWuY4iXTAt+XFr33W0frwFsyFpBd3g/SmpDVjQf7kz0PUuTed/VEI80VcUmNRVjrWqhVcnogzyKM5W1XBwxEmCfA/PgPbb3OSzjy4QXAgUd+4sEYNpG7m2B2dePlB4gU4oPUsIHJUlGr210ez6QeToeotXY6dhPeVQjiI49S6 s9co1XyW rxl5SVsy1VZe16avViCmuEJUSiVrnnM09gmvKKGaThHfUZ0maYwYhiHC5ICmHH8NBlfmNQUout9hv9pZO/namj2OKyvv/y4HH+IsGkJ2q0ThEmDupYU//n45Bu2KB9WLLTcD56K3HC3vr8fhqYlvps/1c8gqkWlkKbH8oAQBFXFgqaNH9SLQBdGfCuZuLG5xqoanBX6Fb2Td8512D+ayYpVZAo56B3yTu4GP/Mjb8o7StMlMbfTTIq5OlgZ5UAQ2RqLZ/9nsgTvdkOJadBC0ED5AhFbbZirGgq3RfCUpIcIxApF3jUWMzFigP0a0na8/UcI3CMznTrnUZh+eFSt10DD1zACwtlZvV69C9hUfzCN4NhochHV21ZcHeyA8U7Q7vHn9S78lGDSQIjpxzNWL8OIHeOJD1fnbNJT37+PPNxgVszqpouoLA+Zf5GkhkdjnYTBZIxtT56IlzYAEUm5CtTVQxtQv1Jou7jqzVHf1MlLNauR9tO2mH6PRFWw2aoU5PsiBHSqfZ7QZ26oI= 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: Add one simple test for UFFDIO_API. With that, I also added a bunch of small but handy helpers along the way. Signed-off-by: Peter Xu Reviewed-by: Mike Rapoport (IBM) --- tools/testing/selftests/mm/uffd-unit-tests.c | 109 ++++++++++++++++++- 1 file changed, 108 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/selftests/mm/uffd-unit-tests.c index 6857388783be..bb492c258486 100644 --- a/tools/testing/selftests/mm/uffd-unit-tests.c +++ b/tools/testing/selftests/mm/uffd-unit-tests.c @@ -9,9 +9,116 @@ #ifdef __NR_userfaultfd +static void uffd_test_report(void) +{ + printf("Userfaults unit tests: pass=%u, skip=%u, fail=%u (total=%u)\n", + ksft_get_pass_cnt(), + ksft_get_xskip_cnt(), + ksft_get_fail_cnt(), + ksft_test_num()); +} + +static void uffd_test_pass(void) +{ + printf("done\n"); + ksft_inc_pass_cnt(); +} + +#define uffd_test_start(...) do { \ + printf("Testing "); \ + printf(__VA_ARGS__); \ + printf("... "); \ + fflush(stdout); \ + } while (0) + +#define uffd_test_fail(...) do { \ + printf("failed [reason: "); \ + printf(__VA_ARGS__); \ + printf("]\n"); \ + ksft_inc_fail_cnt(); \ + } while (0) + +#define uffd_test_skip(...) do { \ + printf("skipped [reason: "); \ + printf(__VA_ARGS__); \ + printf("]\n"); \ + ksft_inc_xskip_cnt(); \ + } while (0) + +/* + * Returns 1 if specific userfaultfd supported, 0 otherwise. Note, we'll + * return 1 even if some test failed as long as uffd supported, because in + * that case we still want to proceed with the rest uffd unit tests. + */ +static int test_uffd_api(bool use_dev) +{ + struct uffdio_api uffdio_api; + int uffd; + + uffd_test_start("UFFDIO_API (with %s)", + use_dev ? "/dev/userfaultfd" : "syscall"); + + if (use_dev) + uffd = uffd_open_dev(UFFD_FLAGS); + else + uffd = uffd_open_sys(UFFD_FLAGS); + if (uffd < 0) { + uffd_test_skip("cannot open userfaultfd handle"); + return 0; + } + + /* Test wrong UFFD_API */ + uffdio_api.api = 0xab; + uffdio_api.features = 0; + if (ioctl(uffd, UFFDIO_API, &uffdio_api) == 0) { + uffd_test_fail("UFFDIO_API should fail with wrong api but didn't"); + goto out; + } + + /* Test wrong feature bit */ + uffdio_api.api = UFFD_API; + uffdio_api.features = BIT_ULL(63); + if (ioctl(uffd, UFFDIO_API, &uffdio_api) == 0) { + uffd_test_fail("UFFDIO_API should fail with wrong feature but didn't"); + goto out; + } + + /* Test normal UFFDIO_API */ + uffdio_api.api = UFFD_API; + uffdio_api.features = 0; + if (ioctl(uffd, UFFDIO_API, &uffdio_api)) { + uffd_test_fail("UFFDIO_API should succeed but failed"); + goto out; + } + + /* Test double requests of UFFDIO_API with a random feature set */ + uffdio_api.features = BIT_ULL(0); + if (ioctl(uffd, UFFDIO_API, &uffdio_api) == 0) { + uffd_test_fail("UFFDIO_API should reject initialized uffd"); + goto out; + } + + uffd_test_pass(); +out: + close(uffd); + /* We have a valid uffd handle */ + return 1; +} + int main(int argc, char *argv[]) { - return KSFT_PASS; + int has_uffd; + + has_uffd = test_uffd_api(false); + has_uffd |= test_uffd_api(true); + + if (!has_uffd) { + printf("Userfaultfd not supported or unprivileged, skip all tests\n"); + exit(KSFT_SKIP); + } + uffd_test_report(); + + return ksft_get_fail_cnt() ? KSFT_FAIL : KSFT_PASS; } #else /* __NR_userfaultfd */ From patchwork Wed Apr 12 16:43:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209353 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 767CAC7619A for ; Wed, 12 Apr 2023 16:43:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 12CA0900005; Wed, 12 Apr 2023 12:43:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0DD67900003; Wed, 12 Apr 2023 12:43:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EE712900005; Wed, 12 Apr 2023 12:43:38 -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 E0370900003 for ; Wed, 12 Apr 2023 12:43:38 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 811B21C3677 for ; Wed, 12 Apr 2023 16:43:38 +0000 (UTC) X-FDA: 80673310116.02.CFBDABC Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf04.hostedemail.com (Postfix) with ESMTP id 65AD74000E for ; Wed, 12 Apr 2023 16:43:36 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ss9IfbrG; spf=pass (imf04.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@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=1681317816; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=mjojpcmOEAy9sHKJxFBhh1D6ilVghlmR8goVSOpVaAo=; b=I7/kWRYP5UQO05kkDpowFIMnoZxNPxHFsnca9L6RTtMKjGp3TlkaLnBbMgEJygi97CVEvB bI8dR4VMDmIg2F8x9Ai3OV+PidhhJMKxoOsqVo5na5YwP2F61LypiGpUtiPfaWxdJEmwqb 6obUp5x1XBKUoDlRZx/0Wd5/IxkbuQo= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ss9IfbrG; spf=pass (imf04.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681317816; a=rsa-sha256; cv=none; b=u7QL2w9Plfvc5ly+bZ4PMzwA/Ajfh/HO6Dw/JB0l9NlCkNdIMRGHSZr1ryNtIiEPQs4UfK qD9x1Wa0pLn3aL+Rxzbr45fnvDQJv6U3xuJABNzSDrWuoQw4h1iLG5cChCCJG+X6lSB7C0 7WpsgSAUhzVWuko7yuhimO54jAmqplY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317815; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mjojpcmOEAy9sHKJxFBhh1D6ilVghlmR8goVSOpVaAo=; b=Ss9IfbrGYFTqiR1+aWetUFv6pg22B8yNmEIFF+foz3OwAhdrUAMuhLyG2kV+bDQR7y/rS7 ORKgl8Tki2wGg+dBNFWGGCaoq3aNGXP+5d88yMcLqsmMkbIiWLQQ16GWyAxmKJJThST1qk UnuVaxvfmKhfPP0yL2CQbofQ+ZPRDFg= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-213-SHqHvRbrP7KoshbGaJJr0w-1; Wed, 12 Apr 2023 12:43:34 -0400 X-MC-Unique: SHqHvRbrP7KoshbGaJJr0w-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-74a90355636so62126185a.0 for ; Wed, 12 Apr 2023 09:43:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317814; x=1683909814; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mjojpcmOEAy9sHKJxFBhh1D6ilVghlmR8goVSOpVaAo=; b=eU+QhTFWEwLpn2LuETLHsEOHPAOxNtUT6bBhhRVBmNZI5kKuNEIse7/f1ow/xoIGLv Cz0SNgAAdmxMkY7r+MeIpXEo1HZZ6pAKmsx6LO76WRJv9gAkpqJbzY/gjX3QTOfOakpn CXDDrgoos5bQ7XYwecyRwwY1acSGI9fHEb5dw5t48gV1+2IQnj+CjXdJXKCvFGKbupVX My61cTMjmoamn+zxbjAfXCshBY57ynBc4++HKqgY7QWbP3q+p0+JYmRpLRSqO8QPIWOP n5fwHEmGr4b6GCx+bCFR00Un/Sy3kTgBCFidKQ3EbBVJHuhz2reLsO0LomWw/BDyxomk sX4Q== X-Gm-Message-State: AAQBX9dAlYxkrLu/Cecbmno0VLtZNz5iJ7ll3K6z6ve65zsEXU1yhhRc G4d7p7c9k7IiKSWhIu6F1vBbXr2Yq1tkf7m2tKyuph5wTSkdnLFOsNxJOzVjdvzm57jw1x2N5nh MdelznkSM6Re16K9b3Vk= X-Received: by 2002:a05:6214:4009:b0:5ac:325c:a28f with SMTP id kd9-20020a056214400900b005ac325ca28fmr28040721qvb.0.1681317813755; Wed, 12 Apr 2023 09:43:33 -0700 (PDT) X-Google-Smtp-Source: AKy350aCRUYX9XSVZcq8LYLtGSnSwVz7FM081yXsn58IDzHk0UjUVjNJXSLp/S7y3S1wvu+8J1/rtQ== X-Received: by 2002:a05:6214:4009:b0:5ac:325c:a28f with SMTP id kd9-20020a056214400900b005ac325ca28fmr28040704qvb.0.1681317813518; Wed, 12 Apr 2023 09:43:33 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id k16-20020a05621414f000b005eea9d3137fsm1749862qvw.134.2023.04.12.09.43.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:43:32 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: David Hildenbrand , Andrew Morton , Leonardo Bras Soares Passos , peterx@redhat.com, Andrea Arcangeli , Nadav Amit , Mike Rapoport , Axel Rasmussen , Mike Kravetz , Mike Rapoport Subject: [PATCH v2 17/31] selftests/mm: Drop global mem_fd in uffd tests Date: Wed, 12 Apr 2023 12:43:31 -0400 Message-Id: <20230412164331.328584-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Stat-Signature: 6jy6npaomjwgccrzw94f9ihdqzywp6dc X-Rspam-User: X-Rspamd-Queue-Id: 65AD74000E X-Rspamd-Server: rspam06 X-HE-Tag: 1681317816-510826 X-HE-Meta: U2FsdGVkX1/5EhrarZVGc3KzqDxJ07v9yq5u+c+FJblcZfh5CJMI/iKqflZTqnySL4hkr3vZ/dp1/WwK1/v0VCYn3IN2+AHMRimW8xhNYCBncIpYSYVlgDb6HcDsThrhjyJdXzQHrLrpnGWzQaDEEXWUd39R6hCukd/jJ1egoNeeTCZ1jDCWBrbBvoTALuRhRcVphZFU1O0KK+UC7hlreNJPZdb5PebUbfOWX4sF0PMx+feNzxXPJUGObwbnrxBeup8XSR3IOqPGYkXUalmPuYRIw2c9H089ladxUNWj3LPGxa3TXTMCh82c0WKOWIF+nFgULkpG8tKMycUBOXUci//7oVTXB0TosP0JzXjpdxGGPaIZuY0jdROdH15OgcFJQE8FiCZi4M5UkVZoBi6iwnYKwjZT0mUmjyDUj+pt9E5Pmqq7f1QpyJRwuEyKoBciTDwmyrJgpdRnRPht9dAP1QDMgqiQK9UajIxs3jSStjt/Dhh2ZUk14/OByD1xWzsnWJIYHjehUFBNTLvoWHD2v0WEFWu1gmH2BuW35wklSIdzbUmY52AoCd1TGHwW5JjhCJ7qo1k0ujHPTvGOpsjgs6m0MPhV//f3gK7ZB/NAMTBnfeP00WCHqpsRaH/YAqrJ58M4bmePvWgf95g+CncMdGAc/tKYaLFDDg2cyNEWFqqumujB3caKyye0QmuRafJb8ml+7G0sGzRr+KHHvqFHXkkh5BH4RqrP6DN7EkWoFBIJyppavc0gJVRDi6kLdQt3ETaPMzKE4Ke73vRmd6bnXIhsDe5BfxEYEPss4EpRS6u4yrOC/2AhTtgTx1D6Ay9yow7AL3tBtwMxBS3uee4+zPnIsd7CJ8VUphJkFrZaiaKM4TsZqZCI+oSO9VdNRbXbaUSHS9CgBuoI/Z+mr9YcDhWDpSlpAG8tbYzadbLQLXDhPkGDYwffR1WIJu7ZTYYUX5DKJIpTUh8sp/mKcLj gDUyjnSf Nmi/N+r4ADdZcGGK4EiJRehG9DHMJnLRfdT11UkB1gVVqEHCDJ2ka9p81osVYEO4Q8EjNsELmQEUqKpggqgj1X1plrueG1TKwY7a83UU4x2jkU1QUzJmKaqNC1BHkaT9AgKkRTXQqEif0ISMrT3+9EqNiq4n3fFf2oDFusTHLkbJHyROv29uTBlp6qElKMMdl+FWTMe2a+gw1/DWk2vwl2ePMDiKdGdl8NPRUw/LZYK46smUBFGdICVPUYdOx6lI/zbARnbWihVYOIJPjaE2T/BKFrB0+G7gyKpoOnE+EjxbQ60pXbP2wv9iNwmFtCp4ktzBAyN7l6S60NK/x5nsOjKvsrgnIIgzizGniS+iTeAFAXuiupZ0zPBa4Zs4OW4jyc6yrI4LiUDfJPQDjRqENM8Q1WpY+hN2tGCOV/hROLeOw9hC1OCDkMW1+nLbyh1sbMOvhzrhYBDLqzH7jd0VeRJOGBwPOY7UqFey4+9qXDCA7slrhD+UhGQ+gEmcvn6+5gvmJJvvkT6dhMfpmv+c+o99QcIzsXU2+/gfm9DxKZysZV+xbL2W8GbmFWa1Kx2ukV2m1WQCpnbdpItQ= 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: Drop it by creating the memfd dynamically in the tests. Reviewed-by: Mike Rapoport (IBM) Signed-off-by: Peter Xu --- tools/testing/selftests/mm/uffd-common.c | 28 +++++++++++++++++++++++- tools/testing/selftests/mm/uffd-common.h | 2 +- tools/testing/selftests/mm/uffd-stress.c | 15 ------------- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-common.c b/tools/testing/selftests/mm/uffd-common.c index 09ea24c5f02c..b1617f5d4517 100644 --- a/tools/testing/selftests/mm/uffd-common.c +++ b/tools/testing/selftests/mm/uffd-common.c @@ -12,12 +12,32 @@ volatile bool test_uffdio_copy_eexist = true; unsigned long nr_cpus, nr_pages, nr_pages_per_cpu, page_size, hpage_size; char *area_src, *area_src_alias, *area_dst, *area_dst_alias, *area_remap; -int mem_fd, uffd = -1, uffd_flags, finished, *pipefd, test_type; +int uffd = -1, uffd_flags, finished, *pipefd, test_type; bool map_shared, test_collapse, test_dev_userfaultfd; bool test_uffdio_wp = true, test_uffdio_minor = false; unsigned long long *count_verify; uffd_test_ops_t *uffd_test_ops; +static int uffd_mem_fd_create(off_t mem_size, bool hugetlb) +{ + unsigned int memfd_flags = 0; + int mem_fd; + + if (hugetlb) + memfd_flags = MFD_HUGETLB; + mem_fd = memfd_create("uffd-test", memfd_flags); + if (mem_fd < 0) + err("memfd_create"); + if (ftruncate(mem_fd, mem_size)) + err("ftruncate"); + if (fallocate(mem_fd, + FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 0, + mem_size)) + err("fallocate"); + + return mem_fd; +} + static void anon_release_pages(char *rel_area) { if (madvise(rel_area, nr_pages * page_size, MADV_DONTNEED)) @@ -51,6 +71,7 @@ static void hugetlb_allocate_area(void **alloc_area, bool is_src) off_t offset = is_src ? 0 : size; void *area_alias = NULL; char **alloc_area_alias; + int mem_fd = uffd_mem_fd_create(size * 2, true); *alloc_area = mmap(NULL, size, PROT_READ | PROT_WRITE, (map_shared ? MAP_SHARED : MAP_PRIVATE) | @@ -73,6 +94,8 @@ static void hugetlb_allocate_area(void **alloc_area, bool is_src) } if (area_alias) *alloc_area_alias = area_alias; + + close(mem_fd); } static void hugetlb_alias_mapping(__u64 *start, size_t len, unsigned long offset) @@ -95,6 +118,7 @@ static void shmem_allocate_area(void **alloc_area, bool is_src) size_t bytes = nr_pages * page_size; unsigned long offset = is_src ? 0 : bytes; char *p = NULL, *p_alias = NULL; + int mem_fd = uffd_mem_fd_create(bytes * 2, false); if (test_collapse) { p = BASE_PMD_ADDR; @@ -124,6 +148,8 @@ static void shmem_allocate_area(void **alloc_area, bool is_src) area_src_alias = area_alias; else area_dst_alias = area_alias; + + close(mem_fd); } static void shmem_alias_mapping(__u64 *start, size_t len, unsigned long offset) diff --git a/tools/testing/selftests/mm/uffd-common.h b/tools/testing/selftests/mm/uffd-common.h index 11f770391bd9..0dfab7057295 100644 --- a/tools/testing/selftests/mm/uffd-common.h +++ b/tools/testing/selftests/mm/uffd-common.h @@ -87,7 +87,7 @@ typedef struct uffd_test_ops uffd_test_ops_t; extern unsigned long nr_cpus, nr_pages, nr_pages_per_cpu, page_size, hpage_size; extern char *area_src, *area_src_alias, *area_dst, *area_dst_alias, *area_remap; -extern int mem_fd, uffd, uffd_flags, finished, *pipefd, test_type; +extern int uffd, uffd_flags, finished, *pipefd, test_type; extern bool map_shared, test_collapse, test_dev_userfaultfd; extern bool test_uffdio_wp, test_uffdio_minor; extern unsigned long long *count_verify; diff --git a/tools/testing/selftests/mm/uffd-stress.c b/tools/testing/selftests/mm/uffd-stress.c index e6d39a755082..4eca1a0276c2 100644 --- a/tools/testing/selftests/mm/uffd-stress.c +++ b/tools/testing/selftests/mm/uffd-stress.c @@ -1090,21 +1090,6 @@ int main(int argc, char **argv) } nr_pages = nr_pages_per_cpu * nr_cpus; - if (test_type == TEST_SHMEM || test_type == TEST_HUGETLB) { - unsigned int memfd_flags = 0; - - if (test_type == TEST_HUGETLB) - memfd_flags = MFD_HUGETLB; - mem_fd = memfd_create(argv[0], memfd_flags); - if (mem_fd < 0) - err("memfd_create"); - if (ftruncate(mem_fd, nr_pages * page_size * 2)) - err("ftruncate"); - if (fallocate(mem_fd, - FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 0, - nr_pages * page_size * 2)) - err("fallocate"); - } printf("nr_pages: %lu, nr_pages_per_cpu: %lu\n", nr_pages, nr_pages_per_cpu); return userfaultfd_stress(); From patchwork Wed Apr 12 16:43:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209354 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 E76DFC77B6E for ; Wed, 12 Apr 2023 16:43:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 83100280002; Wed, 12 Apr 2023 12:43:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7E164280001; Wed, 12 Apr 2023 12:43:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 68269280002; Wed, 12 Apr 2023 12:43:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 561D7280001 for ; Wed, 12 Apr 2023 12:43:42 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 1078280181 for ; Wed, 12 Apr 2023 16:43:42 +0000 (UTC) X-FDA: 80673310284.27.DD2793A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf09.hostedemail.com (Postfix) with ESMTP id B9644140020 for ; Wed, 12 Apr 2023 16:43:39 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Hq1PXmbj; spf=pass (imf09.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@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=1681317819; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=0pO7URj8vYM+yjGhq+aT/ST6K4M19Q/F9Gc+2VYksqI=; b=dyS8TBHdHpgYB53sNtlGb9pIm5aRdWelYGuG6CUZZG76ao35Ps3CrCCwWOeyTXOITOKyd9 wKyeNTwp+rJQwcIeWGPfNMHHBxjUATZ2m0pzn83SUBkf0aPP7yxedAmbawLe2ii5KsIvlJ X1//eI9ICnNkohwn0oqjJz1FD7H9Dj0= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Hq1PXmbj; spf=pass (imf09.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681317819; a=rsa-sha256; cv=none; b=OQ2s9O0vgEFylDtJCCUG3APGEaWMGv0QO4/TN9B/+/qWFDtfPd1XieLuqoQk+WzqU/nlm8 WQc3HnD8/UUdoQbippsTkh91csqqZEKvW5vuiMXqCMquoXXyZFS7hwuS/o7nQCR6n1iAzw AOVdmtQOxVrDwLGwMH4o5H0Z9h6/YOU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317818; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0pO7URj8vYM+yjGhq+aT/ST6K4M19Q/F9Gc+2VYksqI=; b=Hq1PXmbjMD/9Zk+IpshVTTrXAN2+D5VDqbHviRWjOTpEu/YmHws6rqUXYWHEa2MilO4r8u 8tmd0h449X6Q/mmgL4uwDeyRLVl1SvAUiNnnskJaPZxc16LyLp/7BwHI/DCpguRCbcCj7M arTynnrCUwhED90xTea6w399uQ30K+U= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-104-4QhtNAzRPXyxjA8mqQf9MA-1; Wed, 12 Apr 2023 12:43:37 -0400 X-MC-Unique: 4QhtNAzRPXyxjA8mqQf9MA-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-74a9035256eso54269285a.0 for ; Wed, 12 Apr 2023 09:43:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317817; x=1683909817; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0pO7URj8vYM+yjGhq+aT/ST6K4M19Q/F9Gc+2VYksqI=; b=Rhb9lV9OYqExAgJedS7Ycgkx7d2/OhEp8O+U+noBHiG0AVcJKSI4lN8UZdyiNchwTm 3Whef+rQbsJ0FAASQEEybf8pe1zA+NR1wP6d73e024U5MVqV0kbuNpYwYPDMeZl/Dvjw 07jzUB4FrklI+C6pnLMQeS/mbtC7zpNc8K4AzdcHA+e/av5bVdM8NKxEJdpfsDM9R1S5 rornGot5WzumdAl/Y8yfq6affH1C33rdlELXPpJt1VqrjcYo909N5RewqnZFefvlk4Bt SZ19U0L0oFI2M1iE5XFktZMr43uquJOWAt4LYx61Sr6n53kjRyCmqMqmFbTqX03LtPB7 FnHA== X-Gm-Message-State: AAQBX9eFnMFN+ZPiyXIWc/KMHOHgyveg7TPbACCE6DoQfb4ITG+XWlL3 1fs76YgyWBQhNe2jU3LhvT3m57TZjq/wsbX8r5QAnbLf8D7+2nED/wsyAKmQmg4sAcJoP3eoDCe XQQAy4WB2pLY= X-Received: by 2002:a05:6214:4105:b0:5de:5da:b873 with SMTP id kc5-20020a056214410500b005de05dab873mr4443932qvb.3.1681317817218; Wed, 12 Apr 2023 09:43:37 -0700 (PDT) X-Google-Smtp-Source: AKy350Z3R6M8KdFbyjyZ96tq0efKVR1IxKkDB07C26LLb6jjk8ZwbABfKxJGq8KdfFl/AQ+DyKIdCA== X-Received: by 2002:a05:6214:4105:b0:5de:5da:b873 with SMTP id kc5-20020a056214410500b005de05dab873mr4443916qvb.3.1681317816911; Wed, 12 Apr 2023 09:43:36 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id mf18-20020a0562145d9200b005dd8b934579sm3677087qvb.17.2023.04.12.09.43.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:43:35 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: David Hildenbrand , Andrew Morton , Leonardo Bras Soares Passos , peterx@redhat.com, Andrea Arcangeli , Nadav Amit , Mike Rapoport , Axel Rasmussen , Mike Kravetz , Mike Rapoport Subject: [PATCH v2 18/31] selftests/mm: Drop global hpage_size in uffd tests Date: Wed, 12 Apr 2023 12:43:33 -0400 Message-Id: <20230412164333.328596-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: B9644140020 X-Stat-Signature: suupdhyxtx1diqdgen7b6xfrwjhobhha X-HE-Tag: 1681317819-527012 X-HE-Meta: U2FsdGVkX18Mn0/puOERw5afjuHVzkUhsIucW3s79nmS2JZSjoqMBepsBCsF012IErHEqUCtTCPjO94cwvQ15Filx8V0zjTrMu/y2BXZBgNvFNfGKFOy8r3Kr29XLlNewupLfB6IpMgRqPZXYB/hnXcHnNnfc8YkgHtle4sfLxOYnJlKUC7zwhZtJT1+p+x1h/iM7eGVTlr6O9UfX+zld4Yry9l3kqf8hIeKzFCaprgjyhDghTsAZSpvlorMGnzKV9bFpOhW+Z/0XmIgfUZlNK3roc6/Ym926h97eEEDoHni/MXNFP9QpIdylI6tCEelzxR28CKwQhuKrCwtIwpg1sMWiE996wO3seYlG7E17wiim5ExDp9N3eUIVsLODYq/8FL1uQNvCR0Il47fC+r/3ioagw35LaPf9z1XbvudLHx1ABP+GrFuO8ACR6A301gip8PQG7oIxHbBDqQcN1AKlkqWNV1nnXfyKIOuK8nva5zbhtkA8qYg5ASt71sVJmMRXEvy2VAcZVwQkYnCEbNdLu0LOrOgO8KqPxiXx1moac+6XL41MA3zkAOgO4Dbwf8L2g+DkTCOfQYZua6QmyXdRgo7rTQAJRvZD9rWrrdZghvsfa9Vs0HfuM7MWUNLn9nWoVYwDjlsPe8cP0738hI+QpPjdIFg7lu6sCU3ZYcCunV9UliawCi1i71mMovZDZAOJYq/NqYDoJNIJxmBoSGZor2t3Xj2TKdxVVtH5a+hbSeb0M8jDM14LWVJFBjiZDS6PBTBBAwf1X3jYYptRFbLx8tgZ/Mf017t1NJXW0HRL3EqJJesCufYDJ9/w8EP2b+kPnOTrI0ZmlkpaJ9KPox0fHJbgOIkjiasYyBmL0EbyAQYrLNKXFgqkZlMQ5CW/4WbmhF9J+yoJK3hC1UpRWmuARcqbpFH0+g19rXpKZm4m1ci7tDWQ+h8CGMVY8lOphF9ROww0Pra69DIt0CU426 0FGKmdiu H9g4U+2Ywl/DDBAv1QhzvjlPjVUvA8AuK1pX7APeGZSOf5V/+krtfa8N3DhyG03OxGnaOFe+kbYrxEiWMwkWj0Y0kM/WJr7iWQ8PHrIycp8nufxp4a8Z9NN6PUAaekm6+E1Kra5UZEHdJPUMB4m0EYZvWOxlfdk/Z1d9jtaVBvuzmLPF2etzOnw20pByRiIL2ZuEGca6y7n6MDTlnQ2vT0QAd2vxhGLrbr6q1Qb9HwC+x8FuM98Y4QFZJ7nCvQKhDrjv8wrosYuacB5zIPVIoRJ6NXLhwGi5UEuMpCdi15nzo2KF+7o/peCwtzmwFRAYaSiFKShy6eOFy4Nk4wjNtspBsFDqFmyyZ5ZFNM45GydFr4ECgo0l90i/Gl2QeA36nECQ9OfH+LKyx7eGG+0Zi9R3WQlEu9fHVZJwkP6+kgaxt6BxG8Kmdz4NAi0JRhmKVJMpegHGJv7rbbYkkLwP1RWfhrYVIDakfsgbSOwru6saUGH5EkbByjU+aMCz649vGh4W/bw8x7BTO7CDDveF+FcypPWAhCEudmlpTQLJXIOqGoFrYr9M3tz7FNU7GvKyKSdeYdSPR7Q+Z03Y= 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: hpage_size was wrongly used. Sometimes it means hugetlb default size, sometimes it was used as thp size. Remove the global variable and use the right one at each place. Reviewed-by: Mike Rapoport (IBM) Signed-off-by: Peter Xu --- tools/testing/selftests/mm/uffd-common.c | 7 ++++--- tools/testing/selftests/mm/uffd-common.h | 2 +- tools/testing/selftests/mm/uffd-stress.c | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-common.c b/tools/testing/selftests/mm/uffd-common.c index b1617f5d4517..f02dfcf10714 100644 --- a/tools/testing/selftests/mm/uffd-common.c +++ b/tools/testing/selftests/mm/uffd-common.c @@ -10,7 +10,7 @@ #define BASE_PMD_ADDR ((void *)(1UL << 30)) volatile bool test_uffdio_copy_eexist = true; -unsigned long nr_cpus, nr_pages, nr_pages_per_cpu, page_size, hpage_size; +unsigned long nr_cpus, nr_pages, nr_pages_per_cpu, page_size; char *area_src, *area_src_alias, *area_dst, *area_dst_alias, *area_remap; int uffd = -1, uffd_flags, finished, *pipefd, test_type; bool map_shared, test_collapse, test_dev_userfaultfd; @@ -115,7 +115,7 @@ static void shmem_release_pages(char *rel_area) static void shmem_allocate_area(void **alloc_area, bool is_src) { void *area_alias = NULL; - size_t bytes = nr_pages * page_size; + size_t bytes = nr_pages * page_size, hpage_size = read_pmd_pagesize(); unsigned long offset = is_src ? 0 : bytes; char *p = NULL, *p_alias = NULL; int mem_fd = uffd_mem_fd_create(bytes * 2, false); @@ -159,7 +159,8 @@ static void shmem_alias_mapping(__u64 *start, size_t len, unsigned long offset) static void shmem_check_pmd_mapping(void *p, int expect_nr_hpages) { - if (!check_huge_shmem(area_dst_alias, expect_nr_hpages, hpage_size)) + if (!check_huge_shmem(area_dst_alias, expect_nr_hpages, + read_pmd_pagesize())) err("Did not find expected %d number of hugepages", expect_nr_hpages); } diff --git a/tools/testing/selftests/mm/uffd-common.h b/tools/testing/selftests/mm/uffd-common.h index 0dfab7057295..47565b2f2dee 100644 --- a/tools/testing/selftests/mm/uffd-common.h +++ b/tools/testing/selftests/mm/uffd-common.h @@ -85,7 +85,7 @@ struct uffd_test_ops { }; typedef struct uffd_test_ops uffd_test_ops_t; -extern unsigned long nr_cpus, nr_pages, nr_pages_per_cpu, page_size, hpage_size; +extern unsigned long nr_cpus, nr_pages, nr_pages_per_cpu, page_size; extern char *area_src, *area_src_alias, *area_dst, *area_dst_alias, *area_remap; extern int uffd, uffd_flags, finished, *pipefd, test_type; extern bool map_shared, test_collapse, test_dev_userfaultfd; diff --git a/tools/testing/selftests/mm/uffd-stress.c b/tools/testing/selftests/mm/uffd-stress.c index 4eca1a0276c2..54fc9b4ffa3c 100644 --- a/tools/testing/selftests/mm/uffd-stress.c +++ b/tools/testing/selftests/mm/uffd-stress.c @@ -655,7 +655,7 @@ static int userfaultfd_minor_test(void) uffd_test_ops->check_pmd_mapping(area_dst, nr_pages * page_size / - hpage_size); + read_pmd_pagesize()); /* * This won't cause uffd-fault - it purely just makes sure there * was no corruption. @@ -997,7 +997,7 @@ static void parse_test_type_arg(const char *raw_type) err("Unsupported test: %s", raw_type); if (test_type == TEST_HUGETLB) - page_size = hpage_size; + page_size = default_huge_page_size(); else page_size = sysconf(_SC_PAGE_SIZE); @@ -1035,6 +1035,7 @@ static void sigalrm(int sig) int main(int argc, char **argv) { size_t bytes; + size_t hpage_size = read_pmd_pagesize(); if (argc < 4) usage(); @@ -1043,7 +1044,6 @@ int main(int argc, char **argv) err("failed to arm SIGALRM"); alarm(ALARM_INTERVAL_SECS); - hpage_size = default_huge_page_size(); parse_test_type_arg(argv[1]); bytes = atol(argv[2]) * 1024 * 1024; From patchwork Wed Apr 12 16:43:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209355 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 7E1B5C77B6E for ; Wed, 12 Apr 2023 16:43:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1C8F8280003; Wed, 12 Apr 2023 12:43:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1A0A1280001; Wed, 12 Apr 2023 12:43:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0411C280003; Wed, 12 Apr 2023 12:43:46 -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 EA19D280001 for ; Wed, 12 Apr 2023 12:43:46 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id A2F89A01A4 for ; Wed, 12 Apr 2023 16:43:46 +0000 (UTC) X-FDA: 80673310452.03.86FDDEA Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf30.hostedemail.com (Postfix) with ESMTP id 593808001A for ; Wed, 12 Apr 2023 16:43:44 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YkZpH81m; spf=pass (imf30.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@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=1681317824; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=y3C20L7q6E0jI4D7x0NRqCKUvj6UY8rhbxmq4jIDbcM=; b=d8/0yfmloYiuhTab0ic/1QohIRiiLlpV9tUZJgpt1jPHkQmggILY+muWZmF7CBBidwPOQB 0zbQF21n2264vRUigl/mc6Npa8OXvZtw3rzSq4BNU5567mO+86I0UQbq3xXbY1k0Y3mNF4 K960C6KYEH/FDwMtjG5h4eqvrJWS+gY= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YkZpH81m; spf=pass (imf30.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681317824; a=rsa-sha256; cv=none; b=E4P3vGGjhzsHO2t3nnuBCIfsHRvlOMTyCvr+AQggDFvbWZj4UF1MXCfFXuZmVMs0hf9WTS Jn5Sk/jP9PhqgnxLjz7Ty7PYfIx3De+CLdMRMtbiOUDbpZ6luUe8nryDAmD6X9LgeV2YQt 1UO5rcKhtuV8DIX31VHxWENYMtARWac= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317823; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y3C20L7q6E0jI4D7x0NRqCKUvj6UY8rhbxmq4jIDbcM=; b=YkZpH81mCnnk94QQdaCE1Kd6EE1r2BsT7cg1OGfM2/ah3D49OkZiRI5MlmuE6fGJgju1qS vCTvzIBcnkbmgqvzRohx9jZAjBZaSdu/x6No1cENbWVCc88h2ac3pC9DzM3qk18bJTUrkl kWRILQF1x2IeAJxCoD13m1PNN0sygsI= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-448-PjolhF0OPu2ErAgY8vaaZg-1; Wed, 12 Apr 2023 12:43:42 -0400 X-MC-Unique: PjolhF0OPu2ErAgY8vaaZg-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-3e947d81d7dso267931cf.1 for ; Wed, 12 Apr 2023 09:43:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317822; x=1683909822; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y3C20L7q6E0jI4D7x0NRqCKUvj6UY8rhbxmq4jIDbcM=; b=bfJjbF14Ews/9qnMioVzX3zquelrPwlV5vBsiZM7hmxH8G3wNRjLe2c6RjWoPVh6tg T0btR27/5cZ4OqNqjI/KBs+vC4NnCMPLHg0Kpt4yENMUPLdU7e0zxOaUxAmac5mB9VOV SQwcPU9/PYzvv/t0MFRr9Kv1cV/bTOdd3KF7DQsJggCU/kz6sTAblcR8Hs4cn5P5k3mZ XdwSFHM6D2LQHN4sisen9MWk7PgsakFGCANCkStzH6x6Q0ErH2EZlutk3jgkhnJEdEb/ 48nRXX+TeBZcnZGfKC7h7Sr/yjgB10qcj5oQXsbGhuJlUR5xV8Toc9Nmitp9eiSJrm2Q SGOA== X-Gm-Message-State: AAQBX9erq0VxBcLhoRkVNOcVCkSIpLH903lX4RRtLR6aNdzJ/A9ZchVf hyTGAFr622e6/7yfJWczU94K691Z9JBNBN+Sv9lHVekGpmSVaHzKsK2D0lEklK5d551KKzqbfDp qPSwFOC8LAhI= X-Received: by 2002:a05:622a:14cf:b0:3bf:cf77:a861 with SMTP id u15-20020a05622a14cf00b003bfcf77a861mr4120221qtx.4.1681317821788; Wed, 12 Apr 2023 09:43:41 -0700 (PDT) X-Google-Smtp-Source: AKy350bS0H0y2MXWTHEdCzjaxChBZetPVl11/ilu2oRzLKkLGeeR4cj9iwfLJ5Lhe5q6n8VH3atofw== X-Received: by 2002:a05:622a:14cf:b0:3bf:cf77:a861 with SMTP id u15-20020a05622a14cf00b003bfcf77a861mr4120195qtx.4.1681317821429; Wed, 12 Apr 2023 09:43:41 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id b15-20020ac8678f000000b003e38e2815a5sm4328106qtp.22.2023.04.12.09.43.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:43:40 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: David Hildenbrand , Andrew Morton , Leonardo Bras Soares Passos , peterx@redhat.com, Andrea Arcangeli , Nadav Amit , Mike Rapoport , Axel Rasmussen , Mike Kravetz , Mike Rapoport Subject: [PATCH v2 19/31] selftests/mm: Rename uffd_stats to uffd_args Date: Wed, 12 Apr 2023 12:43:37 -0400 Message-Id: <20230412164337.328607-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: 593808001A X-Stat-Signature: tieyfhupmh5ofkguushqnxu1uewdrtqu X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1681317824-219450 X-HE-Meta: U2FsdGVkX19sJ99xcTCfI84rHNzKe42qbm6ZT8hmX1t9Xc+eePriikropwCK+hJ18ajrap2B13jjv3QRhUAsmjRvRRE7s4gq6J917LZGq5+0W43QcB06DrfREpFpAr5MLiq26f45RjPuXI+9pQx8r+OkiDN8/YJkk0TkZU1v1FjAmi5DKg+8aaEOnUJ6dKRvTSCz6tJ+jTbDO8wk6ESC82EG71M07eDVn9PfLPWjkrn679tRtc0efyrHp9TPNk3mSG2gejtXF9Tr/ih9scmC3Th03z1KH4GZJXSlRUnMYDw/h8MZaKYZYBiCoX40HtnYGw3u3zMBfu63WfPO4M87EkkPOTlOeEKZmrNh7WAGAnn9lh21ZfJHa5ZgoMsuLqZbRr53HdweC3OUfmApcqI+P7PD3/fKc2w6p/Sl0awT+g5QxqKOuz58fFIh3JWPAentCH0RBUQW+VCX/9nFtpXTsa9nTO6cqfACma9r1g7m03KchV2TC3ZjWfeUy6P371n2OhGKxIL/lMXXDcvqt/6NlixgLYfDLJ+2eDPoo+x/wugIKiOpDkYBKHF69GGm55Wx/ZoRu2jcedwx2NCsNErFvfHjeA0Aj1FWoymuhwbIBmq5F6o4J8Jw5+JFmBV3eNJZrt5wZnI1ddmwBgh9+MB3shmy60PtR8RVbNEKIZ+6yNQw56P2CVasLRjnQc1dhSkOQSH8Y4yfKSsjed0IfZO26tIXjuPbsviduSgqMf/AJgUd1RgScqaki3B0G8V1VLCg7AHDUcfzRFoa1vxW/ON8pu6w76kViXWD6xjB+Cvt29MWOrtkn5+9DRw4e3+h/RA1jpXi7Xx1uzbFyMBO3N02PnafJzknSVeeM4pdTgw3TuWfIz0I72G0y7MJj8yJkWZOVdL3DEdfiftZLuv3Vq36y6Pneb+OJCZi31vxkt3xaSLzOe3ljaUBI2eF8srEEJN9NRihXe8svrgPogISxTe jooiwX2j ZDMkEnNo1832+s948zyPkQRqwyZIn/6iA8BpC9GQXeukXwosG3A8kZp4ZgccbeZc0y2N2fyGS5iilakrUSjm0Ai6wtO1yAiRK7nIOGx5F012GPy8WhCR7+jt0uiyAEBfbZHRNPLlFtqAc5xe+H8gvFtooSgieW9uMjaKGHMwhXDYPn+m09KgPMxuSfUSBnPr0QJqE1qyMXCyFXs+AkYV/oRVWiie3fYwSfVjQRtxOrBMOc/PD10M4bmhymACj5AOGjQyepwAMz3NA3ua0SFh3XSLL5rH7a/Ez9chzQXuF8RsKS+MBbqpBHtb/dUP8iqrU7evST8X58lF2cL1AWakRzxWb+OqgkvOvzNYGVVwwnbjUCbvVcBmwOzfv6nplkt/2qmu5gywxMQiudE556UbQsRKdKltLUM6A/zZK4AGCawvmdWAXWaOwx1fOOcvUy3ML7wF33BZCRQ7By+jzZg+J6exzL0Ng+kO232RcBhG/a66Yk5WkXFvMmDfzGmFeS//yGKNuKQO5h+xmSYZJnBUR22d9YCm78WUZom9dUY/5QRxWexwR9Y+Z1C7zuQOQS7z8/Z57esxbY50LUrs= 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: Prepare for adding more fields into the struct. Suggested-by: Mike Rapoport (IBM) Signed-off-by: Peter Xu Reviewed-by: Mike Rapoport (IBM) --- tools/testing/selftests/mm/uffd-common.c | 28 ++++++------- tools/testing/selftests/mm/uffd-common.h | 6 +-- tools/testing/selftests/mm/uffd-stress.c | 51 ++++++++++++------------ 3 files changed, 42 insertions(+), 43 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-common.c b/tools/testing/selftests/mm/uffd-common.c index f02dfcf10714..e746405aa8f3 100644 --- a/tools/testing/selftests/mm/uffd-common.c +++ b/tools/testing/selftests/mm/uffd-common.c @@ -186,34 +186,34 @@ struct uffd_test_ops hugetlb_uffd_test_ops = { .check_pmd_mapping = NULL, }; -void uffd_stats_report(struct uffd_stats *stats, int n_cpus) +void uffd_stats_report(struct uffd_args *args, int n_cpus) { int i; unsigned long long miss_total = 0, wp_total = 0, minor_total = 0; for (i = 0; i < n_cpus; i++) { - miss_total += stats[i].missing_faults; - wp_total += stats[i].wp_faults; - minor_total += stats[i].minor_faults; + miss_total += args[i].missing_faults; + wp_total += args[i].wp_faults; + minor_total += args[i].minor_faults; } printf("userfaults: "); if (miss_total) { printf("%llu missing (", miss_total); for (i = 0; i < n_cpus; i++) - printf("%lu+", stats[i].missing_faults); + printf("%lu+", args[i].missing_faults); printf("\b) "); } if (wp_total) { printf("%llu wp (", wp_total); for (i = 0; i < n_cpus; i++) - printf("%lu+", stats[i].wp_faults); + printf("%lu+", args[i].wp_faults); printf("\b) "); } if (minor_total) { printf("%llu minor (", minor_total); for (i = 0; i < n_cpus; i++) - printf("%lu+", stats[i].minor_faults); + printf("%lu+", args[i].minor_faults); printf("\b)"); } printf("\n"); @@ -397,7 +397,7 @@ int uffd_read_msg(int ufd, struct uffd_msg *msg) return 0; } -void uffd_handle_page_fault(struct uffd_msg *msg, struct uffd_stats *stats) +void uffd_handle_page_fault(struct uffd_msg *msg, struct uffd_args *args) { unsigned long offset; @@ -407,7 +407,7 @@ void uffd_handle_page_fault(struct uffd_msg *msg, struct uffd_stats *stats) if (msg->arg.pagefault.flags & UFFD_PAGEFAULT_FLAG_WP) { /* Write protect page faults */ wp_range(uffd, msg->arg.pagefault.address, page_size, false); - stats->wp_faults++; + args->wp_faults++; } else if (msg->arg.pagefault.flags & UFFD_PAGEFAULT_FLAG_MINOR) { uint8_t *area; int b; @@ -430,7 +430,7 @@ void uffd_handle_page_fault(struct uffd_msg *msg, struct uffd_stats *stats) for (b = 0; b < page_size; ++b) area[b] = ~area[b]; continue_range(uffd, msg->arg.pagefault.address, page_size); - stats->minor_faults++; + args->minor_faults++; } else { /* * Missing page faults. @@ -460,14 +460,14 @@ void uffd_handle_page_fault(struct uffd_msg *msg, struct uffd_stats *stats) offset &= ~(page_size-1); if (copy_page(uffd, offset)) - stats->missing_faults++; + args->missing_faults++; } } void *uffd_poll_thread(void *arg) { - struct uffd_stats *stats = (struct uffd_stats *)arg; - unsigned long cpu = stats->cpu; + struct uffd_args *args = (struct uffd_args *)arg; + unsigned long cpu = args->cpu; struct pollfd pollfd[2]; struct uffd_msg msg; struct uffdio_register uffd_reg; @@ -502,7 +502,7 @@ void *uffd_poll_thread(void *arg) err("unexpected msg event %u\n", msg.event); break; case UFFD_EVENT_PAGEFAULT: - uffd_handle_page_fault(&msg, stats); + uffd_handle_page_fault(&msg, args); break; case UFFD_EVENT_FORK: close(uffd); diff --git a/tools/testing/selftests/mm/uffd-common.h b/tools/testing/selftests/mm/uffd-common.h index 47565b2f2dee..f8d2ad178827 100644 --- a/tools/testing/selftests/mm/uffd-common.h +++ b/tools/testing/selftests/mm/uffd-common.h @@ -70,7 +70,7 @@ - 1))) /* Userfaultfd test statistics */ -struct uffd_stats { +struct uffd_args { int cpu; unsigned long missing_faults; unsigned long wp_faults; @@ -98,12 +98,12 @@ extern uffd_test_ops_t shmem_uffd_test_ops; extern uffd_test_ops_t hugetlb_uffd_test_ops; extern uffd_test_ops_t *uffd_test_ops; -void uffd_stats_report(struct uffd_stats *stats, int n_cpus); +void uffd_stats_report(struct uffd_args *args, int n_cpus); void uffd_test_ctx_init(uint64_t features); void userfaultfd_open(uint64_t *features); int uffd_read_msg(int ufd, struct uffd_msg *msg); void wp_range(int ufd, __u64 start, __u64 len, bool wp); -void uffd_handle_page_fault(struct uffd_msg *msg, struct uffd_stats *stats); +void uffd_handle_page_fault(struct uffd_msg *msg, struct uffd_args *args); int __copy_page(int ufd, unsigned long offset, bool retry); int copy_page(int ufd, unsigned long offset); void *uffd_poll_thread(void *arg); diff --git a/tools/testing/selftests/mm/uffd-stress.c b/tools/testing/selftests/mm/uffd-stress.c index 54fc9b4ffa3c..ce7251ab93ef 100644 --- a/tools/testing/selftests/mm/uffd-stress.c +++ b/tools/testing/selftests/mm/uffd-stress.c @@ -90,16 +90,15 @@ static void usage(void) exit(1); } -static void uffd_stats_reset(struct uffd_stats *uffd_stats, - unsigned long n_cpus) +static void uffd_stats_reset(struct uffd_args *args, unsigned long n_cpus) { int i; for (i = 0; i < n_cpus; i++) { - uffd_stats[i].cpu = i; - uffd_stats[i].missing_faults = 0; - uffd_stats[i].wp_faults = 0; - uffd_stats[i].minor_faults = 0; + args[i].cpu = i; + args[i].missing_faults = 0; + args[i].wp_faults = 0; + args[i].minor_faults = 0; } } @@ -163,7 +162,7 @@ pthread_mutex_t uffd_read_mutex = PTHREAD_MUTEX_INITIALIZER; static void *uffd_read_thread(void *arg) { - struct uffd_stats *stats = (struct uffd_stats *)arg; + struct uffd_args *args = (struct uffd_args *)arg; struct uffd_msg msg; pthread_mutex_unlock(&uffd_read_mutex); @@ -172,7 +171,7 @@ static void *uffd_read_thread(void *arg) for (;;) { if (uffd_read_msg(uffd, &msg)) continue; - uffd_handle_page_fault(&msg, stats); + uffd_handle_page_fault(&msg, args); } return NULL; @@ -210,7 +209,7 @@ static void *background_thread(void *arg) return NULL; } -static int stress(struct uffd_stats *uffd_stats) +static int stress(struct uffd_args *args) { unsigned long cpu; pthread_t locking_threads[nr_cpus]; @@ -225,12 +224,12 @@ static int stress(struct uffd_stats *uffd_stats) if (bounces & BOUNCE_POLL) { if (pthread_create(&uffd_threads[cpu], &attr, uffd_poll_thread, - (void *)&uffd_stats[cpu])) + (void *)&args[cpu])) return 1; } else { if (pthread_create(&uffd_threads[cpu], &attr, uffd_read_thread, - (void *)&uffd_stats[cpu])) + (void *)&args[cpu])) return 1; pthread_mutex_lock(&uffd_read_mutex); } @@ -264,7 +263,7 @@ static int stress(struct uffd_stats *uffd_stats) if (write(pipefd[cpu*2+1], &c, 1) != 1) err("pipefd write error"); if (pthread_join(uffd_threads[cpu], - (void *)&uffd_stats[cpu])) + (void *)&args[cpu])) return 1; } else { if (pthread_cancel(uffd_threads[cpu])) @@ -493,7 +492,7 @@ static int userfaultfd_events_test(void) int err, features; pid_t pid; char c; - struct uffd_stats stats = { 0 }; + struct uffd_args args = { 0 }; printf("testing events (fork, remap, remove): "); fflush(stdout); @@ -508,7 +507,7 @@ static int userfaultfd_events_test(void) true, test_uffdio_wp, false)) err("register failure"); - if (pthread_create(&uffd_mon, &attr, uffd_poll_thread, &stats)) + if (pthread_create(&uffd_mon, &attr, uffd_poll_thread, &args)) err("uffd_poll_thread create"); pid = fork(); @@ -526,9 +525,9 @@ static int userfaultfd_events_test(void) if (pthread_join(uffd_mon, NULL)) return 1; - uffd_stats_report(&stats, 1); + uffd_stats_report(&args, 1); - return stats.missing_faults != nr_pages; + return args.missing_faults != nr_pages; } static int userfaultfd_sig_test(void) @@ -538,7 +537,7 @@ static int userfaultfd_sig_test(void) int err, features; pid_t pid; char c; - struct uffd_stats stats = { 0 }; + struct uffd_args args = { 0 }; printf("testing signal delivery: "); fflush(stdout); @@ -557,7 +556,7 @@ static int userfaultfd_sig_test(void) uffd_test_ops->release_pages(area_dst); - if (pthread_create(&uffd_mon, &attr, uffd_poll_thread, &stats)) + if (pthread_create(&uffd_mon, &attr, uffd_poll_thread, &args)) err("uffd_poll_thread create"); pid = fork(); @@ -606,7 +605,7 @@ static int userfaultfd_minor_test(void) unsigned long p; pthread_t uffd_mon; char c; - struct uffd_stats stats = { 0 }; + struct uffd_args args = { 0 }; if (!test_uffdio_minor) return 0; @@ -629,7 +628,7 @@ static int userfaultfd_minor_test(void) page_size); } - if (pthread_create(&uffd_mon, &attr, uffd_poll_thread, &stats)) + if (pthread_create(&uffd_mon, &attr, uffd_poll_thread, &args)) err("uffd_poll_thread create"); /* @@ -645,7 +644,7 @@ static int userfaultfd_minor_test(void) if (pthread_join(uffd_mon, NULL)) return 1; - uffd_stats_report(&stats, 1); + uffd_stats_report(&args, 1); if (test_collapse) { printf("testing collapse of uffd memory into PMD-mapped THPs:"); @@ -664,7 +663,7 @@ static int userfaultfd_minor_test(void) printf(" done.\n"); } - return stats.missing_faults != 0 || stats.minor_faults != nr_pages; + return args.missing_faults != 0 || args.minor_faults != nr_pages; } static int pagemap_open(void) @@ -822,7 +821,7 @@ static int userfaultfd_stress(void) { void *area; unsigned long nr; - struct uffd_stats uffd_stats[nr_cpus]; + struct uffd_args args[nr_cpus]; uint64_t mem_size = nr_pages * page_size; uffd_test_ctx_init(UFFD_FEATURE_WP_UNPOPULATED); @@ -894,10 +893,10 @@ static int userfaultfd_stress(void) */ uffd_test_ops->release_pages(area_dst); - uffd_stats_reset(uffd_stats, nr_cpus); + uffd_stats_reset(args, nr_cpus); /* bounce pass */ - if (stress(uffd_stats)) + if (stress(args)) return 1; /* Clear all the write protections if there is any */ @@ -926,7 +925,7 @@ static int userfaultfd_stress(void) swap(area_src_alias, area_dst_alias); - uffd_stats_report(uffd_stats, nr_cpus); + uffd_stats_report(args, nr_cpus); } if (test_type == TEST_ANON) { From patchwork Wed Apr 12 16:43:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209357 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 7BCF5C77B6E for ; Wed, 12 Apr 2023 16:43:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 12CD2900007; Wed, 12 Apr 2023 12:43:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 08EF2900003; Wed, 12 Apr 2023 12:43:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E23E5900007; Wed, 12 Apr 2023 12:43:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id D1AE3900003 for ; Wed, 12 Apr 2023 12:43:54 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 8EF344014E for ; Wed, 12 Apr 2023 16:43:54 +0000 (UTC) X-FDA: 80673310788.30.89ECC8C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf02.hostedemail.com (Postfix) with ESMTP id 5003880025 for ; Wed, 12 Apr 2023 16:43:52 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UiSBdCkX; spf=pass (imf02.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@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=1681317832; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BeK25Zk7G/NLwTDOVvJddw9Gyk0/O/quMsTWu17keu8=; b=AsnlWDIsTzUmd/K6pNJOAGMcHdYnrrubSdFyAqw66G1wb7QVBmFHsC52sbka/PtwIl01W7 Mlqoc09daweWWL+SOd4cbWwZyl7WamXrYEvCjW8Eq8Sx35ORdK8ouDgFY6NCqYwnYbeGSM akURmVImjxJ4hTZ3uKgrKR/4dCAgabY= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UiSBdCkX; spf=pass (imf02.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681317832; a=rsa-sha256; cv=none; b=nCXH/KMQDOpvyMMktJqpZUQp8fBxtxECt4lJg0jaDVbmeUpFCd+DKyqPNrMwpu5/zZuLwB QQXiIQtvikKTj7jyrLT/+NHqlLmPZLGbnyf1uTgYHqAzEc8vFZqq0x+aMHXdnVrS3uNZ2X mgpTHogsXGSrVDMvaIW7Cnz7IZ7J2Sw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317831; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BeK25Zk7G/NLwTDOVvJddw9Gyk0/O/quMsTWu17keu8=; b=UiSBdCkXjpcG9J1AOia8qgAmMg9tQ/SRB8wjXCpU5wUmRsgmnM3P4K7Ugog5xrYgMM3c25 L4+25BWRROxxiPRWlIhWHyxQJw9ifMYjSdLczW/bs1zze8lwF5TFmIVYfsZQdMU/jPPzg5 9wBE6R1a+euTFX4rRFyTJOfu38+ztG4= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-621-4sTvk3cwOpCxMGknIyacxA-1; Wed, 12 Apr 2023 12:43:46 -0400 X-MC-Unique: 4sTvk3cwOpCxMGknIyacxA-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-3e947d81d7dso268101cf.1 for ; Wed, 12 Apr 2023 09:43:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317825; x=1683909825; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BeK25Zk7G/NLwTDOVvJddw9Gyk0/O/quMsTWu17keu8=; b=LSIPchYdGVCIBeQXTKEITqnLSBhM1CrPTSUgXlO4smZmBIo/FdnVrX60KHO3jrRTHj U0HdlXINIHp9nLwNmzioxxpEMmylA2OXiqnTjsEN2GmViZWVSm4ArvrMWwS/AoTKBpwd aCOzhZ8BT7xyIO0N+Jgn32juJ+XYHh5NrWXoLq0eDdSNefSUoqsFRfhWJHhh6EAwLA05 hY6hQVMFr0S6eyDvXv4NVPJ/xk1zUAI0Z/3CbYUE2ob+eMS2Xdw452yRQLz3ozKX9TAt 9OODsIaGuolztZi9FBftIkecH5VjDojI0YUjF64XKwmlFpNQZjgbWgDwKcLclX1vgTWc btvA== X-Gm-Message-State: AAQBX9cxLnoZ4fbPaUeuiGl8nwXtehAKM0x0b99RdDRK1JYlbui6Sfcc bJmUtFpghTPIElE5FChts252O4ehAjJOyxYgx4IyMxsQmoENF6OB0qmG074u5h0HKasSb0PhEzO 4uxwHZzsYzhk= X-Received: by 2002:a05:622a:1891:b0:3e4:eb39:eb8b with SMTP id v17-20020a05622a189100b003e4eb39eb8bmr4000937qtc.5.1681317825450; Wed, 12 Apr 2023 09:43:45 -0700 (PDT) X-Google-Smtp-Source: AKy350Yl7mWL/S9YEy9zUWOoxCG4PHHcn5sGAnl7GyY2m0LveJWRNpcSER8LkzrTOjY9Kd6J0F5tgw== X-Received: by 2002:a05:622a:1891:b0:3e4:eb39:eb8b with SMTP id v17-20020a05622a189100b003e4eb39eb8bmr4000915qtc.5.1681317825147; Wed, 12 Apr 2023 09:43:45 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id i18-20020ac860d2000000b003e45a39ed74sm4353141qtm.81.2023.04.12.09.43.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:43:44 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: David Hildenbrand , Andrew Morton , Leonardo Bras Soares Passos , peterx@redhat.com, Andrea Arcangeli , Nadav Amit , Mike Rapoport , Axel Rasmussen , Mike Kravetz Subject: [PATCH v2 20/31] selftests/mm: Let uffd_handle_page_fault() take wp parameter Date: Wed, 12 Apr 2023 12:43:41 -0400 Message-Id: <20230412164341.328618-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 5003880025 X-Stat-Signature: dqumg8oqgrpw1xjeiohfpx1pyeixymoi X-HE-Tag: 1681317832-250734 X-HE-Meta: U2FsdGVkX19LIJOe041C4iHII2v9JcBbI5VjsHKvCAzGsoC0R5rKTtuUM2J30N0/2yOYKA4kX1kWcCPwG7/8p7FVWjXwjppAvE2CPQNS/lxiHlELwfaq+u2bPc3ihPUghEK4G9JG5X7t/FaEEjPH9wYfyjSDLHvoBF7x+Nv6JMBaqkqll5vyu9gvsSe5A6WycD42iKxBr418YZba6N1JHsIZkL4fXk0roV0WgiSIrbPoO/nVYW8g9OOFdjyzyNpD6DiwDkhz8NEfs8gy5CtfYAWzrQwDhgntYyX6FhZVM7oZtw8ZydqjZUwKAstxbahbDnsELc3G0NV9Y5AvzQ4EWFg0iI66FD41iGwEap8IEE0UuLZNrOzoTdwz/us9kfF4UHOnZgkTYDeFic5KW9Sx3vC7xTB7eBGsvo0ZvVQsEO+7UzMIE4rIQ1IbbkF0xurUhO8qbv4sWXpk8NtWLopn0ZwmMAMq9PAh82BDmt2jADurtoWp6sboditSnQwDGCaXE6Sn4rHynx9ogj46HLMgz3o2KJo4n6SRtabdv0R4rLHIZiwilZHG27IVU0XyEclUGYd5K1HknQ0ZLbETw8gChhatF6rj55aHDJBGB18NMcsisZpSBpyL5cz7NEVMbdZ9qCMuIs8juCRFwQ91kJ1iL2nwEb4Whgz0dy2A1raGpDqRaxwmdkIDahEUs2lIMd3JmJY3JKbzYN+/s94aCtd7yxPgIoKMNz2yr+cERqBl/4CAxFQ7iZR/27A9Cgnwxq8X++iRkfurKYZ1Lqa2Nc4zd7IPoV/V+wL8weIaoEiEanMAC4Z4Ixt3gyj6qbAI1b2hk/AJZEA4DewRP4G8CDzKw1Kqn3UlhByE3rF0XRr95GgYUFa3VLJXLN1eNhSjtyOmQ1doYHaw5DLXaowXLRtHDNHl9AHavAA6fqiFs04jkPnLGJD+8bXdAUMpzZ88EL7zU+6KYZElKGXdoTUXTxv 9L0Mmn9T kuUhk0Y50VKMOpHrGpmvXwS0Xgl9E+Imc2RcowlH/oyNUdQgGwmhAhEaAgGsMqIpvS+de3zRZF30tiaY85c7fjGzIbltnnCdmvjC9zEqrZSq4sFAjISwh6nwNkpSWvPUAUW/wMMgYPOCh2MVTW0ndd86T+C6UVxeWqo+czeH+3a9tgU2fsdZ3qx8Mb7uW+yCiFTVY9hsGVDMKJNYeHnpCcg7TkoK+RrTJ0SgInkyv5T5RB7j0o8ZkNQzZPQSNytiFx3B0ddPfRilEfLX1mqpLubZ9uDK2byrv9fZtMIKNrz8UqvDQcYDU1gyI8ddigWUmJ2m+0kakd21RKD/WcNyfPipgZq+6S4QUisoBb+mWx4P1vaxpZKLa1el1W6e1/+ktMNTWvVCXTFkqdS5FvCdbBtD16xeci2id5X27pLR/SsoDYLxRN3AdJxJTQDXrXFSWkpHndHbAI4QVlA2e9WsXW5AS8g4GfZxhzZEPz7qYUygAwd++OA6xt7DWoj6E2JTURIVBpd1luKtR4NI= 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: Make the handler optionally apply WP bit when resolving page faults for either missing or minor page faults. This moves towards removing global test_uffdio_wp outside of the common code. Signed-off-by: Peter Xu --- tools/testing/selftests/mm/uffd-common.c | 17 +++++++++-------- tools/testing/selftests/mm/uffd-common.h | 6 ++++-- tools/testing/selftests/mm/uffd-stress.c | 16 ++++++++++------ 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-common.c b/tools/testing/selftests/mm/uffd-common.c index e746405aa8f3..daa2a95408e6 100644 --- a/tools/testing/selftests/mm/uffd-common.c +++ b/tools/testing/selftests/mm/uffd-common.c @@ -353,7 +353,7 @@ void wp_range(int ufd, __u64 start, __u64 len, bool wp) err("clear WP failed: address=0x%"PRIx64, (uint64_t)start); } -static void continue_range(int ufd, __u64 start, __u64 len) +static void continue_range(int ufd, __u64 start, __u64 len, bool wp) { struct uffdio_continue req; int ret; @@ -361,7 +361,7 @@ static void continue_range(int ufd, __u64 start, __u64 len) req.range.start = start; req.range.len = len; req.mode = 0; - if (test_uffdio_wp) + if (wp) req.mode |= UFFDIO_CONTINUE_MODE_WP; if (ioctl(ufd, UFFDIO_CONTINUE, &req)) @@ -429,7 +429,8 @@ void uffd_handle_page_fault(struct uffd_msg *msg, struct uffd_args *args) area_dst_alias)); for (b = 0; b < page_size; ++b) area[b] = ~area[b]; - continue_range(uffd, msg->arg.pagefault.address, page_size); + continue_range(uffd, msg->arg.pagefault.address, page_size, + args->apply_wp); args->minor_faults++; } else { /* @@ -459,7 +460,7 @@ void uffd_handle_page_fault(struct uffd_msg *msg, struct uffd_args *args) offset = (char *)(unsigned long)msg->arg.pagefault.address - area_dst; offset &= ~(page_size-1); - if (copy_page(uffd, offset)) + if (copy_page(uffd, offset, args->apply_wp)) args->missing_faults++; } } @@ -555,7 +556,7 @@ static void wake_range(int ufd, unsigned long addr, unsigned long len) addr), exit(1); } -int __copy_page(int ufd, unsigned long offset, bool retry) +int __copy_page(int ufd, unsigned long offset, bool retry, bool wp) { struct uffdio_copy uffdio_copy; @@ -564,7 +565,7 @@ int __copy_page(int ufd, unsigned long offset, bool retry) uffdio_copy.dst = (unsigned long) area_dst + offset; uffdio_copy.src = (unsigned long) area_src + offset; uffdio_copy.len = page_size; - if (test_uffdio_wp) + if (wp) uffdio_copy.mode = UFFDIO_COPY_MODE_WP; else uffdio_copy.mode = 0; @@ -587,7 +588,7 @@ int __copy_page(int ufd, unsigned long offset, bool retry) return 0; } -int copy_page(int ufd, unsigned long offset) +int copy_page(int ufd, unsigned long offset, bool wp) { - return __copy_page(ufd, offset, false); + return __copy_page(ufd, offset, false, wp); } diff --git a/tools/testing/selftests/mm/uffd-common.h b/tools/testing/selftests/mm/uffd-common.h index f8d2ad178827..0ec07d025cfe 100644 --- a/tools/testing/selftests/mm/uffd-common.h +++ b/tools/testing/selftests/mm/uffd-common.h @@ -72,6 +72,8 @@ /* Userfaultfd test statistics */ struct uffd_args { int cpu; + /* Whether apply wr-protects when installing pages */ + bool apply_wp; unsigned long missing_faults; unsigned long wp_faults; unsigned long minor_faults; @@ -104,8 +106,8 @@ void userfaultfd_open(uint64_t *features); int uffd_read_msg(int ufd, struct uffd_msg *msg); void wp_range(int ufd, __u64 start, __u64 len, bool wp); void uffd_handle_page_fault(struct uffd_msg *msg, struct uffd_args *args); -int __copy_page(int ufd, unsigned long offset, bool retry); -int copy_page(int ufd, unsigned long offset); +int __copy_page(int ufd, unsigned long offset, bool retry, bool wp); +int copy_page(int ufd, unsigned long offset, bool wp); void *uffd_poll_thread(void *arg); #define TEST_ANON 1 diff --git a/tools/testing/selftests/mm/uffd-stress.c b/tools/testing/selftests/mm/uffd-stress.c index ce7251ab93ef..747d588c0d69 100644 --- a/tools/testing/selftests/mm/uffd-stress.c +++ b/tools/testing/selftests/mm/uffd-stress.c @@ -96,6 +96,7 @@ static void uffd_stats_reset(struct uffd_args *args, unsigned long n_cpus) for (i = 0; i < n_cpus; i++) { args[i].cpu = i; + args[i].apply_wp = test_uffdio_wp; args[i].missing_faults = 0; args[i].wp_faults = 0; args[i].minor_faults = 0; @@ -155,7 +156,7 @@ static void *locking_thread(void *arg) static int copy_page_retry(int ufd, unsigned long offset) { - return __copy_page(ufd, offset, true); + return __copy_page(ufd, offset, true, test_uffdio_wp); } pthread_mutex_t uffd_read_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -308,7 +309,7 @@ static void sighndl(int sig, siginfo_t *siginfo, void *ptr) * This also tests UFFD_FEATURE_EVENT_FORK event along with the signal * feature. Using monitor thread, verify no userfault events are generated. */ -static int faulting_process(int signal_test) +static int faulting_process(int signal_test, bool wp) { unsigned long nr; unsigned long long count; @@ -343,7 +344,7 @@ static int faulting_process(int signal_test) if (steps == 1) { /* This is a MISSING request */ steps++; - if (copy_page(uffd, offset)) + if (copy_page(uffd, offset, wp)) signalled++; } else { /* This is a WP request */ @@ -507,6 +508,7 @@ static int userfaultfd_events_test(void) true, test_uffdio_wp, false)) err("register failure"); + args.apply_wp = test_uffdio_wp; if (pthread_create(&uffd_mon, &attr, uffd_poll_thread, &args)) err("uffd_poll_thread create"); @@ -515,7 +517,7 @@ static int userfaultfd_events_test(void) err("fork"); if (!pid) - exit(faulting_process(0)); + exit(faulting_process(0, test_uffdio_wp)); waitpid(pid, &err, 0); if (err) @@ -551,11 +553,12 @@ static int userfaultfd_sig_test(void) true, test_uffdio_wp, false)) err("register failure"); - if (faulting_process(1)) + if (faulting_process(1, test_uffdio_wp)) err("faulting process failed"); uffd_test_ops->release_pages(area_dst); + args.apply_wp = test_uffdio_wp; if (pthread_create(&uffd_mon, &attr, uffd_poll_thread, &args)) err("uffd_poll_thread create"); @@ -564,7 +567,7 @@ static int userfaultfd_sig_test(void) err("fork"); if (!pid) - exit(faulting_process(2)); + exit(faulting_process(2, test_uffdio_wp)); waitpid(pid, &err, 0); if (err) @@ -628,6 +631,7 @@ static int userfaultfd_minor_test(void) page_size); } + args.apply_wp = test_uffdio_wp; if (pthread_create(&uffd_mon, &attr, uffd_poll_thread, &args)) err("uffd_poll_thread create"); From patchwork Wed Apr 12 16:43:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209356 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 5A256C7619A for ; Wed, 12 Apr 2023 16:43:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F0F58900005; Wed, 12 Apr 2023 12:43:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EBFA6900003; Wed, 12 Apr 2023 12:43:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D6092900005; Wed, 12 Apr 2023 12:43:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C5FAF900003 for ; Wed, 12 Apr 2023 12:43:53 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 7D1511601B8 for ; Wed, 12 Apr 2023 16:43:53 +0000 (UTC) X-FDA: 80673310746.11.F173692 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf06.hostedemail.com (Postfix) with ESMTP id 713B218000E for ; Wed, 12 Apr 2023 16:43:51 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SbpZYaZz; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf06.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681317831; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=q6fb7dGe8Qh9zpC1XHTDp4auTsAlmohzusSG+yhHPLI=; b=M7lRacX4HYCrGiSeKuUADOdOEsxox+37yiLVqdCRK9h2n4QO7IX3/RM+/DIuHeQ7XdSQVB 4CPPznK10htq2s4ingHvFEnqiyPC3U3hAz8KRA31/UT3mj30ysASIIwG3OQ6L+1estuvsR i8/GSXVUAc6kCwXBenWhUntysbcRSiY= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SbpZYaZz; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf06.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681317831; a=rsa-sha256; cv=none; b=m8CQ9MuZ9vcNBl9rPyHSUlNN+w86h0XBZcdQ4rsFEN6gP2GanfSef9iI0hW2zh2gRUSIv9 zKigXcM4DHmWYK4mWmluUyMEaKSMx5nLIjhdv9v3OBg3Uv3FuSsiv1N9X5CgQJMeRKb8SC ZzFn5d1ElREgFrNjZZdber2ZNBZwT8s= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317830; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=q6fb7dGe8Qh9zpC1XHTDp4auTsAlmohzusSG+yhHPLI=; b=SbpZYaZzvcjlK4be1XLacjpcUdlOPr4MufJ9Lwv5Qvo6ye4VceiPSq9pBLV6p8VTRzvX/J VPOqtm0XZOmT1dIUBBWCC1GIRg3a5ghWW3iOjpD+JwQS4PMUQ/9BDypVriv0Yzm627BV5B R2cqJg422n2mwxoOe1Gftt+OxM2h9JM= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-649-sdb1MHR9O7aYi9oSJjBjCg-1; Wed, 12 Apr 2023 12:43:49 -0400 X-MC-Unique: sdb1MHR9O7aYi9oSJjBjCg-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-74a65b255beso53920585a.0 for ; Wed, 12 Apr 2023 09:43:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317829; x=1683909829; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=q6fb7dGe8Qh9zpC1XHTDp4auTsAlmohzusSG+yhHPLI=; b=ICHoUCILaQam7K5QfY3TZXgJ2dLG4wRpJxw6+XLdg3UnchJwYEr6Mpvimo13UvLNlb D/BV75v0B3bOPutTyxqC8dqTcDE4Yfh5WHP+0BsyuA+P2yuAKYPuSsQrBNrqX4vDXjQ0 Z7oQ8V5KTYcwUsJ9keXfISs/lxFKo8vdh6uHjvjnTxRpdh2RIWG/SFDaRSz4AVXr0/k2 zyQJ6rffrGOb8cgYmIzXPGAR6LkSwydX5gGyMxOealDOJwg5tFriqDDjUDGFbV11dqPE YxSFgQ53nFKUMTyEBZkjWqmw4/q+/Qem18qrcp8N3MmxQuZ4SGefBKt/z4G4Rf45AMW/ Y+HA== X-Gm-Message-State: AAQBX9fWPLPlsZxABqv5jguIMgmLjTFac8X9K68rW2RR1JU1n+sTrmNP CuF0m4u9y+u9uMquNLtuSwch6K6ucp8AsQWplnFk7MEdXhfI1twEAAcJ+F2029I5xqrn68gdV+7 hLlOrR2z+pHo= X-Received: by 2002:a05:6214:410e:b0:5e8:e227:982e with SMTP id kc14-20020a056214410e00b005e8e227982emr4492225qvb.3.1681317828924; Wed, 12 Apr 2023 09:43:48 -0700 (PDT) X-Google-Smtp-Source: AKy350bUncXTyJW92k3ESgGa7qeDhT/mpGdY2qSDyncYCia8CnYIFPtqWX76/SVSSYIWo1RN9ImdVA== X-Received: by 2002:a05:6214:410e:b0:5e8:e227:982e with SMTP id kc14-20020a056214410e00b005e8e227982emr4492202qvb.3.1681317828637; Wed, 12 Apr 2023 09:43:48 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id w23-20020ac86b17000000b003e6948a8966sm3274810qts.21.2023.04.12.09.43.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:43:47 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: David Hildenbrand , Andrew Morton , Leonardo Bras Soares Passos , peterx@redhat.com, Andrea Arcangeli , Nadav Amit , Mike Rapoport , Axel Rasmussen , Mike Kravetz Subject: [PATCH v2 21/31] selftests/mm: Allow allocate_area() to fail properly Date: Wed, 12 Apr 2023 12:43:45 -0400 Message-Id: <20230412164345.328659-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: 713B218000E X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: mtuzwwwo8aaxq9581r1a9x8w1zuugtci X-HE-Tag: 1681317831-722753 X-HE-Meta: U2FsdGVkX1/YvBmrd4UqvDXptFgndo2mZfnsZsMlRBPAczbxPnEPwZZGwFPAQFrUNrVg97X7T26mF/TkPAUivpmCjp0aNOQhQdMHN3XLZxrtRUrtqd/iesKi3Lv11TytLW0/b/8atBdrSReztRSd/bSbbuf1MxNqFL2nx5SH9k40PGA9Rs1dM/wBPl55Kydv9AmcfgZHwYWaWxx9M6gcAn4RUUxlKb1vd6bKAPToCXiOcdfNMrADwhJyMcPagN6c0nLx6J3Y9uw3XEzqUkUYuPowRvbNWBWljd+3Y/EFHssI7uDlRnzJrIzlOX7V6KK2naP5NcCjGhGw1GPnW1V0DkS59MBocLhoD8g+Beto3bRWIRNn0qzNdyGmJvh1S6Lc2NEdSX8vdVcYwWqYN/Ug0VNwoQvYLowE05Xrt90foUKC0f/VHfGu3S1b+YP2m7WZLb6RxbT/DyxZfvoq8Ngpq7YYhVx2omd+s3GrU3jmuq52WoHDdJmLlTzou+f4HOErmulvARnMjKYKTlxn5od0tieR+2XHGHu/uZqD3llImYSWudd+RdTdpw/jtaEOemujM95VMh/jpj02zqdyVLnePF1tZ8dnSxULyw9hL8g68pDQ81hCzklMDhAGZfYZP0SlycQcdrYLIWJoaOK7eaCy18ZUajQBr+secPnnX2JJLTWqpqY5dmDBOZvR7DIZiLDtAVabc0UksDG6rvUhZfFuo0WPhDHHt0QaqHnrWKjkUPfPSU2SlmTxpEie999ZDLIBc5ohDmXeLUqPq3MZJUZ6T5HeKRbTHGjRILiI7ZrHqiE3+MInFuDOX3JqoBKOVErkqOLkiTh57H9Q04nBnV6MYd6mUDuV0hgUqd0IRPcdUUAfZfsrE4hmWPUAxvitTNjwlI1/ilthGNiEPRVako7JCu681AqdbBuUSKsKICXOT64PGzomovezGkJId3J3wcf1F9dewt3Ji34xbDDWoyL hkm86JMb WT5ajRM0dm6CH3Piuyf/63mdCHUZAqPorgaicouscatqGDoVWugyaVdwYvoXwGHF6CRSXhRWf4wXuymN2rREr5vTwMCM4SbHIdWegb565ZxTizVWlEstSZb8RhYeFKA9tyeIgY9dX3StDdytpdkN3XWI04cKIUaxZNhEefr1SSiKzn2AARdnRBIoQke5pDM5JcG9cinEoKJF9F66XhqggH0GDJ/gGMVpMkzc8/kA/kKdQygb/0BMOIlBEISwStJzzZWkRpk7okOczNW+eI38R+YO5CKyUzZH3zStzuquB8A1b4mWKBWzluFqoLtD0CsSEUDAv/YuWH9jQrKA74iqyO9gGmzAVXz8edFTki1HFmkt6azqMekTvnddVRLV6SywsKFhnTGvuL0GaO+VNjaz/uyNWsumzGNYUGGTCCYtZxj9zwXkreRq+NBNky/cTcw7WPWAcOJPQdQKgUSh0AuxDNeCyLNnZw+/zphGdYU+d2h4kKMlm3p3h5Ktyy88ygZzQq9is8+U65aaAKvc= 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: Mostly to detect hugetlb allocation errors and skip hugetlb tests when pages are not allocated. Signed-off-by: Peter Xu --- tools/testing/selftests/mm/uffd-common.c | 47 +++++++++++++++++------- tools/testing/selftests/mm/uffd-common.h | 4 +- 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-common.c b/tools/testing/selftests/mm/uffd-common.c index daa2a95408e6..bc6c5c38d6dd 100644 --- a/tools/testing/selftests/mm/uffd-common.c +++ b/tools/testing/selftests/mm/uffd-common.c @@ -44,10 +44,15 @@ static void anon_release_pages(char *rel_area) err("madvise(MADV_DONTNEED) failed"); } -static void anon_allocate_area(void **alloc_area, bool is_src) +static int anon_allocate_area(void **alloc_area, bool is_src) { *alloc_area = mmap(NULL, nr_pages * page_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + if (*alloc_area == MAP_FAILED) { + *alloc_area = NULL; + return -errno; + } + return 0; } static void noop_alias_mapping(__u64 *start, size_t len, unsigned long offset) @@ -65,7 +70,7 @@ static void hugetlb_release_pages(char *rel_area) } } -static void hugetlb_allocate_area(void **alloc_area, bool is_src) +static int hugetlb_allocate_area(void **alloc_area, bool is_src) { off_t size = nr_pages * page_size; off_t offset = is_src ? 0 : size; @@ -77,14 +82,16 @@ static void hugetlb_allocate_area(void **alloc_area, bool is_src) (map_shared ? MAP_SHARED : MAP_PRIVATE) | (is_src ? 0 : MAP_NORESERVE), mem_fd, offset); - if (*alloc_area == MAP_FAILED) - err("mmap of hugetlbfs file failed"); + if (*alloc_area == MAP_FAILED) { + *alloc_area = NULL; + return -errno; + } if (map_shared) { area_alias = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, offset); if (area_alias == MAP_FAILED) - err("mmap of hugetlb file alias failed"); + return -errno; } if (is_src) { @@ -96,6 +103,7 @@ static void hugetlb_allocate_area(void **alloc_area, bool is_src) *alloc_area_alias = area_alias; close(mem_fd); + return 0; } static void hugetlb_alias_mapping(__u64 *start, size_t len, unsigned long offset) @@ -112,7 +120,7 @@ static void shmem_release_pages(char *rel_area) err("madvise(MADV_REMOVE) failed"); } -static void shmem_allocate_area(void **alloc_area, bool is_src) +static int shmem_allocate_area(void **alloc_area, bool is_src) { void *area_alias = NULL; size_t bytes = nr_pages * page_size, hpage_size = read_pmd_pagesize(); @@ -132,15 +140,20 @@ static void shmem_allocate_area(void **alloc_area, bool is_src) *alloc_area = mmap(p, bytes, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, offset); - if (*alloc_area == MAP_FAILED) - err("mmap of memfd failed"); + if (*alloc_area == MAP_FAILED) { + *alloc_area = NULL; + return -errno; + } if (test_collapse && *alloc_area != p) err("mmap of memfd failed at %p", p); area_alias = mmap(p_alias, bytes, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, offset); - if (area_alias == MAP_FAILED) - err("mmap of memfd alias failed"); + if (area_alias == MAP_FAILED) { + munmap(*alloc_area, bytes); + *alloc_area = NULL; + return -errno; + } if (test_collapse && area_alias != p_alias) err("mmap of anonymous memory failed at %p", p_alias); @@ -150,6 +163,7 @@ static void shmem_allocate_area(void **alloc_area, bool is_src) area_dst_alias = area_alias; close(mem_fd); + return 0; } static void shmem_alias_mapping(__u64 *start, size_t len, unsigned long offset) @@ -282,14 +296,19 @@ static void uffd_test_ctx_clear(void) munmap_area((void **)&area_remap); } -void uffd_test_ctx_init(uint64_t features) +int uffd_test_ctx_init(uint64_t features) { unsigned long nr, cpu; + int ret; uffd_test_ctx_clear(); - uffd_test_ops->allocate_area((void **)&area_src, true); - uffd_test_ops->allocate_area((void **)&area_dst, false); + ret = uffd_test_ops->allocate_area((void **)&area_src, true); + if (ret) + return ret; + ret = uffd_test_ops->allocate_area((void **)&area_dst, false); + if (ret) + return ret; userfaultfd_open(&features); @@ -337,6 +356,8 @@ void uffd_test_ctx_init(uint64_t features) for (cpu = 0; cpu < nr_cpus; cpu++) if (pipe2(&pipefd[cpu * 2], O_CLOEXEC | O_NONBLOCK)) err("pipe"); + + return 0; } void wp_range(int ufd, __u64 start, __u64 len, bool wp) diff --git a/tools/testing/selftests/mm/uffd-common.h b/tools/testing/selftests/mm/uffd-common.h index 0ec07d025cfe..9479a0649d7f 100644 --- a/tools/testing/selftests/mm/uffd-common.h +++ b/tools/testing/selftests/mm/uffd-common.h @@ -80,7 +80,7 @@ struct uffd_args { }; struct uffd_test_ops { - void (*allocate_area)(void **alloc_area, bool is_src); + int (*allocate_area)(void **alloc_area, bool is_src); void (*release_pages)(char *rel_area); void (*alias_mapping)(__u64 *start, size_t len, unsigned long offset); void (*check_pmd_mapping)(void *p, int expect_nr_hpages); @@ -101,7 +101,7 @@ extern uffd_test_ops_t hugetlb_uffd_test_ops; extern uffd_test_ops_t *uffd_test_ops; void uffd_stats_report(struct uffd_args *args, int n_cpus); -void uffd_test_ctx_init(uint64_t features); +int uffd_test_ctx_init(uint64_t features); void userfaultfd_open(uint64_t *features); int uffd_read_msg(int ufd, struct uffd_msg *msg); void wp_range(int ufd, __u64 start, __u64 len, bool wp); From patchwork Wed Apr 12 16:43:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209358 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 7CB5BC77B6F for ; Wed, 12 Apr 2023 16:43:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 21794900008; Wed, 12 Apr 2023 12:43:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1C93A900003; Wed, 12 Apr 2023 12:43:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 041B9900008; Wed, 12 Apr 2023 12:43:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E89D5900003 for ; Wed, 12 Apr 2023 12:43:56 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id BF6FB1601B2 for ; Wed, 12 Apr 2023 16:43:56 +0000 (UTC) X-FDA: 80673310872.09.17D35D2 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf24.hostedemail.com (Postfix) with ESMTP id B0D2C18000C for ; Wed, 12 Apr 2023 16:43:54 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SkEdKnCi; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf24.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681317834; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ujW8sSFyaGmImGgAfN35Mc7lSxeHHva64g4oK3AlUaQ=; b=xmag6AaGyTso7046hDtzrC3FX9XRfzKBZlhU2Rnq86pGq/jz7IeYYuM4BWnUtOm3mSZn6G 02CqC/SU0rR/tw31CN6+YHoKCU+mVeZKknHo2p09yvJiUbPOXFlO+7eQ6DxW9ZXoa6Aznf wU3sIExUS8u5cvC1OdZtsDG+O050E/w= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SkEdKnCi; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf24.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681317834; a=rsa-sha256; cv=none; b=VkajbWzA/XiPdIUKEGmSBi425ZGJiZ6WRyBMSjWuxE18vdRp/xqlheaI03yxD9hZZuuZ7/ 7rcEsq+yLIAziaDYsz+26foKyI4LnE8uOL8E/TTGz5/72wdY6sZ3at0teB4LJioxFTCiKv Gcjgx0a9PnlREqsIXlD1gZ+hpl5/uBM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317833; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ujW8sSFyaGmImGgAfN35Mc7lSxeHHva64g4oK3AlUaQ=; b=SkEdKnCirYzy1FQJ9fplYfUhkRnenuDaPMhlVpxouhsrR7FH3AdUXggG0w4u/pPEJUHrTi M4Pejg8rMCaP0k/vilmUUd17dj1fv11S+1vVVnrrL/NmbuaIyYruW35zUdl2ZO2toKJLmu 4dEoN+4eJsKgXhmNVbO38TYnXvmgnj0= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-61-EUsiUzK7NVGKwVJ8jKRsJg-1; Wed, 12 Apr 2023 12:43:52 -0400 X-MC-Unique: EUsiUzK7NVGKwVJ8jKRsJg-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-3e948dfe9c9so364941cf.0 for ; Wed, 12 Apr 2023 09:43:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317832; x=1683909832; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ujW8sSFyaGmImGgAfN35Mc7lSxeHHva64g4oK3AlUaQ=; b=abqDozlGIGnga3MKfeq+Ym2nruSD3ZFtal5760BpF3ZiE5Q4Q2zg0BcQ1m9ehggwjX jbIqpcvq2ZDcQUFfWtqna50Xds74TUXLKLVuNj5Q/b5DVRBF4QrYwb70yaXF6TnrYaVN 5u/KNyCtPG9aHGGbeeEkwayhV07YXRuA+XAiAsozFwnVA2eky8VGkMP5oT5rCu5LmW4H uC6YPN85u3GZywSL0LaMM46QwSsTaF/GMmW2WIsOayr4z/Nd68ItdXyxa+XFql/2wKUK omP3yPJywJBvVTTWDBLBNlTG+pnl/cJrj4Bg46JravzDvKm2n77Ag2NEySB5KgFQrlXQ rHog== X-Gm-Message-State: AAQBX9cuipjmWteK/u+vhY7GD4+rp2rKZKMjR2PJcz6eNMv2Zsq6Wc7/ reEBEFMJBv4fZozouW9FxezKcn82PLYwOnMD+lqM/FNjBUSg4nWxJCUGUV3YnTQGOXxOgvd8Bjp JFxKKY+WRjQM= X-Received: by 2002:a05:622a:50d:b0:3e3:1d31:e37 with SMTP id l13-20020a05622a050d00b003e31d310e37mr4709079qtx.1.1681317832366; Wed, 12 Apr 2023 09:43:52 -0700 (PDT) X-Google-Smtp-Source: AKy350aZLU+frgjQvwfaxCNQHkNm3VqYZWvrTQZf2mrndcXgxwvn/h9oIaDpV8SbGuCpWFsDqkjI3A== X-Received: by 2002:a05:622a:50d:b0:3e3:1d31:e37 with SMTP id l13-20020a05622a050d00b003e31d310e37mr4709058qtx.1.1681317832132; Wed, 12 Apr 2023 09:43:52 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id h2-20020ac87442000000b003e3914c6839sm4369508qtr.43.2023.04.12.09.43.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:43:51 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: David Hildenbrand , Andrew Morton , Leonardo Bras Soares Passos , peterx@redhat.com, Andrea Arcangeli , Nadav Amit , Mike Rapoport , Axel Rasmussen , Mike Kravetz Subject: [PATCH v2 22/31] selftests/mm: Add framework for uffd-unit-test Date: Wed, 12 Apr 2023 12:43:48 -0400 Message-Id: <20230412164348.328710-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: B0D2C18000C X-Stat-Signature: kde4td8mxkobbjasp7g3mt5qpepsobmd X-HE-Tag: 1681317834-407081 X-HE-Meta: U2FsdGVkX186T2J1KjOHnhsJr5m2tVhLObSqauds6gMMJWVFp9R3Ht5rwHjm/TyM7muaX7H0xlP0kFNzExWohuSgXtsBUC/JX764JIHvUyioSRPnAXSHkLMqp+KP5V/hNlvvQrFfNwN24TqlkFtNAqAEfscCdhturc62UAafp0S40LnQ9SNJiTgdO7X28YX37qMP+9t72qaZEvrK8dFSK/bm/0hdj7PzMRwsUUUdebOwOTNxZHIcCYrBFSmqmZyjEGZwrOhVh2K0BxdUGdVJnTtrZ+ZW8X9sjvqdbH9ALkuUfninbI/7BZZF3cfR4+dxbuTg8JN/nVAgS+Vyk67pSetpW4bBC/ceQTcGCHNkRdIrSFjXWWZbDIF1VeT/tMspIJRacS7lqw748xzb1qyHMUtDgePObaGQFoHRjxAuEnC0rDAN+u611JDaE7M4ISY7+q+y5EGuT3OWmDvkyHKUFt8/n3DYx1xWKxpB7UBvp402NXdkbQopfVr0yMoJQI5uot1c4UH14Aj9qBZsGDD9i/ATiXZJKWCV4K9GqZqzPW7AVjtmj3XU6FXuUmdL4m7w5zJ8O6n7ZCh1pP36vLLgK9nYLMw9r2ERNzzJeRci4Qe16/q/pj+mIvPv8WzuA/BfAmYxVIo2BEizC0Ys9+1UlDSjd/A9fryooxshmCiZo0xhSJSn9TR8cPhnxS7DvH1F3tG/ZimTE8/IyAyjGO4U6Ub4Uep98maOZJIB4P/VY6LVOf4C1YyYX578CTHsSnXiEvUxI3Zv7fgSc2MUozdOm7srRGypMWZJnyY4tPX9SV2h6cKAIaZOCPQpkzE9EUTa9u7Qq9vCsYSwrJyaDDywVDuVsFiC/zpV7c5Zc1mmKXbpJcYGXGeBAV0XyDmZRLtLVM8ILRchMDz1Wtql0lRu/d4g9aAFeCxyNyKziyPeaIRsOcAjYmvlF+qyY5R9u05fp2FuZrFiRBZuNslrG6U RH0CaTKy O3M9Zi41s7hICCGA5VAhML6JudtDjmyCoLpNFFNjQgaw0clQYMA+KgBjjez6XgCOPGLonoLXhHbz+n4kYPEObZASo0IEmPvVwL01cPwrASB67g5qnzzXyWznfGUpdmH+eH0b+ZSHxl9drub2V7iLPilbimEGmy1OLD0RzibnOCKGUTTdkAFDq7bX+ypEG2fwuvqbeipBYrsFB9ZgXjkrZ053JCUaZxEzpIxmaKjGkF4cRLsmWzcX/1MAZEsmvfyeU/M4T+W6PwYUI6zVfdLvO9wiqDzhtjku+nCs8VNAKFvVMDHAsexZU/gJlz8j1DzgqtQRSblJvpC0n89/56YZWB/RmjVRzJQsFW5FvRwOjDak4HNlCvfYRhbXkZRghXsMrzMw50Vh2YTn5SzTAGOOlefnCdCWl4mOeDlifqY4wZfbT5EB6oTSBMS5gdSv1QfuMDsJXiyHus1/ZccoBHaO3XgfLtDioW3Kgl/YE 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: Add a framework to be prepared to move unit tests from uffd-stress.c into uffd-unit-tests.c. The goal is to allow detection of uffd features for each test, and also loop over specified types of memory that a test support. Signed-off-by: Peter Xu --- tools/testing/selftests/mm/uffd-unit-tests.c | 124 +++++++++++++++++++ tools/testing/selftests/mm/vm_util.c | 37 ++++++ tools/testing/selftests/mm/vm_util.h | 2 + 3 files changed, 163 insertions(+) diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/selftests/mm/uffd-unit-tests.c index bb492c258486..936b24a6f468 100644 --- a/tools/testing/selftests/mm/uffd-unit-tests.c +++ b/tools/testing/selftests/mm/uffd-unit-tests.c @@ -9,6 +9,66 @@ #ifdef __NR_userfaultfd +/* The unit test doesn't need a large or random size, make it 32MB for now */ +#define UFFD_TEST_MEM_SIZE (32UL << 20) + +#define MEM_ANON BIT_ULL(0) +#define MEM_SHMEM BIT_ULL(1) +#define MEM_SHMEM_PRIVATE BIT_ULL(2) +#define MEM_HUGETLB BIT_ULL(3) +#define MEM_HUGETLB_PRIVATE BIT_ULL(4) + +struct mem_type { + const char *name; + unsigned int mem_flag; + uffd_test_ops_t *mem_ops; + bool shared; +}; +typedef struct mem_type mem_type_t; + +mem_type_t mem_types[] = { + { + .name = "anon", + .mem_flag = MEM_ANON, + .mem_ops = &anon_uffd_test_ops, + .shared = false, + }, + { + .name = "shmem", + .mem_flag = MEM_SHMEM, + .mem_ops = &shmem_uffd_test_ops, + .shared = true, + }, + { + .name = "shmem-private", + .mem_flag = MEM_SHMEM_PRIVATE, + .mem_ops = &shmem_uffd_test_ops, + .shared = false, + }, + { + .name = "hugetlb", + .mem_flag = MEM_HUGETLB, + .mem_ops = &hugetlb_uffd_test_ops, + .shared = true, + }, + { + .name = "hugetlb-private", + .mem_flag = MEM_HUGETLB_PRIVATE, + .mem_ops = &hugetlb_uffd_test_ops, + .shared = false, + }, +}; + +/* Returns: UFFD_TEST_* */ +typedef void (*uffd_test_fn)(void); + +typedef struct { + const char *name; + uffd_test_fn uffd_fn; + unsigned int mem_targets; + uint64_t uffd_feature_required; +} uffd_test_case_t; + static void uffd_test_report(void) { printf("Userfaults unit tests: pass=%u, skip=%u, fail=%u (total=%u)\n", @@ -105,9 +165,50 @@ static int test_uffd_api(bool use_dev) return 1; } +/* + * This function initializes the global variables. TODO: remove global + * vars and then remove this. + */ +static int uffd_setup_environment(uffd_test_case_t *test, mem_type_t *mem_type) +{ + map_shared = mem_type->shared; + uffd_test_ops = mem_type->mem_ops; + + if (mem_type->mem_flag & (MEM_HUGETLB_PRIVATE | MEM_HUGETLB)) + page_size = default_huge_page_size(); + else + page_size = psize(); + + nr_pages = UFFD_TEST_MEM_SIZE / page_size; + /* TODO: remove this global var.. it's so ugly */ + nr_cpus = 1; + + return uffd_test_ctx_init(test->uffd_feature_required); +} + +static bool uffd_feature_supported(uffd_test_case_t *test) +{ + uint64_t features; + + if (uffd_get_features(&features)) + return false; + + return (features & test->uffd_feature_required) == + test->uffd_feature_required; +} + +uffd_test_case_t uffd_tests[] = { +}; + int main(int argc, char *argv[]) { + int n_tests = sizeof(uffd_tests) / sizeof(uffd_test_case_t); + int n_mems = sizeof(mem_types) / sizeof(mem_type_t); + uffd_test_case_t *test; + mem_type_t *mem_type; + char test_name[128]; int has_uffd; + int i, j; has_uffd = test_uffd_api(false); has_uffd |= test_uffd_api(true); @@ -116,6 +217,29 @@ int main(int argc, char *argv[]) printf("Userfaultfd not supported or unprivileged, skip all tests\n"); exit(KSFT_SKIP); } + + for (i = 0; i < n_tests; i++) { + test = &uffd_tests[i]; + for (j = 0; j < n_mems; j++) { + mem_type = &mem_types[j]; + if (!(test->mem_targets & mem_type->mem_flag)) + continue; + snprintf(test_name, sizeof(test_name), + "%s on %s", test->name, mem_type->name); + + uffd_test_start(test_name); + if (!uffd_feature_supported(test)) { + uffd_test_skip("feature missing"); + continue; + } + if (uffd_setup_environment(test, mem_type)) { + uffd_test_skip("environment setup failed"); + continue; + } + test->uffd_fn(); + } + } + uffd_test_report(); return ksft_get_fail_cnt() ? KSFT_FAIL : KSFT_PASS; diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c index 5ee6c4688a7c..1bc0ceb01adb 100644 --- a/tools/testing/selftests/mm/vm_util.c +++ b/tools/testing/selftests/mm/vm_util.c @@ -254,3 +254,40 @@ int uffd_open_sys(unsigned int flags) return -1; #endif } + +int uffd_open(unsigned int flags) +{ + int uffd = uffd_open_sys(flags); + + if (uffd < 0) + uffd = uffd_open_dev(flags); + + return uffd; +} + +int uffd_get_features(uint64_t *features) +{ + struct uffdio_api uffdio_api = { .api = UFFD_API, .features = 0 }; + /* + * This should by default work in most kernels; the feature list + * will be the same no matter what we pass in here. + */ + int fd = uffd_open(UFFD_USER_MODE_ONLY); + + if (fd < 0) + /* Maybe the kernel is older than user-only mode? */ + fd = uffd_open(0); + + if (fd < 0) + return fd; + + if (ioctl(fd, UFFDIO_API, &uffdio_api)) { + close(fd); + return -errno; + } + + *features = uffdio_api.features; + close(fd); + + return 0; +} diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h index 481354141533..634eb2f41145 100644 --- a/tools/testing/selftests/mm/vm_util.h +++ b/tools/testing/selftests/mm/vm_util.h @@ -50,6 +50,8 @@ int uffd_register(int uffd, void *addr, uint64_t len, int uffd_unregister(int uffd, void *addr, uint64_t len); int uffd_open_dev(unsigned int flags); int uffd_open_sys(unsigned int flags); +int uffd_open(unsigned int flags); +int uffd_get_features(uint64_t *features); /* * On ppc64 this will only work with radix 2M hugepage size From patchwork Wed Apr 12 16:43:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209359 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 C46FBC7619A for ; Wed, 12 Apr 2023 16:44:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 635C3900009; Wed, 12 Apr 2023 12:44:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5E536900003; Wed, 12 Apr 2023 12:44:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 486BE900009; Wed, 12 Apr 2023 12:44:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 39465900003 for ; Wed, 12 Apr 2023 12:44:04 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0C7EC1401CB for ; Wed, 12 Apr 2023 16:44:04 +0000 (UTC) X-FDA: 80673311208.20.DEC5B74 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf07.hostedemail.com (Postfix) with ESMTP id CD8E14001A for ; Wed, 12 Apr 2023 16:44:01 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=i5ClqfsB; spf=pass (imf07.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681317841; a=rsa-sha256; cv=none; b=N0GZCduPdPW2N5+yDBwGNUKfCKtg5OXyr0x9XWTEhOgPa5uGRhYqkY/rUUaj5T6RI9bayy vUGEIyXYIn1uoJVc61ZLDKnAVX/r412F4cUjKPdKMIjyHWi1aTsmmIjZUK7beO6vupcNf/ AiRKLSqVPHLgCgAJI1GotdG3mNspJMI= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=i5ClqfsB; spf=pass (imf07.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@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=1681317841; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=EPLVHwmG1JWLQdfe+bC3h4cMLKGLNsksPTamWwKRdSQ=; b=TDjB+eBYzI14nrF3HWrGg1XbMv1HLaIZg57FTFn6UkfPRnLTEr0TWiLd01TPQ5dBxzhmdl yQP0Nc1D4PoQWnrihz5cBKZhENtD/K+Z/AyM08My57zznIDi/2dceiN4MD+RGG//FsJhUD ASZLILpqXd+PA9RTrTtYz2O2RVjKDis= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317841; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EPLVHwmG1JWLQdfe+bC3h4cMLKGLNsksPTamWwKRdSQ=; b=i5ClqfsBrqjunAa1cUzLeso1HiIDsV+za7C6n6mBdhjYf4IlgSzHW1xRwaUzj0FP+1dy3y eZ4vdIW4qAbwA+pA+JzS/gmI9VU2iC1mWl27H4TZog6FjRux2nD3Vs9Yo/L1Uf9QcJSUgL /QFy0STi5m82Jnptk/xjIBH82s0hCgY= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-189-8rnC2bYEMYm3nvnWSFilIA-1; Wed, 12 Apr 2023 12:43:57 -0400 X-MC-Unique: 8rnC2bYEMYm3nvnWSFilIA-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-74a9035256eso54273785a.0 for ; Wed, 12 Apr 2023 09:43:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317837; x=1683909837; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EPLVHwmG1JWLQdfe+bC3h4cMLKGLNsksPTamWwKRdSQ=; b=MU4PK13xGGVK1C0c14zydwqb69Xb7QgoGzxjRUuiF1aXa8z/Ih6YJiSHbC89ZD/u2r VPqPszGYiIrT6THNWW7QJYLzX7IrMQZypDinlfoNe1DL0jY/TKgpV9GdH714BN6QUvKv jc0AKg7Ns1mKEyPUuFYN/kXBD7olh0Lrt+LgxZZ5LMXGp6+EoAZ+uLpri0KxqPe51NCH GA0GQzGHmVNXmhfYMH82vlEWj00HWYOmnRGZkO9lCx8eO4Krb2X0C9bKES1NAHzRqY4d MPMfwlNkF7kgPrQzjRbDV1K3avs+VAJ8MjGnagXruL9BeyrW42cAunkDbbdPdjq59O3w RG5A== X-Gm-Message-State: AAQBX9e8MLd/byrrzLCz5nF2bJAVd9R0o2cvpZxmiTuVYRkCGl1/akl5 +BjKUS/EiNlEesbI77Azfs6TwoCIVE9Ll92aikKbmZGaZxTXBbzRr/HExOIC3WUxvSVUfvpbozO ZKlafp3SMmGM= X-Received: by 2002:ac8:5cc8:0:b0:3e6:707e:d3b1 with SMTP id s8-20020ac85cc8000000b003e6707ed3b1mr5019828qta.0.1681317837038; Wed, 12 Apr 2023 09:43:57 -0700 (PDT) X-Google-Smtp-Source: AKy350ZbuxgmUhLJPUZsc/XbkJJrLLicXSsAvTA4gBiNZfg/X0rald8nfCHkMiAjHNJAZFk97T+JTQ== X-Received: by 2002:ac8:5cc8:0:b0:3e6:707e:d3b1 with SMTP id s8-20020ac85cc8000000b003e6707ed3b1mr5019794qta.0.1681317836679; Wed, 12 Apr 2023 09:43:56 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id d23-20020a05620a141700b00746803d7e8dsm4760743qkj.113.2023.04.12.09.43.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:43:55 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: David Hildenbrand , Andrew Morton , Leonardo Bras Soares Passos , peterx@redhat.com, Andrea Arcangeli , Nadav Amit , Mike Rapoport , Axel Rasmussen , Mike Kravetz , Mike Rapoport Subject: [PATCH v2 23/31] selftests/mm: Move uffd pagemap test to unit test Date: Wed, 12 Apr 2023 12:43:52 -0400 Message-Id: <20230412164352.328733-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Queue-Id: CD8E14001A X-Rspamd-Server: rspam01 X-Stat-Signature: 8rqdko1thrd99w8bcit99su7xaqzbdut X-HE-Tag: 1681317841-50640 X-HE-Meta: U2FsdGVkX18U6uhuHt1k/7DGgk7Kx9mWmOuEX9DOeq/iaIOBup0INEnhX0ZO2GhSDmLl+A594fre57jvGruDi6dp7xMCdwHlDO9RYrAqF7qyu/afJCO9nC3qkK5MlpoJwkRlmu+mEZoGN3p/ErLF6DxDrYh9EDDJ+cQK57dHGUuL9RchlT+QlZVwHK05VmD546gp8AZWOA8cvH/7MP4EqVX+C6Li0pkE0pSv5lPI50lkzmXPMy7rI5tOpKFIke4uQwXEtSGsGgnXVGEYtjfxya/BFsF9/5o/E1Hpk4BbWLbgFh5dV+iS0ivq0eaGxfT7C6uiHEbpCzZ4awHCWa/Fd0vfM5rkM1fNZGO9lwjKorpnaJ1kyCvjrqlnoPzzeyWDW/FCWpo54YF5bTgo9jVxGD9DJFskvQr6Affy1wXczy/w8ZXajW2M0Nh9Ft/oYtiZmBW3eeYge/Vie3IKlIMucPFQFIC5w2mLjzq1vKKZMUK0reEbwnp0E7lwv/r4FXvSCdg4xjF5hNOhc7A4vzgbc2RYV6Yr7F/URGYNeRgdrr3EllVw0PcydZtVAA3n0uaN9enSUXXZiBQc5y3KyvIKOAE1JRNpZvihdxLDQXV0tgQUKKQKbCY/M45StZlKottujidWN+4wfQ0VZvLCspdy65Zj8TG106zOIVZryxWyvm5BtTFBkfjZaymhUopjkt0qZ8kcH/mL65sc+NhfVQO/x+tzyB92TLM9G+GejJ8lfYzAAwGkQP3/6HeeJIytFWGvFQoxlO22WwPtIxYGa+MXQ+whABVToGVlcXBZg8uAqzPt/M+2EV9WffQfs2It5UEjBSBnaAJHqgLclrGu1SjS6y1TbOICko+p8PcQtSjQ8cejOLVy1J1SNZII9WuMhoxomO+TNUyqtY0OnvWyJojxp2d0o+Xke1EWgaTb3EIRl3pGkE5/UMU4d94TNsY4pqzRzqQCPfGosirRrqy8HKI tB4GQb2n ogQDgq3dS0FNMKcJ4ohnoO+hcu9xaJlhqnX30vnil2z7xQMKue645wbq13zD1RTGUtB8mr4oNuwyXKhfYs8aLcKYcal+tqw2P2dR0A7G3MQb0JRz0kvhBcrsj5J9spLPb8TLvkxyYlmSLtWJOVa1XoXee9/HprabemNSpAd5ruehjjdEb/xtpcBMuAJ+NTLDlMsGn7DHqklH8yw6g6snlqxMDMTeE51rOYD0ZgCT4r5p88EPmpztkeZKo5J/14/d/cB3IRLrsnA8/taee3Rq3f5SYbkcfyo5yVnQpBdE6kecIaP1NJPqpbsjB68AAbT+cXOyPpHPlmq+RWeiNz6IA88fWqASRo/kZqU23N88mxxWoudCednoeFGwDw+pzYgz4NFr0aMReMD0pjm4iYT9gmZSX8/iYvQkeeDv8iVTw2b3Vuo8aKyh0fJNHgbIH0jCAQXA++UC9qrOUlahNfe9+eudIdGjDc34sdbbuXGkCcoAvso3SRwYWAqpQ6I9XymR0qw6rtKAoKcMlagWkLBWOlhyZV6+q6Srxd3LV 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: Move it over and make it split into two tests, one for pagemap and one for the new WP_UNPOPULATED (to be a separate one). The thp pagemap test wasn't really working (with MADV_HUGEPAGE). Let's just drop it (since it never really worked anyway..) and leave that for later. Reviewed-by: Mike Rapoport (IBM) Signed-off-by: Peter Xu --- tools/testing/selftests/mm/uffd-stress.c | 166 ------------------- tools/testing/selftests/mm/uffd-unit-tests.c | 145 ++++++++++++++++ 2 files changed, 145 insertions(+), 166 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-stress.c b/tools/testing/selftests/mm/uffd-stress.c index 747d588c0d69..61d025d87bf2 100644 --- a/tools/testing/selftests/mm/uffd-stress.c +++ b/tools/testing/selftests/mm/uffd-stress.c @@ -670,157 +670,6 @@ static int userfaultfd_minor_test(void) return args.missing_faults != 0 || args.minor_faults != nr_pages; } -static int pagemap_open(void) -{ - int fd = open("/proc/self/pagemap", O_RDONLY); - - if (fd < 0) - err("open pagemap"); - - return fd; -} - -/* This macro let __LINE__ works in err() */ -#define pagemap_check_wp(value, wp) do { \ - if (!!(value & PM_UFFD_WP) != wp) \ - err("pagemap uffd-wp bit error: 0x%"PRIx64, value); \ - } while (0) - -static int pagemap_test_fork(bool present) -{ - pid_t child = fork(); - uint64_t value; - int fd, result; - - if (!child) { - /* Open the pagemap fd of the child itself */ - fd = pagemap_open(); - value = pagemap_get_entry(fd, area_dst); - /* - * After fork() uffd-wp bit should be gone as long as we're - * without UFFD_FEATURE_EVENT_FORK - */ - pagemap_check_wp(value, false); - /* Succeed */ - exit(0); - } - waitpid(child, &result, 0); - return result; -} - -static void userfaultfd_wp_unpopulated_test(int pagemap_fd) -{ - uint64_t value; - - /* Test applying pte marker to anon unpopulated */ - wp_range(uffd, (uint64_t)area_dst, page_size, true); - value = pagemap_get_entry(pagemap_fd, area_dst); - pagemap_check_wp(value, true); - - /* Test unprotect on anon pte marker */ - wp_range(uffd, (uint64_t)area_dst, page_size, false); - value = pagemap_get_entry(pagemap_fd, area_dst); - pagemap_check_wp(value, false); - - /* Test zap on anon marker */ - wp_range(uffd, (uint64_t)area_dst, page_size, true); - if (madvise(area_dst, page_size, MADV_DONTNEED)) - err("madvise(MADV_DONTNEED) failed"); - value = pagemap_get_entry(pagemap_fd, area_dst); - pagemap_check_wp(value, false); - - /* Test fault in after marker removed */ - *area_dst = 1; - value = pagemap_get_entry(pagemap_fd, area_dst); - pagemap_check_wp(value, false); - /* Drop it to make pte none again */ - if (madvise(area_dst, page_size, MADV_DONTNEED)) - err("madvise(MADV_DONTNEED) failed"); - - /* Test read-zero-page upon pte marker */ - wp_range(uffd, (uint64_t)area_dst, page_size, true); - *(volatile char *)area_dst; - /* Drop it to make pte none again */ - if (madvise(area_dst, page_size, MADV_DONTNEED)) - err("madvise(MADV_DONTNEED) failed"); -} - -static void userfaultfd_pagemap_test(unsigned int test_pgsize) -{ - int pagemap_fd; - uint64_t value; - - /* Pagemap tests uffd-wp only */ - if (!test_uffdio_wp) - return; - - /* Not enough memory to test this page size */ - if (test_pgsize > nr_pages * page_size) - return; - - printf("testing uffd-wp with pagemap (pgsize=%u): ", test_pgsize); - /* Flush so it doesn't flush twice in parent/child later */ - fflush(stdout); - - uffd_test_ctx_init(UFFD_FEATURE_WP_UNPOPULATED); - - if (test_pgsize > page_size) { - /* This is a thp test */ - if (madvise(area_dst, nr_pages * page_size, MADV_HUGEPAGE)) - err("madvise(MADV_HUGEPAGE) failed"); - } else if (test_pgsize == page_size) { - /* This is normal page test; force no thp */ - if (madvise(area_dst, nr_pages * page_size, MADV_NOHUGEPAGE)) - err("madvise(MADV_NOHUGEPAGE) failed"); - } - - if (uffd_register(uffd, area_dst, nr_pages * page_size, - false, true, false)) - err("register failed"); - - pagemap_fd = pagemap_open(); - - /* Smoke test WP_UNPOPULATED first when it's still empty */ - if (test_pgsize == page_size) - userfaultfd_wp_unpopulated_test(pagemap_fd); - - /* Touch the page */ - *area_dst = 1; - wp_range(uffd, (uint64_t)area_dst, test_pgsize, true); - value = pagemap_get_entry(pagemap_fd, area_dst); - pagemap_check_wp(value, true); - /* Make sure uffd-wp bit dropped when fork */ - if (pagemap_test_fork(true)) - err("Detected stall uffd-wp bit in child"); - - /* Exclusive required or PAGEOUT won't work */ - if (!(value & PM_MMAP_EXCLUSIVE)) - err("multiple mapping detected: 0x%"PRIx64, value); - - if (madvise(area_dst, test_pgsize, MADV_PAGEOUT)) - err("madvise(MADV_PAGEOUT) failed"); - - /* Uffd-wp should persist even swapped out */ - value = pagemap_get_entry(pagemap_fd, area_dst); - pagemap_check_wp(value, true); - /* Make sure uffd-wp bit dropped when fork */ - if (pagemap_test_fork(false)) - err("Detected stall uffd-wp bit in child"); - - /* Unprotect; this tests swap pte modifications */ - wp_range(uffd, (uint64_t)area_dst, page_size, false); - value = pagemap_get_entry(pagemap_fd, area_dst); - pagemap_check_wp(value, false); - - /* Fault in the page from disk */ - *area_dst = 2; - value = pagemap_get_entry(pagemap_fd, area_dst); - pagemap_check_wp(value, false); - - close(pagemap_fd); - printf("done\n"); -} - static int userfaultfd_stress(void) { void *area; @@ -932,21 +781,6 @@ static int userfaultfd_stress(void) uffd_stats_report(args, nr_cpus); } - if (test_type == TEST_ANON) { - /* - * shmem/hugetlb won't be able to run since they have different - * behavior on fork() (file-backed memory normally drops ptes - * directly when fork), meanwhile the pagemap test will verify - * pgtable entry of fork()ed child. - */ - userfaultfd_pagemap_test(page_size); - /* - * Hard-code for x86_64 for now for 2M THP, as x86_64 is - * currently the only one that supports uffd-wp - */ - userfaultfd_pagemap_test(page_size * 512); - } - return userfaultfd_zeropage_test() || userfaultfd_sig_test() || userfaultfd_events_test() || userfaultfd_minor_test(); } diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/selftests/mm/uffd-unit-tests.c index 936b24a6f468..4690c95a9420 100644 --- a/tools/testing/selftests/mm/uffd-unit-tests.c +++ b/tools/testing/selftests/mm/uffd-unit-tests.c @@ -197,7 +197,152 @@ static bool uffd_feature_supported(uffd_test_case_t *test) test->uffd_feature_required; } +static int pagemap_open(void) +{ + int fd = open("/proc/self/pagemap", O_RDONLY); + + if (fd < 0) + err("open pagemap"); + + return fd; +} + +/* This macro let __LINE__ works in err() */ +#define pagemap_check_wp(value, wp) do { \ + if (!!(value & PM_UFFD_WP) != wp) \ + err("pagemap uffd-wp bit error: 0x%"PRIx64, value); \ + } while (0) + +static int pagemap_test_fork(bool present) +{ + pid_t child = fork(); + uint64_t value; + int fd, result; + + if (!child) { + /* Open the pagemap fd of the child itself */ + fd = pagemap_open(); + value = pagemap_get_entry(fd, area_dst); + /* + * After fork() uffd-wp bit should be gone as long as we're + * without UFFD_FEATURE_EVENT_FORK + */ + pagemap_check_wp(value, false); + /* Succeed */ + exit(0); + } + waitpid(child, &result, 0); + return result; +} + +static void uffd_wp_unpopulated_test(void) +{ + uint64_t value; + int pagemap_fd; + + if (uffd_register(uffd, area_dst, nr_pages * page_size, + false, true, false)) + err("register failed"); + + pagemap_fd = pagemap_open(); + + /* Test applying pte marker to anon unpopulated */ + wp_range(uffd, (uint64_t)area_dst, page_size, true); + value = pagemap_get_entry(pagemap_fd, area_dst); + pagemap_check_wp(value, true); + + /* Test unprotect on anon pte marker */ + wp_range(uffd, (uint64_t)area_dst, page_size, false); + value = pagemap_get_entry(pagemap_fd, area_dst); + pagemap_check_wp(value, false); + + /* Test zap on anon marker */ + wp_range(uffd, (uint64_t)area_dst, page_size, true); + if (madvise(area_dst, page_size, MADV_DONTNEED)) + err("madvise(MADV_DONTNEED) failed"); + value = pagemap_get_entry(pagemap_fd, area_dst); + pagemap_check_wp(value, false); + + /* Test fault in after marker removed */ + *area_dst = 1; + value = pagemap_get_entry(pagemap_fd, area_dst); + pagemap_check_wp(value, false); + /* Drop it to make pte none again */ + if (madvise(area_dst, page_size, MADV_DONTNEED)) + err("madvise(MADV_DONTNEED) failed"); + + /* Test read-zero-page upon pte marker */ + wp_range(uffd, (uint64_t)area_dst, page_size, true); + *(volatile char *)area_dst; + /* Drop it to make pte none again */ + if (madvise(area_dst, page_size, MADV_DONTNEED)) + err("madvise(MADV_DONTNEED) failed"); + + uffd_test_pass(); +} + +static void uffd_pagemap_test(void) +{ + int pagemap_fd; + uint64_t value; + + if (uffd_register(uffd, area_dst, nr_pages * page_size, + false, true, false)) + err("register failed"); + + pagemap_fd = pagemap_open(); + + /* Touch the page */ + *area_dst = 1; + wp_range(uffd, (uint64_t)area_dst, page_size, true); + value = pagemap_get_entry(pagemap_fd, area_dst); + pagemap_check_wp(value, true); + /* Make sure uffd-wp bit dropped when fork */ + if (pagemap_test_fork(true)) + err("Detected stall uffd-wp bit in child"); + + /* Exclusive required or PAGEOUT won't work */ + if (!(value & PM_MMAP_EXCLUSIVE)) + err("multiple mapping detected: 0x%"PRIx64, value); + + if (madvise(area_dst, page_size, MADV_PAGEOUT)) + err("madvise(MADV_PAGEOUT) failed"); + + /* Uffd-wp should persist even swapped out */ + value = pagemap_get_entry(pagemap_fd, area_dst); + pagemap_check_wp(value, true); + /* Make sure uffd-wp bit dropped when fork */ + if (pagemap_test_fork(false)) + err("Detected stall uffd-wp bit in child"); + + /* Unprotect; this tests swap pte modifications */ + wp_range(uffd, (uint64_t)area_dst, page_size, false); + value = pagemap_get_entry(pagemap_fd, area_dst); + pagemap_check_wp(value, false); + + /* Fault in the page from disk */ + *area_dst = 2; + value = pagemap_get_entry(pagemap_fd, area_dst); + pagemap_check_wp(value, false); + + close(pagemap_fd); + uffd_test_pass(); +} + uffd_test_case_t uffd_tests[] = { + { + .name = "pagemap", + .uffd_fn = uffd_pagemap_test, + .mem_targets = MEM_ANON, + .uffd_feature_required = UFFD_FEATURE_PAGEFAULT_FLAG_WP, + }, + { + .name = "wp-unpopulated", + .uffd_fn = uffd_wp_unpopulated_test, + .mem_targets = MEM_ANON, + .uffd_feature_required = + UFFD_FEATURE_PAGEFAULT_FLAG_WP | UFFD_FEATURE_WP_UNPOPULATED, + }, }; int main(int argc, char *argv[]) From patchwork Wed Apr 12 16:43:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209361 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 86C48C7619A for ; Wed, 12 Apr 2023 16:44:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2172090000B; Wed, 12 Apr 2023 12:44:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1C708900003; Wed, 12 Apr 2023 12:44:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0676090000B; Wed, 12 Apr 2023 12:44:14 -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 E6ABE900003 for ; Wed, 12 Apr 2023 12:44:13 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 9CC42120165 for ; Wed, 12 Apr 2023 16:44:13 +0000 (UTC) X-FDA: 80673311586.11.D54724A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf17.hostedemail.com (Postfix) with ESMTP id 5E3294000E for ; Wed, 12 Apr 2023 16:44:11 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hiuASNIH; spf=pass (imf17.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681317851; a=rsa-sha256; cv=none; b=w35CEntMbnucmEJrwz2BVMpeOnWp+IQlX/3WsCjaKGP8JovEH4VI6EIg5TT00oPIMkyL9B fG08fHZec+9gs7PRJhYUai96QV+BhHxlQzIRxkReT1r6J1lrhpuyYBT4l58ZQ3D/fha2GP xc7EJVWX+BczYf4ghwKDyGHcqbvbqcs= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hiuASNIH; spf=pass (imf17.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@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=1681317851; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=DGYE1DDdeK4+pcxB+E5dvgvlIGHgCfc4atHqaHYPYpQ=; b=PB6t6J+S7ECS0OxmAzGX/v7j9dEGOfzBfrWaoTBHnob5XLNJVIjZpYMJZM9kwdjOyXzWSE BN0DrShqNe2fD0UV46qt6Q7hc4/iQ1kbgBoHKWIkDYCU3TIkboUobaDx0AVxC6TDCXZUOS WW4WgV6X80U4U2ehWYJ/F8msunUfcDA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317850; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DGYE1DDdeK4+pcxB+E5dvgvlIGHgCfc4atHqaHYPYpQ=; b=hiuASNIHfT9zs295GjkQywf2neMTv83SWeaDH8sV/iIItfE/6mCjRilV3oz/xoDY7DNvvN CL3c4IXaYgfg0lfOX1rlioJi3/U83tyG58MK+R50xZH41tDl7u6WpXFHXyWyxEL1S4NvAN mfOzhj3b+etIwVY2ChS7yD+HtbI8wxk= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-672-o-R8E_0WPTSPC3u5PBe6vA-1; Wed, 12 Apr 2023 12:44:02 -0400 X-MC-Unique: o-R8E_0WPTSPC3u5PBe6vA-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-74a904f38f3so86468485a.1 for ; Wed, 12 Apr 2023 09:44:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317841; x=1683909841; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DGYE1DDdeK4+pcxB+E5dvgvlIGHgCfc4atHqaHYPYpQ=; b=I2xbxyP1pSlP0Z70e48tTJ1598LW9Km+XyzAj304oa6jT+Tu06wF5S1bV3jssQEVoE bHulGckpZjqYINRS3cvD7UkvC6IOmMNxI/ezyYxdYdvxyyrw8lN8PG4dlhO49yF69qo/ w0cDlml98tMDOEONALPplUdgkpHrUj3fJrGxzKoqR1CUoLtilblkzB9OxTSBURspfn+q 4VBFDEYEsELepjaPXScW0dpqhe9GhfzfPDWlthZcNTX4RpVhsvKP0rYNd6NfchdDDeFE 4mlgS0XUE9TXiL6VI507hcnTc1umxDqmSalQxXJoQD9KelZQsGAydsn/Z34RgwEKopCx M6LA== X-Gm-Message-State: AAQBX9fIpJxu8OzndliKEGfFSVWqpWXHll8rEPTv3CdyarOUFEngCHV6 gJhz+CsGGwjBdPYrck+ikzXCP+Vhc1SrNv1Y2jjjzZ92r1dFgAojru/Vx2V2B1GjFeg63I8vFCy qEg5ObiKyIilAvDLHD7U= X-Received: by 2002:a05:6214:528e:b0:5a5:e941:f33d with SMTP id kj14-20020a056214528e00b005a5e941f33dmr4706425qvb.3.1681317840862; Wed, 12 Apr 2023 09:44:00 -0700 (PDT) X-Google-Smtp-Source: AKy350ZjRI108S/AEWKqmkwW7425E04im1RHPeYTESzVUXReVKQDc9FypzgLpo/HuPpxAL+w9pWXmQ== X-Received: by 2002:a05:6214:528e:b0:5a5:e941:f33d with SMTP id kj14-20020a056214528e00b005a5e941f33dmr4706400qvb.3.1681317840523; Wed, 12 Apr 2023 09:44:00 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id o191-20020a3741c8000000b0074abe1e1457sm777268qka.76.2023.04.12.09.43.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:43:59 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: David Hildenbrand , Andrew Morton , Leonardo Bras Soares Passos , peterx@redhat.com, Andrea Arcangeli , Nadav Amit , Mike Rapoport , Axel Rasmussen , Mike Kravetz , Zach O'Keefe Subject: [PATCH v2 24/31] selftests/mm: Move uffd minor test to unit test Date: Wed, 12 Apr 2023 12:43:57 -0400 Message-Id: <20230412164357.328779-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Queue-Id: 5E3294000E X-Rspamd-Server: rspam01 X-Stat-Signature: d6oed1c1pcy8zdhukezkksegmb71zrat X-HE-Tag: 1681317851-708085 X-HE-Meta: U2FsdGVkX18XgagL9R15+AG7pc23uo2z8Ezm8bfa5scv0kt5EB1yXYAiFZ3mezfW4PgyCgZDO+UllX8yEhR54lTJ5RuSPMvrZQhsPYd48MEIR3yuWVISfnj2qaMh6DUdG2wR1pMfAIagO/3DsHud7PydKWp7mxz0WjwGEEH4T4fedKbkNkfdo5WAaAltqZicGnrRQdB8t/6fnlBGlLGolnQN0fIk7VJZUgR6YD5GEL1tuduTfX58fOyFSPh9UfROqDI2aKLZ9XdOZnMEFr5Jc7RVU3vLr5vudPit8ejJj70mp/qeaDW4XynWZYrYvPwH0lVV3CyW8BkC8aSFuDf+bSTvRjZ4yp0RaWEM8GMEvgdYHOVxJb2W2Wy/gE0LEispCy5q5LeEdVLXKGLYzkNlzPX/mtcolrRf7DU7NeLVmIr9V8iSbcEqUctaJeKNuayV5XuxaGJOd4u4/7s7CP/sNvVHY9liHHde452IyN953kLiPgoF/XyTFHO0g3yYs+Xs5yuOp9Lys9glD41DaIc/1KOPDgiOOHju86kngNeiDuNrqaL2vnj5Of3qeifSOVJm5AyUq2p7Nz2EMM92dpAoeYZ4Cln31WiC8AD9NiuaPxIFtFO/Pr8mN19KxKJmsH+jHmbs6otYYGhsuawdusptKN3G9/+vQq04+G3Oe2bui8C6QM646OZG8WWyk+34MwB9uO6Nu0qHqbxN6yumhWga1mPKrVbVbgAYXiOhddjgJvuRnacAII+ZgTVJeOYwvDHaSAl87tqa5hpn5kLLrKKpY1eSDW6MqLAjyj5fpwdVN+GOHKJcQmDu6rZHmoWPmzwPyJbEZ866/vFlaCvof4gRw/8s/vG2rJOdNUJubfhZGEi7jx9D5/dm6cMgp+biKwKWcNOAoO1iY6j4qtdulvjcH3h8t+vFczgdECSXrqWyXpnu+8FAxLKIu8aO9jgI0qZ/LqhL/pJ/XzYO+GdpY25 Kwdiyx1f Rc4dC6TXmOiWtv1aRsKr1Q3UDQuRN5KOtdokWUbEHA8eeW/7zDP9KJjm06iptau9FQ15sLfC9ilv+XHAqyiWi16OoVgk0rQawVwVNpiE2b/nR9K+6DVL6UDvT0rC8ozu8BeL+iOBx4nvyXLmHi2ItgxCOSOFmLHzmY+4i/S8Yn3W+FE/qXijLdHweRnqHgPxNAoDSWUDlHHs3bGG9SC9UnJbqUWctT/BNttPveXE8wg+gASUvcaALM6ysddkIPJvwIvoSJ/xFKmmB/U/6tAOj5RVhqvkZC92heinmuq+jAFX6/329DvhOtMTGeIZKOy17Wr4h+RxZ6tI9O3+fAy1RVPAOd3QLau74Q3lVvs+UQRxAWs6a17ImwwxfZtNfSPQ0FddHEdL76kMXfKfr1aLTQ+DnlVJamtamfaF5G+/7QXwQfdsIf10JmpIwEHNLXUNXmEP63gnzHZWF7MB/B6QZkxrEBUpw3Cu8UJxD/ZZENc/zHE/vU5Ey6p93tA== 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: This moves the minor test to the new unit test. Rewrite the content check with char* opeartions to avoid fiddling with my_bcmp(). Drop global vars test_uffdio_minor and test_collapse, just assume test them always in common code for now. OTOH make this single test into five tests: - minor test on [shmem, hugetlb] with wp=false - minor test on [shmem, hugetlb] with wp=true - minor test + collapse on shmem only One thing to mention that we used to test COLLAPSE+WP but that doesn't sound right at all. It's possible it's silently broken but unnoticed because COLLAPSE is not part of the default test suite. Make the MADV_COLLAPSE test fail-able (by skip it when failing), because it's not guaranteed to success anyway. Drop a bunch of useless code after the move, because the unit test always use aligned num of pages and has nothing to do with n_cpus. Cc: Zach O'Keefe Signed-off-by: Peter Xu --- tools/testing/selftests/mm/uffd-common.c | 25 ++-- tools/testing/selftests/mm/uffd-common.h | 4 +- tools/testing/selftests/mm/uffd-stress.c | 131 +------------------ tools/testing/selftests/mm/uffd-unit-tests.c | 120 +++++++++++++++++ 4 files changed, 135 insertions(+), 145 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-common.c b/tools/testing/selftests/mm/uffd-common.c index bc6c5c38d6dd..12ac84712a38 100644 --- a/tools/testing/selftests/mm/uffd-common.c +++ b/tools/testing/selftests/mm/uffd-common.c @@ -13,8 +13,8 @@ volatile bool test_uffdio_copy_eexist = true; unsigned long nr_cpus, nr_pages, nr_pages_per_cpu, page_size; char *area_src, *area_src_alias, *area_dst, *area_dst_alias, *area_remap; int uffd = -1, uffd_flags, finished, *pipefd, test_type; -bool map_shared, test_collapse, test_dev_userfaultfd; -bool test_uffdio_wp = true, test_uffdio_minor = false; +bool map_shared, test_dev_userfaultfd; +bool test_uffdio_wp = true; unsigned long long *count_verify; uffd_test_ops_t *uffd_test_ops; @@ -128,15 +128,14 @@ static int shmem_allocate_area(void **alloc_area, bool is_src) char *p = NULL, *p_alias = NULL; int mem_fd = uffd_mem_fd_create(bytes * 2, false); - if (test_collapse) { - p = BASE_PMD_ADDR; - if (!is_src) - /* src map + alias + interleaved hpages */ - p += 2 * (bytes + hpage_size); - p_alias = p; - p_alias += bytes; - p_alias += hpage_size; /* Prevent src/dst VMA merge */ - } + /* TODO: clean this up. Use a static addr is ugly */ + p = BASE_PMD_ADDR; + if (!is_src) + /* src map + alias + interleaved hpages */ + p += 2 * (bytes + hpage_size); + p_alias = p; + p_alias += bytes; + p_alias += hpage_size; /* Prevent src/dst VMA merge */ *alloc_area = mmap(p, bytes, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, offset); @@ -144,7 +143,7 @@ static int shmem_allocate_area(void **alloc_area, bool is_src) *alloc_area = NULL; return -errno; } - if (test_collapse && *alloc_area != p) + if (*alloc_area != p) err("mmap of memfd failed at %p", p); area_alias = mmap(p_alias, bytes, PROT_READ | PROT_WRITE, MAP_SHARED, @@ -154,7 +153,7 @@ static int shmem_allocate_area(void **alloc_area, bool is_src) *alloc_area = NULL; return -errno; } - if (test_collapse && area_alias != p_alias) + if (area_alias != p_alias) err("mmap of anonymous memory failed at %p", p_alias); if (is_src) diff --git a/tools/testing/selftests/mm/uffd-common.h b/tools/testing/selftests/mm/uffd-common.h index 9479a0649d7f..4bd5915cf5b4 100644 --- a/tools/testing/selftests/mm/uffd-common.h +++ b/tools/testing/selftests/mm/uffd-common.h @@ -90,8 +90,8 @@ typedef struct uffd_test_ops uffd_test_ops_t; extern unsigned long nr_cpus, nr_pages, nr_pages_per_cpu, page_size; extern char *area_src, *area_src_alias, *area_dst, *area_dst_alias, *area_remap; extern int uffd, uffd_flags, finished, *pipefd, test_type; -extern bool map_shared, test_collapse, test_dev_userfaultfd; -extern bool test_uffdio_wp, test_uffdio_minor; +extern bool map_shared, test_dev_userfaultfd; +extern bool test_uffdio_wp; extern unsigned long long *count_verify; extern volatile bool test_uffdio_copy_eexist; diff --git a/tools/testing/selftests/mm/uffd-stress.c b/tools/testing/selftests/mm/uffd-stress.c index 61d025d87bf2..f9322bbaf825 100644 --- a/tools/testing/selftests/mm/uffd-stress.c +++ b/tools/testing/selftests/mm/uffd-stress.c @@ -52,8 +52,6 @@ pthread_attr_t attr; #define swap(a, b) \ do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0) -#define factor_of_2(x) ((x) ^ ((x) & ((x) - 1))) - const char *examples = "# Run anonymous memory test on 100MiB region with 99999 bounces:\n" "./userfaultfd anon 100 99999\n\n" @@ -79,8 +77,6 @@ static void usage(void) "Supported mods:\n"); fprintf(stderr, "\tsyscall - Use userfaultfd(2) (default)\n"); fprintf(stderr, "\tdev - Use /dev/userfaultfd instead of userfaultfd(2)\n"); - fprintf(stderr, "\tcollapse - Test MADV_COLLAPSE of UFFDIO_REGISTER_MODE_MINOR\n" - "memory\n"); fprintf(stderr, "\nExample test mod usage:\n"); fprintf(stderr, "# Run anonymous memory test with /dev/userfaultfd:\n"); fprintf(stderr, "./userfaultfd anon:dev 100 99999\n\n"); @@ -584,92 +580,6 @@ static int userfaultfd_sig_test(void) return userfaults != 0; } -void check_memory_contents(char *p) -{ - unsigned long i; - uint8_t expected_byte; - void *expected_page; - - if (posix_memalign(&expected_page, page_size, page_size)) - err("out of memory"); - - for (i = 0; i < nr_pages; ++i) { - expected_byte = ~((uint8_t)(i % ((uint8_t)-1))); - memset(expected_page, expected_byte, page_size); - if (my_bcmp(expected_page, p + (i * page_size), page_size)) - err("unexpected page contents after minor fault"); - } - - free(expected_page); -} - -static int userfaultfd_minor_test(void) -{ - unsigned long p; - pthread_t uffd_mon; - char c; - struct uffd_args args = { 0 }; - - if (!test_uffdio_minor) - return 0; - - printf("testing minor faults: "); - fflush(stdout); - - uffd_test_ctx_init(uffd_minor_feature()); - - if (uffd_register(uffd, area_dst_alias, nr_pages * page_size, - false, test_uffdio_wp, true)) - err("register failure"); - - /* - * After registering with UFFD, populate the non-UFFD-registered side of - * the shared mapping. This should *not* trigger any UFFD minor faults. - */ - for (p = 0; p < nr_pages; ++p) { - memset(area_dst + (p * page_size), p % ((uint8_t)-1), - page_size); - } - - args.apply_wp = test_uffdio_wp; - if (pthread_create(&uffd_mon, &attr, uffd_poll_thread, &args)) - err("uffd_poll_thread create"); - - /* - * Read each of the pages back using the UFFD-registered mapping. We - * expect that the first time we touch a page, it will result in a minor - * fault. uffd_poll_thread will resolve the fault by bit-flipping the - * page's contents, and then issuing a CONTINUE ioctl. - */ - check_memory_contents(area_dst_alias); - - if (write(pipefd[1], &c, sizeof(c)) != sizeof(c)) - err("pipe write"); - if (pthread_join(uffd_mon, NULL)) - return 1; - - uffd_stats_report(&args, 1); - - if (test_collapse) { - printf("testing collapse of uffd memory into PMD-mapped THPs:"); - if (madvise(area_dst_alias, nr_pages * page_size, - MADV_COLLAPSE)) - err("madvise(MADV_COLLAPSE)"); - - uffd_test_ops->check_pmd_mapping(area_dst, - nr_pages * page_size / - read_pmd_pagesize()); - /* - * This won't cause uffd-fault - it purely just makes sure there - * was no corruption. - */ - check_memory_contents(area_dst_alias); - printf(" done.\n"); - } - - return args.missing_faults != 0 || args.minor_faults != nr_pages; -} - static int userfaultfd_stress(void) { void *area; @@ -782,7 +692,7 @@ static int userfaultfd_stress(void) } return userfaultfd_zeropage_test() || userfaultfd_sig_test() - || userfaultfd_events_test() || userfaultfd_minor_test(); + || userfaultfd_events_test(); } static void set_test_type(const char *type) @@ -797,13 +707,10 @@ static void set_test_type(const char *type) map_shared = true; test_type = TEST_HUGETLB; uffd_test_ops = &hugetlb_uffd_test_ops; - /* Minor faults require shared hugetlb; only enable here. */ - test_uffdio_minor = true; } else if (!strcmp(type, "shmem")) { map_shared = true; test_type = TEST_SHMEM; uffd_test_ops = &shmem_uffd_test_ops; - test_uffdio_minor = true; } } @@ -821,8 +728,6 @@ static void parse_test_type_arg(const char *raw_type) test_dev_userfaultfd = true; else if (!strcmp(token, "syscall")) test_dev_userfaultfd = false; - else if (!strcmp(token, "collapse")) - test_collapse = true; else err("unrecognized test mod '%s'", token); } @@ -830,9 +735,6 @@ static void parse_test_type_arg(const char *raw_type) if (!test_type) err("failed to parse test type argument: '%s'", raw_type); - if (test_collapse && test_type != TEST_SHMEM) - err("Unsupported test: %s", raw_type); - if (test_type == TEST_HUGETLB) page_size = default_huge_page_size(); else @@ -854,8 +756,6 @@ static void parse_test_type_arg(const char *raw_type) test_uffdio_wp = test_uffdio_wp && (features & UFFD_FEATURE_PAGEFAULT_FLAG_WP); - test_uffdio_minor = test_uffdio_minor && - (features & uffd_minor_feature()); close(uffd); uffd = -1; @@ -872,7 +772,6 @@ static void sigalrm(int sig) int main(int argc, char **argv) { size_t bytes; - size_t hpage_size = read_pmd_pagesize(); if (argc < 4) usage(); @@ -884,36 +783,8 @@ int main(int argc, char **argv) parse_test_type_arg(argv[1]); bytes = atol(argv[2]) * 1024 * 1024; - if (test_collapse && bytes & (hpage_size - 1)) - err("MiB must be multiple of %lu if :collapse mod set", - hpage_size >> 20); - nr_cpus = sysconf(_SC_NPROCESSORS_ONLN); - if (test_collapse) { - /* nr_cpus must divide (bytes / page_size), otherwise, - * area allocations of (nr_pages * paze_size) won't be a - * multiple of hpage_size, even if bytes is a multiple of - * hpage_size. - * - * This means that nr_cpus must divide (N * (2 << (H-P)) - * where: - * bytes = hpage_size * N - * hpage_size = 2 << H - * page_size = 2 << P - * - * And we want to chose nr_cpus to be the largest value - * satisfying this constraint, not larger than the number - * of online CPUs. Unfortunately, prime factorization of - * N and nr_cpus may be arbitrary, so have to search for it. - * Instead, just use the highest power of 2 dividing both - * nr_cpus and (bytes / page_size). - */ - int x = factor_of_2(nr_cpus); - int y = factor_of_2(bytes / page_size); - - nr_cpus = x < y ? x : y; - } nr_pages_per_cpu = bytes / page_size / nr_cpus; if (!nr_pages_per_cpu) { _err("invalid MiB"); diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/selftests/mm/uffd-unit-tests.c index 4690c95a9420..cba04608bdb0 100644 --- a/tools/testing/selftests/mm/uffd-unit-tests.c +++ b/tools/testing/selftests/mm/uffd-unit-tests.c @@ -329,6 +329,103 @@ static void uffd_pagemap_test(void) uffd_test_pass(); } +static void check_memory_contents(char *p) +{ + unsigned long i, j; + uint8_t expected_byte; + + for (i = 0; i < nr_pages; ++i) { + expected_byte = ~((uint8_t)(i % ((uint8_t)-1))); + for (j = 0; j < page_size; j++) { + uint8_t v = *(uint8_t *)(p + (i * page_size) + j); + if (v != expected_byte) + err("unexpected page contents"); + } + } +} + +static void uffd_minor_test_common(bool test_collapse, bool test_wp) +{ + unsigned long p; + pthread_t uffd_mon; + char c; + struct uffd_args args = { 0 }; + + /* + * NOTE: MADV_COLLAPSE is not yet compatible with WP, so testing + * both do not make much sense. + */ + assert(!(test_collapse && test_wp)); + + if (uffd_register(uffd, area_dst_alias, nr_pages * page_size, + /* NOTE! MADV_COLLAPSE may not work with uffd-wp */ + false, test_wp, true)) + err("register failure"); + + /* + * After registering with UFFD, populate the non-UFFD-registered side of + * the shared mapping. This should *not* trigger any UFFD minor faults. + */ + for (p = 0; p < nr_pages; ++p) + memset(area_dst + (p * page_size), p % ((uint8_t)-1), + page_size); + + args.apply_wp = test_wp; + if (pthread_create(&uffd_mon, NULL, uffd_poll_thread, &args)) + err("uffd_poll_thread create"); + + /* + * Read each of the pages back using the UFFD-registered mapping. We + * expect that the first time we touch a page, it will result in a minor + * fault. uffd_poll_thread will resolve the fault by bit-flipping the + * page's contents, and then issuing a CONTINUE ioctl. + */ + check_memory_contents(area_dst_alias); + + if (write(pipefd[1], &c, sizeof(c)) != sizeof(c)) + err("pipe write"); + if (pthread_join(uffd_mon, NULL)) + err("join() failed"); + + if (test_collapse) { + if (madvise(area_dst_alias, nr_pages * page_size, + MADV_COLLAPSE)) { + /* It's fine to fail for this one... */ + uffd_test_skip("MADV_COLLAPSE failed"); + return; + } + + uffd_test_ops->check_pmd_mapping(area_dst, + nr_pages * page_size / + read_pmd_pagesize()); + /* + * This won't cause uffd-fault - it purely just makes sure there + * was no corruption. + */ + check_memory_contents(area_dst_alias); + } + + if (args.missing_faults != 0 || args.minor_faults != nr_pages) + uffd_test_fail("stats check error"); + else + uffd_test_pass(); +} + +void uffd_minor_test(void) +{ + uffd_minor_test_common(false, false); +} + +void uffd_minor_wp_test(void) +{ + uffd_minor_test_common(false, true); +} + +void uffd_minor_collapse_test(void) +{ + uffd_minor_test_common(true, false); +} + uffd_test_case_t uffd_tests[] = { { .name = "pagemap", @@ -343,6 +440,29 @@ uffd_test_case_t uffd_tests[] = { .uffd_feature_required = UFFD_FEATURE_PAGEFAULT_FLAG_WP | UFFD_FEATURE_WP_UNPOPULATED, }, + { + .name = "minor", + .uffd_fn = uffd_minor_test, + .mem_targets = MEM_SHMEM | MEM_HUGETLB, + .uffd_feature_required = + UFFD_FEATURE_MINOR_HUGETLBFS | UFFD_FEATURE_MINOR_SHMEM, + }, + { + .name = "minor-wp", + .uffd_fn = uffd_minor_wp_test, + .mem_targets = MEM_SHMEM | MEM_HUGETLB, + .uffd_feature_required = + UFFD_FEATURE_MINOR_HUGETLBFS | UFFD_FEATURE_MINOR_SHMEM | + UFFD_FEATURE_PAGEFAULT_FLAG_WP, + }, + { + .name = "minor-collapse", + .uffd_fn = uffd_minor_collapse_test, + /* MADV_COLLAPSE only works with shmem */ + .mem_targets = MEM_SHMEM, + /* We can't test MADV_COLLAPSE, so try our luck */ + .uffd_feature_required = UFFD_FEATURE_MINOR_SHMEM, + }, }; int main(int argc, char *argv[]) From patchwork Wed Apr 12 16:44:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209360 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 6FA18C77B6E for ; Wed, 12 Apr 2023 16:44:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1059E90000A; Wed, 12 Apr 2023 12:44:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0B662900003; Wed, 12 Apr 2023 12:44:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EBF9D90000A; Wed, 12 Apr 2023 12:44:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id DAF9F900003 for ; Wed, 12 Apr 2023 12:44:11 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id AB627C01AF for ; Wed, 12 Apr 2023 16:44:11 +0000 (UTC) X-FDA: 80673311502.30.999EC80 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf05.hostedemail.com (Postfix) with ESMTP id 6745F10000A for ; Wed, 12 Apr 2023 16:44:09 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=XjfspCJS; spf=pass (imf05.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@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=1681317849; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=moJlUxkxV9yMXHXtrl4RDvvI70k6nNWMdoirhLeOGGU=; b=7Kb3y6s2wIF9qRGIIpcXMUO3Pr5+XjmsK45jY+pQR5JWOh0iRSOJKIT7BjaT/lDX1iCfGt 04EgP7XdA+k1COCk+L4USLK6Z8RUF5dH6D7x1spa2zpsWyB6Myc6OOisf1VLwEtp1mkV8v Bedv0DNRWMdwPDYFKNKaCyT5FsRDI+g= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=XjfspCJS; spf=pass (imf05.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681317849; a=rsa-sha256; cv=none; b=kZOpHnR+8wirBspxfDhcDCCPCtjCC9LYSHo7hQyCX+DnU4LejQvNuVleafBLcEvFM6tUyG wCThqB7BtORD0zRzMXTV6QuJ2UO5JKveeK3XMq7JhhHndKzQ/p6WrFmLmZzr10mxgZaFF0 8pSX4fD7ab48W2JpOKlgxZy/Jib9CSU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317848; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=moJlUxkxV9yMXHXtrl4RDvvI70k6nNWMdoirhLeOGGU=; b=XjfspCJSbEveToo8/3D0S+GHMY+6Hf1e1kyw+YarT/K6L8VFv9wg4kc2ww2LpkkfeJaPNK N/rnuKcMxZBta+VCD8lkc7/rRKt96PksSQyfwizq5HJunpshxJA2bRVDI2eaSaOPWQXMcz WBbmPTvAmU3qdhweuPGmrix1fkh8WZs= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-422-y9yr1hIvNFWg8YPRk5BBmw-1; Wed, 12 Apr 2023 12:44:07 -0400 X-MC-Unique: y9yr1hIvNFWg8YPRk5BBmw-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-3e8d943d3a4so667771cf.1 for ; Wed, 12 Apr 2023 09:44:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317845; x=1683909845; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=moJlUxkxV9yMXHXtrl4RDvvI70k6nNWMdoirhLeOGGU=; b=JfpKpYSI4NE3FK9XSURLePrVT5c8sm/EtiCZ+0MXwbDZPz/K4Q9KaIJdLp1KlwzLGi fwFNpNxOZ+TSIqo4Y3gt0rfzuMHTnk9HkuVBL2UV7fQKaXZfHGrrcNPKOoPc0rfYEJHi rcY080ZnQ+R/ZKn+p7pI/vciB8ps7s3d21PFfzflYWDB9wCE+b1DwlyBL6bMBoMOoTbr V0NLbT4KZMJpNAfW52CHWiI5nX88XuyNC+yISOvRZ+VVO4/OVfSvvTrUBP7kH5y9l4KJ pn0DdgYmhapudEqJZWo5eCVdQGviRrmyDV9x4dCwj8r1oYc0G1zLYE87QEJhAeloHB2B kUMA== X-Gm-Message-State: AAQBX9fEDXruW73PD2pB5r7uDBz0hBR5wpF53MMxCeGIIiQtuGfIH91p EYs/mhMHA3ljAob17LZoIKCDbEhP+lkZtYlcXaxvsoY5vYC3R4FbJsic2VgeeRJurKTCuYWFiKV cA9TM0OSTgBY= X-Received: by 2002:a05:622a:14cf:b0:3b8:6c6e:4949 with SMTP id u15-20020a05622a14cf00b003b86c6e4949mr4198048qtx.4.1681317844851; Wed, 12 Apr 2023 09:44:04 -0700 (PDT) X-Google-Smtp-Source: AKy350ZyI0LO2mW+nKpthrbnN+kJ/X5tJn7Dl5m81czcPWaU9AQPMWeY1C8uomlpugD00uwX305oNw== X-Received: by 2002:a05:622a:14cf:b0:3b8:6c6e:4949 with SMTP id u15-20020a05622a14cf00b003b86c6e4949mr4198015qtx.4.1681317844406; Wed, 12 Apr 2023 09:44:04 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id do28-20020a05620a2b1c00b007484bc04a63sm4782932qkb.99.2023.04.12.09.44.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:44:03 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: David Hildenbrand , Andrew Morton , Leonardo Bras Soares Passos , peterx@redhat.com, Andrea Arcangeli , Nadav Amit , Mike Rapoport , Axel Rasmussen , Mike Kravetz Subject: [PATCH v2 25/31] selftests/mm: Move uffd sig/events tests into uffd unit tests Date: Wed, 12 Apr 2023 12:44:00 -0400 Message-Id: <20230412164400.328798-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Stat-Signature: 3dkuwuc8jqpzste93t63jcae7katpeto X-Rspam-User: X-Rspamd-Queue-Id: 6745F10000A X-Rspamd-Server: rspam06 X-HE-Tag: 1681317849-326875 X-HE-Meta: U2FsdGVkX1/W3cbK/GIzhMce3o4ePaDQzFyZXZKnuYbzs2z62AFBWB9f7e6fwaRVV7mgJ/Fr3gsLfJdbPS3FR1eiq0pas9YO/BuHpK2tfAFUPwrlGm+cKIUn84uw+tfyLUh5hwXNdl6L7qYUWDjpw6Her86bcpasCrRrIxc6dZ/fmrj4YAY0rAPrdvvYHcEPytFaShAe5+sWaTctDrHtVRYd9cmNJcciBngUZWTasqoxHJuchCMgGV7UaDuEb7IiwzphBwWw1W24Flq6ZsS47F8CZTOXos8sPayApyrnoX/MRu9+BOAaA9eEhSAFXmGqnJyGM4fDJ5fbQno+IkgsPm+ruutvS0jFE5thjbwqFn5hkqmsFAu0dI7TsVf1Wzfr4n5GOm2YlpcK/+7A4OmJH05q8FJTiXiRGAAaMfisqNkUxGsFdUEKGojs0HaE5MWyZ4EBG8s7UOM3KupWPE+6IP5CYr/ceqAJV5dqxYp5vIEvX3PsmdE0KgH7s5ZPjrW3ianJNScYOeE/LEHKfPrq8Prdr1gsneyUo5otp6riTw54C4k0m5ea+Pq2FJUx7+J9mBbzrx98VOrjiiPMTqr9WY09jh23ogFukOdKBe7cmcXZy6Kab+m5/EbfrGAkRxOxKiTIGXFPdJ63AZKEfFu5LoVGMvK3OWGixV2ZSV1fs+glgSegJejwgLnJ434zPnVj0wz2nGkcHy2nJLGKHVG8mfnijZ4tiwMM53aZHIrdRKxFNWKRgB7QisV2iJ+dy+aBoCdNhYt7ayENgL+/2ZVuuOca3rMJa9nnWyeKinEao6KwuKdczAe8lcoeF+4l73b6cM7dFa0EHW85gjw5Qr+ijkJ8fWfY8Y6Gjh1mWWyspC60N9vWtAoyl4kNaVLz2rRQAHlc1hIsuEZMfK5i1eM1hhtEWIO8llgBmKqkRUYUe9HoWtgBq0Jideo8eylIwIp+wyaxG000hatWR553urE Wrl+UKZx OTBBqc+0sV61nrbttM7YbmlcNCgrI87l04rwjl9VbUNzJaSdfmI3vJ4IF48zcOzousyKIjhHXqY2yh/PgMTl6r2+2IE5QGPQrrRVe/BIxKb1rLQyLIpZzeTIy9IVrJtvxWCJtMEn4QULsq7Hid7QjDWLhxke9M5OzLbQUB8hcT+304rg/rXfsEnIC/wFWX/n1Wdyt9gg1XqTd6QS6WZXVZ4Dyj33t39k5Aa5Qjv93iRl6f/0vsjPHGUPrZ2PT7IzBHG6/R41dZ41UotYhEq2sL+SvFhw5nWVs7fLdpUXdGkqBrfuJmPO8w/f7yQa91SikN5QApUQtM1+qeNhnKMfBI05RdCmNeRFg1kXPNEHjKtiuguCboDwj6GKgxzUQyXZV+R9q1iIDnTVQkdimLg/D8e34vnWy3X7v5WtVoGfPpNguh68FQqbQTttAtiLFT8GBtSZOv2lkFf4ZGX3UOmeE3q4gUNLLFegUruj3 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: Move the two tests into the unit test, and convert it into 20 standalone tests: - events test on all 5 mem types, with wp on/off - signal test on all 5 mem types, with wp on/off Testing sigbus on anon... done Testing sigbus on shmem... done Testing sigbus on shmem-private... done Testing sigbus on hugetlb... done Testing sigbus on hugetlb-private... done Testing sigbus-wp on anon... done Testing sigbus-wp on shmem... done Testing sigbus-wp on shmem-private... done Testing sigbus-wp on hugetlb... done Testing sigbus-wp on hugetlb-private... done Testing events on anon... done Testing events on shmem... done Testing events on shmem-private... done Testing events on hugetlb... done Testing events on hugetlb-private... done Testing events-wp on anon... done Testing events-wp on shmem... done Testing events-wp on shmem-private... done Testing events-wp on hugetlb... done Testing events-wp on hugetlb-private... done It'll also remove a lot of global references along the way, e.g. test_uffdio_wp will be replaced with the wp value passed over. Signed-off-by: Peter Xu --- tools/testing/selftests/mm/uffd-stress.c | 227 +--------------- tools/testing/selftests/mm/uffd-unit-tests.c | 264 +++++++++++++++++++ 2 files changed, 265 insertions(+), 226 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-stress.c b/tools/testing/selftests/mm/uffd-stress.c index f9322bbaf825..ce51180238d8 100644 --- a/tools/testing/selftests/mm/uffd-stress.c +++ b/tools/testing/selftests/mm/uffd-stress.c @@ -273,133 +273,6 @@ static int stress(struct uffd_args *args) return 0; } -sigjmp_buf jbuf, *sigbuf; - -static void sighndl(int sig, siginfo_t *siginfo, void *ptr) -{ - if (sig == SIGBUS) { - if (sigbuf) - siglongjmp(*sigbuf, 1); - abort(); - } -} - -/* - * For non-cooperative userfaultfd test we fork() a process that will - * generate pagefaults, will mremap the area monitored by the - * userfaultfd and at last this process will release the monitored - * area. - * For the anonymous and shared memory the area is divided into two - * parts, the first part is accessed before mremap, and the second - * part is accessed after mremap. Since hugetlbfs does not support - * mremap, the entire monitored area is accessed in a single pass for - * HUGETLB_TEST. - * The release of the pages currently generates event for shmem and - * anonymous memory (UFFD_EVENT_REMOVE), hence it is not checked - * for hugetlb. - * For signal test(UFFD_FEATURE_SIGBUS), signal_test = 1, we register - * monitored area, generate pagefaults and test that signal is delivered. - * Use UFFDIO_COPY to allocate missing page and retry. For signal_test = 2 - * test robustness use case - we release monitored area, fork a process - * that will generate pagefaults and verify signal is generated. - * This also tests UFFD_FEATURE_EVENT_FORK event along with the signal - * feature. Using monitor thread, verify no userfault events are generated. - */ -static int faulting_process(int signal_test, bool wp) -{ - unsigned long nr; - unsigned long long count; - unsigned long split_nr_pages; - unsigned long lastnr; - struct sigaction act; - volatile unsigned long signalled = 0; - - split_nr_pages = (nr_pages + 1) / 2; - - if (signal_test) { - sigbuf = &jbuf; - memset(&act, 0, sizeof(act)); - act.sa_sigaction = sighndl; - act.sa_flags = SA_SIGINFO; - if (sigaction(SIGBUS, &act, 0)) - err("sigaction"); - lastnr = (unsigned long)-1; - } - - for (nr = 0; nr < split_nr_pages; nr++) { - volatile int steps = 1; - unsigned long offset = nr * page_size; - - if (signal_test) { - if (sigsetjmp(*sigbuf, 1) != 0) { - if (steps == 1 && nr == lastnr) - err("Signal repeated"); - - lastnr = nr; - if (signal_test == 1) { - if (steps == 1) { - /* This is a MISSING request */ - steps++; - if (copy_page(uffd, offset, wp)) - signalled++; - } else { - /* This is a WP request */ - assert(steps == 2); - wp_range(uffd, - (__u64)area_dst + - offset, - page_size, false); - } - } else { - signalled++; - continue; - } - } - } - - count = *area_count(area_dst, nr); - if (count != count_verify[nr]) - err("nr %lu memory corruption %llu %llu\n", - nr, count, count_verify[nr]); - /* - * Trigger write protection if there is by writing - * the same value back. - */ - *area_count(area_dst, nr) = count; - } - - if (signal_test) - return signalled != split_nr_pages; - - area_dst = mremap(area_dst, nr_pages * page_size, nr_pages * page_size, - MREMAP_MAYMOVE | MREMAP_FIXED, area_src); - if (area_dst == MAP_FAILED) - err("mremap"); - /* Reset area_src since we just clobbered it */ - area_src = NULL; - - for (; nr < nr_pages; nr++) { - count = *area_count(area_dst, nr); - if (count != count_verify[nr]) { - err("nr %lu memory corruption %llu %llu\n", - nr, count, count_verify[nr]); - } - /* - * Trigger write protection if there is by writing - * the same value back. - */ - *area_count(area_dst, nr) = count; - } - - uffd_test_ops->release_pages(area_dst); - - for (nr = 0; nr < nr_pages; nr++) - if (my_bcmp(area_dst + nr * page_size, zeropage, page_size)) - err("nr %lu is not zero", nr); - - return 0; -} - static void retry_uffdio_zeropage(int ufd, struct uffdio_zeropage *uffdio_zeropage, unsigned long offset) @@ -483,103 +356,6 @@ static int userfaultfd_zeropage_test(void) return 0; } -static int userfaultfd_events_test(void) -{ - pthread_t uffd_mon; - int err, features; - pid_t pid; - char c; - struct uffd_args args = { 0 }; - - printf("testing events (fork, remap, remove): "); - fflush(stdout); - - features = UFFD_FEATURE_EVENT_FORK | UFFD_FEATURE_EVENT_REMAP | - UFFD_FEATURE_EVENT_REMOVE; - uffd_test_ctx_init(features); - - fcntl(uffd, F_SETFL, uffd_flags | O_NONBLOCK); - - if (uffd_register(uffd, area_dst, nr_pages * page_size, - true, test_uffdio_wp, false)) - err("register failure"); - - args.apply_wp = test_uffdio_wp; - if (pthread_create(&uffd_mon, &attr, uffd_poll_thread, &args)) - err("uffd_poll_thread create"); - - pid = fork(); - if (pid < 0) - err("fork"); - - if (!pid) - exit(faulting_process(0, test_uffdio_wp)); - - waitpid(pid, &err, 0); - if (err) - err("faulting process failed"); - if (write(pipefd[1], &c, sizeof(c)) != sizeof(c)) - err("pipe write"); - if (pthread_join(uffd_mon, NULL)) - return 1; - - uffd_stats_report(&args, 1); - - return args.missing_faults != nr_pages; -} - -static int userfaultfd_sig_test(void) -{ - unsigned long userfaults; - pthread_t uffd_mon; - int err, features; - pid_t pid; - char c; - struct uffd_args args = { 0 }; - - printf("testing signal delivery: "); - fflush(stdout); - - features = UFFD_FEATURE_EVENT_FORK|UFFD_FEATURE_SIGBUS; - uffd_test_ctx_init(features); - - fcntl(uffd, F_SETFL, uffd_flags | O_NONBLOCK); - - if (uffd_register(uffd, area_dst, nr_pages * page_size, - true, test_uffdio_wp, false)) - err("register failure"); - - if (faulting_process(1, test_uffdio_wp)) - err("faulting process failed"); - - uffd_test_ops->release_pages(area_dst); - - args.apply_wp = test_uffdio_wp; - if (pthread_create(&uffd_mon, &attr, uffd_poll_thread, &args)) - err("uffd_poll_thread create"); - - pid = fork(); - if (pid < 0) - err("fork"); - - if (!pid) - exit(faulting_process(2, test_uffdio_wp)); - - waitpid(pid, &err, 0); - if (err) - err("faulting process failed"); - if (write(pipefd[1], &c, sizeof(c)) != sizeof(c)) - err("pipe write"); - if (pthread_join(uffd_mon, (void **)&userfaults)) - return 1; - - printf("done.\n"); - if (userfaults) - err("Signal test failed, userfaults: %ld", userfaults); - - return userfaults != 0; -} - static int userfaultfd_stress(void) { void *area; @@ -691,8 +467,7 @@ static int userfaultfd_stress(void) uffd_stats_report(args, nr_cpus); } - return userfaultfd_zeropage_test() || userfaultfd_sig_test() - || userfaultfd_events_test(); + return userfaultfd_zeropage_test(); } static void set_test_type(const char *type) diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/selftests/mm/uffd-unit-tests.c index cba04608bdb0..94549696f4b2 100644 --- a/tools/testing/selftests/mm/uffd-unit-tests.c +++ b/tools/testing/selftests/mm/uffd-unit-tests.c @@ -18,6 +18,9 @@ #define MEM_HUGETLB BIT_ULL(3) #define MEM_HUGETLB_PRIVATE BIT_ULL(4) +#define MEM_ALL (MEM_ANON | MEM_SHMEM | MEM_SHMEM_PRIVATE | \ + MEM_HUGETLB | MEM_HUGETLB_PRIVATE) + struct mem_type { const char *name; unsigned int mem_flag; @@ -426,6 +429,237 @@ void uffd_minor_collapse_test(void) uffd_minor_test_common(true, false); } +static sigjmp_buf jbuf, *sigbuf; + +static void sighndl(int sig, siginfo_t *siginfo, void *ptr) +{ + if (sig == SIGBUS) { + if (sigbuf) + siglongjmp(*sigbuf, 1); + abort(); + } +} + +/* + * For non-cooperative userfaultfd test we fork() a process that will + * generate pagefaults, will mremap the area monitored by the + * userfaultfd and at last this process will release the monitored + * area. + * For the anonymous and shared memory the area is divided into two + * parts, the first part is accessed before mremap, and the second + * part is accessed after mremap. Since hugetlbfs does not support + * mremap, the entire monitored area is accessed in a single pass for + * HUGETLB_TEST. + * The release of the pages currently generates event for shmem and + * anonymous memory (UFFD_EVENT_REMOVE), hence it is not checked + * for hugetlb. + * For signal test(UFFD_FEATURE_SIGBUS), signal_test = 1, we register + * monitored area, generate pagefaults and test that signal is delivered. + * Use UFFDIO_COPY to allocate missing page and retry. For signal_test = 2 + * test robustness use case - we release monitored area, fork a process + * that will generate pagefaults and verify signal is generated. + * This also tests UFFD_FEATURE_EVENT_FORK event along with the signal + * feature. Using monitor thread, verify no userfault events are generated. + */ +static int faulting_process(int signal_test, bool wp) +{ + unsigned long nr, i; + unsigned long long count; + unsigned long split_nr_pages; + unsigned long lastnr; + struct sigaction act; + volatile unsigned long signalled = 0; + + split_nr_pages = (nr_pages + 1) / 2; + + if (signal_test) { + sigbuf = &jbuf; + memset(&act, 0, sizeof(act)); + act.sa_sigaction = sighndl; + act.sa_flags = SA_SIGINFO; + if (sigaction(SIGBUS, &act, 0)) + err("sigaction"); + lastnr = (unsigned long)-1; + } + + for (nr = 0; nr < split_nr_pages; nr++) { + volatile int steps = 1; + unsigned long offset = nr * page_size; + + if (signal_test) { + if (sigsetjmp(*sigbuf, 1) != 0) { + if (steps == 1 && nr == lastnr) + err("Signal repeated"); + + lastnr = nr; + if (signal_test == 1) { + if (steps == 1) { + /* This is a MISSING request */ + steps++; + if (copy_page(uffd, offset, wp)) + signalled++; + } else { + /* This is a WP request */ + assert(steps == 2); + wp_range(uffd, + (__u64)area_dst + + offset, + page_size, false); + } + } else { + signalled++; + continue; + } + } + } + + count = *area_count(area_dst, nr); + if (count != count_verify[nr]) + err("nr %lu memory corruption %llu %llu\n", + nr, count, count_verify[nr]); + /* + * Trigger write protection if there is by writing + * the same value back. + */ + *area_count(area_dst, nr) = count; + } + + if (signal_test) + return signalled != split_nr_pages; + + area_dst = mremap(area_dst, nr_pages * page_size, nr_pages * page_size, + MREMAP_MAYMOVE | MREMAP_FIXED, area_src); + if (area_dst == MAP_FAILED) + err("mremap"); + /* Reset area_src since we just clobbered it */ + area_src = NULL; + + for (; nr < nr_pages; nr++) { + count = *area_count(area_dst, nr); + if (count != count_verify[nr]) { + err("nr %lu memory corruption %llu %llu\n", + nr, count, count_verify[nr]); + } + /* + * Trigger write protection if there is by writing + * the same value back. + */ + *area_count(area_dst, nr) = count; + } + + uffd_test_ops->release_pages(area_dst); + + for (nr = 0; nr < nr_pages; nr++) + for (i = 0; i < page_size; i++) + if (*(area_dst + nr * page_size + i) != 0) + err("page %lu offset %lu is not zero", nr, i); + + return 0; +} + +static void uffd_sigbus_test_common(bool wp) +{ + unsigned long userfaults; + pthread_t uffd_mon; + pid_t pid; + int err; + char c; + struct uffd_args args = { 0 }; + + fcntl(uffd, F_SETFL, uffd_flags | O_NONBLOCK); + + if (uffd_register(uffd, area_dst, nr_pages * page_size, + true, wp, false)) + err("register failure"); + + if (faulting_process(1, wp)) + err("faulting process failed"); + + uffd_test_ops->release_pages(area_dst); + + args.apply_wp = wp; + if (pthread_create(&uffd_mon, NULL, uffd_poll_thread, &args)) + err("uffd_poll_thread create"); + + pid = fork(); + if (pid < 0) + err("fork"); + + if (!pid) + exit(faulting_process(2, wp)); + + waitpid(pid, &err, 0); + if (err) + err("faulting process failed"); + if (write(pipefd[1], &c, sizeof(c)) != sizeof(c)) + err("pipe write"); + if (pthread_join(uffd_mon, (void **)&userfaults)) + err("pthread_join()"); + + if (userfaults) + uffd_test_fail("Signal test failed, userfaults: %ld", userfaults); + else + uffd_test_pass(); +} + +static void uffd_sigbus_test(void) +{ + uffd_sigbus_test_common(false); +} + +static void uffd_sigbus_wp_test(void) +{ + uffd_sigbus_test_common(true); +} + +static void uffd_events_test_common(bool wp) +{ + pthread_t uffd_mon; + pid_t pid; + int err; + char c; + struct uffd_args args = { 0 }; + + fcntl(uffd, F_SETFL, uffd_flags | O_NONBLOCK); + if (uffd_register(uffd, area_dst, nr_pages * page_size, + true, wp, false)) + err("register failure"); + + args.apply_wp = wp; + if (pthread_create(&uffd_mon, NULL, uffd_poll_thread, &args)) + err("uffd_poll_thread create"); + + pid = fork(); + if (pid < 0) + err("fork"); + + if (!pid) + exit(faulting_process(0, wp)); + + waitpid(pid, &err, 0); + if (err) + err("faulting process failed"); + if (write(pipefd[1], &c, sizeof(c)) != sizeof(c)) + err("pipe write"); + if (pthread_join(uffd_mon, NULL)) + err("pthread_join()"); + + if (args.missing_faults != nr_pages) + uffd_test_fail("Fault counts wrong"); + else + uffd_test_pass(); +} + +static void uffd_events_test(void) +{ + uffd_events_test_common(false); +} + +static void uffd_events_wp_test(void) +{ + uffd_events_test_common(true); +} + uffd_test_case_t uffd_tests[] = { { .name = "pagemap", @@ -463,6 +697,36 @@ uffd_test_case_t uffd_tests[] = { /* We can't test MADV_COLLAPSE, so try our luck */ .uffd_feature_required = UFFD_FEATURE_MINOR_SHMEM, }, + { + .name = "sigbus", + .uffd_fn = uffd_sigbus_test, + .mem_targets = MEM_ALL, + .uffd_feature_required = UFFD_FEATURE_SIGBUS | + UFFD_FEATURE_EVENT_FORK, + }, + { + .name = "sigbus-wp", + .uffd_fn = uffd_sigbus_wp_test, + .mem_targets = MEM_ALL, + .uffd_feature_required = UFFD_FEATURE_SIGBUS | + UFFD_FEATURE_EVENT_FORK | UFFD_FEATURE_PAGEFAULT_FLAG_WP, + }, + { + .name = "events", + .uffd_fn = uffd_events_test, + .mem_targets = MEM_ALL, + .uffd_feature_required = UFFD_FEATURE_EVENT_FORK | + UFFD_FEATURE_EVENT_REMAP | UFFD_FEATURE_EVENT_REMOVE, + }, + { + .name = "events-wp", + .uffd_fn = uffd_events_wp_test, + .mem_targets = MEM_ALL, + .uffd_feature_required = UFFD_FEATURE_EVENT_FORK | + UFFD_FEATURE_EVENT_REMAP | UFFD_FEATURE_EVENT_REMOVE | + UFFD_FEATURE_PAGEFAULT_FLAG_WP | + UFFD_FEATURE_WP_HUGETLBFS_SHMEM, + }, }; int main(int argc, char *argv[]) From patchwork Wed Apr 12 16:44:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209362 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 7F685C7619A for ; Wed, 12 Apr 2023 16:44:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1C92190000C; Wed, 12 Apr 2023 12:44:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 17A8E900003; Wed, 12 Apr 2023 12:44:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 019EF90000C; Wed, 12 Apr 2023 12:44:18 -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 E70FC900003 for ; Wed, 12 Apr 2023 12:44:18 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id C241A1A01B2 for ; Wed, 12 Apr 2023 16:44:18 +0000 (UTC) X-FDA: 80673311796.11.D814946 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf10.hostedemail.com (Postfix) with ESMTP id AB9FBC001F for ; Wed, 12 Apr 2023 16:44:16 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=M2TQoZGh; spf=pass (imf10.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@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=1681317856; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=tbgfGOfUxiSSCaOkyoncCcfniesjTCna7R8zm3hOkOs=; b=DQKUmFB6UjuUp7JmPLMyZO1vXBbZh2VR5nBJohikMRWPaKO/mkSI1lQtnFoITZPcqxGBHn w62mXPilKkg5OmcvciQKEqe7JdjDjGNt6qRQPqDhuBr3EQm5sxQueI/GEWg2qfigD9sPQT fk0erh4AVSQ1nUjSO/nux1aeLbRU1zM= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=M2TQoZGh; spf=pass (imf10.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681317856; a=rsa-sha256; cv=none; b=dEEK0+56aSU/F0xmigTxdso9KH06Igqk9uPodGuolUSWgTJljrvDvCsUxQWIfvqXxaEveF GirpUBKWsVqOeC6UAqSAOap7ssqiVU31duxZvsLvFkXzsqZV+6OenMVVhH9aghxB7fiwI2 nTC3ztzESrF6eGFNGHEQcZpg1WPw2Pw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317855; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tbgfGOfUxiSSCaOkyoncCcfniesjTCna7R8zm3hOkOs=; b=M2TQoZGhSAoR3MYaHIuFSFyti8YGvBhj8gEZFYvR7VegPPnTioYA3P2Edyu4vTlxK5HPKd QSh3I9mg2sOyWpnPDgcKiq5GZ1AYN56foMekzCjI2waDzgTbb2UE9AHH3iXS1onJZK9EOv EyWdkCigabP9HrKoD6R68jCC+HWS/WU= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-398-Dc3UNBZZMO2PhJp2vacRvA-1; Wed, 12 Apr 2023 12:44:13 -0400 X-MC-Unique: Dc3UNBZZMO2PhJp2vacRvA-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-74accc750c1so3424685a.0 for ; Wed, 12 Apr 2023 09:44:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317850; x=1683909850; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tbgfGOfUxiSSCaOkyoncCcfniesjTCna7R8zm3hOkOs=; b=KgUhUv6BLVXfLib/JD0xoNcPebU3YUQfcNCsMl/m+1lDY4VfAWoF9sLqsu/efZ26iG 4h6vRNT4pMjzwivROn+FoSMxuw6iOtgv7z9DdbNfyF8obpWxv7Ht4zUL/RY02fhGw6PO WZaVNR9OACETZr8Yy+uOmsvjufHLECP1dfYxo4/I7UG/gsAQ8fAUDKShI7xqra/2YWUY vfRKQesWt8WAmgZ7oh6RZkzFYfPqCpErku17r34o9GCmwLhzqLMaYd/APonnsbG2mFVD F9yIk4ldsivtiy/BlVkKaK5bKEaV8xpHxy1ocS7a/6OM8+su25qjhkulbB7C+UfAi09z QGTw== X-Gm-Message-State: AAQBX9eAMGiEWfXI0E1LxFW1lfjUGS8YJkyvo1o3APBRtqmGbluJMU4t Tbf9+GuOk/+yT9xsI9aVr0yN0/kYDfzpms6UzrLRp0l6yYW9olBetnRW4vuzFnMZ/G5PWZIFiCj //ZvPv7DTvAY= X-Received: by 2002:a05:6214:528e:b0:5a5:e941:f33d with SMTP id kj14-20020a056214528e00b005a5e941f33dmr4707104qvb.3.1681317850514; Wed, 12 Apr 2023 09:44:10 -0700 (PDT) X-Google-Smtp-Source: AKy350YgYkqzXY4OPOAVlwyIH89dfszaQ4CVLKQFhdriMwZPec01lMU25gulp094+Es9DxvsBiKi5Q== X-Received: by 2002:a05:6214:528e:b0:5a5:e941:f33d with SMTP id kj14-20020a056214528e00b005a5e941f33dmr4707078qvb.3.1681317850234; Wed, 12 Apr 2023 09:44:10 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id b4-20020a0cfb44000000b005dd8b93457csm2915318qvq.20.2023.04.12.09.44.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:44:09 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: David Hildenbrand , Andrew Morton , Leonardo Bras Soares Passos , peterx@redhat.com, Andrea Arcangeli , Nadav Amit , Mike Rapoport , Axel Rasmussen , Mike Kravetz Subject: [PATCH v2 26/31] selftests/mm: Move zeropage test into uffd unit tests Date: Wed, 12 Apr 2023 12:44:04 -0400 Message-Id: <20230412164404.328815-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: AB9FBC001F X-Stat-Signature: s6e444byha6dfc3qc5q4igp64yfrncuc X-HE-Tag: 1681317856-237141 X-HE-Meta: U2FsdGVkX19aOTIc50uqTg0NBRm1ZGdPKcPTzryjMGVEDhVPZPYZKKFT4jLpw/R2xn7USwoCk4jegG6uCERyaDAr5CrYJ4kGySA8BE/VPmHMZr+GSZsXTDLj6j7O20G6zKW+k2db/y4YTskEF0vAyd5tqaQVNpHuL1xqfI9lekLE33zr4Kg4Q4glDBgGHs+RunVwsiA1dtcdJz4YwVn+4ONdjQuZt1XpKN+dUWuJjFu/qWBVrZmHTZDSgYPOUq1qRShWCreNTU2VwDzeSONX0k6H91MH2MPfc8Nz5z4Yc5AKPNctQlprkq0lsSUHFg6oRcWSpBUyY++2HVCG5QhlMkkTg5R3QReD+ywmLmC184mKCFcCV1gxDf2ajAn/Ze4q+4WVx0YTD0N4339NS9DdKfZ8mHtDKhtrg2/1h4SxrPVh+JUO/oS4vhBUH2JDZlEM5NmwsmdTd2ADOgQHzulnp8jEhCrvl8TRSsz+D4BenZ99SEennem+MxAIBjVHmX8ce1rXoVGBkcdbkxIzaXZRpdO7shmqmwOmctPC7fgx6bUVoRKpWrDGLYYE/wTk0pWlRS6WhFmp+SRrD7sUkMw9IBmbisZMe6CYJU+u+S4BiBL09Xvzcoyt4RS86b+PaMUr9nPQ/F28cIcwedta8dN9vFjXyjAWdTwaLmo2Ch/U/AWLnAOeNFriin5NE2P+zpoLmlElB0IGrw8KBI/94hNBK5L6ZltppxrclJPbYHLo24OVfsNdxLl2JDCMvqOiWzaRrPy1mwfub7mUEay947NwpmXG53Xa1/oXQIxPaoFUwgCaPAzcqUyWW+pjJVTKN+CdUty+cSxVia39+LHW2cGV17ccMEfkg6sgCjgZuputW7APb/kHDbA1YFnRqLjb7HG6bXAPtdqOYqcnHaq72KLJI9V4wz13VpAo9uuai3w/b/Jg/UUz6vQA2aTcxCzS8FulF3Ghv3Vc6UWacQxaG+a nG7cBsxN vqAkiRTinrOvO6AlK3eSYghu82LRyPuQShcXzN8W4tFykS4bKuUppOevu8qnyZaNzovpzumnZuGDp7K4mYCfIDimPppbIcFuUD2g7clwHdxyIPbL/I/81s+5oF1mSY19ipmt2kVEYU+1vcdav08+PjTOo8/943GDpIS5YhgI7EOocNIT3i3beBQ9goA4b70r88E1sWYuYYtknGBrJSxSxyHHSzJCy8X4lbj//lmvHlqTtCW+EFPoNNtzDv79rzYceMH+HQaF7yGlFjaigZwZi830OdnrmvIhZmeBKyjc8jUkrfg9L9nbP/hKrP7Kw9a3dEGeSkJ8qoSFAlXcgkjVpHKxcfk4sTWzPGDtTpiVXve9X5WdwGExbvQhlftDLTOyEz5M1X7fukPjtId18je/7YZlJk1q9+kdOSelr/Wn6mPm3U0Up+iN3uxNnrZPfCg32YBIyoiyu5rbeW/WCUERvoPJrKqLHSQFcTBji 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: Simplifies it a bit along the way, e.g., drop the never used offset field (which was always the 1st page so offset=0). Introduce uffd_register_with_ioctls() out of uffd_register() to detect uffdio_register.ioctls got returned. Check that automatically when testing UFFDIO_ZEROPAGE on different types of memory (and kernel). Signed-off-by: Peter Xu --- tools/testing/selftests/mm/uffd-stress.c | 94 +------------------- tools/testing/selftests/mm/uffd-unit-tests.c | 93 +++++++++++++++++++ tools/testing/selftests/mm/vm_util.c | 14 ++- tools/testing/selftests/mm/vm_util.h | 2 + 4 files changed, 108 insertions(+), 95 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-stress.c b/tools/testing/selftests/mm/uffd-stress.c index ce51180238d8..d78f88850011 100644 --- a/tools/testing/selftests/mm/uffd-stress.c +++ b/tools/testing/selftests/mm/uffd-stress.c @@ -109,15 +109,6 @@ static inline uint64_t uffd_minor_feature(void) return 0; } -static int my_bcmp(char *str1, char *str2, size_t n) -{ - unsigned long i; - for (i = 0; i < n; i++) - if (str1[i] != str2[i]) - return 1; - return 0; -} - static void *locking_thread(void *arg) { unsigned long cpu = (unsigned long) arg; @@ -273,89 +264,6 @@ static int stress(struct uffd_args *args) return 0; } -static void retry_uffdio_zeropage(int ufd, - struct uffdio_zeropage *uffdio_zeropage, - unsigned long offset) -{ - uffd_test_ops->alias_mapping(&uffdio_zeropage->range.start, - uffdio_zeropage->range.len, - offset); - if (ioctl(ufd, UFFDIO_ZEROPAGE, uffdio_zeropage)) { - if (uffdio_zeropage->zeropage != -EEXIST) - err("UFFDIO_ZEROPAGE error: %"PRId64, - (int64_t)uffdio_zeropage->zeropage); - } else { - err("UFFDIO_ZEROPAGE error: %"PRId64, - (int64_t)uffdio_zeropage->zeropage); - } -} - -static int __uffdio_zeropage(int ufd, unsigned long offset) -{ - struct uffdio_zeropage uffdio_zeropage; - int ret; - bool has_zeropage = !(test_type == TEST_HUGETLB); - __s64 res; - - if (offset >= nr_pages * page_size) - err("unexpected offset %lu", offset); - uffdio_zeropage.range.start = (unsigned long) area_dst + offset; - uffdio_zeropage.range.len = page_size; - uffdio_zeropage.mode = 0; - ret = ioctl(ufd, UFFDIO_ZEROPAGE, &uffdio_zeropage); - res = uffdio_zeropage.zeropage; - if (ret) { - /* real retval in ufdio_zeropage.zeropage */ - if (has_zeropage) - err("UFFDIO_ZEROPAGE error: %"PRId64, (int64_t)res); - else if (res != -EINVAL) - err("UFFDIO_ZEROPAGE not -EINVAL"); - } else if (has_zeropage) { - if (res != page_size) { - err("UFFDIO_ZEROPAGE unexpected size"); - } else { - retry_uffdio_zeropage(ufd, &uffdio_zeropage, - offset); - return 1; - } - } else - err("UFFDIO_ZEROPAGE succeeded"); - - return 0; -} - -static int uffdio_zeropage(int ufd, unsigned long offset) -{ - return __uffdio_zeropage(ufd, offset); -} - -/* exercise UFFDIO_ZEROPAGE */ -static int userfaultfd_zeropage_test(void) -{ - printf("testing UFFDIO_ZEROPAGE: "); - fflush(stdout); - - uffd_test_ctx_init(0); - - if (uffd_register(uffd, area_dst, nr_pages * page_size, - true, test_uffdio_wp, false)) - err("register failure"); - - if (area_dst_alias) { - /* Needed this to test zeropage-retry on shared memory */ - if (uffd_register(uffd, area_dst_alias, nr_pages * page_size, - true, test_uffdio_wp, false)) - err("register failure"); - } - - if (uffdio_zeropage(uffd, 0)) - if (my_bcmp(area_dst, zeropage, page_size)) - err("zeropage is not zero"); - - printf("done.\n"); - return 0; -} - static int userfaultfd_stress(void) { void *area; @@ -467,7 +375,7 @@ static int userfaultfd_stress(void) uffd_stats_report(args, nr_cpus); } - return userfaultfd_zeropage_test(); + return 0; } static void set_test_type(const char *type) diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/selftests/mm/uffd-unit-tests.c index 94549696f4b2..160bd8ccda55 100644 --- a/tools/testing/selftests/mm/uffd-unit-tests.c +++ b/tools/testing/selftests/mm/uffd-unit-tests.c @@ -660,7 +660,100 @@ static void uffd_events_wp_test(void) uffd_events_test_common(true); } +static void retry_uffdio_zeropage(int ufd, + struct uffdio_zeropage *uffdio_zeropage) +{ + uffd_test_ops->alias_mapping(&uffdio_zeropage->range.start, + uffdio_zeropage->range.len, + 0); + if (ioctl(ufd, UFFDIO_ZEROPAGE, uffdio_zeropage)) { + if (uffdio_zeropage->zeropage != -EEXIST) + err("UFFDIO_ZEROPAGE error: %"PRId64, + (int64_t)uffdio_zeropage->zeropage); + } else { + err("UFFDIO_ZEROPAGE error: %"PRId64, + (int64_t)uffdio_zeropage->zeropage); + } +} + +static bool do_uffdio_zeropage(int ufd, bool has_zeropage) +{ + struct uffdio_zeropage uffdio_zeropage = { 0 }; + int ret; + __s64 res; + + uffdio_zeropage.range.start = (unsigned long) area_dst; + uffdio_zeropage.range.len = page_size; + uffdio_zeropage.mode = 0; + ret = ioctl(ufd, UFFDIO_ZEROPAGE, &uffdio_zeropage); + res = uffdio_zeropage.zeropage; + if (ret) { + /* real retval in ufdio_zeropage.zeropage */ + if (has_zeropage) + err("UFFDIO_ZEROPAGE error: %"PRId64, (int64_t)res); + else if (res != -EINVAL) + err("UFFDIO_ZEROPAGE not -EINVAL"); + } else if (has_zeropage) { + if (res != page_size) + err("UFFDIO_ZEROPAGE unexpected size"); + else + retry_uffdio_zeropage(ufd, &uffdio_zeropage); + return true; + } else + err("UFFDIO_ZEROPAGE succeeded"); + + return false; +} + +/* + * Registers a range with MISSING mode only for zeropage test. Return true + * if UFFDIO_ZEROPAGE supported, false otherwise. Can't use uffd_register() + * because we want to detect .ioctls along the way. + */ +static bool +uffd_register_detect_zeropage(int uffd, void *addr, uint64_t len) +{ + uint64_t ioctls = 0; + + if (uffd_register_with_ioctls(uffd, addr, len, true, + false, false, &ioctls)) + err("zeropage register fail"); + + return ioctls & (1 << _UFFDIO_ZEROPAGE); +} + +/* exercise UFFDIO_ZEROPAGE */ +static void uffd_zeropage_test(void) +{ + bool has_zeropage; + int i; + + has_zeropage = uffd_register_detect_zeropage(uffd, area_dst, page_size); + if (area_dst_alias) + /* Ignore the retval; we already have it */ + uffd_register_detect_zeropage(uffd, area_dst_alias, page_size); + + if (do_uffdio_zeropage(uffd, has_zeropage)) + for (i = 0; i < page_size; i++) + if (area_dst[i] != 0) + err("data non-zero at offset %d\n", i); + + if (uffd_unregister(uffd, area_dst, page_size)) + err("unregister"); + + if (area_dst_alias && uffd_unregister(uffd, area_dst_alias, page_size)) + err("unregister"); + + uffd_test_pass(); +} + uffd_test_case_t uffd_tests[] = { + { + .name = "zeropage", + .uffd_fn = uffd_zeropage_test, + .mem_targets = MEM_ALL, + .uffd_feature_required = 0, + }, { .name = "pagemap", .uffd_fn = uffd_pagemap_test, diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c index 1bc0ceb01adb..9b06a5034808 100644 --- a/tools/testing/selftests/mm/vm_util.c +++ b/tools/testing/selftests/mm/vm_util.c @@ -198,8 +198,9 @@ unsigned long default_huge_page_size(void) return hps; } -int uffd_register(int uffd, void *addr, uint64_t len, - bool miss, bool wp, bool minor) +/* If `ioctls' non-NULL, the allowed ioctls will be returned into the var */ +int uffd_register_with_ioctls(int uffd, void *addr, uint64_t len, + bool miss, bool wp, bool minor, uint64_t *ioctls) { struct uffdio_register uffdio_register = { 0 }; uint64_t mode = 0; @@ -218,10 +219,19 @@ int uffd_register(int uffd, void *addr, uint64_t len, if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register) == -1) ret = -errno; + else if (ioctls) + *ioctls = uffdio_register.ioctls; return ret; } +int uffd_register(int uffd, void *addr, uint64_t len, + bool miss, bool wp, bool minor) +{ + return uffd_register_with_ioctls(uffd, addr, len, + miss, wp, minor, NULL); +} + int uffd_unregister(int uffd, void *addr, uint64_t len) { struct uffdio_range range = { .start = (uintptr_t)addr, .len = len }; diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h index 634eb2f41145..b950bd16083a 100644 --- a/tools/testing/selftests/mm/vm_util.h +++ b/tools/testing/selftests/mm/vm_util.h @@ -52,6 +52,8 @@ int uffd_open_dev(unsigned int flags); int uffd_open_sys(unsigned int flags); int uffd_open(unsigned int flags); int uffd_get_features(uint64_t *features); +int uffd_register_with_ioctls(int uffd, void *addr, uint64_t len, + bool miss, bool wp, bool minor, uint64_t *ioctls); /* * On ppc64 this will only work with radix 2M hugepage size From patchwork Wed Apr 12 16:45:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209363 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 6FE74C77B6E for ; Wed, 12 Apr 2023 16:45:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0DE38900005; Wed, 12 Apr 2023 12:45:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 08DD0900003; Wed, 12 Apr 2023 12:45:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E99BC900005; Wed, 12 Apr 2023 12:45:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id DB096900003 for ; Wed, 12 Apr 2023 12:45:25 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 9EBB61C4795 for ; Wed, 12 Apr 2023 16:45:25 +0000 (UTC) X-FDA: 80673314610.13.CEAD976 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf26.hostedemail.com (Postfix) with ESMTP id 8EBAB140017 for ; Wed, 12 Apr 2023 16:45:23 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=PyMZP+gf; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf26.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681317923; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=7ndlAQp34To4na8gq5wbdyyXxzaHqcVWVuJagrtwfaA=; b=GCA5/bRUqeS6TF7F1a/4QzJYoWr6n+ck1SVW7/IxpHcvMSSID0VYne4J1xLEJsyLabDl0S 3Zn6gtWEINw3XLxfmWquHPzZ4kwsQc8oS8hkEblEb2ANs81jRwHGFmN74iqgk76MasKKtI chM0koLd0pSQFnG6rNHmv7w8reC1wec= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=PyMZP+gf; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf26.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681317923; a=rsa-sha256; cv=none; b=v5/4DGuinp26i/qGC8nGSq/GAWKVYRA5O2B6hok560ok0yygO+kPxs3/dNNByr5F3Kfz2c RuqmYba7BYiYvBxhQIwxkOnnD5IIbVDwT+68k1sDQlXSeoP1Nco6qpy017RQ52F+G6QeIl YLitPCqBfNLE6kZmHtMLkIbVG5vXfAc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317922; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7ndlAQp34To4na8gq5wbdyyXxzaHqcVWVuJagrtwfaA=; b=PyMZP+gf0C/Uuc62+RD3oB7i9rHY7shJxxg6E7s1VFyy/AlTAW4B7l4Rm/vIVrriCxI2jg fuaYbBfpGs8BlPwTwrjT74YfXNdKPryFCQMZJO/BB6xWk9CtYfQLvnBgQwpLup0dnWXGCy +HxXWFwIxxQIQKvucjzZh5Q2wAx0XZ4= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-396-jv9yAtG9NBeRfBDJXglzXA-1; Wed, 12 Apr 2023 12:45:22 -0400 X-MC-Unique: jv9yAtG9NBeRfBDJXglzXA-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-5ea572ef499so7660026d6.1 for ; Wed, 12 Apr 2023 09:45:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317920; x=1683909920; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7ndlAQp34To4na8gq5wbdyyXxzaHqcVWVuJagrtwfaA=; b=eM3za2NWitILMIQK4jH2SjAa958etiO7sAT+3DcoOZXvrzjhl+fmV/ZrvvK9BmqLVh X35ut8gXXWRwSdgqTZlw+4HC8btYTg92Uc0+zwb1DNY9GDK9UWtJ6NSRqMmlrALrqKr+ x02mZYddjSDUgQH4RKlH6SGRfiwD9SjBQ9Kf5Xl/bY3825Vy2hDRAuXaJb3bQkbx/15I 7FI6DSc3iFJ8ig6Ca7QMDOATqJz0EB/PD1atz3AZazQ5uyVZIZOgmfeDsR/XbjhnlZPI hEvH4w7Y6nYu6tBBRcZ1hd5eOUQsX4ZUkz1BPqKhJ9uxOyRCfUqruZAl1UQoS4E1XdPC o/hQ== X-Gm-Message-State: AAQBX9fozjZCryNSu0WmKoalWqLGOxg8+DpKzmfhVrpNgJSLGfS3o5Gc rK4PLAimDPVx38sJK22FKq42Z4OXy2vKq8ipjqY84HFV60hFZT1vDA4z0Tk98t2FQp3WNFcd0wO J54apnwy6/iJPJW/3BN9fg/RKxsFp8A8lb2kzTw5BwC3gc0WhNUKi3tA6wsNPAQWwI9ef X-Received: by 2002:ad4:5de6:0:b0:5da:b965:1efd with SMTP id jn6-20020ad45de6000000b005dab9651efdmr27671987qvb.2.1681317920428; Wed, 12 Apr 2023 09:45:20 -0700 (PDT) X-Google-Smtp-Source: AKy350YZb2K0e1JvXEoA25aoHQ/nvgMcYX1GQMHOJJJS45iAA64autN1RPeNtWC+riOtge78epKXPA== X-Received: by 2002:ad4:5de6:0:b0:5da:b965:1efd with SMTP id jn6-20020ad45de6000000b005dab9651efdmr27671945qvb.2.1681317919979; Wed, 12 Apr 2023 09:45:19 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id cw8-20020ad44dc8000000b005ef465ad69bsm319693qvb.23.2023.04.12.09.45.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:45:19 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Nadav Amit , Mike Rapoport , Leonardo Bras Soares Passos , peterx@redhat.com, David Hildenbrand , Axel Rasmussen , Andrea Arcangeli , Mike Kravetz , Andrew Morton Subject: [PATCH v2 27/31] selftests/mm: Workaround no way to detect uffd-minor + wp Date: Wed, 12 Apr 2023 12:45:17 -0400 Message-Id: <20230412164517.329152-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: 8EBAB140017 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: j3jahdwhs3xwpeffpnd5tzkrthdtkwfc X-HE-Tag: 1681317923-206440 X-HE-Meta: U2FsdGVkX1/bmKZ5inArr3c9E6ig+dfc86mxThJelsXelGnNptJGx4cDrmvR5RJhSZEBtneV97Bt7LcpwqgxL4Cp1BT7vIpH8x8zEfFQhdVd+YBw040VWSpeh3SzEa7pDOV0TuFGh/iJeOw6Ku3gzrHYbXKyoLUV7gK/yArraRvwZrvKwYxPRtZJGG4KSSJUeZRaAaKn6NlAH/6yd7X58YnLfXqWRhuEGfNrIMHlZO0x+0kHVuoN77ENA8SBHG6Xn1g20eQXFpnjL1XnLBpVVKBM/dcBs8FXE/IjhocGCWxf1pC9GDBCsx3OkXUD/61xWoD3zGO47Bv22Ggww0JmRYnSB/GQ8XQKO2dhNxDEqVCBUqqR52W4VOY1D0ZpqVLkaj7PJJZywTq8Lrj6n5xSxmJiN38IJNX7/NNDICvlYkEYDCnSWLT4xK+Z4V0IHPKfRseX5UF3yxa6Zy/nzQ93kK4/BlRApn+FIFyotRG/thE0E7zl5YQ33jK1+0h7KaiB28FbkKg/ZhodtozY16YHvh+4akKpQyZGilcjnqsaCgVBhYfQz8/5KsQ05JCmzAO3/degeACsh7r80W3xvyKZHudgDdxJb2wRuA/aLi6aoJiVv9NvQyh6mrbeTzK8GfPpheXvdjQ4zttDuAGOIKbQ/pRLTE+ZN3QNe3k13d+TABivts2r0+1wmzp+T9yGE9pEw6S+mREF2HHcCMxJPBSupDtgdanYeiqC0oOZO5dQegPuNAPbleiP3sJ/pTDPhLF9LjM/zvqLp9tbPMsx8bUku9s3uh6AEqhIJRHd2CVLd0IRxEfwb24i4ZfJiPx8NMRmmfYeNyHMxqIAYYLHqel7CiDnv0CuduK2Aw5Rfeez8DHb65IQIJJV4T+4qnooUqUCs0+mi9jgDk/HBQrwbk1b52QuRi6FlRHtbjSPDUQjbJL5t8MC/UnrmOXV4heE3iA1WVoIWbkTLvD4xyzPttG CyG1fVSN 6IhjgxtW1wPir6T7NGzXzBLCvHtTVWEIuBWrdzrxu1iVKsigKNc6ne9U7dUM8wJ306J2tHIBq0Bs5cWiaLZSgAp9ey9IMG9Aa19f9OSMHm285BlcfpBN2ZYHzBeTdgivxrbAAU/hz/JXj+LNIVl180UuG61j0ECMwanOH4MlLhvRFe9vIuqcQSjQge5DX47r13gueGSP/kxmQARjL/JJJoXm02U993MNJWCnRRXGv7ABG8a+f2i08x7IY+4K5lmcLgqZdnlXdZhKWLU5hR0r1rArozBA5saR4ZB8iOVg871Ttmvrddv9he+0PfaT9dPqI0tRUQC4zCzOpqX63Exrb/PmHWKuqpUUO91LMIQgeRY0tm2PHPvgHBYaqegZhaU5R/p321bhIscJKF97SzAl+J0beAifgyHh456LD3f26CB7INtAiIAbN6d7EoAgV67swZm18r/W6hgUwb65emrVIlafEKreQ1B3BKhnK 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: Userfaultfd minor+wp mode was very recently added. The test will fail on the old kernels at ioctl(UFFDIO_CONTINUE) which is misterious. Unfortunately there's no feature bit to detect for this support. Add a hack to leverage WP_UNPOPULATED to detect whether that feature existed, since WP_UNPOPULATED was merged right after minor+wp. Signed-off-by: Peter Xu --- tools/testing/selftests/mm/uffd-unit-tests.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/selftests/mm/uffd-unit-tests.c index 160bd8ccda55..a33d6c928eeb 100644 --- a/tools/testing/selftests/mm/uffd-unit-tests.c +++ b/tools/testing/selftests/mm/uffd-unit-tests.c @@ -780,7 +780,13 @@ uffd_test_case_t uffd_tests[] = { .mem_targets = MEM_SHMEM | MEM_HUGETLB, .uffd_feature_required = UFFD_FEATURE_MINOR_HUGETLBFS | UFFD_FEATURE_MINOR_SHMEM | - UFFD_FEATURE_PAGEFAULT_FLAG_WP, + UFFD_FEATURE_PAGEFAULT_FLAG_WP | + /* + * HACK: here we leveraged WP_UNPOPULATED to detect whether + * minor mode supports wr-protect. There's no feature flag + * for it so this is the best we can test against. + */ + UFFD_FEATURE_WP_UNPOPULATED, }, { .name = "minor-collapse", From patchwork Wed Apr 12 16:45:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209364 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 9801EC7619A for ; Wed, 12 Apr 2023 16:45:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 39D3E90000A; Wed, 12 Apr 2023 12:45:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 33336900003; Wed, 12 Apr 2023 12:45:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1A12290000A; Wed, 12 Apr 2023 12:45:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 0490B900003 for ; Wed, 12 Apr 2023 12:45:35 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B98C41C49A4 for ; Wed, 12 Apr 2023 16:45:34 +0000 (UTC) X-FDA: 80673314988.25.735037F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf18.hostedemail.com (Postfix) with ESMTP id 6D9E41C0017 for ; Wed, 12 Apr 2023 16:45:32 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="QD9/AnEa"; spf=pass (imf18.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@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=1681317932; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=RvUBLMIj6eaAe1GDo1uBeLCLb+kkyu1V0plV870AgzY=; b=hKu9ZpIS0L8ZYtAX2Id8R7CnwdI4ZmvBtI/zTADkAjo+QSjQSzYDroKzcmuuBIlMxQIBWc afG/MuJw++57CMNaJVOIBChmYc1kyY6uyYJXdo23cjvf5HqE0nN8+YFryDtd6IlItBEnPx /xgcLIWalwwoWnLimm6vxf4EzBZLGVE= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="QD9/AnEa"; spf=pass (imf18.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681317932; a=rsa-sha256; cv=none; b=A3fSk3TdPhTjCgsQwvB+z13HfOEs0RaOmYYfMqNzpYV9vjhhwyQAYrQxvNIyY+UblATquh OdaiOx/pMIFF6UBzbJ/jUaQlcWSTHXg6QBBgyBU5lbUkne4bT2XnMnpPp/IHcZQLacduNS y+nakzBf6KhIDdwKD0Aghu3rO8ThH3A= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317931; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RvUBLMIj6eaAe1GDo1uBeLCLb+kkyu1V0plV870AgzY=; b=QD9/AnEaA+ZpBu7gt6gieql97fbcPr9RunIubIUO2rgDkRRnwyF7yrEHyNE62XrwVoQofU weihL2PUK4WTnhsUbxCSGTmoVWuih4jYNU9h8fvRSngiTvllO7i81WQU9BcjlhEV3PqwpZ cQj+qEbyRrdAya7ReSPBKD9U03J08qs= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-204-AR7LlFRUOk6h8vGjykuQ4g-1; Wed, 12 Apr 2023 12:45:30 -0400 X-MC-Unique: AR7LlFRUOk6h8vGjykuQ4g-1 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-3e69901d854so896961cf.0 for ; Wed, 12 Apr 2023 09:45:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317925; x=1683909925; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RvUBLMIj6eaAe1GDo1uBeLCLb+kkyu1V0plV870AgzY=; b=Z5r+epkZ50gFRvZPD72li/lbonn8Z5PnhZc/sQJLsVBWvonZuYoEjK8tqvQJXgK28A 4M1+ho83aUyB6BBEAIeuVs8xpauaJl/2yUuQSXF5kcqJ5GcHOWba7X2MvbWSleiR3OWy S1gqOKzmItX52Cmr8qrG+rREgV5QrPV8QYIBHf+Pe2KSqvrGp3kgVUo+FNxHAYHeQLuW 73LgfXjseiXFi/LqIYl+ScMoazAYiZH8+XbinuWrsOHOOUh4jr6g4oiPfYhTevxHSZ1H QCXXILdzg8Eq9aZuT1cVjCv7KGbV7fVUfPpcwzuqMIpK+evAljr0y+WW83e2AwJ8xn9g JicA== X-Gm-Message-State: AAQBX9dtEw9nVdIaeNplTLVf1jolUlL2n3yzoZoWoY/M+U5pAxLXNlMr UkeNIYZVWqO1qKm2oh+/EiSzp6rI9JeBmvggErdiLEPq1NcF38spa0sNPJn5CV7otl63csPBfkB 7lU5tzSUAp4GV7WGlqggktGCxTTjTsDuYu5SdloGZ0AexjqtafAjjEcJ/RIsJMRTkmIKP X-Received: by 2002:a05:622a:1816:b0:3e6:45c7:cf36 with SMTP id t22-20020a05622a181600b003e645c7cf36mr4507555qtc.2.1681317925314; Wed, 12 Apr 2023 09:45:25 -0700 (PDT) X-Google-Smtp-Source: AKy350Z+HrIjE4VkqiqM0waR7nZs5KpOic28Y2xavh1QsIMJZkK6W8GnSwnURyYGigGHyvQoxq9B1Q== X-Received: by 2002:a05:622a:1816:b0:3e6:45c7:cf36 with SMTP id t22-20020a05622a181600b003e645c7cf36mr4507479qtc.2.1681317924355; Wed, 12 Apr 2023 09:45:24 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id 73-20020a37064c000000b0074acd1b32f5sm112009qkg.83.2023.04.12.09.45.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:45:23 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Nadav Amit , Mike Rapoport , Leonardo Bras Soares Passos , peterx@redhat.com, David Hildenbrand , Axel Rasmussen , Andrea Arcangeli , Mike Kravetz , Andrew Morton Subject: [PATCH v2 28/31] selftests/mm: Allow uffd test to skip properly with no privilege Date: Wed, 12 Apr 2023 12:45:20 -0400 Message-Id: <20230412164520.329163-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 6D9E41C0017 X-Stat-Signature: azpny853to6ekiwoxqjfcpi449jd6w1c X-HE-Tag: 1681317932-74508 X-HE-Meta: U2FsdGVkX18my9kzE3hPvG13I+d8F7TIZwUAIgqftRfLq+uQig4uU2tXTUIK7erU2WxTNhnghg4lSNaXQyCWX7qk4+a956JLMNCnfCS4YnZCKxTLrgl8UXLH8qBCUV5vcsRxmEioqk5DVF0zj+UzMpUMOS4RVKJjDQDz5cDyNMTMW00K2QslSsDEUQDCibNJDRqh7+iwE+5IFxPpGWKs4TrmwC2GRffMfz6JFBdrfHTVI2J8NUrCDqLbeuEDwdVcLaBfd8lg/ZFzp14BDZ9Nz2XSTcg/7GqEPEqtfd/aWO3xzBhI4fjsEsougfP2DjmqWEhp+z6nUkXaHG3glBELruUsfsfhdRXDMfVM250B4BoQtt4v8sa8DOejjPAuYJSKg6h5HgqWiFH57FAZin//kkx0W/wAoz1IBBYen0nmM8cHHh7CbA+ZjzVQan1lWJs/Tu2HN+8l3paaDWW6TSys4BTPZXvDiuR2LuREvboPTuTE0VSDFcgqu9TOVZly0bsagj72jgkW5dZgPJo3g7uPmfDhhJquvrTD0YIzEO2nq/t7ljz1lyV+dTtROPOGvar6nmQI1pcYBwoc4HF+NE2LuU03Nw1Xzx4gkeCTcex06E27VCBn9cNApptYhSUnAZicINASqg9q/s+uOnoWb71+5/+pcMoD8IxFukaVd8EPxe8p8kVXJHoQkJT34b6xCjRzxMXKcnYRoLMQakIR0LAUMRg+V99ae1ZCqZdmWeYTHdMowMneGluC3Zg8j6mm9iPE7SaQ+plPQXs9ywDnnwMdQC5cGPwW3FRYy6KhaBb4ABg9/JETIH3dtu4JNb5iFA1bZqt21e8kOonKuDZNcuhTl4+vr1z0RFke8kTEuSJNiSfAS3/BHhp3XitgniAXVSpMbAG23YeVGIpHpH8tdzn22UKM+hvr0ikVSD2pu6NPwH3f0E8Gua8nxnR3z3CDXF3zLHVTUdhe3fQN0jPog1i ES1R/qg5 Tqcjud/xwTqdlllT0lUsK5zSlyn59wvFsVgjJOB4Z9ZsxVLAWYMUXNWCrl/u8t525mje6rUmLsUWjFYmHdHYTwN3WW5AnXrHUTmdibqdJxE0RdMau9bv7JqXOgzF+TOg7FsMcTRKivgOUGDCXvve8uv+DV0IO3EE5+o5aKQ5reUlZv9g9n8BkhxYlDGQiCal8i1FaNZVWF5b/QQp1iz7TkMRwFPxRsgqOhMAYZExwMYY+DqvqeDse97cnAgPPHkIN/GFybJi4kdqwWveR1PV/mcDe0XrkZSYm2ilQ8AxL+R2jEg47b6qeHmbH6UBsxYwWEwkDaXF0x5nW3haalMG5ZV83RHT63TAzQwOHfJuYP3tegJ/lNUEzy+7vWhZfvruT6BRdf8nMDIcEn48yeMLvH27Oeeqf6ko30OU+7hr5Mpgn90I0Q6I5O/wGUrUFb2u7+TtCZTXB+lpD77eM3OJ1Oh4hF+8dUlon0HkI 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: Allow skip a unit test properly due to no privilege (e.g. sigbus and events tests). Signed-off-by: Peter Xu --- tools/testing/selftests/mm/uffd-common.c | 27 ++++++++++++-------- tools/testing/selftests/mm/uffd-common.h | 4 +-- tools/testing/selftests/mm/uffd-stress.c | 6 +++-- tools/testing/selftests/mm/uffd-unit-tests.c | 10 +++++--- 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-common.c b/tools/testing/selftests/mm/uffd-common.c index 12ac84712a38..3e98e129f8bd 100644 --- a/tools/testing/selftests/mm/uffd-common.c +++ b/tools/testing/selftests/mm/uffd-common.c @@ -232,7 +232,7 @@ void uffd_stats_report(struct uffd_args *args, int n_cpus) printf("\n"); } -void userfaultfd_open(uint64_t *features) +int userfaultfd_open(uint64_t *features) { struct uffdio_api uffdio_api; @@ -241,18 +241,19 @@ void userfaultfd_open(uint64_t *features) else uffd = uffd_open_sys(UFFD_FLAGS); if (uffd < 0) - err("uffd open failed (dev=%d)", test_dev_userfaultfd); + return -1; uffd_flags = fcntl(uffd, F_GETFD, NULL); uffdio_api.api = UFFD_API; uffdio_api.features = *features; if (ioctl(uffd, UFFDIO_API, &uffdio_api)) - err("UFFDIO_API failed.\nPlease make sure to " - "run with either root or ptrace capability."); + /* Probably lack of CAP_PTRACE? */ + return -1; if (uffdio_api.api != UFFD_API) err("UFFDIO_API error: %" PRIu64, (uint64_t)uffdio_api.api); *features = uffdio_api.features; + return 0; } static inline void munmap_area(void **area) @@ -295,7 +296,7 @@ static void uffd_test_ctx_clear(void) munmap_area((void **)&area_remap); } -int uffd_test_ctx_init(uint64_t features) +int uffd_test_ctx_init(uint64_t features, const char **errmsg) { unsigned long nr, cpu; int ret; @@ -303,13 +304,19 @@ int uffd_test_ctx_init(uint64_t features) uffd_test_ctx_clear(); ret = uffd_test_ops->allocate_area((void **)&area_src, true); - if (ret) - return ret; - ret = uffd_test_ops->allocate_area((void **)&area_dst, false); - if (ret) + ret |= uffd_test_ops->allocate_area((void **)&area_dst, false); + if (ret) { + if (errmsg) + *errmsg = "memory allocation failed"; return ret; + } - userfaultfd_open(&features); + ret = userfaultfd_open(&features); + if (ret) { + if (errmsg) + *errmsg = "possible lack of priviledge"; + return ret; + } count_verify = malloc(nr_pages * sizeof(unsigned long long)); if (!count_verify) diff --git a/tools/testing/selftests/mm/uffd-common.h b/tools/testing/selftests/mm/uffd-common.h index 4bd5915cf5b4..32e590ce9442 100644 --- a/tools/testing/selftests/mm/uffd-common.h +++ b/tools/testing/selftests/mm/uffd-common.h @@ -101,8 +101,8 @@ extern uffd_test_ops_t hugetlb_uffd_test_ops; extern uffd_test_ops_t *uffd_test_ops; void uffd_stats_report(struct uffd_args *args, int n_cpus); -int uffd_test_ctx_init(uint64_t features); -void userfaultfd_open(uint64_t *features); +int uffd_test_ctx_init(uint64_t features, const char **errmsg); +int userfaultfd_open(uint64_t *features); int uffd_read_msg(int ufd, struct uffd_msg *msg); void wp_range(int ufd, __u64 start, __u64 len, bool wp); void uffd_handle_page_fault(struct uffd_msg *msg, struct uffd_args *args); diff --git a/tools/testing/selftests/mm/uffd-stress.c b/tools/testing/selftests/mm/uffd-stress.c index d78f88850011..c0e804f05002 100644 --- a/tools/testing/selftests/mm/uffd-stress.c +++ b/tools/testing/selftests/mm/uffd-stress.c @@ -271,7 +271,8 @@ static int userfaultfd_stress(void) struct uffd_args args[nr_cpus]; uint64_t mem_size = nr_pages * page_size; - uffd_test_ctx_init(UFFD_FEATURE_WP_UNPOPULATED); + if (uffd_test_ctx_init(UFFD_FEATURE_WP_UNPOPULATED, NULL)) + err("context init failed"); if (posix_memalign(&area, page_size, page_size)) err("out of memory"); @@ -435,7 +436,8 @@ static void parse_test_type_arg(const char *raw_type) * feature. */ - userfaultfd_open(&features); + if (userfaultfd_open(&features)) + err("Userfaultfd open failed"); test_uffdio_wp = test_uffdio_wp && (features & UFFD_FEATURE_PAGEFAULT_FLAG_WP); diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/selftests/mm/uffd-unit-tests.c index a33d6c928eeb..b0acf558e8cb 100644 --- a/tools/testing/selftests/mm/uffd-unit-tests.c +++ b/tools/testing/selftests/mm/uffd-unit-tests.c @@ -172,7 +172,8 @@ static int test_uffd_api(bool use_dev) * This function initializes the global variables. TODO: remove global * vars and then remove this. */ -static int uffd_setup_environment(uffd_test_case_t *test, mem_type_t *mem_type) +static int uffd_setup_environment(uffd_test_case_t *test, mem_type_t *mem_type, + const char **errmsg) { map_shared = mem_type->shared; uffd_test_ops = mem_type->mem_ops; @@ -186,7 +187,7 @@ static int uffd_setup_environment(uffd_test_case_t *test, mem_type_t *mem_type) /* TODO: remove this global var.. it's so ugly */ nr_cpus = 1; - return uffd_test_ctx_init(test->uffd_feature_required); + return uffd_test_ctx_init(test->uffd_feature_required, errmsg); } static bool uffd_feature_supported(uffd_test_case_t *test) @@ -835,6 +836,7 @@ int main(int argc, char *argv[]) uffd_test_case_t *test; mem_type_t *mem_type; char test_name[128]; + const char *errmsg; int has_uffd; int i, j; @@ -860,8 +862,8 @@ int main(int argc, char *argv[]) uffd_test_skip("feature missing"); continue; } - if (uffd_setup_environment(test, mem_type)) { - uffd_test_skip("environment setup failed"); + if (uffd_setup_environment(test, mem_type, &errmsg)) { + uffd_test_skip(errmsg); continue; } test->uffd_fn(); From patchwork Wed Apr 12 16:45:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209365 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 0C8F5C77B6E for ; Wed, 12 Apr 2023 16:45:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A05E390000C; Wed, 12 Apr 2023 12:45:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 98ECF900003; Wed, 12 Apr 2023 12:45:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8089390000C; Wed, 12 Apr 2023 12:45:43 -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 69BED900003 for ; Wed, 12 Apr 2023 12:45:43 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 38079C0184 for ; Wed, 12 Apr 2023 16:45:43 +0000 (UTC) X-FDA: 80673315366.24.2C4DCFC Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf22.hostedemail.com (Postfix) with ESMTP id 177DBC0004 for ; Wed, 12 Apr 2023 16:45:40 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="I/w0zopv"; spf=pass (imf22.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@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=1681317941; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=4P1/ScyFhtwT2WBZ2avhVrVKXGlimCZn+6QVBkOI+hY=; b=juoSBbw3lH3i/bS4uLXfCiJmpVThyyWcOPQX4fUFz4/JMCXs2jb3e4cfPS1svDGGu+Fy9n yHqN3SEgP7mjRTEZ6Jp/01GxZMDHqTxZWuIOxO1Hi6Z1Fvjw23Of8BEXbWKX9iaIk8okc6 4z8mBONGzfA5YgZSf07bXybJZ/+G1cc= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="I/w0zopv"; spf=pass (imf22.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681317941; a=rsa-sha256; cv=none; b=1sPx/i/KFc78OjAu+nz1bKCNI46IrEO2aAD4bCpGkS9U9yYp+P/TcJZPMAQ32thkBvbyg3 LmF4K5M/9PzRZ6CDDhI/1yOQTz/R6lh/mis7ouX3RnKxVCVdNQ7lj6riNZFLZsgnwPwN+P FuVZtRDYq4PCB2ICV6QEjOLj/XsX85Y= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317940; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4P1/ScyFhtwT2WBZ2avhVrVKXGlimCZn+6QVBkOI+hY=; b=I/w0zopvsUAuwVWxbPWIOWfOr7/Ykb8jdWeuZCJcV2HSTbz+UDa1SmZ+xZBMOHrCNRNdc/ bFwH670sb5KhO7SFM1ncCstrwjdD4Oc0vr+VmrgqDaCfktUSoxGOSZFNLqSnXP/3KjiNbt dMPIldlTRrrUdpsKawE/erl0Fmyi1uI= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-70-SuuU4JMOMgeQlwZVY4D_Cw-1; Wed, 12 Apr 2023 12:45:39 -0400 X-MC-Unique: SuuU4JMOMgeQlwZVY4D_Cw-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-74accc750c1so3453385a.0 for ; Wed, 12 Apr 2023 09:45:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317934; x=1683909934; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4P1/ScyFhtwT2WBZ2avhVrVKXGlimCZn+6QVBkOI+hY=; b=e2pYzybAYUPvgF2Zt4j5hZAylZGP76un2bq5/GpIXYflgVgqUtkhSwC2qHN3ZV1140 TpmBG+xrE0rqH7TLnKTgKjGzaliBCprpYIv/Z/U+LE/Q2V38Hbij8pj3TxVdpOalYGlD HURgclBSOhxBxv7cf5xRRcwasOYO4cy+ixjR1xHNRMCI5K5UdryHOA/jFg2/Qaol5if2 m/C8KAiSLv4u5zT3iv6HTvua9taccebQtACE8PcnYp3ifsxXAEzJDuzbP24x0KSgCFFC M7M9c8sUUk557JvF23IEasgYsTMGaeypLDDfugB2jlTRJ0HRs6sVEOx2kjgEYlGIVkUv 4hgg== X-Gm-Message-State: AAQBX9dEgtWqmDP4SQ+7B16wQNcIYTNQuylFp3RlFzrjEmMNvcfyfKJd VoOl6D2BaTOACo3eL/NubTu0qpaz86BGTDrq3zb15IWIEOM/HMKxdMfAl0juaGsYYzqNxRTHn3c C6ZmupKnzpc0VLoV8GUIRRaAtkhSrzK0vhWf+UIj6CrWr52NOY7tQ7hhOEwAb6lIX2F2c X-Received: by 2002:a05:6214:401a:b0:5aa:14b8:e935 with SMTP id kd26-20020a056214401a00b005aa14b8e935mr4735752qvb.2.1681317933907; Wed, 12 Apr 2023 09:45:33 -0700 (PDT) X-Google-Smtp-Source: AKy350YFr4iYYFdfQl6EUz00VO2xExXsFFSl3Ic24dd5qBrL9XsgdoJ8YxnsY9ruU2bfo6aBT4rElA== X-Received: by 2002:a05:6214:401a:b0:5aa:14b8:e935 with SMTP id kd26-20020a056214401a00b005aa14b8e935mr4735714qvb.2.1681317933520; Wed, 12 Apr 2023 09:45:33 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id eh3-20020a056214186300b005dd8b934594sm1817671qvb.44.2023.04.12.09.45.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:45:30 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Nadav Amit , Mike Rapoport , Leonardo Bras Soares Passos , peterx@redhat.com, David Hildenbrand , Axel Rasmussen , Andrea Arcangeli , Mike Kravetz , Andrew Morton Subject: [PATCH v2 29/31] selftests/mm: Drop sys/dev test in uffd-stress test Date: Wed, 12 Apr 2023 12:45:25 -0400 Message-Id: <20230412164525.329176-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 177DBC0004 X-Rspam-User: X-Stat-Signature: jmx4kophn4o73ejxkos84kkkuxpzqeak X-HE-Tag: 1681317940-278731 X-HE-Meta: U2FsdGVkX1+XqrdBJDcQoh6W8xsNUG9KOOGO1+GfchQsBzB/9cvOvAjyVfylVprs7H5mFcUlclUjeUSfIwwxX4z/M5yhVFlsmMA32ffDdWJ1cCPXLxHX4WbSYUUKcOISdPAyWxPMgU9CCIcYNEVIHOiLzgGDXbkJWrXQQt9g0+I3WPjB/PpPBNF4muqKvK9fMZRZWBw7xVxHkVH8LVlQhgwTCI4okYxYAsNXT3taXrxSqFyyhKvbDjY/ziJA1FLnwajr35Y9l0Z1dRBUUy8q9rDrWDQOke3xPskHBbsVjIuMfOarOB2JlkLSWAwYy9PoAQbXQhuV80AKq1MZMhiHkTlzb1II/JQ7AzBolg4ZQQ0yhQj8TCRHGq3vuS5Yz/1lgA0fc9Btc0Rhn/ggnvBXkJBbQKHMLMShpDaO3pgAidyCmFL+aYs/icm9tdTB8qgybKPAp20dqPSIGi6f4N3Tz6iwPcHAePmOf1mlPOdy1InNraiA+Fid86JVU12p8/7ti4HXb+Tcp7BGvv19l2BZjo7649/4khzzOJtB4eQYIAOtBlK2IECT9A0mJ4XGWNmbe7Nv+CmNj0DFA1H9Z7a4rtqAw6Y7aD0iePYRwoBKD0/Lio8DGhkn/V2rmYfmb1RLt3u0ydUbfGqRB8oeDSUZjtsKN86OOzv9QlKhJmExgNQLzB8n+B+KAgbitHxSBrZjx5v1RdfEmRUnRoalpFcqVSDC7idTEnQDLx0ijVTL0peGrisdotvCB8z6c0TaMcFwyD94ZncsIEP9NnooGajTgnIoj9YDnFjfeeCLCNw5Zg6Fi6UrQz/+Nk4CnAnlDWVoR9msyTJmY9avnbgdDu/Edfjcz48eA52feZ2pYLXMjPmlfcRSL4MfGJDl3JYP9qeBDCIXVUxnnN82pbEqkesBkNjoTnY8/T1FOI54h3Cg/fK/tH+ZX6cAwZKJWFw2igbF+NkmCoMl/TBbmGEeFeV J3T1Ghbb i6DEfLPcIhWBfwD5cfpTs8nt2XcXN+l54i4XsX5drC/fUk8HaRjHYRpO3QD6CXwUdGsa+0KXbEg4SM0g5geQew+kWE2S+c1yDkarZtHCeUIE38zMH9fvzEMg6pfc6OoxllOgO3FvDGR/Lq9HIJf8/nPZ3I22FhwDKSgNA2/ekbZfzo/6PNXcL9vaxyUwIkTqcWVTuiDM5S6qjjw3PpFXHjRh0S+lH3aBeGEN/KR1yGs9bEFaiQ7rLgT+TlNde+Y7Xw5nguAZykyXCNbplsHKEmOX1Bh0erQk6xs7/tYgFVq96Jx00udARcKwojs3sXPFBUOUckMkcnvt335uY1QWNSCrNLsSHRVNJB6gQ70tBDXC9rsl3wyhRnuyv8CHQZxtfQW7B+GBANyzYrZsTKZVV4v6mU/PHsFBmrPRO8CeMdjg6ugHMJpKFfGCdkWBONhleJWWDyYIUt8oElFkYZCbcfLaW9KrH6EEpv3ip 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: With the new uffd unit test covering the /dev/userfaultfd path and syscall path of uffd initializations, we can safely drop the devnode test in the old stress test. One thing is to avoid duplication of running the stress test twice which is an overkill to only test the /dev/ interface in run_vmtests.sh. The other benefit is now all uffd tests (that uses userfaultfd_open) can run automatically as long as any type of interface is enabled (either syscall or dev), so it's more likely to succeed rather than fail due to unprivilege. With this patch lands, we can drop all the "mem_type:XXX" handlings too. Signed-off-by: Peter Xu --- tools/testing/selftests/mm/run_vmtests.sh | 15 +++++-------- tools/testing/selftests/mm/uffd-common.c | 7 ++---- tools/testing/selftests/mm/uffd-common.h | 2 +- tools/testing/selftests/mm/uffd-stress.c | 27 ++--------------------- 4 files changed, 11 insertions(+), 40 deletions(-) diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/selftests/mm/run_vmtests.sh index efe22dc569f0..ecc16ea6fc40 100644 --- a/tools/testing/selftests/mm/run_vmtests.sh +++ b/tools/testing/selftests/mm/run_vmtests.sh @@ -197,16 +197,13 @@ CATEGORY="gup_test" run_test ./gup_test -a CATEGORY="gup_test" run_test ./gup_test -ct -F 0x1 0 19 0x1000 CATEGORY="userfaultfd" run_test ./uffd-unit-tests -uffd_mods=("" ":dev") uffd_stress_bin=./uffd-stress -for mod in "${uffd_mods[@]}"; do - CATEGORY="userfaultfd" run_test ${uffd_stress_bin} anon${mod} 20 16 - # Hugetlb tests require source and destination huge pages. Pass in half - # the size ($half_ufd_size_MB), which is used for *each*. - CATEGORY="userfaultfd" run_test ${uffd_stress_bin} hugetlb${mod} "$half_ufd_size_MB" 32 - CATEGORY="userfaultfd" run_test ${uffd_stress_bin} hugetlb_shared${mod} "$half_ufd_size_MB" 32 - CATEGORY="userfaultfd" run_test ${uffd_stress_bin} shmem${mod} 20 16 -done +CATEGORY="userfaultfd" run_test ${uffd_stress_bin} anon 20 16 +# Hugetlb tests require source and destination huge pages. Pass in half +# the size ($half_ufd_size_MB), which is used for *each*. +CATEGORY="userfaultfd" run_test ${uffd_stress_bin} hugetlb "$half_ufd_size_MB" 32 +CATEGORY="userfaultfd" run_test ${uffd_stress_bin} hugetlb_shared "$half_ufd_size_MB" 32 +CATEGORY="userfaultfd" run_test ${uffd_stress_bin} shmem 20 16 #cleanup echo "$nr_hugepgs" > /proc/sys/vm/nr_hugepages diff --git a/tools/testing/selftests/mm/uffd-common.c b/tools/testing/selftests/mm/uffd-common.c index 3e98e129f8bd..61c6250adf93 100644 --- a/tools/testing/selftests/mm/uffd-common.c +++ b/tools/testing/selftests/mm/uffd-common.c @@ -13,7 +13,7 @@ volatile bool test_uffdio_copy_eexist = true; unsigned long nr_cpus, nr_pages, nr_pages_per_cpu, page_size; char *area_src, *area_src_alias, *area_dst, *area_dst_alias, *area_remap; int uffd = -1, uffd_flags, finished, *pipefd, test_type; -bool map_shared, test_dev_userfaultfd; +bool map_shared; bool test_uffdio_wp = true; unsigned long long *count_verify; uffd_test_ops_t *uffd_test_ops; @@ -236,10 +236,7 @@ int userfaultfd_open(uint64_t *features) { struct uffdio_api uffdio_api; - if (test_dev_userfaultfd) - uffd = uffd_open_dev(UFFD_FLAGS); - else - uffd = uffd_open_sys(UFFD_FLAGS); + uffd = uffd_open(UFFD_FLAGS); if (uffd < 0) return -1; uffd_flags = fcntl(uffd, F_GETFD, NULL); diff --git a/tools/testing/selftests/mm/uffd-common.h b/tools/testing/selftests/mm/uffd-common.h index 32e590ce9442..6068f2346b86 100644 --- a/tools/testing/selftests/mm/uffd-common.h +++ b/tools/testing/selftests/mm/uffd-common.h @@ -90,7 +90,7 @@ typedef struct uffd_test_ops uffd_test_ops_t; extern unsigned long nr_cpus, nr_pages, nr_pages_per_cpu, page_size; extern char *area_src, *area_src_alias, *area_dst, *area_dst_alias, *area_remap; extern int uffd, uffd_flags, finished, *pipefd, test_type; -extern bool map_shared, test_dev_userfaultfd; +extern bool map_shared; extern bool test_uffdio_wp; extern unsigned long long *count_verify; extern volatile bool test_uffdio_copy_eexist; diff --git a/tools/testing/selftests/mm/uffd-stress.c b/tools/testing/selftests/mm/uffd-stress.c index c0e804f05002..4e071a7d0ff5 100644 --- a/tools/testing/selftests/mm/uffd-stress.c +++ b/tools/testing/selftests/mm/uffd-stress.c @@ -55,8 +55,6 @@ pthread_attr_t attr; const char *examples = "# Run anonymous memory test on 100MiB region with 99999 bounces:\n" "./userfaultfd anon 100 99999\n\n" - "# Run the same anonymous memory test, but using /dev/userfaultfd:\n" - "./userfaultfd anon:dev 100 99999\n\n" "# Run share memory test on 1GiB region with 99 bounces:\n" "./userfaultfd shmem 1000 99\n\n" "# Run hugetlb memory test on 256MiB region with 50 bounces:\n" @@ -69,18 +67,9 @@ const char *examples = static void usage(void) { - fprintf(stderr, "\nUsage: ./userfaultfd " - "[hugetlbfs_file]\n\n"); + fprintf(stderr, "\nUsage: ./userfaultfd \n\n"); fprintf(stderr, "Supported : anon, hugetlb, " "hugetlb_shared, shmem\n\n"); - fprintf(stderr, "'Test mods' can be joined to the test type string with a ':'. " - "Supported mods:\n"); - fprintf(stderr, "\tsyscall - Use userfaultfd(2) (default)\n"); - fprintf(stderr, "\tdev - Use /dev/userfaultfd instead of userfaultfd(2)\n"); - fprintf(stderr, "\nExample test mod usage:\n"); - fprintf(stderr, "# Run anonymous memory test with /dev/userfaultfd:\n"); - fprintf(stderr, "./userfaultfd anon:dev 100 99999\n\n"); - fprintf(stderr, "Examples:\n\n"); fprintf(stderr, "%s", examples); exit(1); @@ -400,21 +389,9 @@ static void set_test_type(const char *type) static void parse_test_type_arg(const char *raw_type) { - char *buf = strdup(raw_type); uint64_t features = UFFD_API_FEATURES; - while (buf) { - const char *token = strsep(&buf, ":"); - - if (!test_type) - set_test_type(token); - else if (!strcmp(token, "dev")) - test_dev_userfaultfd = true; - else if (!strcmp(token, "syscall")) - test_dev_userfaultfd = false; - else - err("unrecognized test mod '%s'", token); - } + set_test_type(raw_type); if (!test_type) err("failed to parse test type argument: '%s'", raw_type); From patchwork Wed Apr 12 16:45:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209366 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 B294FC77B6E for ; Wed, 12 Apr 2023 16:45:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4FD4B90000D; Wed, 12 Apr 2023 12:45:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 485F1900003; Wed, 12 Apr 2023 12:45:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 34D2E90000D; Wed, 12 Apr 2023 12:45:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 1EE31900003 for ; Wed, 12 Apr 2023 12:45:54 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id EFE411A01AD for ; Wed, 12 Apr 2023 16:45:53 +0000 (UTC) X-FDA: 80673315786.15.7A24372 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf27.hostedemail.com (Postfix) with ESMTP id 8931940026 for ; Wed, 12 Apr 2023 16:45:51 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=DOeG+nrn; spf=pass (imf27.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@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=1681317951; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Z2yWZt1s7MuVGMeOCGLd+TTj5TTX+8gBX0BUmTSUDX0=; b=AjGrmiLYwVnJpeMSjJqPcE0Z1yxKdMbl4lvvy9DDzGDEUWE4VvEu79YZxvWDTGSuSe8HJy 469TZEqvJNkTQt5b1jmY9j/Py/4mNiOos4G/6ceQFNPQHKRcSeHAYf0hijcGgMUDa9ZAX/ ff7/deiuXzkFoE6iQmIVwresQ4dyjKM= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=DOeG+nrn; spf=pass (imf27.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681317951; a=rsa-sha256; cv=none; b=69x2vV6Hlk4D5a9O0PbGJkwygpK/5XjJ0uKri9AtxkH/SYEiMb2treTdjJ4bHlAHepAuae YSh3GBAvwjgqauwXwKT9UgrbJJr5UXAim3Bhucuc/721aK5+8BE5Z6UtB8FMs9kdTH2/Dc bSGVxDl2J5fdEJbPgYvKbGFZrluWth4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317950; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Z2yWZt1s7MuVGMeOCGLd+TTj5TTX+8gBX0BUmTSUDX0=; b=DOeG+nrnTeXq1IzGLe165crwF322vX7D+JeiC9MHkKeIVG932ih/9fEEKHejRX8dWzyCig MGWvb813CW42zT7lppQOfu0L/lFjt+BHbo7PQtsaouKc2Jtb1G2sMz1X5tnDjQ9DxHjw+J 5NC5Q2TXBHXtIJAPWPJhLVpGyExV4Ss= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-604-_Fsg0xqCMm-G9CA3K9FjkA-1; Wed, 12 Apr 2023 12:45:49 -0400 X-MC-Unique: _Fsg0xqCMm-G9CA3K9FjkA-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-3e699015faeso3548741cf.0 for ; Wed, 12 Apr 2023 09:45:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317948; x=1683909948; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Z2yWZt1s7MuVGMeOCGLd+TTj5TTX+8gBX0BUmTSUDX0=; b=dPLzUtH8TmsrIFvpGnu6oEejQbhRfVcA32HUE0VkPCGruoNW1r2ZAlBq7OIqKREnAu sLUHv3MpYGFKToRUWfvbcn0LxNdaJ8ldpc7HmgKGuE/C4sZkU/NqvzsrivVOjwdOhevl cUDebKPPzlA+GPMCawPtEqg+p6ObUqqPz1RJybsuGtGeYES3YyaC3ZFWV37DCMux1k2A 6CW8sPllXIZNjml6xoq5IxMZLlx0B2eRAbs/BWFGnqL9lbaG5rFMfYXwSVJp+GWuCGvH U9hiyzVZa9TG7J6zOBO/0i56UFjXi5j22c5CW0VYl2T66dj0+U2Wuw/7xd47QJ7lM+Rh S//Q== X-Gm-Message-State: AAQBX9el3HEOgGflUagm9aWQR+/EUDWiS2qF2dq1YAIkMuu/GpEnQe25 cro1doxnDAAuB1uQYkR06Ag2c0NljvR0CcAxyc8itC2SMygrE+AOK7d7xSDDNjWYkuYvy7gf1/c m0MLbgGhEFKtI3zJ5bp5rh51EUwDTqAfVaxqR8MXW4tHBz7M3gTpPjt0WgshGlrFDtNla X-Received: by 2002:a05:622a:19a1:b0:3e3:98cf:68ae with SMTP id u33-20020a05622a19a100b003e398cf68aemr5389676qtc.2.1681317948392; Wed, 12 Apr 2023 09:45:48 -0700 (PDT) X-Google-Smtp-Source: AKy350ZiKY7ANBKy64ZZqrbCk8PQr9/JPPi7k1BmBEe0htozZ6mrlT6vo8j3lhtJ4S3TO2Z85boE2w== X-Received: by 2002:a05:622a:19a1:b0:3e3:98cf:68ae with SMTP id u33-20020a05622a19a100b003e398cf68aemr5389622qtc.2.1681317947950; Wed, 12 Apr 2023 09:45:47 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id d23-20020a05620a141700b00746803d7e8dsm4761888qkj.113.2023.04.12.09.45.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:45:47 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Leonardo Bras Soares Passos , peterx@redhat.com, Mike Rapoport , Nadav Amit , Andrea Arcangeli , Mike Kravetz , David Hildenbrand , Andrew Morton , Axel Rasmussen Subject: [PATCH v2 30/31] selftests/mm: Add shmem-private test to uffd-stress Date: Wed, 12 Apr 2023 12:45:46 -0400 Message-Id: <20230412164546.329355-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: gfa5p5byepgp4gpkdybfjbhrdkzf3369 X-Rspamd-Queue-Id: 8931940026 X-HE-Tag: 1681317951-21457 X-HE-Meta: U2FsdGVkX1+EVh20VRbqKXbvqqkmQU3GEvxdnb81NatGtlfGrLQmmfKnQeGAXEFz8R1gcLLXgeh2g1OCuOufPIPPUerLNkikeXGM1xBY0Rg3pb15YhD0jKFsu1Qj0rO/L8BVlpM9Ux2z3KHhETL6eqC8VSCgse3ql9rPZqy24ZE3+6FWQAKaBF1WtZ/4QNLClTlLlD1gN1rKDBw6+UO3JZ17gogFi/grADHWYc5gCEL61L+wG4YK1rXOnsm5pSpiKkGN1A5SJI7Yef4qxkPGqQXXq6dnfphPVArOmlE+d8LIfR+bmInl1rEz3sFgnqpiMyxwbk+uMcZNIBq3gvJhTddn/LNVpxk6T5CfoWd+/cg51FeiH0GJpxz8d6CEd2vRqUA2cL1xKozEDo9ykj8lL+PJ36jDrSAxG6BtZK8oEli1sENEjksEjtzugAKAzyc/B09kPiKNdShLWExWZzgAfDpwWCc6jroLgIvw5rYu/ULvUks7VC8pHUZpgx92/FPhN2RTziX7Mu+659kzF+s74wKsPb9UE+oINILi9M5BvSCGrr7HcQkplIGQm5OlFcFyJ4y8b9sE0arMZ/+ckxrVQVdlsKygSMM/T56ubENO9Vt2lwZpRjinRlxKCdp5YVK1tUBE7k4/LVNnJjOUHwl17w8TDz0f4Fq1AWN73N7OYwdoj+j6VjPtpunwxPaBciK35Px/kRpUSSIx3qdfM9BXfkNAK2V0TIM0a5NI2pBOk/+i3pJA7/Nww1261ybBN/ITVTzdcwScEJKUXODM5c8aUXWOTb2WzyqI7r8C5JPl/YGDR+JZpm04sTGnlQqwJe4bxUf+SqAaEz8mvzHG5ohLcVocoSQmqBrFhUmFIYlZ8aiB2XQAd74qP4gAw8Fjv/HwMActrMQrMBqLyBrUjBu8RIvhnKVFBplnOPpO6S226Q4/EqCKqMYv3bw02oJ1eN4tMglr8zneeZAof1lBbvV 8QpmqDSH +DtpqvOT7I5+XHQhXNbtM8btdtw8aAU8NZ7qk6rWb8PUrXPhU8PwhaaAPIbB32skyfeydiowKm/P//k6HthDpnZHmN5kj0kitPGdaHRCuWHBcOXc2mVZKtXr9hkQ+H25clxT/MnxyehvkwbB13QqO5yOP2boajwUvAqlpfJYBB+u3BKccaaXzkjjj/tkuKQxGUYggXnDonKomVyTUewjfT3a9wWDQUO1wT+PgdVz5PPft5gSd3KbU7FzFe134vw8QisXbJsYb0+cLOi/UZyL2HMYb7TDFxFxJVOOOvtLCKjb6R2cZ6rmIo4nv8FkgdshVKxcfGT9oMot5RyLWFEo5bFRJT5NxmbODqZlUyLNjqd7cn4CGwnb/BptJX2Hyk16HtlOISed+aOQQPLyIplfu0pfoQP8BW/aPtUzwH5zhbFlWxj/ZaCH5TVb/IAdT3krxe6kHii+Ryx3nGRlPQCOh2ly/1HYbt3uM2xPM 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: The userfaultfd stress test never tested private shmem, which I think was overlooked long due. Add it so it matches with uffd unit test and it'll cover all memory supported with the three memory types. Meanwhile, rename the memory types a bit. Considering shared mem is the major use case for both shmem / hugetlbfs, changing from: anon, hugetlb, hugetlb_shared, shmem To (with shmem-private added): anon, hugetlb, hugetlb-private, shmem, shmem-private Add the shmem-private to run_vmtests.sh too. Signed-off-by: Peter Xu --- tools/testing/selftests/mm/run_vmtests.sh | 3 ++- tools/testing/selftests/mm/uffd-stress.c | 11 +++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/selftests/mm/run_vmtests.sh index ecc16ea6fc40..438eb49567b6 100644 --- a/tools/testing/selftests/mm/run_vmtests.sh +++ b/tools/testing/selftests/mm/run_vmtests.sh @@ -202,8 +202,9 @@ CATEGORY="userfaultfd" run_test ${uffd_stress_bin} anon 20 16 # Hugetlb tests require source and destination huge pages. Pass in half # the size ($half_ufd_size_MB), which is used for *each*. CATEGORY="userfaultfd" run_test ${uffd_stress_bin} hugetlb "$half_ufd_size_MB" 32 -CATEGORY="userfaultfd" run_test ${uffd_stress_bin} hugetlb_shared "$half_ufd_size_MB" 32 +CATEGORY="userfaultfd" run_test ${uffd_stress_bin} hugetlb-private "$half_ufd_size_MB" 32 CATEGORY="userfaultfd" run_test ${uffd_stress_bin} shmem 20 16 +CATEGORY="userfaultfd" run_test ${uffd_stress_bin} shmem-private 20 16 #cleanup echo "$nr_hugepgs" > /proc/sys/vm/nr_hugepages diff --git a/tools/testing/selftests/mm/uffd-stress.c b/tools/testing/selftests/mm/uffd-stress.c index 4e071a7d0ff5..f1ad9eef1c3a 100644 --- a/tools/testing/selftests/mm/uffd-stress.c +++ b/tools/testing/selftests/mm/uffd-stress.c @@ -59,8 +59,8 @@ const char *examples = "./userfaultfd shmem 1000 99\n\n" "# Run hugetlb memory test on 256MiB region with 50 bounces:\n" "./userfaultfd hugetlb 256 50\n\n" - "# Run the same hugetlb test but using shared file:\n" - "./userfaultfd hugetlb_shared 256 50\n\n" + "# Run the same hugetlb test but using private file:\n" + "./userfaultfd hugetlb-private 256 50\n\n" "# 10MiB-~6GiB 999 bounces anonymous test, " "continue forever unless an error triggers\n" "while ./userfaultfd anon $[RANDOM % 6000 + 10] 999; do true; done\n\n"; @@ -69,7 +69,7 @@ static void usage(void) { fprintf(stderr, "\nUsage: ./userfaultfd \n\n"); fprintf(stderr, "Supported : anon, hugetlb, " - "hugetlb_shared, shmem\n\n"); + "hugetlb-private, shmem, shmem-private\n\n"); fprintf(stderr, "Examples:\n\n"); fprintf(stderr, "%s", examples); exit(1); @@ -376,14 +376,17 @@ static void set_test_type(const char *type) } else if (!strcmp(type, "hugetlb")) { test_type = TEST_HUGETLB; uffd_test_ops = &hugetlb_uffd_test_ops; - } else if (!strcmp(type, "hugetlb_shared")) { map_shared = true; + } else if (!strcmp(type, "hugetlb-private")) { test_type = TEST_HUGETLB; uffd_test_ops = &hugetlb_uffd_test_ops; } else if (!strcmp(type, "shmem")) { map_shared = true; test_type = TEST_SHMEM; uffd_test_ops = &shmem_uffd_test_ops; + } else if (!strcmp(type, "shmem-private")) { + test_type = TEST_SHMEM; + uffd_test_ops = &shmem_uffd_test_ops; } } From patchwork Wed Apr 12 16:45:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209367 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 67723C77B6F for ; Wed, 12 Apr 2023 16:45:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 01CE090000E; Wed, 12 Apr 2023 12:45:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EE69D900003; Wed, 12 Apr 2023 12:45:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF5C290000E; Wed, 12 Apr 2023 12:45:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id B58D1900003 for ; Wed, 12 Apr 2023 12:45:56 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 730B8AACD1 for ; Wed, 12 Apr 2023 16:45:56 +0000 (UTC) X-FDA: 80673315912.24.C60CE2D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf16.hostedemail.com (Postfix) with ESMTP id 493D1180016 for ; Wed, 12 Apr 2023 16:45:54 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=b2thj6Ce; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf16.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681317954; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=TwrBVEbuHxz2Oj1oTVxriRpco4XXvHrMi+8R/zKrUWA=; b=KTs8wVx6XV69tkq22QiYs7xOws8I4R3oVvGrRB/vs8n5HB4ahbDFMBZsS/pguPoWHyOYHp moXf1nkQNB3WtX/J8+aQ8oX0OjsP7jYlEuRwCibnZiBVbxcs80HPT42fxJc6S8q5Gtph5W bw1bbVaq16rEYKA48OC1wbbgvSSEoRU= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=b2thj6Ce; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf16.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681317954; a=rsa-sha256; cv=none; b=r+Qa8sxmFm+fVf3Ud2v5e1EIqdRyOG/Z4ovoxZAgc5DXb2y5xB10X6vlDiq40Jhput6QKH 6x8E8QF8NFsxee2iKCIeP/KcTGZhsW2LPihKerm8kiMPjCGJHkjrLCgZD7YjJ08IF40dBs NVUT2zq7yLk9vrARbH2+714l1beYHgI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317953; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TwrBVEbuHxz2Oj1oTVxriRpco4XXvHrMi+8R/zKrUWA=; b=b2thj6Cex2dSOyDUefUFUzk7RMnD49NFLqXZsf4/KfGgYgLTAaWkb+2K1vVBItNwVKTeAX 77gxs0LNZ/hN339JFAa4YQsSWGwvmm+8uIzhToiAYs/c3h7XmyemM5M/BwiZFdiB+lHGdq eGP+TcVMlTthXdsCj9Z167Ss9+jIiaM= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-329-6rj1cC3bMtag-7s7Ru0AJQ-1; Wed, 12 Apr 2023 12:45:52 -0400 X-MC-Unique: 6rj1cC3bMtag-7s7Ru0AJQ-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-74acb477be6so2339985a.1 for ; Wed, 12 Apr 2023 09:45:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317951; x=1683909951; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TwrBVEbuHxz2Oj1oTVxriRpco4XXvHrMi+8R/zKrUWA=; b=KXdni2mIRr7yK9bBo5oU4c36KanSWN86T+1NStNx/oEWRmhyUM5hEEYTuk2/bnl2Lj fueRygQllrfxa2DK2xh16qU2dAgwYQNdvSw26E4pvRm6uVlQ5DWw47MPcdFbwjedQ7dO G9EsjPfTW2G9et//g53bdNtuwhhhyLP2lTrqQ0cQp3+KsN64IcznmMSefPYC6cBbL8Tp L8UAfLEDcIbq//IdsTuwzkQPw+Yr8GfA5d28yhGbQeZIy0a+aGk0hId4rmp8iWP7SMCx LUnOlg+2L13GrF3kzqHxurXx4PYPOmeeEfsNLB3pRRRhx1BkocwWtKPSR/clyfxA3+Hg gZDQ== X-Gm-Message-State: AAQBX9fFhnbuPBUWt5ENlnieSxJJLl7F+g7K6TvoDG3ZFwe/w3ZNHdjC Q+oqS1i2lJLlblt/WO2sAiUSdsIyJkHFQxaq9+jzalySql18eTAamFHnP9mbB6tlUZbHEDEbXcL Dzm328M/F1VSOfaFz6SzGVWPQLGqbqahaY87Y6meC9oxdryenQxb5+6YQ/L7vO89tHK+X X-Received: by 2002:a05:6214:529e:b0:532:141d:3750 with SMTP id kj30-20020a056214529e00b00532141d3750mr4520016qvb.2.1681317951219; Wed, 12 Apr 2023 09:45:51 -0700 (PDT) X-Google-Smtp-Source: AKy350bpuR8W/T8tBiH5wpuCxkcIk4HxIzNVlOw/zbLXydj3bE4PGonuqRLOxkqDMl9QuHI+HTiqgA== X-Received: by 2002:a05:6214:529e:b0:532:141d:3750 with SMTP id kj30-20020a056214529e00b00532141d3750mr4519973qvb.2.1681317950777; Wed, 12 Apr 2023 09:45:50 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id k5-20020ad44205000000b005ef447e24adsm416733qvp.19.2023.04.12.09.45.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:45:50 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Leonardo Bras Soares Passos , peterx@redhat.com, Mike Rapoport , Nadav Amit , Andrea Arcangeli , Mike Kravetz , David Hildenbrand , Andrew Morton , Axel Rasmussen Subject: [PATCH v2 31/31] selftests/mm: Add uffdio register ioctls test Date: Wed, 12 Apr 2023 12:45:48 -0400 Message-Id: <20230412164548.329376-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 493D1180016 X-Stat-Signature: cbewbm5o561fhzitdwwwyqhh8nisfi34 X-HE-Tag: 1681317954-653383 X-HE-Meta: U2FsdGVkX18aUr96IogbY+7K46AY81W0E9LB66o9lVLGfDcWt3rP1x51cVyxBC5M5Nqtp03L1QyGk7WeR1N2ImCY/SDC923BESxuU0YaFf8PqJMe2glLj2XqqVhA46TemZEZQWxPcN1GQyyhT2pu66/XoW1Q6D0a4mp9NCPKAyBWGB3QvuNucUjFKSYoZjvpqHml/j2WYYbRX36czNemi8UR1IPTnS+DO6t5sOak4Ulk2ubT8/Oi0tvlO85GeNnVJmWT3Gst56hYTCBUh2m2weSXV/wK0mIT3D4dm7zok0hTVq88MnINbUIXkluB1nXGJrJ1LFHq+I/NEz/K/uIDcxOVcej6XttE3XIzhkDRB8BeU2xlhcmiFOU7MAOBagdlBoH1zc4witFqPJTLwzTKq6KK8VMC7E7xzdAO9cUOnpO7j4nj8uazDaUV2ONK2AYLSEI6mMSOFHTmFMLX2zarPLZp8NEV/35dInu6SIIUALcLqagPfMaas7FJSrrS08Z1LOYLGAAsb+0zIaQ6CuhxPQCfKUYo2ZYE6EE/OtQ3CiaV5ntQRKsCXScVPWKncjuBSqXcAkSyoAn9CCTdAva0Ew4zMr36CmzLtcaa9B9a0yLLJN7A3tvhfUe5e2wou+yX8S6p8KaS3QSoqtGjmT9MOj/WM5D+WyFks6V2FCUrA64lhSMuS8eY5e5xn+E9ShQCASBx3DqHyRKX4lce0gQkgj/LU3RMTxsoVMSnnGGBvQRNnjmM+iKh6LiSE49cUybYMQk4S4pCiWwjQNSYA8qGXk4dx7E/5Bggdz6SnTNRFwJKlE9l7qjFPglbICT/yXN/TFC4OvG55xWgjGkXZP6hduUMnnfrusEmkUKiqxsqSWvzgs3QGcSix8dCKPMnvfSe8+fOp68BVpgJKEenuwuyyf+OOIuXslOyCfnsFR7JKnfrtXQhVPT2t5TB/7BP5oK5TKeRS8qT1R/YkIfzUII mbMa4gyx hrgPwuTJscciyE+80/bKgtMAs8eclVCukqeMSzDj0wSbAVpp96r1AC1d65B0XgI7WvhQwv+b/+/qPHSFd58Q5MzNqZyQqUJ5m7yWK/XPYC+f6tQ0oXrCxZ4YWUzyyvCTHdb4dHCD4D/mL7h1zh1mbK9J+Km/N1vMfQRFZRBpEoLLsyDKBFlB1dZiBPKY5TKTe3cT36o51aPvBneMKAJUld5jpa5saw+vuMZ1Gf/zX3foFiZqlHVXGf2qTFvDVIFZyrpDPRdhBd5gFjx4YEkkbw9E3Xm7axV/RNLLEEI/+5kVzJE66uQ2nOFRm/WVvCUHCEU6HUNpYWLVuVTAcUQXZb1XMWxw6iW6Q+1qJjwy15zsDDg+jAPPfGhez25u+QIg5tG1JFkcHNUggOeNoUC1YnUyYfSR3lKVPoaubdBzSRzKupu1ggrOmP7y9m/eC7TiSWU84jC5wA5+IU8VG3P6MsNVoDu6M7wETyNuB 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: This new test tests against the returned ioctls from UFFDIO_REGISTER, where put into uffdio_register.ioctls. This also tests the expected failure cases of UFFDIO_REGISTER, aka: - Register with empty mode should fail with -EINVAL - Register minor without page cache (anon) should fail with -EINVAL Signed-off-by: Peter Xu --- tools/testing/selftests/mm/uffd-unit-tests.c | 112 ++++++++++++++++--- 1 file changed, 97 insertions(+), 15 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/selftests/mm/uffd-unit-tests.c index b0acf558e8cb..d871bf732e62 100644 --- a/tools/testing/selftests/mm/uffd-unit-tests.c +++ b/tools/testing/selftests/mm/uffd-unit-tests.c @@ -62,8 +62,14 @@ mem_type_t mem_types[] = { }, }; +/* Arguments to be passed over to each uffd unit test */ +struct uffd_test_args { + mem_type_t *mem_type; +}; +typedef struct uffd_test_args uffd_test_args_t; + /* Returns: UFFD_TEST_* */ -typedef void (*uffd_test_fn)(void); +typedef void (*uffd_test_fn)(uffd_test_args_t *); typedef struct { const char *name; @@ -172,8 +178,9 @@ static int test_uffd_api(bool use_dev) * This function initializes the global variables. TODO: remove global * vars and then remove this. */ -static int uffd_setup_environment(uffd_test_case_t *test, mem_type_t *mem_type, - const char **errmsg) +static int +uffd_setup_environment(uffd_test_args_t *args, uffd_test_case_t *test, + mem_type_t *mem_type, const char **errmsg) { map_shared = mem_type->shared; uffd_test_ops = mem_type->mem_ops; @@ -187,6 +194,9 @@ static int uffd_setup_environment(uffd_test_case_t *test, mem_type_t *mem_type, /* TODO: remove this global var.. it's so ugly */ nr_cpus = 1; + /* Initialize test arguments */ + args->mem_type = mem_type; + return uffd_test_ctx_init(test->uffd_feature_required, errmsg); } @@ -239,7 +249,7 @@ static int pagemap_test_fork(bool present) return result; } -static void uffd_wp_unpopulated_test(void) +static void uffd_wp_unpopulated_test(uffd_test_args_t *args) { uint64_t value; int pagemap_fd; @@ -285,7 +295,7 @@ static void uffd_wp_unpopulated_test(void) uffd_test_pass(); } -static void uffd_pagemap_test(void) +static void uffd_pagemap_test(uffd_test_args_t *args) { int pagemap_fd; uint64_t value; @@ -415,17 +425,17 @@ static void uffd_minor_test_common(bool test_collapse, bool test_wp) uffd_test_pass(); } -void uffd_minor_test(void) +void uffd_minor_test(uffd_test_args_t *args) { uffd_minor_test_common(false, false); } -void uffd_minor_wp_test(void) +void uffd_minor_wp_test(uffd_test_args_t *args) { uffd_minor_test_common(false, true); } -void uffd_minor_collapse_test(void) +void uffd_minor_collapse_test(uffd_test_args_t *args) { uffd_minor_test_common(true, false); } @@ -603,12 +613,12 @@ static void uffd_sigbus_test_common(bool wp) uffd_test_pass(); } -static void uffd_sigbus_test(void) +static void uffd_sigbus_test(uffd_test_args_t *args) { uffd_sigbus_test_common(false); } -static void uffd_sigbus_wp_test(void) +static void uffd_sigbus_wp_test(uffd_test_args_t *args) { uffd_sigbus_test_common(true); } @@ -651,12 +661,12 @@ static void uffd_events_test_common(bool wp) uffd_test_pass(); } -static void uffd_events_test(void) +static void uffd_events_test(uffd_test_args_t *args) { uffd_events_test_common(false); } -static void uffd_events_wp_test(void) +static void uffd_events_wp_test(uffd_test_args_t *args) { uffd_events_test_common(true); } @@ -724,7 +734,7 @@ uffd_register_detect_zeropage(int uffd, void *addr, uint64_t len) } /* exercise UFFDIO_ZEROPAGE */ -static void uffd_zeropage_test(void) +static void uffd_zeropage_test(uffd_test_args_t *args) { bool has_zeropage; int i; @@ -748,7 +758,77 @@ static void uffd_zeropage_test(void) uffd_test_pass(); } +/* + * Test the returned uffdio_register.ioctls with different register modes. + * Note that _UFFDIO_ZEROPAGE is tested separately in the zeropage test. + */ +static void +do_register_ioctls_test(uffd_test_args_t *args, bool miss, bool wp, bool minor) +{ + uint64_t ioctls = 0, expected = BIT_ULL(_UFFDIO_WAKE); + mem_type_t *mem_type = args->mem_type; + int ret; + + ret = uffd_register_with_ioctls(uffd, area_dst, page_size, + miss, wp, minor, &ioctls); + + /* + * Handle special cases of UFFDIO_REGISTER here where it should + * just fail with -EINVAL first.. + * + * Case 1: register MINOR on anon + * Case 2: register with no mode selected + */ + if ((minor && (mem_type->mem_flag == MEM_ANON)) || + (!miss && !wp && !minor)) { + if (ret != -EINVAL) + err("register (miss=%d, wp=%d, minor=%d) failed " + "with wrong errno=%d", miss, wp, minor, ret); + return; + } + + /* UFFDIO_REGISTER should succeed, then check ioctls returned */ + if (miss) + expected |= BIT_ULL(_UFFDIO_COPY); + if (wp) + expected |= BIT_ULL(_UFFDIO_WRITEPROTECT); + if (minor) + expected |= BIT_ULL(_UFFDIO_CONTINUE); + + if ((ioctls & expected) != expected) + err("unexpected uffdio_register.ioctls " + "(miss=%d, wp=%d, minor=%d): expected=0x%"PRIx64", " + "returned=0x%"PRIx64, miss, wp, minor, expected, ioctls); + + if (uffd_unregister(uffd, area_dst, page_size)) + err("unregister"); +} + +static void uffd_register_ioctls_test(uffd_test_args_t *args) +{ + int miss, wp, minor; + + for (miss = 0; miss <= 1; miss++) + for (wp = 0; wp <= 1; wp++) + for (minor = 0; minor <= 1; minor++) + do_register_ioctls_test(args, miss, wp, minor); + + uffd_test_pass(); +} + uffd_test_case_t uffd_tests[] = { + { + /* Test returned uffdio_register.ioctls. */ + .name = "register-ioctls", + .uffd_fn = uffd_register_ioctls_test, + .mem_targets = MEM_ALL, + .uffd_feature_required = UFFD_FEATURE_MISSING_HUGETLBFS | + UFFD_FEATURE_MISSING_SHMEM | + UFFD_FEATURE_PAGEFAULT_FLAG_WP | + UFFD_FEATURE_WP_HUGETLBFS_SHMEM | + UFFD_FEATURE_MINOR_HUGETLBFS | + UFFD_FEATURE_MINOR_SHMEM, + }, { .name = "zeropage", .uffd_fn = uffd_zeropage_test, @@ -835,6 +915,7 @@ int main(int argc, char *argv[]) int n_mems = sizeof(mem_types) / sizeof(mem_type_t); uffd_test_case_t *test; mem_type_t *mem_type; + uffd_test_args_t args; char test_name[128]; const char *errmsg; int has_uffd; @@ -862,11 +943,12 @@ int main(int argc, char *argv[]) uffd_test_skip("feature missing"); continue; } - if (uffd_setup_environment(test, mem_type, &errmsg)) { + if (uffd_setup_environment(&args, test, mem_type, + &errmsg)) { uffd_test_skip(errmsg); continue; } - test->uffd_fn(); + test->uffd_fn(&args); } }