From: Dongli Zhang <dongli.zhang@oracle.com>
To: iommu@lists.linux-foundation.org, xen-devel@lists.xenproject.org,
x86@kernel.org, linuxppc-dev@lists.ozlabs.org,
virtualization@lists.linux-foundation.org
Cc: jgross@suse.com, sstabellini@kernel.org, mst@redhat.com,
konrad.wilk@oracle.com, mpe@ellerman.id.au,
dave.hansen@linux.intel.com, joe.jin@oracle.com,
linux-kernel@vger.kernel.org, hch@infradead.org,
mingo@redhat.com, bp@alien8.de, tglx@linutronix.de,
m.szyprowski@samsung.com
Subject: [PATCH RFC v1 4/7] swiotlb: to implement io_tlb_high_mem
Date: Wed, 8 Jun 2022 17:55:50 -0700 [thread overview]
Message-ID: <20220609005553.30954-5-dongli.zhang@oracle.com> (raw)
In-Reply-To: <20220609005553.30954-1-dongli.zhang@oracle.com>
This patch is to implement the extra 'io_tlb_high_mem'. In the future, the
device drivers may choose to use either 'io_tlb_default_mem' or
'io_tlb_high_mem' as dev->dma_io_tlb_mem.
The highmem buffer is regarded as active if
(high_nslabs && io_tlb_high_mem.nslabs) returns true.
Cc: Konrad Wilk <konrad.wilk@oracle.com>
Cc: Joe Jin <joe.jin@oracle.com>
Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
---
arch/powerpc/kernel/dma-swiotlb.c | 8 ++-
arch/x86/kernel/pci-dma.c | 5 +-
include/linux/swiotlb.h | 2 +-
kernel/dma/swiotlb.c | 103 +++++++++++++++++++++---------
4 files changed, 84 insertions(+), 34 deletions(-)
diff --git a/arch/powerpc/kernel/dma-swiotlb.c b/arch/powerpc/kernel/dma-swiotlb.c
index ba256c37bcc0..f18694881264 100644
--- a/arch/powerpc/kernel/dma-swiotlb.c
+++ b/arch/powerpc/kernel/dma-swiotlb.c
@@ -20,9 +20,11 @@ void __init swiotlb_detect_4g(void)
static int __init check_swiotlb_enabled(void)
{
- if (ppc_swiotlb_enable)
- swiotlb_print_info();
- else
+ if (ppc_swiotlb_enable) {
+ swiotlb_print_info(false);
+ if (swiotlb_high_active())
+ swiotlb_print_info(true);
+ } else
swiotlb_exit();
return 0;
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index 30bbe4abb5d6..1504b349b312 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -196,7 +196,10 @@ static int __init pci_iommu_init(void)
/* An IOMMU turned us off. */
if (x86_swiotlb_enable) {
pr_info("PCI-DMA: Using software bounce buffering for IO (SWIOTLB)\n");
- swiotlb_print_info();
+
+ swiotlb_print_info(false);
+ if (swiotlb_high_active())
+ swiotlb_print_info(true);
} else {
swiotlb_exit();
}
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index e61c074c55eb..8196bf961aab 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -166,7 +166,7 @@ static inline void swiotlb_adjust_size(unsigned long size)
#endif /* CONFIG_SWIOTLB */
extern bool swiotlb_high_active(void);
-extern void swiotlb_print_info(void);
+extern void swiotlb_print_info(bool high);
#ifdef CONFIG_DMA_RESTRICTED_POOL
struct page *swiotlb_alloc(struct device *dev, size_t size);
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 7988883ca7f9..ff82b281ce01 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -101,6 +101,21 @@ setup_io_tlb_npages(char *str)
}
early_param("swiotlb", setup_io_tlb_npages);
+static struct io_tlb_mem *io_tlb_mem_get(bool high)
+{
+ return high ? &io_tlb_high_mem : &io_tlb_default_mem;
+}
+
+static unsigned long nslabs_get(bool high)
+{
+ return high ? high_nslabs : default_nslabs;
+}
+
+static char *swiotlb_name_get(bool high)
+{
+ return high ? "high" : "default";
+}
+
bool swiotlb_high_active(void)
{
return high_nslabs && io_tlb_high_mem.nslabs;
@@ -133,17 +148,18 @@ void __init swiotlb_adjust_size(unsigned long size)
pr_info("SWIOTLB bounce buffer size adjusted to %luMB", size >> 20);
}
-void swiotlb_print_info(void)
+void swiotlb_print_info(bool high)
{
- struct io_tlb_mem *mem = &io_tlb_default_mem;
+ struct io_tlb_mem *mem = io_tlb_mem_get(high);
if (!mem->nslabs) {
pr_warn("No low mem\n");
return;
}
- pr_info("mapped [mem %pa-%pa] (%luMB)\n", &mem->start, &mem->end,
- (mem->nslabs << IO_TLB_SHIFT) >> 20);
+ pr_info("%s mapped [mem %pa-%pa] (%luMB)\n",
+ swiotlb_name_get(high), &mem->start, &mem->end,
+ (mem->nslabs << IO_TLB_SHIFT) >> 20);
}
static inline unsigned long io_tlb_offset(unsigned long val)
@@ -184,15 +200,9 @@ static void *swiotlb_mem_remap(struct io_tlb_mem *mem, unsigned long bytes)
}
#endif
-/*
- * Early SWIOTLB allocation may be too early to allow an architecture to
- * perform the desired operations. This function allows the architecture to
- * call SWIOTLB when the operations are possible. It needs to be called
- * before the SWIOTLB memory is used.
- */
-void __init swiotlb_update_mem_attributes(void)
+static void __init __swiotlb_update_mem_attributes(bool high)
{
- struct io_tlb_mem *mem = &io_tlb_default_mem;
+ struct io_tlb_mem *mem = io_tlb_mem_get(high);
void *vaddr;
unsigned long bytes;
@@ -207,6 +217,19 @@ void __init swiotlb_update_mem_attributes(void)
mem->vaddr = vaddr;
}
+/*
+ * Early SWIOTLB allocation may be too early to allow an architecture to
+ * perform the desired operations. This function allows the architecture to
+ * call SWIOTLB when the operations are possible. It needs to be called
+ * before the SWIOTLB memory is used.
+ */
+void __init swiotlb_update_mem_attributes(void)
+{
+ __swiotlb_update_mem_attributes(false);
+ if (swiotlb_high_active())
+ __swiotlb_update_mem_attributes(true);
+}
+
static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
unsigned long nslabs, unsigned int flags, bool late_alloc)
{
@@ -240,15 +263,13 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
return;
}
-/*
- * Statically reserve bounce buffer space and initialize bounce buffer data
- * structures for the software IO TLB used to implement the DMA API.
- */
-void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
- int (*remap)(void *tlb, unsigned long nslabs, bool high))
+static void __init
+__swiotlb_init_remap(bool addressing_limit, unsigned int flags,
+ int (*remap)(void *tlb, unsigned long nslabs, bool high),
+ bool high)
{
- struct io_tlb_mem *mem = &io_tlb_default_mem;
- unsigned long nslabs = default_nslabs;
+ struct io_tlb_mem *mem = io_tlb_mem_get(high);
+ unsigned long nslabs = nslabs_get(high);
size_t alloc_size;
size_t bytes;
void *tlb;
@@ -274,7 +295,7 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
return;
}
- if (remap && remap(tlb, nslabs, false) < 0) {
+ if (remap && remap(tlb, nslabs, high) < 0) {
memblock_free(tlb, PAGE_ALIGN(bytes));
nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
@@ -293,7 +314,20 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, flags, false);
if (flags & SWIOTLB_VERBOSE)
- swiotlb_print_info();
+ swiotlb_print_info(high);
+}
+
+/*
+ * Statically reserve bounce buffer space and initialize bounce buffer data
+ * structures for the software IO TLB used to implement the DMA API.
+ */
+void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
+ int (*remap)(void *tlb, unsigned long nslabs, bool high))
+{
+ __swiotlb_init_remap(addressing_limit, flags, remap, false);
+ if (high_nslabs)
+ __swiotlb_init_remap(addressing_limit, flags | SWIOTLB_ANY,
+ remap, true);
}
void __init swiotlb_init(bool addressing_limit, unsigned int flags)
@@ -364,23 +398,20 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask,
(nslabs << IO_TLB_SHIFT) >> PAGE_SHIFT);
swiotlb_init_io_tlb_mem(mem, virt_to_phys(vstart), nslabs, 0, true);
- swiotlb_print_info();
+ swiotlb_print_info(false);
return 0;
}
-void __init swiotlb_exit(void)
+static void __init __swiotlb_exit(bool high)
{
- struct io_tlb_mem *mem = &io_tlb_default_mem;
+ struct io_tlb_mem *mem = io_tlb_mem_get(high);
unsigned long tbl_vaddr;
size_t tbl_size, slots_size;
- if (swiotlb_force_bounce)
- return;
-
if (!mem->nslabs)
return;
- pr_info("tearing down default memory pool\n");
+ pr_info("tearing down %s memory pool\n", swiotlb_name_get(high));
tbl_vaddr = (unsigned long)phys_to_virt(mem->start);
tbl_size = PAGE_ALIGN(mem->end - mem->start);
slots_size = PAGE_ALIGN(array_size(sizeof(*mem->slots), mem->nslabs));
@@ -397,6 +428,16 @@ void __init swiotlb_exit(void)
memset(mem, 0, sizeof(*mem));
}
+void __init swiotlb_exit(void)
+{
+ if (swiotlb_force_bounce)
+ return;
+
+ __swiotlb_exit(false);
+ if (swiotlb_high_active())
+ __swiotlb_exit(true);
+}
+
/*
* Return the offset into a iotlb slot required to keep the device happy.
*/
@@ -786,6 +827,10 @@ static void swiotlb_create_debugfs_files(struct io_tlb_mem *mem,
static int __init __maybe_unused swiotlb_create_default_debugfs(void)
{
swiotlb_create_debugfs_files(&io_tlb_default_mem, "swiotlb");
+
+ if (swiotlb_high_active())
+ swiotlb_create_debugfs_files(&io_tlb_high_mem, "swiotlb-hi");
+
return 0;
}
--
2.17.1
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
next prev parent reply other threads:[~2022-06-09 0:59 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-09 0:55 [PATCH RFC v1 0/7] swiotlb: extra 64-bit buffer for dev->dma_io_tlb_mem Dongli Zhang
2022-06-09 0:55 ` [PATCH RFC v1 1/7] swiotlb: introduce the highmem swiotlb buffer Dongli Zhang
2022-06-09 5:04 ` Christoph Hellwig
2022-06-09 0:55 ` [PATCH RFC v1 2/7] swiotlb: change the signature of remap function Dongli Zhang
2022-06-09 0:55 ` [PATCH RFC v1 3/7] swiotlb-xen: support highmem for xen specific code Dongli Zhang
2022-06-09 5:08 ` Christoph Hellwig
2022-06-09 0:55 ` Dongli Zhang [this message]
2022-06-09 5:05 ` [PATCH RFC v1 4/7] swiotlb: to implement io_tlb_high_mem Christoph Hellwig
2022-06-10 21:56 ` Dongli Zhang
2022-06-13 6:04 ` Christoph Hellwig
2022-06-09 0:55 ` [PATCH RFC v1 5/7] swiotlb: add interface to set dev->dma_io_tlb_mem Dongli Zhang
2022-06-09 5:06 ` Christoph Hellwig
2022-06-09 0:55 ` [PATCH RFC v1 6/7] virtio: use io_tlb_high_mem if it is active Dongli Zhang
2022-06-09 5:07 ` Christoph Hellwig
2022-06-09 0:55 ` [PATCH RFC v1 7/7] swiotlb: fix the slot_addr() overflow Dongli Zhang
2022-06-09 5:07 ` Christoph Hellwig
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=20220609005553.30954-5-dongli.zhang@oracle.com \
--to=dongli.zhang@oracle.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hch@infradead.org \
--cc=iommu@lists.linux-foundation.org \
--cc=jgross@suse.com \
--cc=joe.jin@oracle.com \
--cc=konrad.wilk@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=m.szyprowski@samsung.com \
--cc=mingo@redhat.com \
--cc=mpe@ellerman.id.au \
--cc=mst@redhat.com \
--cc=sstabellini@kernel.org \
--cc=tglx@linutronix.de \
--cc=virtualization@lists.linux-foundation.org \
--cc=x86@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/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).