From patchwork Tue Nov 8 10:34:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13036113 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 3D8D1C43219 for ; Tue, 8 Nov 2022 10:35:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233911AbiKHKfp (ORCPT ); Tue, 8 Nov 2022 05:35:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233921AbiKHKfk (ORCPT ); Tue, 8 Nov 2022 05:35:40 -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 08C9018E08 for ; Tue, 8 Nov 2022 02:34:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667903683; 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=bKRP4+cw0VhFwZrp8HtA3cgViFo5lHlh1+6syG/i+wQ=; b=fimNQknFaTAUDv6871+ju9r+sWpLVjQOZ1iP2ULFUh30KF7B5anuxoHDfSwiv4zvFCoEtU AL/+c+ONgCBro5tf5cGOeu34agvlNRcy9qsRjnkZTj6MD6R1Dk37OBcLspWGRF6YUag3Nf 2HZbPuKPMFURVqhalPeaTt64X2aNm0E= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-455-6HsaHA6mOJama93TWBLLjg-1; Tue, 08 Nov 2022 05:34:42 -0500 X-MC-Unique: 6HsaHA6mOJama93TWBLLjg-1 Received: by mail-wr1-f69.google.com with SMTP id v12-20020adfa1cc000000b00236eaee7197so3803011wrv.0 for ; Tue, 08 Nov 2022 02:34:41 -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=bKRP4+cw0VhFwZrp8HtA3cgViFo5lHlh1+6syG/i+wQ=; b=Rn6RKe72c7ZxTIAJFtG3yJC1RNbK4JQCW2nD+SY4I6XpjUqOrseS4hwpqxRF5LjDrN rBeTyJb5hlTfzmp6Acrq9eTa33zlgPPqEyu5OOq1X9zxKMbFatHBrwLPbAhXaXB6s+/g WGxewX+fGjybm0TIMBg0eEc83/7JEsnYJJPGAmJ98t9sUSP9B2Qi18WeZcb5vZ67JazE JvKLdCdE2WiV8n2kAjMRKyAu6smIqQUWg4FOBg6w3usGHHIHWElmD9D6eMVDiOoPmKf0 jL341sK6NmlsY8O8imvkt8kyq2c8/8BiT+U/O3CUS5vcOD0amGvBl6pynedkeqcG+9gV +noA== X-Gm-Message-State: ACrzQf3fAXL7ejeur8+BkRTNKgnqQ5R22Cb6gIQxuknsoTpgAGRRyxYf rlHosqS1Ea4UadK5TdK++VNZ1bZzUPw4o7wtwhGTRrPL09N32NGrWHRn9dGNGnLyDTk+TXiMHKC kFeGO+rTldZFU5hMI X-Received: by 2002:a05:600c:ad0:b0:3cf:692a:7f66 with SMTP id c16-20020a05600c0ad000b003cf692a7f66mr35280923wmr.200.1667903680917; Tue, 08 Nov 2022 02:34:40 -0800 (PST) X-Google-Smtp-Source: AMsMyM6ASsVMnXRj7BGCE+XsYeiyRdqfGCW4D/w7QesCAh5x6w9k97okW5QkPTlkLZADWxPYvplZtA== X-Received: by 2002:a05:600c:ad0:b0:3cf:692a:7f66 with SMTP id c16-20020a05600c0ad000b003cf692a7f66mr35280908wmr.200.1667903680649; Tue, 08 Nov 2022 02:34:40 -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.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 02:34:40 -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 1/2] vringh: fix range used in iotlb_translate() Date: Tue, 8 Nov 2022 11:34:36 +0100 Message-Id: <20221108103437.105327-2-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 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") Signed-off-by: Stefano Garzarella Acked-by: Jason Wang --- 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 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: 13036114 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 68AE4C4332F for ; Tue, 8 Nov 2022 10:35:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233921AbiKHKfs (ORCPT ); Tue, 8 Nov 2022 05:35:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233919AbiKHKfp (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.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BCEB209AA 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-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-9-Q7EIQ-daNp6JkW5iZt__bw-1; Tue, 08 Nov 2022 05:34:43 -0500 X-MC-Unique: Q7EIQ-daNp6JkW5iZt__bw-1 Received: by mail-wm1-f69.google.com with SMTP id bg21-20020a05600c3c9500b003c2acbff422so619460wmb.0 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=WY4J2Mj35odypk6FPblXTK6BcG6ggWcsqJpVS+1Xn5mJrB9Kpv6y7iqgGsqjCqkQfV 4p2IhLwE50fGJdOrV0PgKdFq0ui0CshMLu1xz4EJh2pEhUNx7a/fggA8UUo311DTP5ih tXNyTxDn3akc4LG3ttgL6+HgYjvRERAhMMYRFjtuuuvfSXItdaASo4nKH4Aqo13EV0nV cAn0f9P5vS0ZHTPMFilokaGkhQvy872ae2v3EV0z+1TW+7d8uB+E0O3p4ye/F6Kn9Qfz mEqL39asLd5sFeSUTRGupMres8tXYOFGA1HzDw+7dzdbSY+tXTwkNqZ48FvQS64yEBct ETrQ== X-Gm-Message-State: ACrzQf0C3Q7pX2zEyLi4a3C2Oryq9lqvoyNZUBLvnKAXazzth4ta5DaA OieKR+p8Sb1cTp32SSWOb5u8l4yJlVlbBBGQGmijUTeUcSKXYVIXBUGVLrNrb2Ie138NLawMjuE Ogo0JEvedXTME3dew X-Received: by 2002:adf:f303:0:b0:236:d1c0:79dc with SMTP id i3-20020adff303000000b00236d1c079dcmr29615251wro.695.1667903682488; Tue, 08 Nov 2022 02:34:42 -0800 (PST) X-Google-Smtp-Source: AMsMyM60F4oRwRyS4YKIr5SpakIIdGyqUKYKutX+9xZI1DBbeFzrSYNiUGX7Pq6GFACc6ESaUV3XiQ== 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 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: 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;