android_kernel_xiaomi_sm8350/drivers
Keshavamurthy, Anil S eb3fa7cb51 Intel IOMMU: Avoid memory allocation failures in dma map api calls
Intel IOMMU driver needs memory during DMA map calls to setup its internal
page tables and for other data structures.  As we all know that these DMA map
calls are mostly called in the interrupt context or with the spinlock held by
the upper level drivers(network/storage drivers), so in order to avoid any
memory allocation failure due to low memory issues, this patch makes memory
allocation by temporarily setting PF_MEMALLOC flags for the current task
before making memory allocation calls.

We evaluated mempools as a backup when kmem_cache_alloc() fails
and found that mempools are really not useful here because
 1) We don't know for sure how much to reserve in advance
 2) And mempools are not useful for GFP_ATOMIC case (as we call
    memory alloc functions with GFP_ATOMIC)

(akpm: point 2 is wrong...)

With PF_MEMALLOC flag set in the current->flags, the VM subsystem avoids any
watermark checks before allocating memory thus guarantee'ing the memory till
the last free page.  Further, looking at the code in mm/page_alloc.c in
__alloc_pages() function, looks like this flag is useful only in the
non-interrupt context.

If we are in the interrupt context and memory allocation in IOMMU driver fails
for some reason, then the DMA map api's will return failure and it is up to
the higher level drivers to retry.  Suppose, if upper level driver programs
the controller with the buggy DMA virtual address, the IOMMU will block that
DMA transaction when that happens thus preventing any corruption to main
memory.

So far in our test scenario, we were unable to create any memory allocation
failure inside dma map api calls.

Signed-off-by: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
Cc: Andi Kleen <ak@suse.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Muli Ben-Yehuda <muli@il.ibm.com>
Cc: "Siddha, Suresh B" <suresh.b.siddha@intel.com>
Cc: Arjan van de Ven <arjan@infradead.org>
Cc: Ashok Raj <ashok.raj@intel.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Christoph Lameter <clameter@sgi.com>
Cc: Greg KH <greg@kroah.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-10-22 08:13:18 -07:00
..
acorn/char
acpi Merge git://git.kernel.org/pub/scm/linux/kernel/git/bunk/trivial 2007-10-19 20:36:17 -07:00
amba
ata Merge git://git.kernel.org/pub/scm/linux/kernel/git/bunk/trivial 2007-10-19 20:36:17 -07:00
atm Fix misspellings of "system", "controller", "interrupt" and "necessary". 2007-10-19 23:10:43 +02:00
auxdisplay
base memory hotplug: rearrange memory hotplug notifier 2007-10-22 08:13:17 -07:00
block remove unused return within void return function 2007-10-20 02:18:21 +02:00
bluetooth
cdrom Use helpers to obtain task pid in printks 2007-10-19 11:53:43 -07:00
char Documentation: Remove references to dead "cyclades=" boot option 2007-10-20 00:01:12 +02:00
clocksource
connector
cpufreq
cpuidle
crypto
dca
dio
dma I/OAT: Add completion callback for async_tx interface use 2007-10-18 14:37:32 -07:00
edac NULL terminate the pci_device_ids in pasemi_edac 2007-10-19 11:53:56 -07:00
eisa
fc4
firewire fix typo "insted" -> "instead" 2007-10-20 01:55:04 +02:00
firmware define global BIT macro 2007-10-19 11:53:42 -07:00
hid changed email 2007-10-20 00:47:32 +02:00
hwmon Merge git://git.kernel.org/pub/scm/linux/kernel/git/bunk/trivial 2007-10-19 20:36:17 -07:00
i2c typo fixes 2007-10-20 01:34:40 +02:00
ide Merge git://git.kernel.org/pub/scm/linux/kernel/git/bunk/trivial 2007-10-19 20:36:17 -07:00
ieee1394
infiniband [INET]: Justification for local port range robustness. 2007-10-18 22:00:17 -07:00
input Merge git://git.kernel.org/pub/scm/linux/kernel/git/bunk/trivial 2007-10-19 20:36:17 -07:00
isdn Spelling fix: explicitly 2007-10-19 23:22:55 +02:00
kvm
leds fix typo "sort" -> "short" 2007-10-20 01:55:58 +02:00
lguest
macintosh Merge git://git.kernel.org/pub/scm/linux/kernel/git/bunk/trivial 2007-10-19 20:36:17 -07:00
mca
md Merge git://git.kernel.org/pub/scm/linux/kernel/git/bunk/trivial 2007-10-19 20:36:17 -07:00
media more UTF-8 conversions 2007-10-19 23:22:11 +02:00
message Convert files to UTF-8 and some cleanups 2007-10-19 23:21:04 +02:00
mfd typo fixes 2007-10-20 01:34:40 +02:00
misc typo fixes 2007-10-20 01:34:40 +02:00
mmc
mtd typo fixes 2007-10-20 01:34:40 +02:00
net Merge git://git.kernel.org/pub/scm/linux/kernel/git/bunk/trivial 2007-10-19 20:36:17 -07:00
nubus
of
oprofile
parisc
parport
pci Intel IOMMU: Avoid memory allocation failures in dma map api calls 2007-10-22 08:13:18 -07:00
pcmcia remove asm/bitops.h includes 2007-10-19 11:53:41 -07:00
pnp
power Add missing newlines to some uses of dev_<level> messages 2007-10-18 14:37:28 -07:00
ps3 remove asm/bitops.h includes 2007-10-19 11:53:41 -07:00
rapidio
rtc typo fixes 2007-10-20 01:34:40 +02:00
s390 Merge git://git.kernel.org/pub/scm/linux/kernel/git/bunk/trivial 2007-10-19 20:36:17 -07:00
sbus vfc_dev conversion to mutex: fallout 2007-10-20 15:04:06 -07:00
scsi Spelling fix: explicitly 2007-10-19 23:22:55 +02:00
serial Blackfin serial driver Kconfig: depend on DMA not being enabled rather than a specific DMA size 2007-10-21 22:30:01 +08:00
sh
sn
spi Fix misspellings of "system", "controller", "interrupt" and "necessary". 2007-10-19 23:10:43 +02:00
ssb
tc
telephony
uio
usb typo fixes 2007-10-20 01:34:40 +02:00
video Merge git://git.kernel.org/pub/scm/linux/kernel/git/bunk/trivial 2007-10-19 20:36:17 -07:00
w1 Add missing newlines to some uses of dev_<level> messages 2007-10-18 14:37:28 -07:00
watchdog Convert files to UTF-8 and some cleanups 2007-10-19 23:21:04 +02:00
xen Add missing newlines to some uses of dev_<level> messages 2007-10-18 14:37:28 -07:00
zorro Convert files to UTF-8 and some cleanups 2007-10-19 23:21:04 +02:00
Kconfig
Makefile Merge branch 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux-acpi-2.6 2007-10-19 13:12:46 -07:00