Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp188533ybl; Tue, 13 Aug 2019 18:38:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqxgeWtIm59Cu0t/vyoPCoHmF4+YqhU1Ebr/KV1/1c1gTj9FGo43L+HYjkSQ5SuSygVT2nMd X-Received: by 2002:a63:dd0b:: with SMTP id t11mr37159345pgg.410.1565746729727; Tue, 13 Aug 2019 18:38:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565746729; cv=none; d=google.com; s=arc-20160816; b=h8pyILDMfuFRBIfsMtXlggWZzKFV4w1iFaI5ryXzyCnn19Hq5EY37wddb3EPfdCPcz lt57MJDbh/ZDOW5gVfBcm845EsXJ/HmUMU5rZQQiWuJju8jCelYz+vuR16IuoP75FWCq DwHEAV6f/+UZVeIGabuDYYMDZpJuk0eQoHumSIa60wZjQYO0JC6zMl7UhQbI8qrEI+7h ZW7A2Gut4QYk4CDspnPlhF44MOOSxZl0LkeImFZwhg40UPG+Am4s8jlJZn0XQDOQ/fdi BoRtA+IUb4rgb0bVJRfEGHeEYz2mYob2gVvmJQ15/KWdUCPkTO6O+KtzcgtGdDA8aSwH LNHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=T79FqmE4omVh8KvKRr9Ji1NiYF1jwWoBp2a4S3wYfUE=; b=g5vlCp8S89J4MC1ey3CC8qSjsxbl02XaiuhuydGk02hhK1NeafAuNvjJrRk7eWG3pN rS5ggC5UPMuCUPxU/UT7giVSqTuRHtqyrKGgD8XoKA4Z4s3P29asbmbfRmguWkFNsjwB dFtYTgaER+u61ZtSuEpNXBYORu8dKALQYhFFeEjs3lPo2pWyEEtwubkwuYUbx1jsBwe3 sWCY4rR55hm8GJz5Im5G3hSt3v0qjuwP5ocxRYWA2ncILf3gCzs/FGDNQ9aupA18xrn1 3OO6xve1gEy/v+kiC8Mqt5Q/t6ekhlfU5Agi5c3R1GaaRG9fxQAl5+4WIK2A0axNXofe 1A9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=xIgh+scF; 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f26si55112911pfk.81.2019.08.13.18.38.33; Tue, 13 Aug 2019 18:38:49 -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=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=xIgh+scF; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726931AbfHNBgp (ORCPT + 99 others); Tue, 13 Aug 2019 21:36:45 -0400 Received: from mail-ot1-f67.google.com ([209.85.210.67]:46314 "EHLO mail-ot1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726631AbfHNBgp (ORCPT ); Tue, 13 Aug 2019 21:36:45 -0400 Received: by mail-ot1-f67.google.com with SMTP id z17so60219444otk.13 for ; Tue, 13 Aug 2019 18:36:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=T79FqmE4omVh8KvKRr9Ji1NiYF1jwWoBp2a4S3wYfUE=; b=xIgh+scFlFZaMbyoMV1IkOIlX/nYvIEVasdGR+4vgGYHLeiewku5FhfmMF/u82KCRX MSErqkN/DgEQsqSvd4X7p+lT0oNexeTRv86qeokYYdUP0BOeLCGjOX9Sd/JWMKEQoS6g PwX/lC9BqsULCOBZLAvJixho5nREePWl5uOPg2jE9g0vQx3cZII3Ilx0J7oUMkt8HCC0 jWbfmfOLvoT/mbKLqBnkK54WVKRXTWevpUb9oXR/7WiAJXekPzezsPzhCgDd3il+q6/O WYUwutEc9PedlqPBB8PVWWm7kSFEs6Fj841/WMzEqYowG5ogcen99NisCiTcA9kQF5+G eqrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=T79FqmE4omVh8KvKRr9Ji1NiYF1jwWoBp2a4S3wYfUE=; b=fY7OYkhynjBbY+QCm27vUNXSSuc12H0XW+cpfJgKpRmXIc7HTWorpTnHTqx3qbtsEO zcoc+Xq7RD00XwBnqkBcr75LRUo+dCulvP6LT3sPZP6YBy8PMDt1GccWD78BPZqkYny+ oaNhCAGdobdpRZ4q6ofOj9/1tmtzTEXTHMqgdTVPLKBg88HIE2lyyPCx1YpPhEVC/Khk E6NhlCBX/Wy2OL1Am4xdshbaGUNbkTJoEbS0nFcrpP/ade+CwuYDaU1nDQupbI/jEyJ7 NjjfT4zIaWmEau/YEr2d5Fal+R3bxXKgkBB1T0H65icwZZn91C6b24Xcx+yICaicens1 P4mg== X-Gm-Message-State: APjAAAU3BrS/eKbR7QQuu2GV7jUBVDPtr34jjReGAuYy8mhMevSi9+PH jPYlx92kDlQHWQ7LBKdJBaYITFR/EEiQRJBALHB9Ug== X-Received: by 2002:a9d:5f13:: with SMTP id f19mr28233915oti.207.1565746604730; Tue, 13 Aug 2019 18:36:44 -0700 (PDT) MIME-Version: 1.0 References: <20190806160554.14046-1-hch@lst.de> <20190806160554.14046-5-hch@lst.de> <20190807174548.GJ1571@mellanox.com> <20190808065933.GA29382@lst.de> In-Reply-To: <20190808065933.GA29382@lst.de> From: Dan Williams Date: Tue, 13 Aug 2019 18:36:33 -0700 Message-ID: Subject: Re: [PATCH 04/15] mm: remove the pgmap field from struct hmm_vma_walk To: Christoph Hellwig Cc: Jason Gunthorpe , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , Ben Skeggs , Felix Kuehling , Ralph Campbell , "linux-mm@kvack.org" , "nouveau@lists.freedesktop.org" , "dri-devel@lists.freedesktop.org" , "amd-gfx@lists.freedesktop.org" , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 7, 2019 at 11:59 PM Christoph Hellwig wrote: > > On Wed, Aug 07, 2019 at 11:47:22AM -0700, Dan Williams wrote: > > > Unrelated to this patch, but what is the point of getting checking > > > that the pgmap exists for the page and then immediately releasing it? > > > This code has this pattern in several places. > > > > > > It feels racy > > > > Agree, not sure what the intent is here. The only other reason call > > get_dev_pagemap() is to just check in general if the pfn is indeed > > owned by some ZONE_DEVICE instance, but if the intent is to make sure > > the device is still attached/enabled that check is invalidated at > > put_dev_pagemap(). > > > > If it's the former case, validating ZONE_DEVICE pfns, I imagine we can > > do something cheaper with a helper that is on the order of the same > > cost as pfn_valid(). I.e. replace PTE_DEVMAP with a mem_section flag > > or something similar. > > The hmm literally never dereferences the pgmap, so validity checking is > the only explanation for it. > > > > + /* > > > + * We do put_dev_pagemap() here so that we can leverage > > > + * get_dev_pagemap() optimization which will not re-take a > > > + * reference on a pgmap if we already have one. > > > + */ > > > + if (hmm_vma_walk->pgmap) > > > + put_dev_pagemap(hmm_vma_walk->pgmap); > > > + > > > > Seems ok, but only if the caller is guaranteeing that the range does > > not span outside of a single pagemap instance. If that guarantee is > > met why not just have the caller pass in a pinned pagemap? If that > > guarantee is not met, then I think we're back to your race concern. > > It iterates over multiple ptes in a non-huge pmd. Is there any kind of > limitations on different pgmap instances inside a pmd? I can't think > of one, so this might actually be a bug. Section alignment constraints somewhat save us here. The only example I can think of a PMD not containing a uniform pgmap association for each pte is the case when the pgmap overlaps normal dram, i.e. shares the same 'struct memory_section' for a given span. Otherwise, distinct pgmaps arrange to manage their own exclusive sections (and now subsections as of v5.3). Otherwise the implementation could not guarantee different mapping lifetimes. That said, this seems to want a better mechanism to determine "pfn is ZONE_DEVICE".