summaryrefslogtreecommitdiff
path: root/fs/xfs/kmem.h
diff options
context:
space:
mode:
authorDave Chinner <dchinner@redhat.com>2019-08-26 22:08:39 +0300
committerDarrick J. Wong <darrick.wong@oracle.com>2019-08-27 03:43:15 +0300
commitf8f9ee479439c1be9e33c4404912a2a112c46200 (patch)
tree8ab704388f69cc4a45c882636a5c39848c31d7e2 /fs/xfs/kmem.h
parentd916275aa4ddfea69b5480e292f398d58bdb40fc (diff)
downloadlinux-f8f9ee479439c1be9e33c4404912a2a112c46200.tar.xz
xfs: add kmem_alloc_io()
Memory we use to submit for IO needs strict alignment to the underlying driver contraints. Worst case, this is 512 bytes. Given that all allocations for IO are always a power of 2 multiple of 512 bytes, the kernel heap provides natural alignment for objects of these sizes and that suffices. Until, of course, memory debugging of some kind is turned on (e.g. red zones, poisoning, KASAN) and then the alignment of the heap objects is thrown out the window. Then we get weird IO errors and data corruption problems because drivers don't validate alignment and do the wrong thing when passed unaligned memory buffers in bios. TO fix this, introduce kmem_alloc_io(), which will guaranteeat least 512 byte alignment of buffers for IO, even if memory debugging options are turned on. It is assumed that the minimum allocation size will be 512 bytes, and that sizes will be power of 2 mulitples of 512 bytes. Use this everywhere we allocate buffers for IO. This no longer fails with log recovery errors when KASAN is enabled due to the brd driver not handling unaligned memory buffers: # mkfs.xfs -f /dev/ram0 ; mount /dev/ram0 /mnt/test Signed-off-by: Dave Chinner <dchinner@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Diffstat (limited to 'fs/xfs/kmem.h')
-rw-r--r--fs/xfs/kmem.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/fs/xfs/kmem.h b/fs/xfs/kmem.h
index cb6fa7984ffa..8170d95cf930 100644
--- a/fs/xfs/kmem.h
+++ b/fs/xfs/kmem.h
@@ -53,6 +53,7 @@ kmem_flags_convert(xfs_km_flags_t flags)
}
extern void *kmem_alloc(size_t, xfs_km_flags_t);
+extern void *kmem_alloc_io(size_t size, int align_mask, xfs_km_flags_t flags);
extern void *kmem_alloc_large(size_t size, xfs_km_flags_t);
extern void *kmem_realloc(const void *, size_t, xfs_km_flags_t);
static inline void kmem_free(const void *ptr)