From: "Jan Beulich" Subject: Re: [PATCH] xen: Disable emulate.c REP optimization if introspection is active Date: Mon, 03 Nov 2014 10:00:25 +0000 Message-ID: <54576049020000780004446E@mail.emea.novell.com> References: <1415007578-7584-1-git-send-email-rcojocaru@bitdefender.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1415007578-7584-1-git-send-email-rcojocaru@bitdefender.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Razvan Cojocaru Cc: keir@xen.org, xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org >>> On 03.11.14 at 10:39, wrote: > --- a/xen/arch/x86/hvm/emulate.c > +++ b/xen/arch/x86/hvm/emulate.c > @@ -395,6 +395,7 @@ static int hvmemul_virtual_to_linear( > { > struct segment_register *reg; > int okay; > + struct domain *currd = current->domain; This is being used just once and hence not really worthwhile. > @@ -402,12 +403,15 @@ 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); > + if ( currd->arch.hvm_domain.introspection_enabled ) > + *reps = 1; > + else > + /* > + * 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); With introspection_enabled supposedly being the unusual case (at least for the majority of current users), a likely()/unlikely() annotation should be used here. Further, with it being unclear (at least from patch description and context alone) whether *reps could legally be zero when getting here, I'd prefer *reps = min_t(unsigned long, *reps, unlikely(current->domain->arch.hvm_domain.introspection_enabled) ? 1 : 4096); Perhaps with an adjustment to the comment explaining why. Jan