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=-6.2 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 85A3FC433DF for ; Fri, 31 Jul 2020 06:39:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 65A0321883 for ; Fri, 31 Jul 2020 06:39:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731375AbgGaGjp (ORCPT ); Fri, 31 Jul 2020 02:39:45 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:8865 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731224AbgGaGjo (ORCPT ); Fri, 31 Jul 2020 02:39:44 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id DD9B19CED4C9D6C8A047; Fri, 31 Jul 2020 14:39:37 +0800 (CST) Received: from [127.0.0.1] (10.174.186.173) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Fri, 31 Jul 2020 14:39:30 +0800 Subject: Re: [Question] the check of ioeventfd collision in kvm_*assign_ioeventfd_idx To: Paolo Bonzini CC: "S. Tsirkin, Michael" , , , , , , Xiexiangyou References: From: Zhenyu Ye Message-ID: <4aa75d90-f2d2-888c-8970-02a41f3733e4@huawei.com> Date: Fri, 31 Jul 2020 14:39:29 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.186.173] X-CFilter-Loop: Reflected Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On 2020/7/31 2:03, Paolo Bonzini wrote: > Yes, I think it's not needed. Probably the deassign check can be turned into an assertion? > > Paolo > I think we can do this in the same function, and turnt he check of p->eventfd into assertion in kvm_deassign_ioeventfd_idx(). Just like: ---8<--- static inline struct _ioeventfd * get_ioeventfd(struct kvm *kvm, enum kvm_bus bus_idx, struct kvm_ioeventfd *args) { static struct _ioeventfd *_p; bool wildcard = !(args->flags & KVM_IOEVENTFD_FLAG_DATAMATCH); list_for_each_entry(_p, &kvm->ioeventfds, list) if (_p->bus_idx == bus_idx && _p->addr == args->addr && (!_p->length || !args->len || (_p->length == args->len && (_p->wildcard || wildcard || _p->datamatch == args->datamatch)))) return _p; return NULL; } kvm_deassign_ioeventfd_idx() { ... p = get_ioeventfd(kvm, bus_idx, args); if (p) { assert(p->eventfd == eventfd); ... } ---8<---- This may be easier to understand (keep the same logic in assign/deassign). I will send a formal patch soon. Thanks, Zhenyu > Il gio 30 lug 2020, 16:36 Zhenyu Ye > ha scritto: > > Hi all, > > There are checks of ioeventfd collision in both kvm_assign_ioeventfd_idx() > and kvm_deassign_ioeventfd_idx(), however, with different logic. > > In kvm_assign_ioeventfd_idx(), this is done by ioeventfd_check_collision(): > ---8<--- >         if (_p->bus_idx == p->bus_idx && >             _p->addr == p->addr && >             (!_p->length || !p->length || >              (_p->length == p->length && >               (_p->wildcard || p->wildcard || >                _p->datamatch == p->datamatch)))) >                 // then we consider the two are the same > ---8<--- > > The logic in kvm_deassign_ioeventfd_idx() is as follows: > ---8<--- >         if (p->bus_idx != bus_idx || >             p->eventfd != eventfd  || >             p->addr != args->addr  || >             p->length != args->len || >             p->wildcard != wildcard) >                 continue; > >         if (!p->wildcard && p->datamatch != args->datamatch) >                 continue; > >         // then we consider the two are the same > ---8<--- > > As we can see, there is extra check of p->eventfd in > > ().  Why we don't check p->eventfd > in kvm_assign_ioeventfd_idx()? Or should we delete this in > kvm_deassign_ioeventfd_idx()? > > > Thanks, > Zhenyu >