#include <sys/exec.h>
#ifdef UVM_SWAP_ENCRYPT
+#include <uvm/uvm_swap.h>
#include <uvm/uvm_swap_encrypt.h>
#endif
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);
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
/*
}
#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)
{
}
#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.