x86/SVM-IOMMU: Don't opencode memcpy() in queue_iommu_command()
PATCH 1/2 x86/SVM-IOMMU: Don't opencode memcpy() in queue_iommu_command()
In practice, this allows the compiler to replace the loop with a pair of movs.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Suravee Suthikulpanit <[email protected]>
CC: Brian Woods <[email protected]>
--- xen/drivers/passthrough/amd/iommu_cmd.c | 12 ++++-------- xen/include/asm-x86/hvm/svm/amd-iommu-defs.h | 1 - 2 files changed, 4 insertions(+), 9 deletions(-)
xen/drivers/passthrough/amd/iommu_cmd.c +4 -8
@@ -24,8 +24,7 @@static int queue_iommu_command (struct amd_iommu *iommu,u32 cmd[]) { -u32 tail, head, *cmd_buffer; -int i; +uint32_t tail, head; tail = iommu->cmd_buffer.tail;if ( ++tail == iommu->cmd_buffer.entries )
@@ -35,12 +34,9 @@ static int queue_iommu_command(struct amd_iommu *iommu, u32 cmd[]) IOMMU_CMD_BUFFER_HEAD_OFFSET));if ( head != tail ) { - cmd_buffer = (u32 *)(iommu->cmd_buffer.buffer + - (iommu->cmd_buffer.tail * -IOMMU_CMD_BUFFER_ENTRY_SIZE )); - -for ( i =0 ; i <IOMMU_CMD_BUFFER_U32_PER_ENTRY ; i++ ) - cmd_buffer[i] = cmd[i]; +memcpy (iommu->cmd_buffer.buffer + + (iommu->cmd_buffer.tail *IOMMU_CMD_BUFFER_ENTRY_SIZE ), + cmd,IOMMU_CMD_BUFFER_ENTRY_SIZE ); iommu->cmd_buffer.tail = tail;return 1 ;
xen/include/asm-x86/hvm/svm/amd-iommu-defs.h +0 -1
@@ -187,7 +187,6 @@#define IOMMU_CMD_BUFFER_ENTRY_SIZE 16#define IOMMU_CMD_BUFFER_POWER_OF2_ENTRIES_PER_PAGE 8 -#define IOMMU_CMD_BUFFER_U32_PER_ENTRY (IOMMU_CMD_BUFFER_ENTRY_SIZE / 4)#define IOMMU_CMD_OPCODE_MASK 0xF0000000#define IOMMU_CMD_OPCODE_SHIFT 28
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 2/2 x86/SVM-IOMMU: Drop get_field_from_byte()
It is MASK_EXTR() in disguise, but less flexible.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Suravee Suthikulpanit <[email protected]>
CC: Brian Woods <[email protected]>
--- xen/drivers/passthrough/amd/iommu_map.c | 2 +- xen/include/asm-x86/hvm/svm/amd-iommu-proto.h | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-)
xen/drivers/passthrough/amd/iommu_map.c +1 -1
@@ -220,7 +220,7 @@ void __init iommu_dte_add_device_entry(u32 *dte, struct ivrs_mappings *ivrs_dev) dte[7 ] = dte[6 ] = dte[4 ] = dte[2 ] = dte[1 ] = dte[0 ] =0 ; flags = ivrs_dev->device_flags; - sys_mgt =get_field_from_byte (flags,ACPI_IVHD_SYSTEM_MGMT ); + sys_mgt =MASK_EXTR (flags,ACPI_IVHD_SYSTEM_MGMT ); dev_ex = ivrs_dev->dte_allow_exclusion; flags &= mask;
xen/include/asm-x86/hvm/svm/amd-iommu-proto.h +0 -5
@@ -155,11 +155,6 @@ static inline u32 set_field_in_reg_u32(u32 field, u32 reg_value,return reg_value; } -static inline u8 get_field_from_byte (u8 value,u8 mask) -{ -return (value & mask) / (mask & -mask); -} -static inline unsigned long region_to_pages (unsigned long addr,unsigned long size) {return (PAGE_ALIGN (addr + size) - (addr &PAGE_MASK )) >>PAGE_SHIFT ;
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 2/2] x86/SVM-IOMMU: Drop get_field_from_byte()
Quoted 11 lines
-----Original Message-----
From: Andrew Cooper [mailto:[email protected]]
Sent: 24 September 2018 11:56
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Jan Beulich <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>; Paul Durrant <[email protected]>; Suravee Suthikulpanit <[email protected]>; Brian Woods <[email protected]>
Subject: [PATCH 2/2] x86/SVM-IOMMU: Dropget_field_from_byte()
Quoted 5 lines
It is
MASK_EXTR()in disguise, but less flexible.No functional change.
Signed-off-by Andrew Cooper <[email protected]>
Quoted 46 lines
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Suravee Suthikulpanit <[email protected]>
CC: Brian Woods <[email protected]>--- xen/drivers/passthrough/amd/iommu_map.c | 2 +- xen/include/asm-x86/hvm/svm/amd-iommu-proto.h | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-)xen/drivers/passthrough/amd/iommu_map.c +1
-1@@ -220,7 +220,7 @@ void __init iommu_dte_add_device_entry(u32 *dte, struct ivrs_mappings *ivrs_dev) dte[7 ] = dte[6 ] = dte[4 ] = dte[2 ] = dte[1 ] = dte[0 ] =0 ; flags = ivrs_dev->device_flags; - sys_mgt =get_field_from_byte (flags,ACPI_IVHD_SYSTEM_MGMT ); + sys_mgt =MASK_EXTR (flags,ACPI_IVHD_SYSTEM_MGMT ); dev_ex = ivrs_dev->dte_allow_exclusion;flags &= mask;xen/include/asm-x86/hvm/svm/amd-iommu-proto.h +0
-5@@ -155,11 +155,6 @@ static inline u32 set_field_in_reg_u32(u32 field, u32 reg_value, return reg_value; } -static inline u8 get_field_from_byte (u8 value,u8 mask) -{ -return (value & mask) / (mask & -mask); -} -static inline unsigned long region_to_pages (unsigned long addr,unsigned long size){ return (PAGE_ALIGN(addr + size) - (addr & PAGE_MASK)) >> PAGE_SHIFT;
Quoted 2 lines
--
2.1.4
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 2/2] x86/SVM-IOMMU: Drop get_field_from_byte()
In reply to Andrew CooperQuoted 6 lines
Quoted 1 line
Quoted 1 line · On 24.09.18 at 12:55, <[email protected]> wrote:
It is
MASK_EXTR()in disguise, but less flexible.No functional change.
Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 2/2] x86/SVM-IOMMU: Drop get_field_from_byte()
In reply to Andrew CooperQuoted 5 lines · Andy Cooper
It is
MASK_EXTR()in disguise, but less flexible.No functional change.
Signed-off-by Andrew Cooper <[email protected]>
Quoted 44 lines
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Suravee Suthikulpanit <[email protected]>
CC: Brian Woods <[email protected]>--- xen/drivers/passthrough/amd/iommu_map.c | 2 +- xen/include/asm-x86/hvm/svm/amd-iommu-proto.h | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-)xen/drivers/passthrough/amd/iommu_map.c +1
-1@@ -220,7 +220,7 @@ void __init iommu_dte_add_device_entry(u32 *dte, struct ivrs_mappings *ivrs_dev) dte[7 ] = dte[6 ] = dte[4 ] = dte[2 ] = dte[1 ] = dte[0 ] =0 ; flags = ivrs_dev->device_flags; - sys_mgt =get_field_from_byte (flags,ACPI_IVHD_SYSTEM_MGMT ); + sys_mgt =MASK_EXTR (flags,ACPI_IVHD_SYSTEM_MGMT ); dev_ex = ivrs_dev->dte_allow_exclusion; flags &= mask;xen/include/asm-x86/hvm/svm/amd-iommu-proto.h +0
-5@@ -155,11 +155,6 @@ static inline u32 set_field_in_reg_u32(u32 field, u32 reg_value,return reg_value; } -static inline u8 get_field_from_byte (u8 value,u8 mask) -{ -return (value & mask) / (mask & -mask); -} -static inline unsigned long region_to_pages (unsigned long addr,unsigned long size) {return (PAGE_ALIGN (addr + size) - (addr &PAGE_MASK )) >>PAGE_SHIFT ;Signature · 1 line
2.1.4
Signature · 6 lines
Brian Woods _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 2/2] x86/SVM-IOMMU: Drop get_field_from_byte()
In reply to Andrew CooperQuoted 5 lines · Andrew Cooper
It is
MASK_EXTR()in disguise, but less flexible.No functional change.
Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 12 lines
-----Original Message-----
From: Andrew Cooper [mailto:[email protected]]
Sent: 24 September 2018 11:55
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Jan Beulich <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>; Paul Durrant <[email protected]>; Suravee Suthikulpanit <[email protected]>; Brian Woods <[email protected]>
Subject: [PATCH 1/2] x86/SVM-IOMMU: Don't opencodememcpy()inqueue_iommu_command()
Quoted 4 lines
In practice, this allows the compiler to replace the loop with a pair of movs.
No functional change.
Well there is a potential functional change...
Quoted 33 lines
Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Suravee Suthikulpanit <[email protected]>
CC: Brian Woods <[email protected]>--- xen/drivers/passthrough/amd/iommu_cmd.c | 12 ++++-------- xen/include/asm-x86/hvm/svm/amd-iommu-defs.h | 1 - 2 files changed, 4 insertions(+), 9 deletions(-)xen/drivers/passthrough/amd/iommu_cmd.c +1
-2@@ -24,8 +24,7 @@static int queue_iommu_command (struct amd_iommu *iommu,u32 cmd[]) { -u32 tail, head, *cmd_buffer; -int i; +uint32_t tail, head; tail = iommu->cmd_buffer.tail;if ( ++tail == iommu->cmd_buffer.entries )@@ -35,12 +34,9 @@ static int queue_iommu_command(struct amd_iommu *iommu, u32 cmd[]) IOMMU_CMD_BUFFER_HEAD_OFFSET));if ( head != tail )
xen/drivers/passthrough/amd/iommu_cmd.c static int queue_iommu_command(struct amd_iommu *iommu, · line 40
Quoted 10 lines
xen/drivers/passthrough/amd/iommu_cmd.c +3
-6{ - cmd_buffer = (u32 *)(iommu->cmd_buffer.buffer + - (iommu->cmd_buffer.tail * -IOMMU_CMD_BUFFER_ENTRY_SIZE )); - -for ( i =0 ; i <IOMMU_CMD_BUFFER_U32_PER_ENTRY ; i++ ) - cmd_buffer[i] = cmd[i]; +memcpy (iommu->cmd_buffer.buffer + + (iommu->cmd_buffer.tail *IOMMU_CMD_BUFFER_ENTRY_SIZE ), + cmd,IOMMU_CMD_BUFFER_ENTRY_SIZE );
...since the built-in memcpy may not guarantee to the copy in 4 byte chunks in ascending order. As long as that change poses no danger (and seeing as the code contains no barrer-ing I'd assume that to be the case) then this change looks fine to me (with the 'no functional change' comment removed).
Quoted 16 lines
xen/drivers/passthrough/amd/iommu_cmd.c +0
-0iommu->cmd_buffer.tail = tail;return 1 ;xen/include/asm-x86/hvm/svm/amd-iommu-defs.h +0
-1@@ -187,7 +187,6 @@#define IOMMU_CMD_BUFFER_ENTRY_SIZE 16#define IOMMU_CMD_BUFFER_POWER_OF2_ENTRIES_PER_PAGE 8 -#define IOMMU_CMD_BUFFER_U32_PER_ENTRY (IOMMU_CMD_BUFFER_ENTRY_SIZE / 4)#define IOMMU_CMD_OPCODE_MASK 0xF0000000
Quoted 3 lines
#define
IOMMU_CMD_OPCODE_SHIFT28
--
2.1.4
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 53 lines · Paul Durrant
Quoted 12 lines
-----Original Message-----
From: Andrew Cooper [mailto:[email protected]]
Sent: 24 September 2018 11:55
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Jan Beulich <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>; Paul Durrant <[email protected]>; Suravee Suthikulpanit <[email protected]>; Brian Woods <[email protected]>
Subject: [PATCH 1/2] x86/SVM-IOMMU: Don't opencodememcpy()inqueue_iommu_command()Quoted 4 lines
In practice, this allows the compiler to replace the loop with a pair of movs.
No functional change.
Well there is a potential functional change...
Quoted 35 lines
Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Suravee Suthikulpanit <[email protected]>
CC: Brian Woods <[email protected]>--- xen/drivers/passthrough/amd/iommu_cmd.c | 12 ++++-------- xen/include/asm-x86/hvm/svm/amd-iommu-defs.h | 1 - 2 files changed, 4 insertions(+), 9 deletions(-)xen/drivers/passthrough/amd/iommu_cmd.c +1
-4@@ -24,8 +24,7 @@static int queue_iommu_command (struct amd_iommu *iommu,u32 cmd[]) { -u32 tail, head, *cmd_buffer; -int i; +uint32_t tail, head; tail = iommu->cmd_buffer.tail;if ( ++tail == iommu->cmd_buffer.entries )@@ -35,12 +34,9 @@ static int queue_iommu_command(struct amd_iommu *iommu, u32 cmd[]) IOMMU_CMD_BUFFER_HEAD_OFFSET));if ( head != tail ) { - cmd_buffer = (u32 *)(iommu->cmd_buffer.buffer + - (iommu->cmd_buffer.tail *
Quoted 8 lines
xen/drivers/passthrough/amd/iommu_cmd.c static int queue_iommu_command(struct amd_iommu *iommu, u32 cmd[]) · line 39
Quoted 7 lines
xen/drivers/passthrough/amd/iommu_cmd.c +3
-4- IOMMU_CMD_BUFFER_ENTRY_SIZE)); - -for ( i =0 ; i <IOMMU_CMD_BUFFER_U32_PER_ENTRY ; i++ ) - cmd_buffer[i] = cmd[i]; +memcpy (iommu->cmd_buffer.buffer + + (iommu->cmd_buffer.tail *IOMMU_CMD_BUFFER_ENTRY_SIZE ), + cmd,IOMMU_CMD_BUFFER_ENTRY_SIZE );...since the built-in memcpy may not guarantee to the copy in 4 byte chunks in ascending order.
"No functional change" != "The binary is identical".
The functionality of queue_iommu_command() does not change, even if it's code generation does. It is just copying bytes into a shared ring, bounded later by updating the tail pointer.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 74 lines
-----Original Message-----
From: Andrew Cooper
Sent: 24 September 2018 13:06
To: Paul Durrant <[email protected]>; Xen-devel <xen- [email protected]>
Cc: Jan Beulich <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>; Suravee Suthikulpanit <[email protected]>; Brian Woods <[email protected]>
Subject: Re: [PATCH 1/2] x86/SVM-IOMMU: Don't opencodememcpy()inqueue_iommu_command()Quoted 12 lines · Paul Durrant
Quoted 12 lines
-----Original Message-----
From: Andrew Cooper [mailto:[email protected]]
Sent: 24 September 2018 11:55
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Jan Beulich <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>; Paul Durrant <[email protected]>; Suravee Suthikulpanit <[email protected]>; Brian Woods <[email protected]>
Subject: [PATCH 1/2] x86/SVM-IOMMU: Don't opencodememcpy()inqueue_iommu_command()Quoted 1 line
Quoted 1 line
In practice, this allows the compiler to replace the loop with a pair
of
Quoted 31 lines
Quoted 3 lines
movs.
No functional change.
Well there is a potential functional change...
Quoted 26 lines
Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Suravee Suthikulpanit <[email protected]>
CC: Brian Woods <[email protected]>--- xen/drivers/passthrough/amd/iommu_cmd.c | 12 ++++-------- xen/include/asm-x86/hvm/svm/amd-iommu-defs.h | 1 - 2 files changed, 4 insertions(+), 9 deletions(-)xen/drivers/passthrough/amd/iommu_cmd.c +1
-2@@ -24,8 +24,7 @@static int queue_iommu_command (struct amd_iommu *iommu,u32 cmd[]) { -u32 tail, head, *cmd_buffer; -int i; +uint32_t tail, head;Quoted 3 lines
xen/drivers/passthrough/amd/iommu_cmd.c static int queue_iommu_command(struct amd_iommu
Quoted 3 lines
xen/drivers/passthrough/amd/iommu_cmd.c +0
-0tail = iommu->cmd_buffer.tail;if ( ++tail == iommu->cmd_buffer.entries )@@ -35,12 +34,9 @@ static int queue_iommu_command(struct amd_iommu*iommu,
Quoted 13 lines
Quoted 13 lines
xen/drivers/passthrough/amd/iommu_cmd.c +3
-6u32 cmd[]) IOMMU_CMD_BUFFER_HEAD_OFFSET));if ( head != tail ) { - cmd_buffer = (u32 *)(iommu->cmd_buffer.buffer + - (iommu->cmd_buffer.tail * -IOMMU_CMD_BUFFER_ENTRY_SIZE )); - -for ( i =0 ; i <IOMMU_CMD_BUFFER_U32_PER_ENTRY ; i++ ) - cmd_buffer[i] = cmd[i]; +memcpy (iommu->cmd_buffer.buffer + + (iommu->cmd_buffer.tail *IOMMU_CMD_BUFFER_ENTRY_SIZE ), + cmd,IOMMU_CMD_BUFFER_ENTRY_SIZE );
Quoted 8 lines
Quoted 1 line
...since the built-in memcpy may not guarantee to the copy in 4 byte
chunks in ascending order.
"No functional change" != "The binary is identical".
The functionality of
queue_iommu_command()does not change, even if it's code generation does. It is just copying bytes into a shared ring, bounded later by updating the tail pointer.
Yes, my point is that the ring is shared and so DMA by the h/w may race. This is clearly not a good situation but the fact that the code generation may change may have side effects.
Paul
Quoted 2 lines
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 80 lines
Quoted 80 lines
Quoted 1 line · On 24.09.18 at 14:09, <[email protected]> wrote:
-----Original Message-----
From: Andrew Cooper
Sent: 24 September 2018 13:06
To: Paul Durrant <[email protected]>; Xen-devel <xen- [email protected]>
Cc: Jan Beulich <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>; Suravee Suthikulpanit <[email protected]>; Brian Woods <[email protected]>
Subject: Re: [PATCH 1/2] x86/SVM-IOMMU: Don't opencodememcpy()inqueue_iommu_command()Quoted 12 lines · Paul Durrant
Quoted 12 lines
-----Original Message-----
From: Andrew Cooper [mailto:[email protected]]
Sent: 24 September 2018 11:55
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Jan Beulich <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>; Paul Durrant <[email protected]>; Suravee Suthikulpanit <[email protected]>; Brian Woods <[email protected]>
Subject: [PATCH 1/2] x86/SVM-IOMMU: Don't opencodememcpy()inqueue_iommu_command()Quoted 1 line
Quoted 1 line
In practice, this allows the compiler to replace the loop with a pair
of
Quoted 31 lines
Quoted 3 lines
movs.
No functional change.
Well there is a potential functional change...
Quoted 26 lines
Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Suravee Suthikulpanit <[email protected]>
CC: Brian Woods <[email protected]>--- xen/drivers/passthrough/amd/iommu_cmd.c | 12 ++++-------- xen/include/asm-x86/hvm/svm/amd-iommu-defs.h | 1 - 2 files changed, 4 insertions(+), 9 deletions(-)xen/drivers/passthrough/amd/iommu_cmd.c +1
-2@@ -24,8 +24,7 @@static int queue_iommu_command (struct amd_iommu *iommu,u32 cmd[]) { -u32 tail, head, *cmd_buffer; -int i; +uint32_t tail, head;Quoted 3 lines
xen/drivers/passthrough/amd/iommu_cmd.c static int queue_iommu_command(struct amd_iommu
Quoted 3 lines
xen/drivers/passthrough/amd/iommu_cmd.c +0
-0tail = iommu->cmd_buffer.tail;if ( ++tail == iommu->cmd_buffer.entries )@@ -35,12 +34,9 @@ static int queue_iommu_command(struct amd_iommu*iommu,
Quoted 13 lines
xen/drivers/passthrough/amd/iommu_cmd.c static int queue_iommu_command(struct amd_iommu *iommu, u32 cmd[]) · line 39
Quoted 13 lines
xen/drivers/passthrough/amd/iommu_cmd.c +3
-6u32 cmd[]) IOMMU_CMD_BUFFER_HEAD_OFFSET));if ( head != tail ) { - cmd_buffer = (u32 *)(iommu->cmd_buffer.buffer + - (iommu->cmd_buffer.tail * -IOMMU_CMD_BUFFER_ENTRY_SIZE )); - -for ( i =0 ; i <IOMMU_CMD_BUFFER_U32_PER_ENTRY ; i++ ) - cmd_buffer[i] = cmd[i]; +memcpy (iommu->cmd_buffer.buffer + + (iommu->cmd_buffer.tail *IOMMU_CMD_BUFFER_ENTRY_SIZE ), + cmd,IOMMU_CMD_BUFFER_ENTRY_SIZE );Quoted 1 line
...since the built-in memcpy may not guarantee to the copy in 4 byte
chunks in ascending order.
"No functional change" != "The binary is identical".
Quoted 7 lines
Quoted 3 lines
The functionality of
queue_iommu_command()does not change, even if it's code generation does. It is just copying bytes into a shared ring, bounded later by updating the tail pointer.Yes, my point is that the ring is shared and so DMA by the h/w may race. This is clearly not a good situation but the fact that the code generation may change may have side effects.
All writes to the ring occur strictly before the update of the tail pointer (in MMIO), no matter how the copying gets done.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 101 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 24 September 2018 13:16
To: Paul Durrant <[email protected]>
Cc: Brian Woods <[email protected]>; Suravee Suthikulpanit <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monne <[email protected]>; Wei Liu <[email protected]>; Xen-devel <[email protected]>
Subject: RE: [PATCH 1/2] x86/SVM-IOMMU: Don't opencodememcpy()inqueue_iommu_command()Quoted 7 lines
Quoted 7 lines
Quoted 1 line · On 24.09.18 at 14:09, <[email protected]> wrote:
-----Original Message-----
From: Andrew Cooper
Sent: 24 September 2018 13:06
To: Paul Durrant <[email protected]>; Xen-devel <xen- [email protected]>
Cc: Jan Beulich <[email protected]>; Wei Liu <[email protected]>;Roger
Quoted 5 lines
Quoted 5 lines
Pau Monne <[email protected]>; Suravee Suthikulpanit <[email protected]>; Brian Woods <[email protected]>
Subject: Re: [PATCH 1/2] x86/SVM-IOMMU: Don't opencodememcpy()inqueue_iommu_command()Quoted 8 lines
Quoted 8 lines · Paul Durrant
Quoted 7 lines
Quoted 7 lines
-----Original Message-----
From: Andrew Cooper [mailto:[email protected]]
Sent: 24 September 2018 11:55
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Jan Beulich <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>; Paul Durrant <[email protected]>;Suravee
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Suthikulpanit <[email protected]>; Brian Woods <[email protected]>
Subject: [PATCH 1/2] x86/SVM-IOMMU: Don't opencodememcpy()inqueue_iommu_command()In practice, this allows the compiler to replace the loop with a
pair
Quoted 32 lines
Quoted 32 lines
of
Quoted 31 lines
Quoted 3 lines
movs.
No functional change.
Well there is a potential functional change...
Quoted 26 lines
Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Suravee Suthikulpanit <[email protected]>
CC: Brian Woods <[email protected]>--- xen/drivers/passthrough/amd/iommu_cmd.c | 12 ++++-------- xen/include/asm-x86/hvm/svm/amd-iommu-defs.h | 1 - 2 files changed, 4 insertions(+), 9 deletions(-)xen/drivers/passthrough/amd/iommu_cmd.c +1
-2@@ -24,8 +24,7 @@static int queue_iommu_command (struct amd_iommu *iommu,u32 cmd[]) { -u32 tail, head, *cmd_buffer; -int i; +uint32_t tail, head;Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
xen/drivers/passthrough/amd/iommu_cmd.c static int queue_iommu_command(struct amd_iommu
Quoted 3 lines
xen/drivers/passthrough/amd/iommu_cmd.c +0
-0tail = iommu->cmd_buffer.tail;if ( ++tail == iommu->cmd_buffer.entries )@@ -35,12 +34,9 @@ static int queue_iommu_command(struct amd_iommu*iommu,
Quoted 2 lines
Quoted 2 lines
xen/drivers/passthrough/amd/iommu_cmd.c +0
-0u32 cmd[])
IOMMU_CMD_BUFFER_HEAD_OFFSET));Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
xen/drivers/passthrough/amd/iommu_cmd.c static int queue_iommu_command(struct amd_iommu *iommu, u32 cmd[])
Quoted 10 lines
xen/drivers/passthrough/amd/iommu_cmd.c +2
-6if ( head != tail ) { - cmd_buffer = (u32 *)(iommu->cmd_buffer.buffer + - (iommu->cmd_buffer.tail * -IOMMU_CMD_BUFFER_ENTRY_SIZE )); - -for ( i =0 ; i <IOMMU_CMD_BUFFER_U32_PER_ENTRY ; i++ ) - cmd_buffer[i] = cmd[i]; + memcpy(iommu->cmd_buffer.buffer + + (iommu->cmd_buffer.tail *
IOMMU_CMD_BUFFER_ENTRY_SIZE),Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
xen/drivers/passthrough/amd/iommu_cmd.c static int queue_iommu_command(struct amd_iommu *iommu, u32 cmd[]) · line 39
Quoted 1 line
xen/drivers/passthrough/amd/iommu_cmd.c +1
-0+ cmd, IOMMU_CMD_BUFFER_ENTRY_SIZE);...since the built-in memcpy may not guarantee to the copy in 4 byte
chunks in ascending order.
"No functional change" != "The binary is identical".
The functionality of
queue_iommu_command()does not change, even ifit's
Quoted 3 lines
Quoted 2 lines
code generation does. It is just copying bytes into a shared ring, bounded later by updating the tail pointer.
Quoted 7 lines
Quoted 2 lines
Yes, my point is that the ring is shared and so DMA by the h/w may race. This is clearly not a good situation but the fact that the code
generation
Quoted 1 line
may change may have side effects.
All writes to the ring occur strictly before the update of the tail pointer
...unless the compiler decides to re-order. There's no barrier.
Paul
Quoted 3 lines
(in MMIO), no matter how the copying gets done.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 100 lines · Paul Durrant
Quoted 100 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 24 September 2018 13:16
To: Paul Durrant <[email protected]>
Cc: Brian Woods <[email protected]>; Suravee Suthikulpanit <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monne <[email protected]>; Wei Liu <[email protected]>; Xen-devel <[email protected]>
Subject: RE: [PATCH 1/2] x86/SVM-IOMMU: Don't opencodememcpy()inqueue_iommu_command()Quoted 7 lines
Quoted 7 lines
Quoted 1 line · On 24.09.18 at 14:09, <[email protected]> wrote:
-----Original Message-----
From: Andrew Cooper
Sent: 24 September 2018 13:06
To: Paul Durrant <[email protected]>; Xen-devel <xen- [email protected]>
Cc: Jan Beulich <[email protected]>; Wei Liu <[email protected]>;Roger
Quoted 5 lines
Quoted 5 lines
Pau Monne <[email protected]>; Suravee Suthikulpanit <[email protected]>; Brian Woods <[email protected]>
Subject: Re: [PATCH 1/2] x86/SVM-IOMMU: Don't opencodememcpy()inqueue_iommu_command()Quoted 8 lines
Quoted 8 lines · Paul Durrant
Quoted 7 lines
Quoted 7 lines
-----Original Message-----
From: Andrew Cooper [mailto:[email protected]]
Sent: 24 September 2018 11:55
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Jan Beulich <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>; Paul Durrant <[email protected]>;Suravee
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Suthikulpanit <[email protected]>; Brian Woods <[email protected]>
Subject: [PATCH 1/2] x86/SVM-IOMMU: Don't opencodememcpy()inqueue_iommu_command()In practice, this allows the compiler to replace the loop with a
pair
Quoted 32 lines
Quoted 32 lines
of
Quoted 31 lines
Quoted 3 lines
movs.
No functional change.
Well there is a potential functional change...
Quoted 26 lines
Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Suravee Suthikulpanit <[email protected]>
CC: Brian Woods <[email protected]>--- xen/drivers/passthrough/amd/iommu_cmd.c | 12 ++++-------- xen/include/asm-x86/hvm/svm/amd-iommu-defs.h | 1 - 2 files changed, 4 insertions(+), 9 deletions(-)xen/drivers/passthrough/amd/iommu_cmd.c +1
-2@@ -24,8 +24,7 @@static int queue_iommu_command (struct amd_iommu *iommu,u32 cmd[]) { -u32 tail, head, *cmd_buffer; -int i; +uint32_t tail, head;Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
xen/drivers/passthrough/amd/iommu_cmd.c static int queue_iommu_command(struct amd_iommu
Quoted 3 lines
xen/drivers/passthrough/amd/iommu_cmd.c +0
-0tail = iommu->cmd_buffer.tail;if ( ++tail == iommu->cmd_buffer.entries )@@ -35,12 +34,9 @@ static int queue_iommu_command(struct amd_iommu*iommu,
Quoted 2 lines
Quoted 2 lines
xen/drivers/passthrough/amd/iommu_cmd.c +0
-0u32 cmd[])
IOMMU_CMD_BUFFER_HEAD_OFFSET));Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
xen/drivers/passthrough/amd/iommu_cmd.c static int queue_iommu_command(struct amd_iommu *iommu, u32 cmd[])
Quoted 10 lines
xen/drivers/passthrough/amd/iommu_cmd.c +2
-6if ( head != tail ) { - cmd_buffer = (u32 *)(iommu->cmd_buffer.buffer + - (iommu->cmd_buffer.tail * -IOMMU_CMD_BUFFER_ENTRY_SIZE )); - -for ( i =0 ; i <IOMMU_CMD_BUFFER_U32_PER_ENTRY ; i++ ) - cmd_buffer[i] = cmd[i]; + memcpy(iommu->cmd_buffer.buffer + + (iommu->cmd_buffer.tail *
IOMMU_CMD_BUFFER_ENTRY_SIZE),Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
xen/drivers/passthrough/amd/iommu_cmd.c static int queue_iommu_command(struct amd_iommu *iommu, u32 cmd[]) · line 39
Quoted 1 line
xen/drivers/passthrough/amd/iommu_cmd.c +1
-0+ cmd, IOMMU_CMD_BUFFER_ENTRY_SIZE);...since the built-in memcpy may not guarantee to the copy in 4 byte
chunks in ascending order.
"No functional change" != "The binary is identical".
The functionality of
queue_iommu_command()does not change, even ifit's
Quoted 2 lines
Quoted 2 lines
code generation does. It is just copying bytes into a shared ring, bounded later by updating the tail pointer.
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
Yes, my point is that the ring is shared and so DMA by the h/w may race. This is clearly not a good situation but the fact that the code
generation
Quoted 1 line
may change may have side effects.
All writes to the ring occur strictly before the update of the tail pointer
...unless the compiler decides to re-order. There's no barrier.
/sigh - You're right, but the code was equally buggy beforehand.
readl()/writel() aren't suitable for how they are used by this code.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 115 lines
-----Original Message-----
From: Andrew Cooper
Sent: 24 September 2018 13:25
To: Paul Durrant <[email protected]>; 'Jan Beulich' <[email protected]>
Cc: Brian Woods <[email protected]>; Suravee Suthikulpanit <[email protected]>; Roger Pau Monne <[email protected]>; Wei Liu <[email protected]>; Xen-devel <[email protected]>
Subject: Re: [PATCH 1/2] x86/SVM-IOMMU: Don't opencodememcpy()inqueue_iommu_command()Quoted 7 lines · Paul Durrant
Quoted 7 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 24 September 2018 13:16
To: Paul Durrant <[email protected]>
Cc: Brian Woods <[email protected]>; Suravee Suthikulpanit <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monne <[email protected]>;Wei
Quoted 87 lines
Quoted 87 lines
Liu <[email protected]>; Xen-devel <[email protected]>
Subject: RE: [PATCH 1/2] x86/SVM-IOMMU: Don't opencodememcpy()inqueue_iommu_command()Quoted 7 lines
Quoted 7 lines
Quoted 1 line · On 24.09.18 at 14:09, <[email protected]> wrote:
-----Original Message-----
From: Andrew Cooper
Sent: 24 September 2018 13:06
To: Paul Durrant <[email protected]>; Xen-devel <xen- [email protected]>
Cc: Jan Beulich <[email protected]>; Wei Liu <[email protected]>;Roger
Quoted 5 lines
Quoted 5 lines
Pau Monne <[email protected]>; Suravee Suthikulpanit <[email protected]>; Brian Woods <[email protected]>
Subject: Re: [PATCH 1/2] x86/SVM-IOMMU: Don't opencodememcpy()inqueue_iommu_command()Quoted 8 lines
Quoted 8 lines · Paul Durrant
Quoted 7 lines
Quoted 7 lines
-----Original Message-----
From: Andrew Cooper [mailto:[email protected]]
Sent: 24 September 2018 11:55
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Jan Beulich <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>; Paul Durrant <[email protected]>;Suravee
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Suthikulpanit <[email protected]>; Brian Woods <[email protected]>
Subject: [PATCH 1/2] x86/SVM-IOMMU: Don't opencodememcpy()inqueue_iommu_command()In practice, this allows the compiler to replace the loop with a
pair
Quoted 32 lines
Quoted 32 lines
of
Quoted 31 lines
Quoted 3 lines
movs.
No functional change.
Well there is a potential functional change...
Quoted 26 lines
Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Suravee Suthikulpanit <[email protected]>
CC: Brian Woods <[email protected]>--- xen/drivers/passthrough/amd/iommu_cmd.c | 12 ++++-------- xen/include/asm-x86/hvm/svm/amd-iommu-defs.h | 1 - 2 files changed, 4 insertions(+), 9 deletions(-)xen/drivers/passthrough/amd/iommu_cmd.c +1
-2@@ -24,8 +24,7 @@static int queue_iommu_command (struct amd_iommu *iommu,u32 cmd[]) { -u32 tail, head, *cmd_buffer; -int i; +uint32_t tail, head;Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
xen/drivers/passthrough/amd/iommu_cmd.c static int queue_iommu_command(struct amd_iommu
Quoted 3 lines
xen/drivers/passthrough/amd/iommu_cmd.c +0
-0tail = iommu->cmd_buffer.tail;if ( ++tail == iommu->cmd_buffer.entries )@@ -35,12 +34,9 @@ static int queue_iommu_command(struct amd_iommu*iommu,
Quoted 2 lines
Quoted 2 lines
xen/drivers/passthrough/amd/iommu_cmd.c +0
-0u32 cmd[])
IOMMU_CMD_BUFFER_HEAD_OFFSET));Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
xen/drivers/passthrough/amd/iommu_cmd.c static int queue_iommu_command(struct amd_iommu · line 39
Quoted 10 lines
xen/drivers/passthrough/amd/iommu_cmd.c +2
-6if ( head != tail ) { - cmd_buffer = (u32 *)(iommu->cmd_buffer.buffer + - (iommu->cmd_buffer.tail * -IOMMU_CMD_BUFFER_ENTRY_SIZE )); - -for ( i =0 ; i <IOMMU_CMD_BUFFER_U32_PER_ENTRY ; i++ ) - cmd_buffer[i] = cmd[i]; + memcpy(iommu->cmd_buffer.buffer + + (iommu->cmd_buffer.tail *
IOMMU_CMD_BUFFER_ENTRY_SIZE),Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
xen/drivers/passthrough/amd/iommu_cmd.c static int queue_iommu_command(struct amd_iommu · line 40
Quoted 1 line
xen/drivers/passthrough/amd/iommu_cmd.c +1
-0+ cmd, IOMMU_CMD_BUFFER_ENTRY_SIZE);...since the built-in memcpy may not guarantee to the copy in 4 byte
chunks in ascending order.
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
"No functional change" != "The binary is identical".
The functionality of
queue_iommu_command()does not change, even ifit's
Quoted 3 lines
Quoted 2 lines
code generation does. It is just copying bytes into a shared ring, bounded later by updating the tail pointer.
Yes, my point is that the ring is shared and so DMA by the h/w may
race.
Quoted 9 lines
Quoted 6 lines
Quoted 5 lines
Quoted 1 line
This is clearly not a good situation but the fact that the code
generation
Quoted 1 line
may change may have side effects.
All writes to the ring occur strictly before the update of the tail pointer
...unless the compiler decides to re-order. There's no barrier.
/sigh - You're right, but the code was equally buggy beforehand.
Indeed, so there is the potential for functional change. I don't care that much though... someone mining for commits in future probably won't either.
Paul
Quoted 3 lines
readl()/writel() aren't suitable for how they are used by this code.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 8 lines
Quoted 6 lines
Quoted 1 line · On 24.09.18 at 14:18, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Sent: 24 September 2018 13:16All writes to the ring occur strictly before the update of the tail pointer
...unless the compiler decides to re-order. There's no barrier.
But there is (an implied) one, inside writel() (due to the "volatile"). Everything ahead of the writel() invocation may be stored in any order.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 17 lines · Paul Durrant
Quoted 17 lines
Quoted 2 lines
Review static int queue_iommu_command(struct amd_iommu
Quoted 2 lines
(quoted diff) +0
-0@@ -35,12 +34,9 @@ static int queue_iommu_command(struct amd_iommu*iommu,
Quoted 14 lines
xen/drivers/passthrough/amd/iommu_cmd.c static int queue_iommu_command(struct amd_iommu *iommu, u32 cmd[]) · line 39
Quoted 13 lines
xen/drivers/passthrough/amd/iommu_cmd.c +3
-6u32 cmd[]) IOMMU_CMD_BUFFER_HEAD_OFFSET));if ( head != tail ) { - cmd_buffer = (u32 *)(iommu->cmd_buffer.buffer + - (iommu->cmd_buffer.tail * -IOMMU_CMD_BUFFER_ENTRY_SIZE )); - -for ( i =0 ; i <IOMMU_CMD_BUFFER_U32_PER_ENTRY ; i++ ) - cmd_buffer[i] = cmd[i]; +memcpy (iommu->cmd_buffer.buffer + + (iommu->cmd_buffer.tail *IOMMU_CMD_BUFFER_ENTRY_SIZE ), + cmd,IOMMU_CMD_BUFFER_ENTRY_SIZE );...since the built-in memcpy may not guarantee to the copy in 4 byte
Quoted 8 lines
Quoted 7 lines
chunks in ascending order.
"No functional change" != "The binary is identical".
The functionality of
queue_iommu_command()does not change, even if it's code generation does. It is just copying bytes into a shared ring, bounded later by updating the tail pointer.Yes, my point is that the ring is shared and so DMA by the h/w may race. This is clearly not a good situation but the fact that the code generation may change may have side effects.
This is writing past the tail pointer, and then updating the tail pointer to match.
Hardware conforming to the spec won't read any of the data until it is all ready.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 15 lines
Quoted 15 lines
Quoted 1 line · On 24.09.18 at 13:59, <[email protected]> wrote:
From: Andrew Cooper [mailto:[email protected]]
Sent: 24 September 2018 11:55xen/drivers/passthrough/amd/iommu_cmd.c +0
-6@@ -35,12 +34,9 @@ static int queue_iommu_command(struct amd_iommu *iommu, u32 cmd[]) IOMMU_CMD_BUFFER_HEAD_OFFSET));if ( head != tail ) { - cmd_buffer = (u32 *)(iommu->cmd_buffer.buffer + - (iommu->cmd_buffer.tail * -IOMMU_CMD_BUFFER_ENTRY_SIZE )); - -for ( i =0 ; i <IOMMU_CMD_BUFFER_U32_PER_ENTRY ; i++ ) - cmd_buffer[i] = cmd[i];
Quoted 8 lines
xen/drivers/passthrough/amd/iommu_cmd.c static int queue_iommu_command(struct amd_iommu *iommu, u32 cmd[]) · line 39
Quoted 3 lines
xen/drivers/passthrough/amd/iommu_cmd.c +3
-0+memcpy (iommu->cmd_buffer.buffer + + (iommu->cmd_buffer.tail *IOMMU_CMD_BUFFER_ENTRY_SIZE ), + cmd,IOMMU_CMD_BUFFER_ENTRY_SIZE );...since the built-in memcpy may not guarantee to the copy in 4 byte chunks in ascending order. As long as that change poses no danger (and seeing as the code contains no barrer-ing I'd assume that to be the case) then this change looks fine to me (with the 'no functional change' comment removed).
I don't think the compiler is required to translate the original loop to accesses of 4 bytes in ascending order, so I think I agree with Andrew's "no functional change".
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 24.09.18 at 12:55, <[email protected]> wrote:
In practice, this allows the compiler to replace the loop with a pair of movs.
I'm surprised the compiler doesn't recognize this opportunity anyway.
Quoted 3 lines
No functional change.
Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 5 lines · Andy Cooper
In practice, this allows the compiler to replace the loop with a pair of movs.
No functional change.
Signed-off-by Andrew Cooper <[email protected]>
Quoted 57 lines
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Suravee Suthikulpanit <[email protected]>
CC: Brian Woods <[email protected]>--- xen/drivers/passthrough/amd/iommu_cmd.c | 12 ++++-------- xen/include/asm-x86/hvm/svm/amd-iommu-defs.h | 1 - 2 files changed, 4 insertions(+), 9 deletions(-)xen/drivers/passthrough/amd/iommu_cmd.c +4
-8@@ -24,8 +24,7 @@static int queue_iommu_command (struct amd_iommu *iommu,u32 cmd[]) { -u32 tail, head, *cmd_buffer; -int i; +uint32_t tail, head; tail = iommu->cmd_buffer.tail;if ( ++tail == iommu->cmd_buffer.entries )@@ -35,12 +34,9 @@ static int queue_iommu_command(struct amd_iommu *iommu, u32 cmd[]) IOMMU_CMD_BUFFER_HEAD_OFFSET));if ( head != tail ) { - cmd_buffer = (u32 *)(iommu->cmd_buffer.buffer + - (iommu->cmd_buffer.tail * -IOMMU_CMD_BUFFER_ENTRY_SIZE )); - -for ( i =0 ; i <IOMMU_CMD_BUFFER_U32_PER_ENTRY ; i++ ) - cmd_buffer[i] = cmd[i]; +memcpy (iommu->cmd_buffer.buffer + + (iommu->cmd_buffer.tail *IOMMU_CMD_BUFFER_ENTRY_SIZE ), + cmd,IOMMU_CMD_BUFFER_ENTRY_SIZE ); iommu->cmd_buffer.tail = tail;return 1 ;xen/include/asm-x86/hvm/svm/amd-iommu-defs.h +0
-1@@ -187,7 +187,6 @@#define IOMMU_CMD_BUFFER_ENTRY_SIZE 16#define IOMMU_CMD_BUFFER_POWER_OF2_ENTRIES_PER_PAGE 8 -#define IOMMU_CMD_BUFFER_U32_PER_ENTRY (IOMMU_CMD_BUFFER_ENTRY_SIZE / 4)#define IOMMU_CMD_OPCODE_MASK 0xF0000000#define IOMMU_CMD_OPCODE_SHIFT 28Signature · 1 line
2.1.4
Signature · 6 lines
Brian Woods _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 5 lines · Andrew Cooper
In practice, this allows the compiler to replace the loop with a pair of movs.
No functional change.
Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel