Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2741652ybl; Mon, 20 Jan 2020 08:30:11 -0800 (PST) X-Google-Smtp-Source: APXvYqwE7tNMNhveF/gWiChTe69LBzScS4NakJ0B2+FzLTFVX2QvNcTspjimmN5rNcIT2jkjCuDK X-Received: by 2002:a05:6830:ce:: with SMTP id x14mr157260oto.289.1579537811208; Mon, 20 Jan 2020 08:30:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579537811; cv=none; d=google.com; s=arc-20160816; b=iGVcgmtov41kAlsI1craxycNYYnnMFYUBiB3u6ezeyFmtJ/uTq/4xPK8JlWnGzEi29 maSJfHHpZF4h1688UsbeRkEm6rj+wuCfGsaTwarDq7jyCqR1xIRLZzR1KXbF1MU4qc6b FRSow+v5VO9yt9pFB5QGKPqhB30Zx0Tbh94qRNj2lNcRKW/bj+neT/7I5BE+Poz+6tfP v2/x1LTHqvrQY6nr+SZd7Eify++vHcsZytYx5U2oF7p+jw2g2l82uEfFN4rm72WF9xBZ eYW0T6ffC8pNMU7yiesTZOlcGhZRBFJraMgca32z+2EiwUzkDURH10G7iOulZZoUYQ8K s+SA== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=WhDafEfpWxCZW7N1ekgfBlfxmyFi2MY1suCA9Nt8g4g=; b=BJIt9hwNCIEjxTJkHCbZGWDEJUDgSoSy8iFo7HI9IScRa6vor/sOvcbXy/ZBpOAw6P wy2rz7CimIdm7WEOB2R4MV/+YpTZkxsHJhVONCb2nonnZPfw0HR7DgIz98rK3ZRto4Us CKPrSyP8Bw8YQcHnkY06Np9AmX8mXNUXtD9IkNCdLpTkCyAfrgQ3ban+V88eUO1Jrwgo SYjj5JuWMw6nZKNMXCmr+qlTrCbVjxs3zCM43LU+0od53h710ZUIu8JLy9KwmtTKLZg7 GLWU7WWv/a5+HE5+MpKKnEIgojY6BrxLJ2tB0m243UYG+bDP9VsYDvbqYGEHqU1msIr+ kasw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dQWfSSaA; 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 i8si19474311otp.254.2020.01.20.08.29.59; Mon, 20 Jan 2020 08:30:11 -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=dQWfSSaA; 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 S1729388AbgATQ3C (ORCPT + 99 others); Mon, 20 Jan 2020 11:29:02 -0500 Received: from mail-il1-f195.google.com ([209.85.166.195]:38842 "EHLO mail-il1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729210AbgATQ3B (ORCPT ); Mon, 20 Jan 2020 11:29:01 -0500 Received: by mail-il1-f195.google.com with SMTP id f5so27704043ilq.5 for ; Mon, 20 Jan 2020 08:29:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=WhDafEfpWxCZW7N1ekgfBlfxmyFi2MY1suCA9Nt8g4g=; b=dQWfSSaAoPOHR9zlU3AQWP+N+8XjUaOZog2voCI3BigUAoKt6IwPkXnmWjCUSujnhy YGa8UPh9uxPhxWMvLZ3AGlafundnFv9d0pBpbAXKur7asg77zkQoTyVzyHvT1YwOLj8r OvuMcYJi6YELFbOHDMdZLFdSUSTYqdB9PXiIG3gv0gfqOOyYYdqn4wq2ZrpKJD7X8ewt uDCa93APw5k6rwdRrf9k5nHIXKSm+sMr/L0Z/bE7xA6q60hUoKma2D472uwBBN8nRocE KwzaytgrF5c56O7X4gVj/3QzyQhnUiUHdV1Vp/+7mWwchTd/vYNQPyBJpy1Nicxge4Uo VLAw== 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=WhDafEfpWxCZW7N1ekgfBlfxmyFi2MY1suCA9Nt8g4g=; b=O0OP1eAWIuTc3ZF3kwsenrmOd2z6SQtkupZVaKSAlL4udNA6RENy63JY4EkZvwA4w4 MoYUY8QItenQrJPAbPKK0iPE9GTHrVXF8EdPjo285O5ASFQlOr230swrI48ZSb6h/vYd wC0BwDp5y9ajYHKT8d46Y68KC3rLiyy2ri7OBmGjjxhe+Q7NF6mlN/ukHMqOhX+WT2JK tevx6zTvBTHUGJxiPSlimpO9udqjvcktkkzWQnlK7WKjQpUtviXDFt8jEaKBEHXs8KFE 2hLO72/fDWs+hRb0gKAbOSVADb/65vyqOeN7zuO6KslvTkhUWILa46To+MLOt2fWOn1K f4PA== X-Gm-Message-State: APjAAAWK3aKwHzgHBRcWDDeaLNIzOAAoPQHekPIdXA7vqnhh/vwSR4oH QWoef30JLLIXuW2v2zDDRcoA+50VuwVLkiC6pZ4LsQ== X-Received: by 2002:a92:9f1a:: with SMTP id u26mr11955936ili.72.1579537739870; Mon, 20 Jan 2020 08:28:59 -0800 (PST) MIME-Version: 1.0 References: <20200115102142.11229-1-cleger@kalray.eu> <088ceab9-f135-6e70-dcf6-f75ec46110b1@st.com> <79048597.12371594.1579098506802.JavaMail.zimbra@kalray.eu> <612100872.12377996.1579101063237.JavaMail.zimbra@kalray.eu> <20200117225217.GA27535@xps15> <377421261.12898679.1579462834671.JavaMail.zimbra@kalray.eu> In-Reply-To: <377421261.12898679.1579462834671.JavaMail.zimbra@kalray.eu> From: Mathieu Poirier Date: Mon, 20 Jan 2020 09:28:49 -0700 Message-ID: Subject: Re: [PATCH] remoteproc: Add support for predefined notifyids To: =?UTF-8?Q?Cl=C3=A9ment_Leger?= Cc: Arnaud Pouliquen , Ohad Ben-Cohen , Bjorn Andersson , linux-remoteproc , linux-kernel Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 19 Jan 2020 at 12:40, Cl=C3=A9ment Leger wrote: > > Hi Mathieu, > > ----- On 17 Jan, 2020, at 23:52, Mathieu Poirier mathieu.poirier@linaro.o= rg wrote: > > > Hey guys, > > > > On Wed, Jan 15, 2020 at 04:11:03PM +0100, Cl=C3=A9ment Leger wrote: > >> > >> > >> ----- On 15 Jan, 2020, at 16:09, Arnaud Pouliquen arnaud.pouliquen@st.= com wrote: > >> > >> > On 1/15/20 3:28 PM, Cl=C3=A9ment Leger wrote: > >> >> Hi Arnaud, > >> >> > >> >> ----- On 15 Jan, 2020, at 15:06, Arnaud Pouliquen arnaud.pouliquen@= st.com wrote: > >> >> > >> >>> Hi Cl=C3=A9ment, > >> >>> > >> >>> On 1/15/20 11:21 AM, Clement Leger wrote: > >> >>>> In order to support preallocated notify ids, if their value is > >> >>>> equal to FW_RSC_NOTIFY_ID_ANY, then do no allocate a notify id > >> >>>> dynamically but try to allocate the requested one. This is useful= when > >> >>>> using custom ids to bind them to custom vendor resources. For ins= tance, > >> >>>> it allow to assign a group of queues to a specific interrupti in = order > >> >>>> to dispatch notifications. > >> >>>> > >> >>>> Signed-off-by: Clement Leger > >> >>>> --- > >> >>>> drivers/remoteproc/remoteproc_core.c | 27 +++++++++++++++++++---= ----- > >> >>>> include/linux/remoteproc.h | 1 + > >> >>>> 2 files changed, 20 insertions(+), 8 deletions(-) > >> >>>> > >> >>>> diff --git a/drivers/remoteproc/remoteproc_core.c > >> >>>> b/drivers/remoteproc/remoteproc_core.c > >> >>>> index 307df98347ba..b1485fcd0f11 100644 > >> >>>> --- a/drivers/remoteproc/remoteproc_core.c > >> >>>> +++ b/drivers/remoteproc/remoteproc_core.c > >> >>>> @@ -351,14 +351,27 @@ int rproc_alloc_vring(struct rproc_vdev *rv= dev, int i) > >> >>>> /* > >> >>>> * Assign an rproc-wide unique index for this vring > >> >>>> * TODO: assign a notifyid for rvdev updates as well > >> >>>> - * TODO: support predefined notifyids (via resource table= ) > >> >>>> */ > >> >>>> - ret =3D idr_alloc(&rproc->notifyids, rvring, 0, 0, GFP_KE= RNEL); > >> >>>> - if (ret < 0) { > >> >>>> - dev_err(dev, "idr_alloc failed: %d\n", ret); > >> >>>> - return ret; > >> >>>> + if (rsc->vring[i].notifyid =3D=3D FW_RSC_NOTIFY_ID_ANY) { > >> >>>> + ret =3D idr_alloc(&rproc->notifyids, rvring, 0, 0= , GFP_KERNEL); > >> >>>> + if (ret < 0) { > >> >>>> + dev_err(dev, "idr_alloc failed: %d\n", re= t); > >> >>>> + return ret; > >> >>>> + } > >> >>>> + notifyid =3D ret; > >> >>>> + > >> >>>> + /* Let the rproc know the notifyid of this vring.= */ > >> >>>> + rsc->vring[i].notifyid =3D notifyid; > >> >>>> + } else { > >> >>>> + /* Reserve requested notify_id */ > >> >>>> + notifyid =3D rsc->vring[i].notifyid; > >> >>>> + ret =3D idr_alloc(&rproc->notifyids, rvring, noti= fyid, > >> >>>> + notifyid + 1, GFP_KERNEL); > >> >>>> + if (ret < 0) { > >> >>>> + dev_err(dev, "idr_alloc failed: %d\n", re= t); > >> >>>> + return ret; > >> >>>> + } > >> >>>> } > >> >>>> - notifyid =3D ret; > >> >>>> > >> >>>> /* Potentially bump max_notifyid */ > >> >>>> if (notifyid > rproc->max_notifyid) > >> >>>> @@ -366,8 +379,6 @@ int rproc_alloc_vring(struct rproc_vdev *rvde= v, int i) > >> >>>> > >> >>>> rvring->notifyid =3D notifyid; > >> >>>> > >> >>>> - /* Let the rproc know the notifyid of this vring.*/ > >> >>>> - rsc->vring[i].notifyid =3D notifyid; > >> >>>> return 0; > >> >>>> } > >> >>> The rproc_free_vring function resets the notifyid to -1 on free. > >> >>> This could generate a side effect if the resource table is not rel= oaded. > >> >> > >> >> Oh indeed, I did not thought of that. What would you recommend ? > >> >> If using -1 in free vring, notify ids will be reallocated at next > >> >> round. > >> > Regarding the code i'm not sure that it is useful to reset the notif= yID to -1 on > >> > free. > > > > I'm not sure setting notifyid to -1 in rproc_free_vring() is such a big= problem. > > No matter the code path I look at, if rproc_free_vring() is called some= thing > > serious has happened and the resource table will be reloaded if another= attempt > > at booting the remote processor is done. It can also be that a gracefu= l > > shutdown is underway, in which case the resource table will be reloaded= anyway > > if/when the slave is brought back in service. > > > > Let me know if I'm missing a scenario. > > No, you are actually right > > > > > To me the real problem is if a FW image has set the notifyids in the re= source > > table to 0xffffffff, thinking they will be overwritten. In that case t= hings > > will really south. > > Hum, if set to 0xFFFFFFFF, then they will be assigned dynamically and upd= ated > in the resource table (with this patch). But your probably mean existing = code, > right ? My apologies for not expressing myself clearly here - let me try again. At this time notifyids in the firmware's resource table can be set to anything because the code will overwrite them. With this patch firmware images that don't have their notifyids set to -1 will see a change in how ids are assigned, something that has the potential to break user space. Regards, Mathieu > > > > >> > In current version, on alloc, the notifyID is overwriten without che= ck. > >> > And as vdev status is updated, vring struct in resource table should= be > >> > considered as invalid > >> > Except if i missed a usecase/race condition... > >> > > >> >> > >> >> I was also worried that it would break some existing user applicati= ons > >> >> which uses "0" as a notify id in vring but expect the id to be > >> >> allocated dynamically. With my modification, it means it will try t= o > >> >> use "0" as a predefined id, leading to allocation failure. > > > > From my point of view they will have been lucky for all this time. Eve= n with > > a new version of the resource table (which I think is the right way go) > > cases like this will break. > > Agreed, and actually, I may have missread some code. I can't find were I = read > that. By the way, is there any documentation which state the allowed valu= es of > notify ids ? > > > > > Thanks, > > Mathieu > > > >> >> > >> > Yes this could introduce regression for firmware that sets 0 as defa= ult value. > >> > Probably better to introduce this patch with a new version of the re= source table > >> > :) > >> > >> Understood ;) > >> > >> Regards, > >> > >> Cl=C3=A9ment > >> > >> > > >> > Regards > >> > Arnaud > >> >>> > >> >>>> > >> >>>> diff --git a/include/linux/remoteproc.h b/include/linux/remotepro= c.h > >> >>>> index 16ad66683ad0..dcae3394243e 100644 > >> >>>> --- a/include/linux/remoteproc.h > >> >>>> +++ b/include/linux/remoteproc.h > >> >>>> @@ -123,6 +123,7 @@ enum fw_resource_type { > >> >>>> }; > >> >>>> > >> >>>> #define FW_RSC_ADDR_ANY (-1) > >> >>>> +#define FW_RSC_NOTIFY_ID_ANY (-1)This define can also be used in > >> >>>> rproc_free_vring > >> >> > >> >> Indeed. > >> >> > >> >> Thanks for your review. > >> >> > >> >> Regards, > >> >> > >> >> Cl=C3=A9ment > >> >> > >> >>> > >> >>> Regards, > >> >>> Arnaud > >> >>>> > >> >>>> /** > > > > >>> * struct fw_rsc_carveout - physically contiguous memory reque= st