Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp389526rwd; Thu, 1 Jun 2023 01:28:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7SjntvX6GOaBONxqDmVoGgure1IkJ5mqnxT7+cfrt5HOjnsbZw4sgt2IIod/neCCqmuTM5 X-Received: by 2002:a05:6358:441d:b0:123:28ca:888d with SMTP id z29-20020a056358441d00b0012328ca888dmr2528819rwc.10.1685608101749; Thu, 01 Jun 2023 01:28:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685608101; cv=none; d=google.com; s=arc-20160816; b=u2DD+/iog3NHo3aR/v7rJSdqcfrPnRbS60XbpmBFLHysU8BznOiNRNtgcvzDW929mp PvAgq7v+Y16xPcRrRForTwGLffwQu8sJr4ds846iaLi1/FjnCg0m9cAt2+tzPLpeuqEl n1wl9p6boKZVUE4kWk9GFHLLNZBZjuzcPPgGUdbEXsgfiDJg0vLfRuzfU+DjR6ocGR+E XFdfbChEq5g3BsXLxxuqtOgwFdb/EldN+IkXpZo8gtJDdvLLBvT469nCFmmxAUoc9qh2 luTkoJMkmicmiwePUca7+bBfg1DrDTpZoKW7FrWOAS2AlhBC5+28QStgnfHY5bUh3yK8 i5ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:subject :organization:from:references:cc:to:content-language:user-agent :mime-version:date:message-id:dkim-signature; bh=wKmPbrFwESFZJl2H01/KcKj6DErTerOIUGeta+Cdp9Q=; b=dfwYnVkSIUGDiB6N+KptpHF+QviksntoDfjeYGW4Wci8okKzSAID+KqP6RaANQzpnJ F9sZVyFwXJviD4CPoj1HRkru6eIxalPuFSCrjyCmcfgaZTW8LOGrP146Zj4b16pt22R9 a6byH7mPHoh/UQlIcuUV6V0umG77O5I/DL2eaUZhHShEZHG8qKWMj3gkeIHaJE2O1gOT +22uG+YBDuABs1zK2pDv5H0HKwpylGRSQCb9XzITSnYdHf5i2+XTeRkFqnJpneiJFJpA VyGXvCex3TQbVa+Qd80r9zvzua0SngAyFWFxjrsoceF51fbtBJt8ZZOcEftB2hoHE/hv FVEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XkdvHPV7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r207-20020a632bd8000000b0053faf462e4dsi2474610pgr.500.2023.06.01.01.28.07; Thu, 01 Jun 2023 01:28:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XkdvHPV7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231761AbjFAIRi (ORCPT + 99 others); Thu, 1 Jun 2023 04:17:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231622AbjFAIRg (ORCPT ); Thu, 1 Jun 2023 04:17:36 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C027EE2 for ; Thu, 1 Jun 2023 01:16:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685607406; 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=wKmPbrFwESFZJl2H01/KcKj6DErTerOIUGeta+Cdp9Q=; b=XkdvHPV7VHERKN7F2igr0ACbR/e1rF9zs3rmgOw6ADwvwAWovuaO9axvKUi9EVR7fEeK2k Km0yCV95Sa6C4sf9SKV9FFa/fzHa0Q0o2r1vs21mFpIJ5i9EKOj9Rabl5zGEzeCzkXV9hS BzxL34A1RdAI0Bnbqlj9Cuq09uv1se8= Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com [209.85.167.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-349-vymh8J-iN4CFPJdve2MmcA-1; Thu, 01 Jun 2023 04:16:44 -0400 X-MC-Unique: vymh8J-iN4CFPJdve2MmcA-1 Received: by mail-lf1-f70.google.com with SMTP id 2adb3069b0e04-4edc7406cbaso349849e87.2 for ; Thu, 01 Jun 2023 01:16:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685607403; x=1688199403; h=content-transfer-encoding:in-reply-to:subject:organization:from :references:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=wKmPbrFwESFZJl2H01/KcKj6DErTerOIUGeta+Cdp9Q=; b=QZzi8P3CpAKv8Zai3PKuq2ydVrwM19/05ZL5fFjr8ulDuUPwj+nApq0wRtylAErZ3U bXmpKWLhrLQRvSPPSLkzZ9mp0pln8noCS5N6A21F6JTBI+A+ysDjgFDUT4EQ1NkfMKXF 5/DsLgOLyvUAUGtSpYnZSH5+oJQkr5s4QYKYPRO56Pw3aewXRVbjJk88tOPnPVXL0fbx U2vayWu1TziRuxsagcrlFg1AxEhTJeBoFI3Jlvy6+8NiS98m5buh3ugY46XZ7e0dKzwE weFot9oT7lfOhhalrivBQ96QfnsSahTgkp1jFfPx4zCKUUDPpN62Nmljq1VeF7/SeRbQ iQNA== X-Gm-Message-State: AC+VfDwKtMiYvDOemq9KyCSoP0lLBOq0E10R9cxgdeWq7SLVij1D3xZS FSeFl+ZSN0d9I/wFXtPU4Hsxaanz/X7xl0ENQE6Rur4fKELZb0yusWb+XZ2SzoTyrE0ifDqLPle ejVa733YZmrK/URBcbMMbUL9l X-Received: by 2002:ac2:4149:0:b0:4f3:7c24:1029 with SMTP id c9-20020ac24149000000b004f37c241029mr741606lfi.60.1685607403369; Thu, 01 Jun 2023 01:16:43 -0700 (PDT) X-Received: by 2002:ac2:4149:0:b0:4f3:7c24:1029 with SMTP id c9-20020ac24149000000b004f37c241029mr741593lfi.60.1685607402876; Thu, 01 Jun 2023 01:16:42 -0700 (PDT) Received: from ?IPV6:2a09:80c0:192:0:5dac:bf3d:c41:c3e7? ([2a09:80c0:192:0:5dac:bf3d:c41:c3e7]) by smtp.gmail.com with ESMTPSA id z16-20020a7bc7d0000000b003f605814850sm1388319wmk.37.2023.06.01.01.16.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 01 Jun 2023 01:16:42 -0700 (PDT) Message-ID: Date: Thu, 1 Jun 2023 10:16:41 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Content-Language: en-US To: Lorenzo Stoakes Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, Andrew Morton , Shuah Khan , Jens Axboe , Peter Xu , Jason Gunthorpe , John Hubbard , Jan Kara References: <20230519102723.185721-1-david@redhat.com> <20230519102723.185721-3-david@redhat.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v1 2/3] selftests/mm: gup_longterm: new functional test for FOLL_LONGTERM In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 28.05.23 17:03, Lorenzo Stoakes wrote: > On Fri, May 19, 2023 at 12:27:22PM +0200, David Hildenbrand wrote: >> Let's add a new test for checking whether GUP long-term page pinning >> works as expected (R/O vs. R/W, MAP_PRIVATE vs. MAP_SHARED, GUP vs. >> GUP-fast). Note that COW handling with long-term R/O pinning in private >> mappings, and pinning of anonymous memory in general, is tested by the >> COW selftest. This test, therefore, focuses on page pinning in >> file mappings. >> >> The most interesting case is probably the "local tmpfile" case, as that >> will likely end up on a "real" filesystem such as ext4 or xfs, not on a >> virtual one like tmpfs or hugetlb where any long-term page pinning is >> always expected to succeed. >> >> For now, only add tests that use the "/sys/kernel/debug/gup_test" >> interface. We'll add tests based on liburing separately next. >> >> Signed-off-by: David Hildenbrand >> --- [...] >> +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; >> + int ret; >> + >> + if (ftruncate(fd, size)) { >> + ksft_test_result_fail("ftruncate() failed\n"); >> + return; >> + } >> + >> + if (fallocate(fd, 0, 0, size)) { >> + if (size == pagesize) >> + ksft_test_result_fail("fallocate() failed\n"); >> + else >> + ksft_test_result_skip("need more free huge pages\n"); >> + return; >> + } >> + >> + mem = mmap(NULL, size, PROT_READ | PROT_WRITE, >> + shared ? MAP_SHARED : MAP_PRIVATE, fd, 0); >> + if (mem == MAP_FAILED) { >> + if (size == pagesize || shared) >> + ksft_test_result_fail("mmap() failed\n"); >> + else >> + ksft_test_result_skip("need more free huge pages\n"); >> + return; >> + } >> + >> + /* >> + * Fault in the page writable such that GUP-fast can eventually pin >> + * it immediately. >> + */ >> + memset(mem, 0, size); > For shared mappings, MAP_POPULATE will not fault-in the pages writable. See mm/gup.c:populate_vma_page_range(). [There is also the case that mmap() doesn't fail if populate fails, but that's only a side note regarding weird semantics of MAP_POPULATE] [...] >> + int flags = MFD_HUGETLB; >> + int fd; >> + >> + ksft_print_msg("[RUN] %s ... with memfd hugetlb (%zu kB)\n", desc, >> + hugetlbsize / 1024); >> + >> + flags |= __builtin_ctzll(hugetlbsize) << MFD_HUGE_SHIFT; > > Hm this feels a little cute :) It's a weird interfacing, having to specify the desired size via flags ... see the man page of memfd_create, which links to the man page of mmap: "the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset MAP_HUGE_SHIFT". FWIW, we're using the same approach in cow.c already [and other memfd users like QEMU do it just like that, using ctz]. [...] >> diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/selftests/mm/run_vmtests.sh >> index 4893eb60d96d..b6b1eb6a8a6b 100644 >> --- a/tools/testing/selftests/mm/run_vmtests.sh >> +++ b/tools/testing/selftests/mm/run_vmtests.sh >> @@ -24,7 +24,7 @@ separated by spaces: >> - mmap >> tests for mmap(2) >> - gup_test >> - tests for gup using gup_test interface >> + tests for gup > > Super nitty again, but I'm guessing this means the CONFIG_GUP_TEST > interface, perhaps worth keeping? With this patch, agreed. But not longer with the next patch -- guess I simplified when splitting it up. If there are no strong feelings I'll leave it in this patch. [...] >> > > OK this patch is really nice + well implemented, I can only point out a > couple EXTREMELY nitty comments :) Thanks very much for adding a test for > this, it's super useful! > > Therefore, > > Reviewed-by: Lorenzo Stoakes > Thanks for the review! My selftest patches rarely get that much attention, so highly appreciated :) -- Thanks, David / dhildenb