Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2956033imm; Thu, 24 May 2018 19:51:38 -0700 (PDT) X-Google-Smtp-Source: AB8JxZp7jDfeM4+GrrKeTtGFoAim9zhPvV+PWpoui5+CAm+HN8Y2jpreoOxpZ08JjXfgn3db2XmH X-Received: by 2002:a62:7682:: with SMTP id r124-v6mr634580pfc.80.1527216698270; Thu, 24 May 2018 19:51:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527216698; cv=none; d=google.com; s=arc-20160816; b=F5KaXr6fwpeqYo4mPYHj9uLM6x+WBdd7NxMotPwJ+UTXUIcPFIlvjPb7uoTNHwcHsN B4NQYPtkPaQyiBWzpPR2gwQEk+cBFkyaPHopvSgLoaoqma9uTMsTeaK0fNT1wpmd5CTb 9PPkAVgaAe/+7ZSyabd19zy5B5tM65PQRby995bODY6znYGUkvA24yM/T88qRVLXxMpB /kPLi9mtfnuS870/dgYef5BrnHg5HYt+cC4kKi34f2RxSFhQsYWCLoAXble+gRfJcpnK f0+uwXgJqtt3/TODu2Zpl2MdZ/Tb+IPCdWFEA48wIpuC+T6MU0ef3ukwMt2S26ab6EKK AH+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=v/1eiJD/Y88BUnBTrQZv0oZR1ECV9HQ8nENoPNp/f8w=; b=Uwj0/FAzxMOA3Y71Z/uNN75aLKpjPxJRqRUmUE8653ZWs33Bs9Uqe4uH9WKIj/2Dg/ snCMiHBRGd4XrzO2jQnTnqEynxjF4dzzKCbA3d9TYxPWyd8ZIWbl0ok/M+eEEefKkIEO 7lONNeifLwO7BV+33R3WpxHvxldrBddMU0JbNFEl5V1tpI5EO4vJ99KKyAttkxmzEvJX 7pujJ8tauFjRx4nnFdtCHKb1K+c/EhFgElOa5ag3iOpm5pSdyWJWcW4lI8Spks+2BDMe 0zrT3lL7RMo6Aa7VjkGr0kpnlGw3GJ86oqFh9bSJvg3lTpjP8VFGJhyC0IK8yzsNzPyb Kr/Q== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g26-v6si9014075pge.489.2018.05.24.19.51.24; Thu, 24 May 2018 19:51:38 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935659AbeEYC2w (ORCPT + 99 others); Thu, 24 May 2018 22:28:52 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:35970 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S935184AbeEYC2s (ORCPT ); Thu, 24 May 2018 22:28:48 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4A0B84023131; Fri, 25 May 2018 02:28:47 +0000 (UTC) Received: from [10.72.12.58] (ovpn-12-58.pek2.redhat.com [10.72.12.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C83662026DEF; Fri, 25 May 2018 02:28:41 +0000 (UTC) Subject: Re: [RFC V4 PATCH 8/8] vhost: event suppression for packed ring To: mst@redhat.com Cc: kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, jfreimann@redhat.com, wexu@redhat.com, tiwei.bie@intel.com References: <1526473941-16199-1-git-send-email-jasowang@redhat.com> <1526473941-16199-9-git-send-email-jasowang@redhat.com> From: Jason Wang Message-ID: <2757710b-3c36-9730-f205-dd198475bc70@redhat.com> Date: Fri, 25 May 2018 10:28:38 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <1526473941-16199-9-git-send-email-jasowang@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 25 May 2018 02:28:47 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 25 May 2018 02:28:47 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jasowang@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018年05月16日 20:32, Jason Wang wrote: > +static bool vhost_notify_packed(struct vhost_dev *dev, > + struct vhost_virtqueue *vq) > +{ > + __virtio16 event_off_wrap, event_flags; > + __u16 old, new, off_wrap; > + bool v; > + > + /* Flush out used descriptors updates. This is paired > + * with the barrier that the Guest executes when enabling > + * interrupts. > + */ > + smp_mb(); > + > + if (vhost_get_avail(vq, event_flags, > + &vq->driver_event->flags) < 0) { > + vq_err(vq, "Failed to get driver desc_event_flags"); > + return true; > + } > + > + if (event_flags == cpu_to_vhost16(vq, RING_EVENT_FLAGS_DISABLE)) > + return false; > + else if (event_flags == cpu_to_vhost16(vq, RING_EVENT_FLAGS_ENABLE)) > + return true; > + > + /* Read desc event flags before event_off and event_wrap */ > + smp_rmb(); > + > + if (vhost_get_avail(vq, event_off_wrap, > + &vq->driver_event->off_warp) < 0) { > + vq_err(vq, "Failed to get driver desc_event_off/wrap"); > + return true; > + } > + > + off_wrap = vhost16_to_cpu(vq, event_off_wrap); > + > + old = vq->signalled_used; > + v = vq->signalled_used_valid; > + new = vq->signalled_used = vq->last_used_idx; > + vq->signalled_used_valid = true; We should move those idx tracking before checking event_flags. Otherwise we may lose interrupts because of a wrong signalled_used value. Thanks > + > + if (unlikely(!v)) > + return true; > + > + return vhost_vring_packed_need_event(vq, off_wrap, new, old); > +}