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 81220C25B08 for ; Wed, 17 Aug 2022 19:07:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1C8EC6B0073; Wed, 17 Aug 2022 15:07:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 178676B0074; Wed, 17 Aug 2022 15:07:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 040E68D0002; Wed, 17 Aug 2022 15:07:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id E6CEB6B0073 for ; Wed, 17 Aug 2022 15:07:15 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id B26B340943 for ; Wed, 17 Aug 2022 19:07:15 +0000 (UTC) X-FDA: 79810017630.24.9B4B271 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 55416160064 for ; Wed, 17 Aug 2022 19:07:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660763233; 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: in-reply-to:in-reply-to:references:references; bh=5ABSmkuZfQM3Y1mClHJcPhcabJ5jPBDhGKX1+BXsp40=; b=cNL2w9KwtFrAexsqGKBqsxuTgKWqkI35z4xRmEcZdUtDLMXQ1XAhW7FARnaeQIIPbahDMe OYR/FHYtsng2SBn1VYrp6QAOIskTrK1+dO4oNSe36AGssvdJmaDwzs7BmRkQISEydHGUtZ gngx81mxRbP8qjwkWU6xR5Ps+JwH/vo= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-191-2FGnI1ckNraGWi0982JOCQ-1; Wed, 17 Aug 2022 15:07:12 -0400 X-MC-Unique: 2FGnI1ckNraGWi0982JOCQ-1 Received: by mail-qv1-f69.google.com with SMTP id m18-20020a0cf192000000b00496ac947c21so1113913qvl.4 for ; Wed, 17 Aug 2022 12:07:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc; bh=5ABSmkuZfQM3Y1mClHJcPhcabJ5jPBDhGKX1+BXsp40=; b=xkie+xn5F2ku+gsUwOooWwnG+4UGiHOCRY0LBact02jRAen5UDsbxRLNfXy/ET8t2k Nbi6OvyHdUy5/IQqWPwNqnh75nWpqzo+dgSTmSJHEMicGGDhVIi37IOcqQT9+vQ/a+dz LNP0JZ+fYQM+MM5jGOdJmlSMXh4Y6NmSdksAun/qCUqjRNA/k3DfBL5CBf7Ut430ccqn 41Rne1oBComLp7pYycWcdkl9phrDLUYCTq5D3cvx47iKs9T3vPijI7mdVH1PVHqKvV5a z8ok/Nt3uYIo7+jaDeynzEsx28tX5klQvdG4CJ6dKVXHndoN/MvKO/91t82JwxlCeacJ DfGA== X-Gm-Message-State: ACgBeo3X+yhL+FWLNqDPH3vla2GXLmKBpUc140FBEVeyKgBxJPUN78wI OaVnUM32AkNbUUPf56woxB6rcR3ttyLKKPpW9HGdhSgjAGn9lCP73Pg3miDAr5pkqVvozIVzfno lzLsqQEhEKdI= X-Received: by 2002:ac8:5b15:0:b0:343:6789:193a with SMTP id m21-20020ac85b15000000b003436789193amr23697812qtw.647.1660763232198; Wed, 17 Aug 2022 12:07:12 -0700 (PDT) X-Google-Smtp-Source: AA6agR7htcPsTa+zO6/5dGIcJF7fto7SLs+oLa5/xcRr6PogKT9KpDCzjPlwU09EoMQTzAndOv0Wtg== X-Received: by 2002:ac8:5b15:0:b0:343:6789:193a with SMTP id m21-20020ac85b15000000b003436789193amr23697775qtw.647.1660763231904; Wed, 17 Aug 2022 12:07:11 -0700 (PDT) Received: from xz-m1.local (bras-base-aurron9127w-grc-35-70-27-3-10.dsl.bell.ca. [70.27.3.10]) by smtp.gmail.com with ESMTPSA id bl26-20020a05620a1a9a00b006b8e63dfffbsm15302093qkb.58.2022.08.17.12.07.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Aug 2022 12:07:11 -0700 (PDT) Date: Wed, 17 Aug 2022 15:07:09 -0400 From: Peter Xu To: Alistair Popple Cc: huang ying , linux-mm@kvack.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, "Sierra Guiza, Alejandro (Alex)" , Felix Kuehling , Jason Gunthorpe , John Hubbard , David Hildenbrand , Ralph Campbell , Matthew Wilcox , Karol Herbst , Lyude Paul , Ben Skeggs , Logan Gunthorpe , paulus@ozlabs.org, linuxppc-dev@lists.ozlabs.org, Huang Ying , stable@vger.kernel.org Subject: Re: [PATCH v2 1/2] mm/migrate_device.c: Copy pte dirty bit to page Message-ID: References: <6e77914685ede036c419fa65b6adc27f25a6c3e9.1660635033.git-series.apopple@nvidia.com> <871qtfvdlw.fsf@nvdebian.thelocal> <87o7wjtn2g.fsf@nvdebian.thelocal> MIME-Version: 1.0 In-Reply-To: <87o7wjtn2g.fsf@nvdebian.thelocal> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660763234; a=rsa-sha256; cv=none; b=S4yJcYPB0hJaBntauI1WQh7wwVVYt1a307s4jwsHAwTlAwFjRkNL5A4zfeobSQyjpZOVDB vQ8CH3jVJ0UenXYIjRNLWRCv5xZK1y9VjQcAGnYwZuH6gUGQdDGzV7SyRiB9T1fPUEd68L Cjo8fW+yjKQD1OsN9ztvX++pxLEeQGc= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cNL2w9Kw; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660763234; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=5ABSmkuZfQM3Y1mClHJcPhcabJ5jPBDhGKX1+BXsp40=; b=xST3QE9MRTJvZfS/RO84nNLnL1crCLWykZYUPBUUtrJorotpeVv6hbXB4WKSclGHIVDevH 1n+1sEMfssN5VyD8X4HgDsCZ/MD5iCEZE3vIepRk0xw6QKmWanKBgSEncx1t18aRC+wfG/ +bSKS/clXoIq4G5n4a1ugDFFAkYmP/E= X-Stat-Signature: 9h4fecmyx6k89cczucq7dj354c9zmx9s X-Rspamd-Queue-Id: 55416160064 Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cNL2w9Kw; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1660763234-406107 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 Wed, Aug 17, 2022 at 03:41:16PM +1000, Alistair Popple wrote: > My primary concern with batching is ensuring a CPU write after clearing > a clean PTE but before flushing the TLB does the "right thing" (ie. faults > if the PTE is not present). Fair enough. Exactly I have that same concern. But I think Nadav replied very recently on this in the previous thread, quotting from him [1]: I keep not remembering this erratum correctly. IIRC, the erratum says that the access/dirty might be set, but it does not mean that a write is possible after the PTE is cleared (i.e., the dirty/access might be set on the non-present PTE, but the access itself would fail). So it is not an issue in this case - losing A/D would not impact correctness since the access should fail. I don't really know whether he means this, but I really think the hardware should behave like that or otherwise I can't see how it can go right. Let's assume if after pte cleared the page can still be written, then afaict ptep_clear_flush() is not safe either, because fundamentally it is two operations happening in sequence, of: (1) ptep_get_and_clear(), and (2) conditionally do flush_tlb_page() when needed. If page can be written with TLB cached but without pte present, what if some process writes to memory during step (1) and (2)? AFAIU that's the same question as using raw ptep_get_and_clear() and a batched tlb flush. IOW, I don't see how a tlb batched solution can be worse than using per-pte ptep_clear_flush(). It may enlarge the race window but fundamentally (iiuc) they're the same thing here as long as there's no atomic way to both "clear pte and flush tlb". [1] https://lore.kernel.org/lkml/E37036E0-566E-40C7-AD15-720CDB003227@gmail.com/ -- Peter Xu