Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5095718ybv; Tue, 11 Feb 2020 09:05:41 -0800 (PST) X-Google-Smtp-Source: APXvYqyG97ykZbIaa2Um1dUYtD91MoWGYiPm9Ped9JP5Hwr/z4StQajinFPFe2avrjCiy9FTTuM7 X-Received: by 2002:aca:bfc2:: with SMTP id p185mr3595397oif.57.1581440741345; Tue, 11 Feb 2020 09:05:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581440741; cv=none; d=google.com; s=arc-20160816; b=ubySOf484QrMxMNyzcJSx9NWqwQ2i0CSw+EU21M4/NfvKm8yxaKe90/j9vkN+8sAub Fv5IwCEt3dUtJJq02r7gtih+kPYceUrh5hqdZEWwiThHnNBlAW1CXb3Ral5nUKC6/sw/ wC2juBhGwYJmgg0ISLkKq5YNrBClabws8fC9W6L1MPouk0+YvcSxB/nDJaeuNSoopK+q IHV7/ZiUTav6I/RretqRWP8+0MrLzQYr1YMX69B4Qnwtgh9w9E0DT6Q+P2JAhOjtaSDb 6E4QGGPQvW/VGLg0KBA5W586o4ZXcMxDoMieonv3dgKU6/uz7fKgG1oSOO22GAQ16Up4 6XAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=Qj3pP1g0NIVpdR2tc7KGlV5T793lsE6uuaNjFu+vyqQ=; b=uj6ilAbaQvTQwiEl9ZfK8SpTqOqpf9kru1OGE8ZLnSXlumBGW+PdrC4GtEtU8SxNzp Z3JeUxTon2A+lkk/LpTmTuh7ayreRQemmBIpJ+mlQ1iAzugGjist0wb+ZgGEduD97mL1 og1gv+uX95fezZkBQwEJS0VBNrSOCkd9gTdr0uH1NucF4ImO7LBOjEsPqK4CgMG+sJlL oGzczeod+sm7+5F+bAgCOnskxHpO2XrptHf52bWEgIr/RT3Y0/fRZKIdILpAhb5vS2z7 rs2J+WsrSoaklkmn8xt2ecgzUVVon6Abp0yiTVrJvX1oqriLNEa2vXZ7vioVz1Cy1msm Hb3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@st.com header.s=STMicroelectronics header.b=DO7iqWMz; 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=st.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m19si1908861oig.91.2020.02.11.09.05.21; Tue, 11 Feb 2020 09:05:41 -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=@st.com header.s=STMicroelectronics header.b=DO7iqWMz; 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=st.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729715AbgBKPx4 (ORCPT + 99 others); Tue, 11 Feb 2020 10:53:56 -0500 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:1321 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728112AbgBKPx4 (ORCPT ); Tue, 11 Feb 2020 10:53:56 -0500 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01BFgap1025581; Tue, 11 Feb 2020 16:53:32 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=STMicroelectronics; bh=Qj3pP1g0NIVpdR2tc7KGlV5T793lsE6uuaNjFu+vyqQ=; b=DO7iqWMzefkgq1jxEJ7dMGmNWYGsTfR+rDE8syG0V4WVZBJqXJnE18Q05VlwUtIMY6Ab pg/R0zsMKUGLc0U00+e5/j/uK8VGE2nvRKHTh9XnI10yPX7fTzOa74sgl/v4W+Vk53gj PG+KoLJBqwhKPQzR5wjqlCzgKf8qUbZ0Rqvxse50DdBtTnJr9xBp+2XQLMoVVq7pPUBZ yCIxT5lSITMCBS+2ou9+Zv4n5pQzPuy7xP836QXxpwbeymuBB6P8QGuDsSXBTiqIzTLS SEhE1w83JE5XyZ3S0ed2a6jv7ceCYqlrw6OivQi1sPM2jjZ0EL3mOrQq7ALM81iOLOXD jQ== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2y1ufh6q1v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 11 Feb 2020 16:53:32 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id DF40F10003B; Tue, 11 Feb 2020 16:53:27 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag3node1.st.com [10.75.127.7]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id BF2722C1EF0; Tue, 11 Feb 2020 16:53:27 +0100 (CET) Received: from lmecxl0889.lme.st.com (10.75.127.44) by SFHDAG3NODE1.st.com (10.75.127.7) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 11 Feb 2020 16:53:26 +0100 Subject: Re: [PATCH v4 1/5] remoteproc: Use u64 len for da_to_va To: Clement Leger , Ohad Ben-Cohen , Bjorn Andersson , Jonathan Corbet , Shawn Guo , Sascha Hauer , CC: Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Andy Gross , Patrice Chotard , , , , , Loic PALLARDY , s-anna , Mathieu Poirier References: <527785289.2852303.1581062223707.JavaMail.zimbra@kalray.eu> <20200210162209.23149-1-cleger@kalray.eu> <20200210162209.23149-2-cleger@kalray.eu> From: Arnaud POULIQUEN Message-ID: <4465bade-e3de-88b8-63a5-e5410de9adc0@st.com> Date: Tue, 11 Feb 2020 16:53:26 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <20200210162209.23149-2-cleger@kalray.eu> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.75.127.44] X-ClientProxiedBy: SFHDAG3NODE1.st.com (10.75.127.7) To SFHDAG3NODE1.st.com (10.75.127.7) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-11_04:2020-02-10,2020-02-11 signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/10/20 5:22 PM, Clement Leger wrote: > With upcoming changes in elf loader for elf64 support, section size will > be a u64. When used with da_to_va, this will potentially lead to > overflow if using the current "int" type for len argument. Change > da_to_va prototype to use a u64 for len and fix all users of this > function. > > Signed-off-by: Clement Leger > --- > drivers/remoteproc/imx_rproc.c | 11 ++++++----- > drivers/remoteproc/keystone_remoteproc.c | 4 ++-- > drivers/remoteproc/qcom_q6v5_adsp.c | 2 +- > drivers/remoteproc/qcom_q6v5_mss.c | 2 +- > drivers/remoteproc/qcom_q6v5_pas.c | 2 +- > drivers/remoteproc/qcom_q6v5_wcss.c | 2 +- > drivers/remoteproc/qcom_wcnss.c | 2 +- > drivers/remoteproc/remoteproc_core.c | 2 +- > drivers/remoteproc/remoteproc_internal.h | 2 +- > drivers/remoteproc/st_slim_rproc.c | 4 ++-- > drivers/remoteproc/wkup_m3_rproc.c | 4 ++-- > include/linux/remoteproc.h | 2 +- > 12 files changed, 20 insertions(+), 19 deletions(-) > > diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c > index 3e72b6f38d4b..f497f5b49b18 100644 > --- a/drivers/remoteproc/imx_rproc.c > +++ b/drivers/remoteproc/imx_rproc.c > @@ -186,7 +186,7 @@ static int imx_rproc_stop(struct rproc *rproc) > } > > static int imx_rproc_da_to_sys(struct imx_rproc *priv, u64 da, > - int len, u64 *sys) > + u64 len, u64 *sys) > { > const struct imx_rproc_dcfg *dcfg = priv->dcfg; > int i; > @@ -203,19 +203,19 @@ static int imx_rproc_da_to_sys(struct imx_rproc *priv, u64 da, > } > } > > - dev_warn(priv->dev, "Translation failed: da = 0x%llx len = 0x%x\n", > + dev_warn(priv->dev, "Translation failed: da = 0x%llx len = 0x%llx\n", > da, len); > return -ENOENT; > } > > -static void *imx_rproc_da_to_va(struct rproc *rproc, u64 da, int len) > +static void *imx_rproc_da_to_va(struct rproc *rproc, u64 da, u64 len) > { > struct imx_rproc *priv = rproc->priv; > void *va = NULL; > u64 sys; > int i; > > - if (len <= 0) > + if (len == 0) > return NULL; > > /* > @@ -235,7 +235,8 @@ static void *imx_rproc_da_to_va(struct rproc *rproc, u64 da, int len) > } > } > > - dev_dbg(&rproc->dev, "da = 0x%llx len = 0x%x va = 0x%p\n", da, len, va); > + dev_dbg(&rproc->dev, "da = 0x%llx len = 0x%llx va = 0x%p\n", > + da, len, va); > > return va; > } > diff --git a/drivers/remoteproc/keystone_remoteproc.c b/drivers/remoteproc/keystone_remoteproc.c > index 5c4658f00b3d..466093f48814 100644 > --- a/drivers/remoteproc/keystone_remoteproc.c > +++ b/drivers/remoteproc/keystone_remoteproc.c > @@ -246,7 +246,7 @@ static void keystone_rproc_kick(struct rproc *rproc, int vqid) > * can be used either by the remoteproc core for loading (when using kernel > * remoteproc loader), or by any rpmsg bus drivers. > */ > -static void *keystone_rproc_da_to_va(struct rproc *rproc, u64 da, int len) > +static void *keystone_rproc_da_to_va(struct rproc *rproc, u64 da, u64 len) > { > struct keystone_rproc *ksproc = rproc->priv; > void __iomem *va = NULL; > @@ -255,7 +255,7 @@ static void *keystone_rproc_da_to_va(struct rproc *rproc, u64 da, int len) > size_t size; > int i; > > - if (len <= 0) > + if (len == 0) > return NULL; > > for (i = 0; i < ksproc->num_mems; i++) { > diff --git a/drivers/remoteproc/qcom_q6v5_adsp.c b/drivers/remoteproc/qcom_q6v5_adsp.c > index e953886b2eb7..7518e67a49e5 100644 > --- a/drivers/remoteproc/qcom_q6v5_adsp.c > +++ b/drivers/remoteproc/qcom_q6v5_adsp.c > @@ -270,7 +270,7 @@ static int adsp_stop(struct rproc *rproc) > return ret; > } > > -static void *adsp_da_to_va(struct rproc *rproc, u64 da, int len) > +static void *adsp_da_to_va(struct rproc *rproc, u64 da, u64 len) > { > struct qcom_adsp *adsp = (struct qcom_adsp *)rproc->priv; > int offset; > diff --git a/drivers/remoteproc/qcom_q6v5_mss.c b/drivers/remoteproc/qcom_q6v5_mss.c > index 471128a2e723..248febde6fc1 100644 > --- a/drivers/remoteproc/qcom_q6v5_mss.c > +++ b/drivers/remoteproc/qcom_q6v5_mss.c > @@ -1148,7 +1148,7 @@ static int q6v5_stop(struct rproc *rproc) > return 0; > } > > -static void *q6v5_da_to_va(struct rproc *rproc, u64 da, int len) > +static void *q6v5_da_to_va(struct rproc *rproc, u64 da, u64 len) > { > struct q6v5 *qproc = rproc->priv; > int offset; > diff --git a/drivers/remoteproc/qcom_q6v5_pas.c b/drivers/remoteproc/qcom_q6v5_pas.c > index db4b3c4bacd7..cf2cd609c90d 100644 > --- a/drivers/remoteproc/qcom_q6v5_pas.c > +++ b/drivers/remoteproc/qcom_q6v5_pas.c > @@ -159,7 +159,7 @@ static int adsp_stop(struct rproc *rproc) > return ret; > } > > -static void *adsp_da_to_va(struct rproc *rproc, u64 da, int len) > +static void *adsp_da_to_va(struct rproc *rproc, u64 da, u64 len) > { > struct qcom_adsp *adsp = (struct qcom_adsp *)rproc->priv; > int offset; > diff --git a/drivers/remoteproc/qcom_q6v5_wcss.c b/drivers/remoteproc/qcom_q6v5_wcss.c > index f93e1e4a1cc0..3a6b82a16961 100644 > --- a/drivers/remoteproc/qcom_q6v5_wcss.c > +++ b/drivers/remoteproc/qcom_q6v5_wcss.c > @@ -406,7 +406,7 @@ static int q6v5_wcss_stop(struct rproc *rproc) > return 0; > } > > -static void *q6v5_wcss_da_to_va(struct rproc *rproc, u64 da, int len) > +static void *q6v5_wcss_da_to_va(struct rproc *rproc, u64 da, u64 len) > { > struct q6v5_wcss *wcss = rproc->priv; > int offset; > diff --git a/drivers/remoteproc/qcom_wcnss.c b/drivers/remoteproc/qcom_wcnss.c > index dc135754bb9c..f893219e45a8 100644 > --- a/drivers/remoteproc/qcom_wcnss.c > +++ b/drivers/remoteproc/qcom_wcnss.c > @@ -287,7 +287,7 @@ static int wcnss_stop(struct rproc *rproc) > return ret; > } > > -static void *wcnss_da_to_va(struct rproc *rproc, u64 da, int len) > +static void *wcnss_da_to_va(struct rproc *rproc, u64 da, u64 len) > { > struct qcom_wcnss *wcnss = (struct qcom_wcnss *)rproc->priv; > int offset; > diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c > index 307df98347ba..9e6d3c6a60ee 100644 > --- a/drivers/remoteproc/remoteproc_core.c > +++ b/drivers/remoteproc/remoteproc_core.c > @@ -185,7 +185,7 @@ EXPORT_SYMBOL(rproc_va_to_pa); > * here the output of the DMA API for the carveouts, which should be more > * correct. > */ > -void *rproc_da_to_va(struct rproc *rproc, u64 da, int len) > +void *rproc_da_to_va(struct rproc *rproc, u64 da, u64 len) This function is exported, don't see any update in consequence... references: https://elixir.bootlin.com/linux/v5.6-rc1/ident/rproc_da_to_va For instance the function rproc_trace_read use it. it quite strange that my gcc does not warns for the cast but i suppose that some could. An indirect consequence is that the len field in rproc_mem_entry struct should probably been updated to u64 to be aligned. I'm still wondering about the use of size_t instead,which seems more rational from my window. So i you or Mathieu remember it was decided to use u64, please could remind me the arguments? As an alternative a check should be added for 32 bits processors to ensure that the size is not higher than its address range capability... Regards Arnaud > { > struct rproc_mem_entry *carveout; > void *ptr = NULL; > diff --git a/drivers/remoteproc/remoteproc_internal.h b/drivers/remoteproc/remoteproc_internal.h > index 493ef9262411..004867061721 100644 > --- a/drivers/remoteproc/remoteproc_internal.h > +++ b/drivers/remoteproc/remoteproc_internal.h > @@ -50,7 +50,7 @@ void rproc_exit_sysfs(void); > void rproc_free_vring(struct rproc_vring *rvring); > int rproc_alloc_vring(struct rproc_vdev *rvdev, int i); > > -void *rproc_da_to_va(struct rproc *rproc, u64 da, int len); > +void *rproc_da_to_va(struct rproc *rproc, u64 da, u64 len); > phys_addr_t rproc_va_to_pa(void *cpu_addr); > int rproc_trigger_recovery(struct rproc *rproc); > > diff --git a/drivers/remoteproc/st_slim_rproc.c b/drivers/remoteproc/st_slim_rproc.c > index 04492fead3c8..fc01cd879b60 100644 > --- a/drivers/remoteproc/st_slim_rproc.c > +++ b/drivers/remoteproc/st_slim_rproc.c > @@ -174,7 +174,7 @@ static int slim_rproc_stop(struct rproc *rproc) > return 0; > } > > -static void *slim_rproc_da_to_va(struct rproc *rproc, u64 da, int len) > +static void *slim_rproc_da_to_va(struct rproc *rproc, u64 da, u64 len) > { > struct st_slim_rproc *slim_rproc = rproc->priv; > void *va = NULL; > @@ -191,7 +191,7 @@ static void *slim_rproc_da_to_va(struct rproc *rproc, u64 da, int len) > } > } > > - dev_dbg(&rproc->dev, "da = 0x%llx len = 0x%x va = 0x%pK\n", > + dev_dbg(&rproc->dev, "da = 0x%llx len = 0x%llx va = 0x%pK\n", > da, len, va); > > return va; > diff --git a/drivers/remoteproc/wkup_m3_rproc.c b/drivers/remoteproc/wkup_m3_rproc.c > index 3984e585c847..91485b467407 100644 > --- a/drivers/remoteproc/wkup_m3_rproc.c > +++ b/drivers/remoteproc/wkup_m3_rproc.c > @@ -80,14 +80,14 @@ static int wkup_m3_rproc_stop(struct rproc *rproc) > return 0; > } > > -static void *wkup_m3_rproc_da_to_va(struct rproc *rproc, u64 da, int len) > +static void *wkup_m3_rproc_da_to_va(struct rproc *rproc, u64 da, u64 len) > { > struct wkup_m3_rproc *wkupm3 = rproc->priv; > void *va = NULL; > int i; > u32 offset; > > - if (len <= 0) > + if (len == 0) > return NULL; > > for (i = 0; i < WKUPM3_MEM_MAX; i++) { > diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h > index 16ad66683ad0..f84bd5fe0211 100644 > --- a/include/linux/remoteproc.h > +++ b/include/linux/remoteproc.h > @@ -374,7 +374,7 @@ struct rproc_ops { > int (*start)(struct rproc *rproc); > int (*stop)(struct rproc *rproc); > void (*kick)(struct rproc *rproc, int vqid); > - void * (*da_to_va)(struct rproc *rproc, u64 da, int len); > + void * (*da_to_va)(struct rproc *rproc, u64 da, u64 len); > int (*parse_fw)(struct rproc *rproc, const struct firmware *fw); > int (*handle_rsc)(struct rproc *rproc, u32 rsc_type, void *rsc, > int offset, int avail); >