On backports where the dmabuf_page_pool mutex could not be completely
removed because of KMI constraints, we lock the mutex to prevent anyone
from acquiring it. While this is fine for regular builds, lockdep
reports a deadlock because of this behavior. So here we remove the call
to mutex_lock for this unused mutex.
Bug: 269576779
Bug: 278035310
Fixes: 150b3c4e4b ("BACKPORT: ANDROID: dma-buf: heaps: replace mutex lock with spinlock")
Change-Id: Ic426b6e435ec4ac7b0355c50ec9ea14d38acfa43
Signed-off-by: T.J. Mercier <tjmercier@google.com>
kmap_atomic was deprecated in 5.11, and checkpatch now warns about use
of it. Replace with kmap_local_page, and do not manually disable
preemption or page faults.
Bug: 264474028
Fixes: ef2ab77cc1 ("ANDROID: dma-buf: system_heap: Add pagepool support to system heap")
Change-Id: Idd6413ff56aadf4fd925acb6f567366d0e03166f
Signed-off-by: T.J. Mercier <tjmercier@google.com>
We should use spinlock to protect page pool's critical section as
1. The critical section is short, using spinlock is more efficient.
2. Spinlock could protect priority inversion. Ex. Low priority
thread (dmabuf-deferred) hold the page lock but get scheduled
out under heavy loading. Then the other high priority threads
need to wait for dmabuf-deferred to release the lock. It causes
long allocation latency and possible UI jank.
Also, we could move NR_KERNEL_MISC_RECLAIMABLE stat out of the
critical section to make it shorter as mod_node_page_state can
handle concurrent access cases.
Conflicts:
drivers/dma-buf/heaps/page_pool.h
drivers/dma-buf/heaps/page_pool.c
1. The android13-5.15 KMI is frozen, and the modification to struct
dmabuf_page_pool in the original patch would break the KMI.
Instead we wrap dmabuf_page_pool allocations in a struct
dmabuf_page_pool_with_spinlock which also contains a spinlock
replacement for dmabuf_page_pool's mutex.
No callers should attempt to acquire dmabuf_page_pool's mutex on this
branch, so it is locked immediately after initialization and never
unlocked.
(cherry picked from commit 060e38dce1d69b81fe633f31751a610e3dd8e983)
Bug: 245454030
Change-Id: I15f349f9e893621f71ca79f1de037de184c33edf
Signed-off-by: T.J. Mercier <tjmercier@google.com>
For dma-heap users, they can't bypass cache sync when map/unmap iova
with dma heap. But they can do it by adding DMA_ATTR_SKIP_CPU_SYNC
into dma_alloc_attrs.
To keep alignment, at dma_heap side, also use
dma_buf_attachment.dma_map_attrs to do iova map & unmap.
This patch is a little different with linux patch, because ACK
has cached heap, and linux doesn't have it
Bug: 229794062
Link: https://lore.kernel.org/patchwork/patch/1455032/
Change-Id: I324712644688c29e55c9197efcde9283bbbd813b
Signed-off-by: Guangming Cao <Guangming.Cao@mediatek.com>
Since vendors might depend on them for their system heap
implementations, make the page-pool library built-in to
freeze its KMI.
Bug: 183902174
Bug: 212210831
Change-Id: If633619ec1f78d0fbd73c43c48b19d98db7807af
Signed-off-by: Hridya Valsaraju <hridya@google.com>
this critical region should be protected by pool->mutex.
Bug: 207658347
Fixes: e7dac4c3231c ("ANDROID: dma-buf: heaps: Add a shrinker controlled page pool")
Signed-off-by: liuhailong <liuhailong@oppo.com>
Signed-off-by: xieliujie <xieliujie@oppo.com>
Change-Id: I6f129926c96176258a965964c24602fc647db61e
dmabuf_page_pool_init_shrinker needs to be static to prevent a warning
when compiling with -Wmissing-prototypes. Change it to be static.
Fixes: e7dac4c3231c ("ANDROID: dma-buf: heaps: Add a shrinker controlled page pool")
Bug: 168742043
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: I64184cf4062e33c14a60b9c3d505db922f2b9c0b
Changes in 5.15.7
ALSA: usb-audio: Restrict rates for the shared clocks
ALSA: usb-audio: Rename early_playback_start flag with lowlatency_playback
ALSA: usb-audio: Disable low-latency playback for free-wheel mode
ALSA: usb-audio: Disable low-latency mode for implicit feedback sync
ALSA: usb-audio: Check available frames for the next packet size
ALSA: usb-audio: Add spinlock to stop_urbs()
ALSA: usb-audio: Improved lowlatency playback support
ALSA: usb-audio: Avoid killing in-flight URBs during draining
ALSA: usb-audio: Fix packet size calculation regression
ALSA: usb-audio: Less restriction for low-latency playback mode
ALSA: usb-audio: Switch back to non-latency mode at a later point
ALSA: usb-audio: Don't start stream for capture at prepare
gfs2: release iopen glock early in evict
gfs2: Fix length of holes reported at end-of-file
powerpc/pseries/ddw: Revert "Extend upper limit for huge DMA window for persistent memory"
powerpc/pseries/ddw: Do not try direct mapping with persistent memory and one window
drm/sun4i: fix unmet dependency on RESET_CONTROLLER for PHY_SUN6I_MIPI_DPHY
mac80211: do not access the IV when it was stripped
mac80211: fix throughput LED trigger
x86/hyperv: Move required MSRs check to initial platform probing
net/smc: Transfer remaining wait queue entries during fallback
atlantic: Fix OOB read and write in hw_atl_utils_fw_rpc_wait
net: return correct error code
pinctrl: qcom: fix unmet dependencies on GPIOLIB for GPIOLIB_IRQCHIP
platform/x86: dell-wmi-descriptor: disable by default
platform/x86: thinkpad_acpi: Add support for dual fan control
platform/x86: thinkpad_acpi: Fix WWAN device disabled issue after S3 deep
s390/setup: avoid using memblock_enforce_memory_limit
btrfs: silence lockdep when reading chunk tree during mount
btrfs: check-integrity: fix a warning on write caching disabled disk
thermal: core: Reset previous low and high trip during thermal zone init
scsi: iscsi: Unblock session then wake up error handler
net: usb: r8152: Add MAC passthrough support for more Lenovo Docks
drm/amd/pm: Remove artificial freq level on Navi1x
drm/amd/amdkfd: Fix kernel panic when reset failed and been triggered again
drm/amd/amdgpu: fix potential memleak
ata: ahci: Add Green Sardine vendor ID as board_ahci_mobile
ata: libahci: Adjust behavior when StorageD3Enable _DSD is set
ethernet: hisilicon: hns: hns_dsaf_misc: fix a possible array overflow in hns_dsaf_ge_srst_by_port()
ipv6: check return value of ipv6_skip_exthdr
net: tulip: de4x5: fix the problem that the array 'lp->phy[8]' may be out of bound
net: ethernet: dec: tulip: de4x5: fix possible array overflows in type3_infoblock()
perf sort: Fix the 'weight' sort key behavior
perf sort: Fix the 'ins_lat' sort key behavior
perf sort: Fix the 'p_stage_cyc' sort key behavior
perf inject: Fix ARM SPE handling
perf hist: Fix memory leak of a perf_hpp_fmt
perf report: Fix memory leaks around perf_tip()
tracing: Don't use out-of-sync va_list in event printing
net/smc: Avoid warning of possible recursive locking
ACPI: Add stubs for wakeup handler functions
net/tls: Fix authentication failure in CCM mode
vrf: Reset IPCB/IP6CB when processing outbound pkts in vrf dev xmit
kprobes: Limit max data_size of the kretprobe instances
ALSA: hda/cs8409: Set PMSG_ON earlier inside cs8409 driver
rt2x00: do not mark device gone on EPROTO errors during start
ipmi: Move remove_work to dedicated workqueue
cpufreq: Fix get_cpu_device() failure in add_cpu_dev_symlink()
iwlwifi: mvm: retry init flow if failed
dma-buf: system_heap: Use 'for_each_sgtable_sg' in pages free flow
s390/pci: move pseudo-MMIO to prevent MIO overlap
fget: check that the fd still exists after getting a ref to it
sata_fsl: fix UAF in sata_fsl_port_stop when rmmod sata_fsl
sata_fsl: fix warning in remove_proc_entry when rmmod sata_fsl
scsi: lpfc: Fix non-recovery of remote ports following an unsolicited LOGO
scsi: ufs: ufs-pci: Add support for Intel ADL
ipv6: fix memory leak in fib6_rule_suppress
drm/amd/display: Allow DSC on supported MST branch devices
drm/i915/dp: Perform 30ms delay after source OUI write
KVM: fix avic_set_running for preemptable kernels
KVM: Disallow user memslot with size that exceeds "unsigned long"
KVM: x86/mmu: Fix TLB flush range when handling disconnected pt
KVM: Ensure local memslot copies operate on up-to-date arch-specific data
KVM: x86: ignore APICv if LAPIC is not enabled
KVM: nVMX: Emulate guest TLB flush on nested VM-Enter with new vpid12
KVM: nVMX: Flush current VPID (L1 vs. L2) for KVM_REQ_TLB_FLUSH_GUEST
KVM: nVMX: Abide to KVM_REQ_TLB_FLUSH_GUEST request on nested vmentry/vmexit
KVM: VMX: prepare sync_pir_to_irr for running with APICv disabled
KVM: x86: Use a stable condition around all VT-d PI paths
KVM: MMU: shadow nested paging does not have PKU
KVM: arm64: Avoid setting the upper 32 bits of TCR_EL2 and CPTR_EL2 to 1
KVM: X86: Use vcpu->arch.walk_mmu for kvm_mmu_invlpg()
KVM: x86: check PIR even for vCPUs with disabled APICv
tracing/histograms: String compares should not care about signed values
net: dsa: mv88e6xxx: Fix application of erratum 4.8 for 88E6393X
net: dsa: mv88e6xxx: Drop unnecessary check in mv88e6393x_serdes_erratum_4_6()
net: dsa: mv88e6xxx: Save power by disabling SerDes trasmitter and receiver
net: dsa: mv88e6xxx: Add fix for erratum 5.2 of 88E6393X family
net: dsa: mv88e6xxx: Fix inband AN for 2500base-x on 88E6393X family
net: dsa: mv88e6xxx: Link in pcs_get_state() if AN is bypassed
wireguard: selftests: increase default dmesg log size
wireguard: allowedips: add missing __rcu annotation to satisfy sparse
wireguard: selftests: actually test for routing loops
wireguard: selftests: rename DEBUG_PI_LIST to DEBUG_PLIST
wireguard: device: reset peer src endpoint when netns exits
wireguard: receive: use ring buffer for incoming handshakes
wireguard: receive: drop handshakes if queue lock is contended
wireguard: ratelimiter: use kvcalloc() instead of kvzalloc()
i2c: stm32f7: flush TX FIFO upon transfer errors
i2c: stm32f7: recover the bus on access timeout
i2c: stm32f7: stop dma transfer in case of NACK
i2c: cbus-gpio: set atomic transfer callback
natsemi: xtensa: fix section mismatch warnings
tcp: fix page frag corruption on page fault
net: qlogic: qlcnic: Fix a NULL pointer dereference in qlcnic_83xx_add_rings()
net: mpls: Fix notifications when deleting a device
siphash: use _unaligned version by default
arm64: ftrace: add missing BTIs
iwlwifi: fix warnings produced by kernel debug options
net/mlx5e: IPsec: Fix Software parser inner l3 type setting in case of encapsulation
net/mlx4_en: Fix an use-after-free bug in mlx4_en_try_alloc_resources()
selftests: net: Correct case name
net: dsa: b53: Add SPI ID table
mt76: mt7915: fix NULL pointer dereference in mt7915_get_phy_mode
ASoC: tegra: Fix wrong value type in ADMAIF
ASoC: tegra: Fix wrong value type in I2S
ASoC: tegra: Fix wrong value type in DMIC
ASoC: tegra: Fix wrong value type in DSPK
ASoC: tegra: Fix kcontrol put callback in ADMAIF
ASoC: tegra: Fix kcontrol put callback in I2S
ASoC: tegra: Fix kcontrol put callback in DMIC
ASoC: tegra: Fix kcontrol put callback in DSPK
ASoC: tegra: Fix kcontrol put callback in AHUB
rxrpc: Fix rxrpc_peer leak in rxrpc_look_up_bundle()
rxrpc: Fix rxrpc_local leak in rxrpc_lookup_peer()
ALSA: intel-dsp-config: add quirk for CML devices based on ES8336 codec
net: stmmac: Avoid DMA_CHAN_CONTROL write if no Split Header support
net: usb: lan78xx: lan78xx_phy_init(): use PHY_POLL instead of "0" if no IRQ is available
net: marvell: mvpp2: Fix the computation of shared CPUs
dpaa2-eth: destroy workqueue at the end of remove function
octeontx2-af: Fix a memleak bug in rvu_mbox_init()
net: annotate data-races on txq->xmit_lock_owner
ipv4: convert fib_num_tclassid_users to atomic_t
net/smc: fix wrong list_del in smc_lgr_cleanup_early
net/rds: correct socket tunable error in rds_tcp_tune()
net/smc: Keep smc_close_final rc during active close
drm/msm/a6xx: Allocate enough space for GMU registers
drm/msm: Do hw_init() before capturing GPU state
drm/vc4: kms: Wait for the commit before increasing our clock rate
drm/vc4: kms: Fix return code check
drm/vc4: kms: Add missing drm_crtc_commit_put
drm/vc4: kms: Clear the HVS FIFO commit pointer once done
drm/vc4: kms: Don't duplicate pending commit
drm/vc4: kms: Fix previous HVS commit wait
atlantic: Increase delay for fw transactions
atlatnic: enable Nbase-t speeds with base-t
atlantic: Fix to display FW bundle version instead of FW mac version.
atlantic: Add missing DIDs and fix 115c.
Remove Half duplex mode speed capabilities.
atlantic: Fix statistics logic for production hardware
atlantic: Remove warn trace message.
KVM: x86/mmu: Skip tlb flush if it has been done in zap_gfn_range()
KVM: x86/mmu: Pass parameter flush as false in kvm_tdp_mmu_zap_collapsible_sptes()
drm/msm/devfreq: Fix OPP refcnt leak
drm/msm: Fix mmap to include VM_IO and VM_DONTDUMP
drm/msm: Fix wait_fence submitqueue leak
drm/msm: Restore error return on invalid fence
ASoC: rk817: Add module alias for rk817-codec
iwlwifi: Fix memory leaks in error handling path
KVM: X86: Fix when shadow_root_level=5 && guest root_level<4
KVM: SEV: initialize regions_list of a mirror VM
net/mlx5e: Fix missing IPsec statistics on uplink representor
net/mlx5: Move MODIFY_RQT command to ignore list in internal error state
net/mlx5: E-switch, Respect BW share of the new group
net/mlx5: E-Switch, fix single FDB creation on BlueField
net/mlx5: E-Switch, Check group pointer before reading bw_share value
KVM: x86/pmu: Fix reserved bits for AMD PerfEvtSeln register
KVM: VMX: Set failure code in prepare_vmcs02()
mctp: Don't let RTM_DELROUTE delete local routes
Revert "drm/i915: Implement Wa_1508744258"
io-wq: don't retry task_work creation failure on fatal conditions
x86/sev: Fix SEV-ES INS/OUTS instructions for word, dword, and qword
x86/entry: Add a fence for kernel entry SWAPGS in paranoid_entry()
x86/entry: Use the correct fence macro after swapgs in kernel CR3
x86/xen: Add xenpv_restore_regs_and_return_to_usermode()
preempt/dynamic: Fix setup_preempt_mode() return value
sched/uclamp: Fix rq->uclamp_max not set on first enqueue
KVM: SEV: Return appropriate error codes if SEV-ES scratch setup fails
KVM: x86/mmu: Rename slot_handle_leaf to slot_handle_level_4k
KVM: x86/mmu: Remove spurious TLB flushes in TDP MMU zap collapsible path
net/mlx5e: Rename lro_timeout to packet_merge_timeout
net/mlx5e: Rename TIR lro functions to TIR packet merge functions
net/mlx5e: Sync TIR params updates against concurrent create/modify
serial: 8250_bcm7271: UART errors after resuming from S2
parisc: Fix KBUILD_IMAGE for self-extracting kernel
parisc: Fix "make install" on newer debian releases
parisc: Mark cr16 CPU clocksource unstable on all SMP machines
vgacon: Propagate console boot parameters before calling `vc_resize'
xhci: Fix commad ring abort, write all 64 bits to CRCR register.
USB: NO_LPM quirk Lenovo Powered USB-C Travel Hub
usb: typec: tcpm: Wait in SNK_DEBOUNCED until disconnect
usb: cdns3: gadget: fix new urb never complete if ep cancel previous requests
usb: cdnsp: Fix a NULL pointer dereference in cdnsp_endpoint_init()
x86/tsc: Add a timer to make sure TSC_adjust is always checked
x86/tsc: Disable clocksource watchdog for TSC on qualified platorms
x86/64/mm: Map all kernel memory into trampoline_pgd
tty: serial: msm_serial: Deactivate RX DMA for polling support
serial: pl011: Add ACPI SBSA UART match id
serial: tegra: Change lower tolerance baud rate limit for tegra20 and tegra30
serial: core: fix transmit-buffer reset and memleak
serial: 8250_pci: Fix ACCES entries in pci_serial_quirks array
serial: 8250_pci: rewrite pericom_do_set_divisor()
serial: 8250: Fix RTS modem control while in rs485 mode
serial: liteuart: Fix NULL pointer dereference in ->remove()
serial: liteuart: fix use-after-free and memleak on unbind
serial: liteuart: fix minor-number leak on probe errors
ipmi: msghandler: Make symbol 'remove_work_wq' static
Linux 5.15.7
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: I9300a10911f6205d2fb76f18255b017d34d68d1d
commit 679d94cd7d900871e5bc9cf780bd5b73af35ab42 upstream.
For previous version, it uses 'sg_table.nent's to traverse sg_table in pages
free flow.
However, 'sg_table.nents' is reassigned in 'dma_map_sg', it means the number of
created entries in the DMA adderess space.
So, use 'sg_table.nents' in pages free flow will case some pages can't be freed.
Here we should use sg_table.orig_nents to free pages memory, but use the
sgtable helper 'for each_sgtable_sg'(, instead of the previous rather common
helper 'for_each_sg' which maybe cause memory leak) is much better.
Fixes: d963ab0f15 ("dma-buf: system_heap: Allocate higher order pages if available")
Signed-off-by: Guangming <Guangming.Cao@mediatek.com>
Reviewed-by: Robin Murphy <robin.murphy@arm.com>
Cc: <stable@vger.kernel.org> # 5.11.*
Reviewed-by: Christian König <christian.koenig@amd.com>
Reviewed-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Sumit Semwal <sumit.semwal@linaro.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20211126074904.88388-1-guangming.cao@mediatek.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
The deferred-free library heap can be useful for modular implementations
of the system heap, so compile it as a part of the GKI for arm64 and
x86.
Bug: 194472281
Change-Id: Iedd85682a90980b26a2f9aac0a53fcf4e1da219e
Signed-off-by: Isaac J. Manjarres <isaacm@codeaurora.org>
Steps on the way to 5.12-rc1
Resolves merge conflicts in:
drivers/dma-buf/dma-heap.c
drivers/dma-buf/heaps/cma_heap.c
drivers/dma-buf/heaps/system_heap.c
include/linux/dma-heap.h
Cc: John Stultz <john.stultz@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: Ibb32dbdba5183c9e19f5d1e94016cc1ae9616173
This patch sets CONFIG_DMABUF_HEAPS_SYSTEM to tristate and exports the
symbol dma_heap_get_dev() to allow the DMA-BUF system heap to be a
module.
This change is intended to allow partners to continue using
device/SoC-specific optimizations in their system heap implementations
when they switch from ION to DMA-BUF heaps. The ION system heap was
built-in and partners were asked to override the system heap ID with
their own if they wanted to override the GKI system heap. This
per-vendor approach to override system heap will no longer be possible
with DMA-BUF heaps since Android S aims to restrict framework access to
DMA-BUF vendor heaps by only letting it access ABI-defined vendor heaps.
VTS tests will be created to ensure that the system heap is present
at /dev/dma_heap/system and behaves as expected of the system heap.
Bug: 175697666
Bug: 155218010
Bug: 172527615
Change-Id: Iabb24d9aedde308a9b15509781dd0e6b67353e99
Signed-off-by: Hridya Valsaraju <hridya@google.com>
(cherry picked from commit c975699b4953ea3251695c16ef65ecb722c91188)
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
This adds a heap that allocates non-contiguous buffers that are
marked as writecombined, so they are not cached by the CPU.
This is useful, as most graphics buffers are usually not touched
by the CPU or only written into once by the CPU. So when mapping
the buffer over and over between devices, we can skip the CPU
syncing, which saves a lot of cache management overhead, greatly
improving performance.
For folk using ION, there was a ION_FLAG_CACHED flag, which
signaled if the returned buffer should be CPU cacheable or not.
With DMA-BUF heaps, we do not yet have such a flag, and by default
the current heaps (system and cma) produce CPU cachable buffers.
So for folks transitioning from ION to DMA-BUF Heaps, this fills
in some of that missing functionality.
There has been a suggestion to make this functionality a flag
(DMAHEAP_FLAG_UNCACHED?) on the system heap, similar to how
ION used the ION_FLAG_CACHED. But I want to make sure an
_UNCACHED flag would truely be a generic attribute across all
heaps. So far that has been unclear, so having it as a separate
heap seemes better for now. (But I'm open to discussion on this
point!)
This is a rework of earlier efforts to add a uncached system heap,
done utilizing the exisitng system heap, adding just a bit of
logic to handle the uncached case.
Feedback would be very welcome!
Many thanks to Liam Mark for his help to get this working.
Pending opensource users of this code include:
* AOSP HiKey960 gralloc:
- https://android-review.googlesource.com/c/device/linaro/hikey/+/1399519
- Visibly improves performance over the system heap
* AOSP Codec2 (possibly, needs more review):
- https://android-review.googlesource.com/c/platform/frameworks/av/+/1360640/17/media/codec2/vndk/C2DmaBufAllocator.cpp#325
Signed-off-by: John Stultz <john.stultz@linaro.org>
Link: https://lore.kernel.org/lkml/20201110034934.70898-8-john.stultz@linaro.org/
Bug: 170887642
Change-Id: I56cb3acf58546c7dfd423a2ce432e3d6d7fd7a69
Signed-off-by: Hridya Valsaraju <hridya@google.com>
(cherry picked from commit 79793050fa3eaad4099e259a63622ffea17f0683)
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
Steps on the way to 5.11-rc1
Resolves merge issues in:
kernel/sched/sched.h
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: If5b00273202785ed39c5f46dfb92dd7791499cda
Steps on the way to 5.11-rc1
Resolves conflicts in:
drivers/dma-buf/heaps/cma_heap.c
drivers/dma-buf/heaps/system_heap.c
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: Iac498252911dd67ee21bba42b3fa5a2324dd43e0
Because of 20e76f1a70 ("dma-buf: Use struct dma_buf_map in
dma_buf_vunmap() interfaces") and 6619ccf1bb ("dma-buf: Use struct
dma_buf_map in dma_buf_vmap() interfaces"), the vmap and vunmap callback
functions changed. Fix up the cma_heap.c code to reflect these changes.
Fixes: b61614ec31 ("dma-buf: heaps: Add CMA heap to dmabuf heaps")
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: I14e8d404a945db3b63f78a811f23928ecb316c2c
Steps on the way to 5.11-rc1.
Required resolutions in:
include/linux/dma-buf.h
drivers/dma-buf/heaps/system_heap.c
drivers/staging/android/ion/ion_dma_buf.c
drivers/dma-buf/heaps/heap-helpers.c
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: Ic546af62c7f61b5c754ece178c32f45878013c3a
This patch is basically a port of Ørjan Eide's similar patch for ION
https://lore.kernel.org/lkml/20200414134629.54567-1-orjan.eide@arm.com/
Only sync the sg-list of dma-buf heap attachment when the attachment
is actually mapped on the device.
dma-bufs may be synced at any time. It can be reached from user space
via DMA_BUF_IOCTL_SYNC, so there are no guarantees from callers on when
syncs may be attempted, and dma_buf_end_cpu_access() and
dma_buf_begin_cpu_access() may not be paired.
Since the sg_list's dma_address isn't set up until the buffer is used
on the device, and dma_map_sg() is called on it, the dma_address will be
NULL if sync is attempted on the dma-buf before it's mapped on a device.
Before v5.0 (commit 55897af630 ("dma-direct: merge swiotlb_dma_ops
into the dma_direct code")) this was a problem as the dma-api (at least
the swiotlb_dma_ops on arm64) would use the potentially invalid
dma_address. How that failed depended on how the device handled physical
address 0. If 0 was a valid address to physical ram, that page would get
flushed a lot, while the actual pages in the buffer would not get synced
correctly. While if 0 is an invalid physical address it may cause a
fault and trigger a crash.
In v5.0 this was incidentally fixed by commit 55897af630 ("dma-direct:
merge swiotlb_dma_ops into the dma_direct code"), as this moved the
dma-api to use the page pointer in the sg_list, and (for Ion buffers at
least) this will always be valid if the sg_list exists at all.
But, this issue is re-introduced in v5.3 with
commit 449fa54d68 ("dma-direct: correct the physical addr in
dma_direct_sync_sg_for_cpu/device") moves the dma-api back to the old
behaviour and picks the dma_address that may be invalid.
dma-buf core doesn't ensure that the buffer is mapped on the device, and
thus have a valid sg_list, before calling the exporter's
begin_cpu_access.
Logic and commit message originally by: Ørjan Eide <orjan.eide@arm.com>
Cc: Sumit Semwal <sumit.semwal@linaro.org>
Cc: Liam Mark <lmark@codeaurora.org>
Cc: Laura Abbott <labbott@kernel.org>
Cc: Brian Starkey <Brian.Starkey@arm.com>
Cc: Hridya Valsaraju <hridya@google.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Sandeep Patil <sspatil@google.com>
Cc: Daniel Mentz <danielmentz@google.com>
Cc: Chris Goldsworthy <cgoldswo@codeaurora.org>
Cc: Ørjan Eide <orjan.eide@arm.com>
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: Ezequiel Garcia <ezequiel@collabora.com>
Cc: Simon Ser <contact@emersion.fr>
Cc: James Jones <jajones@nvidia.com>
Cc: linux-media@vger.kernel.org
Cc: dri-devel@lists.freedesktop.org
Reviewed-by: Brian Starkey <brian.starkey@arm.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Bug: 173440990
(cherry picked from commit 4c68e499bb
git: //anongit.freedesktop.org/drm/drm-misc
tags/drm-misc-next-2020-11-27)
Link: https://lore.kernel.org/patchwork/patch/1343071/
Change-Id: If1c7312e437a8166a7d3e65bcd4c352f46cab718
Signed-off-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Hridya Valsaraju <hridya@google.com>
This patch is basically a port of Ørjan Eide's similar patch for ION
https://lore.kernel.org/lkml/20200414134629.54567-1-orjan.eide@arm.com/
Only sync the sg-list of dma-buf heap attachment when the attachment
is actually mapped on the device.
dma-bufs may be synced at any time. It can be reached from user space
via DMA_BUF_IOCTL_SYNC, so there are no guarantees from callers on when
syncs may be attempted, and dma_buf_end_cpu_access() and
dma_buf_begin_cpu_access() may not be paired.
Since the sg_list's dma_address isn't set up until the buffer is used
on the device, and dma_map_sg() is called on it, the dma_address will be
NULL if sync is attempted on the dma-buf before it's mapped on a device.
Before v5.0 (commit 55897af630 ("dma-direct: merge swiotlb_dma_ops
into the dma_direct code")) this was a problem as the dma-api (at least
the swiotlb_dma_ops on arm64) would use the potentially invalid
dma_address. How that failed depended on how the device handled physical
address 0. If 0 was a valid address to physical ram, that page would get
flushed a lot, while the actual pages in the buffer would not get synced
correctly. While if 0 is an invalid physical address it may cause a
fault and trigger a crash.
In v5.0 this was incidentally fixed by commit 55897af630 ("dma-direct:
merge swiotlb_dma_ops into the dma_direct code"), as this moved the
dma-api to use the page pointer in the sg_list, and (for Ion buffers at
least) this will always be valid if the sg_list exists at all.
But, this issue is re-introduced in v5.3 with
commit 449fa54d68 ("dma-direct: correct the physical addr in
dma_direct_sync_sg_for_cpu/device") moves the dma-api back to the old
behaviour and picks the dma_address that may be invalid.
dma-buf core doesn't ensure that the buffer is mapped on the device, and
thus have a valid sg_list, before calling the exporter's
begin_cpu_access.
Logic and commit message originally by: Ørjan Eide <orjan.eide@arm.com>
Cc: Sumit Semwal <sumit.semwal@linaro.org>
Cc: Liam Mark <lmark@codeaurora.org>
Cc: Laura Abbott <labbott@kernel.org>
Cc: Brian Starkey <Brian.Starkey@arm.com>
Cc: Hridya Valsaraju <hridya@google.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Sandeep Patil <sspatil@google.com>
Cc: Daniel Mentz <danielmentz@google.com>
Cc: Chris Goldsworthy <cgoldswo@codeaurora.org>
Cc: Ørjan Eide <orjan.eide@arm.com>
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: Ezequiel Garcia <ezequiel@collabora.com>
Cc: Simon Ser <contact@emersion.fr>
Cc: James Jones <jajones@nvidia.com>
Cc: linux-media@vger.kernel.org
Cc: dri-devel@lists.freedesktop.org
Reviewed-by: Brian Starkey <brian.starkey@arm.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Sumit Semwal <sumit.semwal@linaro.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20201121235002.69945-5-john.stultz@linaro.org
Resolves conflicts in:
kernel/dma/mapping.c
Steps on the way to 5.10-rc1
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: I61292201a3ac4b92c39f330585692652cf985550
Steps on the way to 5.10-rc1
Fixes merge conflicts in:
drivers/gpu/drm/bridge/lontium-lt9611.c
drivers/gpu/drm/virtio/virtgpu_display.c
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: I65d9d4c69ea7c79854d275462c9aca0a37d42654
Pull dma-mapping updates from Christoph Hellwig:
- rework the non-coherent DMA allocator
- move private definitions out of <linux/dma-mapping.h>
- lower CMA_ALIGNMENT (Paul Cercueil)
- remove the omap1 dma address translation in favor of the common code
- make dma-direct aware of multiple dma offset ranges (Jim Quinlan)
- support per-node DMA CMA areas (Barry Song)
- increase the default seg boundary limit (Nicolin Chen)
- misc fixes (Robin Murphy, Thomas Tai, Xu Wang)
- various cleanups
* tag 'dma-mapping-5.10' of git://git.infradead.org/users/hch/dma-mapping: (63 commits)
ARM/ixp4xx: add a missing include of dma-map-ops.h
dma-direct: simplify the DMA_ATTR_NO_KERNEL_MAPPING handling
dma-direct: factor out a dma_direct_alloc_from_pool helper
dma-direct check for highmem pages in dma_direct_alloc_pages
dma-mapping: merge <linux/dma-noncoherent.h> into <linux/dma-map-ops.h>
dma-mapping: move large parts of <linux/dma-direct.h> to kernel/dma
dma-mapping: move dma-debug.h to kernel/dma/
dma-mapping: remove <asm/dma-contiguous.h>
dma-mapping: merge <linux/dma-contiguous.h> into <linux/dma-map-ops.h>
dma-contiguous: remove dma_contiguous_set_default
dma-contiguous: remove dev_set_cma_area
dma-contiguous: remove dma_declare_contiguous
dma-mapping: split <linux/dma-mapping.h>
cma: decrease CMA_ALIGNMENT lower limit to 2
firewire-ohci: use dma_alloc_pages
dma-iommu: implement ->alloc_noncoherent
dma-mapping: add new {alloc,free}_noncoherent dma_map_ops methods
dma-mapping: add a new dma_alloc_pages API
dma-mapping: remove dma_cache_sync
53c700: convert to dma_alloc_noncoherent
...
Merge dma-contiguous.h into dma-map-ops.h, after removing the comment
describing the contiguous allocator into kernel/dma/contigous.c.
Signed-off-by: Christoph Hellwig <hch@lst.de>