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 5B6CFECAAD3 for ; Wed, 31 Aug 2022 18:29:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B1EA16B0071; Wed, 31 Aug 2022 14:29:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AA6D08D0002; Wed, 31 Aug 2022 14:29:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8F9918D0001; Wed, 31 Aug 2022 14:29:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 7A73C6B0071 for ; Wed, 31 Aug 2022 14:29:22 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 1FF0D1C67BE for ; Wed, 31 Aug 2022 18:29:22 +0000 (UTC) X-FDA: 79860725364.28.6417A76 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf24.hostedemail.com (Postfix) with ESMTP id B7B05180061 for ; Wed, 31 Aug 2022 18:29:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661970561; 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=o5+efHgbk856m97kY2nZ0pKIsJZ0ZgtcFYWEKHNb/1k=; b=bVmyZs2ytFZDGKnIcz0Zh4Cd2+dULaNW/OeNLe5gk/Dwnh0rHQRnzQ6k6N6YQD0M6iaPYW W3HPDQ7EF/SuJ9Y3Oc0JJbf9Sy994AjN3BiQNZ2k7JVSOjnV/41rTvu2Vk4YMpWtDD5zsG NSYH72cxFbhS3EzUf9W1Y3f1ecA3+yQ= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-99-rYjN1BpiOy6h6MNN-jhqOg-1; Wed, 31 Aug 2022 14:29:12 -0400 X-MC-Unique: rYjN1BpiOy6h6MNN-jhqOg-1 Received: by mail-wm1-f71.google.com with SMTP id 203-20020a1c02d4000000b003a5f5bce876so47874wmc.2 for ; Wed, 31 Aug 2022 11:29:12 -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:subject:organization:from :references:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc; bh=o5+efHgbk856m97kY2nZ0pKIsJZ0ZgtcFYWEKHNb/1k=; b=dEksnmFzqrMeKP1P5UBXcusZ9s6eD93dOxfaWKaaoI1N19dvM7+smxMJ0ShQfRG5cY UwlCiVzozmeBOUnnjOqhzzYJtSSkb0rn5hNZzpL9PA8QKDIx6KeiYkqCHMGTSXg8AiAr mf4QFGdHrja3ICEtghD9WQFFCD31uvrND2MzueAjE1AwHM7XYt8LPuxoqbtovrXJmxwR P1yqiSi95J0V7JGbTXRaXSb3WV576ljpt+9SiwAFEL/kPGwoP67nGr01HH7RtR42PlpS g3HRv9gJOqSXkVoytdLTH3x0rKVAvAUCPiZgKUoA9lSoyM4VXDcSfqpi9nLunCYGNst5 l52A== X-Gm-Message-State: ACgBeo35lsj+Ut6n1YDAuwzE+lyILtEi7vPHC3SL2qs6Y0sgyGJoX5Dk Z/fxsu3Sd7mZvxkzi4ONenSEr0/VtnYiowDyBY/Id3z5r9D80b7ZqirQZKlUDZz0tEfqj7mKOfq AFzN+nEQSN2s= X-Received: by 2002:a05:6000:18ad:b0:226:f3b4:74f2 with SMTP id b13-20020a05600018ad00b00226f3b474f2mr247223wri.537.1661970551394; Wed, 31 Aug 2022 11:29:11 -0700 (PDT) X-Google-Smtp-Source: AA6agR6b1CP6vzUobUKRfSrXGys01uisogD5RmcznVnLtQsvt+FdrsqO1kr/Pc38ceTZ9cobzZ2wdg== X-Received: by 2002:a05:6000:18ad:b0:226:f3b4:74f2 with SMTP id b13-20020a05600018ad00b00226f3b474f2mr247211wri.537.1661970551124; Wed, 31 Aug 2022 11:29:11 -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 m5-20020a5d4a05000000b00225213fd4a9sm13151586wrq.33.2022.08.31.11.29.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 31 Aug 2022 11:29:10 -0700 (PDT) Message-ID: <4845ae71-b7dd-1707-ebc3-2eb3521e7fa0@redhat.com> Date: Wed, 31 Aug 2022 20:29:09 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 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> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v1] mm/ksm: update stale comment in write_protect_page() 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=1661970561; a=rsa-sha256; cv=none; b=xswkaKw0wYovTbCxX0k4cZybbv/tOhO4NJLiXkB3kdpqh3DT/t3n4/pM908SAB38EYeOo3 JIz79ZJVUza1YIAiIXf3NrOKogJpuCPtc+LT476lnu9DRBd0gWGY4zhz8MAY3VyzRtCDEF TBpIfETuX5uGp/GiZnGC/gVIL95LeHA= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bVmyZs2y; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf24.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=1661970561; 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=o5+efHgbk856m97kY2nZ0pKIsJZ0ZgtcFYWEKHNb/1k=; b=Td4eIqFZzA2hihE8poXfJo2IDTzu62IlS3SfkzqXVk+hoc/DHGvN4RH2NHuv+hOPNouE1B DX04+ANT2mYPEsj/4mIvPbgd+Jx6UixPYhNaAjgAa3oZLVsG/YpqqLwsxqqzGToV9jqcZd fgzlAnxNvCVrUa4n2H+OnsDyHSrv950= Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bVmyZs2y; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf24.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: ok1esq8sowkzde9q3x1xp9fyynbrd4xu X-Rspamd-Queue-Id: B7B05180061 X-HE-Tag: 1661970561-462100 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 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(). 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? -- Thanks, David / dhildenb