提交 f23b070e 编写于 作者: X Xiao Guangrong 提交者: Avi Kivity

KVM: x86 emulator: simplify read_emulated

No need split mmio read region into 8-bits pieces since we do it in
emulator_read_write_onepage

Changelog:
  Add a WARN_ON to check read-cache overflow
Acked-by: NMarcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: NXiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
Signed-off-by: NAvi Kivity <avi@redhat.com>
上级 a2766325
...@@ -1166,24 +1166,21 @@ static int read_emulated(struct x86_emulate_ctxt *ctxt, ...@@ -1166,24 +1166,21 @@ static int read_emulated(struct x86_emulate_ctxt *ctxt,
int rc; int rc;
struct read_cache *mc = &ctxt->mem_read; struct read_cache *mc = &ctxt->mem_read;
while (size) { if (mc->pos < mc->end)
int n = min(size, 8u); goto read_cached;
size -= n;
if (mc->pos < mc->end)
goto read_cached;
rc = ctxt->ops->read_emulated(ctxt, addr, mc->data + mc->end, n,
&ctxt->exception);
if (rc != X86EMUL_CONTINUE)
return rc;
mc->end += n;
read_cached: WARN_ON((mc->end + size) >= sizeof(mc->data));
memcpy(dest, mc->data + mc->pos, n);
mc->pos += n; rc = ctxt->ops->read_emulated(ctxt, addr, mc->data + mc->end, size,
dest += n; &ctxt->exception);
addr += n; if (rc != X86EMUL_CONTINUE)
} return rc;
mc->end += size;
read_cached:
memcpy(dest, mc->data + mc->pos, size);
mc->pos += size;
return X86EMUL_CONTINUE; return X86EMUL_CONTINUE;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册