From mboxrd@z Thu Jan 1 00:00:00 1970 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 4BAFDC4345F for ; Mon, 29 Apr 2024 13:10:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B71D86B009A; Mon, 29 Apr 2024 09:10:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B21FA6B009B; Mon, 29 Apr 2024 09:10:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9C2D16B009D; Mon, 29 Apr 2024 09:10:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 803E66B009A for ; Mon, 29 Apr 2024 09:10:25 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 32E1940E69 for ; Mon, 29 Apr 2024 13:10:25 +0000 (UTC) X-FDA: 82062603210.19.E6AA6DF 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 1FA264002E for ; Mon, 29 Apr 2024 13:10:22 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TvGE4COR; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf04.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=1714396223; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=FkfFCXYv9UcZuwlRLfrkkATbPa3Z5klq1PrYHXMu/1k=; b=ygDwtCzoDvuOYqYiRKP/9eNpRJtRro75M+GT6euuE+Aids0OvRHV/PAGmJW913XxSYIz/F +Hne9RFxRIi3HfzXSTjVghD/6WP3SuKE+LTPaAewfQJWTcGxXWEGgYj0zYUvUNwHdEVeN9 fxtPUr1C+JEFtiio9lU/76YF9Mhu7nc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714396223; a=rsa-sha256; cv=none; b=l+VjLfQUcOcW+w0VUQyMPDpgnaU/3lbC8xGoyn/wTfQJlv6K5wKQZFedj/+B1kaywiQwYw VwEqT53992JlGhTRUxey/qG0qS1emsvCLQIk6JwIC6dE8Fr1uWkj0PAUL0hjunXXTm7Qfw zWzYC7ujhSWfJrMZ2GFbfQ1w2+naLk4= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TvGE4COR; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf04.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714396222; 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: in-reply-to:in-reply-to:references:references; bh=FkfFCXYv9UcZuwlRLfrkkATbPa3Z5klq1PrYHXMu/1k=; b=TvGE4CORp8tFECPgybRImlbpxYB/Gp5C7qwntzxmJt44McLk7Mc8pWZynXmLdIbI2Njpw8 rFgV2geW8sfnQBwN51U07GXCrOMAtX9tDazaj+jCwUe+kMkVs/PWRQoSFzMx3Q5mGb3dUB 9T5Ye/kn5SyIYAWU+WzMDoCEfZVmrIo= 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-358-O6yUIT_PNUeqngRopCEebg-1; Mon, 29 Apr 2024 09:10:20 -0400 X-MC-Unique: O6yUIT_PNUeqngRopCEebg-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-6a0bab193c1so241276d6.3 for ; Mon, 29 Apr 2024 06:10:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714396220; x=1715001020; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=FkfFCXYv9UcZuwlRLfrkkATbPa3Z5klq1PrYHXMu/1k=; b=wSnRYIqqs1AVMKR+wL8ZMF3CrhL2Wqk6vwYx1+LYD+U1pb1FAycAPrfQL6PzAIdQGy 9r770yyzA5c0bz5xP/FblBJ+fFBJMvH8Z2b5UXoK3Jd1LebZontrlEdJUBqCXN98c/JE RGdgCI9EQuIvtF80IWvKglFvApVxJwN6vDGN2mrag0WBBGfslTDwu9XEGj/CnhDEXzbe Tve9pl35xd7GUo+HOg2OCBSQPrKvRTRVw4xQiS7MQyRnMmLB1AJ+NbW4pG3jgvuWjZZf nm+PSlmz5CIgHdg8ymIJEY0mrpt7h20uBhDEmqMraOJRVqHSoey0e+A9vpk5ekTu2CxO 8dxg== X-Forwarded-Encrypted: i=1; AJvYcCVbUekV3kgCJe9ZWWnf+QW7PnuXrOd1SPzThVjlDHOr4q2u1mjaxCjTd4MBNkdX2rzOXKQYn4UIfWfiYPEHnocSPe0= X-Gm-Message-State: AOJu0YznJ9lUZE/yRa8WNoLOQgWxZTBAoogrFmLRo36hTwI2csPcdvyf G+AnFAFhElYKSnj1iSPlFgg0Ve69ju2KW9OxElQ1PQgp6kD6OTlF7TCQHxmk72jozXoQUuS/U4N PYiVNoR8uhkjqDEI8Mjqkmf6Xr1dBDU+yCqpxodkJrSq0FhG2 X-Received: by 2002:a05:6214:d08:b0:69b:7d34:9f6 with SMTP id 8-20020a0562140d0800b0069b7d3409f6mr11995224qvh.5.1714396219876; Mon, 29 Apr 2024 06:10:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF3QEggTWhye5fJGV3QCGhFkQqVWr8moqX+4hjr2aO72fCK+ZED3EYpcL7QxN7jCYiTunNTIg== X-Received: by 2002:a05:6214:d08:b0:69b:7d34:9f6 with SMTP id 8-20020a0562140d0800b0069b7d3409f6mr11995189qvh.5.1714396219169; Mon, 29 Apr 2024 06:10:19 -0700 (PDT) Received: from x1n (pool-99-254-121-117.cpe.net.cable.rogers.com. [99.254.121.117]) by smtp.gmail.com with ESMTPSA id g6-20020a0cf846000000b0069b7edb9665sm1896238qvo.19.2024.04.29.06.10.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 06:10:18 -0700 (PDT) Date: Mon, 29 Apr 2024 09:10:16 -0400 From: Peter Xu To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christophe Leroy , Andrew Morton , "Aneesh Kumar K . V" , Lorenzo Stoakes , John Hubbard , linuxppc-dev@lists.ozlabs.org, Muchun Song , Jason Gunthorpe Subject: Re: [PATCH 2/2] mm/selftests: Don't prefault in gup_longterm tests Message-ID: References: <20240428190151.201002-1-peterx@redhat.com> <20240428190151.201002-3-peterx@redhat.com> <4171dbb6-81c0-4553-a405-a55f75be4cb7@redhat.com> MIME-Version: 1.0 In-Reply-To: <4171dbb6-81c0-4553-a405-a55f75be4cb7@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Rspamd-Queue-Id: 1FA264002E X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: xfohdrqethk58cbkmoqb7g47tsaho5mg X-HE-Tag: 1714396222-727540 X-HE-Meta: U2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PAHcrqtymPJmUfZGwIX8OSjKwXxDlE1gBypN4Kz2yA7FLSr+GMaSNuAfpkHnji7G6ta4r41Xa5GtZbyZyf5FTvqltgzSwyznUHkWEhyS0HBsOiuOxK5eGpArEYNu3vrlFY2JMEsCFxgxpDpKClQtP5qeqmhbdnnTtYhGMF17IJ4xsBjfnLC/NPGqTF3TgBkZwrDO3whbYzwvDYrhX2w3xerJxGRn1R7Yi9fqAlyD8v1WLt6XZY7O3yfSfD8ag0hi4YQOaZiIkW92J+kj1kSr7qPH/mRdG6JQnmJz5I44pQVwNLb/pYA37YA35az1zca6hCqwdVXUd2bbDsAvBeQ2j0Gm3F05THmdaQSdGvUIQ1Rmavi6wkLkGI9qCXtBubX9ZIUFDV/GnecLSNczUVamBxpnWPvt//cbd88MIsiP2wBeK0= 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: List-Subscribe: List-Unsubscribe: On Mon, Apr 29, 2024 at 09:28:15AM +0200, David Hildenbrand wrote: > On 28.04.24 21:01, Peter Xu wrote: > > Prefault, especially with RW, makes the GUP test too easy, and may not yet > > reach the core of the test. > > > > For example, R/O longterm pins will just hit, pte_write()==true for > > whatever cases, the unsharing logic won't be ever tested. > > > > This patch remove the prefault. This tortures more code paths at least to > > cover the unshare care for R/O longterm pins, in which case the first R/O > > GUP attempt will fault in the page R/O first, then the 2nd will go through > > the unshare path, checking whether an unshare is needed. > > > > Cc: David Hildenbrand > > Signed-off-by: Peter Xu > > --- > > tools/testing/selftests/mm/gup_longterm.c | 12 +++++++++--- > > 1 file changed, 9 insertions(+), 3 deletions(-) > > > > diff --git a/tools/testing/selftests/mm/gup_longterm.c b/tools/testing/selftests/mm/gup_longterm.c > > index ad168d35b23b..488e32186246 100644 > > --- a/tools/testing/selftests/mm/gup_longterm.c > > +++ b/tools/testing/selftests/mm/gup_longterm.c > > @@ -119,10 +119,16 @@ static void do_test(int fd, size_t size, enum test_type type, bool shared) > > } > > /* > > - * Fault in the page writable such that GUP-fast can eventually pin > > - * it immediately. > > + * Explicitly avoid pre-faulting in the page, this can help testing > > + * more code paths. > > + * > > + * Take example of an upcoming R/O pin test, if we RW prefault the > > + * page, such pin will directly skip R/O unsharing and the longterm > > + * pin will success mostly always. When not prefaulted, R/O > > + * longterm pin will first fault in a RO page, then the 2nd round > > + * it'll go via the unshare check. Otherwise those paths aren't > > + * covered. > > */ > This will mean that GUP-fast never succeeds, which removes quite some testing > coverage for most other tests here. > > Note that the main motivation of this test was to test gup_fast_folio_allowed(), > where we had issues with GUP-fast during development. Ah I didn't notice that, as I thought that whitelists memfd ones. > > Would the following also get the job done? > > diff --git a/tools/testing/selftests/mm/gup_longterm.c b/tools/testing/selftests/mm/gup_longterm.c > index ad168d35b23b7..e917a7c58d571 100644 > --- a/tools/testing/selftests/mm/gup_longterm.c > +++ b/tools/testing/selftests/mm/gup_longterm.c > @@ -92,7 +92,7 @@ static void do_test(int fd, size_t size, enum test_type type, bool shared) > { > __fsword_t fs_type = get_fs_type(fd); > bool should_work; > - char *mem; > + char tmp, *mem; > int ret; > if (ftruncate(fd, size)) { > @@ -119,10 +119,19 @@ static void do_test(int fd, size_t size, enum test_type type, bool shared) > } > /* > - * Fault in the page writable such that GUP-fast can eventually pin > - * it immediately. > + * Fault in the page such that GUP-fast might be able to pin it > + * immediately. To cover more cases, don't fault in pages writable when > + * R/O pinning. > */ > - memset(mem, 0, size); > + switch (type) { > + case TEST_TYPE_RO: > + case TEST_TYPE_RO_FAST: > + tmp = *mem; > + asm volatile("" : "+r" (tmp)); > + break; > + default: > + memset(mem, 0, size); > + }; > switch (type) { > case TEST_TYPE_RO: Yes this could work too. The test patch here doesn't need to rush. David, how about you prepare a better and verified patch and post it separately, making sure to cover all the things we used to cover plus the unshare? IIUC it used to be not touched because of pte_write() always returns true with a write prefault. Then we let patch 1 go through first, and drop this one? Thanks, -- Peter Xu