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=-0.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED 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 A58E6CA9EBC for ; Thu, 24 Oct 2019 14:15:17 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5982320679 for ; Thu, 24 Oct 2019 14:15:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=Mellanox.com header.i=@Mellanox.com header.b="q7JPkZyv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5982320679 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=mellanox.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E68A46B0003; Thu, 24 Oct 2019 10:15:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E18CC6B0005; Thu, 24 Oct 2019 10:15:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CB8E26B0007; Thu, 24 Oct 2019 10:15:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0070.hostedemail.com [216.40.44.70]) by kanga.kvack.org (Postfix) with ESMTP id A0EC46B0003 for ; Thu, 24 Oct 2019 10:15:16 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 322EA82499A8 for ; Thu, 24 Oct 2019 14:15:16 +0000 (UTC) X-FDA: 76078875432.02.toad25_4afe2e1d96326 X-HE-Tag: toad25_4afe2e1d96326 X-Filterd-Recvd-Size: 9352 Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-eopbgr140041.outbound.protection.outlook.com [40.107.14.41]) by imf12.hostedemail.com (Postfix) with ESMTP for ; Thu, 24 Oct 2019 14:15:15 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Jdf4ja3owW56NM/ZVH9WuT3I8YKl6lrUf4hI4gHMgatudyKJuizPxzuR1iNR7E6voWqRCwfiN7aLAvoS7sh5peHJvTmEGrGxXa1YP3CwADta0dDESHN6m19DG6bqfG/21tqD3ULPyt8CcTGuDarmvlutooLUHYheZWYwNocnC9u+SlJilyvvQqnsikRp9uYc6wcW0Co+cXBRj/Xn40d+vdU81+HhrY8c20bepkklCPN1YDK0Uhp0++Kw3bWjba1AWihyzEJbnNwVy8I/hxcEQt0Z0WI7p5SJaL0jbbRgKJL+64gqSoKkdS+bcTHYtbyHcxwZlupw9UHSSTInRn1QlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bkr+TocUZ98FyzPsgLcTGRsZD//ce2Ta+Jb6aPW16z8=; b=muxaDO7ZHBiu7WQxTM0sFaX553XW+j0HFJefbeIfafcCMzNrTQWC8GvkkuLgOA2ReWrVY8IX1OnKpyo4gxHCRjQPbA/1sxOd79O8xWRKbwGLKFCOzfWomIdkyVJcbfnh8iIeD0276BF5V71lRb476gH3d7B+YhXjgKOV3GVnPn/IUmrWxgrbTcIWLEw+tGnM+OJA2NeMyF4QTlmG48UqpK/pWZRLZDaWQp1EkrTUcpeBOnmG5uRzC8Z/ArpARMbfoJu6NZU/4jvLwtM/AF89UVdJ23w9IYUjh25qZ8/oNEmxkzfWj2ZoDuy8q/0QlmimQz9xP7WH5mElrtBMbdVzBg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=mellanox.com; dmarc=pass action=none header.from=mellanox.com; dkim=pass header.d=mellanox.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bkr+TocUZ98FyzPsgLcTGRsZD//ce2Ta+Jb6aPW16z8=; b=q7JPkZyv8t+T+7FmAW0RavllJeBHPL3ZKyXwAjIgkfT6Tg+DBDvcRZP3Oa3O4t7p4mr33gQV13BgreQJiMkeg7dcT5FrJZrYrpzS64/REgRugsy9cpzU0M9afnT/WuGc8+/rQV2puoYaeRZRBYrquX0TUJVecEBp09Ue0z3H5BE= Received: from VI1PR05MB4141.eurprd05.prod.outlook.com (52.133.14.15) by VI1PR05MB5038.eurprd05.prod.outlook.com (20.177.52.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2367.24; Thu, 24 Oct 2019 14:15:12 +0000 Received: from VI1PR05MB4141.eurprd05.prod.outlook.com ([fe80::75ae:b00b:69d8:3db0]) by VI1PR05MB4141.eurprd05.prod.outlook.com ([fe80::75ae:b00b:69d8:3db0%7]) with mapi id 15.20.2367.027; Thu, 24 Oct 2019 14:15:12 +0000 From: Jason Gunthorpe To: Michal Hocko CC: "linux-mm@kvack.org" , =?iso-8859-1?Q?J=E9r=F4me_Glisse?= , Andrea Arcangeli , Christoph Hellwig Subject: Re: [PATCH] mm/mmn: prevent unpaired invalidate_start and invalidate_end with non-blocking Thread-Topic: [PATCH] mm/mmn: prevent unpaired invalidate_start and invalidate_end with non-blocking Thread-Index: AQHVTVSfVNc5Iz/dOkyoKdT7iQpJS6bw6QyAgAA/BwCAAAKMgIB5JZeA Date: Thu, 24 Oct 2019 14:15:12 +0000 Message-ID: <20191024141507.GF22766@mellanox.com> References: <20190807191627.GA3008@ziepe.ca> <20190808081827.GB18351@dhcp22.suse.cz> <20190808120402.GA1975@mellanox.com> <20190808121309.GD18351@dhcp22.suse.cz> In-Reply-To: <20190808121309.GD18351@dhcp22.suse.cz> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MN2PR05CA0032.namprd05.prod.outlook.com (2603:10b6:208:c0::45) To VI1PR05MB4141.eurprd05.prod.outlook.com (2603:10a6:803:44::15) authentication-results: spf=none (sender IP is ) smtp.mailfrom=jgg@mellanox.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [142.162.113.180] x-ms-publictraffictype: Email x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: c942b67e-4c8f-4f3e-4aaa-08d7588c9595 x-ms-traffictypediagnostic: VI1PR05MB5038: x-ms-exchange-purlcount: 1 x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:9508; x-forefront-prvs: 0200DDA8BE x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(4636009)(346002)(396003)(136003)(366004)(39860400002)(376002)(189003)(199004)(7736002)(6116002)(6486002)(3846002)(476003)(305945005)(966005)(486006)(1076003)(86362001)(71200400001)(71190400001)(36756003)(54906003)(33656002)(14454004)(99286004)(76176011)(66946007)(52116002)(66476007)(66556008)(64756008)(66446008)(6306002)(4326008)(229853002)(8936002)(8676002)(25786009)(386003)(5660300002)(186003)(6506007)(81166006)(81156014)(6436002)(102836004)(316002)(6916009)(6512007)(256004)(14444005)(2906002)(11346002)(2616005)(446003)(6246003)(478600001)(66066001)(26005);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR05MB5038;H:VI1PR05MB4141.eurprd05.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 8jTEbU7axyUHJOCE5YYEAUOOGe5dK9RNXqomUoZlqn5r27GuHYMvnxtGTzxebPwlCxXe2TM/xICOc1ScOrUPZUK+TzM6iwlYOYR7w7YwdoQQ7FLhSQke6AXio6rCk+76rjAycty/v3mk2jQ/TpF5cuSbC7T2s6bCskwK2aYfpzCACphF7No3xPK6hnFJKv6hiGU1cqpaoxHLTq64bKXLColL5+LDGQprIwmAfcwJRPzgnrufOHVNkOiu0JQXONV1DPro9PnEcu0k2BPbdVO0AYrSW28zkGH5uAFCPJozDID0ApazCLJwK0mqS8tbPmZZFdL/ncDFnwbrkBT/rzHQRp+YofQRGly/kE17f8mp7lUPTICcipnlc1yBLGE2BbUg/J7I1HwgPBfN9Vf7eM4ovojH8DUypOj3rgAsERpESPZeJULfFXYdkKOqVN7dVGKUTofCWLp+4FqeSL/LW7Y3boaFD9BsCegPpeR8qt5JT2k= x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="iso-8859-1" Content-ID: <54F6AA059B1EB040ACDF599D0BC88698@eurprd05.prod.outlook.com> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: c942b67e-4c8f-4f3e-4aaa-08d7588c9595 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Oct 2019 14:15:12.7047 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: DHiOuBGiUoJpKGWZmD/BjVFgCUz6KmaXT0qoPC/7xlFL42CC1PjZtUggV1IMplPUPVz2wD4Ur2oKSRWicAaWyA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR05MB5038 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, Aug 08, 2019 at 02:13:09PM +0200, Michal Hocko wrote: > On Thu 08-08-19 12:04:07, Jason Gunthorpe wrote: > > On Thu, Aug 08, 2019 at 10:18:27AM +0200, Michal Hocko wrote: > > > On Wed 07-08-19 19:16:32, Jason Gunthorpe wrote: > > > > Many users of the mmu_notifier invalidate_range callbacks maintain > > > > locking/counters/etc on a paired basis and have long expected that > > > > invalidate_range start/end are always paired. > > > >=20 > > > > The recent change to add non-blocking notifiers breaks this assumpt= ion > > > > when multiple notifiers are present in the list as an EAGAIN return= from a > > > > later notifier causes all earlier notifiers to get their > > > > invalidate_range_end() skipped. > > > >=20 > > > > During the development of non-blocking each user was audited to be = sure > > > > they can skip their invalidate_range_end() if their start returns -= EAGAIN, > > > > so the only place that has a problem is when there are multiple > > > > subscriptions. > > > >=20 > > > > Due to the RCU locking we can't reliably generate a subset of the l= inked > > > > list representing the notifiers already called, and generate an > > > > invalidate_range_end() pairing. > > > >=20 > > > > Rather than design an elaborate fix, for now, just block non-blocki= ng > > > > requests early on if there are multiple subscriptions. > > >=20 > > > Which means that the oom path cannot really release any memory for > > > ranges covered by these notifiers which is really unfortunate because > > > that might cover a lot of memory. Especially when the particular rang= e > > > might not be tracked at all, right? > >=20 > > Yes, it is a very big hammer to avoid a bug where the locking schemes > > get corrupted and the impacted drivers deadlock. > >=20 > > If you really don't like it then we have to push ahead on either an > > rcu-safe undo algorithm or some locking thing. I've been looking at > > the locking thing, so we can wait a bit more and see.=20 >=20 > Well, I do not like it but I understand that an over reaction for OOM is > much less of a pain than a deadlock or similar misbehavior. So go ahead > with this as a stop gap with Cc: stable but please let's do not stop > there and let's come up with something of a less hamery kind. >=20 > That being said, feel free to add > Acked-by: Michal Hocko > with a printk_once to explain what is going on and a TODO note that this > is just a stop gap. I didn't resend this pending how the mmu notifiers rework would look. With this patch: https://patchwork.kernel.org/patch/11191423/ Users of the new mmu_range_notifiers can safely share and handling !blocking failures. They also reliably limit their influence for OOM to a specific VA range without taking blocking locks, as desired. I intend to resend this patch, with the warning, with the thinking that all the cases involving sharing notifiers are likely to have been moved to the mmu_range scheme. Does this seem reasonable? Would you look through the above? Thanks, Jason