Received: by 10.223.176.46 with SMTP id f43csp870112wra; Sat, 20 Jan 2018 06:27:07 -0800 (PST) X-Google-Smtp-Source: AH8x226HSAoP7VuSrIfKw+BlZLF6+hxEHOOBSwCoCZx1XjhwnF5Vm6unJQyKVRaD0gwl1ya5bnBK X-Received: by 10.98.174.8 with SMTP id q8mr2482701pff.109.1516458427290; Sat, 20 Jan 2018 06:27:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516458427; cv=none; d=google.com; s=arc-20160816; b=o2JK3h6e+4ESE3Wx4J8FuryW5KHBY14Qv4+PrtvLE3OItQnEhpXi6oMB/ASY5yJmFP YO85FIBRf9fT7R5MElyu4XwWnRD6h6ocQBoZuMQCvjwNqdVlOV0dtclNkdFR4LzevMX/ Nh2B8KKU4wa84QaIdMO+UBdXtPWytOo9BldAIyAIsZJCI+bI0W0pe7xb9wy5T8Ds9L9q PRPiaR1Jc0pdA+wywB8KC4bPRW5pYeQi2bIvcNh0jt5P1F5k/DmnHzTBSPrZH1F9Yzqt wLTc06mOxLsn2d/GWIFEHJt+nU8q7BxgFlD/Qh+8zinRcawCvgiXCpPKVkb1sL1MSp1s AMrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:date:message-id:in-reply-to :references:from:subject:cc:to:arc-authentication-results; bh=msUNJihSLGlb01OPaHliJ55HA0jP2upVLLlwTosaTPw=; b=kww/GbZ7Y1RrXqAoICGH3aw5jb67JlfXNy1fUFTrPyM0culxUeGPpQ557lMSJ1q+wW af0aM42qwYZV47SXeB07+skWpqHqvIfzJp3K7Bxx7HQdRiVmKNFLIHAJL8zzyja25ow8 AV+ZJmO6CiI+iKfBPYVYAbf+56rRt87fcoq3qWRBSeveGgYBCl1nbzyYRk4CAwnn9VNn dythpJYNn8ypIbe958wF0YNbWkjKiF/RRru46mciAg0ulCygB2JArPhAc7F8cF9xFlDB 9kT3k3XA3a5gHTvZVcrgLO24KlqnGJ8RgAvYsKYnRBU+jB7cF0mrefTUUF/dEtoK0d67 26VA== 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 w17si10505119pgm.363.2018.01.20.06.26.52; Sat, 20 Jan 2018 06:27:07 -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 S1755507AbeATOYC (ORCPT + 99 others); Sat, 20 Jan 2018 09:24:02 -0500 Received: from www262.sakura.ne.jp ([202.181.97.72]:37408 "EHLO www262.sakura.ne.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753487AbeATOX6 (ORCPT ); Sat, 20 Jan 2018 09:23:58 -0500 Received: from fsav103.sakura.ne.jp (fsav103.sakura.ne.jp [27.133.134.230]) by www262.sakura.ne.jp (8.14.5/8.14.5) with ESMTP id w0KENuTu059565; Sat, 20 Jan 2018 23:23:56 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav103.sakura.ne.jp (F-Secure/fsigk_smtp/530/fsav103.sakura.ne.jp); Sat, 20 Jan 2018 23:23:56 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/530/fsav103.sakura.ne.jp) Received: from AQUA (softbank126074156036.bbtec.net [126.74.156.36]) (authenticated bits=0) by www262.sakura.ne.jp (8.14.5/8.14.5) with ESMTP id w0KENuC7059561; Sat, 20 Jan 2018 23:23:56 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) To: mst@redhat.com Cc: wei.w.wang@intel.com, 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: [PATCH v22 2/3] virtio-balloon: VIRTIO_BALLOON_F_FREE_PAGE_VQ From: Tetsuo Handa References: <20180117180337-mutt-send-email-mst@kernel.org> <2bb0e3d9-1679-9ad3-b402-f0781f6cf094@I-love.SAKURA.ne.jp> <20180118210239-mutt-send-email-mst@kernel.org> <201801190611.HGI18722.FVtOMQLSHFFOOJ@I-love.SAKURA.ne.jp> <20180119003101-mutt-send-email-mst@kernel.org> In-Reply-To: <20180119003101-mutt-send-email-mst@kernel.org> Message-Id: <201801202323.JHH12456.VtOFHSLOMQFOFJ@I-love.SAKURA.ne.jp> X-Mailer: Winbiff [Version 2.51 PL2] X-Accept-Language: ja,en,zh Date: Sat, 20 Jan 2018 23:23:56 +0900 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Michael S. Tsirkin wrote: > > > > >> + * the page if the vq is full. We are adding one entry each time, > > > > >> + * which essentially results in no memory allocation, so the > > > > >> + * GFP_KERNEL flag below can be ignored. > > > > >> + */ > > > > >> + if (vq->num_free) { > > > > >> + err = virtqueue_add_inbuf(vq, &sg, 1, vq, GFP_KERNEL); > > > > > > > > > > Should we kick here? At least when ring is close to > > > > > being full. Kick at half way full? > > > > > Otherwise it's unlikely ring will > > > > > ever be cleaned until we finish the scan. > > > > > > > > Since this add_one_sg() is called between spin_lock_irqsave(&zone->lock, flags) > > > > and spin_unlock_irqrestore(&zone->lock, flags), it is not permitted to sleep. > > > > > > kick takes a while sometimes but it doesn't sleep. > > > > I don't know about virtio. But the purpose of kicking here is to wait for pending data > > to be flushed in order to increase vq->num_free, isn't it? > > It isn't. It's to wake up device out of sleep to make it start > processing the pending data. If device isn't asleep, it's a nop. We need to wait until vq->num_free > 0 if vq->num_free == 0 if we want to allow virtqueue_add_inbuf() to succeed. When will vq->num_free++ be called? You said virtqueue_kick() is a no-op if the device is not asleep. Then, there will be no guarantee that we can make vq->num_free > 0 by calling virtqueue_kick(). Are you saying that virtqueue_kick(vq); while (!vq->num_free) virtqueue_get_buf(vq, &unused); err = virtqueue_add_inbuf(vq, &sg, 1, vq, GFP_KERNEL); BUG_ON(err); sequence from IRQ disabled atomic context is safe? If no, what is the point with calling virtqueue_kick() when ring is close to being (half way) full? We can't guarantee that all data is sent to QEMU after all. Also, why does the cmd id matter? If VIRTIO_BALLOON_F_FREE_PAGE_VQ does not guarantee the atomicity, I don't see the point of communicating the cmd id between the QEMU and the guest kernel. Just an EOF marker should be enough. I do want to see changes for the QEMU side in order to review changes for the guest kernel side.