2007-09-14 05:15:03

by Rusty Russell

[permalink] [raw]
Subject: [PATCH] Introduce "used_vectors" bitmap which can be used to reserve vectors.

Hi Andi and everyone,

Wanted to get your thoughts on this patch. lguest now supports plan9
guests which use 0x40 for system calls. We want to let the guests use
that vector if available, but have no way to stop io_apic from
clobbering it. This does that, and also simplifies the current code a
little.

Thanks,
Rusty.

This simplifies the io_apic.c __assign_irq_vector() logic and removes
the explicit SYSCALL_VECTOR check, and also allows for vectors to be
reserved by other mechanisms (ie. lguest).

Signed-off-by: Rusty Russell <[email protected]>

---
arch/i386/kernel/i8259.c | 3 ++-
arch/i386/kernel/io_apic.c | 13 ++++++++-----
arch/i386/kernel/traps.c | 10 ++++++++++
include/asm-i386/irq.h | 3 +++
4 files changed, 23 insertions(+), 6 deletions(-)

===================================================================
--- a/arch/i386/kernel/i8259.c
+++ b/arch/i386/kernel/i8259.c
@@ -400,7 +400,8 @@ void __init native_init_IRQ(void)
int vector = FIRST_EXTERNAL_VECTOR + i;
if (i >= NR_IRQS)
break;
- if (vector != SYSCALL_VECTOR)
+ /* SYSCALL_VECTOR was reserved in trap_init. */
+ if (!test_bit(vector, used_vectors))
set_intr_gate(vector, interrupt[i]);
}

===================================================================
--- a/arch/i386/kernel/io_apic.c
+++ b/arch/i386/kernel/io_apic.c
@@ -1198,7 +1198,7 @@ static int __assign_irq_vector(int irq)
static int __assign_irq_vector(int irq)
{
static int current_vector = FIRST_DEVICE_VECTOR, current_offset = 0;
- int vector, offset, i;
+ int vector, offset;

BUG_ON((unsigned)irq >= NR_IRQ_VECTORS);

@@ -1215,11 +1215,8 @@ next:
}
if (vector == current_vector)
return -ENOSPC;
- if (vector == SYSCALL_VECTOR)
+ if (test_and_set_bit(vector, used_vectors))
goto next;
- for (i = 0; i < NR_IRQ_VECTORS; i++)
- if (irq_vector[i] == vector)
- goto next;

current_vector = vector;
current_offset = offset;
@@ -2290,6 +2287,12 @@ static inline void __init check_timer(vo

void __init setup_IO_APIC(void)
{
+ int i;
+
+ /* Reserve all the system vectors. */
+ for (i = FIRST_SYSTEM_VECTOR; i < NR_VECTORS; i++)
+ set_bit(i, used_vectors);
+
enable_IO_APIC();

if (acpi_ioapic)
===================================================================
--- a/arch/i386/kernel/traps.c
+++ b/arch/i386/kernel/traps.c
@@ -64,6 +64,9 @@
#include "mach_traps.h"

int panic_on_unrecovered_nmi;
+
+DECLARE_BITMAP(used_vectors, NR_VECTORS);
+EXPORT_SYMBOL_GPL(used_vectors);

asmlinkage int system_call(void);

@@ -1156,6 +1159,8 @@ static void __init set_task_gate(unsigne

void __init trap_init(void)
{
+ int i;
+
#ifdef CONFIG_EISA
void __iomem *p = ioremap(0x0FFFD9, 4);
if (readl(p) == 'E'+('I'<<8)+('S'<<16)+('A'<<24)) {
@@ -1215,6 +1220,11 @@ void __init trap_init(void)

set_system_gate(SYSCALL_VECTOR,&system_call);

+ /* Reserve all the builtin and the syscall vector. */
+ for (i = 0; i < FIRST_EXTERNAL_VECTOR; i++)
+ set_bit(i, used_vectors);
+ set_bit(SYSCALL_VECTOR, used_vectors);
+
/*
* Should be a barrier for any external CPU state.
*/
===================================================================
--- a/include/asm-i386/irq.h
+++ b/include/asm-i386/irq.h
@@ -45,4 +45,7 @@ void init_IRQ(void);
void init_IRQ(void);
void __init native_init_IRQ(void);

+/* Interrupt vector management */
+extern DECLARE_BITMAP(used_vectors, NR_VECTORS);
+
#endif /* _ASM_IRQ_H */



2007-09-14 07:51:48

by Andi Kleen

[permalink] [raw]
Subject: Re: [PATCH] Introduce "used_vectors" bitmap which can be used to reserve vectors.

On Fri, Sep 14, 2007 at 03:14:09PM +1000, Rusty Russell wrote:
> This simplifies the io_apic.c __assign_irq_vector() logic and removes
> the explicit SYSCALL_VECTOR check, and also allows for vectors to be
> reserved by other mechanisms (ie. lguest).

Seems reasonable even as a cleanup.

>
> int panic_on_unrecovered_nmi;
> +
> +DECLARE_BITMAP(used_vectors, NR_VECTORS);
> +EXPORT_SYMBOL_GPL(used_vectors);

But what is the export good for? Since it's only used at boot
a module cannot do anything useful with it.

-Andi

2007-09-15 02:14:57

by Rusty Russell

[permalink] [raw]
Subject: Re: [PATCH] Introduce "used_vectors" bitmap which can be used to reserve vectors.

On Fri, 2007-09-14 at 09:44 +0200, Andi Kleen wrote:
> On Fri, Sep 14, 2007 at 03:14:09PM +1000, Rusty Russell wrote:
> > This simplifies the io_apic.c __assign_irq_vector() logic and removes
> > the explicit SYSCALL_VECTOR check, and also allows for vectors to be
> > reserved by other mechanisms (ie. lguest).
>
> Seems reasonable even as a cleanup.
>
> >
> > int panic_on_unrecovered_nmi;
> > +
> > +DECLARE_BITMAP(used_vectors, NR_VECTORS);
> > +EXPORT_SYMBOL_GPL(used_vectors);
>
> But what is the export good for? Since it's only used at boot
> a module cannot do anything useful with it.

Hmm, maybe I misunderstood. I assumed that create_irq() was also called
later to get irqs for any devices which appeared later. Although I can
at least check it's not in use.

The current lguest patch uses it like so (syscall_vector is a module
parameter):

int init_interrupts(void)
{
/* If they want some strange system call vector, reserve it now */
if (syscall_vector != SYSCALL_VECTOR
&& test_and_set_bit(syscall_vector, used_vectors)) {
printk("lg: couldn't reserve syscall %u\n", syscall_vector);
return -EBUSY;
}
return 0;
}

Thanks,
Rusty.


2007-09-18 22:39:09

by ron minnich

[permalink] [raw]
Subject: Re: [Lguest] [PATCH] Introduce "used_vectors" bitmap which can be used to reserve vectors.

On 9/13/07, Rusty Russell <[email protected]> wrote:
> Hi Andi and everyone,
>
> Wanted to get your thoughts on this patch. lguest now supports plan9
> guests which use 0x40 for system calls. We want to let the guests use
> that vector if available, but have no way to stop io_apic from
> clobbering it. This does that, and also simplifies the current code a
> little.

I can confirm that this patch supports Plan 9 perfectly as a guest.

thanks

ron