From mboxrd@z Thu Jan 1 00:00:00 1970 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=-5.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 337B9C4363D for ; Fri, 2 Oct 2020 09:40:04 +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 C0AF4206DD for ; Fri, 2 Oct 2020 09:40:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="I79Gb8FN" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C0AF4206DD Authentication-Results: mail.kernel.org; dmarc=fail (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 list by lists.xenproject.org with outflank-mailman.1767.5418 (Exim 4.92) (envelope-from ) id 1kOHXc-0006pL-81; Fri, 02 Oct 2020 09:39:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1767.5418; Fri, 02 Oct 2020 09:39:52 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kOHXc-0006pE-4t; Fri, 02 Oct 2020 09:39:52 +0000 Received: by outflank-mailman (input) for mailman id 1767; Fri, 02 Oct 2020 09:39:50 +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 1kOHXa-0006p9-KD for xen-devel@lists.xenproject.org; Fri, 02 Oct 2020 09:39:50 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 7669fb16-605d-4029-89d3-dbd7f3dff688; Fri, 02 Oct 2020 09:39:49 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 8E8A0AC54; Fri, 2 Oct 2020 09:39:48 +0000 (UTC) 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 1kOHXa-0006p9-KD for xen-devel@lists.xenproject.org; Fri, 02 Oct 2020 09:39:50 +0000 X-Inumbo-ID: 7669fb16-605d-4029-89d3-dbd7f3dff688 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 7669fb16-605d-4029-89d3-dbd7f3dff688; Fri, 02 Oct 2020 09:39:49 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1601631588; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JjOM2wsX9un7MyyNRT0QnyhHaldtAv+oXZi3z52RjaY=; b=I79Gb8FNHptVGe26fFZc5ZF09u2kas+Cwm8g8XupsS4mA0cZr8yk+mGG71/Wr5A6m5O7mE KafoG6XKXoLXw6nUMWm9BRGr79POqhA8YdPSL8d2g10CY39AyCxPvuIRaeADJ5pOSV4oSg 3kWLe9Y+NHm4JvDwVljsKXf4dWaC0ZM= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 8E8A0AC54; Fri, 2 Oct 2020 09:39:48 +0000 (UTC) Subject: Re: [PATCH v2 03/11] x86/vlapic: introduce an EOI callback mechanism To: Roger Pau Monne Cc: xen-devel@lists.xenproject.org, Andrew Cooper , Wei Liu References: <20200930104108.35969-1-roger.pau@citrix.com> <20200930104108.35969-4-roger.pau@citrix.com> From: Jan Beulich Message-ID: Date: Fri, 2 Oct 2020 11:39:50 +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: <20200930104108.35969-4-roger.pau@citrix.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 30.09.2020 12:41, Roger Pau Monne wrote: > Add a new vlapic_set_irq_callback helper in order to inject a vector > and set a callback to be executed when the guest performs the end of > interrupt acknowledgment. On v1 I did ask "One thing I don't understand at all for now is how these callbacks are going to be re-instated after migration for not-yet-EOIed interrupts." Afaics I didn't get an answer on this. > --- > RFC: should callbacks also be executed in vlapic_do_init (which is > called by vlapic_reset). We would need to make sure ISR and IRR > are cleared using some kind of test and clear atomic functionality to > make this race free. I guess this can't be decided at this point of the series, as it may depend on what exactly the callbacks mean to do. It may even be that whether a callback wants to do something depends on whether it gets called "normally" or from vlapic_do_init(). > --- a/xen/arch/x86/hvm/vlapic.c > +++ b/xen/arch/x86/hvm/vlapic.c > @@ -144,7 +144,32 @@ bool vlapic_test_irq(const struct vlapic *vlapic, uint8_t vec) > return vlapic_test_vector(vec, &vlapic->regs->data[APIC_IRR]); > } > > -void vlapic_set_irq(struct vlapic *vlapic, uint8_t vec, uint8_t trig) > +void vlapic_set_callback(struct vlapic *vlapic, unsigned int vec, > + vlapic_eoi_callback_t *callback, void *data) > +{ > + unsigned long flags; > + unsigned int index = vec - 16; > + > + if ( !callback || vec < 16 || vec >= X86_NR_VECTORS ) > + { > + ASSERT_UNREACHABLE(); > + return; > + } > + > + spin_lock_irqsave(&vlapic->callback_lock, flags); > + if ( vlapic->callbacks[index].callback && > + vlapic->callbacks[index].callback != callback ) > + printk(XENLOG_G_WARNING > + "%pv overriding vector %#x callback %ps (%p) with %ps (%p)\n", > + vlapic_vcpu(vlapic), vec, vlapic->callbacks[index].callback, > + vlapic->callbacks[index].callback, callback, callback); > + vlapic->callbacks[index].callback = callback; > + vlapic->callbacks[index].data = data; Should "data" perhaps also be compared in the override check above? > @@ -1629,9 +1672,23 @@ int vlapic_init(struct vcpu *v) > } > clear_page(vlapic->regs); > > + if ( !vlapic->callbacks ) > + { > + vlapic->callbacks = xmalloc_array(typeof(*vlapic->callbacks), > + X86_NR_VECTORS - 16); > + if ( !vlapic->callbacks ) > + { > + dprintk(XENLOG_ERR, "%pv: alloc vlapic callbacks error\n", v); > + return -ENOMEM; > + } > + } > + memset(vlapic->callbacks, 0, sizeof(*vlapic->callbacks) * > + (X86_NR_VECTORS - 16)); While it resembles code earlier in this function, it widens an existing memory leak (I'll make a patch for that one) and also makes it appear as if this function could be called more than once for a vCPU (maybe I'll also make a patch for this). Jan