Received: by 10.192.165.148 with SMTP id m20csp529235imm; Wed, 25 Apr 2018 03:44:48 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/vhmnyxJ7wg0XISAfmapcSpV64Gj9UG55QImuuNWK9HJT1FZts7tGu6mei3z4c5yosRiBs X-Received: by 2002:a17:902:887:: with SMTP id 7-v6mr29380630pll.319.1524653088222; Wed, 25 Apr 2018 03:44:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524653088; cv=none; d=google.com; s=arc-20160816; b=jfZ8WqcJaFIxUnVgiJ64S2oYVumRAZd/HOQKvrEuYp3hLYPXH7Gl8RkBkaROoh7405 pItejDU74v09M1I/QAACfB3D4iNjStKddE6XAHH7nZin33WSE8HNUZqTmA/PhCMk3uqR aLsjGGa3IW543d67v0Xn9+Q7d+MZWZgei0Fvzh8UVdmzjalaHmvFPHotGsblOyt6cEU3 HGTKAFeeke/WI+Y13xomVGjv2zEoCQCjoC38nfL8luUsBFWzOiiVNpL521UO8LnhAAkp MStlaANGNi+keRZ4cGpFLXSiSecG1dhE0dCPHdxtZD5T9CyxmpQI2/HjfU7d4myQDa2F bn2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=tMWWiwaUlzzY25OYrZuC9jKUxAfOw31U/3nVYR3W0Vc=; b=Ui8/Ls+Rk43g0lZAdspYrEyLSQwECzIz5/8PHgtW3WPfv+Tai3R/3GpZVNjvEcxoAM eF+3Jvqj8+iy3OQQdQLih5RVSBFJJ5qBtIURpe/jzorN+U+lgf3Dnb9nSx9wUA5wvDdR 3GREEKLp9y6GCbzQAF1RiZr2oRf1ukGuxsqt4fEJE5WN2VPx3wb2oFi384BIGCKOQgp3 CVIk6bkHqFCs05KUes7d27nI2ge6/rF/8MMm6fdzKTEAdLclF/rmC/0Bq8GshNFMCkWx SyMcB396Calq1iC90uZDWICA7T1obCWDxexHMMY8Ri111/CNNuyglSqBo+KpfAkFnO9l Ubcw== ARC-Authentication-Results: i=1; mx.google.com; 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 v14si13474042pgq.266.2018.04.25.03.44.33; Wed, 25 Apr 2018 03:44:48 -0700 (PDT) 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; 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 S1754219AbeDYKnb (ORCPT + 99 others); Wed, 25 Apr 2018 06:43:31 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:53014 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753730AbeDYKnZ (ORCPT ); Wed, 25 Apr 2018 06:43:25 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id D452D49F; Wed, 25 Apr 2018 10:43:23 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Kirill A. Shutemov" , Vlastimil Babka , Andrea Arcangeli , Michal Hocko , "Aneesh Kumar K.V" , Catalin Marinas , David Daney , David Miller , "H. Peter Anvin" , Hugh Dickins , Ingo Molnar , Martin Schwidefsky , Nitin Gupta , Ralf Baechle , Thomas Gleixner , Vineet Gupta , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 4.14 113/183] asm-generic: provide generic_pmdp_establish() Date: Wed, 25 Apr 2018 12:35:33 +0200 Message-Id: <20180425103246.988906567@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180425103242.532713678@linuxfoundation.org> References: <20180425103242.532713678@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: "Kirill A. Shutemov" [ Upstream commit c58f0bb77ed8bf93dfdde762b01cb67eebbdfc29 ] Patch series "Do not lose dirty bit on THP pages", v4. Vlastimil noted that pmdp_invalidate() is not atomic and we can lose dirty and access bits if CPU sets them after pmdp dereference, but before set_pmd_at(). The bug can lead to data loss, but the race window is tiny and I haven't seen any reports that suggested that it happens in reality. So I don't think it worth sending it to stable. Unfortunately, there's no way to address the issue in a generic way. We need to fix all architectures that support THP one-by-one. All architectures that have THP supported have to provide atomic pmdp_invalidate() that returns previous value. If generic implementation of pmdp_invalidate() is used, architecture needs to provide atomic pmdp_estabish(). pmdp_estabish() is not used out-side generic implementation of pmdp_invalidate() so far, but I think this can change in the future. This patch (of 12): This is an implementation of pmdp_establish() that is only suitable for an architecture that doesn't have hardware dirty/accessed bits. In this case we can't race with CPU which sets these bits and non-atomic approach is fine. Link: http://lkml.kernel.org/r/20171213105756.69879-2-kirill.shutemov@linux.intel.com Signed-off-by: Kirill A. Shutemov Cc: Vlastimil Babka Cc: Andrea Arcangeli Cc: Michal Hocko Cc: Aneesh Kumar K.V Cc: Catalin Marinas Cc: David Daney Cc: David Miller Cc: H. Peter Anvin Cc: Hugh Dickins Cc: Ingo Molnar Cc: Martin Schwidefsky Cc: Nitin Gupta Cc: Ralf Baechle Cc: Thomas Gleixner Cc: Vineet Gupta Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- include/asm-generic/pgtable.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) --- a/include/asm-generic/pgtable.h +++ b/include/asm-generic/pgtable.h @@ -309,6 +309,21 @@ extern void pgtable_trans_huge_deposit(s extern pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp); #endif +#ifdef CONFIG_TRANSPARENT_HUGEPAGE +/* + * This is an implementation of pmdp_establish() that is only suitable for an + * architecture that doesn't have hardware dirty/accessed bits. In this case we + * can't race with CPU which sets these bits and non-atomic aproach is fine. + */ +static inline pmd_t generic_pmdp_establish(struct vm_area_struct *vma, + unsigned long address, pmd_t *pmdp, pmd_t pmd) +{ + pmd_t old_pmd = *pmdp; + set_pmd_at(vma->vm_mm, address, pmdp, pmd); + return old_pmd; +} +#endif + #ifndef __HAVE_ARCH_PMDP_INVALIDATE extern void pmdp_invalidate(struct vm_area_struct *vma, unsigned long address, pmd_t *pmdp);