Received: by 10.223.176.46 with SMTP id f43csp2784035wra; Mon, 22 Jan 2018 03:24:03 -0800 (PST) X-Google-Smtp-Source: AH8x2258tBSNo8ngYWFn0C+vtHGGjLofMGh+q+bMy6feAg4HtEZ37k/bSbsW0lbapoGUrDz5lpF5 X-Received: by 10.98.100.139 with SMTP id y133mr8188437pfb.68.1516620242998; Mon, 22 Jan 2018 03:24:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516620242; cv=none; d=google.com; s=arc-20160816; b=A7YJpV4ozQdEqKONW08m9HyzEM7qTFlW5aNo+d+fCrUqbeSH7S07odtuXXAZ8Uxx96 cUnd9fN0JUpiHzUKqTzl6L4IOlbISSR++dL5SyBzdmpA2c1gG/ElzmXselshbGDvCAj4 g4NsAErHh3VEM8iaAZTb1sDHP7yhKHmeFYjOijL35eLHAoMjTrwM3TiMxXk2mVm3N3Nx jGaksJxxO1zGta1otirYm/NzMWt8J/wnpAivk49X8idOdsfbB3P+SRd54VIqAGltxFdc tVkw8S3MmxP9VxRtPiOIFJjWdXrogjt9KLbNEORxXT5b19kLyV8Kz8kfFqLf/cS0yk+I hsHw== 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:in-reply-to :references:subject:cc:to:mime-version:user-agent:from:date :message-id:arc-authentication-results; bh=5h1NPujUllNm9xh/iHppylgXaGopwPggPvvPSq06+qE=; b=Jlbs/+bKei4UwU2TRdDJuO+S3dB1PuyZUXIPr/XABrN9C24CTI4B7nYi9jpf6BTq8Z WMqtboyu58XqiHJ3gUTom6oBi2lBGcP103ycvZkpjVKvUt+xpjwlZax/LXiIuCjK6W9c 0etsEfR83BF2JSoTeVz2vPrbAIOdEa+FWivxc1H7ZVj9tXefy5N92rcofhgzgQ34gUqE Dmw55MocyEPSs50VqMJ7cRZvBZy3P5aV4ydz9p31JVs33bvHPgRC9QL5/Nz4NjbJXJA4 q2GREZIEFhJNgTjKhg40OOgNwAWU5od6ecDNAGZ75waRW6E8vWS9T9+XMXwF3Mqcig2t /ICQ== 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 g67si13705656pgc.555.2018.01.22.03.23.45; Mon, 22 Jan 2018 03:24:02 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751106AbeAVLXT (ORCPT + 99 others); Mon, 22 Jan 2018 06:23:19 -0500 Received: from mga04.intel.com ([192.55.52.120]:22131 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750828AbeAVLXS (ORCPT ); Mon, 22 Jan 2018 06:23:18 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Jan 2018 03:23:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,396,1511856000"; d="scan'208";a="25300760" Received: from unknown (HELO [10.239.13.97]) ([10.239.13.97]) by orsmga001.jf.intel.com with ESMTP; 22 Jan 2018 03:23:14 -0800 Message-ID: <5A65CA39.2070906@intel.com> Date: Mon, 22 Jan 2018 19:25:45 +0800 From: Wei Wang User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: "Michael S. Tsirkin" 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 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> In-Reply-To: <20180119143517-mutt-send-email-mst@kernel.org> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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