Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp715068imm; Mon, 2 Jul 2018 21:32:04 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcfE87dqYTl4WoenUuCED0KN5S8zq4Y7o3mh5vG0R4Fw0KpWx7wd6aSjeLUreDNNa0izqrh X-Received: by 2002:a62:8b0f:: with SMTP id j15-v6mr22561820pfe.33.1530592324578; Mon, 02 Jul 2018 21:32:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530592324; cv=none; d=google.com; s=arc-20160816; b=Q/WIbNUpWqytIdyTcgjvrOy3+hfv0k0hN3BJ+yIH99TUIJXlMkYhRlyJ5Ovuf3KG1b KP0RZHWWRD9gq8GbG/c//0APlDGIimHOmRlt4JnEGKs9wpxbO22DoSB12byWmuQ+bdSW ENg4DxdAMy3jombqSJv8MHUhwAXZ4dk1kVd5Q6ZS3Y8uloQ7mdw5DL0nLAaY28Fs93k9 bG1PPoPByAlTXV9gMvQ+Az7QrwEBLNE/GF9CcanYzgR8n23X2nWfxmOzuFJyQn112ro2 vtLz+UBM0u7pbTIBHK79evid89wmkxY8MBXzRqJge3Lm2q5S9ZbnRgBJl1a9iGK0SFEN 3uSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=dxnbHm0AlfWzEqN1L+cXA2lEmPH7cc7LWOaP3ejSTmc=; b=ke+bsTy7hiKVeJ3m1O1TJFzL6Mknt6PafMRpiug+2g3AWrlYqLGSvfzi8rsTrT9Vbj RkeZwcTtBCu27QWRvcCaX6QBF8JGVs4U5nmReZHv3DFhITm8eCZcP/aLDwx3/2UqHi+v pbEHTb42KPoGt/gyzLJIW7glWoHNBSHY0fSXrZm8HjnWBJ+zMeZFVkHinmFS+eQ9PIsk k59V3i7MtBIIqFfrfrayARaUQvK24svqFbS+w3ifhSjA60e6BDOirn+avMDZFHGT2kch 87cvjxLJlENfyMu2OJ/5atvXWM1dfSenrfDrDj6BS7XL+lmo+aqF2o75ESj3OLexAPrV BkRg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w22-v6si220984plp.294.2018.07.02.21.31.50; Mon, 02 Jul 2018 21:32:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753941AbeGCEbC (ORCPT + 99 others); Tue, 3 Jul 2018 00:31:02 -0400 Received: from hqemgate16.nvidia.com ([216.228.121.65]:17523 "EHLO hqemgate16.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753484AbeGCEbA (ORCPT ); Tue, 3 Jul 2018 00:31:00 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate16.nvidia.com (using TLS: TLSv1, AES128-SHA) id ; Mon, 02 Jul 2018 21:30:57 -0700 Received: from HQMAIL107.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Mon, 02 Jul 2018 21:31:00 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Mon, 02 Jul 2018 21:31:00 -0700 Received: from [10.2.169.219] (10.2.169.219) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Tue, 3 Jul 2018 04:30:59 +0000 Subject: Re: [PATCH v2 5/6] mm: track gup pages with page->dma_pinned_* fields To: Christopher Lameter CC: Jan Kara , , Matthew Wilcox , Michal Hocko , Jason Gunthorpe , Dan Williams , , LKML , linux-rdma , References: <20180702005654.20369-1-jhubbard@nvidia.com> <20180702005654.20369-6-jhubbard@nvidia.com> <20180702095331.n5zfz35d3invl5al@quack2.suse.cz> <010001645d77ee2c-de7fedbd-f52d-4b74-9388-e6435973792b-000000@email.amazonses.com> From: John Hubbard X-Nvconfidentiality: public Message-ID: Date: Mon, 2 Jul 2018 21:30:28 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <010001645d77ee2c-de7fedbd-f52d-4b74-9388-e6435973792b-000000@email.amazonses.com> X-Originating-IP: [10.2.169.219] X-ClientProxiedBy: HQMAIL104.nvidia.com (172.18.146.11) To HQMAIL107.nvidia.com (172.20.187.13) Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/02/2018 05:08 PM, Christopher Lameter wrote: > On Mon, 2 Jul 2018, John Hubbard wrote: > >>> >>> These two are just wrong. You cannot make any page reference for >>> PageDmaPinned() account against a pin count. First, it is just conceptually >>> wrong as these references need not be long term pins, second, you can >>> easily race like: >>> >>> Pinner Random process >>> get_page(page) >>> pin_page_for_dma() >>> put_page(page) >>> -> oops, page gets unpinned too early >>> >> >> I'll drop this approach, without mentioning any of the locking that is hiding in >> there, since that was probably breaking other rules anyway. :) Thanks for your >> patience in reviewing this. > > Mayb the following would work: > > If you establish a reference to a page then increase the page count. If > the reference is a dma pin action also then increase the pinned count. > > That way you know how many of the references to the page are dma > pins and you can correctly manage the state of the page if the dma pins go > away. > I think this sounds like what this patch already does, right? See: __put_page_for_pinned_dma(), __get_page_for_pinned_dma(), and pin_page_for_dma(). The locking seems correct to me, but I suspect it's too heavyweight for such a hot path. But without adding a new put_user_page() call, that was the best I could come up with. What I'm hearing now from Jan and Michal is that the desired end result is a separate API call, put_user_pages(), so that we can explicitly manage these pinned pages. thanks, -- John Hubbard NVIDIA