Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.1 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C680C43461 for ; Mon, 7 Sep 2020 09:43:49 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DFE8D2075A for ; Mon, 7 Sep 2020 09:43:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DFE8D2075A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kFDgO-0007Ob-Ks; Mon, 07 Sep 2020 09:43:28 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kFDgN-0007OW-La for xen-devel@lists.xenproject.org; Mon, 07 Sep 2020 09:43:27 +0000 X-Inumbo-ID: 0683b9d3-48df-4088-b8e6-89eca4de28fa Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 0683b9d3-48df-4088-b8e6-89eca4de28fa; Mon, 07 Sep 2020 09:43:26 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id BC3DDAC3C; Mon, 7 Sep 2020 09:43:26 +0000 (UTC) Subject: Re: [PATCH v3] x86/HVM: more consistently set I/O completion To: paul@xen.org Cc: xen-devel@lists.xenproject.org, 'Andrew Cooper' , 'Wei Liu' , =?UTF-8?B?J1JvZ2VyIFBhdSBNb25uw6kn?= , 'Jun Nakajima' , 'Kevin Tian' , 'George Dunlap' References: <96a4cc9b-b1fd-494c-9e99-6d3ca733dea9@suse.com> <003301d682d6$d4b5ba20$7e212e60$@xen.org> From: Jan Beulich Message-ID: <7efe7de4-bde4-a769-5817-b64b0e757a3f@suse.com> Date: Mon, 7 Sep 2020 11:43:24 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <003301d682d6$d4b5ba20$7e212e60$@xen.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" On 04.09.2020 18:17, Paul Durrant wrote: >> @@ -2610,8 +2612,13 @@ static const struct x86_emulate_ops hvm_ >> .vmfunc = hvmemul_vmfunc, >> }; >> >> +/* >> + * Note that passing HVMIO_no_completion into this function serves as kind >> + * of (but not fully) an "auto select completion" indicator. >> + */ >> static int _hvm_emulate_one(struct hvm_emulate_ctxt *hvmemul_ctxt, >> - const struct x86_emulate_ops *ops) >> + const struct x86_emulate_ops *ops, >> + enum hvm_io_completion completion) >> { >> const struct cpu_user_regs *regs = hvmemul_ctxt->ctxt.regs; >> struct vcpu *curr = current; >> @@ -2642,16 +2649,31 @@ static int _hvm_emulate_one(struct hvm_e >> rc = X86EMUL_RETRY; >> >> if ( !hvm_ioreq_needs_completion(&vio->io_req) ) >> + completion = HVMIO_no_completion; > > The comment doesn't mention that passing in something other than > HVMIO_no_completion could get overridden. Is that intentional? Well, it was, but since you seem to be asking for it I've added "When there's no completion needed, the passed in value will be ignored in any case." >> + else if ( completion == HVMIO_no_completion ) >> + completion = (vio->io_req.type != IOREQ_TYPE_PIO || >> + hvmemul_ctxt->is_mem_access) ? HVMIO_mmio_completion >> + : HVMIO_pio_completion; >> + >> + switch ( vio->io_completion = completion ) > > I thought we tended to avoid assignments in control flow statements. In if() we do, because of the ambiguity whether == might have been meant instead. But in switch() there's imo no such ambiguity - if == was really meant, if() would better be used anyway. We have quite a few cases of this elsewhere, and I think some of them are reasonably recent introductions. As you're the maintainer of the file, if you strongly think I shouldn't do so, I'll switch of course. >> @@ -2727,8 +2752,8 @@ int hvm_emulate_one_mmio(unsigned long m >> hvm_emulate_init_once(&ctxt, x86_insn_is_mem_write, >> guest_cpu_user_regs()); >> ctxt.ctxt.data = &mmio_ro_ctxt; >> - rc = _hvm_emulate_one(&ctxt, ops); >> - switch ( rc ) >> + >> + switch ( rc = _hvm_emulate_one(&ctxt, ops, HVMIO_no_completion) ) > > Again, why move the assignment into the switch statement? For consistency with the other cases where this gets introduced in this patch, at least. I for one consider this the more concise way of writing such code. >> --- a/xen/arch/x86/hvm/vmx/realmode.c >> +++ b/xen/arch/x86/hvm/vmx/realmode.c >> @@ -97,15 +97,11 @@ static void realmode_deliver_exception( >> void vmx_realmode_emulate_one(struct hvm_emulate_ctxt *hvmemul_ctxt) >> { >> struct vcpu *curr = current; >> - struct hvm_vcpu_io *vio = &curr->arch.hvm.hvm_io; >> int rc; >> >> perfc_incr(realmode_emulations); >> >> - rc = hvm_emulate_one(hvmemul_ctxt); >> - >> - if ( hvm_ioreq_needs_completion(&vio->io_req) ) >> - vio->io_completion = HVMIO_realmode_completion; >> + rc = hvm_emulate_one(hvmemul_ctxt, HVMIO_realmode_completion); > > Ok, I guess the override of completion is intentional to deal with > this case. Perhaps expand the comment above _hvm_emulate_one() then. Right, done as per above. Let me know whether the text still isn't sufficient. >> --- a/xen/include/asm-x86/hvm/emulate.h >> +++ b/xen/include/asm-x86/hvm/emulate.h >> @@ -48,6 +48,8 @@ struct hvm_emulate_ctxt { >> >> uint32_t intr_shadow; >> >> + bool is_mem_access; >> + > > Whilst you mention in the commit comment why this is added, I don't > see any consumer if it in this patch. Will the come later? hvmemul_validate() sets the field, and _hvm_emulate_one() consumes it. Jan