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: 82593 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp479440vqo; Wed, 12 Apr 2023 10:05:47 -0700 (PDT) X-Google-Smtp-Source: AKy350ZcLcZhLiGXOdj4Qwqh5AiGIjpc4Ib8CuOmXgHt10U66H5jO9C7efOXF0bwF6KqSJAsOTP/ X-Received: by 2002:a17:902:cec3:b0:1a5:2993:8aa6 with SMTP id d3-20020a170902cec300b001a529938aa6mr21373104plg.63.1681319147049; Wed, 12 Apr 2023 10:05:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681319147; cv=none; d=google.com; s=arc-20160816; b=zqWbk/20iutGfiw1OeCbbjJqdzYhpIzYwBB61y8tLokRYyikVdR0erBqVQvz/L3rz7 A07s2QEEaekBKzpp9IPYmbU3dg4uOVQvu166JNvwCS2gclL73cIQukaRU0vQ6rewO8Nw Glh3mPXUGHT3dcTQ1gUou7roFfdEnJozqohymS6xdI0EAJkoEXVNU4neBAiLWspYCVby u+oLjfUbswLKfZYOd1rH9Pg9aUYCaY/8GcnlSoKGTrfsYX+g/GGUNlpRryJZokcpYjFm QRjwx2mj8cS4XwOqFMX7Q0k6uEIPmfUbkziFEvufz8M1u/XonM8UTDIf4QbxdW6QKNkm 5UtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=09jtKKMdBkZ99/jQ3MHG3Gpu4kZKeE61xD5S9ADSCnE=; b=Rb08ed8j3Da3E/a5ixhKG/8NXCUvx7RBEjgyMfrBz6Jw1dV87LCf6B5A77BAZuQ/sA FKv4+h603AINtAZmZyQiYse3+6KtJbQzNLYoBJftVjDckwHVPygzDVX5srTZqqobk1eb jLRCxM7UtHukcjuLXYUCiHVKf+K6Fwt5oC6yulwO1OPe49u7hCM5nJwOErcdIQKkCmBq N/1gosqXeqPIG4E1097zJbLZSD2ghJiwHugIM9IkTWMz+pN5DDiD1ATytU+wiUGP6lTJ RGu9+EbY/EdwtB/EdehgueKV2MgSrKaZwPCZmKc6+W5d1mzhqU8FUBJCP5ojXbhomY6s Otvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QQL4bDt5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id km3-20020a17090327c300b0019f25dae4f5si15829995plb.198.2023.04.12.10.05.33; Wed, 12 Apr 2023 10:05:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QQL4bDt5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230332AbjDLQmW (ORCPT + 99 others); Wed, 12 Apr 2023 12:42:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230110AbjDLQmP (ORCPT ); Wed, 12 Apr 2023 12:42:15 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06398268B for ; Wed, 12 Apr 2023 09:41:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317687; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=09jtKKMdBkZ99/jQ3MHG3Gpu4kZKeE61xD5S9ADSCnE=; b=QQL4bDt5LMYcrAWuj9OeLBN47vVfL3HJybzVJlLa9Ru7R8oPNjLO30qg4TarXSvIQ2GAh+ MobKBXMajBrxEipfW09FB0GIBom6h8UnBlHtFTC0lpr+7C5Z8afSoC95BFvxFU7tTOEnHH +RD3bPjHQQVRgv57/CzIiNf2+KLw00s= 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-222-vzCsdpQ7OzepawJY9Cp-HA-1; Wed, 12 Apr 2023 12:39:27 -0400 X-MC-Unique: vzCsdpQ7OzepawJY9Cp-HA-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-5ef4122d2dbso1347536d6.1 for ; Wed, 12 Apr 2023 09:39:26 -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=ijjePcHlUR0deFx6fOVFQbKKoZBFQNmRoWpOZICwPua3Bbz2c5heXOgCmRQiQSkCxm Ij9/QMAc0OW3PCIeZgP7DzqYLKPVL4nPBFJbW8TVuNNH0YEA9gHvuzhwEAvZzV9IjQk0 psQ9Yaok4J2pv1DQVxtXR66Q5c2ckjfDNeVw5/Pf7x65jh/EYZNfZ+gEdD3U3Zi+Z67V s8esR22rXozSdmFO+xiwzwIw3bTXUovUW6MjTtSaCZQc2vumx0UUaPFWiR/4oP/o/K2c M7FThfF/mENFmY4ZBNLF+41t8y0bAv/hFBtWFAUUF8G8a6LcCRucJFLNUiN2fquQ1ulq T9wQ== X-Gm-Message-State: AAQBX9ckovkZejSY6CJqHbUWYlWkk+7DpY8l7+uIvU5XsiL1cDQiaA5E +m6CzlaBHVm9EaKgNYjJ5f4okDlo60AniHYKd3fy8cDRGPWTPaIBC20GRz/gXVB/e3eT6Z6rM+t Q/O2wpSsqq3qoM2NppD2cxzng X-Received: by 2002:a05:6214:401a:b0:5ea:a212:3fe1 with SMTP id kd26-20020a056214401a00b005eaa2123fe1mr4433892qvb.4.1681317565691; Wed, 12 Apr 2023 09:39:25 -0700 (PDT) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762990906337987517?= X-GMAIL-MSGID: =?utf-8?q?1762990906337987517?= 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: 82590 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp478883vqo; Wed, 12 Apr 2023 10:05:07 -0700 (PDT) X-Google-Smtp-Source: AKy350bNNoR2CrXOHq6X+Uqte3fuTYvuCu1L59qijireEvtznyYG1Q9hjpF5EKDj3u0qT2erdvPH X-Received: by 2002:a17:906:2011:b0:93d:7ad:a954 with SMTP id 17-20020a170906201100b0093d07ada954mr15520248ejo.37.1681319107375; Wed, 12 Apr 2023 10:05:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681319107; cv=none; d=google.com; s=arc-20160816; b=bIebJggE3Yx7SCdS2agw24sE2+yWFxjUSgw7qprygEM0fG+oNz/O0vXcqiOZQP8Q8S MRSTPBGBE8ciI8lCCTTS4NIG9sQAlQ56GRVeEdECwcNV82nb4vPLz8pOLxuCPVgluYpn BrIfWh5ONWAU34dLT250zRJDghBn3QIjEtkhzHmMdnw61xmv4snsGZV77AJ3vPbAiKTz RJ7SP5KUAkTTnJn6A7Tv57C1K+zUs7k0rxS4TA9RbOT+QgNaG8oneGGp+B0jxLtivjDC uCdFTvzW5+H9qGOtgIw9rUI+csFQqsFT4QeTy6rWnIySDl0WuYNjuqMAY+KzN/X+Xg6L ZhcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=w5yugiaVpJpS0wWKD2pcIMAyJ75fmPDFVn927vHr9+E=; b=D5y+/jpOPNG/RzTHGF8xy8kVtqjrRMCImFQcblRc80Z9Qc01bV+0wVwMcEFaarZ8t/ xM2QJTbntK1BMSwYyJF6rdvesa3uocPLyZk2YWb/umwsa3HCQnRGvraTYg2s5NghVwdp dgiXpkNTRTsDR5apXmazaLOeK3vVsfxZyeO9UvPD8sP4gJstq6iaAwXdLmlBO1Y25hDa 64K0mroNLFrZZFSkAWeyvT9oVz5pzGL4cbEHI9qVT7r99honGOtr8uYIWbk7ZSUB8EPm kIXNZUtAO7nMdnJCYUponXrpiKWiNGa7WdPcXhoqzHvzikTVVfYjhfg7ZVpLxwl7xxMd Ke+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WgkLcxA6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w7-20020a17090649c700b0092c8da1e5edsi4565164ejv.611.2023.04.12.10.04.42; Wed, 12 Apr 2023 10:05:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WgkLcxA6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230103AbjDLQmI (ORCPT + 99 others); Wed, 12 Apr 2023 12:42:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229709AbjDLQmH (ORCPT ); Wed, 12 Apr 2023 12:42:07 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF38E65A7 for ; Wed, 12 Apr 2023 09:41:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317681; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w5yugiaVpJpS0wWKD2pcIMAyJ75fmPDFVn927vHr9+E=; b=WgkLcxA6Y1Jj3D7o8ueoQB9ncfjX4iUBWTW6/enRg2Pnknf+2O17Y90/EDXFayb2zNiZBI oXcp7Q1H6pIYNFazD12k4vEeGIQCDyrimbOQaoUmLuNKjFpllkjQM3aEj3iPjROXxeaEKj 7JBE2eiogDJdgFiYQaDaM8JZjmG4Xaw= 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-642-vT4JTqURPv-Owv7_JHLZRw-1; Wed, 12 Apr 2023 12:41:19 -0400 X-MC-Unique: vT4JTqURPv-Owv7_JHLZRw-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-74a90355636so62093285a.0 for ; Wed, 12 Apr 2023 09:41:19 -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=gwG/DUZCHUXeYO76dCE2jvseAKraoJmOdKA61mj65Vfot+Ni48B9NOUnCnAQX3c57k I6Y4Tnl7Qv4uY5ZmIz/qUqvn932KF8EwayDk1LJ5ayUyMvtPCk5KkDO5U5Z6uH16R7d7 HabnUbQRrLV9iOA8AkkPeyPlwlTOBNSJGAaMHboC/zqiV0FfLsxJoNYeemodtrb8ut0X sfl3bxtkjQhdYLfv2yxJEcsazY0AnagSpiUO47HODlOGNkI6QQqmYN+OTmKvvOy1gKqY CGvrybWT7qURvZ1mAnVz0bA34o6VzhYENPuOherWKJMz3oNotkqmmnLbEc9RhWqVuhDz MR9A== X-Gm-Message-State: AAQBX9cgbAqBBRVSwRzDQfNhGysMp3qrujwRnxzusiSmX+vGbtk4QefD 0Ydx3UTsti45/n/t29svT0gz/0VPLFJwGsSAyZzkdco6TepQuaFvCmHNYMlYE6LBrBmKdVDXLMA mEmMFhDikQdZgus1OcBW0VRMg4ABL+HboVL13O46re2/ldBo5kdLhD2DD0EefBfsPxBGsQpi4tj +tY4lTkg== X-Received: by 2002:a05:622a:1a90:b0:3e6:3af1:de7a with SMTP id s16-20020a05622a1a9000b003e63af1de7amr29098350qtc.4.1681317677642; Wed, 12 Apr 2023 09:41:17 -0700 (PDT) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762990864332560511?= X-GMAIL-MSGID: =?utf-8?q?1762990864332560511?= 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: 82599 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp480690vqo; Wed, 12 Apr 2023 10:07:24 -0700 (PDT) X-Google-Smtp-Source: AKy350Y/2gpLjK8UqZBetv6DJpIeTdXwdV8x1cf75IT8v1iElpCqq4mOj4Bk3I+ESkDDCj0eHsMN X-Received: by 2002:a62:1aca:0:b0:634:4f6:86da with SMTP id a193-20020a621aca000000b0063404f686damr7664037pfa.28.1681319243912; Wed, 12 Apr 2023 10:07:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681319243; cv=none; d=google.com; s=arc-20160816; b=GpW2v4Ju0AsD9muMeuFjMIc56pda+CWvCGSxSHVr5gxeP/nURniMxVTvCPbTVyi5ru eL8Ta4VL5TBzPvSj/ThrRizhc9wsk3zY2Q4ZSNJXa8eU47hcI08rnQ0xbh9tPtxNFhBD w1714zNGiyCme6bIuAXRLI7JNvGVfkuQkRfCu/nWwm8RHMwOZfzCeS48Ijn9htmkVnq8 1jKWU6pkUEjJ8/JFs9eJnWccpJ+7iIPrOSugKHIb8OoH5Qi4QyKPY25HiXPqiAb/WV5P WV/1HunC85D0VWZk1vY7/ACuKuWRjfM/ZDCw+EpHEFxr0VK4SK+V6Gmj6FEsbmE8PQm3 xcug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=UoyMoOjoICnnEVcPuqz2r5voAg7rax1INu5Vpam+Fw4=; b=dzD0KpXCtq7dV/UvPb21PqGTUvJ5m5JJBBwXUZ8YyjoKvVetaJ7yCj75p27LZ2Vzds wAZ8mjU9FxE9PsEiMRj7S2KhtFhS5inMub6/kn+Z685pM0qF3wdTBMzCXzsk3FwxYiaT 1FvXyvmATORW/rwVMoMw4jp5o45pIMVPudw9z75tx7B9Fbx0VtBV+FygpUSkCXwzPKww rvE/VR1n1Pg0AiXqHjMWddnyvXMTRNXmZ0k8SUGrilIATjcQzf2oTGf6cjn8jr4/Pyed OQm5rmZap8cagiXfyxZ3og9QMQnCy2GXCmXLVfI2yQbXxZVSGbIXhJGl+z1F3/CnYTUV vhdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DsW8QCLT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 196-20020a6302cd000000b00517a9e737c6si12867455pgc.311.2023.04.12.10.07.07; Wed, 12 Apr 2023 10:07:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DsW8QCLT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230137AbjDLQmM (ORCPT + 99 others); Wed, 12 Apr 2023 12:42:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230163AbjDLQmJ (ORCPT ); Wed, 12 Apr 2023 12:42:09 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FF6E65BF for ; Wed, 12 Apr 2023 09:41:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317683; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UoyMoOjoICnnEVcPuqz2r5voAg7rax1INu5Vpam+Fw4=; b=DsW8QCLTxgKgqLWuKHN+nmBVuozPrIYOj/xyX0lhKIAY3mERfnJvMml8ao+lblCWGt+VDc VZ91yPhSNp5+3NAa32+egWsR4q1LkB1x8Qtjj+mlKYwpREkIhIf0xMgKwAUYBDyIuaPYIr pxmxwchFZDpRK4bkeeXgeQ4izaKghp4= 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-407-bYdX4MbmP5GstWRWDxWnVg-1; Wed, 12 Apr 2023 12:41:22 -0400 X-MC-Unique: bYdX4MbmP5GstWRWDxWnVg-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-5ea572ef499so7654656d6.1 for ; Wed, 12 Apr 2023 09:41:22 -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=aHDfNcKXHZisfoZS/iY7v/w3uhmsfOJQXDlSa3NV7URX6xhjz6bBSdCXVu5GN2B4EI uHUhmvOxmoQ05kYKu38PxItx2ebWvPm5MOIXbsH/bTT2xYRWeacuS4MMdxSpMZLW4hpi AFMN6ZrWD8953wvbGyua1/qB8nsUUdBPQX8z96fJd2U6DmIgKzC6AwA91Qq+2ed9IQuf 1XLEFR5Po/+VhlvrMbi2UnSN/E0yClZRNzAzjTCokgWbc3KAy/WF1aSMrss0vZReJn+9 Iqy+kQRInnm00XW6DuYp9sax5Y0EmN9RTsTZ1oeFQj9rBQGniLZ7meath7PStV9VcqCl aCLQ== X-Gm-Message-State: AAQBX9f+UP/ll6eZbAIsbZBpV0a171X0PnmBF5ivnfdOHYkTCqEYSun5 yjgsW8hQ1NKMH/BeFK+BhrUJ0SjIzJGfTdO5Ept4m1pPeepke8ExXymD1+laTN4w5L0/sEl+47K sKUiRpWu2VTIbuhq4F4EVd1q+COxm66xq+1HJ9KUHOddR5za7FiOW95Mp54ozZTFdwGyxQXprnh qfvsJ/8w== X-Received: by 2002:a05:6214:5290:b0:5ed:c96e:ca4a with SMTP id kj16-20020a056214529000b005edc96eca4amr14516826qvb.1.1681317681037; Wed, 12 Apr 2023 09:41:21 -0700 (PDT) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762991007508508290?= X-GMAIL-MSGID: =?utf-8?q?1762991007508508290?= 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: 82584 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp476317vqo; Wed, 12 Apr 2023 10:02:15 -0700 (PDT) X-Google-Smtp-Source: AKy350bHUiIdLBVvqmNipZbk4aYWoLyYA37A3/P2TyQ5y9k4XZSI4TgaCRC9gYsTpcTUxroITXhd X-Received: by 2002:aa7:d610:0:b0:505:74d:d9e with SMTP id c16-20020aa7d610000000b00505074d0d9emr1875377edr.16.1681318935536; Wed, 12 Apr 2023 10:02:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681318935; cv=none; d=google.com; s=arc-20160816; b=IHmJIJEbMLHkA+702nZddsyliADnhVC4tKqervOAKGZXeedF+XbkTv/Js+Hplotohp ouXu8Yv1U8fXG1pHQ71kwkr8CtaTWozm/q2Jfg1SX+YoCWj/fturUX4yvazQQYz5Cspk ftAou3ch5wzlzLrWJ6thtlxhpdTQ2ctu3mW5Gc5MiPAbwyNpQbfNgC8LEL9XU+wqy6fI EZXGFZ3gKHRW6+g33BzhtKA3+4P/h+5mHI+8uPGAUR7PKUNDY/1lO9MVPXZiGumAz6iQ X+bKu4sqc/nK3qZ85csEbWCZXFhrD0eaQ60s/lus82kgPpBXOVH9IFgy5N1XjA29ppJT Jy/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=wXTqxDSTsrRiAkVZ6NC5Z+aMCLpRXkWfeIKb5BVB8IM=; b=nk02QGGg/zsn7Fgm0ZQW/iK8EqMjqZNJSKfLGRRh/b3SGD0ciSVWNSK+FJwx+s44fy 2gYjtl7MA+EyRIgoCWfnbhGDkB1oG53+KKZHBfuvVA8yj3DRX00w8C5IzTNUOX/GWWpK ac9meXtowaEdWFs46iE7qKbpwrh7G0jaH3+Jzy2RfD1ZkkMgVUg2jx9SgDmZ4lNxVSVP 1ZxqVDWwLZyaTDksFePoq8u9fYfZrWXWNMM6AsjLmMEPUhOXBYaeL0aVE8QEDol7dc5A GoeiTkrE7JxcAFkwwv+BZ+zemWGX+bLOY89vWI9LyDkMrZdZu9VfyXqm6DwDJm+SRs+z bq9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fgdkG03q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ay20-20020a056402203400b0050491cb60c5si2679832edb.299.2023.04.12.10.01.49; Wed, 12 Apr 2023 10:02:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fgdkG03q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230356AbjDLQm3 (ORCPT + 99 others); Wed, 12 Apr 2023 12:42:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230341AbjDLQmW (ORCPT ); Wed, 12 Apr 2023 12:42:22 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEE71121 for ; Wed, 12 Apr 2023 09:41:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317694; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wXTqxDSTsrRiAkVZ6NC5Z+aMCLpRXkWfeIKb5BVB8IM=; b=fgdkG03qPmFecnq2VdojiCE+h8YgurP5RcjNw/cjepcl5600s+39PgLNsqW5RdGZZzMU2I XP3bIAMskc4R7v27uzV0Zgkp2FR9kmRExcCHj72HEMcmdvdX88fe15jPTE1sNZoGu3lSlU J2kJxZnxKnAa1l7fLfhjzH60nQ2LszY= 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-141-zoU5faxTMbWdZdZxE_la3Q-1; Wed, 12 Apr 2023 12:41:30 -0400 X-MC-Unique: zoU5faxTMbWdZdZxE_la3Q-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-5e965c54827so8739426d6.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=BULATiRAiMhzp5mO0BXOSWnXIwuQAVXEHPx0+boOp4v7pTg6a+YInVLwFXQWZwdo61 nMQexTzJu9ZdauPTqH9AboNheHDXkNiOVAGUXSLyB+Zz6bSk4ObIo0bnNVPOpomWKCPS JmnHt+2xgx6cHWDvzHA4eSLiz/ptkE4yCiwWMah5hsxTax2Wi30wKov9Kv6PIYqLBHt1 zTkZ9v3T8dbbdB1+PQR3V4I3D7veowlI3x6wMRRxttwVPYo6kZNhGEdrYL1e4Yd0rjRp kWuMzUUbg3VZ96UgWHwOY3jb8z1g27LKypHMcZbsb8B1z/B85JedX0Gw6HGj5JTPbe9/ SfdA== X-Gm-Message-State: AAQBX9eSBf8pgka5/D25/8GjdtkOiUYFzQ+b+FWmUmPS+KfT2uuJ0Zyd 9lrmf7k+zsywFlByQ3/ONMfTtqIi/YnDU3aHB58gyBt2OQ1Tkw2jagMoHIkKPruAgGtg2J1jJAW EGHG0YMrAWXpe74F6s6s1nlHRPxXYi6D0Bp5Bbh6aktVkRQX01ugdXqpb8C6GdNehyLku6t3yaK Kw8ZPjAQ== X-Received: by 2002:ad4:5de6:0:b0:5da:b965:1efd with SMTP id jn6-20020ad45de6000000b005dab9651efdmr27656371qvb.2.1681317684954; Wed, 12 Apr 2023 09:41:24 -0700 (PDT) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762990683788911563?= X-GMAIL-MSGID: =?utf-8?q?1762990683788911563?= 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: 82575 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp472490vqo; Wed, 12 Apr 2023 09:56:49 -0700 (PDT) X-Google-Smtp-Source: AKy350ZoWCs1siDZ9+DpV39+5eXnI7tgxUxEGn994Hfq0BKSCGXoK0uJ1XAo8bHo+DMzS/DU95XT X-Received: by 2002:aa7:d919:0:b0:4fa:4b1c:5ea3 with SMTP id a25-20020aa7d919000000b004fa4b1c5ea3mr6053693edr.23.1681318609293; Wed, 12 Apr 2023 09:56:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681318609; cv=none; d=google.com; s=arc-20160816; b=X63S6sdzJp1G/R3v9zhw4V4JDAiKyogUXdapVd2NuX2yMEdGQeT6TMEVVtwqo8JYNu H0J7aw5xYb2flz/ECMzOzJJMwp7moltEyddcAz4xVpHk/3dVjfU0hFNVXVeePj2gOtyW sT/kGGL+BfwttKB7Bf2GMUJJbTU6RUDPrmLTcJMtc87jvpW/PV5cycFpMpBXNJz1v501 NgJZy6NWyRMTnnqfsflGGwDHfzP9ToihSbGEXut55AG9CdF9WwFGtwBPGqW7449s1zxX 2IUnt+OTeuMVYg1RzSJl3sWgu+8sqXD/JS0KTefFnAxWkQRdkmMtEgplu94Ct2Sn29FN JU2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gGqh0HGkgoECYjM8JfbpdJ2gFcbvM7PfOwSnAOWQ14c=; b=mwQ1a8YCM0iUx0d2ccHss+kCow5yTzsrfK4idXTwUzkc7NEyrFwfr2DYM2CeEbGSUS Lh2m2sWkv5XAH74DpiPjhARjuu3ukdR4aZ0dRddu+S/5s8KIcuNRjJ3WfkD80+vnCRzR ft2jo8WpsdodO3b6o5vkSrceYI/d7bOU30N+OqPATVmQ1cZ4wW3NTOMdQXS/QJ65UoWm JnMtOmKFiaSFUfRWbBPYAfOk/6iuPPdHwtJ/9/D5z9UKxkyliTifADNV+zvCq/EfcmsH 3R7pm/MuGRwD+ZLbNNVKK3K4/57176tlZNXR76mM7h7Asoekt7NMEE0EJvQuLGWB6fCA WFbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XG7SZZDV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z13-20020aa7d40d000000b00504add60b18si6725821edq.532.2023.04.12.09.56.25; Wed, 12 Apr 2023 09:56:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XG7SZZDV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229820AbjDLQnY (ORCPT + 99 others); Wed, 12 Apr 2023 12:43:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229845AbjDLQnV (ORCPT ); Wed, 12 Apr 2023 12:43:21 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 502468A4F for ; Wed, 12 Apr 2023 09:42:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317743; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gGqh0HGkgoECYjM8JfbpdJ2gFcbvM7PfOwSnAOWQ14c=; b=XG7SZZDV7NPWxthngLwoA6PvfqSU5TZBEeUQeHXyo3Q0gxew8acy1Tovpt0pf0rLYZtiIl yVJtQZ9am5wQpUiIJrVf/ftSACdSpHy42yuisDv7xWol6OhHI8fYGOgx5474SeHufLQSC2 AaODQrumAxFw/m0LMUynpqjomDxsUbY= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-602-FeBVkfCMP0W4YjwS14y3sw-1; Wed, 12 Apr 2023 12:42:21 -0400 X-MC-Unique: FeBVkfCMP0W4YjwS14y3sw-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-3e69901d854so893931cf.0 for ; Wed, 12 Apr 2023 09:42:21 -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=LFjsObXzNEcojeVMNC4lxvJgU+wiqwbaDTR8xcRsuKwCGTb3v2ePQChP2JPlLz07tJ haK73+wmXoy/vRJd69ibiilACfHHKDCyvjSo9CXQo/d9xwOvNngbRaLsU64bS007B59W 6fCQTEKJZfg2VlvwwV0685dMOKxHt5HerHnjcXKlGRaCSNo+DRzCGzPirUnNdcgr25nJ ZJ3XMaViUzgnVISWQwZYFnZR5d9Vq5K2Q6ziVMGnp6chP2LB4JS/GtBB1vjjBmrcSenK YUcjEN58XwLth+URq1AX24/5PotphDl3MQJMsHt8xNLorPGuNapXj2RDgN88uJJVWpMN B3bw== X-Gm-Message-State: AAQBX9e6kyKKbpMA38/atBV2NHW/GXXSnzIrBjbsVZjdlHC6yb8mwmLl qXpXqAsac1ZSaT5i8Nw7Pvwoi0d22gWkI4y7VTjiyULOSpLXnXMPHlugv0w5VEt6l6kyoccSipJ Nq8joxIkfppdeChNSCszBlLddCJ5LzIlMXRev18JT9FC7SLQn2tVZC3LKzRnNWSKyttTk8VRp+S 15xKgwhA== X-Received: by 2002:a05:622a:314:b0:3e8:e986:b20b with SMTP id q20-20020a05622a031400b003e8e986b20bmr2585191qtw.6.1681317740330; Wed, 12 Apr 2023 09:42:20 -0700 (PDT) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762990342115178025?= X-GMAIL-MSGID: =?utf-8?q?1762990342115178025?= 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: 82595 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp479671vqo; Wed, 12 Apr 2023 10:06:05 -0700 (PDT) X-Google-Smtp-Source: AKy350aD2URuC3LYMXDSM4aw5ch4QogUKsMl74bBIcfSUfQAjYdy8Z3x/qIpoq57+YFlPaqpPr3C X-Received: by 2002:a05:6402:180c:b0:4ab:d1f4:4b88 with SMTP id g12-20020a056402180c00b004abd1f44b88mr2259719edy.41.1681319164848; Wed, 12 Apr 2023 10:06:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681319164; cv=none; d=google.com; s=arc-20160816; b=hqP/jCUhoSoNeLOE9Wt0n6y36niucbnqJOlMGewKwOPQiFmcUBT2BL41/kU5WyWFiK XzcU1AsWo3KrYIVEs0eGAKh0Lk1XK4vV6CJ78qo+hmQiEJVNLkB8YWPq1hiR5CglossZ eOcN/ENO3t4QnRXp3k/dn286td5KBUveyPnbOvUOJ6w454psL3d5x5nvO+5pqiT7m3Pa qri6rgPSazwR202uqrzlOgimZvwVFKnG3VzejWGmL8qbUUGUKHgzPg9OfXWAe41JsiaV Wg/C2KiH6rKp06WRoHGzaboCi4uIree2BIN7yX2c9G1F+M79zgUHcPCaxUgpEDHkmDOE WXWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=AASukmt80WChuLSYpdLGBsnHxG2u2zyP4JySsjm2BSA=; b=PaGz4lOgmHYUq6yCrOeT0FI6K07y/+hmQDH2AIEd4AdulhvxlLgQH/FyYLsp/0lSlA nWhl4N3RwfKfmBBeb0IB+L2C0cfB2XvuNqTiK5bNK64UCY8dG3yeyFjz0IpaNonOTiyK uj9PMzuRH9DYKavEPaA1grf9u6wK4HZ4Jf9GnChqmQtxSeycui9tp1tryosVwBsknGBb xoTTBacOrdxTMrWAObrVKRVZkuJUfcbQXkYpciEQRsXYe1J6U7UEsyF2w0NNR1F0O1J6 pml8FBjmChR65S8hvOhXKUaHhsVQb8pEyUpFMI3el7a6rFllMDeawudbsn2MpimMx/C0 8BfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=h2mFIRwL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n4-20020a05640206c400b0050481d2f583si1280404edy.537.2023.04.12.10.05.06; Wed, 12 Apr 2023 10:06:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=h2mFIRwL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230390AbjDLQnl (ORCPT + 99 others); Wed, 12 Apr 2023 12:43:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230186AbjDLQn1 (ORCPT ); Wed, 12 Apr 2023 12:43:27 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8D3886B4 for ; Wed, 12 Apr 2023 09:42:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317746; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AASukmt80WChuLSYpdLGBsnHxG2u2zyP4JySsjm2BSA=; b=h2mFIRwLiqzTr6Assw4NHoKNZdg75KbmVR0dNpR4v9CLe+aCl/aBtEy9dNHjBOqJnJGMlx +YzSMh/9gKOpVRu3SI68li1dCflA2hsXLdKowcEZ2CS6Ya9DyHjLSVtOIcsHr0xdGThGvb 3iGbshuatxn3OuI8utfbre2evNN+kcg= 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-212-tV8pNClaNmqE7G1MjxxbIA-1; Wed, 12 Apr 2023 12:42:25 -0400 X-MC-Unique: tV8pNClaNmqE7G1MjxxbIA-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-5ef3c877a1aso1539336d6.0 for ; Wed, 12 Apr 2023 09:42:25 -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=j8w2evCAgyb3Z0pYvg3fSYGt/omznK4k9/+TRvPDpQxxI2I9kqeqNXZIxIzKBn3w+Z MR7qECKtb50cFPshzGRUUiKZTopjBnctTyX0HR6LQs7NmSwqqDLcr4icmPCeiTxOz45A lt7+lB0y4XzWbLemNWx09LDY+I1HT2+QiucLcXe6rWV3WCybneq27GtHKeFz+gMRW5jA KYBDnjp5PdeB8TYzf8se5a9AuErbYUEM4XsPNVCW+N99BkUm23SwupjhQB0LIUuWNWYu MNabIQ24QimDtKj3aowW16ZEilpJtnkZlMyIHrXRi6SqEOnCbvUPCZ7B4TxR1ZFUmK4C 0/tA== X-Gm-Message-State: AAQBX9f8f7sAKYO3amYcfiBMCt74QTQYc63e1dPyzwKbX8ioGfNzx7XK w7r4mNsV4IHZmANn47yctHD72hf7E4LeLH0VkbEhWYLxZAusiKt4y9Y6pI/hyWHLRzQXphV+8cT Xi0RVhbmsNrb7WkI2/p9BEeUUf2ltaABERGW61hKiJzCrc94vipjCbr2t3hAgFELXfXNSy5JRVN byDL3QtA== X-Received: by 2002:a05:6214:5192:b0:5e8:e6ac:591a with SMTP id kl18-20020a056214519200b005e8e6ac591amr4456994qvb.2.1681317743690; Wed, 12 Apr 2023 09:42:23 -0700 (PDT) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762990924638930254?= X-GMAIL-MSGID: =?utf-8?q?1762990924638930254?= 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: 82567 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp466138vqo; Wed, 12 Apr 2023 09:45:54 -0700 (PDT) X-Google-Smtp-Source: AKy350bZTEmU8yf/N6QX8z9xGKff2nIocui5jh3DNd0mox2xGmG2p55VCFN3tGN0R2o+AvnUg+Sh X-Received: by 2002:a17:902:d505:b0:1a1:b172:5428 with SMTP id b5-20020a170902d50500b001a1b1725428mr4341108plg.18.1681317954288; Wed, 12 Apr 2023 09:45:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681317954; cv=none; d=google.com; s=arc-20160816; b=lOwEkmnNIICDcGuFUC+nGKkDTGJFZdv02F4zVZv5EyXVcyBw7ped7b+YDHcdIivUDl wVOYJjbMD8H91SN+DqU1TJVareDGzLcdeNtf3XvGjlrGkL7zNjMd2eJvWo2UW6oFN2c9 PTLRuH1ZzTdncQR6yWuRUdxsd+q86jbxOxkcc+TivrIWDHVizLcbcVLWbRmXp+qo2nPH 0OQXoppIyFOYPv69kWIBFF+wh5voPbf3lV6IcizkZCUfgK0hU5+wvpEQ0nI0mmXh6iuP pclCuH6Pc1Dx+zX2WMuRneVNUXlUHlCW32Dg0QL5G/O+MhYMk1D0TOrPeUi5xcRHxXmn PsJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9w4FTeM4b1xfAgG4y96DPCrYEWea1Mc83v+smBNR1Gs=; b=jfJtQcABeokFBd1rC5cejjoWWGzugiJLzo3SuI1VHC8ehE351ABNrUn65pYKYk/YvM AB1APZfmLf3ES4AAiOAy2OAQ0YrWkKyMJ8Lip+oDnJhWAGa48eTTXDakygrgWp0gc9ug U37AGDL5MERDiwfNmI4h6DEzntrCCqX5Atv5iGbw2kFeWbhCx4j38Kkvg2c3AEFR4Uh/ slqOTo/eCsyzqYJEGCoUgB2PRKp2fGvuCIZcKFh+s1IWjqSt0wLdNX10mt6IYZTzIhwe +lOny12h5+aqaCH1lgWvghAivY/FKdxqOZNvccyJKKyoH9TphNuoiT+0oDmVAmwhszxx cF8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=X2ed2FD9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f16-20020a63f110000000b0050be99a828csi12495746pgi.4.2023.04.12.09.45.41; Wed, 12 Apr 2023 09:45:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=X2ed2FD9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230416AbjDLQnt (ORCPT + 99 others); Wed, 12 Apr 2023 12:43:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229567AbjDLQnf (ORCPT ); Wed, 12 Apr 2023 12:43:35 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BD7A7D86 for ; Wed, 12 Apr 2023 09:42:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317750; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9w4FTeM4b1xfAgG4y96DPCrYEWea1Mc83v+smBNR1Gs=; b=X2ed2FD99jiNWvs0VoEgrMr8NFsHxsbfUYEgHcebia94OWpovljBSDdck4d/W2PJQarvBa GXJQRXMDnfpkjJnzeNbP+lHXPXlhgwTikC5en5eb/AETXSQu8Q0RaNFIVi4kEBmTlepUpB JIkOVvc8FaobEJ173dRGgt5ACk1Dzeg= 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-478-zzNHV1rjMxyKINPfiEgw2Q-1; Wed, 12 Apr 2023 12:42:28 -0400 X-MC-Unique: zzNHV1rjMxyKINPfiEgw2Q-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-74a25fcda05so77596285a.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=bqaC5+jCyPvCOAd8FnsDXxbVFyJTSR1uhWL2tsbup6MnPNXWWcPadIg8NAEXWSuHix gRTqJyfVwYdVhqQimzBYVUohh6FOUVd3uPBdXOGjO6udQbx+l8rT0jbLv9PENSyjZzi5 zssPEOTl3cwqNNDssQsMEvS1kEF+cPV7uMKIEetFaWeMHYiQRe6VrhUJQjhmlEBpjOYW FTX1NkOCLGdGoY+fwfioBy8XRlUbgg0uEZNFOYWbiE7ZQneftvwpjOBuAQtNimB2qe/o WAKsqPaxsIdszM6p8HzBSaDHX5C6hZyV+je3TDbRhVWnpdxgtzX9FvbVkHU9/qybm56T qzlA== X-Gm-Message-State: AAQBX9eq5K6LkEHw2GdSP+TxhMCUezvH9gwxsEJmiwLN6rN58w+Jq+9x OnKKV4z7vhtvqGl1f/GqLx0TfD023fQkHNxtBw8fEut4F05pavSjPe+KiF6S6AUOKEOlgLUvAta K1ymFwAgIgqCrkUpr5LOVogFhlEHtkeWrfe+29wZ/C2trtbg046hM9h8i0ILKZ1ZduTFd2xQaTp XKMe/LkA== X-Received: by 2002:ac8:5cc8:0:b0:3e6:707e:d3b1 with SMTP id s8-20020ac85cc8000000b003e6707ed3b1mr5012782qta.0.1681317747187; Wed, 12 Apr 2023 09:42:27 -0700 (PDT) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762989655105870133?= X-GMAIL-MSGID: =?utf-8?q?1762989655105870133?= 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: 82569 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp466274vqo; Wed, 12 Apr 2023 09:46:08 -0700 (PDT) X-Google-Smtp-Source: AKy350aXoF1KaYQn3ZhCl2pBK6DR6CeDaUVeIsfMjsBeGXSXfjaeDK4dXs19jzYZIJiY2/jd3Gae X-Received: by 2002:a17:902:ca81:b0:19e:6e00:4676 with SMTP id v1-20020a170902ca8100b0019e6e004676mr14149957pld.61.1681317967983; Wed, 12 Apr 2023 09:46:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681317967; cv=none; d=google.com; s=arc-20160816; b=oS1L/Bq5cMhdT2L+EN+KkH6UTDkfayGcDh0WD+0tKdDw5ncOJkCSa7pc5Tri46tf/z Ae60I+mb51qS/NCHn5RwMZP1zKnQeRRZfiNUA2bsixAcDP1r2lG/NM31JjeMa4zsmqdh q28l9Cm8zq1ogs6UvrBRr0hTQKCB//Cjklb0C/dovJlR1rZ11hyN2VpGBkRvh+Kt2+u0 YVWFlEWFEcPkfyCAcoFwBryFUOCb0Aeep8RAIYDUVcqWDmhfceum1fovXf0JzMFHgArj xHi+TCqKkoLghqluRJcPSmOT+WiCM+/sq5exz34txOF6mzm1OlhpnfDJ5vxAy8uVbYkY IQ4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9VoJC4PMtOZChfNpsShin+Q92n+br8Q3f1O4OPEN8PE=; b=GFwze61Q4f44a/bVehtsSUQD6stVyDe2o4P0072QSsM0AzXpBsc4xpG0mxvwe3SjNX HMthi9j5aQxrSZn1K3pnslkLDxizEbHO9UKvFjZ6RY4zZ8VEaDBG3p2CZICxnH++zJ8G g8YeMtNZV+xNl5XHPEAojrltsfk19i0Q+59TU3PNys7Y/LaTrgCJy6m5Gxw0R2rQuR94 ySI9qBSCcGwjCjJ28HNLUNm5IbFPZCLpzVrVfVwpdq0DVmaS+5pfHb+mWZJ+8/5giuM5 rSVGdcMKkxdiOM1SE60fGPDSM9kWIQfDuTS31wkwg4a7EaG5h/MCB3GTGS1Z86NkrcPd Tbgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LMnTkc8o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t4-20020a63eb04000000b0050239e94bf5si16275647pgh.52.2023.04.12.09.45.50; Wed, 12 Apr 2023 09:46:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LMnTkc8o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230487AbjDLQnz (ORCPT + 99 others); Wed, 12 Apr 2023 12:43:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230378AbjDLQnl (ORCPT ); Wed, 12 Apr 2023 12:43:41 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 346CA7ED7 for ; Wed, 12 Apr 2023 09:42:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317754; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9VoJC4PMtOZChfNpsShin+Q92n+br8Q3f1O4OPEN8PE=; b=LMnTkc8ogIha95Cp15TODO8WtDFGZq5myfIqOH/S7nV47vmLlIaiL4fZABS5fcY3AuG0v9 CRODK2E2EPMoEDCaRVULMvvlMiKZAzu1e9dBWNmCvK8GwW30P1aYALNbi7VuLx38JwyD9Z 3cgLZmxCbeA1i2BqcecNQ9e/rnXUJj8= 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-518-0yPeB1l5Nqeyve5oksbMLA-1; Wed, 12 Apr 2023 12:42:33 -0400 X-MC-Unique: 0yPeB1l5Nqeyve5oksbMLA-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-5ef4122d2dbso1350526d6.1 for ; Wed, 12 Apr 2023 09:42:33 -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=dMUy3gs4BYEjDhUpuPYiA1u6gBm+S3vgc9BnxI+OHzZNPNCTczYuiXgkDWxMcr91oO 89ySgtiFh8KBpKaKbmQM/6lkrSuqq1m6TdB6A8xXFsfI9cG0xdKVYuSHkf3WK5fYQJIg y7jIgwu3KyR8Kkly2wJfEdW4P6EmPpp5zRIPZaoF+YNWhY0xOIQ40QoOdy98wwxqDiRZ hjQTV24LqxTlnbdSPcVvYtyS8XqdKbU9yrtIPZUZu1Bj+yEMWIOHbHhkuUIlTK2+WUbT NH6AqACVxdvg9xphmc2/8eUvLHZZqz/5qzJY+hakL1cGjSR9EXFtaW3kWJFiySedJYBK Zt/A== X-Gm-Message-State: AAQBX9eW7OtmT/VWHaPO98FkPETh+nbR/aJ9MDhL6DpJyZKh7h7e7tbm 1xuJFPM7ifVKJ6cTeiYmB15Ymu4C43E0G6nfHetvSS3gBuijWq9f9+ttBoIgNvYXlZYGTRxVhVt vRt7u29ZryiipGLo3/CWeAW8KreFWzEbkNTuL+yEASjzpRAnHqmttLD8emB7mibo2wKqKCBL0gy TMKAiqmg== X-Received: by 2002:a05:6214:4105:b0:5de:5da:b873 with SMTP id kc5-20020a056214410500b005de05dab873mr4439636qvb.3.1681317751517; Wed, 12 Apr 2023 09:42:31 -0700 (PDT) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762989669922689140?= X-GMAIL-MSGID: =?utf-8?q?1762989669922689140?= 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: 82597 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp480526vqo; Wed, 12 Apr 2023 10:07:12 -0700 (PDT) X-Google-Smtp-Source: AKy350Z/jdr6Dc/2BeYd/1iztRUrffvPG1AnczmfKFjLtkG9BqFgFfjoxbCU4eKYZFNR8oVepVDD X-Received: by 2002:a17:90b:38cf:b0:244:9385:807f with SMTP id nn15-20020a17090b38cf00b002449385807fmr23149453pjb.44.1681319231736; Wed, 12 Apr 2023 10:07:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681319231; cv=none; d=google.com; s=arc-20160816; b=bcX2gtU9erc8VKgT3vE0ttgnSMiWJiD0b4uY9FQyJiW0cOcN5ek8Z1D/Gz3QilK9nV ULKoTrbCCswFfuTgkEkvQxtEpEFbsKmzqtP3qQZK8xrJqPxHTkGyFzV4y9Oq3YQNGhGr avlhqp7h6mUm1P+dkHdlS4bqCliNbgi1ZB+cm46QYgDt3hEVxGkIRr9k128ogxh4lMUg CrXv1QkuP09HiYcgL8lRb+Z1FsZeICJP+1NmcBISuaqgGvARRs89GP6FABPkGeG9Mh21 ZhXXOeGaSF1Bnot76BX9zw9sdgAnpQ9kGFLUYA9/2UrmKDNqD5VkClgmbCXp3TCmt7xW Vbkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WqDS6jtSapL9ifdeK9em1EDp4bv+6WCKRXbZ+q/xf6g=; b=mMXUCgX2wK4WVSfKVCGeY+BHb0k95sfjsP4l3vjlqepbDU1ecUewr8YOk25e9oZ0Sv r2gcC/LmFa7a8LKDnmtLyxO4SP+3WgWjZoY48Bd2WXAlB5Zqn5Xe3SA8gXHd+KwpV0XI 6I7jCt9tZm60k8hkdIfCH2C8VzFwFREqRD0xPcwIY5O9lF3hM8rJkSWn3qkdgDiGS1Me DeWbatuTY5rZKOCFrNO0fVB8YJtL9C/qEM1w35xiKJ6lzDwxxJlzzi6VO8ip7VMGxq7s FKFFxVYfcCD4yjQJTRzwCNhDM2H/QiE2jv4s3bN/d/zjkb39HobpXzsf8miDpFbO/hwo kZpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aydLCzjA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id na14-20020a17090b4c0e00b0023d2847e355si2737084pjb.0.2023.04.12.10.06.58; Wed, 12 Apr 2023 10:07:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aydLCzjA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230240AbjDLQoM (ORCPT + 99 others); Wed, 12 Apr 2023 12:44:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230414AbjDLQnt (ORCPT ); Wed, 12 Apr 2023 12:43:49 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 217A37DA5 for ; Wed, 12 Apr 2023 09:42:40 -0700 (PDT) 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WqDS6jtSapL9ifdeK9em1EDp4bv+6WCKRXbZ+q/xf6g=; b=aydLCzjAdysOzWn6y1NskRVL5rn64+JYgfuQ+m4pc16bdwtUgi97rITUFC1YjSFMWkfjcD c2FPY22tu+3ew5+OZbw6APQnw3bYEL2lwlADWuTAyIxW6EDV0XAf1yL4DZxS4my5/Gz3+J Dmn/MgSnfo/2yxCiJBjfGO+74xIJpQg= 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-423-oE5bAW95O8KLdUysWhjZTQ-1; Wed, 12 Apr 2023 12:42:36 -0400 X-MC-Unique: oE5bAW95O8KLdUysWhjZTQ-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-74acb477be6so2293085a.1 for ; Wed, 12 Apr 2023 09:42:36 -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=M7JNEcYTmoVdZiIsZVK7nZN8Qtk0F8ngpjhLy/msI6oorkKelAZpAudYLHjUyvnahJ ADmQghUUx+w/B9/bft19gEQJuf2Kc7o2D5Jxj3KO/0ai4nihphvD/bwAYxJ21oyD+wjz 5Zmw3tA0Cx21M3mbYvYN1b59cjjxtUR4CIYRfm4fsGJboxoCtsVwjsrWhvVDtlbwEL9m nHh3Qx27IQ7GkXW+0ydy8lkKnD7xhRn8SIpL8tt5jByK4Hx7bcKRD+JY6FPz/TeRR7kD IU397wTcwW7atW9DYkKDz/blHqeig44ojIsrZOSah1LAzdL1A+k7fXw9uia6MflNFAtu if2Q== X-Gm-Message-State: AAQBX9eVA6Vv+E2wJePT2fg9MW/MzJh+E24lwSEh2LpOplMaBlnobZfl ay1qCU23Z0p5yAV4FhH90c+fk4tm7ahfLdYbL3UYrYcbn8XkJlBr5hx9nbkIxBMKxp7014PBn0a IaTwmyaJcXgppQQYWv6tU6YNGNQGZ9SQtv2md0/gpzpdXMlaTxgpdXpVhMAWyewfGHSM2ufAeit Njtd4Xtg== X-Received: by 2002:a05:6214:4002:b0:5ac:463b:a992 with SMTP id kd2-20020a056214400200b005ac463ba992mr4597605qvb.0.1681317755030; Wed, 12 Apr 2023 09:42:35 -0700 (PDT) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762990994550324992?= X-GMAIL-MSGID: =?utf-8?q?1762990994550324992?= 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: 82568 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp466263vqo; Wed, 12 Apr 2023 09:46:07 -0700 (PDT) X-Google-Smtp-Source: AKy350Z78H7BbrQUublYYuKHif4wLFma7A/rPLI+qlSv65Jf9rhkz8OvZbMVL24NyqoTOwC/YhNw X-Received: by 2002:a17:902:e743:b0:1a6:61ad:9d03 with SMTP id p3-20020a170902e74300b001a661ad9d03mr5727463plf.65.1681317966936; Wed, 12 Apr 2023 09:46:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681317966; cv=none; d=google.com; s=arc-20160816; b=Ro8K/Xh+xPObhhBfPHyh2TwE/4rSWvJt98wnEcpwOeMTWs7q7vxDadEOhnNmf2VaSa A/TlcyImX55vVgUgKKXcUVwJ73Hfc5ZiLpT4YjtNtmOV2EFMoweuwBWOX8Gzr63CgUeY v6Ig5A7+BGGDKmae8bKgL/KBr4nUvQkcVN/OM29s9XwlR6Twqlvid7bFCiIczDAm371r 6Ab6Ds9h1tCaRyPmB1CXdxSTPCzU4h9L0J9D+i5Xoko62kMU5n0y4/dCj1gHC9gbcC86 kWj6JQRBY8W2KCd1Kovp1b85cjMbLbrf8rTIrXhEfAPgqxng4Ls12aquTnfqJBfpoxVs iHag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ASfRfnQJTCdEglytu7DR/J7BYjWDsPlfNboYF8myg6I=; b=ep/HcGOaiLlazm4/7ulrF22DfNLOPjLB5j6taAY+Vlx6whh8W5A4mXMRpmCKLnW/Pu aaMu5B/UzZvZNXVeAUvECxh3v/thZamujDbCvLFHS1cvhVHgRWE5d72aHUrQhcqD129o CSdny7KP3978Xesx41x2pjpdK2fH2/poMG7HiBtZWj4OYm0N2dxoh9QMA6c/3A6z68DT zEwPFLfdLRigJexDuhl2Y7AXFZSvMV+scKFmdJCUlM/eHQMXuUomq0nVDh3Piun9o2yP 6XpgWdnKEsTa/CdAWW92VUzLzUZfb+Gh7esseq0JbqK01p+ko1OZl6f4gJI7zFSVq6KA vkRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ahtANicE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y16-20020a17090322d000b001a5abc9d9bcsi686108plg.583.2023.04.12.09.45.54; Wed, 12 Apr 2023 09:46:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ahtANicE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230188AbjDLQoQ (ORCPT + 99 others); Wed, 12 Apr 2023 12:44:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230379AbjDLQnz (ORCPT ); Wed, 12 Apr 2023 12:43:55 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6599C86B0 for ; Wed, 12 Apr 2023 09:42:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317761; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ASfRfnQJTCdEglytu7DR/J7BYjWDsPlfNboYF8myg6I=; b=ahtANicEzbRH5R6netmR2G7yRkzNf9ZEzlf5ApMhgYmG88s3/i62Ciqs7BRXBhsGp5NOhW jgpZLEu6PwB+rXw42EQmlIkdkFEAuAKT44K7rqABYPpETPPfbl5RLGC277yc8vkNmr+tqG s59opmNiJJDYTK6IoInZ5RAQj3hlIYk= 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-348-7CtgX-HeNjCEZSfHkPZmqw-1; Wed, 12 Apr 2023 12:42:40 -0400 X-MC-Unique: 7CtgX-HeNjCEZSfHkPZmqw-1 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-3e63ec50808so4676051cf.1 for ; Wed, 12 Apr 2023 09:42:40 -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=BrlTy5npKntJN1FLw/x4MTNyFfn/GetgOc7XSfCikKhX/kILYeI+1tUaIKPJ8iUi5H 1j0vD+N3h8XC/DhWyY/K74NHzmem2Y3jye8FmZyV1+LeYoDGr65H+/LnIVdHiit1sL2u CbOZNxjqUxFaej+4PKJnNem1gU+qSNtN+2wTO464d81egrDXked1kfrnDUToYfG5KlA/ +bRT2x9IYIeUuLtOXS9SAY/MOpcQ0Oi6Dz3rrNe7hAAQqhkrnWOpGMzv9PL9kOmz6J7J u6xUWrKnHopz5bjd0sCgRLn4XencaJd3gvCkya1LS15U4na8ttTAEwqYSt3lA/p2/ybc Ld3A== X-Gm-Message-State: AAQBX9dDIydKArOI7B0srGdPm+3qI8QVnC8oSZxbBnTyGAtV0jVefunI Cc1cWiJTc8pCHls/Dlr3M3CAqiRWywjj5FFZzq/soINc2Yz52MVVgacbfnjXuWyBRqez91MNFc5 qFaiX5QgvsngqXiUr23KE6F0f/X2A/MgHkcX/uyZf7alhRjcd/mGgkpPNgPRc9oDIz9KM3e9UAm PSxzCmhQ== X-Received: by 2002:a05:622a:1a16:b0:3e6:30c4:656f with SMTP id f22-20020a05622a1a1600b003e630c4656fmr31834209qtb.3.1681317758554; Wed, 12 Apr 2023 09:42:38 -0700 (PDT) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762989668936195975?= X-GMAIL-MSGID: =?utf-8?q?1762989668936195975?= 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: 82594 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp479663vqo; Wed, 12 Apr 2023 10:06:04 -0700 (PDT) X-Google-Smtp-Source: AKy350bfRMPyuuFZC+sQlODkb2QQtECU69mhPenxSO73/FTYFx3f+tf0q8LRgvfF6K+UOpfhh9Sf X-Received: by 2002:a17:907:a43:b0:921:da99:f39c with SMTP id be3-20020a1709070a4300b00921da99f39cmr19082002ejc.12.1681319164307; Wed, 12 Apr 2023 10:06:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681319164; cv=none; d=google.com; s=arc-20160816; b=lx3u2iprl/NV4Q2ueznaekqyikkfoz17sq01ZP0Bovh2AUSgsx6qnNHnNxhNVt6v0v Hiaft1LVq9r0scrJyq78kCnfckRG6GQo8ZRu2WfDu9uNyH/i13A+QUPhz8c7cmng1oXS SlRry8xYhYaGwXqcLdWPEO8GyS0qwXk8YB16ZVBK7L1EQ3nvsu7L/zwmko2PvYe19P1N hhLIOwma12qwLL8u1fVGiPX8O4/N2mx/sHcYpc5dtqk0mb4lo/n6QDdP5GN/5BWZXePZ v4375qTSW7O505JyzHqXZldz+yAu/LQI/oaoh546mIvIYfXB6XKjVdohtnUweKFM+8PA PLOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1TTsACSLiRja1XbqXldcznrpQfU/7XLsecI/fn7kMpU=; b=s/qXsBlYuPCOagFoqHQFItBhQDmiFFe0wKt7wuhwhz/R8lrQ/Hop/EfClfh028IuAL DJTgeJ10clKt64+kYuztFtHb1mtprZpoP/lndiZMQlnSROvgCenyiiSDW/DQQ3q11dUJ v4i6yA7urGL/WRq4Zvwt8mShnya1GEUbQ8O9s2bBcJF4T/hulJg5Yr7Tnk3wOgNSrVmB x9ya4Iy51mrEl+70PESNySVYNMOna4Rsij9d1VQADl13xqiRWvZEQQoR399LVblQy+nZ AbxTWdzz6fZs1hphRSZsmr8aqXe6etdmLKdmKRp0yPruX31DSnG9hGy+fWCV7BM46cNM b9/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=G101O6kG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qw27-20020a1709066a1b00b0094cfe2dd496si6391839ejc.411.2023.04.12.10.05.15; Wed, 12 Apr 2023 10:06:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=G101O6kG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230384AbjDLQoU (ORCPT + 99 others); Wed, 12 Apr 2023 12:44:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230502AbjDLQn4 (ORCPT ); Wed, 12 Apr 2023 12:43:56 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3C208A4A for ; Wed, 12 Apr 2023 09:42:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317764; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1TTsACSLiRja1XbqXldcznrpQfU/7XLsecI/fn7kMpU=; b=G101O6kGr66QB31F/K3SOmm5H+EdlVvqLlZuuK1rL9xZ87obZkPPeLfpIqXwfTbT9fluto LXhBZAnlQOrNkcjc7hjuaHGLlkmgiKmCWPCQiwqf4/JZSmHPpMlIxymPtiRPugWop0GbXd 9nkpKA/sklXGxm7ComV8ovGS4bHDyjo= 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-104-Fkl8l0tLMYizcR-bcGnwtA-1; Wed, 12 Apr 2023 12:42:43 -0400 X-MC-Unique: Fkl8l0tLMYizcR-bcGnwtA-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-74a9035256eso54256085a.0 for ; Wed, 12 Apr 2023 09:42:43 -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=bZN+RiudWwtwLK3laSu7eEngUyN0wTOGZ4QhbltZIL6Eli4LQwzBRgGd0Q1W8vGQQI XjWWgwxfkn66SnM6O3+cAUiHKCNrJdBqXnTjJr75HHVJ/9KaYhLpoS8pKdnZs2MKyDn3 FJ6BILpdY2fhEXnaluzi4v7x7CugeLfP3NkkfxJgXPKJHXKeVcgok3eZEmfRt7N30V9O bVG6rISCos3GYW5FtqmrHpTCHfFZzTak6Z7DPu6DdVnzgoX7xUVrK/iXDDQmKUQkwE8Y zaAXHlRloVubT9c0wlWk3mUQYjDnR5QcrNQNjba6G0TlYJJ6Qx/vblyibleiwmGBqcaX vL5w== X-Gm-Message-State: AAQBX9eD6xosxQrXqiXznA+X3fzkrcLAxk3lhT0PWV7bar8qe7KET0dY /1odLLoscTWJraAnMD+MT/gAwNS6vjr8AhF9QKLtyFgUozhFSX4jUb61argNDIwRT9BqKt+FlK8 M6zs/NividRYmmOBxHMYKgM2ct3yMIspC4WJ5/bAJE4POOSO+kBoLisB8uUx9yvyf9mHeur4q1k 5MlvpyKA== X-Received: by 2002:a05:6214:5192:b0:5e8:e6ac:591a with SMTP id kl18-20020a056214519200b005e8e6ac591amr4458283qvb.2.1681317761949; Wed, 12 Apr 2023 09:42:41 -0700 (PDT) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762990923954004742?= X-GMAIL-MSGID: =?utf-8?q?1762990923954004742?= 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: 82576 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp472534vqo; Wed, 12 Apr 2023 09:56:54 -0700 (PDT) X-Google-Smtp-Source: AKy350YuxpzgXYhTp6c33baoe1y8Sf8TCnXCNtlzYBNzNP4zkRFC16OYYAA02jos3lXtpW67g8ZQ X-Received: by 2002:a05:6a20:7513:b0:d4:979a:e31c with SMTP id r19-20020a056a20751300b000d4979ae31cmr2110pzd.62.1681318613842; Wed, 12 Apr 2023 09:56:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681318613; cv=none; d=google.com; s=arc-20160816; b=ylwprrln7xPGM2wt16zDptxbuUiXXWB3Ikdcsohd1N9cwUms1RKlRGLld6vR/H+Ms9 Th6m7DoMMeYsHX4breXayZQzICQB4ergioNrQ2xmFBql0ay/HrGI6kiGm0gYuixsszYO l9A4goHIn6kvRl54qYlxjN9D/ER7+h+RdQQqMwpVFLFBVUZR/RIGwC26MM7079jsrSQL JjCXgjQwH+gygAk4UyfMEaSxxHbjWQZ+/0ilW6jdNphMs4IDrwvdGvoNifUO8s4FPvnE 5wsk7i+WeknYBt6jDY5jI+5ObY/rYfzf4LYntiBPYsvFIUk2hq+A+iCbQpnf/dvpmegX FGHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Iwj5fiaGmEkDB9ZI0G605C/zBaITILZ6MxIdOBed+Ok=; b=DrYk4amqa3T8vLAsNFuGYd71xlVVsZZbT1epJIhJMATJvoZRiLcw+0SrjDwY+OhY6G h1D5BZsIdffpzc/uFl0jI/KUQz+5AoWLsYIbZxV1oIyAPXYpjoFrMvZGu2QblEl2ltK/ nP/Xn81d1fX35x31wsoz7XSd3bUw+jWX5oMdffbKi+sZoul6fwfqwuyxrADvQbWvcIvx Or3RrOcWkkpEgm9Jk0pfow7f+A96bhuzGbnQ1tHIgVNatXPq1Eu7fwd2g7U8DQahQJIK lDw2BiVsf+vtP+9YR5LMYuBtu9oF2ZBkMmP2ald+yr8n/FAPKlyNeanbbGk5ePQC65Eb lG9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PbUDSzGy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a31-20020a631a5f000000b005141973fd45si15638184pgm.329.2023.04.12.09.56.39; Wed, 12 Apr 2023 09:56:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PbUDSzGy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230392AbjDLQoZ (ORCPT + 99 others); Wed, 12 Apr 2023 12:44:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229873AbjDLQoI (ORCPT ); Wed, 12 Apr 2023 12:44:08 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D2CD7EF1 for ; Wed, 12 Apr 2023 09:42:50 -0700 (PDT) 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Iwj5fiaGmEkDB9ZI0G605C/zBaITILZ6MxIdOBed+Ok=; b=PbUDSzGyXnw9EuVearrf+yr1mGGlSsTzqUvi6p8/ZmXZUh2t7EKcQkf5+LZpPJn1OuOA0y m7ljIhV4BRlpW2Ljh9uNu2K4y7nHAyo8c1XW/aqD3JodVx+fLgkWGQWUDOHeQJGm4VMjBl u2yM3yEYZUwf0WbDUSJTdcgvZGuhwD4= 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-491-Ud528tMhOxKPkHiNuztFXw-1; Wed, 12 Apr 2023 12:42:48 -0400 X-MC-Unique: Ud528tMhOxKPkHiNuztFXw-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-74accc750c1so3406785a.0 for ; Wed, 12 Apr 2023 09:42:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317766; x=1683909766; 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=Anifr2hYjocjIgZ+/NRUiLh6cQQwDMB8XZnl+f2TDkEniFM3mef1C1dL1UtbaCBDNz Y7OZblxf1J50fYSDykNef8eCh62FbMn6NJif2R5MmLxEr72bJ1auiUv6nt8RMT3TC74I Gt9+RKpgQka31oKOiIX1PpHl5EGo0wXuvAn97vzAaOFFcyrK9GldO82jbm5fCUEAPW1f xaUm2jjp86Nmzk3lyRAzu9VpWEg31XWsS1hw3NyoIgtjNdi4TxFckXo2AxzC+Hi5N4dZ vy1UamRv586zDUCQiA6NZCrTySKO5Neht3z1YWe3VjqKluWGKi8osf9ewkUAPVEESKMH o+Rg== X-Gm-Message-State: AAQBX9f1uAXk4jlfny/tRo1Bno+om/hfsfe2nHMtyfYVo547/2l+w/6b toJnGunLNUgulboVPBGsBPjTrfCIlfTLVbDwjLI5rdozhQPhQhpjgzuSYpnVCLA+iI4SGOqKAKV VdjuI+JrNopegSJ15cX2trxGPyrwCLud0gZxyIl+heujScnWZ2JgkDw/MHKWkxXV+IzmsPjqb7D DuAyFXaQ== X-Received: by 2002:a05:6214:401a:b0:5aa:14b8:e935 with SMTP id kd26-20020a056214401a00b005aa14b8e935mr4723956qvb.2.1681317765594; Wed, 12 Apr 2023 09:42:45 -0700 (PDT) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762990346753265562?= X-GMAIL-MSGID: =?utf-8?q?1762990346753265562?= 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: 82598 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp480656vqo; Wed, 12 Apr 2023 10:07:22 -0700 (PDT) X-Google-Smtp-Source: AKy350azNsLUGyiC2l7BnbKm5ksPLtWmvSenUUlrWE6k+cOxy3pxdfkzB2R015Bw25KfLXL7URiu X-Received: by 2002:a17:903:41d2:b0:1a5:1e15:9291 with SMTP id u18-20020a17090341d200b001a51e159291mr8637643ple.22.1681319241702; Wed, 12 Apr 2023 10:07:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681319241; cv=none; d=google.com; s=arc-20160816; b=sUpAcfvsX3cZrA0VmoBtYqmOL+9X+lrH966fDvVF5QgAPYXj6mzG31mvwweVYMsNsi eEnoQB/ce4UDulfzdbm4rQ/+E2epHMVvPHv/erDQm0XqT/TrVeNzW/NfvgGpeiEeV1kG 701PU92ZigFK28BgTfWioCW0mBadiOW74KbK2Ax3szMJOgiLkrfGxnjLpgIbD53XEdHm pYzdYZHfW0F5oaVwddgwmpceg7Bhn9Vw0xf8cfFJI6BMLQ8WFcnHri8l0jghRwdnN9ox C7Kkt/Dk8ot2a2KwfNmJJ9+a6BooG3ZaQdsfDB3IU02vWQoAr40zXAkc8JCeoYS1x6BH 4Qxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gEk7ts1lThyIvIfCL1IGZ4lKytmWVdDqEngQ3sxu8hg=; b=BzbG9QqXtQxqEXPk0H6qYVPVtWxat35ZN2TlTTRIFH4WmfzS8mv8XK1tAiLZV3cP+X gJDvxCWsZiY52RHxAUxD3ZD16cnEueu/gzUl9V1PQSnSqD0X8lRqfrNQJKbpDWJmewUV IBK0yAcST4FAtlQ4cVReSyY0toZb/ZQG0M20CcT9NIIqmO1AEthSkOps70nidNLNk6ds lVfyubHm7MdmemOTTOkuqVlHtZw06nqXe3UHzYeEEehl6RiwOQcHZT2HkKmSWy3MD496 kBBB+BV5BvGDsXt+Wux7WJZn1FI9cFFANRtKvZ5Mv3DBmSVfl2gTLnuMZ7PfaBy4QDBE DACA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="T83QQ/zf"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lh11-20020a170903290b00b001a654453ef3si5299890plb.54.2023.04.12.10.07.07; Wed, 12 Apr 2023 10:07:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="T83QQ/zf"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230322AbjDLQon (ORCPT + 99 others); Wed, 12 Apr 2023 12:44:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230243AbjDLQoL (ORCPT ); Wed, 12 Apr 2023 12:44:11 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEAAE8698 for ; Wed, 12 Apr 2023 09:42:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317774; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gEk7ts1lThyIvIfCL1IGZ4lKytmWVdDqEngQ3sxu8hg=; b=T83QQ/zfSNPfNEk0GCUGGdwNGw5/mo+c/aO9XTUtmojndXPlrFZp8H3INe/ae4jmU6vjXh nRtcASNQSmGNoj/Mj87pRTXDYdnULQfv1uOpPdGQtdGlMXSotcOxPFiBTDoMfJfCDGOH7Q R0KUNhgrqEIww11dzVhOX41U3hi7H00= 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-60-ImXb0YNPMdOpFngiTcswMg-1; Wed, 12 Apr 2023 12:42:52 -0400 X-MC-Unique: ImXb0YNPMdOpFngiTcswMg-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-74acb477be6so2297185a.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=iFE9CCpRigso1s9gWKruYQWCNa1WoMAYzMJsBRlhCHdak0RAcBYiM4glDHv1/yDpPX 3ii0IbqTrhxSJA1VY10AgrIb21EdUtM2qRbKnGsqzGh7aCoT4xpkbVsdwR5LadXu8ia+ p2cTRuKyNdsYGNqVCDLB6Vv+aaYhMiaWi30BAgigIGGFcI3wRJUcOg8leQom/+uOLXJb dD+oHcdViZOWOFjzEx6Sy+/F0umYL4T7/Du0HjahNWs27hTxkWyMJiNYG9s6qbkSclg4 AggdY4mRhERSEHt7tHdoM2+rV9cDryohVPmbgZ5Zhu43mLKzozQx7OMhgQu2PAnuHfz9 li5A== X-Gm-Message-State: AAQBX9ee3/JidaoWzpzshr30fNen5MOnM4v3Bkgc8GnlObPi80Bahx0P 8Em74TBRQTkKf8ntlnlGsEQnDSRms5TNHq4I4STAOGFDBpqeuiZIZVTzLi/RFZ2Mabx0A868lGf DRsc0cB1g/ISBl+6dvTx38jh3NGLt0/cEtstxGLJhT+VTRgMYAXjC8ETP/ub+6D2HrgO8oFa4D2 wGwlKdRA== X-Received: by 2002:a05:6214:4002:b0:5ac:463b:a992 with SMTP id kd2-20020a056214400200b005ac463ba992mr4598530qvb.0.1681317767990; Wed, 12 Apr 2023 09:42:47 -0700 (PDT) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762991004824535240?= X-GMAIL-MSGID: =?utf-8?q?1762991004824535240?= 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: 82580 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp474949vqo; Wed, 12 Apr 2023 10:00:52 -0700 (PDT) X-Google-Smtp-Source: AKy350a0dx9EVFY7GzG7EIZ/FZbuBm9YPgvYwMCyGUoSnIip72TsDvHdKgrKK7sNwYRGsHuIIkuK X-Received: by 2002:a17:907:a50b:b0:94e:50df:4659 with SMTP id vr11-20020a170907a50b00b0094e50df4659mr3611475ejc.17.1681318852462; Wed, 12 Apr 2023 10:00:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681318852; cv=none; d=google.com; s=arc-20160816; b=hs8riO6Kx33vRM0KGUqkoy661b6nmpf8hzJZW3R2KqULW4NSSsShvI6Opv+xJ7KnPy 2EBZn1DNmEVQbqs7cfvjg74n42RGMky9Bk4u2Rrr2vH2Lu/jnT9B+GQ/fmyJ9VWChrCl uUilWdLlNeofr9cgIXp6QWxN9VvWX+FUc9tKc1tNcoy9RiAB9kUrXhfrPAdvEvJQc0Gd lM8/C65ZQpjMMWXBj4W3LKH6Idf1jm9KiLBNMZDYfHUWQaeNbfjdIo+SVS1x3gQgoDTd XOM4BoiGIG2ZplcOR+rrWdz//pGF8uKFWcpKR9rRvym8/xJ5lMvHK7ZYBivkQdZ0Gt3m D8yA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ojqw0o6nNzx2NLPCFuTH85mteh7O3LjoH7u5kZisRAA=; b=uO9eXzFFXhvqZ9d1gMsEeF3kf2HtFm88EdL5xpXj71ztFcqJPb4vncokEDKXuiHGDQ dLnjx4ZyF6priPrc38wBF9ZamnP3U7LTCkbAal3VOektpnIysEsrXlsOBcpYeds/mxfG rtMOXYoTqLe+nhcNsh77c9oZW7szd2nMaqq0ure8hv17aRTFjDh5n4br1e7drnQ6cSJ5 ALMftMJRnpqHM3cbs+h+fXo2Wb0LPjnhZrk3MsGuWWBLPZy9zenJ2KwAEcbVrAJe4urb hHTxoLO/X7HLO+8C3PUzNamNbWYrP3AaM61lZj4IvKYpgiOemvZhPFKCHe9bHZRrm958 0THQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GxRNL4Cc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p18-20020a1709065dd200b00947bf51f947si1830155ejv.276.2023.04.12.10.00.26; Wed, 12 Apr 2023 10:00:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GxRNL4Cc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231294AbjDLQou (ORCPT + 99 others); Wed, 12 Apr 2023 12:44:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231134AbjDLQoN (ORCPT ); Wed, 12 Apr 2023 12:44:13 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CE7E1BF for ; Wed, 12 Apr 2023 09:42:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317777; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ojqw0o6nNzx2NLPCFuTH85mteh7O3LjoH7u5kZisRAA=; b=GxRNL4CcwHXwv2ZETHCxUDDCJdDWXkwWRJsQWrxrprWEhbeKQ7EretlkgTtoOc/7fmwFjT PLjLhIWwMmdg9EkVH4//AzR/QofIZR7ONXW90fiV0NaNwtf6dYqMxp2owcXeqlKP7Hf0Ey sftNd8Q1VhA9v63++KcCHdmwo8XCTVU= 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-435-HcfIVNBlMD2-NAIRxPa4Jw-1; Wed, 12 Apr 2023 12:42:56 -0400 X-MC-Unique: HcfIVNBlMD2-NAIRxPa4Jw-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-74a65b255beso53906485a.0 for ; Wed, 12 Apr 2023 09:42:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317775; x=1683909775; 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=gYV1+JT912n/7BAdn4R+H3cZuT0DIhIFp7bqgf2YdY3Mcwn0buc5xdRa4yuNUqrtR3 Ls9+GwjmmRw9zqoVfyykBnxipAgAwGyZTRQI4Ma+zbnjMYloZmRJOnieBcFuYLubFKXT rjLWPQn2K+MD/xndMuATjqpzCIp2M3FdbV3Tj+UD+qA19aNYx7F6zsfzlMGXoJIlzH+m b/IA6sgxOyOV8lm12rZHDgJ7mXpEsuotPWmPQpOtSROt16PnRM/yPgy0RMsTxe355awS PlL51xnVGTgdvPlFfgQVn1t6P9BNMM83PKijY0V/zOwZljvps7dlFd0sGZafAJ+gLNYz EYnQ== X-Gm-Message-State: AAQBX9fC0ufNZI2YGsd2Ivt9B5mWZxz/+3YENnSMXAPsUvj3aCzDFqJM HFdiHqdVRSo/xtn57uzM+LMtZ3BUniZqw2156Y5yarVexQ2nVDJMccuiJj1tpPnSFlroZtwnoNY IfR59tcNXXIu+ZAqAD56geWcHDapjr2JxTp/VqiIJX/bvAed1jq39AjZSjpPUrNSjxaOmAtIAAk cDwqQWZw== X-Received: by 2002:a05:6214:529e:b0:532:141d:3750 with SMTP id kj30-20020a056214529e00b00532141d3750mr4507661qvb.2.1681317774623; Wed, 12 Apr 2023 09:42:54 -0700 (PDT) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762990597117342000?= X-GMAIL-MSGID: =?utf-8?q?1762990597117342000?= 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: 82571 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp470663vqo; Wed, 12 Apr 2023 09:53:29 -0700 (PDT) X-Google-Smtp-Source: AKy350Y8lCWC1C9plrDOL8PijSiEe+5kNFMX1mpyo6LYs1aGKtXdLg13poJdHq73ZIN2LoN0U98S X-Received: by 2002:a05:6a20:4992:b0:db:f682:65ed with SMTP id fs18-20020a056a20499200b000dbf68265edmr3276561pzb.61.1681318409457; Wed, 12 Apr 2023 09:53:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681318409; cv=none; d=google.com; s=arc-20160816; b=ntO7M/EUIbjBfo9Q8TC0I85wqxXwLeSEhyOIrjHGEmdtPR/T1PRo4/AxbeQajHjM1x ix9CeET4p0T0HZrGAoHdUVG3F6GFASM7t2J9WWB6km/Qr7cmkOGzwj36lFXJ7YOv2TMX 26eaEsN1+7rprAQRieCbLT6dOL4dW77nKCBIpv6e5BbaBOF+3I3BPLS38iayNVcJJ7zb zxXsKba63AAx9QotqP8IZmZnPrY/Zr3PkNi3hTfeF4wK+QmavtFiqf5GmWVeeLANdV2d AtItMl/pK65sPuKxvDosQp2IVIwAun8TgS4yydKH4MZzt2o1M4KXma5Lpqfy8eaGhVfo H39g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=AoupzZV60neLuDl2cXNTlifM0oGkfquzJdJQPjel9/o=; b=K/KpksswrF/WBfmmQ0uAA8cv86Mk829i2yf6sbvwJPx5dJDdULtymhZFSZacAELIuL /9/EnCGTz7X479EYBKFRVKhQBTHeunGpj/TAObM/UR2IbuNbrPv+ActpWn4iUFr9lqBr 7PivNClKaMjLtbPXoNqDpro+xu65gcSAjRkrP+bqsymbM7Kf2E3TFR2s9iDo7XPDsCHs v4xg+CocoJeSsUzpWJ8S29U51H1PYq0PDCuRHy0k7fphZIFr+1BuP6e8zPKTqzXfWwtw dOOdmecG0CGrsue4Q7vwt/b/L0wMump7241mV31/Va+IzgjPPSPnrB+A8lwBv93baUo3 YybA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hPB3rxrD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v127-20020a626185000000b0063b1b437e53si1353223pfb.306.2023.04.12.09.53.14; Wed, 12 Apr 2023 09:53:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hPB3rxrD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229749AbjDLQos (ORCPT + 99 others); Wed, 12 Apr 2023 12:44:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229567AbjDLQoN (ORCPT ); Wed, 12 Apr 2023 12:44:13 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08D0E448B for ; Wed, 12 Apr 2023 09:43:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317780; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AoupzZV60neLuDl2cXNTlifM0oGkfquzJdJQPjel9/o=; b=hPB3rxrD2dI1QPBys3g5wafqp8peA28f3RQV1wIwEPoxfT2LYZraDjLdQirxtEVstV226L 6LgRuOOoxf8CDyjIqL7UWxfzNWNVGM816oEd6SJgqmX+Dt9rCgWhGvsCdpWJi5hN7tFe4o BL/DqCUDaUeRHmj0cE3+UgWLGKBeqnM= 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-114-_MJ8t0T7Oaics3B9w-nD4A-1; Wed, 12 Apr 2023 12:42:59 -0400 X-MC-Unique: _MJ8t0T7Oaics3B9w-nD4A-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-74a90355636so62117185a.0 for ; Wed, 12 Apr 2023 09:42:59 -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=PdGLWHsG6HRHsWyjdi+mkv7h9BL4PyUceSYtX8gi8c8YwgIauDPeW0jYslFmYTLJNV rB25KwqEfBd73IFIUyTJ6P32AgIHQK4jy1AjPC8gn6XS9NnZ1SzW20l+MIF6XegOXosU 4rXgZ3Cqyl+UKgLDh+KAKkq4HA6Gs84Wv80TEjHpEQ0I4+tAwPBX1lwtvy0as3c5GSr6 2lKxlhcp0RjX3MAOA7Nv9Y1dRsEYgyOMo91sWYVwRkSJuV1SyduWSBp9/P0gWOHmq/pt pvzYw7ZqR1U/2Wq4bPruL5zza0dzUc4UZiCA2qODqNgEGEpahjD68FAQUHw9+BjvpNgP NyAQ== X-Gm-Message-State: AAQBX9d0VvMIDlYg0rMJi/Z8hbWZiD2xdhL1wuxhu9IMRMIvOSL5FuSI pMhVU7zG1R1ruwT8IBkKLWnv3MjFnVEAVbav0EMjcxCrQe+1UT5QfWMPyEuYLdvMR7J8BGweuef 9wlQw/2/FNcSKDDg6TF1QJJRK2NCjgPe6Ht8fJugOSdad2eU7uXx1djbPorendZ7PMi0JXU6fmo VhREg54w== X-Received: by 2002:a05:6214:5290:b0:5ed:c96e:ca4a with SMTP id kj16-20020a056214529000b005edc96eca4amr14523324qvb.1.1681317777552; Wed, 12 Apr 2023 09:42:57 -0700 (PDT) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762990132604259864?= X-GMAIL-MSGID: =?utf-8?q?1762990132604259864?= 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: 82570 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp466753vqo; Wed, 12 Apr 2023 09:46:55 -0700 (PDT) X-Google-Smtp-Source: AKy350Y4179L2o0vyKPBvmOjMm+UaZiL+hpvbrNyO4845dotmTkoTrgWxtdnkxSYFtIn7fmeanFl X-Received: by 2002:a05:6402:788:b0:501:e26e:502b with SMTP id d8-20020a056402078800b00501e26e502bmr13763130edy.29.1681318015435; Wed, 12 Apr 2023 09:46:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681318015; cv=none; d=google.com; s=arc-20160816; b=hwBy2DBXIiPTreC2EYWJFJOlfLcDOywpOUIwQImTYIZ/ZbhaSnIEtGCtoSxp56hDk5 7SCpT3hQC80SyofRz57jH+TQ89YZ/Aq2J92x4dl/i9HCdFPu9TDwhikvM9yYpE2HwQhj LjWe4T/1jo5OqCeM/7hfQYKCUFRLj19uJckV7noKR7rG5kUWoQtg4hf8yZ42X4Py67xe c5dKEYJ79mYFV46aIpEAF/tJh13W6nKVt0W0sXqsK4RD1QBgCy8wRC6hu8dIJZ4fqAus Ir3NDKlimTbC2SOHSYMr2HRIf5oNkXg7VYsa6APQSxCmISvdPWeE9XnruUW5OXjGYynC 0NLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=j2X1citdDCADI79RLi2EG2irLSOXCvsNG1ixWpJWId4=; b=z3ho/MDCvG27DyUD09WB1tlS3RTimnbTqzxGyO7oP4Z17Nl+OeXit7qeEwdSSYTVT8 rdPXiprvdrZzzeVXtKDhrBNuMESzfcEWRlR7Qfunz9Vj3LkGtzej7Z+BAuCiGD1OZckA a9RD7xcl26jr23OqFlZOnNr/rx09SoiQDbbM61782soyzkgkFihtNKxB2DlUmTSTodaA 6MjSXJRtGSwEy0YirHJhqnOjm2TjuJJ/DcfKVdcTBZ+BeprCT94WA0cGRVq0ODFdGHz6 eHsxOz0Qr7i9WJ9DTfnZ+lUOc+uUAMwiSNu3TmiGbRJLNo5ZKN48cS3lXVMyaWqZZikW uLCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DlSVK8f9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n9-20020a056402514900b00504b647149csi2819890edd.550.2023.04.12.09.46.31; Wed, 12 Apr 2023 09:46:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DlSVK8f9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231207AbjDLQoc (ORCPT + 99 others); Wed, 12 Apr 2023 12:44:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230115AbjDLQoJ (ORCPT ); Wed, 12 Apr 2023 12:44:09 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 399C57D93 for ; Wed, 12 Apr 2023 09:43:07 -0700 (PDT) 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=j2X1citdDCADI79RLi2EG2irLSOXCvsNG1ixWpJWId4=; b=DlSVK8f9fdO4B4EsZhwD2K8UIyVGkTCFAaeglPjvOAwQY9/RrpOkyrMPUcSps5cA4N/WHQ /AJCuGwWDnqC0Fzvx1txUQ58j6JcCPHvfTH6JeYQU19/ionDTmWwPPvRSXXKVCX7D745qO vYmovK0mBqf8QFw7OqtLG6DWSO1T12Q= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-147-Kxfkd2onM26Psee6YroXEw-1; Wed, 12 Apr 2023 12:43:05 -0400 X-MC-Unique: Kxfkd2onM26Psee6YroXEw-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-3e63ec50808so4676541cf.1 for ; Wed, 12 Apr 2023 09:43:05 -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=Nq/6nol0EX9ogSzB5Bt8cZdTlx89dOCmuCAgB1SdexzyDqCBZokM7OH/nXXmQqAjfg UggDq36oXPhEJkQ0l4zGbCxtraNxkGmfLmpBsKOO5JgRT9bDBaPDCBRBd9VN97P0es1k Gbo7MMbDlAI0Y6FM57GDwVtZBHUpE2Im+buDb5pyh3DtVdojpm3/lDpvITqLbOhO2xHt cGgeLyLgXjG1Wkx310XOEkxKB1gW6Tlwr9Gc1K3g7i5cPbbpPhomOOFnCes85yDQ8BKA Dm6yqsZrZNJSrWAQIMRpdySu11N9/UWm8IRbKauP0BMAmIlRq/oxhU25unuF4J04moUP 3nmw== X-Gm-Message-State: AAQBX9eQxzG/tM1iwkG/0FpmrrAVMiKAwq6AH3QHW7JnUgX8gprYttep 6fHx20yWWvAnMwINmOp3kfE6Bc35BcFSdQTcpww7BfVwnGWgDJEKUcj7dR46uVAga9Rg5oJ09h2 OdJGmPQW3cCrsc/f+MANeFp99egod/FTWC8IHIp+CsgoAIqhSa0F8lH7sbvAh/R34rU/zncqmFR VpYhQJAw== X-Received: by 2002:a05:622a:189a:b0:3d1:16f4:ae58 with SMTP id v26-20020a05622a189a00b003d116f4ae58mr31197658qtc.2.1681317780631; Wed, 12 Apr 2023 09:43:00 -0700 (PDT) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762989719104235244?= X-GMAIL-MSGID: =?utf-8?q?1762989719104235244?= 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: 82581 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp475386vqo; Wed, 12 Apr 2023 10:01:18 -0700 (PDT) X-Google-Smtp-Source: AKy350aK/ODrUSHkVPHbBtprjCW9uEqcOSsyA71xh2PaogrGgii+es/uYSL6UcVYqzYgAAcXj4wf X-Received: by 2002:aa7:c754:0:b0:504:7163:2a36 with SMTP id c20-20020aa7c754000000b0050471632a36mr3124943eds.15.1681318878608; Wed, 12 Apr 2023 10:01:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681318878; cv=none; d=google.com; s=arc-20160816; b=w3nOiwoMUE/KgBW7UcQtVKR3Woq14XxUhV29+5q44qar2Hsf7LkPQ5prKxGiwE0d8o GPTZfIlVzLnCz0CLesyVTKGuZoPIfdEDeUOwLmmV9mFk3m3Pl7TYsqQAhk8Pd4H6k4tZ sklA99c+/XKzhJ+xju5HT08Pc7ROGCff8FDHPp+DMAsMWZm+1EiA4YrlDgDssVrclbua 2YNR25SlsqkTxMKIJ8qQXsdyDpZkNpC4k4WFxhhMRFcxdhOIjSNIsqdYY7KRVJDu6QBv ziuIt1GNBxy9zio7BV5fvSpBWx1T7g/xyZ2LvnmFJpcxwHVOwS5tcQT8X95mZo1gvZKr M6ZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mjojpcmOEAy9sHKJxFBhh1D6ilVghlmR8goVSOpVaAo=; b=XOoPXtJt8/YcKmEZzfYlE8iKRkqaPC1cskevVeyvlspbqxgwPJ+Iu2l3NiftXhg5Bg uJC49hbJem9teg6xXj4wh1Hsd+hm6qBL5LDIoXeHp9FbMM7jbBpYRpcF8c2ZVup59ZJG BIkR/4ssZLoxHltsMa6u9IuH0mYCxQfNghNs3FW3L6e76LOuNNZPrCvlwJHyjTfrsv6V iNyZcy8K7s4Dx9kM4Wm+GNhtdwFKiXBJnnsygoLvWUAenVEDrx4U6/HH3z8rLREg29JU DuQbNGxOX3u9x89thgENkmxv/JqFZ/8+EDUYXQSr0rxr8T/lgaKNkqKgCELy9npTvRwe yfdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="aBPA/suD"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e12-20020a50ec8c000000b005048be8a371si3327877edr.441.2023.04.12.10.00.52; Wed, 12 Apr 2023 10:01:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="aBPA/suD"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230298AbjDLQpI (ORCPT + 99 others); Wed, 12 Apr 2023 12:45:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229678AbjDLQoh (ORCPT ); Wed, 12 Apr 2023 12:44:37 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 883CB449C for ; Wed, 12 Apr 2023 09:43:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317816; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mjojpcmOEAy9sHKJxFBhh1D6ilVghlmR8goVSOpVaAo=; b=aBPA/suDeuNhHVeyeXpy4MKFGsYgT0CRWEZxQIpSRfXcJ+2atooRjBMogLXDZFWImH4cQE VLnClEHqHigH7qdAby9g+gSd2aKYDRtOhsV/FtCae1g5fE6f37uk5wzbsM34jLrNVt7DFT +RlvJ3L8mbnF7DGPB67CCpRSLvxV8ho= 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-455-u8VGGvg0Px2J7zF16EaBIA-1; Wed, 12 Apr 2023 12:43:35 -0400 X-MC-Unique: u8VGGvg0Px2J7zF16EaBIA-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-74a7c661208so92379885a.1 for ; Wed, 12 Apr 2023 09:43:35 -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=CXiMRSMlNhOQFs5Eta5LVdj570rog09IkKWHI3yGMrukZIOSaEGBEi+iwjNJPaT6xN lFjioQb6R63i7DhbBx6lenqoozJi6GMPEOws2Q6XrBYyr9kAX9y/iahIX2vQLTPhzpid UdeaB70MfargCKjBmLmLT5jdzcerkvGKGMlere1SLer/tIfNZEGjKaH5xmDTbx2yPMfV kr1DHBWQ53WrxYjv1fsXBhQWuR3mFmuMKfIA2r1p2FzkoBXJnLcJTxiqnq5XwqwmMwuy cmPWjsNA7b7FS6Zvam/+AcHFvr0zIwMs9nIb5ichu19YXvI+W1HFb0ydIxlQwI3zXouL 37Sw== X-Gm-Message-State: AAQBX9cQt015oRAW6WduCJrnkTqI3a4XoDTvSNsTgPtajNp4/NgR5niZ f+4vKv5kvVwvqWRoComYOh+DK6OATFFr7ZxjSRbPUOEvpNYuFzEox54OuLJ6V+qtnhmpMlSQFIl rLwtjEIu2xZg4h9HO/rJb6pvglkvU0kplH8/nb8XYPzFJA3I2HiWbcaRBARLTc0o2yxwdSDO9f6 CqOju5cw== X-Received: by 2002:a05:6214:4009:b0:5ac:325c:a28f with SMTP id kd9-20020a056214400900b005ac325ca28fmr28040733qvb.0.1681317813875; Wed, 12 Apr 2023 09:43:33 -0700 (PDT) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762990624310075210?= X-GMAIL-MSGID: =?utf-8?q?1762990624310075210?= 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: 82572 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp470913vqo; Wed, 12 Apr 2023 09:53:54 -0700 (PDT) X-Google-Smtp-Source: AKy350ai4ArMucx+IzTLNxHtyrQB/qwNN5VI1VQRatxJ+vMJych/ESdt+e38sjuuv8+CblkVxIdM X-Received: by 2002:a05:6402:124e:b0:504:b305:118 with SMTP id l14-20020a056402124e00b00504b3050118mr7182986edw.27.1681318434685; Wed, 12 Apr 2023 09:53:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681318434; cv=none; d=google.com; s=arc-20160816; b=ZOqVM8337F8wd6oU/3JwmnnfsqsU7Zl4suixW/di3scpkYRsqkWoPBfYT3uAM7+uYb TjSjjshJZQeovffaeGI0TKDB2Xyu7YIB6pTQt6HG9PyaoclAP0VRYY70k21nNzptxsf7 L4Ifon4tWNSBPBGi5BDRFa3lRBxrhE/qCSNiM51Nb0TL8uYFmH5HDEXdXSlSeoM0xEYf rHy70kUW/cf70hrB72jeU6ISBzWusXUs/YITIW+AI0aMJso0U1fuWLRTdmjniaQAyMuE CvyTsY5f8Y8z50He7lnobYYtgumyIiq5tRSYTmSmVNFe/wygQbLFGCOS4233lXjI0z71 BlTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0pO7URj8vYM+yjGhq+aT/ST6K4M19Q/F9Gc+2VYksqI=; b=X87HgyNd5pmW8SRLoM3eeKnUNuxp05p1urD6GNjQfp8KNtNCL8x90Esxn50axCcYqy 4euaxcRolzX7sXvmqSEeyH7lRCM0QMG3nkOlb8cIFxGSDFZwbPvP5VSr26LHnHN/q8Lw 92kiUvfY3/q/kQlgkbS+kU06s5DqJ7K8snezxD3ayHKTwqr011PI8QhFAmGgP27jHyCu 4p7AitiBT+vFaOv2bUZMOJiFlGCngkkCRkmf2srvswRy1dyWUg5dXyjc5RuuGj7+ll7O +z0KmwKtXHa1w60uMUwtsElLiXHPlZTTvzh/9YdITl9fChL/xsIw7eku/NQcHNn/s2vO BZNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Xh5moXEx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p12-20020a05640210cc00b005050661fdfcsi1455571edu.451.2023.04.12.09.53.30; Wed, 12 Apr 2023 09:53:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Xh5moXEx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231239AbjDLQpN (ORCPT + 99 others); Wed, 12 Apr 2023 12:45:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230233AbjDLQok (ORCPT ); Wed, 12 Apr 2023 12:44:40 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6E3B86B4 for ; Wed, 12 Apr 2023 09:43:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317819; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0pO7URj8vYM+yjGhq+aT/ST6K4M19Q/F9Gc+2VYksqI=; b=Xh5moXEx1lVc7jN9g7/xiWDUGVKRaHl9O4zyEHgmqCTVyAHqvEjC1GkujtUWVx3C5BucHW ZKA6APvA9Gx0XAh5NHtJ6aqysoilohfEolOx5PCkXyiugfDDyjArWJN5/IIZIflXJHJT/f y0CkHrFCrvFImqo3cn2OhB2tKpHfjGs= 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-371-3AJ12pWrOYufuAWBF2NedA-1; Wed, 12 Apr 2023 12:43:39 -0400 X-MC-Unique: 3AJ12pWrOYufuAWBF2NedA-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-74a25fcda05so77612885a.1 for ; Wed, 12 Apr 2023 09:43:39 -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=aX5PJo7TpA+a2kRi8L0bM34qMHS4hlmN8nstIZt47XyAZxo+Dw14ZegxAFAG9d7e0C 2P4d3yPsXnNxFFdlqsq15DDrflV74BK2C7kKifTA7o4k8Fe3vDx+VP4AEdoyHTHb1BIY ph1uT7BuSPAGBic+rG8ek9AtA6BDi6DW9svTV1/ly1Jf1zWanMqMJc1NivL/QaEdEuf8 Awy/3LoorA9bUrFlzHBFUlEMCGXTwjJZq6bmLvCVBudXTjYxAYgQPvDnymhg4YqUXaYr 1DQkRkXlMkf8nLMKFdUWqsvGd3AHUjPD4KOyZoExzxoLE1sMREZpqEt6JJudzHr6T2k3 VSzg== X-Gm-Message-State: AAQBX9fZvs/Q3rTtlsJhpaMqoS/9OrGyN7L/nP2XYpP0zdu9QVpfNqSc UGK+DXZ/vD+gPA1bjMRPB9rBjwb0V6Th7R0UPBDrB7j6cNlr5jcHEYaekjS27+W4ZECeouiK6Q7 BGmz+cICukwI4oliMQ738Jp1ctNmn+T/jRw+yS6z74oURY2QbW6XbFfL2pXEJRf1bzp5x6WuxMU 49+9vRew== X-Received: by 2002:a05:6214:4105:b0:5de:5da:b873 with SMTP id kc5-20020a056214410500b005de05dab873mr4443944qvb.3.1681317817310; Wed, 12 Apr 2023 09:43:37 -0700 (PDT) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762990158984499348?= X-GMAIL-MSGID: =?utf-8?q?1762990158984499348?= 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: 82592 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp478976vqo; Wed, 12 Apr 2023 10:05:13 -0700 (PDT) X-Google-Smtp-Source: AKy350b9XH1CpREEbxjHYBDfFa3mUxnOwyXASMnxqu8/BLxtjIGSdO8HyczYNj9Q3nx7uxirl/FK X-Received: by 2002:a17:907:77d5:b0:94a:798c:712f with SMTP id kz21-20020a17090777d500b0094a798c712fmr7165764ejc.49.1681319112955; Wed, 12 Apr 2023 10:05:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681319112; cv=none; d=google.com; s=arc-20160816; b=apIiNzAw7BDZ3QeQKjUZhROh7Kp10G4f9U1Vnujhd3lqJRUUqTjdIsr6L7thZ2/BIY dqnVBMp9pgLf2UmfzBWTg8AJP1VDBi5MDFO2UaV2tmpI+22SdVbkBz4VSVNfQfHCKHAQ n51ZXpyCeFEf6xW2W0oK8jMGFXCpOMNfDUxd4lW4LYZeJmo+Se7CV6qFsfc4hWzXnI2A 3Ns2ud0mtsrPWlgDbkJsAbsOoRHUy9f1GLG+6gpAXPXAjyZEet//GXGIv665BnSjrmVq 3K3nizEQd3xfrU9fp35/96oZpQre0dneO4uR4DGMdWY557MBMN2tbjbGkdnkah2HEG6m rm/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=y3C20L7q6E0jI4D7x0NRqCKUvj6UY8rhbxmq4jIDbcM=; b=wx1q9Inici24OtBU8EWDv0cJCp9FCt9D02BepGMmvro+OTSkY+AfS757VMa+IgclwX uZB3PmVRtgwBK+SAxd9m2O42nBverLHGhV6rSwlza4M4J0StHT/QXtqOyUrnHYf+kBNf IlfVVqy2OfDoCCw56loERhSEGjbUxF+pqklJ24dIqan9oar4HWl73tV+AGw8X1Ig+tf3 2dbW1WlwLJG1tfq2mvoDLdkIdazVjHCAcHhxubRxVl89J6DuHD7QDLcUOAoyAnutiiJb iTDEtuTwUoc8Qsw+Gm1uEXDsVDaPW+MCG2DQiM4BHYJMeU5BcFwGImrFzVeGZvlcyR+6 1Ysw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HDbafzJ2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id rg8-20020a1709076b8800b009301cec4c31si14327453ejc.994.2023.04.12.10.04.47; Wed, 12 Apr 2023 10:05:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HDbafzJ2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231286AbjDLQpR (ORCPT + 99 others); Wed, 12 Apr 2023 12:45:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231235AbjDLQok (ORCPT ); Wed, 12 Apr 2023 12:44:40 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC2858A7A for ; Wed, 12 Apr 2023 09:43:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317824; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y3C20L7q6E0jI4D7x0NRqCKUvj6UY8rhbxmq4jIDbcM=; b=HDbafzJ2Pfs2wWHB6TuFWHRC0bQ3XQDzTWD/mH+v+Rm/OlBx1xqGMFC+r6YWo+rBkYAv9Z 1IP0G6ia4YsVo84BZIIwTsBEidcD1+XvMAlWZQCtUM/SBdt7SzcjP0Eb83SMMBE/Fw7k2K U4ElBfL8ESK7PJ34oSzrmOV8lgCg6M0= 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-39-3k4y9FA1MKC4WR4QTA-qhg-1; Wed, 12 Apr 2023 12:43:43 -0400 X-MC-Unique: 3k4y9FA1MKC4WR4QTA-qhg-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-3e699015faeso3543961cf.0 for ; Wed, 12 Apr 2023 09:43:43 -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=fck4d30Qg3nfpLDZeN0AwhY3TZAH82CpqJNT8xRxABX9XBco8b5RCjSo1DaPbeqdVO 2EcZCRhLmfIBt88kF2OzSoujoxtTD6fRuoq+aMW/SY2233H5RuyHdKujZuD0iLIwcQPd gub3rL1Ky3ihm+roTe1mCvg8sJ8h8TNQc2l2teMB8yxdLC0jo3VMnQLv9k0uP7yh3mzR zxNpjvifOZbPP067lEWJszQgEnEgEdS0TQVUh+7Tf2EE4lnJIq0T2h8kMTyswyNQf4FA u6iVLIzwsvqv0rSRq3KDGciXSZ4QiC6wGjFzj3cWcvi7pwZxuprdBGlmX9e6PXpxItQx mAGw== X-Gm-Message-State: AAQBX9cf1iLkeYWIJ4tRFYROXdGQ0GZOAPsIuEMutKHNCjPSE9rhDdMT ul5svrZiR/8tMQfayT+UbI9jOrATJpEdAlGHJ7GKRXSr7VrhupnrWm8RSyl3xf40CH6x4kuGksF bEH5lZFB+XqIvVhzPpCNg7LgA4RRP9Fo2RoXw8hvlrQ26rj6PQ2W6cUtP3vGmO2bCnmgQFTnwK+ JRmgZ/4w== X-Received: by 2002:a05:622a:14cf:b0:3bf:cf77:a861 with SMTP id u15-20020a05622a14cf00b003bfcf77a861mr4120233qtx.4.1681317821882; Wed, 12 Apr 2023 09:43:41 -0700 (PDT) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762990870350743429?= X-GMAIL-MSGID: =?utf-8?q?1762990870350743429?= 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: 82579 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp474927vqo; Wed, 12 Apr 2023 10:00:51 -0700 (PDT) X-Google-Smtp-Source: AKy350av4vWLeQIUuqf8+r49zFu1+AA9AQaTUyiqzdJKT4WjCsYzjkrC5oheEcf+SLkB/HZil0Lp X-Received: by 2002:a17:906:4f91:b0:932:2874:cc5 with SMTP id o17-20020a1709064f9100b0093228740cc5mr13106112eju.16.1681318850895; Wed, 12 Apr 2023 10:00:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681318850; cv=none; d=google.com; s=arc-20160816; b=uFE4Qx+PDS8Tr1S5jXAgE/WTx2bzwf/WT5ahpl1PWsZNVTGP38IjtKfZd7G1T6AmQ0 Sc7paDBwqH3NxrC0kdqVrqfoK4g3Hf34FB549VYuuL5wtDRaxQUN8idg9M3n8pcOF7JD wAw4g8dpZuIA5/5kVi1PYelHVPGzoOvVoP/HJcV6P6qm9MSE12YQOqYSJcoa7KbuUACF IT0VpRrrnC3GkMyetJ3u7W82OUWBPLUzx00fHNkrzQBnO04Pn+8EVgxq4GnGvlrJEcBh MIiztAazVi5AjgyoVyK/xPBhbq6qL0lRIICAWom7oThUoXrRlXfOEUdM6RSHjprhFF1r +x3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=BeK25Zk7G/NLwTDOVvJddw9Gyk0/O/quMsTWu17keu8=; b=tz9PgbvQVwXXeHYGupF0RkBoRsbsqpixRtsW+Ym3eXO7McK6lxxfOTolknCqNnm2iq lqz3yEdkYrOe722yh3EPjoGIayJZLCZzCxpGwMDEoiCtLVfeeL6A0TdqFTN9OQcplY1s e0NXtWy1sWOTa6jnu/0IC7rUpBS+z/dOjiNEExajN1ds5DpU69tyzJDYLKB+UXctomHN EYHheDAEXPT8aVn61wmmzRZgYcUYTLg1wsz+WczWyIy7vk+e5abyaEVLiLh6pVBDi14U x6VHyDasDc7+cCL2SoIq1lzH6sJb5X6JHRfP9lLoGzh6PKfvfqWxxmug5kSmCEY+rlGc 2q/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XThYpklB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id rq10-20020a17090788ca00b0093083e8ec20si1001472ejc.56.2023.04.12.10.00.25; Wed, 12 Apr 2023 10:00:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XThYpklB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231378AbjDLQp0 (ORCPT + 99 others); Wed, 12 Apr 2023 12:45:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231414AbjDLQo4 (ORCPT ); Wed, 12 Apr 2023 12:44:56 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4EDC86B5 for ; Wed, 12 Apr 2023 09:43:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317828; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BeK25Zk7G/NLwTDOVvJddw9Gyk0/O/quMsTWu17keu8=; b=XThYpklB4bklmMInCgZIjFHqgHf737RL0Gw2udByEypz4t8T7Frgv/4Mz7lyWNHO1yyemj xR0shRsmVAhDLWSzbMwFLnddnQDJHGiosBQgFhieRipGvb8u86NO61/26xVh+pA0lp8qCO DjQfcaW9+XOY8tARAlL4IAzF9Xy0NS8= 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-623-7gir-xTMNLGQbhjdwHwwFQ-1; Wed, 12 Apr 2023 12:43:47 -0400 X-MC-Unique: 7gir-xTMNLGQbhjdwHwwFQ-1 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-3e699015faeso3544121cf.0 for ; Wed, 12 Apr 2023 09:43:47 -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=hkziREXSODP7lIrvTNVcw9PM+HJ/JMQWyehUT3u+mR412MvY+I4c9gcjkdRUXK/3Fl UXAIVMSPNWqU/quxzIlX3W4/I/3kLbg3CcdUptPod9SeWzL/jiyWm2Ri7a6z1YvwIOSq g2VljJydAD5EQD/1XtT2jnOVJQr+mu0V+IyFA3jyFHqoDf9oAkOuoKImZBXOLP3Wqh0L mKwOPDGes5jm0q9NsW1CXYOVsk3Y1VEeWysalgO19cwDu79CDt8iqPepHJC+QseV4fqd jz3ko+z8DmOdcSIfZa1m+MW5ftGhr2+dzKOf7PQjU4bXhEqiXc/GnNk6VUbvg3O9HyX1 4EBw== X-Gm-Message-State: AAQBX9ekRjlkiPHR8z4STOiiedRtaF9W57WZu+JmsYRUrrj2H+wTsawe aBYaFIT+Ags16BVZ9l8Kn7zOVK14qLkpfMenPBnn8CVfS/yh+IdHPMY9k1dwxV3HQkbV1T26oVM qcWfHRSotBzK+/JrxhtwJpApBskh+hk8D/eNMAJuXYVbapGenxCqsPORv9vXWxccucH44Jp+gng phnj7OGQ== X-Received: by 2002:a05:622a:1891:b0:3e4:eb39:eb8b with SMTP id v17-20020a05622a189100b003e4eb39eb8bmr4000953qtc.5.1681317825559; Wed, 12 Apr 2023 09:43:45 -0700 (PDT) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762990595196274080?= X-GMAIL-MSGID: =?utf-8?q?1762990595196274080?= 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: 82596 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp480347vqo; Wed, 12 Apr 2023 10:06:56 -0700 (PDT) X-Google-Smtp-Source: AKy350Y48Ijx8bOQhTEz3eEYF/VYvYONTMuNS+tTMpLnqTGHKklnJjkl9Ox1ACaiZAnplBfUJxPo X-Received: by 2002:a17:90a:6c96:b0:244:d441:8f68 with SMTP id y22-20020a17090a6c9600b00244d4418f68mr3765157pjj.16.1681319216520; Wed, 12 Apr 2023 10:06:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681319216; cv=none; d=google.com; s=arc-20160816; b=cYRhOU9X721cFCgrGO3k90p6Wb1Rh7Vpm9UMI7ktwM1E+3KyMZBAGFzrkz/xdbk48D UBbotiiwYUsWO5G/DzsV0I3q/6DPRHCGlVMvjajJ0DX8lAXqVhOQtsbk4ceZqIqsYAaZ 1iI2aeETWAho7xw4fET3usurGXXUQeQhvTEOUjoVHuQxyOaFqBgv1VbsxN4o+cGk8Aev SpFi+Wo+TsuWpsMCHBWu8Ot+nBKJyqs0YdHF0minHIjFmun+m9PY3IYoInvoBTA2jqzw YrkhKB/xL7OVLI6Ve1IxSD9qrMZI5U0EYDUR8zY7eKTUKbzuuGLkdOg2r3u1CPHxH8lT 4Srg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=q6fb7dGe8Qh9zpC1XHTDp4auTsAlmohzusSG+yhHPLI=; b=sjpJchnxd39bniW5NTki0xwlQkQ2CQJVKCTWuBjb6QQuOPyiNLGG2Ml7z7ed3KH6Ki Z2uBZdl7ziW1ZLeorJHOu7XJSIGslyHjjOJHlTXyXUpYqq6V96Ty2Vxgv3Wu89ahKyxs q1dz6YqftpoMvxEjmTL7xYi3qSC2irwgVdut1MtxdcuNXbgNyw5ZxHyXjw3mZN3F+ayl nXq0HlyACMub8UgUamDAQ+NclCancPcPOh4r6dm9twup7seNu+95LZL2iFg8S84VZwVU xHOARjoXNZm4aMbO1I+rrtFYTb61RB0dFAItKR6r3ktt6buTahxsVv/1Z/bJKVnRaWt5 0+Xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JDRit7WO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mq6-20020a17090b380600b002467fbfc021si2602886pjb.23.2023.04.12.10.06.42; Wed, 12 Apr 2023 10:06:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JDRit7WO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231452AbjDLQpj (ORCPT + 99 others); Wed, 12 Apr 2023 12:45:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229873AbjDLQpD (ORCPT ); Wed, 12 Apr 2023 12:45:03 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D9BE977B for ; Wed, 12 Apr 2023 09:43:52 -0700 (PDT) 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=q6fb7dGe8Qh9zpC1XHTDp4auTsAlmohzusSG+yhHPLI=; b=JDRit7WOzUsZLUWMU+pHu93i8EbKOUTZ8EJmmPEn9yI8rmE+d1PsKh5H+rYP3XnY5GHtd4 gtfySFhFZfdUCd+mMJTEupWj/AmPqsSTDuYaCMmCxTLAAG+EGWGYZubxOYSjVc+elc3vhQ H7tV51F/FYXYIQdxp3W5af9XF3mzhOI= 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-643-_cxnZK6MPr2gGqv57ODuMg-1; Wed, 12 Apr 2023 12:43:50 -0400 X-MC-Unique: _cxnZK6MPr2gGqv57ODuMg-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-74acb477be6so2310485a.1 for ; Wed, 12 Apr 2023 09:43:50 -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=BnJICVU/msEcEC6OzdtpGiZzp7/3fRPu9hiysijvi1zXodHxrSkARamRFUjS3n55F8 R+GLws2c52KIPxkD088vf5kAmr3ZrzK7FY/QbvbI5IOc1yH3iUvqGU9mFqDB0qmT4T5a VcP3RTsMNaUONDXcia5G3+mNesnB5MVBMMWYahe/wj/87NjjBGTSFctuTqhz/LtO2j4N Fm+hyD0Y7tEKbKMmRRLzfTS6E7zt4XViEYvsLDCYcYB9T2h8YY+/2Bb0c04nbibindIc PINiWpFHsGEeQ49pS4ntwrqo2pBMNaJUMpNh0qX8SYEabxV979EB352S+tMvA+CkRUjW SKzA== X-Gm-Message-State: AAQBX9exEPvER/e+z6cAIVRdsIPKfzb2ppcFQRUJRP5gEUf5ipFAEP94 citSrbE6NbbDa4OmGPufJuMzrXCGt7LM80wp8ES64Uw85EkXGMWOR7K7AxmgQKdTQwzNjWASoKA KXGAQ6vL9yMcccE1kDVYpy0fSm2FyM/8AThp51TQ4cdt7dYEFB943eBMgRLBHDUxMlzEFBvLBmn AaAIw/WQ== X-Received: by 2002:a05:6214:410e:b0:5e8:e227:982e with SMTP id kc14-20020a056214410e00b005e8e227982emr4492241qvb.3.1681317829026; Wed, 12 Apr 2023 09:43:49 -0700 (PDT) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762990978761408200?= X-GMAIL-MSGID: =?utf-8?q?1762990978761408200?= 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: 82583 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp476327vqo; Wed, 12 Apr 2023 10:02:16 -0700 (PDT) X-Google-Smtp-Source: AKy350bJPNY9fxrx2HKz6MWyV521SJc3eTpe3amwdZlw+i0qqUDeB5q74KM6gxSgD2y2MD7MoQoS X-Received: by 2002:a17:906:f14e:b0:94a:99f8:7457 with SMTP id gw14-20020a170906f14e00b0094a99f87457mr8686636ejb.40.1681318936142; Wed, 12 Apr 2023 10:02:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681318936; cv=none; d=google.com; s=arc-20160816; b=xJrl10qVEfJX7eWtil8KT8YlTTh1O9uYHwTAa2UhI+RSIVvC3kJPXtqdJSg8L6sCDv ODZBCXsKVamJJhFVsMRc+LR6nUhcue9aI3ii8hufbOGwMNf6VXpLmKJKUU8VQyHjKMiq jeaAoVT0H7E3gyJ4zNJ+Y/hZEjc8VmBN78H/+eQx7kDwDA73cF5jnbQKonAFeis4UFke rZxxA/3mseMMxI7p/0Dlz89O0oZWSc4bUrVm50YuN97Iu0RUlUX3gCGpcYhQ3EBn3TR0 bQppwU03Esg9RzVtETAVlNiqvWmlNG75VlXwd+cr8z1R2GpJFT0IrlETojx/+YccDO/k y8PA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ujW8sSFyaGmImGgAfN35Mc7lSxeHHva64g4oK3AlUaQ=; b=J+9lO6hdG7i2fxYBSgNrDdnNyPl2sQ2bGHU/82+gmAqIeckdSmiFlrXIvc6zQYZUOq Ez8bEZELGAlFK5ZGYUgIlIQyn0nMcZxpU/o+4wmJfzcY4JYFJO8Uh5+1D4wTOszQcKuE E2YAr1IZahwy3OmtTmkcsjnfI2oolXbqkHMqPNqaE6MOnjx7I1546kdaJkz1GwsCAy05 FPQr/ULboJYaNYbkao/NPJ/w833YY1xsxXgn9oDbyGDU68dtyZJy2fadStUeT65vmyOZ gdm0BTPyzTx3ftYZ2j32ILWQTUSBSjjHEimnd9iDd1MuJqDhYW0W+brMY+UNR8Y12ap6 EXlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WXECe1r6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g14-20020aa7d1ce000000b0050480620fddsi4367467edp.351.2023.04.12.10.01.50; Wed, 12 Apr 2023 10:02:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WXECe1r6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231322AbjDLQpw (ORCPT + 99 others); Wed, 12 Apr 2023 12:45:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231262AbjDLQpN (ORCPT ); Wed, 12 Apr 2023 12:45:13 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59BB7976C for ; Wed, 12 Apr 2023 09:43:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317835; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ujW8sSFyaGmImGgAfN35Mc7lSxeHHva64g4oK3AlUaQ=; b=WXECe1r6sPYXuk3zpYqSWkeXZe2UPAHh4H3sw6TFjkoID1Vo2eKaDVjsrU7EKg9iDY6/yE irPfZkc4yVDT1ODIAGZwI44RLEj9kBi7UBaMV8PTa3WsHT7R2ChV4YhXSJ0YqqdW28A2YC NGonSFHPFkvm86ASfkzCA/x1mHIezIE= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-636-hVDJx8isO0GSeEqGox967A-1; Wed, 12 Apr 2023 12:43:54 -0400 X-MC-Unique: hVDJx8isO0GSeEqGox967A-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-3e948dfe9c9so365011cf.0 for ; Wed, 12 Apr 2023 09:43:54 -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=eHuJap8/sNTuLd5HBkPYq0f8xLqrGdE+eFLnCfDX+nQatqv+nSLIYQc1LwBaGtrDYs 3R7IVaaAqmrOboBui2xQp2vz22A1w3MNiFccJjJK6ZC525DpnJUQ8Log9dtA5azfS6EJ SCKzobdXVZYLt+jNkpmnjajK/xmhkLgTl5o2e2qfsdoaPDHaZu87ZIkuiB+dN3nuWc4c mAOFEiuYPRkz8b5fi4Z5Y4oBWGNd487q/NT3eimB63Kd4kw96cK4YZR5hpmPNtkQwb9i utGiLWnaAIHbRMvmPaWjzIcAHWUO50bkdznkb+pa1QdbmkEydI+rlMJ+JfR82ZGn2MBg qDhg== X-Gm-Message-State: AAQBX9enWlpzQqMmwv9/ClpFHRtqn2s8YWiMtbUvtOC0tm16krG0dydn VMskcd+Yr3RROglRvJ3KI81BAwU/Mo5Y5aTj2+bD3tWibcwpUP9uFZiFlzoE+v24kjKxkn5K7Ur izW5z2uEE/ahqBxgk1gCVt5tY1ANfBBrLZO1MHcDL7TrB2fytObva5YSXXE2R44RI4RkvMcVitK 3pyIfRlw== X-Received: by 2002:a05:622a:50d:b0:3e3:1d31:e37 with SMTP id l13-20020a05622a050d00b003e31d310e37mr4709095qtx.1.1681317832542; Wed, 12 Apr 2023 09:43:52 -0700 (PDT) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762990685061329993?= X-GMAIL-MSGID: =?utf-8?q?1762990685061329993?= 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: 82582 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp475924vqo; Wed, 12 Apr 2023 10:01:54 -0700 (PDT) X-Google-Smtp-Source: AKy350YIxHqhEkAra4LzKAf+iELrhNsDhTSUDU+T8u3dRBeL9Aa/olsAGlH+3Bk7Y5o0xbBosv2f X-Received: by 2002:a05:6402:2030:b0:502:52dd:57a2 with SMTP id ay16-20020a056402203000b0050252dd57a2mr12691228edb.24.1681318913970; Wed, 12 Apr 2023 10:01:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681318913; cv=none; d=google.com; s=arc-20160816; b=pqwDRcMupQ7KZS8Iks8J5XtjCljEuia6OVcr+wrJF1XoWu2kolTu36L3Iw5QZoGvZ3 fedczZWjGeBHQumZq2OLKg69ArGXWyqDBfjwqO5Thmq5Df6pGbnFK5al98RdogsJyRyN fAtLRu8mb3B20spxZOQb74T9hajWaNFSPwXNXikyFKt49NOixYhtwODM/SMD2A6brxEh DIptFnKd4gp223C/tPz9tzCbS5LjqQysXHHhtoRc3+u069uf+qtfGJR1DMOlQVsT16qF wbP9+nzYIpuHHs3i5d21q2kGgfJikr3miuFw5YG4UUPmIA7Sy+xxLPEeqR6n5Gz+/Sw0 aC+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=EPLVHwmG1JWLQdfe+bC3h4cMLKGLNsksPTamWwKRdSQ=; b=xIw6pMWrjbeuqxVekHnrTT9A9VMHJsKlpHaPP0ccFrsbuINRmRg3SCdRmJXv/N8+tS /he5r6I5oZQ3JXDzFEGf3b9XCUhqXfQhoCU1x5C5w6BrduD7JDYRlTyrl5zL39Xj9Cdh OFxWrKFi8v5hA5dH9vEEp92xaXD6KDaUoPd/JvijzhFQKPxywGWAhXRnYIKAtWBIModS /1krjsWC8futMsJp2vmtCBHqt3NIPTZFiaK++aPUfTiH19UYNxSHC5m4qDl//usAtr8c HiOIY8SkiJMjcm0jrAJIvdK5c146Qvtnc5LmsKpNcUzw7TJxq9x4TE5KH7Mkr7irpmv3 6O2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dNT4CWui; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u9-20020a056402064900b0050270e743d4si2636703edx.590.2023.04.12.10.01.28; Wed, 12 Apr 2023 10:01:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dNT4CWui; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231459AbjDLQqI (ORCPT + 99 others); Wed, 12 Apr 2023 12:46:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230243AbjDLQpo (ORCPT ); Wed, 12 Apr 2023 12:45:44 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33D2476BB for ; Wed, 12 Apr 2023 09:44:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317839; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EPLVHwmG1JWLQdfe+bC3h4cMLKGLNsksPTamWwKRdSQ=; b=dNT4CWuiA6H3ozax1FAsMBK9WjVyGJmXQqZpwJ2InYTlZawhEvQMgSR1bc3/OOvXPUu7Ge j6ZTIuEjURQXvU8uoXQgxLlqo2KU0fyC0AD3CBWDvjorvtqmwpbZCxt47Q4YLKL1zkdaSF 9qAMN0vZ7qUsvNLMUA/rrC49hDRvitI= 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-157-6G2BJ_UhMdSjBeRnqSCfJw-1; Wed, 12 Apr 2023 12:43:58 -0400 X-MC-Unique: 6G2BJ_UhMdSjBeRnqSCfJw-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-74a9035256eso54274185a.0 for ; Wed, 12 Apr 2023 09:43:58 -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=GuSN9lWTA/OZ6z5t75NxSdZbgKowRaVA+UTNEJj/4k5fUi3HNI42UC7FsjDV8v6cIY 0UD3zb3SXj9ZOeU94SSNgF7VfPPaSjH6EZJzQ3asP8+1+hCssg83yZOaVbFkIWN5fOOe v59LlVai/6AxFd4yO7QfMk9n8NXlcYyo/x5BHP10XAfzyjp9g7/2QwNAbad3kmglysAQ hAXNvVozpwqk68/heqln6rBj7fMrx0t4vw1a5yimIpKdDQHiA6oAWWQmxN8+5fA74K5H 5WX2EV4/B2keJi4iNS5nZbN2U47mEkpPyYw5Z9xkU98rYmglzFFgHipHoEjgz32xmMxf Ybiw== X-Gm-Message-State: AAQBX9cfyOLe8JQDWaRpJAFxgGKzagrdHCs+TKLAntigTXrdRaImjB6e 0mimJwvE9krlB+c/Vm9SADdHQRp04/7nD+QvuW1oTqy7To1rxfGT189wD8QL13agVl74SyqSDj0 a4unqimVDAps4oRhsnIH0WFFGLfD7b0yBSi+qMv1CDmF3jgoG64GE6qF3EcSpqQvhoMBZxFHdVH YtZP5ZZg== X-Received: by 2002:ac8:5cc8:0:b0:3e6:707e:d3b1 with SMTP id s8-20020ac85cc8000000b003e6707ed3b1mr5019847qta.0.1681317837120; Wed, 12 Apr 2023 09:43:57 -0700 (PDT) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762990661407180870?= X-GMAIL-MSGID: =?utf-8?q?1762990661407180870?= 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: 82574 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp472040vqo; Wed, 12 Apr 2023 09:55:59 -0700 (PDT) X-Google-Smtp-Source: AKy350Z8AweYlZBjTF7zgb0Nb8jStVq1o/wWeXqvOKA7I9bkaZJxuYyv+hUdYaj91OpnB8PuLseg X-Received: by 2002:a17:907:16a0:b0:94a:8f3a:1a65 with SMTP id hc32-20020a17090716a000b0094a8f3a1a65mr8036845ejc.5.1681318558728; Wed, 12 Apr 2023 09:55:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681318558; cv=none; d=google.com; s=arc-20160816; b=YcZKhEgjxqj+Rmbsr2urV+Zy+g9veCTYoxKL3OERfAo6nFj0rC2yBhpEShT2n/zZqy 0/AOIL2B/1iwVLguVQIihzsUVS1FliaUTAGs3PIimBug6IfysV4/aJoAucLMEYI/lDMm Z9Utq7V1e+jdAO0UAAw3WR+/2reZSgYTcnGOzvMr0EYT0kPZfKSlTGccEyhB/7pRDa4h UH82WB2ppjZTq8yXMUvvvPP9NwgrTkG6I84T23uWT/UQJ/rU1yuljSnaiBcswFYalMAF HDyDXQj4wtDikPIkKtmUi+NiHiLmMKG6IQry49vXpv6dV8MJyekOu0ss2UJWl5tm1JtG xzIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=DGYE1DDdeK4+pcxB+E5dvgvlIGHgCfc4atHqaHYPYpQ=; b=PowfX51qbemqIIwnxJLDby69CCSQJ55jKiZojIEXW3u8C7wr/kCRAUflqQ1GQXuBdW L6DuRu2pQb/pv73zcN0Ic5li2LeQp4QVxSamzJAnmHx+rl4UN3MCTpOXcGM8dIWwqLTs foNxXxo0RobatifyieGJNFkQJsPEmG0feFZ/frn+/ueqSSCZS/Og2XQ2CihLQrLTe8wm JAOnJ2Ss/KUabyZ6o0TANIlV3bIyfaYn6uaUwt7HdhCUR1NDWo1T5eO7k/kEqTPXxIgz WxQOA8K6DUxuENeeJhgk6rhO7sjYulHTvrdnjnuxgU+bt5Hu5MHUf8HL8ZWUyMSUMmIg UrtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=K07TSWG+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l12-20020a170906644c00b00920e94e35cdsi12365974ejn.901.2023.04.12.09.55.29; Wed, 12 Apr 2023 09:55:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=K07TSWG+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230183AbjDLQqW (ORCPT + 99 others); Wed, 12 Apr 2023 12:46:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229548AbjDLQqD (ORCPT ); Wed, 12 Apr 2023 12:46:03 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9144E8A60 for ; Wed, 12 Apr 2023 09:44:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317844; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DGYE1DDdeK4+pcxB+E5dvgvlIGHgCfc4atHqaHYPYpQ=; b=K07TSWG+xWXK96/48tbSWNcx6n1sXfX9dhviT/Ie0tQ1U0IKGlFY8H7bSSLb/5CSXsz/Vu 64H4XJb2ygv/lcJT8vaQ6B/BR2DupvLjePZqpDD8sZ7l2Q5HCn4ma6t/UJ7F2Un3SxFxZa VzhhB/mZou8nL7ckU9NOG8chno36LlM= 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-302-nGWwhBwvN0qmsEaxmADopQ-1; Wed, 12 Apr 2023 12:44:02 -0400 X-MC-Unique: nGWwhBwvN0qmsEaxmADopQ-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-74accc750c1so3422285a.0 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=aNWo85nWYZ+7UpW2wT5rN44KkV5PPFd/dJkZNdoyx7Svew/uKcoFz8+VV+yvoWWzpj w48gQWG+v/yVNNVyNy5u0Iiex1xIbsfvlBmsMs0MKLuRUfk90jpFXKvVo4yVQr4jEJYL ZIFKAQdRf/fUg0CwWlQgPec48qdoyV4Xvh2i5NoHjuxBQq+laIkiMaT2FxTli2B86hL0 ZsY5EgqGaVakikgjb2IO+V4zbqiuUubelVZ6y+MJJVbEk9s8ILPSsPArGVuQstKW2u6J S1IGA6vEvU08puSYNYCGLZs8HPkYy9qYaSbkni769Z6TQE/CPzsgyG8Bf6T4eyr2vssn A0xA== X-Gm-Message-State: AAQBX9d5GQNmabQpnlt1LiOx/HvpDOACszvrL0ugpGFp9IFhOOCRQnLD urZR4qnQZfEXP9wUa50DtJwL1kQU/utLmz2XIQdgGRGGrwMoGIuaoRfr5ZszN++s0KrUkcJiK1F b1jMDtlzG1JWZ+94RvBNvHRYqo03kItYwh8MvxxoIlM7L8vmxVgKcUaW1v4R0GVzoyjcSOKnR07 N378X7iQ== X-Received: by 2002:a05:6214:528e:b0:5a5:e941:f33d with SMTP id kj14-20020a056214528e00b005a5e941f33dmr4706439qvb.3.1681317841005; Wed, 12 Apr 2023 09:44:01 -0700 (PDT) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762990288901983642?= X-GMAIL-MSGID: =?utf-8?q?1762990288901983642?= 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: 82600 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp480871vqo; Wed, 12 Apr 2023 10:07:38 -0700 (PDT) X-Google-Smtp-Source: AKy350aXSTQbkwNHPie5EjV0mORJLkEdCft1ocbjPANY+TFhmKFLUJn889rZhI8fiOzLzr5Y1/Kv X-Received: by 2002:a05:6a20:e94:b0:d3:6d54:7852 with SMTP id fk20-20020a056a200e9400b000d36d547852mr5725182pzb.31.1681319257173; Wed, 12 Apr 2023 10:07:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681319257; cv=none; d=google.com; s=arc-20160816; b=FCr4QXHPMqLssPQTG/z38UND55TX2ZpzbBkXLyYlraUoF3OiC3ar1/0osvtsn6nWny InxSQkUR3uUDG8fu6F+JmIclo1qH3ErPGAp/3BASQEgOL6/WpGB4+GKUhMKimyCSQDSp B9pwwHH00+R6rQTpZwQLYDFpCL5q7ImxuyUnca8FBAIHyMN+5pAkO0AxKZO5t8K+SCc3 9Ohlmu5zHrTAJ/654zA2w5uUI+FsNs9E7Echv8HI9MVsq2389Sgx8a2U+cqef0Atv2RY fX3GC1eVhNlsAhzxSjv8+xNs6sqJNH48dCcO0YyBb5o8fRfWtaN4JdnYz+kkwQaBceZ6 xQoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=moJlUxkxV9yMXHXtrl4RDvvI70k6nNWMdoirhLeOGGU=; b=OeGuStMVo9Jb1JFHl+mT7Ax8/C1sH3T+s0i7aX9oD+cLDaht2Fppl5+WND6mITib0a 4LK8iVCw2z08KdKe4rZ/PS1ZlnTdJ0yy3bZqXrqI6MZVD5E/n+45ewn/nRPKr0Xh3fgk bxIyW4o0rd/fkiEQo6szzYLmUYxQ0qwZqW3ukwblKzYGSFPYQX2nzqBPHdacAE4J1U39 xHll4O3QlFfuF12837P/6WAKykEQSyAdRdDYY0gneusljrIxq3p/fA5UmgfmOTvuQyKq aAP4ngC0tfbplDCroo16B5Det9PJzeBmrZEDxPw1cVidxgRciOCJJYBEYrybH/onDOb5 /FqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=d1aTx4Ju; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v3-20020a654603000000b005023e0f160dsi16835854pgq.489.2023.04.12.10.07.22; Wed, 12 Apr 2023 10:07:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=d1aTx4Ju; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231485AbjDLQqp (ORCPT + 99 others); Wed, 12 Apr 2023 12:46:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229969AbjDLQqZ (ORCPT ); Wed, 12 Apr 2023 12:46:25 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B4069758 for ; Wed, 12 Apr 2023 09:44:42 -0700 (PDT) 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=moJlUxkxV9yMXHXtrl4RDvvI70k6nNWMdoirhLeOGGU=; b=d1aTx4JuRpo9lusjEbi8CiAjAcHr4Lxzs1lULLk3/L30qWUUL4QQWcFYI1n/+5jsbq5yDp U/My85KzBpS1iV+Q17X6BL2h7e3xoLhs2abO31lY0qs2QxlGI/jgCIHAHrwmGR5q70hgCy GgFeLykDPNjXvMFbTzX9T0X1CxHafis= 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-171-JOBEczZtNl61d4k9vkU9nA-1; Wed, 12 Apr 2023 12:44:09 -0400 X-MC-Unique: JOBEczZtNl61d4k9vkU9nA-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-3e8d943d3a4so667881cf.1 for ; Wed, 12 Apr 2023 09:44:09 -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=l9mzaHxU1mvgbOzW7pvrOur+WLQjfNAFgcFu0E2o8cgnHuhOpvzTQ70JKaI9Maxzpy oZgKzxFEcs5qgGEo7qqHcG3NdTbULFAcHYa3MTjy11wUV0VQi29Sy2SkvqChBqBGxU95 hawPiMDXkk6jruWCgJv4AUJO+ZKenTI484+kRe8LJuvVw2Izf6jU49u7OOU9y4bVQqHg Vj+35mLFjQLw3ehzld17ID2iR5ObzbuntVakAmTlHQ1c9NymBwSQT41jrGMzCZYj9Lvh Htv7pxws33DJcHterqLPxCz4APoBuuAWSWHtOAIzrgMrOXIi9G1J/SUvv02NxmoAT1UH Vfqw== X-Gm-Message-State: AAQBX9dKMHOTmfZqi2eM61AloguSn2A/QgMQNsfXaLdyFk2kgkAFIvMl 5l3WNdO1OZN6QJiBQZg+u0NFGa+A5b95KLaBb5tRFq6H++3mr7bgsBx6tZnHne+a6a7AP04xfVA 7bTh80p4ZRqod3sNL3vGnlaehnp8b7CaFGD8B2XYNhBm1BCrBYrex1JSqhMMuPs9miXHu5E9BFf k7/cu/mw== X-Received: by 2002:a05:622a:14cf:b0:3b8:6c6e:4949 with SMTP id u15-20020a05622a14cf00b003b86c6e4949mr4198065qtx.4.1681317845033; Wed, 12 Apr 2023 09:44:05 -0700 (PDT) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762991021381011111?= X-GMAIL-MSGID: =?utf-8?q?1762991021381011111?= 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: 82587 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp477997vqo; Wed, 12 Apr 2023 10:04:05 -0700 (PDT) X-Google-Smtp-Source: AKy350bHugUGiRDSySC36UW7TkyYu+ym1TqKGxdNp2NwgTo5nHXl6mbcapXEe/Fya5Dlv23XxQl4 X-Received: by 2002:a17:90a:17e8:b0:247:900:12db with SMTP id q95-20020a17090a17e800b00247090012dbmr1650541pja.24.1681319044817; Wed, 12 Apr 2023 10:04:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681319044; cv=none; d=google.com; s=arc-20160816; b=Pf+cvX5dfrUlVrIkw4xNj/UTUf5HjI4W6JLXrWeDYVgTaYES3kFbywYdgpJtsUZjtG MnxdKvYZZGiNOZxycsfzsrEihZdVPOGCbN7SIsONI9weJ0jB30PxSmaTneLlOUQYoOUo t5WISR+2qc7D1Oes7n6oU8+sPBaiHxGuUn8qwHlBDsdJelQiDJaUkEPfUZ7h6EMsJ7pf Pv5RFAWkIxBgyMVDtZIMUIJzGSj+tZu7n2CjvMBQnyPcCvR4aqf56crIB4I8FO985iz8 ujVRQomnQSxqucXJgfeef5iuzBk5Sjgrr/879SLqj/STu2SoSW/zRh1t7OxnQsrlQvSh HPWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=tbgfGOfUxiSSCaOkyoncCcfniesjTCna7R8zm3hOkOs=; b=SX4PM0GThpXv/56w8Ae/lqho36/vFIzmNSIGTPvsumB3lre6aAbmkGRWNTKW5+oYO+ pHj7/CqiDeN4NaVFaP+0tQ2RMvw3wRxder3m6BLSdpDpI6EZowixXXbEeCbbSBQasRTR U72jRXwqWu9niePlaEl0c+0u37JOQ/C0edq5kQDb1BB4hBh+414UITaJ4MkC6vvv1cF5 OULhxRytj8AgmNX+/WEiHkLc1XdwM6H5ZFr5l4l36cInaqOC9r24gMgHkwjwS1mHlB1q A32fc+WX4a8dZ4KHpYmCJqOpkl8W/G04YLoR35kjMm+5PM+LjDDsPG15O28y0lRzDByv wRQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=duvuodg2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ot2-20020a17090b3b4200b0023755d1a1e1si2706349pjb.28.2023.04.12.10.03.51; Wed, 12 Apr 2023 10:04:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=duvuodg2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231495AbjDLQqu (ORCPT + 99 others); Wed, 12 Apr 2023 12:46:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230194AbjDLQq1 (ORCPT ); Wed, 12 Apr 2023 12:46:27 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EA89902D for ; Wed, 12 Apr 2023 09:44:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317854; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tbgfGOfUxiSSCaOkyoncCcfniesjTCna7R8zm3hOkOs=; b=duvuodg2x0wt0HDYybwz9/l/IcS641UITDwRSkPt+gJtKSkNbKcKjGBMPIVBl9ksnaFUZy 8Lx5UWCCn0wqmnQ5vyEIcJcrEeOIiQxgCnADi4CMX/GRxjuuaaVy9KS31b54Lv5F7mO0I+ gyxNs6IuwRPhCYYwRe6urMN0+lO9xjw= 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-424-AgXypREeOCWeOHaAYZ7C3w-1; Wed, 12 Apr 2023 12:44:12 -0400 X-MC-Unique: AgXypREeOCWeOHaAYZ7C3w-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-74a904f38f3so86471285a.1 for ; Wed, 12 Apr 2023 09:44:12 -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=bJPoKERMnQQyh5juNXTVgQXlScLpBxCeFx1Vw0frgEHCWL762uBXud2Sk9/2og0FRK mrbTR3ySZRk5ozvxJQP+ztoqFJIk7pHndnDBhuWDPo2zd30u1gnoTc0FavnULOFfxV2n sPQk2Iqq2nwerPOCrW7lezsM01K5h/vTKZ0hQehwtzaFYB/DYN3eKX/E674T1CJOzccq 4hb2q4pScE9Ni4hIBIoQheLka8QMmgCM87qNf+ssK6UcWHrGjJj4iKo7HCUgWTo9BFt4 G9JCV+QZM4//U91nknmPnos5fB/nUp7p+YdZFWwmiPgn+E5Ucr18ZMgghHOFi1Qy/5V2 w0cA== X-Gm-Message-State: AAQBX9dplgnP+H/ANr8wszO8bmjXv2zgBld6G6BEWMOOXerKT4Idnx5W VV/oUbid03Pxeld9sirIWtWWoUiEwlQXo1cvA+RVNNTzZ77osjA9oZy5uOAeLtYBY/7ZkBgsIln hUuOSMpKKh3DTFyir4+4IHFlrL8lX48pvZrRYdvB8d9K73dLkSWb2p8koYWl8UMBElqmf61QWgb gnHoZrCw== X-Received: by 2002:a05:6214:528e:b0:5a5:e941:f33d with SMTP id kj14-20020a056214528e00b005a5e941f33dmr4707113qvb.3.1681317850560; Wed, 12 Apr 2023 09:44:10 -0700 (PDT) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762990799016236679?= X-GMAIL-MSGID: =?utf-8?q?1762990799016236679?= 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: 82602 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp483835vqo; Wed, 12 Apr 2023 10:12:02 -0700 (PDT) X-Google-Smtp-Source: AKy350YRDJTzXlRv+l3C6el0w0qyH+nI8a7AiKZxLP/9QDwoHHNZqbOCAxntFvlVZJnUsmSmZa3u X-Received: by 2002:aa7:c754:0:b0:504:7163:2a36 with SMTP id c20-20020aa7c754000000b0050471632a36mr3164526eds.15.1681319522055; Wed, 12 Apr 2023 10:12:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681319522; cv=none; d=google.com; s=arc-20160816; b=tGKvwKJFZDQYYcIMogwAZ5tzD75pRk6LqT7bZQd9K5OJWT8CRqAWUyZjqEOUYM4glO taVE+md3cc9uwtOhR5t/EMuTsE8jwjTx4SnQfM9mt6clqQpMdxqYOkytFjYsHXX83+sg VjZGOgdks+/tT8Hz5N6CjanCkrk7TroFvUKkJZ2XQnnVTudwbUUdCA/mVAe2OFwh4iME 1DPhlEmpah24usglH0pGZh5ZblL6xLmg03KHQVhf1Z4MNhEcEdg3gDypxPDWyDTt34PG oK+fnZDwkY0J+hGu4Nzcboz+/yboKr9pRP0AzgLswkyOLquhwGrzWEJ6QGTvSk7IBlCT 8zSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7ndlAQp34To4na8gq5wbdyyXxzaHqcVWVuJagrtwfaA=; b=ZurXcz8U6ypYMGYFqCr8Z8HW9ZUgCsm+wEpaE/hr8TJYya2hAF5Rp3ODH3tUsXGQUQ 513DMSZCEJyGZ4xgUVvxLVgUo7ZqGFjniaHFpV1/Zl1gv566xEXcCjRAIYjPIpF23R0Z UsbSYOLsFciunsGhOXVgc0633BWsAJUc8VI59pkBUA8XKbwl02u735dkMZBSgoMibLnw bsi+OWNb4nfIDmelYsxOiGKoIiErhiGjJ6HW0pwpEqopVvy2ihe/DO99h5BR7lLTFCI0 B2NG38dDf31tLUY77VC9ZFMWkJJNx/NaAwBDuZOBqt/8q5M10rghQ5TqRK3kdPOHt9VG cLAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="P/lB6CWQ"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z1-20020a50eb41000000b004fd1ef9b95csi2542512edp.598.2023.04.12.10.11.34; Wed, 12 Apr 2023 10:12:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="P/lB6CWQ"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229934AbjDLQ5b (ORCPT + 99 others); Wed, 12 Apr 2023 12:57:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229575AbjDLQ50 (ORCPT ); Wed, 12 Apr 2023 12:57:26 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8503E8A42 for ; Wed, 12 Apr 2023 09:56:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681318539; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7ndlAQp34To4na8gq5wbdyyXxzaHqcVWVuJagrtwfaA=; b=P/lB6CWQMG15p8zd+SQrUspYKd+E3JMd7RIySdaEL3+FZ8gDW1ijmAK7bYW5kn9rF0gpzy 3M/xt3zbhkpiHM4sxvZSMAyY/+yQDoX0RKmeTKZMK7vSA5g1EDurcmfOLSlqwHvJEOeqKz P1LWtvRRn51/AtDO0PMBKHSfBGLciZA= 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-575-vawm8nB-PmCS-58qXLKOzw-1; Wed, 12 Apr 2023 12:45:20 -0400 X-MC-Unique: vawm8nB-PmCS-58qXLKOzw-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-5ea572ef499so7659966d6.1 for ; Wed, 12 Apr 2023 09:45:20 -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=SUwPOUvw6QyP1CfcmQNfsgu6CQQmPLssPlPaCzyM6IqAJsGvVm5DhUTykiOVKIYM/R LWJbOcBFEE8WfgTeEv/c0GKp7ZMaBNwsbb45fXiQBQDNykX1ExH3paAcfql6g5gXFtBr WEUsbXTP6daXdCOWSBG9xLeCAvJZ/7rZ4Gvob61Tk//7QLDDA1xI4SELtj/ZJs1K01hA yS9vLquU6tE9ulIl521LsWg51+aMvSRP1zVwLUgf61E0qVlonPMW/+AsHb5C6/Cq8R70 vd4/ZH3SubouRlU/plTiV6xlb0sO70KwSjSltrrDtJ9+Z4xWkKtJ1w76v1HAJbgg4I9X 1Qyw== X-Gm-Message-State: AAQBX9cc/pIaKIvrXpAQFfDXb3bMhTMJbryi/JAVm0DgJZje1w3BFXhx /U6AzMUNJZQV6FVHzYMjqJ94d6YHiUTELcAm73OsnMVgUqPy+M8TS/nbyeBlnyIWf4TPlWXC5aO KgcBGu0F+LAbHLgTLyECePEfo X-Received: by 2002:ad4:5de6:0:b0:5da:b965:1efd with SMTP id jn6-20020ad45de6000000b005dab9651efdmr27671967qvb.2.1681317920286; Wed, 12 Apr 2023 09:45:20 -0700 (PDT) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762991298918293308?= X-GMAIL-MSGID: =?utf-8?q?1762991298918293308?= 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: 82578 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp473819vqo; Wed, 12 Apr 2023 09:59:17 -0700 (PDT) X-Google-Smtp-Source: AKy350be69kDQI724R03VgMgjP1/ekmiutPrZlMD2L52y8SoSdtxQKe5/4Hn8B0563aY8IG6LRum X-Received: by 2002:a17:907:9886:b0:94a:7097:7893 with SMTP id ja6-20020a170907988600b0094a70977893mr6420171ejc.40.1681318757023; Wed, 12 Apr 2023 09:59:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681318757; cv=none; d=google.com; s=arc-20160816; b=d39hNWhNM/g96QYL0RznlGrITtOgLhzf1U3OvClsvGhISlPEJSbQ3gl+sNlJMmGjZi tNJJEt1Tzq8wEsuZTLK6otw3QxYO8kgKF8w0DvxImMQlXQqCx67ByaTXd1sKRmuZAXE7 EbWGZDBSqXzJZBEyiN5rEYn2STOfUNJQ1/nZNeiiZdD3GI1D/NiMCNV/3XpXavLQG281 KguuLFsZ6KUP8cAEGCeRmRy82ZJh07TGLGJyENC8+lkFFbXGloDeZApNtkB7hLFbGjP8 l2mop6N6k04LLp5a8xWzNowxZrgaOo9dcYRRVNtNx6ecgkdDDliBWqiUxNvpQxpjZ82+ oVUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=RvUBLMIj6eaAe1GDo1uBeLCLb+kkyu1V0plV870AgzY=; b=witPm9tO7Qo/+TK5hiLUV9ndy3Crn8172QgeqHn/LtBLkz5XZ2MZFFS928hynmC5Nx QSSw11gPdXHmnXjVckqlONFolnB0TeCNXwSdaSMxA4ImrrDKY3DTOCoU+byYk5hZMgFs KlsSdfN/25Gr399s6/d92EIG7XhdshdMx8BTP2LiMDIUza4HjiyFRKVJKqKgb5//rnKA Fcx1KCSjhzE/Apb+lauYojlddXcKYt2H/kwCEv1fNEMTWhIl0QTQtsVfPCv9Oehlk4iF NYHARvRrv60sWvNWc07IEDBFLybZS96lXMk6vGk14NKqOrnvJJ4tJlGkk4W4+r8uQnMJ IbTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dMREYaFm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hs37-20020a1709073ea500b0094e162554a7si1740757ejc.262.2023.04.12.09.58.51; Wed, 12 Apr 2023 09:59:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dMREYaFm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231493AbjDLQvi (ORCPT + 99 others); Wed, 12 Apr 2023 12:51:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231553AbjDLQvN (ORCPT ); Wed, 12 Apr 2023 12:51:13 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC67693EF for ; Wed, 12 Apr 2023 09:50:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681318141; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RvUBLMIj6eaAe1GDo1uBeLCLb+kkyu1V0plV870AgzY=; b=dMREYaFmEUTyUivNAns7jYi1rMXVXc+z6dQg1darMPKEqfONTgH1XdfLt7k8fQ+YRB0fo9 8O8dgkdvZD8PP6ioJ8GOEcLhagcOoV35v6bH47iFhjhmQsNOO3LJPqL6T0pwFGygLszV++ R5HpYni2TvMo3r+TuzuZ0FTR5NGM3sg= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-204-hrrzXzmLPf-EDkOxcsiVJA-1; Wed, 12 Apr 2023 12:45:30 -0400 X-MC-Unique: hrrzXzmLPf-EDkOxcsiVJA-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-3e8d943d3a4so669641cf.1 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=IGA2znnCz6q84+iCXtoSAiEDWt1nNe+KFT11VOWDEEvDIEpUXQ2mq5uxvmB/YLxYVg yDnHiSID9ELfSKXBRPxTL9Lx3J9KxKpV5YLCop7t1uLl8Uer5oZswu3k3t7q3EiTnYps Z9ydCmltx0a9sl8lLNZXFFuVqFGPp8NwqPwj9BncqpQGrSdLHrKv3IsIUQ5JPssYeRPH zD4Wmf8xRtFaeO5bxykdNqFP4QiXvhdaBdwwGerl2aVHNBMFGShaWTHcQBAUTnjxd/GZ fVm4S7eUREsVSCHLd5LE85CPXb7dl4tP3NUwc/QnpNBoRNLPvdTHih0q4L5r+mvU4OzN aLlw== X-Gm-Message-State: AAQBX9fL/Ro7gAO73Kz4oTBy+muZWdBRPjPSDlg8uhIfKV0QfiO8GI+x TNbcrgOfoa+PYfeczcNeU4yzxL1IK73pqdah3q5UJVCEtXDCOBs69hVq+Qh8X5/OHVs54ZQ5vVR SJlsndK27Ph34nDgVs8IVW6sK X-Received: by 2002:a05:622a:1816:b0:3e6:45c7:cf36 with SMTP id t22-20020a05622a181600b003e645c7cf36mr4507542qtc.2.1681317925220; Wed, 12 Apr 2023 09:45:25 -0700 (PDT) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762990497294878516?= X-GMAIL-MSGID: =?utf-8?q?1762990497294878516?= 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: 82586 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp476982vqo; Wed, 12 Apr 2023 10:02:55 -0700 (PDT) X-Google-Smtp-Source: AKy350ZbzpYlBYiXGNoR6KpAgF18SV8vIG10Z7URdL43T8ad26+XOEHTJZlXZEj+uEgH/9Pjbq8s X-Received: by 2002:a17:906:eea:b0:94e:4489:f24d with SMTP id x10-20020a1709060eea00b0094e4489f24dmr3167490eji.61.1681318975261; Wed, 12 Apr 2023 10:02:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681318975; cv=none; d=google.com; s=arc-20160816; b=WGzl2HhtvT7iwxyqgPb+p+1axv2uA2/f/Y5SpguLwfJ9fpxKTIbk6boh0SE6SmQvgo kMhivkNdpSAorK2Q0lzedu+9ZzpdDKEu0uGLs2jQXeCfZaBO8cy+TigRQNAJP1s//ZT8 ZRa7ULkDAkH+upOq7C72NaZcKn/O0BiI7zs/E0w4+k0JwP8vHhQGiYSAj4rzMF4CPw2f PH7VThEbT/EHDOY43XlS5O80nuJ/3jt6/1ocmtKFwTgwZJvc2VaHpC2V+kAOIIND+WrV jtlshobqxlz1l9pfA7stinUtlipfmvEDitz+isUa4wrhwOYZLLr7tyko3KAn7eNb5oio 9oXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4P1/ScyFhtwT2WBZ2avhVrVKXGlimCZn+6QVBkOI+hY=; b=QkrWT7F5Y9vPfakukv7IweZkiiwVLGEy6/RNBGND2aKWihIXEFnji5xNDKl8cOlVNr +x1l+cdA7BLxl6ngPAZFXyTFyJ+0vSmm9EcKufkJjE7Cvyf7GvnjO6ETDsMsfC5lEs// KnZ3Rb+KnfJm/owRajKCb+Q9yPZbuWrQOp5Av/TU2POc4Jk8iYHlcmx00UD2auoPBNo9 X7JnakjMsI2J59WdBhH/FoZJ/fi7tq7KWy9XcMVPH4m96mvqmDWVdrRYuvIekC8Mx+ze K5wPzAuDRBTbrg6SiT7N3YrNtpLIH9fBafxXk/Deu+HsnWTSj7RqiL7X2ZqTOwScAtFu 4yeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="ay3/1p/9"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h12-20020aa7c60c000000b004ab9fed6acesi3362258edq.384.2023.04.12.10.02.29; Wed, 12 Apr 2023 10:02:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="ay3/1p/9"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230365AbjDLQsF (ORCPT + 99 others); Wed, 12 Apr 2023 12:48:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229997AbjDLQsE (ORCPT ); Wed, 12 Apr 2023 12:48:04 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38B5993D2 for ; Wed, 12 Apr 2023 09:46:46 -0700 (PDT) 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4P1/ScyFhtwT2WBZ2avhVrVKXGlimCZn+6QVBkOI+hY=; b=ay3/1p/9r0bq0UTWuJVstf/Evrf9pVq8Bj+XoYNuqHkYuupOr+U51D0JiRG2y71H+o8UZC nTXNLvsCgXtdINSGFoyMEWIRtR8lj2Jg6VpamV0OFCk/e+jiiRtKv5QhyZO5220pg69vbo Appg0E4w6pu5vqFnWOutw7j0wWpZzC0= 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-610-OsNpgVeJNIuvAzY8f6vjIA-1; Wed, 12 Apr 2023 12:45:39 -0400 X-MC-Unique: OsNpgVeJNIuvAzY8f6vjIA-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-3e947d81d7dso272561cf.1 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=fWUIcaAVjNaF0foTMz0qEx6Jbds4QyyXd3Z91tFxBuTev3teeL7Ohh3/vjIsPH/8JT wy4J+oknnLSCX+XYmAFtcuxv1UutV4edQhJ6Kc2t+9lVcPXVkp1Rt0eAoq0q7eC3o0yN +7wHjJClTmcK/xUbBP8q5kBAvu5kIEOF2NoreKVmq6GqenxOgFfKfpU88x3NY0C1/MDs xElxx4Q+awxTV0b+JGGtcnvzX6j0GNZoqPXsgncSxUoVdqDbaocp3fphHdoSX32+SIxq VmSeFDFYSfosz+UE8wTDDeGQ2nR3DUMoiuFApzlim2vxG0VWN4dyH9exh9mwucl+yNhK 3QJA== X-Gm-Message-State: AAQBX9cBm5bUjcmx3SUhu2N6TrDJuNiI1ARtqwEnBgO2GIawNIxGRfz2 YFFrD9q82FGyBOHxNvK/gfsqq+GyTSOQWX5FZe5uojZ9mn68FCdj04ugHww3kkSxQnM7upAQnIB Uy8WaDahzISfCJJskqNIfkHnF X-Received: by 2002:a05:6214:401a:b0:5aa:14b8:e935 with SMTP id kd26-20020a056214401a00b005aa14b8e935mr4735734qvb.2.1681317933758; Wed, 12 Apr 2023 09:45:33 -0700 (PDT) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762990725683807181?= X-GMAIL-MSGID: =?utf-8?q?1762990725683807181?= 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: 82607 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp494367vqo; Wed, 12 Apr 2023 10:31:34 -0700 (PDT) X-Google-Smtp-Source: AKy350YD18k5Y1KbhDI5tQk+fyhgDXlr+c/QJY4AuxhHSymvHwx0d9PWCHUFLgzEXHwoKMeG+jwI X-Received: by 2002:a17:906:1857:b0:94a:4e86:31bc with SMTP id w23-20020a170906185700b0094a4e8631bcmr3574338eje.13.1681320694190; Wed, 12 Apr 2023 10:31:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681320694; cv=none; d=google.com; s=arc-20160816; b=szKVqBVp2wizIgA9cs4Y2bVdo62PRtkBNQNhnwcwXScDQdkzODjt+qq02CjRIB7yYO KAbi5xTWwtrYmtoVGMOkqIIzyihyNdT+PHgXB/M9NGV3lki+mz7PjlH5uQARjq16fU3f Q25Csbe0YhyLmIiY5evjyuwbz3mbRjPfuXJO/vpGoyQh2qr2eLfAeZSOpo1ly0P2OnYR TdCtSbDYKdypNfWrFtvTIXnoqVzaawxCM2CMCzbmWKuSIkVxk19GDgXQzu12e2r2HMkg NB6rb11w0wymrCqO3B5lkBU0IKP3ZzmbNcdkc9WZeg+rEVHfY/YLdMQ0JnfixW1M0VhQ eO7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Z2yWZt1s7MuVGMeOCGLd+TTj5TTX+8gBX0BUmTSUDX0=; b=DCxApo1JM09pvCovDUWqAkbcWgIaL+niwYxHf0Bntt0Pwr/dwifbEZA8Eck/sCF2c0 nIM98I3DLQHPb5CwF9aUj/1R+lDW8ONEcgD03tMLDv/PqHoyzh8oC310VCDxOWa5muOB q3J8TFQewzQAE4AnawMPUK9Zpc1QHsxldUg1fokOGa4uP2ZdY0HhRG9E9NrKldEZdWgw j03auhURINQYtsXI1TLnntGtEjD0sXiLzxK+YUFVbQIrkOK7sgVJcbnmCxkw6PMFonMC 1akRBpb0PVLIJ0JRHFEnmH/hwB03r3ACuUdpij7IyVJxGGRpBkJKfk6/qwgt7nVxIZbK sujA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PsqDH26i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nd38-20020a17090762a600b0094e4e481c2esi2589160ejc.247.2023.04.12.10.31.09; Wed, 12 Apr 2023 10:31:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PsqDH26i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231134AbjDLRBv (ORCPT + 99 others); Wed, 12 Apr 2023 13:01:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231343AbjDLRBg (ORCPT ); Wed, 12 Apr 2023 13:01:36 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B082E7AB8 for ; Wed, 12 Apr 2023 10:00:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681318821; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Z2yWZt1s7MuVGMeOCGLd+TTj5TTX+8gBX0BUmTSUDX0=; b=PsqDH26iyJedwjXgjcIGrP+E2Zo0Q8bfh0RSd+9hCwDZ4uXsCTWNsweo9v+1b1KLuiyTWB mw2kiwg32kiJUMrmSdl/mD2Y/CK7XXvw0yffLdceK0Y6b9ULBseOgFsL103xgTc16HpLdU 87GkwFii+4M9s+PO9xK4NU/f6CB4rus= 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-468-DATm5dPtM3yAsNKUOMiMWA-1; Wed, 12 Apr 2023 12:45:48 -0400 X-MC-Unique: DATm5dPtM3yAsNKUOMiMWA-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-3e947d81d7dso272951cf.1 for ; Wed, 12 Apr 2023 09:45:48 -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=F17kCG9aUAnbNVNuiuQ1vWv6cNAqmTaUXS9RuzG84ZeExUbnPYtEtR/CnuPSBkDigC J/Gyrsbw6ufx6ofrG4CLLi7v2wbQcl7Xk1GRGFj+xGHnAkTCaVCw4ezh9UE7AB/xRz9W dkxHs6FA4K5mpbmm1Xd4k6IwPozhX70g0hiM0lBfwSF2gpHi4ExD753yfhYjhEsnYhWI z7sp+hac/OKqO9aBJPQg5SN670N+ilPSEE72NoRwriFvUov9aOC43Jz1RpgkO0oTB+ve oF+ceS78iOx4l+C+/b6dNwqA2zXY7V2Z737IGAezI7G/iHQm3LKZ5l1YzXz6oCFU10ob SwqQ== X-Gm-Message-State: AAQBX9e2ILQWWpGeFrpcN3DKCq9zAyn/sYpLRJxKpy31lRW8Gum7HLEB PvqU++L8oY/vpbKNCEtJd1na6ZJQlJqAKb9qan6v+HNNyRxg5rxca9lGco3aCWMcfSLXqjInKhM nyBfd+Aoo/JV5U6rn6g2x27n2 X-Received: by 2002:a05:622a:19a1:b0:3e3:98cf:68ae with SMTP id u33-20020a05622a19a100b003e398cf68aemr5389663qtc.2.1681317948340; Wed, 12 Apr 2023 09:45:48 -0700 (PDT) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762992528130570122?= X-GMAIL-MSGID: =?utf-8?q?1762992528130570122?= 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: 82588 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp478057vqo; Wed, 12 Apr 2023 10:04:10 -0700 (PDT) X-Google-Smtp-Source: AKy350Y9+KnEtEuYc+iyN/2me/FViFiKblwwzJgQF+HSunbT7LYwm07yO3dwNZhPDZYtLxe8BlJP X-Received: by 2002:a17:906:d97:b0:94a:8ead:c7f with SMTP id m23-20020a1709060d9700b0094a8ead0c7fmr9817054eji.23.1681319050720; Wed, 12 Apr 2023 10:04:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681319050; cv=none; d=google.com; s=arc-20160816; b=dcGXakBbVF9NhiaBIG5BJZwIpTE5BRkUNJxjAamER3nzZok11jrrBscNG4ufPrEiw6 jxr4JSi/kbPzMuOQjsuLjJjHISnyq8vIzN10rCDoMuS/m0S2WtVzRPFLxpctvQhvDLa9 ZYN4hvI9Lvss06CTGk3TMMsktXxMvV5aEMITcRXoroL458Xn34HUCTVwNcZh8FSozIy6 KOwCXNmymFYGYk28Mkdscdg0gP1A1bkb9B5h8vAJIop0mtkLSIgoHmPVgrNoIpAxO2GM e5hnUIBLi8fdZY3r6TyEFQ4yDUEKAqm8dXE6lE4wr6RvtAv83gtd0/NMUATtZVyPBBQl XyOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=TwrBVEbuHxz2Oj1oTVxriRpco4XXvHrMi+8R/zKrUWA=; b=QIeGwWXsNpZfyXOCqWcruu8TyCIcpSt35zBqbkIpVaST+lKLBBVyKpeTauViVpf4uV ixvVuK0f/a76WMOjQNHnty4Sr8nCwBtUVBzn0QDbCdQeT3ET+YyNn/rPD0YPS4IC3GoG QjE+yJpoqcSY97TlYoopQG4ZgfCP8EBLCgNz/zRIDQDRFVYY+MKSNwdSSiE+GbS9iNNH UTekadDBJq1jKM4pOxpP14tMBjh1X4QomFPm2gRbPphGYHmAs1iQ9BKDHW+eCkZQA6BP XMf8Rd0m78C/5siBt1CYqKGyQXNtKhIfWysZNp4UXwnaZAoX0sNec7BLXBxzHnoz7ZTm L1xQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LvHhC67Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d21-20020aa7c1d5000000b005024cdeac4dsi2512695edp.70.2023.04.12.10.03.45; Wed, 12 Apr 2023 10:04:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LvHhC67Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229535AbjDLQsV (ORCPT + 99 others); Wed, 12 Apr 2023 12:48:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230383AbjDLQsQ (ORCPT ); Wed, 12 Apr 2023 12:48:16 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B66A65A7 for ; Wed, 12 Apr 2023 09:46:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317952; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TwrBVEbuHxz2Oj1oTVxriRpco4XXvHrMi+8R/zKrUWA=; b=LvHhC67ZVfhkJbQHzK22JZ89a+cXxSmEWKxRjjvnPbFVfVXYoqC0dXPf3GYIRZoybjMP0a IHCu4zwKZ4qEGTxWj03A0DW71kLd6WZImcDNJ956fzVSRS3Q/98ro1/sCWMcIEfg4vmTXx bJrL3LFYUnYktauqUS29FO+ysKabh/o= 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-606-6xj6vuE-M6mqfrZMwLzjfg-1; Wed, 12 Apr 2023 12:45:51 -0400 X-MC-Unique: 6xj6vuE-M6mqfrZMwLzjfg-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-74acb477be6so2339385a.1 for ; Wed, 12 Apr 2023 09:45:51 -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=jcGaF82nR1u7JPr0Q71qfubNAScHmWUUAq80D+N7jlQmhR3OL4Kl8dox+PyPweJ0sD PrpkUnyecRHSCQyJtCtfk2oIy6EW3DoEzMcOzQlnYnYhEpswiITWlST3ve9v0qKUZU9S OKivcSSMAKYGI3woxDVtAYZit3gZPi8UWi4RVRxz8wuIvlhLsQoX5Qskios/hyC7rsSV WHYKVFw1rkBSYJV1OEF16OuhtPGK0nm/1xhbbIU0Q8vIdNG0l4pxstTia+27JzpygW1K gnBoZIckQyFJZqIFvsddIWAZBHDm20WQ84OBUJeizcLmhVq+uljT2m9mBo2T3eJt2tV9 Algg== X-Gm-Message-State: AAQBX9cS5a7bX7UIsOb4/TmXfFx+KwgC6kqvmmwOz/acPpfihYq7gUaf JLqR79zJRFeMjn/UZCO96bhu9nHXODe0dBinwChR69sf5LPdW42qDU8qVsYU3v2Bztuze/66vWu PiSwTcGsPP1ctUQw7Ly1nzFhh X-Received: by 2002:a05:6214:529e:b0:532:141d:3750 with SMTP id kj30-20020a056214529e00b00532141d3750mr4519997qvb.2.1681317951121; Wed, 12 Apr 2023 09:45:51 -0700 (PDT) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762990804593162451?= X-GMAIL-MSGID: =?utf-8?q?1762990804593162451?= 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); } }