From patchwork Tue Nov 8 10:34:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 16978 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2619857wru; Tue, 8 Nov 2022 02:38:42 -0800 (PST) X-Google-Smtp-Source: AMsMyM5cjxxaJZXOHmkouxKwBh2IETlqc9WETWK6oNV5q3oYB8QRDkenFCa4Ub049bLzrqRayig4 X-Received: by 2002:aa7:d590:0:b0:463:d21a:f0af with SMTP id r16-20020aa7d590000000b00463d21af0afmr36284183edq.50.1667903922555; Tue, 08 Nov 2022 02:38:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667903922; cv=none; d=google.com; s=arc-20160816; b=pkeTmZY5jVDFo+EX2NTQPFRFy4Sa2/lriHCccZrFdhbLtGC9YK91yCgaIZFY5u2vd5 dd0/GbhA0hkUzVh7Bcu8ud0IyKImIYNwQD2mjOPLIR+Jovqkw6LdzIzp8p0j15zh4xj9 b1GV4nC0GkViyDP8F+nADodj76GjYsv/ogpcsB4UlhQWwp4jMlq2mHww+QwoPgq3SaBd sL32GsvbAvD06kfVM5WxLCY7wl1spjWvZW+Ba/nRRzmuVIYvU/nRzuMTM/Pq2pXI3F3T 1RtT+VlcJMc2SasBL1Wl9U6sFZmXUwTSX+K/pLk+5bSSHO6G1wdlli/S0spZLav9x0u5 5GsQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jnEQ/6uclYdSedN00zhcPF82VnGpN8n10b9g5MbTnn0=; b=Y2nR5ZKLo5C4KDGKey+zXEOe1dEOiAPnVArzeJPx5vtEfjXnriy0oK8yH7dQXHosi0 eBahUBoYy9w1DPH7FNeT7AVoQI5bIY1ZlN71nniBNZ77rt9e3jz9tnXHGP4qy0Xwfy+a O6lToUbC5uNeE5RUN+y1L2maLtNbdWupLh0hNvuqK8+mQtRjEc5shH8SLEZXWoXVF9NK 3XsPR4Mvis2S3yclSAAa2p38N03qLt4Uhk0ltumE34SCfJnKBGEtPboEHF7w5bXR7SGu j0L6aVsN2YClqehuKtsQTuaaXBx501uqpzDafts0Y1+Ivy7vx+3R6uYmicRlrVlSskVD NWbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CVy8Xvpd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ho8-20020a1709070e8800b0079b8cce1170si14592859ejc.950.2022.11.08.02.38.17; Tue, 08 Nov 2022 02:38:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CVy8Xvpd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S233962AbiKHKf4 (ORCPT + 99 others); Tue, 8 Nov 2022 05:35:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233922AbiKHKfp (ORCPT ); Tue, 8 Nov 2022 05:35:45 -0500 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 4D4A54090E for ; Tue, 8 Nov 2022 02:34:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667903685; 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=jnEQ/6uclYdSedN00zhcPF82VnGpN8n10b9g5MbTnn0=; b=CVy8Xvpd6yVBllRxXHMwaZkOzymHzFbHcH6mapNZQS5O62Ey4U0Mmo5Rj1gOsyGgXjB9k9 cJNZl9WvQ2J8mp4tIEltPFPdga97qUKKxexRZPX9jlga75qDq7Zc+OCH1Yf6cRP3noy/fp GE6AF5u3m5RVsVfWbIwkz2wanUZR94s= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-660-hAtSb8RlMvKGWA-X2JbZ-A-1; Tue, 08 Nov 2022 05:34:43 -0500 X-MC-Unique: hAtSb8RlMvKGWA-X2JbZ-A-1 Received: by mail-wr1-f72.google.com with SMTP id j25-20020adfa559000000b0023d5d7f95a2so2269367wrb.21 for ; Tue, 08 Nov 2022 02:34:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jnEQ/6uclYdSedN00zhcPF82VnGpN8n10b9g5MbTnn0=; b=qQvfEGz3XXcTAcfJL5remhy+m0l7Zil4yrkDXEGFspInokgUnSh9LQQQV3YXUzE/Zw A5fQ1ZvbtTCqF9FeiB5LnUmXJU2D7Ngf/LXdVAfB9kHd1hx12pb8PqzAIupmN6XEfl/b jSFuhqMKjy9YT56mCRslpMRvTuXn5wjfdH80MjJ5T8Haf9DsLUR1bnNDhO52mXOyunnS V/1gLvL4P/qL1sazsUbQmQoucB2YydpkyQOGU/HPCVq9YEKglDJ+fuGKrC7G21iAbM/G m3i+Loxzf5wDGDeH5hg/PIeSh7WxnjiwABCZt27N/YMknVa3m1XsH2/UQmtNuGmGM9RM aiDw== X-Gm-Message-State: ACrzQf0jnsLpDlaiSw1kFWK0pPJfFTJpl4Dha3cXGtrnJkA1/AHrJe5P QpFEquKxPbY2vIlsHFfqw/LMEfZikAQI1aXadpoa1tT5Ri+lWRj4CQ7qe8T9HApMzZIqph1f5Qt 0yl0CMBZiSdfjvbveQQVJm4om X-Received: by 2002:adf:f303:0:b0:236:d1c0:79dc with SMTP id i3-20020adff303000000b00236d1c079dcmr29615256wro.695.1667903682489; Tue, 08 Nov 2022 02:34:42 -0800 (PST) X-Received: by 2002:adf:f303:0:b0:236:d1c0:79dc with SMTP id i3-20020adff303000000b00236d1c079dcmr29615240wro.695.1667903682285; Tue, 08 Nov 2022 02:34:42 -0800 (PST) Received: from step1.redhat.com (host-82-53-134-234.retail.telecomitalia.it. [82.53.134.234]) by smtp.gmail.com with ESMTPSA id m11-20020a5d4a0b000000b0022ca921dc67sm9632802wrq.88.2022.11.08.02.34.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 02:34:41 -0800 (PST) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: linux-kernel@vger.kernel.org, "Michael S. Tsirkin" , kvm@vger.kernel.org, Jason Wang , netdev@vger.kernel.org, Stefano Garzarella Subject: [PATCH 2/2] vhost: fix range used in translate_desc() Date: Tue, 8 Nov 2022 11:34:37 +0100 Message-Id: <20221108103437.105327-3-sgarzare@redhat.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221108103437.105327-1-sgarzare@redhat.com> References: <20221108103437.105327-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748924023203813940?= X-GMAIL-MSGID: =?utf-8?q?1748924023203813940?= vhost_iotlb_itree_first() requires `start` and `last` parameters to search for a mapping that overlaps the range. In translate_desc() we cyclically call vhost_iotlb_itree_first(), incrementing `addr` by the amount already translated, so rightly we move the `start` parameter passed to vhost_iotlb_itree_first(), but we should hold the `last` parameter constant. Let's fix it by saving the `last` parameter value before incrementing `addr` in the loop. Fixes: 0bbe30668d89 ("vhost: factor out IOTLB") Signed-off-by: Stefano Garzarella Acked-by: Jason Wang --- I'm not sure about the fixes tag. On the one I used this patch should apply cleanly, but looking at the latest stable (4.9), maybe we should use Fixes: a9709d6874d5 ("vhost: convert pre sorted vhost memory array to interval tree") Suggestions? --- drivers/vhost/vhost.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 40097826cff0..3c2359570df9 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -2053,7 +2053,7 @@ static int translate_desc(struct vhost_virtqueue *vq, u64 addr, u32 len, struct vhost_dev *dev = vq->dev; struct vhost_iotlb *umem = dev->iotlb ? dev->iotlb : dev->umem; struct iovec *_iov; - u64 s = 0; + u64 s = 0, last = addr + len - 1; int ret = 0; while ((u64)len > s) { @@ -2063,7 +2063,7 @@ static int translate_desc(struct vhost_virtqueue *vq, u64 addr, u32 len, break; } - map = vhost_iotlb_itree_first(umem, addr, addr + len - 1); + map = vhost_iotlb_itree_first(umem, addr, last); if (map == NULL || map->start > addr) { if (umem != dev->iotlb) { ret = -EFAULT;