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: 13194483 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB26CC6FD1D for ; Thu, 30 Mar 2023 15:57:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 34F946B0072; Thu, 30 Mar 2023 11:57:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2B2B26B0074; Thu, 30 Mar 2023 11:57:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 12C226B0078; Thu, 30 Mar 2023 11:57:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 056D86B0072 for ; Thu, 30 Mar 2023 11:57:22 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id C4402120AB4 for ; Thu, 30 Mar 2023 15:57:21 +0000 (UTC) X-FDA: 80626019082.18.3A099E1 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf02.hostedemail.com (Postfix) with ESMTP id BB3D28001F for ; Thu, 30 Mar 2023 15:57:19 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TZSqqLut; spf=pass (imf02.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680191839; a=rsa-sha256; cv=none; b=QgBjYn9ItJwifzHNz4LBPAFcZI8dEEFQgoWa8k6rYkt1NGB2y9ac1+KGaR4VuO77vwwjGG SmUmLy96OJYmQrb3kr4cBQ4HbWx3/gYbdq9c13qjI17DZnGlSPQd7DVPYn7s2Fgt2OG8ft 9qn/rU6Rz0V4zrDYmJHO5hWdkDbyZbg= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TZSqqLut; spf=pass (imf02.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680191839; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=sP9rqjignnWh2VSPIiMl4HPMQh9/IMP3JUMCK79G4dM=; b=SD3FQDrfCzQsLpHRI17+fT13524jm0VUtdWRiO84A7vbrbKQtM6jJILlwT860FFSvivOV4 3XMwUod6wy7P6FIGtGUKm3sqQyVcx/yXPqTv1RNS6ro5ISGpWdUh4SZjhwQ4Hl006Yt0XB aywPZwfeWtaXagQLNCrrvLT8Y4cWxgo= 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-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sP9rqjignnWh2VSPIiMl4HPMQh9/IMP3JUMCK79G4dM=; b=TZSqqLutSnZDtbmFfNm3xmCVZZ/KSrxVItJcuirx8s5Wgs5L8SAblNZ887jRr4zLC+pO0i 7VZYRW6vrzBkkV8yI97cgWia8T4/kNRYXrxMFiG1ROUJHY7o0jymVacEAwroeGTTp/xddS hxx2+Hn8ZIhtg/s+WU91FPUbyrVfP2s= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-523-IMt6O7NGNUCjhbox8j6Y7w-1; Thu, 30 Mar 2023 11:57:17 -0400 X-MC-Unique: IMt6O7NGNUCjhbox8j6Y7w-1 Received: by mail-qt1-f198.google.com with SMTP id m7-20020a05622a118700b003e4e203bc30so10326071qtk.7 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=OpEqtBLiRmpJulp10CMNPk+ddKM6EWNpmM3gMDXnKHgzegGLqWaE2tQF/iTYA4AcLM omIi6HgiteFdqvZCo8OWfRYFjuMc+HpS0OZMhpJ6Zp/0f7D3QL6X5b4Vi5ooK9DbQdnj 1NhsDC/8XImorV9ag7+3vx45JQaKtHVa6pvEcpBIJyHTisMQjh41IlBLLDYuiLB6AxaY GvpdPoyf2oEVEk6qDuwGBE3AydivfllF8Ttt7LKi/p8aJZ15LsiPcyqLhXzEDEpLVUDS Fp+Nl674lD+2+rybxsm5qDcK1DaHwVueqxI8+wviHs117SFn30jRWUJsJdxjQmeIU67o Nnug== X-Gm-Message-State: AO0yUKXDwd1fqsSIXRRrMbv9UMGmeuG/nYon5xRJ+H2XHjVNQRxK/pR7 RTZ0kx3wgmTJWRg+GS+RRQxvrNkXg648xjWzffOgKgyti4Z//6bpYKXVUWsL4I/D4+rXYMd6aAB 3a7lGfYjSG6X4H/yrItXzSxgTwQGdjPXQ2/6S9IXsMQojQgScgrjin3yJPbE+Lw6/bxVb X-Received: by 2002:a05:622a:1981:b0:3dc:483f:9c82 with SMTP id u1-20020a05622a198100b003dc483f9c82mr36684519qtc.0.1680191832483; Thu, 30 Mar 2023 08:57:12 -0700 (PDT) X-Google-Smtp-Source: AK7set+XjaORt6GiFu74wzWerLNgGw4I0eI596quziToVBJF2U76yQS3mN30JraI0EQ6rxzmNnxCxA== 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Queue-Id: BB3D28001F X-Rspamd-Server: rspam01 X-Stat-Signature: mjazshdxacs6bqnmgcr333kbpmuyxps1 X-HE-Tag: 1680191839-252597 X-HE-Meta: U2FsdGVkX1/rAPROa6/xR6Dcv5wnLY614kZViqIl9mEGxHoWBZA/yxjJNWpgBaqV2DZY62drSW0ro/NZJ9Wy47X7q18Fy/LIGZWctLDYWirOvjs8eZaUL8syy0/vfz0tIg8Np2ad6K3I8SSjRIIU1Ybv7zqGwT1OebE9dcvCKePYf9L9mH9XsPyKE8OTaJoGf1zOJdYQmfO6QhNRM6i8WQX0uCov2RHHDVu8WgU5hU7MRHdVPSqnkVvoeBGP5zEOuYNE//oNH6uUN/9fetaqkAS6uOPalO8dmnSUA93sprLefujcgGBLzZ//Tq96IcQ6qHbDfAXZxVPceX2RcMj5mDVPXhg73pmUOeoz2Bb6/N+iY18bwzpQXQc4p0cyE0OBW4/0Dq+d2wZ2xFNZey04rRg2QF5YZ2w0EXSEPaPrZDpdOiqkI3m8jgQ77HDhkSkgJoUnYjRBf77ceuFg6wKZD8KmltbsKQSxLyIaBCmsxkDdRfgQ5ktDqfzgdSD6OLEERnYIdzU0YyMrgpz42wnyS5oPGjT7ZKLfYSnbVhOtwmG4Z21xYRncjSn+AX4xb8AreXfFTLGmNFrHqH79uBO0TnPx1uDLWdJjUQN62QTjsjKzyAw91WKZuN59nkV+IXmQPPUVu15/eJrp6ZOLNPSvOKjNdFT8RDizq83PTlUyzk5acSoZqelBy4Bxw/LIF45VvOQ3Fe+6q2XV4KbDxYr0lwpmLI6sU3jJux7UQXAs3sXPhOW3+uryNaQznry4hdlNzOXDg90PZeTza6WfLqSepI2qy9i2dx37sXJPVr+ArhhT5TuykknGOFyx7PODSVNa1lf5Rf9a6X8FjgmEZXXlicREgWkvCWEoFnfBxWXuma3LS51hN5FhE/VV6EbgoNaWMxv1AMs6iKW2PvSBuRfY/bUyKUMgNybwRPbvovIdSCztjWmrdCzuDjwdLXj4zflCC02yX/c5+6ivXSYQutF GFMro+pi Qi7i7OEH5ydqwdZbVi/472WnYLYMpHHUKrmePGpyy+XNVE7Q8gMMRpN95QXZRUTMfeLjQfnWyqD+nsb4hn2v1NE7tPW4q0IEjyT3a6b5P2JOXGLJH5Gw84GZGPRDIJf9ApaVWpnDtmYuDDaU5cY6tgD7SQEkBx9Fc3pfIMFR2XybNIp/hoqV7niCIXmykvakY/LvJ2KnV2iPvYQSRBBCTY5NOd6DeaWjJW/GNYu93qm/eZg/oplDrxjgh/QxRJWHJTq9OI+5kCZkuAl15zQLD9JT2WkWLw8JhsbkEoQ5v0vfQAzWfA4fWLLofzZj4kYfMvGA2jhvWlvmFt4wN+bGZBxhnh7y/ogxoxg1x1r+rB/BU3/4f1Obor7340LeXJhGoC1CAyM68POrh5L04Nf9VfwaKkdTIjTCYo3MJSuNDns7co6DHGtMwilIulatW8lCCDvzWKE5in1D5ncwq6xdk6z/8yxZ508LpsJH9Uh/E13KMb8B8D1KOQuMdODB/cd6W8O1MhJThObdt/GLSNTxf0A/HFgm/+hsIfzqA7TH/LBM2cST2Dtd3lzKYRw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This 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: 13194484 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6CB3C761A6 for ; Thu, 30 Mar 2023 16:06:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 20F866B0071; Thu, 30 Mar 2023 12:06:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1BF566B0072; Thu, 30 Mar 2023 12:06:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 063666B0074; Thu, 30 Mar 2023 12:06:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E849E6B0071 for ; Thu, 30 Mar 2023 12:06:53 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 8D918AC762 for ; Thu, 30 Mar 2023 16:06:53 +0000 (UTC) X-FDA: 80626043106.27.0328CF9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf16.hostedemail.com (Postfix) with ESMTP id 6AA72180021 for ; Thu, 30 Mar 2023 16:06:50 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GmZffnD7; spf=pass (imf16.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680192410; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=YTYh+E3AEUbIuKqZIO8jsHd8WLvzzX9QzK3UcbYoR1Y=; b=08XgCHtjfIMGkIyhc50zV0BVPs162ANYcSzGHpw1LJgKdFBng58Jd3RainVMFTakuFOABf vYq8dC8psEIVLQAaiOL45tjla0SChRJOQP94vXAziDcwdUtJ4BK4fC43KvNVJnvpuhl7wq Eol0eXxVfQ/7wnqt0RWwtgUL1GqCT4o= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GmZffnD7; spf=pass (imf16.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680192410; a=rsa-sha256; cv=none; b=nP9JNuQChvdeeXCZHXMz53zyAU5XJpco+dkC95TBv9kVsCq97E8fsAFVDXOYZJWy5MKWW5 UKZytzp7qLDCLb4C9Xe71aBIOpm0UIdcIibVNZ+S+Q+A01X7AAAvPc/Pe9hsED5W6iPz9+ 6VR21X9C4M9MjQCPTCCGFFqEnKiI04s= 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-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YTYh+E3AEUbIuKqZIO8jsHd8WLvzzX9QzK3UcbYoR1Y=; b=GmZffnD7cqs3GPLg1crHrEARJKgiB6rk17nHyDZc4BZvrDkFjCarPIXMzZBQicMZp7oxLV cA8BA9HMjuw/oJ/XVjALfEXKM/7TBJYVKiwxz7KXQaLOQRQj+lYeXZ0pDD/m4HHJkJBrD1 TodAvroqKSK65+UOkem5Gj8WYipGXNg= 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-172-IYommTOlPuqJNPZGQHl2pg-1; Thu, 30 Mar 2023 12:06:48 -0400 X-MC-Unique: IYommTOlPuqJNPZGQHl2pg-1 Received: by mail-qv1-f69.google.com with SMTP id oo15-20020a056214450f00b005a228adfcefso8530633qvb.2 for ; Thu, 30 Mar 2023 09:06:47 -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=2hBWq1fV6xnBOrtzHAet4AhbdAhrBeMBUg2tzZqcenYaOmAXwaJcUFjl0scPMs8n9s drt939zhmSsX7OV5EAEbTlMoRZl9TNUM2iQ2JY2XzRNV1McZx/LNnTzzb9fdywnQWsj3 bAJrrTdW2FdvOlu+0uPlQZLf9GJF3JRiBcLRzMBjsrCXdw6lOakb9S1DjKixtfc7HELd LtdOvTBmxCV0DRMwW8OIPfmcIEu7wLF/f+6/0/Ph4BN1hrdBzRS0QYN0ttlugKVDiFbF ngPrtUpLNKs7opmdh13zHE6YUJ/fVxhN/1FVBq28fAkYzHOx1Joj807ZmivcV0aTKwvL B6yw== X-Gm-Message-State: AO0yUKXyVmP/mOzoaolTsuaakyafw783kGJffxa4zdSCzpCCtmFV/dOe 8BTvIWjj3vtXgYpxSPUeKjzjPGlUFYH5T1sZBasnHgFV/1o6jApyzTolxVlzrr85M8om7MSlP61 W0dOhn3ULR2tGjjh6F/uZT9TjONRNKbGTYZgq3lhfsRfOD83hU5PXzC15HkFwBSq+yGPt X-Received: by 2002:a05:622a:1886:b0:3d1:16f4:ae58 with SMTP id v6-20020a05622a188600b003d116f4ae58mr37192721qtc.2.1680192406341; Thu, 30 Mar 2023 09:06:46 -0700 (PDT) X-Google-Smtp-Source: AK7set+DfmwmgvSk/9QMK33YSWaZ+XaRstViNG93WHdzarb6l0ctIK/zH2ncD77kXk8cljlX9EelRg== 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 6AA72180021 X-Rspam-User: X-Stat-Signature: wco3qrdkd4motcty3t93jcpmyfddkuuc X-HE-Tag: 1680192410-679754 X-HE-Meta: U2FsdGVkX18qt5LmnvzPeYAkD8CdsApvEviOM7pb4cjGOfk7URTutBZyZ/5KgTDXK2FukrDz/sTesd4OdVosBDg4pnkFDgwgcg9OR1unsTk5Ds8YwIR9yEYmPFzpj0og7p4gdpPB0HmYAEiWE/DyOKIQa7dPe0hSRhSeHAOh+e8AuanmoOMJ5CZA8F40Q9Lpmj8oCwrJ7vOUp8zd9LvJvGe6JJKRCicRv45c/Y5jUiVcqB50NT7e1ZEtmQiBJBIodAffBDVvUM+tCw6DLLOIkIRazm7VC2/T43kXpm7ue2CZIFxnCNg1KLN/Lgfr2CuMIRnfsrGTAHw+cKH1QEBiSrjkHuKcsFV/kZ1/T7VcVu5Nw5AeOq3rxp/xcjNLn0q7nhQbio/9vmzt8Ev/I6V/VJhSzEbHiTiwv8UI1iKQrAEAXtzwxTP4y8Ztj333nsoudf9Lubrqe0MjyPN1cM8/GBuEb/2npf957TxhNyK/bBbJjZmUfwA56n5TOTS65zgUD4e2mvnCfKuQXM1WhTOxC9y1IhPDnzwvGY4KWLXZs4YPNok12X6U9jvTar6uVVE32zzXL3OlIWyJolgSUkygl/pgqbqxM9C78UHB+AaVnBZnR8Zx2wfPtgZj0da0Jl0E6rkjTUliApvsGl+py/lPC8IVH7JUj1jI8j/YOSdtdd+YLfFCbQCNIo3n86tveqLw9658ynk/H2QrH7PO3pnp8QroKQyptvNQjGbVep4lp0oFIq/3YVqDqMIXRhCesh++/LTpLBJcLDN6kzeQ5pz7tcPdddOyUZlwXcOmD9MWbXlFMHZVJ7DcsqVKH7u1IgQF+NWY0OLFLEWed00e37hR1gizCqfIcDQu4klXieKA4CVPWElWLeyq2pQMdsDBh40ev3Lyh2uL5Pgd5bsRqP5gPQasWTnExr1fl1ZNyGOj8617BkWcdsolWmq+al61rX/kDq9bz/pzIaT3ubDXpbx E+Nj1u+X +oyB6SIYwuj5hkHSdb050vcDKh9H4Z3n2NlZbnRGXc4Q/JZMtO/yntcUM/bXQJvZCtUsIRkjKrNLOW1mGserlZJeawkHbnNndh+0Bnu3umlHD5oip0qOeArEN6wPvqdNkDDL50lUHg2ZNp2zzUk9p+LFoqDMIQTlX2CfZal1J/hF5Zbq6ttuZXH3v9orCOvI1xxAeQltTpoQN0bVuk7lgKja+IDiiQfmq1drUTafBWcBQlo3/y7dz5phC50Mj6UY6/6y6Yr5cEpCLjPvx1jmnFXZQtmFVEG86ylZlrUwCQoWfkWkt1t4mvrpQ8HuTfQlhLxzS4uZypOfwSB5U5d3YM/CYawjxV2/wHvgpCVEgRZqnc5kyJVIBgQ+IelGVU03WHMnwV/l+rMBPewF0WDrt3z/1mmtrkPK/L1ebqr7QvAbDvwLGmWSZGlJtvzqJzJXHJd+TMNz7tVbudF1AlclUpP1k+VRfKhOs6GtL X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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: 13194485 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B51EC6FD1D for ; Thu, 30 Mar 2023 16:06:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A27C36B0074; Thu, 30 Mar 2023 12:06:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B0BA6B0078; Thu, 30 Mar 2023 12:06:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 84FA3900002; Thu, 30 Mar 2023 12:06:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 751E86B0074 for ; Thu, 30 Mar 2023 12:06:55 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 4674AAC7DE for ; Thu, 30 Mar 2023 16:06:55 +0000 (UTC) X-FDA: 80626043190.30.8CA2712 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf23.hostedemail.com (Postfix) with ESMTP id F184414001A for ; Thu, 30 Mar 2023 16:06:52 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=DhsjqUNR; spf=pass (imf23.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680192413; a=rsa-sha256; cv=none; b=MRd4xCCADLqVUcKTqh1srsqaqSNcm91ekpDLNgMyLP4cdFDDbRWdgg4Ld7uuAtkwDxhScV 5CWS49xAkmdruvTY7Dd3kAoAWr0gOqZkewrPhFED5MV7ft4PXJXRQ/3Do8mivY7ptDkQ9X TnRqJ08iDGoOj0H6EXdXLiLZBEQ7CBo= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=DhsjqUNR; spf=pass (imf23.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680192413; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Ur7tdcX2754X/jwxH6S7nx/WMyBE34LUGKNmt1W9AUk=; b=SxHx66mClvGhbtdbkhD73M7c5XoFf7xRnl5Z0+4VKjmaw0swr7x5mx3T+GV5nV3bPvIReo QfwADGtjOLEvwnQrSb+23ljjuIBOy7Cqpb7JNcIYI2rMXUjtiJRki0q/4cOECXgRYmtNdi Sz8Z1O+vPDrroNWVeP77vKof9kF8DU4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192412; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ur7tdcX2754X/jwxH6S7nx/WMyBE34LUGKNmt1W9AUk=; b=DhsjqUNRNv7jEjspa/kRaXXya/PdVHK4IYhsfIuZC6ryksN3ASlB+KdZXPTVnqGkhZQ4jF 9Vcdq3dI58dRRYT+RC7XW/3BDBNiP+r3TCUn1CU5iEnWG7Bk5HEX9ELq+XvOENfHaev6WM LsoDBq7KP7kUaS5kJd4ySx4BfKGoBko= 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-591-Xd_U8-OFMlCcBpGR-p1Gow-1; Thu, 30 Mar 2023 12:06:51 -0400 X-MC-Unique: Xd_U8-OFMlCcBpGR-p1Gow-1 Received: by mail-qv1-f72.google.com with SMTP id h7-20020a0cd807000000b005dd254e7babso8423572qvj.14 for ; Thu, 30 Mar 2023 09:06:51 -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=1lkywsI60rakeHa+SXVJu61wt4jESAfXByEDksTkadhOvgO3OG0RWWKisvN+ICzS0Y 1zixInpPKPdO2bTX7st6yHqg6fs82lz+NiicgfcVoDk3q+oWvxFnnkMg3ddqDlTmT6vL pqBNIwbhNps5TxlhJo38cP50GCeT4HjCLhG5OZfLcUHl2Z1s3B3fc3L6y54I3VY5pZtk stE0CEzcraNY7IvHWaZWOiC07/8FLqvaxciBayhfcjkKCIONQTLcc05zjIeZVhKt1503 wA1kEkwygtIOP5nexkjltV0KTcZ1M4X7UQAgsm+FtYGG2eOMksVfmOrxTfPBb5p74/S+ V9ew== X-Gm-Message-State: AAQBX9dYRpQ07ZZDKPOAcu4QN4Hkgf/+NdkfPG4gQtQjMNLug9lEUIT2 xgkeokZXeWBIqGuGAdCjEa6isv04+F268gL2XaqZ0MTstERO+I6Yj07m2wYgr4sM6rR0VovR5pV 1IIZid8vUa6p96K5gUO6H/RmncuqmRoqXlHNlMHqx6RHy3YyMDIWiv5PZ+NfXUiywnL35 X-Received: by 2002:a05:6214:518a:b0:5de:5da:b873 with SMTP id kl10-20020a056214518a00b005de05dab873mr3919761qvb.3.1680192409937; Thu, 30 Mar 2023 09:06:49 -0700 (PDT) X-Google-Smtp-Source: AKy350baROru4BSpw3JpIlSLNAp+ESXSwo1NPW+Z7d/OD7Cm1StOx06WqJRNSws7xERwMIoZLTH2Jw== 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Queue-Id: F184414001A X-Rspamd-Server: rspam01 X-Stat-Signature: 8nkd39yd9om14bnpag9tt4fyw6ofeohp X-HE-Tag: 1680192412-427188 X-HE-Meta: U2FsdGVkX1/pDRKq8upreeS7qJNJU1Wry+LFys2l7kTf+zZUrtrdaK2U4J/fJ28DPDrvk1iOJHUrPn43NU4FcG97zZnCxdod7an0jwBMg/6APRG+J1NMVR3i3pCfjzLFhp2a5duh7PQKImzpM32k6TxQA49uEzgWGmpy/cN/9Vce7xguKfCrHwjLHXsIZkTbPhrZCHpZm6bQLHvaVxiBf8RqEnGhMmw+ewuMnx2N+6FM/h+4Ar3SQh1dbWUtqVRVrdFpDHXWRws7jO3xPJCUSeFCnhWXIaIxtUfRtcNoBxvoKaL74qiXQ+kQ67E05Cy7mjPs4yxekQK3Y0Sfh7kOVWJmuROzpksBFMd5ran7JX902gBT+R7Hksya3d+GEg4XkpQgzQkNTphpBpHTPplwd6Mb7VqRzvH85uoo2CfOCzMRhX9OWcpnhfyT9IGrkQ2O5Vgpp5kjdfZMKDsbR/5CnTQFv3wmKv00AuPNJ+GkOqm+9J6PMQWq5P5G9GB61Grb2XfBj9klh3a4kWX92ehS2q4xq19n0R66HWKkbs2UE+6F+LI+m5pzuj3q5jzohV7I1U9gmudcNSTlk/aw+eIsv/8sJp2HKWsqfDofaYrbQruGqs2iazJ2G+bSj3QlFDWJm91ktAUziCTuXoBgPGF43inULKbU4+MauynXy7JjCiH+TGOa/yFUCwkM/prRCVBkESesvgkx98+eDKyPhoSoXocHU+boufBZEDkJC7dNpoZUdU4nejrfgyrKF/MSuOON98vDypq9bYTl/tkv3bSxmNU+uGubQEUFr6knUd/9ebntWxgXZS6gg80hcpkakKhHhlqjg4gtAeeizsfE2miRqFo3jrynS37HmdkHbxGNECRB9zYjIxgqRmvJ+ZOuQSoV/Bgqz/kLyjdQ82FWSkzSifwo3/D1kQRK26HqFsSbCSvOsJekYTRmo28LVBAs1b+1SjUESDnNfu/LaBrXXl7 io2buYSJ DSCblJdHuK4qxKcxJvkJeXii6nmyWesCfMNSSiLAbwNOJdT7XvD/WykugnTYNRmSlO1bWECnS4Y7cTocRQdvGHBygFx2TUSjo2S9koNkzbuR0tysOefrDZZyd/5+5cbCEHQEJhg8hAm2GMcM+E8zMD6U92GRVgqN29HSa/Ns7+lnVLgjgUBrF/mTVU+YZsc+pJe3C8OfmB6CtYzKfQ//y0y6TVQNpWEIglOpSt2qUVANVvHBbjUD8CnmE6q2pZoBwOFrG1sa1BGsjOM4nUFBjPTdz1qx+le6Vjv4r8crQAchwMsozlhIC3hA79tCFxQdeqgZvetvY01Ek2uutBlrKC7KfWoPHBejk2ocdd7XGVcTf1KP499DNZ+nVw22gt+GlJeQox3ZoZ7cYqy6Fxm2ZfviRotA6BHNCl6/TV46Ofh3ga/wBnD9H77vxOxSIU60dnvAcDg3v/LiEHGqI2aFCec9+rpwhzl2ry9BN0h7ug1LsY9/B8+/kOo1FnEFqHz7xgeadHRbqL+rC9QU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Dump a summary after running whatever test specified. Useful for human runners to identify any kind of failures (besides exit code). 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: 13194487 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED7ECC77B60 for ; Thu, 30 Mar 2023 16:07:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 877B96B007D; Thu, 30 Mar 2023 12:07:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 827BD900002; Thu, 30 Mar 2023 12:07:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A2BE6B0080; Thu, 30 Mar 2023 12:07:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 576166B007D for ; Thu, 30 Mar 2023 12:07:12 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 0AA85160128 for ; Thu, 30 Mar 2023 16:07:12 +0000 (UTC) X-FDA: 80626043904.05.1672357 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf28.hostedemail.com (Postfix) with ESMTP id 60CD4C0013 for ; Thu, 30 Mar 2023 16:07:09 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=K9vNu+h0; spf=pass (imf28.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680192429; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=7NTd9ykbxp4UXzRNrTfarBboXMMqnuQ6sOTF5uMlUjU=; b=gGE3ir17nbd4+3u23m4dX4BrFl+nK9pTJrOme9+2o175VbCRp8A/J1iBzokU2KJ88h3SmH i+IO3zYWsWN1/gQ4fsWrr70F2XLWTg+Idb0+T/hqtZ0PcYpg3oDp7ZXuw0v6QR5ozkgYmR LQJYDKYL3w6ybHwkURmNfd0miKXUyWk= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=K9vNu+h0; spf=pass (imf28.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680192429; a=rsa-sha256; cv=none; b=SGML90ym78LhX0jPtQrbOFrhU7TjDsdsrppL0l6XHwxCgSHzdLQVjuw2AhdawXI8uAty8u kXYn/PBtTO/wZNi6+OjlFFhB6hUlSqxwb57W452Kz4ptAzz56V+v3x6ctdrGMJzQEGF0+R KGuU96Ba6KxorxgfnEGlBpzBlU2GGDY= 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-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7NTd9ykbxp4UXzRNrTfarBboXMMqnuQ6sOTF5uMlUjU=; b=K9vNu+h0weu4wtxycoRDm1FbMDNBg+4xliABLrvD/q+SdoAilw9cVWmIlrTiNX5umV/9iX kB6O3wRFavfel6HpaaO2qaf79AXVqklf7tXgy6XBnfbsGUq6SzsNW4iWQ5fho3GV6fRgkS KHGEMoObqNUgRqSnK9bjEzBtf1JfdrQ= 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-308-q_aoFJLANye-7myhghhrCQ-1; Thu, 30 Mar 2023 12:07:06 -0400 X-MC-Unique: q_aoFJLANye-7myhghhrCQ-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-57c67ea348eso12975936d6.1 for ; Thu, 30 Mar 2023 09:06:59 -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=Yej8YHJO9kZZsR+Mif7rnFOtD0UbhFWp9Qt+KVzD+yyPtsZ4u+fhYtOfG7xUHoV60o 9WFl6WYcB0ROafddQaltojCn4e17JTyQ9R+jgkwhwkrtpMpEM8dOsfrnpuDZ9ZhLp1Dy pwXlkC60sVI8updiBEz/mcCp/L6OFIZGnQlUvX7LiJq6B2IrixQge9zLaXqoKBE+oZJD mSpspG2rfkmsbUy2jKc5jOTY6vuHQKkjvSWDj04ENVp04r5+yaEIy+vGOohgJtpbYBnp sXDJCx3Ek82gOUckWx0U/QBCFNj9YBiUUwkoz8LFo2mQch998OZt1ojTbYrMr6kHvqt/ Z+CA== X-Gm-Message-State: AAQBX9d3ZKsFV9Suv5YvUy2YroPKcGblk04yljQpiSo4MkVyyq2MVxOW KVi+NNAH0814XUv6pbMHDPOwXuYvkodPqxmMQqOdjbEJ5sWwYZm3O3umevj0iEwhOqQESVSTocx xsP70AZEVa3g5QwTqEAuWXNU8ric33gWLvtyVwYEsT+kcWMGKJn0LjS72lo7I+ypSSAlP X-Received: by 2002:a05:6214:d0c:b0:5df:a693:39e with SMTP id 12-20020a0562140d0c00b005dfa693039emr3564921qvh.5.1680192414136; Thu, 30 Mar 2023 09:06:54 -0700 (PDT) X-Google-Smtp-Source: AKy350ay9foZ+7sLH0l9upG28YZMcH3wwEPMDOy35oTEC9bGWqO6YTuX4ly8yK4M9vqcaISxkOHyLQ== 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 60CD4C0013 X-Stat-Signature: zskwqhxuqh5axpsnjixf57tmck7b3da4 X-Rspam-User: X-HE-Tag: 1680192429-304519 X-HE-Meta: U2FsdGVkX1/SvwWzHEfNTgFQfFCRF8YL28Yle2TpOHHY7hhuf9E3eoLxHLWDeeD0823H717ltEnv7ML/Ai/EkCaVRB0Xfj7z/vvxa+i3T/xfbP4ETyWMbD2XPa0FXIlWdgPXT/Nq3Oy/JXlbB8vcpmkHdUCK8k0z34MJ2U07iAh/sisQBtrMrHJ01v02YyCQDmpn9IvY71bR2jjMvrQX601xnEJHQ48vjgJP5XPhZGUPT6JUIxo+G3HI3kmxBVHbXS3rkzqrgHrIP23ZUonhftfJIYsB2vhdnDyZRkCjX5wtt4eOoFm2tuDkI8ZOjoarMJ6NlDX7Hog+7talel6UKLvdUyt0E0P58i/+NzGmvC2WEaSKPlMq5C4VQxvMX2Dikrz7CmNL1mbqpUb9pOcgonxk4S2I4xysLypctYcghmnSndZd4NTlyvGaFZYMQ4HiiDkQmKJTQTZLfQc1wsFPZRKr9s+vpo5qFhyPmH5cmLQmsSsOzQP82QtHkqBVjMwKrxcDKfRPdrjzhHbFRGNmZMR4Basawq9k/tK1udynGSSoSIcYE/SVuVejL2hJGUKLMttr2Ab2xfbwr40EipfLPopN5a8IUQP8y/c9dvqMY9gwwpcUPIbM5V2RMmTDNiS5hq0kb7dm6CRPv4s6A7azi1fv5EzTrTQfE9/zT6d3kShmIoBdkedBhSWeDRDjkHkBCKwg1+Teyzv+/07iJ3NAFpCNPyFHgQ2De3yuzCOeNuq2GLkPtxoTm87JI3yL9ULn7aPedUzVMlr2QjwZBKEZCvimPjuq+QKd8nE6gjlydiyT3bi+wFTcboMaxWY7x9lu6WXyQjXjL4dGJFH4mSjQEMcAgFXQX+vCN7TzjyxzOf1VdQjzh4X9wPfim/KLONOhSqPNZ3cuoKfp4W6B1Gwmw6INOxEd3jLROxiCYmPNwbAB4eXfqb6HO9YoyDV5oD3/wJQq5qHImKYDx/MPSt6 lhAyCudi Z/13UuRALnD4WnlzwcfdwTUcfjHQq/0bdWh+qxtDf8a4rHZH6cxLaLohD6pomB4lJCZcPj6GiGvc8nZANeSVsjeepEMD3ulmYzIceoLrzZzNCUoP/0xR06Ia8TRT/p1echg93DwqKKhHwnHoMJrYEYwHfcPyLCwxopGhDfiBMtO31r+4K2GTi7v85lSynqMpwcEBp5S4Wm5mwq3TJNu79QPaUOso6mOsEEPyUrlNsbg7TvqYhD9IAjn6dUizU0GMlhwhet+eB3hGQRtnrLG4nxTFNonlUn44s03cIZOGoxGWtHRuN9jNMpcEUMmwDAawtBkeR4WKsKQIRhs6UglwU+YJWF7bFByTM/GeJWZvtiq0ZD77qTv0WABad39t9hPpTMZgJS9Hf/3SGK4YTOsTj89z+qXcKN/pz6mbiQor2pi41G3VXLhX0tQ+UwieL7zmXPi/pcqjlc6D9caAx/dRXypBFOCMGHXkR8De7cmBh9QFgP4sExOVChZ0phPY2Lq7ABU0trTX4C5mDPU0= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: There're two util headers under mm/ kselftest. Merge one with another. It turns out util.h is the easy one to move. When merging, drop PAGE_SIZE / PAGE_SHIFT because they're unnecessary wrappers to page_size() / page_shift(), meanwhile rename them to psize() and pshift() so as to not conflict with some existing definitions in some test files that includes vm_util.h. 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: 13194486 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E925C761A6 for ; Thu, 30 Mar 2023 16:07:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D5A0E6B0078; Thu, 30 Mar 2023 12:07:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D0A346B007B; Thu, 30 Mar 2023 12:07:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BAA506B007D; Thu, 30 Mar 2023 12:07:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id ABC056B0078 for ; Thu, 30 Mar 2023 12:07:09 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 7F4F4A0593 for ; Thu, 30 Mar 2023 16:07:09 +0000 (UTC) X-FDA: 80626043778.07.41C615A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 3E54240012 for ; Thu, 30 Mar 2023 16:07:07 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="f/GoVXPE"; spf=pass (imf11.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680192427; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=KQ4ftFOSRnTCxQ3k16FeIYD6t7fNL3xHl6bh3AvSWJg=; b=7H320BlxfPc487laccFLRZA3L06WlTc4dOHWZXf8b57JzNnSgqncyd0mfXKzgUsYo83r7s SKz0pb7MB/2hyoNpIoZorcnM5GNhYjR7vijYAtPUY2JRHrTLekhv6kYCqG043afWx2QfZ6 qsteBx15ZGFcZiSEcci0hDSSin988Fs= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="f/GoVXPE"; spf=pass (imf11.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680192427; a=rsa-sha256; cv=none; b=JHly2nwlWW3+QmDdHQlomEVVwJuQFpCKO5JHs3TdeQOd9Jc6FzHCPZarTkPtIwNuJrKaJ4 nY7E2xc4Ea3meGVpJIsRZECuCMIyB2NzaaIF6bnzFGfq5SKbGBoxucR22Pv5TeI0W8xYA/ x8SjDqsW1fRJwPTDxZLaVefShLKa2K0= 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-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KQ4ftFOSRnTCxQ3k16FeIYD6t7fNL3xHl6bh3AvSWJg=; b=f/GoVXPEF+oLUpvlA9AKUrKnEjPgmma03WQBpFtCMMwaEop/HrJMhe8M82iwRX8oZLryBn SUrpvsBkGjOpA2001q8KGZLiz4mPmy5IKZNYkKcHRfzLCrxPbKthSRzjz/TgdAREeTnDNe vsrQmU14ekVi9E/H0+vL5T1KyZ9qG4s= 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-465-A6OFP01lNQOfdVTyxrOBfA-1; Thu, 30 Mar 2023 12:07:05 -0400 X-MC-Unique: A6OFP01lNQOfdVTyxrOBfA-1 Received: by mail-qv1-f70.google.com with SMTP id m3-20020a0cbf03000000b005de7233ca79so6265870qvi.3 for ; Thu, 30 Mar 2023 09:07:04 -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=Vk/TQth8S1VT1XCyOSo6AOXRwNwrSjW+3EYXOZVoOGpHGepOfjavmTbLcpMXa0cYDE aCnzyzhyBj0uRCAOLe9/ChGy4FydFOaoaS5Xf3V3kX6K/bW/9AJq2/b6CGSoRLTHeszU kC/TdffQ6Wk7jHA1h5iK9qU0CuHJXDgVFKSQMwdAL0Poy2f/1CckE7wpCmvUZDy+nf+5 6ZKWO+IX7RVTzqQWhH3Uz+yScIvb8Xoj4kb646sf89XETDDVZ7C+dh1TrqQ/Vb5YaOBZ Kk/0e9uu0aWwG++OKNs0PX0zESPzwyPsw1+PycLD/DZwOYYJeK5ZE0brLH8HEDWGXd3D wN1w== X-Gm-Message-State: AAQBX9eOLyFFjhvOqBQEVvssHPZJ9JkjDeTyfWuqDpJQh5zvN+yekGOi gzq+sgCvfywYUghzFLPLJhOJc6J5ULs8zcPfu1lJwJkKEh/K3IYuodwiTK9iDCYSnuLlq2dIRLa h0Sl8QSfTY4UzHjSNBklOfRP5TGJetWxY+Gkm0XQwVr1a6I1n4TCak+JRp1QuKnuZEVbS X-Received: by 2002:a05:6214:509b:b0:5af:3a13:202d with SMTP id kk27-20020a056214509b00b005af3a13202dmr3919599qvb.4.1680192420334; Thu, 30 Mar 2023 09:07:00 -0700 (PDT) X-Google-Smtp-Source: AKy350bLzP4GpcegMpvHKLVfgNmScSdhSk7athulffSgV0YbWPWaz9dWtQYXSRFdrOj4JKqHaphj6Q== 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: 3E54240012 X-Stat-Signature: t64eh95uogta6npxzjutmidfbx7ayga9 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1680192427-712358 X-HE-Meta: U2FsdGVkX1+8weBucnaFmKr147669LSRNitQzDaPlRxi/86r2RXLR3YVij2maS9LLpcHUWsq1Fu4ihKZLUKySdZ+U95xHSZa4yXySs+1zzlZZM9tG9D/fqbr5ZhiNBTx+KqUszOBmHS1TRPa80sMeyELKhvDT31Cxn49BS4wgRuKuf1zhTVb1F19UBTXfTTgB+X/JKTgmdk0CG4y2dys7m1ocSIsmOXsN9fOcZjP8A2vQRpbWYC5nREgmdx2NOFtXQfLKFcve2skIDdezvDCG7FIAkD9TPVLNZaKz0ZW9TUCcPUhh55B7Bsv+HLGVaJlTlhZnWcFfMtA3adMbLp7WYucbJfaiOQsqLsacxbdU/1kEjlFat2wr5/jqpAmOKuZ/KRPVryHolm/p6eXqdUGzxL/4V48wjxOjlZ586YhjNCj+GDzxDiQJv43L2jQOSjv7X5NxfWvAzvPzQdrbml80KMaM8T1iO9mglwruCfBgLqoa4malgTKqgMuKCHvRneCa5kKJLXI2haDaHKtC96EH2X8DHIdq1BkOVNmn8sTVhSwJynYgeo80bBDhTp3IkccPY/TUg87DjCYtve3c9JOvEWhmYMk300rwDLwwnh2Vw45Brtxy9+fcI7Vay6+rlXVIa2H3STMyAge0MyJZL+kr3M50b85p+ZuT+/iPz2AOZ4R2ffgUJqozRIxUWw4w2z4O9bmfI3CDwYa9+k+AVDETN9ANk+B3ln1rQ+9B8L2uXPm3v9rE3d3Wk5cxgUmPhOIRV3ip8dKp+lEFpYsOze+utbQgpGdE2y+vyT5HtwNvaRdkhywLXAu2QNqEiOT/zdBzx8QUW3fByMAIWox5qLhRvBwP7HfjM2BerCrt3GGZ/0yES5rWCOdgxv94mD5CApi3g1EDLQliJddBU+mKv4IIeI7kYP++7B31RKQ3nd99u6XcpTEPaY1rE2tmmTJkw4/znVrzPUC+iE5bcn2qsI H6Gd1yjQ +glxRGBpw2hw/gGjTJcRTFeST0/MU5d7hyEVS7gr8KnaGrDbQWbHNAXat7YLuxA+GIICGpnxAWEJJ9LckYZc5C6tMvX1g1Nrl0Q/n62gVyJygAw5XBti6BmfAi4upUPsckSoDsW5+H8O9upUABl/gOEh46WScY2sHoHT0KntxnR2DBhCLFySmZzB62Phfow52r2eHOhBPN4tmYiC0skui4DCRk0WhskVzxZQDEUv9ZLt2yzbNDU1PLFBGDhoXpnuBTJZshuGEb0UylhHvOTMSrJyoY5JpQPkoTm/QxmurEbuvQr1nZyqDTW5IwWCgp+4DenWcOpfhN70MP1D2EfhjWmYMvoXqPc2l8S1HHTfkcpxdtuaIY9s2Hj7RdNrbhcPJG5y0U9qD0T1HMjSk2izEt7opa+H1iZJecHbB/9dE67MmdaH45t5fzKwjOHNIfo1EDOLoN9um+HZ3oEZ56j+hC0skq+ZI1pZbFp/e8R/aalIZWl5US7s1M72z4JgJu9mxPeud8+yxaTdEDmc= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: TEST_GEN_PROGS and TEST_GEN_FILES are used randomly in the mm/Makefile to specify programs that need to build. Logically all these binaries should all fall into TEST_GEN_PROGS. Replace those TEST_GEN_FILES with TEST_GEN_PROGS, so that we can reference all the tests easily later. 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: 13194489 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D26FC77B60 for ; Thu, 30 Mar 2023 16:07:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5E0FB6B0081; Thu, 30 Mar 2023 12:07:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 58F7D6B0082; Thu, 30 Mar 2023 12:07:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E3D56B0083; Thu, 30 Mar 2023 12:07:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 2A1636B0081 for ; Thu, 30 Mar 2023 12:07:19 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E41BC1A0991 for ; Thu, 30 Mar 2023 16:07:18 +0000 (UTC) X-FDA: 80626044156.12.B16D1AA Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf14.hostedemail.com (Postfix) with ESMTP id AF359100015 for ; Thu, 30 Mar 2023 16:07:15 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=StYIWdgp; spf=pass (imf14.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680192435; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/DyAZC+/gpTxCJoW2F/j7VlnCZ3k9Ngitz86Xlm4uL8=; b=lbW2HTyvLxeBHitw8V5sF2R20EESjOoD1yT/zFp2EMSzIOAdz3PI0+zu0TApp/GjeCgTBP efm0Q9nKLjolV54oH4a7uqFMGgi/nHJRSiLHk0871DaNQno4bFPCUX77oVqvtTCHBvA4y/ Pp2NbmBS5gTGUlGVTmQmOhf+XtFMMfA= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=StYIWdgp; spf=pass (imf14.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680192435; a=rsa-sha256; cv=none; b=tdBcv0qug+GAJGApO0mZZV//KVDgLtSZS0Axz7q/qqKUhb3ykTYoxzY4X+5gKdGsleYVlO nSsaB8tR+1PvkFWQgY6PCJ8v9Nb9YSv3xB+W65dYA+FfJ4ZB/0qKg9onfnkOKdUl0cSJvK vmRiO9/eFPaAjDVjKlEkhJ5wF83LY80= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192435; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/DyAZC+/gpTxCJoW2F/j7VlnCZ3k9Ngitz86Xlm4uL8=; b=StYIWdgpsGznld3JMmeW3aGhjn4mTgvea+3lMqDpsDlyV8kFfHRy/kSllLNMLKi6mxUm/d LDcpEOnX0+EWlcyDnzi5VmHaWVv1MsKZ6Lk2TSFx/bc/CbLw6j/jS1MEMhg+cvso2dfCgP oZteZ7416dNVd/Oo8an3hRXYe/iYMVI= 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-653-lSZdP627N3Ox4f4-QjnGTQ-1; Thu, 30 Mar 2023 12:07:10 -0400 X-MC-Unique: lSZdP627N3Ox4f4-QjnGTQ-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-5aae34d87f7so13014306d6.0 for ; Thu, 30 Mar 2023 09:07:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192426; 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=UgPh/jF8PupfUyki8oR/cJ2W+Y3gPJwdhRF9F7xzZJhKV8MZzSmXzx/cDXA/SLBAwa +UEog/z6Y6tMqfsujOjxa7aTtFaPqEl+Q0qyGy5DQ6ufKybc3seKHbsslJQz7OgE6MXq MRT2iWiMIVhlXc+Ekeh1TQrjbsn7PIFDZHlrxSF576vaYN0+sTwVe4sOqsaXY3ZKL1VC FTUoM8pdQJhU34q31auW7hB8aDLrmqryQcaOTG7jpbXAtB0hayWW4xEZDilNHce2CtC2 I21zjZ+3jcblZlSjG1QjzNMu3Tdyd9FsjNFqDE0yPKkOVI5DX7Ns8ug0TX5Nrtv3A8mY rHJQ== X-Gm-Message-State: AAQBX9dcWQas5eDWxF/T1MhGadzJg5X2P+r+O6eS6PiGzGsXwFLd7Kpo AB77rX7AIiGqp6lXUPnb+MdNNot5n0pQnGXmSoVSHtuOAHo5LwPU7vF735EwFcnY7K3rIUHXpuJ TSc9uaOXE1akgjEN3vUDe7Uq5DPrKHg/hbmslJtzuzNlr+SxvOl8mQ8hfsGpSHOx2Sdhh X-Received: by 2002:a05:6214:528f:b0:5a5:e941:f33d with SMTP id kj15-20020a056214528f00b005a5e941f33dmr3644505qvb.3.1680192425841; Thu, 30 Mar 2023 09:07:05 -0700 (PDT) X-Google-Smtp-Source: AKy350Y8AnvqrQxdANaOHqwR9jEVyFMo9wivJ8eoja66xX8MtAvhRbrTVRkVpNxVq9kH1pnRwQAeXQ== 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: nqwaqyatr7x6ad55r1jor7b981765gtk X-Rspamd-Queue-Id: AF359100015 X-HE-Tag: 1680192435-173735 X-HE-Meta: U2FsdGVkX18+UOp+beHA6J38Hdv7jeNgnRaAxTFDMYG1vuMDqCvjWl+Mz5023pM2+cYIFNbwX8rcJCxZozF/VX3lCxZCh9JYjhw3UezLyqd1IYnXdAo/QiVZonm4CrD392pFrZf4FfaBAjZy8+Wk3uT8KMgdhSF2yFsIDImB6MGQmjtWVwKxj07IKkObhL/+wWXqnaoT4qJBZUDgMrFflyCr7E3CF4aWXqGkZQ63gvXyHgqPCNSbuptfr7i+9sgv6TuXCQTp67Dq3yNYIDqLyAlx16Hip1SUDY31gnmHmcqeOvl13f6MYzSTfhBRfNq7wRq0HqLyzR33G+tMJyLJiTAdBsp0BQ6fau5OsvJvLB4yu4fY9Ae/5zxzR+Rk/RLPgkNAD5KIcQisX92G7Ji5SaKIGD9kK51R0oeaMg+t01EZ9Gx8K8D1Du8u+RrlwK2hL0NgdUece5Jq4wsc2eCvVcEYqQ+lIT9f3L43jKJuSrY497nscQ5t/TmIIA6XARuqkPVjjOuMHknEIhG20OQv2UJJU4Sw7y4f40YqMeyOCLWhy+bN40YDGEXgWk0m4hlUexRNICfKUDyFY7RQSpc327ONAgywvwLQFK7ZsKaYCYGoG2zzPzy9Y0yLF1frxlA4eKnHtrJO9kOQ7BRdgqsS66Q3UmcJv4UG8IX2iPhQy+gic2IvzpdWZKhD6qfoKdZAelYXbUTpDBkYbDSC/PW2cqS5KDwdlPkaz1ePNo3hwVzq0DlWh7t4S908bhhI49KYQvZ058NCQlkU4b7CsNG1OJanIPfhf0ayo3jf+xvO9Yqi+N+XU+x2wofr7wDEBtDKhfIHtNNDvVmjokre50C2tKM/g5zZ2jfKrR/9C1INRCWDWEEyDJWfksMk9IUjhNKMcCZ0jNAnu8Qkc4VY2IG19pxBASXwe63AZpSclyIGXX23v3yuGPcskCN41KhmMbgXr4R7tI1qMGnrRQQJWsK o3mnAN0r mXIktaUO3QZPoIhG/4ExECXgcPFy55/Ij31hENd3TP/4pjZ/8fX03dXOh5s2yoDGMrDNx0bssU4fOtGoDJeCcWu8BJVBkfcNGUZdCAeWNpbTrwG7gIn0rCp/0xG69KTBwM2lnZ9MyYW5OdSfSy85nT0e2pQFaVFHLVUmOltTxKP0yMtyEPiUukmKq0UWhheBtfUDQ/fT0XQ/t7lV/Rm5QCvB24xAhF3EdzxFT9oq3Ny3eHyUYI6J5xZcPtduj/wzByV4S3WX34Fxpx49ZI0GwU6h4/32dtgmDcpXhSkaNtfZ31n+ndq3Ut3aF3Yrc2ManMg2wuLMDJ2d1bm0jvL2g08yC01FGAN9TYKTnAs3Wf4H4Q/Zxatt5mz65T2J/5DU814ikdKMAJJfyYc2GK9RnB/c0thLuhkoNWRceYNxBS170iK1R015iJMy80c2LXq3aDOdQRkfYF/Gv4+8gIPMz/HzC/A9tRvE8xTYghgCMfHeBeCIcAjXCF6wemiAj6qiyGA1QPpHzHMSM+6E= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: We do have plenty of files that want to link against vm_util.c. Just make it simple by linking it always. 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: 13194488 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 222EAC761A6 for ; Thu, 30 Mar 2023 16:07:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 802326B007E; Thu, 30 Mar 2023 12:07:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7B2E66B0080; Thu, 30 Mar 2023 12:07:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 655C16B0081; Thu, 30 Mar 2023 12:07:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 559D06B007E for ; Thu, 30 Mar 2023 12:07:18 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 1A195A08DD for ; Thu, 30 Mar 2023 16:07:18 +0000 (UTC) X-FDA: 80626044156.27.D70AF93 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf12.hostedemail.com (Postfix) with ESMTP id B106E4001C for ; Thu, 30 Mar 2023 16:07:15 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KUGHufjb; spf=pass (imf12.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680192435; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=3OY41FoDSXIz8Px4DR5ueHfK5qhzGwiU30swTtCORuo=; b=ShbSo1jokkUTGbK6RISl2ZvtyCvut2fmBbWTLzhasqHFiUp45hJ8AcK+GgIQ4IXiAA9P8J 0WLZOPK3sCX10aoATw0ZVb5sD0K2BLh0qHn6ivAETJsUJ4SdwdQzbyPgndQ63I+sBjctQp ZTNIHrD1QwYDqOMgfBkm19czKpJ0/2I= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KUGHufjb; spf=pass (imf12.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680192435; a=rsa-sha256; cv=none; b=fGU5jE3+J1hqB4GaaNpi/mervsQxy7INH1oumP5LDBo/y1elkK96YovAvcLiZ00GJ8xo2J qttNxanvggnBikb5oHeMJm5XgJHkYVhtY1KRR9JroNa0atYYe8YD05oTbxHg3mwET8+QaD ZZFZl6M0/l5CD1X2J2phb6+1MrNjnyU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192435; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3OY41FoDSXIz8Px4DR5ueHfK5qhzGwiU30swTtCORuo=; b=KUGHufjbz12DD9DKVFtYSGkI3e7xTAsGheCkUeYmsZc+DJUOmGCBu1TwsGs6Ay8eSN+F9x aho0VhlfItLo8kPsXyMU1o+mwQgAhjMgwst/1M+R/6LOjj+lsnhvaSZkxQcZRw5+w9IVvV MWOz+nx1mR5tg8A2N4NbIR26S2vLCII= 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-390-fgSrd5RmO-u7cBx9InYHlQ-1; Thu, 30 Mar 2023 12:07:13 -0400 X-MC-Unique: fgSrd5RmO-u7cBx9InYHlQ-1 Received: by mail-qk1-f200.google.com with SMTP id c186-20020a379ac3000000b007484744a472so8807274qke.22 for ; Thu, 30 Mar 2023 09:07:10 -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=7sXwHgQS3JlX2Qi+3IXT+O/OlbquewYvduSuXIMZZicdZl7/S4Scp8EtlcSgoZGmqo l88yc4fWYPNRflReCCQaguq/CzJGdK9J96mJ8F5fXAaITmlsRFbQ8xkX6I3u5e4tAzE8 gpQDkCKmAMJFWBebDUqCAxtU/Yo/pYkxR/8JG3XDE8VxFdiwbWw0cbincKOA0unp1suH +zDVW4wtpHDrIVENl+bYl41lVI8aQcOd9TqUpGD8aLDC98VaVuCFkbS/FMqUm1JHSieP 2yQfDH+bVexpWShfp8yzUI5TfjsFNfX6AuREUVKGKugx8Iw03DsvxtrxYue7d7kSfm+r OKBA== X-Gm-Message-State: AAQBX9fSOIO6eYD/CYQLwtsnLfYBvWLGe22r6SHPhaarEAtbZkDuObgp 4XChtHlLw5V+7PbBYta+y9TX6mY9118Pjge8smJGjjeKb3yK77e5NwR3KsaIF9QQ++unE3k5xq1 HfZIOCm333E2m4goYHVb7PKtzouGkErDhFVlxwiCYcwtnxsfLKk7tx6+M+wfh6XAzqwvp X-Received: by 2002:a05:6214:5090:b0:532:141d:3750 with SMTP id kk16-20020a056214509000b00532141d3750mr3688762qvb.2.1680192428362; Thu, 30 Mar 2023 09:07:08 -0700 (PDT) X-Google-Smtp-Source: AKy350Ys6fX7rmt9YD/vVT9J8araJkwcE6MiBOgwawHwu2UT8IpOsYcMasH6fyTBBFlM3DCctSA8FA== 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: wfa5uudmukymsbx7fzyrnrhh45e76468 X-Rspamd-Queue-Id: B106E4001C X-HE-Tag: 1680192435-164279 X-HE-Meta: U2FsdGVkX1+Fv7W3Xp028Byp03wTiGXroPhtcr1xvUy/w6c4uqIxPKAH97z4zTkvWfVEgKveFcJcH1ENdsXyHnQ4gtbt73AvOm2cqihetX7VwxOODEtMVO0GhtzobJMVvkRJTye2cccZ75+PBPda1D7ANpGis/WaNaizHPKi2+Kbnaw0iQ7IWHhNCZMHV9aZOlUkeVhRuNdXXvWyKSbgZM1ydQsZkZJB2GQN7+TMA2xjfpGHzLL9eOtFhFwWM6/Dnht1yIGSb+vJ76SGrvq6oeCeYd2/S/8uv7xvrp4nRuLjgJ+kd+9Ux4KrFOYnu0b5p2Qm17PEFplbFMjx37lLBo4Qmp2pyW20wWvKcCdVQ2e64BsD3PpLYa5zVLZwtPR4eAdWx7tRJLgPQuUAfTLTNuU1nJ2ZvItkqmMIX3hN6JfitzFJ3NN3Umk3Rx4AgmmqnW8ACHo39wnpA7RsJ8iVFJ5JEG6sTLXmh8ww9nXuf1z5OLq5+aetfdWfMm5AIK9jIX61UqIj2yX757uPgkNzVoTM3kuLTmT7S9iuP2RuCOlYU6Gcad0ddGEdKxvxBg97fuFppS2TPtl372wCWbb7gm1l2Aan/NOAAnq2KpA3ufUM1X1vUW+sKhJdMtTuqywMOlPzJ2IH49UNybkX4XPto/xJCo+4NpG7+zN3f61FClECa7VXeZo7wJHYulXktgIkryxP6BsuI192rb//kjAuifCDWmTpLaCRx2XEboEgdUhSihNg+1D/TW1530ZSscF1EcSJmT7dnJa5nuLwRTJCw5DpPFpoDH1/paLm7BG3g70VG1CPyQsosEa+Yo/mdaovyNwRnxWvQQJU+SHB6TIXeL5tVpWch7pwEwr/P4nlVw5QrBUYH0eaOKkgp4ERgYEIFrap4a7KB8u/KDmu6F5fDv4q184/D1H3AB+DhjVZowpztQJBJ7mn2+ZtOwOQXnkh5zLgKXAxPFFmzEds9Em AUU0dUDg 0kfWDq6zZ6/F/4QTk57QjMCwFu3Dv3mtin0yfhct2BNSouTq9rvPyX5nlWJOSOZUvJTb1EeqdbVOojEXbZkOmx7hm+mzVw5boKJXYOKs+Kg6SZz1gBra32q2gYGRvqVV/GQqcXfR9EdOcBIECS6czP+Ofhx4TDFooZpVpwN97IiOzovAr0ivRaK133LSNuJFYdtkIwqnucPdIE4TbHQ96Sy+Tz1Vz0Dt/KX0aqXBnS5DSY6qazZf+Ke4yvDZBYmEbur58qc4yKCjhvJQzTHspnsyvuau4F46bxb0CJJtnjV9mLHYFg9o9AN0KaKuFISLv9gMryvXgl+XREb3OCu5PLnWwYcbYDmRrYGQwjGLvvaOzCi2X2EX5Aeg31CEsScYcRnXwLvzdS0u/+H1kRWVVNPmHjW2MM73bL7vjXe1I8ulPDHQMaXBnp8OXVdTMtSsXgIVHSEwJQfPfE46u5iNAPQk+NRH8eYDoiCl9WcviGdSEcUmltYFPz2UwSdHWDTJZSjWr6vDdAI1q2Uk= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: There're already 3 same definitions of the three functions. Move it into vm_util.[ch]. 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: 13194490 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC758C6FD1D for ; Thu, 30 Mar 2023 16:07:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C71886B0082; Thu, 30 Mar 2023 12:07:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C20666B0083; Thu, 30 Mar 2023 12:07:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A72676B0085; Thu, 30 Mar 2023 12:07:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 92C866B0082 for ; Thu, 30 Mar 2023 12:07:20 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 58495A096A for ; Thu, 30 Mar 2023 16:07:20 +0000 (UTC) X-FDA: 80626044240.16.6D4E2CE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 01B60A0027 for ; Thu, 30 Mar 2023 16:07:16 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LPaGa3de; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf15.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680192437; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=GWrLladF+2uMEiKA8QDU9N/tbvqlj2DcoX5RP21NYpg=; b=ps5DfwdtpPtdrwSaiYvIbdyEqG8IDf3hrTVwWC03/VPMlhk+8UiobnVqYkEeLD0ncE8UJL OVfvQI6Sv53WBgkPKGpG2TGYRSHlrOgMlZAZ1uzVNGf/hX2Jwr/L7yk46rzklarDRwr1z2 qhyCVy3xdjZnLD0sThJMc35WZBBzahg= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LPaGa3de; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf15.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680192437; a=rsa-sha256; cv=none; b=NjwRTe8WuJPogfWKntr6bwdUM/OJhcQm4VnGHx8MISZYUOam9Z/B2z3GLgpsSUUWhMjs6n 4qMMSnAQiAx9ggzEjT0M0wmEvvoU0b+zRcULSfESsPU9zawtclI3Cy+tk0BVOYmySzRSmY 5j9/Wbo6Tp3agEKWN+CJJnlMTj2/aAU= 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-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GWrLladF+2uMEiKA8QDU9N/tbvqlj2DcoX5RP21NYpg=; b=LPaGa3de5lR1fHs+zZEfPitm/BAEp3UBGBw2P5Heez/A8LOayumVpekFKVBqDfxCxoSf4/ L4TIyhrIVy6Yj9tK8Gn4ODNEDcgc+IDr5+gE1I28+yprJ0XjudLXR1PJMso9nILwQWf3hG F2fxr3pQ3SOLHdxD2Nd14RBSOVkF+DE= 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-629-yv-YAHyFOaW-cW2y8zYFuA-1; Thu, 30 Mar 2023 12:07:15 -0400 X-MC-Unique: yv-YAHyFOaW-cW2y8zYFuA-1 Received: by mail-qt1-f199.google.com with SMTP id v7-20020a05622a188700b003e0e27bbc2eso12710363qtc.8 for ; Thu, 30 Mar 2023 09:07:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192432; x=1682784432; 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=pw2MrJSPblTg5RETCajJoHN5hHOhWu+mDQvDI4cb1r1qxdhC2c0SDruMBLjQH3ju3H ZNMdQh+pD+Dhglv5kMvfV1wgzrU1+jRh5+RNqdnQ1MZb+VuM0e4V5GdGF2qhi5jmOmbZ tZGM2GIiXD3ectgpjTs8R9WAN/Sz7zDGiN4k2+aBprAVsh+LNt7p159f4F3pyUAIpqd1 5uZDJe9NOsWfTT/1astg99qrxCajeGd8NcZEsbKvWbwbroVT1SUBvnNesIV/TitLG7KZ pv2o/TUHilfynpMyawmmxsWDf99lmKcyHUu1uQr1B/kgyjLjfE93gBBt+W5gFyiS7Aac jQhQ== X-Gm-Message-State: AO0yUKXlbC7AVAmG9RSVjEP6CH+s5iD0vlvt5bEbIV7tX5jb+11PH+4T eZCnBa7nhsuJVEvzEvIw2624BqZKLy+4iz1qda1VryZ+ko9/2bYTXXNdzX6COPdbdjrF7khc8DC /dC3DU9Zab0/XWXzHlSzgnBkMBSS46iKvss7CaKowPIhPEHjiCfB9LfLma3Korv0HH17f X-Received: by 2002:a05:622a:1886:b0:3d1:16f4:ae58 with SMTP id v6-20020a05622a188600b003d116f4ae58mr37195482qtc.2.1680192431693; Thu, 30 Mar 2023 09:07:11 -0700 (PDT) X-Google-Smtp-Source: AK7set8GQWWP5A2SWociPwDs+/krj5i0TiQOKiGvePWsmn+f7FgX8FsfyTl2mFFLsw0jAZRNZOJYbg== 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: 01B60A0027 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: qknbx1xkxt8jhy9ki5tg7sybt7ffr7p1 X-HE-Tag: 1680192436-417943 X-HE-Meta: U2FsdGVkX18oBbd5aYc4tvO0UQPKG2REhXsll4slGcPMxgo37nwfr88SCcTawWCbPtoYznnSPMHSUFvDEEmko1axP7rONy2L8ZGCOeNixJIYp+9zLFMYu5GnOftuG587ObIFqGQT64NI4dw5VcTjJtMHVxp9dAgX2ygz/2wFqGyOtW34pv71fMuX5gF7L6rXzsbkWQA/qNjOe6R1YY25ijdYecnVo+seLewBSKp/ASYQ+NZfzLEimS7GemH8dxEPUVjizPw+i22ia1Dao84dqlzWWyN2ar4U2FVr9DmEab9tySYw3gsITDBGctKMWm8QKBb15IxgvgQbGs/7WyQdKKQw8Dl/J7Y2aJsGfqkrL0e/8pdGaLF9vYrYTGbXBk2XmGZEEhtCdv+HLX4sg7nEPlfKlVsLClSa3Xa11iQ+6cOVPvIuk9aDCOTChXmYvdmnOuxTVIkciRgkxmUy6PKkv4L71INA5rPqja9arQay5KCWMBGl+NIft1AThu6EB/PwImyVFtbFsHC/ERcvkohuViQlLPNJxASl9V2ODpK2lkOwBoEn1DGH6rZzLBvql9PkOLc0eGWOJ+roJ8zydXan14iHd4M6skPqqj/pUUQLAZCELlyjySPOqEfO2sgkkxweQhHUZtPYrg2gxcSFkrmOhUpBPTe1SfKZK15pWtcluTHW943s56hceRrFVcr0LR/qh0aMKQWVO4Qv3vYA2XGvsxeXxPb+2WEtPOzHbx6yEq4tqRUycXNbvuX98n9sepzZRVJ/tgnn8i9YtjVceVpHvAm0M35E5lPNbA8lwqjknLXHbT0LElTDT/i9P1CJV0oDWXhYG+BpNm7BRLVa9xUgfr7mz3joSJ3jakRjcd76g6D3ey3YyUmtaGWxcsAOpoTXjX/FrY6b0JGyRQODxDMpgRV0seJrJX5xUBjLdujNQRkDy+1o3I7C69Qz+RgbbAc74Q2DLUXRrHEjSdKcd+h Ao80y4Sh AwioOH2cYckHspoM1/PeOnnjGlq0YJmxAED5K97lgsraYOu8eggOEIEjvPZ0IJW8uuv8XATNMG1YQ+ZWPMjwchJiZ52T+D6FgsKSHyHHMuwQRVWIsenAlPTaVaHVG2zzHqsIgmhUmhMUAGveOlJwhMJA71stB2JGpve4jtB8TMhnARFONUAagYrhk+6Ef28C/v2uGSl8V+WNml0RYMn367VX0xmF9aUpd/oZeq31CkhUlkHMQ0CIjSFmDMozch9W0biOBVZwHSq4ewENCCchkd1d8M0nlLMV81zgSHL+dQlS3ln8we93drhzRmXYF9W3NnpR/FSPwcAwbdT69xtAhIqvxgbY9IgHYsdjH9686ZSITJq7qTT+X3/LO59XC+xWlzgVJPomGeOC3Dc/q78s1VA+4DUD2d7YnJ9vs4DsqjNGvx3u3DK2C/tb6AhD9CUKYo31GyAtv7jraHecsYg2MbGunXuoNaYYo2w69y1qHkAQLeDV0yFTEEzzIGwE/55AT+T1LEEnGRxNxPug= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: We've got the macros in uffd-stress.c, move it over and use it in vm_util.h. 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: 13194491 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40CC7C77B60 for ; Thu, 30 Mar 2023 16:07:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BFAAA6B0085; Thu, 30 Mar 2023 12:07:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B5D396B0087; Thu, 30 Mar 2023 12:07:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9AEFE900002; Thu, 30 Mar 2023 12:07:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 88D156B0085 for ; Thu, 30 Mar 2023 12:07:22 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 4B56D1A09E6 for ; Thu, 30 Mar 2023 16:07:22 +0000 (UTC) X-FDA: 80626044324.22.2F1CACC Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 28CF440010 for ; Thu, 30 Mar 2023 16:07:19 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Sj41GHY+; spf=pass (imf11.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680192440; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=E56MghZwBJmwObq6HpbLSvJ4ZkxH3HDhcAvyqpX+TEo=; b=EKalpmqIe+oLDdtD+EiZJzLY7IdYDwTgGJp+tchNlF9jiZIkNOHk4jvBLc3m1kPj8zu/o0 4sArhGtSRM+DDT9O3k+kgdKzX76nD9P2h4blk2bZYGUYoKwdFV8F2ED6fmYhdfF7cfrU19 7yDvcV0jkd2rvWf4sKMncJhHX0paBiA= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Sj41GHY+; spf=pass (imf11.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680192440; a=rsa-sha256; cv=none; b=l48I2ZU0i8y3fY+Nw0HWEmt8+vWWlO6EnCQ7xmeXsBjjFMKZcvs6U2ay5WyJRzP7eb6bOA JrDmjFjBw0appadlk16ifteSt83pBEaOcRS/tsP0rBvO7f2267BdfBZOEV5wLFGgKDBwSR qRdZY0gXrGBJhSBsH0WLlq4bEAylLNI= 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-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=E56MghZwBJmwObq6HpbLSvJ4ZkxH3HDhcAvyqpX+TEo=; b=Sj41GHY+TP1Hr56nhapEHjBKwRNMZnR2beqvgS3NYHIxeG2kWGHM4f8bLEYyBI5LRC5XIe 2KimJI5Y3ghUs/tqIC9CfHjlHcg3p7hoP2KKBl9tniIxmsd2xORLWB7oGvjjLGMiNoGu18 hwgampGp9RfAfhPPUHW8QXQMu+yyJ70= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-156-HuTmpIlQMACOjLLpWZ16dg-1; Thu, 30 Mar 2023 12:07:18 -0400 X-MC-Unique: HuTmpIlQMACOjLLpWZ16dg-1 Received: by mail-qt1-f198.google.com with SMTP id f36-20020a05622a1a2400b003deb2fa544bso12792648qtb.0 for ; Thu, 30 Mar 2023 09:07:15 -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=DMVMpnsZhlCzDmy2F2m5pdLqAzTSNaSkGu3Wf6OWaCduGyLZE24S2QazmV0vvH5wZy mknrnna3lzKQKhFRpZpMdLdft92jjeTzl5NyxaugV2GM4g709a4JsLR0eMmtKoVca0p+ jG+AzMHW0EZfZ20OLYnwQaOfBfpHGFBD0/gMWwR1DLbE4iJ9baIIThbwLVdSAcmVpPB9 ocCE6N3eod8ECFkW52RL0Ui5s+QhxVjByN7k8DzIvfAjZzSTsSEQLxFIyXV28M5HCMLk BxEorr7j0ljz8jo38HCMSRpu6hoQBIERg1k7sIltu8FrGfDqwDfvaTPJxyuPU2hdzf3v 6MEw== X-Gm-Message-State: AO0yUKV6yU94K/NG8yETqwxnpWjMlFc/rxJeQ2EiZutwU56g4nIzxnU+ zb9LRIRVU+GE0neeSDXRIqfATRtb/2X/A06aO16J3eMvc4l/2uWQNBV1iIX+IJbg8o6ay7KaBxG 5WTUjdufJlEfhzfzCGF7h5ES/oLkak1vtHbNszTAM9G98dmSb+g7S4LY4/yIYs6ustYZn X-Received: by 2002:a05:622a:1441:b0:3e3:c889:ecf9 with SMTP id v1-20020a05622a144100b003e3c889ecf9mr39965922qtx.1.1680192434282; Thu, 30 Mar 2023 09:07:14 -0700 (PDT) X-Google-Smtp-Source: AK7set9xAaaiu8B7fUg9IKNqpQZzRasQSp33mstFG5mjRfDlXBiQLIYFStz2qxFjSs126X/1sVdKHA== 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: 28CF440010 X-Stat-Signature: wmd3irgfacdu16qkqrow4krht4d5yyzy X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1680192439-806725 X-HE-Meta: U2FsdGVkX1/dB+CMMYMb1PmRodsX+K46c5PxN3cJcL2xySSLcPJblEd5SQ/dY8ENFNUVocNoCQnbD448xbbGXVnRy8RYRzBeMK03/8/hCvCmz/7p8casnrRQxRV9n7BKcgjorXjjTGN3eWmpIkn01uF9dZaANy3m3Q+FSEz3QFuZGY6fmWdmUXiSlPvpTPC81Z4OzvMiS7aI/TuK5uBKvL5sEKa3R4L27LaQEGubGCfts9ZBzZOZclyYox5d0R/XYymFbza9J71PUjrPez54lXZAONB6UKIHTOp4yUXZU3jegXsP4/l3lqwmXun2rk9+KXcIfXIvgfgSHeihCoJsWtBKIfJIiqIlnBasFYuXV9to0Nte8vUwoPENF9E+rNiJGGsGJXWXfv9CI0JUboPnfvtzwRl+xUtToGx4/F87zZSqV+wtJ4NVZcSqHZI+ItMqz99b/XapVSQDEVVJ5+7s5E9xUS9x5eQYWHHP29HR98GWzElyM6BVapqEWsdCOPOuAv8hLYPUhM4eZcTwRnqMJ4V2GZrrJh+0qYTkh7ZMGb6XDBHz1G8YeOudTg3w+qoH/EPPDOk8vY5HLjAHAAUGLg+meDt5Lgvnoh1wHC/7nHDuRwC7ZBmKGYpUO1ZZabosy+3yA4TCw085FKZDRS6K1uyIv5j/su2sH6QlzUPizln1ljI2H4gBkcvvItTx5Pk2d4Zoq+AbKX/jCqbNbfiF6O/LlvZbu6Jx37izgvfOf9eV/cZiO0s3U/uGQBVg7nOEEOR2/W8RuFo6o4bayqtksNcKpsIrPuliRrekBHe+8vWB2pcQo86UeZF14UP+fCnG0YYFO5aDRZSrcvN6+um1wGrFm93VXFwnJquf1nEeuwSmiNyWUsafDn3FxYQaqeIqPBq38h8jYEGhDKEnq7qubA5X0mrdonjbSGLjUh5Ahc5zfBr1UScHE3RFjUw/PFrKp9F/5oiy3E3lrxBOrlA SwEX3Mnt P50hzXI+006+rpS+7+oWbTjC0CWghEi9LCsn4OswOPlOAC+crVjdsngrKBr2C9C8wzJbho5u6vv0F7EsyRMSG0+JXy/O+cgtyOalTTchyLXypZUJhFwRLBvr9F/AUJdG2dSooBye0W8VV9AXKql4XwG93dZw7mOxb9AvX/TnlRNcxnhqvz4u9MEq4jbT/8jwOkI1yFu21f4UvzyQVb0redQVYFW5RipC3M/97WJeSry6J4TlVxn0PleNFy3wnwN0w4gDp/t84Qz8EETOi5O/3JVTH7Jl5VgWhYfweyo087hyjRg6nDtXCj+UzVogQ1PUjks59tmaHP5mtQN9QYZniyiEM4ctWvuDrARfPI/vphx2xeyz2W+9DeJ/Dh2hZyASdVHfwlXTB9ZYN8Crq0Y/Bq4WACANI8N9akSSf+WXytGsJNj0gJcdTJfW4AcIbEQGalUMYB7qZL/BhDZhX9HyWFDW2QuoheQFKIHiURhcJaxtdGFJzdH/E95iBlMeraR+APSSMgiMBkl9cpyE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Meanwhile drop pagemap_read_vaddr(). 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: 13194492 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9FBAC77B60 for ; Thu, 30 Mar 2023 16:07:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B5D976B0087; Thu, 30 Mar 2023 12:07:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B0E02900002; Thu, 30 Mar 2023 12:07:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9AF3E6B0089; Thu, 30 Mar 2023 12:07:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 89D676B0087 for ; Thu, 30 Mar 2023 12:07:23 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 17AEE120AD3 for ; Thu, 30 Mar 2023 16:07:23 +0000 (UTC) X-FDA: 80626044366.04.8938B67 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf29.hostedemail.com (Postfix) with ESMTP id DA25712002C for ; Thu, 30 Mar 2023 16:07:20 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UkOXf8Yd; spf=pass (imf29.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680192441; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ASfRfnQJTCdEglytu7DR/J7BYjWDsPlfNboYF8myg6I=; b=Zy+GChEbWohiGl2of8HuLdl3QMtFx0tW84F0nd8LoZofzXVRMsh80ykGQj0cTRL66nkKFa ZbNX1cFrkZkRKkFmep048OlOER0crXCwhA1iuV6NptqDoN0aLhsDvYjlRpwFWFOtBrTgh5 ObfZPUd9NWENQVqDt3SGTWIIPt1PRcw= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UkOXf8Yd; spf=pass (imf29.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680192441; a=rsa-sha256; cv=none; b=Prmcfp8sbRcsHzmcaXHSbENLfbBQlSB6SOJJVFqGKydRO6eyHpkaO+TcsRvFmOzFroNnkG O0qB6q58LIFs5pre91XONsUEc+XRi/KuHQEOjSdlMO0ssusS9WhikduVwRdlMHQg0brCMf fifhApio2IkPXPaKIVMPTWuuK2YMgWw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192440; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ASfRfnQJTCdEglytu7DR/J7BYjWDsPlfNboYF8myg6I=; b=UkOXf8YdVdUDd4fsNqq1lIBKq+SUuzddFN5g1ueevJLfliIRJUXju9Hx7tjHqIhLezQq1P pwwlXg003fijOFz0+W41RNlgFhVI3w0EV7EdVt4uAcrkbA4VSv8sslp9SEfeiWg3ukdd1o Z4dRIkFbue7d5q1jjYx2o3bME4MlaQo= 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-7-uT6DloeUNriD93q-nyrBmQ-1; Thu, 30 Mar 2023 12:07:19 -0400 X-MC-Unique: uT6DloeUNriD93q-nyrBmQ-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-74678af9349so60311385a.0 for ; Thu, 30 Mar 2023 09:07:19 -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=Wv9oa7c72Gs9U5rZ/KvtFzmLoxZPYnAmhwMsTsngAGYQR7896M53hgsFHD4fP8TQ4X B8Q/dpWsReuS0i3c2Rrzpo8MDnr1n8u/gvNkMCLX0qPjpVLmDvEMPjQIWaWmEbwQnKEp HZ5YdCdfi67gHl4uexFII/uw2BhB/hZZ9h/sKNuvl9PeMrxPBzuHPilqIlxuDVDdDrS3 klKxuexcDDiM2qn1Lg5M+Rba5kcTmc2R9eMfNBF+XLRD/au5T2DNQaQwyStBAMYutEfH ljXKbu5CdlYapARAjLG3v9syp50n++Ya7tVmbCkMJEE3W/9yd05Cx0BeKu4J5yoUB7iQ YrnQ== X-Gm-Message-State: AAQBX9d7H4g9/zJit7B5MmFONtsZax4EYMGmSXewt8QEKwEV0FWnwAYQ 9Sgg+PlCpGaNRoEB24WJTR3ij3cU3+qfXCauC9AipFBLNaDHARFuSskdhLjm0tPnymfFOwBuTjf bY5blW6iZEGBR7rnSst1l8MgPsit6enmc4Z8Zf+63dVLxwC+aN/FhE7wFt5zUc+yAd+MZ X-Received: by 2002:a05:622a:1802:b0:3e2:4280:bc58 with SMTP id t2-20020a05622a180200b003e24280bc58mr4246305qtc.3.1680192437153; Thu, 30 Mar 2023 09:07:17 -0700 (PDT) X-Google-Smtp-Source: AKy350a/m9csPZTjry35+9guJnM30T3PDQjzdsPf9pXQljVsY4zoOcdyzpO3PTr9qXcknHqkrIxBoQ== 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: DA25712002C X-Stat-Signature: 475yj1mdefftcqidrptf3tx1nuoti31s X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1680192440-674893 X-HE-Meta: U2FsdGVkX18tk8tFPgLQ5EAskd4MsqFtksvSzJG7MNRj9kdGAsT6BIgyZMUOgjbCFmU+JTF75W++glpTN5fe2DvDENaU2hwlDHN9zZjjXcnXG1tr7K+XHQMvEn75oNN1BRDa7Ej2pKOzCkVjhfDE+TgYTwCFIde1d0T+yA8DLs4zcPTycBekn7srraWchgX8VquyfmvYcMddkDF8226MH1paSgK679TArTa7O/LwQaVkrX1Vt0LX3ids8bkTzHQj1lVeHGSOUhYo1zRs8dPi6Uwjuk0Hlj0UzGHjYAgW2vnE+A/wOo7qzRUbkkUFMZh5f9pX62nEgbV0KvVsSGUMIlLiwz0W+L+ZJqw70bKf5KEpo6/ee6dLoL6e23Pq26ikOrvOi+jdWMRcI+c0JxZvrxDfbpSG6qqcwsvZ6nCOdQWPchxFvuBSVJeCHAozn+Zd1zfUwUNcVWnesPZUas0N/yMMvI8bk95bXYS2MK/5RYcx6ccW1QAX4WEOCtPOjkOTZQChutt0n+lkE5PNMaXFbEk34Wmqn33zlY9MCrBoam/JClVgMfFZekBBpOQh7ejWlQgP5essPL87cAauOI/vtaONtpJSbD2vG5VsKko2jjPbph3zwRZoKdK49u0wQzlEHxXYzo8O0QqIyLyEMaSnPPp7INdEhn5IlKDkk9pSJJBUbGwOTaDnxKrvaSfoT8LqstO9IspI54hmC7E1THm6t+SwWOT9q1Axf9oMNTeff39nx57MOZcgTQdKBQhy12gZlafIYxaQiL0oqN9R+7LGUUaWhoz2imU1AXFw1v1R7jHq2WdZb8UMikhA3dJGUoN2aDUE8l6tAa7suyt/cUTO3RUyal+a4Va+eEAgc5u/YH1doe9ebj4aHK75UmKq5hG7ix7+GOCp1p81GFO8SXPC+KUc4IGkuGUVhXzIWm+qtuhx50jLcB1rxLVbV7mGmKaEBpABZWV8lyQUuPT+79N hdxi8ajx RFmKomYVBM3FjQpAOv8hbs47ztu6E8sH+lv/ejAcJIdTgYFYvgBCU6EKltDCiA089YCibhEJJdJfTK90ki/WXD7dtthOX0QrWzCvysnhDGnGxTHKiXOM5IoPfzFuNUeVbWMZ/SlQ3nj0xV/Qr7/Uea64vjgF7uSPxIXEsYi7sU1uHWAiDxwXz9D0TLM+zCj57FuY5+IjFmxzXtKDay6fSc79WxIXQuTgjrf9U+GQ3BrZIltLfHYR42LrdT17W8qqYYIvsLel6qJplgy9Ijag2HqZfbxXWndgwO+M7kuuCikPTlgq6O1dJ5AIpQeNiJ2xeGlOGbKgYQqM7SGo1lHHpQoAWE2aC1Z28oMePy4gFUkyY0xykpP4V6pzT4p21YsL/QPXWghswvJH+BSmBl5CjpneR84ZiJDexRSoHieAbvAbfRHMUsZlNFr8rD5QXqgYfeFRsHSNoZ227NLcvMxy7cZayWgNJZmmFf7oj/KufdnuQeXzoAOAARr3OqPkjNO/iz/gB/iZ+Bt7QORekq/XaDt55MylWpPCfdvpUUYw2Hg/6Kr7Y6aJzAh8w8Q== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000007, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Make the check as simple as "test_type == TEST_HUGETLB" because that's the only mem that doesn't support ZEROPAGE. Signed-off-by: Peter Xu --- 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: 13194493 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C4FFC761A6 for ; Thu, 30 Mar 2023 16:07:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 237806B0089; Thu, 30 Mar 2023 12:07:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 198EC6B008A; Thu, 30 Mar 2023 12:07:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 039146B008C; Thu, 30 Mar 2023 12:07:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id E46836B0089 for ; Thu, 30 Mar 2023 12:07:26 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id A923840F09 for ; Thu, 30 Mar 2023 16:07:26 +0000 (UTC) X-FDA: 80626044492.14.E635FAB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf25.hostedemail.com (Postfix) with ESMTP id 6A8D8A0016 for ; Thu, 30 Mar 2023 16:07:24 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=OAaB6PSf; spf=pass (imf25.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680192444; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=yBXFNiQEy11weTKM7tK5TrNqKeG1r9RMGXvyXsqJW94=; b=njEcRTDD/D8Ccf/1wHb+1Wlu+eYCciBFn4PX/d6X2B0wlJpiVviUQxNImR0uAOk+5fbnSC qC/IvNKo9T6mFXmns1NXI+Z/Byb97clHkS46xKX4jOrUxnFsKp0j5mmp4PCHd0s3jbIIc4 LtJ+qyNls2258KLOHhVJ2OBThxpt5Ok= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=OAaB6PSf; spf=pass (imf25.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680192444; a=rsa-sha256; cv=none; b=U9dC1lOwbOXgSli7nK9XZ0vvvzy2kDaDDcLQ6lIPEhMw7oZSI+YmBwz81HBCb3vvHKyeZY JeOlMVBMABRuAf+DAxorvFQGSuAKnkD9R0YAOHXXB01JGhc56rXSl9A+zsaHy+mFYMyga5 v/Aj/WycNzlSAkJqkwlXRxo/9CahfVc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192443; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yBXFNiQEy11weTKM7tK5TrNqKeG1r9RMGXvyXsqJW94=; b=OAaB6PSffFN+77Ge/obT0E5dfZiDAe/4WhocH6aDW/KsFRlOerAHzx5oA4Pv8p+j4J0B39 8bp6TXoA5LILGEj3o7cgoVnsK+gwFVZ15sn+YFBxKJSo4iGDPFXkFplp57DTxd1E/XgWe/ /Ti0MkPI4Z9cWF4SG7au9f1mofE0AH4= 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-553-JEQMdT9gNDWnYCZ5exj_gg-1; Thu, 30 Mar 2023 12:07:22 -0400 X-MC-Unique: JEQMdT9gNDWnYCZ5exj_gg-1 Received: by mail-qv1-f71.google.com with SMTP id p14-20020a0cc3ce000000b005e14204a86bso370711qvi.10 for ; Thu, 30 Mar 2023 09:07:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192441; x=1682784441; 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=5BAKYrMraRSxTDzBwrK2vPv6VfXl0/Uh8m2peju1SEJ7A/eR9KrJJ9ybtoVk91XEdF Zj5CvFl2gM2nJkVVA8oUtyp0p/JvRBUUbBCNXomDOyGHVqn21/+3xeUzBpDeAAvJRDf+ x0uWxbFRdM4GBF+bFsN6CSdn9QLYcDNVznLgvFoEiUtzGfouEkgf8SFvJrsBCnknqyIF 9F6GZhyf6AxzBY1akB+ip8Qxvbpg6AtqDWsrIJP+n+b8mWGyrng5AYVVDUtsLHXoYMrR xqlDUm+vK0SH1kc7sqYwbXn8sB6HZ25PHHReVw3jkNP9Pq5iDYYwCmal7RAAyG8UhoSv fF0A== X-Gm-Message-State: AAQBX9dF7nxNhUh3mjbHul5onj9DJLIIhzA3AbNA9p1bG6jT9CAxjQ2n J2uQLez1Bcs0jCpAl4hzlGMeFDnLw+XfcQq5op+4BUO1Jl2MJwsc10XepxAXn2FwIwF53tcQDWN 3uzljslTJPccHKmqqR13W3+MYwVahbWtJR3IUNWlfq3q1EkrxJwgJgDUGk207DjvQSJok X-Received: by 2002:a05:6214:f67:b0:5e0:3825:9adb with SMTP id iy7-20020a0562140f6700b005e038259adbmr3997393qvb.2.1680192440746; Thu, 30 Mar 2023 09:07:20 -0700 (PDT) X-Google-Smtp-Source: AKy350agoyNKdIa8Z89k2xkNRJVMAlfupevmh3H7qWdAB3fR6lzQMsGdBqB1QpElcSem0cMxlH2SCg== 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Stat-Signature: 57mzw1pm6uheishhpekeh6nsip7khwpe X-Rspam-User: X-Rspamd-Queue-Id: 6A8D8A0016 X-Rspamd-Server: rspam06 X-HE-Tag: 1680192444-916501 X-HE-Meta: U2FsdGVkX1+1ODl5zPg7+PtFZMbAZr4tGcHVslCHX5G+9zBrZxvxJTfr263R+ZREx9Ql1nFDJSlVrNUdipvClXYCkfEADP6z9TRqvNJ4q4h+32zRXnnjsq+9xY39ZzqyhpvwrySHmVLOV9e1TQwqtOMdu5JV4oEuY4a91Gy8pN4v5VsMi1sOwnQ6D1vFtBEwl0DxKzd+oSKOYmkeREqZxxTVDVaNTGV1pMWshzDgt9tBP3skoIEHfxrXV/BBuY6jqr/r0NwapVfcXvLxoIxJ8bA/QLblkuS9bRY74UXgWg24wnrBRVfbV/mhmLkpF8BYO7+3sR5seeqFt73FKpB6W0JmiD78rb3/EmrqxlWq4D+q+O8rUAp2dh3haXrUvgakvoMpBJwbiBrRg4uuKMUG4hVg1tTtQg134lhCvB5dQO/z7RUVHgjFJSoUi3Nhq3tQciWvQ1EKO3C7IKugjSjFldfwSOf6k9VtdAy32Mga0p7AdRxyG09H2u4Qz5aOu1WgB/yd/CDAN4ABdfTmhQJ4q2iqg9JH2zBeyJXfaGm/sBA+lmzz3Ygjcpvd7JrOnIO1bA/I86X2VNJQXaA9Ng6ql0u5Un/qNIwV/P5bpYMXY5dOG102hSV2fymJF4ajd3SqL46ZkWEeZjQaFeNmc/s/vqpqi0VZ122BjXFbsRYE9+GaWbDBMdQj9m2hwQZbaZ4+alQYyNoT81DLWGDoeLD6iApOl1O++N+zIuutRZzWYo0YJ2v0skoKrVsX5+vCIumUXCYa0DvKbshsrTVNneFMWLJU3H/7dsF+g4VkyiJ4dZQxC8Potkm1HIT14yzHMTnT2LR6J3jomf8jU2EorVjjmTeyrFyco100By+z6rr/ZRkdqJfwFbLqdpfAQzm7zsBWSeRIlApyPj/vUyCHpWTdzkIvksl54kthDHyLVB+ebcv8eHU2EEpGkgMGgZZnLWrkyfoK34tV8fusJs+VnB/ vpqXX9iY qVasKuQ7sWKrsg8zVC886oOnlvOHEcEVN5b/ddRrzix/H+RfKBV6zFDfjy9Z9nGbObNrx3BFN+6QDysREYAmuynbXpn2lWLuSavdQWSznypJM8HPyGzFgN7PFelAKQvPzJBnHfqVHRNH61y2qSYRe+gCTfPZwRvaOXv1ewM6BBA8cdD+VSwIKKcuNl6S0Lfz14H0fEBacdon20wN90lCqzaVnNPnjOQLizUC/QOk6lm4ZwRQ1psXzJV6JN+UAeiPzVJeiaiesA/Vdm0LzJnPi1ema773WiONO9mSOaztBKP9Kftk+g+Ujw946eGAgSt6tgvYs3mXRzwMtIvwLDK0dDGFlVy8Raf4GGei2nl2/SsjaqKqmv2FUZgGafGMACDEMEjIH+VeR6HcVnCVYTik4XZhvAER05tkjMqsaiBWbwzwSnTz+pu7TGWjZc5UlgztdgthVTEO9R0ZdeTdYPtGFF2jYXHymIOjix/jmBqfbhVt82zlNnUOVQoNacFcnWcansgsqfZ/0H+xT+BI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The idea was trying to flip this var in the alarm handler from time to time to test -EEXIST of UFFDIO_ZEROPAGE, but firstly it's only used in the zeropage test so probably only used once, meanwhile we passed "retry==false" so it'll never got tested anyway. Drop both sides so we always test UFFDIO_ZEROPAGE retries if has_zeropage is set (!hugetlb). One more thing to do is doing UFFDIO_REGISTER for the alias buffer too, because otherwise the test won't even pass! We were just lucky that this test never really got ran at all. 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: 13194494 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E364FC6FD1D for ; Thu, 30 Mar 2023 16:07:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2F9CE6B008C; Thu, 30 Mar 2023 12:07:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2AB526B0092; Thu, 30 Mar 2023 12:07:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0FC5A6B0093; Thu, 30 Mar 2023 12:07:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E68306B008C for ; Thu, 30 Mar 2023 12:07:31 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 698B0120AD5 for ; Thu, 30 Mar 2023 16:07:31 +0000 (UTC) X-FDA: 80626044702.28.3E2A080 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf18.hostedemail.com (Postfix) with ESMTP id D5F041C0023 for ; Thu, 30 Mar 2023 16:07:28 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bXv6sR6a; spf=pass (imf18.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680192449; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=db6YoFSypJnTIouTrDztz4PPOGN8H3NbJ+XG7IwkLI4=; b=LaOeIoXtSQVBxsn2HA6TioYPSOudWhdQbsbYfjaPHbMau0487625TmYvoUqZ+y/aJlD89J fxyjOHlsJ5McymigJh54zRAGLaOLDC/hk/XzxdnQZcNR3Fs+DoZ/QGZZ8Grij0fuOxYpAz si67c1tQwZ3a7VF/VWT92hN7awuIDL4= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bXv6sR6a; spf=pass (imf18.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680192449; a=rsa-sha256; cv=none; b=Onk+pTjlMqXAVgCxfiYURgZXoLdTSQjCt+gmAjQ0dtYdsLT6ivQOWG6y+5Aa5RguxJFTMV NJgkLLZsB169TJfrXCUPNgaS5WfOejNHxtNVP1wO5LuOx+FeOmHpJ/TuEgfa0qm495AjuY lCEO90NbnqnFnUeg97ZgYjiY/DQopXQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192448; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=db6YoFSypJnTIouTrDztz4PPOGN8H3NbJ+XG7IwkLI4=; b=bXv6sR6a/EV3Qrf37WvTxySwOLqzUAA5bCivuP14pvIhqqH2asqXN6yadL12nEDtJ2SOkc 0gGgjw8NHGDtVTP/275DGbAuQwcGVFctsXWRKvxTpbZDO5TCd63XFojWbYF3/sWsALeYXM ZNtxa835Mn4wDaEdkB7XCiqbOcUtVG0= 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-632-juMJoWWbO2SGY3gpzdwVWQ-1; Thu, 30 Mar 2023 12:07:26 -0400 X-MC-Unique: juMJoWWbO2SGY3gpzdwVWQ-1 Received: by mail-qv1-f70.google.com with SMTP id pe26-20020a056214495a00b005df3eac4c0bso5346752qvb.1 for ; Thu, 30 Mar 2023 09:07:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192445; x=1682784445; 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=lzTjWoKHOlUbv4AqCWGo4Et+cbjvHmxbO6PnBBPPHPCCcCkv/qzNHR0upu9Sq2b2zk GGTCgaj92dYwVK/+eHJCjMQZOuvDoZ6+m4mhKD8ZtqNIOyJIxfJjQ3rIabhsGGrH2sVR 5cY6bgIhWyej1WzliNaz3RZnCmwJsX/NnGxzp/ImgGsS4sr2ED8OgpI7A9vvdFKMmO8M r9ksoK1kq7Aqy65oqUekB+ZYPNChdKlZwsfgvficKpIsEcdZdPqIfLh85b9C/GRbN0oC ur07M96tHX2BwPru2CZp29OkIgdWPX8IEiIx8PDoJtdQeYwrpanDhFP+iIZPpKoi+wQI SBkw== X-Gm-Message-State: AO0yUKW2v4HmRDCVSnJiHE3aOSwAlmcETCNd6DEjBaXXijYfwnS1G6wt NQI0AAm8w/FAcbcixW+qo1ElfRRT9FzfkJzlDjLri+v8xu4yzldsBOeTzS46VAqJvAVVk2x4eCm xmsh2zD+XknNTuYrsi9lDJQwUDoSE3tC2965CuHuz/wUwRK1y5cfXMhcPvB9HwJqDkm5s X-Received: by 2002:a05:622a:1441:b0:3e3:c889:ecf9 with SMTP id v1-20020a05622a144100b003e3c889ecf9mr39967031qtx.1.1680192444069; Thu, 30 Mar 2023 09:07:24 -0700 (PDT) X-Google-Smtp-Source: AK7set8NP+ElEFUZi/FQlI+wMTehrXi8sXGiQJhwf0nLobOlWBUuFRTmOho1iWz5s5A65oqwy/4F8g== 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: D5F041C0023 X-Stat-Signature: 46qyit4krueweeqd79yd693xcuexsjg8 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1680192448-131508 X-HE-Meta: U2FsdGVkX1//Oi1z9tm04JbZApTvp8eNQsJ8hfCId20fVGaUUdcoD5reFlKyHGDhYIhcry8HPofO4nwAu6QrXg6lpT7vdjULmb2MYCcG0vasOzICmBpnJn7DSGjZ8Z5faS1qIcMBP1NpzenQM7gRlzBBVOjyRMnuZOwYhgWWDjJhiAm+Zx6s3HrfLqZI4CLkey/m/nGOcKneknY3wxeh67Qr5Jol6f5wl6zHB10DOClReRnAQst902fZyEQa0YqcTnia70MR0f5+BfKkN3R1KdT9buDJQ1mp6eOPg/ffyF391fDnt/EPhiVgtCgjIV5sXmsfSfqSmRBbDJsM0ndg6X03iNi+IavAZnY5rLF1YACese0psf2KWPHtehZWQgRcJyszjO129duVWtXtfjUXjdGlPtYYx37K8CvsqHzboGmtXm8EKH3VudxrS2ymTy7SOs7fA3brqOY1wvZ8kHXSuONn/TAWljsSQCLAK41P8AxleeTJVTNfsPDMohU3dQAJ9Ziy/p4H783Lh0ne68YkC5Gkq1rGBvhQtzn4kcRZJ5LBMN0lbvK5We5VJy54OgEO9qX7H6aNFXVAW2xiE4FDcDiZgbYtXHQxFXyzb4jhN4FiC64y+i3L5ArDZTZc+dsl2KWPgZuxgJHmcAaH5K+gY9SI94X6nwftfaFbNJs+uq6rvdIJKrVVsjGrxk9zHL21AljItYdUCkls2A8U+dY87iGSya6ZGfVlPh556wAkf3gTbDIeOCNj/2OttgZzK6xh/49ZJPAn6KY9Vt8mY0UZjiB8eog8bPmuO8pPViV0X6e5VhIeZWZ3yJxVmn/vIAGVrgSbdulbt8pIoCsNr/ce7ziASSut1pXTFUVXA7m9dJf/q2krTVe4ZUkgoyeNHdB33ozLV0DZYFcARls6RnvPQTyfxR7p6XGvlaACHlm9zKmAU98sF4PkVVx8XdI/tb2DDxCpzE4J/tLzoGXhqMT +lv3RTJ1 yL7ww3YZD1UZi7PuseqOUkjaXm/rKF1QUqr/c3tcFhxIgWGOsVh7509zbDNRy2HrvmPBrEobYfQesYuDbTf+vJRD3YInZGjq1OSgu8cU0bsw0kFyaN0EWqa4PLczFYmhcvpJDMzz8oO58y1Mr5Gv9ITyOGo/FJqNlzr1HVh1WVZf9PshcOjDrx/956/oAlym4zpkD0JJlmqCfvHkIZSmw56ISwfEXRrMZoHp3+IfuJ4lTp4ZoFGw1hCXjJgLscG8sUiK4ai4K3wZMN8IBg6j51/GaosWxglAQGmoHC0kjXPN+Fw2zbxubsMGTZm3UEQcMVstU9adRtquXsqqY+5BoSnpNVGmSHBfGghI3k3S41YmH+dpQ0Veyc7RoaeVz0TLMWYONvor7gghL6wQSnqFeLlwniYkKMtasbCTkUzrElKw1CeFUYBG42P63ZXhuH9RfyXzM0kQpGIdQdn1oSklaBTt0aOp04+SiAXAA X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Move common utility functions into uffd-common.[ch] files from the original userfaultfd.c. This prepares for a split of userfaultfd.c into two tests: one to only cover the old but powerful stress test, the other one covers all the functional tests. This movement is kind of a brute-force effort for now, with light touch-ups but nothing should really change. There's chances to optimize more, but let's leave that for later. 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: 13194495 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E6FBC77B60 for ; Thu, 30 Mar 2023 16:07:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1EA0C6B0093; Thu, 30 Mar 2023 12:07:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1BF2C6B0095; Thu, 30 Mar 2023 12:07:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 011E4900002; Thu, 30 Mar 2023 12:07:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id E15E96B0093 for ; Thu, 30 Mar 2023 12:07:35 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id A8C18A071C for ; Thu, 30 Mar 2023 16:07:35 +0000 (UTC) X-FDA: 80626044870.30.E5D9800 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf14.hostedemail.com (Postfix) with ESMTP id 25FFE10000D for ; Thu, 30 Mar 2023 16:07:32 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=BrnrCJli; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf14.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680192453; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=9IAbBMcnsKQ/wMG+wiEQBSaGDUBrmUfxUQY9hBhFLu8=; b=RDBetNJ5EExiaiLuxFwpGgDbXKs5w7lLVUTLoaGYkIp1Hmv+prN7Dp5brvgvKQtndDh+Wd JQKU5CE9ErDhPBWFiU/gh1P/r0hN/pPhMMkFrHPRFFFm6eyoYRanI3Dy2zHCJsiH6/ssYm AJzS0T/Uq5SDk5B8GLiCp29NMNZqAqM= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=BrnrCJli; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf14.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680192453; a=rsa-sha256; cv=none; b=G1kFgalYyb4t0kd+T7LdbJk6+As81Dh4ohABPKj1SBcipEGz8/AjVhUayDzkW47rtjlgqM V1UFUHpNcrq/V5rrFROLcecT+uPZmK5IEXEptaKSOUGs+A05OqjytryOPVJNirfw7kDkO1 3gVOMs6F7AJ0pQsmmIDk/aeKpFb3s40= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192452; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9IAbBMcnsKQ/wMG+wiEQBSaGDUBrmUfxUQY9hBhFLu8=; b=BrnrCJliNJMaK5S7he9guLfIl9SioaTPFQ/CLsobhCATwAXB0DO8jwO/AvfqVIFnHMR1yT L4IeWEvTKdPkOmFNcTxdPE5tA9DGtpWLtlLz0FzeZIlGbmmy7fwhpLjlRz+MZlCpeHu09L 8M941CinsK16MmqMEUEUJ+lqZcW2ySI= 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-475-ac33Z6lGMRCyfmAknDlKxg-1; Thu, 30 Mar 2023 12:07:31 -0400 X-MC-Unique: ac33Z6lGMRCyfmAknDlKxg-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-746bae78af3so60162785a.1 for ; Thu, 30 Mar 2023 09:07:31 -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=tjAbjHwmQiKG7xowKHg9SsWC1u0GOmXlmPqkjPy6+sSrshmWs5wF70x/v7Q3jh+djv yxp+kjUTWqwpZIkC8t5JqZy0wy8EzIt+lBgwN3BAyuTKhfG3JIJKf+0zRufMctyHJJPr Fmw0B/5q38TIWQj7nJTDShk91VFCCnslhcbxLfBhQ9SDEu5UeyA2DpdKfhPNfwavjo2h nPrXAT/5xDWn90LAOdR2vIx34R1hVwro+Y0O4Zc+U8QDfzf3TOtvOY9gK5IuLbiwjVpG 0lJGFv5rHm7g4COjCaUx33zOzNnMlv5xMmFVi80zzR25XWUBNghFRdrZk2gwgmT4C/5q et6A== X-Gm-Message-State: AAQBX9ftnSUFeI0isZOzFMsJDu9izC5DxD7eUX8RfKbyQw8TXz8m+xEJ 2LWuE/yiKzLLBLnR2qdHXUfGYEftfMI70/rTpmTb9HAsjupDgf2L4DeAVSyBYU3KhVQPe5/LVeH wT/rWo0xcB6xmhYSyLvtV8oI0KS1Fm1RzJVwu+xsgj8G/INbGOgtPTQcwG4aRdJmakoab X-Received: by 2002:a05:622a:1885:b0:3bf:cf77:a861 with SMTP id v5-20020a05622a188500b003bfcf77a861mr4161770qtc.4.1680192446777; Thu, 30 Mar 2023 09:07:26 -0700 (PDT) X-Google-Smtp-Source: AKy350aDzum34tIGGIl5D1DP0AG1BkXRe6bE/ERsqntOfZrNMLu3f+ZX4TwL8/dXblBvXoRbwqvGXg== 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 25FFE10000D X-Stat-Signature: 3hw6xeeexumtgaos87riowfm9rhjayge X-HE-Tag: 1680192452-804463 X-HE-Meta: U2FsdGVkX1+56ok6OimJdwNgppiY6iCpbdx4LkyApXEftpabsbau+t1PPtlkjXjse8/IjTgANk/euiCGhz6+TaXnsyKPHrP9aocyaDoHZQHxkErXoD60r89a04nlI2e6q7UiE2xIzdchdcc0Mo8RaFYVldTeYHNA/4N087dOzFun5fD0TaMAMf1gd8iIjtJfrnDBeaAeyefUdz8tNAau/yHnrgQxmDuNastA7XHHVjvYB3MZSWhI0TggyZKzs7OBdESvmiSgvRkdHNjY+gyalXiHwEdrxWT7bmCpkcmgQYR/qLtElAviYfeqzfpBM6KjS/Sw/AIRXENxSYubfjYmItDhKCILUdSPYGBMPpwf/uPB48eshRO3egNbEg8ocI//5DR+pc9lhCPBUz16M2303hTaZ+kF2KK5jzgwAXWp2gwmtIwpajaR9qFKqLVVtqhXGQozDDS6CYq3HhMY5FQwPeF66ItvJBgdkWkawSCE3O54gr/Z+pJfd9MuCSNVSMcgXY5I2Tgro8pH5aiAW7TYExvXHJDfjwFV2C4Fd/CiKTP/4Y6Mef+K5X4RFaVfuHTYuH1R/UkjP914d5wuO+B6+qM1gP6dA47k4ciSu+FaqFd3EVIBslJ9dATNLvaGX7+zAJFvgIgozVRd9W4KW9zKnXwnHs6JgpVn2+u4DFxL7vrk5OQ3afJ/550Hm+xnPzzDtIRe4bWyDL7wHpUTLBaqSl6VUan8jnquS0xf2FmMvtWF8yHzxYyHkcuR7ON6bx363VAwwV43qEkB4/ERc7XqUNiZUp/yYkH8vAyKV7eLmISszhnEaZIuP0ItrbNpvpmSVJfnP89MdXcDOYX562IyCdLzkF0bBVGvi9XH3vUUk3ByyyVjNPR4DNNdd89dWpHDsXi3I+DEAAWngesDTd22XIh6xo81NmOfZR3ASmWWC1YuHmEPfeF9QScx4NxnLyH8EW9t/GGQopMVRs0hnCJ hwarcGd8 xbv21LBClMPuOQ88cK5VOEpQphGSgbn3dC0ktOmWPaywMiNKWbW1y+w86Brf7VbtdexLwGAw2TLF6gpogled4/Pi3Qlu3YTwacF0M2V7zT/1RfN8IMZwLssB77lYcmtytT/fMaK0nZmxmeIRlrS+E1OvUFBaCIqvGEyWgIwXzQCyI/ESgK8wCcPGzNdJdh1OBTu+/n1VmpJGuPeegSQgf8fVtKCWfQmNro6ldmkrYuvgCEDbUAXjyE0gisgGqxHcLf1bwJBwotIvZT9rpw9zxoj+m5lVjxX5wNwL0Tyf8yBN3f1Hl7poamXOmPrC/IHkD6PGw4PvMi/Ad2civb0wpFcs0YXXcEFEZd+J0vj57ksvLU7aBFLIIsRTTXV02ETeHwgcsWfTjZGdvSWBp2vkDwYCWlWAfFwpQW2A33/eDuu5HNZXatgMIg6CVuZ+T1qDjHT+D5rWpe49saD9mKb4QGizyGi6uOuIAephy X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In many ways it's weird and unwanted to keep all the tests in the same userfaultfd.c at least when still in the current way. For example, it doesn't make much sense to run the stress test for each method we can create an userfaultfd handle (either via syscall or /dev/ node). It's a waste of time running this twice for the whole stress as the stress paths are the same, only the open path is different. It's also just weird to need to manually specify different types of memory to run all unit tests for the userfaultfd interface. We should be able to just run a single program and that should go through all functional uffd tests without running the stress test at all. The stress test was more for torturing and finding race conditions. We don't want to wait for stress to finish just to regress test a functional test. When we start to pile up more things on top of the same file and same functions, things start to go a bit chaos and the code is just harder to maintain too with tons of global variables. This patch creates a new test uffd-unit-tests to keep userfaultfd unit tests in the future, currently empty. Meanwhile rename the old userfaultfd.c test to uffd-stress.c. 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: 13194496 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6CDF6C761A6 for ; Thu, 30 Mar 2023 16:07:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0AEBF6B0089; Thu, 30 Mar 2023 12:07:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 060806B0096; Thu, 30 Mar 2023 12:07:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E1AE9900002; Thu, 30 Mar 2023 12:07:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id CEADF6B0089 for ; Thu, 30 Mar 2023 12:07:55 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 786C2A0A8A for ; Thu, 30 Mar 2023 16:07:55 +0000 (UTC) X-FDA: 80626045710.15.4C939D7 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf07.hostedemail.com (Postfix) with ESMTP id 525374001F for ; Thu, 30 Mar 2023 16:07:53 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dI7mhydc; spf=pass (imf07.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680192473; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=t0fDgNcYvYYWETXPJiek9vgfY3+GH1MCmZd5+QiqXiU=; b=wYlRMpvEQV72ThJPjgKn6f82TxN/+aqhg9KIOWGA+9e23Cakv1inP/+0JESV24gJTUuZti vS1+XKvhCii+K2StDnF2pwyc7CPClMC/hqD0RJVXZW5vTdIJFNkHYXa+I63WDg9TOj3FC1 KvWQ3/6HUAAVAIdvX6igimgEeS6t6ZE= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dI7mhydc; spf=pass (imf07.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680192473; a=rsa-sha256; cv=none; b=djzTFOYDto8E2LAZ1T+4g1KbmkP8sjvM4M+ngAQKW2X5Vtk3P6YgzSzkOZuQ+AB2+KrA6v OEccKx+Fh9ME49eFdx7Q2jPrEqJfWMDDXmu/c6dY5zncxEXUrKkHTkXiNaTPm56ZgYHOX9 fO2QncVkg9js5uLLXAkpDXS5euadBIk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192472; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=t0fDgNcYvYYWETXPJiek9vgfY3+GH1MCmZd5+QiqXiU=; b=dI7mhydcHKZBPem9OeDzGFl/vte8EvPgzjHESFkfS0iBUsNck+/k2IN5+hIaxebMW//nAk +xDn9xhpvtS+t0vAdw61+TmQ+PPSrGDU09dL/XPNsaC5ddyv14B5pmlP5t43pMODOXV9sR SYJD5KpixyYy4ZySZS+UgXbFpfZz/wY= 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-618-nSjpTbYCPb-MpaFqtlpjeg-1; Thu, 30 Mar 2023 12:07:51 -0400 X-MC-Unique: nSjpTbYCPb-MpaFqtlpjeg-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-746bae78af3so60170785a.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=BEprBhDyPJdq0QLhIzPzcvE9yFpRESXdl8A3hMq/Zy6JUqOO9Y0kwgPxLLMovQBL76 OUaOOW8V3V+IQ3t7JOo2H3TrjW7i4L4E0eH+9+XFH76vxcxBazcBgVVekA93k0rJzFWo U6IJQhKZod8Gplo3hFZQDwEg8nsv1U8fh1P4vOHZNmEHv4dt2NdxGW59WPXwRxDt+nN2 tCroNkRbhZ6f+N9yq3fOmVYqDrrxFww+a/xrjoEVMlv8044TQ08wV7B3nMFXqvz7/cCS /L4MP1zyDFalIZ9hMyCU8PvVDLMbv2ksqKVPyeG/EubfNqtkcSzXrKOm/vihQjWNjmJ5 P2WA== X-Gm-Message-State: AAQBX9dbathKBSFOdlr6sr1UspA950WgnU3PNf/eedRLxz6+ra2pZVgr xoRIT5Jsh5JihJ7XH8xtNCzi6MkalXzDX2CVnxJEjTIAVW5nU8FC7Kf1Sh0i3BYOn1R1sAbXUyI 4XF26lOtKqnTflSl3Gy4u8MnQM3sidGCYb6esihMxsBdaM3RyvpP9dhkGBj/g1XZ0wNh8 X-Received: by 2002:a05:622a:1aa1:b0:3e3:8e1a:c30b with SMTP id s33-20020a05622a1aa100b003e38e1ac30bmr4579825qtc.1.1680192470111; Thu, 30 Mar 2023 09:07:50 -0700 (PDT) X-Google-Smtp-Source: AKy350bISALJDsJEmaVdBJpcLTGX6PSIXoG+fwKiOAlCT8YbnZWDRnPeLTz9TUVS+0m6Cgnx60xAtQ== 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: zpp66i6116z1b5d7dn9tx46mf9ubdfx7 X-Rspamd-Queue-Id: 525374001F X-HE-Tag: 1680192473-295478 X-HE-Meta: U2FsdGVkX1/mtPcb3749SxIYxY4IJj1N+VnF49FtYkqdv3F8V1m47GPR5Sc164gRMo6tzDicvKYyV/ndEDM/YitZGXA2FyK1V7/vA1rnVoA70hcBPDncMqSO7vlfjGe+rpCq/4PR/SIK9/QsKobQL0wWEeDAl69rCnMJwzz+WQZNo6TZTkX9Nyrjn0slsn08CL6BNz6tR6Kog37DvTvxSRsvFSBI5gYivEIV7EmeDjf3cIcrHj03TbL5kxIUXPTJ9LKuwEUKv603atpY/CcaH3nMLcstTVUeEyy7xVOWQucFJjT55k6ghUKkBA5Z4RojcvzEp2zk7pa02anwWIieZt5byE372lW1S/28qbMpoSFIrZZ34cKY4TCrd382TAaGRpJaoYfcwOjtRf8HmdRbaKDNHdgms4+rXeI/9w2nmAeugCBiTAhWjvd+h4/SOmMW95vfAJj2zLsG2r019SzgNdB65eKX/BRoDkbskpM+GbtQ/SuL5BpQFNT2TX8lEO734/kAEuFbaslTyyJbfGf2RP7WNusbZJ1j/zU4RsQ4tHHGbo2Cd8coQU5rMWuhupv9GlPEKMycWDT7kpVVmRxOugfuw07fPbIiAuID80uvpQV6wJFQl2sty8KVWxkmgHGnyzt+eDBXbsFeGeMA0ZqALzK8nMUgbZ32SZl1Tw6j2uk+zt2qx+9wf50NqkIrwPofggXotuFjwZWWya3eHYk4Ex2gynzXB0hqPpId/rfi/5ZA9n3+Z6HwAKMYw9L1aMsSMDRD5sBw0Pz44rzXAvAgfPLByIKjVgQLGjMQlpAZ5zFGtZkS0qeP36E0yzrrLUlYviBHdDcdPNILuvBc4oEqH2G/Ofzg366OYoy15M077vPhPwMYYuqeGb56nxfo2vtLMegPKg7WP62q6IrcmIKni2QGGhTjbuuaC6lELw+DgmK//cBKH9jYc8IvW7Vodwi4JceA5kKstkMYoX8blJR L8scKHRe 2tXXYnB5Uqzfc3783fBIc2CyFT6UdeyBG5V1ajr8+vD/mrQVluZICUlG1GftUYDIhB8nmXOa7/n48EJs3wex4qXF4v9o99j/yEXFXFBj2j5cDhMbAeZUcUCwr67MwpgIHb2czwkq0K14H7LJjfKeoSFFjzjugNuoVBTx/sOv8XizQN9hRrwwm/6y6VU5zsr08RHyjGSFFmCEcjmT6dOC3HyfCoEcv1AVh1sENMpKjE3WTpTVS3sxYUjH3/xqxpiI2JmmjNtCgDcHm1gNH0RYl/dv6PTC6vK7Dgim56K6Mo9ggksspPN39Jp5EoTjRkDDHcaClGbZvK/qowrwcUmssZOl1+njesgObGB0O7GbLtFUiy9nVs3jNim64poBUlWM97jXSugXcFfcIxc/8DeboSALfrBkLGemyTrIvg0R5f2GxtDYTHzx6GNhShVOrWCB+sZKSGhYV+tS40pKxLIdCjrCR2DdVlyGrWDOkDZPcWVne+ELUdAVkm5E7EWGtr74PP35cE0cwUJCk7igt6OTJG51JesIO6Ak/RBgxWp9X+557oOY= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add two helpers to register/unregister to an uffd. Use them to drop duplicate codes. This patch also drops assert_expected_ioctls_present() and get_expected_ioctls(). Reasons: - It'll need a lot of effort to pass test_type==HUGETLB into it from the upper, so it's the simplest way to get rid of another global var - The ioctls returned in UFFDIO_REGISTER is hardly useful at all, because any app can already detect kernel support on any ioctl via its corresponding UFFD_FEATURE_*. The check here is for sanity mostly but it's probably destined no user app will even use it. - It's not friendly to one future goal of uffd to run on old kernels, the problem is get_expected_ioctls() compiles against UFFD_API_RANGE_IOCTLS, which is a value that can change depending on where the test is compiled, rather than reflecting what the kernel underneath has. It means it'll report false negatives on old kernels so it's against our will. So let's make our live easier. Signed-off-by: Peter Xu --- 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: 13194497 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2090C77B62 for ; Thu, 30 Mar 2023 16:07:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 40A986B0098; Thu, 30 Mar 2023 12:07:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3BA7D6B0099; Thu, 30 Mar 2023 12:07:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 25BAE900002; Thu, 30 Mar 2023 12:07:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 1275F6B0098 for ; Thu, 30 Mar 2023 12:07:58 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 8DEF7120AA1 for ; Thu, 30 Mar 2023 16:07:57 +0000 (UTC) X-FDA: 80626045794.19.F25CDBD Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 34D51A0031 for ; Thu, 30 Mar 2023 16:07:55 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LLhrok7D; spf=pass (imf15.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680192475; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=y+QAWrtqijcBRWNbbJvqOTcdIrT0hJlkJlw2bNALieY=; b=ppW6ExqDv3QUkF+hFQBLd97WBSmBN/ugFz8vyI6fhTAlpD3A5YI8LYkP2/T27MKJq2KRgJ mYliENzzD7bWJf2YpZ9ee/ZPcW8fUEdpCe7SWZf8EjLKjPNTYx4BH38Q+pfjzugUesftBv 65G8uFcQ+u3bfa74mcIEgm6gKSYbeqk= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LLhrok7D; spf=pass (imf15.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680192475; a=rsa-sha256; cv=none; b=nFWYtO4Aynvv6dQvMcvplPeOpTvYqavp+v6Z7Ke0pXTeoYgIKEF67L8MlESk5MBzPiWPTO CUEZXis2GqPcnwe2DJhF9eHbZE0jL0dtT3miZfZbsE37BRe6Auc21OPnwffhvBKjo6Y6/i c3fHfG1mySIbifUT0Z5tkSgo5rkGslk= 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-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y+QAWrtqijcBRWNbbJvqOTcdIrT0hJlkJlw2bNALieY=; b=LLhrok7DfJR0AomX8qvUMJxVfniyIfmG4v+yvKZDuBy6FczHqJYZQ8TkQqPbsc8K7G4TES evXH4wCAsh5YLvhtSHJdV95+myA9jsQCLQnxbaxLWP1lx4/01RI2dApdt1scDncEByX/1/ pqy8SmUsGjy0Dk97nb+xnMSNFrvEikA= 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-59-5jjfm70vO8aYH0CdLP3NIg-1; Thu, 30 Mar 2023 12:07:53 -0400 X-MC-Unique: 5jjfm70vO8aYH0CdLP3NIg-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-57c67ea348eso12977346d6.1 for ; Thu, 30 Mar 2023 09:07:53 -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=WX4xr8R0AnQI4HjxUtWa4+r01Ub4fbw9vO5m1pMurf5B/EffW/SLJYpT4w0UosMXgv TaFxNs+xZmBNVDq05oV37ZifDlPQhcx/03tOgkvWIBfdm4f77w1mcYRc0jHYR0o8Y3NL HTf3cS6yMW28j+oH1Jmz2GIAeMwkFV/LAb6PWM8RZvJ491UTC22l24K4cNcH+Ji10zv2 Tki2AepN9BSCuqjWOZI3xhf3Fz7Us+EgU96Ii/Cx9Y8nNBVPvopyJybShK074+X4EV59 aYLaZ1hs/4Z2tze+8r6ViZvbmIeo0f9250uxboteFz0LY0KIPt4Wt5nN249GRIz9chde ifSA== X-Gm-Message-State: AAQBX9fFyJFC/yS/dWT9ieDriIE7LaubN+mK3e894qLCib290DBDzVEQ 8TT9x5D7wjH5FcIB6phJ93sMWHSnJIAlGTyN0L/uW9LotoMQjwhWKdqXSkYZshWhU3AdLg3Nd7e ztNnttrFjP2jjXnapiRCfLsLmYcosZ+SsLfJOlABnKJ86wrWXMG8WsjoBYscw62cbgZC2 X-Received: by 2002:a05:6214:5089:b0:57d:747b:1f7 with SMTP id kk9-20020a056214508900b0057d747b01f7mr3712141qvb.1.1680192472277; Thu, 30 Mar 2023 09:07:52 -0700 (PDT) X-Google-Smtp-Source: AKy350ZAVMXrazBe1vAQ/esRv12K7m2amBl/weU4s0XRJNLyUQvvVZevPT3MnJh9bSHpN/NtrYQMVw== 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 34D51A0031 X-Stat-Signature: eibjry8zigmqf4xi6xawfkcygikb4615 X-HE-Tag: 1680192475-935324 X-HE-Meta: U2FsdGVkX19IrqSaZCpp4FIs9MNJ7Xr58eLYPHW6Lvj8/YDNXo/9SkRP5132z/5qJYk9GV8/pRhyu8O9Co71LRM+WidzjONyotlR01uJKjAwufnYIjuMznmgdSM+vOeIGa7t1Q8BNzVW/jGk9utWD2+SmuCuCGWK+saxhV96A2bxmOzaRElOyvH/8EYWin5ujKjDfR9f0bo446oTjHF74f3TkzDLxuwVN68/KsOJM8RoKaIAIbbcBwV++XG9WBkWLjfLEIqGIXXU7lJJiagy0IFtoT7Y785AgXuHX7bZx+Qx4xcjELVoi7qjnxIKCm0z8CKGJBtKJHozZfoQP9keBBq5gdQ0n5D/KFY1j25HVnrya3KEZIYlTCu1I1vU6EeyfjGhrBdB0OB8cfkaPIn7zOwiFAjAUGY13XMmdOso8XmnW3eK2fURKyUP0YfgOv39692UHWh9FvHa39Su7tN6os+np21MPIXoiKyBTNpq1GYEyBPYsE8n4ijCnkewDmuXWkkQetdagfNv9CQHL5OatfXQ5rRWaKS5JpNK10BHbCldtkjIPgdjGtMWhnpaYnMC6VZKfSnlhnz36YiSNA/j8wew8BkYyjsex4dcSGDLLqp5If0mbzztJSpuPmkugixif78sRwFXVPCzwaK5CwpTurenD2QSKwCpKiL3LOZQ5w4x5lgXNIpe/ZBeeFiBD3cTjScbi54YsYlEAAVvpWo6Pu2HYea1hA1chXbNrYXGpYVEyYfpd66yrPSx+f028DMwXWWtDfqPo5XFgV85tOdMSXQU6XstxvwuS3tbt99JP/38tVGb2qwpSxCnqUHx3+qiY+Kn6tUzCIATXdNNmwBMUe9VsiZZphSpi7NE7aGGNSnnZkDRelGhfniV5sw3KlIC+b42mExCgPZFKzNsQPIi8QTwRPomc5qFX85LxtRWpIm/UrXdh+CDJRIC+jSs1W5Oa2iUyX77icq8ioNRgg8 6452tRHG Pti2ICFZ4Z5zjdIJNzmNK+/P5mQPEeJKjfWnXtRLmJ6BGKfNVIfLCZZEFqbuLLOFY3s9jGiGXw8EEh9in7Zk/Q6lwV6wsrEhJvstTVAYJP36HddtjZMo9fxG4vh68YmbSqpDNXOCeTD2eO4baOmPrLDEK4X9yUsHjtFTbUfR3TnzMUzQeVgvd/yuLY/Lye2H7uoHc0mqjT1Q80lCAyxBWFkEDDlHrvFolAWhAu4Kd3YL3oiKNP7jAbgURweeAKhy37wMLBNDzr1zdYTlf9JjpxMdSDSjwxB/2b2LiE+XRPqmfA989HkwNKLT1Cy7RWLzmDOKF4NDFng2FWOaAMFIRkEzhltQYQoWMvbXpdLXdlQGH6Izeh8g5D7U7Pz9LuT2gOZqyLyXqK3HP/Myj9S/8hUy335PIjwMxsNI83MSAXFSw7WofiuRj54EmvFxE7u1TH9AIRMuDF4P/HJpTyLgewFT6OTzRJ0uy9yWmyBbtJ3qKCxbsWKRpmXf2M+wKrkIQah/wEIjHx6UVwQM= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Provide two helpers to open an uffd handle. Drop the error checks around SKIPs because it's inside an errexit() anyway, which IMHO doesn't really help much if the test will not continue. 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: 13194498 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 631C7C761A6 for ; Thu, 30 Mar 2023 16:08:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 013CB6B007D; Thu, 30 Mar 2023 12:08:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F0463900002; Thu, 30 Mar 2023 12:08:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DA5C66B009B; Thu, 30 Mar 2023 12:08:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id C74926B007D for ; Thu, 30 Mar 2023 12:08:10 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 85B72120ABD for ; Thu, 30 Mar 2023 16:08:10 +0000 (UTC) X-FDA: 80626046340.26.FA4CD02 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf05.hostedemail.com (Postfix) with ESMTP id 0971D10000B for ; Thu, 30 Mar 2023 16:08:07 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eD1kvA8c; spf=pass (imf05.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680192488; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Pi0McrG33VvWSi8wJEF+ZnP9lqDjRKaT61ZsjgmAIPc=; b=IvCEJhAAZy8Ng3cYlSRTzXM0tUKcJbCD89kXqQShp82MN0LeAchCJMk+BaQlj9w3dKACOP Bn1fj6LZlhWRzcIHIq+lE3GgwBsO/jA3zzs7B+b23TiOXePjdqvLJnfQhXQwQrWIAxqL4d 6HkRNF9fYn0tZnF16jvtpn4NOBB3Pjc= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eD1kvA8c; spf=pass (imf05.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680192488; a=rsa-sha256; cv=none; b=qzfqJetPQ9ygXern5APx7BP/oEUaJE5pPwKD60YJw1OSeFf5X/xA09BFofzR4zdjQE9pIi zLn+ddqb5hvSbztOQF+hVURxNelqOLqabGvSI8tZT+yTYlrr+cwHNy49snuEfxzjtZQHPv TsQV+TdUu/ZB/nkMTgObBKFSk30cp3w= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192487; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Pi0McrG33VvWSi8wJEF+ZnP9lqDjRKaT61ZsjgmAIPc=; b=eD1kvA8cuhW/LlQs5JnYhy8M7UrJcwPn02JK3B1Eg9+GQUrCnPzGHmT++jsOpFKJrakymS 40PQyoMLs+GLxZXWYcoU4uezTdfMdTR7vueGsgJQ+JjUVAkjcP6JEw85DDCE7LqYP7Llik OzBsSBWzOcN7YnaF7S+5+Lks082LPHs= 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-547-sKLJ8rUVOya-SKjBwx--kA-1; Thu, 30 Mar 2023 12:08:04 -0400 X-MC-Unique: sKLJ8rUVOya-SKjBwx--kA-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-5aae34d87f7so13016356d6.0 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=PtUlYRLzjJdO441eA3k5uNbCE7+TmiTvihXdLB5TjerUVsh1c0w0i3mLtXZ/1/jLXC /i6OA5buQAUQdDtrIR3uEaJvYab485n00lEMYS7XrApHrWZKqBI0MDSi7lkp9mvAPnEd RjGxzH0dnhB0kt4KjKIymPzBdkcd1xUSA3AeuMuLloHJfyoVzAX5GHxTO1gMbZMiztW1 PNNvEaeYC/ubIqQfNNZ2xYQF0jbtUtGvuUn4RCJkEMG/ETWHHmIqvqh0eCpNzGeTheMz t4mBbqXJfK6iw0cR63WMZx5ma7qaUEiNSIkQbbg1JUHz2Ls68e2S6+shYSsn6WORmB2o iQsw== X-Gm-Message-State: AAQBX9f1ftsLo//kh7OrgX4l299JQt9npmMoMBBgUWwHZQcpk7JZpX53 8AYZ91MnuxZC/cbpjuhtZ99MRY/VUl5a50Njz7Vs1htC7OWryV0ZZSBT0lXmcE4vj0IS2ErEUvs TrdHEEh+42vr/FjL1HH7yyKhA70mj3iUPqJkJNjwJi96LhRd3ouBrfv/2/amWlU9pPmUD X-Received: by 2002:a05:6214:528f:b0:5a5:e941:f33d with SMTP id kj15-20020a056214528f00b005a5e941f33dmr3649494qvb.3.1680192475320; Thu, 30 Mar 2023 09:07:55 -0700 (PDT) X-Google-Smtp-Source: AKy350Y+5Of9BQ51FgDOPQFkGMpVhdWP6DIaYdi2MOHzvLJbq+jW3Pu9yxIViDQt4nTW5eY4voEBhg== 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: 37thwwpadxdcfbwi614it1epfmcypasm X-Rspamd-Queue-Id: 0971D10000B X-HE-Tag: 1680192487-235923 X-HE-Meta: U2FsdGVkX19qAMRQmRygMGZHd5swBRKSjfHguaI+zXigEeRGOBzIXeioM8S2yxE3nX6E6SgpZVcXeDXvd6+okrrNvK6KBT5ojZl7Tvzp4OkcrKpXUf7156/jO5jtZs6eyhdB5Q/ct9fyByJiVdZlPPKTsOCnJfAq4CQWt4XzBCC586VgsRydPq6eJZeuaKg7U8kcAOz2PT00MQZfrXQdFNTdF9I+bY7P8O/5LmDXliZPWbL8ZMIs1hhCuFrozRSzw5nBL5SRw9JxMzSup7ZrK3/NlVbR8oxviAT17EzQwjXRhK3tv+UWFCUM59uOONbRPpqY9JWUqSdo4/DfiXS/IwyRHIFcJtif4f7hEWhFQgXlBKFao+FIzQPoeoYcBbH3F5btuxGCFG1yWw3yF5OhGGgig2BFLFfguwSbr7eTsSNXs3tH/xGqe56gNKKqFNhS2Lr9uXGjpHcMktCSder5mOsNmdDFDal6j5FLvuflZZSNqmbpHSrhkVXUEZKMlhJ0h31TPjud1EJhyqeIPB3DSATxE2KBPglNIZJk6UUu+yX2NoPlTCK/pS46DIX0H305bGCSLv24eQ1PLKTwmitLGwjy6UHN02BLsS5VSNNWqC3/QzltLBn4dyvskDAbs/1axHh1geOXEtKBlsijTsgPM71BMoCjGX8cuCfx0hsY/n0r7bUOFqqFHYC+3CRSQfP6Q9sBfX8YiyWO1Im8i1a6NwvADR1HZsrBx3ZhNmly5cuwO88xhSBxQiSCyQTEGeYR8bD2WejOhFe4q+JCBQD+39xF4A6yTbf57p+6xSKarqR+IhLJXWglsO11v1q+je37y/EZEaWxwBB5sMmYAbScJDfa5dEKrVM2PbG2mbfg/BBfGhePVtyPj9EcR/qHkbajVevWssusCEMdRPu4lGLIyOWoQo7Uxbw8DSiPMSYs9EOvh26lJToQ2vauQmM8XIbV8W7KOF+GXRd+USL68+U nEK7QQxD EfB2/HMHPEGbpCR18ToOLR/1Dj9aCTVAlhKguALQNcxoG5EgeKnjkFcnQ0/cEvTOE9PrH8IgS9nRuJ67FBvJCd67tTkOnBvfr3seNEFme/1FDkC9LNu9JRMEQzDdFeGuZ7jLCr6TZ6MrP/dJ19mzld9t2Hf2MGKjGZN9IvTPC1nwPX+zc0ULhbPckriBMH/A0pg5Tt+o7R5BQc+ubt1cYpLOHnSRwfrCKJeocN6Q6wdWdvahQdxvXx7E/OVvu086XBwHtKjQtBe3mobWpTRHx++XoCuzqkSXlP8v/i4WUipJiBsgwyZ1OcugqI7FBRFegMcooP4v/SXItUc1fx452z+6pO3VRFpCG05URDPLg8EbuHX5eveA+1ubaPHRswKWrsEoT07EQinR54VSL1uxfBY8Wet9EMg/p/hrwbVKxShLHg5NWMS0RPHI0GaHdF3sHwpkv3/8t5OznoFXkO2PI3vz4aosSBPvE4ZbqXTXi7LBTNo2UN+gtEV/thPTTojFXr2n4bHoG1zPXlMw= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add one simple test for UFFDIO_API. With that, I also added a bunch of small but handy helpers along the way. Signed-off-by: Peter Xu --- 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: 13194499 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DAEB8C6FD1D for ; Thu, 30 Mar 2023 16:08:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 73E626B009A; Thu, 30 Mar 2023 12:08:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6EE0A900003; Thu, 30 Mar 2023 12:08:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5684A900002; Thu, 30 Mar 2023 12:08:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 46A106B009A for ; Thu, 30 Mar 2023 12:08:15 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 1110D1A0A83 for ; Thu, 30 Mar 2023 16:08:15 +0000 (UTC) X-FDA: 80626046550.18.E2BA5BF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf29.hostedemail.com (Postfix) with ESMTP id E67C0120029 for ; Thu, 30 Mar 2023 16:08:11 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IKHaQDFp; spf=pass (imf29.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680192492; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=lYveN9kYI+AE0CuBqSxlkzyTIkRFNshZ9iE0ExlkrHo=; b=k/qyIzuAKLPBpyFW+nA0u2ymWtT2oPaNUWD0LGphJfZItGp/XroXCDY/qNCVBFYZrL8A5o vWR5QSzvhbbpS2mIdIERXX2CPHMy6H8mN1qMI4LoHhhR7PSxxYYptfHBkS2u03yRjwcCuP VGG9Z/UP+vrQWoCcRBu0OZi0ZWB6Dho= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IKHaQDFp; spf=pass (imf29.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680192492; a=rsa-sha256; cv=none; b=JlVFZN6DhPbKQUw+HxhCWV30PasTj2/Y0P0l7l7mpbjs4aqk4G4pvvY7wvNo3dB27Ls/Me 0lgws/KvFZfkfjlxSDlifFGMWNwGDMyZtiXNkDrCrR5yPIHlCDEMoF1wUWSyx2WJ7EgWnW imaMXyAPRaDesbhfioY+oK0NzNgUTXg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192491; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lYveN9kYI+AE0CuBqSxlkzyTIkRFNshZ9iE0ExlkrHo=; b=IKHaQDFpblHJsz3dbKnQRrDVfs24SCteyX8Z0R7IdcSBIaTd8JCzfqHvcSC5ryW7hL9o36 3EfLI53zbZu8rN5e83E+I3uYLRXFDVGCcxIPjpPcub83X8jKwKIWgwat6srWSNVbvCY4JH rx1dfSGdU8mCNehWLtyBfzJs8z7Laww= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-558-FOS8VbWgNRKP3r0VSt2mgw-1; Thu, 30 Mar 2023 12:08:09 -0400 X-MC-Unique: FOS8VbWgNRKP3r0VSt2mgw-1 Received: by mail-qt1-f200.google.com with SMTP id u1-20020a05622a198100b003e12a0467easo12705657qtc.11 for ; Thu, 30 Mar 2023 09:08:09 -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=vLJDv1mVi8hBjlSuzGegagQ7t8MLeruF9lZdDKtKF8puykRmE+dZFhEAOVRN/c+0Rh Vi70aGMVkdzBxMso48QX2OgSFJ8nnKnPhfOfrFiZqrdYtiAmL581gKFIQ1sKny85DWWY yuwzg/Ad3RqHlj+pvv7zExpFbHeb8BoF1Fvc1ircoS4u3wobr0eaJKjumOVJJvSytV6p y3+DaqgWUHvltP3EUT8HpXMHjNOhRRWuLpM8qeBYlLZu1ktt5F6NFvcWW5cC7w696Tnw XsjIL+os5CQW1DCZgzjFsUmL0HU4HtyuIVwI6kzuvZiLk8ktcHYsMFyPFNh39XEP7d96 2OJw== X-Gm-Message-State: AAQBX9d/9t0Kxcp6EHtqC2IhwnpD+dp9BHTFEmWzFI0WNtCANznSHrrB 0FtmL5wJfMnDSiqdQG69tInA2iITM3tr+SX440m3MxMCr9bSCPkTK506/mEV5OkrVUYO8GOU4T/ ekD1Hr8UlfX4= X-Received: by 2002:a05:6214:4005:b0:56c:d9e:c9a0 with SMTP id kd5-20020a056214400500b0056c0d9ec9a0mr3701330qvb.1.1680192489104; Thu, 30 Mar 2023 09:08:09 -0700 (PDT) X-Google-Smtp-Source: AKy350aTdkYANw/GA8UM9SuMd+jqJY9HVceHWacP5BOag5vY6hpxHhAdpkx3urUgNiYoPKaL8hSmQg== 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Stat-Signature: 1wu3rad1zkafuwcbzqxqwbymyj1i7uri X-Rspam-User: X-Rspamd-Queue-Id: E67C0120029 X-Rspamd-Server: rspam06 X-HE-Tag: 1680192491-186102 X-HE-Meta: U2FsdGVkX1+vRe1UMxZR/cUxzcbN8pbLfkK240jiurrMda/hH9YTNIOtHcnNpeuWgDwzRqzfnhcroVOaCjg4TBJeRQf38kLv2+8vlgbkQ4TlsobSqpjr1fxYbsr9wJabwEfRcva1v/5GfuME9uMSnB9kzYbxYdoPsv8KWpPeEF7/UmCqXKHzY1LzdZmrPL96+Rzt3mUiqfNqGOjvRlWkjzdPQE+mQoQiyOFqWphDRBxiZ7YBkc0y7rAlxeK4kmdaXJ7yuR4/d8/R7h8WYwUFreuKiELTKnm6aKGWWe0SjwWMlBnJ6je2fJjn8AkxQR7m9/vOUyypXJfb1fHO0lJ7NlsfidTCjb82lniOZVnFz0ctoFO1nRtX0BHKWKuoalzaQUiDHFT+HywFIN4mPjiiPxNVnWoMccQ1YSk7nidNX//r3COnh8iUL4UzXYTqwRojKMkF7KGZmxSGl/tITC/9dbzCxlU9yzDKo+RKs0Ejezo0Y/PCA33ZJC75XE3TV4JWmKF/ayR8hn4byI5edrsvirMGaFJbGDHlnTh3U+AyWmM2brw3adyh9PYR4mLM6DpMpMz3WWgwnttR0dSFOClJTIV+4jGoHgGVnbhmypgtWs6ruIVvx9nLYJ6RUj2dWyuHSVEu9qjbTdtN12cgqD9EonpaXaF7Yi7JPq6Pz3ARk3CV9jXjSBM4Mb6sIuBSDdLOdaTfES39Mx2DgTYiQ0D2prcMrfTUKYMI6jBP3FDvoWOmtXBs1ZA08gB9GHZVjv5XQayWoNwnnQPj8Jw//0UA2pbt07w3KvUATe3F2Lyh3CZrrqo/k7M5sK8dJZ2L5T4EjD6y0jqyoxY8TyoY/BRNqtvTfXQNVbrHkv5UyRrinN0adtyq+Es49F0DUH7dXoehxtHuov6epFt1BQj24bgSYUp1GWvheNqsPOusFgftS3c/dLn1pxW53HA2us4/6nj0CQQ3lSGdkqhcaCV+X5a IA/FECFW 8oOY/T03UdGF/1xErfQj4BjFBEF8YhNhctx6a/ZTek3I/E4deVX/wxoQ99WHBZTn7UBI05W/N3A2cclLPFNP1G6sIXWAgVfsPQMXINgLrfEup/FbNqjfBWHEmZOBEW2GOTwdIfTPrB7V2RiQl3JJYTm2a2z4Me7ME3pJTSNE5K08DTmZE++T9MNAuAyvDtD1+a2goMLWm25Li9dyphgnrDcYemOe8xuSKnhUIQuS12cJE3kqccRyxigVqxsCnk/XjpmgzvlT3Ee4cQWV+CRHS00cBtAyETOOL5V/CU03slx84WKE1WQHSG3jC2ICqdrsfGaHXbJwUvwcT+D+UnHAP92iWXRZEIoYfciyqhP3waQmK1wQkS/o8yoAoSSTyNeoEaB4kZVI2CgwI/GmjjFGgrlwGAGHcn61VGxZAA2crpvQionUT7A1MveVFw8d6EeTEBxyqGQ8V9g69C6saQWi7GzeV3oAWqk90aAlpyT0cZOvkeRsv7S4IOV/3tVoKwDGIMi/ZWk6+0+es1EU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Drop it by creating the memfd dynamically in the tests. 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: 13194500 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5DD28C6FD1D for ; Thu, 30 Mar 2023 16:08:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E91A3900002; Thu, 30 Mar 2023 12:08:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E42C06B009C; Thu, 30 Mar 2023 12:08:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CE32C900002; Thu, 30 Mar 2023 12:08:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id BAF946B009B for ; Thu, 30 Mar 2023 12:08:17 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 99F91161033 for ; Thu, 30 Mar 2023 16:08:17 +0000 (UTC) X-FDA: 80626046634.06.626D3ED Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf19.hostedemail.com (Postfix) with ESMTP id 782001A0026 for ; Thu, 30 Mar 2023 16:08:15 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=AxuCaBAB; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf19.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680192495; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=gA0z3fLtS/53pi31HkFC8RYwaDcusvVg7bMc/ulU8j0=; b=zvfzqIUqeBS9qysxMEqr6vWuUekH0m+W8ZsUzF+gv0Rfucx09IyCnhr+lIfLQifpyhOGq1 gdOqY2VPVaYrXrUMOnp911GBupumc+qQ+JNOjBjbn46Ptz1/RF0+dwLIKPEf0xOV3zkMAr FYuvx/UUJJ3cumvPlwf3cVZhbjd8AVQ= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=AxuCaBAB; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf19.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680192495; a=rsa-sha256; cv=none; b=2OUlWNWLmz7+H43yY6SmRaKJ/t5vNSc4t7NuagCUbix/fb/nV1gmsiSyBrTDPXmqkKg4CN 3DNhx2J9CKwkw6wPFxFcfTfmGfJgQzDF7AW6jU6jlvsg18XQiyc6vn+9br/BmyuC5Ng42y Eu5iMt0Onlmo0ovsrFLWMNxG3YgJbxA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192494; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gA0z3fLtS/53pi31HkFC8RYwaDcusvVg7bMc/ulU8j0=; b=AxuCaBABBpTe0taGzseR/d94Ps8EW2+Dh+ipA8CNLNBu0EZyNVNyoUkcU/rxSYjBo/sQyL AOwC/rME7LUW0zhbBrSt2nDkVYHu5Pu5tWU3eeRbqZxSchc4d6P9swoYcS+Sy47MUkDyBf eFDE4En6KAhvN9jH6TXMVS+5nkgi8hI= 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-547-L64jRtaUPPuQ4Ta872ob4A-1; Thu, 30 Mar 2023 12:08:13 -0400 X-MC-Unique: L64jRtaUPPuQ4Ta872ob4A-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-57c67ea348eso12978056d6.1 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=2m4GqaP1mK9ywDqHl++KbGs3IOnuKAySlXsyJA5CGMR08gvDsZGLiPamNCY2e7Ocu6 5OIBG3VjCdk7pUAVoewB5Pz23gRSVD2s1PyMIHqjzAzl4V7fLAv2iPw/e1nlBZ+QQvJf bg9eEacsaIsIU1vTqQsib+jSjXbpoV77/fGb82n3xwalW/jo0nSl7tf5B5nCRp0FVjXR D8ymyMBeYYX5Y1YyzasCevJmSXPqD/bSRuid/p2nf49EisB4CEazczg+28Str6mTaVDF 3qH5MQvi3FHsdd2KNXkfMw2P/Aujqvn7EhwlFUxx9KpI1AIgd7X4p2rsPUQR8jFW/5JZ PsEw== X-Gm-Message-State: AAQBX9eJ0xd+NzQS8xJA59RIpZvkWDQ/j7dIQMKGhPvDOXlKgMzDc+Fb OVRUoTbq4pAujfIXWdRDMSSBGg43hnWaumOKxqEbI8FgeZcs09frvuecX+mT0/sgZF8cX4ZE06F XzWrharMeq5PvXhOL298= X-Received: by 2002:a05:6214:d0c:b0:5df:a693:39e with SMTP id 12-20020a0562140d0c00b005dfa693039emr3572744qvh.5.1680192492171; Thu, 30 Mar 2023 09:08:12 -0700 (PDT) X-Google-Smtp-Source: AKy350a31IcuGsNWlBkf8cNmNuBl6n8qJKAWJr7SjOPxGZusPrloFA/ON2e0syMszVgcE7KnbiFCxQ== 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 782001A0026 X-Stat-Signature: 977x78cdjkbhs98cks551o5ixci9hz1d X-HE-Tag: 1680192495-524672 X-HE-Meta: U2FsdGVkX18Ivc+48TVQedOZvdUC63dm21xwVmuylO13mDg3ObQpgwowGv+Jb5kyYjKX4vZirEuaMBK4wnIqrLiKTEmM7VNVWhX5O7OjHYcgXuqItElJvQuRc4wYSXkEktJ18rTXpZxhXLmC98FtAnLvPve08RByfze1Sqj9G0ZcS8gBRwXJA5WADudYR7OkFtXPSMiS46VBHwvfwZnvV2vOASiu4Q2ABEKX0W0ip3iRSsNIRobPEgaPN8pDmGrztMmsQ2ZReHdrboBgqFcKHrT837Oo3bQLZtKKUVP0Ji6DR2spxReh6R1apXygWIM5nYr1lNkCng4uHndLHDzsTyjO8Ox1/gdfi1mIBA1Ank4RauwzQyn83UQZeTBkYdybAYIvtOhp6xvNY8YFELN8TX88dqtz37ZmgyMlH9kok/iRyjDzNZHmJEPJkSZHcCQq/di4tT21X2vKNd8cWk/xldtD7AXKEVAXUCBLYoFou1MD8216pFA3Bo0cA9cr3OcWJ8AEpwOyZ0MpSPgmaqjeTGobPsx5WbefcFKdZl7572jyt9sfnlUcdxbJV2Ax7Igtp6+LjVEg2+gg9cKK1ZHbIkX9y5iCclf8AqbbZ5L7Qg+GYBgQ6YXnZjPPvtZ/bWn/vbnKnm0rGXsF0ajJAKYcaeb953cDPUZvwdthFk0Lpms0AVo52lEAx8cnGFVu4q7dZh3rqg/XEFGdcxdt8G2Ffhc9t1b+Xvsx3YeN0yS6un8DhDIk588FdjaMEIUMgC2dacHB6mva2TGR6n/cRPiSzqma0Ymqmue1AJQ92rpcaSkX4xpnFCNdWsggy1w2hHaETLO2TJE2Y+QrZr/Dt45hzcwVUmU5jMcqayiroqlsAO07eMPjgKhqa6Q5qyblt3IJB+Y7lrr/i1h+LkW9bGSr/G2JLmYbYye7MX5aKfzJ5cewgA/3uV+zWXVkJrZ77Enn8ody9FEQEEr3aFNeV59 i9XLRjJn 5nr6v27hO1Ri71XyFJwLjyBLfgFsT91cDL+5SdvGSfTMSJnehrucgddPQG4LLoj27Y34vmLfkZER98CPwCl2PQwjC04pwmUOJxwEcW5+ILKFBfXdhsX9/lbeXErqn024Wi6EbBM+sc7eQtC//iojFpe157AAg9+5uYtnpiA/hv1ZIioUqFHwlsanxVE9Yzl2JCLGPfPdwD04la72vqlynRdJ8XyLrZh/kKQ0e/8VfZkRxiuUgE4dT9p83O5nbeA2ZmefqNewgki7tOFtVq8kOqVEpW9wb/l+IBs+8q/HpbzIUFFfarv2tvEiEV4HI9520Cv1qS4VTg3zmWItKaMzu+oytOgPX2Dh3HdGoeMGbSh9U7NUD0bwGXj7kQw5oTiYbg7VH2xzaRZHOf+RB0G79Qw7yxd83MKh+S8VmxJhVjWIA6BfcHHQFpwqnc3B3DUshCfu8YmWYmVs3VNqJ9HbtfG4GBQ/37pSW7O9uFZu8NzaJrPvHdvqD61GZE7zRJQjRa45Hvu5yc1Hzom0= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: hpage_size was wrongly used. Sometimes it means hugetlb default size, sometimes it was used as thp size. Remove the global variable and use the right one at each place. 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: 13194501 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF499C761A6 for ; Thu, 30 Mar 2023 16:08:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5B796900003; Thu, 30 Mar 2023 12:08:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 568626B009C; Thu, 30 Mar 2023 12:08:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E13F6B009D; Thu, 30 Mar 2023 12:08:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 2BCC56B009B for ; Thu, 30 Mar 2023 12:08:21 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 003B51A0A83 for ; Thu, 30 Mar 2023 16:08:20 +0000 (UTC) X-FDA: 80626046802.24.E56CFB4 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf29.hostedemail.com (Postfix) with ESMTP id 5F1CB120027 for ; Thu, 30 Mar 2023 16:08:18 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LcsIBjlt; spf=pass (imf29.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680192498; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=8NTrS8mJzWPEnPLBWSlseOL+7dIWq0u/3um5fPzddJ8=; b=68uuze/xmnEKvws6f5uIgOTAP7Kq88V6hVI7soiCaCV19b6yrE5rcYHTRnR5Ss/JAefQha BZZqxoDdnf6YLpwQS1vGbkF+Z9FlrquSB9sDDdT0vMCGIgE29bQh6nL9mul/F2rcz+4AT4 TAdd/cyTz3m066TjGo5u/4OG8StVpbQ= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LcsIBjlt; spf=pass (imf29.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680192498; a=rsa-sha256; cv=none; b=3UhYDKhM/V4TwxEEv1HL382ARNcxCdnVI3VJ+pFL1s7PllKMCcvuiVCJFgzmCTvPwulrIZ Djkxm5KZn8O/HsQombC1CinNmwF8WGGHVWXN6pBW7NmdQ+H9ULkkQVLfyRh1WvKRobCp6+ ogX6I5XXvZh/Xc2qsEBHPTb0bwXGwcc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192497; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8NTrS8mJzWPEnPLBWSlseOL+7dIWq0u/3um5fPzddJ8=; b=LcsIBjltTXhzyaYrrR5Op3z7T44Sup/r6npNPpeaVmhsmWWBiuFPnzqPMTbyabuz2PFZMG HTEoCq67XEzUD7gtCqCq720gNgpZXDTasLDU//Kgh1zrZ3RoIjiBpLUImHijSxjQXR/kGI 1nws6P12+wFhENfYsWY0snwfAde13Tg= 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-595-QRPUpWnUOkOqADGVNAqiJg-1; Thu, 30 Mar 2023 12:08:16 -0400 X-MC-Unique: QRPUpWnUOkOqADGVNAqiJg-1 Received: by mail-qv1-f71.google.com with SMTP id dl18-20020ad44e12000000b005a4d5420bc6so8440910qvb.11 for ; Thu, 30 Mar 2023 09:08:16 -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=09QwH3YxeyMbo4zjmBNBD7Y117vFoL/Ig+BgCv1Gu2RHmTca4lJjbsxgk6U1ApGoAZ jHd5R29O5Fm7i9cdRuBXcnaFYt747O7Dql7jLx76QlCG6rudEBi5k3m4Axq3nL77w1F0 NwQaFYYaseou/6BlFest1JorpDNSmnfQEWDoH64iPjIDXIjJgOVzIsa0KiWq0AZxasdV 84HqqSuFNcv4Mfh2vvQc0slH5rMuiXFzCeDnusidrN+slo/PaCWg4Vc9UYzWTXZ3rEXv rA+uwyhjsyDKadKln9lhEoEhAmq1ZyW1fBnrxBhbUVGGUzdWxJudY0/CuxRK2AGpevZY 6J1Q== X-Gm-Message-State: AO0yUKVeUGYVVqfvuClz5Hi0bAYiGweJ5QQ9Etb96v6WwQ97aX/HmegO 751C196yY9pPNQzI+lJcjhTmj+QqZ/JtxDhv+1+02ScG+Lhj4YW8HKGvkZptslpxhgjlKXycCDm T7dvykX/1yqM= X-Received: by 2002:a05:622a:3c9:b0:3b8:36f8:830e with SMTP id k9-20020a05622a03c900b003b836f8830emr37733720qtx.6.1680192495914; Thu, 30 Mar 2023 09:08:15 -0700 (PDT) X-Google-Smtp-Source: AK7set+xWLH8y6GmL2ENvwzVmLLUlI8WPGbRuYB5jyqQ/eNHJax24mqyfmVMDw61Ei3HBM8optw/0w== 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 5F1CB120027 X-Stat-Signature: mgh5514gnkdodo9gdecx7rnkmmgtcrcm X-HE-Tag: 1680192498-19121 X-HE-Meta: U2FsdGVkX19R7WBPo86nywQ42q4OY7x4VaiWt4tW9r1FyomBl7n26Loxx1gNTyEJK0OvUw97iodR5KOcKbymIYke/it/oGg3ix96nHReu4W0WyE61AGWj6CYarlM17uiGeeeoSE1MBPR4Srg13o+hgMpjvEuwfTKlDyqs3RVvVWMEGwFAj7YFWCCA4qrq5zNx5HfktkOi/gMJfDLHhVnqiesF+pOpO+Wti5FMKL7wNKlhLwg7vm+INijs8gaoC+Xfi9hHunixr/I93CKxSH4HALhPAYXd1VzLI50qy9S0+/f/4ALkT+A7Igc2/JEoPjhErQyi/aloQ4DqOwj7gvvdLfWa4cOaajFQjRx43Hhjc02a1E6v5GIAm9XH+cE33tt39DMGW7dYeZAfvng4FkyBpY9tYsCnA+/9BdRX8gNuIAasdxQcGDz133FZcvKZXoq8vGG1iCDjD/zzY0k1+KDBsAacP8cRXpPdW5gO8w9gK++ecVpOG+L1GfpMiO8cAd8GpRGu+WJ0oT6PEBHfNo9bMU1nklHMXzjWSZ9zNIBgxTLV3rw6ZxNcHb1UZPaQH7Us2TOCx+raZto+cVdeEPHL7oKOSAxww7G8PIFZR/v1R8uiAa/sqHZmJhnTcq2W/3Hi7f7cFzZxA/dpV+7S9nSmXLbfgxvMSJQ+kShu1bPYd2yuhpS50pqsPvXwjNPasg+sDXhbJZV2jZMdRAqLl9qJFvKApKzGPsqYjI8AaiHHHpowg1pWvYHJxUoqe8vDm7BFdvK3aYz7Nd8KUde3Ru/ua9TX/qL8n5dLPuBYRU72tBgLzA0gF60NhrTcEh+lxqLyORgDyt2+4tV4u2aCIDtZa59bdKR/AVmSfsx9/i3vhfdu31rue3T8A6vmv82L/nJ5f7dcM1XPjnb68ovYPFz5lbTuXFxAda3umBsvlcTIyHXRQ3kixoW65kqanptpgIrjxUDiihyLQg+aTTawcJ tCIGtofX TQL0QI7X+OP//fMCY7P8yupGbjcWEsZqVSw7Ancht/AtXOXiJeQoOzElU1JvlCB4FLDMoWRJCDrWJBOCHyg8V9zSkArVi9VQhSEnD4XESLlgdJHiX0MWzWCR5DAolcu/14GfZtY8q0JVToFeAfnkFawBmfMLj5T3Aa4bbxkpEW0gykkyCPfHxk7m8ICixI+0QuthKeKDKJIEU9CkUPkeLX50PU6QDd+Xps001n8BEmpASJDbj5jak/xWPT6+/A4igK/SQmCcvAVQ7k42atJn63BJExaOpCwZw68C5YvyFtAGtI05tkLnU88e3DGzInzWwCkrQEiG6f04AZ43CJWluEI90JfrMW3lqiWsc//OyfnniU1TDmeIQMBvZULOSiEDd0bwdNvG+bgw5ZdITTS+F+Qhf8kqwcgD1ikUT0+iD17IKUfQsqDhRKt4YwiDUkWNGFZ468jKZDTxjIFQ0Kb7BhVa3LCo3DGhWpVdr3fNA8SSvCWxpcZGo3uw7yPJkGYS4hVcOzLZZCNQDNzk= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Make the handler optionally apply WP bit when resolving page faults for either missing or minor page faults. This 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: 13194502 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79E2DC6FD1D for ; Thu, 30 Mar 2023 16:08:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 17336900004; Thu, 30 Mar 2023 12:08:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 122636B009C; Thu, 30 Mar 2023 12:08:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F04E3900004; Thu, 30 Mar 2023 12:08:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id DECE26B009B for ; Thu, 30 Mar 2023 12:08:23 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id A3C0E1C66CB for ; Thu, 30 Mar 2023 16:08:23 +0000 (UTC) X-FDA: 80626046886.17.A5F038F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf29.hostedemail.com (Postfix) with ESMTP id 29710120027 for ; Thu, 30 Mar 2023 16:08:20 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UYmtNtjR; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf29.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680192501; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=fazvJ2yoVQ3FbqTtLeeKqsLvxYRtSAddCup9lQnAU9I=; b=QAlmUEOfG4TJWOFFUfNqFlrgaA4vTrgTaSF/4egNWGu63GSQZZHcRjhNDcIiBQ+IICtJSv 8sABaN4VQztkkk8OYQyWoT+mr7QjdSh2kEBuLeEujFKt7+DgM9IrDCKFkpQ4CQ8NBWy5Xv 0RIn+jqxP75rIEr62Hq1TmwQFVEyc6o= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UYmtNtjR; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf29.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680192501; a=rsa-sha256; cv=none; b=evB42I8cdvD0E3eaETZyLYvz/P4Q26A+EMlBFjbisrEk3NrpnCfBGvSHcZi5L3ajTJTICM x3iGGwwIFDkS95Gw3gVSPadhcv40Zag1AnK8ZXQKB+Hpu5Oc3fmD62oFki7PGLH0LKpSBb nlTJLdQDAZCP7wdoUlI9IeJGGhKBLP4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192500; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fazvJ2yoVQ3FbqTtLeeKqsLvxYRtSAddCup9lQnAU9I=; b=UYmtNtjRR0UZQLsv1afgK/flgHdmWf1o/gjDK/ZFeV/QuA+I6NNN3Rd64L9f2/YoeS56Eb dyXMBWCMeqzak+yn5GnuDKcpzIRPBe3/dIIEhx0QWCzNB5c1mx2LPAag7/WPNlcHdvMRWg r1/GD2xrNHrrdKcJnKLExiMOtQCtETI= 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-594-qBN9V3nVOYSy_PtxPcIPyQ-1; Thu, 30 Mar 2023 12:08:19 -0400 X-MC-Unique: qBN9V3nVOYSy_PtxPcIPyQ-1 Received: by mail-qv1-f72.google.com with SMTP id m3-20020a0cbf03000000b005de7233ca79so6267576qvi.3 for ; Thu, 30 Mar 2023 09:08:19 -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=lUmfg2h9X3s92To8VBZMauBS7Lx/ex7e6U2jrLabjvCHyS35CAtOXDR7YnyvyfZ20a PSqbYxND3x32CP7yD/Zukftkmqs+3qWWm2JqjA8bN3Ts/wT8sFKEksKoT+fzZGCOFK+I RITYCQr8C+H0tYu5pUDTFda4nWXHbRHY8Zf3xeGW0Wp2g5qEQIkdROMMf+H57uCDwrKo f1JaDBJsVn4HBjPs5QyixluXNkKJ69E4r2ZqlHoCysqmjnYkm+OYAK9rsSJy9J+cy7oY MITexIId20TKSRdWcwcdciks6MLhu22nMw/qx9QK83f2GJfrqR6Ia6o+741ieDw7BYrg T0Kg== X-Gm-Message-State: AAQBX9co0rVP8o5+94YZRyNnFnFZ25RvDDcmZxjzv1KjEcmtyvVIEavp tEKndukH1nigt+F8UGSnoJNQAU97u3LcnTl6PfxREs3FHb/dpTF3SMV9WNJeSttr+g7OLkPZmZI oeZNlmOvpTM0= X-Received: by 2002:a05:6214:509b:b0:5af:3a13:202d with SMTP id kk27-20020a056214509b00b005af3a13202dmr3927543qvb.4.1680192498768; Thu, 30 Mar 2023 09:08:18 -0700 (PDT) X-Google-Smtp-Source: AKy350acTLaMKvkjgA5o3kANLnUneMIVx+Sq4WzW6L7IohGdoOjgIBbl1U95wQXN6zpuQKJP6h7ekA== 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 29710120027 X-Stat-Signature: fneanozw5apzfyp1h1ebd1tc8rkwkd4p X-HE-Tag: 1680192500-924257 X-HE-Meta: U2FsdGVkX18DAAfKcmKiY1QUlgEwd/TG0SdHI1Up9MWrBGhfVdzSx8Bct0FylJ4Ir4eheGkwNcNCDO7FLNz8bShn5ZporwPJSqnT3NBy76q04QGsRMUvQqmODKEgeXYUhyHdvBzssxE4DbdyldrVKGetcInv9Hn1sueIJiLOdM86/gTcGoHc6vH55Ngj60aLOLJM3BGiBzacr0CU2IN6/vvuSVNgOQ5xjzQ4RtODuQhGioHo25tYtdcFXWm8H/y9eIsDRqa6FcP5cj9Qm7rwMGBZliDE3kFZvXvml2M2OqzRdxxAYK2Hl/gQsUrwBcbAS57Lly+XhY0HZ/+VEbx8jfxPc9eXMfNN5CSJs0bs1NzLRtvkE0R4Q2x8doY8/ZQGcd+GCO1fHnPDp3mSPuT8hFjHsNN9GFMkYxBRLG7ZG6V3aH+XtVmLB4rXCQPbkDSCxYmNhC3SnObdgTtmfDgCGs9ZImg4GkbCNWCimH39qRnh8I6nwp+O0FZlnETbYlrPIR/mVqw+6WxJESgX8ZzP7MZmRp5sVzkzf1sSZTZIINqZY6dockjg1ooSO+pMMPYbKprCLf3M3lPtoGjomRg9DNS2G2jGQb+Mmt8duRS9ysGcCNGTeu8Iw8vTqNYy9rVzjKCPHf0YuABsMMKlCmOmIsTVavr/TiouMv1rDPy797REd2yOuCXFjOdjsAUxkXOzorJssWjUHnEEqBqW23/iG0m1KPaILXhjr7iw0XN/qprec0j5X6lKQsCTsUxOCa0djugWZ3cDSaJgWDPdnQFEKDFDSO4frkMk9wkgqbBI0Bmd8m0nNzb1K7rT6kYrxLZwMLVkN38cEJERbxVK20EtlBwSWFL2UY5YanNkMJVW6ZgswPtWXoIpoQgug5ZMCgsyCBgzr5OwPHx4H09BcBN82flrcXkA8kG3cbGUqwVZGo+iQdaR3zn9DV2ik98hfvtgWQ8ZG5APBuUj8rsqh0P pYAwL3b7 xgZTY3bvo06fp0BwW9d3kardzz2O8iPdMnG9IoxOeXxriWYKyf/aHCs7Cw4058YMDgep2GEhtSG3CBc0vwI8zYdV5y5w7cepWAAJcqr7trBSKq5bXajdQI1PghiPI2BH5puFbbXjkvOQQeHkNPibZZwSAcmE9JZn4z/De3LEs6Z+ZISArz+1aE45FLQesipm7p1+IYBQMbHTihBdOoaYdeo268dcOkL++Q8Ja7TrGhpPy0Za85kWozHHUPnxx7xFyS15xveNbHpzvoiOxV/piQOX3+jPEa87qc/7eVQq5m/C/cN3v9XUJZ/TaNoEuCn11phZdSFwGHLIkykN7Ygk9LfwmW+129ugbXag7R18U5g2Pd3CZLHBCXECy5tW8JRihPCb4NcAUA1P2+24hRJ68ibgUrbKwL2v/KhVxtJHu8HJ1FdDaJ3OmfK3SBUdFXlJqU4fzpiqtgyijpLhXhCAlyDoip+tTgw0vpKtzBm9Dntl89A+rQbIPgLNH5fTGq2RmMqixLuXUF0SVJUM= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Mostly to detect hugetlb allocation errors and skip hugetlb tests when pages are not allocated. Signed-off-by: Peter Xu --- tools/testing/selftests/mm/uffd-common.c | 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: 13194503 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79016C761A6 for ; Thu, 30 Mar 2023 16:08:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EDED6900005; Thu, 30 Mar 2023 12:08:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E8F9B6B009C; Thu, 30 Mar 2023 12:08:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D5783900005; Thu, 30 Mar 2023 12:08:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id C45016B009B for ; Thu, 30 Mar 2023 12:08:26 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 88117AB2CE for ; Thu, 30 Mar 2023 16:08:26 +0000 (UTC) X-FDA: 80626047012.04.AB0C608 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf09.hostedemail.com (Postfix) with ESMTP id 6639C140021 for ; Thu, 30 Mar 2023 16:08:24 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ZjMpU5bS; spf=pass (imf09.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680192504; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=uhDA/wjfT6X0KP/XkxMZvdeJDhg2SLQS/Rv9HxMM2sI=; b=WSxlB/FTCv2ROBXr3wGf9J5O7JLLkF7XsmplB5CtnyjrbbYOAL48VD89Cklo/6DRG1BhdV tFskqpJcvZBkjIzW1hzoV/itIEotsuWA7xqKukkC/90EGGU7KHruW3SR5FjkoSyBNYY0/g dKvyrOqb6svClSJJC8lm8QLI/d4psog= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ZjMpU5bS; spf=pass (imf09.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680192504; a=rsa-sha256; cv=none; b=hBts8F/jGZyyRtyOj0el0cvja3kLNRu4Bp2rwdjYAjmQbr+IRRlvXiRk3XOu3dIV81hpQD tCO6IACLJUmpQCwzpRUgrYnvdlxcA9IRGGETFRSuzfESI66fxyTthPqmMCH351bR6aD6Up eNVFChHu05L7I/Q0B0DKAa9IarZ3H+s= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192503; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uhDA/wjfT6X0KP/XkxMZvdeJDhg2SLQS/Rv9HxMM2sI=; b=ZjMpU5bSEyYPn4T9sIEwprY/tTPF2d91qxnWkVrTKWJm23cAhP/dvuJy+fjMDlBwEwzdd0 CRbq1Hwmrt4T3Rib/fhzUS4X27EZeEvxu9wuBKWLb2/tgKC3oKi7hhBWKG66IMEWuNQgTa sLRgfZWJv4KENRWkXFmJkb4vUfPze8Y= 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-279-vzXaHdmmPEumVCu5LdWobA-1; Thu, 30 Mar 2023 12:08:22 -0400 X-MC-Unique: vzXaHdmmPEumVCu5LdWobA-1 Received: by mail-qk1-f199.google.com with SMTP id 198-20020a370bcf000000b007468cffa4e2so9101616qkl.10 for ; Thu, 30 Mar 2023 09:08:22 -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=VRMnwsa+ysj5z1Csf/+SpbpNkBYfX+sgtWJGTyCGvXkBKxObEHilj+4JO9LlijHEh3 pyqBMfphHsMqaodXyiA4FeyM/XpB5srjf9KeV2rOhc0LjhGh5jp0+2KEhePbsg5rJPc+ A74Re+muUBu0VEo+6nZcM+mt6PWvFnyZD5ZZ/bkEqhpfYPLSAQisDB4P0bOpeYvkY05Q GkUW4Epn0mR6L4fmGMiTkLBp2vWCX0oT0lfAf/STGEaT6S/P2zIt84o7KHEHJ64Z5ju3 wXiyLJGk/G4Zwvd6vhmiHynZe73rCPTKP6+5KNS8oOm448bwonLAo567jZMAGIVPAgPY UyqA== X-Gm-Message-State: AAQBX9cgPypnQZwKKiiUlNdtzHDcO8QJEF1GnaoX/srOsoGCDjcwy2QU k2wSF776UikUkeEZ5ZOxQn9qdAWaBg3p1U94C6ZLEqOBx0GeB9SpPI2GMW2qDRlza5R1W3VB7ym 8+FcaQHrRaAg= X-Received: by 2002:a05:6214:4005:b0:56c:d9e:c9a0 with SMTP id kd5-20020a056214400500b0056c0d9ec9a0mr3702700qvb.1.1680192501607; Thu, 30 Mar 2023 09:08:21 -0700 (PDT) X-Google-Smtp-Source: AKy350bIVoRr5JKeD10TL5Z3VboZfFB7o7h5MoQBZi1Ow1eqcSHcj8AcQbyOTnGNgHxF8PIDsqGFfQ== 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 6639C140021 X-Rspam-User: X-Stat-Signature: 68zxg71sh1at54b4k9mnykcsh559bxeb X-HE-Tag: 1680192504-207379 X-HE-Meta: U2FsdGVkX18tc4CUd7pdBPpSdeTsF0i8NnzNWfgMX/bqq3c7XHxuNu3d9UzMJyudYfPm85kGuZyDOQBHIpogqok75433M2RbsPDpPPMcSiLxOXyWkGk0mZH8+SybK9LW+nS+yLbUi/F2fGGalX4Q5M63xGDkTibxYmPdH04nqYThzuTAj3vJ9wmgP+nwS4688/gWnnScSgmAi0lsoPEEg9HtzcchbUGwUuI5t5Cp+YGLTx7Wx6QdWJz+IpduXdwms3yl4ggGIY10L/MkJdyyC5DN5iySCPVSJRaRerw3WLGQu9WXjKi2Ms51P14OHkPwq/InEYGSeo6LEwGutqtXV11z1zc9JbTifRXyQc9mBGDIHYaqcLzPZ+31Tksd1VOEXlJK3UZ19keoeDQAzxTVI8LuPiAIHgE5V9KnGeh9TSji7i+qLHpdQ9Jy8oyfUvUjaHJjjf+S4TIil58qxZO1KMaFoRbnBmCOPKU5YcrYPZKd7N1yFkdbpzQeCFR/90QxsiIqKo37/HWlH9ZaYqtSFTNH5Y2URQKruba3PtkiNOQrujtBRjxIo9491hghZkLaBwM7beyc5Q8i/Y6AFY2Iv9rS1wC5/cW/KBqjLJB0jcrLPbhLAtFdeUnasxSPrTTY0TuHyYIjYabH0tMO0VFWMN8LW7DyU0M8ZluBI6HksXfaFgM79GVZ5i7JnT0kuCtU7NI2ZgrGYifjEz+rkcUxP6wFKkV/swugGkoanaP3Bezpx1/fIb8G+CjJRfkHRV5skvUDb44dpV7dei+l22TSAFeXrdFiCP9+OQ/z56HtGV1Tt6jLt7oNpmc+wyAUBg5/urZHnbqlx644AiDN/SSdmz5lWmp9xjTaYd86aKY/sy/uzyZil3UmXSoN9xSwcf2ToibAP8JBe98+hr+B06tI7LDEGdDszHvfM7WU4dKWy1do9f+D2U0uLWrZmI72E4+FoxzgSz3VGZRLz7eGrAM DJx1qZB2 FVz3odb40E06vMDiTMs0C8/DiIFopQP4sE1O53TfohlxUS3+OKzWv3jU4mqe9At9cLrmiOzm/lDAW/p7L5p1OLVPqKaU2PlUirg58qnC+sNgF3+9AHnUUJ1woLuPEMLAlorQPExV05pqFASvZFhZKQeXcoUMfmekrffXuuIwbqJqc9vmHf5zfe72mOBhxZfgWahvgRQPZKVCJjt4wMU5xlZe+DR/Rh9wtstsXLJJUPt9zhwCU2vTtNePLxfWK+Joz8aRTveEugoHioHBlLas8F0omyTpnDHFQdBD9iabNaIQZOooKHt6NJwmwljWpbJ1Giyt1fex0djVtT6JarAiUUJBZ7Wu0qFWM2n/wvQ3ZscSCNJG48r/7AMjovIE79zDsfCqzweRAx4V7toA32Q8hmk/rNvoDPqKFND0W6+qvw6SHX1s8hfcduflhnQRMZbCYKTtDNZ7wpPiwUpzkq8Lj+JZ8sITwGFZ4DVZr X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add a framework to be prepared to move unit tests from uffd-stress.c into uffd-unit-tests.c. The goal is to allow detection of uffd features for each test, and also loop over specified types of memory that a test support. Signed-off-by: Peter Xu --- tools/testing/selftests/mm/uffd-unit-tests.c | 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: 13194504 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA684C77B6D for ; Thu, 30 Mar 2023 16:08:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7174D6B009B; Thu, 30 Mar 2023 12:08:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6C700900006; Thu, 30 Mar 2023 12:08:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 567E36B009D; Thu, 30 Mar 2023 12:08:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 43F986B009B for ; Thu, 30 Mar 2023 12:08:29 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 1F305AB2CE for ; Thu, 30 Mar 2023 16:08:29 +0000 (UTC) X-FDA: 80626047138.29.C9D3AFD Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf20.hostedemail.com (Postfix) with ESMTP id D51F21C0006 for ; Thu, 30 Mar 2023 16:08:26 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="TbM2Q4/u"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf20.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680192506; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=xLgapT9bBZ+99GDEmTuONCJOEOezrqQqmgr0JZLPIac=; b=7lomrPpvjHCHbt01xvS8FqS0MUf3lXExLfy73U5XZrec6KvbQlVVkim7hFwj3uqKqL0pHO c9DG7SnXwbG985wyr3UvL/WNtdhH655wHouxKn7Ydw3e7gt4snqDKD4jFQ1z9ppyTPsr57 T4M4v9EQgvyLhGeVJXUAcXY/CnaJabY= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="TbM2Q4/u"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf20.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680192506; a=rsa-sha256; cv=none; b=ZQgE4TO7tatSexgL9pNuFSwY5Rhxn5O+Ly4MXjQWKEK7PfAg0Obc0LqEb1DVv20Qr9iv9e QqPnJAXyS0s3dgQjggRTUb7H1Br/jG2Ww9P+eXO0tkDER4Z3CdJrTo5MpcujIuC1Y+Bv+o QNAfo7tOBW3GC8UPafRdtfqunDErqgQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192506; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xLgapT9bBZ+99GDEmTuONCJOEOezrqQqmgr0JZLPIac=; b=TbM2Q4/uC5/MrrHNzLlWDFemiG0gUqGd3wyKzxagpH6TWqbOYAl0GNV2Hv0qlMZzbfE+3R MjGFll/yUDjXs9IDtVW4SKprgKI0NGGsaqZr2q6dein1h2LXjvrccTxzG3AMcozM8ZZ1ka +t31qTz6l+ToNLZ33e4IzJWcfRp5bSg= 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-120-Cy5PVoIaOQafhl7AQ-eI6w-1; Thu, 30 Mar 2023 12:08:24 -0400 X-MC-Unique: Cy5PVoIaOQafhl7AQ-eI6w-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-5aae34d87f7so13017266d6.0 for ; Thu, 30 Mar 2023 09:08:24 -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=3zIaG0Lic6GJBvKZyd4xESq8Cw+1GlA8zwz+xxNVaDH6e8D74lfuIBaWvHhAinxOQj zCzOgIFz9XkBoSwpgxNjozolIuCk7kc3zfvtGhfvrCQ6OsBOjG/L0FtUVJBLCM+h/AYP zQsVOhcTM6aYJuDEj2TtgyPgU4tYrJGKyrQjLf3foONPVqQftN2NayCq2zMb8+LswCID crjLIeE9WTGah4sobFCsxZRpyrZaTFkc7ZGFYhqXznBHKH2N+LhUoE7pfPYe+bzKGo/a 84nbKp/LOoW1qlgT+2HArDnrWtu5K5bws6pSc3UtNHQsmATAoEVL5p15UkgMx3D5Kbib Ox2g== X-Gm-Message-State: AAQBX9dC/mgdzfT3FWCwii1hFxFIIPWGERvD1MrZ5v+N7N71pLkQ2Gra RrtKN1N7wa58Uh705b867oiSGqLSsVWp4J18DdU0Vwwm8APXyFo2vevQqDf2+g+879Yv5AETZZI HCxSKtuq1+9Y= X-Received: by 2002:a05:6214:4007:b0:5da:b965:1efe with SMTP id kd7-20020a056214400700b005dab9651efemr3648507qvb.4.1680192504250; Thu, 30 Mar 2023 09:08:24 -0700 (PDT) X-Google-Smtp-Source: AKy350aH6oyf0Up2gN8U0vpoWNDr4p8tT9aXJ3/orA+qv3unlxlWSXFhXjQOmrmgGPnvNrKYnAuuAA== 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: D51F21C0006 X-Stat-Signature: 5ep574y4oigw8ukx6qyj3uwn8u4wrgyj X-HE-Tag: 1680192506-187521 X-HE-Meta: U2FsdGVkX19yrPe+bO3MA8KWGK2QQWMnVW0HOTDo8KrIi86XelnwR3OFUZOBGEEO5EAeLbPAReE4dpBQYotDQosZwadzbBsmJfDRkaX4r61hubdpckbXGpS/zjpNrLC7cT8TvKhl26V5Vluyhfbks5zmTPTy+0zUe841MtJrWuc0KZ0w93TqKcGEn4snuk/bddZ01RGWuwIWVnoqu8sakEcVSjKrkO+a7tlLJVYOwY55QVkCegmtlrCJ2NWgUabZWIVcjc2QNyZqSNLyRqANOuBImkSXwdfWFlOgghKltBtxegYZFmsijUqfeWnKlCVH38GyCSkUoNjfYIFTK/hZdu8N1Ks9gsqzjJdy4Q4TCYU9qRSOU0qKLULuw591xp/xsCbGxgVejgyIFjdBlok1nWHJBIo1CHVg3Qf4LjdSYK8OlIYY0w1EiHunCtnpYycLZ/toiJZXLqyl5tdZKWtILKIzmZdejP+/ZXG9z5GsvxRxVuzt7stPKA/LN4596zIp/eWWT3GnDmviU3mtd6zJO+Et3iBmSJ9UuUJyThgcQ5zOoWLpAzuRCHfj8Op4Tlq051o4DaC6AeUGSAf8+3v/EJSTSkIaJxFQb67Fi5fpaaiKujye/3z22Ktt7uhGjbBXCyhyiDAwiU+TWOy16DAw3eQXmAx3fhY5TfUol+Gb19lqo7bUpFWDXD3vTmGjKZQwMHmQ53uwWiZYWoysZZfkZCeKci5APmS0sA8ItPO7oUg7QasRibGSwHHgTcaA7vgmpQG/hPm/ksvlb1bD2SEBJ/MZaGtkCC6Aim2trs7CK8gI3Or1/KMhsxUuGNKACcBb+NGJhUCrizInRwVNkBLKv+92REFa+0VfXIPC43bJPlbMxEP8BCPQlMdbSjj+23+rCP7F6yHfYsg0ZwSZW25PTz1dx3NAgmEyN3FqqG+XGiOcNUUr6e9jjdpKpXsRYeeL2qB5uNVl5wcRQOFOzM1 hFvW1lHn XgyJEXQFtVf8UNJYHx2B42lVJ/O/YgtVf01A2/tUvxm90oNl44ns2HdWa9KaV2C6+l4e51duydGTlDI+SqlUEGh3QDe45bTvnp9y3msgFv6gkWvBfM2VnevyZOHoSGNR9EGgaXojzO7Fmg2+r1+IE4Vdx6TxX2UpGvE4a77j1Pm9CcuaNV21ZcyNMq9Da3ywVn6k92DMSZg3y79q0LJh4ffXVuNraa2iTI8wqlC9+QdSh6ipwjgHM8mq9qoKgYtSIcXGq9r9qiHEFC2fChvKwHUvKemdLuf87o+9wQwY8lrgY/9tugTmnxFyc/Bqgt1SLVL1aCdbFKHOzxgtuKGfKjZIRl2mzTy9TKSzYdN2fTtTor+ngFLZ3iSqhyrLTFLk9YnyU7XQ2zrxRXmrlQYPOcKJGUhUaTg5TyHChwNX3Zh6h874jDM7SXhBxuCZHsHQQhzxUNuWD7/U+Nn66zuUlvD6JD4w/mFB1YHw+ X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Move it over and make it split into two tests, one for pagemap and one for the new WP_UNPOPULATED (to be a separate one). The thp pagemap test wasn't really working (with MADV_HUGEPAGE). Let's just drop it (since it never really worked anyway..) and leave that for later. 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: 13194505 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45DF0C761A6 for ; Thu, 30 Mar 2023 16:08:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D599E900006; Thu, 30 Mar 2023 12:08:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CE16E6B009D; Thu, 30 Mar 2023 12:08:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B5C1C900006; Thu, 30 Mar 2023 12:08:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id A3A916B009C for ; Thu, 30 Mar 2023 12:08:33 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 1019EC0DFF for ; Thu, 30 Mar 2023 16:08:33 +0000 (UTC) X-FDA: 80626047306.14.B2B11A8 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf18.hostedemail.com (Postfix) with ESMTP id 689811C0005 for ; Thu, 30 Mar 2023 16:08:30 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TnBZOkb5; spf=pass (imf18.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680192510; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=FYl/6yS5UtVMnAaCmSItplLGUyy4Ed+8ZQVGZ0RDCPU=; b=lEdiO5O5nrVufYmCnIb+VjxUnYxYXzvW0+GrB0xEbY+kaJzl9ssU5dC8Tqtqw6mlnYlrjG MkQHqWAPQYYOPfCuLBdPZnXFxjRypbvx+qO+qAevI8xNKa54r+JeSdcpUTtoHlYb9UJgbX xmDIY7X5aDU0KAJbKz+BAApa/CCV4Z0= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TnBZOkb5; spf=pass (imf18.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680192510; a=rsa-sha256; cv=none; b=iJos07Shk9q6O1/DcAv5Q5lRus8pcryOAj6kSOL3IElvGsSg//+Wosdd5Ie4GK/GZz8Ouc AgLtaR2bLTTC0sKRsH9/VWyU+lqkmy1LwO0+dzgbDH4tpWXNVUOPY25dNu/z7mIFGs3XdT TOFIbEBns7AyW5utRn+PpoVdJ21tvB8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192509; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FYl/6yS5UtVMnAaCmSItplLGUyy4Ed+8ZQVGZ0RDCPU=; b=TnBZOkb5kdgSSvxqdAX1HE4kVJy4ydIzeBnDngq61rhX1B6NhabKR/FZxfCWFu2CNPvm4F wSgGC7eQJJxHF5WG3iRTfH8cXQTmNHl8ZMp1uyhYkGtYDK949xVADiEi12wsC9UEziX4kb lXOtAGQF703yB+gbKY5va+YDuSuOOiE= 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-448-OvBW3b_WOiypMOQcb0hajA-1; Thu, 30 Mar 2023 12:08:28 -0400 X-MC-Unique: OvBW3b_WOiypMOQcb0hajA-1 Received: by mail-qt1-f199.google.com with SMTP id a11-20020ac85b8b000000b003e3979be6abso12643637qta.12 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=5+eX1qRV2gWBQjp9+j3X/qLm+ASgct+sDFCwbp/B26HrQQ8zDrXioXFXXd2QUZL6yF nHNTzyyDqriVBEEYPrZeVlPNZ83BqlklbarP8CxNTVJpGK+JGW6P4BXjfXbqAxaoHOQA bCzrCLQHIMQZ3jUB1zz/VP1sXVHGc4bmjMyU65vTbMbU5BwDQna3s4Bn3KIX7sdEhQuU 4Fj1dwdKR31IRvbGiU1eQjSuhByuIg+4lTuiywRUMcb1YWkM4MydAQ1ekY0j6NrBZpmc ulneNQep6zOh3K2BZUU6tXy7+8bja2BTOa/GTMRQ9xlDMb/aYqyeGZsELsuXesvPyaG8 Swlg== X-Gm-Message-State: AAQBX9e+z8NpeQGp+Gx4hxp+T5hWRHN1N5aZwv3lHnuV1ytJEkQPPaK+ i1u/UMCHYERVHd5LNipe8exQa62G4EQ4kcYRsABoY8NGjd3hHtWW1FS4po1J7kqcjLsLfjlT2jo bbXapYSNgdMM= X-Received: by 2002:a05:6214:300f:b0:5da:b965:1efd with SMTP id ke15-20020a056214300f00b005dab9651efdmr36932456qvb.2.1680192507596; Thu, 30 Mar 2023 09:08:27 -0700 (PDT) X-Google-Smtp-Source: AKy350bzvSc/AqAbP4HYGGuB2Ff0cVAuMuN0w5MB74cxWKB4kqee51E4nrpLgVuoA/lFvXDiP0RqlQ== 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: 689811C0005 X-Stat-Signature: eskbetim5pxfc7cxmoxjaoi9sgx8aar5 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1680192510-56301 X-HE-Meta: U2FsdGVkX18GPSof/+XHCRerk1IxI6kEcnDVPwWreDsFdyOs3eASpdCjeIzDhHWW78x5Koz1Mbd7/w/REFQWYxIfRSC6yAs3U0p1QSiEcU6nr/J/6tbROIrK/8fjLtLIUvsRmE4+YBmH+hEz/4qLKIThDuEimU9i7j4zDA+wF9KFruFL5pdhY1LLaU6M/AMNkzemllM6IpyQbRsw0/sa3dlwkWVcZJtfjpXbFofkOdQCt7wKHCsoJ1rL/sB8zQykLg8hkWX/x8Z9I7d0kftWyi1vWmTXaibAP5BRkP/Wlb4TlTxKG7DXA8s8oYxfoZdefvg1F8L8KnuOHYoJK7JNGpbp0Tbkh7z0kIAXYEJMf9CEMbHzJqgUC3s1WS4jkLmpdQkAqPVZIqibgtTv9yi/qRNfHOl8x26AaZPcgMlRLlI6awg0+ULruoanTtQYYK+O8pawT/a8z5dh7sis4E3ybskrWlzVXo20v3LkIiGs5r5udIL2I3ofE+OmMg484/R9+rcCvCdyEaXgXyXXwbH1t7fDLQGshix5fdvM1o6bgvJYeOqM5nt673FUactDrMIatElkYC5noOXIbIBiTHL03nGjGEGxV+nmFhWN15+Du2u5mYaL4ZH3bNp3SvHkNxf1YvTlReUSLusP/0PxqoX8jxkaTFGtMcGkyrBGiepuRoxI5DiHgW2Ui6fRY9E+4dzJ6m9ZzJLiR0d2+gZCY10P30eRRAWfGadYCDJBVHae+yOvNsSvG+5Y8j4nCA3cdnKvDKsp5uUSCf2ga8VTCFXy2F20igijEAN7sy+mSDKOQGIaQpEuoj9XpymHSJwVK9aJEjLrAPMFcbCR6PrUtTLl9v2/Hg1y7nKe1ZHJrWf83hKXKH/m1N1w/CUuTlJKwjoD4y/4TMWYMtVBXJEDE2fI9129ONGFa/dY7egmKWliaPVqBfFWcsKYCi2a1ApMo1HjORAcW7HaVYsHYlYLWzx 8ZY+jlfg fN1raz18RxxcKpx3S6LC+MzyLCBvTZ3OoEJAOm4rvDKws8xlwwjX2EkZy8RNl2D50TKSJfuRPTqQcp/bfvcEppv4rtkgh7ruh/8fBkslFz85Qw70j1i+4IS0MK14wwLt/MhMpFqumVXlmgU7b2dDXa6XbrYfdDiPoXJFIPtZpLZxF95ZxuZmEZMF7AdvsJg4UkfnMVu0Gqz9Ov4zJk5JYGTKEjy0VKs7OM9/HWUOb81KDcbLXPcwn6jjzcAWbyc321/H2o0XsbjGFDAG2K3bbWCK331TBSvX6Ptol5GmvUeryENdho3Q4ugo/6C8ZGFtvupUeGwZcqjRFEuEFid2+zVAk9YRLSMK+9Sge7j0BSgb8Sjortk//637pWVby+yzxqMu1B2caXjqIuRCHeTMg1gak79PByy3gtzkiN8j5HWQGvT87cabdH5/eenvOPQBNS4E7Ad3nlQmETAPkRrRYDytlrlK9kiLe7Cueh+eOIIkkAaRlo11si22t3A== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This moves the minor test to the new unit test. Rewrite the content check with char* opeartions to avoid fiddling with my_bcmp(). Drop global vars test_uffdio_minor and test_collapse, just assume test them always in common code for now. OTOH make this single test into five tests: - minor test on [shmem, hugetlb] with wp=false - minor test on [shmem, hugetlb] with wp=true - minor test + collapse on shmem only One thing to mention that we used to test COLLAPSE+WP but that doesn't sound right at all. It's possible it's silently broken but unnoticed because COLLAPSE is not part of the default test suite. Make the MADV_COLLAPSE test fail-able (by skip it when failing), because it's not guaranteed to success anyway. Drop a bunch of useless code after the move, because the unit test always use aligned num of pages and has nothing to do with n_cpus. Cc: Zach O'Keefe Signed-off-by: Peter Xu --- tools/testing/selftests/mm/uffd-common.c | 25 ++-- tools/testing/selftests/mm/uffd-common.h | 4 +- tools/testing/selftests/mm/uffd-stress.c | 131 +------------------ tools/testing/selftests/mm/uffd-unit-tests.c | 120 +++++++++++++++++ 4 files changed, 135 insertions(+), 145 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-common.c b/tools/testing/selftests/mm/uffd-common.c index 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: 13194506 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC4EDC6FD1D for ; Thu, 30 Mar 2023 16:08:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5910A900007; Thu, 30 Mar 2023 12:08:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 541476B009D; Thu, 30 Mar 2023 12:08:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3BA786B009E; Thu, 30 Mar 2023 12:08:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 292386B009C for ; Thu, 30 Mar 2023 12:08:38 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id DFE94161033 for ; Thu, 30 Mar 2023 16:08:37 +0000 (UTC) X-FDA: 80626047474.08.0CAFB7A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf24.hostedemail.com (Postfix) with ESMTP id 3E530180024 for ; Thu, 30 Mar 2023 16:08:35 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EvtCAkeN; spf=pass (imf24.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680192515; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=oTM5xtnArxH9EHNqMOFW/9fpO7KeYtGodOd2BXmVLVI=; b=5cj6oVKeYwF0xMj6DLA0T2532RhUoeJxikG/cS/83gLFapWjqZRk+hdR47YwuPxVQg4vsW 91lTsrrgW5tMSkmw2sz0Tish4hM7W2KoGHj605odQwQJHG3yGtwMGsRH47NomxXJD3wjIL Z7scZfNaeWUI/WtS7y5l/tOFnSQJdIA= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EvtCAkeN; spf=pass (imf24.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680192515; a=rsa-sha256; cv=none; b=ULR25dAdhpIHh5z0naKTpwqHtpzAVW2JtI6RWX4ujfXxaBptvOjv9HUuMsqXE00ekzWfkA KLsqOGczMzsca9sKeePc/KwS3VddhUWQedGnQwFthfjhtE4k92u/IbRvPs5r6tcfhtxa30 dmc4I8qaJY+VREgl33r6UxIcLv2NWog= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192514; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oTM5xtnArxH9EHNqMOFW/9fpO7KeYtGodOd2BXmVLVI=; b=EvtCAkeN/yP6NaXwgtUOi4OvkQrMSoSTyJ3JvQBFTuCRb3ivl42VFgP+69WLZCDtqY74Xc 4ztdodOQoyL+m2xd+c9WDA0Zm8lT2pcJIWTY5Cn1R6W6qqQttsKqaUBQEoLhNep5wbwO9v Ff3PLZ1K4Pw/hUNI8c2aZv4OqQANKOw= 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-131-4Zf90ovvOXyNQBqiiX4uzw-1; Thu, 30 Mar 2023 12:08:30 -0400 X-MC-Unique: 4Zf90ovvOXyNQBqiiX4uzw-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-74678af9349so60335185a.0 for ; Thu, 30 Mar 2023 09:08:30 -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=TEhDecDxyoi8PxfM7rWDAcExztZPwfda0dPpAM5pkk90RMPx1m2ZESe/1XjlDrHRZB 27T6WJEFTxpr5oi/Y5do0dADD76XSesG9Y/yjOkYTjScYfRvDJT/O8bZZiOHtncMnF2T ckWd3Kam1wX1pFuvTPZ4YZZfUc6AXwcIgQcdQcCIfnZU03/XfM5/TwNvwsCZZBa5xsp5 2noCo8i/Cm/hF+KQVwYVLBQHu32Id5vzRZmrxA7Y3F5UnZrQ8Qy5yJ1dZfk70QP5ljCV Aogbr7MOVqb9S4EmVet0uePdHjssbO2Xv4H7a0uBqsy0T56ohXprpjAaFU+vRXjScyDn nSag== X-Gm-Message-State: AAQBX9daOJZkreaSn+6E8UzJL4lqWtudfbbG16J71Ctx5y1C3rpVWP2Y IBdVQ4L7LdYZ/TG/4kwj7r7BeqLzEsmUsjK9QFA2T1bGzClrJePplzEQHEYBIGOx4Ih/uV5+a/q oS0lkh5BKKeQ= X-Received: by 2002:a05:622a:1aa1:b0:3e3:8e1a:c30b with SMTP id s33-20020a05622a1aa100b003e38e1ac30bmr4584652qtc.1.1680192510037; Thu, 30 Mar 2023 09:08:30 -0700 (PDT) X-Google-Smtp-Source: AKy350avriHt3XCOjyRNwFhAa+6n3UwABlp02KxPIJQDVusPVqqtc5AFGtAyQG20QSUpJkKO74s2mA== 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 3E530180024 X-Stat-Signature: db8ktr6rwc6wpp54wwrk7u7869edqkid X-Rspam-User: X-HE-Tag: 1680192515-520464 X-HE-Meta: U2FsdGVkX19B8iTOhbWlZQYOHpiuQtRVyJQEOqNjGxg+/puZLqnq53uzxvjRqK/AhSnKK+Br9xh0TU8j407RUAMw9AzOgmPYcce/xCu2wbe3TpVxsATDwH0PHfmoPzBivooGdW3RbnKW6iRn3ZQIxNgksPjDVUQOVB+qQpMUjO6PlWAxgev+tw/z+ERuYV20NxaN0EOzxjT6aYMmnAkUk6h/s/m9NlhubZWuZ7ZAXt7gJTVGgfL8Y4hBy/dxqVw0r6MQkGPsNHM3fVfsSfzttLugFw7pJaxwUPkghTjxlAt1zAitFkTxjlEHcwQofmWg9GBq0FamjrTL0SrckQ+qjOU9Gs7TO3nVRmMUZ/NLgo161tp9gqN5NOnxTOGMUu5CQtvBVajcDwyamqlUWIWT5jgUMEi4gG5mRum970ZBrLnd49nFhVjUpTNxh7CAzN28W2oUVW4t2dEWrO8ojkqUiKgu9DEDgppboyysboxkBpNvdF3EPzO6S26e+jvnQhyHe0+cKMFu02pnnkyG7KnZtdPqzn5y0KBbo57x9pUsSXV3E4EV4xhpqoEtDXLzLWfDfAlhlXZLwB7FUe2vUW5e7jfogNFoLsU0ttT4n9bJD/vRjv5EMyn69JzhrSh/DHUFWcXDYK+EDpq74nJdoVK0mfw0EMh6daNBowBTeakSYpTOdUw7zhet57U1CSLWODiJG/whlkCnoLFcwdH8numXR05DQCsYydTg6sJG9bSW6rg7AYcTUtfeYjQb7kTXVtpgcp5S3oSn6htrji9O9WiLcCNnBlMlE60hT2vBuh7aPuXgr8l7+1/iMeZnJBOZSHhKC7lZB2VrIT7JjG0p3/3hKWTvPJlvOx+lOk6Rw6w/1GQaCEKkgoaOpOYggNK5SENt2tVE9NvCKYANf0IhFlWB6Gdk6QVYDUCVlyVNASzvkZTDLWV0BOi4R3xsxbLFuoZ3EoazQkKGoqTsxdsWFnY wvCCif+5 yC6xWGD/Por01BFZ9AFrr0iw/aYEu9eum23sJIcH4LpXb7wtT5qKh2L4gxeY6w7oVoD00F6dzK5kKzaayW6XgCimok9+c7SgqQwZqIUAaNwP4C2u0dlcEHMsdA58BM9kMq9l4VfPJi9cHkoGNV72PmHCiQ/Dqtx/+loh3UxgueMHYpX528Pz4BP4QSwf2Mk9Y4jpaumx0j77C1uKneB3WfamF5uTn3p+3itBliy6VQ/kyie0YiaJWs42S1w5otGIjSZWgNH9ARiX4Dg1RKRbdPAMzkc1/ZaR25NhpcSrunXFHdoreqE9KUTS/1Zy535/W/7++oAEjTMGUPLjKUVGrh2pY5OdRH1nVPmyzAmChFVAE2rn0HSHZXsfIkvfXY2l1NiOAyxwo0W2vpHCdLtrALzHeoaqD1jTKRgQGW55RFYnbAJzFYgQU6dPj6A9lsRsxHzvzXdCGw7BGum+VNbRogKcyTS6zHNP0LJC/ X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Move the two tests into the unit test, and convert it into 20 standalone tests: - events test on all 5 mem types, with wp on/off - signal test on all 5 mem types, with wp on/off Testing sigbus on anon... done Testing sigbus on shmem... done Testing sigbus on shmem-private... done Testing sigbus on hugetlb... done Testing sigbus on hugetlb-private... done Testing sigbus-wp on anon... done Testing sigbus-wp on shmem... done Testing sigbus-wp on shmem-private... done Testing sigbus-wp on hugetlb... done Testing sigbus-wp on hugetlb-private... done Testing events on anon... done Testing events on shmem... done Testing events on shmem-private... done Testing events on hugetlb... done Testing events on hugetlb-private... done Testing events-wp on anon... done Testing events-wp on shmem... done Testing events-wp on shmem-private... done Testing events-wp on hugetlb... done Testing events-wp on hugetlb-private... done It'll also remove a lot of global references along the way, e.g. test_uffdio_wp will be replaced with the wp value passed over. Signed-off-by: Peter Xu --- tools/testing/selftests/mm/uffd-stress.c | 227 +--------------- tools/testing/selftests/mm/uffd-unit-tests.c | 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: 13194507 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D936C77B62 for ; Thu, 30 Mar 2023 16:08:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BD2ED900008; Thu, 30 Mar 2023 12:08:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B81C26B009D; Thu, 30 Mar 2023 12:08:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D453900008; Thu, 30 Mar 2023 12:08:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 8A29A6B009C for ; Thu, 30 Mar 2023 12:08:38 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 55090161033 for ; Thu, 30 Mar 2023 16:08:38 +0000 (UTC) X-FDA: 80626047516.03.2E7C0E2 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf05.hostedemail.com (Postfix) with ESMTP id BA3E9100028 for ; Thu, 30 Mar 2023 16:08:35 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ST8XVy04; spf=pass (imf05.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680192515; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Roeuk409dPF2L2QvtyDeIj99sNqVdIN74Z+r6aghdT8=; b=BTPo/mb/9dm9s0VXDaQ+YWy7cQ7LMn1CpMGaRuY6lc6dEelhjaPcn1uM/FySqTEHZjXwMF D8L2xTNTHnxdO/Zxgp7eG1K7XKSAHDtQ66w0hpbinZJD0ECQCbYASGWYibRdMctTtbEbAL oh8rNbCbVw2pyjv2CS29bpW+R3MP25E= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ST8XVy04; spf=pass (imf05.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680192515; a=rsa-sha256; cv=none; b=qlNXxkvAJ6MDH0Wmb56AOHCJGffdmqAXpvGP+eep2VWyo9CS/LwPL+k8xYhrLEq2XvA363 1m+4gefWLAV3g4I0n4SFkLSQBjjjgXo6+sNiBfBzWlVPHUQ/Tx6TH8RJMp1gxdnkwbW1uI xD91o1ZZC12y3/VMjejOwm3fXo+qRAM= 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-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Roeuk409dPF2L2QvtyDeIj99sNqVdIN74Z+r6aghdT8=; b=ST8XVy047m9ocDOzNXfkP0aTVQFr7Mx9/UImqWnUrq1TsJggztdmzWWqtzT2gc/xwVkNrH i4odHNGoZFPIo1oHgq6EVpAb/KAnQvjsjdXe5vWAcwmx0JvCvNt1hjfvPCmG1SupeQNzI8 lX2D+SB00gbxS1t+I4T2BymrxzfZnXo= 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-619-xLuMN5Y7O6yb8pDAYZpBaQ-1; Thu, 30 Mar 2023 12:08:33 -0400 X-MC-Unique: xLuMN5Y7O6yb8pDAYZpBaQ-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-746bae78af3so60184185a.1 for ; Thu, 30 Mar 2023 09:08:33 -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=XJB0QUDdV2yJhV6E9JxrLL/eY32TcTRXk3c49BWA4SzzVPaxMO6t52cY3ABOpVwKNm RhBv2hwocRy8QaqYpqGZMl2iybTr/rXmdx9HsANU7t21aB03n2pQLizVPtRixFZ8tiDO o6XWfP6WSuaj+QO/vLXC+BHNuEuUxc1QDhVSzZuQuOJNJ8b36hO6IR3YQJN4hfpJA98q WQtOGlFsUoicUB2YGwfF3QRDJgKpdKd4dQDGed/jRwoNU/n0zMV7osssy2zC9jtRGGWD eA0EuDignQDsaTUkT95wxeSrVOp4+YxH8QP1LwFnzFfNRm8Plqqakui2wtY9LRvyIVEz h9EA== X-Gm-Message-State: AAQBX9dgW19piBCMR+WZ3KsmYlPbQY5YGgmYl0PVBzyftLvCM27ISr6u RZQGMniXnI/XQVgFW/jOXZF1bAjQ/E3TvHjV9Qflj1EHzEe1NPDjyIZH5w6Zi/4bS0/hhC2WOjz R159VgAfi/y0= X-Received: by 2002:a05:622a:199a:b0:3e4:eb39:eb8b with SMTP id u26-20020a05622a199a00b003e4eb39eb8bmr4380191qtc.5.1680192513135; Thu, 30 Mar 2023 09:08:33 -0700 (PDT) X-Google-Smtp-Source: AKy350Zj+eN5QPeQ5wVil623hZvzJrIMImI+/YUsY/jqTUUYPanRTL0PgneBxr/Nlg9DU4Nsp1MaQg== 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: BA3E9100028 X-Stat-Signature: sk64opte1c7wj3dfghjtjykgmgusj4ec X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1680192515-908411 X-HE-Meta: U2FsdGVkX19mNrtPBKkUXwf7VLhxjy19/oDkinfOGTFvmNRwOcnwN7E2ZJe2DB/HyBpu0EuYNTCtDJwVD4FlnFoxSbNDlSIdPhPDEvFVgJslecQenCcq/gs4XqGowcPsNSSyWkBzSAumwXKujKV/p/U5ILAsomi1KJHjQW4nkVMbJu02ZHIi1Hj7Hm+A0qPgPUKv6Od3Nb7nLh4oEFWz9Y1qYsdCEzr3tl7POUOmZ7aW0wMxUY1QWjUqhrBn509PtTuNW7pDzp4xnVmg3SDIkT+yzBSbpcnceC1gu0XfoKsdKLEqTDCmfqNeLMv2rM8WCETK0Azbkmd1XzUDBWTS2GgseFMUlvpGt4bPRXHTPd+XycNNwm8oggOkTBh6kUiYYzVxy4nU5lj2lz19R0yG3vQPtuP9oY2LiKqdv3PwFrRY9uw4PigXG662KrN74S+ZKtCk3uQCgsjlpaWZW9+w+12j3g0IHU806hiObiTwsuzcOV8zBZb9Hs3orXQagjSBB3AL+qhePs0zlvhk2XgHfxhXp8xGP24U98F9kXF78suPRF3rsm8I3EX5b1G7GbUGmqX6zG9l/XBXTv4mxVSVPEhrAHvN/2CNWLh1N9qbTOZ8M3hV1LhsjeBCcHXu3nQHk44st6B7A5fAoYElGxvBwbNMduSAI5YgyyTB8WJDy2Z/mpHDiyGrvkK+WYM7YKH1d1CjdJTp6AIX7MppjTvS8peu1g6n5gN61eo8iG4fyJwL6JyknoPXts5YSGl6vxs93hWX4hL6KfTqH0UUKkh9wri5oK/UXGF3rymUVj3XrfIqiOxHsm3oi+NnEzUXA3ups3L5i6BWCdgOYARpIHX8+JeVuyVS0Me4OT86+bQFZQkfTOmIZOTnVgTxPOekMwFfBvhDTBU2rG2Jhdi0fsbd4XKTqalM7rl7jOhWzeGI8Bf/Hsp0fVZzk6D0fTQZb2Nc8TT8mklq1JLRH+ro5xg Do8rzzrH rG5nBls+TK17dIl3h+Y4A/dveDaDru2scUjgSHhVuEE03o2leZm//hDE8k0JleBA9bt2Lze9ctI0je1TXW3mLkzF1PIi6MYRdd5+kZBjUK2rxz19Tjd4KmiJW6wxg2R7D17inOvPnxYzLO277NKzt6rIaxoAGh3n36ZKas/fJvzDHkZXbImQJ5PTIBizLKPn4yN+z0dLHJkRA2bZ/uMwHq3z952fSLZCePy2v35Bth6ut1qF1l7xAsdmaOmilHVo0r7JlKfeVl1Y/LGlPKvVNZjpeF1aAvRAsgNx00mDz9laMfqXsy29N//6kjKw/4Tfm5XwDZ9untcvj2DuWsjZFmKGQrrgYCXHQlHEKR0F2BJcfTb5UnV1bxpVhu88tFHYOUBTjVlPDpL7rLNx5gkvB+PHiKatikY/I8uoGDSyqFAs3yPS7a7m0md9MM7vdKUWRUSHaSdjDNceVVvyzmDCdwrXsjKDAc5y8UBHj X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Simplifies it a bit along the way, e.g., drop the never used offset field (which was always the 1st page so offset=0). 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: 13194508 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9EA15C6FD1D for ; Thu, 30 Mar 2023 16:08:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6A243900009; Thu, 30 Mar 2023 12:08:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 652AD6B009D; Thu, 30 Mar 2023 12:08:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 417B5900009; Thu, 30 Mar 2023 12:08:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 28C046B009C for ; Thu, 30 Mar 2023 12:08:40 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id D53A9C0EF9 for ; Thu, 30 Mar 2023 16:08:39 +0000 (UTC) X-FDA: 80626047558.03.F90FA6E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf08.hostedemail.com (Postfix) with ESMTP id A901B16003A for ; Thu, 30 Mar 2023 16:08:37 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=XZxtd29E; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680192517; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=IPQaNGX43g5m/+6Rf9W/FOC5JWY5QcIX+G5qmLnnQxA=; b=q9MpT+U12gK9dhjsiYQnoddtZlfPURqrkiokDcJBjslold0yuOORWb/BvaOip41bGd2EWJ jmyzMOdQSjbBz2+QimVTLcRDTL2jL4mRD1GwtIOzi97KuQKB25IQK9Eju7P+9f7mRduCND EqKIcAHSziphCyg+evT8yoLsxUqR8KA= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=XZxtd29E; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680192517; a=rsa-sha256; cv=none; b=GbT9fSB+a+iAHTs4WaUUfO0UEu1V8CG5Kn5ZdmgqNdLLOcdnufDdROPFHfTlokJHjIDMn4 tJsLWxscggG43l+sFERycZ1AtEhxioBShLxqihaGCGMjID+rglEgHyE2oyCi6MBMf77GYo zst9Hz46+LN2ZsJZsPwkdqci+srN3Zc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192517; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IPQaNGX43g5m/+6Rf9W/FOC5JWY5QcIX+G5qmLnnQxA=; b=XZxtd29EV7X/aey/mcStsQsHBoV1FSsBCGu7bT6eU6aRwNnYl/0kgDlHsHcb9q2QxYt2wD 01ee02/w8LIh8XiNw3TJmx5/A9c859kUjG6qHl3AWlifbHKSd/I6nCdkI9pMzYpB22sXDD JXL3Q7ksnI1qs+oCP5K9ZBaBP30sP/o= 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-612-2Eyp-qOaN5-K8TOaVxDiVw-1; Thu, 30 Mar 2023 12:08:35 -0400 X-MC-Unique: 2Eyp-qOaN5-K8TOaVxDiVw-1 Received: by mail-qv1-f70.google.com with SMTP id g14-20020ad457ae000000b005aab630eb8eso8493509qvx.13 for ; Thu, 30 Mar 2023 09:08:35 -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=ziBkBIVXGDa8cRoq9ZlJCOSG6dZEph21guPbU5lTvoe4SkAe1NMnoR8CuWbuuxgy38 6qBsURqk5Aekp65UapqIXy0i8+tiaSheKSAE6HBaqFoPdMU5QQ/BFiWXTVJ87gHl0RQt tIV//8ghbQ/nSr5PY0Dh2TumAh3yf9fqh+BpJSlWo43HCO9v/EX930uLyiDt4V3OlI5n tQosJK2Zz+Mo0lEWBVWG2HMp587+43dYN6R5jOW20vCpULLM3Dh1jX//57gtHUw/UDQr RonMgW7VRJ3dvFQmcv2rJQq1H4pOKTI9Gl4JjV2RFCu+xs/TPDWtf+wIBOAIuNSfRB79 47rQ== X-Gm-Message-State: AAQBX9dZTThYQyZx6ZI/NEkHuJyToEpUdu/53UzlMvvOOEp5kpNbRh0f xnAM6x2P19iVVr0GFpQY0fFtibgTvSJv3maEcMhaFKU7fx72aQswYz0uX98KQNwQkMARBYssuCa DRzyDkvQ8yZc= X-Received: by 2002:a05:622a:1894:b0:3e4:d3cc:4211 with SMTP id v20-20020a05622a189400b003e4d3cc4211mr4416045qtc.3.1680192515336; Thu, 30 Mar 2023 09:08:35 -0700 (PDT) X-Google-Smtp-Source: AKy350aRBS/3Ba03nR6/rH7+O6OKnPp5UZSkwf7AEEAgfK8oTfxGPLAAS7vHG57dqP9Xg/7Bnp679A== 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: A901B16003A X-Stat-Signature: cytgoy83b8kk4o548yk1hcz41s8gucqa X-HE-Tag: 1680192517-407831 X-HE-Meta: U2FsdGVkX180nsbpBPZz8sTAjZ2Rk/9+fV0ALxqXHiI5IbyHR0uZZujWdNHP7inxvCRZ/9yjJaEhjYqyTQBwAeDhb1X9Cfhf0HutV3TY3/siaJ5sBKMiAKrBL/IhMas37HIqePMSRAfmTGB/HOFEk31BHCd94AePuDyGurNq9MzDLayXB4HpWDU5snOhfw7VTD2zoDl7vrOJNKa+n00b2S9D4WlrkWUAN0+QaRf1oXVRsSaS2gNSr3M5p2Lm7vgMgBZSJKfMXntEp9ZlfiP0DmE+j7jP/yOGSCKORRvUm28pWOqhTYqQYMyqBDnk2vBV6B0W2tJy51pti71x8zchfv66K+coJszsM5fCPu4ls0pRDU3p49SulrIFukygDc9kcXRG87Kiek0peYu2t2Sro+YfsETnWFH8uUQtaZ04FKTZC3zmVqtvfjOzz87urb9S5po42XbJLv8EbPIYqK31mCzlPMG3ac4tGkAtuVK73ifjAztZOLmUXqxO7/rE0CFyhZForzGzcRXGh4B910jAe1ZX1XH81TjVrl0smRpaFj1zAAAxTaF3bcd3aOokOG6KZs6qssKQr3Vf55prPQoUoOYI6q4ethF9KJIa8XBztGLNhi1/L6lWKeZ7QNKHGy1o5Xo+vfepA9tXfw+k0Kt9Es/AoeZehuoGcM4N2id6xiajyKvHUoVleRIQQxrEkcyUZfN0P/Tizjawmv+ni6ujrX9FwzGBoE3NUaxPIoiuoyhq/lk+3nXhonxL7Bf7FDke3/38laqc8qOgLR4tXUsdkX6MJ+CgSTvCse2lML9IugCwEzEJwBSr2SjKkxAhhQmBE1x5qOJr7bEzqL26sT9tCYATYKctV+mAFUqlArM4YtM3AkdS0bq/9ajRbRaA0mkxglwAQBzZSKgkCY+Fy3wX5flHrsui+55DIXIhz9tHR8py9E7HX7mUtFTrj7fgwpJAcrwZr0CWTwvqnAMO3Hh bMjSP4JZ VPY/8egQ/02qFOz03F+mo99C7mS1xn4RpCR4vlUl1g9hJhGkg+cno77dySqYmR1DweOKuzexnmBgKNwOMx42wj7riBIJG0HHDz1RM0fPWhN8hzgXwW88d+sk+ti1kIHq1HU/RBIrEd6zAsHib13CVyTL/tBvik7qsuiBJy01M6gvwnIY6oilGUYc303NX2lPJ564jxdjXVuad1vw1c5/eo9SBreuIag/wJASXbAp3h+DgOhSJ8PlxbAax/4oeD3M/1esP0Uhln09r2RkxNg92AIURDCM9K3L6GMsVXI4KXNV2Br/Wzq8yt7MQAvTSY1lCuVyqqWKd3hHpfQakLuVbW5Lfp/lT4OpZFBE9xMH1IKYbqnMEBuTQX363NouK8EAZtEiby6Yzk5NsYAA/sSo69DX6gKrlwOIfeu3WcFhiZHwLttCCs9XlWzpQwok18UeivYNSU65BY5PKynwXvnimisRNPCGm5dw7NHTK X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Userfaultfd minor+wp mode was very recently added. The test will fail on the old kernels at ioctl(UFFDIO_CONTINUE) which is misterious. Unfortunately there's no feature bit to detect for this support. Add a hack to leverage WP_UNPOPULATED to detect whether that feature existed, since WP_UNPOPULATED was merged right after minor+wp. Signed-off-by: Peter Xu --- tools/testing/selftests/mm/uffd-unit-tests.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/selftests/mm/uffd-unit-tests.c index 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: 13194509 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5E2CC77B60 for ; Thu, 30 Mar 2023 16:08:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4CDF7900002; Thu, 30 Mar 2023 12:08:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 458126B009D; Thu, 30 Mar 2023 12:08:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 234FC900002; Thu, 30 Mar 2023 12:08:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 041806B009C for ; Thu, 30 Mar 2023 12:08:43 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id DC742161041 for ; Thu, 30 Mar 2023 16:08:42 +0000 (UTC) X-FDA: 80626047684.26.7F438F6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf04.hostedemail.com (Postfix) with ESMTP id 9E39C4000C for ; Thu, 30 Mar 2023 16:08:40 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=f8yFnMQA; spf=pass (imf04.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680192520; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=WAXTpuab088GPUG02wNB3TGzyfzkRuRXgQ9Q53l/WHY=; b=abngeQV9UJgERbxto2BT1meXaIno2Vch5YfGbsC3XoU5AGyeebq7xg7cr6BlVOit9XWHOQ p0uwx8SmiEFAJP9QoIVcR9gj1/n1mWfPtREa4TcTtz1P7c/Rdwk1l2cmGlhyJjoUbWAC6T kQCQBkmbHMIoItcx/I0z6TQ02kR1csc= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=f8yFnMQA; spf=pass (imf04.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680192520; a=rsa-sha256; cv=none; b=CGIZG6XaCmWGj+0lWNjNq0HVS+DU1/Pb9bvny+UpwMp2xKUI1lcv5IFkVosOt8PHoIvde5 a3nlU4kO6KSjBkWUwA9GvCXI8erKc9N1RtzOvokn4yOZnDwIYJKjqcFUOBUtLDPZZZ20mb DjSRnrB7ZIjPxstPz3GmaUHzZUBYMkU= 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-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WAXTpuab088GPUG02wNB3TGzyfzkRuRXgQ9Q53l/WHY=; b=f8yFnMQAPIs1851ubDzo5cfVO60+8k+5FcJ0BoAzeVMZevgeZPvFS8tJ1Heg7qo/GgPBne wnBWnxsK2BJ8tGDx3wrqM5DPcT9ax4j2PsahKnes3bZvJS23QSqxvwKX3wYUurBBFM0Bty DPsuq1Osft5ychZvsfrvzHJMSewWtAY= 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-526-1vQMHZd3MpeL58fhYDzxbg-1; Thu, 30 Mar 2023 12:08:38 -0400 X-MC-Unique: 1vQMHZd3MpeL58fhYDzxbg-1 Received: by mail-qt1-f197.google.com with SMTP id b11-20020ac87fcb000000b003e37d72d532so12709283qtk.18 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=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=sOfMkWuoKxvg66zzUvDV/5MnpEeRHnfKsBR7U6gpQyM1o+1xrNcSeekVge/hIuO+IG 01p/iZbj0UvEmkXsScqLs+dFGFu/JgltWPBmCUvLyGZdcOuZrCVRSqdJnPdDQSwL4Qn2 4CkmpZ9t5VYfnjNyeIw5rF21XMh+iIU7qejABmZFfQxnwJfOkpjZjlsy8pTsE8Ye8e5W rVySViY6kriuMcGWbLAJ9VR1caXL66ZNk+JtVemm+DiGV9pfp+s76wkg0TbTkLBHdHs1 2aYln17XX3eiRo32K8NvUyVwJjDhJpnVyq27ejoGA/mQJsyeDhjZiewRYER2IwcqNlPL mVlQ== X-Gm-Message-State: AO0yUKXdtBzbTHB3cIT2K7ZBfbXpi0J7Z0JwnJb4nqXsJrX1mlq789ma zaW1iKrBCN6gExhKaDPFkECrUxPv8JW+Ttnq7aXfFEcslNbiXUKlFCuZrYG+/mOmoVh2SSVixMs Ph9KQb4FKk8Q= X-Received: by 2002:a05:622a:3c9:b0:3b8:36f8:830e with SMTP id k9-20020a05622a03c900b003b836f8830emr37735697qtx.6.1680192517752; Thu, 30 Mar 2023 09:08:37 -0700 (PDT) X-Google-Smtp-Source: AK7set812uf+kM7Yhq9Ka7uXYBi3m3muJq4kJHafeEAcNFKKp1xJShq8EXVPV3LRZllFJWeH38i74A== 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 9E39C4000C X-Rspam-User: X-Stat-Signature: pi6p587yjqrje47ecqxe1gbergb87iox X-HE-Tag: 1680192520-441508 X-HE-Meta: U2FsdGVkX1+LR94nLluQ/NueGSnb6JoP4wKES4q/4dcm+sLmuAykLnPfp3j4pvd6N2vrt8F4TMJAL1fUUuRLWe0tRZPx20m9dJ1uUkxUk1opKAqdgBVAGRo6jg9gNnFVW8aoMy47i4MUAASdrNXPfAZ9Siu/3QilNsJTfwDHgLW2bmN4QNJiyjZXKL/jlD62mhyMl8WgKW2SGqAU4b1wKtnaL1XMA278Vbygfw4WkBtKOLUJSOyo6Q3aoyljnP4dx+IDQc4UF7o1s9c5uRM1E69OvH6dQm6z51TWVIZoXIAwYR26tmkgRS2XRcovV5gQYCo+LykdmmSo4wbz3iC9QEBznfjIud8NGelNOivJkNbvuV68guoqPBLGiomhpLQKG4J3lrwb3flGqG/ulqpKUTh9KYmbEPEplmWMVU7SZyf0bkqYQpqXcKA+gohbB3neNnhxLVsWuOLgKVe1O99X/VNPEuO3CUFmPRT5PTWMUG39X8iRlYEb7fORdHo58+BoltHhxFFCCupLCW+cj8PROaCVAHXo/Vhx/EMJQP2BWzlZL1dwLf5/i9/kUqHBaxXJYU1PbvqWawlSQO0U+O4yZjuMzpvXgGYn/gZqcroBC0RJMj6X1opQokJLjd2KXD8T6rapU337qNONzuxa/m7SWhK1m8D3YwAmHLZyoz0wFsfDGrVP6cIC97jRS2P10i2qFAvPtZjxlPQNhDYm5KIOoJvbOr85yHUTvBb8Ia4o4vmzTdps0KUlzXYzn+Y/27vaAI25sUHcvFpYozRvO/8RffsaAQCDqOVp7HD5WibHhRXI30sMHcTtp/7xol+w1NgAdyR9PMzr2FuNwt7B2k1n4fWMskDseqqEjPlwGxuW5xxNaY8UpX9TntLqLxKrV1E4aZB0fsT5N4/26dUgh54RYz/TBWE+ZLf8HoOyFaqm0MfJ5iN7UALWqOp2flGjefToHz72ZUVP3WBWn4EfQnD bjsTPMP1 Y7jq1hz5Fz37+nwbavf+KM0UW1J6VvFWhcFnsPbHc71aFw7uIEnK8PvnpXoR3bkbm6vUHq60/o3l8SQHMT5uqZ4sku03SC3EA2Hulou7T/2XrIQm3bQ2aj68AA19/pxbIOApJdmFXZ9iTObB6JxK/EmgXxhkM1hR7pIC8U10fRFzvBxrFd0cqtppqNzXszyPPj0PkS2zPua/38fdXEvr+WyLtIc3JusHykzrn4ea2tozKRKfmJnqKuFOdBr/bPSHSPcO628JTrsXu7PSbRmVM2XFjUNWnZcb2mlwaiINC+KIDcRIV/KtM5gThgera21gpanOV/ouGKujuwlyjzxhBv4KMjq6roYaKAKRiq9FYDznjK/a9/DLF6zwJ6zpNzLMBQZpXmP5L9RulJdioPZkvmc2qCmkfzQ+YwOrD8sADuCtAHhMNBF26au40I+187FJ9BcmHdH4J0yxfoXht2enA+4Pb2FzOF24GU6yR X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Allow skip a unit test properly due to no privilege (e.g. sigbus and events tests). Signed-off-by: Peter Xu --- tools/testing/selftests/mm/uffd-common.c | 27 ++++++++++++-------- tools/testing/selftests/mm/uffd-common.h | 4 +-- tools/testing/selftests/mm/uffd-stress.c | 6 +++-- tools/testing/selftests/mm/uffd-unit-tests.c | 10 +++++--- 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-common.c b/tools/testing/selftests/mm/uffd-common.c index 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: 13194510 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9FDC1C6FD1D for ; Thu, 30 Mar 2023 16:08:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6576E6B009C; Thu, 30 Mar 2023 12:08:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 590C090000A; Thu, 30 Mar 2023 12:08:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 393256B009E; Thu, 30 Mar 2023 12:08:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 2307C6B009C for ; Thu, 30 Mar 2023 12:08:45 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id F15CFAC1A6 for ; Thu, 30 Mar 2023 16:08:44 +0000 (UTC) X-FDA: 80626047768.19.5D3E669 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf23.hostedemail.com (Postfix) with ESMTP id C81F5140022 for ; Thu, 30 Mar 2023 16:08:42 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HF0knmSu; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf23.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680192522; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=SqqRZE0+KdLihnYJHNBsrIiryhx5Vgf+EPtUaXiDnEk=; b=7AB8Emt56OJnm9DAyJbHZIKf0/3zfGWc+dIGb6WLW9NqiokrcRFpXhoTJ5q0/O15Dd7AFf L0Hb0pPHAtXHSh1O0Pv7Y7QKRrM8ZMi8nyNG4HIQIUGNm/8WqKrAWEhhPZDKQ0i84iPUbs IKAJNSuDzs9VB+Rj7PIwfX3F8S5g6s8= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HF0knmSu; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf23.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680192522; a=rsa-sha256; cv=none; b=K/6ijZONxLXiWDJeaooWv55sg+rOs2quMDT8qb78e2F6c+V0Izv1FKCFRQEHYmdPxx+p0u BQ4qwnZ0goMKq47xg4iAKb04TOHYuun2ySidTicqNvckWD7RFJCpiPtnKTTMcbX2sBYxLP e67+st7AiJTzPpZR9uWsK08f7Elq1tI= 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-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SqqRZE0+KdLihnYJHNBsrIiryhx5Vgf+EPtUaXiDnEk=; b=HF0knmSuYvEYRVAZCBF7GxhWUMqP2CLqLB2fNvmin13K1t2AdN0G1LreQGfkTFr2eHFKa4 bejLlF+a1lnbkkj8V5M1/Hw/HdN5vPYaIEUEkGVd62Nwp7yp3oBQPRTbfmbIXGRdRRpYhV mXIQx/hoTE+IWovkL576O0p4lly6JhI= 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-642-myKYyltIM32S22y8mmL6Qg-1; Thu, 30 Mar 2023 12:08:40 -0400 X-MC-Unique: myKYyltIM32S22y8mmL6Qg-1 Received: by mail-qk1-f200.google.com with SMTP id d72-20020ae9ef4b000000b007467a30076fso9087604qkg.18 for ; Thu, 30 Mar 2023 09:08:40 -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=LlfrNExZ9oe4NuB654TousJiRAfblTD0APFQLIXZEtnfg5qcxnMKSPUFSz92dAt0xt /Y5UUthsaJKYGGk1Nb0N/dUvpWpBPp2RZHNqzrEE5DlhCVkw4ircnu1auNAI1xZTItJ7 /e0Hnv3PRBW9tnk2L9HHpAlznEu/mhWIztDMmab7OmsKYOdYRNQLOTOTpYxaZeh/XQkW YitqS/BMmVMBrIOkv4T++vZBX0N6zpS331DLywbRUaETkGUnzEkzEAP5JeE1L5aoCEHd LcPYpJncW0ma0HxgWlRqGWzB5oEmOmMKt9+sSZFbB4kviIIBPXmAkU8wkwvXxj/8GR2u jUcw== X-Gm-Message-State: AAQBX9fnDwIzIn5m6c4qehSMivnonwYCUm8OrFIaIIhB25zYBRenZ4fj SoAxs4+oqlfP77kSUEfUTMj5PiQDgD3wZ6uE9AECCg6T57zty+7rssD0QOj2Wc15+tIWZNsqikH EH9gxkb5dePQ= X-Received: by 2002:a05:6214:519e:b0:5df:55b5:b1a with SMTP id kl30-20020a056214519e00b005df55b50b1amr3622813qvb.4.1680192520215; Thu, 30 Mar 2023 09:08:40 -0700 (PDT) X-Google-Smtp-Source: AKy350bqP/iX2AlNio2XqzWARNgLqKc/rTJrU3oBSu0UdCvPePSSbjDMbIS03DCF8/QdFFI9R5EhrQ== 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: C81F5140022 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: wromodk54tsnaqke6f7pci9fw8ogecy7 X-HE-Tag: 1680192522-471678 X-HE-Meta: U2FsdGVkX186H3tzNk0SWvkK3tJTTPVtWmQzkfdiU8mUvhQNGJs8U2GJGNEzcOPgFvKAtQgYtkLXRNLpCKFLCzUi9ZDBac6iXdni+BooRdxZLUuuVBMFtxIK7RyglnaPbcTIPhi9arkaqvYuZ+cZBckuqZqQRvSG/KwPTN2oMU3U/R+wPE33Kh7GPq9dZDSusdDyHGsIMlMTTCzIXNKuX7B/9tu9AnZErzdlMh0NX4C3bfpwa/v5Rfy59qUzLfKrhAgEqPTI1B60VsWbY+zvIWeXNnxq6bt1xfg6VnxeLYLjV4HxinMVnuTkpyjvL/nTWHoZh3sI5NKwvAeoAB053lwmQKHouLQzRAYVZZC2+iTHS7KN5ikLBXLf5zjFK5bl015zCfOvmgEZkXLrnY5UnFB5QEWBZ3kO3P4PcitzCGSHWewWiejaeD38hKz28YyCLwG6b2MeSqjJPXnjNVSd/HRISuYoiiPBoSIYgXmx21r5MulAZvDcL8+5yVynS91c1jJnzTCJYi2nPWz3vZOvTWbg0mbULoDZC0hKjAzPk9ww5dXEBCwF9x06OLlbI+dWAipDGSbsaojgrxLwvmrBk6Msom9DDlzGNNe00LO+Koq1cG0w5t463q1ohG+h5Bg1SJrqfWtSWa50I69YFrXS/ncZPHLnTvHFPwA1f6J7iVv5QLgJynOu3B9H2t8DiiiUVbg1vaCNgRT0XHj4KLq8tP7NPTgM/qa1nCjj7Rkf1ZlBvtiGtmfsC0c3XFRRpR51Frr3cg3osFM2uSF3+UESpzljx6HMGtzerk8Y48JaSwZUYBwt1+Mo4pknfkFJs8ug6i5HXtBjpM4aKbMg+XTKg+u0xWunh5bsvHrk03XcGyCZKqLNUxRq1Fa2jl+Jn5bxZWWTE7wh3RS+5BdZbKCyD5y1j1jet/dedgmWi/yjvgRRIjqvVCcvVmzSockuj5/Yo30s/sAFz0MqlCzX25c 0cdSTwV4 +uGV5hdlE17iwAajaomuwvWWFtVX2jYXTFb1xAekW6ZPE270xwFa1oqLo310SlPEByvnZVNGVziefCnxBGMZe7fG12YNVaCgtGmUGsE2XF/TMyGEVVGfaC7Kkw2Cux/jxR0ySrbTxWMrwI+gx9S6F1y6mEd7zfaNa51S0a1oh0hAN0U+E5Mn9ex3FkLiJy4ffjHkD1pHlW/AAUBPoMuBHTs2PVbtw7ES9mBEqLxxTpwBviMS90+cNVQDH2f1w9x4AN7AcPmd9Nj8prLeNjlqkKjEXjUe24gr7d+dgYkQkkRnCQ9WJTwdN3fNJZskDzESMJ+S/Nrd0J9JMl6lGRy4R9TtRGn6vuLDCT3FUM13dGEUIer77LO8nEWS21HOX5FuFS++W3BBWoB8dsYenv2PPg/+vrS46EJN8yd+jyOd9RLZFwYbwYs2NDhzmHsWxBn3ueuQjEJ22+wjiwPGdFsvGGWF6Ci3Sieb+3vq8 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: With the new uffd unit test covering the /dev/userfaultfd path and syscall path of uffd initializations, we can safely drop the devnode test in the old stress test. One thing is to avoid duplication of running the stress test twice which is an overkill to only test the /dev/ interface in run_vmtests.sh. The other benefit is now all uffd tests (that uses userfaultfd_open) can run automatically as long as any type of interface is enabled (either syscall or dev), so it's more likely to succeed rather than fail due to unprivilege. With this patch lands, we can drop all the "mem_type:XXX" handlings too. Signed-off-by: Peter Xu --- tools/testing/selftests/mm/run_vmtests.sh | 15 +++++-------- tools/testing/selftests/mm/uffd-common.c | 7 ++---- tools/testing/selftests/mm/uffd-common.h | 2 +- tools/testing/selftests/mm/uffd-stress.c | 27 ++--------------------- 4 files changed, 11 insertions(+), 40 deletions(-) diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/selftests/mm/run_vmtests.sh index 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: 13194511 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C2D1C761A6 for ; Thu, 30 Mar 2023 16:08:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B379590000A; Thu, 30 Mar 2023 12:08:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AE6876B009F; Thu, 30 Mar 2023 12:08:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 986FF90000A; Thu, 30 Mar 2023 12:08:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 7FFA26B009E for ; Thu, 30 Mar 2023 12:08:49 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 408D4140340 for ; Thu, 30 Mar 2023 16:08:49 +0000 (UTC) X-FDA: 80626047978.22.3AE90FE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf13.hostedemail.com (Postfix) with ESMTP id 0E1B920019 for ; Thu, 30 Mar 2023 16:08:45 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="J1vMA/q4"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf13.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680192527; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=QgmTtu8OFjFdW8yq7WIzzTW/am1uahC9wawM1FIOBXg=; b=4yBYGA9j2euq8ZuJ1oSzMQoM6bsk0wAvJBxvHfWYjxQ6tErbWWAHzFICqc42psrmz/JFKu 7WAt7AFhB3RSCK/p65cxWI2TRQBqXmXPh2bkS/ltiJKtVA3k/p4vb1sgoQxOxk4r803G/W gChaXBq1A8WWWkyd95A17lFHbB9sXGM= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="J1vMA/q4"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf13.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680192527; a=rsa-sha256; cv=none; b=pg8lRpKk11bFrQSrksjgb7dsfHnifQnf9IiH72vkj0UReRigbmzS7ZP7Ym2UrYBifTo/7Q /OGuk1c/xF/A1M+0QpGxVFmUdESTR7dacUpYfN7vT1egMgttc/cB2dUqvdRelK9CL7EkPl Akc/7dELMcPYkuY7TM8iWDBFw83Y3pw= 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-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QgmTtu8OFjFdW8yq7WIzzTW/am1uahC9wawM1FIOBXg=; b=J1vMA/q4zDrPX3sUb4S8XvXbtYwpnOHWGtjN6hhYDmSZth0VUSduiNZmzruQVuLBQgqHDU WYZIerWvQW+k8/JoJJWjj+4wGttGNOVGx9f/W0qhd3oFiUsD2h4JlIsjCSsMaix3rEqZhA 5bYRyQGtTwq3SxQzQpxlYbFkpwoVclA= 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-632-4URUY3gWMMmJSzQwAZk1yw-1; Thu, 30 Mar 2023 12:08:44 -0400 X-MC-Unique: 4URUY3gWMMmJSzQwAZk1yw-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-5aae34d87f7so13017726d6.0 for ; Thu, 30 Mar 2023 09:08:42 -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=xwFQ81dgUeX1Fk8jJQ0j1kz9JRMO8PCpeTNfryQBytBKw4nz7O7ri4CZjkLEf5wzmT /3SZ4uvWTknl05DCAudU46W9Zf2mzJXslklSHd6ZxGWt2J7W7ODzkZ72TYe2WLwJNH3p 07rfVa6Mkhj9qyrrNcK3W2zzYto/c4VtuahA/DjpcsTWVIsHx2CB0jH/qhpqDh3PlImo niUWNpjTgSODZgyuKPO/bjUxJYS9KY3BmA7YPYWKSVJw6q8Fz9pmAL2VCuGhEOyrd4Rc i6ybnK73KV5BwDseK0aNSwU6i04ZF7XmcEAZrWdDCWoiWFjZ1UXP+NUkfbKvojykhsHk rzpg== X-Gm-Message-State: AAQBX9d8bTl18KaU7OkbgFxbRmv1mvNZQ0u4djMRqW1FKzektX9R8DbB 0hgAj4Hr+v3WlrYMXiaRvTEOlVL0y3PR39E4u+7/fxJLq+lCWi4/ha4unGpeiVQ20OLkX05UN8D NE1ZC+EYoN+4= X-Received: by 2002:a05:6214:3014:b0:5aa:14b8:e935 with SMTP id ke20-20020a056214301400b005aa14b8e935mr3723997qvb.2.1680192522426; Thu, 30 Mar 2023 09:08:42 -0700 (PDT) X-Google-Smtp-Source: AKy350YMKgyQGsiWXfxMgANl5DSoc8CnFLkGelQ0rF4PH3xD4dOO2E/F49CFek+tRBt85PQwpxWhkw== 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: 0E1B920019 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: uyt768e6dxx6ih4didn7hx5ox1xbsugq X-HE-Tag: 1680192525-998838 X-HE-Meta: U2FsdGVkX18m9RJ/WBGRIDK0NE/G4xLOOQc7h0F8jVDCBgnuznw3ejjPxan40WcwcPpafa9N3DIYVX2NeYLb1/lNoHqaZ6wlgSBxNbgkJgq+xFZjP8OgXfRtYj9yscTD99WUHgoVI/DsuD93gmaobvr5FBYpZl9vogzw9CHSjTr8RUWiEbNeiAPi6OeCL7jyKXTtJ8gGNfYuJKlT2dIo5qYYOXkJgbT/d2RtYPZrISZmaWNoUwjPZSpK8Wn0C+719vr3l+qdwozRNU2e0oNu4VzodLlvgpbqzPe6XI7FxySByv8ERRiFxPV74RJO75dg+rsUKi+VZU6TuuWlCyHP4qC1VvzX1/ZnbhsKndNQSFsUYjkdfU9WqjIVNLTzI4aMqjDPFtnQHqdPDz1z0xYfatJQ7nGeQ+iZoD6VuK0Jun44rrdni8LJGW6sv+MUp2y8j9YK0lvJTOLfbIzQJNcI7W2L8Kkx2UD6HjH9zy9s1QQZ1jpjQYmszJ5J6QNsEfLg2g3VQrARQC/yp81b895BY+XeOK4TJ5ezczgbhLEHcE14r/IL9ed1Du8eYeFbQZuAmZHYxAZOIZxss6SpUWdCPhu5fwcJKhnog8N+2fTgGIlNfM1tz006NiQ5eYfA9IlfAAPff3o1mHaM39JLi4z3gXL3xGC4HrOUd/umum1NKc0BNC4E3v6FW8fMZ/JVYypdmdViYZ7lSR+mFcXV7UA9r2MLsBk9AV8pExwfD2j18op2NdcydUVeIvFhPaMddaTnz98K1WPCeRocnmV52VzAr00G78injiRE3zU8QJmRohTXT8iQL9FrggtQVDpDM/B/JkCwg8IPHInv9U0ijx+vKx5pQIp0MysC511yMtmJ/KQPHGIUdgbuLOXooLjkQvLpfxcG/syA5F0otE+T9TL9Zc0mcKkdL9grViTsEqk/dG1bJfPRENi0PL9+5jshS5EhWeGvmNw1G6qhW9FQW0F BlxXzQDB Db5IEnbsDOQJb0/M02SAhmMQPKRJmLj02VZUby7WuiTU8mBMTx4lAZxDnJG/qiM2VFOuOWLxWSTmdaunUvRkrcm16ikpO8Y3Tk2ZlSoIiHeYgT9F0f8VVT8YrrziTj2Oi33ZgSEsmrkErltTPZjaF/sZ7651lZ+Wfv9AuMjmMFqgKoayyP28rUZoxTTKFCnRRFByx409olHbHI2Mw91DYvXT+laLt1GTJe/UBNZ6PfFITQXn763u44yqlHgCB1j9inOKbmJL2I03ZGdxUydOrnivfp5wxFbnXfKDV8MYNSnIn8/clKmGRg9ZhfI5NiGgOhH+MQg1fVPH7kp64nNAYYSkOBHWRWPf2GevpoxnS69Glk80JbZvQ+k+oRR5YBDghdm87h2iyolLeMp1sjX19d8zQZriMTJfep68GA8nw3PsvOkTUr6IB9GSvcchclGzIs9YdLtnuvbuMoW1ofUwhMtWiF4/c2CXPAKlu X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The userfaultfd stress test never tested private shmem, which I think was overlooked long due. Add it so it matches with uffd unit test and it'll cover all memory supported with the three memory types. Meanwhile, rename the memory types a bit. Considering shared mem is the major use case for both shmem / hugetlbfs, changing from: anon, hugetlb, hugetlb_shared, shmem To (with shmem-private added): anon, hugetlb, hugetlb-private, shmem, shmem-private Add the shmem-private to run_vmtests.sh too. Signed-off-by: Peter Xu --- tools/testing/selftests/mm/run_vmtests.sh | 3 ++- tools/testing/selftests/mm/uffd-stress.c | 11 +++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/selftests/mm/run_vmtests.sh index 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; } }