SHA256
1
0
forked from pool/rtl-sdr
rtl-sdr/rtl-sdr-0001-mmap-bug-arm.patch

52 lines
1.9 KiB
Diff
Raw Normal View History

Accepting request 907681 from home:wkazubski:test:science - patches: rtl-sdr-0003-disable-zerocopy-by-default.patch rtl-sdr-0007-allow-build-rtlsdr-as-subroject.patch rtl-sdr-0008-add-CMP0075-policy.patch rtl-sdr-0016-add-missing-rtlsdrConfig.patch rtl-sdr-0017-add-rtl_biast-as-install-target.patch rtl-sdr-0018-fix-for-older-cmake.patch merged into rtl-sdr-0015-modernize-cmake-usage.patch - patch rtl-sdr-0005-add-rtlsdr_set_bias_tee_gpio.patch merged into rtl-sdr-0006-add-rtl_biast.patch - Added patches to upgrade to latest git head (only significant changes), including: + rtl-sdr-0001-mmap-bug-arm.patch + rtl-sdr-0002-fix-rtlsdr_open-memory-leak.patch + rtl-sdr-0003-disable-zerocopy-by-default.patch + rtl-sdr-0004-fix-rtl_eeprom-warnings.patch + rtl-sdr-0005-add-rtlsdr_set_bias_tee_gpio.patch + rtl-sdr-0006-add-rtl_biast.patch + rtl-sdr-0007-allow-build-rtlsdr-as-subroject.patch + rtl-sdr-0008-add-CMP0075-policy.patch + rtl-sdr-0009-fix-FC0013-UHF-reception.patch + rtl-sdr-0010-improve-librtlsdr_pc.patch + rtl-sdr-0011-improve-rtl_power--scanning-range-parsing.patch + rtl-sdr-0012-use-udev-uaccess_rules.patch (not used) + rtl-sdr-0013-add-IPV6-for-rtl_tcp.patch + rtl-sdr-0014-initialize-listensocket_in-rtl_tcp.patch + rtl-sdr-0015-modernize-cmake-usage.patch + rtl-sdr-0016-add-missing-rtlsdrConfig.patch + rtl-sdr-0017-add-rtl_biast-as-install-target.patch + rtl-sdr-0018-fix-for-older-cmake.patch + rtl-sdr-0019-fix-short-write-in-r82xx_read.patch + rtl-sdr-0020-populate-pkgconfig-with-prefix.patch * Full bias tee support for RTL-SDR v3 dongle * Command line utility rtl_biast for controlling bias tee * IPV-6 support for rtl_tcp * Fixed some bugs and compile time issues OBS-URL: https://build.opensuse.org/request/show/907681 OBS-URL: https://build.opensuse.org/package/show/hardware:sdr/rtl-sdr?expand=0&rev=21
2021-07-31 11:22:31 +02:00
From f68bb2fa772ad94f58c59babd78353667570630b Mon Sep 17 00:00:00 2001
From: Steve Markgraf <steve@steve-m.de>
Date: Sun, 7 Oct 2018 01:16:07 +0200
Subject: [PATCH] lib: Add workaround for Linux usbfs mmap() bug
The Linux Kernel has a bug on ARM/ARM64 systems where the USB CMA
memory is incorrectly mapped to userspace, breaking zerocopy.
When the Kernel allocates the memory, it clears it with memset().
If the mapping worked correctly, we should have zeroed out buffers,
if it doesn't, we get random Kernel memory. We now check for this,
and fall back to buffers in userspace if that's the case.
Signed-off-by: Steve Markgraf <steve@steve-m.de>
---
src/librtlsdr.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/src/librtlsdr.c b/src/librtlsdr.c
index 433ed5b..89ec903 100644
--- a/src/librtlsdr.c
+++ b/src/librtlsdr.c
@@ -1755,11 +1755,26 @@ static int _rtlsdr_alloc_async_buffers(rtlsdr_dev_t *dev)
for (i = 0; i < dev->xfer_buf_num; ++i) {
dev->xfer_buf[i] = libusb_dev_mem_alloc(dev->devh, dev->xfer_buf_len);
- if (!dev->xfer_buf[i]) {
+ if (dev->xfer_buf[i]) {
+ /* Check if Kernel usbfs mmap() bug is present: if the
+ * mapping is correct, the buffers point to memory that
+ * was memset to 0 by the Kernel, otherwise, they point
+ * to random memory. We check if the buffers are zeroed
+ * and otherwise fall back to buffers in userspace.
+ */
+ if (dev->xfer_buf[i][0] || memcmp(dev->xfer_buf[i],
+ dev->xfer_buf[i] + 1,
+ dev->xfer_buf_len - 1)) {
+ fprintf(stderr, "Detected Kernel usbfs mmap() "
+ "bug, falling back to buffers "
+ "in userspace\n");
+ dev->use_zerocopy = 0;
+ break;
+ }
+ } else {
fprintf(stderr, "Failed to allocate zero-copy "
"buffer for transfer %d\nFalling "
"back to buffers in userspace\n", i);
-
dev->use_zerocopy = 0;
break;
}