Received: by 10.213.65.68 with SMTP id h4csp1184233imn; Thu, 22 Mar 2018 18:02:00 -0700 (PDT) X-Google-Smtp-Source: AG47ELuSUS7s/CVTbqG3Er+tFsjBdBwYaNB6xlIrkhNfxreLN3LwE3tMTCQDcj5USpLxxKWBXi2B X-Received: by 10.98.75.129 with SMTP id d1mr22276489pfj.19.1521766920620; Thu, 22 Mar 2018 18:02:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521766920; cv=none; d=google.com; s=arc-20160816; b=clxRl5YlcPO3dC0lIUJs/fg2or+PvpJEFTtyR32zs79gV4ZVzbfl0uPOxbcAo9UDPM YQZCfWLWez1jc/gBoyGAeQ0Jk+054aZOteaspAI/eshnTyr/2JJSYUk4/MpWyvP53TrT 7qWB+XID8ripYEQzryi5mwQhO+VlwOAqWSuP9wR9r7gBMyeq3XM4bLX6M5pV0tj0mcQb uswP4JooqA2WsxXRVeG1scsUvo2yzGxui1Cj54BB7rXSAQD6iMtpVxR6yOSVmB1z50Gp 1UPbU/LEoX88Rw0QT4h5KWw6UCVSlyl5jfx5QWhk1OcE9U1cv1DBYE5s0yYQcYNj54Zp x0uA== 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:arc-authentication-results; bh=mcQ98YlprrstmfnxUAPHjX21TKYxexfG3UQ2Z+oBhe0=; b=iKf/sjTZ+nAUWjBsxhg3RR30+Zg3nE5QOIMRolV3lnZs8ngqFdaQQGJPBtnZPDfYCI D+/MGRDxtK9/DR9Ej+28Y6LVIVA8iuCC7KL/P3q5VR4DxpUWYnCuPc8h1qMbe2v8weIs I6CSESL5kemIZiWVyZfbq56YCFeyht6iyyNiXcDj+d5Aa8gtXICHU1NhBmD30EPIhAg0 JhmTCsxDW5tpDzYsy1eMpAWQ480M/cq0ituAYFjpKnzZAVPbBi9AvhABNhQ3qFm0kAY+ CXoTD5vXabH38E33jPQ7TumZ+lVjV5BZl1ry/7DY/wErcwE/ogxb6tMe6N/27L6ATnkO 93Sw== 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q1si5063340pgt.303.2018.03.22.18.01.45; Thu, 22 Mar 2018 18:02:00 -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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752028AbeCWA6w (ORCPT + 99 others); Thu, 22 Mar 2018 20:58:52 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:49738 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751551AbeCWA6u (ORCPT ); Thu, 22 Mar 2018 20:58:50 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BBF958182D3A; Fri, 23 Mar 2018 00:58:49 +0000 (UTC) Received: from localhost (ovpn-8-20.pek2.redhat.com [10.72.8.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C7456215CDA7; Fri, 23 Mar 2018 00:58:48 +0000 (UTC) Date: Fri, 23 Mar 2018 08:58:45 +0800 From: Baoquan He To: Andrew Morton Cc: linux-kernel@vger.kernel.org, kexec@lists.infradead.org, takahiro.akashi@linaro.org, ebiederm@xmission.com, vgoyal@redhat.com, dyoung@redhat.com, prudo@linux.vnet.ibm.com Subject: Re: [PATCH 1/2] resource: add walk_system_ram_res_rev() Message-ID: <20180323005845.GA25740@localhost.localdomain> References: <20180322033722.9279-1-bhe@redhat.com> <20180322033722.9279-2-bhe@redhat.com> <20180322152929.9b421af2f66cc819ad691207@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180322152929.9b421af2f66cc819ad691207@linux-foundation.org> User-Agent: Mutt/1.9.1 (2017-09-22) X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 23 Mar 2018 00:58:49 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 23 Mar 2018 00:58:49 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'bhe@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Andrew, Thanks a lot for your reviewing! On 03/22/18 at 03:29pm, Andrew Morton wrote: > > /* > > + * This function, being a variant of walk_system_ram_res(), calls the @func > > + * callback against all memory ranges of type System RAM which are marked as > > + * IORESOURCE_SYSTEM_RAM and IORESOUCE_BUSY in reversed order, i.e., from > > + * higher to lower. > > + */ > > This should document the return value, as should walk_system_ram_res(). > Why does it return -1 on error rather than an errno (ENOMEM)? OK, will add sentences to tell this. So for walk_system_ram_res() only '-1' indicates the failure of finding, '0' the success. While in walk_system_ram_res_rev(), add '-ENOMEM' to indicate failure of vmalloc allocation. > > > +int walk_system_ram_res_rev(u64 start, u64 end, void *arg, > > + int (*func)(struct resource *, void *)) > > +{ > > + struct resource res, *rams; > > + int rams_size = 16, i; > > + int ret = -1; > > + > > + /* create a list */ > > + rams = vmalloc(sizeof(struct resource) * rams_size); > > + if (!rams) > > + return ret; > > + > > + res.start = start; > > + res.end = end; > > + res.flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY; > > + i = 0; > > + while ((res.start < res.end) && > > + (!find_next_iomem_res(&res, IORES_DESC_NONE, true))) { > > + if (i >= rams_size) { > > + /* re-alloc */ > > + struct resource *rams_new; > > + int rams_new_size; > > + > > + rams_new_size = rams_size + 16; > > + rams_new = vmalloc(sizeof(struct resource) > > + * rams_new_size); > > + if (!rams_new) > > + goto out; > > + > > + memcpy(rams_new, rams, > > + sizeof(struct resource) * rams_size); > > + vfree(rams); > > + rams = rams_new; > > + rams_size = rams_new_size; > > + } > > + > > + rams[i].start = res.start; > > + rams[i++].end = res.end; > > + > > + res.start = res.end + 1; > > + res.end = end; > > + } > > + > > + /* go reverse */ > > + for (i--; i >= 0; i--) { > > + ret = (*func)(&rams[i], arg); > > + if (ret) > > + break; > > + } > > erk, this is pretty nasty. Isn't there a better way :( Yes, this is not efficient. In struct resource{}, ->sibling list is a singly linked list. I ever thought about changing it to doubly linked list, yet not very sure if it will have effect since struct resource is a core data structure. AKASHI's method is more acceptable, and currently only kexec has this requirement. > > > +out: > > + vfree(rams); > > + return ret; > > +} >