Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp5560709ybh; Wed, 7 Aug 2019 07:58:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqzyiYqJpkgjayGAWHh2BD4AsCA1X/tH8gKNGv5EaYlHG0Y3k8cLP/iR764mNnxLXSoUy/4Q X-Received: by 2002:aa7:9819:: with SMTP id e25mr9426103pfl.47.1565189919373; Wed, 07 Aug 2019 07:58:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565189919; cv=none; d=google.com; s=arc-20160816; b=vLWy/5h92bZdYnolVSEHRXNwyc/xAUDvlXZ+3uzwH0zU9+Ij24yNfVmlqUe4CcrwR1 QLpfQe7BFQ/KpNoWal9W1mAEONRAVicCZG2OVv3MkrNAaM4scWi7FtZ7etZEvM9udwIt ZyGSAC/M1m3S0/jgJzla0T8eFnETWL2u66aF/GnVxrmTFVecI6ukh63b8mMfw5Dosrwe lEzpfVXJcZKa3mboc12IM68ChE690v8KC+dszX3/gEx73vywSxLOU7tHJ6gcL99VXaaI lLPHCTW1z1Yqx1Agw3uRssdYRR84OBQ2ZbHPJWgcRg2nREOdg/X4Ba60PCxsPZ9aqz7v jwgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=WHDkGIkGDhi7s/aX5RIG2h076WJQgiwTmFKZsiix88I=; b=GK5/drXMI5RodzOzIqqDJrolgwwVF/9FhC6y3UmBVV7VCQBeESFtjMBidvlozTfJTg VTNBdpUFd9wdSwwC3nHTRutnFCxEYMPbIDCHkBywxt+oyv81xPNRLKtzHcmpbMJmdO6/ VROPzlA73PB2Db7dRN5oRna5VD6ZGnB1ZSqZTchnRTg19OvalHMmk345+otdH61p44TW Vqf+EVq5WvfAQiZY2KR3aVVlFZAXZ7UPl8ZhOr/yabOb4AtUc+9UlmNW5zZJEq1F2wl1 Sml8fDptANnpOYckp5+0eSTjjt+f4O9KIeMsq9IVEViwdQ2R6oI0DSYMXJDnitW7I0d/ +DzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=AC2sFIrC; 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 g6si47031407pll.82.2019.08.07.07.58.24; Wed, 07 Aug 2019 07:58:39 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=AC2sFIrC; 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 S1730038AbfHGO4G (ORCPT + 99 others); Wed, 7 Aug 2019 10:56:06 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:59070 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729550AbfHGO4F (ORCPT ); Wed, 7 Aug 2019 10:56:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=WHDkGIkGDhi7s/aX5RIG2h076WJQgiwTmFKZsiix88I=; b=AC2sFIrClzvrAuopVrXvwugiY 8pjCjcoNMRxBAbOu1e+IYWnWwBn23rrvVb3+zo9jSy/rEqV0jtM6OKmuaKJgIPCd+ZEJGVHI1xCUM V33yiZR1LBHycuELJYuk3ChIMHbwC3+U3UkD+itrcmrRrXwcGTUiy4Emh3dDvFH8iJCGHKTIyZkSS JkM7h5vZfpkNwqmfAGioAVQ7oEBCMiwDFERlYOCfEHok0Ct0gRQBQZhg0acgBiGO6N99OC8PyFqGX RBH5duCu835KJqDGvsVYJ2T0t8xRO3dI5YDATQhUwKO6u2/VVkIlC73MRjL16m50yadyh4WpPfYWx CslHyrvIQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.92 #3 (Red Hat Linux)) id 1hvNM9-00082M-J1; Wed, 07 Aug 2019 14:56:01 +0000 Date: Wed, 7 Aug 2019 07:56:01 -0700 From: Matthew Wilcox To: Steven Price Cc: Christoph Hellwig , Linus Torvalds , Thomas =?iso-8859-1?Q?Hellstr=F6m_=28VMware=29?= , Dave Airlie , Thomas Hellstrom , Daniel Vetter , LKML , dri-devel , Jerome Glisse , Jason Gunthorpe , Andrew Morton , Linux-MM Subject: Re: drm pull for v5.3-rc1 Message-ID: <20190807145601.GB5482@bombadil.infradead.org> References: <48890b55-afc5-ced8-5913-5a755ce6c1ab@shipmail.org> <20190806073831.GA26668@infradead.org> <20190806190937.GD30179@bombadil.infradead.org> <20190807064000.GC6002@infradead.org> <20190807141517.GA5482@bombadil.infradead.org> <62cbe523-e8a4-cdfd-90c2-80260cefa5de@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <62cbe523-e8a4-cdfd-90c2-80260cefa5de@arm.com> User-Agent: Mutt/1.11.4 (2019-03-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 07, 2019 at 03:30:38PM +0100, Steven Price wrote: > On 07/08/2019 15:15, Matthew Wilcox wrote: > > On Tue, Aug 06, 2019 at 11:40:00PM -0700, Christoph Hellwig wrote: > >> On Tue, Aug 06, 2019 at 12:09:38PM -0700, Matthew Wilcox wrote: > >>> Has anyone looked at turning the interface inside-out? ie something like: > >>> > >>> struct mm_walk_state state = { .mm = mm, .start = start, .end = end, }; > >>> > >>> for_each_page_range(&state, page) { > >>> ... do something with page ... > >>> } > >>> > >>> with appropriate macrology along the lines of: > >>> > >>> #define for_each_page_range(state, page) \ > >>> while ((page = page_range_walk_next(state))) > >>> > >>> Then you don't need to package anything up into structs that are shared > >>> between the caller and the iterated function. > >> > >> I'm not an all that huge fan of super magic macro loops. But in this > >> case I don't see how it could even work, as we get special callbacks > >> for huge pages and holes, and people are trying to add a few more ops > >> as well. > > > > We could have bits in the mm_walk_state which indicate what things to return > > and what things to skip. We could (and probably should) also use different > > iterator names if people actually want to iterate different things. eg > > for_each_pte_range(&state, pte) as well as for_each_page_range(). > > > > The iterator approach could be awkward for the likes of my generic > ptdump implementation[1]. It would require an iterator which returns all > levels and allows skipping levels when required (to prevent KASAN > slowing things down too much). So something like: > > start_walk_range(&state); > for_each_page_range(&state, page) { > switch(page->level) { > case PTE: > ... > case PMD: > if (...) > skip_pmd(&state); > ... > case HOLE: > .... > ... > } > } > end_walk_range(&state); > > It seems a little fragile - e.g. we wouldn't (easily) get type checking > that you are actually treating a PTE as a pte_t. The state mutators like > skip_pmd() also seem a bit clumsy. Once you're on-board with using a state structure, you can use it in all kinds of fun ways. For example: struct mm_walk_state { struct mm_struct *mm; unsigned long start; unsigned long end; unsigned long curr; p4d_t p4d; pud_t pud; pmd_t pmd; pte_t pte; enum page_entry_size size; int flags; }; For this user, I'd expect something like ... DECLARE_MM_WALK_FLAGS(state, mm, start, end, MM_WALK_HOLES | MM_WALK_ALL_SIZES); walk_each_pte(state) { switch (state->size) { case PE_SIZE_PTE: ... case PE_SIZE_PMD: if (...(state->pmd)) continue; ... } } There's no need to have start / end walk function calls.