Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3298755
  • 博文数量: 258
  • 博客积分: 9440
  • 博客等级: 少将
  • 技术积分: 6998
  • 用 户 组: 普通用户
  • 注册时间: 2009-05-03 10:28
个人简介

-- linux爱好者,业余时间热衷于分析linux内核源码 -- 目前主要研究云计算和虚拟化相关的技术,主要包括libvirt/qemu,openstack,opennebula架构和源码分析。 -- 第五届云计算大会演讲嘉宾 微博:@Marshal-Liu

文章分类

全部博文(258)

文章存档

2016年(1)

2015年(4)

2014年(16)

2013年(22)

2012年(41)

2011年(59)

2010年(40)

2009年(75)

分类: LINUX

2009-11-26 10:08:38

On Tue, 2007-09-11 at 15:07 +0900, Alexandre Courbot wrote:
> Hello Rusty, thanks for your reply!
>
> > Yes, I'm not surprised it fails. We don't support debug register
> > manipulation in the guest. Not for any particularly good reason, mind
> > you, I just never got around to it and you're the first person to want
> > it.
> >
> > It's not that hard to do, but it requires some understanding of debug
> > registers. Anyone with an Intel manual can implement it (a new
> > hypercall plus some sanity checking plus restoring debug registers
> > before entering the guest).
>
> Allright, I see. So maybe I could have a look at this stuff then - I'm
> neither a kernel expert nor do I know much about debug registers, but
> maybe with the proper documentation I could come with something.
> Lguest by itself is rather compact and well documented, which would
> help a lot. Do you think that would be realistic in a reasonable
> amount of time, or would it require more experience?

No, it should be straight forward if you do it one piece at a time.
Intel's manuals are on their web site (you want System Programming Guide
Part 2, Chapter 18 Debugging and Performance Monitoring).

The process would look like this:

1) Add hypercalls LHCALL_SET_DEBUGREG(regnum, val) and
LHCALL_GET_DEBUGREG(regnum).

2) Hook them into the get_debugreg and set_debugreg entries in
paravirt_ops.

3) Add a debugregs[8] array into struct lguest, and make the hypercalls
set and get them.

4) Sanity check what they put in those registers. Registers 0 to 3 are
breakpoint addresses (don't let them put switcher addresses here!).
Register 7 is the control register: see arch/i386/kernel/ptrace.c to
see how the kernel checks it from userspace.

5) In copy_in_guest_info(), set the debug reg 7 to 0 to disable all
breakpoints, then set debug regs 0-3 from debugregs[].

6) In the switcher, set reg 7 to what guest expects (it has to be in the
switcher, otherwise the guest might cause a breakpoint in the host).
This might be a bit tricky, but perhaps you can put it on top of the
stack?

7) When the guest flips back, if the trap is a debug trap, save the
debug reg 6 (the status register).

Then add optimizations to taste...

Cheers!
Rusty.
阅读(2240) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~