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 4A0D5C04A95 for ; Fri, 23 Sep 2022 22:58:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CE28B8002A; Fri, 23 Sep 2022 18:58:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C919080016; Fri, 23 Sep 2022 18:58:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B31F48002A; Fri, 23 Sep 2022 18:58:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id A492380016 for ; Fri, 23 Sep 2022 18:58:52 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 53A6A140161 for ; Fri, 23 Sep 2022 22:58:52 +0000 (UTC) X-FDA: 79944866904.10.CC032A5 Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) by imf26.hostedemail.com (Postfix) with ESMTP id E7C50140003 for ; Fri, 23 Sep 2022 22:58:51 +0000 (UTC) Received: by mail-qt1-f171.google.com with SMTP id cj27so974391qtb.7 for ; Fri, 23 Sep 2022 15:58:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date; bh=FNVLh7QhTGQ0fcTY+ctZvZZG3IwOkyYDgRdATbQqFOE=; b=K6ThUhwaPxzE2uNJlUneDV+lEcb3sOSkMme+uJcOlA6PYnkzlx9eWnQI1++F4JHPTq 6r5PK01FmTenaqwabhqB54wtpEtSh4q/f93LAarupwwOtTOjD+IgB/VnY7DUeuIhnkQC ueJpGrhUyrDSBys3KiQqSXiiBkciEmtt9rHzEbu8riWDZ48ZSyiWrSiPky8YDf3TxmTw JUiu1YmBDldxsDnWcSHllSPx0BxlwyOXe/lppV6D0S4dxlwZK9P4DpsQeTWyB8t6HwzK z3SSHJoW/95nBFxiW6hEVkAM1qDx4k+3uHGKOmgxxq5NvqNGbvm3e45Zg2lFjxXsyWRU k//Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=FNVLh7QhTGQ0fcTY+ctZvZZG3IwOkyYDgRdATbQqFOE=; b=t7hlwE4TPqCl6PurwVpnVSw1eMNGKiAjr1+kwm60KVY+8KvCRk/0VE3sFV59kucMy5 OX8lRg3F27hwl6/2wf0d9Rk1+fsoTdSrr7Bbaxj6jftVMIHEXhJlYuRI6MrLSwPOcj6C 9w9pgJnZ8c1QzKd6YzOZeHnVq6/QjXQO+mxIkAcjSB4gRJmYYl+WQ4IWEHFkqCFCvuDn RIYxjg+4OweehNrEuz/OcsAGVCfSnivLorQQbMYYLIBSzMK5br8Oe+SV4V0sK8u22LWJ Yilm7sbaWE/jeOS9BMXOLxisXsnsoDIpqgpVm5jm52J1+hRAOV7R5l3zwkSLUen1v3hu 9B8A== X-Gm-Message-State: ACrzQf0Yf33A+i2a5lQvyfiLaFryE2OCPOctmDxdLhYAVn72aBNuVOub 5+K1MXISm53s2h/AC2gE/SAKIw== X-Google-Smtp-Source: AMsMyM47dsm4TxegiRkZUeLCH+5O+Wr8H54uLORgq4Q+/7wXo2aoGW0gmLRhcDSR3jPPk1osSOqTXA== X-Received: by 2002:ac8:5a8b:0:b0:35b:f5c0:d5c9 with SMTP id c11-20020ac85a8b000000b0035bf5c0d5c9mr9233331qtc.14.1663973931136; Fri, 23 Sep 2022 15:58:51 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-142-162-113-129.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.162.113.129]) by smtp.gmail.com with ESMTPSA id s5-20020a05620a254500b006b98315c6fbsm7255492qko.1.2022.09.23.15.58.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Sep 2022 15:58:50 -0700 (PDT) Received: from jgg by wakko with local (Exim 4.95) (envelope-from ) id 1obrdB-00316G-At; Fri, 23 Sep 2022 19:58:49 -0300 Date: Fri, 23 Sep 2022 19:58:49 -0300 From: Jason Gunthorpe To: Logan Gunthorpe Cc: linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-block@vger.kernel.org, linux-pci@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , Greg Kroah-Hartman , Dan Williams , Christian =?utf-8?B?S8O2bmln?= , John Hubbard , Don Dutile , Matthew Wilcox , Daniel Vetter , Minturn Dave B , Jason Ekstrand , Dave Hansen , Xiong Jianxin , Bjorn Helgaas , Ira Weiny , Robin Murphy , Martin Oliveira , Chaitanya Kulkarni , Ralph Campbell , Stephen Bates Subject: Re: [PATCH v10 1/8] mm: introduce FOLL_PCI_P2PDMA to gate getting PCI P2PDMA pages Message-ID: References: <20220922163926.7077-1-logang@deltatee.com> <20220922163926.7077-2-logang@deltatee.com> <64f8da81-7803-4db4-73da-a158295cbc9c@deltatee.com> <2327d393-af5c-3f4c-b9b9-6852b9d72f90@deltatee.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2327d393-af5c-3f4c-b9b9-6852b9d72f90@deltatee.com> ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663973932; a=rsa-sha256; cv=none; b=r/CxfTzSBgSx8Zbn+A4EOsoet5xuokxtJ3140TaZUJ78o92hSEAdYbbUeNG+Y7fjfRYZRd b++FYtpWZOxh66UHWsc7KdHBdX96OUua2vwK9F79UQOB5zbwdYKVAa9XjZv4I9O5O9x8oW l2BBema2/Mp7K0H55/j875L66fMwirg= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=ziepe.ca header.s=google header.b=K6ThUhwa; spf=pass (imf26.hostedemail.com: domain of jgg@ziepe.ca designates 209.85.160.171 as permitted sender) smtp.mailfrom=jgg@ziepe.ca; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663973932; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=FNVLh7QhTGQ0fcTY+ctZvZZG3IwOkyYDgRdATbQqFOE=; b=EnONziz6gM1SCdk4yj2NqjdPRsGbn58TNpUwUufr3D57ukPwr7V7awvt2lUWS4j9jDl/JD MgH3l+mM6u5F1lfIxEHZ9gYRE/SYX3J9fv0Wsz7MVX0/G3dpNtlg2ykwWV5vmHoCDRMlFE 9IpIRJ332EHx2jqWtahhxQ7jopSwvOM= X-Stat-Signature: gk5u75r9q8srua8a3hzcibebdjm83ex3 X-Rspamd-Queue-Id: E7C50140003 X-Rspam-User: X-Rspamd-Server: rspam08 Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=ziepe.ca header.s=google header.b=K6ThUhwa; spf=pass (imf26.hostedemail.com: domain of jgg@ziepe.ca designates 209.85.160.171 as permitted sender) smtp.mailfrom=jgg@ziepe.ca; dmarc=none X-HE-Tag: 1663973931-114441 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 Fri, Sep 23, 2022 at 02:11:03PM -0600, Logan Gunthorpe wrote: > > > On 2022-09-23 13:53, Jason Gunthorpe wrote: > > On Fri, Sep 23, 2022 at 01:08:31PM -0600, Logan Gunthorpe wrote: > > I'm encouraging Dan to work on better infrastructure in pgmap core > > because every pgmap implementation has this issue currently. > > > > For that reason it is probably not so relavent to this series. > > > > Perhaps just clarify in the commit message that the FOLL_LONGTERM > > restriction is to copy DAX until the pgmap page refcounts are fixed. > > Ok, I'll add that note. > > Per the fix for the try_grab_page(), to me it doesn't fit well in > try_grab_page() without doing a bunch of cleanup to change the > error handling, and the same would have to be added to try_grab_folio(). > So I think it's better to leave it where it was, but move it below the > respective grab calls. Does the incremental patch below look correct? Oh? I was thinking of just a very simple thing: --- a/mm/gup.c +++ b/mm/gup.c @@ -225,6 +225,11 @@ bool __must_check try_grab_page(struct page *page, unsigned int flags) node_stat_mod_folio(folio, NR_FOLL_PIN_ACQUIRED, 1); } + if (unlikely(!(flags & FOLL_PCI_P2PDMA) && is_pci_p2pdma_page(page))) { + gup_put_folio(page_folio(page), 1, flags); + return false; + } + return true; } > I am confused about what happens if neither FOLL_PIN or FOLL_GET > are set (which the documentation for try_grab_x() says is possible, but > other documentation suggests that FOLL_GET is automatically set). > In which case it'd be impossible to do the check if we can't > access the page. try_grab_page is operating under the PTL so it can probably touch the page OK (though perhaps we don't need to even check anything) try_grab_folio cannot be called without PIN/GET, so like this perhaps: @@ -123,11 +123,14 @@ static inline struct folio *try_get_folio(struct page *page, int refs) */ struct folio *try_grab_folio(struct page *page, int refs, unsigned int flags) { + struct folio *folio; + + if (WARN_ON((flags & (FOLL_GET | FOLL_PIN)) == 0)) + return NULL; + if (flags & FOLL_GET) - return try_get_folio(page, refs); + folio = try_get_folio(page, refs); else if (flags & FOLL_PIN) { - struct folio *folio; - /* * Can't do FOLL_LONGTERM + FOLL_PIN gup fast path if not in a * right zone, so fail and let the caller fall back to the slow @@ -160,11 +163,14 @@ struct folio *try_grab_folio(struct page *page, int refs, unsigned int flags) refs * (GUP_PIN_COUNTING_BIAS - 1)); node_stat_mod_folio(folio, NR_FOLL_PIN_ACQUIRED, refs); - return folio; } - WARN_ON_ONCE(1); - return NULL; + if (unlikely(!(flags & FOLL_PCI_P2PDMA) && is_pci_p2pdma_page(page))) { + gup_put_folio(page, 1, flags); + return NULL; + } + + return folio; } Jason