summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorotto <otto@openbsd.org>2018-12-16 08:33:16 +0000
committerotto <otto@openbsd.org>2018-12-16 08:33:16 +0000
commit6ab058fbe2fceafdb56e1cea089b1952bf618936 (patch)
tree7c67f25d752272e80e1e509f124ca4a8484bea04
parentMake the freelist best fit code a tiny bit smarter to not use a block if (diff)
downloadwireguard-openbsd-6ab058fbe2fceafdb56e1cea089b1952bf618936.tar.xz
wireguard-openbsd-6ab058fbe2fceafdb56e1cea089b1952bf618936.zip
Avoid using a too big bounce buffer by splitting up large reads. Allows
for booting using large (64k) blocksize filesystems. ok tedu@
-rw-r--r--sys/arch/amd64/stand/libsa/biosdev.c22
-rw-r--r--sys/arch/i386/stand/libsa/biosdev.c22
2 files changed, 36 insertions, 8 deletions
diff --git a/sys/arch/amd64/stand/libsa/biosdev.c b/sys/arch/amd64/stand/libsa/biosdev.c
index 4ca8436f32c..fdd1c90170a 100644
--- a/sys/arch/amd64/stand/libsa/biosdev.c
+++ b/sys/arch/amd64/stand/libsa/biosdev.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: biosdev.c,v 1.32 2018/08/10 16:41:35 jsing Exp $ */
+/* $OpenBSD: biosdev.c,v 1.33 2018/12/16 08:33:16 otto Exp $ */
/*
* Copyright (c) 1996 Michael Shalayeff
@@ -340,11 +340,26 @@ biosd_io(int rw, bios_diskinfo_t *bd, u_int off, int nsect, void *buf)
return error;
}
+#define MAXSECTS 32
+
int
biosd_diskio(int rw, struct diskinfo *dip, u_int off, int nsect, void *buf)
{
- return biosd_io(rw, &dip->bios_info, off, nsect, buf);
+ char *dest = buf;
+ int n, ret;
+
+ /*
+ * Avoid doing too large reads, the bounce buffer used by biosd_io()
+ * might run us out-of-mem.
+ */
+ for (ret = 0; ret == 0 && nsect > 0;
+ off += MAXSECTS, dest += MAXSECTS * DEV_BSIZE, nsect -= MAXSECTS) {
+ n = nsect >= MAXSECTS ? MAXSECTS : nsect;
+ ret = biosd_io(rw, &dip->bios_info, off, n, dest);
+ }
+ return ret;
}
+
/*
* Try to read the bsd label on the given BIOS device.
*/
@@ -715,7 +730,6 @@ biosstrategy(void *devdata, int rw, daddr32_t blk, size_t size, void *buf,
size_t *rsize)
{
struct diskinfo *dip = (struct diskinfo *)devdata;
- bios_diskinfo_t *bd = &dip->bios_info;
u_int8_t error = 0;
size_t nsect;
@@ -732,7 +746,7 @@ biosstrategy(void *devdata, int rw, daddr32_t blk, size_t size, void *buf,
if (blk < 0)
error = EINVAL;
else
- error = biosd_io(rw, bd, blk, nsect, buf);
+ error = biosd_diskio(rw, dip, blk, nsect, buf);
#ifdef BIOS_DEBUG
if (debug) {
diff --git a/sys/arch/i386/stand/libsa/biosdev.c b/sys/arch/i386/stand/libsa/biosdev.c
index 7baddd2f145..394fc6b061d 100644
--- a/sys/arch/i386/stand/libsa/biosdev.c
+++ b/sys/arch/i386/stand/libsa/biosdev.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: biosdev.c,v 1.98 2018/09/06 11:50:54 jsg Exp $ */
+/* $OpenBSD: biosdev.c,v 1.99 2018/12/16 08:33:16 otto Exp $ */
/*
* Copyright (c) 1996 Michael Shalayeff
@@ -341,11 +341,26 @@ biosd_io(int rw, bios_diskinfo_t *bd, u_int off, int nsect, void *buf)
return error;
}
+#define MAXSECTS 32
+
int
biosd_diskio(int rw, struct diskinfo *dip, u_int off, int nsect, void *buf)
{
- return biosd_io(rw, &dip->bios_info, off, nsect, buf);
+ char *dest = buf;
+ int n, ret;
+
+ /*
+ * Avoid doing too large reads, the bounce buffer used by biosd_io()
+ * might run us out-of-mem.
+ */
+ for (ret = 0; ret == 0 && nsect > 0;
+ off += MAXSECTS, dest += MAXSECTS * DEV_BSIZE, nsect -= MAXSECTS) {
+ n = nsect >= MAXSECTS ? MAXSECTS : nsect;
+ ret = biosd_io(rw, &dip->bios_info, off, n, dest);
+ }
+ return ret;
}
+
/*
* Try to read the bsd label on the given BIOS device.
*/
@@ -716,7 +731,6 @@ biosstrategy(void *devdata, int rw, daddr32_t blk, size_t size, void *buf,
size_t *rsize)
{
struct diskinfo *dip = (struct diskinfo *)devdata;
- bios_diskinfo_t *bd = &dip->bios_info;
u_int8_t error = 0;
size_t nsect;
@@ -733,7 +747,7 @@ biosstrategy(void *devdata, int rw, daddr32_t blk, size_t size, void *buf,
if (blk < 0)
error = EINVAL;
else
- error = biosd_io(rw, bd, blk, nsect, buf);
+ error = biosd_diskio(rw, dip, blk, nsect, buf);
#ifdef BIOS_DEBUG
if (debug) {