From: provos Date: Sat, 18 Mar 2000 20:51:32 +0000 (+0000) Subject: postpone memory allocation for uvm swap encryption until it is turned on with X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=7e52177c186c219f7a603b84ce64a8c56ca7c803;p=openbsd postpone memory allocation for uvm swap encryption until it is turned on with sysctl. --- diff --git a/sys/uvm/uvm_meter.c b/sys/uvm/uvm_meter.c index 3c287ca34e5..da160cf64e3 100644 --- a/sys/uvm/uvm_meter.c +++ b/sys/uvm/uvm_meter.c @@ -49,6 +49,7 @@ #include #ifdef UVM_SWAP_ENCRYPT +#include #include #endif @@ -153,9 +154,23 @@ uvm_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p) return (sysctl_rdstruct(oldp, oldlenp, newp, &_ps, sizeof(_ps))); #ifdef UVM_SWAP_ENCRYPT - case VM_SWAPENCRYPT: - return (sysctl_int(oldp, oldlenp, newp, newlen, - &uvm_doswapencrypt)); + case VM_SWAPENCRYPT: { + int doencrypt = uvm_doswapencrypt; + int result; + + result = sysctl_int(oldp, oldlenp, newp, newlen, &doencrypt); + if (result) + return result; + + /* Swap Encryption has been turned on, we need to + * initalize state for swap devices that have been + * added + */ + if (doencrypt) + uvm_swap_initcrypt_all(); + uvm_doswapencrypt = doencrypt; + return (0); + } #endif default: return (EOPNOTSUPP); diff --git a/sys/uvm/uvm_swap.c b/sys/uvm/uvm_swap.c index 21f73ef23fe..c00ccc2db9a 100644 --- a/sys/uvm/uvm_swap.c +++ b/sys/uvm/uvm_swap.c @@ -282,6 +282,7 @@ boolean_t uvm_swap_allocpages __P((struct vm_page **, int)); void uvm_swap_freepages __P((struct vm_page **, int)); void uvm_swap_markdecrypt __P((struct swapdev *, int, int, int)); boolean_t uvm_swap_needdecrypt __P((struct swapdev *, int)); +void uvm_swap_initcrypt __P((struct swapdev *, int)); #endif /* @@ -358,6 +359,39 @@ uvm_swap_init() } #ifdef UVM_SWAP_ENCRYPT +void +uvm_swap_initcrypt_all(void) +{ + struct swapdev *sdp; + struct swappri *spp; + + simple_lock(&uvm.swap_data_lock); + + for (spp = swap_priority.lh_first; spp != NULL; + spp = spp->spi_swappri.le_next) { + for (sdp = spp->spi_swapdev.cqh_first; + sdp != (void *)&spp->spi_swapdev; + sdp = sdp->swd_next.cqe_next) + if (sdp->swd_decrypt == NULL) + uvm_swap_initcrypt(sdp, sdp->swd_npages); + } + simple_unlock(&uvm.swap_data_lock); +} + +void +uvm_swap_initcrypt(struct swapdev *sdp, int npages) +{ + /* + * keep information if a page needs to be decrypted when we get it + * from the swap device. + * We cannot chance a malloc later, if we are doing ASYNC puts, + * we may not call malloc with M_WAITOK. This consumes only + * 8KB memory for a 256MB swap partition. + */ + sdp->swd_decrypt = malloc(SWD_DCRYPT_SIZE(npages), M_VMSWAP, M_WAITOK); + bzero(sdp->swd_decrypt, SWD_DCRYPT_SIZE(npages)); +} + boolean_t uvm_swap_allocpages(struct vm_page **pps, int npages) { @@ -1109,15 +1143,8 @@ swap_on(p, sdp) } #ifdef UVM_SWAP_ENCRYPT - /* - * keep information if a page needs to be decrypted when we get it - * from the swap device. - * We cannot chance a malloc later, if we are doing ASYNC puts, - * we may not call malloc with M_WAITOK. This takes consumes only - * 8KB memory for a 256MB swap partition. - */ - sdp->swd_decrypt = malloc(SWD_DCRYPT_SIZE(npages), M_VMSWAP, M_WAITOK); - bzero(sdp->swd_decrypt, SWD_DCRYPT_SIZE(npages)); + if (uvm_doswapencrypt) + uvm_swap_initcrypt(sdp, npages); #endif /* * now add the new swapdev to the drum and enable. diff --git a/sys/uvm/uvm_swap.h b/sys/uvm/uvm_swap.h index 008db98b241..42a6f4aa4e6 100644 --- a/sys/uvm/uvm_swap.h +++ b/sys/uvm/uvm_swap.h @@ -39,4 +39,7 @@ int uvm_swap_put __P((int, struct vm_page **, int, int uvm_swap_alloc __P((int *wanted, boolean_t lessok)); void uvm_swap_free __P((int startslot, int nslots)); +#ifdef UVM_SWAP_ENCRYPT +void uvm_swap_initcrypt_all __P((void)); +#endif #endif /* _UVM_UVM_SWAP_H_ */