From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id EC65041E9F; Wed, 15 Mar 2023 12:32:08 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7ACA740A7A; Wed, 15 Mar 2023 12:32:08 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 42AF840141 for ; Wed, 15 Mar 2023 12:32:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678879925; 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=FhAW0H9sZiloVJnXHuvDQ+ux8W3lXyQF0+YbOPx+SSw=; b=cQMKoAaBCaG00Clq9IXGYaD6dwX4/un1hOHvKZLN+aKb7t3OP9K7qJYMy1PeCvXGT7sb6M f6e+t2XFIwNjsYn55nfJUd46MRm0RaVVA8tFkbvm+cHbwrsi+/o7PI6Lvj/tut/gBj65uC tr8mcp81p4oXZOfYaaKH3ATfeRSlINU= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-617-oHTr-krJM4qAL3saLoefEg-1; Wed, 15 Mar 2023 07:32:04 -0400 X-MC-Unique: oHTr-krJM4qAL3saLoefEg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0DB511C07581; Wed, 15 Mar 2023 11:32:04 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id D903D492B00; Wed, 15 Mar 2023 11:32:02 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, mkp@redhat.com, chenbo.xia@intel.com, david.marchand@redhat.com Cc: Maxime Coquelin Subject: [PATCH] vhost: fix madvise IOTLB entries pages overlap check Date: Wed, 15 Mar 2023 12:31:58 +0100 Message-Id: <20230315113158.442632-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org At removal time, when testing whether the IOTLB entry has shared pages with the previous and next entries in the cache, it checks whether the start address of the entry to be removed is on the same page as the start address of the next entry in the cache. This is not correct, as an entry could cover several page so the end address of the entry to be remove should be used. This patch address this issue. Fixes: dea092d0addb ("vhost: fix madvise arguments alignment") Signed-off-by: Maxime Coquelin --- lib/vhost/iotlb.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/vhost/iotlb.c b/lib/vhost/iotlb.c index 11785392ac..bfa04a0439 100644 --- a/lib/vhost/iotlb.c +++ b/lib/vhost/iotlb.c @@ -182,8 +182,8 @@ vhost_user_iotlb_cache_random_evict(struct virtio_net *dev, struct vhost_virtque (node->uaddr & mask) != (prev_node->uaddr & mask)) { next_node = RTE_TAILQ_NEXT(node, next); /* Don't disable coredump if the next node is in the same page */ - if (next_node == NULL || - (node->uaddr & mask) != (next_node->uaddr & mask)) + if (next_node == NULL || ((node->uaddr + node->size) & mask) != + (next_node->uaddr & mask)) mem_set_dump((void *)(uintptr_t)node->uaddr, node->size, false, alignment); } @@ -287,8 +287,8 @@ vhost_user_iotlb_cache_remove(struct virtio_net *dev, struct vhost_virtqueue *vq (node->uaddr & mask) != (prev_node->uaddr & mask)) { next_node = RTE_TAILQ_NEXT(node, next); /* Don't disable coredump if the next node is in the same page */ - if (next_node == NULL || - (node->uaddr & mask) != (next_node->uaddr & mask)) + if (next_node == NULL || ((node->uaddr + node->size) & mask) != + (next_node->uaddr & mask)) mem_set_dump((void *)(uintptr_t)node->uaddr, node->size, false, alignment); } -- 2.39.2