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 74BF8ECAAD1 for ; Wed, 31 Aug 2022 19:36:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 089566B0072; Wed, 31 Aug 2022 15:36:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 038E06B0073; Wed, 31 Aug 2022 15:36:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E1C3E8D0001; Wed, 31 Aug 2022 15:36:41 -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 D10106B0072 for ; Wed, 31 Aug 2022 15:36:41 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A3D001A03AD for ; Wed, 31 Aug 2022 19:36:41 +0000 (UTC) X-FDA: 79860895002.09.3A6E3CA Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf08.hostedemail.com (Postfix) with ESMTP id F105C16002A for ; Wed, 31 Aug 2022 19:36:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661974600; 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=KxzVUHNaqjzajgQOML3hm8V8CKnGAzf1ViuWb5adgrs=; b=Y1q4jE+hTkrydLtqKY7yxrR94KB4a7xazSaDynHr3cKN1xk7AJSnx8auR2lIneCmbPQErC u8N6EM8+j4AQ0uKuzNGgPIVW+AklS198ScnWe54Dk+X49YOm7l+F+wlhRmXk03Fl9kD1v+ 3JMda9rEmsryQC+qcQ/cmbWjJVEWwHE= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-647-mpZ3e5QVPcCi7cDBzbxLLA-1; Wed, 31 Aug 2022 15:36:36 -0400 X-MC-Unique: mpZ3e5QVPcCi7cDBzbxLLA-1 Received: by mail-wm1-f70.google.com with SMTP id p19-20020a05600c1d9300b003a5c3141365so109067wms.9 for ; Wed, 31 Aug 2022 12:36:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc; bh=KxzVUHNaqjzajgQOML3hm8V8CKnGAzf1ViuWb5adgrs=; b=xUFuRepB96RZ4UAyGMjZ4NNBR5/Iiw+cDx4jHrCyOm6rgJKEWcYAX2NrUTmu87OPIA qk14REWqZPdC4McTqsFnXiezxdEtSEtV39VNlXl+swanohQBBQX8kc255x1kiNDLW3U3 N+BablvQAiDmVcTQSALVKD5nm56vdneQBj8krZ3zHZQAjNUALUnj+DH4iO77D+sUaSrv D+rrIuIkkEMf2goxStPCYGJjLKhDZ84oJ7uvOSlS+NUnT638feuHCpoCC4VJEgU2Y83o tlrJTAB+MHsXMFZQbDtRpNiseF89eeMlFvzLTiv5CYqVm+cBDfZwFvcaPsbmEAW1mwP+ g3vA== X-Gm-Message-State: ACgBeo3jrPc0iIY52g+dx1vVWi+bTkQjUDMGq8PeMuEi1p4TNBr+yBFY PX7IOZjO5Lz4/ZHMuNEnUiNkZ4oV2+qDK/n2FbVHRAdC9ZCzKHgiUEzJiO0OCR2ondiDPBMm71J 9GH+nd90UDJk= X-Received: by 2002:a05:600c:4e04:b0:3a5:a34e:ae81 with SMTP id b4-20020a05600c4e0400b003a5a34eae81mr2860047wmq.147.1661974595567; Wed, 31 Aug 2022 12:36:35 -0700 (PDT) X-Google-Smtp-Source: AA6agR7B/zLJcwKJ2G4azHjhFK7bo/QfmH+ZS5YUgsxbS+hYfWaxG8gDfRoY5pKTGEhmNyF32r7tdA== X-Received: by 2002:a05:600c:4e04:b0:3a5:a34e:ae81 with SMTP id b4-20020a05600c4e0400b003a5a34eae81mr2860035wmq.147.1661974595255; Wed, 31 Aug 2022 12:36:35 -0700 (PDT) Received: from ?IPV6:2003:cb:c706:2900:1613:4308:aca3:2786? (p200300cbc706290016134308aca32786.dip0.t-ipconnect.de. [2003:cb:c706:2900:1613:4308:aca3:2786]) by smtp.gmail.com with ESMTPSA id u21-20020a7bc055000000b003a3442f1229sm2889493wmc.29.2022.08.31.12.36.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 31 Aug 2022 12:36:34 -0700 (PDT) Message-ID: <94c3217d-df73-2b6b-21f0-95baf117c584@redhat.com> Date: Wed, 31 Aug 2022 21:36:25 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Subject: Re: [PATCH v1] mm/ksm: update stale comment in write_protect_page() To: Yang Shi Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Jason Gunthorpe , John Hubbard , Andrea Arcangeli , Hugh Dickins , Peter Xu , "Kirill A. Shutemov" References: <20220831083024.37138-1-david@redhat.com> <4845ae71-b7dd-1707-ebc3-2eb3521e7fa0@redhat.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661974601; a=rsa-sha256; cv=none; b=USsQMl/7DXOnIv89tFy8xkMM8/ruWsOH7xYM7UbcOjsjgXKlhYeTyhm1vYMvObb/BMdyFQ tW/MUHJiB5pZo++xiiMHUI351x0jGG+x1WrLTyGl8H5dMrgb736YkKCcz8d+MCVI6zjnzI 3fVHBVU/El7LM8b1ftqXhUOFdMg1wVw= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Y1q4jE+h; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661974601; 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=KxzVUHNaqjzajgQOML3hm8V8CKnGAzf1ViuWb5adgrs=; b=m3Xr6wPAaqs7RgOgL7O/t1RexGiU7t/Decr2+gOSIsFKJv7recJqDpPPwSpbWdA4wyBZeS BCjxIHf+4Ig2nCfnoUUSnEJrfPsebddGgLbdj4Da/mkx8RhUn5yaLCp4Wy/TZsYGlKTOqK yUct9xVCbc03hhd89PD6kvw9Cf+pOik= Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Y1q4jE+h; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com X-Rspam-User: X-Rspamd-Server: rspam12 X-Stat-Signature: g9oo6136gr57xwi1sg57uhtxxqzfq4fy X-Rspamd-Queue-Id: F105C16002A X-HE-Tag: 1661974600-807456 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: On 31.08.22 21:34, Yang Shi wrote: > On Wed, Aug 31, 2022 at 12:15 PM David Hildenbrand wrote: >> >> On 31.08.22 21:08, Yang Shi wrote: >>> On Wed, Aug 31, 2022 at 11:29 AM David Hildenbrand wrote: >>>> >>>> On 31.08.22 19:55, Yang Shi wrote: >>>>> On Wed, Aug 31, 2022 at 1:30 AM David Hildenbrand wrote: >>>>>> >>>>>> The comment is stale, because a TLB flush is no longer sufficient and >>>>>> required to synchronize against concurrent GUP-fast. This used to be true >>>>>> in the past, whereby a TLB flush would have implied an IPI on architectures >>>>>> that support GUP-fast, resulting in GUP-fast that disables local interrupts >>>>>> from completing before completing the flush. >>>>> >>>>> Hmm... it seems there might be problem for THP collapse IIUC. THP >>>>> collapse clears and flushes pmd before doing anything on pte and >>>>> relies on interrupt disable of fast GUP to serialize against fast GUP. >>>>> But if TLB flush is no longer sufficient, then we may run into the >>>>> below race IIUC: >>>>> >>>>> CPU A CPU B >>>>> THP collapse fast GUP >>>>> >>>>> gup_pmd_range() <-- see valid pmd >>>>> >>>>> gup_pte_range() <-- work on pte >>>>> clear pmd and flush TLB >>>>> __collapse_huge_page_isolate() >>>>> isolate page <-- before GUP bump refcount >>>>> >>>>> pin the page >>>>> __collapse_huge_page_copy() >>>>> copy data to huge page >>>>> clear pte (don't flush TLB) >>>>> Install huge pmd for huge page >>>>> >>>>> return the obsolete page >>>> >>>> Hm, the is_refcount_suitable() check runs while the PTE hasn't been >>>> cleared yet. And we don't check if the PMD changed once we're in >>>> gup_pte_range(). >>> >>> Yes >>> >>>> >>>> The comment most certainly should be stale as well -- unless there is >>>> some kind of an implicit IPI broadcast being done. >>>> >>>> 2667f50e8b81 mentions: "The RCU page table free logic coupled with an >>>> IPI broadcast on THP split (which is a rare event), allows one to >>>> protect a page table walker by merely disabling the interrupts during >>>> the walk." >>>> >>>> I'm not able to quickly locate that IPI broadcast -- maybe there is one >>>> being done here (in collapse) as well? >>> >>> The TLB flush may call IPI. I'm supposed it is arch dependent, right? >>> Some do use IPI, some may not. >> >> Right, and the whole idea of the RCU GUP-fast was to support >> architectures that don't do it. x86-64 does it. IIRC, powerpc doesn't do >> it -- but maybe it does so for PMDs? > > It looks powerpc does issue IPI for pmd flush. But arm64 doesn't IIRC. > > So maybe we should implement pmdp_collapse_flush() for those arches to > issue IPI. ... or find another way to detect and handle this in GUP-fast? Not sure if, for handling PMDs, it could be sufficient to propagate the pmdp pointer + value and double check that the values didn't change. -- Thanks, David / dhildenb