hw/remote/vfio-user: Fix config space access byte order
PCI config space is little-endian, so on a big-endian host we need to perform byte swaps for values as they are passed to and received from the generic PCI config space access machinery. Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Jagannathan Raman <jag.raman@oracle.com> Signed-off-by: Mattias Nissler <mnissler@rivosinc.com> Message-ID: <20240507094210.300566-6-mnissler@rivosinc.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
This commit is contained in:
		
							parent
							
								
									09d98a241c
								
							
						
					
					
						commit
						e6578f1f68
					
				@ -281,7 +281,7 @@ static ssize_t vfu_object_cfg_access(vfu_ctx_t *vfu_ctx, char * const buf,
 | 
				
			|||||||
    while (bytes > 0) {
 | 
					    while (bytes > 0) {
 | 
				
			||||||
        len = (bytes > pci_access_width) ? pci_access_width : bytes;
 | 
					        len = (bytes > pci_access_width) ? pci_access_width : bytes;
 | 
				
			||||||
        if (is_write) {
 | 
					        if (is_write) {
 | 
				
			||||||
            memcpy(&val, ptr, len);
 | 
					            val = ldn_le_p(ptr, len);
 | 
				
			||||||
            pci_host_config_write_common(o->pci_dev, offset,
 | 
					            pci_host_config_write_common(o->pci_dev, offset,
 | 
				
			||||||
                                         pci_config_size(o->pci_dev),
 | 
					                                         pci_config_size(o->pci_dev),
 | 
				
			||||||
                                         val, len);
 | 
					                                         val, len);
 | 
				
			||||||
@ -289,7 +289,7 @@ static ssize_t vfu_object_cfg_access(vfu_ctx_t *vfu_ctx, char * const buf,
 | 
				
			|||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            val = pci_host_config_read_common(o->pci_dev, offset,
 | 
					            val = pci_host_config_read_common(o->pci_dev, offset,
 | 
				
			||||||
                                              pci_config_size(o->pci_dev), len);
 | 
					                                              pci_config_size(o->pci_dev), len);
 | 
				
			||||||
            memcpy(ptr, &val, len);
 | 
					            stn_le_p(ptr, len, val);
 | 
				
			||||||
            trace_vfu_cfg_read(offset, val);
 | 
					            trace_vfu_cfg_read(offset, val);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        offset += len;
 | 
					        offset += len;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user