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 25000C77B7C for ; Wed, 24 May 2023 07:06:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 263326B007B; Wed, 24 May 2023 03:06:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 213516B007D; Wed, 24 May 2023 03:06:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0DCAE900002; Wed, 24 May 2023 03:06:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id F29AF6B007B for ; Wed, 24 May 2023 03:06:44 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id BCBBEA08B1 for ; Wed, 24 May 2023 07:06:44 +0000 (UTC) X-FDA: 80824265928.18.C79A0AC Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf01.hostedemail.com (Postfix) with ESMTP id 4C17040007 for ; Wed, 24 May 2023 07:06:42 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HNqocnUU; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684912002; h=from:from:sender: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:dkim-signature; bh=LjhHjHBMY39aJuSZuOz+uNWhK5sxOn0xoRbBRqqPSZg=; b=mISWoS1Z3kDszWd5626Tm+/s7lh8Zv3OrpTbR3mLRi5GQgwFkSGJVsQhP4GrVCnTcOXdNu 694aulu1epR5Q2Ww5S7ohWDmcy07FPKCvpYPGYA3LSu00cCj6LjhqqUJQL0yfFaFUY+nVG a7u/yjMhZSfkIDvumNHkoC3vbJQkA/8= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HNqocnUU; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684912002; a=rsa-sha256; cv=none; b=PijhV7IemivYbhJDVMVWH+7mxwBqPt2JWe3byqu5reCpqufNIZqyLBusVrl6KfdJ4Vr/wq XPQrOusM7IExLU6jw+VDFOkx1174S2Dwu939f0X08fbOajo7C+1N8jZ6TD2kGQvzoGBCY6 XoHu11AUsh+mO/wbpEdSSyZ1wmTjecE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684912001; 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=LjhHjHBMY39aJuSZuOz+uNWhK5sxOn0xoRbBRqqPSZg=; b=HNqocnUUPsx81Rii0CrhS2I2Wrgc/kLK8Sd84kTtc7m3+VOkyBzkigH3kGh/FhKpjO218l eOz9gaeLENPGsbJKDAAm0RBQo/FMNfmnmi80R9OUBLvRrDcZFK36iBQ/HpbF2WODDsOvW6 1C/lykFWsZcHiNHrgY4v8g8X7waD7lQ= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-255-xymKI49lNGqCiXMWb3VPDw-1; Wed, 24 May 2023 03:06:39 -0400 X-MC-Unique: xymKI49lNGqCiXMWb3VPDw-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-3f612a1b0fdso2917055e9.2 for ; Wed, 24 May 2023 00:06:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684911998; x=1687503998; h=content-transfer-encoding:in-reply-to:subject:organization:from :content-language:references:cc:to:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=LjhHjHBMY39aJuSZuOz+uNWhK5sxOn0xoRbBRqqPSZg=; b=XPksxTn0r0iMVbWBwTIUQZyCBcwmZCsayAE2w7vB8BXSnLK6NV3Jfcu7Dwi8yKagaO fhrunSibPCygd78hzEeAwDC0AuCLmAV/ZqIFoiBtoaPtOXOcxqYuUDfGRCtCOU8gaF76 pgxDVcU6Tj5/N9YzABCOr0co3GhVHmgcZzDZeBlnrG3wldJ2Dfk3KWRBBBokoIBx3ikh 5Z7I6cfPgngAiiozdBtsoxgM5LICpz4rbHhHHavD1E8rRdK6s7OTsEbuDipzxiyIDWrs 79NnZOwWyK+rDoiCE+Kxw63beydAZYRtKLpAcFFzzwt/IohDY2p5LoBOEOA/PfsGq98w +dvw== X-Gm-Message-State: AC+VfDyGDkV/6ZjYGn671cP4xtca4JkWxUakCt4USR2a3f+918AKOVG9 bi8MoUMgN8RyOKBN2CKSXXTjP/EdzZyEUXARbpOfCtdzNhgwjh8YY7uncyZnN7f1ulDmRMY8UQA aAF33cEtTNyM= X-Received: by 2002:a7b:cd01:0:b0:3f1:72ec:4009 with SMTP id f1-20020a7bcd01000000b003f172ec4009mr11268159wmj.9.1684911998686; Wed, 24 May 2023 00:06:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7V6VeTW9TIXyu+6RB5cNPwFpMMHuHEbMO29YN09EiaTzY9XRov0K5pXdabLvAWr7aHZwRaiA== X-Received: by 2002:a7b:cd01:0:b0:3f1:72ec:4009 with SMTP id f1-20020a7bcd01000000b003f172ec4009mr11268140wmj.9.1684911998304; Wed, 24 May 2023 00:06:38 -0700 (PDT) Received: from ?IPV6:2003:cb:c70d:f700:24cd:855:1c60:1ff4? (p200300cbc70df70024cd08551c601ff4.dip0.t-ipconnect.de. [2003:cb:c70d:f700:24cd:855:1c60:1ff4]) by smtp.gmail.com with ESMTPSA id 12-20020a05600c024c00b003f4e8530696sm1199877wmj.46.2023.05.24.00.06.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 24 May 2023 00:06:37 -0700 (PDT) Message-ID: <5c4160cc-6aec-f6a6-8bab-b0bf201a037c@redhat.com> Date: Wed, 24 May 2023 09:06:36 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 To: David Howells , Christoph Hellwig Cc: Jens Axboe , Al Viro , Matthew Wilcox , Jan Kara , Jeff Layton , Jason Gunthorpe , Logan Gunthorpe , Hillf Danton , Christian Brauner , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20230522205744.2825689-1-dhowells@redhat.com> <3068545.1684872971@warthog.procyon.org.uk> From: David Hildenbrand Organization: Red Hat Subject: Re: Extending page pinning into fs/direct-io.c In-Reply-To: <3068545.1684872971@warthog.procyon.org.uk> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 4C17040007 X-Stat-Signature: ptenrme3swsoxp4mptu6eeeqc63w8gpf X-Rspam-User: X-HE-Tag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PC7saKwpSAbNokW5hCjAHjU/qvTReHCfYd0F51RPkH49lrC1/1qdn05yTAbxjYqspyz0I0YWj+qk3RD1z4tPfNQqGG0TaJ1VjYEZ4+U7RRPZIZ/9XYyp9HT3EMkCcfuFAFvhgOj8BcTqrKfbwclLatPf2glzG4KNbaZWmsUqMa437bcnlokFLKuTJ+dyHrDs+vLaOZIFCPeKH+uIBqY2oI6RKBV1+JpsPHMjNWUXpID4wuprAiE0R9rXc93n39QNzaI3CKX0ZfK2uaOajPdUObPooq39sKRsljgiHD/EJWX8/cu8qTvUufQOJiOVumrDC6o5kiI1s5OMNrlYS6SBK/oVbM5Cwc3HUsFNa+jDHc4DZtGUtjOPaH0Y0UNpUytUeWe7BJbYQbyBGtW9ett0vRAMafg== 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 23.05.23 22:16, David Howells wrote: > Christoph Hellwig wrote: > >> But can you please also take care of the legacy direct I/O code? I'd really >> hate to leave yet another unfinished transition around. > > I've been poking at it this afternoon, but it doesn't look like it's going to > be straightforward, unfortunately. The mm folks have been withdrawing access > to the pinning API behind the ramparts of the mm/ dir. Further, the dio code > will (I think), under some circumstances, arbitrarily insert the zero_page > into a list of things that are maybe pinned or maybe unpinned, but I can (I > think) also be given a pinned zero_page from the GUP code if the page tables > point to one and a DIO-write is requested - so just doing if page == zero_page > isn't sufficient. > > What I'd like to do is to make the GUP code not take a ref on the zero_page > if, say, FOLL_DONT_PIN_ZEROPAGE is passed in, and then make the bio cleanup > code always ignore the zero_page. We discussed doing that unconditionally in the context of vfio (below), but vfio decided to add a workaround suitable for stable. In case of FOLL_PIN it's simple: if we detect the zeropage, don't mess with the refcount when pinning and don't mess with the refcount when unpinning (esp. unpin_user_pages). FOLL_GET is a different story but we don't have to mess with that. So there shouldn't be need for a FOLL_DONT_PIN_ZEROPAGE, we could just do it unconditionally. > > Alternatively, I can drop the pin immediately if I get given one on the > zero_page - it's not going anywhere, after all. That's what vfio did in commit 873aefb376bbc0ed1dd2381ea1d6ec88106fdbd4 Author: Alex Williamson Date: Mon Aug 29 21:05:40 2022 -0600 vfio/type1: Unpin zero pages There's currently a reference count leak on the zero page. We increment the reference via pin_user_pages_remote(), but the page is later handled as an invalid/reserved page, therefore it's not accounted against the user and not unpinned by our put_pfn(). Introducing special zero page handling in put_pfn() would resolve the leak, but without accounting of the zero page, a single user could still create enough mappings to generate a reference count overflow. The zero page is always resident, so for our purposes there's no reason to keep it pinned. Therefore, add a loop to walk pages returned from pin_user_pages_remote() and unpin any zero pages. For vfio that handling no longer required, because FOLL_LONGTERM will never pin the shared zeropage. -- Thanks, David / dhildenb