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=-17.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham 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 6AB2CC433ED for ; Mon, 3 May 2021 15:50:56 +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 F1E10611AB for ; Mon, 3 May 2021 15:50:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F1E10611AB Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine 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.121737.229609 (Exim 4.92) (envelope-from ) id 1ldaqJ-0003Ud-Rf; Mon, 03 May 2021 15:50:43 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 121737.229609; Mon, 03 May 2021 15:50:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ldaqJ-0003UW-Oi; Mon, 03 May 2021 15:50:43 +0000 Received: by outflank-mailman (input) for mailman id 121737; Mon, 03 May 2021 15:50:42 +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 1ldaqI-0003UR-Cn for xen-devel@lists.xenproject.org; Mon, 03 May 2021 15:50:42 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 03490bff-fbd4-4548-9724-83d10e329e84; Mon, 03 May 2021 15:50:41 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 38305B20F; Mon, 3 May 2021 15:50:40 +0000 (UTC) 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" X-Inumbo-ID: 03490bff-fbd4-4548-9724-83d10e329e84 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=1620057040; h=from:from:reply-to: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=7vgsUSIt1qrfYBtRqm5wgG+fvrjDxM14z0fDosLzFv8=; b=bXipMq5TMsk3/0DHUMOOHXAakdAPEhlBR1L7eSabUUhsPu5/FLGeowjLnICskCq7Xt9YEK e4q7GOmpYhCB8Woanbn6jO7CK4fqzWph/em7McWC3y4ACLX0HlbJLYbhvVf8y3vpKC1dFn sj9uO7avpHksmi8oNkGbM1R9O4KQtDE= Subject: Re: [PATCH v4 05/12] x86/hvm: allowing registering EOI callbacks for GSIs To: Roger Pau Monne Cc: Andrew Cooper , Wei Liu , xen-devel@lists.xenproject.org References: <20210420140723.65321-1-roger.pau@citrix.com> <20210420140723.65321-6-roger.pau@citrix.com> From: Jan Beulich Message-ID: <19b0b30d-2fd6-4cc3-fd7a-4f4a3ce735f7@suse.com> Date: Mon, 3 May 2021 17:50:39 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: <20210420140723.65321-6-roger.pau@citrix.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit On 20.04.2021 16:07, Roger Pau Monne wrote: > Such callbacks will be executed once a EOI is performed by the guest, > regardless of whether the interrupts are injected from the vIO-APIC or > the vPIC, as ISA IRQs are translated to GSIs and then the > corresponding callback is executed at EOI. > > The vIO-APIC infrastructure for handling EOIs is build on top of the > existing vlapic EOI callback functionality, while the vPIC one is > handled when writing to the vPIC EOI register. > > Note that such callbacks need to be registered and de-registered, and > that a single GSI can have multiple callbacks associated. That's > because GSIs can be level triggered and shared, as that's the case > with legacy PCI interrupts shared between several devices. > > Strictly speaking this is a non-functional change, since there are no > users of this new interface introduced by this change. > > Signed-off-by: Roger Pau Monné In principle, as everything looks functionally correct to me, Reviewed-by: Jan Beulich Nevertheless, besides a few remarks further down, I have to admit I'm concerned of the direct-to-indirect calls conversion (not just here, but also covering earlier patches), which (considering we're talking of EOI) I expect may occur quite frequently for at least some guests. There aren't that many different callback functions which get registered, are there? Hence I wonder whether enumerating them and picking the right one via, say, an enum wouldn't be more efficient and still allow elimination of (in the case here) unconditional calls to hvm_dpci_eoi() for every EOI. > --- a/xen/arch/x86/hvm/irq.c > +++ b/xen/arch/x86/hvm/irq.c > @@ -595,6 +595,81 @@ int hvm_local_events_need_delivery(struct vcpu *v) > return !hvm_interrupt_blocked(v, intack); > } > > +int hvm_gsi_register_callback(struct domain *d, unsigned int gsi, > + struct hvm_gsi_eoi_callback *cb) > +{ > + struct hvm_irq *hvm_irq = hvm_domain_irq(d); > + > + if ( gsi >= hvm_irq->nr_gsis ) > + { > + ASSERT_UNREACHABLE(); > + return -EINVAL; > + } > + > + write_lock(&hvm_irq->gsi_callbacks_lock); > + list_add(&cb->list, &hvm_irq->gsi_callbacks[gsi]); > + write_unlock(&hvm_irq->gsi_callbacks_lock); > + > + return 0; > +} > + > +int hvm_gsi_unregister_callback(struct domain *d, unsigned int gsi, > + struct hvm_gsi_eoi_callback *cb) > +{ > + struct hvm_irq *hvm_irq = hvm_domain_irq(d); > + const struct list_head *tmp; > + bool found = false; > + > + if ( gsi >= hvm_irq->nr_gsis ) > + { > + ASSERT_UNREACHABLE(); > + return -EINVAL; > + } > + > + write_lock(&hvm_irq->gsi_callbacks_lock); > + list_for_each ( tmp, &hvm_irq->gsi_callbacks[gsi] ) > + if ( tmp == &cb->list ) > + { > + list_del(&cb->list); Minor remark: Would passing "tmp" here lead to better generated code? > @@ -419,13 +421,25 @@ static void eoi_callback(struct vcpu *v, unsigned int vector, void *data) > if ( is_iommu_enabled(d) ) > { > spin_unlock(&d->arch.hvm.irq_lock); > - hvm_dpci_eoi(d, vioapic->base_gsi + pin); > + hvm_dpci_eoi(d, gsi); > spin_lock(&d->arch.hvm.irq_lock); > } > > + /* > + * Callbacks don't expect to be executed with any lock held, so > + * drop the lock that protects the vIO-APIC fields from changing. > + * > + * Note that the redirection entry itself cannot go away, so upon > + * retaking the lock we only need to avoid making assumptions on > + * redirection entry field values (ie: recheck the IRR field). > + */ > + spin_unlock(&d->arch.hvm.irq_lock); > + hvm_gsi_execute_callbacks(d, gsi); > + spin_lock(&d->arch.hvm.irq_lock); While this may be transient in the series, as said before I'm not happy about this double unlock/relock sequence. I didn't really understand what would be wrong with spin_unlock(&d->arch.hvm.irq_lock); if ( is_iommu_enabled(d) ) hvm_dpci_eoi(d, gsi); hvm_gsi_execute_callbacks(d, gsi); spin_lock(&d->arch.hvm.irq_lock); This in particular wouldn't grow but even shrink the later patch dropping the call to hvm_dpci_eoi(). > --- a/xen/arch/x86/hvm/vpic.c > +++ b/xen/arch/x86/hvm/vpic.c > @@ -235,6 +235,8 @@ static void vpic_ioport_write( > unsigned int pin = __scanbit(pending, 8); > > ASSERT(pin < 8); > + hvm_gsi_execute_callbacks(current->domain, > + hvm_isa_irq_to_gsi((addr >> 7) ? (pin | 8) : pin)); > hvm_dpci_eoi(current->domain, > hvm_isa_irq_to_gsi((addr >> 7) ? (pin | 8) : pin)); > __clear_bit(pin, &pending); > @@ -285,6 +287,8 @@ static void vpic_ioport_write( > /* Release lock and EOI the physical interrupt (if any). */ > vpic_update_int_output(vpic); > vpic_unlock(vpic); > + hvm_gsi_execute_callbacks(current->domain, > + hvm_isa_irq_to_gsi((addr >> 7) ? (pin | 8) : pin)); > hvm_dpci_eoi(current->domain, > hvm_isa_irq_to_gsi((addr >> 7) ? (pin | 8) : pin)); > return; /* bail immediately */ Another presumably minor remark: In the IO-APIC case you insert after the call to hvm_dpci_eoi(). I wonder if consistency wouldn't help avoid questions of archeologists in a couple of years time. Jan