From patchwork Wed Nov 9 10:25:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13037321 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87776C43217 for ; Wed, 9 Nov 2022 10:26:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230435AbiKIK0R (ORCPT ); Wed, 9 Nov 2022 05:26:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229834AbiKIK0P (ORCPT ); Wed, 9 Nov 2022 05:26:15 -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 473A514085 for ; Wed, 9 Nov 2022 02:25:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667989512; 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=yog0hcuy+DRZPETd9YkKxOoct4jxmNsATV6V9Xx3MWc=; b=Cubzxsp/FhdnicGCbhVeu3i8DFdv7sJKe48wsnkZMoQp7Hvgc1+gTA+spZ+aO3T13aChYp XCqZeEC9QcOT8MOzop+Pwni7Qv2zkK7Cpq4grURXR2I38IACB64iJgShINi3+0gf+4AT3X seVrIsp9h3SN0sk9trc1CdPCY0fFV7g= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-626-Mfw_B51iNF6hZxrH0hp1qg-1; Wed, 09 Nov 2022 05:25:11 -0500 X-MC-Unique: Mfw_B51iNF6hZxrH0hp1qg-1 Received: by mail-qk1-f198.google.com with SMTP id br12-20020a05620a460c00b006fa52448320so15315140qkb.0 for ; Wed, 09 Nov 2022 02:25:11 -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=yog0hcuy+DRZPETd9YkKxOoct4jxmNsATV6V9Xx3MWc=; b=7/6udnppEGf3uIcLw94fSZ5t4f0OIGj2I6VWjOeI1LI4See9Lcpin5RXYs7ubodeJm Uyba8FcYkMqlc/fSIrKbio7HYmrTWyT4KgrdK3Fe+zFdQTgdZEuo3AnjGLnmu2wF0Btr MJOEJIq1O0gV43/tTMRnSK5vI1O5zf3N78H8ZTyz0Oe/C1Z3JXXCi3k7uRZ2pJWoQxl+ CHkgOZegYhamW2BOqL4DwMhkbLKdVzp3cg2kqpMXN3PkmY3FlwXs4tn5yMqccH/ZMNvS BtqqBRmUTobxCsQY28M92z/kE6OfnzminGSr+bcv1q1D1/bEE2ZNrGRYDwqIxubloFyJ zMJg== X-Gm-Message-State: ACrzQf3j7XXBThwBtKL/7s9fPklWtA1rw1lB9BYHHyuoeirTWuYobkS9 EPjY8YzFvcTmKwinS2zEZs6+9JLGG+d0SzfVSjR7q14aBvgOqKjJOJKsGOulFEXyahpGN6rJj7I 3ELOTNsSZw2OsWV9g X-Received: by 2002:a05:622a:12:b0:3a5:6899:5add with SMTP id x18-20020a05622a001200b003a568995addmr20183667qtw.629.1667989510777; Wed, 09 Nov 2022 02:25:10 -0800 (PST) X-Google-Smtp-Source: AMsMyM7dHRvHahxNPyxd5cXNPDwYDthvEkrvK4CouVYmtTTQjEql4SHBFw0gbhGAtAaO5z7i7a0AnQ== X-Received: by 2002:a05:622a:12:b0:3a5:6899:5add with SMTP id x18-20020a05622a001200b003a568995addmr20183656qtw.629.1667989510546; Wed, 09 Nov 2022 02:25:10 -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 bj10-20020a05620a190a00b006fa313bf185sm10827522qkb.8.2022.11.09.02.25.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Nov 2022 02:25:09 -0800 (PST) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Stefano Garzarella Subject: [PATCH v2 1/2] vringh: fix range used in iotlb_translate() Date: Wed, 9 Nov 2022 11:25:02 +0100 Message-Id: <20221109102503.18816-2-sgarzare@redhat.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221109102503.18816-1-sgarzare@redhat.com> References: <20221109102503.18816-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-type: text/plain Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org vhost_iotlb_itree_first() requires `start` and `last` parameters to search for a mapping that overlaps the range. In iotlb_translate() 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: 9ad9c49cfe97 ("vringh: IOTLB support") Acked-by: Jason Wang Signed-off-by: Stefano Garzarella --- drivers/vhost/vringh.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c index 11f59dd06a74..828c29306565 100644 --- a/drivers/vhost/vringh.c +++ b/drivers/vhost/vringh.c @@ -1102,7 +1102,7 @@ static int iotlb_translate(const struct vringh *vrh, struct vhost_iotlb_map *map; struct vhost_iotlb *iotlb = vrh->iotlb; int ret = 0; - u64 s = 0; + u64 s = 0, last = addr + len - 1; spin_lock(vrh->iotlb_lock); @@ -1114,8 +1114,7 @@ static int iotlb_translate(const struct vringh *vrh, break; } - map = vhost_iotlb_itree_first(iotlb, addr, - addr + len - 1); + map = vhost_iotlb_itree_first(iotlb, addr, last); if (!map || map->start > addr) { ret = -EINVAL; break; From patchwork Wed Nov 9 10:25:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13037322 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC5E5C433FE for ; Wed, 9 Nov 2022 10:26:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230463AbiKIK0T (ORCPT ); Wed, 9 Nov 2022 05:26:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230442AbiKIK0P (ORCPT ); Wed, 9 Nov 2022 05:26:15 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBC0217AAD for ; Wed, 9 Nov 2022 02:25:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667989515; 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=XonZz/B2W6BqtiPIn1XQ7dqlSI0WP9PGZyzmQRe2lsc=; b=Zm66+uF3sVBCczxY4QxIbu3wMYa/qP6OSuU8ZFH1AP6Sme9s+jaSiD39xcrO+9WL9OUvQv v8Jn2hIMwxR336G358pkdYyN8yL/7YfJ5a0wZSliEdHUYkAKhZeuHG40C69es8/KywTNO3 Xdkz0fFz26filpd0q8dEbaNnwFwVxK8= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-601-5rt0f4DTPAa7jfZgsgXhfg-1; Wed, 09 Nov 2022 05:25:13 -0500 X-MC-Unique: 5rt0f4DTPAa7jfZgsgXhfg-1 Received: by mail-qt1-f198.google.com with SMTP id fb5-20020a05622a480500b003a525d52abcso12225661qtb.10 for ; Wed, 09 Nov 2022 02:25:13 -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=XonZz/B2W6BqtiPIn1XQ7dqlSI0WP9PGZyzmQRe2lsc=; b=fucxipuNnaZt47DnlKc95FSaGRkKAHd1zbUJAzhyWzAxXcNP7kXJ0MOh4eBkWEprFE L3A+OvBzBVOiZv1o4VDz+9avcMgeT6mjZyWd+haZ2vcV7DwEyC797RNacxHHOb/V4Bbx /rES14g8WUB3Eo6DdU8tcEe3uK7AZy+QzKJoflC1YwPeKLVJ6fxq1uNmuzkk217t+m43 ySBcxcqSzXTHvs6+c18bWhl7SaPcg5rgmX4isNrKeqL46gVEPFvax0sTSQEJnwyjdCRb QNLopvTV6DH36Ytf6h0u9H9JeTcgKSLFEhzaeDKTsNW6bF49E4o0IuxQcH78ltPlAmfI c+QA== X-Gm-Message-State: ACrzQf3MpuQbaQcSpvWhYVDAWDN7hlA/yApN0K0BrSgJ3kGD5bkZd0q/ yHfwkDUEinK45wWcBn9JZjAtT+5rwMijmWwZJVGrxE/O7ImeO1RxEFra9SdUne6sfqhSOPsIUGp LBeHz1eCxFqk2oJB6 X-Received: by 2002:a37:8943:0:b0:6fa:a454:c8d2 with SMTP id l64-20020a378943000000b006faa454c8d2mr16840217qkd.534.1667989513373; Wed, 09 Nov 2022 02:25:13 -0800 (PST) X-Google-Smtp-Source: AMsMyM7bgS44r6yW8TpTmUka6iM1lFnyLysINGmhFPYaKUR8f+8FNUgnbq7sR8Utx2EfXdQOWtRelQ== X-Received: by 2002:a37:8943:0:b0:6fa:a454:c8d2 with SMTP id l64-20020a378943000000b006faa454c8d2mr16840207qkd.534.1667989513122; Wed, 09 Nov 2022 02:25:13 -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 bj10-20020a05620a190a00b006fa313bf185sm10827522qkb.8.2022.11.09.02.25.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Nov 2022 02:25:12 -0800 (PST) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Stefano Garzarella Subject: [PATCH v2 2/2] vhost: fix range used in translate_desc() Date: Wed, 9 Nov 2022 11:25:03 +0100 Message-Id: <20221109102503.18816-3-sgarzare@redhat.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221109102503.18816-1-sgarzare@redhat.com> References: <20221109102503.18816-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-type: text/plain Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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: a9709d6874d5 ("vhost: convert pre sorted vhost memory array to interval tree") Acked-by: Jason Wang Signed-off-by: Stefano Garzarella --- v2: - Replaced Fixes tag with the right one [Jason] --- 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;