Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5404307ybv; Tue, 11 Feb 2020 15:13:08 -0800 (PST) X-Google-Smtp-Source: APXvYqzJjp44ZY6x9BUxYnA7zylUGqfDAZ1UVtrNagQdLLNDzQHTiJO5CQ6l5O4rc2EEvBav71Wa X-Received: by 2002:a05:6830:c9:: with SMTP id x9mr7112145oto.345.1581462788177; Tue, 11 Feb 2020 15:13:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581462788; cv=none; d=google.com; s=arc-20160816; b=DI8eg9MRTMKMPXXm/dU5LKVHue9joHn8Xeh9+6sdt5vhy4GfF7SVgNjnaC+KLC66ar sWpKlVDn6g2ocsutjX2LOfoV8cYFlnmIyUaHONnxHiGbqNvQxZuMuvY1nvbBTdw96wpr ekpIF2BQFtmY/Qdjlxtsl5RZ5tAxmVnOuvEAv840hksbQ3JYMd9EMZ/8MFVhTierV6o0 mUue1P4y0BDGCGmm/UVFL9jiWU68CiupX82WKTiQiJhRAEa/dm5Dk99RNQkw9SOuKmQJ JeEhsrYSH/Gd1Y4lTJreQXBlxHxfd4Jb+S1LZKvwHvKkHgEFtp7bRJOBOzG0/S7tYRIJ +x4Q== 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=EXXb6hCMslPYpe5QP7cxVvPU1qd+QxQG6hNKW0K/ZLY=; b=gCOAyPivbRTI8zlLDBDJPa6ichUSf2UaGHzWzXY20/FUIsrSdyfhn1ZEzoQzNmNc7C 6xO23wpujEO4I2mmpO0gTT+Z9yFdYB1HtJ3A1P8h2oQ6pv30EZEzJ+1kw5A6654IoRcA h5+Ts+qgf7eqMQFnJ3iRX+DWz69YH4HEWWH3qB/7p3Zt0Xwaiwk5biSSKmq/RjY2f9gQ LT/GYGxGYZQTT0iDfKPbhukfv3qQmD6vj8IJBkQRmz/FHKTnFYD/BWPnQVkmiWjoQT4k R2fHIkNNT2g0YJlJkoVovXnsxaD1ab03osvgnvHTxCt9lAmxvQZADYmpI5Fo+Rl8XQ69 wS8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fop2NIzB; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v13si2552309otp.273.2020.02.11.15.12.47; Tue, 11 Feb 2020 15:13:08 -0800 (PST) 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=pass header.i=@linaro.org header.s=google header.b=fop2NIzB; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727879AbgBKXLX (ORCPT + 99 others); Tue, 11 Feb 2020 18:11:23 -0500 Received: from mail-yw1-f65.google.com ([209.85.161.65]:46685 "EHLO mail-yw1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727640AbgBKXLX (ORCPT ); Tue, 11 Feb 2020 18:11:23 -0500 Received: by mail-yw1-f65.google.com with SMTP id z141so154863ywd.13 for ; Tue, 11 Feb 2020 15:11:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=EXXb6hCMslPYpe5QP7cxVvPU1qd+QxQG6hNKW0K/ZLY=; b=fop2NIzBeVUkWE0MlDvWAQtd9quHXKUj9/QUT8DzCVcakN2DfmHAbDUwD56PGJNQMw 0b+nhl7EM6w5ux123fhGvdDJlkNi5i+W6PxI6/IGmYEeOkZNyg7FxpeFL4hke2j2QRwD d8Qo97MbA/K8UziNakOSCGkH31E6H2B27AUPVpddgO2cVYm1GD9+dOFx4/NZa23LFNon vKBmrRqhXJF9ReafwFZONeQYUFAKlHV5vCIbfAdzMeuKKoEw7Yb2QPqx6ce2KCc5wzUy QNbxBDwY5VY63Y+YtBk3M6ueHAgpi70zeFc7v8zNFQMceaBolVO4appQ3jPKdbL382TM exkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=EXXb6hCMslPYpe5QP7cxVvPU1qd+QxQG6hNKW0K/ZLY=; b=mto3v79sUdqj0aYs4DwqLfTa4Biodh8Hnk92ICupfEEdjg2navkVlfVJQH28ujd1El m+axNKz6ViWSrc/bmXxb8hDDwlolwidNx6sYO7waf3urOm3lRim8zGOdh3tNM9wDpvOb ZPU3QTV6cWBMWszzCGx2D046SGRxD9QEr63dBNRQbXIWRP3VGz+10k8rr46Vss2U94OH QrUmDpwdJyBxZUO9zPDdM2z1lsYi3bk/WENI4K7A7VAcCBnwRzzrHcMRFdmHUa25DF9X 8TiMsztp/3QyGeXt1/NwLpnHzgEMmp8QoTSv7xsAU+P0V0GPWeToDQcK7Wl01PsHutfL Eibg== X-Gm-Message-State: APjAAAVcMwSFctG8lZm1B4LSGOHi2g7Opacz04HjXzxhdE4lvDktRLJp 05dFE/vFNCirMPSh/dlxDJlh4A== X-Received: by 2002:a81:1fc2:: with SMTP id f185mr8054253ywf.241.1581462681779; Tue, 11 Feb 2020 15:11:21 -0800 (PST) Received: from xps15 (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id i84sm2571884ywc.43.2020.02.11.15.11.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Feb 2020 15:11:21 -0800 (PST) Date: Tue, 11 Feb 2020 16:11:18 -0700 From: Mathieu Poirier To: Clement Leger Cc: Ohad Ben-Cohen , Bjorn Andersson , Jonathan Corbet , Shawn Guo , Sascha Hauer , linux-remoteproc@vger.kernel.org, Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Andy Gross , Patrice Chotard , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, Arnaud Pouliquen , Loic PALLARDY , s-anna Subject: Re: [PATCH v4 5/5] remoteproc: Adapt coredump to generate correct elf type Message-ID: <20200211231118.GB27770@xps15> References: <527785289.2852303.1581062223707.JavaMail.zimbra@kalray.eu> <20200210162209.23149-1-cleger@kalray.eu> <20200210162209.23149-6-cleger@kalray.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200210162209.23149-6-cleger@kalray.eu> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 10, 2020 at 05:22:09PM +0100, Clement Leger wrote: > Now that remoteproc can load an elf64, coredump elf class should be > the same as the loaded elf class. In order to do that, add a > elf_class field to rproc with default values. If an elf is loaded > successfully, these fields will be updated with the loaded elf class. > Then, the coredump core code has been modified to use the generic elf > macro in order to create an elf file with correct class. > > Signed-off-by: Clement Leger > --- > drivers/remoteproc/remoteproc_core.c | 67 ++++++++++++++++-------------- > drivers/remoteproc/remoteproc_elf_loader.c | 3 ++ > include/linux/remoteproc.h | 1 + > 3 files changed, 39 insertions(+), 32 deletions(-) > > diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c > index 9e6d3c6a60ee..ce70656ae150 100644 > --- a/drivers/remoteproc/remoteproc_core.c > +++ b/drivers/remoteproc/remoteproc_core.c > @@ -38,6 +38,7 @@ > #include > > #include "remoteproc_internal.h" > +#include "remoteproc_elf_helpers.h" > > #define HIGH_BITS_MASK 0xFFFFFFFF00000000ULL > > @@ -1564,20 +1565,21 @@ EXPORT_SYMBOL(rproc_coredump_add_custom_segment); > static void rproc_coredump(struct rproc *rproc) > { > struct rproc_dump_segment *segment; > - struct elf32_phdr *phdr; > - struct elf32_hdr *ehdr; > + void *phdr; > + void *ehdr; > size_t data_size; > size_t offset; > void *data; > void *ptr; > + u8 class = rproc->elf_class; > int phnum = 0; > > if (list_empty(&rproc->dump_segments)) > return; > > - data_size = sizeof(*ehdr); > + data_size = elf_size_of_hdr(class); > list_for_each_entry(segment, &rproc->dump_segments, node) { > - data_size += sizeof(*phdr) + segment->size; > + data_size += elf_size_of_phdr(class) + segment->size; > > phnum++; > } > @@ -1588,33 +1590,33 @@ static void rproc_coredump(struct rproc *rproc) > > ehdr = data; > > - memset(ehdr, 0, sizeof(*ehdr)); > - memcpy(ehdr->e_ident, ELFMAG, SELFMAG); > - ehdr->e_ident[EI_CLASS] = ELFCLASS32; > - ehdr->e_ident[EI_DATA] = ELFDATA2LSB; > - ehdr->e_ident[EI_VERSION] = EV_CURRENT; > - ehdr->e_ident[EI_OSABI] = ELFOSABI_NONE; > - ehdr->e_type = ET_CORE; > - ehdr->e_machine = EM_NONE; > - ehdr->e_version = EV_CURRENT; > - ehdr->e_entry = rproc->bootaddr; > - ehdr->e_phoff = sizeof(*ehdr); > - ehdr->e_ehsize = sizeof(*ehdr); > - ehdr->e_phentsize = sizeof(*phdr); > - ehdr->e_phnum = phnum; > - > - phdr = data + ehdr->e_phoff; > - offset = ehdr->e_phoff + sizeof(*phdr) * ehdr->e_phnum; > + memset(ehdr, 0, elf_size_of_hdr(class)); > + /* e_ident field is common for both elf32 and elf64 */ > + elf_hdr_init_ident(ehdr, class); > + > + elf_hdr_set_e_type(class, ehdr, ET_CORE); > + elf_hdr_set_e_machine(class, ehdr, EM_NONE); > + elf_hdr_set_e_version(class, ehdr, EV_CURRENT); > + elf_hdr_set_e_entry(class, ehdr, rproc->bootaddr); > + elf_hdr_set_e_phoff(class, ehdr, elf_size_of_hdr(class)); > + elf_hdr_set_e_ehsize(class, ehdr, elf_size_of_hdr(class)); > + elf_hdr_set_e_phentsize(class, ehdr, elf_size_of_phdr(class)); > + elf_hdr_set_e_phnum(class, ehdr, phnum); > + > + phdr = data + elf_hdr_get_e_phoff(class, ehdr); > + offset = elf_hdr_get_e_phoff(class, ehdr); > + offset += elf_size_of_phdr(class) * elf_hdr_get_e_phnum(class, ehdr); > + > list_for_each_entry(segment, &rproc->dump_segments, node) { > - memset(phdr, 0, sizeof(*phdr)); > - phdr->p_type = PT_LOAD; > - phdr->p_offset = offset; > - phdr->p_vaddr = segment->da; > - phdr->p_paddr = segment->da; > - phdr->p_filesz = segment->size; > - phdr->p_memsz = segment->size; > - phdr->p_flags = PF_R | PF_W | PF_X; > - phdr->p_align = 0; > + memset(phdr, 0, elf_size_of_phdr(class)); > + elf_phdr_set_p_type(class, phdr, PT_LOAD); > + elf_phdr_set_p_offset(class, phdr, offset); > + elf_phdr_set_p_vaddr(class, phdr, segment->da); > + elf_phdr_set_p_paddr(class, phdr, segment->da); > + elf_phdr_set_p_filesz(class, phdr, segment->size); > + elf_phdr_set_p_memsz(class, phdr, segment->size); > + elf_phdr_set_p_flags(class, phdr, PF_R | PF_W | PF_X); > + elf_phdr_set_p_align(class, phdr, 0); > > if (segment->dump) { > segment->dump(rproc, segment, data + offset); > @@ -1630,8 +1632,8 @@ static void rproc_coredump(struct rproc *rproc) > } > } > > - offset += phdr->p_filesz; > - phdr++; > + offset += elf_phdr_get_p_filesz(class, phdr); > + phdr += elf_size_of_phdr(class); > } > > dev_coredumpv(&rproc->dev, data, data_size, GFP_KERNEL); > @@ -2029,6 +2031,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, > rproc->name = name; > rproc->priv = &rproc[1]; > rproc->auto_boot = true; > + rproc->elf_class = ELFCLASS32; I suppose this is as good a place as any. > > device_initialize(&rproc->dev); > rproc->dev.parent = dev; > diff --git a/drivers/remoteproc/remoteproc_elf_loader.c b/drivers/remoteproc/remoteproc_elf_loader.c > index 2ffb02a2ee36..07712a541ea6 100644 > --- a/drivers/remoteproc/remoteproc_elf_loader.c > +++ b/drivers/remoteproc/remoteproc_elf_loader.c > @@ -220,6 +220,9 @@ int rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw) > memset(ptr + filesz, 0, memsz - filesz); > } > > + if (ret == 0) > + rproc->elf_class = class; > + > return ret; > } > EXPORT_SYMBOL(rproc_elf_load_segments); > diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h > index 82cebca9344c..113e356ce56a 100644 > --- a/include/linux/remoteproc.h > +++ b/include/linux/remoteproc.h > @@ -514,6 +514,7 @@ struct rproc { > bool auto_boot; > struct list_head dump_segments; > int nb_vdev; > + int elf_class; Type 'int'? I expected 'u8' as it is in the specification and in rproc_elf_load_segments(). Thanks, Mathieu > }; > > /** > -- > 2.15.0.276.g89ea799 >