linux-coco.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: "GuoRui.Yu" <GuoRui.Yu@linux.alibaba.com>
To: linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org,
	konrad.wilk@oracle.com, linux-coco@lists.linux.dev
Cc: GuoRui.Yu@linux.alibaba.com, robin.murphy@arm.com
Subject: [PATCH 4/4] cc-swiotlb: Allow set swiotlb watermark from cmdline
Date: Sat, 28 Jan 2023 16:32:54 +0800	[thread overview]
Message-ID: <20230128083254.86012-5-GuoRui.Yu@linux.alibaba.com> (raw)
In-Reply-To: <20230128083254.86012-1-GuoRui.Yu@linux.alibaba.com>

Signed-off-by: GuoRui.Yu <GuoRui.Yu@linux.alibaba.com>
---
 .../admin-guide/kernel-parameters.txt         | 11 ++++++
 kernel/dma/cc-swiotlb.c                       | 34 ++++++++++++++++++-
 2 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 6cfa6e3996cf..ad510e392998 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -6090,6 +6090,17 @@
 			         wouldn't be automatically used by the kernel
 			noforce -- Never use bounce buffers (for debugging)
 
+	cc_swiotlb=	[X86]
+			Format: { [<int>, <int>, <int>, <int>]| force ]}
+			Set the swiotlb TLB buffer initial size for Confidential Computing like
+			TDX and SEV-SNP.
+			<int> -- Number of I/O TLB of 256 bytes
+			<int> -- Number of I/O TLB of 4 KiB
+			<int> -- Number of I/O TLB of 64 KiB
+			<int> -- Number of I/O TLB of 256 KiB
+			force -- force using of cc bounce buffers even if they
+			         wouldn't be automatically used by the kernel (for debugging)
+
 	switches=	[HW,M68k]
 
 	sysctl.*=	[KNL]
diff --git a/kernel/dma/cc-swiotlb.c b/kernel/dma/cc-swiotlb.c
index e85d3ce2272f..ff1cc52189b9 100644
--- a/kernel/dma/cc-swiotlb.c
+++ b/kernel/dma/cc-swiotlb.c
@@ -52,6 +52,32 @@ enum SLOT_SIZE {
 
 const unsigned int SLOT_SIZES[NR_OF_SIZES] = {512, 2048, 4096, 16 * 1024, 512 * 1024};
 unsigned int WATERMARK_SLOT_SIZE[NR_OF_SIZES] = {256, 16384, 8192, 1024, 32};
+static bool swiotlb_force_bounce = false;
+
+static int __init
+setup_io_tlb_watermark(char *str)
+{
+	int i;
+	size_t size;
+
+	for (i = 0; i < NR_OF_SIZES; i++) {
+		if (isdigit(*str)) {
+			size = simple_strtoul(str, &str, 0);
+			WATERMARK_SLOT_SIZE[i] = size;
+
+			if (*str == ',')
+				++str;
+		}
+		else
+			break;
+	}
+
+	if (!strcmp(str, "force"))
+		swiotlb_force_bounce = true;
+
+	return 0;
+}
+early_param("cc_swiotlb", setup_io_tlb_watermark);
 
 struct slot_terrace {
 	struct list_head slots_by_size[NR_OF_SIZES];
@@ -330,6 +356,7 @@ static void cc_populate_pages(void)
 	size_t i, j, k;
 	const size_t max_bytes_per_alloc = (MAX_ORDER_NR_PAGES << PAGE_SHIFT);
 	size_t remain_alloc_size, rounds, round_size, round_slot_nr;
+	size_t size = 0;
 
 	for (i = 0; i < NR_OF_SIZES; i++) {
 		if (atomic_read(&terrace.free_count_by_size[i]) > WATERMARK_SLOT_SIZE[i])
@@ -377,6 +404,11 @@ static void cc_populate_pages(void)
 			spin_unlock_irqrestore(&terrace.lock_by_size[i], flags);
 		}
 	}
+
+	for (i = 0; i < NR_OF_SIZES; i++) {
+		size += (size_t)atomic_read(&terrace.total_count_by_size[i]) * SLOT_SIZES[i];
+	}
+	pr_info("bounce buffer size adjusted to %luMB", size >> 20);
 }
 
 static int kccd(void *p)
@@ -437,7 +469,7 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 		return;
 	}
 
-	io_tlb_default_mem.force_bounce = cc_platform_has(CC_ATTR_MEM_ENCRYPT);
+	io_tlb_default_mem.force_bounce = cc_platform_has(CC_ATTR_MEM_ENCRYPT) || swiotlb_force_bounce;
 
 	xa_init_flags(io_tlb_default_mem.mapping, 0);
 
-- 
2.31.1


  parent reply	other threads:[~2023-01-28  8:48 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-28  8:32 [RFC] swiotlb: Add a new cc-swiotlb implementation for Confidential VMs GuoRui.Yu
2023-01-28  8:32 ` [PATCH 1/4] swiotlb: Split common code from swiotlb.{c,h} GuoRui.Yu
2023-01-28  8:32 ` [PATCH 2/4] swiotlb: Add a new cc-swiotlb implementation for Confidential VMs GuoRui.Yu
2023-01-28 12:03   ` kernel test robot
2023-01-28 16:41   ` Randy Dunlap
2023-01-29  1:54     ` Guorui Yu
2023-01-29 16:58   ` Andi Kleen
2023-01-30  2:25     ` Guorui Yu
2023-01-30  6:46       ` Andi Kleen
2023-01-30 13:45         ` Guorui Yu
2023-01-31 17:16           ` Andi Kleen
2023-02-01  2:08             ` Guorui Yu
2023-01-28  8:32 ` [PATCH 3/4] swiotlb: Add tracepoint swiotlb_unbounced GuoRui.Yu
2023-01-28  8:32 ` GuoRui.Yu [this message]
2023-01-28 20:19   ` [PATCH 4/4] cc-swiotlb: Allow set swiotlb watermark from cmdline kernel test robot
2023-01-28  9:03 ` [RFC] swiotlb: Add a new cc-swiotlb implementation for Confidential VMs Guorui Yu
2023-01-30  6:54   ` Christoph Hellwig
2023-01-30 13:03 ` Robin Murphy
2023-01-30 14:37   ` Guorui Yu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230128083254.86012-5-GuoRui.Yu@linux.alibaba.com \
    --to=guorui.yu@linux.alibaba.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=konrad.wilk@oracle.com \
    --cc=linux-coco@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robin.murphy@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).