/* * HIGHMEM case: the page may have to be mapped into memory. To avoid * the complexity of having to map multiple pages at once per sg entry, * clamp the returned length to not cross a page boundary. * * !HIGHMEM case: no mapping is needed; all pages of the sg entry are * already mapped contiguously in the kernel's direct map. For improved * performance, allow the walker to return data segments that cross a * page boundary. Do still cap the length to PAGE_SIZE, since some * users rely on that to avoid disabling preemption for too long when * using SIMD. It's also needed for when skcipher_walk uses a bounce * page due to the data not being aligned to the algorithm's alignmask.
*/ if (IS_ENABLED(CONFIG_HIGHMEM))
limit = PAGE_SIZE - offset_in_page(walk->offset); else
limit = PAGE_SIZE;
return min3(nbytes, len_this_sg, limit);
}
/* * Create a scatterlist that represents the remaining data in a walk. Uses * chaining to reference the original scatterlist, so this uses at most two * entries in @sg_out regardless of the number of entries in the original list. * Assumes that sg_init_table() was already done.
*/ staticinlinevoid scatterwalk_get_sglist(struct scatter_walk *walk, struct scatterlist sg_out[2])
{ if (walk->offset >= walk->sg->offset + walk->sg->length)
scatterwalk_start(walk, sg_next(walk->sg));
sg_set_page(sg_out, sg_page(walk->sg),
walk->sg->offset + walk->sg->length - walk->offset,
walk->offset);
scatterwalk_crypto_chain(sg_out, sg_next(walk->sg), 2);
}
if (IS_ENABLED(CONFIG_HIGHMEM)) { struct page *page;
page = nth_page(base_page, offset >> PAGE_SHIFT);
offset = offset_in_page(offset);
addr = kmap_local_page(page) + offset;
} else { /* * When !HIGHMEM we allow the walker to return segments that * span a page boundary; see scatterwalk_clamp(). To make it * clear that in this case we're working in the linear buffer of * the whole sg entry in the kernel's direct map rather than * within the mapped buffer of a single page, compute the * address as an offset from the page_address() of the first * page of the sg entry. Either way the result is the address * in the direct map, but this makes it clearer what is really * going on.
*/
addr = page_address(base_page) + offset;
}
walk->__addr = addr;
}
/** * scatterwalk_next() - Get the next data buffer in a scatterlist walk * @walk: the scatter_walk * @total: the total number of bytes remaining, > 0 * * A virtual address for the next segment of data from the scatterlist will * be placed into @walk->addr. The caller must call scatterwalk_done_src() * or scatterwalk_done_dst() when it is done using this virtual address. * * Returns: the next number of bytes available, <= @total
*/ staticinlineunsignedint scatterwalk_next(struct scatter_walk *walk, unsignedint total)
{ unsignedint nbytes = scatterwalk_clamp(walk, total);
scatterwalk_map(walk); return nbytes;
}
staticinlinevoid scatterwalk_unmap(struct scatter_walk *walk)
{ if (IS_ENABLED(CONFIG_HIGHMEM))
kunmap_local(walk->__addr);
}
/** * scatterwalk_done_src() - Finish one step of a walk of source scatterlist * @walk: the scatter_walk * @nbytes: the number of bytes processed this step, less than or equal to the * number of bytes that scatterwalk_next() returned. * * Use this if the mapped address was not written to, i.e. it is source data.
*/ staticinlinevoid scatterwalk_done_src(struct scatter_walk *walk, unsignedint nbytes)
{
scatterwalk_unmap(walk);
scatterwalk_advance(walk, nbytes);
}
/** * scatterwalk_done_dst() - Finish one step of a walk of destination scatterlist * @walk: the scatter_walk * @nbytes: the number of bytes processed this step, less than or equal to the * number of bytes that scatterwalk_next() returned. * * Use this if the mapped address may have been written to, i.e. it is * destination data.
*/ staticinlinevoid scatterwalk_done_dst(struct scatter_walk *walk, unsignedint nbytes)
{
scatterwalk_unmap(walk); /* * Explicitly check ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE instead of just * relying on flush_dcache_page() being a no-op when not implemented, * since otherwise the BUG_ON in sg_page() does not get optimized out. * This also avoids having to consider whether the loop would get * reliably optimized out or not.
*/ if (ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE) { struct page *base_page; unsignedint offset; int start, end, i;
base_page = sg_page(walk->sg);
offset = walk->offset;
start = offset >> PAGE_SHIFT;
end = start + (nbytes >> PAGE_SHIFT);
end += (offset_in_page(offset) + offset_in_page(nbytes) +
PAGE_SIZE - 1) >> PAGE_SHIFT; for (i = start; i < end; i++)
flush_dcache_page(nth_page(base_page, i));
}
scatterwalk_advance(walk, nbytes);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.