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 B6E9842970; Mon, 17 Apr 2023 21:39:52 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8EC99410E4; Mon, 17 Apr 2023 21:39:52 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 43D7640DFB for ; Mon, 17 Apr 2023 21:39:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681760390; 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=FkXvPaJaH6CU3vZjf/bUWbXsZCeOs4o3L3SkoUvcEEk=; b=fza2NiBPnI96fVNvgSVSjGVnWaOFaaDsW8NuEhnefzoHljCQ4PiwRapkA/o18GP0B5P0CN 5SJggTDT+PnsF95V/fBLBZzddvZsaYr+QrNYiVDkgnLkMe1DGAPaOrbp5juiToOFx/t9fh dUaGEey7z4Ghwd4C99qNS2VMh7q1Iow= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-282-UtHG1XlaPKOEZ7sInE2GnQ-1; Mon, 17 Apr 2023 15:39:49 -0400 X-MC-Unique: UtHG1XlaPKOEZ7sInE2GnQ-1 Received: by mail-ed1-f70.google.com with SMTP id v10-20020a50d08a000000b0050675b95c83so6757095edd.4 for ; Mon, 17 Apr 2023 12:39:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681760388; x=1684352388; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FkXvPaJaH6CU3vZjf/bUWbXsZCeOs4o3L3SkoUvcEEk=; b=SLz4jI2F23rWoM1zU5dke4070IGeOQNtwtiAU2Nk8OyuNluMObuhbM93DpMl2EFB4g gBakkgawcnPdB3IWVt/hEsyCs3/mxi2MHaH2iD28bl6/vWvJKZ1mCy3lccRoSWvT6Umy o+qEflFWo3HlUmMBB2yTd6HBrRnq/A54rURgsCKCxGSVYONaNZxDFvIg/4HV+o+yaKCq 5N7Ym0EZbNBMvId+5nvC2vFKy8q9GaXTXthNmBZidsxSi9GBdOU0lCiEorvvcS1pSJQN buMjMxYHOfjhzABmGb2PreARPPMaIcPQQa+vXckbj1/cVzUDviHXyhYnTYxfA1qXyu82 oETQ== X-Gm-Message-State: AAQBX9euZ5lf8971EAj2pPQp08C/gFIlbWv1m/yiE5Pz8nIdiQzWtpIV NjubFJgegOuJjCaJFbVnCV242dpVnnHM26QXJdQ5j2OFE6ovr5jN9YgNfNj5b8BwuXd6jszB4+L YMnnv/UEnZscoG/mfWrWXqvkPr+8YTg== X-Received: by 2002:a17:907:77ce:b0:94f:3d8:3d80 with SMTP id kz14-20020a17090777ce00b0094f03d83d80mr8450192ejc.11.1681760388109; Mon, 17 Apr 2023 12:39:48 -0700 (PDT) X-Google-Smtp-Source: AKy350YqiVG5xa2hMz7+GjRTRyJ8McdT6xIS6NyyLuxysl6LexFY5QJ8obV7g4k/62I9H12LHcDJSReDqi5QY8kPqpU= X-Received: by 2002:a17:907:77ce:b0:94f:3d8:3d80 with SMTP id kz14-20020a17090777ce00b0094f03d83d80mr8450172ejc.11.1681760387867; Mon, 17 Apr 2023 12:39:47 -0700 (PDT) MIME-Version: 1.0 References: <20230331154259.1447831-1-maxime.coquelin@redhat.com> <20230331154259.1447831-6-maxime.coquelin@redhat.com> In-Reply-To: <20230331154259.1447831-6-maxime.coquelin@redhat.com> From: Mike Pattrick Date: Mon, 17 Apr 2023 15:39:36 -0400 Message-ID: Subject: Re: [RFC 05/27] vhost: add helper for IOTLB entries shared page check To: Maxime Coquelin Cc: dev@dpdk.org, david.marchand@redhat.com, chenbo.xia@intel.com, fbl@redhat.com, jasowang@redhat.com, cunming.liang@intel.com, xieyongji@bytedance.com, echaudro@redhat.com, eperezma@redhat.com, amorenoz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 Hi Maxime, On Fri, Mar 31, 2023 at 11:43=E2=80=AFAM Maxime Coquelin wrote: > > This patch introduces a helper to check whether two IOTLB > entries share a page. > > Signed-off-by: Maxime Coquelin > --- > lib/vhost/iotlb.c | 25 ++++++++++++++++++++----- > 1 file changed, 20 insertions(+), 5 deletions(-) > > diff --git a/lib/vhost/iotlb.c b/lib/vhost/iotlb.c > index e8f1cb661e..d919f74704 100644 > --- a/lib/vhost/iotlb.c > +++ b/lib/vhost/iotlb.c > @@ -23,6 +23,23 @@ struct vhost_iotlb_entry { > > #define IOTLB_CACHE_SIZE 2048 > > +static bool > +vhost_user_iotlb_share_page(struct vhost_iotlb_entry *a, struct vhost_io= tlb_entry *b, > + uint64_t align) > +{ > + uint64_t a_end, b_start; > + > + if (a =3D=3D NULL || b =3D=3D NULL) > + return false; > + > + /* Assumes entry a lower than entry b */ > + RTE_ASSERT(a->uaddr < b->uaddr); > + a_end =3D RTE_ALIGN_CEIL(a->uaddr + a->size, align); > + b_start =3D RTE_ALIGN_FLOOR(b->uaddr, align); > + > + return a_end > b_start; This may be a very minor detail, but it might improve readability if the a_end calculation used addr + size - 1 and the return conditional used >=3D. Cheers, M > +} > + > static void > vhost_user_iotlb_set_dump(struct virtio_net *dev, struct vhost_iotlb_ent= ry *node) > { > @@ -37,16 +54,14 @@ static void > vhost_user_iotlb_clear_dump(struct virtio_net *dev, struct vhost_iotlb_e= ntry *node, > struct vhost_iotlb_entry *prev, struct vhost_iotlb_entry = *next) > { > - uint64_t align, mask; > + uint64_t align; > > align =3D hua_to_alignment(dev->mem, (void *)(uintptr_t)node->uad= dr); > - mask =3D ~(align - 1); > > /* Don't disable coredump if the previous node is in the same pag= e */ > - if (prev =3D=3D NULL || (node->uaddr & mask) !=3D ((prev->uaddr += prev->size - 1) & mask)) { > + if (!vhost_user_iotlb_share_page(prev, node, align)) { > /* Don't disable coredump if the next node is in the same= page */ > - if (next =3D=3D NULL || > - ((node->uaddr + node->size - 1) & mask) != =3D (next->uaddr & mask)) > + if (!vhost_user_iotlb_share_page(node, next, align)) > mem_set_dump((void *)(uintptr_t)node->uaddr, node= ->size, false, align); > } > } > -- > 2.39.2 >