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 X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E9EAC11D04 for ; Thu, 20 Feb 2020 13:13:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C5392222C4 for ; Thu, 20 Feb 2020 13:12:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=shutemov-name.20150623.gappssmtp.com header.i=@shutemov-name.20150623.gappssmtp.com header.b="K4vLOeea" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C5392222C4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4D4076B0005; Thu, 20 Feb 2020 08:12:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4AA186B0006; Thu, 20 Feb 2020 08:12:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 39B0D6B0007; Thu, 20 Feb 2020 08:12:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0054.hostedemail.com [216.40.44.54]) by kanga.kvack.org (Postfix) with ESMTP id 1E8A76B0005 for ; Thu, 20 Feb 2020 08:12:59 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 924E12491 for ; Thu, 20 Feb 2020 13:12:58 +0000 (UTC) X-FDA: 76510545636.13.space70_3705adca9122e X-HE-Tag: space70_3705adca9122e X-Filterd-Recvd-Size: 4764 Received: from mail-lj1-f195.google.com (mail-lj1-f195.google.com [209.85.208.195]) by imf47.hostedemail.com (Postfix) with ESMTP for ; Thu, 20 Feb 2020 13:12:57 +0000 (UTC) Received: by mail-lj1-f195.google.com with SMTP id q8so4181480ljb.2 for ; Thu, 20 Feb 2020 05:12:58 -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=nzvj4Su8QL+MNhZfYje++ei+CSFQA8OGDGbnkpiaba476VBE+FKxbw8xUByrKQe8Hj JjYQF5kJ2dARQDx/qnlCqz5R5HkkItyrvKHSjyVbQo6rQ2BrgRZjlNXfFW+tql60RzM6 PwM9N7ZpHQQ25g22e+dFJ7i7Q0mwebIsUNZsrnRBtqIzPt3R3Fgw0juwdrs4jpAwKP5W N0sm8Pom6Bemx0/wQm/XdAX6pytijbWmI6ndmzNDAwj6AN/PZkAvRKde5cR6yNumFDq6 ibAFcuSNqRTNPRIQaGF965bChOK/8wcsuB8QFj0Ycgy+YUkpru7z/7KmIdAXhWfdAw7c pnCg== X-Gm-Message-State: APjAAAUWHKx0QUavVAZVJh7Z7aZNDcPMBW7PcP1VSll1HfUPz7xT/o/6 oBiRH0JcGVxnhRWStVt45dBaPA== X-Google-Smtp-Source: APXvYqwaE144CzFHNPc2ptsLvuY5jTWwyOCULsFygaInuVevwoDVdizIDXa1G2ZI2dDqhPsffLZD1w== 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> 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 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