x86/HVM: drop stdvga caching mode
v2 cover x86/HVM: drop stdvga caching mode
It's been unused for nearly 9 years. By the end of the series stdvga.c's sole purpose will be to make sure VRAM writes use the bufio ioreq path.
1: properly reject "indirect" VRAM writes
2: drop stdvga's "stdvga" struct member
3: remove unused MMIO handling code
4: drop stdvga's "gr[]" struct member
5: drop stdvga's "sr[]" struct member
6: drop stdvga's "{g,s}r_index" struct members
7: drop stdvga's "vram_page[]" struct member
8: drop stdvga's "lock" struct member
9: drop .complete hook for intercept handling
Jan
PATCH v2 1/9 x86/HVM: properly reject "indirect" VRAM writes
While ->count will only be different from 1 for "indirect" (data in guest memory) accesses, it being 1 does not exclude the request being an "indirect" one. Check both to be on the safe side, and bring the ->count part also in line with what ioreq_send_buffered() actually refuses to handle.
---
v2: New.
xen/arch/x86/hvm/stdvga.c +2 -2
@@ -498,13 +498,13 @@ static bool cf_check stdvga_mem_accept(spin_lock (&s->lock); -if ( p->dir ==IOREQ_WRITE && p->count >1 ) +if ( p->dir ==IOREQ_WRITE && (p->data_is_ptr || p->count !=1 ) ) {/* * We cannot return X86EMUL_UNHANDLEABLE on anything other then the * first cycle of an I/O. So, since we cannot guarantee to always be * able to send buffered writes, we have to reject any multi-cycle -* I/O. +* or "indirect" I/O. */ goto reject; }
Re: [PATCH v2 1/9] x86/HVM: properly reject "indirect" VRAM writes
Quoted 8 lines · Jan Beulich
While ->count will only be different from 1 for "indirect" (data in guest memory) accesses, it being 1 does not exclude the request being an "indirect" one. Check both to be on the safe side, and bring the ->count part also in line with what
ioreq_send_buffered()actually refuses to handle.Fixes 3bbaaec09b1b ("x86/hvm: unify stdvga mmio intercept with standard mmio intercept")Signed-off-by Jan Beulich <[email protected]>
PATCH v2 2/9 x86/HVM: drop stdvga's "stdvga" struct member
In reply to Jan BeulichTwo of its consumers are dead (in compile-time constant conditionals) and the only remaining ones are merely controlling debug logging. Hence the field is now pointless to set, which in particular allows to get rid of the questionable conditional from which the field's value was established (afaict 551ceee97513 ["x86, hvm: stdvga cache always on"] had dropped too much of the earlier extra check that was there, and quite likely further checks were missing).
---
v2: Reduce a (largely pre-existing) comment. Re-base over new earlier
patch.
xen/arch/x86/hvm/stdvga.c +5 -25
@@ -103,7 +103,7 @@ static void vram_put(struct hvm_hw_stdvgstatic int stdvga_outb (uint64_t addr,uint8_t val) {struct hvm_hw_stdvga *s = ¤t->domain->arch.hvm.stdvga; -int rc =1 , prev_stdvga = s->stdvga; +int rc =1 ;switch ( addr ) {
@@ -132,19 +132,6 @@ static int stdvga_outb(uint64_t addr, uibreak ; } -/* When in standard vga mode, emulate here all writes to the vram buffer -* so we can immediately satisfy reads without waiting for qemu. */ - s->stdvga = (s->sr[7 ] ==0x00 ); - -if ( !prev_stdvga && s->stdvga ) - { -gdprintk (XENLOG_INFO ,"entering stdvga mode\n" ); - } -else if ( prev_stdvga && !s->stdvga ) - { -gdprintk (XENLOG_INFO ,"leaving stdvga mode\n" ); - } -return rc; }
@@ -425,7 +412,6 @@ static int cf_check stdvga_mem_write( const struct hvm_io_handler *handler, uint64_t addr, uint32_t size, uint64_t data) { - struct hvm_hw_stdvga *s = ¤t->domain->arch.hvm.stdvga; ioreq_t p = { .type = IOREQ_TYPE_COPY, .addr = addr,
@@ -436,8 +422,7 @@ static int cf_check stdvga_mem_write( };struct ioreq_server *srv; -if ( true || !s->stdvga ) - goto done; + goto done;/* Intercept mmio write */ switch ( size )
@@ -498,19 +483,14 @@ static bool cf_check stdvga_mem_accept(spin_lock (&s->lock); -if ( p->dir ==IOREQ_WRITE && (p->data_is_ptr || p->count !=1 ) ) +if ( p->dir !=IOREQ_WRITE || p->data_is_ptr || p->count !=1 ) {/* -* We cannot return X86EMUL_UNHANDLEABLE on anything other then the -* first cycle of an I/O. So, since we cannot guarantee to always be -* able to send buffered writes, we have to reject any multi-cycle -* or "indirect" I/O. +* Only accept single direct writes, as that's the only thing we can +* accelerate using buffered ioreq handling. */ goto reject; } -else if ( p->dir ==IOREQ_READ && - (true || !s->stdvga) ) - goto reject;/* s->lock intentionally held */ return 1 ;
xen/arch/x86/include/asm/hvm/io.h +0 -1
@@ -115,7 +115,6 @@ struct hvm_hw_stdvga {uint8_t sr[8 ];uint8_t gr_index;uint8_t gr[9 ]; -bool stdvga;uint32_t latch;struct page_info *vram_page[64 ];/* shadow of 0xa0000-0xaffff */ spinlock_t lock;
Re: [PATCH v2 2/9] x86/HVM: drop stdvga's "stdvga" struct member
Quoted 9 lines · Jan Beulich
Two of its consumers are dead (in compile-time constant conditionals) and the only remaining ones are merely controlling debug logging. Hence the field is now pointless to set, which in particular allows to get rid of the questionable conditional from which the field's value was established (afaict
551ceee97513["x86, hvm: stdvga cache always on"] had dropped too much of the earlier extra check that was there, and quite likely further checks were missing).Signed-off-by Jan Beulich <[email protected]>
PATCH v2 3/9 x86/HVM: remove unused MMIO handling code
In reply to Jan BeulichAll read accesses are rejected by the ->accept handler, while writes bypass the bulk of the function body. Drop the dead code, leaving an assertion in the read handler.
A number of other static items (and a macro) are then unreferenced and hence also need (want) dropping. The same applies to the "latch" field of the state structure.
xen/arch/x86/hvm/stdvga.c +4 -313
@@ -37,26 +37,6 @@#define VGA_MEM_BASE 0xa0000#define VGA_MEM_SIZE 0x20000 -#define PAT (x) (x) -static const uint32_t mask16[16 ] = { -PAT (0x00000000U ), -PAT (0x000000ffU ), -PAT (0x0000ff00U ), -PAT (0x0000ffffU ), -PAT (0x00ff0000U ), -PAT (0x00ff00ffU ), -PAT (0x00ffff00U ), -PAT (0x00ffffffU ), -PAT (0xff000000U ), -PAT (0xff0000ffU ), -PAT (0xff00ff00U ), -PAT (0xff00ffffU ), -PAT (0xffff0000U ), -PAT (0xffff00ffU ), -PAT (0xffffff00U ), -PAT (0xffffffffU ), -}; -/* force some bits to zero */ static const uint8_t sr_mask[8 ] = { (uint8_t )~0xfc ,
@@ -81,25 +61,6 @@ static const uint8_t gr_mask[9] = { (uint8_t)~0x00, /* 0x08 */ }; -static uint8_t *vram_getb (struct hvm_hw_stdvga *s,unsigned int a) -{ -struct page_info *pg = s->vram_page[(a >>12 ) &0x3f ]; -uint8_t *p =__map_domain_page (pg); -return &p[a &0xfff ]; -} - -static uint32_t *vram_getl (struct hvm_hw_stdvga *s,unsigned int a) -{ -struct page_info *pg = s->vram_page[(a >>10 ) &0x3f ]; -uint32_t *p =__map_domain_page (pg); -return &p[a &0x3ff ]; -} - -static void vram_put (struct hvm_hw_stdvga *s,void *p) -{ -unmap_domain_page (p); -} -static int stdvga_outb (uint64_t addr,uint8_t val) {struct hvm_hw_stdvga *s = ¤t->domain->arch.hvm.stdvga;
@@ -168,244 +129,13 @@ static int cf_check stdvga_intercept_pioreturn X86EMUL_UNHANDLEABLE ;/* propagate to external ioemu */ } -static unsigned int stdvga_mem_offset ( -struct hvm_hw_stdvga *s,unsigned int mmio_addr) -{ -unsigned int memory_map_mode = (s->gr[6 ] >>2 ) &3 ; -unsigned int offset = mmio_addr &0x1ffff ; - -switch ( memory_map_mode ) - { -case 0 : -break ; -case 1 : -if ( offset >=0x10000 ) - goto fail; - offset +=0 ;/* assume bank_offset == 0; */ -break ; -case 2 : - offset -=0x10000 ; -if ( offset >=0x8000 ) - goto fail; -break ; -default : -case 3 : - offset -=0x18000 ; -if ( offset >=0x8000 ) - goto fail; -break ; - } - -return offset; - - fail: -return ~0u ; -} - -#define GET_PLANE (data, p) (((data) >> ((p) * 8)) & 0xff) - -static uint8_t stdvga_mem_readb (uint64_t addr) -{ -struct hvm_hw_stdvga *s = ¤t->domain->arch.hvm.stdvga; -int plane; -uint32_t ret, *vram_l; -uint8_t *vram_b; - - addr =stdvga_mem_offset (s, addr); -if ( addr == ~0u ) -return 0xff ; - -if ( s->sr[4 ] &0x08 ) - { -/* chain 4 mode : simplest access */ - vram_b =vram_getb (s, addr); - ret = *vram_b; -vram_put (s, vram_b); - } -else if ( s->gr[5 ] &0x10 ) - { -/* odd/even mode (aka text mode mapping) */ - plane = (s->gr[4 ] &2 ) | (addr &1 ); - vram_b =vram_getb (s, ((addr & ~1 ) <<1 ) | plane); - ret = *vram_b; -vram_put (s, vram_b); - } -else - { -/* standard VGA latched access */ - vram_l =vram_getl (s, addr); - s->latch = *vram_l; -vram_put (s, vram_l); - -if ( !(s->gr[5 ] &0x08 ) ) - { -/* read mode 0 */ - plane = s->gr[4 ]; - ret =GET_PLANE (s->latch, plane); - } -else - { -/* read mode 1 */ - ret = (s->latch ^ mask16[s->gr[2 ]]) & mask16[s->gr[7 ]]; - ret |= ret >>16 ; - ret |= ret >>8 ; - ret = (~ret) &0xff ; - } - } - -return ret; -} - static int cf_check stdvga_mem_read(const struct hvm_io_handler *handler,uint64_t addr,uint32_t size,uint64_t *p_data) { -uint64_t data = ~0UL ; - -switch ( size ) - { -case 1 : - data =stdvga_mem_readb (addr); -break ; - -case 2 : - data =stdvga_mem_readb (addr); - data |=stdvga_mem_readb (addr +1 ) <<8 ; -break ; - -case 4 : - data =stdvga_mem_readb (addr); - data |=stdvga_mem_readb (addr +1 ) <<8 ; - data |=stdvga_mem_readb (addr +2 ) <<16 ; - data |= (uint32_t )stdvga_mem_readb (addr +3 ) <<24 ; -break ; - -case 8 : - data = (uint64_t )(stdvga_mem_readb (addr)); - data |= (uint64_t )(stdvga_mem_readb (addr +1 )) <<8 ; - data |= (uint64_t )(stdvga_mem_readb (addr +2 )) <<16 ; - data |= (uint64_t )(stdvga_mem_readb (addr +3 )) <<24 ; - data |= (uint64_t )(stdvga_mem_readb (addr +4 )) <<32 ; - data |= (uint64_t )(stdvga_mem_readb (addr +5 )) <<40 ; - data |= (uint64_t )(stdvga_mem_readb (addr +6 )) <<48 ; - data |= (uint64_t )(stdvga_mem_readb (addr +7 )) <<56 ; -break ; - -default : -gdprintk (XENLOG_WARNING ,"invalid io size: %u\n" , size); -break ; - } - - *p_data = data; -return X86EMUL_OKAY ; -} - -static void stdvga_mem_writeb (uint64_t addr,uint32_t val) -{ -struct hvm_hw_stdvga *s = ¤t->domain->arch.hvm.stdvga; -int plane, write_mode, b, func_select, mask; -uint32_t write_mask, bit_mask, set_mask, *vram_l; -uint8_t *vram_b; - - addr =stdvga_mem_offset (s, addr); -if ( addr == ~0u ) -return ; - -if ( s->sr[4 ] &0x08 ) - { -/* chain 4 mode : simplest access */ - plane = addr &3 ; - mask = (1 << plane); -if ( s->sr[2 ] & mask ) - { - vram_b =vram_getb (s, addr); - *vram_b = val; -vram_put (s, vram_b); - } - } -else if ( s->gr[5 ] &0x10 ) - { -/* odd/even mode (aka text mode mapping) */ - plane = (s->gr[4 ] &2 ) | (addr &1 ); - mask = (1 << plane); -if ( s->sr[2 ] & mask ) - { - addr = ((addr & ~1 ) <<1 ) | plane; - vram_b =vram_getb (s, addr); - *vram_b = val; -vram_put (s, vram_b); - } - } -else - { - write_mode = s->gr[5 ] &3 ; -switch ( write_mode ) - { -default : -case 0 : -/* rotate */ - b = s->gr[3 ] &7 ; - val = ((val >> b) | (val << (8 - b))) &0xff ; - val |= val <<8 ; - val |= val <<16 ; - -/* apply set/reset mask */ - set_mask = mask16[s->gr[1 ]]; - val = (val & ~set_mask) | (mask16[s->gr[0 ]] & set_mask); - bit_mask = s->gr[8 ]; -break ; -case 1 : - val = s->latch; - goto do_write; -case 2 : - val = mask16[val &0x0f ]; - bit_mask = s->gr[8 ]; -break ; -case 3 : -/* rotate */ - b = s->gr[3 ] &7 ; - val = (val >> b) | (val << (8 - b)); - - bit_mask = s->gr[8 ] & val; - val = mask16[s->gr[0 ]]; -break ; - } - -/* apply logical operation */ - func_select = s->gr[3 ] >>3 ; -switch ( func_select ) - { -case 0 : -default : -/* nothing to do */ -break ; -case 1 : -/* and */ - val &= s->latch; -break ; -case 2 : -/* or */ - val |= s->latch; -break ; -case 3 : -/* xor */ - val ^= s->latch; -break ; - } - -/* apply bit mask */ - bit_mask |= bit_mask <<8 ; - bit_mask |= bit_mask <<16 ; - val = (val & bit_mask) | (s->latch & ~bit_mask); - - do_write: -/* mask data according to sr[2] */ - mask = s->sr[2 ]; - write_mask = mask16[mask]; - vram_l =vram_getl (s, addr); - *vram_l = (*vram_l & ~write_mask) | (val & write_mask); -vram_put (s, vram_l); - } +ASSERT_UNREACHABLE (); + *p_data = ~0 ; +return X86EMUL_UNHANDLEABLE ; } static int cf_check stdvga_mem_write(
@@ -420,47 +150,8 @@ static int cf_check stdvga_mem_write( .dir = IOREQ_WRITE, .data = data, }; -struct ioreq_server *srv; - - goto done; - -/* Intercept mmio write */ -switch ( size ) - { -case 1 : -stdvga_mem_writeb (addr, (data >>0 ) &0xff ); -break ; - -case 2 : -stdvga_mem_writeb (addr+0 , (data >>0 ) &0xff ); -stdvga_mem_writeb (addr+1 , (data >>8 ) &0xff ); -break ; - -case 4 : -stdvga_mem_writeb (addr+0 , (data >>0 ) &0xff ); -stdvga_mem_writeb (addr+1 , (data >>8 ) &0xff ); -stdvga_mem_writeb (addr+2 , (data >>16 ) &0xff ); -stdvga_mem_writeb (addr+3 , (data >>24 ) &0xff ); -break ; - -case 8 : -stdvga_mem_writeb (addr+0 , (data >>0 ) &0xff ); -stdvga_mem_writeb (addr+1 , (data >>8 ) &0xff ); -stdvga_mem_writeb (addr+2 , (data >>16 ) &0xff ); -stdvga_mem_writeb (addr+3 , (data >>24 ) &0xff ); -stdvga_mem_writeb (addr+4 , (data >>32 ) &0xff ); -stdvga_mem_writeb (addr+5 , (data >>40 ) &0xff ); -stdvga_mem_writeb (addr+6 , (data >>48 ) &0xff ); -stdvga_mem_writeb (addr+7 , (data >>56 ) &0xff ); -break ; - -default : -gdprintk (XENLOG_WARNING ,"invalid io size: %u\n" , size); -break ; - } +struct ioreq_server *srv =ioreq_server_select (current->domain, &p); - done: - srv =ioreq_server_select (current->domain, &p);if ( !srv )return X86EMUL_UNHANDLEABLE ;
xen/arch/x86/include/asm/hvm/io.h +0 -1
@@ -115,7 +115,6 @@ struct hvm_hw_stdvga {uint8_t sr[8 ];uint8_t gr_index;uint8_t gr[9 ]; -uint32_t latch;struct page_info *vram_page[64 ];/* shadow of 0xa0000-0xaffff */ spinlock_t lock; };
PATCH v2 4/9 x86/HVM: drop stdvga's "gr[]" struct member
In reply to Jan BeulichNo consumers are left, hence the producer and the array itself can also go away. The static gr_mask[] is then orphaned and hence needs dropping, too.
xen/arch/x86/hvm/stdvga.c +0 -18
@@ -49,18 +49,6 @@ static const uint8_t sr_mask[8] = { (uint8_t)~0x00, }; -static const uint8_t gr_mask[9 ] = { - (uint8_t )~0xf0 ,/* 0x00 */ - (uint8_t )~0xf0 ,/* 0x01 */ - (uint8_t )~0xf0 ,/* 0x02 */ - (uint8_t )~0xe0 ,/* 0x03 */ - (uint8_t )~0xfc ,/* 0x04 */ - (uint8_t )~0x84 ,/* 0x05 */ - (uint8_t )~0xf0 ,/* 0x06 */ - (uint8_t )~0xf0 ,/* 0x07 */ - (uint8_t )~0x00 ,/* 0x08 */ -}; -static int stdvga_outb (uint64_t addr,uint8_t val) {struct hvm_hw_stdvga *s = ¤t->domain->arch.hvm.stdvga;
@@ -82,12 +70,6 @@ static int stdvga_outb(uint64_t addr, ui s->gr_index = val;break ; -case 0x3cf :/* graphics data register */ - rc = (s->gr_index <sizeof (s->gr)); -if ( rc ) - s->gr[s->gr_index] = val & gr_mask[s->gr_index]; -break ; -default : rc =0 ;break ;
xen/arch/x86/include/asm/hvm/io.h +0 -1
@@ -114,7 +114,6 @@ struct hvm_hw_stdvga {uint8_t sr_index;uint8_t sr[8 ];uint8_t gr_index; -uint8_t gr[9 ];struct page_info *vram_page[64 ];/* shadow of 0xa0000-0xaffff */ spinlock_t lock; };
PATCH v2 5/9 x86/HVM: drop stdvga's "sr[]" struct member
In reply to Jan BeulichNo consumers are left, hence the producer and the array itself can also go away. The static sr_mask[] is then orphaned and hence needs dropping, too.
xen/arch/x86/hvm/stdvga.c +0 -18
@@ -37,18 +37,6 @@#define VGA_MEM_BASE 0xa0000#define VGA_MEM_SIZE 0x20000 -/* force some bits to zero */ -static const uint8_t sr_mask[8 ] = { - (uint8_t )~0xfc , - (uint8_t )~0xc2 , - (uint8_t )~0xf0 , - (uint8_t )~0xc0 , - (uint8_t )~0xf1 , - (uint8_t )~0xff , - (uint8_t )~0xff , - (uint8_t )~0x00 , -}; -static int stdvga_outb (uint64_t addr,uint8_t val) {struct hvm_hw_stdvga *s = ¤t->domain->arch.hvm.stdvga;
@@ -60,12 +48,6 @@ static int stdvga_outb(uint64_t addr, ui s->sr_index = val;break ; -case 0x3c5 :/* sequencer data register */ - rc = (s->sr_index <sizeof (s->sr)); -if ( rc ) - s->sr[s->sr_index] = val & sr_mask[s->sr_index] ; -break ; -case 0x3ce :/* graphics address register */ s->gr_index = val;break ;
xen/arch/x86/include/asm/hvm/io.h +0 -1
@@ -112,7 +112,6 @@ struct vpci_arch_msix_entry {struct hvm_hw_stdvga {uint8_t sr_index; -uint8_t sr[8 ];uint8_t gr_index;struct page_info *vram_page[64 ];/* shadow of 0xa0000-0xaffff */ spinlock_t lock;
PATCH v2 6/9 x86/HVM: drop stdvga's "{g,s}r_index" struct members
In reply to Jan BeulichNo consumers are left, hence the producer and the fields themselves can also go away. stdvga_outb() is then useless, rendering stdvga_out() useless as well. Hence the entire I/O port intercept can go away.
xen/arch/x86/hvm/stdvga.c +0 -61
@@ -37,62 +37,6 @@#define VGA_MEM_BASE 0xa0000#define VGA_MEM_SIZE 0x20000 -static int stdvga_outb (uint64_t addr,uint8_t val) -{ -struct hvm_hw_stdvga *s = ¤t->domain->arch.hvm.stdvga; -int rc =1 ; - -switch ( addr ) - { -case 0x3c4 :/* sequencer address register */ - s->sr_index = val; -break ; - -case 0x3ce :/* graphics address register */ - s->gr_index = val; -break ; - -default : - rc =0 ; -break ; - } - -return rc; -} - -static void stdvga_out (uint32_t port,uint32_t bytes,uint32_t val) -{ -switch ( bytes ) - { -case 1 : -stdvga_outb (port, val); -break ; - -case 2 : -stdvga_outb (port +0 , val >>0 ); -stdvga_outb (port +1 , val >>8 ); -break ; - -default : -break ; - } -} - -static int cf_check stdvga_intercept_pio( -int dir,unsigned int port,unsigned int bytes,uint32_t *val) -{ -struct hvm_hw_stdvga *s = ¤t->domain->arch.hvm.stdvga; - -if ( dir ==IOREQ_WRITE ) - { -spin_lock (&s->lock); -stdvga_out (port, bytes, *val); -spin_unlock (&s->lock); - } - -return X86EMUL_UNHANDLEABLE ;/* propagate to external ioemu */ -} - static int cf_check stdvga_mem_read(const struct hvm_io_handler *handler,uint64_t addr,uint32_t size,uint64_t *p_data)
@@ -194,11 +138,6 @@ void stdvga_init(struct domain *d) {struct hvm_io_handler *handler; -/* Sequencer registers. */ -register_portio_handler (d,0x3c4 ,2 , stdvga_intercept_pio); -/* Graphics registers. */ -register_portio_handler (d,0x3ce ,2 , stdvga_intercept_pio); -/* VGA memory */ handler =hvm_next_io_handler (d);
xen/arch/x86/include/asm/hvm/io.h +0 -2
@@ -111,8 +111,6 @@ struct vpci_arch_msix_entry { };struct hvm_hw_stdvga { -uint8_t sr_index; -uint8_t gr_index;struct page_info *vram_page[64 ];/* shadow of 0xa0000-0xaffff */ spinlock_t lock; };
PATCH v2 7/9 x86/HVM: drop stdvga's "vram_page[]" struct member
In reply to Jan BeulichNo uses are left, hence its setup, teardown, and the field itself can also go away. stdvga_deinit() is then empty and can be dropped as well.
---
I have no idea whether in the tool stack some memory calculations would want adjusting, to account for the 256k less that a HVM domain now needs.
xen/arch/x86/hvm/hvm.c +0 -2
@@ -700,7 +700,6 @@ int hvm_domain_initialise(struct domainreturn 0 ; fail2: -stdvga_deinit (d);vioapic_deinit (d); fail1:if (is_hardware_domain (d) )
@@ -763,7 +762,6 @@ void hvm_domain_destroy(struct domain *dif ( hvm_funcs.domain_destroy )alternative_vcall (hvm_funcs.domain_destroy, d); -stdvga_deinit (d);vioapic_deinit (d);XFREE (d->arch.hvm.pl_time);
xen/arch/x86/hvm/stdvga.c +4 -37
59 lines not on this page · raw message
xen/arch/x86/include/asm/hvm/io.h +0 -2
@@ -111,12 +111,10 @@ struct vpci_arch_msix_entry { };struct hvm_hw_stdvga { -struct page_info *vram_page[64 ];/* shadow of 0xa0000-0xaffff */ spinlock_t lock; };void stdvga_init (struct domain *d); -void stdvga_deinit (struct domain *d);extern void hvm_dpci_msi_eoi (struct domain *d,int vector);
PATCH v2 8/9 x86/HVM: drop stdvga's "lock" struct member
In reply to Jan BeulichNo state is left to protect. It being the last field, drop the struct itself as well. Similarly for then ending up empty, drop the .complete handler.
---
v2: New.
xen/arch/x86/hvm/stdvga.c +2 -23
@@ -69,8 +69,6 @@ static int cf_check stdvga_mem_write( static bool cf_check stdvga_mem_accept(const struct hvm_io_handler *handler,const ioreq_t *p) { -struct hvm_hw_stdvga *s = ¤t->domain->arch.hvm.stdvga; -/* * The range check must be done without taking the lock, to avoid * deadlock when hvm_mmio_internal() is called from
@@ -80,50 +78,31 @@ static bool cf_check stdvga_mem_accept( (ioreq_mmio_last_byte(p) >= (VGA_MEM_BASE + VGA_MEM_SIZE)) )return 0 ; -spin_lock (&s->lock); -if ( p->dir !=IOREQ_WRITE || p->data_is_ptr || p->count !=1 ) {/* * Only accept single direct writes, as that's the only thing we can * accelerate using buffered ioreq handling. */ - goto reject; +return false; } -/* s->lock intentionally held */ -return 1 ; - - reject: -spin_unlock (&s->lock); -return 0 ; -} - -static void cf_check stdvga_mem_complete(const struct hvm_io_handler *handler) -{ -struct hvm_hw_stdvga *s = ¤t->domain->arch.hvm.stdvga; - -spin_unlock (&s->lock); +return true; }static const struct hvm_io_ops stdvga_mem_ops = { .accept = stdvga_mem_accept, .read = stdvga_mem_read, .write = stdvga_mem_write, - .complete = stdvga_mem_complete };void stdvga_init (struct domain *d) { -struct hvm_hw_stdvga *s = &d->arch.hvm.stdvga;struct hvm_io_handler *handler;if ( !has_vvga (d) )return ; -memset (s,0 ,sizeof (*s)); -spin_lock_init (&s->lock); -/* VGA memory */ handler =hvm_next_io_handler (d);if ( handler )
xen/arch/x86/include/asm/hvm/domain.h +0 -1
@@ -72,7 +72,6 @@ struct hvm_domain {struct hvm_hw_vpic vpic[2 ];/* 0=master; 1=slave */ struct hvm_vioapic **vioapic;unsigned int nr_vioapics; -struct hvm_hw_stdvga stdvga;/* * hvm_hw_pmtimer is a publicly-visible name. We will defer renaming
xen/arch/x86/include/asm/hvm/io.h +0 -4
@@ -110,10 +110,6 @@ struct vpci_arch_msix_entry {int pirq; }; -struct hvm_hw_stdvga { -spinlock_t lock; -}; -void stdvga_init (struct domain *d);extern void hvm_dpci_msi_eoi (struct domain *d,int vector);
Re: [PATCH v2 8/9] x86/HVM: drop stdvga's "lock" struct member
Quoted 6 lines · Jan Beulich
No state is left to protect. It being the last field, drop the struct itself as well. Similarly for then ending up empty, drop the .complete handler.
Suggested-by Andrew Cooper <[email protected]>Signed-off-by Jan Beulich <[email protected]>
Quoted 15 lines
---
v2: New.xen/arch/x86/hvm/stdvga.c +0
-2@@ -69,8 +69,6 @@ static int cf_check stdvga_mem_write( static bool cf_check stdvga_mem_accept(const struct hvm_io_handler *handler,const ioreq_t *p) { -struct hvm_hw_stdvga *s = ¤t->domain->arch.hvm.stdvga; -/* * The range check must be done without taking the lock, to avoid * deadlock when hvm_mmio_internal() is called from
xen/arch/x86/hvm/stdvga.c static bool cf_check stdvga_mem_accept( · line 79
Quoted 2 lines
xen/arch/x86/hvm/stdvga.c +0
-0@@ -80,50 +78,31 @@ static bool cf_check stdvga_mem_accept( (ioreq_mmio_last_byte(p) >= (VGA_MEM_BASE + VGA_MEM_SIZE)) )return 0 ;
This wants adjusting too. At a minimum the comment about deadlock needs dropping, and a straight delete is fine.
However for performance, we also want to do the dir/ptr/count exclusions before the address range exclusions, meaning that ...
xen/arch/x86/hvm/stdvga.c static bool cf_check stdvga_mem_accept( · line 86
Quoted 9 lines
xen/arch/x86/hvm/stdvga.c +0
-2-spin_lock (&s->lock); -if ( p->dir !=IOREQ_WRITE || p->data_is_ptr || p->count !=1 ) {/* * Only accept single direct writes, as that's the only thing we can * accelerate using buffered ioreq handling. */
... it wants merging with this into a single expression.
~Andrew
Re: [PATCH v2 8/9] x86/HVM: drop stdvga's "lock" struct member
Quoted 9 lines · Andrew Cooper
Quoted 6 lines · Jan Beulich
No state is left to protect. It being the last field, drop the struct itself as well. Similarly for then ending up empty, drop the .complete handler.
Suggested-by Andrew Cooper <[email protected]>Signed-off-by Jan Beulich <[email protected]>
Thanks.
Quoted 9 lines
Quoted 9 lines
xen/arch/x86/hvm/stdvga.c +0
-2@@ -69,8 +69,6 @@ static int cf_check stdvga_mem_write( static bool cf_check stdvga_mem_accept(const struct hvm_io_handler *handler,const ioreq_t *p) { -struct hvm_hw_stdvga *s = ¤t->domain->arch.hvm.stdvga; -/*
Quoted 8 lines
xen/arch/x86/hvm/stdvga.c static bool cf_check stdvga_mem_accept( · line 79
Quoted 5 lines
xen/arch/x86/hvm/stdvga.c +0
-0* The range check must be done without taking the lock, to avoid * deadlock when hvm_mmio_internal() is called from @@ -80,50 +78,31 @@ static bool cf_check stdvga_mem_accept( (ioreq_mmio_last_byte(p) >= (VGA_MEM_BASE + VGA_MEM_SIZE)) )return 0 ;This wants adjusting too. At a minimum the comment about deadlock needs dropping, and a straight delete is fine.
Oh, of course. I meant to but then forgot.
Quoted 13 lines
However for performance, we also want to do the dir/ptr/count exclusions before the address range exclusions, meaning that ...
xen/arch/x86/hvm/stdvga.c static bool cf_check stdvga_mem_accept( · line 86
Quoted 9 lines
xen/arch/x86/hvm/stdvga.c +0
-2-spin_lock (&s->lock); -if ( p->dir !=IOREQ_WRITE || p->data_is_ptr || p->count !=1 ) {/* * Only accept single direct writes, as that's the only thing we can * accelerate using buffered ioreq handling. */
Quoted 1 line
... it wants merging with this into a single expression.
I'm not convinced, and hence would at least want to keep this separate. Which exact order checks want doing in would require more detailed analysis imo. Or do you have blindingly obvious reasons to believe that the re-ordering you suggest is always going to be an improvement?
Jan
Re: [PATCH v2 8/9] x86/HVM: drop stdvga's "lock" struct member
Quoted 14 lines · Jan Beulich
Quoted 13 lines · Andrew Cooper
On 11/09/2024 1:29 pm, Jan Beulich wrote:
However for performance, we also want to do the dir/ptr/count exclusions before the address range exclusions, meaning that ...Quoted 9 lines
xen/arch/x86/hvm/stdvga.c +0
-2-spin_lock (&s->lock); -if ( p->dir !=IOREQ_WRITE || p->data_is_ptr || p->count !=1 ) {/* * Only accept single direct writes, as that's the only thing we can * accelerate using buffered ioreq handling. */
Quoted 5 lines
Quoted 1 line
... it wants merging with this into a single expression.
I'm not convinced, and hence would at least want to keep this separate. Which exact order checks want doing in would require more detailed analysis imo. Or do you have blindingly obvious reasons to believe that the re-ordering you suggest is always going to be an improvement?
I'm not overly fussed if this is delayed to a later patch. My review stands as long as the comment is gone.
But, right now, accept() is called linearly over all handlers (there's not range based registration) so *every* IO comes through this logic path.
The likely path is the excluded path. ioreq_mmio_{first,last}_byte() are non-trivial logic because they account for DF, so being able to exclude based on direction/size before the DF calculations is a definite improvement.
~Andrew
Re: [PATCH v2 8/9] x86/HVM: drop stdvga's "lock" struct member
Quoted 21 lines · Andrew Cooper
Quoted 14 lines · Jan Beulich
Quoted 13 lines · Andrew Cooper
On 11/09/2024 1:29 pm, Jan Beulich wrote:
However for performance, we also want to do the dir/ptr/count exclusions before the address range exclusions, meaning that ...Quoted 9 lines
xen/arch/x86/hvm/stdvga.c +0
-2-spin_lock (&s->lock); -if ( p->dir !=IOREQ_WRITE || p->data_is_ptr || p->count !=1 ) {/* * Only accept single direct writes, as that's the only thing we can * accelerate using buffered ioreq handling. */ Quoted 5 lines
Quoted 1 line
... it wants merging with this into a single expression.
I'm not convinced, and hence would at least want to keep this separate. Which exact order checks want doing in would require more detailed analysis imo. Or do you have blindingly obvious reasons to believe that the re-ordering you suggest is always going to be an improvement?
Quoted 5 lines
I'm not overly fussed if this is delayed to a later patch. My review stands as long as the comment is gone.
But, right now,
accept()is called linearly over all handlers (there's not range based registration) so *every* IO comes through this logic path.
Not exactly every, only ones not claimed earlier. But yes.
Quoted 4 lines
The likely path is the excluded path. ioreq_mmio_{first,last}_byte() are non-trivial logic because they account for DF, so being able to exclude based on direction/size before the DF calculations is a definite improvement.
Perhaps. Yet if we were to re-order, calling ioreq_mmio_{first,last}_byte() becomes questionable in the first place. I wouldn't expect the compiler to spot that it can reduce those expressions as a result of knowing ->count being 1 (and hence ->df playing no role at all). Maybe I'm overly pessimistic ...
Jan
PATCH v2 9/9 x86/HVM: drop .complete hook for intercept handling
In reply to Jan BeulichNo user of the hook exists anymore.
While touching hvm_mmio_internal() also make direction of the request explicit - it only so happens that IOREQ_WRITE is zero. Yet it being a write is imperative for stdvga.c to "accept" the request.
---
v2: New.
xen/arch/x86/hvm/intercept.c +3 -21
@@ -240,21 +240,13 @@ static const struct hvm_io_handler *hvm_int hvm_io_intercept (ioreq_t *p) {const struct hvm_io_handler *handler; -const struct hvm_io_ops *ops; -int rc; handler =hvm_find_io_handler (p);if ( handler ==NULL )return X86EMUL_UNHANDLEABLE ; - rc =hvm_process_io_intercept (handler, p); - - ops = handler->ops; -if ( ops->complete !=NULL ) - ops->complete (handler); - -return rc; +return hvm_process_io_intercept (handler, p); }struct hvm_io_handler *hvm_next_io_handler (struct domain *d)
@@ -326,25 +318,15 @@ bool relocate_portio_handler(struct domabool hvm_mmio_internal (paddr_t gpa) { -const struct hvm_io_handler *handler; -const struct hvm_io_ops *ops;ioreq_t p = { .type =IOREQ_TYPE_COPY , .addr = gpa, .count =1 , .size =1 , + .dir =IOREQ_WRITE ,/* for stdvga */ }; - handler =hvm_find_io_handler (&p); - -if ( handler ==NULL ) -return 0 ; - - ops = handler->ops; -if ( ops->complete !=NULL ) - ops->complete (handler); - -return 1 ; +return hvm_find_io_handler (&p); }/*
xen/arch/x86/include/asm/hvm/io.h +0 -2
@@ -56,13 +56,11 @@ typedef int (*hvm_io_write_t)(const stru uint64_t data);typedef bool (*hvm_io_accept_t )(const struct hvm_io_handler *handler,const ioreq_t *p); -typedef void (*hvm_io_complete_t )(const struct hvm_io_handler *handler);struct hvm_io_ops {hvm_io_accept_t accept;hvm_io_read_t read;hvm_io_write_t write; -hvm_io_complete_t complete; }; int hvm_process_io_intercept(const struct hvm_io_handler *handler,
Re: [PATCH v2 9/9] x86/HVM: drop .complete hook for intercept handling
Quoted 8 lines · Jan Beulich
No user of the hook exists anymore.
While touching
hvm_mmio_internal()also make direction of the request explicit - it only so happens thatIOREQ_WRITEis zero. Yet it being a write is imperative forstdvga.cto "accept" the request.Requested-by Andrew Cooper <[email protected]>Signed-off-by Jan Beulich <[email protected]>
I am reminded of my opinion that hvm_mmio_internal() is a gross layering violation.