From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751846AbdJBNpL (ORCPT ); Mon, 2 Oct 2017 09:45:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60510 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751746AbdJBNpH (ORCPT ); Mon, 2 Oct 2017 09:45:07 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 68AEF4A6F0 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=mst@redhat.com Date: Mon, 2 Oct 2017 16:44:52 +0300 From: "Michael S. Tsirkin" To: "Wang, Wei W" Cc: "virtio-dev@lists.oasis-open.org" , "linux-kernel@vger.kernel.org" , "qemu-devel@nongnu.org" , "virtualization@lists.linux-foundation.org" , "kvm@vger.kernel.org" , "linux-mm@kvack.org" , "mhocko@kernel.org" , "akpm@linux-foundation.org" , "mawilcox@microsoft.com" , "david@redhat.com" , "cornelia.huck@de.ibm.com" , "mgorman@techsingularity.net" , "aarcange@redhat.com" , "amit.shah@redhat.com" , "pbonzini@redhat.com" , "willy@infradead.org" , "liliang.opensource@gmail.com" , "yang.zhang.wz@gmail.com" , "quan.xu@aliyun.com" Subject: Re: [PATCH v16 3/5] virtio-balloon: VIRTIO_BALLOON_F_SG Message-ID: <20171002160757-mutt-send-email-mst@kernel.org> References: <1506744354-20979-1-git-send-email-wei.w.wang@intel.com> <1506744354-20979-4-git-send-email-wei.w.wang@intel.com> <20171002072106-mutt-send-email-mst@kernel.org> <286AC319A985734F985F78AFA26841F73931FDB5@shsmsx102.ccr.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <286AC319A985734F985F78AFA26841F73931FDB5@shsmsx102.ccr.corp.intel.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 02 Oct 2017 13:45:07 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 02, 2017 at 12:39:30PM +0000, Wang, Wei W wrote: > On Monday, October 2, 2017 12:30 PM, Michael S. Tsirkin wrote: > > On Sat, Sep 30, 2017 at 12:05:52PM +0800, Wei Wang wrote: > > > +static int send_balloon_page_sg(struct virtio_balloon *vb, > > > + struct virtqueue *vq, > > > + void *addr, > > > + uint32_t size, > > > + bool batch) > > > +{ > > > + int err; > > > + > > > + err = add_one_sg(vq, addr, size); > > > + > > > + /* If batchng is requested, we batch till the vq is full */ > > > > typo > > > > > + if (!batch || !vq->num_free) > > > + kick_and_wait(vq, vb->acked); > > > + > > > + return err; > > > +} > > > > If add_one_sg fails, kick_and_wait will hang forever. > > > > The reason this might work in because > > 1. with 1 sg there are no memory allocations 2. if adding fails on vq full, then > > something > > is in queue and will wake up kick_and_wait. > > > > So in short this is expected to never fail. > > How about a BUG_ON here then? > > And make it void, and add a comment with above explanation. > > > > > Yes, agree that this wouldn't fail - the worker thread performing the ballooning operations has been put into sleep when the vq is full, so I think there shouldn't be anyone else to put more sgs onto the vq then. > Btw, not sure if we need to mention memory allocation in the comment, I found virtqueue_add() doesn't return any error when allocation (for indirect desc-s) fails - it simply avoids the use of indirect desc. > > What do you think of the following? > > err = add_one_sg(vq, addr, size); > /* > * This is expected to never fail: there is always at least 1 entry available on the vq, > * because when the vq is full the worker thread that adds the sg will be put into > * sleep until at least 1 entry is available to use. > */ > BUG_ON(err); > > Best, > Wei > > > > Sounds good. From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Michael S. Tsirkin" Subject: Re: [PATCH v16 3/5] virtio-balloon: VIRTIO_BALLOON_F_SG Date: Mon, 2 Oct 2017 16:44:52 +0300 Message-ID: <20171002160757-mutt-send-email-mst@kernel.org> References: <1506744354-20979-1-git-send-email-wei.w.wang@intel.com> <1506744354-20979-4-git-send-email-wei.w.wang@intel.com> <20171002072106-mutt-send-email-mst@kernel.org> <286AC319A985734F985F78AFA26841F73931FDB5@shsmsx102.ccr.corp.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: "virtio-dev@lists.oasis-open.org" , "linux-kernel@vger.kernel.org" , "qemu-devel@nongnu.org" , "virtualization@lists.linux-foundation.org" , "kvm@vger.kernel.org" , "linux-mm@kvack.org" , "mhocko@kernel.org" , "akpm@linux-foundation.org" , "mawilcox@microsoft.com" , "david@redhat.com" , "cornelia.huck@de.ibm.com" , "mgorman@techsingularity.net" , "aarcange@redhat.com" , "amit.shah@redhat.com" , "pbonzini@redhat.com" , "willy@infradead.org" , "liliang.opensource@gmail.com" Return-path: Content-Disposition: inline In-Reply-To: <286AC319A985734F985F78AFA26841F73931FDB5@shsmsx102.ccr.corp.intel.com> Sender: owner-linux-mm@kvack.org List-Id: kvm.vger.kernel.org On Mon, Oct 02, 2017 at 12:39:30PM +0000, Wang, Wei W wrote: > On Monday, October 2, 2017 12:30 PM, Michael S. Tsirkin wrote: > > On Sat, Sep 30, 2017 at 12:05:52PM +0800, Wei Wang wrote: > > > +static int send_balloon_page_sg(struct virtio_balloon *vb, > > > + struct virtqueue *vq, > > > + void *addr, > > > + uint32_t size, > > > + bool batch) > > > +{ > > > + int err; > > > + > > > + err = add_one_sg(vq, addr, size); > > > + > > > + /* If batchng is requested, we batch till the vq is full */ > > > > typo > > > > > + if (!batch || !vq->num_free) > > > + kick_and_wait(vq, vb->acked); > > > + > > > + return err; > > > +} > > > > If add_one_sg fails, kick_and_wait will hang forever. > > > > The reason this might work in because > > 1. with 1 sg there are no memory allocations 2. if adding fails on vq full, then > > something > > is in queue and will wake up kick_and_wait. > > > > So in short this is expected to never fail. > > How about a BUG_ON here then? > > And make it void, and add a comment with above explanation. > > > > > Yes, agree that this wouldn't fail - the worker thread performing the ballooning operations has been put into sleep when the vq is full, so I think there shouldn't be anyone else to put more sgs onto the vq then. > Btw, not sure if we need to mention memory allocation in the comment, I found virtqueue_add() doesn't return any error when allocation (for indirect desc-s) fails - it simply avoids the use of indirect desc. > > What do you think of the following? > > err = add_one_sg(vq, addr, size); > /* > * This is expected to never fail: there is always at least 1 entry available on the vq, > * because when the vq is full the worker thread that adds the sg will be put into > * sleep until at least 1 entry is available to use. > */ > BUG_ON(err); > > Best, > Wei > > > > Sounds good. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk0-f199.google.com (mail-qk0-f199.google.com [209.85.220.199]) by kanga.kvack.org (Postfix) with ESMTP id DAE996B0033 for ; Mon, 2 Oct 2017 09:45:08 -0400 (EDT) Received: by mail-qk0-f199.google.com with SMTP id a12so2648356qka.7 for ; Mon, 02 Oct 2017 06:45:08 -0700 (PDT) Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id n200si38376qke.281.2017.10.02.06.45.07 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Oct 2017 06:45:07 -0700 (PDT) Date: Mon, 2 Oct 2017 16:44:52 +0300 From: "Michael S. Tsirkin" Subject: Re: [PATCH v16 3/5] virtio-balloon: VIRTIO_BALLOON_F_SG Message-ID: <20171002160757-mutt-send-email-mst@kernel.org> References: <1506744354-20979-1-git-send-email-wei.w.wang@intel.com> <1506744354-20979-4-git-send-email-wei.w.wang@intel.com> <20171002072106-mutt-send-email-mst@kernel.org> <286AC319A985734F985F78AFA26841F73931FDB5@shsmsx102.ccr.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <286AC319A985734F985F78AFA26841F73931FDB5@shsmsx102.ccr.corp.intel.com> Sender: owner-linux-mm@kvack.org List-ID: To: "Wang, Wei W" Cc: "virtio-dev@lists.oasis-open.org" , "linux-kernel@vger.kernel.org" , "qemu-devel@nongnu.org" , "virtualization@lists.linux-foundation.org" , "kvm@vger.kernel.org" , "linux-mm@kvack.org" , "mhocko@kernel.org" , "akpm@linux-foundation.org" , "mawilcox@microsoft.com" , "david@redhat.com" , "cornelia.huck@de.ibm.com" , "mgorman@techsingularity.net" , "aarcange@redhat.com" , "amit.shah@redhat.com" , "pbonzini@redhat.com" , "willy@infradead.org" , "liliang.opensource@gmail.com" , "yang.zhang.wz@gmail.com" , "quan.xu@aliyun.com" On Mon, Oct 02, 2017 at 12:39:30PM +0000, Wang, Wei W wrote: > On Monday, October 2, 2017 12:30 PM, Michael S. Tsirkin wrote: > > On Sat, Sep 30, 2017 at 12:05:52PM +0800, Wei Wang wrote: > > > +static int send_balloon_page_sg(struct virtio_balloon *vb, > > > + struct virtqueue *vq, > > > + void *addr, > > > + uint32_t size, > > > + bool batch) > > > +{ > > > + int err; > > > + > > > + err = add_one_sg(vq, addr, size); > > > + > > > + /* If batchng is requested, we batch till the vq is full */ > > > > typo > > > > > + if (!batch || !vq->num_free) > > > + kick_and_wait(vq, vb->acked); > > > + > > > + return err; > > > +} > > > > If add_one_sg fails, kick_and_wait will hang forever. > > > > The reason this might work in because > > 1. with 1 sg there are no memory allocations 2. if adding fails on vq full, then > > something > > is in queue and will wake up kick_and_wait. > > > > So in short this is expected to never fail. > > How about a BUG_ON here then? > > And make it void, and add a comment with above explanation. > > > > > Yes, agree that this wouldn't fail - the worker thread performing the ballooning operations has been put into sleep when the vq is full, so I think there shouldn't be anyone else to put more sgs onto the vq then. > Btw, not sure if we need to mention memory allocation in the comment, I found virtqueue_add() doesn't return any error when allocation (for indirect desc-s) fails - it simply avoids the use of indirect desc. > > What do you think of the following? > > err = add_one_sg(vq, addr, size); > /* > * This is expected to never fail: there is always at least 1 entry available on the vq, > * because when the vq is full the worker thread that adds the sg will be put into > * sleep until at least 1 entry is available to use. > */ > BUG_ON(err); > > Best, > Wei > > > > Sounds good. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34227) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dz120-0003lF-Ev for qemu-devel@nongnu.org; Mon, 02 Oct 2017 09:45:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dz11w-0001t4-E5 for qemu-devel@nongnu.org; Mon, 02 Oct 2017 09:45:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50368) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dz11w-0001qQ-3t for qemu-devel@nongnu.org; Mon, 02 Oct 2017 09:45:08 -0400 Date: Mon, 2 Oct 2017 16:44:52 +0300 From: "Michael S. Tsirkin" Message-ID: <20171002160757-mutt-send-email-mst@kernel.org> References: <1506744354-20979-1-git-send-email-wei.w.wang@intel.com> <1506744354-20979-4-git-send-email-wei.w.wang@intel.com> <20171002072106-mutt-send-email-mst@kernel.org> <286AC319A985734F985F78AFA26841F73931FDB5@shsmsx102.ccr.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <286AC319A985734F985F78AFA26841F73931FDB5@shsmsx102.ccr.corp.intel.com> Subject: Re: [Qemu-devel] [PATCH v16 3/5] virtio-balloon: VIRTIO_BALLOON_F_SG List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Wang, Wei W" Cc: "virtio-dev@lists.oasis-open.org" , "linux-kernel@vger.kernel.org" , "qemu-devel@nongnu.org" , "virtualization@lists.linux-foundation.org" , "kvm@vger.kernel.org" , "linux-mm@kvack.org" , "mhocko@kernel.org" , "akpm@linux-foundation.org" , "mawilcox@microsoft.com" , "david@redhat.com" , "cornelia.huck@de.ibm.com" , "mgorman@techsingularity.net" , "aarcange@redhat.com" , "amit.shah@redhat.com" , "pbonzini@redhat.com" , "willy@infradead.org" , "liliang.opensource@gmail.com" , "yang.zhang.wz@gmail.com" , "quan.xu@aliyun.com" List-ID: On Mon, Oct 02, 2017 at 12:39:30PM +0000, Wang, Wei W wrote: > On Monday, October 2, 2017 12:30 PM, Michael S. Tsirkin wrote: > > On Sat, Sep 30, 2017 at 12:05:52PM +0800, Wei Wang wrote: > > > +static int send_balloon_page_sg(struct virtio_balloon *vb, > > > + struct virtqueue *vq, > > > + void *addr, > > > + uint32_t size, > > > + bool batch) > > > +{ > > > + int err; > > > + > > > + err = add_one_sg(vq, addr, size); > > > + > > > + /* If batchng is requested, we batch till the vq is full */ > > > > typo > > > > > + if (!batch || !vq->num_free) > > > + kick_and_wait(vq, vb->acked); > > > + > > > + return err; > > > +} > > > > If add_one_sg fails, kick_and_wait will hang forever. > > > > The reason this might work in because > > 1. with 1 sg there are no memory allocations 2. if adding fails on vq full, then > > something > > is in queue and will wake up kick_and_wait. > > > > So in short this is expected to never fail. > > How about a BUG_ON here then? > > And make it void, and add a comment with above explanation. > > > > > Yes, agree that this wouldn't fail - the worker thread performing the ballooning operations has been put into sleep when the vq is full, so I think there shouldn't be anyone else to put more sgs onto the vq then. > Btw, not sure if we need to mention memory allocation in the comment, I found virtqueue_add() doesn't return any error when allocation (for indirect desc-s) fails - it simply avoids the use of indirect desc. > > What do you think of the following? > > err = add_one_sg(vq, addr, size); > /* > * This is expected to never fail: there is always at least 1 entry available on the vq, > * because when the vq is full the worker thread that adds the sg will be put into > * sleep until at least 1 entry is available to use. > */ > BUG_ON(err); > > Best, > Wei > > > > Sounds good.