From patchwork Fri Jan 5 23:57:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 123573 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1428097qgn; Fri, 5 Jan 2018 15:58:18 -0800 (PST) X-Google-Smtp-Source: ACJfBotSyjET8PPROkPfVTETWrD3akb2mxfUpTQYKKN6q1/0TZ1lrXzVEbczL4Fx0sU+ZU5TnLvM X-Received: by 10.124.25.17 with SMTP id c17mr102496plz.90.1515196697919; Fri, 05 Jan 2018 15:58:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515196697; cv=none; d=google.com; s=arc-20160816; b=vSW3mY42xV/mPT4DwoZU69jWsZH3/lQEft93kZ8JZoq2Ep6K1t+4jF5FZGm9pK6MA5 6GredLLsVm2M0uqBklfmv23riQMZ9NKwcBi905UFLoy11lO+fxcBy1+ixAtNOs7nGMHO m8ukgQcb8lWITfsQVOXPBlKE3lhK38lSbQr2LD+gtCM45H5Mb5YpWPadsrQFWBaTL2Me dE+jeW1bzIOq88x/2reVHt/cxB5MzlnWh7X7Lh8JPgghj3F0k+ZhmWmgwvdvoJTJu9Az h+RqWpdFVhVZfF52+ZgPsExoCwuRbrM9W01E/bnfdCcOhLCxW33FWifQafDX8isWPhR0 YOTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=uVfw65ecBEIs0WbFb7RKr44rjgHi008nQKdIuSy6IQg=; b=VcbOXIOUxXe/A8pcRVOOSDXVXMi8KA0eReU/kT8UtUj2WAz3AylUQvF+RjK5bDdyvn hnxTARBPycM0dvP+yKZA2hSVzPrm7ysqmI2QD63/lXpLGopzrUltLItNJYY02oRkyahc isTVcOfR3KZnKSj7M0JugAPnXKX1tkTAglnvn6+SbGbjh5rnxfalYn7yabxh5E7245mo ddWd2hYqa0u3TU5a7D8iZOPoKzNawLgb6vmvq6KwbxB8DDUmyuXo1UgLbFIIef2ukqxC xtn3WBYQmVNAGgVubKIdA6STVvuC5U/ZJbb5VrV4TLEMSVoaxkWVMU+YX2j0uqV+NfNf Sp2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gctGiDpl; 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 1si4695311plj.8.2018.01.05.15.58.17; Fri, 05 Jan 2018 15:58:17 -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=gctGiDpl; 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 S1752848AbeAEX6Q (ORCPT + 28 others); Fri, 5 Jan 2018 18:58:16 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:38011 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753346AbeAEX6M (ORCPT ); Fri, 5 Jan 2018 18:58:12 -0500 Received: by mail-pf0-f195.google.com with SMTP id u25so2815115pfg.5 for ; Fri, 05 Jan 2018 15:58:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=uVfw65ecBEIs0WbFb7RKr44rjgHi008nQKdIuSy6IQg=; b=gctGiDplmSETKV5y4JXDNWlke5qUh7BtB8PTO3wGgtVXwe8IM1y3KK0Is/xO7nYkSB MnM+jDGHT2xqzIuRaOS2RLomzYos6F2wjNgHVYyZc9iq5EIONIjSI0p4TkAblwn/akJ8 mGVfLB/ktT9vjOOE48HHvlr++jghZVsH0aio0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=uVfw65ecBEIs0WbFb7RKr44rjgHi008nQKdIuSy6IQg=; b=Z93nzo+bcPD8b+JQq+315unSDQg6vsq7VJ9SCEJVdnkkdJNJ9iayj7zAkYzp6NTgjZ NaiyLqw3KvJridNgcWjGo3ifJ8VJ4xMajd8RI86IIfXE1eSZKyOHJHFLT/UXGYCKnWgh 0euw8uvVipk2Z0HqmG2m2seUNRTfNh9I4VJnTtAZuS3oFRxysy4iGVZXhcd8GiznnPHk OF8d5DDOas1cMz/PTpzgZqD1VrmZtGw2SJjcdkN5q4aeCr+QT5yfoKIJ4Bwh+jVb28gW fZgBWi7r9oyypvJnRMhT7u+E3ZY2YRYk786Fsm9X5kU+Jd+HCWPMUbFnkEctu5+8pOl9 2xeg== X-Gm-Message-State: AKGB3mLp4LY6XRlvsdIfbAAWV7m1vBhHPIoddel9zSp3Dn3sMHEsXgX/ DmpvyboWOZn6Oa0HKXu+xx7lnQ== X-Received: by 10.101.64.67 with SMTP id h3mr3912584pgp.123.1515196692118; Fri, 05 Jan 2018 15:58:12 -0800 (PST) Received: from localhost.localdomain (104-188-17-28.lightspeed.sndgca.sbcglobal.net. [104.188.17.28]) by smtp.gmail.com with ESMTPSA id x4sm14473188pfk.51.2018.01.05.15.58.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 Jan 2018 15:58:11 -0800 (PST) From: Bjorn Andersson To: Ohad Ben-Cohen , Bjorn Andersson Cc: linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, Loic Pallardy Subject: [PATCH v2 2/8] remoteproc: Cache resource table size Date: Fri, 5 Jan 2018 15:57:59 -0800 Message-Id: <20180105235805.9948-3-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20180105235805.9948-1-bjorn.andersson@linaro.org> References: <20180105235805.9948-1-bjorn.andersson@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We don't re-read the resource table during a recovery, so it is possible in the recovery path that the resource table has a different size than cached_table. Store the original size of cached_table to avoid these getting out of sync. Signed-off-by: Bjorn Andersson --- Changes since v1: - None drivers/remoteproc/remoteproc_core.c | 20 +++++++------------- include/linux/remoteproc.h | 2 ++ 2 files changed, 9 insertions(+), 13 deletions(-) -- 2.15.0 diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 758fad3131a3..208ccf709cad 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -732,7 +732,7 @@ static rproc_handle_resource_t rproc_loading_handlers[RSC_LAST] = { }; /* handle firmware resource entries before booting the remote processor */ -static int rproc_handle_resources(struct rproc *rproc, int len, +static int rproc_handle_resources(struct rproc *rproc, rproc_handle_resource_t handlers[RSC_LAST]) { struct device *dev = &rproc->dev; @@ -742,7 +742,7 @@ static int rproc_handle_resources(struct rproc *rproc, int len, for (i = 0; i < rproc->table_ptr->num; i++) { int offset = rproc->table_ptr->offset[i]; struct fw_rsc_hdr *hdr = (void *)rproc->table_ptr + offset; - int avail = len - offset - sizeof(*hdr); + int avail = rproc->table_sz - offset - sizeof(*hdr); void *rsc = (void *)hdr + sizeof(*hdr); /* make sure table isn't truncated */ @@ -849,16 +849,9 @@ static void rproc_resource_cleanup(struct rproc *rproc) static int rproc_start(struct rproc *rproc, const struct firmware *fw) { - struct resource_table *table, *loaded_table; + struct resource_table *loaded_table; struct device *dev = &rproc->dev; - int ret, tablesz; - - /* look for the resource table */ - table = rproc_find_rsc_table(rproc, fw, &tablesz); - if (!table) { - dev_err(dev, "Resource table look up failed\n"); - return -EINVAL; - } + int ret; /* load the ELF segments to memory */ ret = rproc_load_segments(rproc, fw); @@ -877,7 +870,7 @@ static int rproc_start(struct rproc *rproc, const struct firmware *fw) */ loaded_table = rproc_find_loaded_rsc_table(rproc, fw); if (loaded_table) { - memcpy(loaded_table, rproc->cached_table, tablesz); + memcpy(loaded_table, rproc->cached_table, rproc->table_sz); rproc->table_ptr = loaded_table; } @@ -951,12 +944,13 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) goto clean_up; rproc->table_ptr = rproc->cached_table; + rproc->table_sz = tablesz; /* reset max_notifyid */ rproc->max_notifyid = -1; /* handle fw resources which are required to boot rproc */ - ret = rproc_handle_resources(rproc, tablesz, rproc_loading_handlers); + ret = rproc_handle_resources(rproc, rproc_loading_handlers); if (ret) { dev_err(dev, "Failed to process resources: %d\n", ret); goto clean_up_resources; diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index 6f1d8e025c81..6fdc62e29d6f 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -410,6 +410,7 @@ enum rproc_crash_type { * @max_notifyid: largest allocated notify id. * @table_ptr: pointer to the resource table in effect * @cached_table: copy of the resource table + * @table_sz: size of @cached_table * @has_iommu: flag to indicate if remote processor is behind an MMU */ struct rproc { @@ -440,6 +441,7 @@ struct rproc { int max_notifyid; struct resource_table *table_ptr; struct resource_table *cached_table; + size_t table_sz; bool has_iommu; bool auto_boot; };