Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3259784pxk; Mon, 28 Sep 2020 12:32:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyX3dbaQ9Pz/KIkmTDj5XCLmMSuL1cIxSeXt/lO0jTRzWs9bmGFfUx8bEmOLV0KFq9pJNbw X-Received: by 2002:a50:fe07:: with SMTP id f7mr3686303edt.173.1601321543024; Mon, 28 Sep 2020 12:32:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601321543; cv=none; d=google.com; s=arc-20160816; b=xlQPCLdr+YOg+aoM2eI/eTtWvz0shc6sSVZ6hFxY/EUvZVpl+oIdF0eam2HHuph5Hd qegKP1Tde1o3TMxAR/LTQVmYI0GVMyDuU1z6ApHoCQDBcRYmQa14Q9nTXTGnX96qwIY0 HY8M5IcfS37yD5aLtVhiDK/QuHgFFkrHiTvrJTfhUen7KdovJL3AD3fjb85G1kVPTAP0 uFTTeUdpixeJU5PADIdNzwFDbPpaQpwbBvRMjINurbFKEWtcWT3TRx94O5oYV8o15ypl vgzZ2+2z7VyvYqR31c4/BYyJILj5y8UYhftjBCRVRoLlmEJW92aiGnG6dnjjSPoOi0cF 4blw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=wY4Gq79q0P/2bX+CuESc1n2E6IaS6wqp2Rm0+ZTB6Q0=; b=0YV+niGdtoJDS513vsY84JXrk437fgoPvMR2U8Hjc8soyAgVXgxFBivNyqR7ysXR6A J0OxYREg8ZX2ZQvq9Gct35zJ1YbzOyvfY8eTeouzYL4xETiEUBUSWYpNt6U1EGs74LQM OzYhbq/WWEqGsLHea/pJj8VCNbcBL/JFM3cG1uqdFHzEIXvWImrkS69GIXLsJBMVliMC kATZpBFS5tR57nJ3Ygx/EM60EQqCq/Sr8k0FrR7+OX8JXXPh67i9lrHeVY9lLSWJurS0 HUdq4+avssxZe0zEGsZN0vafw+sVKkv4qRu3tEHLWZs8iwmVSjULphw4aOp5hHgq+JYX PRBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=de4GMA4Q; 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 h6si1178588ejx.417.2020.09.28.12.31.59; Mon, 28 Sep 2020 12:32:23 -0700 (PDT) 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=@linux-foundation.org header.s=google header.b=de4GMA4Q; 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 S1726734AbgI1TaR (ORCPT + 99 others); Mon, 28 Sep 2020 15:30:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726565AbgI1TaR (ORCPT ); Mon, 28 Sep 2020 15:30:17 -0400 Received: from mail-lj1-x244.google.com (mail-lj1-x244.google.com [IPv6:2a00:1450:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0B59C061755 for ; Mon, 28 Sep 2020 12:30:16 -0700 (PDT) Received: by mail-lj1-x244.google.com with SMTP id v23so1996830ljd.1 for ; Mon, 28 Sep 2020 12:30:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=wY4Gq79q0P/2bX+CuESc1n2E6IaS6wqp2Rm0+ZTB6Q0=; b=de4GMA4QpsyK1q3+qSjbj6c/bLM77xIl2+5sVk0F/tdoa8BfjO8UHtRwPAqhaCHHUk 3uuZoHZ6nnGsdkuYJCmNPv8mLzeOXJVMpSpnADjB0rjFW0XGsiRnswMvG/RD1vL90qBW 9kJvFSyX6yVkV/XpEYZh26BJn07eZw9TlrY9s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=wY4Gq79q0P/2bX+CuESc1n2E6IaS6wqp2Rm0+ZTB6Q0=; b=ScyKu90qFzke7cshu94RaxTkZ3Rq1YDaGEMbZe8sJtk4p7x9QKA8DR7gqEi294rXfh 1XBwyOI9MKB7HjHCS4SW8bdxXz3ji8g4iqcXnbVXx33bRNwhjPFHHpffeRCpQfOgaaQQ /FzjQmsRQiuQyWCjwRanYmjZTpEhNhjhdQIeltpc/0dEKKoo6iCAgFFOYYHU6lbQfZe2 KWDkxh+DMnJB9E+yvsGH8epcZZTQDB02iLdekY2UjBPfToSP1cT6rARomtlNf+lWagZu Y8VLZH7R01Eg/JUMslfbKtq8WlfcbGSpLwGIDdjO6k+bRINpw78StSBllk9DBDpBekMU FePw== X-Gm-Message-State: AOAM532HeqTpYc9x6dJ+L+O4AeidhYdqOE0nD3S/Qm0+IWR6hGAuyBai vcc2+ngqAN/cqa7Y1od5O70BCtfJQq0wgA== X-Received: by 2002:a2e:2244:: with SMTP id i65mr34914lji.185.1601321414584; Mon, 28 Sep 2020 12:30:14 -0700 (PDT) Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com. [209.85.167.41]) by smtp.gmail.com with ESMTPSA id g74sm2918715lfd.152.2020.09.28.12.30.12 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 28 Sep 2020 12:30:13 -0700 (PDT) Received: by mail-lf1-f41.google.com with SMTP id m5so2662939lfp.7 for ; Mon, 28 Sep 2020 12:30:12 -0700 (PDT) X-Received: by 2002:ac2:4a6a:: with SMTP id q10mr899873lfp.534.1601321412324; Mon, 28 Sep 2020 12:30:12 -0700 (PDT) MIME-Version: 1.0 References: <20200926004136.GJ9916@ziepe.ca> <20200927062337.GE2280698@unreal> <20200928124937.GN9916@ziepe.ca> <20200928172256.GB59869@xz-x1> <20200928183928.GR9916@ziepe.ca> In-Reply-To: <20200928183928.GR9916@ziepe.ca> From: Linus Torvalds Date: Mon, 28 Sep 2020 12:29:55 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/5] mm: Introduce mm_struct.has_pinned To: Jason Gunthorpe Cc: Peter Xu , Leon Romanovsky , John Hubbard , Linux-MM , Linux Kernel Mailing List , Andrew Morton , Jan Kara , Michal Hocko , Kirill Tkhai , Kirill Shutemov , Hugh Dickins , Christoph Hellwig , Andrea Arcangeli , Oleg Nesterov , Jann Horn Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 28, 2020 at 11:39 AM Jason Gunthorpe wrote: > > I prefer the version where read pin and write pin are symmetric. The > PTE in the MM should not change once pinned. The thing is, I don't really see how to do that. Right now the write pin fastpath part depends on the PTE being writable. That implies "this VM has access to this page". For a read pin there simply is no other way to do it. So we'd basically say "fast read pin only works on writable pages", and then we'd have to go to the slow path if it isn't dirty and writable. And the slow path would then do whatever COW is required, but it wouldn't mark the result dirty (and in the case of a shared mapping, couldn't mark it writable). So a read pin action would basically never work for the fast-path for a few cases, notably a shared read-only mapping - because we could never mark it in the page tables as "fast pin accessible" See the problem? A read-only pin is fundamentally different from a write one, because a write one has that fundamental mark of "I have private access to this page" in ways a read one simply does not. So we could make the requirement be that a pinned page is either (a) from a shared mapping (so the pinning depends on the page cache association). But we can't test this in the fast path. or (b) for a private mapping we require page_mapcount() == 1 and that it's writable. but since (a) requires the mapping type, we can't check in the fast path - we only have the PTE and the page. So the fast-path can only "emulate" it by that "writable", which is a proper subset of (a) or (b), but it's not something that is in any way guaranteed. End result: FOLL_PIN would really only work on private pages, and only if you don't want to share with the page cache. And it would basically have no advantages over a writable FOLL_PIN. It would break the association with any backing store for private pages, because otherwise it can't follow future writes. Linus