Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4154719pxf; Tue, 23 Mar 2021 04:14:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+g5wtYGrFCUqFFSGP9mnJnkCXAJdI1iJFkUWw9JsUYns71r2yC5kxhgIskTmPTlzBsfin X-Received: by 2002:a17:906:3395:: with SMTP id v21mr4431463eja.322.1616498071411; Tue, 23 Mar 2021 04:14:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616498071; cv=none; d=google.com; s=arc-20160816; b=DR2WZjEf8rk+3Wt6SV3NclGaEGTQ6zU29XBd/SrpKEY0xr2MkoF9/YQKeA0E3LvekI rfUSEl8THmOHcYRqFtHAgAzOR72Q9Yh73DaohZzVfrut+Ion7KCC/w/hUcF+0bCOAkiO crl3ESTyrEu79W8JPZIs5mXUypOSvAcU3WKY9mmrRmEzzrYnABfNLJlMbgtVOtw9bIK2 LYHHggxDgSOxuH0uu5S0yFm3fuqOIZLUxYfS0D3fyj9PJ+xw24eGOhW2jqMygNmaxXxU eCsL+PraUw+3cj1zZdCk4xUiU4bSESERtpAtLuFi7alWvXH8PHz4VHdVeEK6dtIe6EEp azWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :ironport-sdr:ironport-sdr; bh=5x88J7G2JYTW3jeDSOhlIQAVieehIAHzZrK36/f8nHE=; b=HqgaiXDxw6YpxblWl2mfLO1yGAFQ1RRs2PUrrzC6sDBloUcYDNPa3gBDa0pvNkxOY5 GPiLw9aszbAt9dMZEYbjb90Kph2V36unKaYBGjJasyQd6SdqKLNyupuHhaNudjObOI1I xKLhjYRwblWctG6TiYSQzoLpiDHrIDq3bWUdtbBhqx734qi7uhCa8/GS4pghurYn+nOW URLtQwV9ZWL5Xpb0zcK9KlOzd1sznWPClOcysAh5N2pnN9yxD9p338BGl11/MkdCynHZ 9W0zW5kpXUsX5dOPuWBSnsRjUkttB/zX0UjyzdtTEX92KMcWZBZDM5W8jp6EcXoOHO6b zeTA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id z9si12822014edb.10.2021.03.23.04.14.08; Tue, 23 Mar 2021 04:14:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S230269AbhCWLLd (ORCPT + 99 others); Tue, 23 Mar 2021 07:11:33 -0400 Received: from mga09.intel.com ([134.134.136.24]:65415 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230287AbhCWLLO (ORCPT ); Tue, 23 Mar 2021 07:11:14 -0400 IronPort-SDR: oA6itixW/c6TkZQnjQUkPIegUJMlL1o/0RxM7kGxnY882cJsbzBH3LI7DxGNzSTi4cCZnIThkT WeXbsIrRgz9A== X-IronPort-AV: E=McAfee;i="6000,8403,9931"; a="190550145" X-IronPort-AV: E=Sophos;i="5.81,271,1610438400"; d="scan'208";a="190550145" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2021 04:11:13 -0700 IronPort-SDR: 64mApGEIQa4io6AeSQL7N9FDzK2pxtOcSUqA/mPu2Y8sojK3JidjZnvPI8H3aOWneM66tt8KiQ cYhmhCVNRbiA== X-IronPort-AV: E=Sophos;i="5.81,271,1610438400"; d="scan'208";a="604269151" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2021 04:11:08 -0700 Received: from andy by smile with local (Exim 4.94) (envelope-from ) id 1lOewC-00Ezlc-F7; Tue, 23 Mar 2021 13:11:04 +0200 Date: Tue, 23 Mar 2021 13:11:04 +0200 From: Andy Shevchenko To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Greg Kroah-Hartman , Dan Williams , Daniel Vetter , Mauro Carvalho Chehab , Dave Young , Baoquan He , Vivek Goyal , Dave Hansen , Keith Busch , Michal Hocko , Qian Cai , Oscar Salvador , Eric Biederman , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Tom Lendacky , Brijesh Singh , x86@kernel.org, kexec@lists.infradead.org Subject: Re: [PATCH v1 3/3] kernel/resource: remove first_lvl / siblings_only logic Message-ID: References: <20210322160200.19633-1-david@redhat.com> <20210322160200.19633-4-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210322160200.19633-4-david@redhat.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 22, 2021 at 05:02:00PM +0100, David Hildenbrand wrote: > All IORESOURCE_SYSTEM_RAM and IORESOURCE_MEM now properly consider the > whole resource tree, not just the first level. Let's drop the unused > first_lvl / siblings_only logic. > > All functions properly search the whole tree, so remove documentation > that indicates that some functions behave differently. Like this clean up! Reviewed-by: Andy Shevchenko Although a few nit-picks below. > Cc: Andrew Morton > Cc: Greg Kroah-Hartman > Cc: Dan Williams > Cc: Daniel Vetter > Cc: Andy Shevchenko > Cc: Mauro Carvalho Chehab > Cc: Signed-off-by: David Hildenbrand > Cc: Dave Young > Cc: Baoquan He > Cc: Vivek Goyal > Cc: Dave Hansen > Cc: Keith Busch > Cc: Michal Hocko > Cc: Qian Cai > Cc: Oscar Salvador > Cc: Eric Biederman > Cc: Thomas Gleixner > Cc: Ingo Molnar > Cc: Borislav Petkov > Cc: "H. Peter Anvin" > Cc: Tom Lendacky > Cc: Brijesh Singh > Cc: x86@kernel.org > Cc: kexec@lists.infradead.org > Signed-off-by: David Hildenbrand > --- > kernel/resource.c | 45 ++++++++++++--------------------------------- > 1 file changed, 12 insertions(+), 33 deletions(-) > > diff --git a/kernel/resource.c b/kernel/resource.c > index 16e0c7e8ed24..7e00239a023a 100644 > --- a/kernel/resource.c > +++ b/kernel/resource.c > @@ -64,12 +64,8 @@ static DEFINE_RWLOCK(resource_lock); > static struct resource *bootmem_resource_free; > static DEFINE_SPINLOCK(bootmem_resource_lock); > > -static struct resource *next_resource(struct resource *p, bool sibling_only) > +static struct resource *next_resource(struct resource *p) > { > - /* Caller wants to traverse through siblings only */ > - if (sibling_only) > - return p->sibling; > - > if (p->child) > return p->child; > while (!p->sibling && p->parent) > @@ -81,7 +77,7 @@ static void *r_next(struct seq_file *m, void *v, loff_t *pos) > { > struct resource *p = v; > (*pos)++; > - return (void *)next_resource(p, false); > + return (void *)next_resource(p); > } > > #ifdef CONFIG_PROC_FS > @@ -330,14 +326,10 @@ EXPORT_SYMBOL(release_resource); > * of the resource that's within [@start..@end]; if none is found, returns > * -ENODEV. Returns -EINVAL for invalid parameters. > * > - * This function walks the whole tree and not just first level children > - * unless @first_lvl is true. > - * > * @start: start address of the resource searched for > * @end: end address of same resource > * @flags: flags which the resource must have > * @desc: descriptor the resource must have > - * @first_lvl: walk only the first level children, if set > * @res: return ptr, if resource found > * > * The caller must specify @start, @end, @flags, and @desc > @@ -345,9 +337,8 @@ EXPORT_SYMBOL(release_resource); > */ > static int find_next_iomem_res(resource_size_t start, resource_size_t end, > unsigned long flags, unsigned long desc, > - bool first_lvl, struct resource *res) > + struct resource *res) > { > - bool siblings_only = true; > struct resource *p; > > if (!res) > @@ -358,7 +349,7 @@ static int find_next_iomem_res(resource_size_t start, resource_size_t end, > > read_lock(&resource_lock); > > - for (p = iomem_resource.child; p; p = next_resource(p, siblings_only)) { > + for (p = iomem_resource.child; p; p = next_resource(p)) { > /* If we passed the resource we are looking for, stop */ > if (p->start > end) { > p = NULL; > @@ -369,13 +360,6 @@ static int find_next_iomem_res(resource_size_t start, resource_size_t end, > if (p->end < start) > continue; > > - /* > - * Now that we found a range that matches what we look for, > - * check the flags and the descriptor. If we were not asked to > - * use only the first level, start looking at children as well. > - */ > - siblings_only = first_lvl; > - > if ((p->flags & flags) != flags) > continue; > if ((desc != IORES_DESC_NONE) && (desc != p->desc)) > @@ -402,14 +386,14 @@ static int find_next_iomem_res(resource_size_t start, resource_size_t end, > > static int __walk_iomem_res_desc(resource_size_t start, resource_size_t end, > unsigned long flags, unsigned long desc, > - bool first_lvl, void *arg, > + void *arg, > int (*func)(struct resource *, void *)) Can it be one line? > { > struct resource res; > int ret = -EINVAL; > > while (start < end && > - !find_next_iomem_res(start, end, flags, desc, first_lvl, &res)) { > + !find_next_iomem_res(start, end, flags, desc, &res)) { > ret = (*func)(&res, arg); > if (ret) > break; > @@ -431,7 +415,6 @@ static int __walk_iomem_res_desc(resource_size_t start, resource_size_t end, > * @arg: function argument for the callback @func > * @func: callback function that is called for each qualifying resource area > * > - * This walks through whole tree and not just first level children. > * All the memory ranges which overlap start,end and also match flags and > * desc are valid candidates. > * > @@ -441,7 +424,7 @@ static int __walk_iomem_res_desc(resource_size_t start, resource_size_t end, > int walk_iomem_res_desc(unsigned long desc, unsigned long flags, u64 start, > u64 end, void *arg, int (*func)(struct resource *, void *)) > { > - return __walk_iomem_res_desc(start, end, flags, desc, false, arg, func); > + return __walk_iomem_res_desc(start, end, flags, desc, arg, func); > } > EXPORT_SYMBOL_GPL(walk_iomem_res_desc); > > @@ -457,8 +440,8 @@ int walk_system_ram_res(u64 start, u64 end, void *arg, > { > unsigned long flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY; > > - return __walk_iomem_res_desc(start, end, flags, IORES_DESC_NONE, false, > - arg, func); > + return __walk_iomem_res_desc(start, end, flags, IORES_DESC_NONE, arg, > + func); I guess you may do it on one line. > } > > /* > @@ -470,17 +453,14 @@ int walk_mem_res(u64 start, u64 end, void *arg, > { > unsigned long flags = IORESOURCE_MEM | IORESOURCE_BUSY; > > - return __walk_iomem_res_desc(start, end, flags, IORES_DESC_NONE, false, > - arg, func); > + return __walk_iomem_res_desc(start, end, flags, IORES_DESC_NONE, arg, > + func); Ditto. > } > > /* > * This function calls the @func callback against all memory ranges of type > * System RAM which are marked as IORESOURCE_SYSTEM_RAM and IORESOUCE_BUSY. > * It is to be used only for System RAM. > - * > - * This will find System RAM ranges that are children of top-level resources > - * in addition to top-level System RAM resources. > */ > int walk_system_ram_range(unsigned long start_pfn, unsigned long nr_pages, > void *arg, int (*func)(unsigned long, unsigned long, void *)) > @@ -495,8 +475,7 @@ int walk_system_ram_range(unsigned long start_pfn, unsigned long nr_pages, > end = ((u64)(start_pfn + nr_pages) << PAGE_SHIFT) - 1; > flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY; > while (start < end && > - !find_next_iomem_res(start, end, flags, IORES_DESC_NONE, > - false, &res)) { > + !find_next_iomem_res(start, end, flags, IORES_DESC_NONE, &res)) { > pfn = PFN_UP(res.start); > end_pfn = PFN_DOWN(res.end + 1); > if (end_pfn > pfn) > -- > 2.29.2 > -- With Best Regards, Andy Shevchenko