Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp552848imm; Mon, 2 Jul 2018 17:09:13 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLfgVW214p0TinQCVD9h6ZFUHRvnuJycAedtY7ZDII+XBVjmpg/B5Z/EFgzFsBOLF0kysQk X-Received: by 2002:a65:6094:: with SMTP id t20-v6mr23828774pgu.264.1530576553497; Mon, 02 Jul 2018 17:09:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530576553; cv=none; d=google.com; s=arc-20160816; b=hcuF+1sq34QjCTjsHns5Tu5FAgwS9EtciwZmFhqxcKKUs2jhRtc16wqjsAvWijSdmJ v0uOd5VWYRzMNoQw+uCvz+X5tfuYTV0W6fuH3zPElQgkhal3bJ0XG3fATJDIB0T8oasL 7GkZGlKH00sZd3RlKlBsMIEpquAq4x465JYLJMqK032kYPA0CplKqV6orxobjsAdhDpm pxymTWOMarrNvIoHVHcllCSMV4gib3FesD256Lc8LpL12+6NrIBcaB3AzNdmC8TGFjGA jtyUUbpwGpRXCYZQM3If/xbXDl33FX0rTFsQ/CP4ZZizyuuxha7g+FvgS0RQbgoFR9D2 Qytg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:feedback-id:mime-version:user-agent :references:message-id:in-reply-to:subject:cc:to:from:date :dkim-signature:arc-authentication-results; bh=lY3UPQt4WugWZbZGOVOUxMhdg3DSWo6EAr4Qdc9Y05g=; b=dwghMPZUlZWJkWYkVy2FMGbdNCSnBcCGW4bWqKG2S+qx77WaPG6xkvcsgMTAnrK+E6 t+tsItUIRTTslyCGs64vRJGnhZ/8Mte+wpSC9bQkfn6p5+t/0R2Rg/b6/trPYCQwz+nt Nf3LGJwo/2041YhDyE/6yU1ntIxO2bzP2GsPeXp8AeCLy5cgYI9KbgZtGJL/tBQ9cuFh 9WnKiGncoxyA4rkLvCEV4t7p0SQhlZn11fJw/I4tbDBlYzLskf3ckcrI+dCQBZYwA8o7 BuW6+ofbGzZFRxKq9Pl+mB3pDQgIaE47wvjskK8x6TMHF1sC99rXOKBtei3L/18043n8 eZjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazonses.com header.s=ug7nbtf4gccmlpwj322ax3p6ow6yfsug header.b=fuqLACHb; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k190-v6si15501946pge.276.2018.07.02.17.08.58; Mon, 02 Jul 2018 17:09:13 -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; dkim=pass header.i=@amazonses.com header.s=ug7nbtf4gccmlpwj322ax3p6ow6yfsug header.b=fuqLACHb; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753773AbeGCAIU (ORCPT + 99 others); Mon, 2 Jul 2018 20:08:20 -0400 Received: from a9-99.smtp-out.amazonses.com ([54.240.9.99]:45164 "EHLO a9-99.smtp-out.amazonses.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753264AbeGCAIT (ORCPT ); Mon, 2 Jul 2018 20:08:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=ug7nbtf4gccmlpwj322ax3p6ow6yfsug; d=amazonses.com; t=1530576498; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References:MIME-Version:Content-Type:Feedback-ID; bh=VghKJfYA1USV4fZE22ydPab9s3xIpTiBLLuaUamU68g=; b=fuqLACHbnBn4ukXbV3Z9v9EID+mX7zmAifHXHqE6aZpqustVQ8Wnd4LQ4wKVb0G3 m37879O2WIYIu2iopkboUCe1CKcpo9DerjD8H5pm7WBk/RHUfD2A878gGbpIBznm4Ru 4RWJSaAdIcoN3XqKjkaGqW2okDjwb1hxCVVgOfH0= Date: Tue, 3 Jul 2018 00:08:18 +0000 From: Christopher Lameter X-X-Sender: cl@nuc-kabylake To: John Hubbard cc: Jan Kara , john.hubbard@gmail.com, Matthew Wilcox , Michal Hocko , Jason Gunthorpe , Dan Williams , linux-mm@kvack.org, LKML , linux-rdma , linux-fsdevel@vger.kernel.org Subject: Re: [PATCH v2 5/6] mm: track gup pages with page->dma_pinned_* fields In-Reply-To: Message-ID: <010001645d77ee2c-de7fedbd-f52d-4b74-9388-e6435973792b-000000@email.amazonses.com> References: <20180702005654.20369-1-jhubbard@nvidia.com> <20180702005654.20369-6-jhubbard@nvidia.com> <20180702095331.n5zfz35d3invl5al@quack2.suse.cz> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-SES-Outgoing: 2018.07.03-54.240.9.99 Feedback-ID: 1.us-east-1.fQZZZ0Xtj2+TD7V5apTT/NrT6QKuPgzCT/IC7XYgDKI=:AmazonSES Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.