Commit 3de18c86 authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge branch 'stable/for-linus-5.15' of...

Merge branch 'stable/for-linus-5.15' of git://git.kernel.org/pub/scm/linux/kernel/git/konrad/swiotlb

Pull swiotlb updates from Konrad Rzeszutek Wilk:
 "A new feature called restricted DMA pools. It allows SWIOTLB to
  utilize per-device (or per-platform) allocated memory pools instead of
  using the global one.

  The first big user of this is ARM Confidential Computing where the
  memory for DMA operations can be set per platform"

* 'stable/for-linus-5.15' of git://git.kernel.org/pub/scm/linux/kernel/git/konrad/swiotlb: (23 commits)
  swiotlb: use depends on for DMA_RESTRICTED_POOL
  of: restricted dma: Don't fail device probe on rmem init failure
  of: Move of_dma_set_restricted_buffer() into device.c
  powerpc/svm: Don't issue ultracalls if !mem_encrypt_active()
  s390/pv: fix the forcing of the swiotlb
  swiotlb: Free tbl memory in swiotlb_exit()
  swiotlb: Emit diagnostic in swiotlb_exit()
  swiotlb: Convert io_default_tlb_mem to static allocation
  of: Return success from of_dma_set_restricted_buffer() when !OF_ADDRESS
  swiotlb: add overflow checks to swiotlb_bounce
  swiotlb: fix implicit debugfs declarations
  of: Add plumbing for restricted DMA pool
  dt-bindings: of: Add restricted DMA pool
  swiotlb: Add restricted DMA pool initialization
  swiotlb: Add restricted DMA alloc/free support
  swiotlb: Refactor swiotlb_tbl_unmap_single
  swiotlb: Move alloc_size to swiotlb_find_slots
  swiotlb: Use is_swiotlb_force_bounce for swiotlb data bouncing
  swiotlb: Update is_swiotlb_active to add a struct device argument
  swiotlb: Update is_swiotlb_buffer to add a struct device argument
  ...
parents 14726903 f3c4b134
Loading
Loading
Loading
Loading
+33 −3
Original line number Diff line number Diff line
@@ -51,6 +51,23 @@ compatible (optional) - standard definition
          used as a shared pool of DMA buffers for a set of devices. It can
          be used by an operating system to instantiate the necessary pool
          management subsystem if necessary.
        - restricted-dma-pool: This indicates a region of memory meant to be
          used as a pool of restricted DMA buffers for a set of devices. The
          memory region would be the only region accessible to those devices.
          When using this, the no-map and reusable properties must not be set,
          so the operating system can create a virtual mapping that will be used
          for synchronization. The main purpose for restricted DMA is to
          mitigate the lack of DMA access control on systems without an IOMMU,
          which could result in the DMA accessing the system memory at
          unexpected times and/or unexpected addresses, possibly leading to data
          leakage or corruption. The feature on its own provides a basic level
          of protection against the DMA overwriting buffer contents at
          unexpected times. However, to protect against general data leakage and
          system memory corruption, the system needs to provide way to lock down
          the memory access, e.g., MPU. Note that since coherent allocation
          needs remapping, one must set up another device coherent pool by
          shared-dma-pool and use dma_alloc_from_dev_coherent instead for atomic
          coherent allocation.
        - vendor specific string in the form <vendor>,[<device>-]<usage>
no-map (optional) - empty property
    - Indicates the operating system must not create a virtual mapping
@@ -85,10 +102,11 @@ memory-region-names (optional) - a list of names, one for each corresponding

Example
-------
This example defines 3 contiguous regions are defined for Linux kernel:
This example defines 4 contiguous regions for Linux kernel:
one default of all device drivers (named linux,cma@72000000 and 64MiB in size),
one dedicated to the framebuffer device (named framebuffer@78000000, 8MiB), and
one for multimedia processing (named multimedia-memory@77000000, 64MiB).
one dedicated to the framebuffer device (named framebuffer@78000000, 8MiB),
one for multimedia processing (named multimedia-memory@77000000, 64MiB), and
one for restricted dma pool (named restricted_dma_reserved@0x50000000, 64MiB).

/ {
	#address-cells = <1>;
@@ -120,6 +138,11 @@ one for multimedia processing (named multimedia-memory@77000000, 64MiB).
			compatible = "acme,multimedia-memory";
			reg = <0x77000000 0x4000000>;
		};

		restricted_dma_reserved: restricted_dma_reserved {
			compatible = "restricted-dma-pool";
			reg = <0x50000000 0x4000000>;
		};
	};

	/* ... */
@@ -138,4 +161,11 @@ one for multimedia processing (named multimedia-memory@77000000, 64MiB).
		memory-region = <&multimedia_reserved>;
		/* ... */
	};

	pcie_device: pcie_device@0,0 {
		reg = <0x83010000 0x0 0x00000000 0x0 0x00100000
		       0x83010000 0x0 0x00100000 0x0 0x00100000>;
		memory-region = <&restricted_dma_reserved>;
		/* ... */
	};
};
+6 −0
Original line number Diff line number Diff line
@@ -63,6 +63,9 @@ void __init svm_swiotlb_init(void)

int set_memory_encrypted(unsigned long addr, int numpages)
{
	if (!mem_encrypt_active())
		return 0;

	if (!PAGE_ALIGNED(addr))
		return -EINVAL;

@@ -73,6 +76,9 @@ int set_memory_encrypted(unsigned long addr, int numpages)

int set_memory_decrypted(unsigned long addr, int numpages)
{
	if (!mem_encrypt_active())
		return 0;

	if (!PAGE_ALIGNED(addr))
		return -EINVAL;

+1 −1
Original line number Diff line number Diff line
@@ -187,9 +187,9 @@ static void pv_init(void)
		return;

	/* make sure bounce buffers are shared */
	swiotlb_force = SWIOTLB_FORCE;
	swiotlb_init(1);
	swiotlb_update_mem_attributes();
	swiotlb_force = SWIOTLB_FORCE;
}

void __init mem_init(void)
+4 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
#include <linux/netdevice.h>
#include <linux/sched/signal.h>
#include <linux/sched/mm.h>
#include <linux/swiotlb.h>
#include <linux/sysfs.h>
#include <linux/dma-map-ops.h> /* for dma_default_coherent */

@@ -2851,6 +2852,9 @@ void device_initialize(struct device *dev)
    defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL)
	dev->dma_coherent = dma_default_coherent;
#endif
#ifdef CONFIG_SWIOTLB
	dev->dma_io_tlb_mem = &io_tlb_default_mem;
#endif
}
EXPORT_SYMBOL_GPL(device_initialize);

+1 −1
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ static int i915_gem_object_get_pages_internal(struct drm_i915_gem_object *obj)

	max_order = MAX_ORDER;
#ifdef CONFIG_SWIOTLB
	if (is_swiotlb_active()) {
	if (is_swiotlb_active(obj->base.dev->dev)) {
		unsigned int max_segment;

		max_segment = swiotlb_max_segment();
Loading