Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp765986pxv; Thu, 24 Jun 2021 20:25:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+CxFAczvJZZHao9cdID+2E7a53yS9wvU0cd+F8jy6WiG2eeMXiUKCrz3KNZt5W26Qo+V0 X-Received: by 2002:a02:9665:: with SMTP id c92mr7563025jai.56.1624591558668; Thu, 24 Jun 2021 20:25:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624591558; cv=none; d=google.com; s=arc-20160816; b=y8jdChywBHLidHWpmdCXSsA4Q4MsuzOY+XxgV6uWt496slLbbM5i8LhR+gqm1yuD5W CF/bHb/19ouzYmgE7hvuhWLQSXAdd6GAO6QSxW15lSnkUjeY6d6IlmJmh+qyrE4h+55W hBi2LlHW4/c2T3dPQXVOF7WsRYw+yXPscDBfLGuVN9tUWfwvBLW2oIsvscYVzyNkxV1S pnS0g60b62YScHV3uJuFZw/GBIoo3REL1azv9MHnkEQE0tiUI0+IzCyHF0cJrcG5PJCL u0YXK+/QBfymbw3y796BSFjRqBQ8VjFOno11ZKYVMntUt889ZPzleAYF7ZJieexmvIBx ZwBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from:dmarc-filter :sender:dkim-signature; bh=1OKKAMM0YbUVRu/d0x/9APRTo8SYNuVejwQx1EDQ0qY=; b=gzo3RHA2InZfY9H3w2X2/J8wfIlAjm4zZOe45GFTzuMdzl9N0y4uZOG0eReHy/8Dor QWqRWW5xiQivqVUdo1mhs9QJFNlltAoWObj7X0dzweF9J1qdt5hLYhtMMCl3o1uT9yyA UxrhUWwmXRXloZkR8d5q+CjxNdaOybywpaNoqz4TgZ/OJI2ZC2H91O0OFhwxgzq6vzGl SHs61KyFjrUs92KbHvCTFDxFdT0f4ckokhckN0mG23Lj71Dg7YKBKcvLH4vvq+jsyk/k bN0gACbxWIGhhDX9F6aQPbNlKkE+qp/1qE20kBqAXlzenDCFpynSf1fPm9lF1mJseXfK h7sA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=toTuJevz; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k3si4596866ilv.69.2021.06.24.20.25.46; Thu, 24 Jun 2021 20:25:58 -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=@mg.codeaurora.org header.s=smtp header.b=toTuJevz; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233041AbhFYD13 (ORCPT + 99 others); Thu, 24 Jun 2021 23:27:29 -0400 Received: from so254-9.mailgun.net ([198.61.254.9]:29220 "EHLO so254-9.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232917AbhFYD13 (ORCPT ); Thu, 24 Jun 2021 23:27:29 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1624591509; h=Message-Id: Date: Subject: Cc: To: From: Sender; bh=1OKKAMM0YbUVRu/d0x/9APRTo8SYNuVejwQx1EDQ0qY=; b=toTuJevzmcQlQsPtndVC+jDbB53yxaHI34cD2SzkAClci+FAIRkYWbXgVpGrwug4Ja1T4onQ vfMZENxrMyILLc1VMJ+s/+mml+ix9kKXXS9j7m/ciIzwe0M+nzRa9zRs74vuCm5OnqZUMZ5C 2pGSP7i6NuPi9MzHhL+/2VJtEYM= X-Mailgun-Sending-Ip: 198.61.254.9 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n07.prod.us-east-1.postgun.com with SMTP id 60d54c944ca9face34423a02 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Fri, 25 Jun 2021 03:25:08 GMT Sender: neeraju=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id C3469C43460; Fri, 25 Jun 2021 03:25:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=ALL_TRUSTED,BAYES_00,SPF_FAIL autolearn=no autolearn_force=no version=3.4.0 Received: from localhost (unknown [202.46.22.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: neeraju) by smtp.codeaurora.org (Postfix) with ESMTPSA id 2E19FC433F1; Fri, 25 Jun 2021 03:25:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 2E19FC433F1 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=fail smtp.mailfrom=neeraju@codeaurora.org From: Neeraj Upadhyay To: mst@redhat.com, jasowang@redhat.com Cc: virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, sgarzare@redhat.com, Neeraj Upadhyay Subject: [PATCH v2] vringh: Use wiov->used to check for read/write desc order Date: Fri, 25 Jun 2021 08:55:02 +0530 Message-Id: <1624591502-4827-1-git-send-email-neeraju@codeaurora.org> X-Mailer: git-send-email 2.7.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As __vringh_iov() traverses a descriptor chain, it populates each descriptor entry into either read or write vring iov and increments that iov's ->used member. So, as we iterate over a descriptor chain, at any point, (riov/wriov)->used value gives the number of descriptor enteries available, which are to be read or written by the device. As all read iovs must precede the write iovs, wiov->used should be zero when we are traversing a read descriptor. Current code checks for wiov->i, to figure out whether any previous entry in the current descriptor chain was a write descriptor. However, iov->i is only incremented, when these vring iovs are consumed, at a later point, and remain 0 in __vringh_iov(). So, correct the check for read and write descriptor order, to use wiov->used. Acked-by: Jason Wang Reviewed-by: Stefano Garzarella Signed-off-by: Neeraj Upadhyay --- Changes in v2: Commit message updated to clarify why wiov->i cannot be used. drivers/vhost/vringh.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c index 4af8fa2..14e2043 100644 --- a/drivers/vhost/vringh.c +++ b/drivers/vhost/vringh.c @@ -359,7 +359,7 @@ __vringh_iov(struct vringh *vrh, u16 i, iov = wiov; else { iov = riov; - if (unlikely(wiov && wiov->i)) { + if (unlikely(wiov && wiov->used)) { vringh_bad("Readable desc %p after writable", &descs[i]); err = -EINVAL; -- QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation