Source-Changes-D archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: CVS commit: src/sys/dev
Hi!
I've made a draft patch to support dumping against > 2Gi blocks
for backends like nvme(4) or virtio(4).
Does it look reasonable to you?
Thanks,
rin
On 2025/04/12 16:30, Michael van Elst wrote:
Module Name: src
Committed By: mlelstv
Date: Sat Apr 12 07:30:01 UTC 2025
Modified Files:
src/sys/dev: ld.c
Log Message:
ld sc_dump backend takes an 'int' as disk address, fail when the
disk address is outside the possible range of an int.
To generate a diff of this commit:
cvs rdiff -u -r1.114 -r1.115 src/sys/dev/ld.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/ld.c
diff -u src/sys/dev/ld.c:1.114 src/sys/dev/ld.c:1.115
--- src/sys/dev/ld.c:1.114 Wed Mar 5 00:41:17 2025
+++ src/sys/dev/ld.c Sat Apr 12 07:30:01 2025
@@ -1,4 +1,4 @@
-/* $NetBSD: ld.c,v 1.114 2025/03/05 00:41:17 jakllsch Exp $ */
+/* $NetBSD: ld.c,v 1.115 2025/04/12 07:30:01 mlelstv Exp $ */
/*-
* Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ld.c,v 1.114 2025/03/05 00:41:17 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ld.c,v 1.115 2025/04/12 07:30:01 mlelstv Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -603,6 +603,12 @@ ld_dumpblocks(device_t dev, void *va, da
if (sc->sc_dump == NULL)
return (ENODEV);
+ /*
+ * sc_dump takes only an 'int' as a disk address
+ */
+ if (blkno < 0 || blkno + nblk - 1 > INT_MAX)
+ return (EIO);
+
return (*sc->sc_dump)(sc, va, blkno, nblk);
}
From 853041872113cb0ce7b8676b0e080f19948ec125 Mon Sep 17 00:00:00 2001
From: Rin Okuyama <rokuyama.rk%gmail.com@localhost>
Date: Sat, 12 Apr 2025 17:55:12 +0900
Subject: [PATCH] ld(4): Convert blkno argument for sc_dump() to daddr_t
Introduce LDF_BLOCK32 sc_flags to indicate the backend only support
32-bit block address at the same time.
Now, it should be possible to dump against > 2Gi blocks for backends
without LDF_BLOCK32 flag bit.
Compile-test only (for amd64/ALL).
---
sys/arch/usermode/dev/ld_thunkbus.c | 4 ++--
sys/dev/ata/ld_ataraid.c | 5 ++---
sys/dev/i2o/ld_iop.c | 4 ++--
sys/dev/ic/ld_aac.c | 4 ++--
sys/dev/ic/ld_cac.c | 6 +++---
sys/dev/ic/ld_icp.c | 5 +++--
sys/dev/ic/ld_mlx.c | 5 +++--
sys/dev/ic/ld_nvme.c | 4 ++--
sys/dev/ld.c | 6 ++++--
sys/dev/ldvar.h | 3 ++-
sys/dev/pci/ld_amr.c | 5 +++--
sys/dev/pci/ld_twa.c | 4 ++--
sys/dev/pci/ld_twe.c | 6 +++---
sys/dev/pci/ld_virtio.c | 6 +++---
sys/dev/sdmmc/ld_sdmmc.c | 6 +++---
15 files changed, 39 insertions(+), 34 deletions(-)
diff --git a/sys/arch/usermode/dev/ld_thunkbus.c b/sys/arch/usermode/dev/ld_thunkbus.c
index f1d366b2e1e..2509b0d0d39 100644
--- a/sys/arch/usermode/dev/ld_thunkbus.c
+++ b/sys/arch/usermode/dev/ld_thunkbus.c
@@ -48,7 +48,7 @@ static int ld_thunkbus_match(device_t, cfdata_t, void *);
static void ld_thunkbus_attach(device_t, device_t, void *);
static int ld_thunkbus_ldstart(struct ld_softc *, struct buf *);
-static int ld_thunkbus_lddump(struct ld_softc *, void *, int, int);
+static int ld_thunkbus_lddump(struct ld_softc *, void *, daddr_t, int);
static int ld_thunkbus_ioctl(struct ld_softc *, u_long, void *, int32_t, bool);
//#define LD_USE_AIO
@@ -304,7 +304,7 @@ ld_thunkbus_complete(void *arg)
static int
-ld_thunkbus_lddump(struct ld_softc *ld, void *data, int blkno, int blkcnt)
+ld_thunkbus_lddump(struct ld_softc *ld, void *data, daddr_t blkno, int blkcnt)
{
struct ld_thunkbus_softc *sc = (struct ld_thunkbus_softc *)ld;
ssize_t len;
diff --git a/sys/dev/ata/ld_ataraid.c b/sys/dev/ata/ld_ataraid.c
index 6c2e95e02dc..07003469380 100644
--- a/sys/dev/ata/ld_ataraid.c
+++ b/sys/dev/ata/ld_ataraid.c
@@ -101,7 +101,7 @@ struct ld_ataraid_softc {
static int ld_ataraid_match(device_t, cfdata_t, void *);
static void ld_ataraid_attach(device_t, device_t, void *);
-static int ld_ataraid_dump(struct ld_softc *, void *, int, int);
+static int ld_ataraid_dump(struct ld_softc *, void *, daddr_t, int);
static int ld_ataraid_ioctl(struct ld_softc *, u_long, void *, int32_t,
bool);
@@ -581,8 +581,7 @@ out:
}
static int
-ld_ataraid_dump(struct ld_softc *sc, void *data,
- int blkno, int blkcnt)
+ld_ataraid_dump(struct ld_softc *sc, void *data, daddr_t blkno, int blkcnt)
{
return (EIO);
diff --git a/sys/dev/i2o/ld_iop.c b/sys/dev/i2o/ld_iop.c
index fd8259cd801..d577f6a48da 100644
--- a/sys/dev/i2o/ld_iop.c
+++ b/sys/dev/i2o/ld_iop.c
@@ -72,7 +72,7 @@ struct ld_iop_softc {
static void ld_iop_adjqparam(device_t, int);
static void ld_iop_attach(device_t, device_t, void *);
static int ld_iop_detach(device_t, int);
-static int ld_iop_dump(struct ld_softc *, void *, int, int);
+static int ld_iop_dump(struct ld_softc *, void *, daddr_t, int);
static int ld_iop_flush(struct ld_softc *, bool);
static int ld_iop_ioctl(struct ld_softc *, u_long, void *, int32_t, bool);
static void ld_iop_intr(device_t, struct iop_msg *, void *);
@@ -401,7 +401,7 @@ ld_iop_start(struct ld_softc *ld, struct buf *bp)
}
static int
-ld_iop_dump(struct ld_softc *ld, void *data, int blkno, int blkcnt)
+ld_iop_dump(struct ld_softc *ld, void *data, daddr_t blkno, int blkcnt)
{
struct iop_msg *im;
struct iop_softc *iop;
diff --git a/sys/dev/ic/ld_aac.c b/sys/dev/ic/ld_aac.c
index 863960df90b..10ea0382831 100644
--- a/sys/dev/ic/ld_aac.c
+++ b/sys/dev/ic/ld_aac.c
@@ -61,7 +61,7 @@ static void ld_aac_attach(device_t, device_t, void *);
static void ld_aac_intr(struct aac_ccb *);
static int ld_aac_dobio(struct ld_aac_softc *, void *, int, daddr_t, int,
struct buf *);
-static int ld_aac_dump(struct ld_softc *, void *, int, int);
+static int ld_aac_dump(struct ld_softc *, void *, daddr_t, int);
static int ld_aac_match(device_t, cfdata_t, void *);
static int ld_aac_start(struct ld_softc *, struct buf *);
@@ -357,7 +357,7 @@ ld_aac_intr(struct aac_ccb *ac)
}
static int
-ld_aac_dump(struct ld_softc *ld, void *data, int blkno, int blkcnt)
+ld_aac_dump(struct ld_softc *ld, void *data, daddr_t blkno, int blkcnt)
{
return (ld_aac_dobio((struct ld_aac_softc *)ld, data,
diff --git a/sys/dev/ic/ld_cac.c b/sys/dev/ic/ld_cac.c
index afe672e8ebe..1d819c3d27a 100644
--- a/sys/dev/ic/ld_cac.c
+++ b/sys/dev/ic/ld_cac.c
@@ -65,7 +65,7 @@ struct ld_cac_softc {
void ld_cac_attach(device_t, device_t, void *);
void ld_cac_done(device_t, void *, int);
-int ld_cac_dump(struct ld_softc *, void *, int, int);
+int ld_cac_dump(struct ld_softc *, void *, daddr_t, int);
int ld_cac_match(device_t, cfdata_t, void *);
int ld_cac_start(struct ld_softc *, struct buf *);
@@ -131,7 +131,7 @@ ld_cac_attach(device_t parent, device_t self, void *aux)
aprint_normal(": %s array\n", type);
/* XXX We should verify this... */
- ld->sc_flags = LDF_ENABLED | LDF_MPSAFE;
+ ld->sc_flags = LDF_ENABLED | LDF_MPSAFE | LDF_BLOCK32;
ldattach(ld, BUFQ_DISK_DEFAULT_STRAT);
}
@@ -163,7 +163,7 @@ ld_cac_start(struct ld_softc *ld, struct buf *bp)
}
int
-ld_cac_dump(struct ld_softc *ld, void *data, int blkno, int blkcnt)
+ld_cac_dump(struct ld_softc *ld, void *data, daddr_t blkno, int blkcnt)
{
struct ld_cac_softc *sc;
diff --git a/sys/dev/ic/ld_icp.c b/sys/dev/ic/ld_icp.c
index b6fed708692..42aac57c40f 100644
--- a/sys/dev/ic/ld_icp.c
+++ b/sys/dev/ic/ld_icp.c
@@ -64,7 +64,7 @@ static void ld_icp_attach(device_t, device_t, void *);
static int ld_icp_detach(device_t, int);
static int ld_icp_dobio(struct ld_icp_softc *, void *, int, int, int,
struct buf *);
-static int ld_icp_dump(struct ld_softc *, void *, int, int);
+static int ld_icp_dump(struct ld_softc *, void *, daddr_t, int);
static int ld_icp_flush(struct ld_softc *, bool);
static int ld_icp_ioctl(struct ld_softc *, u_long, void *, int32_t, bool);
static void ld_icp_intr(struct icp_ccb *);
@@ -161,6 +161,7 @@ ld_icp_attach(device_t parent, device_t self, void *aux)
aprint_normal("status: %s\n", str);
out:
+ ld->sc_flags |= LDF_BLOCK32;
ldattach(ld, BUFQ_DISK_DEFAULT_STRAT);
}
@@ -249,7 +250,7 @@ ld_icp_start(struct ld_softc *ld, struct buf *bp)
}
static int
-ld_icp_dump(struct ld_softc *ld, void *data, int blkno, int blkcnt)
+ld_icp_dump(struct ld_softc *ld, void *data, daddr_t blkno, int blkcnt)
{
return (ld_icp_dobio((struct ld_icp_softc *)ld, data,
diff --git a/sys/dev/ic/ld_mlx.c b/sys/dev/ic/ld_mlx.c
index 302141444c5..dab60d7647b 100644
--- a/sys/dev/ic/ld_mlx.c
+++ b/sys/dev/ic/ld_mlx.c
@@ -66,7 +66,7 @@ static void ld_mlx_attach(device_t, device_t, void *);
static int ld_mlx_detach(device_t, int);
static int ld_mlx_dobio(struct ld_mlx_softc *, void *, int, int, int,
struct buf *);
-static int ld_mlx_dump(struct ld_softc *, void *, int, int);
+static int ld_mlx_dump(struct ld_softc *, void *, daddr_t, int);
static void ld_mlx_handler(struct mlx_ccb *);
static int ld_mlx_match(device_t, cfdata_t, void *);
static int ld_mlx_start(struct ld_softc *, struct buf *);
@@ -123,6 +123,7 @@ ld_mlx_attach(device_t parent, device_t self, void *aux)
statestr = "state unknown";
break;
}
+ ld->sc_flags |= LDF_BLOCK32;
if (ms->ms_raidlevel == MLX_SYS_DRV_JBOD)
aprint_normal(": JBOD, %s\n", statestr);
@@ -244,7 +245,7 @@ ld_mlx_handler(struct mlx_ccb *mc)
}
static int
-ld_mlx_dump(struct ld_softc *ld, void *data, int blkno, int blkcnt)
+ld_mlx_dump(struct ld_softc *ld, void *data, daddr_t blkno, int blkcnt)
{
return (ld_mlx_dobio((struct ld_mlx_softc *)ld, data,
diff --git a/sys/dev/ic/ld_nvme.c b/sys/dev/ic/ld_nvme.c
index c02b2ffac92..1ee1d41f244 100644
--- a/sys/dev/ic/ld_nvme.c
+++ b/sys/dev/ic/ld_nvme.c
@@ -59,7 +59,7 @@ CFATTACH_DECL_NEW(ld_nvme, sizeof(struct ld_nvme_softc),
ld_nvme_match, ld_nvme_attach, ld_nvme_detach, NULL);
static int ld_nvme_start(struct ld_softc *, struct buf *);
-static int ld_nvme_dump(struct ld_softc *, void *, int, int);
+static int ld_nvme_dump(struct ld_softc *, void *, daddr_t, int);
static int ld_nvme_flush(struct ld_softc *, bool);
static int ld_nvme_getcache(struct ld_softc *, int *);
static int ld_nvme_ioctl(struct ld_softc *, u_long, void *, int32_t, bool);
@@ -147,7 +147,7 @@ ld_nvme_start(struct ld_softc *ld, struct buf *bp)
}
static int
-ld_nvme_dump(struct ld_softc *ld, void *data, int blkno, int blkcnt)
+ld_nvme_dump(struct ld_softc *ld, void *data, daddr_t blkno, int blkcnt)
{
struct ld_nvme_softc *sc = device_private(ld->sc_dv);
diff --git a/sys/dev/ld.c b/sys/dev/ld.c
index 31fd854e0b1..c35c457b4f7 100644
--- a/sys/dev/ld.c
+++ b/sys/dev/ld.c
@@ -604,9 +604,11 @@ ld_dumpblocks(device_t dev, void *va, daddr_t blkno, int nblk)
return (ENODEV);
/*
- * sc_dump takes only an 'int' as a disk address
+ * Minimum consistency check; sc_dump() should check
+ * device-dependent constraints if necessary.
*/
- if (blkno < 0 || blkno + nblk - 1 > INT_MAX)
+ if (blkno < 0 ||
+ ((sc->sc_flags & LDF_BLOCK32) != 0 && blkno + nblk > UINT32_MAX))
return (EIO);
return (*sc->sc_dump)(sc, va, blkno, nblk);
diff --git a/sys/dev/ldvar.h b/sys/dev/ldvar.h
index d5275d3d7be..609f281917f 100644
--- a/sys/dev/ldvar.h
+++ b/sys/dev/ldvar.h
@@ -61,7 +61,7 @@ struct ld_softc {
int sc_maxqueuecnt; /* maximum h/w queue depth */
char *sc_typename; /* inquiry data */
- int (*sc_dump)(struct ld_softc *, void *, int, int);
+ int (*sc_dump)(struct ld_softc *, void *, daddr_t, int);
int (*sc_ioctl)(struct ld_softc *, u_long, void *, int32_t, bool);
int (*sc_start)(struct ld_softc *, struct buf *);
int (*sc_discard)(struct ld_softc *, struct buf *);
@@ -73,6 +73,7 @@ struct ld_softc {
#define LDF_NO_RND 0x040 /* do not attach rnd source */
#define LDF_MPSAFE 0x080 /* backend is MPSAFE */
#define LDF_SUSPEND 0x100 /* disk is suspended until resume */
+#define LDF_BLOCK32 0x200 /* 32-bit block addressing */
int ldadjqparam(struct ld_softc *, int);
void ldattach(struct ld_softc *, const char *);
diff --git a/sys/dev/pci/ld_amr.c b/sys/dev/pci/ld_amr.c
index e6694739ed8..4183eeb248c 100644
--- a/sys/dev/pci/ld_amr.c
+++ b/sys/dev/pci/ld_amr.c
@@ -65,7 +65,7 @@ struct ld_amr_softc {
static int ld_amr_dobio(struct ld_amr_softc *, void *, int, int, int,
struct buf *);
-static int ld_amr_dump(struct ld_softc *, void *, int, int);
+static int ld_amr_dump(struct ld_softc *, void *, daddr_t, int);
static void ld_amr_handler(struct amr_ccb *);
static int ld_amr_start(struct ld_softc *, struct buf *);
@@ -106,6 +106,7 @@ ld_amr_attach(device_t parent, device_t self, void *aux)
&happy);
if (happy)
ld->sc_flags = LDF_ENABLED;
+ ld->sc_flags |= LDF_BLOCK32;
aprint_normal(": RAID %d, %s\n",
amr->amr_drive[sc->sc_hwunit].al_properties & AMR_DRV_RAID_MASK,
statestr);
@@ -195,7 +196,7 @@ ld_amr_handler(struct amr_ccb *ac)
}
static int
-ld_amr_dump(struct ld_softc *ld, void *data, int blkno, int blkcnt)
+ld_amr_dump(struct ld_softc *ld, void *data, daddr_t blkno, int blkcnt)
{
struct ld_amr_softc *sc;
diff --git a/sys/dev/pci/ld_twa.c b/sys/dev/pci/ld_twa.c
index f3b44c4d433..b3b079ccda6 100644
--- a/sys/dev/pci/ld_twa.c
+++ b/sys/dev/pci/ld_twa.c
@@ -75,7 +75,7 @@ static void ld_twa_attach(device_t, device_t, void *);
static int ld_twa_detach(device_t, int);
static int ld_twa_dobio(struct ld_twa_softc *, void *, size_t, daddr_t,
struct buf *);
-static int ld_twa_dump(struct ld_softc *, void *, int, int);
+static int ld_twa_dump(struct ld_softc *, void *, daddr_t, int);
static int ld_twa_flush(struct ld_softc *, bool);
static int ld_twa_ioctl(struct ld_softc *, u_long, void *, int32_t, bool);
static void ld_twa_handler(struct twa_request *);
@@ -221,7 +221,7 @@ ld_twa_handler(struct twa_request *tr)
}
static int
-ld_twa_dump(struct ld_softc *ld, void *data, int blkno, int blkcnt)
+ld_twa_dump(struct ld_softc *ld, void *data, daddr_t blkno, int blkcnt)
{
#if 0
diff --git a/sys/dev/pci/ld_twe.c b/sys/dev/pci/ld_twe.c
index dc4e0f3e8f1..cc548f388ba 100644
--- a/sys/dev/pci/ld_twe.c
+++ b/sys/dev/pci/ld_twe.c
@@ -65,7 +65,7 @@ static void ld_twe_attach(device_t, device_t, void *);
static int ld_twe_detach(device_t, int);
static int ld_twe_dobio(struct ld_twe_softc *, void *, int, int, int,
struct buf *);
-static int ld_twe_dump(struct ld_softc *, void *, int, int);
+static int ld_twe_dump(struct ld_softc *, void *, daddr_t, int);
static int ld_twe_flush(struct ld_softc *, bool);
static int ld_twe_ioctl(struct ld_softc *, u_long, void *, int32_t, bool);
static void ld_twe_handler(struct twe_ccb *, int);
@@ -106,7 +106,7 @@ ld_twe_attach(device_t parent, device_t self, void *aux)
twe_register_callbacks(twe, twea->twea_unit, &ld_twe_callbacks);
sc->sc_hwunit = twea->twea_unit;
- ld->sc_flags = LDF_ENABLED;
+ ld->sc_flags = LDF_ENABLED | LDF_BLOCK32;
ld->sc_maxxfer = twe_get_maxxfer(twe_get_maxsegs());
ld->sc_secperunit = td->td_size;
ld->sc_secsize = TWE_SECTOR_SIZE;
@@ -259,7 +259,7 @@ ld_twe_handler(struct twe_ccb *ccb, int error)
}
static int
-ld_twe_dump(struct ld_softc *ld, void *data, int blkno, int blkcnt)
+ld_twe_dump(struct ld_softc *ld, void *data, daddr_t blkno, int blkcnt)
{
return (ld_twe_dobio((struct ld_twe_softc *)ld, data,
diff --git a/sys/dev/pci/ld_virtio.c b/sys/dev/pci/ld_virtio.c
index bddab19c749..47059091ef6 100644
--- a/sys/dev/pci/ld_virtio.c
+++ b/sys/dev/pci/ld_virtio.c
@@ -210,7 +210,7 @@ ld_virtio_match(device_t parent, cfdata_t match, void *aux)
}
static int ld_virtio_vq_done(struct virtqueue *);
-static int ld_virtio_dump(struct ld_softc *, void *, int, int);
+static int ld_virtio_dump(struct ld_softc *, void *, daddr_t, int);
static int ld_virtio_start(struct ld_softc *, struct buf *);
static int ld_virtio_ioctl(struct ld_softc *, u_long, void *, int32_t, bool);
static int ld_virtio_info(struct ld_softc *, bool);
@@ -749,7 +749,7 @@ again:
}
static int
-ld_virtio_dump(struct ld_softc *ld, void *data, int blkno, int blkcnt)
+ld_virtio_dump(struct ld_softc *ld, void *data, daddr_t blkno, int blkcnt)
{
struct ld_virtio_softc *sc = device_private(ld->sc_dv);
struct virtio_softc *vsc = sc->sc_virtio;
@@ -789,7 +789,7 @@ ld_virtio_dump(struct ld_softc *ld, void *data, int blkno, int blkcnt)
vr->vr_hdr.type = virtio_rw32(vsc, VIRTIO_BLK_T_OUT);
vr->vr_hdr.ioprio = virtio_rw32(vsc, 0);
vr->vr_hdr.sector = virtio_rw64(vsc,
- (daddr_t) blkno * ld->sc_secsize /
+ blkno * ld->sc_secsize /
VIRTIO_BLK_BSIZE);
bus_dmamap_sync(virtio_dmat(vsc), vr->vr_cmdsts,
diff --git a/sys/dev/sdmmc/ld_sdmmc.c b/sys/dev/sdmmc/ld_sdmmc.c
index 2046973cc7f..99c35d929c5 100644
--- a/sys/dev/sdmmc/ld_sdmmc.c
+++ b/sys/dev/sdmmc/ld_sdmmc.c
@@ -111,7 +111,7 @@ static int ld_sdmmc_match(device_t, cfdata_t, void *);
static void ld_sdmmc_attach(device_t, device_t, void *);
static int ld_sdmmc_detach(device_t, int);
-static int ld_sdmmc_dump(struct ld_softc *, void *, int, int);
+static int ld_sdmmc_dump(struct ld_softc *, void *, daddr_t, int);
static int ld_sdmmc_start(struct ld_softc *, struct buf *);
static void ld_sdmmc_restart(void *);
static int ld_sdmmc_discard(struct ld_softc *, struct buf *);
@@ -289,7 +289,7 @@ ld_sdmmc_attach(device_t parent, device_t self, void *aux)
sc->sc_hwunit = 0; /* always 0? */
sc->sc_sf = sa->sf;
- ld->sc_flags = LDF_ENABLED | LDF_MPSAFE;
+ ld->sc_flags = LDF_ENABLED | LDF_MPSAFE | LDF_BLOCK32;
ld->sc_secperunit = sc->sc_sf->csd.capacity;
ld->sc_secsize = SDMMC_SECTOR_SIZE;
ld->sc_maxxfer = MAXPHYS;
@@ -510,7 +510,7 @@ done_locked:
}
static int
-ld_sdmmc_dump(struct ld_softc *ld, void *data, int blkno, int blkcnt)
+ld_sdmmc_dump(struct ld_softc *ld, void *data, daddr_t blkno, int blkcnt)
{
struct ld_sdmmc_softc *sc = device_private(ld->sc_dv);
--
2.46.1
Home |
Main Index |
Thread Index |
Old Index