Received: by 10.223.176.46 with SMTP id f43csp617764wra; Wed, 24 Jan 2018 03:27:44 -0800 (PST) X-Google-Smtp-Source: AH8x224EvYVafJEZbloL0+SNZeLBZ304Zsix5KBg2tkzDPvThw5/dneMGpuKVZCRKgdPGEAVE7xb X-Received: by 10.98.234.4 with SMTP id t4mr12825564pfh.74.1516793263976; Wed, 24 Jan 2018 03:27:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516793263; cv=none; d=google.com; s=arc-20160816; b=jK4M5ejgUZ9h1Mxz3woTPtu23Z4qNlkgqwqm+U13UneuAmlmc7cJ1iN0okCXCB4s9c sWsEMxVhY1VNSes/dzjDlCO8Cjdqo6XKkxlapYnuSHQZbxZU9c6fXUsKHoTdSFcv6TgK AmvJFs0kndbb/kq9cFLmUht7E5Y+40p01fiBodQNOxmSMR5NwuXBBBzfkdd8vr6467JP XxudvS4kKfQ6ZHJAI7VocjMLX9K8K4ARb5eliA7Mgh7TM9l9HG+i5ErSomLmMCpYX0TP iNfEaihjTzwaAq9CvPbGlQL1vVHLqyVQB2QIIdSzwf0erUJoi4eewuK3sfCoFiwSfo3L uzcw== 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=0A5AuG2B6cay6+m/z6lEw74WGx0URgY/9lJg8KmauS0=; b=XknPaskEjtNUGyDBVZcqBJtgxcMb8NnP1x5xb+VFe9HT1y6HQlvKFqmNeQUjd9o6vU k1lxKMe77xE05AYZjoBPYbUk2S/OYaFmyxdRE829K6KXqL53XgjdKjKCcMMWjOH1AJXA LGKiVkt6/13hsoZMnGi7gtObJh2iwtujGlMQtqRZEqTYqlAUmQHAQxpfhBghmpKd4nZx 0bM6p2ngzE8f5+B3cvcdcSzBxSzZQKBxe/LwuP3VMRPGYJlHZpP0aVjhAboaMgAYHNJg /2vdpoS5Ou+hRgbOwMm4d+ArPfraR/0AOq5WeLeWUzGdhTsfa8rHbxhhJQEyNmHUas11 Kj/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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r17si28736pge.478.2018.01.24.03.27.30; Wed, 24 Jan 2018 03:27:43 -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 S933570AbeAXL0S (ORCPT + 99 others); Wed, 24 Jan 2018 06:26:18 -0500 Received: from mga03.intel.com ([134.134.136.65]:52002 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933085AbeAXL0Q (ORCPT ); Wed, 24 Jan 2018 06:26:16 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Jan 2018 03:26:15 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,406,1511856000"; d="scan'208";a="198392153" Received: from unknown (HELO [10.239.13.97]) ([10.239.13.97]) by fmsmga006.fm.intel.com with ESMTP; 24 Jan 2018 03:26:13 -0800 Message-ID: <5A686DEE.4050008@intel.com> Date: Wed, 24 Jan 2018 19:28:46 +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> <5A65CA39.2070906@intel.com> <20180124062723-mutt-send-email-mst@kernel.org> In-Reply-To: <20180124062723-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/24/2018 12:29 PM, Michael S. Tsirkin wrote: > 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. > OK, I've fixed it in the new version, v24. Please have a check there. Thanks. (Other changes based on the comments on v23 have also been included) Best, Wei