Skip to contentSkip to conversation

Problem setting up a custom GDT

DISCUSSION Simon Kagstrom 3 participants 4 messages Jun 9, 2006 – Jun 12, 2006

lore
Share & tools
lore
#0 lore raw

Hello!

I have some problems setting up a custom GDT (I need one where the code is readable). Anyway, I try to switch to my own GDT as follows:

   unsigned long frames[16];

   volatile unsigned long va = (unsigned long)GDT;
   volatile unsigned long pa = to_phys(va);
   volatile unsigned long ma = phys_to_machine(pa) & ~_PAGE_RW  | _PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_DIRTY;

   /* Make it read-only */
   HYPERVISOR_update_va_mapping(va, (pte_t){ ma }, 0);
   frames[0] = ma;

   int ret = HYPERVISOR_set_gdt(frames, 16);

(The GDT Is just copied from Linux' right now). When doing this, I always get -EINVAL from set_gdt, which I suspect is because HYPERVISOR_update_va_mapping for some reason does not succeed in setting the page read-only.

I've checked the Linux implementation, and it does basically the same thing (pte_wrprotect() on the machine-address before calling update_va_mapping). Does anyone see what is wrong here?

// Simon

#1 lore raw
Quoted 27 lines · Simon Kagstrom

Hello!

I have some problems setting up a custom GDT (I need one where the code is readable). Anyway, I try to switch to my own GDT as follows:

  unsigned long frames[16];

  volatile unsigned long va = (unsigned long)GDT;
  volatile unsigned long pa = to_phys(va);
  volatile unsigned long ma = phys_to_machine(pa) & ~_PAGE_RW  | _PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_DIRTY;

  /* Make it read-only */
  HYPERVISOR_update_va_mapping(va, (pte_t){ ma }, 0);
  frames[0] = ma;

  int ret = HYPERVISOR_set_gdt(frames, 16);

(The GDT Is just copied from Linux' right now). When doing this, I always get -EINVAL from set_gdt, which I suspect is because HYPERVISOR_update_va_mapping for some reason does not succeed in setting the page read-only.

I've checked the Linux implementation, and it does basically the same thing (pte_wrprotect() on the machine-address before calling update_va_mapping). Does anyone see what is wrong here?

Quoted 8 lines

// Simon

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

The machine address you pass to Xen is a page table entry. Xen want a machine frame number.

frames[0] = ma >> PAGE_SHIFT;

should fix you problem.

Mathieu

#2 lore raw

At Fri, 09 Jun 2006 13:07:02 +0200,

Quoted 18 lines · Mathieu Ropert
Quoted 5 lines · Simon Kagstrom

Hello!

I have some problems setting up a custom GDT (I need one where the code is readable). Anyway, I try to switch to my own GDT as follows:

Quoted 9 lines
  unsigned long frames[16];

  volatile unsigned long va = (unsigned long)GDT;
  volatile unsigned long pa = to_phys(va);
  volatile unsigned long ma = phys_to_machine(pa) & ~_PAGE_RW  | _PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_DIRTY;

  /* Make it read-only */
  HYPERVISOR_update_va_mapping(va, (pte_t){ ma }, 0);
  frames[0] = ma;
Quoted 6 lines

The machine address you pass to Xen is a page table entry. Xen want a machine frame number.

frames[0] = ma >> PAGE_SHIFT;

should fix you problem.

Ah, thank you! This fixed the problem!

I see now that Linux uses virt_to_mfn() - I should have looked at that one...

// Simon

#3 lore raw
In reply to Simon Kagstrom
Quoted 8 lines · Simon Kagstrom

(The GDT Is just copied from Linux' right now). When doing this, I always get -EINVAL from set_gdt, which I suspect is because HYPERVISOR_update_va_mapping for some reason does not succeed in setting the page read-only.

I've checked the Linux implementation, and it does basically the same thing (pte_wrprotect() on the machine-address before calling update_va_mapping). Does anyone see what is wrong here?

Is your GDT page-aligned and -padded.

-- Keir