From patchwork Thu Mar 30 15:56:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 77283 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1249040vqo; Thu, 30 Mar 2023 09:20:47 -0700 (PDT) X-Google-Smtp-Source: AKy350a2WhB+n8l25YzEogQPh2vfCYN/+wWXj16aKK6qdrDvLVe1mcohQEUGa1bbU4icCr7spHJ0 X-Received: by 2002:a17:90b:1d86:b0:23b:3f18:a8fe with SMTP id pf6-20020a17090b1d8600b0023b3f18a8femr27218813pjb.31.1680193247323; Thu, 30 Mar 2023 09:20:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680193247; cv=none; d=google.com; s=arc-20160816; b=AzgRRacGe/xXYA0K0qumPrO58gJgLApJQR0FVU0u+AWXLH012WDzf39MXnevmRMIDv zGHOdIaK5w+Hj+dQ4mMzKGCRcC0d/uhVmxujpIrn8onhDuGNcRu7n76Ubn4tD2gufHnF tGINSvVOhsdsj090rEoWSN5TWk2ozf8a8KBSFgP7/ObRtp5WXZeSTdg5L0f8+CpnuFuS NO2c6tTz6Z/TUcSOr/qlQYwqAIC8gdhDJFOBFWxbjkLecjn8sklTYWCEzung89VkF/fT TYcC3SUXGvawolaNYF/owcRQt69wGZGpxvnkLFLi0+mBGQoC0ySdfHrscV7jTM5EouSc X+6g== 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=sP9rqjignnWh2VSPIiMl4HPMQh9/IMP3JUMCK79G4dM=; b=AccF+OZ4d4iK32/tP8dh3pxiTPnSGLsAxYOcM1ccsnt+wzpyco2DPBnRERBQKi6GzQ OJOlzN1+NoGEKl6y1viZVZXJHs8dQglZxv/jWrCmfwDr/geD3/zIShiR4RUjodkTDzpy D8WN8Z/vMyF9ViVD4XsB0jpLB3jAtms2e7kCaw8v5DngPCqXMrAtzUQYLXOsGVNOKkEE Zvc7AH044uzPfeHYsVT2v2wCSES0Yr2DDtPv8uKek1MqhyuGxPkEquBhv7H6eEGkJoAV WXrAu0PXC5T3XtXt5pOk4xEJyTfwhKtPDhJDSfQE9hFHk24OR56cVjBB9/j6jBU8hSRj dPsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=eMCUvD3e; 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 t10-20020a17090a6a0a00b0023f14c9a5fesi4181468pjj.100.2023.03.30.09.20.33; Thu, 30 Mar 2023 09:20: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=eMCUvD3e; 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 S232874AbjC3P6K (ORCPT + 99 others); Thu, 30 Mar 2023 11:58:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233501AbjC3P6E (ORCPT ); Thu, 30 Mar 2023 11:58:04 -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 6933B10CF for ; Thu, 30 Mar 2023 08:57:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680191839; 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=sP9rqjignnWh2VSPIiMl4HPMQh9/IMP3JUMCK79G4dM=; b=eMCUvD3eYSZZ+FKilEItqt1NS+/NsoI6qIuR8ZAmwdr86TJL9TbGbpblRWwMUE2rUPq8pr WXYperdklGGfr4NBOz6d7FrapK0wSqghgVmISjHHaoJbkNtuE/0INoY7zaAZiDJc5+a18J YLRQbUpBwxpILWifXMc/N5zRlIMKOe4= 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-563-AZLvEGlFPpeN5WRBTqjq0Q-1; Thu, 30 Mar 2023 11:57:17 -0400 X-MC-Unique: AZLvEGlFPpeN5WRBTqjq0Q-1 Received: by mail-qk1-f198.google.com with SMTP id 72-20020a37064b000000b007467c5d3abeso9069881qkg.19 for ; Thu, 30 Mar 2023 08:57:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680191832; x=1682783832; 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=sP9rqjignnWh2VSPIiMl4HPMQh9/IMP3JUMCK79G4dM=; b=i0GshvcBPzUahTTFTz2t/WBoCOGrDI61mIusz6wfi4olvzrEFHtwR5J4XB/f5ihFsa aP9SmuM6azLKTEFzXBYW44ACo2Do09+Z3h4mtm+pFvDkCjERIoa6uHZe+lxX4pgqnSln oE04fYMbj7Jia7jjccQn8aKCoFQ3HFq6O4a8s6h3jvxKKcnBiBVNbx8/BtqSBBlVAEu0 3wwE9UU3HskXHo6pMhwKPqd0m5Lf0vJ216tnDVwjY9JI6byQ4mxZ+9e6dY5AxtDecAFT cnxM2i76xdBSL++CEJa2VA5cCXswLkKT4+j2D+3KcffuaFsIFFqzRV0olslNnO9K+eZ+ yBpA== X-Gm-Message-State: AO0yUKXCcTIYI70Kt7UMCltnQwWJFCGNSVCNDOy7rwQfiESmQ+OB6qUt mXqhLy4waicgIO6qpGPEBK3gLxSrCi+wcEkt8lfg+KBG5izdq36MY6WF+TQUT+mQ3ZKhc93s8J1 AnSbgtOVI71L/gzZqADa8Qau8 X-Received: by 2002:a05:622a:1981:b0:3dc:483f:9c82 with SMTP id u1-20020a05622a198100b003dc483f9c82mr36684514qtc.0.1680191832432; Thu, 30 Mar 2023 08:57:12 -0700 (PDT) X-Received: by 2002:a05:622a:1981:b0:3dc:483f:9c82 with SMTP id u1-20020a05622a198100b003dc483f9c82mr36684482qtc.0.1680191832185; Thu, 30 Mar 2023 08:57:12 -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 o10-20020a05620a0d4a00b0074281812276sm13059380qkl.97.2023.03.30.08.57.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 08:57:10 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: peterx@redhat.com, Mike Kravetz , Andrew Morton , Andrea Arcangeli , Mike Rapoport , Axel Rasmussen , Nadav Amit , Leonardo Bras Soares Passos , David Hildenbrand , linux-stable Subject: [PATCH 01/29] Revert "userfaultfd: don't fail on unrecognized features" Date: Thu, 30 Mar 2023 11:56:39 -0400 Message-Id: <20230330155707.3106228-2-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230330155707.3106228-1-peterx@redhat.com> References: <20230330155707.3106228-1-peterx@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=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=unavailable 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?1761810314880139031?= X-GMAIL-MSGID: =?utf-8?q?1761810314880139031?= 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 Cc: Axel Rasmussen Cc: linux-stable Signed-off-by: Peter Xu Acked-by: David Hildenbrand --- 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 Thu Mar 30 16:06:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 77286 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1249739vqo; Thu, 30 Mar 2023 09:21:34 -0700 (PDT) X-Google-Smtp-Source: AKy350bVMSxCjQK9D2SUlX6kTQg8TfNQQ3i/bypkxfYtyJtl2iJH9ozeXnG77IADkblAEiINI9Cc X-Received: by 2002:a17:902:f542:b0:19e:e172:2a40 with SMTP id h2-20020a170902f54200b0019ee1722a40mr29501307plf.65.1680193294557; Thu, 30 Mar 2023 09:21:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680193294; cv=none; d=google.com; s=arc-20160816; b=D5iQ0FstlWq+BGSmd3dZgJpIb3xepSUvI5umwuYtQ5HVQwf/phoejD2b0mGYnZKVfB iIXfYV4gPZQVVRlxhvXHzUKkJSTD888QnjHma+g2uxmxBuELkFxiRmSL/39XYdh4TQZp RDzVjonzauDtJf58Rbt75h9oI9AI0ihIvAsW4FhB7EGHOkIGlh1k9z8HdyRM/3DjrIeU L22H04EEoiAkKXE5zchrhlyq6LfoP3kpoq1ILyF25eJBUwZfMCG+/2VaQNqqhcL29ScQ kWcVBr8aK+xOiAiChGn8qQeeyF53mPod6LxEl8+d1PcmgdzuW/ebAbP+DOJh7wrQpkki T22w== 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=YTYh+E3AEUbIuKqZIO8jsHd8WLvzzX9QzK3UcbYoR1Y=; b=q8FwzcvnE8fLBqjnW0TrwhZMxy1KqXGiBLDGp9odgu5XB3esE10Gic2YOHotLUsyhT xdQdoZWA0Mbl8dFKoG5UKjeTUJQsdrlFK5KcX5kbNElRzRs9JCgayGehEh7bB+n+TrYM R/AeeXnf/NtwcphXmyhaFMjYUHI2cPGrc+0QdheyjqI8vG5rM/ZI7VPxVyYVhkUWaPR2 GXf+hpa/7PLWocf702hxDVg87pBP9a6cBJr5LLkAYKBgDdKRijgTQ+sojI0dV7i/ZpVT JefNPtLtFaDgc+IjQ7TdcFdyx7jDdntDJwoiNuLM1vVuwQAPAUBEggvLr3NU7elZ/VMl jHnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FkbnxmbQ; 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 x26-20020a63171a000000b005004b2acf6dsi2613450pgl.810.2023.03.30.09.21.20; Thu, 30 Mar 2023 09:21: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=FkbnxmbQ; 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 S229764AbjC3QHh (ORCPT + 99 others); Thu, 30 Mar 2023 12:07:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229543AbjC3QHf (ORCPT ); Thu, 30 Mar 2023 12:07:35 -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 11F218A7D for ; Thu, 30 Mar 2023 09:06:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192409; 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=YTYh+E3AEUbIuKqZIO8jsHd8WLvzzX9QzK3UcbYoR1Y=; b=FkbnxmbQ+HS4mWJSUWx1fAgHuw0hNwb2B4Hug/dUxQ2dBJ2P82nRIuZ51nPm8x+xPEBiOp IGuCLLnQP2lsFeJfwEnyDs/nS0RPq5a/IM9On4rvK/TPGtIOTWHLnGr8oY2olnFLTAWTCd QO48g+JZTBKz9xixBk3Ng3qELKDNiX4= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-561-S9C5sULqPeCvmUFKY6xBPQ-1; Thu, 30 Mar 2023 12:06:46 -0400 X-MC-Unique: S9C5sULqPeCvmUFKY6xBPQ-1 Received: by mail-qv1-f71.google.com with SMTP id w2-20020a0cc242000000b00583d8e55181so8444510qvh.23 for ; Thu, 30 Mar 2023 09:06:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192406; x=1682784406; 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=YTYh+E3AEUbIuKqZIO8jsHd8WLvzzX9QzK3UcbYoR1Y=; b=lNgcfMumbktVd/xSk83qsnTKjjQGzyBAj/vQkOaTQ0CQGiGQRSInJU6/eHSyhannYi vMLxhXYIH7Y8/OzbpQTDxLeJYmMA7cPA5MZum51WmElDA4+YsIFeGBe12F0+WPWj5H2B NMhk6jP1qXtdl7IrO6MN9xZhanRiPwAHHT39dCvmjfEjauppYSwzxWxEzI4kNXIZFl3Q NYe/Sn8WoxevKtLLYhdLyJvYrLPJYiqi7CJTAGM6ZB9XbyDS8nT395S+j1DMIrmKu8Hi V6yiQa1ydxvuM+opVtzvNuXzu5Ig0QY9sjWCvAxpJMQNQjLiN6tgiK+UkE8ylNrqmy+h hxug== X-Gm-Message-State: AO0yUKVvLRmh7D8mpqeRQxW6fc+hZIY0avXe9iLAYLAno/QBQ+fkkOLG Hw0aEbprt+yBmbRoMpKf2N0FzqV+Bxok5x2Rx+Q9Gngke3fNzo0BwToU6YArysHZCxLEWkzCFW0 PpQNiAKemjzUX70NcBtoeG3Qt X-Received: by 2002:a05:622a:1886:b0:3d1:16f4:ae58 with SMTP id v6-20020a05622a188600b003d116f4ae58mr37192710qtc.2.1680192406271; Thu, 30 Mar 2023 09:06:46 -0700 (PDT) X-Received: by 2002:a05:622a:1886:b0:3d1:16f4:ae58 with SMTP id v6-20020a05622a188600b003d116f4ae58mr37192679qtc.2.1680192406057; Thu, 30 Mar 2023 09:06:46 -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 66-20020a370b45000000b0071eddd3bebbsm11294515qkl.81.2023.03.30.09.06.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:06:44 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Andrew Morton , Andrea Arcangeli , peterx@redhat.com, Axel Rasmussen , Mike Kravetz , Leonardo Bras Soares Passos , Mike Rapoport , Nadav Amit Subject: [PATCH 02/29] selftests/mm: Update .gitignore with two missing tests Date: Thu, 30 Mar 2023 12:06:43 -0400 Message-Id: <20230330160643.3106892-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230330155707.3106228-1-peterx@redhat.com> References: <20230330155707.3106228-1-peterx@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=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=unavailable 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?1761810363943664130?= X-GMAIL-MSGID: =?utf-8?q?1761810363943664130?= Signed-off-by: Peter Xu Reviewed-by: David Hildenbrand Reviewed-by: Mike Rapoport (IBM) --- 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 Thu Mar 30 16:06: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: 77290 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1249904vqo; Thu, 30 Mar 2023 09:21:46 -0700 (PDT) X-Google-Smtp-Source: AKy350Ycb+pn4sPXiFpS9t4+nFph16eR0VJhIE3jkZ+aWT9EDZ76u/uBb31ND+8GixPthSG1vAA+ X-Received: by 2002:a17:906:8559:b0:931:9cd2:c214 with SMTP id h25-20020a170906855900b009319cd2c214mr23400102ejy.66.1680193306674; Thu, 30 Mar 2023 09:21:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680193306; cv=none; d=google.com; s=arc-20160816; b=RXqgUIt0cLnKyhc2gfgwNljPhiLEzV7ZD5MDRN/OQnDFZyI38Zg5wyjPHSzO97Qo2y DdZGeT9RJdMmue7EKSEZXQaL06waoWFfuQXrTZPXrzOKHqG3Y/qyZxNyYogMkohlUqkW TaAiMrii1sxUMOhrH0gX8x7eKeQMxgBT4etGvKhI/mDUV+FzjeVwj4r9LJd2vBHVTE9P 5WYUk+QYmzDJFqpLk2jpWHyEYUqBsG5a6h+4meGPnkfzh7RsVdUhi0A3KQ4KwCEk45qO 9sNxS7hL5NCXIsccutnUIgBZKgbQv8lSy30WUJIde1heDJWRu3lniNWzidaxrtA46iEF qUrw== 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=Ur7tdcX2754X/jwxH6S7nx/WMyBE34LUGKNmt1W9AUk=; b=YqPxsSBlTIF1ahsJlyNrNpFRU6uVELi3SL6yOAipvIeZQWy+G86pHRuwNE622acvtH Yuf/iKvgvsGTeY9rMD6JQ40VrklEtrJ/GP+iH6n/0jlE1iUZ3mwI24W5ZdywMSaKjCoI rSzAKZDOjsVi/dkfIoqQe1O5GKlTaLmiz3syrq7dkncDGh7VFS1ZayUwuasM8tMYWd3k rL2yGzxTc7PmHRz32dNMmXhli6BSTlHGlyAlhemEaLmeJK76jOuq/jITm6XcZvFnHSkG RPvEm7xutfSR+DefykyGo5G6+vdg7SmIklwiwjCy9pY3PFY2YWnGp+Q2IKDxmxAwdwW3 aO3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EYKJIM0d; 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 p15-20020a170906a00f00b00933260c6385si14948ejy.230.2023.03.30.09.21.22; Thu, 30 Mar 2023 09:21:46 -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=EYKJIM0d; 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 S229902AbjC3QHr (ORCPT + 99 others); Thu, 30 Mar 2023 12:07:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230525AbjC3QHp (ORCPT ); Thu, 30 Mar 2023 12:07:45 -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 7ADB0900D for ; Thu, 30 Mar 2023 09:06:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192413; 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=Ur7tdcX2754X/jwxH6S7nx/WMyBE34LUGKNmt1W9AUk=; b=EYKJIM0dIvr0IRBY+U25LLa+VToES3JxHR9t3uigjq7tLzH0HqWY3N+tlJ6DLQXSDJSG+d R2iTOYqmjnUPjHhskKa8dIht/VrCmnfe16/EltTo72b52FB4Lhjyr2Ewesq2t6diVLsR+R moIcea9tRVBvs9IlOaKlwEbW9yf7OIo= 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-134-_7mtD-WyOMCl8rdjjMHARQ-1; Thu, 30 Mar 2023 12:06:50 -0400 X-MC-Unique: _7mtD-WyOMCl8rdjjMHARQ-1 Received: by mail-qk1-f197.google.com with SMTP id b142-20020ae9eb94000000b007486a8b9ae9so6467482qkg.11 for ; Thu, 30 Mar 2023 09:06:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192410; x=1682784410; 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=Ur7tdcX2754X/jwxH6S7nx/WMyBE34LUGKNmt1W9AUk=; b=eo/yiDPNz0BMkZAqqqK9Fs1Ne8GX+VrTYh5sFoBQv5NXQn8A+9EqtU25UOdcYg4MsH 9w8TPLEL2UH9AgOuDhdpfxtBEnuYI1ypyBMEgkHxdXMfivp8OA4THDhC57boGj3rn8Er BU9a88PnDsQMDcHNEFuTsVSeA/OTiW4c9shOorDCiMLZqrb48QvohoM5YZvp8/yxCqsR vO6Gq7N8zZ6kpm/mnedfk88o6OYq8ftwRXj/KzGiaSSWzNkMmRRADTL/qrfVUZ5lpei5 iGmdYohTDGfqFgKeW7F00vBVO2/x/qez0hAANizZS3MGUH8F32Mxew37AmuqWQAtRKlB Wlyw== X-Gm-Message-State: AAQBX9dtG8EBwwPttj6iIBL3i4lGVU0WrQlLhaQwG5bjX/DOx2JjC+cc zgZF0yCq8JNrtncyL0meCZNSO5ht9VXgoCQnTtfYgzpBggDrsNl5Sg1lj7/7IUfvL5ZvoJTGmdi hDdayKIKCf1PKFKJsJq/ZxL7K X-Received: by 2002:a05:6214:518a:b0:5de:5da:b873 with SMTP id kl10-20020a056214518a00b005de05dab873mr3919739qvb.3.1680192409807; Thu, 30 Mar 2023 09:06:49 -0700 (PDT) X-Received: by 2002:a05:6214:518a:b0:5de:5da:b873 with SMTP id kl10-20020a056214518a00b005de05dab873mr3919704qvb.3.1680192409526; Thu, 30 Mar 2023 09:06:49 -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 15-20020a05620a048f00b0074636e35405sm12074981qkr.65.2023.03.30.09.06.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:06:48 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Andrew Morton , Andrea Arcangeli , peterx@redhat.com, Axel Rasmussen , Mike Kravetz , Leonardo Bras Soares Passos , Mike Rapoport , Nadav Amit Subject: [PATCH 03/29] selftests/mm: Dump a summary in run_vmtests.sh Date: Thu, 30 Mar 2023 12:06:46 -0400 Message-Id: <20230330160646.3106903-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230330155707.3106228-1-peterx@redhat.com> References: <20230330155707.3106228-1-peterx@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=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=unavailable 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?1761810376903443631?= X-GMAIL-MSGID: =?utf-8?q?1761810376903443631?= Dump a summary after running whatever test specified. Useful for human runners to identify any kind of failures (besides exit code). Signed-off-by: Peter Xu Reviewed-by: Axel Rasmussen Reviewed-by: David Hildenbrand Reviewed-by: Mike Rapoport (IBM) --- 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..9cc33984aa9f 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 Thu Mar 30 16:06:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 77287 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1249726vqo; Thu, 30 Mar 2023 09:21:34 -0700 (PDT) X-Google-Smtp-Source: AK7set+S02C51RVCgxkAnyPRJ06WR2s4yCli6FHmt3IeSlYMb+GdPN0qW8y9wfu+hsWAEoN0tWwr X-Received: by 2002:a05:6a20:6714:b0:da:897b:ae40 with SMTP id q20-20020a056a20671400b000da897bae40mr22182821pzh.37.1680193294170; Thu, 30 Mar 2023 09:21:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680193294; cv=none; d=google.com; s=arc-20160816; b=g2zQECMP0RpM3r6wuVWBW9V3Ir217Ogowdlju9I0iN254wGJPomWY7kMhKhZXw17Ih VAau7gV58+MUuINqICKFcOXPqC+2LmqDV0kfdsyuSDCgHUCRF4A+/ooIR98GzRaQQRMg r8P+Ne6qGtaj/9o+DhvLWxAtXcFXbf6UoHjd4ETlFCRW4jsKiAbzbKxmXWeslYK+LULP AC2JbiG9o6/QGRZu7RaTnjf/yfAxUenXiW7xoNA0DFLNodjP5npGO8NA1PlmxHAwLzNO wia8YQd03A/y6JFotVUeRN1mv/5A+Lvb/9kUzrYyh3CNvWDZ1iqjf5oC0AUrpRr74X4X bimg== 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=7NTd9ykbxp4UXzRNrTfarBboXMMqnuQ6sOTF5uMlUjU=; b=BzLplLLouwszoXU5B9zvB5RAw1ni0FkzOLy0nNz+oSzhTBXbj6V1IymwF727WcByGq VRrad7cuUVcbpeoCE5oYbywNAXzc124f9pj+uN+rQq9VDs0jSC2H16CoWda8h2TNyW92 W+eORvMExqN6Yf0aBO7sp7HzB3RoNZvljAmteAr78N5tc3f/FlUSHcGy80q1xLK2mRPe NKBDNulvXf1Q1BIqlhgnE7ExQopTG8P4uvJmQ4aCqUrUUutd/aYWojPiegBvTE7hmj/T 38wYD6rvw0ZZjdXV2LFuvAin036pxgrhBDGpzSRHvSjjrEpBwNFh/0lzfL91qKGlp0hC N/hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=K5JhMXgf; 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 129-20020a620587000000b00627f0f8d49fsi54723pff.373.2023.03.30.09.21.20; Thu, 30 Mar 2023 09:21: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=K5JhMXgf; 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 S231514AbjC3QHu (ORCPT + 99 others); Thu, 30 Mar 2023 12:07:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231255AbjC3QHs (ORCPT ); Thu, 30 Mar 2023 12:07:48 -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 0A4A193CA for ; Thu, 30 Mar 2023 09:07:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192428; 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=7NTd9ykbxp4UXzRNrTfarBboXMMqnuQ6sOTF5uMlUjU=; b=K5JhMXgfm6kguiQKimQG+Aj2vDjGAiw3wQw4wmg+x0a9pqoLgoYreSpg2vI6OAFjI+Ua2P 6hW/EseOhskhomjC5ppTzMwNsIzZKKnm20vMif7tc0v5iagRt6iF0y1LrKc0/r2Pylz+TI 5eDqnOEcq112meGMni8GmLA+lW1rYvM= 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-345-hL8PWttiOsqPp9cPULO47w-1; Thu, 30 Mar 2023 12:07:02 -0400 X-MC-Unique: hL8PWttiOsqPp9cPULO47w-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-5aae34d87f7so13014036d6.0 for ; Thu, 30 Mar 2023 09:06:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192414; 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=7NTd9ykbxp4UXzRNrTfarBboXMMqnuQ6sOTF5uMlUjU=; b=t8WxwOs4DOFa8+wDpV20Fmh/7qcN+FNXK3Nc9D5o+vr/Dz89aHpQ0rYkqes+yh5yE8 uiK/62ZPVCl1u03qhD0ioeftcbAO+RTyk8mGsxtymD6TKdczgXdspjyOfJwqk0q7xI2x 55p0zSLfPfU8zk8dRyB3CyrlgVxGDxJev/ostNjNijxd1U1XhzU9CKMYTQpX/MfWzhGT GoQNbnwZBXLPLCFnUunmNuujccpGzK7xiy71K0lqKFJKbO/BU/3IbmRWGIOn/9ISTZzq niyWDO2tJG4c+bV5530XekRVJWNm/ABYeTyOqseHnGteBVfkzHaq77rlPrPCo9Z3ZQsS agGw== X-Gm-Message-State: AAQBX9dBdSLMvdY6YDe6lGhPlesDHqF6ET57uhkFthQ+FjCGnsvjzs7d 2jysYffGgJF9tBQox7cPSE2cleee31mHrSibLSo7pjWVy3z6WRlBxcQooGzLkiwGLN+UHMgaxKU 1kkIbm83cL4u/LrCMzG4u2U3D X-Received: by 2002:a05:6214:d0c:b0:5df:a693:39e with SMTP id 12-20020a0562140d0c00b005dfa693039emr3564904qvh.5.1680192414017; Thu, 30 Mar 2023 09:06:54 -0700 (PDT) X-Received: by 2002:a05:6214:d0c:b0:5df:a693:39e with SMTP id 12-20020a0562140d0c00b005dfa693039emr3564872qvh.5.1680192413714; Thu, 30 Mar 2023 09:06:53 -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 jy3-20020a0562142b4300b005dd8b934595sm5541041qvb.45.2023.03.30.09.06.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:06:52 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Andrew Morton , Andrea Arcangeli , peterx@redhat.com, Axel Rasmussen , Mike Kravetz , Leonardo Bras Soares Passos , Mike Rapoport , Nadav Amit Subject: [PATCH 04/29] selftests/mm: Merge util.h into vm_util.h Date: Thu, 30 Mar 2023 12:06:49 -0400 Message-Id: <20230330160649.3106916-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230330155707.3106228-1-peterx@redhat.com> References: <20230330155707.3106228-1-peterx@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=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=unavailable 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?1761810363271468288?= X-GMAIL-MSGID: =?utf-8?q?1761810363271468288?= 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. Signed-off-by: Peter Xu Reviewed-by: Axel Rasmussen Reviewed-by: David Hildenbrand Reviewed-by: Mike Rapoport (IBM) --- 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 fbf5646b1072..4188435967ed 100644 --- a/tools/testing/selftests/mm/Makefile +++ b/tools/testing/selftests/mm/Makefile @@ -111,6 +111,10 @@ $(OUTPUT)/madv_populate: 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 9fb21b982dc9..85a49aea3ab8 100644 --- a/tools/testing/selftests/mm/ksm_tests.c +++ b/tools/testing/selftests/mm/ksm_tests.c @@ -14,7 +14,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 40e795624ff3..0204c469be43 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 Thu Mar 30 16:06: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: 77285 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1249734vqo; Thu, 30 Mar 2023 09:21:34 -0700 (PDT) X-Google-Smtp-Source: AKy350YXVsKSLv597DjlVumZqc1Jre2tCgb0t9uC6jGlD2fWuBRkfRpoDgc4wyUU4AM/FwCVXhZg X-Received: by 2002:a17:902:db0d:b0:1a1:e410:a1ff with SMTP id m13-20020a170902db0d00b001a1e410a1ffmr29507661plx.24.1680193294498; Thu, 30 Mar 2023 09:21:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680193294; cv=none; d=google.com; s=arc-20160816; b=JtwI797Tv7PH9OKG64bQ3+sZ/lyLdibK6g2wHxY8NAVseyhaR15B3ypoVWInlgHrDw jCLmVIyF6kEffY6R82uyHzPAq8kD5FxgnbRLpE83uz8BnGEx601NwQhv08VJqVlyj2K7 4IcOG1Rz0Ud5rtSrR8lXfkP2PyHeNBnNy1j25gO2rHSqNe+/byrUGNJDWpti/UenKnwP GnUyRX8hTeRXufOVh7iqrgqByldzaIt2lRFmg5N6R4Zf74RqCNptWTY+LeG8395hi7T5 q/Rie2bPQcdHBWpRNy4DY6Y/UqFCujOiiHzZJRf1dJOv3YLFMDjJ13eYU/aD455LqL72 XcSA== 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=KQ4ftFOSRnTCxQ3k16FeIYD6t7fNL3xHl6bh3AvSWJg=; b=t57gdKTUap2PFZjQPIEZHwI6WUjS/VOKDncrBOAnblGjC47ipChugKjtcAzw6NVS0t XeNZ2eZIF553kkCgfdJbSjtqnvtD80t9CA2CzgXaJ0BdyO6hWLoDn9iUWJuBbI4xAtP2 tVDabazpHAwR31JZLJ/iZS4fBCeDBwp+qR0XAlMgwmFZ5Y58lr16/svIwQlJRrx9K+O3 lKQ9ZsA90ln4U3K/bJvyZv3FJInFmT7XhKZCi6NueXOjOA93mI+UXOeODHdi3YKJ8e7f WIIyex6M4reyU8wcHPQwOoltyXcLNgQeVgkWACTlkNGMDT5lI8qKhyP1Q0UKzOFg2OtX yUDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GZPEVMuC; 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 bk13-20020a056a02028d00b0050c04831b70si33654919pgb.800.2023.03.30.09.21.20; Thu, 30 Mar 2023 09:21: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=GZPEVMuC; 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 S231293AbjC3QHx (ORCPT + 99 others); Thu, 30 Mar 2023 12:07:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231381AbjC3QHt (ORCPT ); Thu, 30 Mar 2023 12:07: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 554BC93F9 for ; Thu, 30 Mar 2023 09:07:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192426; 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=KQ4ftFOSRnTCxQ3k16FeIYD6t7fNL3xHl6bh3AvSWJg=; b=GZPEVMuC0ko8IbQElid6M0CBsIoweo9IITLCZ0y7lxjeBvrzsN75HG1wirLtxO98IWQEuh 5xArJtRXPxIBArxnZ9XiDK7K9/0AfHhfIsUWbuDEACfecap6L0o6ev/kru4Zz+wXlB3meo yBkG+ThjuCisMKoKQ6uSeWbAJhoeX74= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-65-JzpKxE4ZN-qwPoxr1fKyow-1; Thu, 30 Mar 2023 12:07:02 -0400 X-MC-Unique: JzpKxE4ZN-qwPoxr1fKyow-1 Received: by mail-qv1-f70.google.com with SMTP id m3-20020a0cbf03000000b005de7233ca79so6265810qvi.3 for ; Thu, 30 Mar 2023 09:07:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192420; x=1682784420; 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=KQ4ftFOSRnTCxQ3k16FeIYD6t7fNL3xHl6bh3AvSWJg=; b=K98zgL3VKblFFiuXWAm76aM9sTLAexy6gXxjD68hk7vSd+cQl1UUjg04q7zHhjSKzC WrO02ZcLZ/W8Waf83DtHLzikEPBmyLuMyQJ2+yLfxWgQmd6Pu9VpODk/Sk4BNpW4wXKI JUUfRP7xQk1HvkMMF/kIK3XyOwMD7qT80NaItvTz+e6qor+webBgzw6T6jTzFUsG249j XUlcuTzrDGdlGV/gMqJDObwQXnhmN/Di68oNGM8y6vAcL6WZaTzFO+kFfLSeK9J6YY4I 9+FE4gr4R//Wx4mrKlHGkmsIGj7l224Q+qHQhVlsh9JYyzP1/dVHTt4O8E+LInG0/LHW wgCg== X-Gm-Message-State: AAQBX9e0d3pWyO0O7I6PEdxNWi0m3pAtR9zutTY1aCDv/TljjaVt4kiS H54rTeBdCnfR6kxI+1oSNh1BQi1P5LM0vLwUtcmSXxTJ7h9Mh8diFe1nTdZQEbkXDtxdvG8PL+W +BveGJjcYXbnFs1UFO9yYSqfy X-Received: by 2002:a05:6214:509b:b0:5af:3a13:202d with SMTP id kk27-20020a056214509b00b005af3a13202dmr3919565qvb.4.1680192420084; Thu, 30 Mar 2023 09:07:00 -0700 (PDT) X-Received: by 2002:a05:6214:509b:b0:5af:3a13:202d with SMTP id kk27-20020a056214509b00b005af3a13202dmr3919542qvb.4.1680192419807; Thu, 30 Mar 2023 09:06:59 -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 f13-20020ad442cd000000b005dd8b9345b8sm5531537qvr.80.2023.03.30.09.06.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:06:59 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Andrew Morton , Andrea Arcangeli , peterx@redhat.com, Axel Rasmussen , Mike Kravetz , Leonardo Bras Soares Passos , Mike Rapoport , Nadav Amit Subject: [PATCH 05/29] selftests/mm: Use TEST_GEN_PROGS where proper Date: Thu, 30 Mar 2023 12:06:54 -0400 Message-Id: <20230330160654.3106929-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230330155707.3106228-1-peterx@redhat.com> References: <20230330155707.3106228-1-peterx@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=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=unavailable 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?1761810363856812441?= X-GMAIL-MSGID: =?utf-8?q?1761810363856812441?= 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. Signed-off-by: Peter Xu Reviewed-by: David Hildenbrand Reviewed-by: Mike Rapoport (IBM) --- 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 4188435967ed..47516a78d447 100644 --- a/tools/testing/selftests/mm/Makefile +++ b/tools/testing/selftests/mm/Makefile @@ -31,34 +31,35 @@ MAKEFLAGS += --no-builtin-rules CFLAGS = -Wall -I $(top_srcdir) -I $(top_srcdir)/tools/include/uapi $(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_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 += 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 += 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 @@ -76,24 +77,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 Thu Mar 30 16:07: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: 77288 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1249783vqo; Thu, 30 Mar 2023 09:21:38 -0700 (PDT) X-Google-Smtp-Source: AKy350bbeXsg7nFWNfiAuwS3AGHcBDS+4WiUG/63O9duTlWxWaVWNew4ZIiC2aAivlO1ft2g/l2Z X-Received: by 2002:a17:90b:1811:b0:237:b64c:6bb3 with SMTP id lw17-20020a17090b181100b00237b64c6bb3mr26968669pjb.11.1680193298075; Thu, 30 Mar 2023 09:21:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680193298; cv=none; d=google.com; s=arc-20160816; b=B9byPlQt9jxmpTnSiMabOUUr2mb5vCM5gMaZdI+urVd5hALX7/jeNgyGc6rmDcMoaw 7B3Vu/NOXpEueKSrx7xSLYTu5r+2L4CWs3Tm7722JiOsnMFs8OZvUriQfhckdOXlKEpD q0WMrHXu10+BZXtz/3sR5JZmjw1VFKCmaf4U48hO9E+jscB92aLzS+nnnR4w0TLh9Upr ZbrCvFRpv88XiVuh6Xcr1UbEb6cuwnZCDyfwJOTjeDUilEdBn/pH8jq73Ku88e2klist dOfuJ3sZ50u26xQ2QDh6+jdl4/5Ac84Jw9KJK4eoCfJsceTUsRbQEYCu5L9S65rxmjCS vLRg== 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=/DyAZC+/gpTxCJoW2F/j7VlnCZ3k9Ngitz86Xlm4uL8=; b=meTq945cdLAZxhRz8ocgMzDOxuI6r82+wW4uCKks0Z+ZZeufYXHAhd/t2KZ2FoSI0M KZf2Q32iSgGdlNxKbAU+wJ85Oq8MSmlqcXeOBUT82/0ncQ3dF1jR5GWh2TuSBWr3vcoU aoeijHaIYeDHv5ogbQKcH9f641BZJOM7oCCy+vc+7Zha4fsOf7+LQmPYTafM/GJVeoRn UyaKe+n5rGxsTUUC8RFd/eRY3TPX18gTOrsS3Jlfpyuiuf8eewFhuxgegw7A1ks808lA TGyOCX7YLGoHSQK6CF495Q0BM4mLxtdcckiUcxgsLMxjA5T3Ve1zP4ui1yVArBjncq6X Rxhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="ImGjAq/v"; 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-20020a17090b4c0e00b00230c06399e8si4624363pjb.89.2023.03.30.09.21.24; Thu, 30 Mar 2023 09:21:38 -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="ImGjAq/v"; 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 S231379AbjC3QIF (ORCPT + 99 others); Thu, 30 Mar 2023 12:08:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231628AbjC3QH7 (ORCPT ); Thu, 30 Mar 2023 12:07:59 -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 920EC9750 for ; Thu, 30 Mar 2023 09:07:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192432; 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=/DyAZC+/gpTxCJoW2F/j7VlnCZ3k9Ngitz86Xlm4uL8=; b=ImGjAq/vfgu9OJ6UsCoB5E9lsITQmAo2Uwh23JSIAtWsl6Qt1/uYA6SCcIw2P5qmo6MjMS t4RvxpeGOIiet0I/x7OVwUOzZ5y7YnvqVUrUxfzEAOx/sRrwgmyvR112fojmgLMbJ4jquT I48Bgh2Q5Z1/UDIcri2qlL9BRDzYvcM= 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-340-9yfrOVvNODSqDwV4bD_0Qg-1; Thu, 30 Mar 2023 12:07:11 -0400 X-MC-Unique: 9yfrOVvNODSqDwV4bD_0Qg-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-57c67ea348eso12976106d6.1 for ; Thu, 30 Mar 2023 09:07:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192425; 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=/DyAZC+/gpTxCJoW2F/j7VlnCZ3k9Ngitz86Xlm4uL8=; b=jcILiYd9VU7MqIOCqpGoiFp4vH3t0QOenrAIQQfFVpnzHVxJe19EwI2+vO4bsZUkJC hFPKXWMVCX7pkRr+H0AHTK37OLfchBjuRMZWzc0pa2sV3eKUq484qcyleA1wxSddV//4 JTxXpypnJz1kR1Tn7pY7hvMCI7ochxv0Qb3ypsgDUAxgkbY9uk4yPMWC7jR/ntZmiW49 fpIwxvT1jWm+wiPhkqKasKY5dZkDVH1tmO5V1VKt9/3cLPHNbJcRCCIbGZiF5IR7KBXG UJFSHMTHQJNkuKFV5UsgGgZYK24q113GMRCCrie3AC+LzLkWrPyfHF6Wc6CbOxfiIg9+ Kd8Q== X-Gm-Message-State: AAQBX9fgF0/0JVUAtVW2b9DC2bgGRGDJdwUX4z0FTa+umM/XmeCF3xdY vCWv8oI+tguDIUpNmvzaupW3GcppW9hEUTw0IgUJswVW2HZOl+XY9QRufTW+kqZu3PgknX0pWVJ Wy7URwAZM5DR91vVCGQT97mJ4 X-Received: by 2002:a05:6214:528f:b0:5a5:e941:f33d with SMTP id kj15-20020a056214528f00b005a5e941f33dmr3644486qvb.3.1680192425765; Thu, 30 Mar 2023 09:07:05 -0700 (PDT) X-Received: by 2002:a05:6214:528f:b0:5a5:e941:f33d with SMTP id kj15-20020a056214528f00b005a5e941f33dmr3644457qvb.3.1680192425523; Thu, 30 Mar 2023 09:07:05 -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 b17-20020ad45191000000b005dd8b93457fsm5467877qvp.23.2023.03.30.09.07.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:07:02 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Andrew Morton , Andrea Arcangeli , peterx@redhat.com, Axel Rasmussen , Mike Kravetz , Leonardo Bras Soares Passos , Mike Rapoport , Nadav Amit Subject: [PATCH 06/29] selftests/mm: Link vm_util.c always Date: Thu, 30 Mar 2023 12:07:00 -0400 Message-Id: <20230330160700.3106955-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230330155707.3106228-1-peterx@redhat.com> References: <20230330155707.3106228-1-peterx@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=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=unavailable 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?1761810367668220150?= X-GMAIL-MSGID: =?utf-8?q?1761810367668220150?= We do have plenty of files that want to link against vm_util.c. Just make it simple by linking it always. Signed-off-by: Peter Xu Reviewed-by: David Hildenbrand Reviewed-by: Mike Rapoport (IBM) --- tools/testing/selftests/mm/Makefile | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/mm/Makefile index 47516a78d447..b35f3eafde3c 100644 --- a/tools/testing/selftests/mm/Makefile +++ b/tools/testing/selftests/mm/Makefile @@ -105,17 +105,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)/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 Thu Mar 30 16:07:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 77317 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1268879vqo; Thu, 30 Mar 2023 09:49:28 -0700 (PDT) X-Google-Smtp-Source: AKy350Y1v1HV4bW3GzrWxBZXjEEk3+T3jGsCsgQ80SX3gBDqwurRGs2x8+T3UDymzr+KrHvLZhUa X-Received: by 2002:a17:90b:4f4d:b0:23f:7c82:2463 with SMTP id pj13-20020a17090b4f4d00b0023f7c822463mr26227114pjb.9.1680194968646; Thu, 30 Mar 2023 09:49:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680194968; cv=none; d=google.com; s=arc-20160816; b=qaDUJN4BpCDrK9KuV5VGeQ5RFlyhn8zkVnMZ40/dbWOI/rDUvH6BLoSp2hDtRr359x FfWWgQT2y3Db+KOhtdMzVvj+k9ow1KMF+N3//uP0t/cE1qTBqKGEMtUD8yGUBO4pgh/z P7adXFuspqoJGMWmGwzePe5heXD1QSFY4PO9X0oOfilKR+BebDXfnrkTXMfrGKK8FyVw Rf9JzVSjgrw9QCv1PKs1Vw+GZ12Eo4iBIslxHpfND2cqFherwXd3HDN/1hbreqFGYY2J 4jwtP+G49hfHPLzmdE92jEYFwdMk1j/AVsoXFATbaOGJ9Fkz1FLafCPaMdA5zBu+9dPM SAEQ== 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=3OY41FoDSXIz8Px4DR5ueHfK5qhzGwiU30swTtCORuo=; b=iSvWSo+e0319md3dVxN2eUuA2i6MCewz+OXNQq4813QuYLJ+k/sT50e7TmqIz7z6LV egb76QyPfCYZdBdkkWhH6oXP/cdPQiSSdqjM42jKk57wqUYg9KViLCnQ98p5meT1HvVi WdkeAHe9XwkePEtrpkscO7cUH1oL5gDuzwtuTn+tTElrKsYJdEC5myYR22LM3/lUV3uN DDEjqbfEgbINPGnl2CV634Bgcw0A2hQYOd4VYTUJop/gQdJ/3MOahqcKYoGv11SoDTUW ugt16cUL1a7nPv3FytOX4kkYjyWQGwYKhlXzBucWjSiH3QpsIHtowOuCM39A0E4SB5Ka Y7xA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JWF+84Eo; 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 ck14-20020a17090afe0e00b002409afb27ccsi716470pjb.21.2023.03.30.09.49.09; Thu, 30 Mar 2023 09:49:28 -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=JWF+84Eo; 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 S231821AbjC3QIL (ORCPT + 99 others); Thu, 30 Mar 2023 12:08:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231674AbjC3QH7 (ORCPT ); Thu, 30 Mar 2023 12:07:59 -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 A029A976D for ; Thu, 30 Mar 2023 09:07:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192430; 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=3OY41FoDSXIz8Px4DR5ueHfK5qhzGwiU30swTtCORuo=; b=JWF+84EoztgdDi3RKVDFDH07xLDm22qVs45rU+27AE/nxkBTl1YyO5olOWA4ltLNP714oP WodL5/ANw9xufidGOlUrC8BWu5LZKOFgoZ5B2uQBv/ura3xZujwqZBInNCFjrNCeH+z0bc b9yTVot+bbNGtgUGD+dVYPytRK1Hi3k= 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-558-2XSnw-gONMy2Ie_jsV56Ug-1; Thu, 30 Mar 2023 12:07:09 -0400 X-MC-Unique: 2XSnw-gONMy2Ie_jsV56Ug-1 Received: by mail-qt1-f197.google.com with SMTP id w13-20020ac857cd000000b003e37d3e6de2so12759855qta.16 for ; Thu, 30 Mar 2023 09:07:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192428; 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=3OY41FoDSXIz8Px4DR5ueHfK5qhzGwiU30swTtCORuo=; b=C8BbQNJTj4HIORWuCU7vfzQvC5yEwfvuoxt1/cmYamYnJHKap+hhJtM6I33Z0A62jp Bp8lyjEiMKZ41k7v3nzidlsbEl3G4wUih+dYwapMQgx4F6BzgNgM6J2YI/Puc+rfrmMS ///Kv1yx8v49efX6c37PK73Z60yrXgvpEB4SBJ19YsOLfZ1z9P/XjK2d+LDm/lcjzvje /5EiFavyQdjrjALVNxw6dQZ0VwWs7ZDV+hYaIvGkCr4zX1quflZWeU4xZX6N+9ZZXJyJ FYQFR0XB5rxqslP9tj9DMyIZEeQDoxUcDnVUD0msGMsbcNYJOGPIgi4z/P/LPPjviHfA tyvA== X-Gm-Message-State: AAQBX9el9nOf269JYve7EOGmgyQPKHo6MTWd+BMUKB3874i00J3tqoZq CFDXoZsYJO2KPI5JFeKY6K9hhPIsIh6kozOUScDAMipYj1jjjlnSe9ZCbu8lkVceFn8Ci732l+w jwyiLsg7LAaFKPybIQsWj3keA X-Received: by 2002:a05:6214:5090:b0:532:141d:3750 with SMTP id kk16-20020a056214509000b00532141d3750mr3688740qvb.2.1680192428266; Thu, 30 Mar 2023 09:07:08 -0700 (PDT) X-Received: by 2002:a05:6214:5090:b0:532:141d:3750 with SMTP id kk16-20020a056214509000b00532141d3750mr3688715qvb.2.1680192428056; Thu, 30 Mar 2023 09:07:08 -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 r6-20020a0cf806000000b005dd8b93457asm5582136qvn.18.2023.03.30.09.07.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:07:07 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Andrew Morton , Andrea Arcangeli , peterx@redhat.com, Axel Rasmussen , Mike Kravetz , Leonardo Bras Soares Passos , Mike Rapoport , Nadav Amit Subject: [PATCH 07/29] selftests/mm: Merge default_huge_page_size() into one Date: Thu, 30 Mar 2023 12:07:05 -0400 Message-Id: <20230330160705.3106966-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230330155707.3106228-1-peterx@redhat.com> References: <20230330155707.3106228-1-peterx@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=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=unavailable 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?1761812119753296562?= X-GMAIL-MSGID: =?utf-8?q?1761812119753296562?= There're already 3 same definitions of the three functions. Move it into vm_util.[ch]. Signed-off-by: Peter Xu Reviewed-by: Axel Rasmussen Reviewed-by: Mike Kravetz Reviewed-by: David Hildenbrand Reviewed-by: Mike Rapoport (IBM) --- 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 0204c469be43..12dc654b5be3 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 Thu Mar 30 16:07:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 77291 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1250385vqo; Thu, 30 Mar 2023 09:22:19 -0700 (PDT) X-Google-Smtp-Source: AKy350aXV5c0+tC+qM21eHJvqTSO3QyQP6KZf3NXUa1MU5Pswja368I4vcMhb61AnRWerFh6eHjQ X-Received: by 2002:a17:90b:3e8e:b0:23f:58a2:7d86 with SMTP id rj14-20020a17090b3e8e00b0023f58a27d86mr27066946pjb.10.1680193339400; Thu, 30 Mar 2023 09:22:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680193339; cv=none; d=google.com; s=arc-20160816; b=EttRSTgGaK5hUT08OD5BPPTkJ9GPFnC4wxUlgZKVlOKRX9zsS5VnrOdJ0kz9BYyxuW RlWtrjCr8YZOi5Y8Tzx4HzEiWP5ZhaHYqz83sbD++ZMAmZ5+MH25481YSGWwDVnAitYl 8FbKk99BxCy8GD8jRdqtNwmCK6Tk4x9te3kfnlHmonBU+S8arO9ZbbhRNRkzPHypBQTg KjzwXW5rq69RKvLmOh7+wNEUCWW8N7wYDM2GZcbAl/vHXGTL4nPC7rtMy6P4oynS0MM8 MSM5QLJQU6dVCxuDTy/FHTkCxrZMV14KSCVeyRbiRECp1tRimu41xm5rjJgGzgwQezCJ oNpw== 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=GWrLladF+2uMEiKA8QDU9N/tbvqlj2DcoX5RP21NYpg=; b=FFtLVHgsnOQGU0SB6QfspRMI8R9hsof65jSAyAzWXCG/5M78QqibE6hO03Zpj3bido XH6eO6BFIJzbWzErRHagb4/2NcelDo39MsZ7iP2QyAveCRtJQnJvaGfXnV8MZcvJKLs5 LIXp074xSvh+F8q+rDnHY5Hft0b0UWroOKz9FLFbPmS8N5Im5OtUr2ln4Om6utoxy7vl 0kij2rygbNdWONNwKjPhLTd2iH7ulEIXfXGZoPdbyevF5xhFArVNjzgFT/Swmp+V0Xdr wnjAomEKrlTZb7jKalDT3O5EgNJc+j29O8+s4tWYA9K8/FXGN9LVolZj0qv6ZdLA8+XO kNAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KU9tWyru; 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 b12-20020a170902d88c00b001a220a984f9si13970235plz.546.2023.03.30.09.22.04; Thu, 30 Mar 2023 09:22:19 -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=KU9tWyru; 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 S232395AbjC3QIP (ORCPT + 99 others); Thu, 30 Mar 2023 12:08:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231689AbjC3QIA (ORCPT ); Thu, 30 Mar 2023 12:08:00 -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 A3C58B771 for ; Thu, 30 Mar 2023 09:07:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192436; 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=GWrLladF+2uMEiKA8QDU9N/tbvqlj2DcoX5RP21NYpg=; b=KU9tWyruuQxgCvrZzW8Rr57s3CEV0YxqgFFzxEQikHVrmw1pqSGQiftCj8AbKLZngWOhJR 0aAL2sEYIZUVQaCNmeg3B3uKVlEVQ5OKItkKynXWgkzY7z+dPNk1v2MTYGLIVUhdb6bmOa 0vunZLC2B77r/AGFgAKevkqGYc2TSPg= 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-474-dVPK78B6NSKV8Bzc-BEd_w-1; Thu, 30 Mar 2023 12:07:15 -0400 X-MC-Unique: dVPK78B6NSKV8Bzc-BEd_w-1 Received: by mail-qk1-f199.google.com with SMTP id x80-20020a376353000000b0074681bc7f42so9100671qkb.8 for ; Thu, 30 Mar 2023 09:07:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192431; x=1682784431; 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=GWrLladF+2uMEiKA8QDU9N/tbvqlj2DcoX5RP21NYpg=; b=UjFc6yVY4LSxzJaLnC49ox9UUscRrEyZsTDiQvJL/klNyNPlp/Nr2T9ZKvYz6P4F5v KVNt84rwWPkCuH4BFP6DzWK++Pgq8tdh+0yehvpPyNsF8q3G8kaEo02J1ESvepgHuvrA x5xmgEm+FX7SmhqqDf+5FwHGAO5GmiaFmx3r+W5YrAKl3qmNmEm6EV2kVJ3eq01/ZKWx +e5cc1q/WRJjxlxKsKY1RcF6VO2QS4txoDoV6yq+pqQKj/s3r4wfrHVx4QB/03kFxb+j /q/XkeYXkIAf3Pc6uYgj7n9a000c+6YwnNkifjknWCV1Ol/gUoDbJEG055nVrKAE8AT8 7Q7w== X-Gm-Message-State: AO0yUKVXHRJCaEO3ySVfl2pVfFQQOdYib74LUCDPEGF57kCk8Yj6DVl0 KTkApxfhJGAuncc5mjgBcjUZeF+vywYXNOewCQHBbnoJtQANtT6MveAuW6Fa9O55e5CianYoXs3 jRwSYZW0AvD4pLmpBkC77jgYW X-Received: by 2002:a05:622a:1886:b0:3d1:16f4:ae58 with SMTP id v6-20020a05622a188600b003d116f4ae58mr37195469qtc.2.1680192431567; Thu, 30 Mar 2023 09:07:11 -0700 (PDT) X-Received: by 2002:a05:622a:1886:b0:3d1:16f4:ae58 with SMTP id v6-20020a05622a188600b003d116f4ae58mr37195424qtc.2.1680192431235; Thu, 30 Mar 2023 09:07:11 -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 12-20020a370b0c000000b0074680682acdsm14989583qkl.76.2023.03.30.09.07.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:07:10 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Andrew Morton , Andrea Arcangeli , peterx@redhat.com, Axel Rasmussen , Mike Kravetz , Leonardo Bras Soares Passos , Mike Rapoport , Nadav Amit Subject: [PATCH 08/29] selftests/mm: Use PM_* macros in vm_utils.h Date: Thu, 30 Mar 2023 12:07:08 -0400 Message-Id: <20230330160708.3106977-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230330155707.3106228-1-peterx@redhat.com> References: <20230330155707.3106228-1-peterx@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=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=unavailable 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?1761810410695951109?= X-GMAIL-MSGID: =?utf-8?q?1761810410695951109?= We've got the macros in uffd-stress.c, move it over and use it in vm_util.h. Signed-off-by: Peter Xu Reviewed-by: Mike Kravetz Reviewed-by: David Hildenbrand Reviewed-by: Mike Rapoport (IBM) --- 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 12dc654b5be3..8e9da621764a 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 Thu Mar 30 16:07:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 77289 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1249842vqo; Thu, 30 Mar 2023 09:21:43 -0700 (PDT) X-Google-Smtp-Source: AKy350abm/z6dG1CcC7YE1jEWQsSaSM1I2lQEK7U6rxaFfZ06Odz0pFqV1sTCmmKVgR6jUMWtxOi X-Received: by 2002:a17:90a:190f:b0:237:50b6:9838 with SMTP id 15-20020a17090a190f00b0023750b69838mr28314518pjg.45.1680193303081; Thu, 30 Mar 2023 09:21:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680193303; cv=none; d=google.com; s=arc-20160816; b=iQloERRP1J106BE+2cEV25pVPRVbEQ3HI05pPnHHiHGGyZ4PbYsZ8GTZlh1EoD4xUH P3oE9o2AITRSByY9sZBcmQENIIfozkBuM7CfxSjxZ7wKByhP8QrHlaxZqS5xR7xFEWcC Z5MkMu7IaMW9hjs2w2nRp1HqgT9s4RuAWtaqdxctrwSgi9m37qCQSY48CLMStlev7id9 g89SMJOEKdPCovpDt6HH0wZFjdCMeZXk6GoexbqVJwvTXNhwHkyDLAMkD4z2af3Gkz08 CUainGmLsavQ69xCuCJiCDQc3XvjtkNZ5ZH7k64dk1TVPjlmrmlhR6gy/K5ovARC3wQv DCJg== 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=E56MghZwBJmwObq6HpbLSvJ4ZkxH3HDhcAvyqpX+TEo=; b=TO+Z6oSBvCHq0o+ShU39+B1bfDcG/LrBjfvLHXUbDI8W8U0ui2WQVKugw0b7o0fam/ xL0ehnRpmRZFNzME9C1baWcXWaPiC8ocoq9UEcYqdFlVShzncPOGv+TR2bAxXrcbLukH +xxjhTpmfSYg8DL9Fw24rq1i3eqTjw/1GDNPFebDHCTGcy5/juoSe5eFHSqHg98agbdE 4yquwcahWXMhMIp7+6s5wvpXBbTgR5tB44Ak23gURUu0/WHpBAWkgc4vFE95xvgmcpDU 93ZpnKvo2+SXEV28t5mG/V64hQCf0eNCWTwc8iN6+DQ1GIR8SEna0Dzisb/kAYI0c2Pp rxzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=AF91dBak; 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 r21-20020a170902e3d500b001a1f6d61e0fsi14747930ple.134.2023.03.30.09.21.29; Thu, 30 Mar 2023 09:21:43 -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=AF91dBak; 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 S231272AbjC3QII (ORCPT + 99 others); Thu, 30 Mar 2023 12:08:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231625AbjC3QH4 (ORCPT ); Thu, 30 Mar 2023 12:07: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 02510A27B for ; Thu, 30 Mar 2023 09:07:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192436; 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=E56MghZwBJmwObq6HpbLSvJ4ZkxH3HDhcAvyqpX+TEo=; b=AF91dBakt6zza2SclKAYqOdBUynTFRYfJxLY53C8Xq/LnXEpnJTDBquEfSREl0K2WoeYJN xIi2krrkU+KlWIbE9RWdr2MiujoXt42RX6JrBRZo6oJavojhsOKB8XAY8ikV5+2WGgrv63 lNZBLuGFon6vIWriVoezjxEMqKyB1PY= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-290-1dMOqwSCMwKLlmZnQcXyPg-1; Thu, 30 Mar 2023 12:07:14 -0400 X-MC-Unique: 1dMOqwSCMwKLlmZnQcXyPg-1 Received: by mail-qv1-f72.google.com with SMTP id px9-20020a056214050900b005d510cdfc41so8511729qvb.7 for ; Thu, 30 Mar 2023 09:07:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192434; x=1682784434; 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=E56MghZwBJmwObq6HpbLSvJ4ZkxH3HDhcAvyqpX+TEo=; b=Y7kkQZV5Q5v0MzhjgxQ+hZ+/NcwFXo6RRqsHCkfMIcbVyAkdZoGCdSurKvRPeNFDOK K/toUIAzUFlCqNHwAWBYwfCITiD1OBmeq0aU3cvuVQrWO2o+M/GQIbgYTknZ1426EyI/ BHsw9751J+KaHDhrrqfzYpAHbAqwmKOMJezknfZWAGKCq395w8eRpCMx93JF7DykRcTS OIAklilFWGYFNohCxPqMx3CKze8GDt0YJqyST9/ifRu64LyivT18vG3IxYEar7Eg6q0T qwYZ/8HazpsL/X7kQGdxuxO9nA1CNbzcydUt9JsyXYynW4GMY3PfWlUnyUBcJTpMXfVO jekQ== X-Gm-Message-State: AO0yUKUAKpYEuhKuYfp4N4iyNa3mIUtlFDuYz2XrO+Ihl2YBxFxWvCTQ TQXvSP8LM/k3qZfV6MfuQPi7uUStDsWPrcW9twcvRngNUKmvn2QSszy2hUGf7zALODDp+b8mNq7 P4RQw+pBukVAB9Bdi21rT69TE X-Received: by 2002:a05:622a:1441:b0:3e3:c889:ecf9 with SMTP id v1-20020a05622a144100b003e3c889ecf9mr39965906qtx.1.1680192434233; Thu, 30 Mar 2023 09:07:14 -0700 (PDT) X-Received: by 2002:a05:622a:1441:b0:3e3:c889:ecf9 with SMTP id v1-20020a05622a144100b003e3c889ecf9mr39965871qtx.1.1680192433979; Thu, 30 Mar 2023 09:07:13 -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 p126-20020a374284000000b007486fc7a74csm3517380qka.135.2023.03.30.09.07.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:07:12 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Andrew Morton , Andrea Arcangeli , peterx@redhat.com, Axel Rasmussen , Mike Kravetz , Leonardo Bras Soares Passos , Mike Rapoport , Nadav Amit Subject: [PATCH 09/29] selftests/mm: Reuse pagemap_get_entry() in vm_util.h Date: Thu, 30 Mar 2023 12:07:11 -0400 Message-Id: <20230330160711.3106988-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230330155707.3106228-1-peterx@redhat.com> References: <20230330155707.3106228-1-peterx@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=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=unavailable 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?1761810373349016639?= X-GMAIL-MSGID: =?utf-8?q?1761810373349016639?= Meanwhile drop pagemap_read_vaddr(). Signed-off-by: Peter Xu Reviewed-by: Axel Rasmussen Reviewed-by: Mike Kravetz Reviewed-by: David Hildenbrand Reviewed-by: Mike Rapoport (IBM) --- 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 Thu Mar 30 16:07: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: 77292 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1250653vqo; Thu, 30 Mar 2023 09:22:41 -0700 (PDT) X-Google-Smtp-Source: AKy350Y+5WFI2KWhxOJa3FtywN5KUIvoCMRMhxup+SV4JPhqrtOtQ6CujymymzhsrsmfmH2cIZkF X-Received: by 2002:a17:90a:1a05:b0:23d:5485:b80e with SMTP id 5-20020a17090a1a0500b0023d5485b80emr26386480pjk.6.1680193360880; Thu, 30 Mar 2023 09:22:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680193360; cv=none; d=google.com; s=arc-20160816; b=jOFU66hgMJd9eqB0hBGAzDX4s1B64E5BMFvimkMsWKH8UbvtErVsvdufY8OzGPxNIq QmiFbgvIQNGfzqBBm6E5xForUdmZBtI0AUyp6aWkNzPiD7NJjgFprMLacUOgJ3on47Rg PP6YbvpOn5z0cnGvn95v5kaQDE2ktABdeLLC3QKYVnUO+56foIki4W6m4CCWA9LdXp0b WZxWpjzyII1RN6rEcTipLG9vsCBnAoO/+PwKlUXZ+rcRgKhbxpXki33vG6Kr1nT/OdI9 HfwpSRxuQ2mnEL7AnFdY72SJmV1pSD7qhsx07qHx0jX+VOzS+VMHVvr4f/Njs/4AB8hd SpKw== 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=RfhhWk3VzAXDagpY62p8nGCD/pabXAkikDD2DMuf9IIt44k0C6TytaGyh+WcaxHZOV k8Waz8bMvETspp0otGo2Ezf2AFMIuXHL3txoxE2B8qqqKf79CTGuUYRH/dlNRkXbZ8LK KaJIgtRxRMVvtD3mWCYegZsy2lD0cuJLhltBQJ1ysRp1r/Un6Uvd1+PdpU79OhjB/7oT ZshtwnewvlcR4X2wY97bnBCiFEXzPH+vn6ZagDdBcfiZZZMxwTcq1+S4NiUzrQvQ/xTE jCi/egx8OCSlulzkhZ5xbYAUv7FqYnb0WzjW0vqw1hTPpAtqHm63mGjZPuFeyp+D9mSj Mw0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PGXCY5M6; 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 x11-20020a17090aca0b00b00233c5363cdcsi1586911pjt.142.2023.03.30.09.22.24; Thu, 30 Mar 2023 09:22:40 -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=PGXCY5M6; 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 S232885AbjC3QIT (ORCPT + 99 others); Thu, 30 Mar 2023 12:08:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231566AbjC3QIE (ORCPT ); Thu, 30 Mar 2023 12:08:04 -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 4BE9B9EE0 for ; Thu, 30 Mar 2023 09:07:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192439; 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=PGXCY5M6uUnCD/BeXnzDKcl0fDTXAAjNvz52OAHFA4JAQBOYz2lwPuz0jLLzGovVCwHUsB MQcphRsgYLkY7vASdD6xpV4wnrT69B1ACQ8rvfQfU8iTzW4zrQ6EK1iVlHm7CmkBCkuh2j +mEx+xs0JF1mSucFjSBE5K09ZQEG7rM= 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-259-wGpkg7j2OGm4_IpG_jxung-1; Thu, 30 Mar 2023 12:07:18 -0400 X-MC-Unique: wGpkg7j2OGm4_IpG_jxung-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-746bae78af3so60157885a.1 for ; Thu, 30 Mar 2023 09:07:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192437; 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=gE7BtTKQsYzebb4aHofOTIkNAODIp1rEKlkU9bWqFL71eErsxiz9euOrdsUYQZnLJk 5LEPZXtSJWRReyeuwc2l/tb9gJ88R7xJrgspCDP9jn4VE9gF03gYXVJJZCJ+AHu1lWBa c6awuLq7QreM0X+KSZziG0fzewgb2mP+OV54y8GiTx4X6H98h4e948Pd4D6D1kFCwlyf xyb+vTBH4c5ngzcADwLbguK/Asiy0Kck5Xaci3i8xZa/eGmBnBdJxKxYUdsBpzXH43f8 lOgDdMpZB+zzmYzKuRe9YRysTcdmT2GJICFvIcOFo9f9kryGFaUA45Hz7xeaJD/7lyXx l9gA== X-Gm-Message-State: AAQBX9d+dfRbaFXc7NQVsbW/3Xz/CiOd4CjHrelp1yTR2UctiRsU+EEp 7TqA4AmqbAaNH0DGBYXalGflDij6uRjqGzJyC1XqiIEoAJbZlxWOutI5LaVxN7nq4442VBG213t 8dOtA+a+WPFZpZOlg2+57odZ2Z0m9VXMh X-Received: by 2002:a05:622a:1802:b0:3e2:4280:bc58 with SMTP id t2-20020a05622a180200b003e24280bc58mr4246277qtc.3.1680192437027; Thu, 30 Mar 2023 09:07:17 -0700 (PDT) X-Received: by 2002:a05:622a:1802:b0:3e2:4280:bc58 with SMTP id t2-20020a05622a180200b003e24280bc58mr4246240qtc.3.1680192436773; Thu, 30 Mar 2023 09:07:16 -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 s80-20020a37a953000000b00741a984943fsm11749352qke.40.2023.03.30.09.07.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:07:15 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Andrew Morton , Andrea Arcangeli , peterx@redhat.com, Axel Rasmussen , Mike Kravetz , Leonardo Bras Soares Passos , Mike Rapoport , Nadav Amit Subject: [PATCH 10/29] selftests/mm: Test UFFDIO_ZEROPAGE only when !hugetlb Date: Thu, 30 Mar 2023 12:07:14 -0400 Message-Id: <20230330160714.3106999-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230330155707.3106228-1-peterx@redhat.com> References: <20230330155707.3106228-1-peterx@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=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=unavailable 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?1761810433412766043?= X-GMAIL-MSGID: =?utf-8?q?1761810433412766043?= 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 --- 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 Thu Mar 30 16:07: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: 77297 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1251157vqo; Thu, 30 Mar 2023 09:23:18 -0700 (PDT) X-Google-Smtp-Source: AKy350bqWO4Lm9oU2vVxOYAcvuAK5WiGsQK3CXa64xGpakkJJmxnuitQ56buPYzfZtW7bdxGGage X-Received: by 2002:a17:907:a424:b0:93e:6f40:d141 with SMTP id sg36-20020a170907a42400b0093e6f40d141mr28342366ejc.40.1680193398189; Thu, 30 Mar 2023 09:23:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680193398; cv=none; d=google.com; s=arc-20160816; b=SefnNgmcUzChbwMtl2acoT8shxDeuy3k8QmWp2Rm3CSYG7Z9rqWZQiU99cgrhkzJZI W1nqaelC9wU0OCJ/TNmksn+c9LcQcUqmyXKtFpCPnkrwPv4vHl/w8exoYfJvezUIdUVu c+U2QURTwCl+kCsYjv/RHQCJTqO5s0DrCTpitwSCxKFi/MeQFkkRDNnIFurDl/s5qyPT C7iCSYW7KwhfbLrlMu/VB1bXdp2D4/k3zC1ihmTeAcZrNbshiBXFAr6zVnxM/CzXrzys uUVg2bb6DTK7E91qS/0j3STQA9pimfOLIQhmgFaFyDCfhao3ySZQ5OxGIc2NMDH7OGfc 6wnw== 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=yBXFNiQEy11weTKM7tK5TrNqKeG1r9RMGXvyXsqJW94=; b=ULIOsuNbEEnHOlXfKUTQ9uaokIyMRXZ1RX3dERhkLrIJEHG1ZcYJ2puQ70OHc0cLYu 5RxgpfQEb2yqF3NLQ11l/pJv/k4VOfeop93/SFZrkO6NWzSKgBVMO7wXwN4YEB4KUb39 hQcM7lB32q+k6kTa8C0uNm5B9wxrZt92xgM6povja5f8lgEMWzZhgvWkKse3hcX6Cc9V 595HmY3HaHbyKmdqGJ9RaGSoZleLqqNEzog7qBNV1hBafycjtNJQok1pCLwhltRZkF1x LoqLzPh3AoK0bsMJjhRooyaQPm4covwPuYK8Hk6M73PnkODm+5030urD5oMVYVMA6Ni0 C7ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=INhxXP8f; 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 vi14-20020a170907d40e00b00931d797789fsi27145658ejc.1003.2023.03.30.09.22.43; Thu, 30 Mar 2023 09:23: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=INhxXP8f; 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 S231674AbjC3QI2 (ORCPT + 99 others); Thu, 30 Mar 2023 12:08:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231838AbjC3QIM (ORCPT ); Thu, 30 Mar 2023 12:08:12 -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 393EC9ED8 for ; Thu, 30 Mar 2023 09:07:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192442; 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=yBXFNiQEy11weTKM7tK5TrNqKeG1r9RMGXvyXsqJW94=; b=INhxXP8f1TI5QgUgYh3taKeCZ8lt9qMjh4IpIoS2NOl9HmYdWQDLQvW9Zhk5Nl2n7+Yumm SdTQdwIMVlis94768jrnMBoL/qKFQ02S6C1R/n3uMTeyUEMMy4WhImoydp5gvS2SxGMxFp f8cmLBPlxdy4UJAHAJMrN1j5I7E/Wo0= 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-416-pSR0SseUNXe9yN5GoxU-OA-1; Thu, 30 Mar 2023 12:07:21 -0400 X-MC-Unique: pSR0SseUNXe9yN5GoxU-OA-1 Received: by mail-qv1-f69.google.com with SMTP id px9-20020a056214050900b005d510cdfc41so8511894qvb.7 for ; Thu, 30 Mar 2023 09:07:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192440; x=1682784440; 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=yBXFNiQEy11weTKM7tK5TrNqKeG1r9RMGXvyXsqJW94=; b=dlgrDU3ONLEs2hX1fenrWC7NYDx128PHXPiiCoezY+Yxywbi9bP+DsYr645wbGyhYm OS32yagqbB79osLPy8TJJ2QG5U2nm0t2+wy0lvg8lubsN7latLln9Ra+rjVTT1qOglEX BTVpchr9Wf+akJLEEfx22QgsZWWyXIR5j9j5I7EJV+DtzuzKq9aHb/koxVPXd0kMyXpd oj/IuUjFbABILUTQM3l+XFIy+y6Mw1TUZjXghULcfx4tJvJ+mSw/OEgCZui0m9X3B7Fi fch+Ov1dAAXWKcCyrE2REpc8YcveRpu4zmaPesUm++VnuUDHXuioW0QQPxTsfukH9Xn8 tzJQ== X-Gm-Message-State: AAQBX9fhEZvvK4rcQi9nWU1TyjfSyHDTXDW4rQSJbLxYdebYLRtSOK09 V6SXkrRVuReZdvyHQ4S5EiY3naJqAsJMXmTtqKuev//xcMf+N+M8ffnnHsaK7JybEGUuxBoyYQV cEJY6+a70OmgsZnjgE8VIK9T2 X-Received: by 2002:a05:6214:f67:b0:5e0:3825:9adb with SMTP id iy7-20020a0562140f6700b005e038259adbmr3997365qvb.2.1680192440538; Thu, 30 Mar 2023 09:07:20 -0700 (PDT) X-Received: by 2002:a05:6214:f67:b0:5e0:3825:9adb with SMTP id iy7-20020a0562140f6700b005e038259adbmr3997336qvb.2.1680192440324; Thu, 30 Mar 2023 09:07: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 pr23-20020a056214141700b005dd8b934579sm5514594qvb.17.2023.03.30.09.07.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:07:19 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Andrew Morton , Andrea Arcangeli , peterx@redhat.com, Axel Rasmussen , Mike Kravetz , Leonardo Bras Soares Passos , Mike Rapoport , Nadav Amit Subject: [PATCH 11/29] selftests/mm: Drop test_uffdio_zeropage_eexist Date: Thu, 30 Mar 2023 12:07:17 -0400 Message-Id: <20230330160717.3107010-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230330155707.3106228-1-peterx@redhat.com> References: <20230330155707.3106228-1-peterx@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=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=unavailable 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?1761810472344115245?= X-GMAIL-MSGID: =?utf-8?q?1761810472344115245?= 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. Signed-off-by: Peter Xu Reviewed-by: Mike Kravetz Reviewed-by: David Hildenbrand Reviewed-by: Mike Rapoport (IBM) --- 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 Thu Mar 30 16:07: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: 77293 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1250827vqo; Thu, 30 Mar 2023 09:22:54 -0700 (PDT) X-Google-Smtp-Source: AK7set+Zw5EFqoDdRdgXkAv7qIhy8AoEe/9zdQmyFwQ7N/LsVeiAOZZ6EB3QliLyAKOaXGQOcQnY X-Received: by 2002:a05:6a20:80c8:b0:db:6026:4393 with SMTP id d8-20020a056a2080c800b000db60264393mr20552787pza.59.1680193374200; Thu, 30 Mar 2023 09:22:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680193374; cv=none; d=google.com; s=arc-20160816; b=IxiwfSH8s9EISO/MP1wyJPPLuK8R3iEfsC6te9V9Q9a6HEo6846b2DpvXGSvG2XC// PYLCnBt4t1+LAwg6Fo8pgmRpISkyTRZy9xDNGc2mXMZ2A82ICj0uw8PgMYFtQRwejoMV o/q+JEKUJvPRjDsqvSpuOiZDMZyHdpTib4ahjrAos5s++M5AebKav123xGlzAlUDk8ac WMBju+wL8IZV76HfAowWdSwEJKW4B/mwU9QVn5Tln+VspWwz3ogrDs3lVUlWm+4EEN5e QHTWWoPBu1l+pvszUAxR0hb/iFJkHeqzlVe7aUBH743m2alJSy/c5SPM3IY9aU9vbj1+ F+iA== 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=db6YoFSypJnTIouTrDztz4PPOGN8H3NbJ+XG7IwkLI4=; b=BB9/NMAXFjLi+05pI10TFHvGmavUz3TYWVtc/HTZdKUMEGI0i/nnRjCmPmZ+BmG+3O iG2OLYzWBgaDrle4c/LII7L/hIXtiRC3CRHlRsfM88Fdp+PRPxld62ab0Ysfs3jw/jZX +f4+m++aFOtVt4gdA0MEcsedi221SuUqW87ThyG45n25n3eGNB1lYUhhW9qPWUObogQJ AtxRj90PU23uPrEKu298BbT0lmCU7qGXoTsP0qUvgaJdyssEiefp1o93IsGQeG9OqRpp a+1/k6+2tY1HkSgqi2rfL9eff1pCOF1JcZajgmp0b+D4w1/H/B7o8QuEaMaibjHM1XRn BFeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PgqipptT; 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 129-20020a620587000000b00627f0f8d49fsi54723pff.373.2023.03.30.09.22.35; Thu, 30 Mar 2023 09:22: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=PgqipptT; 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 S232076AbjC3QIa (ORCPT + 99 others); Thu, 30 Mar 2023 12:08:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232191AbjC3QIO (ORCPT ); Thu, 30 Mar 2023 12:08:14 -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 EE908A246 for ; Thu, 30 Mar 2023 09:07:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192446; 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=db6YoFSypJnTIouTrDztz4PPOGN8H3NbJ+XG7IwkLI4=; b=PgqipptT0NZnLIk3hlnRW5c9tVkEdvA2T6UIN2Pd9XEq2SHyYnQdM13vajQZdh0hM0qpkB kPtRlsYkVdqew1pN+tMHZRBYVRaXykCRwN0xF8bkP6TmLcLC9KOeVSUWijsgT5xezuG7cK qJVo9Fl/fG4YwgbC5Otgx4u4f7UdjV4= 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-586-ckhZSk5OMpqK3CXIwQ1u4g-1; Thu, 30 Mar 2023 12:07:24 -0400 X-MC-Unique: ckhZSk5OMpqK3CXIwQ1u4g-1 Received: by mail-qt1-f197.google.com with SMTP id u22-20020a05622a011600b003dfd61e8594so12717107qtw.15 for ; Thu, 30 Mar 2023 09:07:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192444; x=1682784444; 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=db6YoFSypJnTIouTrDztz4PPOGN8H3NbJ+XG7IwkLI4=; b=zt8Y/qvTFuDnir1hHAmk2yR+Ctu5+V3DnhapczasvL2NxAdx/9mekUtZID6U15Vncv mqXISRNjjpC6DAtAq7qgBiG5h8dleK4cl32lYaiBHvf8BO/bc/Zy3ZmZWqriGZKINK/e 5gvyeKx26260wEmg8k+JIMeY761sN3eLIGkrdPyZjNEBeJJqgVoM7r711KgWqDxl+G/q pQT7IwJWZWIpSXPIf5BYfzi8bcI/mE47sGbcxwxVwaqhL0NEL/lf8TNyZC+amHOYQrNM sWFPrJTcOQCdRF2h+VUjAm6bOGomDWGd89SmHuGtP7NGnwvtWwQb66OtSOdkuObL0jz6 t59g== X-Gm-Message-State: AO0yUKVeA31w2nbBod5qh3dhPh0W2qqiy8GLy6lZBo55W3ZTjMo97Po1 LxFJyG8/sek6L/YjPjJKa+9iB70ryeTc2iJB/f6vpWCry0mpyiJC83HHaF1BRdT/eysHsQ2Ad8o YWc125cYsfqQMO7aa35ibmWlv X-Received: by 2002:a05:622a:1441:b0:3e3:c889:ecf9 with SMTP id v1-20020a05622a144100b003e3c889ecf9mr39966948qtx.1.1680192443357; Thu, 30 Mar 2023 09:07:23 -0700 (PDT) X-Received: by 2002:a05:622a:1441:b0:3e3:c889:ecf9 with SMTP id v1-20020a05622a144100b003e3c889ecf9mr39966866qtx.1.1680192442731; Thu, 30 Mar 2023 09:07:22 -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 o10-20020a05620a0d4a00b0074281812276sm13066719qkl.97.2023.03.30.09.07.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:07:22 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Andrew Morton , Andrea Arcangeli , peterx@redhat.com, Axel Rasmussen , Mike Kravetz , Leonardo Bras Soares Passos , Mike Rapoport , Nadav Amit Subject: [PATCH 12/29] selftests/mm: Create uffd-common.[ch] Date: Thu, 30 Mar 2023 12:07:20 -0400 Message-Id: <20230330160720.3107021-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230330155707.3106228-1-peterx@redhat.com> References: <20230330155707.3106228-1-peterx@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=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=unavailable 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?1761810447020915928?= X-GMAIL-MSGID: =?utf-8?q?1761810447020915928?= 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. Signed-off-by: Peter Xu Reviewed-by: Mike Rapoport (IBM) --- 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 b35f3eafde3c..9c3737285f8a 100644 --- a/tools/testing/selftests/mm/Makefile +++ b/tools/testing/selftests/mm/Makefile @@ -107,6 +107,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 Thu Mar 30 16:07: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: 77294 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1251031vqo; Thu, 30 Mar 2023 09:23:09 -0700 (PDT) X-Google-Smtp-Source: AKy350b2EJa8vlrWstaUN5MdsPmRb1Z0EQmRveBiI3m9bHnD3lwAgjBMKtI71aLvpAVXCT627/vi X-Received: by 2002:a17:90a:31c:b0:23f:870c:83a6 with SMTP id 28-20020a17090a031c00b0023f870c83a6mr27954671pje.0.1680193388963; Thu, 30 Mar 2023 09:23:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680193388; cv=none; d=google.com; s=arc-20160816; b=oKIdNIAc6GI9aaH3/FEKXWkykz6kZvvbB8fME4lNX7slvmrKnPx9Db+EQMBPB6z36+ gSb1MpP53wPZplTxAF8hselpuQifdPKuB86x+FN8S9UT7puIl3UofL0vauFDTGlOKlMO Su3i7gNedEKVFQ3EQfTNp/6yT7vP/EQskkoN3a7dqey0y476QKvYjY9s0Nya2zrXx1dZ Qd9z8rYtbzkEK4spW9fwhESoPYXm/647RrSm1Kh76lpoBks5UPpajoowUpcONbBXscmN hVIwNxA2RZXbUJxrwMjy4wfQQSTJJsjSgyWX/8w5X96x+Bw6sp7CVHbVeH/aOBI1uK+d B6CA== 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=9IAbBMcnsKQ/wMG+wiEQBSaGDUBrmUfxUQY9hBhFLu8=; b=wh9x8HI+Xw+IKqWayob6Lg9zVjxWXv6Hkt61MBptSyCtpAoaodaXviBaZE08K2fi6Q UWWNo5bMq5PSVFYODwUzAT6WAdmcTRmEDg0c9B3IyJg/3krWYkOknbvpA8BPoBco2NxM z106dC80r2fPpnXWY7Jllk2Zq+KO/+1MOAb4NBwspk6mI81oYARzY5AJm87IugvxDniq 56P50dnXpdhCdtRrVyfTJDdL+fJLoTolEP3MyQhd5Sks/53PfBEu4pPGBEpNSjwlOPyN mWVrYT7s6pBkCFUvKqwWy0M8AsLIHSLtiZdpSo/4rJ75iidyqR4jEhqLZYqLZ0I6GhRx kYTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FLI1kdsg; 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 km16-20020a17090327d000b001a04bde6843si14111378plb.259.2023.03.30.09.22.43; Thu, 30 Mar 2023 09:23:08 -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=FLI1kdsg; 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 S233542AbjC3QIh (ORCPT + 99 others); Thu, 30 Mar 2023 12:08:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232815AbjC3QIT (ORCPT ); Thu, 30 Mar 2023 12:08:19 -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 B4E6CA24B for ; Thu, 30 Mar 2023 09:07:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192451; 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=9IAbBMcnsKQ/wMG+wiEQBSaGDUBrmUfxUQY9hBhFLu8=; b=FLI1kdsg3y6jiXseASDT8PAS0qVMJHuc3QUeY5OMsxb8saCtBezQAP4G6rOVmPkGH10+xV qreKVOc56SAgh02iLsThs7XxJhb34UsNVeKlwdvAgtPyS6J8PWbg2nDvobQjx0AJslsL4n 1csVagEGC8KF5SzyQQWk1Yp7u87O/8w= 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-413-UzN6F66WNPuB8VWtdmINqw-1; Thu, 30 Mar 2023 12:07:30 -0400 X-MC-Unique: UzN6F66WNPuB8VWtdmINqw-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-74678af9349so60314585a.0 for ; Thu, 30 Mar 2023 09:07:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192447; 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=9IAbBMcnsKQ/wMG+wiEQBSaGDUBrmUfxUQY9hBhFLu8=; b=zZ1ZLw4FGVUa0pGzFy+Fx+FObgcQG/tvVbfsGCMYSZDV8P6yeWB4GkyLguRNtfssYv bOG6r74ZWmLP62Y4AEZRK+tt8M6ntbypTknRK1FR65NkeIxZ0VYOdlMUK99/SdVcWNHQ d3kdZL4HN4FRqzQxphSp74eMqRlLNdXWuMy5WD8ztVqcKOpSxEoZUsxxYrPwvDsaBV0C 8ista8va3hoKWK+MtKqDcGZpkITB9XVNtWaN74lg/Bppb7m/D7jrqRfhITN+vUjvFow8 Q33kHOQbwgrAzk1zp0xJ4mRd+eADeFlNJC+MOGd50lm/Cd9bGbiwQcl6zFlo3kTlEsqp HLAw== X-Gm-Message-State: AAQBX9fLyaW9vvraTLeW13HymwSXbrMnCpcMl0ziETLr6spG6dY/gV5f HBaCttke5CNN0hNiZmkoPkK8kvPI9TJ6hWvii0lQuSFmPDIJt/jkngpezV5FCqKmsdGNWik6EnS LUsjXtCPYan1uExm1dJJVOpjF X-Received: by 2002:a05:622a:1885:b0:3bf:cf77:a861 with SMTP id v5-20020a05622a188500b003bfcf77a861mr4161754qtc.4.1680192446657; Thu, 30 Mar 2023 09:07:26 -0700 (PDT) X-Received: by 2002:a05:622a:1885:b0:3bf:cf77:a861 with SMTP id v5-20020a05622a188500b003bfcf77a861mr4161702qtc.4.1680192446285; Thu, 30 Mar 2023 09:07: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 p126-20020a374284000000b007486fc7a74csm3517511qka.135.2023.03.30.09.07.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:07:24 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Andrew Morton , Andrea Arcangeli , peterx@redhat.com, Axel Rasmussen , Mike Kravetz , Leonardo Bras Soares Passos , Mike Rapoport , Nadav Amit Subject: [PATCH 13/29] selftests/mm: Split uffd tests into uffd-stress and uffd-unit-tests Date: Thu, 30 Mar 2023 12:07:23 -0400 Message-Id: <20230330160723.3107032-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230330155707.3106228-1-peterx@redhat.com> References: <20230330155707.3106228-1-peterx@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=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=unavailable 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?1761810462772297071?= X-GMAIL-MSGID: =?utf-8?q?1761810462772297071?= 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. Signed-off-by: Peter Xu Reviewed-by: Mike Rapoport (IBM) --- 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 9c3737285f8a..ca8bc4ac71e6 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 @@ -56,7 +56,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 @@ -107,7 +108,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 9cc33984aa9f..af7bbc74cd83 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 Thu Mar 30 16:07: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: 77298 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1251282vqo; Thu, 30 Mar 2023 09:23:27 -0700 (PDT) X-Google-Smtp-Source: AKy350aMENBg0KpVdi/hvsblywo+juWYmUJzunlFi8SLWrix3L1syMRDZq1Z875cqFxFc2Zt6T7V X-Received: by 2002:aa7:df85:0:b0:502:709e:fc41 with SMTP id b5-20020aa7df85000000b00502709efc41mr2230638edy.33.1680193407125; Thu, 30 Mar 2023 09:23:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680193407; cv=none; d=google.com; s=arc-20160816; b=Gs+88X4UT1W/OWiP8VH700/ilGhN/LexDZXD7y0Oai9uK5gF/nUYe7kANOVAzRelWj 0/DNGE9D0FMmhyyDK2aM46PCJxhPqYYGv4xN7y4vCOJnOGaLdDt/YxLDQXZIHnS2jGYO 0dYx7G416CNBrPUIxE7IxWsJbHKd7It8kXRWDc+dOkqjtgHUWuVRlHx2aRYKTFRl6iD+ m7EWWbzpzSK8YSbWkc2QGdEuI+a/ch5ozxCQszc4lrNNDgNZZ/jBHXnS5oewbHKIACSW n2l7E4i37JIXjuzCRGeHugAp73nSCqkjVVzjhVA5kH5t+K8FLQ/+Rry6IxhC5KSK3knW lfMg== 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=t0fDgNcYvYYWETXPJiek9vgfY3+GH1MCmZd5+QiqXiU=; b=l2OIhsKrwzWqk3tImepxPBQiDSyEKHP1r0oroNuAqLlH4OBC1EvlndUZrg/FhaGc0O f29XlV+8rbLhsXvRcZLeQNsLsRl2rna+XEbwEXaW0VJv87ABPrkX1bpNab+2vtpE3yW1 0GlNwQCvfyG199UlfkdqVJ2qxl4zMq90Eg2PQDywdskEqx3GYScGuwabUfslr5aLhL6b 7GpT5cI8s32OkGJit4oKQbvKPI1MjCOga17ejF3X2+iD83N63Z5Nxx69x5MMZXVq5ucS G2G1k8jbLRRx4AgMeEaVTD1tUli/6QFoUCLotEKAYmhHHh1hQLweha7OZ0IdETJ60U/N xhrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JFsIikuc; 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 d16-20020a170906175000b008e41fc88f2bsi35217673eje.981.2023.03.30.09.22.55; Thu, 30 Mar 2023 09:23:27 -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=JFsIikuc; 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 S231311AbjC3QJS (ORCPT + 99 others); Thu, 30 Mar 2023 12:09:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232936AbjC3QJA (ORCPT ); Thu, 30 Mar 2023 12:09:00 -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 DD626C168 for ; Thu, 30 Mar 2023 09:08:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192479; 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=t0fDgNcYvYYWETXPJiek9vgfY3+GH1MCmZd5+QiqXiU=; b=JFsIikucHw5aY9SQsQhcqJMfZsDhcGLh+PezXbMAfZca9mSfT62Uy/h0w5MVUvBhPJvcWB qvcRNgLsL2lfjziy2A7PyZPmvLsLEUzRWyUSuxC0t4/5m93LTL6LHZ8NKcpIbF89uy78w5 eer21HYMz0V7oDBJu55TnFfsrzjuWOs= 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-471-2N_e10GjPKKN_bB-T61t0A-1; Thu, 30 Mar 2023 12:07:51 -0400 X-MC-Unique: 2N_e10GjPKKN_bB-T61t0A-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-746bae78af3so60170485a.1 for ; Thu, 30 Mar 2023 09:07:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192470; 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=t0fDgNcYvYYWETXPJiek9vgfY3+GH1MCmZd5+QiqXiU=; b=tM+FB4G6wSI56/2Rg9wiCSqIIQjLUhesTLycnJ9IYS15zqx3NDU2IBiTN++JOARWrw z3ExX7hbTR/Fenk3tcD0Dm9X5WFBD+DmQOBHGhyzEu3f8vbQayv2jm2r79ZpZuK5TYgF 43PYnF0FUBzojH3XGp9xQajd9vFCuXHizYdApYBhIh5xZlpbeHJScH7jU2SZg933AH7t f6oSeab8NsqL4CG9p/BaU7yo/Tx9z5ODUxa7w4dQ80DHzZ/GLiOhHvRu7OX3dx79g3Pz s5nDRCaTJUWXTMgR1QxYZZpE0aMcSYTT4UGoCfeZlJSmHb3xq2Sq5hA/05R0I8B+D1j2 cXAQ== X-Gm-Message-State: AAQBX9dfOO5zszT8seAk0Wgv9c7btrqAXfgUCN88ezDPgnZ4iYRdVemK +7wLUV8TLGKzc+z2C4+oUfSh6eWU0yRAwhaBGIVrX/egLRhikxMiHEq/6Ej9X4+2sr++161gtr8 ky8+7VHx1ijqzlEapk/Qnxao5ILjJyqoZ X-Received: by 2002:a05:622a:1aa1:b0:3e3:8e1a:c30b with SMTP id s33-20020a05622a1aa100b003e38e1ac30bmr4579792qtc.1.1680192469864; Thu, 30 Mar 2023 09:07:49 -0700 (PDT) X-Received: by 2002:a05:622a:1aa1:b0:3e3:8e1a:c30b with SMTP id s33-20020a05622a1aa100b003e38e1ac30bmr4579758qtc.1.1680192469579; Thu, 30 Mar 2023 09:07:49 -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 d185-20020a37b4c2000000b007425ef4cbc2sm19546682qkf.100.2023.03.30.09.07.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:07:48 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Andrea Arcangeli , peterx@redhat.com, David Hildenbrand , Andrew Morton , Nadav Amit , Mike Kravetz , Axel Rasmussen , Leonardo Bras Soares Passos , Mike Rapoport Subject: [PATCH 14/29] selftests/mm: uffd_[un]register() Date: Thu, 30 Mar 2023 12:07:47 -0400 Message-Id: <20230330160747.3107258-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230330155707.3106228-1-peterx@redhat.com> References: <20230330155707.3106228-1-peterx@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=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=unavailable 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?1761810482235525850?= X-GMAIL-MSGID: =?utf-8?q?1761810482235525850?= 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 --- tools/testing/selftests/mm/hugepage-mremap.c | 7 +- .../selftests/mm/ksm_functional_tests.c | 6 +- tools/testing/selftests/mm/uffd-common.c | 28 +------ 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 | 7 ++ 7 files changed, 66 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..17f2bb82c3db 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; @@ -609,3 +582,4 @@ 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 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 8e9da621764a..10e76400ed70 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..a67db8432855 100644 --- a/tools/testing/selftests/mm/vm_util.h +++ b/tools/testing/selftests/mm/vm_util.h @@ -45,6 +45,13 @@ 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_open_dev(unsigned int flags); +int uffd_open_sys(unsigned int flags); +int uffd_open(unsigned int flags); +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 Thu Mar 30 16:07:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 77295 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1251060vqo; Thu, 30 Mar 2023 09:23:11 -0700 (PDT) X-Google-Smtp-Source: AKy350YT2EBQg4yXlzvnav34ISW4rIvU/1UExv8VvCaV9oTBUP+RZeJGmKFL8xEcgH5ZMmkNdEwl X-Received: by 2002:a17:903:2803:b0:19c:d309:4612 with SMTP id kp3-20020a170903280300b0019cd3094612mr20025278plb.6.1680193390845; Thu, 30 Mar 2023 09:23:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680193390; cv=none; d=google.com; s=arc-20160816; b=JvGwSCxeHml5ckzeXWE7jb183NxDvr6iSfTa+baMGI9tN+jpgjg/NlOSu094PEjVIk kGSPWBLFhy3CkkcX+DipA3207+G0GbetkptoBzTQ9p6swDR6tOxmvt6u4tvmDO6sDNo/ VhSaW/QCnVcqY4YKbyOvSz93RNgif5LtjeQp7JExdIXzc5lnQ3/tn/JhAbjDnWLb8nLM FbDJammGd5awK9djqOqMzrrNPGMWDEpQDMvxuhBaxZPITA+tyUEEhyO8vy91TCk/9UT6 pVqU5iwfuwavpGBVF3BIizWhiZZvbZn+nIYwnyhb9G7iDNIBN/kL77ST+4aGdbC5ulxC uQ8A== 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=y+QAWrtqijcBRWNbbJvqOTcdIrT0hJlkJlw2bNALieY=; b=jpf05eBlzJSRvcgERDLn559SDxh4xObNty7rgIl+uQENgYFMa7pIzLdM2aa2ctkgB0 rI8qWLWW7PJMG3O/Tf2VUp7H12CE7/gP35TddBZOs/VKVqKs3P9f6Sq9fuolV1DeyV0a Mg1qG8WgwfF58XIKOd2h5i10+4v5t/77v9yJNq0ca+LNEif/8g62tezx2CMS4zqOxBML +VxhpP4kb7Yapa4GOjQus+mo0MFyG6oObQv3NOGN/CBsBxr/dr8HTfjA/HAJs9klNOZu kz+vwu8rIVto/THtrcG+tltU5X5jDKZ4CWgkepCKf/8TzvSwVWAfYX4+gWKgISHOZ1Ec WAtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Bfxtvo9G; 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 h6-20020a170902748600b001a05652e369si34067763pll.100.2023.03.30.09.22.45; Thu, 30 Mar 2023 09:23: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=Bfxtvo9G; 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 S232116AbjC3QJI (ORCPT + 99 others); Thu, 30 Mar 2023 12:09:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231817AbjC3QIv (ORCPT ); Thu, 30 Mar 2023 12:08:51 -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 3E271103 for ; Thu, 30 Mar 2023 09:07:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192474; 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=y+QAWrtqijcBRWNbbJvqOTcdIrT0hJlkJlw2bNALieY=; b=Bfxtvo9G7DNj0J9UaJtiIFZZcAH73nFi/dq8zBbbEF/Zq62zMwUQyGCWleOkqnVVVYuBhZ zXTFE3bkXUyQVPOxGPYBnnX6esRICIctnJ+k7b8u/003zQrmWrdi0UKHseytECP6V0+iQ+ +OU9ZYIqCS0s2aOsmaMthIqYkt4qEMA= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-630-n1gvLEObMauLq5kOesBvdQ-1; Thu, 30 Mar 2023 12:07:52 -0400 X-MC-Unique: n1gvLEObMauLq5kOesBvdQ-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-57c67ea348eso12977306d6.1 for ; Thu, 30 Mar 2023 09:07:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192472; 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=y+QAWrtqijcBRWNbbJvqOTcdIrT0hJlkJlw2bNALieY=; b=qo8O1vG7jeg16oKcA+JEhqu4NfaCe2rPnVODr6/nS8THSesAL0RmRGQf5yPjAPgrbO 613gTj1ZY6c9KVaqfYxJ4Yu0nwtR+5LAnveWUmBYFwaOEvAhQ2W1wdYBT5kp72r61C8U MWATbE7CNWXtvySBXOaaeoMP6DBQcX5xyoBdfjLe7R+e+HsypzEyUPOY7X3g9ljYek1q a+JhW4iJLC+N8U5ly+PK9txtMzQuB+wyNNk6z0bAITgKPyV6VdY/w4/v7T83uV+en85j VOa4EvIWu8pVllHYKi2BY/xm6+2LyUilIKUxX7zgpbefJnAh9IX1ht/pcpgZTQyTJ8X9 fipg== X-Gm-Message-State: AAQBX9c0teNojQweSWOax1z5YsiAfmSBkZOc0YxQJzRncMoMJLcOb629 plYKKOs2G/m+hkF4JKfV7e4+B924wIuFYsJ//dtPUZbrmGQIm+FyBDt9Uh2hXuei67N/7wkOLik SoiF4iGV7FqJG3dP1/KlkOwbo X-Received: by 2002:a05:6214:5089:b0:57d:747b:1f7 with SMTP id kk9-20020a056214508900b0057d747b01f7mr3712118qvb.1.1680192472107; Thu, 30 Mar 2023 09:07:52 -0700 (PDT) X-Received: by 2002:a05:6214:5089:b0:57d:747b:1f7 with SMTP id kk9-20020a056214508900b0057d747b01f7mr3712094qvb.1.1680192471894; Thu, 30 Mar 2023 09:07:51 -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 ev11-20020a0562140a8b00b005dd8b9345bcsm5580475qvb.84.2023.03.30.09.07.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:07:51 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Andrea Arcangeli , peterx@redhat.com, David Hildenbrand , Andrew Morton , Nadav Amit , Mike Kravetz , Axel Rasmussen , Leonardo Bras Soares Passos , Mike Rapoport Subject: [PATCH 15/29] selftests/mm: uffd_open_{dev|sys}() Date: Thu, 30 Mar 2023 12:07:49 -0400 Message-Id: <20230330160749.3107270-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230330155707.3106228-1-peterx@redhat.com> References: <20230330155707.3106228-1-peterx@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=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=unavailable 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?1761810465194782757?= X-GMAIL-MSGID: =?utf-8?q?1761810465194782757?= 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. Signed-off-by: Peter Xu Reviewed-by: David Hildenbrand Reviewed-by: Mike Rapoport (IBM) --- tools/testing/selftests/mm/uffd-common.c | 28 +++++------------------- tools/testing/selftests/mm/vm_util.c | 24 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-common.c b/tools/testing/selftests/mm/uffd-common.c index 17f2bb82c3db..3a9b5c1aca9d 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 10e76400ed70..7c2bf88d6393 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 +} From patchwork Thu Mar 30 16:07: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: 77296 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1251086vqo; Thu, 30 Mar 2023 09:23:13 -0700 (PDT) X-Google-Smtp-Source: AK7set/MZYnWClUoKqdVzXgyzRyNZjtPWPEK/HfhQm8ZJflsqsXYgVDOpo3VsMmgLEJ6gZVMoKq4 X-Received: by 2002:a05:6a20:7924:b0:da:17b4:461a with SMTP id b36-20020a056a20792400b000da17b4461amr19937219pzg.32.1680193393206; Thu, 30 Mar 2023 09:23:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680193393; cv=none; d=google.com; s=arc-20160816; b=UQLhLNcxu1kMZ8O8mCIGVJmhmJyrB4NpFYv/Zsf1CVzhkTvkTk+L6yFj+EskvaGyTb eM3WXE6OWaMHkHeNAoYpD0zQ5UQYY1gIu3NB2e9Ppu0uAdQJaO+cWsg4waXUdtwKxVR3 rVt3vMFFvqU1KjmKXJd3G0gXRVQJap86mY4ugt78l8Qjuqxua0IaqybLywkx+t7hReV/ m/BZJzofx3LEhmEMs7sz3U0OE0LRvq12zPN1yzKG/6HbgI5qMbFzwVXPYXRBW9eiZFAE YHOANzShI/D9bk0ll+KFebwXKgFPdyeNS7JaFOYTzyeDg98ZU+mt02/3OXZnbfW8KV39 66ig== 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=Pi0McrG33VvWSi8wJEF+ZnP9lqDjRKaT61ZsjgmAIPc=; b=kfoC92IWvbmChAeGWNqkWH3ivuUmzJIXWge6tACg75MGSAr2ouIMnsOCdxPYJciTMo BKgmob9plCG7G2u2qKM3/U/q4hEOQDeTmocckxXdreSPD/BKQw0NepVbmMuOdflVPHsQ dsjZFK04YJFjYRGGDuZ4MRi4kTmYKNk04MeMvBmavzaek3tArWJceXh/tj+I9WAI+L37 441U9RnRSdstFThk07usVHzNbyLq37ehDUXNu8vXXfTKKBJDDTVl0ZF64yowTlV2F0XF 0uw8TsVO39Ux9RkPwP5qpy194Rl1XSDHHrKfyXI2YO6iDP3zOo+U+9KZUJQuoIDybJLy mtbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=F9IXHLTF; 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 f20-20020a63f114000000b005073e334327si25636731pgi.779.2023.03.30.09.22.49; Thu, 30 Mar 2023 09:23:13 -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=F9IXHLTF; 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 S232059AbjC3QJ1 (ORCPT + 99 others); Thu, 30 Mar 2023 12:09:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231869AbjC3QJH (ORCPT ); Thu, 30 Mar 2023 12:09: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 0643E9750 for ; Thu, 30 Mar 2023 09:08:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192483; 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=Pi0McrG33VvWSi8wJEF+ZnP9lqDjRKaT61ZsjgmAIPc=; b=F9IXHLTFLdcQKC63lniv1YDIfcAb6eJR7uE7mjdCPkaqoANI/7KKPooaudFIIv6PZ0wEDx w+NoQZlMv77QpxXHga0GGWmEp6ABAVi7yEawfL+b6s9mcDTydOeyGiKn2n7y1vyUUaTsr5 Ph3X0FA0xtsBdZubHCUuNkfncq1/FHQ= 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-128-9gAKRPr7O2euqJG7T0FH3w-1; Thu, 30 Mar 2023 12:07:59 -0400 X-MC-Unique: 9gAKRPr7O2euqJG7T0FH3w-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-57c67ea348eso12977546d6.1 for ; Thu, 30 Mar 2023 09:07:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192475; 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=Pi0McrG33VvWSi8wJEF+ZnP9lqDjRKaT61ZsjgmAIPc=; b=Swl9kX6rCafUUpSaIbWgytBvrWd24CSK7RQfs/T3dITrEglgl1ByKCoxP2GPphLRaY L1vEpfJp3GsEOW1dsd/VzV9V9CXuDxtzvo3AQYxzKAyLgA7JFqZubkeLqbuAweY4OG6F N7z524+QaXlGEWsv1QKf0v+G8V1Eg08MsNuJDdJR69UPK5+OzpteBZ5Fxcsw/5+P0rWe Ln5INGfWe5bCqPbODa4VNS8XncGAvzsZHFDDJn87wXfk0oiBVMRk2/DV3aYIK6kxyiOb h4FA0UUPaaea0FlwyAoT61GA8RvxpwjaXFNY3zK337rdyIR/dZ3gL1sk4n2rwkJ6TgKp +/Fg== X-Gm-Message-State: AAQBX9eC+INKDjmE9IKswrDP2HxyJbRBU5R1zw+1ePj6w2sE6kK8Wq+q BsqAsSzbW/D1alGAia+d0oW5J3apAH05xORQLG7XWZVfAz72K9qBDDI6UzMTG7xdoN35bJ4dRnZ gm0TJTF53cXwVSXdf8rgtXCHE X-Received: by 2002:a05:6214:528f:b0:5a5:e941:f33d with SMTP id kj15-20020a056214528f00b005a5e941f33dmr3649471qvb.3.1680192475183; Thu, 30 Mar 2023 09:07:55 -0700 (PDT) X-Received: by 2002:a05:6214:528f:b0:5a5:e941:f33d with SMTP id kj15-20020a056214528f00b005a5e941f33dmr3649415qvb.3.1680192474610; Thu, 30 Mar 2023 09:07: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 bl28-20020a05620a1a9c00b007339c5114a9sm19630391qkb.103.2023.03.30.09.07.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:07:53 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Andrea Arcangeli , peterx@redhat.com, David Hildenbrand , Andrew Morton , Nadav Amit , Mike Kravetz , Axel Rasmussen , Leonardo Bras Soares Passos , Mike Rapoport Subject: [PATCH 16/29] selftests/mm: UFFDIO_API test Date: Thu, 30 Mar 2023 12:07:52 -0400 Message-Id: <20230330160752.3107283-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230330155707.3106228-1-peterx@redhat.com> References: <20230330155707.3106228-1-peterx@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=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=unavailable 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?1761810467423260323?= X-GMAIL-MSGID: =?utf-8?q?1761810467423260323?= 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 --- tools/testing/selftests/mm/uffd-unit-tests.c | 111 ++++++++++++++++++- tools/testing/selftests/mm/vm_util.c | 10 ++ 2 files changed, 120 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..dfb44ffad5f5 100644 --- a/tools/testing/selftests/mm/uffd-unit-tests.c +++ b/tools/testing/selftests/mm/uffd-unit-tests.c @@ -9,9 +9,118 @@ #ifdef __NR_userfaultfd +struct { + unsigned int pass, skip, fail, total; +} uffd_test_acct; + +static void uffd_test_report(void) +{ + printf("Userfaults unit tests: pass=%u, skip=%u, fail=%u (total=%u)\n", + uffd_test_acct.pass, + uffd_test_acct.skip, + uffd_test_acct.fail, + uffd_test_acct.total); +} + +static void uffd_test_pass(void) +{ + printf("done\n"); + uffd_test_acct.pass++; +} + +#define uffd_test_start(...) do { \ + printf(__VA_ARGS__); \ + printf("... "); \ + uffd_test_acct.total++; \ + } while (0) + +#define uffd_test_fail(...) do { \ + printf("failed [reason: "); \ + printf(__VA_ARGS__); \ + printf("]\n"); \ + uffd_test_acct.fail++; \ + } while (0) + +#define uffd_test_skip(...) do { \ + printf("skipped [reason: "); \ + printf(__VA_ARGS__); \ + printf("]\n"); \ + uffd_test_acct.skip++; \ + } 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 uffd_test_acct.fail ? KSFT_FAIL : KSFT_PASS; } #else /* __NR_userfaultfd */ diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c index 7c2bf88d6393..62fcf039d6b7 100644 --- a/tools/testing/selftests/mm/vm_util.c +++ b/tools/testing/selftests/mm/vm_util.c @@ -254,3 +254,13 @@ 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; +} From patchwork Thu Mar 30 16:08:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 77299 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1251421vqo; Thu, 30 Mar 2023 09:23:37 -0700 (PDT) X-Google-Smtp-Source: AKy350ZebEEP+pdln+pHjGX3Tk9NyJxQDjEuz5RTZwVs5f1ZqqyXwq9Eb4HZ1s95OekRWmSJ8VDM X-Received: by 2002:a17:903:6c5:b0:19d:778:ff5 with SMTP id kj5-20020a17090306c500b0019d07780ff5mr21897945plb.15.1680193417237; Thu, 30 Mar 2023 09:23:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680193417; cv=none; d=google.com; s=arc-20160816; b=U6dokhJy/MFnnYT3lzoNODFahD1im1UKSWx1Z7ALERU76xLQxnFrDKbpqLwwNAOfxz VxHtiwxVKibTz2YgQmScESo8jZK+rWAwQqZ7GoGWzqfNcKYv73Uwu7klGUtGHfTkl/am KMHjPJnZSLHi4bbdZ6DH57fH55YG35JnPl6x0xpXgaBgGrnaTAsPvc4JzYFS+sSeBxTe tptq8qIi/0iOASK3dN9IhNVaxXdxbtkx8TJ+ujEpHN/fCXTw6nI9W/wRrac/irADC4CU 1sC0t/aKbJvJcangguVLB4WyoYpezzG3JH/YHlXtbQyWd5OLD63SDOAscuz0DSqo7vba 69sQ== 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=lYveN9kYI+AE0CuBqSxlkzyTIkRFNshZ9iE0ExlkrHo=; b=X4PqnMUQL5wD3oHCX/An4ojT47jl+/fovy3zmeHBNQYkZnP/0DyjmTNNWdNJJYNBav SAmHBLcz/9eW3yNCZMW7Hm/DlMDJ65FwK2VCHn8Mf8+bFXjpvby8Fws7FzYH8YAgHPLe Gip6hnEy9zUI238YIfD7+j4wgqVtft2IIqThwjH+p7ub8IpP/6f/tqVPU2tPAc2P/Uoq Sg3T3Y01mlQ13bJMHgO3PrfZu/aceG/zgI7VXF6NJ/TNnBCbp+4C0k03UIs0iWs2wq0Z BLQPRqDGaU/yIfCl1XMkrUPgSBi5nSI+jD2eZI2/tHZXB1cdov1/flASzhSaaVkg8BMp rmGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=eQRu5bWa; 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 b12-20020a170902d88c00b001a220a984f9si13970235plz.546.2023.03.30.09.23.21; Thu, 30 Mar 2023 09:23: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=eQRu5bWa; 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 S229609AbjC3QJm (ORCPT + 99 others); Thu, 30 Mar 2023 12:09:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232010AbjC3QJZ (ORCPT ); Thu, 30 Mar 2023 12:09:25 -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 1B9B3D32E for ; Thu, 30 Mar 2023 09:08:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192492; 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=lYveN9kYI+AE0CuBqSxlkzyTIkRFNshZ9iE0ExlkrHo=; b=eQRu5bWaFjcdN08/IhsDIeE4uWoLMiMRDyk/z31AxtJKFDPm7F7DmMIFZi9xHzI29VVC7u 0zP9/GRE33UdT7i9e110PySv0PnA2j2+0V3mG2BLEHNqD2AAsMFC74uK7uIB3CXPFGpxdK JotC3of7xV5OhojbsbN+YkTgS/3wKok= 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-474-bC1EW9GVNo-k5HgQypLCNQ-1; Thu, 30 Mar 2023 12:08:10 -0400 X-MC-Unique: bC1EW9GVNo-k5HgQypLCNQ-1 Received: by mail-qt1-f197.google.com with SMTP id b11-20020ac87fcb000000b003e37d72d532so12708542qtk.18 for ; Thu, 30 Mar 2023 09:08:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192489; 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=lYveN9kYI+AE0CuBqSxlkzyTIkRFNshZ9iE0ExlkrHo=; b=6XUA39pzDaarttByQdil8sROGUzD5cfka89pNWKY3PbVnpqdWDJnK4v9QExU8gpsrn 4FKT38VqYJmhWBKojutOLcuSYU0Cv82InchXyw8X1a/pnVTGgoIsWWnabYIzn6pOOQIb ZZNdZhjG7OlSe1rvJA2vcT2BgN+6V/ouXCYRhLvtIl/qOUScw0sasmRLrReHHcxNCNU3 UNnrWsQaLEVZ9QfLV5ojwmlK/unSLSOkemZG70VJvkhb7sAjQyq7kY4hBvnqJw8kpAwR La0HeFOH78bNYmwOZt2JP/rnUYoEkeaVXGhG2UfHZNNh2ZdiodrLiv4hQqw/BuXh8FBH X2kA== X-Gm-Message-State: AAQBX9dN2zNjlNxSdjN4DZ0bQ4DJTPi6ccg0PRlw4KZzlGXgEcqVmF25 9EDQuEVzwaz6uHVAyow3efCF5FqM3xytHJWHRmRYw0yljp3PZv62uHADPhsU/6KpfMAsrcVOS/J uX+2oStrnnWoWwtNznLXUvS/6TCtwjGMh4POMwMWmoGmT53KxQgiAfA2nxISvhBGJG1mTBWYzRz FK1MD11A== X-Received: by 2002:a05:6214:4005:b0:56c:d9e:c9a0 with SMTP id kd5-20020a056214400500b0056c0d9ec9a0mr3701343qvb.1.1680192489198; Thu, 30 Mar 2023 09:08:09 -0700 (PDT) X-Received: by 2002:a05:6214:4005:b0:56c:d9e:c9a0 with SMTP id kd5-20020a056214400500b0056c0d9ec9a0mr3701286qvb.1.1680192488771; Thu, 30 Mar 2023 09:08:08 -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 m12-20020ad44a0c000000b005dd8b93456dsm5504054qvz.5.2023.03.30.09.08.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:08:08 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Mike Kravetz , Mike Rapoport , Andrea Arcangeli , peterx@redhat.com, Leonardo Bras Soares Passos , Andrew Morton , David Hildenbrand , Axel Rasmussen , Nadav Amit Subject: [PATCH 17/29] selftests/mm: Drop global mem_fd in uffd tests Date: Thu, 30 Mar 2023 12:08:06 -0400 Message-Id: <20230330160806.3107497-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230330155707.3106228-1-peterx@redhat.com> References: <20230330155707.3106228-1-peterx@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=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=unavailable 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?1761810493145134631?= X-GMAIL-MSGID: =?utf-8?q?1761810493145134631?= Drop it by creating the memfd dynamically in the tests. 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 | 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 3a9b5c1aca9d..a2b6e4957d0f 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 Thu Mar 30 16:08:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 77304 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1253505vqo; Thu, 30 Mar 2023 09:26:39 -0700 (PDT) X-Google-Smtp-Source: AKy350YSzGpw9XDItYWpppyH/xCbTfQDc6JQ+7x6DZl4oIHVAqtImz5ybAOeJ4XjPOGs1kAmrMFE X-Received: by 2002:a17:906:90c9:b0:933:6ae6:374d with SMTP id v9-20020a17090690c900b009336ae6374dmr20709927ejw.73.1680193599529; Thu, 30 Mar 2023 09:26:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680193599; cv=none; d=google.com; s=arc-20160816; b=Aif/eOK4byvF4X0tyGEgptKJ23dHdORMAaN7tHdhfjCE7MIWpBNcVOg0Wegy18s39Y JDUvgU0d/P53lcp9cbYOaDOi/jPwYw6Yq8CsKLwtCw7PscjtZe+xwYx/iPLCzetS4afa FLrKlmFhiqS8032g7B/kOvSTCwrHDAfstC62n37n9/JD0pHAjKmr55X7fZScEB45LNs0 nUL3f7BSBt37uDEyuOhVL2V+HIskhygmUH0kt1dYYYu+i+lw6w5vvaPgO0M/XYq33+KC FGogWro6IsT7LCPqr0vA/CJzqscwjnQwEuSW5cZiX+ke0qlTXj7842knTuFC1pqfMxnQ 1PnQ== 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=gA0z3fLtS/53pi31HkFC8RYwaDcusvVg7bMc/ulU8j0=; b=NKw+/9niI7d/IhR1jsjENOGCwr1aldpIRlVLNdm/uphLj7oRgo2MkoBLdl/PZYJGWw GD3OiPvr1AqRZXdOgU87EoJ3qJLDINHGFUUVCIUTO35D7G4q8Dw+Ct0cp4omDsbtHpr6 fttxDlPV3QTMwxq8dyAyMRzjqbPhR/oNgtEING1S8CKBJODmAoWmyydNaitkjoCEopGy L7LenAYkgTo1/1rGndYMd26OUbKa9U4be/xWQCoaHYX9nxllGUxIfsvdpYbjFxhnNudB FiCt4cDZCgeI6diJIHvBMWQlsE6tWrfkd2tdAxrkhQp9u0GTRt++2DtwZzMGrQODL/Rw OFsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KIKb0DkI; 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 k7-20020a170906970700b0093cd9fa2838si17090368ejx.1009.2023.03.30.09.26.15; Thu, 30 Mar 2023 09:26:39 -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=KIKb0DkI; 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 S232114AbjC3QJt (ORCPT + 99 others); Thu, 30 Mar 2023 12:09:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231588AbjC3QJj (ORCPT ); Thu, 30 Mar 2023 12:09:39 -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 2B700E398 for ; Thu, 30 Mar 2023 09:08:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192496; 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=gA0z3fLtS/53pi31HkFC8RYwaDcusvVg7bMc/ulU8j0=; b=KIKb0DkIF41uP2Cw/gAv5F2Lm8NJfxK+HOlhcuXZWgrTkgJHI2nlRxnqMaQopYGKqXw2qe SAtww0SNGQBT8G5w3AdM6xG25vl/WhCOmjjFLCN1TEw6xmOkPdCJQZl5ClnHvpXgWF3B4t OK2USu/MBdVuGk59WWVPCxtB3qqSxb0= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-551-09LYY7_lPxCzaU0pf8JnHQ-1; Thu, 30 Mar 2023 12:08:15 -0400 X-MC-Unique: 09LYY7_lPxCzaU0pf8JnHQ-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-5aae34d87f7so13016926d6.0 for ; Thu, 30 Mar 2023 09:08:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192492; 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=gA0z3fLtS/53pi31HkFC8RYwaDcusvVg7bMc/ulU8j0=; b=ZIEJWL+nHs/gUTuU4N9Pkw0+GyCfKP8Q2E6JwocvRwrEEmTcWL8knu4ECOpqOSXU84 8dcEH3y6vQYd8b2fnzx0LbGCLQxzpvRuh+0bSi3qHRp/xcIiyFk7ITIaVXskZysNTopI WiQnH9te1KSNI1jBNOzbm+e3hAApamyfyeSvr5XsgzvGgauGMFD3hVbKWd2IaUGjivQ9 SXa6qWAyxboa3OUA1bG4QFTdMJ0Dmw9z6/r8ipXjpbHwSlaw1oZ+XoV6XXK6cRg0tSny LD7OYexDJc6opFTrUvMQue+pUx8bUW1oYsrvOJ0TzAmhIyP/f5GKkgpJeAAv/ndxT05H bBPQ== X-Gm-Message-State: AAQBX9cJr2V0nNN8hx1z1ZNi6wRg9v5PYkkm4wyUlmJpkAZx+oyqjejv h6GSdNl2qlo9X9g12jYHDNU42yZX33DR6zbLAmN/b6EgABEZcepXxUYMvoraA+E+e10sT3HXnHV JFEbFeWAhSj14Bw74+KHaSe8Ve8BzIypMMGau3jF/vKhlpxetYCKCEqb2g5r+oJUjFMf21f3c6N mjZaiiMw== X-Received: by 2002:a05:6214:d0c:b0:5df:a693:39e with SMTP id 12-20020a0562140d0c00b005dfa693039emr3572761qvh.5.1680192492261; Thu, 30 Mar 2023 09:08:12 -0700 (PDT) X-Received: by 2002:a05:6214:d0c:b0:5df:a693:39e with SMTP id 12-20020a0562140d0c00b005dfa693039emr3572696qvh.5.1680192491770; Thu, 30 Mar 2023 09:08:11 -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 mk5-20020a056214580500b005dd8b93459csm5534560qvb.52.2023.03.30.09.08.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:08:10 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Mike Kravetz , Mike Rapoport , Andrea Arcangeli , peterx@redhat.com, Leonardo Bras Soares Passos , Andrew Morton , David Hildenbrand , Axel Rasmussen , Nadav Amit Subject: [PATCH 18/29] selftests/mm: Drop global hpage_size in uffd tests Date: Thu, 30 Mar 2023 12:08:09 -0400 Message-Id: <20230330160809.3107511-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230330155707.3106228-1-peterx@redhat.com> References: <20230330155707.3106228-1-peterx@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=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=unavailable 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?1761810683875765515?= X-GMAIL-MSGID: =?utf-8?q?1761810683875765515?= 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. Signed-off-by: Peter Xu Reviewed-by: Mike Rapoport (IBM) --- 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 a2b6e4957d0f..025e40ffc7bf 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 Thu Mar 30 16:08:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 77300 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1251634vqo; Thu, 30 Mar 2023 09:23:55 -0700 (PDT) X-Google-Smtp-Source: AKy350YMBGTnqaHpDR0/X4p0D7PL9BMaJXHfPZqiLcUqLEIE3p80eDYOcgqTmL4HQSOlY5QACuFs X-Received: by 2002:a17:90b:1e01:b0:234:159:4003 with SMTP id pg1-20020a17090b1e0100b0023401594003mr23843071pjb.25.1680193435550; Thu, 30 Mar 2023 09:23:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680193435; cv=none; d=google.com; s=arc-20160816; b=sFG43CbQ/Ypc0eskueBXFmBG80hloor0EmyuOhGdMyngjrYOiaoI4x0N6mi5uz4vaI OFKYFp9WPIyG9Gx1EEo+4SX9Dpq1ifY5AmoDXvCsE1Q+KUuXHOzD3uEIwkgipkVUMJft 3ypH5EsRJ2CqAjGOWjwkqDhjhODsQR2LJ9rqzvsr0QdTaYmaZbL7H4WGLj4/834J/uJD 3y+oTUL9sxC6bPx0SvmQ8a3j2mCJLToVeu22+hft6D23x7kGKrrWmyBP62FTzTj8g9PT QLahc5S8flQmSkzUYo+tVYCmzOmDNztt+rl0x03gFgh+a06hFUXZXnrrxurECEM1wP3W NwNw== 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=8NTrS8mJzWPEnPLBWSlseOL+7dIWq0u/3um5fPzddJ8=; b=I1qU3Ye5EmzK4kn8vXvXhsmKxF0G7mCGGGS3tCJEKGwots5fS0Tmm2x6LsAFHPRTcZ DQU4uFntsIPViX+PZ933dtnZKNYPaPL58SAmiEWUhcOD1B4Ntz1TA51UWsshiR90S+3z cgGWIki52RJ6LF/0QJmiSuxu3rMY50LolhQi+/gpc7Iq/TokIjCLCIAfuvw+jtn6njLO E92Wh+JWrrPMVor1DAZVYNDspvmOEDHLVvK2B6RxYgmz6VWzzGeoPQaQ9vUOQ/7HRn/O 0BG0lHBB0Dwz+jryLp/VYNyUDQvEULXZt1+SPuDrHelqjO+E0TOiAgHxrOWiZb+5+GDh zf0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="h/pX68xs"; 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 x11-20020a17090aca0b00b00233c5363cdcsi1586911pjt.142.2023.03.30.09.23.41; Thu, 30 Mar 2023 09:23: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="h/pX68xs"; 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 S233453AbjC3QKB (ORCPT + 99 others); Thu, 30 Mar 2023 12:10:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231707AbjC3QJo (ORCPT ); Thu, 30 Mar 2023 12:09:44 -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 4ADCF9ED8 for ; Thu, 30 Mar 2023 09:08:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192499; 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=8NTrS8mJzWPEnPLBWSlseOL+7dIWq0u/3um5fPzddJ8=; b=h/pX68xsoKsLbvBW2mDDwXoxhajDw3NdLkny3v8Oiq4+0aw05EvqBhf3HpUWwyPX1rFGH5 Z/zjEQAwKq2KkoSBNLpMwL4PhosXEmB5xG7TAWAytUNt8A6FtAkIMphnFpw7wDNCwKJBlp UT2i09IZM3zzez32gQro4BIZqcI4Yio= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-312-m-5B07egPu-qhKeUh8Impw-1; Thu, 30 Mar 2023 12:08:17 -0400 X-MC-Unique: m-5B07egPu-qhKeUh8Impw-1 Received: by mail-qv1-f70.google.com with SMTP id f8-20020a0cbec8000000b005b14a30945cso8446157qvj.8 for ; Thu, 30 Mar 2023 09:08:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192496; x=1682784496; 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=8NTrS8mJzWPEnPLBWSlseOL+7dIWq0u/3um5fPzddJ8=; b=ItB8rOB+aCDO7GftPppSmfbQKg5HAN319gWXJ1wOCOVyBKxZnyAfuFG1mjuE7NB+br yv0/E0zEto5LXTiH1EmQLO1yNAk4Jrv9/0P53wvRzSyfHChjTDzBzvoWo0M100ylmr5W 32TQCt5SHsRVFIqjKRWgL7SRioKUikA8LtqeQc+AG3Lhqn2uHMM7s//tkhxGg9NSzSmO aYKmSfnDRzb6iM4keda3zeLAw2vOLzavwsa0r2U/aUKRNT8Tgp4wdk+wZqepjsjjR0aa v1goAUDE2mlRZoB6hVMyKAdev3LVqzinzD22pX1ekxPEoVd0m/siruJ1BC44MhaUwE8M DwPw== X-Gm-Message-State: AO0yUKXmwhD2EK4HEei9hUBclYRmBBvZIRQkrLdG3azT6+WtIImocI/A e9p9HvxcJgdoxU6HgM67+7u2/EOvXy4M1WDBL7Y79k1wktO+xiLtCUY6DAxbku04IxEwHVtn1yd GbP78UCTzxXPYJj2/SUlolETXOUBijxgriOTau5DjD4FpRbtb3h659T9SCKCSGumA4WADs67gBF GpoqUe+Q== X-Received: by 2002:a05:622a:3c9:b0:3b8:36f8:830e with SMTP id k9-20020a05622a03c900b003b836f8830emr37733733qtx.6.1680192496042; Thu, 30 Mar 2023 09:08:16 -0700 (PDT) X-Received: by 2002:a05:622a:3c9:b0:3b8:36f8:830e with SMTP id k9-20020a05622a03c900b003b836f8830emr37733689qtx.6.1680192495676; Thu, 30 Mar 2023 09:08:15 -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 bn29-20020a05620a2add00b007486052d731sm4247503qkb.10.2023.03.30.09.08.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:08:15 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Mike Kravetz , Mike Rapoport , Andrea Arcangeli , peterx@redhat.com, Leonardo Bras Soares Passos , Andrew Morton , David Hildenbrand , Axel Rasmussen , Nadav Amit Subject: [PATCH 19/29] selftests/mm: Let uffd_handle_page_fault() takes wp parameter Date: Thu, 30 Mar 2023 12:08:12 -0400 Message-Id: <20230330160812.3107522-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230330155707.3106228-1-peterx@redhat.com> References: <20230330155707.3106228-1-peterx@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=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=unavailable 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?1761810511925716257?= X-GMAIL-MSGID: =?utf-8?q?1761810511925716257?= Make the handler optionally apply WP bit when resolving page faults for either missing or minor page faults. This move towards removing global test_uffdio_wp outside of the common code. For this, slightly abuse uffd_stats to keep one more parameter on whether we'd like to resolve page faults with WP bit set. Note that only the name is abused, it'll be better to be called uffd_args or similar but let's not bother for now. 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 025e40ffc7bf..92b7e00efa8a 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_stats *stats) 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, + stats->apply_wp); stats->minor_faults++; } else { /* @@ -459,7 +460,7 @@ void uffd_handle_page_fault(struct uffd_msg *msg, struct uffd_stats *stats) offset = (char *)(unsigned long)msg->arg.pagefault.address - area_dst; offset &= ~(page_size-1); - if (copy_page(uffd, offset)) + if (copy_page(uffd, offset, stats->apply_wp)) stats->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,8 +588,8 @@ 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 47565b2f2dee..f4bc73ce3b48 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_stats { 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_stats *stats); -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 54fc9b4ffa3c..70cb0619354e 100644 --- a/tools/testing/selftests/mm/uffd-stress.c +++ b/tools/testing/selftests/mm/uffd-stress.c @@ -97,6 +97,7 @@ static void uffd_stats_reset(struct uffd_stats *uffd_stats, for (i = 0; i < n_cpus; i++) { uffd_stats[i].cpu = i; + uffd_stats[i].apply_wp = test_uffdio_wp; uffd_stats[i].missing_faults = 0; uffd_stats[i].wp_faults = 0; uffd_stats[i].minor_faults = 0; @@ -156,7 +157,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; @@ -309,7 +310,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; @@ -344,7 +345,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 */ @@ -508,6 +509,7 @@ static int userfaultfd_events_test(void) true, test_uffdio_wp, false)) err("register failure"); + stats.apply_wp = test_uffdio_wp; if (pthread_create(&uffd_mon, &attr, uffd_poll_thread, &stats)) err("uffd_poll_thread create"); @@ -516,7 +518,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) @@ -552,11 +554,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); + stats.apply_wp = test_uffdio_wp; if (pthread_create(&uffd_mon, &attr, uffd_poll_thread, &stats)) err("uffd_poll_thread create"); @@ -565,7 +568,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) @@ -629,6 +632,7 @@ static int userfaultfd_minor_test(void) page_size); } + stats.apply_wp = test_uffdio_wp; if (pthread_create(&uffd_mon, &attr, uffd_poll_thread, &stats)) err("uffd_poll_thread create"); From patchwork Thu Mar 30 16:08:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 77312 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1267351vqo; Thu, 30 Mar 2023 09:47:01 -0700 (PDT) X-Google-Smtp-Source: AKy350ameEO//3CkEH/9AnVrm50KEXg2zhcNsJvwCEc9tekdWuQ61iABRJGukVHFP47xUs8zlbet X-Received: by 2002:a62:585:0:b0:5a9:bf42:fcc5 with SMTP id 127-20020a620585000000b005a9bf42fcc5mr21171153pff.0.1680194821441; Thu, 30 Mar 2023 09:47:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680194821; cv=none; d=google.com; s=arc-20160816; b=Ft+9kTWkC8URHxNCmsYLuYz/tkJSKi69UNZzwdurlQCMD9rou/qTO1W9xb6IpT5ijx LbOBlS2rT6XT/b4Zzi4qitn/tkligZO0paaFsF93uAfQA+eg+YmmbM77rMdnjRFu69Fz BPZ2mWLa1JUciZm39TKNBE5Lmns86txdCwWB2c0JHqQIdaTEgp00aikOxRJloRXEp2QV TH+Z/03/ysyD73SATvsgnBZBDeLnH/7p/gO7lm3OrBTzVI54b8GA6N803dMCftiNuaEZ wu0b/CQiIXQjzfjuBy+8kM0//0o/NCHlZzCcVxp0zdTUSkR3aBqHkH36nEOMICtNGDFC mAvw== 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=fazvJ2yoVQ3FbqTtLeeKqsLvxYRtSAddCup9lQnAU9I=; b=punCoULsriBXy9Y7UVu9SIidZs0lD/T4mXS6RudvuQxyxZSQPOLOGVaxV322izRFaI trHWtvzjB5Uknc4fqpslVWI0TyzGPWkikUcces7hTPab/x7KnOTxsfXhbdcdwElFW4fu o4i0tlTvDOdxeBiDqBz5ySRVZJtGPDujDiwpCeJ1lXQkBZf/QaU5+N4QIDTi8F/2jrlB BRMpw0GCkOInoHm90nQgdMHG9QncKokLYv1gwjtDN9ONJIPjXEu7/W912iD6DcKk0F8E IKOoSumn/qQu78R3HVxk32gzED1mZHlP63j2KZb9GkulGwXCAETJvqu6XyOZbtbyklve 0xtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ImXgVj56; 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 q25-20020aa78439000000b00622bad41034si215236pfn.95.2023.03.30.09.46.45; Thu, 30 Mar 2023 09:47:01 -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=ImXgVj56; 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 S230027AbjC3QMd (ORCPT + 99 others); Thu, 30 Mar 2023 12:12:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230079AbjC3QMb (ORCPT ); Thu, 30 Mar 2023 12:12:31 -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 0DE87CC1C for ; Thu, 30 Mar 2023 09:11:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192635; 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=fazvJ2yoVQ3FbqTtLeeKqsLvxYRtSAddCup9lQnAU9I=; b=ImXgVj561CxRV7Co5nf+bFPpUWX1wcugydOwiFFTtUc5G5Eg8D9cOzJK9PuIx5KtF/9IQ0 iaD28q28JppcVVIfDdHtjHhNpmmme9HIeNJiXXTLzdkfzBVeOEFErukHJ5FBgGaLyMz1Ql xgMAOFpDMfNuFq4dcZPYghR827XLwfg= 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-675-Zw41IXoxPFqlzT2WkOARig-1; Thu, 30 Mar 2023 12:08:29 -0400 X-MC-Unique: Zw41IXoxPFqlzT2WkOARig-1 Received: by mail-qt1-f199.google.com with SMTP id h6-20020ac85846000000b003e3c23d562aso12740691qth.1 for ; Thu, 30 Mar 2023 09:08:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192499; x=1682784499; 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=fazvJ2yoVQ3FbqTtLeeKqsLvxYRtSAddCup9lQnAU9I=; b=kuZID7v6q5vnBwwPRzcHU0IqSP5FKhvDMT3q4fpnTAIzFPgRZL+Y5F1h6Wyf4ODFi6 4i99D2JeYo2C64H1V/SSqrgsKwNs+ofPyYfwTcmL7JuUFULXRQ4jr5V1i7SwCIrC64XJ KeuGa54xjZoJaAaJOUMXJVFwBLd95HQEZLt+1a2DHy6IfwBjqw2G3d7YRU902BSX/Ju+ N3mgL6Y4M0FNfHSI7uezCNfY1yg6Slm6iv5fTvIFjH2BOHhRvSp2lkqbqQaVLYZA4JQq BPOCLxP1MgjYMGMjMbmjGztRdcFflFsK/3YJAUtDHfuKC2UoxylbHwnyF8dtuQBWVvB7 Tz8w== X-Gm-Message-State: AAQBX9fT0YUL8QBY4KmCu65zDA3pIJ/dfGjZ/bzeM+y6zMXy2gkdTXg0 coek5pYoQUO715uAqlKnjE9zCgXMMGn2fi7F9C/jTm2rDgS/itgv0tm1c/2ofnSBHsT0vzmlJqF FPy4ebsn+UcxHbtg6WryADEGy11zZVGIdYHoOh4s2Kh3z2SByQTr4Sk0lzJ7pk3c645AG+ICpy/ rLJjVTMw== X-Received: by 2002:a05:6214:509b:b0:5af:3a13:202d with SMTP id kk27-20020a056214509b00b005af3a13202dmr3927559qvb.4.1680192498917; Thu, 30 Mar 2023 09:08:18 -0700 (PDT) X-Received: by 2002:a05:6214:509b:b0:5af:3a13:202d with SMTP id kk27-20020a056214509b00b005af3a13202dmr3927505qvb.4.1680192498409; Thu, 30 Mar 2023 09:08:18 -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 nh12-20020a056214390c00b005dd8b9345cbsm5546921qvb.99.2023.03.30.09.08.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:08:17 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Mike Kravetz , Mike Rapoport , Andrea Arcangeli , peterx@redhat.com, Leonardo Bras Soares Passos , Andrew Morton , David Hildenbrand , Axel Rasmussen , Nadav Amit Subject: [PATCH 20/29] selftests/mm: Allow allocate_area() to fail properly Date: Thu, 30 Mar 2023 12:08:15 -0400 Message-Id: <20230330160815.3107534-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230330155707.3106228-1-peterx@redhat.com> References: <20230330155707.3106228-1-peterx@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=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=unavailable 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?1761811965251517888?= X-GMAIL-MSGID: =?utf-8?q?1761811965251517888?= 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 | 32 +++++++++++++++++------- tools/testing/selftests/mm/uffd-common.h | 4 +-- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-common.c b/tools/testing/selftests/mm/uffd-common.c index 92b7e00efa8a..ae6b61144b53 100644 --- a/tools/testing/selftests/mm/uffd-common.c +++ b/tools/testing/selftests/mm/uffd-common.c @@ -44,10 +44,13 @@ 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) + err("ENOMEM"); + return 0; } static void noop_alias_mapping(__u64 *start, size_t len, unsigned long offset) @@ -65,7 +68,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 +80,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 +101,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 +118,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(); @@ -150,6 +156,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 +289,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 +349,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 f4bc73ce3b48..51ec75f6d0c1 100644 --- a/tools/testing/selftests/mm/uffd-common.h +++ b/tools/testing/selftests/mm/uffd-common.h @@ -80,7 +80,7 @@ struct uffd_stats { }; 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_stats *stats, 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 Thu Mar 30 16:08: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: 77303 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1252779vqo; Thu, 30 Mar 2023 09:25:40 -0700 (PDT) X-Google-Smtp-Source: AKy350apd5cRkC81ajG42IMiJ7I7cBWFptP+JwTbtzbV68nIKY+jIQPqQvWs690/zYgdmf33Et50 X-Received: by 2002:a17:902:e2ca:b0:1a2:9051:f0a3 with SMTP id l10-20020a170902e2ca00b001a29051f0a3mr1664355plc.24.1680193540478; Thu, 30 Mar 2023 09:25:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680193540; cv=none; d=google.com; s=arc-20160816; b=puvTmLA5tdVVY45voTLCigZIn+ktIpqkMoYlAhfom4GpNOS25ZWmwVTrvu611doDN4 OSd5n9jtqbCoEG7T6V8DnCci739AdKmn4XeXMn2M8S17s5uvTYWOBR/SS4X8Sqd7/GR7 xca3mkHK/wu/wFolsrJMccfJ8DSV1Erj6xdFK9sJVwzq7VQTimDmL1UI7w4LOVnLhWE4 a9wyU+Cq1dLGhXaOi7oxGPT9LHOUg0Z9MdSfy50IBTGBdyuD7dTSD1tzW1vEF0UWaRgY 9BHbchQrdixSPmAx6oD6QvWsPVsJPCB+lO89YD4ERR1t9X8gsEPsWvTpLIRxCOVWrn1+ Jq5w== 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=uhDA/wjfT6X0KP/XkxMZvdeJDhg2SLQS/Rv9HxMM2sI=; b=AmtnXbBlFMa4+eXQrxCWigzNIH4F6d40wo/NYdTaWlhTDuxR2TsiUWQfQbbXYIJavs c6+uuWBd4vgc0IYpNeK9my+7QM4nNAPofIeXcwxhnsZG4N0FhNK4HOhTIMvz1eZAEYGN i+kT/jihyawtP9cvELKJe/MLKzKk/51Qcq6jgP8Qt9wsa/SvQHo4ROIwZlh5U3iJDhJG wG5NtcJIOH1K5JIc1UZE93jUqNBcb1C7YPmbS7C/CQi3Za9iynmHLVCH18G7wuFwhOMk 0UgbXitq1758Plm63Y1RqYxeS0Wta7xnO663NLqZ+DRqE8I1Aj4N93bgfxyRC3gmYoD/ dG0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UB1nxhQa; 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 km16-20020a17090327d000b001a04bde6843si14111378plb.259.2023.03.30.09.25.26; Thu, 30 Mar 2023 09:25:40 -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=UB1nxhQa; 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 S232191AbjC3QK1 (ORCPT + 99 others); Thu, 30 Mar 2023 12:10:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231825AbjC3QKO (ORCPT ); Thu, 30 Mar 2023 12:10:14 -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 28223D33D for ; Thu, 30 Mar 2023 09:09:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192505; 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=uhDA/wjfT6X0KP/XkxMZvdeJDhg2SLQS/Rv9HxMM2sI=; b=UB1nxhQaVKRMv+toni/81Une2kbcN4X4jgE8LoGIRJ+Sblatf8NZyYNizZK89/E/p253rs GTIOHDwlkf5ySVc8JaNpx+I45jyrV1ULQicUaodfM/HvkqYaaNN/NuDQPZYfWzs7mJWT3Q zr2boiq+jK0u/OSZT3xzsfH/RulUkD8= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-98-RuQv74wlMBuekp-YuXlFaQ-1; Thu, 30 Mar 2023 12:08:23 -0400 X-MC-Unique: RuQv74wlMBuekp-YuXlFaQ-1 Received: by mail-qv1-f72.google.com with SMTP id px9-20020a056214050900b005d510cdfc41so8513284qvb.7 for ; Thu, 30 Mar 2023 09:08:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192502; 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=uhDA/wjfT6X0KP/XkxMZvdeJDhg2SLQS/Rv9HxMM2sI=; b=fkcU06DPoZbDr6SW8F3jev2PEM9xC9QZ3mMWqM1Zae1uUohIJldNd9MwWwnsD/2yzl bcBX769Y/oX6oRSX2VIWm3vVvPs1agDYnGjtwZ8bcuO4wb2Sqjy9h33sqeTiJigyQJjk AnF2NDL4guXoQ/e8PG3nbIVxvX5q5SuSPqM1n5CLKhAvGPlEzAzGoyXAEh1RvCqLGBvc xa1YiXQczvzgyRy1+xMaRbYtFkgW6belXGWmYnuWFcDTevvsKPSjnu+4yViR1O2ZPGqF W78KnmmqYuDqgfmn67luERlyHrZzdqoXGYzKLI0zyhKgFaBfw0P7Tpda9RbEvgmWYpmL yHQA== X-Gm-Message-State: AAQBX9fv2RSYTVPq8tRczAoUaKxsJ8VC4iVxb58j5vrCNz393SzuZPn2 UKkH/hJpSflGuZIZBzq3siIFC9QUGNMvzmOMO8HE3Ho3HUj107DsgwBSIisnZsKgKCGUpv1Gqja TxXC+ID36SVQJPEg8itimEQgRcJXhiDP74kFBBdnaYXbqcMdcL0/+RUKH2Ynp/y1t0XhLwOgRoE G17WRMpQ== X-Received: by 2002:a05:6214:4005:b0:56c:d9e:c9a0 with SMTP id kd5-20020a056214400500b0056c0d9ec9a0mr3702716qvb.1.1680192501732; Thu, 30 Mar 2023 09:08:21 -0700 (PDT) X-Received: by 2002:a05:6214:4005:b0:56c:d9e:c9a0 with SMTP id kd5-20020a056214400500b0056c0d9ec9a0mr3702655qvb.1.1680192501195; Thu, 30 Mar 2023 09:08:21 -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 j5-20020a0ce6a5000000b005dd8b93458esm5515078qvn.38.2023.03.30.09.08.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:08:20 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Mike Kravetz , Mike Rapoport , Andrea Arcangeli , peterx@redhat.com, Leonardo Bras Soares Passos , Andrew Morton , David Hildenbrand , Axel Rasmussen , Nadav Amit Subject: [PATCH 21/29] selftests/mm: Add framework for uffd-unit-test Date: Thu, 30 Mar 2023 12:08:18 -0400 Message-Id: <20230330160818.3107545-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230330155707.3106228-1-peterx@redhat.com> References: <20230330155707.3106228-1-peterx@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=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=unavailable 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?1761810621648492209?= X-GMAIL-MSGID: =?utf-8?q?1761810621648492209?= 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 | 125 +++++++++++++++++++ tools/testing/selftests/mm/vm_util.c | 27 ++++ tools/testing/selftests/mm/vm_util.h | 1 + 3 files changed, 153 insertions(+) diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/selftests/mm/uffd-unit-tests.c index dfb44ffad5f5..007145063363 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; + struct { unsigned int pass, skip, fail, total; } uffd_test_acct; @@ -108,9 +168,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); @@ -119,7 +220,31 @@ 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("memory allocation failed"); + continue; + } + test->uffd_fn(); + } + } + uffd_test_report(); + return uffd_test_acct.fail ? KSFT_FAIL : KSFT_PASS; } diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c index 62fcf039d6b7..dad1f62a7ecd 100644 --- a/tools/testing/selftests/mm/vm_util.c +++ b/tools/testing/selftests/mm/vm_util.c @@ -264,3 +264,30 @@ int uffd_open(unsigned int 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 a67db8432855..2edad3256271 100644 --- a/tools/testing/selftests/mm/vm_util.h +++ b/tools/testing/selftests/mm/vm_util.h @@ -51,6 +51,7 @@ int uffd_open(unsigned int flags); 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_get_features(uint64_t *features); /* * On ppc64 this will only work with radix 2M hugepage size From patchwork Thu Mar 30 16:08:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 77315 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1268303vqo; Thu, 30 Mar 2023 09:48:32 -0700 (PDT) X-Google-Smtp-Source: AKy350YMU0K04YND1yFJqBZBGCVKuEKTDTg32LYCA99E51HxJMEWrf8f7LEfuDeDjA9AK3im3w+l X-Received: by 2002:a17:902:ced0:b0:19e:7a2c:78a7 with SMTP id d16-20020a170902ced000b0019e7a2c78a7mr26510607plg.57.1680194912277; Thu, 30 Mar 2023 09:48:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680194912; cv=none; d=google.com; s=arc-20160816; b=ohwyLNjl5aDthdeLWnMnD9e+cNyDfQytMOr9kKmbt9uyc9iyL3LA4rKo6TxpaQWMZl HAo+/Y0VO6xRtjvkqwh2IRyP872aWg28tmgWqEzAShLIBR8mdQ3663NKMxRnH3E+sAJa qnufF7V7XTv7Y1GbbdtPCzaRQRrNc0fA1NSbMbChBJrd0nOFAFOOmtBltRyj7UcvxhFx 51YNiqMnlAf+zC5ZCgv2lJP5DDUl921kj7jzxYZhf2nfEp80Cucbzxjn1uXoGvfP7yRR jbF7LErMZz6A3C3bfPmwABgdDabz8hHP04oh5OfIKVUCKwGgTD2r40knwrRkqrBTwH9/ Y91w== 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=xLgapT9bBZ+99GDEmTuONCJOEOezrqQqmgr0JZLPIac=; b=bQmPAr2eGOKm0+XIct7VTHAi5khNXoeMg7Kj8HXOvvmkppzTjaKCnT8anebWlpcPFf ZG8HcEU5Ny+/tKoHqmicLlQS1kvgDlUptDq4gzy1U6u2lUVAThJDErsUc/+aqwYNW6Fj 2aGIge1dm6QS7sIaH6X6RxlWMp97ARtpgXomP31DS/bM3+/NWG6mr5jM1YvBihwC+jA4 7C1gHEblMbMS6znp4tZxIuHxpjBJiHfrAtXgLfQPB9oVYGVkAb302+jPVWlNCO5INqBJ A8IheTsAOcgTd+ML0NPQ/EhG1sQKc5MN6Up1VfnVF1h5L3+JAoyGCEqDHu6ubJjSNSsc PvkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="a0sId/HV"; 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 q9-20020a170902b10900b001a2927c8068si1018578plr.47.2023.03.30.09.48.18; Thu, 30 Mar 2023 09:48:32 -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="a0sId/HV"; 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 S231494AbjC3QOY (ORCPT + 99 others); Thu, 30 Mar 2023 12:14:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231464AbjC3QOM (ORCPT ); Thu, 30 Mar 2023 12:14:12 -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 BDB8DCA38 for ; Thu, 30 Mar 2023 09:12:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192721; 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=xLgapT9bBZ+99GDEmTuONCJOEOezrqQqmgr0JZLPIac=; b=a0sId/HVntJvqmvj1xhIsStpL06UAbDLLaheLvHi9JUyjCpZEccDGWitB5xPifoKF+iDKY lO8PKxRb4VNw/RHyZJ1F5881xB060JCvV7XwtKByKTPS5lYdrMsVs46nUWLyahoVbONeqr K+oiirO5QmM+bygspWAiIz0tqODO1Mo= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-473--dOnVvYINDaGzQOlJNFGIQ-1; Thu, 30 Mar 2023 12:08:25 -0400 X-MC-Unique: -dOnVvYINDaGzQOlJNFGIQ-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-5aae34d87f7so13017296d6.0 for ; Thu, 30 Mar 2023 09:08:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192504; 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=xLgapT9bBZ+99GDEmTuONCJOEOezrqQqmgr0JZLPIac=; b=rxwLcWXDrpZR0sZSqYsivGhshIiFBM5QU2sIKfZ5aOb5bexBhpAa0gjY8ucMOATU5D OL535sXkhSVRIUfcPwf49K1BKVzKARzM7gq09iawOrs0KK/d503NWiVYr81d85Px9V17 9lPVrF9wYT9Wzx/l4AW06m98bGWwN6apVRyYpx2Otp1j/IPBUJ5uMF+qcgldq2LuTEt6 VmrdaDAn09d7UOl8S7AKpgsBfKvtcsU7OWAwFQyMrjE4C5LY9/VsjRormf4x/K9RN8zY GOCl+REweYb0p/ABbLCKutX7RhN5R0n0pZ3JinrjLxaO6qjnSrhHLHz0FO0giqZYWvdq jYLA== X-Gm-Message-State: AAQBX9d3UJH7Gzymisyoc4ok7DFXgPwvcMb9LwHRzEROkeuxR5do2Q5u mEp50bmC8e9B/rzNucOb70jZO7lCaeXr5k4XsvcNheba+y21w5frYSYX8csDTSw2p3B8Y/6bLzl UB22HVSWl5Weq1M/F7bR9vcrcRZdXmQUri3zQu12QcZuRXHI3AxfgakD6t1DEhhzxqPKSulpTQU P4g4qV4w== X-Received: by 2002:a05:6214:4007:b0:5da:b965:1efe with SMTP id kd7-20020a056214400700b005dab9651efemr3648524qvb.4.1680192504348; Thu, 30 Mar 2023 09:08:24 -0700 (PDT) X-Received: by 2002:a05:6214:4007:b0:5da:b965:1efe with SMTP id kd7-20020a056214400700b005dab9651efemr3648464qvb.4.1680192503778; Thu, 30 Mar 2023 09:08: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 on15-20020a056214448f00b005dd8b9345bbsm357979qvb.83.2023.03.30.09.08.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:08:23 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Mike Kravetz , Mike Rapoport , Andrea Arcangeli , peterx@redhat.com, Leonardo Bras Soares Passos , Andrew Morton , David Hildenbrand , Axel Rasmussen , Nadav Amit Subject: [PATCH 22/29] selftests/mm: Move uffd pagemap test to unit test Date: Thu, 30 Mar 2023 12:08:21 -0400 Message-Id: <20230330160821.3107558-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230330155707.3106228-1-peterx@redhat.com> References: <20230330155707.3106228-1-peterx@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=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=unavailable 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?1761812060160340362?= X-GMAIL-MSGID: =?utf-8?q?1761812060160340362?= 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. Signed-off-by: Peter Xu Reviewed-by: Mike Rapoport (IBM) --- 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 70cb0619354e..50738a993afc 100644 --- a/tools/testing/selftests/mm/uffd-stress.c +++ b/tools/testing/selftests/mm/uffd-stress.c @@ -671,157 +671,6 @@ static int userfaultfd_minor_test(void) return stats.missing_faults != 0 || stats.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; @@ -933,21 +782,6 @@ static int userfaultfd_stress(void) uffd_stats_report(uffd_stats, 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 007145063363..bcd67bd4ec90 100644 --- a/tools/testing/selftests/mm/uffd-unit-tests.c +++ b/tools/testing/selftests/mm/uffd-unit-tests.c @@ -200,7 +200,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 Thu Mar 30 16:08:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 77314 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1268040vqo; Thu, 30 Mar 2023 09:48:04 -0700 (PDT) X-Google-Smtp-Source: AKy350ZKF7jW65Sv8iarifEcX+GbZAbMqnih8UqxOwnQwsZKjdxBBM0J5YKzythNjgvZtmKZvpx6 X-Received: by 2002:aa7:9d9d:0:b0:62d:cfd3:d697 with SMTP id f29-20020aa79d9d000000b0062dcfd3d697mr2330327pfq.26.1680194884552; Thu, 30 Mar 2023 09:48:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680194884; cv=none; d=google.com; s=arc-20160816; b=HoGMANs9hq8K55noCA0aoYTw4mNR49GC/2To74Ly/J2Y2Ssj6w6GZA/xkTNPdPIlq+ UV6Au+jBvHmarW8TTk3Pk931edPhnVEHhawdf4dka2NxWKxZq2OsMiD7Pmm19tOfj1iR /+T4inShvFA+qwyo7t0M7cm7E9Dbyr+jHilpDu0bH3+T4kImPwOAxvmbNxSqnokSEdKD WpYSJoyGdEt/j+QfpteKVV5sNKC9frd2TK7zGxMeMGk6mEQVKBkx9BjUC1QdGVzMvclT i4EL43a3UrmySwUwLEtJCDzmBQkDfNbn69wFfN606+uIH0W4lGiQZDDdFbJ8Gq94IcUD dJjQ== 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=FYl/6yS5UtVMnAaCmSItplLGUyy4Ed+8ZQVGZ0RDCPU=; b=aJ6w03ye7//wn8a3796rV1Py3fBjDI2JvpefH6YZh7w4fUA7gkMhy+S1r/5xWcT95n zW1xBD8AhGOfn7nxlPn12AAR545WTJzyL6lEnQm4ZyCxgsVSgSyQxXsApv7N6ZcA0O40 9UFhBO7PGfY7RFcPyZJSDslqPKgz6GCtOJo/+Jawv3jNNHofoqJEAzJTMI4eaPIXAcaf oMc5amxGDpgK9RvYGKuxgZ6OUMkU3aPjLyCcjCf7ove35UZSYcDICnZq3KA6SNMmnThQ pMZRK3ulVhMMtsl3VeKcN/cV66hbgK7uyJTs+XT1pbTFXnynygCjqY3tqSJ7Z/ZJk/9T Jqjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="PAc39p/O"; 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 g78-20020a625251000000b0062ae6345c74si131591pfb.399.2023.03.30.09.47.50; Thu, 30 Mar 2023 09:48: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="PAc39p/O"; 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 S232055AbjC3QKf (ORCPT + 99 others); Thu, 30 Mar 2023 12:10:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232109AbjC3QKO (ORCPT ); Thu, 30 Mar 2023 12:10:14 -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 DFE24C667 for ; Thu, 30 Mar 2023 09:09:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192510; 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=FYl/6yS5UtVMnAaCmSItplLGUyy4Ed+8ZQVGZ0RDCPU=; b=PAc39p/OUbtamE99OvPV62MzJZarmCjJT6ecbtGbTnP2IfQVWv5nNXM9hzdV+mcqiITihN W6nc5fYqWS90ID7JDc4oxjeLGWcgN4BPVHpExheM9yDjHElDOD/dhMjLtPQDMuJCxhn8WU IRdc20iGIAlIuVECwuUQ0sbW3+qgRyg= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-629-7JwnABFAP66jIQyhbBXMWQ-1; Thu, 30 Mar 2023 12:08:28 -0400 X-MC-Unique: 7JwnABFAP66jIQyhbBXMWQ-1 Received: by mail-qv1-f72.google.com with SMTP id y19-20020ad445b3000000b005a5123cb627so8420451qvu.20 for ; Thu, 30 Mar 2023 09:08:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192508; x=1682784508; 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=FYl/6yS5UtVMnAaCmSItplLGUyy4Ed+8ZQVGZ0RDCPU=; b=UF2HwBC0cexUTBfWj0zm4UmxfPBMpgNq/HQow85ZwEdju3hEMzYoDWYwnQIX4+EyNg OoUqS2EIpJ8sMi4xFKc+mHns4A1OHKBdxbkgucF8t1JQPeBlf3cYLKWIoan9lMCDt7BP 2XkuKxR7uv/QTQd/9/OmqguQncxhumrrMptcXb0sN9hIrOiuMsPiQ0bpA4E4tL64UMvf xU/LEO1LCsN399dXTyqddHmAbUsD103YzFgBkYypeXPd6HW35n5nxxx1g7j5zIrSG5ae nFaJL6dNfwtNSs5Tu6zbodUOJXH4V3LND+UdX5dXkTWHH7id7y2S5iE3TuVhH47Hl7li AM7A== X-Gm-Message-State: AAQBX9erkwZvkVU+7LKhS5fg5QPUtADij7vboq/px7SbnXyPNhocb1WX hcOtFqKxu/ovQAHlp79urUVxEdkiwi+petKOh3LoLB+hAcKwwDDGqxwzAJ/xlGT5eOMMHalpci2 m3x3A5mr5jUlAfGvgX1utmSHtDycQODZXJg8i+IPYsp2HGxxS/FVR0LM8Qyd6JBuihsIbZaF8Zc JqzfPOFg== X-Received: by 2002:a05:6214:300f:b0:5da:b965:1efd with SMTP id ke15-20020a056214300f00b005dab9651efdmr36932473qvb.2.1680192507646; Thu, 30 Mar 2023 09:08:27 -0700 (PDT) X-Received: by 2002:a05:6214:300f:b0:5da:b965:1efd with SMTP id ke15-20020a056214300f00b005dab9651efdmr36932407qvb.2.1680192507098; Thu, 30 Mar 2023 09:08:27 -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 r6-20020a0cf806000000b005dd8b93457asm5582943qvn.18.2023.03.30.09.08.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:08:26 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Mike Kravetz , Mike Rapoport , Andrea Arcangeli , peterx@redhat.com, Leonardo Bras Soares Passos , Andrew Morton , David Hildenbrand , Axel Rasmussen , Nadav Amit , Zach O'Keefe Subject: [PATCH 23/29] selftests/mm: Move uffd minor test to unit test Date: Thu, 30 Mar 2023 12:08:24 -0400 Message-Id: <20230330160824.3107569-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230330155707.3106228-1-peterx@redhat.com> References: <20230330155707.3106228-1-peterx@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=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=unavailable 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?1761812031306630298?= X-GMAIL-MSGID: =?utf-8?q?1761812031306630298?= 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 ae6b61144b53..95ad619d0df4 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; @@ -126,28 +126,27 @@ 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); if (*alloc_area == MAP_FAILED) err("mmap of memfd failed"); - 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, mem_fd, offset); if (area_alias == MAP_FAILED) err("mmap of memfd alias failed"); - 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 51ec75f6d0c1..16d32ddf8412 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 50738a993afc..49fa61e5c54a 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"); @@ -585,92 +581,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_stats stats = { 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); - } - - stats.apply_wp = test_uffdio_wp; - if (pthread_create(&uffd_mon, &attr, uffd_poll_thread, &stats)) - 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(&stats, 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 stats.missing_faults != 0 || stats.minor_faults != nr_pages; -} - static int userfaultfd_stress(void) { void *area; @@ -783,7 +693,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) @@ -798,13 +708,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; } } @@ -822,8 +729,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); } @@ -831,9 +736,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 @@ -855,8 +757,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; @@ -873,7 +773,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(); @@ -885,36 +784,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 bcd67bd4ec90..ecb8ba658736 100644 --- a/tools/testing/selftests/mm/uffd-unit-tests.c +++ b/tools/testing/selftests/mm/uffd-unit-tests.c @@ -332,6 +332,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_stats stats = { 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); + + stats.apply_wp = test_wp; + if (pthread_create(&uffd_mon, NULL, uffd_poll_thread, &stats)) + 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 (stats.missing_faults != 0 || stats.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", @@ -346,6 +443,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 Thu Mar 30 16:08: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: 77306 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1254133vqo; Thu, 30 Mar 2023 09:27:38 -0700 (PDT) X-Google-Smtp-Source: AKy350ZP3EwsTqTgCNAdKIBje/S+RNLx3g4gVumzOziACzpBZAP4WMwlsEFM9hptli6iC10Jk5yW X-Received: by 2002:a17:906:4787:b0:933:89a1:57e6 with SMTP id cw7-20020a170906478700b0093389a157e6mr32168910ejc.26.1680193658062; Thu, 30 Mar 2023 09:27:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680193658; cv=none; d=google.com; s=arc-20160816; b=DV/Eu0bQjNCf17TVc0h9UIaBFoBwOJwQ9J5uLnlGggerSLJKH9Lb1vQWcE2TJ06zsS CatjRwVmwrAyZRMyGulzjGw3Fwaf8JzUoBOJpHXFuyH+bq3lEHBgVafGfaEz3RyW8px7 B7soD0gbFdt9aeKVfQYV92YWRWIm5nl58a7hvWOIOVbXY9H1WUNAdUE6JprzL+v1m91S jFry3rEMLW88+M57eo/YkwfjGZETy/hh4fxAZeK9CwrKd7egRhzt5GDlWXaKWQoz/NCe 6tGzybN1S2L93h/o6FZz3p5U7RV9b2RvH9AS0en+02x+rooAU1GsVVly1iX58o0h7TX+ Vf7Q== 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=oTM5xtnArxH9EHNqMOFW/9fpO7KeYtGodOd2BXmVLVI=; b=fFCjvyWALBrq5Vd2r5/JujwMBvOT53PvRcq27N/8jvmRLvEJG4fRwJDpnhawji0Rrc b+K9eReJE1FGOz5SoEgcY8SUdXJBUrfunlLfNE6SaNZnjijU2Rs3Mzpx3R2WQIjtRoLs ehSA/Wm8WuMh1Rtii0rFW2OreSlz5QzFic2ukdNDNvtAKsfeoGJg8g9cFCpwaJET+xFM 1zC/BMJ6BCRH2rq5WVq2yncKk74KFAGY9wrm3jMSIMhL5iVB/FSC3E/GjsCJvl8bmbPy CisNO08xKr1+OJKJDDwpMNbg5Kenybu6qh7ImsJvLNd35U99pPpr7C2dGnZXis4gD38+ GaGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SDTLvsUc; 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 r10-20020aa7cfca000000b004a18f2ffb81si121180edy.321.2023.03.30.09.27.12; Thu, 30 Mar 2023 09:27:38 -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=SDTLvsUc; 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 S229436AbjC3QKa (ORCPT + 99 others); Thu, 30 Mar 2023 12:10:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231873AbjC3QKO (ORCPT ); Thu, 30 Mar 2023 12:10:14 -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 423CDA25A for ; Thu, 30 Mar 2023 09:09:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192513; 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=oTM5xtnArxH9EHNqMOFW/9fpO7KeYtGodOd2BXmVLVI=; b=SDTLvsUcY7iVfkJHxCTyLiYbyRT6r8AIagBTkN0Sut/j65SmgY/+P9n9XhQ3EuB8C4aW1X 1ekhhTH7RestBx+ZOlhT5XHO8BG2T+OnWEokvSrBDRuXl6WSjuKbueXSDV/+SBoYp+8D7E /7Mb3mqIIADJy4vJS2lDZUiL9/sOMYs= 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-401-XOZYRgdAMlqLt9gBC6VKvg-1; Thu, 30 Mar 2023 12:08:32 -0400 X-MC-Unique: XOZYRgdAMlqLt9gBC6VKvg-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-746bae78af3so60183685a.1 for ; Thu, 30 Mar 2023 09:08:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192510; 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=oTM5xtnArxH9EHNqMOFW/9fpO7KeYtGodOd2BXmVLVI=; b=7qXZVxffRayvF1hD9yN5YGoUHcazYUjgKn2u1oe0jQqmUnxuvtvW4V0YwtDZTQqU36 VO2dvG5nzBkolDa6UyQ4/YxPZbaWvhXxXN1NXpiePKLzNnP4sZta09DKg7jkRSOgWyeP GwDJ0o0BA1rbs/E/mpOAYZMCo05FjZwlflGG8nML71AGrIs0XXKn1dLV5rqpO35hD/Rm opaLFtqNwp9xqiDa2nEegttt9lKYZAe7yVjhod7McdoQ+03dl/iOIGbkpsVxyjXGAs3N D5+/t4VQqNIW/jU1KVUGW7KPDk65EWMoCipUftC+8A70VAhZaOwxksNscC89vC/C5ss7 p5lQ== X-Gm-Message-State: AAQBX9c3QEMmzSRyNGhtcdr25EGyxY35l7ajlCfzuLiCF/BrDbBjC1lc NXRsokApu0DhfhV2k3L2+Fqugkn9qDn18YoEhtD22XWMrdweaFMDuUMSwFnXEwMNjsS8suG4gm1 wn8spP0tHDNX4j7vIPlOtHdnoGL+nZK0F/Hdrt1gXNuE+qnywjvTG2vC3HPUDAchIcExr2KX+hI N/M02gTA== X-Received: by 2002:a05:622a:1aa1:b0:3e3:8e1a:c30b with SMTP id s33-20020a05622a1aa100b003e38e1ac30bmr4584678qtc.1.1680192510217; Thu, 30 Mar 2023 09:08:30 -0700 (PDT) X-Received: by 2002:a05:622a:1aa1:b0:3e3:8e1a:c30b with SMTP id s33-20020a05622a1aa100b003e38e1ac30bmr4584621qtc.1.1680192509724; Thu, 30 Mar 2023 09:08:29 -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 n14-20020ac8674e000000b003d65e257f10sm8616359qtp.79.2023.03.30.09.08.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:08:29 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Mike Kravetz , Mike Rapoport , Andrea Arcangeli , peterx@redhat.com, Leonardo Bras Soares Passos , Andrew Morton , David Hildenbrand , Axel Rasmussen , Nadav Amit Subject: [PATCH 24/29] selftests/mm: Move uffd sig/events tests into uffd unit tests Date: Thu, 30 Mar 2023 12:08:27 -0400 Message-Id: <20230330160827.3107580-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230330155707.3106228-1-peterx@redhat.com> References: <20230330155707.3106228-1-peterx@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=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=unavailable 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?1761810745215985312?= X-GMAIL-MSGID: =?utf-8?q?1761810745215985312?= 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 | 263 +++++++++++++++++++ 2 files changed, 264 insertions(+), 226 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-stress.c b/tools/testing/selftests/mm/uffd-stress.c index 49fa61e5c54a..f3046ae13a90 100644 --- a/tools/testing/selftests/mm/uffd-stress.c +++ b/tools/testing/selftests/mm/uffd-stress.c @@ -274,133 +274,6 @@ static int stress(struct uffd_stats *uffd_stats) 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) @@ -484,103 +357,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_stats stats = { 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"); - - stats.apply_wp = test_uffdio_wp; - if (pthread_create(&uffd_mon, &attr, uffd_poll_thread, &stats)) - 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(&stats, 1); - - return stats.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_stats stats = { 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); - - stats.apply_wp = test_uffdio_wp; - if (pthread_create(&uffd_mon, &attr, uffd_poll_thread, &stats)) - 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; @@ -692,8 +468,7 @@ static int userfaultfd_stress(void) uffd_stats_report(uffd_stats, 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 ecb8ba658736..ebf45cb0eca8 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; @@ -429,6 +432,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_stats stats = { 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); + + stats.apply_wp = wp; + if (pthread_create(&uffd_mon, NULL, uffd_poll_thread, &stats)) + 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_stats stats = { 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"); + + stats.apply_wp = wp; + if (pthread_create(&uffd_mon, NULL, uffd_poll_thread, &stats)) + 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 (stats.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", @@ -466,6 +700,35 @@ 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, + }, }; int main(int argc, char *argv[]) From patchwork Thu Mar 30 16:08:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 77302 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1252739vqo; Thu, 30 Mar 2023 09:25:37 -0700 (PDT) X-Google-Smtp-Source: AKy350aSSy3Nwk4Oiu4vjLXMKuyl36oWgA9EspQE9zN509HM75/PJfdXkIt6o7IbKVixPR4uVotT X-Received: by 2002:a17:90b:4d86:b0:23c:fdb9:b528 with SMTP id oj6-20020a17090b4d8600b0023cfdb9b528mr27122804pjb.27.1680193537646; Thu, 30 Mar 2023 09:25:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680193537; cv=none; d=google.com; s=arc-20160816; b=gVdjqleWzSnKPA4o6dfjb1jNTOaHYjVWebtX6Irfw/9T7lk0Q5pvyPonLenHBu+TP1 35c8vdbU5HinMsTB16U7Ww40+nmubnA49xk1DQKdG3SiWXVZ0w5BG0AvgVB6ziUiwi8A uL4hmYM1mOt1SHKZHKQUH0sVxzdnw/mReYH0qB8Eifb2yAO09zjucwPYJ1xFt7kAQBLt Sn2RDKicbFiR0iiwowZu3wiLvv+O1Q/wuPAKpokLCt5NDQzL73BOjB4r9GZ0YeqoYuAZ iq8cki0OG+noIFOWlt5sB9hFt7rENnXnYhGobNtnIUMYdCkAvpoICu5Jm6AEXUu2qxUp 73sQ== 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=Roeuk409dPF2L2QvtyDeIj99sNqVdIN74Z+r6aghdT8=; b=WtmcI/qFk1JFH6tzJoPjt6+9Y6xfr3SSdEYAkLDYks6aUi08zTPLs5UfWw+FF01S+l 6mGi5e7BM65NBkHv/MLysjcwPnT7a/etIKqzz759VW2DHiToAUo54OIwBdKxCxyVNw71 C/37wpFmIGPADlVJ+OEpLpSAWJL1QDJP+PiwGC3ScP4nYmCBskjavSvaXn0O5RYMJwp5 TKe+n/bdujWKwQZpMcHoBkf588po6Ed4cBguWbl/SxlpuiZDTcGXNDMxu7I3R9wez3JH R96x7EaAnK1Oe88Jc2pMy/KIqOMEQ/u7FsgYRN4JRkeeQC6krmA4bvaNxx1T9Zp22vK2 dUQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QI8EXuMu; 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 x11-20020a17090aca0b00b00233c5363cdcsi1586911pjt.142.2023.03.30.09.25.23; Thu, 30 Mar 2023 09:25: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=QI8EXuMu; 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 S232291AbjC3QK4 (ORCPT + 99 others); Thu, 30 Mar 2023 12:10:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231431AbjC3QKZ (ORCPT ); Thu, 30 Mar 2023 12:10:25 -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 14CE2E192 for ; Thu, 30 Mar 2023 09:09:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192515; 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=Roeuk409dPF2L2QvtyDeIj99sNqVdIN74Z+r6aghdT8=; b=QI8EXuMuCOyJ/kvc3umd6ObUulcgKJ+NOMU8WW04rxPDNT9FOw0mczyUNCAMDxC3m6fjpL meaUBS2+w+BFyNvuwB8xApne0qc9/tMRXXbVa1u8sCqs7bLtSBMHT35/E5iXa/Da5AF1YG +tu01Rtp3vC/jWMGCqTGRTX0FOWAAjI= 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-630-7jHPJga7OUOvRWmxRCvmVA-1; Thu, 30 Mar 2023 12:08:34 -0400 X-MC-Unique: 7jHPJga7OUOvRWmxRCvmVA-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-746bae78af3so60184885a.1 for ; Thu, 30 Mar 2023 09:08:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192513; 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=Roeuk409dPF2L2QvtyDeIj99sNqVdIN74Z+r6aghdT8=; b=IZorTI/m1ksi98iKVUZnIYNKKvnPsjajDCakD07phMGjegZ62ecrykF0AsPcZUAqm6 mEMpiqkb1EPHnJGAxwr+lmkKvJImmPCxKjjGij793AcvScO1K8QL4t021gJ4TqKhCr/f VZpz9fZTydQSX+sdswleJrBXRMzzxF6G3/QLXlBWQ5TrYsnfPaF33D9UKj9NaEuvCAhb /AMDlL6Awj6NPff95+VwItnpDNp1z5DWunXysopI7AvausEpKuZ0jPJNGhx6IG801sHH 5v0A+4TusLLj9Hfm3ISaR6BBDG7lzRgpqPK3t4CDRcEeHwVH4Oo3Hp9WOy9bGrl9Az+b gcYA== X-Gm-Message-State: AAQBX9cfpPyVVtlQ+jur69pVvW3n5pvrLMBuNShnsTbx5dsSKqRLWPLS ovGOm8dF9JSyW/jIfIJ80tj1qPWzCaIG3+BxzWI/UrD4JF4A745fhjPJQd8jiA3BXzXYML/Ochs txEBkbfXeKWdLVWnJoezR92Tm//aQOasRBeH53xsDlXrUv89+7OKIT3dFwFbpqjm8DgmL+sPMLk z2CGfUzw== X-Received: by 2002:a05:622a:199a:b0:3e4:eb39:eb8b with SMTP id u26-20020a05622a199a00b003e4eb39eb8bmr4380210qtc.5.1680192513186; Thu, 30 Mar 2023 09:08:33 -0700 (PDT) X-Received: by 2002:a05:622a:199a:b0:3e4:eb39:eb8b with SMTP id u26-20020a05622a199a00b003e4eb39eb8bmr4380140qtc.5.1680192512678; Thu, 30 Mar 2023 09:08:32 -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 s13-20020ac8758d000000b003e4e1ea3cb5sm3925874qtq.51.2023.03.30.09.08.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:08:32 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Mike Kravetz , Mike Rapoport , Andrea Arcangeli , peterx@redhat.com, Leonardo Bras Soares Passos , Andrew Morton , David Hildenbrand , Axel Rasmussen , Nadav Amit Subject: [PATCH 25/29] selftests/mm: Move zeropage test into uffd unit tests Date: Thu, 30 Mar 2023 12:08:29 -0400 Message-Id: <20230330160829.3107591-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230330155707.3106228-1-peterx@redhat.com> References: <20230330155707.3106228-1-peterx@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=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=unavailable 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?1761810618949805437?= X-GMAIL-MSGID: =?utf-8?q?1761810618949805437?= Simplifies it a bit along the way, e.g., drop the never used offset field (which was always the 1st page so offset=0). Signed-off-by: Peter Xu --- tools/testing/selftests/mm/uffd-stress.c | 94 +------------------- tools/testing/selftests/mm/uffd-unit-tests.c | 94 ++++++++++++++++++++ 2 files changed, 95 insertions(+), 93 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-stress.c b/tools/testing/selftests/mm/uffd-stress.c index f3046ae13a90..a6f3609c1ad1 100644 --- a/tools/testing/selftests/mm/uffd-stress.c +++ b/tools/testing/selftests/mm/uffd-stress.c @@ -110,15 +110,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; @@ -274,89 +265,6 @@ static int stress(struct uffd_stats *uffd_stats) 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; @@ -468,7 +376,7 @@ static int userfaultfd_stress(void) uffd_stats_report(uffd_stats, 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 ebf45cb0eca8..376dfa320b6f 100644 --- a/tools/testing/selftests/mm/uffd-unit-tests.c +++ b/tools/testing/selftests/mm/uffd-unit-tests.c @@ -663,7 +663,101 @@ 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; +} + +/* exercise UFFDIO_ZEROPAGE */ +static void uffd_zeropage_test_common(bool has_zeropage) +{ + if (uffd_register(uffd, area_dst, page_size, + true, false, false)) + err("register"); + + if (area_dst_alias) + if (uffd_register(uffd, area_dst_alias, page_size, + true, false, false)) + err("register"); + + if (do_uffdio_zeropage(uffd, has_zeropage)) { + int i; + + 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 * nr_pages)) + err("unregister"); + + uffd_test_pass(); +} + +static void uffd_zeropage_test(void) +{ + uffd_zeropage_test_common(true); +} + +static void uffd_zeropage_hugetlb_test(void) +{ + uffd_zeropage_test_common(false); +} + uffd_test_case_t uffd_tests[] = { + { + .name = "zeropage", + .uffd_fn = uffd_zeropage_test, + .mem_targets = MEM_ANON | MEM_SHMEM | MEM_SHMEM_PRIVATE, + .uffd_feature_required = 0, + }, + { + .name = "zeropage-hugetlb", + .uffd_fn = uffd_zeropage_hugetlb_test, + .mem_targets = MEM_HUGETLB | MEM_HUGETLB_PRIVATE, + .uffd_feature_required = 0, + }, { .name = "pagemap", .uffd_fn = uffd_pagemap_test, From patchwork Thu Mar 30 16:08: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: 77310 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1264028vqo; Thu, 30 Mar 2023 09:41:30 -0700 (PDT) X-Google-Smtp-Source: AKy350bmRhjQTu93hKY7BXHBafH1jdXY0lZnkvs82TKvnJeEkT4xiob23pX0nJ3iOT2TbdtyLK8O X-Received: by 2002:a17:902:ecc6:b0:1a2:23f7:20f with SMTP id a6-20020a170902ecc600b001a223f7020fmr26600440plh.28.1680194490198; Thu, 30 Mar 2023 09:41:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680194490; cv=none; d=google.com; s=arc-20160816; b=PbrS+OR//B9+EvVONAFQYO8mKVmh3N94NQWU8FcCxkQtEu2WfhiHDXTLYi9NwX4hW+ nm2Cnz6NWnMxhI1ns1ccZIZ6ZxD3wjqDPfXjNQSLsSpwouEkKyHcKC4DypzfckHqW4AN v3DkeQ/Yei68ZFVD5EyvP1FIAA7MqmZLX518wFI2vvfcuNNfoD68O+v11lDa8col4MfR 3oz+Sd4uO7i/NZ7tdWvEXur7TKK4whxSv7HI8NLw9+nJTg+XBRbSC0BbHpKTTXu/polC d9bjEFNTBpUmE+2wcPfOg5F1qdiReyRfX87pm8cK/+DmaWoc0IaEkBxk6vOvEeqb3SQw f+bw== 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=IPQaNGX43g5m/+6Rf9W/FOC5JWY5QcIX+G5qmLnnQxA=; b=n4lpX8195Dg33C4RBbTXCnT8x1tRkzHdiFUDJ95Qk2xUC6xNjZnoVNAwvUe1puVn/Q juC/AFKdIQZhRe0onciy6WYBnGpXI08gQdWr0/lgkhTfwxeH50tQ3VUrC9SvLWLTpXWm S+yHZ0q8IoaspxQWCenSgVekVK5Smhn5BS4RMC7ldeKU0ZoB96nT4LxRb2WubzByWaEM IVvYptUGPjIIx86dGf5Ghz+VYvxltmOx4eKzaQRZXSLxZjgiUWCFKjp7Y5gaYV04ECv6 uwOLMrYa7LVB2lvzGUq82Z5IoA6jPoa/RmiTLBahCEpLuZgLu/pzp7OfXVzPO70hLDyl eH5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Hb+5TF64; 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 ja5-20020a170902efc500b0019cf1bde932si33522266plb.35.2023.03.30.09.41.15; Thu, 30 Mar 2023 09:41:30 -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=Hb+5TF64; 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 S230088AbjC3QLu (ORCPT + 99 others); Thu, 30 Mar 2023 12:11:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230030AbjC3QLn (ORCPT ); Thu, 30 Mar 2023 12:11:43 -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 63BF9D329 for ; Thu, 30 Mar 2023 09:10:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192519; 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=IPQaNGX43g5m/+6Rf9W/FOC5JWY5QcIX+G5qmLnnQxA=; b=Hb+5TF649nX2wLjYKfDBk6kNgL870K4+ohErg/DmguCOFw5VN2QHAX0qHn/SmU/5Dz2WUD H1X03GNOVBFYck26q83488wDfWpyGXn8Um3T/h1itR4vQnaNqCEcQ1lvnEbrsMpGGs+znw wRj5X6ltaAb6Bz2UyWfye4d99g9UXIE= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-136-4bRmtZ_9Oy6UcYlN6N0lLg-1; Thu, 30 Mar 2023 12:08:38 -0400 X-MC-Unique: 4bRmtZ_9Oy6UcYlN6N0lLg-1 Received: by mail-qv1-f72.google.com with SMTP id w2-20020a0cc242000000b00583d8e55181so8447049qvh.23 for ; Thu, 30 Mar 2023 09:08:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192515; 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=IPQaNGX43g5m/+6Rf9W/FOC5JWY5QcIX+G5qmLnnQxA=; b=oI8EtJWwuYIKClEaZCIknK93SvKXJwzlAuUzJhEsFGT2Yw4AC1OLwQWEoaeeSdZ/QB ghGzfOC3qvOxlVGVuzWy7f/HtWg7YQggCzXJlM4AOck0XniIQvryfcSAT3VIGYAY2SwW 6hcU0B3dpX+8RSgLqGtmVohs/svzwmvlJboT++TfAWRo4S/3EYrX2HUh+/QbtmSwJ6p5 bcOv+onr7h3QMrVG4nByzIPSmxC78gjUa9gXS1j5k+Xu6URJWgtj6sdWeOjSHMeCymRG dX0duquv4aVa1FY4+6/5CxXMJEcGghBwE8+0tf/ReJAV8v9S3WxgbncEQkQApNWqerpt +Vrg== X-Gm-Message-State: AAQBX9dctWoPThzTgmdfXRcpii/woOldLkAywXwZXJ4vzQnUrwDv6nxi 04HgTBDnAM1ng0BPSPaSLEBNOxsbX03ggl+QEOaF4J6/16j3T1L+zh1zxhfI88eXGtrr+7r+Hup 923OBX2v5xxASxmKreHVJibsJjAA8Y7OoZ4VoA4HEW8s1AhpGJC6Zb+Q4vrrGmFch5AtAZYnGNY dqKBMbiQ== X-Received: by 2002:a05:622a:1894:b0:3e4:d3cc:4211 with SMTP id v20-20020a05622a189400b003e4d3cc4211mr4416059qtc.3.1680192515384; Thu, 30 Mar 2023 09:08:35 -0700 (PDT) X-Received: by 2002:a05:622a:1894:b0:3e4:d3cc:4211 with SMTP id v20-20020a05622a189400b003e4d3cc4211mr4416001qtc.3.1680192515042; Thu, 30 Mar 2023 09:08:35 -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 l18-20020ac84a92000000b003e3860f12f7sm9484075qtq.56.2023.03.30.09.08.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:08:34 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Mike Kravetz , Mike Rapoport , Andrea Arcangeli , peterx@redhat.com, Leonardo Bras Soares Passos , Andrew Morton , David Hildenbrand , Axel Rasmussen , Nadav Amit Subject: [PATCH 26/29] selftests/mm: Workaround no way to detect uffd-minor + wp Date: Thu, 30 Mar 2023 12:08:33 -0400 Message-Id: <20230330160833.3107602-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230330155707.3106228-1-peterx@redhat.com> References: <20230330155707.3106228-1-peterx@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=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=unavailable 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?1761811617632899921?= X-GMAIL-MSGID: =?utf-8?q?1761811617632899921?= 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 376dfa320b6f..82fd3aaa06c2 100644 --- a/tools/testing/selftests/mm/uffd-unit-tests.c +++ b/tools/testing/selftests/mm/uffd-unit-tests.c @@ -784,7 +784,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 Thu Mar 30 16:08:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 77313 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1267762vqo; Thu, 30 Mar 2023 09:47:36 -0700 (PDT) X-Google-Smtp-Source: AKy350ZEiXNK4mpdyL476kTHoLq2KdkDPga5JVLuoM7xL18BpsjGMAECZ538mLtJenvrwNH0j8ch X-Received: by 2002:a17:902:f681:b0:1a2:15af:d53f with SMTP id l1-20020a170902f68100b001a215afd53fmr30326547plg.41.1680194856466; Thu, 30 Mar 2023 09:47:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680194856; cv=none; d=google.com; s=arc-20160816; b=KMB2i9Dvzg3DDcw1wnyXUIv2cIxd/H3K66U5Bb+yrVT4odM8Ye3COFGSlVSdwDk4VY roGS1qvA7w2cokIJsVLTYjS673XWLTSOCQ8LmgesBbVhz6bY55vv24ytzfNHam/zjrlj VULyLIxFJA4AWkTs2MDq2zTehyASht70FJMBjpj+nt6c7sosBW/sBnIcuuKo4LLwN/wG n+SSwfhjyNMuyWE3JM7SmM37l0RXKRyiBY7/2g/pwtcdxK6yP+rDOr3saknNf68ShYx0 n4SnTGUl3yQGa3UiouWq6TZvw88rcEYm6puCqG4X8Njd8fwxQh01T0j+rGHt2FNUB1yd my8Q== 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=WAXTpuab088GPUG02wNB3TGzyfzkRuRXgQ9Q53l/WHY=; b=DXO7vL0CthZX2zEYH3VyajupOffiFSGJ7hkA7DzAR4WTGgmum/pyIp7N6rhhbmcox9 FQDXyeJRIkuH4S6RDyfE18/6KlljvAhEeHsAglEl77NKRubm92LZ7V0HIaZETvOkA4nQ TYbKMUfQnOVWrI7wZfxQ+RoqVwtz6IPrbGiLplpF1tfEe0o6PEIyXKULC5juhJIY3Ocl NZDbdFq2bqq6J5KNFxd3H13agytaEUVpIKyGXo9sDD2W+S0WBndC3EjQPjW3NDrdpF/Q 7JvmCEU/aF0CeajezQVIvrkpMdsYaovjlkIeeENjMrQaOC35QHyIjGn7Bof6RMvC2BOC 111w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VB7afFUa; 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 u7-20020a170902e5c700b0019ca3bea326si37282194plf.269.2023.03.30.09.47.17; Thu, 30 Mar 2023 09:47:36 -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=VB7afFUa; 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 S231315AbjC3QNy (ORCPT + 99 others); Thu, 30 Mar 2023 12:13:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231307AbjC3QNv (ORCPT ); Thu, 30 Mar 2023 12:13:51 -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 BF545E385 for ; Thu, 30 Mar 2023 09:12:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192708; 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=WAXTpuab088GPUG02wNB3TGzyfzkRuRXgQ9Q53l/WHY=; b=VB7afFUazUyUMWehXBjJSeYo5gxmoX1LRFl6c3/W0PMXTE2EUt+Al9tvze6lSs1P6RpKPp 4ESCf+hA+oFfTOf+WlFqrnvrrOZV6pIPdqoU/k8495NHW0pDfaSgVcf97YqcTSKaG3b+8/ mcGSqpNeBtAYrON+Pa6UikLntTVLzxA= 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-355-k_o-mmXtOBmdFnGhVnzVyw-1; Thu, 30 Mar 2023 12:08:39 -0400 X-MC-Unique: k_o-mmXtOBmdFnGhVnzVyw-1 Received: by mail-qt1-f197.google.com with SMTP id l13-20020a05622a174d00b003e4df699997so10555398qtk.20 for ; Thu, 30 Mar 2023 09:08:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192518; x=1682784518; 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=WAXTpuab088GPUG02wNB3TGzyfzkRuRXgQ9Q53l/WHY=; b=KnTjzIF9unyLxhQ2ibFPxHrkI/HysQga9zhpVgj6sDCk4JuEzSF2ZUmswYQ/rEWEUr WiFoHrGUEI2n1O5cc/h3F33qfYOj1LPe3/SszxSMK/B4VmRu42y48lPMVjnMNOnITkPs 7XwQaNKOW269WAhbwj7XE6PPbAqsI+yKoBYgnNYk5s3PXpVevoHGCh8neJrZJprNytio cNKiFc+kco+T4bkYwftpyCSkt9nx5WPKIOV7XHh9dc0w/7s4nRNQvSiPpkRhsWONC3Mb CsqfUsV0olfklBWeNqeY6qo27sVHoVz7XXqF0e9Rt0OqCdHLPaED2iYvdrkcFuIJ5OoD 3e+A== X-Gm-Message-State: AO0yUKWg9EjUCY1FInhAfR82VEgSLaO0pGuX2CTzlz2x+aCDkw+xsPwC lDLR/Z2s6rY0nDCZkEsR+gxDkYs1nTOSs2fFYtZJ1nnn3t3lJy+X3FlP/SMiyuov6AXgEBdVV7u d/1i729XmDFr/ATE1ZjT8zEESKzHPb767OtMerC3j6oePNOJ0TaFYdjjMwtAvTSPNZuQ/PCs+zx tafC79nQ== X-Received: by 2002:a05:622a:3c9:b0:3b8:36f8:830e with SMTP id k9-20020a05622a03c900b003b836f8830emr37735721qtx.6.1680192517937; Thu, 30 Mar 2023 09:08:37 -0700 (PDT) X-Received: by 2002:a05:622a:3c9:b0:3b8:36f8:830e with SMTP id k9-20020a05622a03c900b003b836f8830emr37735663qtx.6.1680192517402; Thu, 30 Mar 2023 09:08:37 -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 r13-20020ac8794d000000b003e638d0aa67sm195332qtt.93.2023.03.30.09.08.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:08:36 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Mike Kravetz , Mike Rapoport , Andrea Arcangeli , peterx@redhat.com, Leonardo Bras Soares Passos , Andrew Morton , David Hildenbrand , Axel Rasmussen , Nadav Amit Subject: [PATCH 27/29] selftests/mm: Allow uffd test to skip properly with no privilege Date: Thu, 30 Mar 2023 12:08:35 -0400 Message-Id: <20230330160835.3107613-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230330155707.3106228-1-peterx@redhat.com> References: <20230330155707.3106228-1-peterx@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=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=unavailable 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?1761812001625274448?= X-GMAIL-MSGID: =?utf-8?q?1761812001625274448?= 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 95ad619d0df4..964fa57b710a 100644 --- a/tools/testing/selftests/mm/uffd-common.c +++ b/tools/testing/selftests/mm/uffd-common.c @@ -225,7 +225,7 @@ void uffd_stats_report(struct uffd_stats *stats, int n_cpus) printf("\n"); } -void userfaultfd_open(uint64_t *features) +int userfaultfd_open(uint64_t *features) { struct uffdio_api uffdio_api; @@ -234,18 +234,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) @@ -288,7 +289,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; @@ -296,13 +297,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 16d32ddf8412..07d00e9809dc 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_stats *stats, 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_stats *stats); diff --git a/tools/testing/selftests/mm/uffd-stress.c b/tools/testing/selftests/mm/uffd-stress.c index a6f3609c1ad1..8f41bef2fbda 100644 --- a/tools/testing/selftests/mm/uffd-stress.c +++ b/tools/testing/selftests/mm/uffd-stress.c @@ -272,7 +272,8 @@ static int userfaultfd_stress(void) struct uffd_stats uffd_stats[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"); @@ -436,7 +437,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 82fd3aaa06c2..9e7f7c7f2982 100644 --- a/tools/testing/selftests/mm/uffd-unit-tests.c +++ b/tools/testing/selftests/mm/uffd-unit-tests.c @@ -175,7 +175,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; @@ -189,7 +190,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) @@ -838,6 +839,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; @@ -863,8 +865,8 @@ int main(int argc, char *argv[]) uffd_test_skip("feature missing"); continue; } - if (uffd_setup_environment(test, mem_type)) { - uffd_test_skip("memory allocation failed"); + if (uffd_setup_environment(test, mem_type, &errmsg)) { + uffd_test_skip(errmsg); continue; } test->uffd_fn(); From patchwork Thu Mar 30 16:08: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: 77305 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1253591vqo; Thu, 30 Mar 2023 09:26:46 -0700 (PDT) X-Google-Smtp-Source: AKy350ZB4F34uZsJtuuI/69N3qcbt7ttM0P4aYXOb4j6zoZLFQE+vBrqrz9Dxv4HUsbR39paHG8s X-Received: by 2002:a17:90a:1c4:b0:234:13a3:6e67 with SMTP id 4-20020a17090a01c400b0023413a36e67mr27507390pjd.12.1680193605913; Thu, 30 Mar 2023 09:26:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680193605; cv=none; d=google.com; s=arc-20160816; b=rojdPxJNpyNwiQnWDh6AoLYgqUq/G4duUfW0E2RP8CSzhv13cArI6wgmpff4QCSyzk lkWBhOgj7nfF6FoIMXob7/C6RNnmG6C0bTXCWWITyxdvg7rzsj2XTXWepUJuC7c8yPgH N5UDKO5QTeY2Eu6PI91SSItCYNm9o4PWb5WQy+X3QDLCY/0xWz/z61b0LLfNWi0MZFIM +QC+ZIelEfem+5dkCjERiikFX+MjSk3phLJkqvilNUNb0QJLx1QuCpyQE19aT7OcemSX xF2Dz106t7F8g7fB5uKoVOhZNYu5fwKiro3t7yPnfZzPMMIymqUaF9I/Bs1SMrv+q1CA yoXg== 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=SqqRZE0+KdLihnYJHNBsrIiryhx5Vgf+EPtUaXiDnEk=; b=j/7rY8PzNNZEem+5viBf0lh1V1+DXRtcYuFMaavcBQwXQywFFgh1wqXHDQB0Pl6CBc CKCbNBr9UveS5NwoRAmjD7A6ETc0dz0H/yWIk/W0SeDobSeAePS0nM6e64P6+Zwkv0eC 4UbWZrZWx847zbVWq+AeeY8vz60SNSH8utBNmnbaIhrS5XRb93aNIqNItJZOEFQIBLvw kjYsWSsMlmN11Ni2dbPbQszxcyGpxSZh/2Qqr3MmWG1L4GnQKUvwlBVUuVB23wbkELwe PYhjDO5/PVNC7m8GeL3AhRJ9vTUj2NL9M+RVGKkES9m0+36MT8CSx+AqgAZ4AYBhYTCz usMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=L5eHCmGN; 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 cx17-20020a17090afd9100b00232dd9ab146si4205545pjb.13.2023.03.30.09.26.31; Thu, 30 Mar 2023 09:26:45 -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=L5eHCmGN; 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 S231381AbjC3QKt (ORCPT + 99 others); Thu, 30 Mar 2023 12:10:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231315AbjC3QKZ (ORCPT ); Thu, 30 Mar 2023 12:10: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 18312A246 for ; Thu, 30 Mar 2023 09:09:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192522; 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=SqqRZE0+KdLihnYJHNBsrIiryhx5Vgf+EPtUaXiDnEk=; b=L5eHCmGN9aKZONvXwVzLZvVBku4igj97ambjCWCDyydGGlC3fz0qZsTZNid5TIO2Lde+Cu 2RZOrJt2yw4CK3x2/hrKSCqc+0O+9O0MebXkaoCUJkmEfvXpJscqcFNZtDmKhvW06T0ywn BrSCV10QS41N5mvQaNK1M+33Y7CqgBM= 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-127-_kFysrE9OqSxhR7S6nOm6w-1; Thu, 30 Mar 2023 12:08:41 -0400 X-MC-Unique: _kFysrE9OqSxhR7S6nOm6w-1 Received: by mail-qk1-f197.google.com with SMTP id 72-20020a37064b000000b007467c5d3abeso9087867qkg.19 for ; Thu, 30 Mar 2023 09:08:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192520; 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=SqqRZE0+KdLihnYJHNBsrIiryhx5Vgf+EPtUaXiDnEk=; b=VPhtgGwZ9G3ieU0fgYkuJ/Jseej+yGMyrxdljORojx+jWZkT0L/S7vuhX5EvW5NqvO 2jN/nXQ3cbHiJelfoeyS5jTl9vpwHZeeOmY4GmkNkF24uJsHsmhOi9B03VQuRZRcsLip I6xvmR67wNGCUaetb4J2E/2Il++wNN8wpirXAEf2lMvEpu2azCLYOV3Fcjab81gSfh+z Z3gh1iWQkuvGTtJHXcItcP4kynlUAUN92TCDKnVtxve17FncTxpf1yeww4ZJ2+5u+9rN y0/8pto2qgfa/jaPSS4ofZF0uwO45tPw7ormpJujWoQkCWQ1AsBDtP/8zG9R7KGWRSi2 gsMQ== X-Gm-Message-State: AAQBX9es6av/VfCQJIxJhBaK9thAqPhitkZtE9Ci77XV5ilkqTtF0+Hr 1dg7KE76ZACMksKGqBbYC7P0mhPsURrqRX90AwiUgerHvImfVjLqBDAKOD2TtRCjyGihVcJ6OCd cg2pvJ166xm9sluYgg0s8+1QQv/d08DmrAc01dZj4sNrI2oRfaEzVesuvO40jVsOzNhEfYwAgl4 lC2S8YxA== X-Received: by 2002:a05:6214:519e:b0:5df:55b5:b1a with SMTP id kl30-20020a056214519e00b005df55b50b1amr3622833qvb.4.1680192520325; Thu, 30 Mar 2023 09:08:40 -0700 (PDT) X-Received: by 2002:a05:6214:519e:b0:5df:55b5:b1a with SMTP id kl30-20020a056214519e00b005df55b50b1amr3622788qvb.4.1680192519977; Thu, 30 Mar 2023 09:08:39 -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 mn15-20020a0562145ecf00b005dd8b93458dsm5543495qvb.37.2023.03.30.09.08.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:08:39 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Mike Kravetz , Mike Rapoport , Andrea Arcangeli , peterx@redhat.com, Leonardo Bras Soares Passos , Andrew Morton , David Hildenbrand , Axel Rasmussen , Nadav Amit Subject: [PATCH 28/29] selftests/mm: Drop sys/dev test in uffd-stress test Date: Thu, 30 Mar 2023 12:08:37 -0400 Message-Id: <20230330160837.3107624-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230330155707.3106228-1-peterx@redhat.com> References: <20230330155707.3106228-1-peterx@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=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=unavailable 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?1761810690425386520?= X-GMAIL-MSGID: =?utf-8?q?1761810690425386520?= 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 af7bbc74cd83..845ce8a48204 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 964fa57b710a..f14bf0941077 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; @@ -229,10 +229,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 07d00e9809dc..f2e2fbb37cda 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 8f41bef2fbda..7461021dd4af 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); @@ -401,21 +390,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 Thu Mar 30 16:08:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 77301 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1252536vqo; Thu, 30 Mar 2023 09:25:17 -0700 (PDT) X-Google-Smtp-Source: AKy350auS1qg2XEpdRgz9ZdkVrnmqAP/y1mOfeBXMl58ewoeKOm2sRFmgsCtC76vauDaePu+3MfF X-Received: by 2002:a17:903:283:b0:19f:e9e7:4cb with SMTP id j3-20020a170903028300b0019fe9e704cbmr29019582plr.45.1680193517254; Thu, 30 Mar 2023 09:25:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680193517; cv=none; d=google.com; s=arc-20160816; b=ycSTETJqcJc1E62AaH1lJAK2GWELQF5FOv8BkUP8V6TYPNUu0naOianRgw8cmFoLzR kthoS4CP/JyEUyO2jyau0vXeh55MzDZ3bAMvpei5Fw5bMqODLDiHEFeB0Fzrazja/go4 WSZRNK/O680W4xYJb94rP0RVQFaiO4BuCZMrNOlDFiuiIxARG+Y5gYfYT4QH3wmFvV2n 4V588oxWldAHRMEedfGmweAj1d+N0xpNbOl1I8HQFGcYC6inBnk6vOWTISkWVIRgnf6U BxEVG46IF9Lqb/DiDDcOESbZ5Wut5h5jc7utVz8r/UAwRyga4i97WAX+7ro1qnF9llMU Cb8A== 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=QgmTtu8OFjFdW8yq7WIzzTW/am1uahC9wawM1FIOBXg=; b=wP1eTrD14bvJ4u7zLeFhHrtg6ItZGVKhhve20vGnv+c65ztdniQ0C4dYUzkbsST5xB rzE95Umad63qbaLL4wAQTGBFMDigsLY/9PUNGdWDx2h0wLOi+YeORyyRpAEPBb59ygxH x4+1FcW69i/yd6S5fbhqRRpJD2ozK2DoeTg0ROaCyJJqREWeBwr2eJdAnWsJeYhwG9Lu 7iP49iba5HhPYsXxJebLRMFRpDwcLkJChZbYsikyP6A2D7RoI+4WzVhY0TEdQmr3mmD1 uIjk0uGAMGd+6FQBwzu6haC7jrSasqgdqL9nSyA0EpcEyggl0Jq/DjPKIE7MVGARSazx oy5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GIFEKQlc; 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 h6-20020a170902748600b001a05652e369si34067763pll.100.2023.03.30.09.25.01; Thu, 30 Mar 2023 09:25: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=GIFEKQlc; 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 S229795AbjC3QKw (ORCPT + 99 others); Thu, 30 Mar 2023 12:10:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231698AbjC3QK0 (ORCPT ); Thu, 30 Mar 2023 12:10: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 3AD5EE1A6 for ; Thu, 30 Mar 2023 09:09:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192525; 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=QgmTtu8OFjFdW8yq7WIzzTW/am1uahC9wawM1FIOBXg=; b=GIFEKQlcSWWlvVLW8R33Now6EfDwxHz5cXJjAPIfbHWso2WAMeLqjZwglCNAtNjZCqb+2H /0TDD2obUQNYSRnNTbF3IhYfXUd1jimRmTZcLPa8GKj76o0W4ZTbC/Zk1oyp+ze40Jsqcn Ua+P7gp+eDr9l4bgw0Gepg0UnetlPlo= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-271-BQVzeRJbMEmlF5CTlsQfVg-1; Thu, 30 Mar 2023 12:08:44 -0400 X-MC-Unique: BQVzeRJbMEmlF5CTlsQfVg-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-57c67ea348eso12978976d6.1 for ; Thu, 30 Mar 2023 09:08:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192522; 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=QgmTtu8OFjFdW8yq7WIzzTW/am1uahC9wawM1FIOBXg=; b=vLDUezW82rH7Gt7t7LO1/lTkFZClQEueXl//OIkgFm9ZEjKzf0DD4yyVtXvwMxVY5T wOnA913mTJ7JpNnIIMM8pw1qqeEV78CDCRmxa9IxVLWziaWnTK68p40ZSEz3NG/ExhTY qFYvbDwFaXHMBB4X66Bq1wyPANot/gJngZmv8U3r3BuAeqviB9C4gawik4sFpRr2AKWP /Ht2kOxTsBn59PdDtVG9AHWKWqpkJcCwfPG98MYwUoNa3GvUp4+0l64pYi1EZz+4kvdZ tpmBetTjx1dK60K60jaWNRXSfT5GrSY9cbvbhU6P/gxHcq8xLUE/BFkjRYu2/y0Sg0Db lkrw== X-Gm-Message-State: AAQBX9ctCKC03v0b06xLgOLzPGCYL4xB0rpAKcGujb38mze+xWZpYQjK 26qRhsdPpRytagzDii/eu2EvwKtcwUe1UwPx856SYbfEjF8rciSTTQ+gvlzJjVjx3ewTHTLM/YQ gsMBycE3AR9vMXfkqrL08+ejW+jBBo1qKIYnjqNlT5bpNfGeDOkrkJfYaKJeEyl2y1d0Kb8P53q GFZj2rxQ== X-Received: by 2002:a05:6214:3014:b0:5aa:14b8:e935 with SMTP id ke20-20020a056214301400b005aa14b8e935mr3724010qvb.2.1680192522488; Thu, 30 Mar 2023 09:08:42 -0700 (PDT) X-Received: by 2002:a05:6214:3014:b0:5aa:14b8:e935 with SMTP id ke20-20020a056214301400b005aa14b8e935mr3723957qvb.2.1680192522120; Thu, 30 Mar 2023 09:08:42 -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 k2-20020a0cc782000000b005e1235e6f2esm227430qvj.12.2023.03.30.09.08.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:08:41 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Mike Kravetz , Mike Rapoport , Andrea Arcangeli , peterx@redhat.com, Leonardo Bras Soares Passos , Andrew Morton , David Hildenbrand , Axel Rasmussen , Nadav Amit Subject: [PATCH 29/29] selftests/mm: Add shmem-private test to uffd-stress Date: Thu, 30 Mar 2023 12:08:40 -0400 Message-Id: <20230330160840.3107635-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230330155707.3106228-1-peterx@redhat.com> References: <20230330155707.3106228-1-peterx@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=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=unavailable 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?1761810597862234705?= X-GMAIL-MSGID: =?utf-8?q?1761810597862234705?= 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 845ce8a48204..b8ab75bc731c 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 7461021dd4af..6172ebfe732e 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); @@ -377,14 +377,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; } }