From aa6af210f6a8684e7a5a8c7e66b44d482902b01c Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Tue, 19 Aug 2008 18:52:04 +0100 Subject: [PATCH] x86 hvm: Add clarifying comments about clipping repeated string instructions to 4096 iterations. Signed-off-by: Keir Fraser --- xen/arch/x86/hvm/emulate.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/hvm/emulate.c b/xen/arch/x86/hvm/emulate.c index 7b7ac5b09c..60a815c7e5 100644 --- a/xen/arch/x86/hvm/emulate.c +++ b/xen/arch/x86/hvm/emulate.c @@ -210,7 +210,10 @@ static int hvmemul_linear_to_phys( unsigned long pfn, npfn, done, todo, i; int reverse; - /* Clip repetitions to a sensible maximum. */ + /* + * Clip repetitions to a sensible maximum. This avoids extensive looping in + * this function while still amortising the cost of I/O trap-and-emulate. + */ *reps = min_t(unsigned long, *reps, 4096); /* With no paging it's easy: linear == physical. */ @@ -297,7 +300,13 @@ static int hvmemul_virtual_to_linear( return X86EMUL_OKAY; } + /* + * Clip repetitions to avoid overflow when multiplying by @bytes_per_rep. + * The chosen maximum is very conservative but it's what we use in + * hvmemul_linear_to_phys() so there is no point in using a larger value. + */ *reps = min_t(unsigned long, *reps, 4096); + reg = hvmemul_get_seg_reg(seg, hvmemul_ctxt); if ( (hvmemul_ctxt->ctxt.regs->eflags & X86_EFLAGS_DF) && (*reps > 1) ) -- 2.30.2