crypto/scompress.c
Source file repositories/reference/linux-study-clean/crypto/scompress.c
File Facts
- System
- Linux kernel
- Corpus path
crypto/scompress.c- Extension
.c- Size
- 9309 bytes
- Lines
- 403
- Domain
- Kernel Services
- Bucket
- crypto
- Inferred role
- Kernel Services: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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
crypto/internal/scompress.hcrypto/scatterwalk.hlinux/cpumask.hlinux/cryptouser.hlinux/err.hlinux/highmem.hlinux/kernel.hlinux/module.hlinux/overflow.hlinux/scatterlist.hlinux/seq_file.hlinux/slab.hlinux/string.hlinux/workqueue.hnet/netlink.hcompress.h
Detected Declarations
struct scomp_scratchfunction crypto_scomp_reportfunction crypto_scomp_showfunction crypto_scomp_free_scratchesfunction for_each_possible_cpufunction scomp_alloc_scratchfunction scomp_scratch_workfnfunction for_each_cpufunction crypto_scomp_alloc_scratchesfunction crypto_scomp_init_tfmfunction scomp_unlock_scratchfunction scomp_acomp_comp_decompfunction scomp_acomp_compressfunction scomp_acomp_decompressfunction crypto_exit_scomp_ops_asyncfunction crypto_init_scomp_ops_asyncfunction crypto_scomp_destroyfunction scomp_prepare_algfunction crypto_register_scompfunction crypto_unregister_scompfunction crypto_register_scompsfunction crypto_unregister_scompsexport crypto_register_scompexport crypto_unregister_scompexport crypto_register_scompsexport crypto_unregister_scomps
Annotated Snippet
struct scomp_scratch {
spinlock_t lock;
union {
void *src __guarded_by(&lock);
unsigned long saddr __guarded_by(&lock);
};
};
static DEFINE_PER_CPU(struct scomp_scratch, scomp_scratch) = {
.lock = __SPIN_LOCK_UNLOCKED(scomp_scratch.lock),
};
static const struct crypto_type crypto_scomp_type;
static DEFINE_MUTEX(scomp_lock);
static int scomp_scratch_users __guarded_by(&scomp_lock);
static cpumask_t scomp_scratch_want;
static void scomp_scratch_workfn(struct work_struct *work);
static DECLARE_WORK(scomp_scratch_work, scomp_scratch_workfn);
static int __maybe_unused crypto_scomp_report(
struct sk_buff *skb, struct crypto_alg *alg)
{
struct crypto_report_comp rscomp = {
.type = "scomp",
};
return nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
sizeof(rscomp), &rscomp);
}
static void __maybe_unused crypto_scomp_show(struct seq_file *m,
struct crypto_alg *alg)
{
seq_puts(m, "type : scomp\n");
}
static void crypto_scomp_free_scratches(void)
__context_unsafe(/* frees @scratch */)
{
struct scomp_scratch *scratch;
int i;
for_each_possible_cpu(i) {
scratch = per_cpu_ptr(&scomp_scratch, i);
free_page(scratch->saddr);
scratch->src = NULL;
}
}
static int scomp_alloc_scratch(struct scomp_scratch *scratch, int cpu)
{
int node = cpu_to_node(cpu);
struct page *page;
page = alloc_pages_node(node, GFP_KERNEL, 0);
if (!page)
return -ENOMEM;
spin_lock_bh(&scratch->lock);
scratch->src = page_address(page);
spin_unlock_bh(&scratch->lock);
return 0;
}
static void scomp_scratch_workfn(struct work_struct *work)
{
int cpu;
for_each_cpu(cpu, &scomp_scratch_want) {
struct scomp_scratch *scratch;
scratch = per_cpu_ptr(&scomp_scratch, cpu);
if (context_unsafe(scratch->src))
continue;
if (scomp_alloc_scratch(scratch, cpu))
break;
cpumask_clear_cpu(cpu, &scomp_scratch_want);
}
}
static int crypto_scomp_alloc_scratches(void)
__context_unsafe(/* allocates @scratch */)
{
unsigned int i = cpumask_first(cpu_possible_mask);
struct scomp_scratch *scratch;
scratch = per_cpu_ptr(&scomp_scratch, i);
return scomp_alloc_scratch(scratch, i);
Annotation
- Immediate include surface: `crypto/internal/scompress.h`, `crypto/scatterwalk.h`, `linux/cpumask.h`, `linux/cryptouser.h`, `linux/err.h`, `linux/highmem.h`, `linux/kernel.h`, `linux/module.h`.
- Detected declarations: `struct scomp_scratch`, `function crypto_scomp_report`, `function crypto_scomp_show`, `function crypto_scomp_free_scratches`, `function for_each_possible_cpu`, `function scomp_alloc_scratch`, `function scomp_scratch_workfn`, `function for_each_cpu`, `function crypto_scomp_alloc_scratches`, `function crypto_scomp_init_tfm`.
- Atlas domain: Kernel Services / crypto.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.