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 85999ECAAA6 for ; Fri, 26 Aug 2022 16:46:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E019E6B0074; Fri, 26 Aug 2022 12:46:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DBDAC6B0075; Fri, 26 Aug 2022 12:46:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C29C8940007; Fri, 26 Aug 2022 12:46:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id B10616B0074 for ; Fri, 26 Aug 2022 12:46:15 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 67E711C5C4F for ; Fri, 26 Aug 2022 16:46:15 +0000 (UTC) X-FDA: 79842321510.07.67A5C7A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf13.hostedemail.com (Postfix) with ESMTP id 0A3552002A for ; Fri, 26 Aug 2022 16:46:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661532374; 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=aM/0vWRQhG6l7795J8Sv+413xc0zb7CfNl42O6VQfck=; b=HqwCv4oSfh0QwYVOcJh+KTiNdFLAzHQaPDklncuFpplEy5LFZSsF2D7CjaXN/CmbEZt4MX xIKnAjMS6luPzC5rudU4spkyg30F1VK+NKyGrJZxR69t9UuJD+R0wFp9De4D+oWJGvh5r3 k+uEQMom4S0QIdBECIJ5fnYeScEtf7w= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-17-y3DHTnQpNsSjSPyYJumuiA-1; Fri, 26 Aug 2022 12:46:05 -0400 X-MC-Unique: y3DHTnQpNsSjSPyYJumuiA-1 Received: by mail-wm1-f72.google.com with SMTP id c66-20020a1c3545000000b003a5f6dd6a25so4314098wma.1 for ; Fri, 26 Aug 2022 09:46:05 -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=aM/0vWRQhG6l7795J8Sv+413xc0zb7CfNl42O6VQfck=; b=YV07QTmeL2GV1xlxuTtnWVP/uNhujTxQ5H9UsC3dHCxHmfDPR2zqhKeDSOASOe+rVx Krfy6jLloxN3T5BYFwtfgN/U9FhHhu5Ivl+7xzx1oeaizvXWs+Vhbk8bGzI/BgSZlXWx 4CIYMbd3O5BlhZ8A8qbDIO4bhTE0/CVwSPDC17nl/Hn82HZGuIRswYBwmrQoPwuoxh+p FknlNae/SQIAui4fgNjIMyM2ag9gbIvrPB8BGZ4GKn7HfN0LAu79NJjqJmV50eWUbJZs de8mP7p10cPQHrkk1YczDhrMdy+clV8PQOjE+Hgr3/JCDjF4XND9Ig1MOzhpQMORnECs xZiw== X-Gm-Message-State: ACgBeo3byFyKiPfy4+LNIy69pOcrUWEEnnll1wVPRIrHNOg22GqGWGYd bVAIf+kr9Oi/0VfMiNyXARhuSD2fklvsoaeczJgM+NntaexVN26M5vJ4G8lS2PAn4/UXF7LZa2X dfMwAAmpXLDU= X-Received: by 2002:a7b:cd0f:0:b0:3a5:ec59:daf0 with SMTP id f15-20020a7bcd0f000000b003a5ec59daf0mr279209wmj.13.1661532364613; Fri, 26 Aug 2022 09:46:04 -0700 (PDT) X-Google-Smtp-Source: AA6agR40NbGvjbiWl5L8l+XuL5Rh4KAQqMtg/LZ8GOIke5nZFYZHD6d6ipQhIpQgrK46S3HVwjTkJA== X-Received: by 2002:a7b:cd0f:0:b0:3a5:ec59:daf0 with SMTP id f15-20020a7bcd0f000000b003a5ec59daf0mr279186wmj.13.1661532364308; Fri, 26 Aug 2022 09:46:04 -0700 (PDT) Received: from ?IPV6:2003:cb:c708:f600:abad:360:c840:33fa? (p200300cbc708f600abad0360c84033fa.dip0.t-ipconnect.de. [2003:cb:c708:f600:abad:360:c840:33fa]) by smtp.gmail.com with ESMTPSA id l9-20020a7bc349000000b003a5fa79007fsm162159wmj.7.2022.08.26.09.46.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 26 Aug 2022 09:46:03 -0700 (PDT) Message-ID: <140e7688-b66d-2f6d-fed8-e39da5045420@redhat.com> Date: Fri, 26 Aug 2022 18:46:02 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 To: Peter Xu Cc: Alistair Popple , linux-mm@kvack.org, akpm@linux-foundation.org, Nadav Amit , huang ying , LKML , "Sierra Guiza, Alejandro (Alex)" , Felix Kuehling , Jason Gunthorpe , John Hubbard , Ralph Campbell , Matthew Wilcox , Karol Herbst , Lyude Paul , Ben Skeggs , Logan Gunthorpe , paulus@ozlabs.org, linuxppc-dev@lists.ozlabs.org, stable@vger.kernel.org, Huang Ying References: <3b01af093515ce2960ac39bb16ff77473150d179.1661309831.git-series.apopple@nvidia.com> <8735dkeyyg.fsf@nvdebian.thelocal> <8735dj7qwb.fsf@nvdebian.thelocal> <72146725-3d70-0427-50d4-165283a5a85d@redhat.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v3 2/3] mm/migrate_device.c: Copy pte dirty bit to 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=1661532375; a=rsa-sha256; cv=none; b=HT/Eimy84a3bvLikP8oxcWzqjDgfjkWVeh8Wr7kziFwaKqla5Q8FMfoA3vChg8/QYPmi2f SiB4Mklp48YK2cRQCBzf8bBP+EQQ2ktqe7cHakO7ZEs+jXc/ykUPIbAjveKWZBRvfmELLp WdBgDCEB5rhh+5bZ7x7biosDG9kG4d0= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HqwCv4oS; spf=pass (imf13.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661532375; 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=aM/0vWRQhG6l7795J8Sv+413xc0zb7CfNl42O6VQfck=; b=DYWtOEI249iYn94IIpxiRBbeKCxIsAFSJA6/uJaSgxqR8+M8aTyKpsY3fVbCDwi9YTqfGV Ix9H/kvdOsHpfBmdfy0qGYiwzggjVVCAhqikA4RfHGDsnepYa9DpzKWiHoBuBjBRX6c39J 1vWQuvbDuUebaHHPPGIG60DvmyOLYtY= X-Rspam-User: Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HqwCv4oS; spf=pass (imf13.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam10 X-Stat-Signature: 7i61pz6ake15ipxyf5cocq99hrqfyb7z X-Rspamd-Queue-Id: 0A3552002A X-HE-Tag: 1661532374-598404 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 26.08.22 17:55, Peter Xu wrote: > On Fri, Aug 26, 2022 at 04:47:22PM +0200, David Hildenbrand wrote: >>> To me anon exclusive only shows this mm exclusively owns this page. I >>> didn't quickly figure out why that requires different handling on tlb >>> flushs. Did I perhaps miss something? >> >> GUP-fast is the magic bit, we have to make sure that we won't see new >> GUP pins, thus the TLB flush. >> >> include/linux/mm.h:gup_must_unshare() contains documentation. > > Hmm.. Shouldn't ptep_get_and_clear() (e.g., xchg() on x86_64) already > guarantees that no other process/thread will see this pte anymore > afterwards? You could have a GUP-fast thread that just looked up the PTE and is going to pin the page afterwards, after the ptep_get_and_clear() returned. You'll have to wait until that thread finished. Another user that relies on this interaction between GUP-fast and TLB flushing is for example mm/ksm.c:write_protect_page() There is a comment in there explaining the interaction a bit more detailed. Maybe we'll be able to handle this differently in the future (maybe once this turns out to be an actual performance problem). Unfortunately, mm->write_protect_seq isn't easily usable because we'd need have to make sure we're the exclusive writer. For now, it's not too complicated. For PTEs: * try_to_migrate_one() already uses ptep_clear_flush(). * try_to_unmap_one() already conditionally used ptep_clear_flush(). * migrate_vma_collect_pmd() was the one case that didn't use it already (and I wonder why it's different than try_to_migrate_one()). -- Thanks, David / dhildenb