From patchwork Sun Apr 28 19:01:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1928679 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=B82VAc50; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=B82VAc50; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VSG8M3Shsz23ny for ; Mon, 29 Apr 2024 05:03:47 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=B82VAc50; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=B82VAc50; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VSG8M0JgDz3cWp for ; Mon, 29 Apr 2024 05:03:47 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=B82VAc50; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=B82VAc50; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=redhat.com (client-ip=170.10.129.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=peterx@redhat.com; receiver=lists.ozlabs.org) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4VSG6N56sKz3btX for ; Mon, 29 Apr 2024 05:02:03 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714330918; 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=1t4UcvVVCt+Lz5av6btBnWLmCHNkWkDBAkPZW0Lpq7g=; b=B82VAc5093u7dHlEp2LqIeli5wsF6qqmCMtFU8V+ZG2oe0pCxFjJSqL4sw3nMhQVuDF1gx 7XBSBpdixQ5DtEvm3QwB/lyp7kYin8SC2td1kKYNIFrqVxUL+bwDjdWPgOZqIlUUdXbSin mgfmA6bMiHgn8aEE5TzltVdcuuuaDUE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714330918; 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=1t4UcvVVCt+Lz5av6btBnWLmCHNkWkDBAkPZW0Lpq7g=; b=B82VAc5093u7dHlEp2LqIeli5wsF6qqmCMtFU8V+ZG2oe0pCxFjJSqL4sw3nMhQVuDF1gx 7XBSBpdixQ5DtEvm3QwB/lyp7kYin8SC2td1kKYNIFrqVxUL+bwDjdWPgOZqIlUUdXbSin mgfmA6bMiHgn8aEE5TzltVdcuuuaDUE= 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-171-KqDlQBnvO3-QAQL8iqVd_A-1; Sun, 28 Apr 2024 15:01:56 -0400 X-MC-Unique: KqDlQBnvO3-QAQL8iqVd_A-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-790f387bd46so248485a.2 for ; Sun, 28 Apr 2024 12:01:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714330915; x=1714935715; 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=1t4UcvVVCt+Lz5av6btBnWLmCHNkWkDBAkPZW0Lpq7g=; b=KvkNlecyih9YaCX/jwUpBh5hsjkniBnBpAUyTni4YA72nOnx2pDC/FVYvOG4QO087e WsZLycs5ztBnBN21ppDYzjz15ieXOyWqOelrAOXDDDLnoa2LrLy/RUwugmkFpSoc5+Iw TfJfTY5bUJ3bCcd2Yb0eZ5+gzRX39RH4yb9jstNLoIIQZcwtkTAWrU1Uv8HUs1XrZSYz yopl3ITcxMh3DIJ3uyNbMYZpBu+Q/jFQMUmcK0AUTt0m1qW28sT2Gj34Ljn7tVlzQXcs 564tzRFr+QRR08HisLuV7hGytdQ6SGlgPiJkM8KZEJwAXXtsB6q0cJ1PWuCOqc7cFuJJ rkNw== X-Forwarded-Encrypted: i=1; AJvYcCUTxQdT6gQoL1X1X76dMBVsNGEzeJJjhenCdNeUid79G9Vvv9pdQqG0LgvLHJDc7EnwvqNIs2gTB6zL39lwIVT3SxOTX0WGCuUJ/7+FDg== X-Gm-Message-State: AOJu0YydRzMF2XjjhkN7yPYxCsyB4q8joTrDxt73E1UnnN3dkmLvd+05 47wb5J6fUpa2fTpbeMt0M5PthFP05RIBlEpxYDR1BEq50x+Ck4ozfLjjxqVxPD2daPuwtTegBFK gEbeAG+h5AueDR4rh6gJAiMf3AFOi6KiM8M8q6dxcydLDo2L3xIxD3L7B/gBIbAA= X-Received: by 2002:a05:620a:17a0:b0:790:e83a:e6eb with SMTP id ay32-20020a05620a17a000b00790e83ae6ebmr4022691qkb.5.1714330915149; Sun, 28 Apr 2024 12:01:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEq4u33yQLthyJZ4VKOCA3UIJSHLI7n1RNa/Jea7Dll1CjPi5vBpPXi0aewsChF2WFetPSb5Q== X-Received: by 2002:a05:620a:17a0:b0:790:e83a:e6eb with SMTP id ay32-20020a05620a17a000b00790e83ae6ebmr4022657qkb.5.1714330914396; Sun, 28 Apr 2024 12:01:54 -0700 (PDT) Received: from x1n.redhat.com (pool-99-254-121-117.cpe.net.cable.rogers.com. [99.254.121.117]) by smtp.gmail.com with ESMTPSA id oo8-20020a05620a530800b0078d693c0b4bsm9818152qkn.135.2024.04.28.12.01.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Apr 2024 12:01:53 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 1/2] mm/gup: Fix hugepd handling in hugetlb rework Date: Sun, 28 Apr 2024 15:01:50 -0400 Message-ID: <20240428190151.201002-2-peterx@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240428190151.201002-1-peterx@redhat.com> References: <20240428190151.201002-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lorenzo Stoakes , David Hildenbrand , John Hubbard , Muchun Song , peterx@redhat.com, "Aneesh Kumar K . V" , Jason Gunthorpe , Andrew Morton , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Commit a12083d721d7 added hugepd handling for gup-slow, reusing gup-fast functions. follow_hugepd() correctly took the vma pointer in, however didn't pass it over into the lower functions, which was overlooked. The issue is gup_fast_hugepte() uses the vma pointer to make the correct decision on whether an unshare is needed for a FOLL_PIN|FOLL_LONGTERM. Now without vma ponter it will constantly return "true" (needs an unshare) for a page cache, even though in the SHARED case it will be wrong to unshare. The other problem is, even if an unshare is needed, it now returns 0 rather than -EMLINK, which will not trigger a follow up FAULT_FLAG_UNSHARE fault. That will need to be fixed too when the unshare is wanted. gup_longterm test didn't expose this issue in the past because it didn't yet test R/O unshare in this case, another separate patch will enable that in future tests. Fix it by passing vma correctly to the bottom, rename gup_fast_hugepte() back to gup_hugepte() as it is shared between the fast/slow paths, and also allow -EMLINK to be returned properly by gup_hugepte() even though gup-fast will take it the same as zero. Reported-by: David Hildenbrand Fixes: a12083d721d7 ("mm/gup: handle hugepd for follow_page()") Signed-off-by: Peter Xu Reviewed-by: David Hildenbrand --- Note: The target commit to be fixed should just been moved into mm-stable, so no need to cc stable. --- mm/gup.c | 64 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 2f7baf96f655..ca0f5cedce9b 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -525,9 +525,17 @@ static unsigned long hugepte_addr_end(unsigned long addr, unsigned long end, return (__boundary - 1 < end - 1) ? __boundary : end; } -static int gup_fast_hugepte(pte_t *ptep, unsigned long sz, unsigned long addr, - unsigned long end, unsigned int flags, struct page **pages, - int *nr) +/* + * Returns 1 if succeeded, 0 if failed, -EMLINK if unshare needed. + * + * NOTE: for the same entry, gup-fast and gup-slow can return different + * results (0 v.s. -EMLINK) depending on whether vma is available. This is + * the expected behavior, where we simply want gup-fast to fallback to + * gup-slow to take the vma reference first. + */ +static int gup_hugepte(struct vm_area_struct *vma, pte_t *ptep, unsigned long sz, + unsigned long addr, unsigned long end, unsigned int flags, + struct page **pages, int *nr) { unsigned long pte_end; struct page *page; @@ -559,9 +567,9 @@ static int gup_fast_hugepte(pte_t *ptep, unsigned long sz, unsigned long addr, return 0; } - if (!pte_write(pte) && gup_must_unshare(NULL, flags, &folio->page)) { + if (!pte_write(pte) && gup_must_unshare(vma, flags, &folio->page)) { gup_put_folio(folio, refs, flags); - return 0; + return -EMLINK; } *nr += refs; @@ -577,19 +585,22 @@ static int gup_fast_hugepte(pte_t *ptep, unsigned long sz, unsigned long addr, * of the other folios. See writable_file_mapping_allowed() and * gup_fast_folio_allowed() for more information. */ -static int gup_fast_hugepd(hugepd_t hugepd, unsigned long addr, - unsigned int pdshift, unsigned long end, unsigned int flags, - struct page **pages, int *nr) +static int gup_hugepd(struct vm_area_struct *vma, hugepd_t hugepd, + unsigned long addr, unsigned int pdshift, + unsigned long end, unsigned int flags, + struct page **pages, int *nr) { pte_t *ptep; unsigned long sz = 1UL << hugepd_shift(hugepd); unsigned long next; + int ret; ptep = hugepte_offset(hugepd, addr, pdshift); do { next = hugepte_addr_end(addr, end, sz); - if (!gup_fast_hugepte(ptep, sz, addr, end, flags, pages, nr)) - return 0; + ret = gup_hugepte(vma, ptep, sz, addr, end, flags, pages, nr); + if (ret != 1) + return ret; } while (ptep++, addr = next, addr != end); return 1; @@ -613,22 +624,25 @@ static struct page *follow_hugepd(struct vm_area_struct *vma, hugepd_t hugepd, h = hstate_vma(vma); ptep = hugepte_offset(hugepd, addr, pdshift); ptl = huge_pte_lock(h, vma->vm_mm, ptep); - ret = gup_fast_hugepd(hugepd, addr, pdshift, addr + PAGE_SIZE, - flags, &page, &nr); + ret = gup_hugepd(vma, hugepd, addr, pdshift, addr + PAGE_SIZE, + flags, &page, &nr); spin_unlock(ptl); - if (ret) { + if (ret == 1) { + /* GUP succeeded */ WARN_ON_ONCE(nr != 1); ctx->page_mask = (1U << huge_page_order(h)) - 1; return page; } - return NULL; + /* ret can be either 0 (translates to NULL) or negative */ + return ERR_PTR(ret); } #else /* CONFIG_ARCH_HAS_HUGEPD */ -static inline int gup_fast_hugepd(hugepd_t hugepd, unsigned long addr, - unsigned int pdshift, unsigned long end, unsigned int flags, - struct page **pages, int *nr) +static inline int gup_hugepd(struct vm_area_struct *vma, hugepd_t hugepd, + unsigned long addr, unsigned int pdshift, + unsigned long end, unsigned int flags, + struct page **pages, int *nr) { return 0; } @@ -3261,8 +3275,8 @@ static int gup_fast_pmd_range(pud_t *pudp, pud_t pud, unsigned long addr, * architecture have different format for hugetlbfs * pmd format and THP pmd format */ - if (!gup_fast_hugepd(__hugepd(pmd_val(pmd)), addr, - PMD_SHIFT, next, flags, pages, nr)) + if (gup_hugepd(NULL, __hugepd(pmd_val(pmd)), addr, + PMD_SHIFT, next, flags, pages, nr) != 1) return 0; } else if (!gup_fast_pte_range(pmd, pmdp, addr, next, flags, pages, nr)) @@ -3291,8 +3305,8 @@ static int gup_fast_pud_range(p4d_t *p4dp, p4d_t p4d, unsigned long addr, pages, nr)) return 0; } else if (unlikely(is_hugepd(__hugepd(pud_val(pud))))) { - if (!gup_fast_hugepd(__hugepd(pud_val(pud)), addr, - PUD_SHIFT, next, flags, pages, nr)) + if (gup_hugepd(NULL, __hugepd(pud_val(pud)), addr, + PUD_SHIFT, next, flags, pages, nr) != 1) return 0; } else if (!gup_fast_pmd_range(pudp, pud, addr, next, flags, pages, nr)) @@ -3318,8 +3332,8 @@ static int gup_fast_p4d_range(pgd_t *pgdp, pgd_t pgd, unsigned long addr, return 0; BUILD_BUG_ON(p4d_leaf(p4d)); if (unlikely(is_hugepd(__hugepd(p4d_val(p4d))))) { - if (!gup_fast_hugepd(__hugepd(p4d_val(p4d)), addr, - P4D_SHIFT, next, flags, pages, nr)) + if (gup_hugepd(NULL, __hugepd(p4d_val(p4d)), addr, + P4D_SHIFT, next, flags, pages, nr) != 1) return 0; } else if (!gup_fast_pud_range(p4dp, p4d, addr, next, flags, pages, nr)) @@ -3347,8 +3361,8 @@ static void gup_fast_pgd_range(unsigned long addr, unsigned long end, pages, nr)) return; } else if (unlikely(is_hugepd(__hugepd(pgd_val(pgd))))) { - if (!gup_fast_hugepd(__hugepd(pgd_val(pgd)), addr, - PGDIR_SHIFT, next, flags, pages, nr)) + if (gup_hugepd(NULL, __hugepd(pgd_val(pgd)), addr, + PGDIR_SHIFT, next, flags, pages, nr) != 1) return; } else if (!gup_fast_p4d_range(pgdp, pgd, addr, next, flags, pages, nr)) From patchwork Sun Apr 28 19:01:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1928677 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Axk6keNv; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=L9SqdAw5; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VSG6q4v5Yz23ny for ; Mon, 29 Apr 2024 05:02:26 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Axk6keNv; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=L9SqdAw5; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VSG6m6PZmz3cNQ for ; Mon, 29 Apr 2024 05:02:24 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Axk6keNv; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=L9SqdAw5; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=redhat.com (client-ip=170.10.129.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=peterx@redhat.com; receiver=lists.ozlabs.org) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4VSG6N4PD9z30gK for ; Mon, 29 Apr 2024 05:02:03 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714330918; 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=TChkYNJLokf0R7TU3fj1Jd4fvD6sn29Wrs03bf1LQhQ=; b=Axk6keNvXKEbIba4UfZYVs0EImo7LuSWyQJok2oAAnhJA5JZTgj4Cm5/YDlwOAXvhp72uJ VjYgsQ5cthy7flGvlgpj8GF9T9JGrtNRYRnjA23w+kbdnwX3tvVP4OmiPwAGozauF4tcHW nMyKjz0MkkS330rRfiAs3oIJ4JpkIYQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714330919; 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=TChkYNJLokf0R7TU3fj1Jd4fvD6sn29Wrs03bf1LQhQ=; b=L9SqdAw5Jp6lX2qgXB3sIjYo7KK/AviG2+8F9ZhhT7gWOdnLqZ9l52rNlZs8198QocXf1n EZ5sTe7dOhjQxlB7AclvAHmy3mw9jhqJM0dtPNYWvXUVub+gjgEjpYC1wxQYgIoAV5AfM5 CAgOwlca02EWQbPUcNkBjjVbsB6GDLo= Received: from mail-oo1-f70.google.com (mail-oo1-f70.google.com [209.85.161.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-539-95DZ5fYmOQu6o6Q8bIkMug-1; Sun, 28 Apr 2024 15:01:57 -0400 X-MC-Unique: 95DZ5fYmOQu6o6Q8bIkMug-1 Received: by mail-oo1-f70.google.com with SMTP id 006d021491bc7-5af985fcdadso684596eaf.3 for ; Sun, 28 Apr 2024 12:01:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714330916; x=1714935716; 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=TChkYNJLokf0R7TU3fj1Jd4fvD6sn29Wrs03bf1LQhQ=; b=BQd7rm+TIl37prJ//JY2V1azGNxleo8d+NdrMOv2ttz6xxFUIeob6FxbKVMeVWAd5Y WC0yYbv2Px8R1e8nto7gqiqi8Q+FgWWyejqLtUhYakx+Vp1bHgu9sVOy9Umenf+efNzj uaReiutUOQbfBzwCZS6aGO/JUMNeluoqbeG8DTtiX4o6VrluHYOLokyPNHkwaLHRsRM7 w/JVT516VCtnGwn5I3gNxDeyai/DRj8aDqaJfqcBam6G3E3u1DDaFhovVAPFIvf/FIpd S8werF4AIwTXb32Jm/c/2j1SC1KslsHHg7Lv4val1TLDxha3qzSn/WmBNgpaMWMrKCyh uTKQ== X-Forwarded-Encrypted: i=1; AJvYcCVUQ/5+LS2RJ/DIRYN7mEdMRGrGJ7TXQkQaJpB1BfjuytIz/bk/rR+HGPX+E12Pv5lI1XJh+OwA+RDgzEwwXnSkIdv8PC9Z1VvJDsOnLA== X-Gm-Message-State: AOJu0Yw25jt95eDEX4jJKpNDfFa4eQs92CJRVtW8yJgQUcX5UtnfojwJ eBPlx/pXxRPwmM6H8kCDczhJZZ6Tz0Uqb7zKOnWbYnYTSKNkApioaXjL+J4ZJtlICthPLAkzBY3 i57s8GB9mxUmLCMy6dloExNnLcSncBZEVuJwbcbom+TLoqB7Y97DTGAon/GmdQVw= X-Received: by 2002:a05:6830:7193:b0:6ed:ffd4:f871 with SMTP id el19-20020a056830719300b006edffd4f871mr5375195otb.0.1714330916162; Sun, 28 Apr 2024 12:01:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGbfCPhcOZyAaf7bBZJaTYiO0a8lHR2gVf15VHmfKPjl2t1+bRyODyi0XieC0TmXGWNmTdCnA== X-Received: by 2002:a05:6830:7193:b0:6ed:ffd4:f871 with SMTP id el19-20020a056830719300b006edffd4f871mr5375155otb.0.1714330915677; Sun, 28 Apr 2024 12:01:55 -0700 (PDT) Received: from x1n.redhat.com (pool-99-254-121-117.cpe.net.cable.rogers.com. [99.254.121.117]) by smtp.gmail.com with ESMTPSA id oo8-20020a05620a530800b0078d693c0b4bsm9818152qkn.135.2024.04.28.12.01.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Apr 2024 12:01:55 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 2/2] mm/selftests: Don't prefault in gup_longterm tests Date: Sun, 28 Apr 2024 15:01:51 -0400 Message-ID: <20240428190151.201002-3-peterx@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240428190151.201002-1-peterx@redhat.com> References: <20240428190151.201002-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lorenzo Stoakes , David Hildenbrand , John Hubbard , Muchun Song , peterx@redhat.com, "Aneesh Kumar K . V" , Jason Gunthorpe , Andrew Morton , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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. */ - memset(mem, 0, size); switch (type) { case TEST_TYPE_RO: