Received: by 10.223.176.46 with SMTP id f43csp261157wra; Tue, 23 Jan 2018 20:31:45 -0800 (PST) X-Google-Smtp-Source: AH8x224lOE193PkQvoN+6YQa1XSKVdoeYuHE+eY/j5oZPXdihJg9uCwYu3u7kdcM/RJGsL9vMuQl X-Received: by 10.99.183.15 with SMTP id t15mr10083139pgf.111.1516768305494; Tue, 23 Jan 2018 20:31:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516768305; cv=none; d=google.com; s=arc-20160816; b=o1Z3x88yMaHGK3o2SXM76rjSTDMSQWo0gYAfMD+JSA4YjDodZySRlh11zzr4zZJr8I 1+w7jIkuEpSwZucmztN2JzpufVEy2ZneOMoROML8Vcz39CITiI2b/WU9bd/o4lr74bLO UGsBEPVbwE54aG5uGwbuW8PNIcRCKgmAWgc8FaqA7XUSaaQWQGxYoSIJqx74stmX/W75 b+d6+4iufxJQNDqhGd8KyWFO+PJNtedjqXwJtX06yU0d8+j1pPaKL57PpEUoZqibzy9+ lb8fJvKAAcPhgvVzI/0OniS6EI9sZcgE5bZi/F9jaw/lYSLZI6JU71pw+u3ml27muB+N 05gg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :arc-authentication-results; bh=UO44IXf8PET4OQ6Nl5eJRhWnTtAakwnfeeFkGvH5uOs=; b=P1/MWmUVBxnt97bIJIxTLcsLwJ1sjqU4cQjB4JVX7BHJpPFXD2DppyFFon6ggdfpak RF/13yzayhF850kLnrnck+KW2yFeSTWwVz39k6gPpjzLxB3BBJQv6srux1sYpFwXiCS5 8GK445C1GP9p9pepYGAWMf7Ot9C59gp9+/yM+n4DmCvDPKKpH5eHqx1zjfV5Luw8Ijug F/VmQ0H0zPF4L27WVPb7D3MuDDnGeQRva4rlm79bUgEgow87kKnEokld/RIKP1LItKC9 WA8P+OySBVG/qJWPY8K1lAbBDCNU5bP79uQV11ju0dWR5LuuhgCdEzBU+fEYQYOG8LsC iL4Q== 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 a33-v6si3876822pla.36.2018.01.23.20.31.31; Tue, 23 Jan 2018 20:31:45 -0800 (PST) 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 S933424AbeAXE35 (ORCPT + 99 others); Tue, 23 Jan 2018 23:29:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38542 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932630AbeAXE3y (ORCPT ); Tue, 23 Jan 2018 23:29:54 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EECDFC047B6D; Wed, 24 Jan 2018 04:29:53 +0000 (UTC) Received: from redhat.com (ovpn-120-26.rdu2.redhat.com [10.10.120.26]) by smtp.corp.redhat.com (Postfix) with SMTP id 8311260BE1; Wed, 24 Jan 2018 04:29:45 +0000 (UTC) Date: Wed, 24 Jan 2018 06:29:45 +0200 From: "Michael S. Tsirkin" To: Wei Wang Cc: virtio-dev@lists.oasis-open.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, linux-mm@kvack.org, mhocko@kernel.org, akpm@linux-foundation.org, pbonzini@redhat.com, liliang.opensource@gmail.com, yang.zhang.wz@gmail.com, quan.xu0@gmail.com, nilal@redhat.com, riel@redhat.com Subject: Re: [virtio-dev] Re: [PATCH v22 2/3] virtio-balloon: VIRTIO_BALLOON_F_FREE_PAGE_VQ Message-ID: <20180124062723-mutt-send-email-mst@kernel.org> References: <1516165812-3995-1-git-send-email-wei.w.wang@intel.com> <1516165812-3995-3-git-send-email-wei.w.wang@intel.com> <20180117180337-mutt-send-email-mst@kernel.org> <5A616995.4050702@intel.com> <20180119143517-mutt-send-email-mst@kernel.org> <5A65CA39.2070906@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5A65CA39.2070906@intel.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 24 Jan 2018 04:29:54 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 22, 2018 at 07:25:45PM +0800, Wei Wang wrote: > On 01/19/2018 08:39 PM, Michael S. Tsirkin wrote: > > On Fri, Jan 19, 2018 at 11:44:21AM +0800, Wei Wang wrote: > > > On 01/18/2018 12:44 AM, Michael S. Tsirkin wrote: > > > > On Wed, Jan 17, 2018 at 01:10:11PM +0800, Wei Wang wrote: > > > > > > > > > + vb->start_cmd_id = cmd_id; > > > > > + queue_work(vb->balloon_wq, &vb->report_free_page_work); > > > > It seems that if a command was already queued (with a different id), > > > > this will result in new command id being sent to host twice, which will > > > > likely confuse the host. > > > I think that case won't happen, because > > > - the host sends a cmd id to the guest via the config, while the guest acks > > > back the received cmd id via the virtqueue; > > > - the guest ack back a cmd id only when a new cmd id is received from the > > > host, that is the above check: > > > > > > if (cmd_id != vb->start_cmd_id) { --> the driver only queues the > > > reporting work only when a new cmd id is received > > > /* > > > * Host requests to start the reporting by sending a > > > * new cmd id. > > > */ > > > WRITE_ONCE(vb->report_free_page, true); > > > vb->start_cmd_id = cmd_id; > > > queue_work(vb->balloon_wq, > > > &vb->report_free_page_work); > > > } > > > > > > So the same cmd id wouldn't queue the reporting work twice. > > > > > Like this: > > > > vb->start_cmd_id = cmd_id; > > queue_work(vb->balloon_wq, &vb->report_free_page_work); > > > > command id changes > > > > vb->start_cmd_id = cmd_id; > > > > work executes > > > > queue_work(vb->balloon_wq, &vb->report_free_page_work); > > > > work executes again > > > > If we think about the whole working flow, I think this case couldn't happen: > > 1) device send cmd_id=1 to driver; > 2) driver receives cmd_id=1 in the config and acks cmd_id=1 to the device > via the vq; > 3) device revives cmd_id=1; > 4) device wants to stop the reporting by sending cmd_id=STOP; > 5) driver receives cmd_id=STOP from the config, and acks cmd_id=STOP to the > device via the vq; > 6) device sends cmd_id=2 to driver; > ... > > cmd_id=2 won't come after cmd_id=1, there will be a STOP cmd in between them > (STOP won't queue the work). > > How about defining the correct device behavior in the spec: > The device Should NOT send a second cmd id to the driver until a STOP cmd > ack for the previous cmd id has been received from the guest. > > > Best, > Wei I think we should just fix races in the driver rather than introduce random restrictions in the device. If device wants to start a new sequence, it should be able to do just that without a complicated back and forth with several roundtrips through the driver. -- MST