Message ID | 20230925103057.104541-1-sgarzare@redhat.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1352270vqu; Mon, 25 Sep 2023 09:58:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFDdavzmDqMNAbzmszS0P3RhWfNxP6pD90tIhzSdf7B9j4mjErb5TVk9f9Ze3L6FbnMMVtg X-Received: by 2002:a17:902:f801:b0:1c6:362:3553 with SMTP id ix1-20020a170902f80100b001c603623553mr222387plb.31.1695661088971; Mon, 25 Sep 2023 09:58:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695661088; cv=none; d=google.com; s=arc-20160816; b=ss3MhndIt6htosqcl6i6OJLMLN9OqQ7cR2ZiFdd+qqRbBYIIuhxnUVrw4cDraE4yzL VgJDOPrX09bYEuIKfSEmqhOimqI7soqzXyYavGqWK9B+XctAPldQoZrJ/RdmYtOKUKiU Vg7yS1canaWzHjc8P1JVAZw5vYRAFj4O+558noaJvjIjodU9Wf3eITHwEYxqYOKB4bZC 0BR2UCMnNefiHYfc1Wu7o7htxszas7vvMjFCuMCOrEMpgA29FmcVnWeoQ1xMFz8vlvxA BL4vyupRe9grJeNhlqBOKhIS1FX9NTyQxsT32Ioabx6utTnhaWSXgnCbcOM6oYnMwLFa Sqcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=0DpECY4xgD810waS/rgF1VksorNZHYkHpCmfPvNqmEU=; fh=qrc8HGg5lqc9+IW9O+SY3XkG8EockghAIddZTHk8lvQ=; b=M/u3ua+VXPAAenPCR9r6fnNXmm0KLZKawgTUVB09K5YoKYbDCnfeZoix7YnYxDJHc4 Y7BS7aEnSDAsO88geCbppxhRxjOHzgbS2YFBDy5t2zyAGDo62G6iJ0jkJlMaM4v1B82G ZxyngxZ2QNibs4TBN3HnqAcid7SMQP1AGMhyY6iCXil9UBvqfbuG4KuN4Rxw3ADns5Gj zyLJwqeX8IKgEs7zE2CTPi0SQZr5KCGNQOsvvoV+ms5/iL8RXSqAJtoB3Ivah5BJn+wf mMOMW1xHngXeH6aSuZEYcAsbS6dfGaxldxoT9QtQQEvffPwq4BxQfK12dNbBrr64yT65 bdxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ePyqz1Es; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id j14-20020a170903024e00b001bb377f8c8bsi11495013plh.2.2023.09.25.09.58.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 09:58:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ePyqz1Es; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id AD60980AC463; Mon, 25 Sep 2023 03:32:11 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231825AbjIYKb7 (ORCPT <rfc822;pusanteemu@gmail.com> + 29 others); Mon, 25 Sep 2023 06:31:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231778AbjIYKb4 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 25 Sep 2023 06:31:56 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C353AAB for <linux-kernel@vger.kernel.org>; Mon, 25 Sep 2023 03:31:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695637864; 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; bh=0DpECY4xgD810waS/rgF1VksorNZHYkHpCmfPvNqmEU=; b=ePyqz1EsLb9CWe/6RWcb3GbCQq9NpcyiGzTGv647lTewWWn39wro/EMhnqbhgF/JSASoqE aNWY6oAmy7mmmqkqQnHL2dm06kqM5/XjaXnMtt2/RtRVcFQbNwmyNky3L0ZprY8coQhidS z03mhY3QCnI/gFD8OBJ2K4WpkxJ73s4= Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-522-ZwymEXolN8aakM0apb4t3g-1; Mon, 25 Sep 2023 06:31:02 -0400 X-MC-Unique: ZwymEXolN8aakM0apb4t3g-1 Received: by mail-lj1-f197.google.com with SMTP id 38308e7fff4ca-2b8405aace3so79638281fa.3 for <linux-kernel@vger.kernel.org>; Mon, 25 Sep 2023 03:31:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695637861; x=1696242661; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=0DpECY4xgD810waS/rgF1VksorNZHYkHpCmfPvNqmEU=; b=QbjRO6IiBLnc15NtuJS2+Z1UdINDE02ickASS8A/ilCpX8/+Q0dUZMf2KvsuOAl/gB 3Y0WigUUL6VqZtlZRISasvCxMM+RbP4ukeeomQpjiWiHU/XKDoZ2XScOJXnTto7KWUhK Sq5TVoScwMZ0YQDG9z1DGbZMZn61DINmajg7tEKKKqEffiMNDMajk/enJZmwrDi8jCZs t+GTpZvgRWIXKx1IVjFR6fCtUH17qAwThSEdMuMZpe69jLhKl9qbZjphGvVGt+JKrLCZ ojQVRJycTeejB8iI668B+JsqQ16s5n7oYAZRwEN1ZrHoEXmNHDsEL6dQ+RqGJo7ugt0O /28Q== X-Gm-Message-State: AOJu0Yz+qfmSlQqi5PxYof0EveGGGrDoyhExI9F/reSY6mY2WrZeQ/gr 14jztJHe51Zasq+53XPfCoLSbrkYApexItge4j9rcv/zVJg4j3hghluLCszteohOMXuFlFTG0Yg ZuPHx98amZItvk1CYZouL6YVn X-Received: by 2002:a2e:8084:0:b0:2bc:fa8f:83c4 with SMTP id i4-20020a2e8084000000b002bcfa8f83c4mr5126302ljg.39.1695637861134; Mon, 25 Sep 2023 03:31:01 -0700 (PDT) X-Received: by 2002:a2e:8084:0:b0:2bc:fa8f:83c4 with SMTP id i4-20020a2e8084000000b002bcfa8f83c4mr5126286ljg.39.1695637860736; Mon, 25 Sep 2023 03:31:00 -0700 (PDT) Received: from step1.lan ([46.6.235.141]) by smtp.gmail.com with ESMTPSA id mh2-20020a170906eb8200b0099cc3c7ace2sm6161066ejb.140.2023.09.25.03.30.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 03:30:59 -0700 (PDT) From: Stefano Garzarella <sgarzare@redhat.com> To: virtualization@lists.linux-foundation.org Cc: netdev@vger.kernel.org, kvm@vger.kernel.org, "Michael S. Tsirkin" <mst@redhat.com>, Stefano Garzarella <sgarzare@redhat.com>, Jason Wang <jasowang@redhat.com>, linux-kernel@vger.kernel.org Subject: [PATCH] vringh: don't use vringh_kiov_advance() in vringh_iov_xfer() Date: Mon, 25 Sep 2023 12:30:57 +0200 Message-ID: <20230925103057.104541-1-sgarzare@redhat.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Mon, 25 Sep 2023 03:32:11 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778029521990165609 X-GMAIL-MSGID: 1778029521990165609 |
Series |
vringh: don't use vringh_kiov_advance() in vringh_iov_xfer()
|
|
Commit Message
Stefano Garzarella
Sept. 25, 2023, 10:30 a.m. UTC
In the while loop of vringh_iov_xfer(), `partlen` could be 0 if one of
the `iov` has 0 lenght.
In this case, we should skip the iov and go to the next one.
But calling vringh_kiov_advance() with 0 lenght does not cause the
advancement, since it returns immediately if asked to advance by 0 bytes.
Let's restore the code that was there before commit b8c06ad4d67d
("vringh: implement vringh_kiov_advance()"), avoiding using
vringh_kiov_advance().
Fixes: b8c06ad4d67d ("vringh: implement vringh_kiov_advance()")
Cc: stable@vger.kernel.org
Reported-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
---
drivers/vhost/vringh.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
Comments
On Mon, Sep 25, 2023 at 6:31 PM Stefano Garzarella <sgarzare@redhat.com> wrote: > > In the while loop of vringh_iov_xfer(), `partlen` could be 0 if one of > the `iov` has 0 lenght. > In this case, we should skip the iov and go to the next one. > But calling vringh_kiov_advance() with 0 lenght does not cause the > advancement, since it returns immediately if asked to advance by 0 bytes. > > Let's restore the code that was there before commit b8c06ad4d67d > ("vringh: implement vringh_kiov_advance()"), avoiding using > vringh_kiov_advance(). > > Fixes: b8c06ad4d67d ("vringh: implement vringh_kiov_advance()") > Cc: stable@vger.kernel.org > Reported-by: Jason Wang <jasowang@redhat.com> > Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> Acked-by: Jason Wang <jasowang@redhat.com> Thanks > --- > drivers/vhost/vringh.c | 12 +++++++++++- > 1 file changed, 11 insertions(+), 1 deletion(-) > > diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c > index 955d938eb663..7b8fd977f71c 100644 > --- a/drivers/vhost/vringh.c > +++ b/drivers/vhost/vringh.c > @@ -123,8 +123,18 @@ static inline ssize_t vringh_iov_xfer(struct vringh *vrh, > done += partlen; > len -= partlen; > ptr += partlen; > + iov->consumed += partlen; > + iov->iov[iov->i].iov_len -= partlen; > + iov->iov[iov->i].iov_base += partlen; > > - vringh_kiov_advance(iov, partlen); > + if (!iov->iov[iov->i].iov_len) { > + /* Fix up old iov element then increment. */ > + iov->iov[iov->i].iov_len = iov->consumed; > + iov->iov[iov->i].iov_base -= iov->consumed; > + > + iov->consumed = 0; > + iov->i++; > + } > } > return done; > } > -- > 2.41.0 >
Hello: This patch was applied to netdev/net.git (main) by David S. Miller <davem@davemloft.net>: On Mon, 25 Sep 2023 12:30:57 +0200 you wrote: > In the while loop of vringh_iov_xfer(), `partlen` could be 0 if one of > the `iov` has 0 lenght. > In this case, we should skip the iov and go to the next one. > But calling vringh_kiov_advance() with 0 lenght does not cause the > advancement, since it returns immediately if asked to advance by 0 bytes. > > Let's restore the code that was there before commit b8c06ad4d67d > ("vringh: implement vringh_kiov_advance()"), avoiding using > vringh_kiov_advance(). > > [...] Here is the summary with links: - vringh: don't use vringh_kiov_advance() in vringh_iov_xfer() https://git.kernel.org/netdev/net/c/7aed44babc7f You are awesome, thank you!
diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c index 955d938eb663..7b8fd977f71c 100644 --- a/drivers/vhost/vringh.c +++ b/drivers/vhost/vringh.c @@ -123,8 +123,18 @@ static inline ssize_t vringh_iov_xfer(struct vringh *vrh, done += partlen; len -= partlen; ptr += partlen; + iov->consumed += partlen; + iov->iov[iov->i].iov_len -= partlen; + iov->iov[iov->i].iov_base += partlen; - vringh_kiov_advance(iov, partlen); + if (!iov->iov[iov->i].iov_len) { + /* Fix up old iov element then increment. */ + iov->iov[iov->i].iov_len = iov->consumed; + iov->iov[iov->i].iov_base -= iov->consumed; + + iov->consumed = 0; + iov->i++; + } } return done; }