summaryrefslogtreecommitdiff
path: root/sys/uvm
diff options
context:
space:
mode:
authorNiels Provos <provos@cvs.openbsd.org>2000-03-18 20:51:33 +0000
committerNiels Provos <provos@cvs.openbsd.org>2000-03-18 20:51:33 +0000
commit73822b33170c55f3895c839a96f283f51025560e (patch)
tree24f50553fb39536f3e774b100efb5d16ea35347a /sys/uvm
parente777b7cb9c0e2e41ed8dcb4b818e181f92df435a (diff)
postpone memory allocation for uvm swap encryption until it is turned on with
sysctl.
Diffstat (limited to 'sys/uvm')
-rw-r--r--sys/uvm/uvm_meter.c21
-rw-r--r--sys/uvm/uvm_swap.c45
-rw-r--r--sys/uvm/uvm_swap.h3
3 files changed, 57 insertions, 12 deletions
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 <sys/exec.h>
#ifdef UVM_SWAP_ENCRYPT
+#include <uvm/uvm_swap.h>
#include <uvm/uvm_swap_encrypt.h>
#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_ */