From patchwork Tue Mar 5 11:18:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 13582162 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 310F3C54E41 for ; Tue, 5 Mar 2024 11:19:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B765B6B00A3; Tue, 5 Mar 2024 06:19:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AFD736B00DD; Tue, 5 Mar 2024 06:19:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 926706B00DF; Tue, 5 Mar 2024 06:19:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 7CE736B00A3 for ; Tue, 5 Mar 2024 06:19:48 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 5502AA0DA6 for ; Tue, 5 Mar 2024 11:19:48 +0000 (UTC) X-FDA: 81862740456.16.9065418 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf15.hostedemail.com (Postfix) with ESMTP id D2308A001D for ; Tue, 5 Mar 2024 11:19:46 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=kbsMf9DJ; spf=pass (imf15.hostedemail.com: domain of leon@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=leon@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709637586; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=CTugSmgLwJgDA9ipI5mnVckl7fOXK4aUNX016/UL5M0=; b=NRkBSNroGy1iJJ4m2leHkkYVn9szchzpaE8qrQ0nh7uLPOsVOSdE5ddjfGNilFJ1lkUO73 pqLbEugH1eK12iSFBjjTKuETCqxWCEpD8+oW+KAF9wT1xNsv1Gh3cXrGNwvuyoTEXrarvJ PySMCpnfOetVleDwnF8E39pN3Jb32PU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709637586; a=rsa-sha256; cv=none; b=t3QXOazFPbmbg+eBTX3yV5QLkSieFbt3fPQRaR/FhvahW6UAMouE3QMbh3Zt7qTMR98Agz GwhXgiAo7XPb1UeRiInBgiAk2TFb1v9QH7/Rx+EyYJeD8Isd4xSkuf6JX3rvQ2oAcSBBLH KORM9/+RQrChlOOlDgzYH1SEPmr6PLk= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=kbsMf9DJ; spf=pass (imf15.hostedemail.com: domain of leon@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=leon@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 0AC4D613B3; Tue, 5 Mar 2024 11:19:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 980C4C433C7; Tue, 5 Mar 2024 11:19:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709637585; bh=WBfM8ZvY1JfgPv87VMT5XwFqFK1pOKYXqtZNVa4/Kmg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kbsMf9DJdoige6tJLshijtU8Kah4MBtJADzS0kuryTgbhA9Aurzvs2NHr9PC2Sxdk aWMyTQA9cpqJ9BZzF2xzaOYOiC9rT0wRI5JB4o6/Bd19PA6j8h5et4xH1Ybnssusxv ofz4zG1sNo7UQbdSRgvuO4DR++wHk5xf9qd7pP3BUoMIXhUyuiKKBSd7cguagJOd5c 2If7Dk3oa46O/Qqcblo2jX+SAbFRpj9bAAcaayM0w5quJX8gW8FLX3ZCbV05DbU0rN OkYxpZQZxj/lFGRv3G3vvw9fuADM/7YcjA+xBr5fSWKCwCH4P1a8ifmHULe6ES3OET IDThNn5c/6MLg== From: Leon Romanovsky To: Christoph Hellwig , Robin Murphy , Marek Szyprowski , Joerg Roedel , Will Deacon , Jason Gunthorpe , Chaitanya Kulkarni Cc: Leon Romanovsky , Jonathan Corbet , Jens Axboe , Keith Busch , Sagi Grimberg , Yishai Hadas , Shameer Kolothum , Kevin Tian , Alex Williamson , =?utf-8?b?SsOpcsO0bWUgR2xp?= =?utf-8?b?c3Nl?= , Andrew Morton , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-rdma@vger.kernel.org, iommu@lists.linux.dev, linux-nvme@lists.infradead.org, kvm@vger.kernel.org, linux-mm@kvack.org, Bart Van Assche , Damien Le Moal , Amir Goldstein , "josef@toxicpanda.com" , "Martin K. Petersen" , "daniel@iogearbox.net" , Dan Williams , "jack@suse.com" , Zhu Yanjun Subject: [RFC RESEND 13/16] vfio/mlx5: Explicitly store page list Date: Tue, 5 Mar 2024 13:18:44 +0200 Message-ID: <1d0ca7408af6e5f0bb09baffd021bc72287e5ed8.1709635535.git.leon@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: D2308A001D X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: dws3jbttp4w4a1qd5ch6mcah8ey4ph66 X-HE-Tag: 1709637586-876119 X-HE-Meta: U2FsdGVkX1805HrXF6OviXreiG4BjDO2YIOBwtY0qVmAly5hXCBW6MidHJdw7lWRNyN5A6JExXTquMbr0oTlskLshX056snM/185VatL5XEryHXDZEGe4+Mj6FDTJP9cuIBh70FJEzdED+/Xmf0hqI5pD6FCkffdl7rqzBdPAVun9HA+lkuPK9iYGGOirf0nr6L2iL59Q1YcJ12bXMbRPFymwo8nhdyhAiMXJC1lGIIjD/yCrU3HuQlip9AjKJFsZYY+bwk7Bmgy5m7ggu1hqbadvoy3xiiEtn/UY3PPjYlG9//G/mzHd7k88L+TE3d5gpKFl3OfkjfhErz5PczU2KGnDpnut+jnL5BKZX4qJuGFtPTTHB/soBxlMbsSdOa1PaIJ+kCUFTPlSkqhzFVbxKPUaHt6BVApr9MuxVWYRa1KKDa9qzt6E9qRPv/+X50CpxHDkZm7kjBG9oVP/Hu0H2pIefF/yf+LjQdYB6hEVR+8l9DuULwkEsCxEIbgJ7rQiF0UbQ0Zcnrj8002kzkKLlCEwAxNBeT5lqdMK9YfI5IuUyRnjSmMST3SHw1apGOO5djIgl5Y7r/Trz9Da9OMOvM1FGT4C2OXpAo7Oil2wuf4o8Rhaoh6bu13DkruhUiMfM5OijIegGjI0J0MOEH7IZXphVrJbRAGi2pLkNwLZguV8YtaEUB6ri/H2LVAjJmJpot6xlQWghtj7zuUeazGQ6CJMWB8okwb4BNutidcdhig5me7f///KzEmbyrgl5WlLeeP4WF86J7t3NyW1GgTv8JNnYw5F6Vr4kvadpM3HyUQWF9tHH4sA7WPLFDTCgjReRXFYXD/t7tPTiz79LBG8LVtM/7BHB0Y9sfYSjbE0U8MF8iWVh9faJIPz2psWXo9HZqk9rq3LmT4s2sDyKDsIYQmEYARbWhZG7nHaz1O5OxHWOmXm6TqYZB2mAf9UyL9HkIN8x49HK9w7FfV0qz TZvNKxl0 oFx3i X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Leon Romanovsky As a preparation to removal scatter-gather table and unifying receive and send list, explicitly store page list. Signed-off-by: Leon Romanovsky --- drivers/vfio/pci/mlx5/cmd.c | 1 + drivers/vfio/pci/mlx5/cmd.h | 1 + drivers/vfio/pci/mlx5/main.c | 35 +++++++++++++++++------------------ 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/drivers/vfio/pci/mlx5/cmd.c b/drivers/vfio/pci/mlx5/cmd.c index 44762980fcb9..5e2103042d9b 100644 --- a/drivers/vfio/pci/mlx5/cmd.c +++ b/drivers/vfio/pci/mlx5/cmd.c @@ -411,6 +411,7 @@ void mlx5vf_free_data_buffer(struct mlx5_vhca_data_buffer *buf) for_each_sgtable_page(&buf->table.sgt, &sg_iter, 0) __free_page(sg_page_iter_page(&sg_iter)); sg_free_append_table(&buf->table); + kvfree(buf->page_list); kfree(buf); } diff --git a/drivers/vfio/pci/mlx5/cmd.h b/drivers/vfio/pci/mlx5/cmd.h index 83728c0669e7..815fcb54494d 100644 --- a/drivers/vfio/pci/mlx5/cmd.h +++ b/drivers/vfio/pci/mlx5/cmd.h @@ -57,6 +57,7 @@ struct mlx5_vf_migration_header { }; struct mlx5_vhca_data_buffer { + struct page **page_list; struct sg_append_table table; loff_t start_pos; u64 length; diff --git a/drivers/vfio/pci/mlx5/main.c b/drivers/vfio/pci/mlx5/main.c index b11b1c27d284..7ffe24693a55 100644 --- a/drivers/vfio/pci/mlx5/main.c +++ b/drivers/vfio/pci/mlx5/main.c @@ -69,44 +69,43 @@ int mlx5vf_add_migration_pages(struct mlx5_vhca_data_buffer *buf, unsigned int npages) { unsigned int to_alloc = npages; + size_t old_size, new_size; struct page **page_list; unsigned long filled; unsigned int to_fill; int ret; - to_fill = min_t(unsigned int, npages, PAGE_SIZE / sizeof(*page_list)); - page_list = kvzalloc(to_fill * sizeof(*page_list), GFP_KERNEL_ACCOUNT); + to_fill = min_t(unsigned int, npages, + PAGE_SIZE / sizeof(*buf->page_list)); + old_size = buf->npages * sizeof(*buf->page_list); + new_size = old_size + to_fill * sizeof(*buf->page_list); + page_list = kvrealloc(buf->page_list, old_size, new_size, + GFP_KERNEL_ACCOUNT | __GFP_ZERO); if (!page_list) return -ENOMEM; + buf->page_list = page_list; + do { filled = alloc_pages_bulk_array(GFP_KERNEL_ACCOUNT, to_fill, - page_list); - if (!filled) { - ret = -ENOMEM; - goto err; - } + buf->page_list + buf->npages); + if (!filled) + return -ENOMEM; + to_alloc -= filled; ret = sg_alloc_append_table_from_pages( - &buf->table, page_list, filled, 0, + &buf->table, buf->page_list + buf->npages, filled, 0, filled << PAGE_SHIFT, UINT_MAX, SG_MAX_SINGLE_ALLOC, GFP_KERNEL_ACCOUNT); - if (ret) - goto err; + return ret; + buf->npages += filled; - /* clean input for another bulk allocation */ - memset(page_list, 0, filled * sizeof(*page_list)); to_fill = min_t(unsigned int, to_alloc, - PAGE_SIZE / sizeof(*page_list)); + PAGE_SIZE / sizeof(*buf->page_list)); } while (to_alloc > 0); - kvfree(page_list); return 0; - -err: - kvfree(page_list); - return ret; } static void mlx5vf_disable_fd(struct mlx5_vf_migration_file *migf)