Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753881AbcJKSXo (ORCPT ); Tue, 11 Oct 2016 14:23:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57708 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752992AbcJKSXm (ORCPT ); Tue, 11 Oct 2016 14:23:42 -0400 Date: Tue, 11 Oct 2016 20:23:37 +0200 From: Radim =?utf-8?B?S3LEjW3DocWZ?= To: "Longpeng(Mike)" Cc: pbonzini@redhat.com, tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, zhaoshenglong@huawei.com, richard.weiyang@huawei.com Subject: Re: [PATCH] kvm: x86: correct the misleading comment in vmx_handle_external_intr Message-ID: <20161011182337.GB16406@potion> References: <1476059023-33224-1-git-send-email-longpeng2@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1476059023-33224-1-git-send-email-longpeng2@huawei.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 11 Oct 2016 18:23:41 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2154 Lines: 47 2016-10-10 08:23+0800, Longpeng(Mike): > Since Paolo has removed irq-enable-operation in vmx_handle_external_intr > (KVM: x86: use guest_exit_irqoff), the original comment about the IF bit > in rflags is incorrect now. > > Signed-off-by: Longpeng(Mike) > --- > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > @@ -8647,9 +8647,12 @@ static void vmx_handle_external_intr(struct kvm_vcpu *vcpu) > register void *__sp asm(_ASM_SP); > > /* > - * If external interrupt exists, IF bit is set in rflags/eflags on the > - * interrupt stack frame, and interrupt will be enabled on a return > - * from interrupt handler. Good catch, thanks. We want to change it, but I think that the new comment is an overkill. I am generally not a fan of code comments that describe what the code does; code speaks for itself and it is better to fix the code, e.g. split into well named functions, instead of duplicating it. > + * If external interrupt exists, fakes an interrupt stack and jump to > + * idt table to let real handler to handle it. This is the duplication I was talking about. If the corresponding part of the code is not obvious, it would be better to rework it instead. > Because most of bits in > + * rflags are cleared when VM exit(Intel SDM volum 3, chapter 27.5.3), > + * the IF bit is 0 in rflags on the interrupt stack frame, so interrupt > + * is still disabled when return from the irq handler, but it will be > + * enabled later by the caller. This part is acceptable as it gives a new information code, yet the function does not modify flags, which makes it unremarkable. And dependencies on the caller would be better described in a header (if we cannot express them well in the code). The most comment-worthy thing about this function is the reason why we execute the interrupt handler manually, i.e. the dependency on VM_EXIT_ACK_INTR_ON_EXIT, but that is easy to tell from the commit message and convenient access to git history is essential in a workflow, so providing a leeway could be counter-productive. I would go with no comment for now.