lib/tests/kunit_iov_iter.c
Source file repositories/reference/linux-study-clean/lib/tests/kunit_iov_iter.c
File Facts
- System
- Linux kernel
- Corpus path
lib/tests/kunit_iov_iter.c- Extension
.c- Size
- 31480 bytes
- Lines
- 1252
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: implementation source
- Status
- source implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/vmalloc.hlinux/mm.hlinux/uio.hlinux/bvec.hlinux/folio_queue.hlinux/scatterlist.hlinux/minmax.hlinux/mman.hkunit/test.h
Detected Declarations
struct kvec_test_rangestruct bvec_test_rangestruct iov_kunit_iter_to_sg_datafunction patternfunction iov_kunit_unmapfunction iov_kunit_create_bufferfunction iov_kunit_load_kvecfunction iov_kunit_copy_to_kvecfunction iov_kunit_copy_from_kvecfunction iov_kunit_load_bvecfunction iov_kunit_copy_to_bvecfunction iov_kunit_copy_from_bvecfunction iov_kunit_destroy_folioqfunction iov_kunit_load_folioqfunction iov_kunit_copy_to_folioqfunction iov_kunit_copy_from_folioqfunction iov_kunit_destroy_xarrayfunction iov_kunit_load_xarrayfunction iov_kunit_copy_to_xarrayfunction iov_kunit_copy_from_xarrayfunction iov_kunit_extract_pages_kvecfunction iov_kunit_extract_pages_bvecfunction iov_kunit_extract_pages_folioqfunction iov_kunit_extract_pages_xarrayfunction iov_kunit_iter_unpin_sgtfunction iov_kunit_iter_to_sg_initfunction iov_kunit_iter_to_sg_checkfunction iov_kunit_iter_to_sg_kvecfunction iov_kunit_iter_to_sg_bvecfunction iov_kunit_iter_to_sg_folioqfunction iov_kunit_iter_to_sg_xarrayfunction iov_kunit_iter_to_sg_ubuf
Annotated Snippet
struct kvec_test_range {
int from, to;
};
static const struct kvec_test_range kvec_test_ranges[] = {
{ 0x00002, 0x00002 },
{ 0x00027, 0x03000 },
{ 0x05193, 0x18794 },
{ 0x20000, 0x20000 },
{ 0x20000, 0x24000 },
{ 0x24000, 0x27001 },
{ 0x29000, 0xffffb },
{ 0xffffd, 0xffffe },
{ -1 }
};
static inline u8 pattern(unsigned long x)
{
return (u8)x + (u8)(x >> 8) + (u8)(x >> 16);
}
static void iov_kunit_unmap(void *data)
{
vfree(data);
}
static void *__init iov_kunit_create_buffer(struct kunit *test,
struct page ***ppages,
size_t npages)
{
struct page **pages;
unsigned long got, last;
void *buffer;
unsigned int i;
pages = kzalloc_objs(struct page *, npages, GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pages);
*ppages = pages;
got = 0;
while (true) {
last = got;
got = alloc_pages_bulk(GFP_KERNEL, npages, pages);
if (last == got || got == npages)
break;
}
if (got != npages) {
release_pages(pages, got);
kvfree(pages);
KUNIT_ASSERT_EQ(test, got, npages);
}
/* Make sure that we don't get a physically contiguous buffer. */
for (i = 0; i < npages / 4; ++i)
swap(pages[i], pages[i + npages / 2]);
buffer = vmap(pages, npages, VM_MAP | VM_MAP_PUT_PAGES, PAGE_KERNEL);
if (buffer == NULL) {
release_pages(pages, got);
kvfree(pages);
}
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buffer);
kunit_add_action_or_reset(test, iov_kunit_unmap, buffer);
return buffer;
}
static void __init iov_kunit_load_kvec(struct kunit *test,
struct iov_iter *iter, int dir,
struct kvec *kvec, unsigned int kvmax,
void *buffer, size_t bufsize,
const struct kvec_test_range *pr)
{
size_t size = 0;
int i;
for (i = 0; i < kvmax; i++, pr++) {
if (pr->from < 0)
break;
KUNIT_ASSERT_GE(test, pr->to, pr->from);
KUNIT_ASSERT_LE(test, pr->to, bufsize);
kvec[i].iov_base = buffer + pr->from;
kvec[i].iov_len = pr->to - pr->from;
size += pr->to - pr->from;
}
KUNIT_ASSERT_LE(test, size, bufsize);
iov_iter_kvec(iter, dir, kvec, i, size);
}
Annotation
- Immediate include surface: `linux/module.h`, `linux/vmalloc.h`, `linux/mm.h`, `linux/uio.h`, `linux/bvec.h`, `linux/folio_queue.h`, `linux/scatterlist.h`, `linux/minmax.h`.
- Detected declarations: `struct kvec_test_range`, `struct bvec_test_range`, `struct iov_kunit_iter_to_sg_data`, `function pattern`, `function iov_kunit_unmap`, `function iov_kunit_create_buffer`, `function iov_kunit_load_kvec`, `function iov_kunit_copy_to_kvec`, `function iov_kunit_copy_from_kvec`, `function iov_kunit_load_bvec`.
- Atlas domain: Kernel Services / lib.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.