Skip to content

Commit 3f6280d

Browse files
committed
Merge branch 'iommu-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip
* 'iommu-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: (61 commits) amd-iommu: remove unnecessary "AMD IOMMU: " prefix amd-iommu: detach device explicitly before attaching it to a new domain amd-iommu: remove BUS_NOTIFY_BOUND_DRIVER handling dma-debug: simplify logic in driver_filter() dma-debug: disable/enable irqs only once in device_dma_allocations dma-debug: use pr_* instead of printk(KERN_* ...) dma-debug: code style fixes dma-debug: comment style fixes dma-debug: change hash_bucket_find from first-fit to best-fit x86: enable GART-IOMMU only after setting up protection methods amd_iommu: fix lock imbalance dma-debug: add documentation for the driver filter dma-debug: add dma_debug_driver kernel command line dma-debug: add debugfs file for driver filter dma-debug: add variables and checks for driver filter dma-debug: fix debug_dma_sync_sg_for_cpu and debug_dma_sync_sg_for_device dma-debug: use sg_dma_len accessor dma-debug: use sg_dma_address accessor instead of using dma_address directly amd-iommu: don't free dma adresses below 512MB with CONFIG_IOMMU_STRESS amd-iommu: don't preallocate page tables with CONFIG_IOMMU_STRESS ...
2 parents 7506360 + 92db1e6 commit 3f6280d

14 files changed

Lines changed: 1099 additions & 438 deletions

File tree

‎Documentation/DMA-API.txt‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,12 +704,24 @@ this directory the following files can currently be found:
704704
The current number of free dma_debug_entries
705705
in the allocator.
706706

707+
dma-api/driver-filter
708+
You can write a name of a driver into this file
709+
to limit the debug output to requests from that
710+
particular driver. Write an empty string to
711+
that file to disable the filter and see
712+
all errors again.
713+
707714
If you have this code compiled into your kernel it will be enabled by default.
708715
If you want to boot without the bookkeeping anyway you can provide
709716
'dma_debug=off' as a boot parameter. This will disable DMA-API debugging.
710717
Notice that you can not enable it again at runtime. You have to reboot to do
711718
so.
712719

720+
If you want to see debug messages only for a special device driver you can
721+
specify the dma_debug_driver=<drivername> parameter. This will enable the
722+
driver filter at boot time. The debug code will only print errors for that
723+
driver afterwards. This filter can be disabled or changed later using debugfs.
724+
713725
When the code disables itself at runtime this is most likely because it ran
714726
out of dma_debug_entries. These entries are preallocated at boot. The number
715727
of preallocated entries is defined per architecture. If it is too low for you

‎Documentation/kernel-parameters.txt‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,6 @@ and is between 256 and 4096 characters. It is defined in the file
329329
flushed before they will be reused, which
330330
is a lot of faster
331331

332-
amd_iommu_size= [HW,X86-64]
333-
Define the size of the aperture for the AMD IOMMU
334-
driver. Possible values are:
335-
'32M', '64M' (default), '128M', '256M', '512M', '1G'
336-
337332
amijoy.map= [HW,JOY] Amiga joystick support
338333
Map of devices attached to JOY0DAT and JOY1DAT
339334
Format: <a>,<b>
@@ -646,6 +641,13 @@ and is between 256 and 4096 characters. It is defined in the file
646641
DMA-API debugging code disables itself because the
647642
architectural default is too low.
648643

644+
dma_debug_driver=<driver_name>
645+
With this option the DMA-API debugging driver
646+
filter feature can be enabled at boot time. Just
647+
pass the driver to filter for as the parameter.
648+
The filter can be disabled or changed to another
649+
driver later using sysfs.
650+
649651
dscc4.setup= [NET]
650652

651653
dtc3181e= [HW,SCSI]

‎arch/x86/Kconfig.debug‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,17 @@ config IOMMU_DEBUG
159159
options. See Documentation/x86_64/boot-options.txt for more
160160
details.
161161

162+
config IOMMU_STRESS
163+
bool "Enable IOMMU stress-test mode"
164+
---help---
165+
This option disables various optimizations in IOMMU related
166+
code to do real stress testing of the IOMMU code. This option
167+
will cause a performance drop and should only be enabled for
168+
testing.
169+
162170
config IOMMU_LEAK
163171
bool "IOMMU leak tracing"
164-
depends on DEBUG_KERNEL
165-
depends on IOMMU_DEBUG
172+
depends on IOMMU_DEBUG && DMA_API_DEBUG
166173
---help---
167174
Add a simple leak tracer to the IOMMU code. This is useful when you
168175
are debugging a buggy device driver that leaks IOMMU mappings.

‎arch/x86/include/asm/amd_iommu.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ extern int amd_iommu_init(void);
2727
extern int amd_iommu_init_dma_ops(void);
2828
extern void amd_iommu_detect(void);
2929
extern irqreturn_t amd_iommu_int_handler(int irq, void *data);
30+
extern void amd_iommu_flush_all_domains(void);
31+
extern void amd_iommu_flush_all_devices(void);
3032
#else
3133
static inline int amd_iommu_init(void) { return -ENODEV; }
3234
static inline void amd_iommu_detect(void) { }

‎arch/x86/include/asm/amd_iommu_types.h‎

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,27 @@
194194
#define PD_DMA_OPS_MASK (1UL << 0) /* domain used for dma_ops */
195195
#define PD_DEFAULT_MASK (1UL << 1) /* domain is a default dma_ops
196196
domain for an IOMMU */
197+
extern bool amd_iommu_dump;
198+
#define DUMP_printk(format, arg...) \
199+
do { \
200+
if (amd_iommu_dump) \
201+
printk(KERN_INFO "AMD IOMMU: " format, ## arg); \
202+
} while(0);
203+
204+
/*
205+
* Make iterating over all IOMMUs easier
206+
*/
207+
#define for_each_iommu(iommu) \
208+
list_for_each_entry((iommu), &amd_iommu_list, list)
209+
#define for_each_iommu_safe(iommu, next) \
210+
list_for_each_entry_safe((iommu), (next), &amd_iommu_list, list)
211+
212+
#define APERTURE_RANGE_SHIFT 27 /* 128 MB */
213+
#define APERTURE_RANGE_SIZE (1ULL << APERTURE_RANGE_SHIFT)
214+
#define APERTURE_RANGE_PAGES (APERTURE_RANGE_SIZE >> PAGE_SHIFT)
215+
#define APERTURE_MAX_RANGES 32 /* allows 4GB of DMA address space */
216+
#define APERTURE_RANGE_INDEX(a) ((a) >> APERTURE_RANGE_SHIFT)
217+
#define APERTURE_PAGE_INDEX(a) (((a) >> 21) & 0x3fULL)
197218

198219
/*
199220
* This structure contains generic data for IOMMU protection domains
@@ -209,6 +230,26 @@ struct protection_domain {
209230
void *priv; /* private data */
210231
};
211232

233+
/*
234+
* For dynamic growth the aperture size is split into ranges of 128MB of
235+
* DMA address space each. This struct represents one such range.
236+
*/
237+
struct aperture_range {
238+
239+
/* address allocation bitmap */
240+
unsigned long *bitmap;
241+
242+
/*
243+
* Array of PTE pages for the aperture. In this array we save all the
244+
* leaf pages of the domain page table used for the aperture. This way
245+
* we don't need to walk the page table to find a specific PTE. We can
246+
* just calculate its address in constant time.
247+
*/
248+
u64 *pte_pages[64];
249+
250+
unsigned long offset;
251+
};
252+
212253
/*
213254
* Data container for a dma_ops specific protection domain
214255
*/
@@ -222,18 +263,10 @@ struct dma_ops_domain {
222263
unsigned long aperture_size;
223264

224265
/* address we start to search for free addresses */
225-
unsigned long next_bit;
226-
227-
/* address allocation bitmap */
228-
unsigned long *bitmap;
266+
unsigned long next_address;
229267

230-
/*
231-
* Array of PTE pages for the aperture. In this array we save all the
232-
* leaf pages of the domain page table used for the aperture. This way
233-
* we don't need to walk the page table to find a specific PTE. We can
234-
* just calculate its address in constant time.
235-
*/
236-
u64 **pte_pages;
268+
/* address space relevant data */
269+
struct aperture_range *aperture[APERTURE_MAX_RANGES];
237270

238271
/* This will be set to true when TLB needs to be flushed */
239272
bool need_flush;

0 commit comments

Comments
 (0)