Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Revert "remoteproc: Merge table_ptr and cached_table pointers"

Following any fw_rsc_vdev entries in the resource table are two variable
length arrays, the first one reference vring resources and the second
one is the virtio config space. The virtio config space is used by
virtio to communicate status and configuration changes and must as such
be shared with the remote.

The reverted commit incorrectly made any changes to the virtio config
space only affect the local copy, in an attempt to allowing memory
protection of the shared resource table.

This reverts commit cda8529346935fc86f476999ac4fbfe4e17abf11.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>

+19 -11
+16 -10
drivers/remoteproc/remoteproc_core.c
··· 886 886 /* 887 887 * Create a copy of the resource table. When a virtio device starts 888 888 * and calls vring_new_virtqueue() the address of the allocated vring 889 - * will be stored in the table_ptr. Before the device is started, 890 - * table_ptr will be copied into device memory. 889 + * will be stored in the cached_table. Before the device is started, 890 + * cached_table will be copied into device memory. 891 891 */ 892 - rproc->table_ptr = kmemdup(table, tablesz, GFP_KERNEL); 893 - if (!rproc->table_ptr) 892 + rproc->cached_table = kmemdup(table, tablesz, GFP_KERNEL); 893 + if (!rproc->cached_table) 894 894 goto clean_up; 895 + 896 + rproc->table_ptr = rproc->cached_table; 895 897 896 898 /* reset max_notifyid */ 897 899 rproc->max_notifyid = -1; ··· 913 911 } 914 912 915 913 /* 916 - * The starting device has been given the rproc->table_ptr as the 914 + * The starting device has been given the rproc->cached_table as the 917 915 * resource table. The address of the vring along with the other 918 - * allocated resources (carveouts etc) is stored in table_ptr. 916 + * allocated resources (carveouts etc) is stored in cached_table. 919 917 * In order to pass this information to the remote device we must copy 920 918 * this information to device memory. We also update the table_ptr so 921 919 * that any subsequent changes will be applied to the loaded version. 922 920 */ 923 921 loaded_table = rproc_find_loaded_rsc_table(rproc, fw); 924 - if (loaded_table) 925 - memcpy(loaded_table, rproc->table_ptr, tablesz); 922 + if (loaded_table) { 923 + memcpy(loaded_table, rproc->cached_table, tablesz); 924 + rproc->table_ptr = loaded_table; 925 + } 926 926 927 927 /* power up the remote processor */ 928 928 ret = rproc->ops->start(rproc); ··· 952 948 clean_up_resources: 953 949 rproc_resource_cleanup(rproc); 954 950 clean_up: 955 - kfree(rproc->table_ptr); 951 + kfree(rproc->cached_table); 952 + rproc->cached_table = NULL; 956 953 rproc->table_ptr = NULL; 957 954 958 955 rproc_disable_iommu(rproc); ··· 1187 1182 rproc_disable_iommu(rproc); 1188 1183 1189 1184 /* Free the copy of the resource table */ 1190 - kfree(rproc->table_ptr); 1185 + kfree(rproc->cached_table); 1186 + rproc->cached_table = NULL; 1191 1187 rproc->table_ptr = NULL; 1192 1188 1193 1189 /* if in crash state, unlock crash handler */
+3 -1
include/linux/remoteproc.h
··· 408 408 * @crash_comp: completion used to sync crash handler and the rproc reload 409 409 * @recovery_disabled: flag that state if recovery was disabled 410 410 * @max_notifyid: largest allocated notify id. 411 - * @table_ptr: our copy of the resource table 411 + * @table_ptr: pointer to the resource table in effect 412 + * @cached_table: copy of the resource table 412 413 * @has_iommu: flag to indicate if remote processor is behind an MMU 413 414 */ 414 415 struct rproc { ··· 441 440 bool recovery_disabled; 442 441 int max_notifyid; 443 442 struct resource_table *table_ptr; 443 + struct resource_table *cached_table; 444 444 bool has_iommu; 445 445 bool auto_boot; 446 446 };