|
|
Subscribe / Log in / New account

Allow dynamic allocation of software IO TLB bounce buffers

From:  Petr Tesarik <petrtesarik-AT-huaweicloud.com>
To:  Jonathan Corbet <corbet-AT-lwn.net>, Greg Kroah-Hartman <gregkh-AT-linuxfoundation.org>, "Rafael J. Wysocki" <rafael-AT-kernel.org>, Maarten Lankhorst <maarten.lankhorst-AT-linux.intel.com>, Maxime Ripard <mripard-AT-kernel.org>, Thomas Zimmermann <tzimmermann-AT-suse.de>, David Airlie <airlied-AT-gmail.com>, Daniel Vetter <daniel-AT-ffwll.ch>, Christoph Hellwig <hch-AT-lst.de>, Marek Szyprowski <m.szyprowski-AT-samsung.com>, Robin Murphy <robin.murphy-AT-arm.com>, Borislav Petkov <bp-AT-suse.de>, "Paul E. McKenney" <paulmck-AT-kernel.org>, Catalin Marinas <catalin.marinas-AT-arm.com>, Will Deacon <will-AT-kernel.org>, Zhen Lei <thunder.leizhen-AT-huawei.com>, Randy Dunlap <rdunlap-AT-infradead.org>, Damien Le Moal <damien.lemoal-AT-opensource.wdc.com>, Kim Phillips <kim.phillips-AT-amd.com>, "Steven Rostedt (Google)" <rostedt-AT-goodmis.org>, Muchun Song <muchun.song-AT-linux.dev>, Ondrej Zary <linux-AT-zary.sk>, "Jason A. Donenfeld" <Jason-AT-zx2c4.com>, Petr Tesarik <petr.tesarik.ext-AT-huawei.com>, Hans de Goede <hdegoede-AT-redhat.com>, Dan Williams <dan.j.williams-AT-intel.com>, Andy Shevchenko <andriy.shevchenko-AT-linux.intel.com>, Kees Cook <keescook-AT-chromium.org>, Thomas Gleixner <tglx-AT-linutronix.de>, Won Chung <wonchung-AT-google.com>, linux-doc-AT-vger.kernel.org (open list:DOCUMENTATION), linux-kernel-AT-vger.kernel.org (open list), dri-devel-AT-lists.freedesktop.org (open list:DRM DRIVERS), iommu-AT-lists.linux.dev (open list:DMA MAPPING HELPERS)
Subject:  [PATCH v2 0/7] Allow dynamic allocation of software IO TLB bounce buffers
Date:  Wed, 19 Apr 2023 12:03:52 +0200
Message-ID:  <cover.1681898595.git.petr.tesarik.ext@huawei.com>
Cc:  Roberto Sassu <roberto.sassu-AT-huawei.com>, Kefeng Wang <wangkefeng.wang-AT-huawei.com>, petr-AT-tesarici.cz
Archive-link:  Article

From: Petr Tesarik <petr.tesarik.ext@huawei.com>

The goal of my work is to provide more flexibility in the sizing of
SWIOTLB.

The software IO TLB was designed with these assumptions:

1. It would not be used much, especially on 64-bit systems.
2. A small fixed memory area (64 MiB by default) is sufficient to
   handle the few cases which require a bounce buffer.
3. 64 MiB is little enough that it has no impact on the rest of the
   system.

First, if SEV is active, all DMA must be done through shared
unencrypted pages, and SWIOTLB is used to make this happen without
changing device drivers. The software IO TLB size is increased to
6% of total memory in sev_setup_arch(), but that is more of an
approximation. The actual requirements may vary depending on the
amount of I/O and which drivers are used. These factors may not be
know at boot time, i.e. when SWIOTLB is allocated.

Second, other colleagues have noticed that they can reliably get
rid of occasional OOM kills on an Arm embedded device by reducing
the SWIOTLB size. This can be achieved with a kernel parameter, but
determining the right value puts additional burden on pre-release
testing, which could be avoided if SWIOTLB is allocated small and
grows only when necessary.

Changes from v1-devel-v7:
- Add comments to acquire/release barriers
- Fix whitespace issues reported by checkpatch.pl

Changes from v1-devel-v6:
- Provide long description of functions
- Fix kernel-doc (Returns: to Return:)
- Rename __lookup_dyn_slot() to lookup_dyn_slot_locked()

Changes from RFC:
- Track dynamic buffers per device instead of per swiotlb
- Use a linked list instead of a maple tree
- Move initialization of swiotlb fields of struct device to a
  helper function
- Rename __lookup_dyn_slot() to lookup_dyn_slot_locked()
- Introduce per-device flag if dynamic buffers are in use
- Add one more user of DMA_ATTR_MAY_SLEEP
- Add kernel-doc comments for new (and some old) code
- Properly escape '*' in dma-attributes.rst

Petr Tesarik (7):
  swiotlb: Use a helper to initialize swiotlb fields in struct device
  swiotlb: Move code around in preparation for dynamic bounce buffers
  dma-mapping: introduce the DMA_ATTR_MAY_SLEEP attribute
  swiotlb: Dynamically allocated bounce buffers
  swiotlb: Add a boot option to enable dynamic bounce buffers
  drm: Use DMA_ATTR_MAY_SLEEP from process context
  swiotlb: per-device flag if there are dynamically allocated buffers

 .../admin-guide/kernel-parameters.txt         |   6 +-
 Documentation/core-api/dma-attributes.rst     |  10 +
 drivers/base/core.c                           |   4 +-
 drivers/gpu/drm/drm_gem_shmem_helper.c        |   2 +-
 drivers/gpu/drm/drm_prime.c                   |   2 +-
 include/linux/device.h                        |  12 +
 include/linux/dma-mapping.h                   |   6 +
 include/linux/swiotlb.h                       |  54 ++-
 kernel/dma/swiotlb.c                          | 382 ++++++++++++++++--
 9 files changed, 443 insertions(+), 35 deletions(-)

-- 
2.25.1



Copyright © 2023, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds