Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1342638ybt; Sun, 14 Jun 2020 19:46:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyb6Rs5co6cr7hven8dsZVGcwkmaJ5CuLgxQRAwk8zPMdJ2Vb/EBA19fFMTHoQnhbErv2L8 X-Received: by 2002:a05:6402:1606:: with SMTP id f6mr21388042edv.286.1592189207839; Sun, 14 Jun 2020 19:46:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592189207; cv=none; d=google.com; s=arc-20160816; b=lNqsWMrbUMCo+gKJkSD9Xg/7/UqlTqUU8NcfjdECGpzlr13KuS0HPYncwpLeiL4yQw LXZfIf0HxRaPisM+VnDjjeiqpPrrwuLLTH07D+1FOn4wmJwrTdwhyp67gAAKxmCqooAz M88QbQLFZBTQk57ur67LCwWyDQhb9fSVWkkawkod0DmYV+3cLNGuXL//oiDRit8qXpVI EnqV1ouOm4npGVh5V+dOe4duXePEzRQ+uAyeAYKEDoWOUhL5AN3tdrdFGTZ5IU1kXAiE SLx3d9Rh112mU+TePu/noyH37JqPHKngsmZksL03KAtuSzeU3VVan8ic3ApD4QrgA2Wu kxlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=CDf2ubutxAR6PnZDzVX0vkP0DzBLtkr2OZNFYDY7Wa0=; b=L9ZsX+LLd380RgHa2wcrGr+FJdnHjq5uDFLK4tieZcYk/nf8wuQIyTYpHvZJgShN0q e074vKLuViz+OdwEr/16jV4NUczqozkP7upJLrwJ+viunVqmg4L214EMvsqzGVbfQnDN afX8vdD0l4kMVVHjlBxRm5crCAK1IOgqrmZ0F+HzlQwrlwWjrVrQb5F7+k292Uv/TOIa Cldql9k4VwcreFqewgJmFcNjH/gOB2zx902dLyjbOBPdZfNvc33V5lyZH9G62eiFyid9 irea1zgIe7LR5Z310fHYtRD8lVd3dZBJQvD1p6mM/HnvQvg+z3i4kC/GCpqqRx5HB996 CvSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EcArHfig; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j6si8333634edp.147.2020.06.14.19.46.10; Sun, 14 Jun 2020 19:46:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EcArHfig; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728144AbgFOCny (ORCPT + 99 others); Sun, 14 Jun 2020 22:43:54 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:47288 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727971AbgFOCny (ORCPT ); Sun, 14 Jun 2020 22:43:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592189033; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CDf2ubutxAR6PnZDzVX0vkP0DzBLtkr2OZNFYDY7Wa0=; b=EcArHfigCkC3lWILCvUQln660S4+IqDUHkf6euu6PImrfuJkXRB6flUOs88dQk/uleu7L3 lR4CZncVSlF/nSt54FFDaxYCH08O+/peVqIqGCSS/RZz4j8Qj19H8xxPwJn59FyO68nMrr oDS7Y6TD38nG//IT3DtJBXg7N8QiauQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-514-zrMBqGQyM0aTkj5DQlI_rw-1; Sun, 14 Jun 2020 22:43:51 -0400 X-MC-Unique: zrMBqGQyM0aTkj5DQlI_rw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3D412108BD1A; Mon, 15 Jun 2020 02:43:50 +0000 (UTC) Received: from [10.72.13.232] (ovpn-13-232.pek2.redhat.com [10.72.13.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id 602001A91F; Mon, 15 Jun 2020 02:43:44 +0000 (UTC) Subject: Re: [PATCH RFC v6 02/11] vhost: use batched get_vq_desc version To: "Michael S. Tsirkin" Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, eperezma@redhat.com References: <20200608125238.728563-1-mst@redhat.com> <20200608125238.728563-3-mst@redhat.com> <81904cc5-b662-028d-3b4a-bdfdbd2deb8c@redhat.com> <20200610070259-mutt-send-email-mst@kernel.org> <76b14132-407a-48bf-c4d5-9d0b2c700bb0@redhat.com> <20200611050416-mutt-send-email-mst@kernel.org> From: Jason Wang Message-ID: Date: Mon, 15 Jun 2020 10:43:42 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <20200611050416-mutt-send-email-mst@kernel.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/6/11 下午5:06, Michael S. Tsirkin wrote: > On Thu, Jun 11, 2020 at 11:02:57AM +0800, Jason Wang wrote: >> On 2020/6/10 下午7:05, Michael S. Tsirkin wrote: >>>>> +EXPORT_SYMBOL_GPL(vhost_get_vq_desc); >>>>> /* Reverse the effect of vhost_get_vq_desc. Useful for error handling. */ >>>>> void vhost_discard_vq_desc(struct vhost_virtqueue *vq, int n) >>>>> { >>>>> + unfetch_descs(vq); >>>>> vq->last_avail_idx -= n; >>>> So unfetch_descs() has decreased last_avail_idx. >>>> Can we fix this by letting unfetch_descs() return the number and then we can >>>> do: >>>> >>>> int d = unfetch_descs(vq); >>>> vq->last_avail_idx -= (n > d) ? n - d: 0; >>>> >>>> Thanks >>> That's intentional I think - we need both. >> >> Yes, but: >> >> >>> Unfetch_descs drops the descriptors in the cache that were >>> *not returned to caller* through get_vq_desc. >>> >>> vhost_discard_vq_desc drops the ones that were returned through get_vq_desc. >>> >>> Did I miss anything? >> We could count some descriptors twice, consider the case e.g we only cache >> on descriptor: >> >> fetch_descs() >>     fetch_buf() >>         last_avail_idx++; >> >> Then we want do discard it: >> vhost_discard_avail_buf(1) >>     unfetch_descs() >>         last_avail_idx--; >>     last_avail_idx -= 1; >> >> Thanks > > I don't think that happens. vhost_discard_avail_buf(1) is only called > after get vhost_get_avail_buf. vhost_get_avail_buf increments > first_desc. unfetch_descs only counts from first_desc to ndescs. > > If I'm wrong, could you show values of first_desc and ndescs in this > scenario? You're right, fetch_descriptor could not be called directly from the device code. Thanks >