From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755371AbbIAIWa (ORCPT ); Tue, 1 Sep 2015 04:22:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34032 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755306AbbIAIW1 (ORCPT ); Tue, 1 Sep 2015 04:22:27 -0400 Subject: Re: [PATCH V3 2/3] kvm: don't register wildcard MMIO EVENTFD on two buses To: "Michael S. Tsirkin" References: <1440493548-2971-2-git-send-email-jasowang@redhat.com> <20150825144925-mutt-send-email-mst@redhat.com> <55DD4A5A.3080006@redhat.com> <55E3C607.1060005@redhat.com> <20150831102838-mutt-send-email-mst@redhat.com> <55E40A6F.5010003@redhat.com> <20150831143047-mutt-send-email-mst@redhat.com> <55E51C97.3040409@redhat.com> <20150901072708-mutt-send-email-mst@redhat.com> <55E52DE8.4000308@redhat.com> <20150901065444.GA31420@redhat.com> Cc: gleb@kernel.org, pbonzini@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, cornelia.huck@de.ibm.com From: Jason Wang Message-ID: <55E5603E.9070409@redhat.com> Date: Tue, 1 Sep 2015 16:22:22 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <20150901065444.GA31420@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/01/2015 02:54 PM, Michael S. Tsirkin wrote: > On Tue, Sep 01, 2015 at 12:47:36PM +0800, Jason Wang wrote: >> >> On 09/01/2015 12:31 PM, Michael S. Tsirkin wrote: >>> On Tue, Sep 01, 2015 at 11:33:43AM +0800, Jason Wang wrote: >>>> On 08/31/2015 07:33 PM, Michael S. Tsirkin wrote: >>>>> On Mon, Aug 31, 2015 at 04:03:59PM +0800, Jason Wang wrote: >>>>>>> On 08/31/2015 03:29 PM, Michael S. Tsirkin wrote: >>>>>>>>>>>>>>>>> Thinking more about this, invoking the 0-length write after >>>>>>>>>>>>>>>>>>>>>>>>> the != 0 length one would be better: it would mean we only >>>>>>>>>>>>>>>>>>>>>>>>> handle the userspace MMIO like this. >>>>>>>>>>>>>>>>> Right. >>>>>>>>>>>>>>>>> >>>>>>>>>>>>> Using current unittest. This patch is about 2.9% slower than before, and >>>>>>>>>>>>> invoking 0-length write after is still 1.1% slower (mmio-datamatch-eventfd). >>>>>>>>>>>>> >>>>>>>>>>>>> /patch/result/-+%/ >>>>>>>>>>>>> /base/2957/0/ >>>>>>>>>>>>> /V3/3043/+2.9%/ >>>>>>>>>>>>> /V3+invoking != 0 length first/2990/+1.1%/ >>>>>>>>>>>>> >>>>>>>>>>>>> So looks like the best method is not searching KVM_FAST_MMIO_BUS during >>>>>>>>>>>>> KVM_MMIO_BUS. Instead, let userspace to register both datamatch and >>>>>>>>>>>>> wildcard in this case. Does this sound good to you? >>>>>>>>> No - we can't change userspace. >>>>>>> Actually, the change was as simple as following. So I don't get the >>>>>>> reason why. >>>>> Because it's too late - we committed to a specific userspace ABI >>>>> when this was merged in kernel, we must maintain it. >>>> Ok ( Though I don't think it has real users for this now because it was >>>> actually broken). >>> It actually worked most of the time - you only trigger a use after free >>> on deregister. >>> >> It doesn't work for amd and intel machine without ept. > I thought it does :( > >>>>> Even if I thought yours is a good API (and I don't BTW - it's exposing >>>>> internal implementation details) it's too late to change it. >>>> I believe we should document the special treatment in kernel of zero >>>> length mmio eventfd in api.txt? If yes, is this an exposing? If not, how >>>> can userspace know the advantages of this and use it? For better API, >>>> probably we need another new flag just for fast mmio and obsolete >>>> current one by failing the assigning for zero length mmio eventfd. >>> I sent a patch to update api.txt already as part of >>> kvm: add KVM_CAP_IOEVENTFD_PF capability. >>> I should probably split it out. >>> >>> Sorry, I don't think the api change you propose makes sense - just fix the >>> crash in the existing one. >>> >> Ok, so I believe the fix should go: >> >> - having two ioeventfds when we want to assign zero length mmio eventfd > You mean the in-kernel data structures? Yes. > >> - change the kvm_io_bus_sort_cmp() and can handle zero length correctly > This one's for amd/non ept, right? I'd rather we implemented the > fast mmio optimization for these. Agree, but we'd better fix it and backport it to stable first?