Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2512069pxb; Fri, 17 Sep 2021 11:24:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz89676QFTgpjmQwCAxtvCa/sbo3p7OsrT6DSfhOd6rO8e1MJupcRyyzxaHJV/RXBoCVY+h X-Received: by 2002:a5d:84d2:: with SMTP id z18mr7870123ior.52.1631903050876; Fri, 17 Sep 2021 11:24:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631903050; cv=none; d=google.com; s=arc-20160816; b=jptLO9xrSJFzJ5RzPYbf5KOanUMHIn+Fdr3Yk/+gXYQ+5OVhGeUA2d7f1bj1xTsWkL dficZnOlpMbKAo9wd/Jeu1dXj3rF+k58oqjsWw5xjXQbo+iYak8qvcUFYpF7f82fDQ7z A0//MFjPzQt28YhoeSCQcAV0WSkdOCcj0ewWqHIuIg0smPrIzbnB/6e06pLcXv7oUk6m UEe2Ujgv07HdeohmPoGIA3hKFx41BdppYCArdVq7FrkSjPKP3MckQCKH85k68Gpc+056 qDC5hGTKA7EgWn4XRvA5Y2ERU9hd1PczKLQ4Gd6Z8VARRKU7UWRlUv+a/NicLyYHhtyM MCig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=ilmdDUD6qsXcaiPoHf3s6YHGPq9ZLgh8ShhzVJlWhq4=; b=KAQi373sb2+ElUDq+s3xJmxKeNXWBgr3PTFaftf5enh0RGIJ2e/6WNrZi28WCSOcbV Pe7h/hnZHO013DskFZI/PzFdkF0Uzd2OaQfLc4xXwTp74u/2qhT6SniBxc06vPK+2bkO chYYNOCHFnc1/SeNJQw00iygB0mxbvtOaZ+rXpczhgwGHmCfh+IAOoXw7XN1V1DncxFc hLGsTf0ox3bvrhngfwnbvo7dOBOeHHcnU5fhqaaQndmt/mS2zAUtZlUbdPytkJRI2gTx +/tPjExvH29N0O8KY4F5I9qmccCc7NLndjumI6K3j5icA6jv719OGDiZpLc1hoOC23zT xsDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=L5N5pLsy; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q2si6176539jac.2.2021.09.17.11.23.59; Fri, 17 Sep 2021 11:24:10 -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; dkim=pass header.i=@gmail.com header.s=20210112 header.b=L5N5pLsy; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343626AbhIQJqY (ORCPT + 99 others); Fri, 17 Sep 2021 05:46:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245748AbhIQJqR (ORCPT ); Fri, 17 Sep 2021 05:46:17 -0400 Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECDC7C061764; Fri, 17 Sep 2021 02:44:55 -0700 (PDT) Received: by mail-qt1-x830.google.com with SMTP id u4so8245050qta.2; Fri, 17 Sep 2021 02:44:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ilmdDUD6qsXcaiPoHf3s6YHGPq9ZLgh8ShhzVJlWhq4=; b=L5N5pLsyDpOW+k7EHOX1yiZRWFugStu3kxDpMgeDUiWViGc53vmBALJZTInp386PeU Vmn80DkA9ZMBXk33Bg8uAnXDO5EqpcUMoN576VkymOONriE0nwS+fL87alc+NcpSskcH HMoamoFB+gr4OVB838sNcziIzYhG/5Idn2mGOYzrEHe3E4D+A0qSStestChxN2O+sw+6 OT2ToUEoIq2UFe6RWygTN3p3HiQX7voiLll0gAfq57froxpug9/nP234brSeE2oCMp2J UbiFoHVjAMpa6e04M42+UHbIkCV/GV0EaW07877Br8SQ1xXnacTFW0Flau7FLFyew8s+ XVUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ilmdDUD6qsXcaiPoHf3s6YHGPq9ZLgh8ShhzVJlWhq4=; b=l/3ZcHJUxho8tliqXcM3vIeS3FVQ85l3S50t3vmHwfXk9yNocN0SuTLtuKIGh5knax M2ivFQ8a/ab2v8QvAjzNpsK1AFfouxwfZPLNZYTcGGsL3IaOIKZItgXob61yG3yQx8VB 9iAQb26a5FvPktgzvigwb+vWPPPzS8jczjR4m3uGDkHqYlXJPWW86O6yKaMuncjs7VSK N5/Aj3rhm+/6COgQ4BtXTMT8Lfg6leb44otW06dVmKddFy9x0Kdg+y5wwZZuxtw8tzTg MIFC1q5f61d0z7lU94/41AdT6Uoo8nPOBhsCc+SJAiikHE7D8MxStJu6DPX8RzRm7MZ5 hxDg== X-Gm-Message-State: AOAM530ic/2cyl+5rQ+/VOuV90PLVel/wvNEDYTMPvoUfxG1bViKAyEn 9u2I1K2X0XGpFN3s3tEoqB1F+AeruSc1uskxo+8= X-Received: by 2002:ac8:5316:: with SMTP id t22mr1124648qtn.176.1631871895128; Fri, 17 Sep 2021 02:44:55 -0700 (PDT) MIME-Version: 1.0 References: <1631092255-25150-1-git-send-email-shengjiu.wang@nxp.com> <1631092255-25150-4-git-send-email-shengjiu.wang@nxp.com> <20210915161624.GA1770838@p14s> <20210916165957.GA1825273@p14s> In-Reply-To: From: Shengjiu Wang Date: Fri, 17 Sep 2021 17:44:44 +0800 Message-ID: Subject: Re: [PATCH v4 3/4] remoteproc: imx_dsp_rproc: Add remoteproc driver for DSP on i.MX To: Mathieu Poirier Cc: Shengjiu Wang , Ohad Ben Cohen , Bjorn Andersson , Rob Herring , Shawn Guo , Sascha Hauer , Sascha Hauer , Fabio Estevam , Daniel Baluta , NXP Linux Team , "open list:REMOTE PROCESSOR (REMOTEPROC) SUBSYSTEM" , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , "moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE" , linux-kernel Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 17, 2021 at 1:20 PM Shengjiu Wang wrote: > > On Fri, Sep 17, 2021 at 1:00 AM Mathieu Poirier > wrote: > > > > [...] > > > > > > > + > > > > > +/** > > > > > + * imx_dsp_rproc_elf_load_segments() - load firmware segments to memory > > > > > + * @rproc: remote processor which will be booted using these fw segments > > > > > + * @fw: the ELF firmware image > > > > > + * > > > > > + * This function specially checks if memsz is zero or not, otherwise it > > > > > + * is mostly same as rproc_elf_load_segments(). > > > > > + */ > > > > > +static int imx_dsp_rproc_elf_load_segments(struct rproc *rproc, > > > > > + const struct firmware *fw) > > > > > +{ > > > > > + struct device *dev = &rproc->dev; > > > > > + u8 class = fw_elf_get_class(fw); > > > > > + u32 elf_phdr_get_size = elf_size_of_phdr(class); > > > > > + const u8 *elf_data = fw->data; > > > > > + const void *ehdr, *phdr; > > > > > + int i, ret = 0; > > > > > + u16 phnum; > > > > > + > > > > > + ehdr = elf_data; > > > > > + phnum = elf_hdr_get_e_phnum(class, ehdr); > > > > > + phdr = elf_data + elf_hdr_get_e_phoff(class, ehdr); > > > > > + > > > > > + /* go through the available ELF segments */ > > > > > + for (i = 0; i < phnum; i++, phdr += elf_phdr_get_size) { > > > > > + u64 da = elf_phdr_get_p_paddr(class, phdr); > > > > > + u64 memsz = elf_phdr_get_p_memsz(class, phdr); > > > > > + u64 filesz = elf_phdr_get_p_filesz(class, phdr); > > > > > + u64 offset = elf_phdr_get_p_offset(class, phdr); > > > > > + u32 type = elf_phdr_get_p_type(class, phdr); > > > > > + void *ptr; > > > > > + bool is_iomem; > > > > > + > > > > > + if (type != PT_LOAD || !memsz) > > > > > > > > You did a really good job with adding comments but this part is undocumented... > > > > If I read this correctly you need to check for !memsz because some part of > > > > the program segment may have a header but its memsz is zero, in which case it can > > > > be safely skipped. So why is that segment in the image to start with, and why > > > > is it marked PT_LOAD if it is not needed? This is very puzzling... > > > > > > Actually I have added comments in the header of this function. > > > > Indeed there is a mention of memsz in the function's header but it doesn't > > mention _why_ this is needed, and that is what I'm looking for. > > > > > > > > memsz= 0 with PT_LOAD issue, I have asked the toolchain's vendor, > > > they said that this case is allowed by elf spec... > > > > > > And in the "pru_rproc.c" and "mtk_scp.c", seems they met same problem > > > they also check the filesz in their internal xxx_elf_load_segments() function. > > > > In both cases they are skipping PT_LOAD sections where "filesz" is '0', which > > makes sense because we don't know how many bytes to copy. But here you are > > skipping over a PT_LOAD section with a potentially valid filesz, and that is the > > part I don't understand. > > Ok, I can use filesz instead. For my case, filesz = memsz = 0, > it is the same result I want. > > The reason why I use "memsz '' is because there is "if (filesz > memsz) " > check after this, if memsz is zero, then "filesz" should be zero too, other > values are not allowed. But I still think checking "!memsz" is better than filesz, because memsz > filesz is allowed (filesz = 0), the code below can be executed. filesz > memsz is not allowed. What do you think? Best regards Wang shengjiu > > > > > > > > > > > > > > > > > > > + continue; > > > > > + > > > > > + dev_dbg(dev, "phdr: type %d da 0x%llx memsz 0x%llx filesz 0x%llx\n", > > > > > + type, da, memsz, filesz); > > > > > + > > > > > + if (filesz > memsz) { > > > > > + dev_err(dev, "bad phdr filesz 0x%llx memsz 0x%llx\n", > > > > > + filesz, memsz); > > > > > + ret = -EINVAL; > > > > > + break; > > > > > + } > > > > > + > > > > > + if (offset + filesz > fw->size) { > > > > > + dev_err(dev, "truncated fw: need 0x%llx avail 0x%zx\n", > > > > > + offset + filesz, fw->size); > > > > > + ret = -EINVAL; > > > > > + break; > > > > > + } > > > > > + > > > > > + if (!rproc_u64_fit_in_size_t(memsz)) { > > > > > + dev_err(dev, "size (%llx) does not fit in size_t type\n", > > > > > + memsz); > > > > > + ret = -EOVERFLOW; > > > > > + break; > > > > > + } > > > > > + > > > > > + /* grab the kernel address for this device address */ > > > > > + ptr = rproc_da_to_va(rproc, da, memsz, &is_iomem); > > > > > > > > rproc_da_to_va(rproc, da, memsz, NULL); > > > > > > yes, will update it. > > > > > > > > > > > More comments to follow later today or tomorrow. > > > > > > Thanks. > > > > > > Best regards > > > Wang Shengjiu