On Tue, 2007-07-17 at 16:25 +0300, Avi Kivity wrote: > Rusty Russell wrote: > > Creating one's own BITMAP macro seems suboptimal: if we use manual > > arithmetic in the one place exposed to userspace, we can use standard > > macros elsewhere. > > > > The - 7 + 8 calc is overkill: can NR_IRQ_WORDS ever really change? > > > > Looks like it can:
Sure, but the number 256 is part of the x86 architecture. A paravirt guest could choose to have more interrupts, but is there really a point? > > /* for KVM_CREATE_MEMORY_REGION */ > > struct kvm_memory_region { > > @@ -163,7 +157,7 @@ struct kvm_sregs { > > __u64 cr0, cr2, cr3, cr4, cr8; > > __u64 efer; > > __u64 apic_base; > > - __u64 interrupt_bitmap[KVM_IRQ_BITMAP_SIZE(__u64)]; > > + __u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 7) / 8]; > > }; > > > > > > The size is in bytes, but the element type is __u64. Doh, fixed here: == Use standard BITMAP macros, open-code userspace-exposed header. Creating one's own BITMAP macro seems suboptimal: if we use manual arithmetic in the one place exposed to userspace, we can use standard macros elsewhere. Signed-off-by: Rusty Russell <[EMAIL PROTECTED]> diff -r 85a8c51d3df8 drivers/kvm/kvm.h --- a/drivers/kvm/kvm.h Tue Jul 17 13:10:00 2007 +1000 +++ b/drivers/kvm/kvm.h Tue Jul 17 13:15:22 2007 +1000 @@ -342,8 +342,7 @@ struct kvm_vcpu { int guest_mode; unsigned long requests; unsigned long irq_summary; /* bit vector: 1 per word in irq_pending */ -#define NR_IRQ_WORDS KVM_IRQ_BITMAP_SIZE(unsigned long) - unsigned long irq_pending[NR_IRQ_WORDS]; + DECLARE_BITMAP(irq_pending, KVM_NR_INTERRUPTS); unsigned long regs[NR_VCPU_REGS]; /* for rsp: vcpu_load_rsp_rip() */ unsigned long rip; /* needs vcpu_load_rsp_rip() */ diff -r 85a8c51d3df8 drivers/kvm/kvm_main.c --- a/drivers/kvm/kvm_main.c Tue Jul 17 13:10:00 2007 +1000 +++ b/drivers/kvm/kvm_main.c Tue Jul 17 16:26:10 2007 +1000 @@ -2122,7 +2122,7 @@ static int kvm_vcpu_ioctl_set_sregs(stru memcpy(vcpu->irq_pending, sregs->interrupt_bitmap, sizeof vcpu->irq_pending); vcpu->irq_summary = 0; - for (i = 0; i < NR_IRQ_WORDS; ++i) + for (i = 0; i < ARRAY_SIZE(vcpu->irq_pending); ++i) if (vcpu->irq_pending[i]) __set_bit(i, &vcpu->irq_summary); diff -r 85a8c51d3df8 include/linux/kvm.h --- a/include/linux/kvm.h Tue Jul 17 13:10:00 2007 +1000 +++ b/include/linux/kvm.h Tue Jul 17 13:25:48 2007 +1000 @@ -12,14 +12,8 @@ #define KVM_API_VERSION 12 -/* - * Architectural interrupt line count, and the size of the bitmap needed - * to hold them. - */ +/* Architectural interrupt line count. */ #define KVM_NR_INTERRUPTS 256 -#define KVM_IRQ_BITMAP_SIZE_BYTES ((KVM_NR_INTERRUPTS + 7) / 8) -#define KVM_IRQ_BITMAP_SIZE(type) (KVM_IRQ_BITMAP_SIZE_BYTES / sizeof(type)) - /* for KVM_CREATE_MEMORY_REGION */ struct kvm_memory_region { @@ -163,7 +157,7 @@ struct kvm_sregs { __u64 cr0, cr2, cr3, cr4, cr8; __u64 efer; __u64 apic_base; - __u64 interrupt_bitmap[KVM_IRQ_BITMAP_SIZE(__u64)]; + __u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 63) / 64]; }; struct kvm_msr_entry { ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel