Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp661714ybv; Thu, 20 Feb 2020 05:13:22 -0800 (PST) X-Google-Smtp-Source: APXvYqyhGIqphMHesHJJTnZIQyxkwPbPq0skE+UoL1LFLgY6udozyjaZAT1+RNMF3R4Q5Xhpl5AH X-Received: by 2002:a9d:620c:: with SMTP id g12mr11522429otj.111.1582204402095; Thu, 20 Feb 2020 05:13:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582204402; cv=none; d=google.com; s=arc-20160816; b=cLUMciV15tAYzom7q7LetiTkXEGojUo756iVOY2YOhzQD4Bw89/k2oCvfBdlOHntNl ryINEM/8rfOjjhm6gcjtcZcDcJyD4zPNXwapgqxVikRu+gcmxTvPrfVL+r/m7X7s9JU+ bowJ97Jw0t40ld20U9a1rIh7boGcYyHP7HPl7NEKf6Px7LcVfV804837ljNta6jk+5CW EbH+yuQIz3fmCJ4FQ1mbCQP60ayd2p84cuTwDcHRznCHcAR8GfeFFoZImg8yxzWDIfZ+ j1elNuANjv247GuEyE1jH8tOo/Rrf6FBZOvc/6+IaGMaw1owXs7PzsAReiYzAl43tzRL yHSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=GzNziDqoL/AUz4B68gds+Nqpq3Cs5xfNdbm3Hr7a7BQ=; b=CmNSUO2e5HOdSmC7joRiiEAC+UIVutNzWegGeAOMntTiCWmlE4VaIvg46mtOskfevH C0nwZJi4TmS3e9Xp7m9OVrOayjVTxYvhWPgmN/rWoGjXtSwzTNL0XNEC18kFOyM/gsvx Qf9YuDWdx04rXEpf1W7jOyGLGOA/djinIw7O+3LNgT3MzxLqru5qdbeAPQfKqp2sO3gU 9ERA3NgraP6xR0bv++2Ix3iVC/lRIPeOiVZEz+uYWX0Racvj36c9JXu/hbBBbZ0uOJaV jV8xCcNdYDnlZlqtEOSvL4VxTxJsahyrbTxigjfvtiNVjredDIlc5BQ4tlESvhCzr9lo DFIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=K4vLOeea; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i3si1699466otc.272.2020.02.20.05.13.08; Thu, 20 Feb 2020 05:13:22 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=K4vLOeea; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728072AbgBTNM7 (ORCPT + 99 others); Thu, 20 Feb 2020 08:12:59 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:42703 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727088AbgBTNM6 (ORCPT ); Thu, 20 Feb 2020 08:12:58 -0500 Received: by mail-lj1-f196.google.com with SMTP id d10so4140628ljl.9 for ; Thu, 20 Feb 2020 05:12:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=GzNziDqoL/AUz4B68gds+Nqpq3Cs5xfNdbm3Hr7a7BQ=; b=K4vLOeeal5lD62N5rp44dErrQJ/7YZhgd+S/o071QQuMO+lR5PNq/f5PuECNd0Ps3q MDFxOM9hsuf/2N8nr6xRpX+q6eUKzDiIkACheNgp/epR22Dmsj6kg8hPT4IwAhrg8sbM M0bnueZA88O5tbgFHu7UMcdwte23Yrr86E+JTLO6xc2nyJ+8KfdBxRJg11VJZH75W1re 8kRQR5K14xPczsg/eeg+nRKKi/7Q/pQvxSwxysUCo9U+MQXU7KAK7C0QW+pT/70uCUEC m9P+xnzLHWkfhXmLd2mAV3KkScTdnSq7bGUrpKqXVUYVmieqMtdIFTNImeyN6SDIM+Bx 6Iqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=GzNziDqoL/AUz4B68gds+Nqpq3Cs5xfNdbm3Hr7a7BQ=; b=R9pm1hg6gSPZzPqhSm+L3suU5cilAOsDLy/lMZ0mfgiSaHyx1A6W9E/acQXX0FL34Z y63F8Kb6xEQNbmeiwf2eoylNNbbquuDv1yWInbdX0H+u7/DCnY/dVzbXfXjCvxP9FSDt s0W7yHPkJjbUFsJjYv+gQUf9Uk4RhEq6K5ou5jJME9zN7m0rm/06sj1xSm8qkiL5rQAI WlW57wybqFcLlUadQ0gApYKBe1Xb4P7UA88f5XI4zrB10nROAKUKikFT5k4DBQDcABB8 GCqzz0XwTUYlx/OEO+ONnl8QUkFsBojezLuT9s4c65c8Hleg0N9MNc0AG12TvKU2eMpf 4dow== X-Gm-Message-State: APjAAAWazj13mAHo4d+Bln2jO4NSmVNjWNoM9sX2emc/cBt0faoY16wk 0AZ2djUmIVfpjXr9M5xh3wNlFA== X-Received: by 2002:a2e:88c4:: with SMTP id a4mr19216575ljk.174.1582204376901; Thu, 20 Feb 2020 05:12:56 -0800 (PST) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id n11sm1851850ljg.15.2020.02.20.05.12.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Feb 2020 05:12:56 -0800 (PST) Received: by box.localdomain (Postfix, from userid 1000) id 7F899100FBB; Thu, 20 Feb 2020 16:13:25 +0300 (+03) Date: Thu, 20 Feb 2020 16:13:25 +0300 From: "Kirill A. Shutemov" To: "Huang, Ying" Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Zi Yan , "Kirill A . Shutemov" , Andrea Arcangeli , Michal Hocko , Vlastimil Babka Subject: Re: [PATCH] mm: Fix possible PMD dirty bit lost in set_pmd_migration_entry() Message-ID: <20200220131325.e56ttzhjcvxyic7i@box> References: <20200220075220.2327056-1-ying.huang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200220075220.2327056-1-ying.huang@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 20, 2020 at 03:52:20PM +0800, Huang, Ying wrote: > From: Huang Ying > > In set_pmd_migration_entry(), pmdp_invalidate() is used to change PMD > atomically. But the PMD is read before that with an ordinary memory > reading. If the THP (transparent huge page) is written between the > PMD reading and pmdp_invalidate(), the PMD dirty bit may be lost, and > cause data corruption. The race window is quite small, but still > possible in theory, so need to be fixed. > > The race is fixed via using the return value of pmdp_invalidate() to > get the original content of PMD, which is a read/modify/write atomic > operation. So no THP writing can occur in between. > > The race has been introduced when the THP migration support is added > in the commit 616b8371539a ("mm: thp: enable thp migration in generic > path"). But this fix depends on the commit d52605d7cb30 ("mm: do not > lose dirty and accessed bits in pmdp_invalidate()"). So it's easy to > be backported after v4.16. But the race window is really small, so it > may be fine not to backport the fix at all. > > Signed-off-by: "Huang, Ying" > Cc: Zi Yan > Cc: Kirill A. Shutemov > Cc: Andrea Arcangeli > Cc: Michal Hocko > Cc: Vlastimil Babka Acked-by: Kirill A. Shutemov -- Kirill A. Shutemov