From: Guorui Yu <GuoRui.Yu@linux.alibaba.com>
To: Andi Kleen <ak@linux.intel.com>,
linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org,
konrad.wilk@oracle.com, linux-coco@lists.linux.dev
Cc: robin.murphy@arm.com
Subject: Re: [PATCH 2/4] swiotlb: Add a new cc-swiotlb implementation for Confidential VMs
Date: Mon, 30 Jan 2023 21:45:22 +0800 [thread overview]
Message-ID: <ccc21265-07aa-cd82-f679-4fee9c51df47@linux.alibaba.com> (raw)
In-Reply-To: <09a56915-7ce2-b70c-33ec-3a8767269637@linux.intel.com>
Hi Andi,
在 2023/1/30 14:46, Andi Kleen 写道:
>
>> I try to solve this problem by creating a new kernel thread, "kccd",
>> to populate the TLB buffer in the backgroud.
>>
>> Specifically,
>> 1. A new kernel thread is created with the help of "arch_initcall",
>> and this kthread is responsible for memory allocation and setting
>> memory attributes (private or shared);
>> 2. The "swiotlb_tbl_map_single" routine only use the spin_lock
>> protected TLB buffers pre-allocated by the kthread;
>> a) which actually includes ONE memory allocation brought by xarray
>> insertion "__xa_insert__".
>
> That already seems dangerous with all the usual problems of memory
> allocations in IO paths. Normally code at least uses a mempool to avoid
> the worst dead lock potential.
>
The __xa_insert__ is called with GFP_NOWAIT (GFP_ATOMIC & ~__GFP_HIGH),
and I will try to dig into this to check if there is any chance to have
the deadlock.
I also tried my best to test this piece of code, and no issue have been
found in the case of a maximum of 700,000 IOPS.
Thanks for your advices from this point, since I have not notice such
possibility.
>> 3. After each allocation, the water level of TLB resources will be
>> checked. If the current TLB resources are found to be lower than the
>> preset value (half of the watermark), the kthread will be awakened to
>> fill them.
>> 4. The TLB buffer allocation in the kthread is batched to
>> "(MAX_ORDER_NR_PAGES << PAGE_SHIFT)" to reduce the holding time of
>> spin_lock and number of calls to set_memory_decrypted().
>
> Okay, but does this guarantee that it will never run out of memory?
>
> It seems difficult to make such guarantees. What happens for example if
> the background thread gets starved by something higher priority?
>
No, this cannot guarantee we always have sufficient TLB caches, so we
can also have a "No memory for cc-swiotlb buffer" warning.
But I want to emphasize that in this case, the current implementation is
no worse than the legacy implementation. Moreover, dynamic TLB
allocation is more suitable for situations where more disks/network
devices will be hotplugged, in which case you cannot pre-set a
reasonable value.
> Or if the allocators have such high bandwidth that they can overwhelm
> any reasonable background thread.
>
> -Andi
>
Sincerely,
Guorui
next prev parent reply other threads:[~2023-01-30 13:45 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-28 8:32 [RFC] " 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 [this message]
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 ` [PATCH 4/4] cc-swiotlb: Allow set swiotlb watermark from cmdline GuoRui.Yu
2023-01-28 20:19 ` 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=ccc21265-07aa-cd82-f679-4fee9c51df47@linux.alibaba.com \
--to=guorui.yu@linux.alibaba.com \
--cc=ak@linux.intel.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
Powered by JetHome