Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4062660pxf; Tue, 6 Apr 2021 07:09:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxARE4mnn9OQ1guPdNn1ytkXMfvKTT5daF9UAeQzMJshMsUlAVRC8u/9fcteQWO8A6PosG X-Received: by 2002:a05:6e02:1084:: with SMTP id r4mr7023672ilj.202.1617718175131; Tue, 06 Apr 2021 07:09:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617718175; cv=none; d=google.com; s=arc-20160816; b=bY35BSr6PlQOI2is4EaMKA/6PrbC3+QKQqsgYHUtgWX8W8HeVWTa9dtco3VmklyTw7 oalBpujeJNKeQjD9NkgPbm4HVUHA1xSgrK4aDyoqnxirzXaCY+JgBcjKall2A6wRVwfK yuaozHwzEcfO3RUknX3wH2pAEA9nGw55ODjC7H0Vp48/HGdNznrcEzcMYVoZT2FMLT/o Jy7J93/NQ6iPd9Cf+9G2vIOlzYe5eczI1YcTctTwYsYsbMZ3MjGVn3c/Esi2e6ryYCQn VRaUvkCYPzyrnL/dzFpFO9PYdEwYPqOXync6mGhvsmEtKfHzmCVzY82S2ho0c3qqfntX DXhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=ar+ZvzB63y1/wjh7E1FNehlDOcDLDZymLGiFTsYxOx4=; b=bLCrWtM1KczS0jOXPVUB4OlioAAgznGhLLXHlAmFY2AF3oVz9ExpJGEm5EPJikEOy/ R0sWFxQsAbw64DiwO/tiBrV8YQlA9r0reo8muRdRQxQ1ZxUZG4LWBq+H1pnmoeKoquoO EAxN7cyPZAITjd+KLhBSWqfepUeycwY+5OcUV8pQg02V6MjOlnxVYgnW2Towa1kT8GvT FC7Q42vOSSDgxL2j6O44cjI/f4fX1RQ1fZIt89wOmfPiaHblrOKcK2MCxpnEkTS0e4tt hNd99VQ5pCPvzd91VZ2Bw5cT5R4M/u+XNiy2cnLZMLXUoJ7586MmqrKRvtLciYATrphK Dysg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t9si18356030ilu.69.2021.04.06.07.09.22; Tue, 06 Apr 2021 07:09:35 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239884AbhDFIWp convert rfc822-to-8bit (ORCPT + 99 others); Tue, 6 Apr 2021 04:22:45 -0400 Received: from mail-vk1-f177.google.com ([209.85.221.177]:36754 "EHLO mail-vk1-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239922AbhDFIWn (ORCPT ); Tue, 6 Apr 2021 04:22:43 -0400 Received: by mail-vk1-f177.google.com with SMTP id d82so3016055vkd.3 for ; Tue, 06 Apr 2021 01:22:36 -0700 (PDT) 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:content-transfer-encoding; bh=Az9dSdeZDXjGuSIhOGjrTFbuKwYYbifVIyBF0wPvnYY=; b=SjxAg5w+mrVv/Vpr2o9Pod9xoLSBum1JkEgFQL1r2ZIWQvntzSPolBDOisz+XiFFNr uCsnGwiKpkcGkZUgo1BjdA0ZUBbYsDCVc95LtP6/dhDsUWll9fluUptCsjbaDEhg/9AZ rDABdlSEa4J0eyi6LIka4RSbjFwXv/Q+OYmdWMoNyjm1IwGhE6GR3gme7l4sBzb2euua Q702R/PD0JV0j/kvzQtNiRh5pM2y8YS/csJ+Ua2tkJzPC6h//WJKJhg4uA9u4nkHA0Yr 13EUm+D29zQFMxsvBJRAEb4FQnt4KcRlm64tPLwN9CVD+3Xim+LCF4xC0ZzD6/57CD9U mr3w== X-Gm-Message-State: AOAM533cSLEdA0eoRweUa3D5mR+dUpBXdoOx4wVYOez7ow4hnV2+BfSJ zq4mrKFRFUOv54D4bOGnyuh4F1sXpEIOtexhdU9qdMLq X-Received: by 2002:a1f:2502:: with SMTP id l2mr16284892vkl.5.1617697355921; Tue, 06 Apr 2021 01:22:35 -0700 (PDT) MIME-Version: 1.0 References: <20210405085712.1953848-1-mick@ics.forth.gr> <20210405085712.1953848-4-mick@ics.forth.gr> <5a09d1f0ded4581c9e7458f546db9329@mailhost.ics.forth.gr> In-Reply-To: <5a09d1f0ded4581c9e7458f546db9329@mailhost.ics.forth.gr> From: Geert Uytterhoeven Date: Tue, 6 Apr 2021 10:22:24 +0200 Message-ID: Subject: Re: [PATCH v3 3/5] RISC-V: Improve init_resources To: Nick Kossifidis Cc: linux-riscv , Palmer Dabbelt , Paul Walmsley , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Nick, On Tue, Apr 6, 2021 at 10:11 AM Nick Kossifidis wrote: > Hello Geert, > Στις 2021-04-06 10:19, Geert Uytterhoeven έγραψε: > > On Mon, Apr 5, 2021 at 10:57 AM Nick Kossifidis > > wrote: > >> * Kernel region is always present and we know where it is, no > >> need to look for it inside the loop, just ignore it like the > >> rest of the reserved regions within system's memory. > >> > >> * Don't call memblock_free inside the loop, if called it'll split > >> the region of pre-allocated resources in two parts, messing things > >> up, just re-use the previous pre-allocated resource and free any > >> unused resources after both loops finish. > >> > >> * memblock_alloc may add a region when called, so increase the > >> number of pre-allocated regions by one to be on the safe side > >> (reported and patched by Geert Uytterhoeven) > >> > >> Signed-off-by: Geert Uytterhoeven > > > > Where does this SoB come from? > > > >> Signed-off-by: Nick Kossifidis > > > >> --- a/arch/riscv/kernel/setup.c > >> +++ b/arch/riscv/kernel/setup.c > > > >> @@ -129,53 +139,42 @@ static void __init init_resources(void) > >> struct resource *res = NULL; > >> struct resource *mem_res = NULL; > >> size_t mem_res_sz = 0; > >> - int ret = 0, i = 0; > >> - > >> - code_res.start = __pa_symbol(_text); > >> - code_res.end = __pa_symbol(_etext) - 1; > >> - code_res.flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY; > >> - > >> - rodata_res.start = __pa_symbol(__start_rodata); > >> - rodata_res.end = __pa_symbol(__end_rodata) - 1; > >> - rodata_res.flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY; > >> - > >> - data_res.start = __pa_symbol(_data); > >> - data_res.end = __pa_symbol(_edata) - 1; > >> - data_res.flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY; > >> + int num_resources = 0, res_idx = 0; > >> + int ret = 0; > >> > >> - bss_res.start = __pa_symbol(__bss_start); > >> - bss_res.end = __pa_symbol(__bss_stop) - 1; > >> - bss_res.flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY; > >> + /* + 1 as memblock_alloc() might increase > >> memblock.reserved.cnt */ > >> + num_resources = memblock.memory.cnt + memblock.reserved.cnt + > >> 1; > >> + res_idx = num_resources - 1; > >> > >> - mem_res_sz = (memblock.memory.cnt + memblock.reserved.cnt) * > >> sizeof(*mem_res); > > > > Oh, you incorporated my commit ce989f1472ae350e ("RISC-V: Fix > > out-of-bounds > > accesses in init_resources()") (from v5.12-rc4) into your patch. > > Why? This means your patch does not apply against upstream. > > > > Sorry if this looks awkward, I'm under the impression that new features > go on for-next instead of fixes and your patch hasn't been merged on > for-next yet. I thought it would be cleaner to have one patch to merge > for init_resources instead of two, and simpler for people to test the > series. I can rebase this on top of fixes if that works better for you > or Palmer. Ideally the fixes branch is part of the next branch. That also helps to avoid other people having to fix conflicts when merging both. Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds