Received: by 10.213.65.68 with SMTP id h4csp2117143imn; Sun, 8 Apr 2018 20:08:09 -0700 (PDT) X-Google-Smtp-Source: AIpwx49Au1PCl+PVHU6f8WqQIqM+KqK+0N6wjuryEX3mtNkUaeug4QxUvOGkaDYxVtXvQtpYIzuP X-Received: by 10.101.96.47 with SMTP id p15mr23834538pgu.430.1523243289164; Sun, 08 Apr 2018 20:08:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243289; cv=none; d=google.com; s=arc-20160816; b=0yNr9Juv1nlaCIfhO1C0XX7NLJZBhxMQUY8EYcvu5a+BrpTOFHotq0Jo5Ls/jS2VoO BCIqrA3V06yjtRi5wMues90mztM4RWT5Vjb82OfXdq9oEznLDk0qI52HZ0+I1DKlLiYj RpyV0Hp9f0z1J5rfnoBqFua9qs9qYvpCTu5j50PDxaEXOBEjlpBjkk2uruG/waO+VNyG azwY4zziobZ2k9SPOs3Vp0F5JN2te4Soj4DJGNwPTOH6bhnQNnUxp95O2dBBsnPGRGl2 fBVIzHGqUfNr8x0QxDc2cfyuak0XhUokCfrUjDfWTdAjjkVhTnlY93qp3AOksxiHywsM oeXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=NdHWNyOmKmeoOXBjU+aijedrS5pUxZJjpMmpMWik01Y=; b=J8Y4YtkQzf3xVh0l08r9siGPq/l04ZYi7jbx3a+AruwVkRTV/ffUVvE6cbj9HOby9W 1QOxGAyrFUy1s2d9tWvpeVEDeFaqA5usIdknLja4YZWNYjagvFESOG6nQNq2TBmvvlHq 7u1QmW2de6+AQbbctX6btUcxAFluHUj6zS0L7wm8mDML5OzPEdK0ILTo8mVVwvKOJlXp M5Q3Jjpngo4brkT0X5mBbMOedFr+A7IQRdvHKmHvBK3LcxHVrjTW+ZUazo/LNe6n+AUa OJWVjo45EpEl48WQKz7OIDDZMQGjz8lkIVK6/oSeFSSuB/cmOuPomFgQndIZNXJQK/R7 4mEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=Iulx4f7e; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i63si12036425pfk.159.2018.04.08.20.07.32; Sun, 08 Apr 2018 20:08:09 -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; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=Iulx4f7e; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756964AbeDIBsd (ORCPT + 99 others); Sun, 8 Apr 2018 21:48:33 -0400 Received: from mail-by2nam01on0130.outbound.protection.outlook.com ([104.47.34.130]:18358 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932394AbeDIAd7 (ORCPT ); Sun, 8 Apr 2018 20:33:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=NdHWNyOmKmeoOXBjU+aijedrS5pUxZJjpMmpMWik01Y=; b=Iulx4f7ebMZAykC5jmXvImaARy6TfIls/EcP3LUg6e6Nzynf0zdfkZJbw9OA4VUmOoqqZBXvM7ROHMFhFSpdu3y0Yv/D193lSleZq7CZarg+g+oV2a7YQiMBDvk0uor9pTpXjQrZJFBS7OTyxO+XdvDU3IJE8yy95s1uxwbO/hM= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0806.namprd21.prod.outlook.com (10.167.107.156) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.3; Mon, 9 Apr 2018 00:33:54 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:33:54 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: "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 AUTOSEL for 4.9 259/293] asm-generic: provide generic_pmdp_establish() Thread-Topic: [PATCH AUTOSEL for 4.9 259/293] asm-generic: provide generic_pmdp_establish() Thread-Index: AQHTz5lfzW+6GA/Bvky3wuRWSH/0cQ== Date: Mon, 9 Apr 2018 00:26:16 +0000 Message-ID: <20180409002239.163177-259-alexander.levin@microsoft.com> References: <20180409002239.163177-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002239.163177-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB0806;7:uUJCnc0RfZMeohDbD9cZVdnl2fO1QVA6zIzqot03Xh3BjCBTMD+6VihYlpkaU4mAc0xivZsLcAsgA2ADvvT7VOsWhKpBUaa1y1PEB9Vw71G7A2F31BIOoEzDqRUMrHe0AYvuZ4p0TGqo8KtVKLydY3SsUIL1T4UAeWG5IrrOo7x0p7R/5k/0Yqr+LEO/a1zvhiU8CdGtp7I3uhgufwQsH/zeuOWqg3jWn6iznynDWZJO+Ot/vj1ALF3V/aabLzLl;20:xgDBn9d9iRtIzzveyCh1n6eGoea6WNr6XS0XpNWPV1U++ok9RZfx1fzWdBccCmX4L/5rPnUJpQfPQaTvTwlDg6pJdZcQem2dxO3nL0uIUmyysa/+Z5b/FvpEhMuwWZIvjddBgiPw29MebCbM6f6KikGMr8LN3Gu11hjULDGHOpw= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 63936684-b87e-4ab5-2ed0-08d59db192ee x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0806; x-ms-traffictypediagnostic: DM5PR2101MB0806: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(180628864354917)(20558992708506)(89211679590171)(190383065149520)(211936372134217)(42068640409301)(153496737603132)(104084551191319)(146099531331640); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(3231221)(944501327)(52105095)(93006095)(93001095)(10201501046)(3002001)(6055026)(61426038)(61427038)(6041310)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(20161123558120)(6072148)(201708071742011);SRVR:DM5PR2101MB0806;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0806; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(39860400002)(376002)(396003)(366004)(39380400002)(199004)(189003)(2906002)(25786009)(2501003)(10290500003)(476003)(11346002)(446003)(97736004)(5250100002)(68736007)(2616005)(102836004)(6506007)(59450400001)(3846002)(3660700001)(486006)(3280700002)(305945005)(6666003)(99286004)(5660300001)(76176011)(7416002)(1076002)(186003)(26005)(7736002)(6116002)(81156014)(81166006)(86612001)(4326008)(105586002)(10090500001)(2900100001)(54906003)(22452003)(316002)(36756003)(110136005)(107886003)(8676002)(6436002)(478600001)(53936002)(66066001)(6486002)(6512007)(6306002)(575784001)(86362001)(966005)(14454004)(72206003)(8936002)(106356001)(22906009)(41533002)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0806;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: QfP3P+4Wb0f4kAoWKI7O09LT7ViUi/Fpq19nxviYCiX2ubMxdCFc+8kTjFI2S212DKU7kPmyFzj6Lqy+I2e+GIpZT8PSKVG2XGv+dPJTEkrVgAAxe12xd+MMvPOB7ja1jzlP7FgYdty6rJpKO/n1unov64Hne7+ZkTCkDZgfcFIBPlreMIph7/VsCoKgNSsAW8iBZaKIPpmeZF/qDUuyHjvePwHoOHARN00TnN/fEotD8zTBwQUz7Ip3cYM/Qooy1C//wQLrmOgYzWOeiKLnnzL7EgIjdC5Et2+QrBz9MubqmVDG/YOQp8SYO6grLIgXm5FyBaoB23hjCxlPEMWN3NwOAMvlieHyffOKAG+ve3p9HDOC8XvGHmYhrbfLiknfMO5KBGdvr7T+LZvZG63uZlvGdRxCz4ANDzWfz7Ll1z8= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 63936684-b87e-4ab5-2ed0-08d59db192ee X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:26:16.6132 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0806 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- include/asm-generic/pgtable.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h index f6ea0f3c03f8..4e8551c8ef18 100644 --- a/include/asm-generic/pgtable.h +++ b/include/asm-generic/pgtable.h @@ -234,6 +234,21 @@ extern void pgtable_trans_huge_deposit(struct mm_struc= t *mm, pmd_t *pmdp, extern pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *= pmdp); #endif =20 +#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 ca= se we + * can't race with CPU which sets these bits and non-atomic aproach is fin= e. + */ +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 =3D *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 addr= ess, pmd_t *pmdp); --=20 2.15.1