From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 419E02641C6 for ; Thu, 16 Oct 2025 19:13:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760642035; cv=none; b=lz6y7DGJcphhRHuaX8kB4oZZp/+OFeUyOLMbMGi+n+CJDFh9W1kjQRSd3A98vs0b1l618ZIZXIUxFMXTmlgvzbw0Md+Xfn6BgRSFN77yRqlGKxhOcNGZgGcoaPL/0iIbXTe5IRkNZahCbmytxb62ZlVWrNkeMU4enE+tufoO1qI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760642035; c=relaxed/simple; bh=4qBipVPoBhYeIJEev22aR1xq5N8meGLNCefqEh/uhR4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=kiQEoBtUDpcCIYmkBp0uJgFQgIl/eTK9zAykWYgo1inn3cm40EQtJaDz16o11PqgUP/Y3BQvHUXgqxavnM/IagmqaB05qqRtLz2PoQPu82aEiaZyAeoDJWA1ul0kN82wEqb9CqMh9O9HpYpj2fjuettSSN4RdPXN75RpmHJrcjo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=DwNNa1xl; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DwNNa1xl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1760642033; 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:autocrypt:autocrypt; bh=JaZdjRa7yEZiZyCMhP1rrLiVtpOhbGtyEZuYlYpV77E=; b=DwNNa1xlsxzc3adw/mUYEc+FBpDbHUX5y2rSrMR2oYO9Nijm46za4j/v80Wq/c30s/wED7 ijvurSDX+Fj+Iul+nE/TWz3itI7LKg5hR5q5Z9NDAF4NHekngaYOkPKd9G0qz/1eSSgikN 0zeO1dyurTSKQ6Zz4VqhL60p9XNyB5Y= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-576-pwfC6IKsMwKJsFhjfNmgvQ-1; Thu, 16 Oct 2025 15:13:51 -0400 X-MC-Unique: pwfC6IKsMwKJsFhjfNmgvQ-1 X-Mimecast-MFC-AGG-ID: pwfC6IKsMwKJsFhjfNmgvQ_1760642031 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-47113dcc1e0so6927435e9.3 for ; Thu, 16 Oct 2025 12:13:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760642030; x=1761246830; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :from:references:cc:to:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=JaZdjRa7yEZiZyCMhP1rrLiVtpOhbGtyEZuYlYpV77E=; b=Qul1mm0mDcxLg8nFIqcirIH8m3Uj55hTLOfWfe+VMnKwKMtbSqp/Ga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0AFdzRlF8= X-Received: by 2002:a05:600c:5287:b0:471:7a:7922 with SMTP id 5b1f17b1804b1-47117874a26mr10089155e9.6.1760642030625; Thu, 16 Oct 2025 12:13:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IENXdoVpKL4SaZsI8wh6bbHQjJKXIIrDbzHNFmgs/sQ0Xp2kcBJz/Qzps/cepiaqf/0WuYRCQ== X-Received: by 2002:a05:600c:5287:b0:471:7a:7922 with SMTP id 5b1f17b1804b1-47117874a26mr10088955e9.6.1760642030199; Thu, 16 Oct 2025 12:13:50 -0700 (PDT) Received: from ?IPV6:2003:d8:2f0c:c200:fa4a:c4ff:1b32:21ce? (p200300d82f0cc200fa4ac4ff1b3221ce.dip0.t-ipconnect.de. [2003:d8:2f0c:c200:fa4a:c4ff:1b32:21ce]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-471144d1765sm56096685e9.17.2025.10.16.12.13.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 16 Oct 2025 12:13:49 -0700 (PDT) Message-ID: Date: Thu, 16 Oct 2025 21:13:48 +0200 Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Bug: Performance regression in 1013af4f585f: mm/hugetlb: fix huge_pmd_unshare() vs GUP-fast race To: Lorenzo Stoakes Cc: Jann Horn , "Uschakow, Stanislav" , "linux-mm@kvack.org" , "trix@redhat.com" , "ndesaulniers@google.com" , "nathan@kernel.org" , "akpm@linux-foundation.org" , "muchun.song@linux.dev" , "mike.kravetz@oracle.com" , "liam.howlett@oracle.com" , "osalvador@suse.de" , "vbabka@suse.cz" , "stable@vger.kernel.org" References: <4d3878531c76479d9f8ca9789dc6485d@amazon.de> <45084140-cd90-4fd8-bd31-f1a8a4d64bad@lucifer.local> From: David Hildenbrand Content-Language: en-US Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+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cwRuj1m73D sq8DEFBdZ5eEkj1dCyx+t/ga6x2rHyc8Sl86oK1tvAkwBNsfKou3v+jP/l14a7DGBvrmlYjO 59o3t6inu6H7pt7OL6u6BQj7DoMAEQEAAcLBfAQYAQgAJgIbDBYhBBvZyq1zXEw6Rg38yk3e EPcA/4NaBQJonNqrBQkmWAihAAoJEE3eEPcA/4NaKtMQALAJ8PzprBEXbXcEXwDKQu+P/vts IfUb1UNMfMV76BicGa5NCZnJNQASDP/+bFg6O3gx5NbhHHPeaWz/VxlOmYHokHodOvtL0WCC 8A5PEP8tOk6029Z+J+xUcMrJClNVFpzVvOpb1lCbhjwAV465Hy+NUSbbUiRxdzNQtLtgZzOV Zw7jxUCs4UUZLQTCuBpFgb15bBxYZ/BL9MbzxPxvfUQIPbnzQMcqtpUs21CMK2PdfCh5c4gS sDci6D5/ZIBw94UQWmGpM/O1ilGXde2ZzzGYl64glmccD8e87OnEgKnH3FbnJnT4iJchtSvx yJNi1+t0+qDti4m88+/9IuPqCKb6Stl+s2dnLtJNrjXBGJtsQG/sRpqsJz5x1/2nPJSRMsx9 5YfqbdrJSOFXDzZ8/r82HgQEtUvlSXNaXCa95ez0UkOG7+bDm2b3s0XahBQeLVCH0mw3RAQg r7xDAYKIrAwfHHmMTnBQDPJwVqxJjVNr7yBic4yfzVWGCGNE4DnOW0vcIeoyhy9vnIa3w1uZ 3iyY2Nsd7JxfKu1PRhCGwXzRw5TlfEsoRI7V9A8isUCoqE2Dzh3FvYHVeX4Us+bRL/oqareJ CIFqgYMyvHj7Q06kTKmauOe4Nf0l0qEkIuIzfoLJ3qr5UyXc2hLtWyT9Ir+lYlX9efqh7mOY qIws/H2t In-Reply-To: <45084140-cd90-4fd8-bd31-f1a8a4d64bad@lucifer.local> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit >> >> (I don't understand how the page table can be used for "normal, >> non-hugetlb". I could only see how it is used for the remaining user for >> hugetlb stuff, but that's different question) > > Right, this surely is related only to hugetlb PTS, otherwise the refcount > shouldn't be a factor no? The example from Jann is scary. But I think it checks out. > >> >> How does the fix work when an architecture does not issue IPIs for TLB >> shootdown? To handle gup-fast on these architectures, we use RCU. >> >> So I'm wondering whether we use RCU somehow. > > Presumably you mean whether we _can_ use RCU somehow? No, whether there is an implied RCU sync before the page table gets reused, see my reply from Jann. > >> >> But note that in gup_fast_pte_range(), we are validating whether the PMD >> changed: >> >> if (unlikely(pmd_val(pmd) != pmd_val(*pmdp)) || >> unlikely(pte_val(pte) != pte_val(ptep_get(ptep)))) { >> gup_put_folio(folio, 1, flags); >> goto pte_unmap; >> } > > Right and as per the comment there: > > /* > ... > * For THP collapse, it's a bit more complicated because GUP-fast may be > * walking a pgtable page that is being freed (pte is still valid but pmd > * can be cleared already). To avoid race in such condition, we need to > * also check pmd here to make sure pmd doesn't change (corresponds to > * pmdp_collapse_flush() in the THP collapse code path). > ... > */ > > So if this can correctly handle a cleared PMD entry in the teardown case, surely > it can handle it in this case also? Right. But see my other mail, on architectures that don't free page tables with RCU we still need the IPI, so that is nasty. > >> >> >> So in case the page table got reused in the meantime, we should just back >> off and be fine, right? > > Yeah seems to be the case to me. > >> >> -- >> Cheers >> >> David / dhildenb >> > > So it seems like you have a proposal here - could you send a patch so we can > assess it please? :) It's a bit tricky, I think I have to discuss with Jann some more first. But right now my understanding is that Janns fix might not have taken care of arch without the IPI sync -- I might be wrong. -- Cheers David / dhildenb