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 E05F141E9F; Wed, 15 Mar 2023 12:40:39 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D28D140A7A; Wed, 15 Mar 2023 12:40:39 +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 78B8F40141 for ; Wed, 15 Mar 2023 12:40:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678880438; 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=vWj4FfQ0i0DceP4pnWhX/nXrlDdwl9sUmZK9YTA4iDU=; b=U+wbJ3bFREVS0Trt68gQ6BV0w1k1D939kME0bYMCl1vQdey8cbKPUMQmbcyIrRZZ+/76CQ bBaGXhca28JicsbtlnF1oenb1bqZohJ9fTM4KnrVIGmlMFI0xiozTjp0TiaiABeN2mad73 kVbxzLzPh0m0POxcIJs00SEbgXxLqAU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-423-G99BLxuwOiW2F6vol2apxA-1; Wed, 15 Mar 2023 07:40:34 -0400 X-MC-Unique: G99BLxuwOiW2F6vol2apxA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 52AC7101A531; Wed, 15 Mar 2023 11:40:34 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2C0D440C6E67; Wed, 15 Mar 2023 11:40:33 +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 v2] vhost: fix madvise IOTLB entries pages overlap check Date: Wed, 15 Mar 2023 12:40:10 +0100 Message-Id: <20230315114010.444005-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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..3f45bc6061 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 - 1) & 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 - 1) & mask) != + (next_node->uaddr & mask)) mem_set_dump((void *)(uintptr_t)node->uaddr, node->size, false, alignment); } -- 2.39.2