Given that shadow_len is size_t (unsigned integer), subtracting a number
from it will make it wrap around < 0 and become positive again so the
subsequent "if (n > 0)" check will be mostly useless. On AOSP this makes
rmtfs segfault, on Linux distributions rmtfs happily reads beyond the
end of the buf.
Fix this by casting both parameters to ssize_t (which is signed) to
correctly use the if and not read beyond the end of shadow_buf.
Relevant trace using extra debug statements:
storage_populate_shadow_buf: file=/dev/disk/by-partlabel/fsg shadow_buf=0xffffa5217060 shadow_len=0x280000
<snip>
storage_pread: memcpy shadow_buf=0xffffa5217060 offset=0x27fc00 n=0x200
storage_pread: memcpy shadow_buf=0xffffa5217060 offset=0x27fe00 n=0x200
storage_pread: memcpy shadow_buf=0xffffa5217060 offset=0x280000 n=0x0 - don't read!
storage_pread: memcpy shadow_buf=0xffffa5217060 offset=0x280200 n=0x200
storage_pread: memcpy shadow_buf=0xffffa5217060 offset=0x280400 n=0x200
storage_pread: memcpy shadow_buf=0xffffa5217060 offset=0x280600 n=0x200
storage_pread: memcpy shadow_buf=0xffffa5217060 offset=0x280800 n=0x200
<snip>
Signed-off-by: Luca Weiss <luca.weiss@fairphone.com>
Opening the backing files with O_SYNC makes things really slow. So slow
in fact that the modem times out after 10 seconds waiting for the last
EFS sync to go through. I think this takes forever because rmtfs is
doing 512-byte reads and writes.
One option would be to make this bigger. But a better option is to not
use O_SYNC, but explicitly do an fdatasync() after the iovec operation
is complete. This is better because 1) it's way faster, we no longer see
10-12 second delays at rebooto time, and 2) partial syncs of the EFS
file aren't useful anyway.
Use fdatasync() as opposed to fsync() since it's not important for the
metadata to be synced, just the file contents.
Signed-off-by: Evan Green <evangreen86@gmail.com>
Open the storage devices as O_SYNC, to make sure modem writes aren't
lingering in the event of power loss or sudden reboot.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Use storage_close() to free up the shadow buffers as well, to avoid any
lingering allocations.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
We're not joining the start and stop threads, so create them in detached
state to avoid having their resources lingering.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
According to valgrind the modalias read from the remoteproc device is
not NUL-terminated, so do this to avoid reading in the weeds.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Include the reason for the failure to update the "state" sysfs
attribtue in the error message.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
The old mechanism searched for remoteproc instances from the
qcom_q6v5_mss driver, but in modern platforms the MSA based remoteproc
model has been replaced by the PAS based one. As such we use the common
qcom_q6v5_pas driver - as with other subsystems.
Use the modalias to find remoteproc drivers with the mpss-pas or mss-pil
compatible to find these, and fall back to the old heuristics if this
fails.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Attempting to shut down a system with rmtfs running without an
associated remoteproc results in systemd waiting forever for the
remoteproc code to never signal that it's done.
Instead exit immediately when signalled, when there's no associated
remoteproc.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Building rmtfs on AOSP, we see a lot of the following:
warning: arithmetic on a pointer to void is a GNU extension
Fix this by casting the void* ptrs to char* when doing pointer
arithmatic.
Signed-off-by: John Stultz <john.stultz@linaro.org>
[AmitP: Fixed cherry-pick conflicts and updated commit log]
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Instead of hardcoding BY_PARTLABEL_PATH for AOSP,
reuse -o option as suggested by Bjorn to expand John's
patch to find correct partition by-name on newer
kernels (which is /dev/block/platform/soc*/*.*/by-name).
For example: On db845c running v5.4+ kernel we run:
rmtfs -o /dev/block/platform/soc@0/1d84000.ufshc/by-name -P -r -s
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
* Add Android.bp makefile to build rmtfs for AOSP.
* libudev is not supported on AOSP so read
/sys/class/rmtfs sysfs entries directly.
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Systemd has a default restart policy of 5 retries so wait
1 second in each retry because if is too fast will fail to
start properly.
Signed-off-by: Aníbal Limón <anibal.limon@linaro.org>
When -s option is specified rmtfs handled the start of rproc
but at init may be the /sys entries are not fully populated yet
due to module load/setup so exit with 1 and let systemd restart
the service.
Signed-off-by: Aníbal Limón <anibal.limon@linaro.org>
Upon populating the shadow_buf the no fd is associated with the rmtfd.
Therefor the next open request will conclude that the rmtfd is available
and use the same entry. Fix this by checking for both associated fd and
shadow_buf in the open call.
Fixes: c35633ab23 ("storage: Allow read only backing storage")
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Add sigterm/sigint handlers to enable graceful rmtfs server
bringdown on first instance of SIGINT/SIGTERM. Start/Stop the
remoteproc instance on RMTFS service up and SIGINT/SIGTERM
respectively. Force quit on second instance of SIGINT/SIGTERM.
Signed-off-by: Sibi Sankar <sibis@codeaurora.org>
[bjorn: Pipe for event loop signaling, reworked /sys traversal]
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Most devices has partitions named modemst1, modemst2, fsg and fsc
backing the rmtfs. Add a new argument '-P' to get the storage
implementation to use these partitions directly instead of files.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Add a new argument '-r' to prevent writes back to the backing storage.
This is useful for experimenting with the remote storage, without having
the files overwritten.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Pass "struct rmtfd" instead of file descriptors in the interface. This
cleans up the api a little bit, but more importantly allow us to
associate additional things with the remote file descriptors.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
The caller (and caller_id) are really "remote file descriptors", so
rename them based on this.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Instead of relying on an initial lseek, use pread/pwrite. This creates a
cleaner interface towards the storage.c implementation, allowing us to
provide a memory-only implementation of the backing storage.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Enable the specification of storage paths other than /boot, using
a new -o command line argument. Getoptify the command line arguments
for better processing.
Currently, in order to back the EFS storage with a regular file,
those files have to be pre-allocated, and with their correct size.
This is especially problematic when preparing a minimal FSG, since
we do not know ahead of time what size to pre-allocate.
Allow reads that go beyond the end of the backing storage to simply
read zeroes. When a write comes in, the file will be automatically
expanded to the correct size. (And should really only be written
if a full sector was pulled out of the modem). For solutions
that use partitions instead of files, this change should be a no-op.
The 'phys_address' argument of rmtfs_mem_read() and rmtfs_mem_write() is
an 'unsigned long' type value, which is then passed to the
'phys_address' argument of rmtfs_mem_ptr(), which is an 'unsigned int'
type value. This patch fixes the mismatch.
Signed-off-by: Ben Chan <benchan@chromium.org>
I see warnings like this:
sharedmem.c:89:44: warning: incompatible pointer types passing 'uint64_t *' (aka 'unsigned long long *') to parameter of type 'unsigned long *' [-Wincompatible-pointer-types]
Since 'unsigned long' might actually be smaller than 'uint64_t', we
should really upgrade to 'unsigned long long' parsing.
At the same time, the existing error handling was wrong: it should have
been looking for ULONG_MAX (per the man page). Convert that to
ULLONG_MAX to fix that bug while we're at it.
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
While convenient it's easy to mess things up with the qrtr project in
the include and library path. Drop these and rely on the installed
version of the include and library files.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
The message pump is cleaned up from cruft that was added to deal with
multiple services (rmtfs and rfsa) as well as ENETRESET handling.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Utilize the QMI encoder/decoder functions being part of libqrtr instead
of rolling our own.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
The rfsa service is not used on any supported targets and should most
likely be implemented in the kernel driver directly, so remove any
traces of it from rmtfs.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
The kernel driver exposing the shared memory was renamed, update the
path in rmtfs as well.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Attempt to open /dev/qcom_rfsa1 and use this instead of memory mapping
/dev/mem, while falling back to the old behavior. This allow us to drop
the dependency on /dev/mem access and will aid supporting multiple
memory regions.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Rather than exposing a pointer to the mmapped memory and performing IO
directly on this address pass the data through a local buffer and move
the reading and writing of memory into the sharedmem module.
This allows us to support shared memory that is not memory mapped in the
future.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Introduce a struct to pass around the parameters related to the rmtfs
memory, in preparation for supporting multiple memory regions.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>