Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp920969img; Mon, 18 Mar 2019 18:11:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqxjNfb15QzWKR9xhMl+zjTwnwQhItcCugnnwjp+4Msytn80cmXUOaY5v/GMtHAWYYQE3tdo X-Received: by 2002:aa7:8841:: with SMTP id k1mr21923561pfo.115.1552957877095; Mon, 18 Mar 2019 18:11:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552957877; cv=none; d=google.com; s=arc-20160816; b=Rk0o0xK+YDJZBWBykXDQltongARBMyy9Uip50yHWDDUpru6VFiWo0ovC0FLTdhr5zs WWBq7o1U4oiYXx++IDBfLwu3fegvjruCsBsw+qa8p8ZbNw7RJNQieQASvl0RY1mGKYpF gBg6pw7n8J35DG6t6WqkwgvGX9vH1KK9JOX7VT37DOh6A6hbzCzvbwp1oyDPbmARXH+D eM59Q5biXnS7Dc9vk6n8DU22X84gdc9s1a65E3EI5f/hi24GeDRSZYa9Ocdv9GoglqLB K7BY00rHdV0qKOmZP0u++RuDdYrDsu+jXf+GL+30E0wNW/SknQtWKHVlPMvTORaZCBsY kyoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=IQyLrUYRj72ggQQbzBkIyALMhskt0g42VXZtgmEf5B8=; b=vnKGJvT0EQGdPqsxxWO7xmWsXYJFF+duaE9J16XrQkE5fv1U8SO2E/REZcKe9FAUsY 7b0W2gNq0yTtUyNhhKW3emi498T8U8bHMy+3cVNVybAay/lyKJ3ei3X7VxBSdx2yVm64 //NANdRTlb7A+eEkjDhyyj738V/EXoF5DA6BoFQaZysQeVBV6ADve/SGgzOl8agl5xIC 6Nr26fLJ4QbckzNdj9ecsGXbFGG8CPKqyYMiBRQo4KQHwP01bQtRcCRS8EdU5aCWX0Vy aJoIGW+rXSAuj2jRssjM9Pmxs/NvB4GLODvKXnfIjU/x6w1ckQ/wwPSz4Y8xrzuUjvI0 aBNw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g75si10996325pfg.49.2019.03.18.18.11.02; Mon, 18 Mar 2019 18:11:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727205AbfCSBKY (ORCPT + 99 others); Mon, 18 Mar 2019 21:10:24 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:59520 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726487AbfCSBKX (ORCPT ); Mon, 18 Mar 2019 21:10:23 -0400 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id F16309200FB58420DCD5; Tue, 19 Mar 2019 09:10:20 +0800 (CST) Received: from [127.0.0.1] (10.184.12.158) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.408.0; Tue, 19 Mar 2019 09:10:10 +0800 Subject: Re: [RFC PATCH] KVM: arm/arm64: Enable direct irqfd MSI injection To: Marc Zyngier , , "Raslan, KarimAllah" CC: , , , , , , , , , , , , , References: <1552833373-19828-1-git-send-email-yuzenghui@huawei.com> <86o969z42z.wl-marc.zyngier@arm.com> From: Zenghui Yu Message-ID: <428b2aac-5a0f-e9da-8d74-8045f99a8c74@huawei.com> Date: Tue, 19 Mar 2019 09:09:43 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:64.0) Gecko/20100101 Thunderbird/64.0 MIME-Version: 1.0 In-Reply-To: <86o969z42z.wl-marc.zyngier@arm.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.184.12.158] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi all, On 2019/3/18 3:35, Marc Zyngier wrote: > On Sun, 17 Mar 2019 14:36:13 +0000, > Zenghui Yu wrote: >> >> Currently, IRQFD on arm still uses the deferred workqueue mechanism >> to inject interrupts into guest, which will likely lead to a busy >> context-switching from/to the kworker thread. This overhead is for >> no purpose (only in my view ...) and will result in an interrupt >> performance degradation. >> >> Implement kvm_arch_set_irq_inatomic() for arm/arm64 to support direct >> irqfd MSI injection, by which we can get rid of the annoying latency. >> As a result, irqfd MSI intensive scenarios (e.g., DPDK with high packet >> processing workloads) will benefit from it. >> >> Signed-off-by: Zenghui Yu >> --- >> >> It seems that only MSI will follow the IRQFD path, did I miss something? >> >> This patch is still under test and sent out for early feedback. If I have >> any mis-understanding, please fix me up and let me know. Thanks! > > As mentioned by other folks in the thread, this is clearly wrong. The > first thing kvm_inject_msi does is to lock the corresponding ITS using > a mutex. So the "no purpose" bit was a bit too quick. > > When doing this kind of work, I suggest you enable lockdep and all the > related checkers. Also, for any optimisation, please post actual > numbers for the relevant benchmarks. Saying "application X will > benefit from it" is meaningless without any actual data. > >> >> --- >> virt/kvm/arm/vgic/trace.h | 22 ++++++++++++++++++++++ >> virt/kvm/arm/vgic/vgic-irqfd.c | 21 +++++++++++++++++++++ >> 2 files changed, 43 insertions(+) >> >> diff --git a/virt/kvm/arm/vgic/trace.h b/virt/kvm/arm/vgic/trace.h >> index 55fed77..bc1f4db 100644 >> --- a/virt/kvm/arm/vgic/trace.h >> +++ b/virt/kvm/arm/vgic/trace.h >> @@ -27,6 +27,28 @@ >> __entry->vcpu_id, __entry->irq, __entry->level) >> ); >> >> +TRACE_EVENT(kvm_arch_set_irq_inatomic, >> + TP_PROTO(u32 gsi, u32 type, int level, int irq_source_id), >> + TP_ARGS(gsi, type, level, irq_source_id), >> + >> + TP_STRUCT__entry( >> + __field( u32, gsi ) >> + __field( u32, type ) >> + __field( int, level ) >> + __field( int, irq_source_id ) >> + ), >> + >> + TP_fast_assign( >> + __entry->gsi = gsi; >> + __entry->type = type; >> + __entry->level = level; >> + __entry->irq_source_id = irq_source_id; >> + ), >> + >> + TP_printk("gsi %u type %u level %d source %d", __entry->gsi, >> + __entry->type, __entry->level, __entry->irq_source_id) >> +); >> + >> #endif /* _TRACE_VGIC_H */ >> >> #undef TRACE_INCLUDE_PATH >> diff --git a/virt/kvm/arm/vgic/vgic-irqfd.c b/virt/kvm/arm/vgic/vgic-irqfd.c >> index 99e026d..4cfc3f4 100644 >> --- a/virt/kvm/arm/vgic/vgic-irqfd.c >> +++ b/virt/kvm/arm/vgic/vgic-irqfd.c >> @@ -19,6 +19,7 @@ >> #include >> #include >> #include "vgic.h" >> +#include "trace.h" >> >> /** >> * vgic_irqfd_set_irq: inject the IRQ corresponding to the >> @@ -105,6 +106,26 @@ int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, >> return vgic_its_inject_msi(kvm, &msi); >> } >> >> +/** >> + * kvm_arch_set_irq_inatomic: fast-path for irqfd injection >> + * >> + * Currently only direct MSI injecton is supported. >> + */ >> +int kvm_arch_set_irq_inatomic(struct kvm_kernel_irq_routing_entry *e, >> + struct kvm *kvm, int irq_source_id, int level, >> + bool line_status) >> +{ >> + int ret; >> + >> + trace_kvm_arch_set_irq_inatomic(e->gsi, e->type, level, irq_source_id); >> + >> + if (unlikely(e->type != KVM_IRQ_ROUTING_MSI)) >> + return -EWOULDBLOCK; >> + >> + ret = kvm_set_msi(e, kvm, irq_source_id, level, line_status); >> + return ret; >> +} >> + > > Although we've established that the approach is wrong, maybe we can > look at improving this aspect. > > A first approach would be to keep a small cache of the last few > successful translations for this ITS, cache that could be looked-up by > holding a spinlock instead. A hit in this cache could directly be > injected. Any command that invalidates or changes anything (DISCARD, > INV, INVALL, MAPC with V=0, MAPD with V=0, MOVALL, MOVI) should nuke > the cache altogether. > > Of course, all of that needs to be quantified. Thanks for all of your explanations, especially for Marc's suggestions! It took me long time to figure out my mistakes, since I am not very familiar with the locking stuff. Now I have to apologize for my noise. As for the its-translation-cache code (a really good news to us), we have a rough look at it and start testing now! thanks, zenghui > > Thanks, > > M. >