The virtio specifications allows for up to 128 bits for the device features. Soon we are going to use some of the 'extended' bits features (above 64) for the virtio net driver.
For platform natively supporting 128 bits, introduce a 128 bit integer state. Signed-off-by: Paolo Abeni <pab...@redhat.com> --- include/migration/qemu-file-types.h | 15 +++++++++++++++ include/migration/vmstate.h | 11 +++++++++++ migration/qemu-file.c | 16 ++++++++++++++++ migration/vmstate-types.c | 25 +++++++++++++++++++++++++ 4 files changed, 67 insertions(+) diff --git a/include/migration/qemu-file-types.h b/include/migration/qemu-file-types.h index adec5abc07..094ace5bb2 100644 --- a/include/migration/qemu-file-types.h +++ b/include/migration/qemu-file-types.h @@ -92,6 +92,21 @@ static inline void qemu_get_8s(QEMUFile *f, uint8_t *pv) *pv = qemu_get_byte(f); } +#ifdef CONFIG_INT128 +void qemu_put_be128(QEMUFile *f, __uint128_t v); +__uint128_t qemu_get_be128(QEMUFile *f); + +static inline void qemu_put_be128s(QEMUFile *f, const __uint128_t *pv) +{ + qemu_put_be128(f, *pv); +} + +static inline void qemu_get_be128s(QEMUFile *f, __uint128_t *pv) +{ + *pv = qemu_get_be128(f); +} +#endif + /* Signed versions for type safety */ static inline void qemu_put_sbe16(QEMUFile *f, int v) { diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index a1dfab4460..9695d4ba06 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -903,6 +903,17 @@ extern const VMStateInfo vmstate_info_qlist; #define VMSTATE_UINT64_V(_f, _s, _v) \ VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64, uint64_t) +#ifdef CONFIG_INT128 +#define VMSTATE_UINT128_V(_f, _s, _v) \ + VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint128, __uint128_t) +#define VMSTATE_UINT128(_f, _s) \ + VMSTATE_UINT128_V(_f, _s, 0) +#define VMSTATE_UINT128_TEST(_f, _s, _t) \ + VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int128, __int128_t) + +extern const VMStateInfo vmstate_info_uint128; +#endif + #define VMSTATE_FD_V(_f, _s, _v) \ VMSTATE_SINGLE(_f, _s, _v, vmstate_info_fd, int32_t) diff --git a/migration/qemu-file.c b/migration/qemu-file.c index b6ac190034..3dc7645d3e 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -825,6 +825,22 @@ void qemu_put_be64(QEMUFile *f, uint64_t v) qemu_put_be32(f, v); } +#ifdef CONFIG_INT128 +void qemu_put_be128(QEMUFile *f, __uint128_t v) +{ + qemu_put_be64(f, v >> 64); + qemu_put_be64(f, v); +} + +__uint128_t qemu_get_be128(QEMUFile *f) +{ + __uint128_t v; + v = (__uint128_t)qemu_get_be64(f) << 64; + v |= qemu_get_be64(f); + return v; +} +#endif + unsigned int qemu_get_be16(QEMUFile *f) { unsigned int v; diff --git a/migration/vmstate-types.c b/migration/vmstate-types.c index 741a588b7e..120ea1f9cd 100644 --- a/migration/vmstate-types.c +++ b/migration/vmstate-types.c @@ -315,6 +315,31 @@ const VMStateInfo vmstate_info_uint64 = { .put = put_uint64, }; +/* 128 bit unsigned int */ +#ifdef CONFIG_INT128 +static int get_uint128(QEMUFile *f, void *pv, size_t size, + const VMStateField *field) +{ + __uint128_t *v = pv; + qemu_get_be128s(f, v); + return 0; +} + +static int put_uint128(QEMUFile *f, void *pv, size_t size, + const VMStateField *field, JSONWriter *vmdesc) +{ + __uint128_t *v = pv; + qemu_put_be128s(f, v); + return 0; +} + +const VMStateInfo vmstate_info_uint128 = { + .name = "uint128", + .get = get_uint128, + .put = put_uint128, +}; +#endif + /* File descriptor communicated via SCM_RIGHTS */ static int get_fd(QEMUFile *f, void *pv, size_t size, -- 2.49.0