Block patches
Subsystems (3)
The following changes since commit 813bac3d8d70d85cb7835f7945eb9eed84c2d8d0:
Merge tag '2023q3-bsd-user-pull-request' of https://gitlab.com/bsdimp/qemu into staging (2023-08-29 08:58:00 -0400)
are available in the Git repository at:
https://gitlab.com/stefanha/qemu.git tags/block-pull-request
for you to fetch changes up to 3f5f2285bfcdd855508a55da7875fb92de1a6ed0:
tests/qemu-iotests/197: add testcase for CoR with subclusters (2023-08-29 13:19:56 -0400)
----------------------------------------------------------------
Pull request
v2:
- Fix authorship information lost by the mailing list for Andrey Drobyshev
----------------------------------------------------------------
Andrey Drobyshev (3):
block: add subcluster_size field to BlockDriverInfo block/io: align requests to subcluster_size tests/qemu-iotests/197: add testcase for CoR with subclusters
Fabiano Rosas (1):
block-migration: Ensure we don't crash during migration cleanup
Jeuk Kim (4):
hw/ufs: Initial commit for emulated Universal-Flash-Storage hw/ufs: Support for Query Transfer Requests hw/ufs: Support for UFS logical unit
tests/qtest: Introduce tests for UFS
MAINTAINERS | 7 + docs/specs/pci-ids.rst | 2 + meson.build | 1 + hw/ufs/trace.h | 1 + hw/ufs/ufs.h | 131 +++ include/block/block-common.h | 5 + include/block/block-io.h | 8 +- include/block/ufs.h | 1090 +++++++++++++++++++++++++ include/hw/pci/pci.h | 1 + include/hw/pci/pci_ids.h | 1 + include/scsi/constants.h | 1 + block.c | 7 + block/io.c | 50 +- block/mirror.c | 8 +- block/qcow2.c | 1 + hw/ufs/lu.c | 1445 ++++++++++++++++++++++++++++++++ hw/ufs/ufs.c | 1494 ++++++++++++++++++++++++++++++++++ migration/block.c | 11 +- tests/qtest/ufs-test.c | 584 +++++++++++++ hw/Kconfig | 1 + hw/meson.build | 1 + hw/ufs/Kconfig | 4 + hw/ufs/meson.build | 1 + hw/ufs/trace-events | 58 ++ tests/qemu-iotests/197 | 29 + tests/qemu-iotests/197.out | 24 + tests/qtest/meson.build | 1 + 27 files changed, 4932 insertions(+), 35 deletions(-) create mode 100644 hw/ufs/trace.h create mode 100644 hw/ufs/ufs.h create mode 100644 include/block/ufs.h create mode 100644 hw/ufs/lu.c create mode 100644 hw/ufs/ufs.c create mode 100644 tests/qtest/ufs-test.c create mode 100644 hw/ufs/Kconfig create mode 100644 hw/ufs/meson.build create mode 100644 hw/ufs/trace-events
Signature · 1 line
2.41.0
[PULL v2 2/8] hw/ufs: Support for Query Transfer Requests
From: Jeuk Kim <[email protected]>
This commit makes the UFS device support query and nop out transfer requests.
The next patch would be support for UFS logical unit and scsi command transfer request.
Message-id: d06b440d660872092f70af1b8167bd5f4704c957.1691062912.git.jeuk20.kim@samsung.com
--- hw/ufs/ufs.h | 46 +++ hw/ufs/ufs.c | 980 +++++++++++++++++++++++++++++++++++++++++++- hw/ufs/trace-events | 1 + 3 files changed, 1025 insertions(+), 2 deletions(-)
hw/ufs/ufs.h +46 -0
@@ -18,6 +18,32 @@#define UFS_MAX_LUS 32#define UFS_BLOCK_SIZE 4096 +typedef enum UfsRequestState { +UFS_REQUEST_IDLE =0 , +UFS_REQUEST_READY =1 , +UFS_REQUEST_RUNNING =2 , +UFS_REQUEST_COMPLETE =3 , +UFS_REQUEST_ERROR =4 , +}UfsRequestState ; + +typedef enum UfsReqResult { +UFS_REQUEST_SUCCESS =0 , +UFS_REQUEST_FAIL =1 , +}UfsReqResult ; + +typedef struct UfsRequest { +struct UfsHc *hc; +UfsRequestState state; +int slot; + +UtpTransferReqDesc utrd; +UtpUpiuReq req_upiu; +UtpUpiuRsp rsp_upiu; + +/* for scsi command */ +QEMUSGList *sg; +}UfsRequest ; + typedef struct UfsParams { char *serial; uint8_t nutrs; /* Number of UTP Transfer Request Slots */
@@ -30,6 +56,12 @@ typedef struct UfsHc {UfsReg reg;UfsParams params;uint32_t reg_size; +UfsRequest *req_list; + +DeviceDescriptor device_desc; +GeometryDescriptor geometry_desc; +Attributes attributes; +Flags flags;qemu_irq irq;QEMUBH *doorbell_bh;
@@ -39,4 +71,18 @@ typedef struct UfsHc {#define TYPE_UFS "ufs"#define UFS (obj) OBJECT_CHECK(UfsHc, (obj), TYPE_UFS) +typedef enum UfsQueryFlagPerm { +UFS_QUERY_FLAG_NONE =0x0 , +UFS_QUERY_FLAG_READ =0x1 , +UFS_QUERY_FLAG_SET =0x2 , +UFS_QUERY_FLAG_CLEAR =0x4 , +UFS_QUERY_FLAG_TOGGLE =0x8 , +}UfsQueryFlagPerm ; + +typedef enum UfsQueryAttrPerm { +UFS_QUERY_ATTR_NONE =0x0 , +UFS_QUERY_ATTR_READ =0x1 , +UFS_QUERY_ATTR_WRITE =0x2 , +}UfsQueryAttrPerm ; +#endif /* HW_UFS_UFS_H */
hw/ufs/ufs.c +978 -2
1,035 lines not on this page · raw message
hw/ufs/trace-events +1 -0
@@ -18,6 +18,7 @@ ufs_err_dma_read_req_upiu(uint32_t slot, uint64_t addr) "failed to read req upiu ufs_err_dma_read_prdt(uint32_t slot, uint64_t addr) "failed to read prdt. UTRLDBR slot %"PRIu32", prdt addr %"PRIu64"" ufs_err_dma_write_utrd(uint32_t slot, uint64_t addr) "failed to write utrd. UTRLDBR slot %"PRIu32", UTRD dma addr %"PRIu64"" ufs_err_dma_write_rsp_upiu(uint32_t slot, uint64_t addr) "failed to write rsp upiu. UTRLDBR slot %"PRIu32", response upiu addr %"PRIu64"" +ufs_err_utrl_slot_error(uint32_t slot) "UTRLDBR slot %"PRIu32" is in error" ufs_err_utrl_slot_busy(uint32_t slot) "UTRLDBR slot %"PRIu32" is busy" ufs_err_unsupport_register_offset(uint32_t offset) "Register offset 0x%"PRIx32" is not yet supported" ufs_err_invalid_register_offset(uint32_t offset) "Register offset 0x%"PRIx32" is invalid"
Signature · 1 line
2.41.0
[PULL v2 4/8] tests/qtest: Introduce tests for UFS
In reply to Stefan HajnocziFrom: Jeuk Kim <[email protected]>
This patch includes the following tests
Test mmio read
Test ufs device initialization and ufs-lu recognition Test I/O (Performs a write followed by a read to verify)
Message-id: af6b8d54c049490b3533a784a0aeac4798bb9217.1691062912.git.jeuk20.kim@samsung.com
--- MAINTAINERS | 1 + tests/qtest/ufs-test.c | 584 ++++++++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 1 + 3 files changed, 586 insertions(+) create mode 100644 tests/qtest/ufs-test.c
MAINTAINERS +1 -0
@@ -2261,6 +2261,7 @@ M: Jeuk Kim <[email protected]> S: Supported F: hw/ufs/* F: include/block/ufs.h +F: tests/qtest/ufs-test.c megasas M: Hannes Reinecke <[email protected]>
tests/qtest/ufs-test.c new file +584 -0
584 lines not on this page · raw message
tests/qtest/meson.build +1 -0
@@ -269,6 +269,7 @@ qos_test_ss.add( 'virtio-iommu-test.c', 'vmxnet3-test.c', 'igb-test.c', + 'ufs-test.c', ) if config_all_devices.has_key('CONFIG_VIRTIO_SERIAL')
Signature · 1 line
2.41.0
[PULL v2 5/8] block-migration: Ensure we don't crash during migration cleanup
In reply to Stefan HajnocziFrom: Fabiano Rosas <[email protected]>
We can fail the blk_insert_bs() at init_blk_migration(), leaving the BlkMigDevState without a dirty_bitmap and BlockDriverState. Account for the possibly missing elements when doing cleanup.
Fix the following crashes:
Thread 1 "qemu-system-x86" received signal SIGSEGV, Segmentation fault. 0x0000555555ec83ef in bdrv_release_dirty_bitmap (bitmap=0x0) at ../block/dirty-bitmap.c:359
359 BlockDriverState *bs = bitmap->bs;
#0 0x0000555555ec83ef in bdrv_release_dirty_bitmap (bitmap=0x0) at ../block/dirty-bitmap.c:359 #1 0x0000555555bba331 in unset_dirty_tracking () at ../migration/block.c:371 #2 0x0000555555bbad98 in block_migration_cleanup_bmds () at ../migration/block.c:681
Thread 1 "qemu-system-x86" received signal SIGSEGV, Segmentation fault.0x0000555555e971ff in bdrv_op_unblock (bs=0x0, op=BLOCK_OP_TYPE_BACKUP_SOURCE, reason=0x0) at ../block.c:7073
7073 QLIST_FOREACH_SAFE(blocker, &bs->op_blockers[op], list, next) {
#0 0x0000555555e971ff in bdrv_op_unblock (bs=0x0, op=BLOCK_OP_TYPE_BACKUP_SOURCE, reason=0x0) at ../block.c:7073 #1 0x0000555555e9734a in bdrv_op_unblock_all (bs=0x0, reason=0x0) at ../block.c:7095 #2 0x0000555555bbae13 in block_migration_cleanup_bmds () at ../migration/block.c:690
Message-id: [email protected]
--- migration/block.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
migration/block.c +9 -2
@@ -368,7 +368,9 @@ static void unset_dirty_tracking(void)BlkMigDevState *bmds; QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) { -bdrv_release_dirty_bitmap (bmds->dirty_bitmap); +if (bmds->dirty_bitmap) { +bdrv_release_dirty_bitmap (bmds->dirty_bitmap); + } } }
@@ -676,13 +678,18 @@ static int64_t get_remaining_dirty(void)static void block_migration_cleanup_bmds (void ) {BlkMigDevState *bmds; +BlockDriverState *bs;AioContext *ctx;unset_dirty_tracking ();while ((bmds =QSIMPLEQ_FIRST (&block_mig_state.bmds_list)) !=NULL ) {QSIMPLEQ_REMOVE_HEAD (&block_mig_state.bmds_list, entry); -bdrv_op_unblock_all (blk_bs (bmds->blk), bmds->blocker); + + bs =blk_bs (bmds->blk); +if (bs) { +bdrv_op_unblock_all (bs, bmds->blocker); + }error_free (bmds->blocker);/* Save ctx, because bmds->blk can disappear during blk_unref. */
Signature · 1 line
2.41.0
[PULL v2 7/8] block/io: align requests to subcluster_size
In reply to Stefan HajnocziFrom: Andrey Drobyshev <[email protected]>
When target image is using subclusters, and we align the request during copy-on-read, it makes sense to align to subcluster_size rather than cluster_size. Otherwise we end up with unnecessary allocations.
This commit renames bdrv_round_to_clusters() to bdrv_round_to_subclusters() and utilizes subcluster_size field of BlockDriverInfo to make necessary alignments. It affects copy-on-read as well as mirror job (which is using bdrv_round_to_clusters()).
This change also fixes the following bug with failing assert (covered by the test in the subsequent commit):
qemu-img create -f qcow2 base.qcow2 64K
qemu-img create -f qcow2 -o extended_l2=on,backing_file=base.qcow2,backing_fmt=qcow2 img.qcow2 64K qemu-io -c "write -P 0xaa 0 2K" img.qcow2
qemu-io -C -c "read -P 0x00 2K 62K" img.qcow2
qemu-io: ../block/io.c:1236: bdrv_co_do_copy_on_readv: Assertion `skip_bytes < pnum' failed.
Message-ID: <[email protected]>
--- include/block/block-io.h | 8 +++---- block/io.c | 50 ++++++++++++++++++++-------------------- block/mirror.c | 8 +++---- 3 files changed, 33 insertions(+), 33 deletions(-)
include/block/block-io.h +4 -4
@@ -189,10 +189,10 @@ bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi);ImageInfoSpecific *bdrv_get_specific_info (BlockDriverState *bs,Error **errp);BlockStatsSpecific *bdrv_get_specific_stats (BlockDriverState *bs); -void bdrv_round_to_clusters (BlockDriverState *bs, -int64_t offset,int64_t bytes, -int64_t *cluster_offset, -int64_t *cluster_bytes); +void bdrv_round_to_subclusters (BlockDriverState *bs, +int64_t offset,int64_t bytes, +int64_t *cluster_offset, +int64_t *cluster_bytes);void bdrv_get_backing_filename (BlockDriverState *bs,char *filename,int filename_size);
block/io.c +25 -25
117 lines not on this page · raw message
block/mirror.c +4 -4
@@ -283,8 +283,8 @@ static int coroutine_fn mirror_cow_align(MirrorBlockJob *s, int64_t *offset, need_cow |= !test_bit ((*offset + *bytes -1 ) / s->granularity, s->cow_bitmap);if (need_cow) { -bdrv_round_to_clusters (blk_bs (s->target), *offset, *bytes, - &align_offset, &align_bytes); +bdrv_round_to_subclusters (blk_bs (s->target), *offset, *bytes, + &align_offset, &align_bytes); }if (align_bytes > max_bytes) {
@@ -576,8 +576,8 @@ static void coroutine_fn mirror_iteration(MirrorBlockJob *s)int64_t target_offset;int64_t target_bytes; WITH_GRAPH_RDLOCK_GUARD() { -bdrv_round_to_clusters (blk_bs (s->target), offset, io_bytes, - &target_offset, &target_bytes); +bdrv_round_to_subclusters (blk_bs (s->target), offset, io_bytes, + &target_offset, &target_bytes); }if (target_offset == offset && target_bytes == io_bytes) {
Signature · 1 line
2.41.0
[PULL v2 3/8] hw/ufs: Support for UFS logical unit
In reply to Stefan HajnocziFrom: Jeuk Kim <[email protected]>
This commit adds support for ufs logical unit. The LU handles processing for the SCSI command, unit descriptor query request.
This commit enables the UFS device to process IO requests.
Message-id: 898cea923e819dc21a99597bf045a12d7983be28.1691062912.git.jeuk20.kim@samsung.com
--- hw/ufs/ufs.h | 43 ++ include/scsi/constants.h | 1 + hw/ufs/lu.c | 1445 ++++++++++++++++++++++++++++++++++++++ hw/ufs/ufs.c | 252 ++++++- hw/ufs/meson.build | 2 +- hw/ufs/trace-events | 25 + 6 files changed, 1761 insertions(+), 7 deletions(-) create mode 100644 hw/ufs/lu.c
hw/ufs/ufs.h +43 -0
@@ -18,6 +18,18 @@#define UFS_MAX_LUS 32#define UFS_BLOCK_SIZE 4096 +typedef struct UfsBusClass { +BusClass parent_class; +bool (*parent_check_address)(BusState *bus,DeviceState *dev,Error **errp); +}UfsBusClass ; + +typedef struct UfsBus { +SCSIBus parent_bus; +}UfsBus ; + +#define TYPE_UFS_BUS "ufs-bus" +DECLARE_OBJ_CHECKERS(UfsBus, UfsBusClass, UFS_BUS, TYPE_UFS_BUS) + typedef enum UfsRequestState { UFS_REQUEST_IDLE = 0, UFS_REQUEST_READY = 1,
@@ -29,6 +41,7 @@ typedef enum UfsRequestState {typedef enum UfsReqResult {UFS_REQUEST_SUCCESS =0 ,UFS_REQUEST_FAIL =1 , +UFS_REQUEST_NO_COMPLETE =2 , }UfsReqResult ; typedef struct UfsRequest {
@@ -44,6 +57,17 @@ typedef struct UfsRequest {QEMUSGList *sg; } UfsRequest; +typedef struct UfsLu { +SCSIDevice qdev; +uint8_t lun; +UnitDescriptor unit_desc; +}UfsLu ; + +typedef struct UfsWLu { +SCSIDevice qdev; +uint8_t lun; +}UfsWLu ; + typedef struct UfsParams { char *serial; uint8_t nutrs; /* Number of UTP Transfer Request Slots */
@@ -52,12 +76,18 @@ typedef struct UfsParams { typedef struct UfsHc { PCIDevice parent_obj; + UfsBus bus; MemoryRegion iomem; UfsReg reg; UfsParams params; uint32_t reg_size; UfsRequest *req_list; + UfsLu *lus[UFS_MAX_LUS]; + UfsWLu *report_wlu; + UfsWLu *dev_wlu; + UfsWLu *boot_wlu; + UfsWLu *rpmb_wlu; DeviceDescriptor device_desc; GeometryDescriptor geometry_desc; Attributes attributes;
@@ -71,6 +101,12 @@ typedef struct UfsHc {#define TYPE_UFS "ufs"#define UFS (obj) OBJECT_CHECK(UfsHc, (obj), TYPE_UFS) +#define TYPE_UFS_LU "ufs-lu" +#define UFSLU (obj) OBJECT_CHECK(UfsLu, (obj), TYPE_UFS_LU) + +#define TYPE_UFS_WLU "ufs-wlu" +#define UFSWLU (obj) OBJECT_CHECK(UfsWLu, (obj), TYPE_UFS_WLU) + typedef enum UfsQueryFlagPerm { UFS_QUERY_FLAG_NONE = 0x0, UFS_QUERY_FLAG_READ = 0x1,
@@ -85,4 +121,11 @@ typedef enum UfsQueryAttrPerm {UFS_QUERY_ATTR_WRITE =0x2 , } UfsQueryAttrPerm; +static inline bool is_wlun (uint8_t lun) +{ +return (lun ==UFS_UPIU_REPORT_LUNS_WLUN || + lun ==UFS_UPIU_UFS_DEVICE_WLUN || lun ==UFS_UPIU_BOOT_WLUN || + lun ==UFS_UPIU_RPMB_WLUN ); +} +#endif /* HW_UFS_UFS_H */
include/scsi/constants.h +1 -0
@@ -231,6 +231,7 @@#define MODE_PAGE_FLEXIBLE_DISK_GEOMETRY 0x05#define MODE_PAGE_CACHING 0x08#define MODE_PAGE_AUDIO_CTL 0x0e +#define MODE_PAGE_CONTROL 0x0a#define MODE_PAGE_POWER 0x1a#define MODE_PAGE_FAULT_FAIL 0x1c#define MODE_PAGE_TO_PROTECT 0x1d
hw/ufs/lu.c new file +1445 -0
1,445 lines not on this page · raw message
hw/ufs/ufs.c +246 -6
332 lines not on this page · raw message
hw/ufs/meson.build +1 -1
@@ -1 +1 @@ -system_ss.add(when: 'CONFIG_UFS_PCI', if_true: files('ufs.c')) +system_ss.add(when: 'CONFIG_UFS_PCI', if_true: files('ufs.c', 'lu.c'))
hw/ufs/trace-events +25 -0
@@ -12,6 +12,31 @@ ufs_exec_scsi_cmd(uint32_t slot, uint8_t lun, uint8_t opcode) "slot %"PRIu32", l ufs_exec_query_cmd(uint32_t slot, uint8_t opcode) "slot %"PRIu32", opcode 0x%"PRIx8"" ufs_process_uiccmd(uint32_t uiccmd, uint32_t ucmdarg1, uint32_t ucmdarg2, uint32_t ucmdarg3) "uiccmd 0x%"PRIx32", ucmdarg1 0x%"PRIx32", ucmdarg2 0x%"PRIx32", ucmdarg3 0x%"PRIx32"" +# lu.c +ufs_scsi_check_condition(uint32_t tag, uint8_t key, uint8_t asc, uint8_t ascq) "Command complete tag=0x%x sense=%d/%d/%d" +ufs_scsi_read_complete(uint32_t tag, size_t size) "Data ready tag=0x%x len=%zd" +ufs_scsi_read_data_count(uint32_t sector_count) "Read sector_count=%d" +ufs_scsi_read_data_invalid(void) "Data transfer direction invalid" +ufs_scsi_write_complete_noio(uint32_t tag, size_t size) "Write complete tag=0x%x more=%zd" +ufs_scsi_write_data_invalid(void) "Data transfer direction invalid" +ufs_scsi_emulate_vpd_page_00(size_t xfer) "Inquiry EVPD[Supported pages] buffer size %zd" +ufs_scsi_emulate_vpd_page_80_not_supported(void) "Inquiry EVPD[Serial number] not supported" +ufs_scsi_emulate_vpd_page_80(size_t xfer) "Inquiry EVPD[Serial number] buffer size %zd" +ufs_scsi_emulate_vpd_page_87(size_t xfer) "Inquiry EVPD[Mode Page Policy] buffer size %zd" +ufs_scsi_emulate_mode_sense(int cmd, int page, size_t xfer, int control) "Mode Sense(%d) (page %d, xfer %zd, page_control %d)" +ufs_scsi_emulate_read_data(int buflen) "Read buf_len=%d" +ufs_scsi_emulate_write_data(int buflen) "Write buf_len=%d" +ufs_scsi_emulate_command_START_STOP(void) "START STOP UNIT" +ufs_scsi_emulate_command_FORMAT_UNIT(void) "FORMAT UNIT" +ufs_scsi_emulate_command_SEND_DIAGNOSTIC(void) "SEND DIAGNOSTIC" +ufs_scsi_emulate_command_SAI_16(void) "SAI READ CAPACITY(16)" +ufs_scsi_emulate_command_SAI_unsupported(void) "Unsupported Service Action In" +ufs_scsi_emulate_command_MODE_SELECT_10(size_t xfer) "Mode Select(10) (len %zd)" +ufs_scsi_emulate_command_VERIFY(int bytchk) "Verify (bytchk %d)" +ufs_scsi_emulate_command_UNKNOWN(int cmd, const char *name) "Unknown SCSI command (0x%2.2x=%s)" +ufs_scsi_dma_command_READ(uint64_t lba, uint32_t len) "Read (block %" PRIu64 ", count %u)" +ufs_scsi_dma_command_WRITE(uint64_t lba, int len) "Write (block %" PRIu64 ", count %u)" + # error condition ufs_err_dma_read_utrd(uint32_t slot, uint64_t addr) "failed to read utrd. UTRLDBR slot %"PRIu32", UTRD dma addr %"PRIu64"" ufs_err_dma_read_req_upiu(uint32_t slot, uint64_t addr) "failed to read req upiu. UTRLDBR slot %"PRIu32", request upiu addr %"PRIu64""
Signature · 1 line
2.41.0
[PULL v2 1/8] hw/ufs: Initial commit for emulated Universal-Flash-Storage
In reply to Stefan HajnocziFrom: Jeuk Kim <[email protected]>
Universal Flash Storage (UFS) is a high-performance mass storage device with a serial interface. It is primarily used as a high-performance data storage device for embedded applications.
This commit contains code for UFS device to be recognized as a UFS PCI device.
Patches to handle UFS logical unit and Transfer Request will follow.
Message-id: 9f3db32fe1c708090a6bb764d456973b5abef55f.1691062912.git.jeuk20.kim@samsung.com
--- MAINTAINERS | 6 + docs/specs/pci-ids.rst | 2 + meson.build | 1 + hw/ufs/trace.h | 1 + hw/ufs/ufs.h | 42 ++ include/block/ufs.h | 1090 ++++++++++++++++++++++++++++++++++++++ include/hw/pci/pci.h | 1 + include/hw/pci/pci_ids.h | 1 + hw/ufs/ufs.c | 278 ++++++++++ hw/Kconfig | 1 + hw/meson.build | 1 + hw/ufs/Kconfig | 4 + hw/ufs/meson.build | 1 + hw/ufs/trace-events | 32 ++ 14 files changed, 1461 insertions(+) create mode 100644 hw/ufs/trace.h create mode 100644 hw/ufs/ufs.h create mode 100644 include/block/ufs.h create mode 100644 hw/ufs/ufs.c create mode 100644 hw/ufs/Kconfig create mode 100644 hw/ufs/meson.build create mode 100644 hw/ufs/trace-events
MAINTAINERS +6 -0
@@ -2256,6 +2256,12 @@ F: tests/qtest/nvme-test.c F: docs/system/devices/nvme.rst T: git git://git.infradead.org/qemu-nvme.git nvme-next +ufs +M: Jeuk Kim <[email protected]> +S: Supported +F: hw/ufs/* +F: include/block/ufs.h + megasas M: Hannes Reinecke <[email protected]> L: [email protected]
docs/specs/pci-ids.rst +2 -0
@@ -92,6 +92,8 @@ PCI devices (other than virtio): PCI PVPanic device (``-device pvpanic-pci``) 1b36:0012 PCI ACPI ERST device (``-device acpi-erst``) +1b36:0013 + PCI UFS device (``-device ufs``) All these devices are documented in :doc:`index`.
meson.build +1 -0
@@ -3277,6 +3277,7 @@ if have_system 'hw/ssi', 'hw/timer', 'hw/tpm', + 'hw/ufs', 'hw/usb', 'hw/vfio', 'hw/virtio',
hw/ufs/trace.h new file +1 -0
@@ -0,0 +1 @@ +#include "trace/trace-hw_ufs.h"
hw/ufs/ufs.h new file +42 -0
42 lines not on this page · raw message
include/block/ufs.h new file +1090 -0
1,090 lines not on this page · raw message
include/hw/pci/pci.h +1 -0
@@ -114,6 +114,7 @@ extern bool pci_available;#define PCI_DEVICE_ID_REDHAT_NVME 0x0010#define PCI_DEVICE_ID_REDHAT_PVPANIC 0x0011#define PCI_DEVICE_ID_REDHAT_ACPI_ERST 0x0012 +#define PCI_DEVICE_ID_REDHAT_UFS 0x0013#define PCI_DEVICE_ID_REDHAT_QXL 0x0100#define FMT_PCIBUS PRIx64
include/hw/pci/pci_ids.h +1 -0
@@ -26,6 +26,7 @@#define PCI_CLASS_STORAGE_SATA 0x0106#define PCI_CLASS_STORAGE_SAS 0x0107#define PCI_CLASS_STORAGE_EXPRESS 0x0108 +#define PCI_CLASS_STORAGE_UFS 0x0109#define PCI_CLASS_STORAGE_OTHER 0x0180#define PCI_BASE_CLASS_NETWORK 0x02
hw/ufs/ufs.c new file +278 -0
278 lines not on this page · raw message
hw/Kconfig +1 -0
@@ -38,6 +38,7 @@ source smbios/Kconfig source ssi/Kconfig source timer/Kconfig source tpm/Kconfig +source ufs/Kconfig source usb/Kconfig source virtio/Kconfig source vfio/Kconfig
hw/meson.build +1 -0
@@ -37,6 +37,7 @@ subdir('smbios') subdir('ssi') subdir('timer') subdir('tpm') +subdir('ufs') subdir('usb') subdir('vfio') subdir('virtio')
hw/ufs/Kconfig new file +4 -0
@@ -0,0 +1,4 @@ +config UFS_PCI + bool + default y if PCI_DEVICES + depends on PCI
hw/ufs/meson.build new file +1 -0
@@ -0,0 +1 @@ +system_ss.add(when: 'CONFIG_UFS_PCI', if_true: files('ufs.c'))
hw/ufs/trace-events new file +32 -0
@@ -0,0 +1,32 @@ +# ufs.c +ufs_irq_raise(void) "INTx" +ufs_irq_lower(void) "INTx" +ufs_mmio_read(uint64_t addr, uint64_t data, unsigned size) "addr 0x%"PRIx64" data 0x%"PRIx64" size %d" +ufs_mmio_write(uint64_t addr, uint64_t data, unsigned size) "addr 0x%"PRIx64" data 0x%"PRIx64" size %d" +ufs_process_db(uint32_t slot) "UTRLDBR slot %"PRIu32"" +ufs_process_req(uint32_t slot) "UTRLDBR slot %"PRIu32"" +ufs_complete_req(uint32_t slot) "UTRLDBR slot %"PRIu32"" +ufs_sendback_req(uint32_t slot) "UTRLDBR slot %"PRIu32"" +ufs_exec_nop_cmd(uint32_t slot) "UTRLDBR slot %"PRIu32"" +ufs_exec_scsi_cmd(uint32_t slot, uint8_t lun, uint8_t opcode) "slot %"PRIu32", lun 0x%"PRIx8", opcode 0x%"PRIx8"" +ufs_exec_query_cmd(uint32_t slot, uint8_t opcode) "slot %"PRIu32", opcode 0x%"PRIx8"" +ufs_process_uiccmd(uint32_t uiccmd, uint32_t ucmdarg1, uint32_t ucmdarg2, uint32_t ucmdarg3) "uiccmd 0x%"PRIx32", ucmdarg1 0x%"PRIx32", ucmdarg2 0x%"PRIx32", ucmdarg3 0x%"PRIx32"" + +# error condition +ufs_err_dma_read_utrd(uint32_t slot, uint64_t addr) "failed to read utrd. UTRLDBR slot %"PRIu32", UTRD dma addr %"PRIu64"" +ufs_err_dma_read_req_upiu(uint32_t slot, uint64_t addr) "failed to read req upiu. UTRLDBR slot %"PRIu32", request upiu addr %"PRIu64"" +ufs_err_dma_read_prdt(uint32_t slot, uint64_t addr) "failed to read prdt. UTRLDBR slot %"PRIu32", prdt addr %"PRIu64"" +ufs_err_dma_write_utrd(uint32_t slot, uint64_t addr) "failed to write utrd. UTRLDBR slot %"PRIu32", UTRD dma addr %"PRIu64"" +ufs_err_dma_write_rsp_upiu(uint32_t slot, uint64_t addr) "failed to write rsp upiu. UTRLDBR slot %"PRIu32", response upiu addr %"PRIu64"" +ufs_err_utrl_slot_busy(uint32_t slot) "UTRLDBR slot %"PRIu32" is busy" +ufs_err_unsupport_register_offset(uint32_t offset) "Register offset 0x%"PRIx32" is not yet supported" +ufs_err_invalid_register_offset(uint32_t offset) "Register offset 0x%"PRIx32" is invalid" +ufs_err_scsi_cmd_invalid_lun(uint8_t lun) "scsi command has invalid lun: 0x%"PRIx8"" +ufs_err_query_flag_not_readable(uint8_t idn) "query flag idn 0x%"PRIx8" is denied to read" +ufs_err_query_flag_not_writable(uint8_t idn) "query flag idn 0x%"PRIx8" is denied to write" +ufs_err_query_attr_not_readable(uint8_t idn) "query attribute idn 0x%"PRIx8" is denied to read" +ufs_err_query_attr_not_writable(uint8_t idn) "query attribute idn 0x%"PRIx8" is denied to write" +ufs_err_query_invalid_opcode(uint8_t opcode) "query request has invalid opcode. opcode: 0x%"PRIx8"" +ufs_err_query_invalid_idn(uint8_t opcode, uint8_t idn) "query request has invalid idn. opcode: 0x%"PRIx8", idn 0x%"PRIx8"" +ufs_err_query_invalid_index(uint8_t opcode, uint8_t index) "query request has invalid index. opcode: 0x%"PRIx8", index 0x%"PRIx8"" +ufs_err_invalid_trans_code(uint32_t slot, uint8_t trans_code) "request upiu has invalid transaction code. slot: %"PRIu32", trans_code: 0x%"PRIx8""
Signature · 1 line
2.41.0
[PULL v2 6/8] block: add subcluster_size field to BlockDriverInfo
In reply to Stefan HajnocziFrom: Andrey Drobyshev <[email protected]>
This is going to be used in the subsequent commit as requests alignment (in particular, during copy-on-read). This value only makes sense for the formats which support subclusters (currently QCOW2 only). If this field isn't set by driver's own bdrv_get_info() implementation, we simply set it equal to the cluster size thus treating each cluster as having a single subcluster.
Message-ID: <[email protected]>
--- include/block/block-common.h | 5 +++++ block.c | 7 +++++++ block/qcow2.c | 1 + 3 files changed, 13 insertions(+)
include/block/block-common.h +5 -0
@@ -132,6 +132,11 @@ typedef struct BlockZoneWps { typedef struct BlockDriverInfo { /* in bytes, 0 if irrelevant */ int cluster_size; + /* + * A fraction of cluster_size, if supported (currently QCOW2 only); if + * disabled or unsupported, set equal to cluster_size. + */ + int subcluster_size; /* offset at which the VM state can be saved (0 if not possible) */ int64_t vm_state_offset; bool is_dirty;
block.c +7 -0
@@ -6480,6 +6480,13 @@ int coroutine_fn bdrv_co_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) }memset (bdi,0 ,sizeof (*bdi)); ret = drv->bdrv_co_get_info (bs, bdi); +if (bdi->subcluster_size ==0 ) { +/* +* If the driver left this unset, subclusters are not supported. +* Then it is safe to treat each cluster as having only one subcluster. +*/ + bdi->subcluster_size = bdi->cluster_size; + }if (ret <0 ) {return ret; }
block/qcow2.c +1 -0
@@ -5197,6 +5197,7 @@ qcow2_co_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) {BDRVQcow2State *s = bs->opaque; bdi->cluster_size = s->cluster_size; + bdi->subcluster_size = s->subcluster_size; bdi->vm_state_offset =qcow2_vm_state_offset (s); bdi->is_dirty = s->incompatible_features &QCOW2_INCOMPAT_DIRTY ;return 0 ;
Signature · 1 line
2.41.0
[PULL v2 8/8] tests/qemu-iotests/197: add testcase for CoR with subclusters
In reply to Stefan HajnocziFrom: Andrey Drobyshev <[email protected]>
Add testcase which checks that allocations during copy-on-read are performed on the subcluster basis when subclusters are enabled in target image.
This testcase also triggers the following assert with previous commit not being applied, so we check that as well:
qemu-io: ../block/io.c:1236: bdrv_co_do_copy_on_readv: Assertion `skip_bytes < pnum' failed.
Message-ID: <[email protected]>
--- tests/qemu-iotests/197 | 29 +++++++++++++++++++++++++++++ tests/qemu-iotests/197.out | 24 ++++++++++++++++++++++++ 2 files changed, 53 insertions(+)
tests/qemu-iotests/197 +29 -0
@@ -122,6 +122,35 @@ $QEMU_IO -f qcow2 -C -c 'read 0 1024' "$TEST_WRAP" | _filter_qemu_io $QEMU_IO -f qcow2 -c map "$TEST_WRAP" _check_test_img +echo +echo '=== Copy-on-read with subclusters ===' +echo + +# Create base and top images 64K (1 cluster) each. Make subclusters enabled +# for the top image +_make_test_img 64K +IMGPROTO=file IMGFMT=qcow2 TEST_IMG_FILE="$TEST_WRAP" \ + _make_test_img --no-opts -o extended_l2=true -F "$IMGFMT" -b "$TEST_IMG" \ + 64K | _filter_img_create + +$QEMU_IO -c "write -P 0xaa 0 64k" "$TEST_IMG" | _filter_qemu_io + +# Allocate individual subclusters in the top image, and not the whole cluster +$QEMU_IO -c "write -P 0xbb 28K 2K" -c "write -P 0xcc 34K 2K" "$TEST_WRAP" \ + | _filter_qemu_io + +# Only 2 subclusters should be allocated in the top image at this point +$QEMU_IMG map "$TEST_WRAP" | _filter_qemu_img_map + +# Actual copy-on-read operation +$QEMU_IO -C -c "read -P 0xaa 30K 4K" "$TEST_WRAP" | _filter_qemu_io + +# And here we should have 4 subclusters allocated right in the middle of the +# top image. Make sure the whole cluster remains unallocated +$QEMU_IMG map "$TEST_WRAP" | _filter_qemu_img_map + +_check_test_img + # success, all done echo '*** done' status=0
tests/qemu-iotests/197.out +24 -0
@@ -31,4 +31,28 @@ read 1024/1024 bytes at offset 0 1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) 1 KiB (0x400) bytes allocated at offset 0 bytes (0x0) No errors were found on the image. + +=== Copy-on-read with subclusters === + +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=65536 +Formatting 'TEST_DIR/t.wrap.IMGFMT', fmt=IMGFMT size=65536 backing_file=TEST_DIR/t.IMGFMT backing_fmt=IMGFMT +wrote 65536/65536 bytes at offset 0 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 2048/2048 bytes at offset 28672 +2 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 2048/2048 bytes at offset 34816 +2 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +Offset Length File +0 0x7000 TEST_DIR/t.IMGFMT +0x7000 0x800 TEST_DIR/t.wrap.IMGFMT +0x7800 0x1000 TEST_DIR/t.IMGFMT +0x8800 0x800 TEST_DIR/t.wrap.IMGFMT +0x9000 0x7000 TEST_DIR/t.IMGFMT +read 4096/4096 bytes at offset 30720 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +Offset Length File +0 0x7000 TEST_DIR/t.IMGFMT +0x7000 0x2000 TEST_DIR/t.wrap.IMGFMT +0x9000 0x7000 TEST_DIR/t.IMGFMT +No errors were found on the image. *** done
Signature · 1 line
2.41.0