x86/vMSI-X: further write snoop improvements
cover x86/vMSI-X: further write snoop improvements
1: add further checks to snoop logic
2: also snoop qword writes
3: also snoop REP MOVS
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH 1/3 x86/vMSI-X: add further checks to snoop logic
msixtbl_range(), as any other MMIO ->check() handlers, may get called with other than the base address of an access - avoid the snoop logic considering those.
Also avoid considering vCPU-s not blocked in the hypervisor in msixtbl_pt_register(), just to be on the safe side.
xen/arch/x86/hvm/vmsi.c +3 -2
@@ -349,7 +349,7 @@ static int msixtbl_range(struct vcpu *v, {const ioreq_t *r = &v->arch.hvm_vcpu.hvm_io.io_req; -if ( r->state !=STATE_IOREQ_READY ) +if ( r->state !=STATE_IOREQ_READY || r->addr != addr )return 0 ;ASSERT (r->type ==IOREQ_TYPE_COPY ); if ( r->dir == IOREQ_WRITE && r->size == 4 && !r->data_is_ptr
@@ -457,7 +457,8 @@ out: for_each_vcpu ( d, v ) { -if ( v->arch.hvm_vcpu.hvm_io.msix_snoop_address == +if ( (v->pause_flags & VPF_blocked_in_xen) && + v->arch.hvm_vcpu.hvm_io.msix_snoop_address == (gtable + msi_desc->msi_attrib.entry_nr *PCI_MSIX_ENTRY_SIZE +PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET ) )
x86/vMSI-X: add further checks to snoop logic
msixtbl_range(), as any other MMIO ->check() handlers, may get called with other than the base address of an access - avoid the snoop logic considering those.
Also avoid considering vCPU-s not blocked in the hypervisor in msixtbl_pt_register(), just to be on the safe side.
xen/arch/x86/hvm/vmsi.c +3 -2
@@ -349,7 +349,7 @@ static int msixtbl_range(struct vcpu *v, {const ioreq_t *r = &v->arch.hvm_vcpu.hvm_io.io_req; -if ( r->state !=STATE_IOREQ_READY ) +if ( r->state !=STATE_IOREQ_READY || r->addr != addr )return 0 ;ASSERT (r->type ==IOREQ_TYPE_COPY ); if ( r->dir == IOREQ_WRITE && r->size == 4 && !r->data_is_ptr
@@ -457,7 +457,8 @@ out: for_each_vcpu ( d, v ) { -if ( v->arch.hvm_vcpu.hvm_io.msix_snoop_address == +if ( (v->pause_flags & VPF_blocked_in_xen) && + v->arch.hvm_vcpu.hvm_io.msix_snoop_address == (gtable + msi_desc->msi_attrib.entry_nr *PCI_MSIX_ENTRY_SIZE +PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET ) )
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 1/3] x86/vMSI-X: add further checks to snoop logic
Quoted 8 lines · Jan Beulich
msixtbl_range(), as any other MMIO ->check() handlers, may get called with other than the base address of an access - avoid the snoop logic considering those.Also avoid considering vCPU-s not blocked in the hypervisor in
msixtbl_pt_register(), just to be on the safe side.Signed-off-by Jan Beulich <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 1/3] x86/vMSI-X: add further checks to snoop logic
In reply to Jan BeulichQuoted 7 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 28 April 2016 10:49
To: xen-devel
Cc: Andrew Cooper; Paul Durrant
Subject: [PATCH 1/3] x86/vMSI-X: add further checks to snoop logic
Quoted 8 lines
msixtbl_range(), as any other MMIO ->check() handlers, may get called with other than the base address of an access - avoid the snoop logic considering those.Also avoid considering vCPU-s not blocked in the hypervisor in
msixtbl_pt_register(), just to be on the safe side.Signed-off-by Jan Beulich <[email protected]>
Quoted 15 lines
xen/arch/x86/hvm/vmsi.c +1
-1@@ -349,7 +349,7 @@ static int msixtbl_range(struct vcpu *v, {const ioreq_t *r = &v->arch.hvm_vcpu.hvm_io.io_req; -if ( r->state !=STATE_IOREQ_READY ) +if ( r->state !=STATE_IOREQ_READY || r->addr != addr )return 0 ;ASSERT (r->type ==IOREQ_TYPE_COPY ); if ( r->dir == IOREQ_WRITE && r->size == 4 && !r->data_is_ptr
xen/arch/x86/hvm/vmsi.c out: · line 464
Quoted 9 lines
xen/arch/x86/hvm/vmsi.c +2
-1@@ -457,7 +457,8 @@ out: for_each_vcpu ( d, v ) { -if ( v->arch.hvm_vcpu.hvm_io.msix_snoop_address == +if ( (v->pause_flags & VPF_blocked_in_xen) && + v->arch.hvm_vcpu.hvm_io.msix_snoop_address == (gtable + msi_desc->msi_attrib.entry_nr *PCI_MSIX_ENTRY_SIZE +PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET ) )
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH 2/3 x86/vMSI-X: also snoop qword writes
In reply to Jan Beulich... the high half of which may be a write to the Vector Control field. This gets things in sync again with msixtbl_write().
xen/arch/x86/hvm/vmsi.c +22 -9
@@ -336,6 +336,7 @@ out:static int msixtbl_range (struct vcpu *v,unsigned long addr) {const struct msi_desc *desc; +const ioreq_t *r;rcu_read_lock (&msixtbl_rcu_lock); desc =msixtbl_addr_to_desc (msixtbl_find_entry (v, addr), addr);
@@ -344,17 +345,29 @@ static int msixtbl_range(struct vcpu *v,if ( desc )return 1 ; -if ( (addr & (PCI_MSIX_ENTRY_SIZE -1 )) == -PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET ) + r = &v->arch.hvm_vcpu.hvm_io.io_req; +if ( r->state !=STATE_IOREQ_READY || r->addr != addr ) +return 0 ; +ASSERT (r->type ==IOREQ_TYPE_COPY ); +if ( r->dir ==IOREQ_WRITE ) { -const ioreq_t *r = &v->arch.hvm_vcpu.hvm_io.io_req; +if ( !r->data_is_ptr ) + { +unsigned int size = r->size; +uint64_t data = r->data; -if ( r->state !=STATE_IOREQ_READY || r->addr != addr ) -return 0 ; -ASSERT (r->type ==IOREQ_TYPE_COPY ); -if ( r->dir ==IOREQ_WRITE && r->size ==4 && !r->data_is_ptr - && !(r->data &PCI_MSIX_VECTOR_BITMASK ) ) - v->arch.hvm_vcpu.hvm_io.msix_snoop_address = addr; +if ( size ==8 ) + { +BUILD_BUG_ON (!(PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET &4 )); + data >>=32 ; + addr += size =4 ; + } +if ( size ==4 && + ((addr & (PCI_MSIX_ENTRY_SIZE -1 )) == +PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET ) && + !(data &PCI_MSIX_VECTOR_BITMASK ) ) + v->arch.hvm_vcpu.hvm_io.msix_snoop_address = addr; + } }return 0 ;
x86/vMSI-X: also snoop qword writes
... the high half of which may be a write to the Vector Control field. This gets things in sync again with msixtbl_write().
xen/arch/x86/hvm/vmsi.c +22 -9
@@ -336,6 +336,7 @@ out:static int msixtbl_range (struct vcpu *v,unsigned long addr) {const struct msi_desc *desc; +const ioreq_t *r;rcu_read_lock (&msixtbl_rcu_lock); desc =msixtbl_addr_to_desc (msixtbl_find_entry (v, addr), addr);
@@ -344,17 +345,29 @@ static int msixtbl_range(struct vcpu *v,if ( desc )return 1 ; -if ( (addr & (PCI_MSIX_ENTRY_SIZE -1 )) == -PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET ) + r = &v->arch.hvm_vcpu.hvm_io.io_req; +if ( r->state !=STATE_IOREQ_READY || r->addr != addr ) +return 0 ; +ASSERT (r->type ==IOREQ_TYPE_COPY ); +if ( r->dir ==IOREQ_WRITE ) { -const ioreq_t *r = &v->arch.hvm_vcpu.hvm_io.io_req; +if ( !r->data_is_ptr ) + { +unsigned int size = r->size; +uint64_t data = r->data; -if ( r->state !=STATE_IOREQ_READY || r->addr != addr ) -return 0 ; -ASSERT (r->type ==IOREQ_TYPE_COPY ); -if ( r->dir ==IOREQ_WRITE && r->size ==4 && !r->data_is_ptr - && !(r->data &PCI_MSIX_VECTOR_BITMASK ) ) - v->arch.hvm_vcpu.hvm_io.msix_snoop_address = addr; +if ( size ==8 ) + { +BUILD_BUG_ON (!(PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET &4 )); + data >>=32 ; + addr += size =4 ; + } +if ( size ==4 && + ((addr & (PCI_MSIX_ENTRY_SIZE -1 )) == +PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET ) && + !(data &PCI_MSIX_VECTOR_BITMASK ) ) + v->arch.hvm_vcpu.hvm_io.msix_snoop_address = addr; + } }return 0 ;
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 2/3] x86/vMSI-X: also snoop qword writes
Quoted 4 lines · Jan Beulich
... the high half of which may be a write to the Vector Control field. This gets things in sync again with
msixtbl_write().Signed-off-by Jan Beulich <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 2/3] x86/vMSI-X: also snoop qword writes
In reply to Jan BeulichQuoted 11 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 28 April 2016 10:50
To: xen-devel
Cc: Andrew Cooper; Paul Durrant
Subject: [PATCH 2/3] x86/vMSI-X: also snoop qword writes... the high half of which may be a write to the Vector Control field. This gets things in sync again with
msixtbl_write().Signed-off-by Jan Beulich <[email protected]>
Quoted 42 lines
xen/arch/x86/hvm/vmsi.c +15
-9@@ -336,6 +336,7 @@ out:static int msixtbl_range (struct vcpu *v,unsigned long addr) {const struct msi_desc *desc; +const ioreq_t *r;rcu_read_lock (&msixtbl_rcu_lock); desc =msixtbl_addr_to_desc (msixtbl_find_entry (v, addr), addr);@@ -344,17 +345,29 @@ static int msixtbl_range(struct vcpu *v,if ( desc )return 1 ; -if ( (addr & (PCI_MSIX_ENTRY_SIZE -1 )) == -PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET ) + r = &v->arch.hvm_vcpu.hvm_io.io_req; +if ( r->state !=STATE_IOREQ_READY || r->addr != addr ) +return 0 ; +ASSERT (r->type ==IOREQ_TYPE_COPY ); +if ( r->dir ==IOREQ_WRITE ) { -const ioreq_t *r = &v->arch.hvm_vcpu.hvm_io.io_req; +if ( !r->data_is_ptr ) + { +unsigned int size = r->size; +uint64_t data = r->data; -if ( r->state !=STATE_IOREQ_READY || r->addr != addr ) -return 0 ; -ASSERT (r->type ==IOREQ_TYPE_COPY ); -if ( r->dir ==IOREQ_WRITE && r->size ==4 && !r->data_is_ptr - && !(r->data &PCI_MSIX_VECTOR_BITMASK ) ) - v->arch.hvm_vcpu.hvm_io.msix_snoop_address = addr; +if ( size ==8 ) + { +BUILD_BUG_ON (!(PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET &4 )); + data >>=32 ; + addr += size =4 ;
xen/arch/x86/hvm/vmsi.c static int msixtbl_range(struct vcpu *v, · line 373
Quoted 10 lines
xen/arch/x86/hvm/vmsi.c +7
-0+ } +if ( size ==4 && + ((addr & (PCI_MSIX_ENTRY_SIZE -1 )) == +PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET ) && + !(data &PCI_MSIX_VECTOR_BITMASK ) ) + v->arch.hvm_vcpu.hvm_io.msix_snoop_address = addr; + } }return 0 ;
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH 3/3 x86/vMSI-X: also snoop REP MOVS
In reply to Jan Beulich... as at least certain versions of Windows use such to update the MSI-X table. However, to not overly complicate the logic for now
- only EFLAGS.DF=0 is being handled,
- only updates not crossing MSI-X table entry boundaries are handled.
xen/arch/x86/hvm/vmsi.c +38 -1
@@ -351,9 +351,10 @@ static int msixtbl_range(struct vcpu *v,ASSERT (r->type ==IOREQ_TYPE_COPY );if ( r->dir ==IOREQ_WRITE ) { +unsigned int size = r->size; +if ( !r->data_is_ptr ) { -unsigned int size = r->size;uint64_t data = r->data;if ( size ==8 )
@@ -366,7 +367,22 @@ static int msixtbl_range(struct vcpu *v, ((addr & (PCI_MSIX_ENTRY_SIZE -1 )) ==PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET ) && !(data & PCI_MSIX_VECTOR_BITMASK) ) + { v->arch.hvm_vcpu.hvm_io.msix_snoop_address = addr; + v->arch.hvm_vcpu.hvm_io.msix_snoop_gpa =0 ; + } + } +else if ( (size ==4 || size ==8 ) && !r->df && + r->count && r->count <=PCI_MSIX_ENTRY_SIZE / size && + !((addr + (size * r->count)) & (PCI_MSIX_ENTRY_SIZE -1 )) ) + { +BUILD_BUG_ON ((PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET +4 ) & + (PCI_MSIX_ENTRY_SIZE -1 )); + + v->arch.hvm_vcpu.hvm_io.msix_snoop_address = + addr + size * r->count -4 ; + v->arch.hvm_vcpu.hvm_io.msix_snoop_gpa = + r->data + size * r->count -4 ; } }
@@ -471,6 +487,7 @@ out: for_each_vcpu ( d, v ) { if ( (v->pause_flags & VPF_blocked_in_xen) && + !v->arch.hvm_vcpu.hvm_io.msix_snoop_gpa && v->arch.hvm_vcpu.hvm_io.msix_snoop_address == (gtable + msi_desc->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE +
@@ -551,9 +568,29 @@ void msixtbl_pt_cleanup(struct domain *dvoid msix_write_completion (struct vcpu *v) {unsigned long ctrl_address = v->arch.hvm_vcpu.hvm_io.msix_unmask_address; +unsigned long snoop_addr = v->arch.hvm_vcpu.hvm_io.msix_snoop_address; v->arch.hvm_vcpu.hvm_io.msix_snoop_address =0 ; +if ( !ctrl_address && snoop_addr && + v->arch.hvm_vcpu.hvm_io.msix_snoop_gpa ) + { +const struct msi_desc *desc; +uint32_t data; + +rcu_read_lock (&msixtbl_rcu_lock); + desc =msixtbl_addr_to_desc (msixtbl_find_entry (v, snoop_addr), + snoop_addr); +rcu_read_unlock (&msixtbl_rcu_lock); + +if ( desc && +hvm_copy_from_guest_phys (&data, + v->arch.hvm_vcpu.hvm_io.msix_snoop_gpa, +sizeof (data)) == HVMCOPY_okay && + !(data &PCI_MSIX_VECTOR_BITMASK ) ) + ctrl_address = snoop_addr; + } +if ( !ctrl_address )return ;
xen/include/asm-x86/hvm/vcpu.h +1 -0
@@ -86,6 +86,7 @@ struct hvm_vcpu_io {unsigned long msix_unmask_address;unsigned long msix_snoop_address; +unsigned long msix_snoop_gpa;const struct g2m_ioport *g2m_ioport; };
x86/vMSI-X: also snoop REP MOVS
... as at least certain versions of Windows use such to update the MSI-X table. However, to not overly complicate the logic for now
- only EFLAGS.DF=0 is being handled,
- only updates not crossing MSI-X table entry boundaries are handled.
xen/arch/x86/hvm/vmsi.c +38 -1
@@ -351,9 +351,10 @@ static int msixtbl_range(struct vcpu *v,ASSERT (r->type ==IOREQ_TYPE_COPY );if ( r->dir ==IOREQ_WRITE ) { +unsigned int size = r->size; +if ( !r->data_is_ptr ) { -unsigned int size = r->size;uint64_t data = r->data;if ( size ==8 )
@@ -366,7 +367,22 @@ static int msixtbl_range(struct vcpu *v, ((addr & (PCI_MSIX_ENTRY_SIZE -1 )) ==PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET ) && !(data & PCI_MSIX_VECTOR_BITMASK) ) + { v->arch.hvm_vcpu.hvm_io.msix_snoop_address = addr; + v->arch.hvm_vcpu.hvm_io.msix_snoop_gpa =0 ; + } + } +else if ( (size ==4 || size ==8 ) && !r->df && + r->count && r->count <=PCI_MSIX_ENTRY_SIZE / size && + !((addr + (size * r->count)) & (PCI_MSIX_ENTRY_SIZE -1 )) ) + { +BUILD_BUG_ON ((PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET +4 ) & + (PCI_MSIX_ENTRY_SIZE -1 )); + + v->arch.hvm_vcpu.hvm_io.msix_snoop_address = + addr + size * r->count -4 ; + v->arch.hvm_vcpu.hvm_io.msix_snoop_gpa = + r->data + size * r->count -4 ; } }
@@ -471,6 +487,7 @@ out: for_each_vcpu ( d, v ) { if ( (v->pause_flags & VPF_blocked_in_xen) && + !v->arch.hvm_vcpu.hvm_io.msix_snoop_gpa && v->arch.hvm_vcpu.hvm_io.msix_snoop_address == (gtable + msi_desc->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE +
@@ -551,9 +568,29 @@ void msixtbl_pt_cleanup(struct domain *dvoid msix_write_completion (struct vcpu *v) {unsigned long ctrl_address = v->arch.hvm_vcpu.hvm_io.msix_unmask_address; +unsigned long snoop_addr = v->arch.hvm_vcpu.hvm_io.msix_snoop_address; v->arch.hvm_vcpu.hvm_io.msix_snoop_address =0 ; +if ( !ctrl_address && snoop_addr && + v->arch.hvm_vcpu.hvm_io.msix_snoop_gpa ) + { +const struct msi_desc *desc; +uint32_t data; + +rcu_read_lock (&msixtbl_rcu_lock); + desc =msixtbl_addr_to_desc (msixtbl_find_entry (v, snoop_addr), + snoop_addr); +rcu_read_unlock (&msixtbl_rcu_lock); + +if ( desc && +hvm_copy_from_guest_phys (&data, + v->arch.hvm_vcpu.hvm_io.msix_snoop_gpa, +sizeof (data)) == HVMCOPY_okay && + !(data &PCI_MSIX_VECTOR_BITMASK ) ) + ctrl_address = snoop_addr; + } +if ( !ctrl_address )return ;
xen/include/asm-x86/hvm/vcpu.h +1 -0
@@ -86,6 +86,7 @@ struct hvm_vcpu_io {unsigned long msix_unmask_address;unsigned long msix_snoop_address; +unsigned long msix_snoop_gpa;const struct g2m_ioport *g2m_ioport; };
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 3/3] x86/vMSI-X: also snoop REP MOVS
Quoted 6 lines · Jan Beulich
... as at least certain versions of Windows use such to update the MSI-X table. However, to not overly complicate the logic for now
- only EFLAGS.DF=0 is being handled,
- only updates not crossing MSI-X table entry boundaries are handled.Signed-off-by Jan Beulich <[email protected]>
IMO, under those circumstances we should domain_crash() and be rather loud on the console.
Perhaps in a debug build only, but this will be a very unpleasant issue to debug for whomever finds an OS which falls into of those unhandled situations.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 3/3] x86/vMSI-X: also snoop REP MOVS
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 28.04.16 at 12:34, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
... as at least certain versions of Windows use such to update the MSI-X table. However, to not overly complicate the logic for now
- only EFLAGS.DF=0 is being handled,
- only updates not crossing MSI-X table entry boundaries are handled.
Quoted 8 lines
Quoted 1 line
Signed-off-by Jan Beulich <[email protected]>IMO, under those circumstances we should
domain_crash()and be rather loud on the console.Perhaps in a debug build only, but this will be a very unpleasant issue to debug for whomever finds an OS which falls into of those unhandled situations.
I disagree: At the time we snoop accesses, we don't know whether they're targeting any MSI-X table entry. And we shouldn't crash the guest just because it accessed _something else_ in a way the snoop logic doesn't support. If any unsupported access gets done by a guest, all that'll happen is that MSI-X again doesn't work inside the guest, i.e. the same situation as the previous and this patches are trying to deal with. (And yes, the debugging wasn't really pleasant, but that's more because the original authors didn't design the whole thing properly, and any other solution I could think of would have caused issues with the qemu/Xen interface logic.)
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 3/3] x86/vMSI-X: also snoop REP MOVS
In reply to Jan BeulichQuoted 30 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 28 April 2016 10:50
To: xen-devel
Cc: Andrew Cooper; Paul Durrant
Subject: [PATCH 3/3] x86/vMSI-X: also snoop REP MOVS... as at least certain versions of Windows use such to update the MSI-X table. However, to not overly complicate the logic for now
- only EFLAGS.DF=0 is being handled,
- only updates not crossing MSI-X table entry boundaries are handled.Signed-off-by Jan Beulich <[email protected]>xen/arch/x86/hvm/vmsi.c +2
-1@@ -351,9 +351,10 @@ static int msixtbl_range(struct vcpu *v,ASSERT (r->type ==IOREQ_TYPE_COPY );if ( r->dir ==IOREQ_WRITE ) { +unsigned int size = r->size; +if ( !r->data_is_ptr ) { -unsigned int size = r->size;uint64_t data = r->data;if ( size ==8 )@@ -366,7 +367,22 @@ static int msixtbl_range(struct vcpu *v, ((addr & (PCI_MSIX_ENTRY_SIZE - 1)) ==
xen/arch/x86/hvm/vmsi.c static int msixtbl_range(struct vcpu *v, · line 377
Quoted 10 lines
xen/arch/x86/hvm/vmsi.c +7
-0PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET) && !(data & PCI_MSIX_VECTOR_BITMASK) ) + { v->arch.hvm_vcpu.hvm_io.msix_snoop_address = addr; + v->arch.hvm_vcpu.hvm_io.msix_snoop_gpa =0 ; + } + } +else if ( (size ==4 || size ==8 ) && !r->df && + r->count && r->count <=PCI_MSIX_ENTRY_SIZE / size && + !((addr + (size * r->count)) & (PCI_MSIX_ENTRY_SIZE -1 )) )
That's quite an if statement. Any chance of making it more decipherable? I also think it's worth putting the restrictions you outline in the commit in a comment here so that it's clear that the code is not trying to handle all corner cases.
xen/arch/x86/hvm/vmsi.c static int msixtbl_range(struct vcpu *v, · line 385
Quoted 8 lines
xen/arch/x86/hvm/vmsi.c +8
-0+ { +BUILD_BUG_ON ((PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET +4 ) & + (PCI_MSIX_ENTRY_SIZE -1 )); + + v->arch.hvm_vcpu.hvm_io.msix_snoop_address = + addr + size * r->count -4 ; + v->arch.hvm_vcpu.hvm_io.msix_snoop_gpa = + r->data + size * r->count -4 ;
Does there need to be any explicit type promotion here since r->data is uint64_t?
Paul
Quoted 50 lines
xen/arch/x86/hvm/vmsi.c +21
-0} }@@ -471,6 +487,7 @@ out: for_each_vcpu ( d, v ) { if ( (v->pause_flags & VPF_blocked_in_xen) && + !v->arch.hvm_vcpu.hvm_io.msix_snoop_gpa && v->arch.hvm_vcpu.hvm_io.msix_snoop_address == (gtable + msi_desc->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE +@@ -551,9 +568,29 @@ void msixtbl_pt_cleanup(struct domain *dvoid msix_write_completion (struct vcpu *v) {unsigned long ctrl_address = v- >arch.hvm_vcpu.hvm_io.msix_unmask_address; +unsigned long snoop_addr = v- >arch.hvm_vcpu.hvm_io.msix_snoop_address; v->arch.hvm_vcpu.hvm_io.msix_snoop_address =0 ; +if ( !ctrl_address && snoop_addr && + v->arch.hvm_vcpu.hvm_io.msix_snoop_gpa ) + { +const struct msi_desc *desc; +uint32_t data; + +rcu_read_lock (&msixtbl_rcu_lock); + desc =msixtbl_addr_to_desc (msixtbl_find_entry (v, snoop_addr), + snoop_addr); +rcu_read_unlock (&msixtbl_rcu_lock); + +if ( desc && +hvm_copy_from_guest_phys (&data, + v->arch.hvm_vcpu.hvm_io.msix_snoop_gpa, +sizeof (data)) == HVMCOPY_okay && + !(data &PCI_MSIX_VECTOR_BITMASK ) ) + ctrl_address = snoop_addr; + } +if ( !ctrl_address )return;---
unstable.orig/xen/include/asm-x86/hvm/vcpu.h2016-04-27
14:47:25.000000000 +0200
+++unstable/xen/include/asm-x86/hvm/vcpu.h2016-04-25
16:04:48.000000000 +0200
xen/arch/x86/hvm/vmsi.c struct hvm_vcpu_io { · line 92
Quoted 7 lines
xen/arch/x86/hvm/vmsi.c +1
-0@@ -86,6 +86,7 @@ struct hvm_vcpu_io {unsigned long msix_unmask_address;unsigned long msix_snoop_address; +unsigned long msix_snoop_gpa;const struct g2m_ioport *g2m_ioport; };
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 3/3] x86/vMSI-X: also snoop REP MOVS
Quoted 17 lines
Quoted 5 lines
Quoted 1 line · On 28.04.16 at 13:17, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Sent: 28 April 2016 10:50xen/arch/x86/hvm/vmsi.c +0
-0@@ -366,7 +367,22 @@ static int msixtbl_range(struct vcpu *v, ((addr & (PCI_MSIX_ENTRY_SIZE - 1)) ==xen/arch/x86/hvm/vmsi.c static int msixtbl_range(struct vcpu *v, · line 377
Quoted 10 lines
xen/arch/x86/hvm/vmsi.c +7
-0PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET) && !(data & PCI_MSIX_VECTOR_BITMASK) ) + { v->arch.hvm_vcpu.hvm_io.msix_snoop_address = addr; + v->arch.hvm_vcpu.hvm_io.msix_snoop_gpa =0 ; + } + } +else if ( (size ==4 || size ==8 ) && !r->df && + r->count && r->count <=PCI_MSIX_ENTRY_SIZE / size && + !((addr + (size * r->count)) & (PCI_MSIX_ENTRY_SIZE -1 )) )That's quite an if statement. Any chance of making it more decipherable? I
I don't see how I could be doing this.
Quoted 3 lines
also think it's worth putting the restrictions you outline in the commit in a comment here so that it's clear that the code is not trying to handle all corner cases.
Sure. Question is whether by mixing code and comments things would get better readable (to at least somewhat address your request above), or whether that instead would make things worse. Thoughts?
Quoted 11 lines
xen/arch/x86/hvm/vmsi.c static int msixtbl_range(struct vcpu *v, · line 385
Quoted 8 lines
xen/arch/x86/hvm/vmsi.c +8
-0+ { +BUILD_BUG_ON ((PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET +4 ) & + (PCI_MSIX_ENTRY_SIZE -1 )); + + v->arch.hvm_vcpu.hvm_io.msix_snoop_address = + addr + size * r->count -4 ; + v->arch.hvm_vcpu.hvm_io.msix_snoop_gpa = + r->data + size * r->count -4 ;Does there need to be any explicit type promotion here since
r->dataisuint64_t?
No, because both size and r->count did already get bounds checked to very narrow ranges.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 3/3] x86/vMSI-X: also snoop REP MOVS
Quoted 27 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 28 April 2016 12:44
To: Paul Durrant
Cc: Andrew Cooper; xen-devel
Subject: RE: [PATCH 3/3] x86/vMSI-X: also snoop REP MOVSQuoted 17 lines
Quoted 5 lines
Quoted 1 line · On 28.04.16 at 13:17, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Sent: 28 April 2016 10:50xen/arch/x86/hvm/vmsi.c +0
-0@@ -366,7 +367,22 @@ static int msixtbl_range(struct vcpu *v, ((addr & (PCI_MSIX_ENTRY_SIZE - 1)) ==xen/arch/x86/hvm/vmsi.c static int msixtbl_range(struct vcpu *v, · line 377
Quoted 10 lines
xen/arch/x86/hvm/vmsi.c +7
-0PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET) && !(data & PCI_MSIX_VECTOR_BITMASK) ) + { v->arch.hvm_vcpu.hvm_io.msix_snoop_address = addr; + v->arch.hvm_vcpu.hvm_io.msix_snoop_gpa =0 ; + } + } +else if ( (size ==4 || size ==8 ) && !r->df && + r->count && r->count <=PCI_MSIX_ENTRY_SIZE / size && + !((addr + (size * r->count)) & (PCI_MSIX_ENTRY_SIZE -1 )) )That's quite an if statement. Any chance of making it more decipherable? I
I don't see how I could be doing this.
Quoted 8 lines
Quoted 3 lines
also think it's worth putting the restrictions you outline in the commit in a comment here so that it's clear that the code is not trying to handle all corner cases.
Sure. Question is whether by mixing code and comments things would get better readable (to at least somewhat address your request above), or whether that instead would make things worse. Thoughts?
I think mentioning why you're only tackling the !r->df case would be worth commenting on and if the && !r->df were on a separate line then the comment could go inline. Also, do you really need to check r->count (seems like a count of 0 should have been picked up before the code got here) and then TBH I'm not even sure what !((addr + (size * r->count)) & (PCI_MSIX_ENTRY_SIZE - 1)) is even checking so how about an illustratively named macro?
Paul
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
xen/arch/x86/hvm/vmsi.c +8
-0+ { +BUILD_BUG_ON ((PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET +4 ) & + (PCI_MSIX_ENTRY_SIZE -1 )); + + v->arch.hvm_vcpu.hvm_io.msix_snoop_address = + addr + size * r->count -4 ; + v->arch.hvm_vcpu.hvm_io.msix_snoop_gpa = + r->data + size * r->count -4 ;
Quoted 7 lines
Quoted 2 lines
Does there need to be any explicit type promotion here since
r->dataisuint64_t?No, because both size and
r->countdid already get bounds checked to very narrow ranges.Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 3/3] x86/vMSI-X: also snoop REP MOVS
Quoted 33 lines
Quoted 26 lines
Quoted 1 line · On 28.04.16 at 13:58, <[email protected]> wrote:
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 28 April 2016 12:44
To: Paul Durrant
Cc: Andrew Cooper; xen-devel
Subject: RE: [PATCH 3/3] x86/vMSI-X: also snoop REP MOVSQuoted 17 lines
Quoted 5 lines
Quoted 1 line · On 28.04.16 at 13:17, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Sent: 28 April 2016 10:50xen/arch/x86/hvm/vmsi.c +0
-0@@ -366,7 +367,22 @@ static int msixtbl_range(struct vcpu *v, ((addr & (PCI_MSIX_ENTRY_SIZE - 1)) ==xen/arch/x86/hvm/vmsi.c static int msixtbl_range(struct vcpu *v, · line 377
Quoted 10 lines
xen/arch/x86/hvm/vmsi.c +7
-0PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET) && !(data & PCI_MSIX_VECTOR_BITMASK) ) + { v->arch.hvm_vcpu.hvm_io.msix_snoop_address = addr; + v->arch.hvm_vcpu.hvm_io.msix_snoop_gpa =0 ; + } + } +else if ( (size ==4 || size ==8 ) && !r->df && + r->count && r->count <=PCI_MSIX_ENTRY_SIZE / size && + !((addr + (size * r->count)) & (PCI_MSIX_ENTRY_SIZE -1 )) )That's quite an if statement. Any chance of making it more decipherable? I
Quoted 3 lines
I don't see how I could be doing this.
Quoted 1 line
also think it's worth putting the restrictions you outline in the commit in
a
Quoted 3 lines
Quoted 2 lines
comment here so that it's clear that the code is not trying to handle all corner cases.
Quoted 8 lines
Quoted 4 lines
Sure. Question is whether by mixing code and comments things would get better readable (to at least somewhat address your request above), or whether that instead would make things worse. Thoughts?
I think mentioning why you're only tackling the !r->df case would be worth commenting on and if the && !r->df were on a separate line then the comment could go inline.
That's what I did.
Quoted 2 lines
Also, do you really need to check
r->count(seems like a count of 0 should have been picked up before the code got here)
I've tried to fine where r->count == 0 would be dealt with, but could spot the location (other than relying on x86_emulate.c never passing such down), so since I want to subtract 1 from it (or really 4 from its product with "size") I wanted to be on the safe side. If you prefer, I could replace this by a respective ASSERT()...
Quoted 3 lines
and then TBH I'm not
even sure what !((addr + (size *r->count)) & (PCI_MSIX_ENTRY_SIZE- 1)) is even checking so how about an illustratively named macro?
How about this (without macro)?
else if ( (size == 4 || size == 8) &&
/* Only support forward REP MOVS for now. */
!r->df &&
/*
* Only fully support accesses to a single table entry for
* now (if multiple ones get written to in one go, only the
* final one gets dealt with).
*/
r->count && r->count <= PCI_MSIX_ENTRY_SIZE / size &&
!((addr + (size * r->count)) & (PCI_MSIX_ENTRY_SIZE - 1)) )
{Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 3/3] x86/vMSI-X: also snoop REP MOVS
Quoted 70 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 28 April 2016 13:31
To: Paul Durrant
Cc: Andrew Cooper; xen-devel
Subject: RE: [PATCH 3/3] x86/vMSI-X: also snoop REP MOVSQuoted 9 lines
Quoted 9 lines
Quoted 1 line · On 28.04.16 at 13:58, <[email protected]> wrote:
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 28 April 2016 12:44
To: Paul Durrant
Cc: Andrew Cooper; xen-devel
Subject: RE: [PATCH 3/3] x86/vMSI-X: also snoop REP MOVSQuoted 1 line
Quoted 1 line
Quoted 1 line · On 28.04.16 at 13:17, <[email protected]> wrote:
Quoted 16 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
From: Jan Beulich [mailto:[email protected]]
Sent: 28 April 2016 10:50xen/arch/x86/hvm/vmsi.c +1
-0@@ -366,7 +367,22 @@ static int msixtbl_range(struct vcpu *v, ((addr & (PCI_MSIX_ENTRY_SIZE - 1)) == PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET) && !(data & PCI_MSIX_VECTOR_BITMASK) ) + { v->arch.hvm_vcpu.hvm_io.msix_snoop_address = addr;Quoted 8 lines
Quoted 8 lines
xen/arch/x86/hvm/vmsi.c static int msixtbl_range(struct vcpu *v, · line 377
Quoted 6 lines
xen/arch/x86/hvm/vmsi.c +6
-0+ v->arch.hvm_vcpu.hvm_io.msix_snoop_gpa =0 ; + } + } +else if ( (size ==4 || size ==8 ) && !r->df && + r->count && r->count <=PCI_MSIX_ENTRY_SIZE / size && + !((addr + (size * r->count)) & (PCI_MSIX_ENTRY_SIZE -1 )) )That's quite an if statement. Any chance of making it more
decipherable? I
Quoted 8 lines
Quoted 4 lines
I don't see how I could be doing this.
Quoted 1 line
also think it's worth putting the restrictions you outline in the commit in
a
Quoted 3 lines
Quoted 2 lines
comment here so that it's clear that the code is not trying to handle all corner cases.
Quoted 7 lines
Quoted 4 lines
Sure. Question is whether by mixing code and comments things would get better readable (to at least somewhat address your request above), or whether that instead would make things worse. Thoughts?
I think mentioning why you're only tackling the !r->df case would be worth commenting on and if the && !r->df were on a separate line then the
comment could
Quoted 1 line
go inline.
That's what I did.
Quoted 2 lines
Also, do you really need to check
r->count(seems like a count of 0 should have been picked up before the code got here)I've tried to fine where
r->count== 0 would be dealt with, but could spot the location (other than relying onx86_emulate.cnever passing such down), so since I want to subtract 1 from it (or really 4 from its product with "size") I wanted to be on the safe side. If you prefer, I could replace this by a respectiveASSERT()...Quoted 2 lines
and then TBH I'm not
even sure what !((addr + (size *r->count)) & (PCI_MSIX_ENTRY_SIZE- 1))is even
Quoted 1 line
checking so how about an illustratively named macro?
How about this (without macro)?
Quoted 12 lines
else if ( (size == 4 || size == 8) &&
/* Only support forward REP MOVS for now. */
!r->df &&
/*
* Only fully support accesses to a single table entry for
* now (if multiple ones get written to in one go, only the
* final one gets dealt with).
*/
r->count && r->count <= PCI_MSIX_ENTRY_SIZE / size &&
!((addr + (size * r->count)) & (PCI_MSIX_ENTRY_SIZE - 1)) )
{That looks a lot better to me :-)
Paul
Quoted 1 line
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 28.04.16 at 11:35, <[email protected]> wrote:
1: add further checks to snoop logic
2: also snoop qword writes
3: also snoop REP MOVSSigned-off-by Jan Beulich <[email protected]>
Wei,
I've only now realized that I should have Cc-ed you on this series (all intended for 4.7).
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 28.04.16 at 11:35, <[email protected]> wrote:
1: add further checks to snoop logic
2: also snoop qword writes
3: also snoop REP MOVS
Quoted 7 lines
Quoted 1 line
Signed-off-by Jan Beulich <[email protected]>Wei,
I've only now realized that I should have Cc-ed you on this series (all intended for 4.7).
Subject to ack / review from Andrew / Paul:
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel