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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31326C433EF for ; Mon, 21 Mar 2022 16:15:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5F8C96B0071; Mon, 21 Mar 2022 12:15:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5A7BF8D0001; Mon, 21 Mar 2022 12:15:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 449D56B0074; Mon, 21 Mar 2022 12:15:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0045.hostedemail.com [216.40.44.45]) by kanga.kvack.org (Postfix) with ESMTP id 35AD56B0071 for ; Mon, 21 Mar 2022 12:15:12 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id E5A829F33D for ; Mon, 21 Mar 2022 16:15:11 +0000 (UTC) X-FDA: 79268892822.29.94FD8BD Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf12.hostedemail.com (Postfix) with ESMTP id 8BE8740035 for ; Mon, 21 Mar 2022 16:15:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647879310; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GWSu+Df1NTcRHn2JTsvvlDbbrD7r44W7HRjFAAjbrvk=; b=O42V1jWJCFSVaPS3LUSZDMHijhFay5vrdBt/irpHhZ7BpCrlUGkgmvjBlP1oSwrziPMmQI 7DfAhxxEnBgyZWf+JKzs1UlrXPLcKOp53KHs01Sj80wtm4MAKj/5jB6xPfVst0ClwPoKjA o5ODPPj9ZnQgyYeldYRD091zXzVdSAE= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-641-suqCknDLOs-SOz44Q0EW6g-1; Mon, 21 Mar 2022 12:15:09 -0400 X-MC-Unique: suqCknDLOs-SOz44Q0EW6g-1 Received: by mail-wr1-f72.google.com with SMTP id h11-20020a5d430b000000b001f01a35a86fso3235961wrq.4 for ; Mon, 21 Mar 2022 09:15:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:organization:in-reply-to :content-transfer-encoding; bh=GWSu+Df1NTcRHn2JTsvvlDbbrD7r44W7HRjFAAjbrvk=; b=OLJCGvhk+DcuZxykj5CJwyZcAJu5Jo56cS5oYGl0WrbI1nhAkQEPjIjakM7NoXFn8q IOw6ddRgIyNfMCbp9IMsMN30/webXcAHz7P0GLp44k1bIYEm4O5xtQ/2qHGJ42xXxd9d qWGIOf1en0h5b2BgsMkQJoTG/WaE9TNIFeZu6URkK/Mw050xjRrjhCB9ot4YneoitXhS XzGnnQGsTgdtU2m69O03tIkbYkSql26QXS9Kv4UnqUtTCmCOTdLUJ8eQWlu3MgoqFFzj BE38NaxROeenfxxYzMfavOmz3/l5pi0selyjp66PELPu4uq+eIFhXnI18+qmQJgam5KH La3A== X-Gm-Message-State: AOAM533JLVPf329l1/zVHzfTiebyWGbL1BjNRuhGAFJOi/Lev1Qojhf3 toU+ZOGz7noBCUbGoaJVmxMuK9WwLP6Ux91FCZClQrUx1olkkZvZzIiBqFOzazIHYubz+YOeTf7 08Ayl8DS47G0= X-Received: by 2002:a7b:c186:0:b0:38c:75ea:4903 with SMTP id y6-20020a7bc186000000b0038c75ea4903mr20053737wmi.176.1647879308340; Mon, 21 Mar 2022 09:15:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9vbmXdlBs0qYvMyCxjbPwPobTZnA/F1kYqtLCUimqr9jidJsAu8QnRnWfnBt0Bn3okiqO+Q== X-Received: by 2002:a7b:c186:0:b0:38c:75ea:4903 with SMTP id y6-20020a7bc186000000b0038c75ea4903mr20053707wmi.176.1647879308017; Mon, 21 Mar 2022 09:15:08 -0700 (PDT) Received: from ?IPV6:2003:cb:c704:4900:849b:f76e:5e1f:ff95? (p200300cbc7044900849bf76e5e1fff95.dip0.t-ipconnect.de. [2003:cb:c704:4900:849b:f76e:5e1f:ff95]) by smtp.gmail.com with ESMTPSA id p8-20020a5d59a8000000b00204178688d3sm2509795wrr.100.2022.03.21.09.15.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 21 Mar 2022 09:15:07 -0700 (PDT) Message-ID: Date: Mon, 21 Mar 2022 17:15:06 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.2 Subject: Re: [PATCH v2 13/15] mm: support GUP-triggered unsharing of anonymous pages To: Jason Gunthorpe Cc: linux-kernel@vger.kernel.org, Andrew Morton , Hugh Dickins , Linus Torvalds , David Rientjes , Shakeel Butt , John Hubbard , Mike Kravetz , Mike Rapoport , Yang Shi , "Kirill A . Shutemov" , Matthew Wilcox , Vlastimil Babka , Jann Horn , Michal Hocko , Nadav Amit , Rik van Riel , Roman Gushchin , Andrea Arcangeli , Peter Xu , Donald Dutile , Christoph Hellwig , Oleg Nesterov , Jan Kara , Liang Zhang , Pedro Gomes , Oded Gabbay , linux-mm@kvack.org References: <20220315104741.63071-1-david@redhat.com> <20220315104741.63071-14-david@redhat.com> <20220318233035.GA11336@nvidia.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: <20220318233035.GA11336@nvidia.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 8BE8740035 X-Rspam-User: Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=O42V1jWJ; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf12.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=david@redhat.com X-Stat-Signature: bw1m789zexxuo6p1cxie6bewyzbizoz4 X-Rspamd-Server: rspam04 X-HE-Tag: 1647879310-158985 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 19.03.22 00:30, Jason Gunthorpe wrote: > On Tue, Mar 15, 2022 at 11:47:39AM +0100, David Hildenbrand wrote: >> Whenever GUP currently ends up taking a R/O pin on an anonymous page that >> might be shared -- mapped R/O and !PageAnonExclusive() -- any write fault >> on the page table entry will end up replacing the mapped anonymous page >> due to COW, resulting in the GUP pin no longer being consistent with the >> page actually mapped into the page table. >> >> The possible ways to deal with this situation are: >> (1) Ignore and pin -- what we do right now. >> (2) Fail to pin -- which would be rather surprising to callers and >> could break user space. >> (3) Trigger unsharing and pin the now exclusive page -- reliable R/O >> pins. >> >> We want to implement 3) because it provides the clearest semantics and >> allows for checking in unpin_user_pages() and friends for possible BUGs: >> when trying to unpin a page that's no longer exclusive, clearly >> something went very wrong and might result in memory corruptions that >> might be hard to debug. So we better have a nice way to spot such >> issues. >> >> To implement 3), we need a way for GUP to trigger unsharing: >> FAULT_FLAG_UNSHARE. FAULT_FLAG_UNSHARE is only applicable to R/O mapped >> anonymous pages and resembles COW logic during a write fault. However, in >> contrast to a write fault, GUP-triggered unsharing will, for example, still >> maintain the write protection. > > Given the way this series has developed you might want to call this > FAULT_FLAG_MAKE_ANON_EXCLUSIVE > > Which strikes me as more directly connected to what it is trying to > do. I thought about something similar along those lines, and I think it would apply even when extending that mechanism to anything !anon inside a MAP_PRIVATE mapping. The whole const bool unshare = vmf->flags & FAULT_FLAG_UNSHARE; would get a little more verbose, though const bool make_anon_exclusive = vmf->flags & FAULT_FLAG_MAKE_ANON_EXCLUSIVE; No strong opinion, any other opinions or alternatives? -- Thanks, David / dhildenb