Received: by 10.213.65.68 with SMTP id h4csp2118056imn; Sun, 8 Apr 2018 20:09:17 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/Ah58r0wNpSLTEZsXnxUq/cCKkrJNdvhdCIl242e2C9+0mJBIvtQcwO0vZBTAbrCJ8kYvN X-Received: by 2002:a17:902:7894:: with SMTP id q20-v6mr37470718pll.86.1523243357183; Sun, 08 Apr 2018 20:09:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243357; cv=none; d=google.com; s=arc-20160816; b=rPCwZtPSsFU6uVVA4HdoPmiMVlFKqmMFDv5UakC+TtUu64VCD/Gj24iaexzwCoVIFw tirhwz4/KBU12Pwfdit6L/DKEIFy+8Rz0s2g21bQL5AInUZrbz9VoJnoHVkK9dKdwHxb uRYXVzquqSCRv4m/PbIofE6QAX1/vlEDU21jThclYFGxbHpU5/FfGQB+9TksPBxW/VJI QQYlpXSAxIWOBngkU1XBM4VknkFpns76tuJJNUpHIA2Zolxd4AtP2gOLAx5Cf3nvh59p R53B8t59Hu7QMox4CiaOL5xgmd7s3Be7LxpT25tQZR4RHtVD2oCYvFPujSLVi2uoNwCU NIdw== 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=UR+hyys3ehhCBStH+JzvzUmSoWiuhwbvfRTrqdkSfY0=; b=l6G72ZzdGVFpQuynvDinACXer7TKV7xTzFFfTaxj0oiZhw8ocibtV6clroCk0Acf9Z EV7w5QSJQiINKvf0MyeH9nOYLGQfZxsiOQY/CuSw2dkLhUrW2EMKdXJHTvXhJpn5vKpo 7bNIH89x0wjRr98rgSvl7Z6uRwp72QzidIoavTwu6t/SkmW8kDDGPI54OifQBAH5BokQ Dzm1/bv14Dv8Q1QkCDquSDfddC0gr+BBDwHWPaooQpI6EQosXr+L1T90XdnfgbAElHKb xVkOq3Fy0ozKsFXZx/+yFem1cKyvkX4+DVgy7ALz+1LxwyHamWipe+F/COZimC3EV5px Hm9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=MmH6fEgX; 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 f13si8766262pgp.666.2018.04.08.20.08.40; Sun, 08 Apr 2018 20:09:17 -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=MmH6fEgX; 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 S1757023AbeDIBJP (ORCPT + 99 others); Sun, 8 Apr 2018 21:09:15 -0400 Received: from mail-co1nam03on0120.outbound.protection.outlook.com ([104.47.40.120]:40064 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933028AbeDIAir (ORCPT ); Sun, 8 Apr 2018 20:38:47 -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=UR+hyys3ehhCBStH+JzvzUmSoWiuhwbvfRTrqdkSfY0=; b=MmH6fEgXZv1AkCquV6XwBUFNalAUJnzz35g+fEWJ6GqZGJJFGSMjIkygjKrIT+z0pE48M2N7ionL8iJDES9VQ+Hv42do8Zr1nFaeZvJXy6QLIJKi/0mZS757ecHGLu0N/WPou5XRvpi0Xws5K6eq7jmVB7JHt8oZ/4MRXBNcK58= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1125.namprd21.prod.outlook.com (52.132.130.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:38:42 +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:38:42 +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.4 141/162] asm-generic: provide generic_pmdp_establish() Thread-Topic: [PATCH AUTOSEL for 4.4 141/162] asm-generic: provide generic_pmdp_establish() Thread-Index: AQHTz5nXr8zZBffnAU+/Ufrota+3Ww== Date: Mon, 9 Apr 2018 00:29:38 +0000 Message-ID: <20180409002738.163941-141-alexander.levin@microsoft.com> References: <20180409002738.163941-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002738.163941-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;DM5PR2101MB1125;7:SO/DqMWU/E2edGgG9FHHcDPjCUDOFp+HiFCKJWjam0in0eieE1IpI7kppl2Dus4nYgLuKNXw/J3dPQPNRfWhiXRTNRqh2C/FWkBLaX4mXsKa4ZP6Znp64UP3IGGBrVRgTo+S0VRwhP1kui9n7sFnXAsesOAP7xzwyiF6K3sGB5kEUSSbRUb5LmQ1Ym0hZm9gNvRqgqxTM8A4sTqqTwktSJIbTo6Sfbqx/tWPy7ye/soISwAxhOciK44opzlvXPSg;20:IANdjCCLmu90Wj8s6FFZy4mqd8v5tAf1ynjeuLuJdNjtEBalgrN0DHGP5kZLdtSz20XLHjqBk+TjnqeEzkh4JXLSxW4K1hol8PWuIdXezqKqWWmAs4dOG9IzmuFUlcGFUvtO8Y2wYXLnoXplIYxwI+6+sZJeyyy27rrtU4hY42c= X-MS-Office365-Filtering-Correlation-Id: 44fc20ed-68e5-4bd2-9139-08d59db23ea8 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(3008032)(48565401081)(2017052603328)(7193020);SRVR:DM5PR2101MB1125; x-ms-traffictypediagnostic: DM5PR2101MB1125: 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)(3002001)(93006095)(93001095)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123560045)(20161123564045)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM5PR2101MB1125;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1125; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(39860400002)(39380400002)(366004)(376002)(396003)(189003)(199004)(2906002)(25786009)(6512007)(10090500001)(3280700002)(10290500003)(6666003)(6306002)(3660700001)(316002)(110136005)(54906003)(11346002)(107886003)(2616005)(476003)(446003)(36756003)(7416002)(99286004)(86612001)(53936002)(4326008)(486006)(6436002)(3846002)(81156014)(305945005)(966005)(5250100002)(1076002)(102836004)(14454004)(66066001)(7736002)(105586002)(81166006)(59450400001)(106356001)(8676002)(97736004)(6116002)(6506007)(6486002)(5660300001)(186003)(76176011)(22452003)(72206003)(478600001)(2501003)(2900100001)(26005)(86362001)(575784001)(8936002)(68736007)(22906009)(41533002)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1125;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: 66r2XezClPjhjYhPvn1wjhD5Lx7OzzlsxI/I/TCWWwlaVeWabeFXYONzWUngmy5mnfa9Ja7vnnGPRmbG3y5pAHGvqKKzqEhy4HusDkR+MQsRG10NiIIVz5+jiA1QbzcjliCWvctd7K1wo+DeFdqZEWZAtvQcUUGcEK9xCE52Ty3Dg13vqoV5vTAYgd7TzHZdG83+4lPYJq4c/Wh0YQ0DuGvM7tT1oaLH52NyPNgEeAT4ITBFtl2yMJNon1gQ5JOJMxmgAS62pCsjGcSabpKSjru7Zrw0FkWZe49WjcC49QfjgD8F8tSNy+XSelsXa/eSIKMm8FuSwR8h2BSRvKmvFpbRyGqW4iZjX73HvAQ1nWps1D7pYYxRmaMV8dnwi/xIGGxBZnF2hVGIAaP91xS0q8HwkbizgFUNZoGAqccoQ48= 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: 44fc20ed-68e5-4bd2-9139-08d59db23ea8 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:29:38.2870 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1125 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 4814cf971048..25b793325b09 100644 --- a/include/asm-generic/pgtable.h +++ b/include/asm-generic/pgtable.h @@ -237,6 +237,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