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 E7D31C04A95 for ; Fri, 23 Sep 2022 18:13:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 39EA180007; Fri, 23 Sep 2022 14:13:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 34E1F6B0073; Fri, 23 Sep 2022 14:13:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1EDE580007; Fri, 23 Sep 2022 14:13:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 0D75B6B0072 for ; Fri, 23 Sep 2022 14:13:04 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id CE7391401B0 for ; Fri, 23 Sep 2022 18:13:03 +0000 (UTC) X-FDA: 79944146646.22.6A1B831 Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com [209.85.160.176]) by imf27.hostedemail.com (Postfix) with ESMTP id 7737D40005 for ; Fri, 23 Sep 2022 18:13:03 +0000 (UTC) Received: by mail-qt1-f176.google.com with SMTP id c11so555985qtw.8 for ; Fri, 23 Sep 2022 11:13:03 -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=ESjxMV4FxoH+Qzt/uSGYOPflTsCgLENu7dcc3YowE6k=; b=kY7MMNDmdRDXgBREGl1n+cj9EEOun4Jy+ls14IMPSV0csWh1NDhj6Y4IB13T7BfdUg Wi26eUp33Pa5tk7zFyBI2Mq+szalxQ6Q7xLkG63kAED5icqyWvausogbFqMjBz0Q3OAh 8jqc4H2+05KPQwocTeDkku8kSoajsIwV/5IYLvCARPSewr33UpGNeEeIiU9QvvDqKKWA 39NJUXg4YGPg3p8VI/Tc5XyFrJVFGr/E8X/vqYnNdWZ2ScfDLSTdMHKUBAKg0NCPBOg6 IuCIVAumakjRmdj960aYL4S9ORJZ+CwZb7srEB3nY3ZBFIp+qJ2V46gkbAaTq221ryrS b8jg== 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=ESjxMV4FxoH+Qzt/uSGYOPflTsCgLENu7dcc3YowE6k=; b=0peSdMVpBQDCWwM2uW0Fvpz0Mlqch5WfkZBrdcwYSLzq14hWBaK7ATLnhgdYPrHCzj rHwZpjU4IjXZRC/POL6BFGc96sSPvJzxtUSM65JzzwOxDS5mPaOheI4gGeDfXo4/ZRsv n0rFABzVC1aHIk1op+PmXHomCU2ShEVa1TOXbNYmphwZdjzB/pS3WADu5PzN49CAKlKE yaFS/tgTEiktV0FqEkV1cY4ACLF4hGzJW0W87eRJEBBTyBMdLWIsgZYZxYzCLUdBlPes 5iuro0kLebLpMLpr5CbwFo5+aSLBvt4J2jATrVQqX6hhqMNITsUxnsFwbtGF+C2bmPOk yRNQ== X-Gm-Message-State: ACrzQf1Jwd9+nzJo6l+a5pJOfzOdMoqynuiAOkRn/RhQog/xkV/hDioB ybTQfljtGs8XLpDLZBUISyv0Vw== X-Google-Smtp-Source: AMsMyM70jy04UOYomyiLCRjAafYD9I2h2rthRpjbDcZ+gaI+Pe3GK1nBzDBvaI6cptEThcPFiSijKQ== X-Received: by 2002:a05:622a:1053:b0:35c:bab4:bd80 with SMTP id f19-20020a05622a105300b0035cbab4bd80mr8343380qte.189.1663956782680; Fri, 23 Sep 2022 11:13:02 -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 r13-20020ac87eed000000b0034035e73be0sm5730575qtc.4.2022.09.23.11.13.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Sep 2022 11:13:01 -0700 (PDT) Received: from jgg by wakko with local (Exim 4.95) (envelope-from ) id 1obnAb-002jAI-6N; Fri, 23 Sep 2022 15:13:01 -0300 Date: Fri, 23 Sep 2022 15:13:01 -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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220922163926.7077-2-logang@deltatee.com> ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=ziepe.ca header.s=google header.b=kY7MMNDm; spf=pass (imf27.hostedemail.com: domain of jgg@ziepe.ca designates 209.85.160.176 as permitted sender) smtp.mailfrom=jgg@ziepe.ca; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663956783; a=rsa-sha256; cv=none; b=MGcT16zbLO6Rn0KrIb6ypBXj/jLaswlIBo251V7Ar/U38ByxUT3NtPic0Hc9LfjbEAV4Gx gnaCKnqfMY8wyiKBJwHoBB7hfPJAwymKsUnzHhk9J1umxKvaKrAZhJ1G0Ogo7a2igMSBQc DLPLogXJYzVU6GnMmup4bEiOrk95LmY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663956783; 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=ESjxMV4FxoH+Qzt/uSGYOPflTsCgLENu7dcc3YowE6k=; b=NaoYcBfg8VDjmUAx0cCPg6fp9rUSb0AoqVRNKhQqMq2weor3K8ivmiE7Ah6y882MK3+de/ wqAykc9q5xt3U/u22LROZiqFzTF3SbVck4hhRCZu8BKSyL5epc8GzlHnHZLfARcgk6U4TF 85PEideRUOO3u3kjJUQfn+HAL4qOxiA= X-Stat-Signature: sixpequq9chh18qy63pmzezr3x7soz6o X-Rspamd-Queue-Id: 7737D40005 Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=ziepe.ca header.s=google header.b=kY7MMNDm; spf=pass (imf27.hostedemail.com: domain of jgg@ziepe.ca designates 209.85.160.176 as permitted sender) smtp.mailfrom=jgg@ziepe.ca; dmarc=none X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1663956783-821450 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 Thu, Sep 22, 2022 at 10:39:19AM -0600, Logan Gunthorpe wrote: > GUP Callers that expect PCI P2PDMA pages can now set FOLL_PCI_P2PDMA to > allow obtaining P2PDMA pages. If GUP is called without the flag and a > P2PDMA page is found, it will return an error. > > FOLL_PCI_P2PDMA cannot be set if FOLL_LONGTERM is set. What is causing this? It is really troublesome, I would like to fix it. eg I would like to have P2PDMA pages in VFIO iommu page tables and in RDMA MR's - both require longterm. Is it just because ZONE_DEVICE was created for DAX and carried that revocable assumption over? Does anything in your series require revocable? > @@ -2383,6 +2392,10 @@ static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned long end, > VM_BUG_ON(!pfn_valid(pte_pfn(pte))); > page = pte_page(pte); > > + if (unlikely(!(flags & FOLL_PCI_P2PDMA) && > + is_pci_p2pdma_page(page))) > + goto pte_unmap; > + > folio = try_grab_folio(page, 1, flags); > if (!folio) > goto pte_unmap; On closer look this is not in the right place, we cannot touch the content of *page without holding a ref, and that doesn't happen until until try_grab_folio() completes. It would be simpler to put this check in try_grab_folio/try_grab_page after the ref has been obtained. That will naturally cover all the places that need it. Jason