Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp5267385pxu; Tue, 22 Dec 2020 12:18:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJyNb+/EOJJl/fso1wLaButlZiLpOe6Z4uXCHZURTvaK/Ef9KRfguDMJ9NXxlVW3RXblOx/P X-Received: by 2002:a17:906:d209:: with SMTP id w9mr20538839ejz.211.1608668331088; Tue, 22 Dec 2020 12:18:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608668331; cv=none; d=google.com; s=arc-20160816; b=KhJpaaXwONNWersbNTDmc1RyYOMLQaE3Was0K+WFWKxJBHocU9j0KmV5pIUtLfNgMe LjR7v5zpuw4R9dz1qoccEuFdWMmQxRugwTkqGP0F/7AnPXstS+7Qe2RIZvAO/q9m4GBJ MKNzxPuAKJ5dajoRlIulOdcwcZPfgu67W030LviUMBn9DGiKzmoJz8703gfGiYcJUrnm L3pFaQNgpmP1Umz50C+4SqTQP3CHHZ3ZmGtNKwSl+76k0kjkRSblwYjdNWWbuHfODajJ 5k4HzVoOXnZjLTkTllD/kZ/Ski81c5meACbYCs7U9I/EkE5+csLIBgKZcBL2FGqiY4sC bFRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Eb4oYoqAZRfDz+/ydpDOyvDen++mgZRQ1xf6qRXS0jM=; b=taqPhn20Sjw24VSA7H3hxFvVT/cdrx3hjOVRnPRCHFfvLp0sU3uspDuEEdSnAUfLAY AUPI4yw01NbSZIqJ7v7LHPhFveX9EpqSa5IkxBz5JlIMkTGvwDGAKRkD9NUMLo4iHvNn So1n/rCzB9GNh+qjIWBc3LQxttvaO8Y5mYSRqZ36F1xEUwhf3c9CVcycjTWYpitE+wSW dqRUDoi/3Eyz3ifhqicw7Tkp2f6yzQIhSjs4/f0zG2LrcVf9kqizyIVL3MVNQH+pK7mK 4ng4kaVK4M0PJ9QwgT7CZFKmLqgttWPJkutAmMD74YwOUa9SQ5oAzrfsQB1F25QtckH3 9lEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=Kihezujl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z1si4149447eji.695.2020.12.22.12.18.28; Tue, 22 Dec 2020 12:18:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=Kihezujl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727756AbgLVUQs (ORCPT + 99 others); Tue, 22 Dec 2020 15:16:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725850AbgLVUQr (ORCPT ); Tue, 22 Dec 2020 15:16:47 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F79CC0613D3; Tue, 22 Dec 2020 12:16:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Eb4oYoqAZRfDz+/ydpDOyvDen++mgZRQ1xf6qRXS0jM=; b=Kihezujl/NgUHtFjqSIBp8508s psorRppd6ox/i/CY4WCRNyeLoeD57xRUpTBde984iYXHEW1IxLx/H7a+kbfXZH2dEJGBMz66om6Po hVa523arlguvIchso5pVuVWOKfffwBthl4KDEeAMBnA/TnLCa96oDvgYur1Kc/5leh366YtOIdxlU flB5B4SVpg5sN80NPoDn75QhtxTgbaPrGXPj+wHLnGwuZ1opwVBYcWtfmftnPMDowDOtB2bKZRgeJ pkPpyqCsTR3dYQYTG6bD4CZH/VLVhLb4Ma/hnZtbTUmSc5vEuxEUK5BCYhnPmU0FBHmKrbLcWQDz/ /AzjaH/g==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kro4X-0002uj-Ti; Tue, 22 Dec 2020 20:15:54 +0000 Date: Tue, 22 Dec 2020 20:15:53 +0000 From: Matthew Wilcox To: Andrea Arcangeli Cc: Andy Lutomirski , Linus Torvalds , Peter Xu , Nadav Amit , Yu Zhao , linux-mm , lkml , Pavel Emelyanov , Mike Kravetz , Mike Rapoport , stable , Minchan Kim , Will Deacon , Peter Zijlstra , Kent Overstreet Subject: Re: [PATCH] mm/userfaultfd: fix memory corruption due to writeprotect Message-ID: <20201222201553.GM874@casper.infradead.org> References: <9E301C7C-882A-4E0F-8D6D-1170E792065A@gmail.com> <1FCC8F93-FF29-44D3-A73A-DF943D056680@gmail.com> <20201221223041.GL6640@xz-x1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 22, 2020 at 02:31:52PM -0500, Andrea Arcangeli wrote: > My previous suggestion to use a mutex to serialize > userfaultfd_writeprotect with a mutex will still work, but we can run > as many wrprotect and un-wrprotect as we want in parallel, as long as > they're not simultaneous, we can do much better than a mutex. > > Ideally we would need a new two_group_semaphore, where each group can > run as many parallel instances as it wants, but no instance of one > group can run in parallel with any instance of the other group. AFIK > such a kind of lock doesn't exist right now. Kent and I worked on one for a bit, and we called it a red-black mutex. If team red had the lock, more members of team red could join in. If team black had the lock, more members of team black could join in. I forget what our rule was around fairness (if team red has the lock, and somebody from team black is waiting, can another member of team red take the lock, or must they block?) It was to solve the direct-IO vs buffered-IO problem (you can have as many direct-IO readers/writers at once or you can have as many buffered-IO readers/writers at once, but exclude a mix of direct and buffered I/O). In the end, we decided it didn't work all that well.