* Re: [PATCH v6 23/43] KVM: selftests: Create gmem fd before "regular" fd when adding memslot
From: Fuad Tabba @ 2026-05-21 12:11 UTC (permalink / raw)
To: ackerleytng
Cc: aik, andrew.jones, binbin.wu, brauner, chao.p.peng, david,
ira.weiny, jmattson, jthoughton, michael.roth, oupton,
pankaj.gupta, qperret, rick.p.edgecombe, rientjes, shivankg,
steven.price, willy, wyihan, yan.y.zhao, forkloop, pratyush,
suzuki.poulose, aneesh.kumar, liam, Paolo Bonzini,
Sean Christopherson, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin, Steven Rostedt,
Masami Hiramatsu, Mathieu Desnoyers, Jonathan Corbet, Shuah Khan,
Shuah Khan, Vishal Annapurve, Andrew Morton, Chris Li,
Kairui Song, Kemeng Shi, Nhat Pham, Baoquan He, Barry Song,
Axel Rasmussen, Yuanchu Xie, Wei Xu, Youngjun Park, Qi Zheng,
Shakeel Butt, Kiryl Shutsemau, Jason Gunthorpe, Vlastimil Babka,
kvm, linux-kernel, linux-trace-kernel, linux-doc, linux-kselftest,
linux-mm, linux-coco
In-Reply-To: <20260507-gmem-inplace-conversion-v6-23-91ab5a8b19a4@google.com>
On Thu, 7 May 2026 at 21:23, Ackerley Tng via B4 Relay
<devnull+ackerleytng.google.com@kernel.org> wrote:
>
> From: Sean Christopherson <seanjc@google.com>
>
> When adding a memslot associated a guest_memfd instance, create/dup the
> guest_memfd before creating the "normal" backing file. This will allow
> dup'ing the gmem fd as the normal fd when guest_memfd supports mmap(),
> i.e. to make guest_memfd the _only_ backing source for the memslot.
>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> Signed-off-by: Ackerley Tng <ackerleytng@google.com>
Reviewed-by: Fuad Tabba <tabba@google.com>
Cheers,
/fuad
> ---
> tools/testing/selftests/kvm/lib/kvm_util.c | 45 +++++++++++++++---------------
> 1 file changed, 23 insertions(+), 22 deletions(-)
>
> diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
> index 2a76eca7029d3..df73b23a4c66a 100644
> --- a/tools/testing/selftests/kvm/lib/kvm_util.c
> +++ b/tools/testing/selftests/kvm/lib/kvm_util.c
> @@ -1054,6 +1054,29 @@ void vm_mem_add(struct kvm_vm *vm, enum vm_mem_backing_src_type src_type,
> if (alignment > 1)
> region->mmap_size += alignment;
>
> + if (flags & KVM_MEM_GUEST_MEMFD) {
> + if (guest_memfd < 0) {
> + u32 guest_memfd_flags = 0;
> +
> + TEST_ASSERT(!guest_memfd_offset,
> + "Offset must be zero when creating new guest_memfd");
> + guest_memfd = vm_create_guest_memfd(vm, mem_size, guest_memfd_flags);
> + } else {
> + /*
> + * Install a unique fd for each memslot so that the fd
> + * can be closed when the region is deleted without
> + * needing to track if the fd is owned by the framework
> + * or by the caller.
> + */
> + guest_memfd = kvm_dup(guest_memfd);
> + }
> +
> + region->region.guest_memfd = guest_memfd;
> + region->region.guest_memfd_offset = guest_memfd_offset;
> + } else {
> + region->region.guest_memfd = -1;
> + }
> +
> region->fd = -1;
> if (backing_src_is_shared(src_type))
> region->fd = kvm_memfd_alloc(region->mmap_size,
> @@ -1083,28 +1106,6 @@ void vm_mem_add(struct kvm_vm *vm, enum vm_mem_backing_src_type src_type,
>
> region->backing_src_type = src_type;
>
> - if (flags & KVM_MEM_GUEST_MEMFD) {
> - if (guest_memfd < 0) {
> - u32 guest_memfd_flags = 0;
> - TEST_ASSERT(!guest_memfd_offset,
> - "Offset must be zero when creating new guest_memfd");
> - guest_memfd = vm_create_guest_memfd(vm, mem_size, guest_memfd_flags);
> - } else {
> - /*
> - * Install a unique fd for each memslot so that the fd
> - * can be closed when the region is deleted without
> - * needing to track if the fd is owned by the framework
> - * or by the caller.
> - */
> - guest_memfd = kvm_dup(guest_memfd);
> - }
> -
> - region->region.guest_memfd = guest_memfd;
> - region->region.guest_memfd_offset = guest_memfd_offset;
> - } else {
> - region->region.guest_memfd = -1;
> - }
> -
> region->unused_phy_pages = sparsebit_alloc();
> if (vm_arch_has_protected_memory(vm))
> region->protected_phy_pages = sparsebit_alloc();
>
> --
> 2.54.0.563.g4f69b47b94-goog
>
>
^ permalink raw reply
* Re: [PATCH v2 4/4] cpufreq: Use policy->min/max init as QoS request
From: Pierre Gondois @ 2026-05-21 11:58 UTC (permalink / raw)
To: Jie Zhan, linux-kernel
Cc: Lifeng Zheng, Ionela Voinescu, Sumit Gupta, Zhongqiu Han,
Rafael J. Wysocki, Viresh Kumar, Jonathan Corbet, Shuah Khan,
Huang Rui, Mario Limonciello, Perry Yuan, K Prateek Nayak,
Srinivas Pandruvada, Len Brown, Saravana Kannan, linux-pm,
linux-doc
In-Reply-To: <112c6947-d496-46a9-8561-bbc23793e615@hisilicon.com>
Hello Jie,
On 5/20/26 10:38, Jie Zhan wrote:
> On 5/11/2026 9:55 PM, Pierre Gondois wrote:
>> Consider policy->min/max being set in the driver .init()
>> callback as a QoS request. Impacted driver are:
>> - gx-suspmod.c (min)
>> - cppc-cpufreq.c (min)
>> - longrun.c (min/max)
>>
>> Update the documentation accordingly.
>>
>> Signed-off-by: Pierre Gondois<pierre.gondois@arm.com>
>> ---
>> Documentation/cpu-freq/cpu-drivers.rst | 10 ++++++++--
>> drivers/cpufreq/cpufreq.c | 12 ++++++++++--
>> 2 files changed, 18 insertions(+), 4 deletions(-)
>>
>> diff --git a/Documentation/cpu-freq/cpu-drivers.rst b/Documentation/cpu-freq/cpu-drivers.rst
>> index c5635ac3de547..ab4f3c0f3a89b 100644
>> --- a/Documentation/cpu-freq/cpu-drivers.rst
>> +++ b/Documentation/cpu-freq/cpu-drivers.rst
>> @@ -114,8 +114,14 @@ Then, the driver must fill in the following values:
>> |policy->cur | The current operating frequency of |
>> | | this CPU (if appropriate) |
>> +-----------------------------------+--------------------------------------+
>> -|policy->min, | |
>> -|policy->max, | |
>> +|policy->min | If set by the driver in ->init(), |
>> +| | used as initial minimum frequency |
>> +| | QoS request. |
>> ++-----------------------------------+--------------------------------------+
>> +|policy->max | If set by the driver in ->init(), |
>> +| | used as initial maximum frequency |
>> +| | QoS request. |
>> ++-----------------------------------+--------------------------------------+
> Hi Pierre,
>
> Trivial bit: add the general meaning alongside its driver usage at the init
> stage, and mention it defaults to cpuinfo_min/max_freq if not set?
>
> I mean something like:
> The minimum/maximum scaling frequency. If set by the driver in ->init(),
> used as initial minimum/maximum frequency QoS request; otherwise, follow
> policy->cpuinfo.min/max_freq.
Just one NIT, policy->min/max should follow the min/max allowed freq.
the cpufreq driver can set. E.g. a thermal constraint can impact it (cf.
dtpm_cpu.c).
Would this fit ?
The minimum/maximum scaling frequency. If set by the driver in ->init(),
used as initial minimum/maximum frequency QoS request; otherwise, follow
the min/max allowed freq. the cpufreq driver can set.
> Thanks,
> Jie
>> |policy->policy and, if necessary, | |
>> |policy->governor | must contain the "default policy" for|
>> | | this CPU. A few moments later, |
> [ ... ]
^ permalink raw reply
* Re: [PATCH v2 4/4] cpufreq: Use policy->min/max init as QoS request
From: Pierre Gondois @ 2026-05-21 11:58 UTC (permalink / raw)
To: zhenglifeng (A), linux-kernel
Cc: Jie Zhan, Ionela Voinescu, Sumit Gupta, Zhongqiu Han,
Rafael J. Wysocki, Viresh Kumar, Jonathan Corbet, Shuah Khan,
Huang Rui, Mario Limonciello, Perry Yuan, K Prateek Nayak,
Srinivas Pandruvada, Len Brown, Saravana Kannan, linux-pm,
linux-doc
In-Reply-To: <05a5a8a3-7153-460d-86f8-d2be04062d6b@huawei.com>
Hello Lifeng,
On 5/21/26 13:26, zhenglifeng (A) wrote:
> On 5/11/2026 9:55 PM, Pierre Gondois wrote:
>> Consider policy->min/max being set in the driver .init()
>> callback as a QoS request. Impacted driver are:
>> - gx-suspmod.c (min)
>> - cppc-cpufreq.c (min)
>> - longrun.c (min/max)
>>
>> Update the documentation accordingly.
>>
>> Signed-off-by: Pierre Gondois<pierre.gondois@arm.com>
>> ---
>> Documentation/cpu-freq/cpu-drivers.rst | 10 ++++++++--
>> drivers/cpufreq/cpufreq.c | 12 ++++++++++--
>> 2 files changed, 18 insertions(+), 4 deletions(-)
>>
>> diff --git a/Documentation/cpu-freq/cpu-drivers.rst b/Documentation/cpu-freq/cpu-drivers.rst
>> index c5635ac3de547..ab4f3c0f3a89b 100644
>> --- a/Documentation/cpu-freq/cpu-drivers.rst
>> +++ b/Documentation/cpu-freq/cpu-drivers.rst
>> @@ -114,8 +114,14 @@ Then, the driver must fill in the following values:
>> |policy->cur | The current operating frequency of |
>> | | this CPU (if appropriate) |
>> +-----------------------------------+--------------------------------------+
>> -|policy->min, | |
>> -|policy->max, | |
>> +|policy->min | If set by the driver in ->init(), |
>> +| | used as initial minimum frequency |
>> +| | QoS request. |
>> ++-----------------------------------+--------------------------------------+
>> +|policy->max | If set by the driver in ->init(), |
>> +| | used as initial maximum frequency |
>> +| | QoS request. |
>> ++-----------------------------------+--------------------------------------+
>> |policy->policy and, if necessary, | |
>> |policy->governor | must contain the "default policy" for|
>> | | this CPU. A few moments later, |
>> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
>> index 9e2d9d3fc5351..9a005367ed87b 100644
>> --- a/drivers/cpufreq/cpufreq.c
>> +++ b/drivers/cpufreq/cpufreq.c
>> @@ -1399,8 +1399,16 @@ static void cpufreq_policy_free(struct cpufreq_policy *policy)
>>
>> static int cpufreq_policy_init_qos(struct cpufreq_policy *policy)
>> {
>> + unsigned int min_freq, max_freq;
>> int ret;
>>
>> + /* Use policy->min/max set by the driver as QoS requests. */
>> + min_freq = max(FREQ_QOS_MIN_DEFAULT_VALUE, policy->min);
>> + if (policy->max)
>> + max_freq = min(FREQ_QOS_MAX_DEFAULT_VALUE, policy->max);
>> + else
>> + max_freq = FREQ_QOS_MAX_DEFAULT_VALUE;
>> +
> Can't see the point of this. Why not just use policy->max and policy->min
> to init qos?
With patch [3/4] "cpufreq: Remove driver default policy->min/max init",
some drivers don't set policy->min/max. For the max value, we would end-up
with a max QoS constraint of 0.
If we were to use cpuinfo.max_freq instead, then we this would bring us
back to:
521223d8b3ec ("cpufreq: Fix initialization of min and max
frequency QoS requests")
>> /*
>> * If the driver didn't set policy->min/max, set them as
>> * they are used to clamp frequency requests.
>> @@ -1418,12 +1426,12 @@ static int cpufreq_policy_init_qos(struct cpufreq_policy *policy)
>> }
>>
>> ret = freq_qos_add_request(&policy->constraints, &policy->min_freq_req,
>> - FREQ_QOS_MIN, FREQ_QOS_MIN_DEFAULT_VALUE);
>> + FREQ_QOS_MIN, min_freq);
>> if (ret < 0)
>> return ret;
>>
>> ret = freq_qos_add_request(&policy->constraints, &policy->max_freq_req,
>> - FREQ_QOS_MAX, FREQ_QOS_MAX_DEFAULT_VALUE);
>> + FREQ_QOS_MAX, max_freq);
>> if (ret < 0)
>> return ret;
>>
^ permalink raw reply
* Re: [PATCH v2 4/4] cpufreq: Use policy->min/max init as QoS request
From: Pierre Gondois @ 2026-05-21 11:58 UTC (permalink / raw)
To: Viresh Kumar
Cc: linux-kernel, Jie Zhan, Lifeng Zheng, Ionela Voinescu,
Sumit Gupta, Zhongqiu Han, Rafael J. Wysocki, Jonathan Corbet,
Shuah Khan, Huang Rui, Mario Limonciello, Perry Yuan,
K Prateek Nayak, Srinivas Pandruvada, Len Brown, Saravana Kannan,
linux-pm, linux-doc
In-Reply-To: <bflxwyho5epheovbjnzlsvgvoitaqjbiv7kxcwbnoiz2nlmuvv@dtunrpupeyie>
Hello Viresh,
On 5/20/26 12:03, Viresh Kumar wrote:
> On 11-05-26, 15:55, Pierre Gondois wrote:
>> @@ -1399,8 +1399,16 @@ static void cpufreq_policy_free(struct cpufreq_policy *policy)
>>
>> static int cpufreq_policy_init_qos(struct cpufreq_policy *policy)
>> {
>> + unsigned int min_freq, max_freq;
>> int ret;
>>
>> + /* Use policy->min/max set by the driver as QoS requests. */
>> + min_freq = max(FREQ_QOS_MIN_DEFAULT_VALUE, policy->min);
>> + if (policy->max)
>> + max_freq = min(FREQ_QOS_MAX_DEFAULT_VALUE, policy->max);
>> + else
>> + max_freq = FREQ_QOS_MAX_DEFAULT_VALUE;
>> +
> Why is this required to be done before setting policy->min/max ? And
> so I don't think patch 1/4 is required at all.
Sorry if I misunderstand, but if we do:
"""
/*
* If the driver didn't set policy->min/max, set them as
* they are used to clamp frequency requests.
*/
policy->min = policy->min ? policy->min : policy->cpuinfo.min_freq;
policy->max = policy->max ? policy->max : policy->cpuinfo.max_freq;
/* Use policy->min/max set by the driver as QoS requests. */
min_freq = max(FREQ_QOS_MIN_DEFAULT_VALUE, policy->min);
if (policy->max)
max_freq = min(FREQ_QOS_MAX_DEFAULT_VALUE, policy->max);
else
max_freq = FREQ_QOS_MAX_DEFAULT_VALUE;
"""
then drivers that don't set policy->min/max in their .init() callback
will end up with a QoS constraint of:
[cpuinfo.min_freq:cpuinfo.max_freq].
This would bring us to what the following patch tried to solve:
521223d8b3ec ("cpufreq: Fix initialization of min and max
frequency QoS requests")
------
About removing patch [1/4], Zhongqiu noted that policy->min/max should
be set before the CPUFREQ_CREATE_POLICY notifier [1].
I then thought it would be better to save policy->min/max values
that are meant to become QoS constraint:
- as close as possible to the cpufreq_driver->init() call
- in a separate function, to do all the QoS creation in a separate
function.
[1]
https://lore.kernel.org/all/73fac9ca-451d-49f0-b9c7-5ef6bc0119bf@oss.qualcomm.com/
>> /*
>> * If the driver didn't set policy->min/max, set them as
>> * they are used to clamp frequency requests.
>> @@ -1418,12 +1426,12 @@ static int cpufreq_policy_init_qos(struct cpufreq_policy *policy)
>> }
>>
>> ret = freq_qos_add_request(&policy->constraints, &policy->min_freq_req,
>> - FREQ_QOS_MIN, FREQ_QOS_MIN_DEFAULT_VALUE);
>> + FREQ_QOS_MIN, min_freq);
>> if (ret < 0)
>> return ret;
>>
>> ret = freq_qos_add_request(&policy->constraints, &policy->max_freq_req,
>> - FREQ_QOS_MAX, FREQ_QOS_MAX_DEFAULT_VALUE);
>> + FREQ_QOS_MAX, max_freq);
>> if (ret < 0)
>> return ret;
>>
>> --
>> 2.43.0
^ permalink raw reply
* RE: [PATCH v12 5/6] iio: adc: ad4691: add oversampling support
From: Sabau, Radu bogdan @ 2026-05-21 11:32 UTC (permalink / raw)
To: Sabau, Radu bogdan, Lars-Peter Clausen, Hennerich, Michael,
Jonathan Cameron, David Lechner, Sa, Nuno, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Uwe Kleine-König, Liam Girdwood, Mark Brown, Linus Walleij,
Bartosz Golaszewski, Philipp Zabel, Jonathan Corbet, Shuah Khan
Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org,
linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org
In-Reply-To: <20260519-ad4692-multichannel-sar-adc-driver-v12-5-5b335162aa51@analog.com>
> -----Original Message-----
> From: Radu Sabau via B4 Relay <devnull+radu.sabau.analog.com@kernel.org>
> Sent: Tuesday, May 19, 2026 3:20 PM
...
>
> + iio_for_each_active_channel(indio_dev, bit) {
> + ret = regmap_write(st->regmap,
> AD4691_ACC_DEPTH_IN(bit), st->osr[bit]);
Unfortunately enough, I think a v13 will come, too...
Had a look again on what Sashiko had to say, and seeing the sampling frequency
shared_by_all comment again made me have a deeper look see how the code could
be commented so he wouldn't complain about this anymore, and...
Perhaps he is a bit right after all. I found a section stating that in standard
sequencer mode (which the driver uses right now), all the channels actually use
the ACC_DEPTH_IN0 for osr, and so changing ACC_DEPTH_INn for other channels
doesn't really do much. And so I tested this selecting both voltage0 and voltage1
for sampling with osr4 for voltage0 and osr1 for voltage1 and with a 100kHz osc freq
indeed DR fell after approximately 80us which points out both channels were actually
using OSR of 4. Perhaps the OSR should be shared by all and therefore the
sampling frequency would also be shared by all, right?
The usage of internal_osc_freq and pre-computed freq values depending on osr would
stay the same since those are still correct anyway.
What's your opinion on this?
Radu
^ permalink raw reply
* Re: [PATCH v2 4/4] cpufreq: Use policy->min/max init as QoS request
From: zhenglifeng (A) @ 2026-05-21 11:26 UTC (permalink / raw)
To: Pierre Gondois, linux-kernel
Cc: Jie Zhan, Ionela Voinescu, Sumit Gupta, Zhongqiu Han,
Rafael J. Wysocki, Viresh Kumar, Jonathan Corbet, Shuah Khan,
Huang Rui, Mario Limonciello, Perry Yuan, K Prateek Nayak,
Srinivas Pandruvada, Len Brown, Saravana Kannan, linux-pm,
linux-doc
In-Reply-To: <20260511135538.522653-5-pierre.gondois@arm.com>
On 5/11/2026 9:55 PM, Pierre Gondois wrote:
> Consider policy->min/max being set in the driver .init()
> callback as a QoS request. Impacted driver are:
> - gx-suspmod.c (min)
> - cppc-cpufreq.c (min)
> - longrun.c (min/max)
>
> Update the documentation accordingly.
>
> Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
> ---
> Documentation/cpu-freq/cpu-drivers.rst | 10 ++++++++--
> drivers/cpufreq/cpufreq.c | 12 ++++++++++--
> 2 files changed, 18 insertions(+), 4 deletions(-)
>
> diff --git a/Documentation/cpu-freq/cpu-drivers.rst b/Documentation/cpu-freq/cpu-drivers.rst
> index c5635ac3de547..ab4f3c0f3a89b 100644
> --- a/Documentation/cpu-freq/cpu-drivers.rst
> +++ b/Documentation/cpu-freq/cpu-drivers.rst
> @@ -114,8 +114,14 @@ Then, the driver must fill in the following values:
> |policy->cur | The current operating frequency of |
> | | this CPU (if appropriate) |
> +-----------------------------------+--------------------------------------+
> -|policy->min, | |
> -|policy->max, | |
> +|policy->min | If set by the driver in ->init(), |
> +| | used as initial minimum frequency |
> +| | QoS request. |
> ++-----------------------------------+--------------------------------------+
> +|policy->max | If set by the driver in ->init(), |
> +| | used as initial maximum frequency |
> +| | QoS request. |
> ++-----------------------------------+--------------------------------------+
> |policy->policy and, if necessary, | |
> |policy->governor | must contain the "default policy" for|
> | | this CPU. A few moments later, |
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index 9e2d9d3fc5351..9a005367ed87b 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -1399,8 +1399,16 @@ static void cpufreq_policy_free(struct cpufreq_policy *policy)
>
> static int cpufreq_policy_init_qos(struct cpufreq_policy *policy)
> {
> + unsigned int min_freq, max_freq;
> int ret;
>
> + /* Use policy->min/max set by the driver as QoS requests. */
> + min_freq = max(FREQ_QOS_MIN_DEFAULT_VALUE, policy->min);
> + if (policy->max)
> + max_freq = min(FREQ_QOS_MAX_DEFAULT_VALUE, policy->max);
> + else
> + max_freq = FREQ_QOS_MAX_DEFAULT_VALUE;
> +
Can't see the point of this. Why not just use policy->max and policy->min
to init qos?
> /*
> * If the driver didn't set policy->min/max, set them as
> * they are used to clamp frequency requests.
> @@ -1418,12 +1426,12 @@ static int cpufreq_policy_init_qos(struct cpufreq_policy *policy)
> }
>
> ret = freq_qos_add_request(&policy->constraints, &policy->min_freq_req,
> - FREQ_QOS_MIN, FREQ_QOS_MIN_DEFAULT_VALUE);
> + FREQ_QOS_MIN, min_freq);
> if (ret < 0)
> return ret;
>
> ret = freq_qos_add_request(&policy->constraints, &policy->max_freq_req,
> - FREQ_QOS_MAX, FREQ_QOS_MAX_DEFAULT_VALUE);
> + FREQ_QOS_MAX, max_freq);
> if (ret < 0)
> return ret;
>
^ permalink raw reply
* [PATCH v3 4/4] selftests/mm: rewrite gup_test as a standalone harness-based selftest
From: Sarthak Sharma @ 2026-05-21 11:18 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand
Cc: Jonathan Corbet, Lorenzo Stoakes, Liam R . Howlett,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
Shuah Khan, Shuah Khan, Jason Gunthorpe, John Hubbard, Peter Xu,
Leon Romanovsky, Zi Yan, Baolin Wang, Nico Pache, Ryan Roberts,
Dev Jain, Barry Song, Lance Yang, Mark Brown, linux-kernel,
linux-mm, linux-kselftest, linux-doc, Sarthak Sharma
In-Reply-To: <20260521111801.173019-1-sarthak.sharma@arm.com>
Rewrite gup_test.c using kselftest_harness.h. The new test covers 12
mapping configurations: THP on, THP off and hugetlb, each across
private/shared and read/write variants. It runs seven test cases per
variant: get_user_pages, get_user_pages_fast, pin_user_pages,
pin_user_pages_fast, pin_user_pages_longterm, and DUMP_USER_PAGES_TEST
via both get and pin.
Each test case sweeps four nr_pages_per_call values: 1, 512, 123, and
all pages. This preserves the old run_gup_matrix() sweep: 12 mapping
combinations x 5 GUP/PUP operations x 4 batch sizes = 240 ioctl sweeps.
It also expands DUMP_USER_PAGES_TEST coverage from one standalone
invocation to 12 variants x 2 dump modes x 4 batch sizes = 96
additional sweeps.
Preserve the old sparse dump coverage from run_vmtests.sh with one
standalone test that exercises DUMP_USER_PAGES_TEST with page indices
0, 19 and 0x1000. This brings the total to 85 TAP-reported cases
(12 x 7 + 1) and 337 ioctl sweeps (240 + 96 + 1).
On a Radxa Orion O6 board, ./gup_test completes in 5.39s on average
over 10 runs (range: 5.33s - 5.48s).
Update run_vmtests.sh: remove run_gup_matrix() and the multiple flagged
invocations of gup_test, replacing them with a single unconditional
invocation. Benchmark functionality is handled by tools/mm/gup_bench
introduced in the previous patch.
Update Documentation/core-api/pin_user_pages.rst to reflect the new
harness-based gup_test interface rather than command-line flag
invocations.
Suggested-by: David Hildenbrand (Arm) <david@kernel.org>
Signed-off-by: Sarthak Sharma <sarthak.sharma@arm.com>
---
Documentation/core-api/pin_user_pages.rst | 12 +-
tools/testing/selftests/mm/gup_test.c | 584 ++++++++++++++--------
tools/testing/selftests/mm/run_vmtests.sh | 37 +-
3 files changed, 376 insertions(+), 257 deletions(-)
diff --git a/Documentation/core-api/pin_user_pages.rst b/Documentation/core-api/pin_user_pages.rst
index c16ca163b55e..ea722adf22cc 100644
--- a/Documentation/core-api/pin_user_pages.rst
+++ b/Documentation/core-api/pin_user_pages.rst
@@ -230,10 +230,16 @@ This file::
tools/testing/selftests/mm/gup_test.c
-has the following new calls to exercise the new pin*() wrapper functions:
+contains the following test cases to exercise pin_user_pages*():
-* PIN_FAST_BENCHMARK (./gup_test -a)
-* PIN_BASIC_TEST (./gup_test -b)
+* pin_user_pages via PIN_BASIC_TEST
+* pin_user_pages_fast via PIN_FAST_BENCHMARK
+* pin_user_pages_longterm via PIN_LONGTERM_BENCHMARK
+
+Run with::
+
+ make -C tools/testing/selftests/mm
+ ./tools/testing/selftests/mm/gup_test
You can monitor how many total dma-pinned pages have been acquired and released
since the system was booted, via two new /proc/vmstat entries: ::
diff --git a/tools/testing/selftests/mm/gup_test.c b/tools/testing/selftests/mm/gup_test.c
index 803ab829a841..3f6626fe94a2 100644
--- a/tools/testing/selftests/mm/gup_test.c
+++ b/tools/testing/selftests/mm/gup_test.c
@@ -9,268 +9,416 @@
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
-#include <pthread.h>
-#include <assert.h>
#include <mm/gup_test.h>
#include <mm/hugepage_settings.h>
#include "kselftest.h"
#include "vm_util.h"
+#include "kselftest_harness.h"
#define MB (1UL << 20)
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+#endif
+
/* Just the flags we need, copied from the kernel internals. */
#define FOLL_WRITE 0x01 /* check pte is writable */
+/* Page counts exercising single, THP-batch, partial, and full-mapping GUP. */
+static const int nr_pages_list[] = { 1, 512, 123, -1 };
+
#define GUP_TEST_FILE "/sys/kernel/debug/gup_test"
-static unsigned long cmd = GUP_FAST_BENCHMARK;
-static int gup_fd, repeats = 1;
-static unsigned long size = 128 * MB;
-/* Serialize prints */
-static pthread_mutex_t print_mutex = PTHREAD_MUTEX_INITIALIZER;
+FIXTURE(gup_test)
+{
+ int gup_fd;
+ char *addr;
+ unsigned long size;
+};
+
+FIXTURE_VARIANT(gup_test)
+{
+ bool thp;
+ bool hugetlb;
+ bool write;
+ bool shared;
+};
+
+FIXTURE_VARIANT_ADD(gup_test, private_write)
+{
+ .thp = false,
+ .hugetlb = false,
+ .write = true,
+ .shared = false,
+};
+
+FIXTURE_VARIANT_ADD(gup_test, private_readonly)
+{
+ .thp = false,
+ .hugetlb = false,
+ .write = false,
+ .shared = false,
+};
+
+FIXTURE_VARIANT_ADD(gup_test, private_write_thp)
+{
+ .thp = true,
+ .hugetlb = false,
+ .write = true,
+ .shared = false,
+};
+
+FIXTURE_VARIANT_ADD(gup_test, private_readonly_thp)
+{
+ .thp = true,
+ .hugetlb = false,
+ .write = false,
+ .shared = false,
+};
+
+FIXTURE_VARIANT_ADD(gup_test, private_write_hugetlb)
+{
+ .thp = false,
+ .hugetlb = true,
+ .write = true,
+ .shared = false,
+};
+
+FIXTURE_VARIANT_ADD(gup_test, private_readonly_hugetlb)
+{
+ .thp = false,
+ .hugetlb = true,
+ .write = false,
+ .shared = false,
+};
+
+FIXTURE_VARIANT_ADD(gup_test, shared_write)
+{
+ .thp = false,
+ .hugetlb = false,
+ .write = true,
+ .shared = true,
+};
+
+FIXTURE_VARIANT_ADD(gup_test, shared_readonly)
+{
+ .thp = false,
+ .hugetlb = false,
+ .write = false,
+ .shared = true,
+};
+
+FIXTURE_VARIANT_ADD(gup_test, shared_write_thp)
+{
+ .thp = true,
+ .hugetlb = false,
+ .write = true,
+ .shared = true,
+};
-static char *cmd_to_str(unsigned long cmd)
+FIXTURE_VARIANT_ADD(gup_test, shared_readonly_thp)
{
- switch (cmd) {
- case GUP_FAST_BENCHMARK:
- return "GUP_FAST_BENCHMARK";
- case PIN_FAST_BENCHMARK:
- return "PIN_FAST_BENCHMARK";
- case PIN_LONGTERM_BENCHMARK:
- return "PIN_LONGTERM_BENCHMARK";
- case GUP_BASIC_TEST:
- return "GUP_BASIC_TEST";
- case PIN_BASIC_TEST:
- return "PIN_BASIC_TEST";
- case DUMP_USER_PAGES_TEST:
- return "DUMP_USER_PAGES_TEST";
+ .thp = true,
+ .hugetlb = false,
+ .write = false,
+ .shared = true,
+};
+
+FIXTURE_VARIANT_ADD(gup_test, shared_write_hugetlb)
+{
+ .thp = false,
+ .hugetlb = true,
+ .write = true,
+ .shared = true,
+};
+
+FIXTURE_VARIANT_ADD(gup_test, shared_readonly_hugetlb)
+{
+ .thp = false,
+ .hugetlb = true,
+ .write = false,
+ .shared = true,
+};
+
+FIXTURE_SETUP(gup_test)
+{
+ int mmap_flags = MAP_PRIVATE;
+ int zero_fd;
+ char *p;
+
+ self->size = variant->hugetlb ? 256 * MB : 128 * MB;
+
+ /* Check for hugetlb */
+ if (variant->hugetlb) {
+ unsigned long hp_size = default_huge_page_size();
+
+ if (!hp_size)
+ SKIP(return, "HugeTLB not available\n");
+
+ self->size = (self->size + hp_size - 1) & ~(hp_size - 1);
+ if (!hugetlb_setup_default(self->size / hp_size)) {
+ hugetlb_restore_settings();
+ SKIP(return, "Not enough huge pages\n");
+ }
+
+ mmap_flags |= (MAP_HUGETLB | MAP_ANONYMOUS);
}
- return "Unknown command";
+
+ /* zero_fd has to be >= 0. Already checked in main() */
+ zero_fd = open("/dev/zero", O_RDWR);
+ ASSERT_GE(zero_fd, 0);
+
+ /* gup_fd has to be >= 0. Already checked in main() */
+ self->gup_fd = open(GUP_TEST_FILE, O_RDWR);
+ ASSERT_GE(self->gup_fd, 0);
+
+ if (variant->shared)
+ mmap_flags = (mmap_flags & ~MAP_PRIVATE) | MAP_SHARED;
+
+ self->addr = mmap(NULL, self->size, PROT_READ | PROT_WRITE,
+ mmap_flags, zero_fd, 0);
+ close(zero_fd);
+ ASSERT_NE(self->addr, MAP_FAILED);
+
+ if (variant->thp)
+ madvise(self->addr, self->size, MADV_HUGEPAGE);
+ else
+ madvise(self->addr, self->size, MADV_NOHUGEPAGE);
+
+ for (p = self->addr; (unsigned long)p < (unsigned long)self->addr
+ + self->size; p += psize())
+ p[0] = 0;
}
-void *gup_thread(void *data)
+FIXTURE_TEARDOWN(gup_test)
{
- struct gup_test gup = *(struct gup_test *)data;
- int i, status;
-
- /* Only report timing information on the *_BENCHMARK commands: */
- if ((cmd == PIN_FAST_BENCHMARK) || (cmd == GUP_FAST_BENCHMARK) ||
- (cmd == PIN_LONGTERM_BENCHMARK)) {
- for (i = 0; i < repeats; i++) {
- gup.size = size;
- status = ioctl(gup_fd, cmd, &gup);
- if (status)
- break;
-
- pthread_mutex_lock(&print_mutex);
- ksft_print_msg("%s: Time: get:%lld put:%lld us",
- cmd_to_str(cmd), gup.get_delta_usec,
- gup.put_delta_usec);
- if (gup.size != size)
- ksft_print_msg(", truncated (size: %lld)", gup.size);
- ksft_print_msg("\n");
- pthread_mutex_unlock(&print_mutex);
- }
- } else {
- gup.size = size;
- status = ioctl(gup_fd, cmd, &gup);
- if (status)
- goto return_;
-
- pthread_mutex_lock(&print_mutex);
- ksft_print_msg("%s: done\n", cmd_to_str(cmd));
- if (gup.size != size)
- ksft_print_msg("Truncated (size: %lld)\n", gup.size);
- pthread_mutex_unlock(&print_mutex);
+ munmap(self->addr, self->size);
+ close(self->gup_fd);
+
+ if (variant->hugetlb)
+ hugetlb_restore_settings();
+}
+
+TEST_F(gup_test, get_user_pages)
+{
+ /* Tests the get_user_pages path */
+ int i;
+
+ for (i = 0; i < (int)ARRAY_SIZE(nr_pages_list); i++) {
+ struct gup_test gup = { 0 };
+
+ gup.addr = (unsigned long)self->addr;
+ gup.size = self->size;
+ gup.nr_pages_per_call = nr_pages_list[i] < 0 ?
+ self->size / psize() : nr_pages_list[i];
+
+ if (variant->write)
+ gup.gup_flags |= FOLL_WRITE;
+
+ TH_LOG("nr_pages_per_call=%u", gup.nr_pages_per_call);
+ ASSERT_EQ(ioctl(self->gup_fd, GUP_BASIC_TEST, &gup), 0);
+ }
+}
+
+TEST_F(gup_test, pin_user_pages)
+{
+ /* Tests the pin_user_pages path */
+ int i;
+
+ for (i = 0; i < (int)ARRAY_SIZE(nr_pages_list); i++) {
+ struct gup_test gup = { 0 };
+
+ gup.addr = (unsigned long)self->addr;
+ gup.size = self->size;
+ gup.nr_pages_per_call = nr_pages_list[i] < 0 ?
+ self->size / psize() : nr_pages_list[i];
+
+ if (variant->write)
+ gup.gup_flags |= FOLL_WRITE;
+
+ TH_LOG("nr_pages_per_call=%u", gup.nr_pages_per_call);
+ ASSERT_EQ(ioctl(self->gup_fd, PIN_BASIC_TEST, &gup), 0);
}
+}
+
+TEST_F(gup_test, dump_user_pages_with_get)
+{
+ /* Tests DUMP_USER_PAGES_TEST using get_user_pages */
+ int i;
+
+ for (i = 0; i < (int)ARRAY_SIZE(nr_pages_list); i++) {
+ struct gup_test gup = { 0 };
+
+ gup.addr = (unsigned long)self->addr;
+ gup.size = self->size;
+ gup.nr_pages_per_call = nr_pages_list[i] < 0 ?
+ self->size / psize() : nr_pages_list[i];
-return_:
- ksft_test_result(!status, "ioctl status %d\n", status);
- return NULL;
+ if (variant->write)
+ gup.gup_flags |= FOLL_WRITE;
+
+ gup.which_pages[0] = 1;
+
+ TH_LOG("nr_pages_per_call=%u", gup.nr_pages_per_call);
+ ASSERT_EQ(ioctl(self->gup_fd, DUMP_USER_PAGES_TEST, &gup), 0);
+ }
}
-int main(int argc, char **argv)
+TEST_F(gup_test, dump_user_pages_with_pin)
{
- struct gup_test gup = { 0 };
- int filed, i, opt, nr_pages = 1, thp = -1, write = 1, nthreads = 1, ret;
- int flags = MAP_PRIVATE;
- char *file = "/dev/zero";
- bool hugetlb = false;
- pthread_t *tid;
- char *p;
+ /* Tests DUMP_USER_PAGES_TEST using pin_user_pages */
+ int i;
- while ((opt = getopt(argc, argv, "m:r:n:F:f:abcj:tTLUuwWSHpz")) != -1) {
- switch (opt) {
- case 'a':
- cmd = PIN_FAST_BENCHMARK;
- break;
- case 'b':
- cmd = PIN_BASIC_TEST;
- break;
- case 'L':
- cmd = PIN_LONGTERM_BENCHMARK;
- break;
- case 'c':
- cmd = DUMP_USER_PAGES_TEST;
- /*
- * Dump page 0 (index 1). May be overridden later, by
- * user's non-option arguments.
- *
- * .which_pages is zero-based, so that zero can mean "do
- * nothing".
- */
- gup.which_pages[0] = 1;
- break;
- case 'p':
- /* works only with DUMP_USER_PAGES_TEST */
- gup.test_flags |= GUP_TEST_FLAG_DUMP_PAGES_USE_PIN;
- break;
- case 'F':
- /* strtol, so you can pass flags in hex form */
- gup.gup_flags = strtol(optarg, 0, 0);
- break;
- case 'j':
- nthreads = atoi(optarg);
- break;
- case 'm':
- size = atoi(optarg) * MB;
- break;
- case 'r':
- repeats = atoi(optarg);
- break;
- case 'n':
- nr_pages = atoi(optarg);
- if (nr_pages < 0)
- nr_pages = size / psize();
- break;
- case 't':
- thp = 1;
- break;
- case 'T':
- thp = 0;
- break;
- case 'U':
- cmd = GUP_BASIC_TEST;
- break;
- case 'u':
- cmd = GUP_FAST_BENCHMARK;
- break;
- case 'w':
- write = 1;
- break;
- case 'W':
- write = 0;
- break;
- case 'f':
- file = optarg;
- break;
- case 'S':
- flags &= ~MAP_PRIVATE;
- flags |= MAP_SHARED;
- break;
- case 'H':
- flags |= (MAP_HUGETLB | MAP_ANONYMOUS);
- hugetlb = true;
- break;
- default:
- ksft_exit_fail_msg("Wrong argument\n");
- }
+ for (i = 0; i < (int)ARRAY_SIZE(nr_pages_list); i++) {
+ struct gup_test gup = { 0 };
+
+ gup.addr = (unsigned long)self->addr;
+ gup.size = self->size;
+ gup.nr_pages_per_call = nr_pages_list[i] < 0 ?
+ self->size / psize() : nr_pages_list[i];
+
+ if (variant->write)
+ gup.gup_flags |= FOLL_WRITE;
+
+ gup.which_pages[0] = 1;
+ gup.test_flags |= GUP_TEST_FLAG_DUMP_PAGES_USE_PIN;
+
+ TH_LOG("nr_pages_per_call=%u", gup.nr_pages_per_call);
+ ASSERT_EQ(ioctl(self->gup_fd, DUMP_USER_PAGES_TEST, &gup), 0);
}
+}
- if (optind < argc) {
- int extra_arg_count = 0;
- /*
- * For example:
- *
- * ./gup_test -c 0 1 0x1001
- *
- * ...to dump pages 0, 1, and 4097
- */
-
- while ((optind < argc) &&
- (extra_arg_count < GUP_TEST_MAX_PAGES_TO_DUMP)) {
- /*
- * Do the 1-based indexing here, so that the user can
- * use normal 0-based indexing on the command line.
- */
- long page_index = strtol(argv[optind], 0, 0) + 1;
-
- gup.which_pages[extra_arg_count] = page_index;
- extra_arg_count++;
- optind++;
- }
+TEST_F(gup_test, get_user_pages_fast)
+{
+ /* Tests the lockless get_user_pages_fast() path */
+ int i;
+
+ for (i = 0; i < (int)ARRAY_SIZE(nr_pages_list); i++) {
+ struct gup_test gup = { 0 };
+
+ gup.addr = (unsigned long)self->addr;
+ gup.size = self->size;
+ gup.nr_pages_per_call = nr_pages_list[i] < 0 ?
+ self->size / psize() : nr_pages_list[i];
+
+ if (variant->write)
+ gup.gup_flags |= FOLL_WRITE;
+
+ TH_LOG("nr_pages_per_call=%u", gup.nr_pages_per_call);
+ ASSERT_EQ(ioctl(self->gup_fd, GUP_FAST_BENCHMARK, &gup), 0);
}
+}
- ksft_print_header();
+TEST_F(gup_test, pin_user_pages_fast)
+{
+ /* Tests the lockless pin_user_pages_fast() path */
+ int i;
- if (hugetlb) {
- unsigned long hp_size = default_huge_page_size();
+ for (i = 0; i < (int)ARRAY_SIZE(nr_pages_list); i++) {
+ struct gup_test gup = { 0 };
- if (!hp_size)
- ksft_exit_skip("HugeTLB is unavailable\n");
+ gup.addr = (unsigned long)self->addr;
+ gup.size = self->size;
+ gup.nr_pages_per_call = nr_pages_list[i] < 0 ?
+ self->size / psize() : nr_pages_list[i];
+
+ if (variant->write)
+ gup.gup_flags |= FOLL_WRITE;
- size = (size + hp_size - 1) & ~(hp_size - 1);
- if (!hugetlb_setup_default(size / hp_size))
- ksft_exit_skip("Not enough huge pages\n");
+ TH_LOG("nr_pages_per_call=%u", gup.nr_pages_per_call);
+ ASSERT_EQ(ioctl(self->gup_fd, PIN_FAST_BENCHMARK, &gup), 0);
}
+}
- ksft_set_plan(nthreads);
+TEST_F(gup_test, pin_user_pages_longterm)
+{
+ /* Tests pin_user_pages() with FOLL_LONGTERM */
+ int i;
- filed = open(file, O_RDWR|O_CREAT, 0664);
- if (filed < 0)
- ksft_exit_fail_msg("Unable to open %s: %s\n", file, strerror(errno));
+ for (i = 0; i < (int)ARRAY_SIZE(nr_pages_list); i++) {
+ struct gup_test gup = { 0 };
- gup.nr_pages_per_call = nr_pages;
- if (write)
- gup.gup_flags |= FOLL_WRITE;
+ gup.addr = (unsigned long)self->addr;
+ gup.size = self->size;
+ gup.nr_pages_per_call = nr_pages_list[i] < 0 ?
+ self->size / psize() : nr_pages_list[i];
- gup_fd = open(GUP_TEST_FILE, O_RDWR);
- if (gup_fd == -1) {
- switch (errno) {
- case EACCES:
- if (getuid())
- ksft_print_msg("Please run this test as root\n");
- break;
- case ENOENT:
- if (opendir("/sys/kernel/debug") == NULL)
- ksft_print_msg("mount debugfs at /sys/kernel/debug\n");
- ksft_print_msg("check if CONFIG_GUP_TEST is enabled in kernel config\n");
- break;
- default:
- ksft_print_msg("failed to open %s: %s\n", GUP_TEST_FILE, strerror(errno));
- break;
- }
- ksft_test_result_skip("Please run this test as root\n");
- ksft_exit_pass();
+ if (variant->write)
+ gup.gup_flags |= FOLL_WRITE;
+
+ TH_LOG("nr_pages_per_call=%u", gup.nr_pages_per_call);
+ ASSERT_EQ(ioctl(self->gup_fd, PIN_LONGTERM_BENCHMARK, &gup), 0);
}
+}
- p = mmap(NULL, size, PROT_READ | PROT_WRITE, flags, filed, 0);
- if (p == MAP_FAILED)
- ksft_exit_fail_msg("mmap: %s\n", strerror(errno));
- gup.addr = (unsigned long)p;
+TEST(dump_user_pages_sparse_indices)
+{
+ /* Tests sparse multi-index which_pages[] inputs. */
+ struct gup_test gup = { 0 };
+ unsigned long size = 128 * MB;
+ int zero_fd, gup_fd;
+ char *addr, *p;
+
+ zero_fd = open("/dev/zero", O_RDWR);
+ ASSERT_GE(zero_fd, 0);
+
+ gup_fd = open(GUP_TEST_FILE, O_RDWR);
+ ASSERT_GE(gup_fd, 0);
- if (thp == 1)
- madvise(p, size, MADV_HUGEPAGE);
- else if (thp == 0)
- madvise(p, size, MADV_NOHUGEPAGE);
+ addr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, zero_fd, 0);
+ close(zero_fd);
+ ASSERT_NE(addr, MAP_FAILED);
- /* Fault them in here, from user space. */
- for (; (unsigned long)p < gup.addr + size; p += psize())
+ ASSERT_EQ(madvise(addr, size, MADV_HUGEPAGE), 0);
+
+ for (p = addr; (unsigned long)p < (unsigned long)addr + size;
+ p += psize())
p[0] = 0;
- tid = malloc(sizeof(pthread_t) * nthreads);
- assert(tid);
- for (i = 0; i < nthreads; i++) {
- ret = pthread_create(&tid[i], NULL, gup_thread, &gup);
- assert(ret == 0);
- }
- for (i = 0; i < nthreads; i++) {
- ret = pthread_join(tid[i], NULL);
- assert(ret == 0);
+ gup.addr = (unsigned long)addr;
+ gup.size = size;
+ gup.gup_flags = FOLL_WRITE;
+ gup.which_pages[0] = 1;
+ gup.which_pages[1] = 20;
+ gup.which_pages[2] = 0x1001;
+
+ /*
+ * Preserve the old "./gup_test -ct -F 0x1 0 19 0x1000" sparse dump
+ * coverage after removing command-line parsing from this binary.
+ */
+ ASSERT_EQ(ioctl(gup_fd, DUMP_USER_PAGES_TEST, &gup), 0);
+
+ munmap(addr, size);
+ close(gup_fd);
+}
+
+int main(int argc, char **argv)
+{
+ int fd;
+ char *file = "/dev/zero";
+
+ fd = open(file, O_RDWR);
+ if (fd < 0) {
+ ksft_print_header();
+ ksft_exit_fail_msg("Unable to open %s: %s\n", file, strerror(errno));
}
+ close(fd);
- free(tid);
+ fd = open(GUP_TEST_FILE, O_RDWR);
+ if (fd == -1) {
+ ksft_print_header();
+ if (errno == EACCES)
+ ksft_exit_skip("Please run this test as root\n");
+ if (errno == ENOENT) {
+ if (opendir("/sys/kernel/debug") == NULL)
+ ksft_exit_skip("Mount debugfs at /sys/kernel/debug\n");
+ else
+ ksft_exit_skip("Check CONFIG_GUP_TEST in kernel config\n");
+ }
+ ksft_exit_skip("failed to open %s: %s\n", GUP_TEST_FILE, strerror(errno));
+ }
+ close(fd);
- ksft_exit_pass();
+ return test_harness_run(argc, argv);
}
diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/selftests/mm/run_vmtests.sh
index 043aa3ed2596..65a4ef0f3748 100755
--- a/tools/testing/selftests/mm/run_vmtests.sh
+++ b/tools/testing/selftests/mm/run_vmtests.sh
@@ -130,30 +130,6 @@ test_selected() {
fi
}
-run_gup_matrix() {
- # -t: thp=on, -T: thp=off, -H: hugetlb=on
- local hugetlb_mb=256
-
- for huge in -t -T "-H -m $hugetlb_mb"; do
- # -u: gup-fast, -U: gup-basic, -a: pin-fast, -b: pin-basic, -L: pin-longterm
- for test_cmd in -u -U -a -b -L; do
- # -w: write=1, -W: write=0
- for write in -w -W; do
- # -S: shared
- for share in -S " "; do
- # -n: How many pages to fetch together? 512 is special
- # because it's default thp size (or 2M on x86), 123 to
- # just test partial gup when hit a huge in whatever form
- for num in "-n 1" "-n 512" "-n 123" "-n -1"; do
- CATEGORY="gup_test" run_test ./gup_test \
- $huge $test_cmd $write $share $num
- done
- done
- done
- done
- done
-}
-
# filter 64bit architectures
ARCH64STR="arm64 mips64 parisc64 ppc64 ppc64le riscv64 s390x sparc64 x86_64"
if [ -z "$ARCH" ]; then
@@ -239,18 +215,7 @@ fi
CATEGORY="mmap" run_test ./map_fixed_noreplace
-if $RUN_ALL; then
- run_gup_matrix
-else
- # get_user_pages_fast() benchmark
- CATEGORY="gup_test" run_test ./gup_test -u -n 1
- CATEGORY="gup_test" run_test ./gup_test -u -n -1
- # pin_user_pages_fast() benchmark
- CATEGORY="gup_test" run_test ./gup_test -a -n 1
- CATEGORY="gup_test" run_test ./gup_test -a -n -1
-fi
-# Dump pages 0, 19, and 4096, using pin_user_pages:
-CATEGORY="gup_test" run_test ./gup_test -ct -F 0x1 0 19 0x1000
+CATEGORY="gup_test" run_test ./gup_test
CATEGORY="gup_test" run_test ./gup_longterm
CATEGORY="userfaultfd" run_test ./uffd-unit-tests
--
2.39.5
^ permalink raw reply related
* [PATCH v3 3/4] tools/mm: add a standalone GUP microbenchmark
From: Sarthak Sharma @ 2026-05-21 11:18 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand
Cc: Jonathan Corbet, Lorenzo Stoakes, Liam R . Howlett,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
Shuah Khan, Shuah Khan, Jason Gunthorpe, John Hubbard, Peter Xu,
Leon Romanovsky, Zi Yan, Baolin Wang, Nico Pache, Ryan Roberts,
Dev Jain, Barry Song, Lance Yang, Mark Brown, linux-kernel,
linux-mm, linux-kselftest, linux-doc, Sarthak Sharma
In-Reply-To: <20260521111801.173019-1-sarthak.sharma@arm.com>
Add a command-line tool for benchmarking get_user_pages fast-path
(GUP_FAST), pin_user_pages fast-path (PIN_FAST), and pin_user_pages
longterm (PIN_LONGTERM) via the CONFIG_GUP_TEST debugfs interface.
When invoked without arguments, gup_bench runs the same matrix of
configurations as run_gup_matrix() in run_vmtests.sh: all three GUP
commands across read/write, private/shared mappings, and a range of
page counts, with THP on/off for regular mappings and hugetlb for huge
page mappings.
This tool is a mix of reused and new logic. The mapping/setup path comes
from selftests/mm/gup_test.c, while the default benchmark matrix matches
run_gup_matrix() in run_vmtests.sh. The standalone CLI and tools/mm
integration are added here and the HugeTLB setup code is shared via
tools/lib/mm.
Add gup_bench to BUILD_TARGETS and INSTALL_TARGETS in tools/mm/Makefile,
link it against the shared tools/lib/mm hugepage helpers, and ignore the
resulting binary in tools/mm/.gitignore. While here, also add the
missing thp_swap_allocator_test entry to .gitignore.
Add tools/mm/gup_bench.c to the GUP entry in MAINTAINERS.
Suggested-by: David Hildenbrand (Arm) <david@kernel.org>
Signed-off-by: Sarthak Sharma <sarthak.sharma@arm.com>
---
MAINTAINERS | 1 +
tools/mm/.gitignore | 2 +
tools/mm/Makefile | 10 +-
tools/mm/gup_bench.c | 390 +++++++++++++++++++++++++++++++++++++++++++
4 files changed, 400 insertions(+), 3 deletions(-)
create mode 100644 tools/mm/gup_bench.c
diff --git a/MAINTAINERS b/MAINTAINERS
index 7887a3263373..0dbb90247a75 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -16839,6 +16839,7 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
F: mm/gup.c
F: mm/gup_test.c
F: mm/gup_test.h
+F: tools/mm/gup_bench.c
F: tools/testing/selftests/mm/gup_longterm.c
F: tools/testing/selftests/mm/gup_test.c
diff --git a/tools/mm/.gitignore b/tools/mm/.gitignore
index 922879f93fc8..154d740be02e 100644
--- a/tools/mm/.gitignore
+++ b/tools/mm/.gitignore
@@ -2,3 +2,5 @@
slabinfo
page-types
page_owner_sort
+thp_swap_allocator_test
+gup_bench
diff --git a/tools/mm/Makefile b/tools/mm/Makefile
index f5725b5c23aa..d82cc8c43ee0 100644
--- a/tools/mm/Makefile
+++ b/tools/mm/Makefile
@@ -3,13 +3,14 @@
#
include ../scripts/Makefile.include
-BUILD_TARGETS=page-types slabinfo page_owner_sort thp_swap_allocator_test
+BUILD_TARGETS=page-types slabinfo page_owner_sort thp_swap_allocator_test gup_bench
INSTALL_TARGETS = $(BUILD_TARGETS) thpmaps
LIB_DIR = ../lib/api
LIBS = $(LIB_DIR)/libapi.a
+GUP_BENCH_OBJS = gup_bench.c ../lib/mm/hugepage_settings.c ../lib/mm/file_utils.c
-CFLAGS += -Wall -Wextra -I../lib/ -pthread
+CFLAGS += -Wall -Wextra -I../lib/ -I../.. -pthread
LDFLAGS += $(LIBS) -pthread
all: $(BUILD_TARGETS)
@@ -22,8 +23,11 @@ $(LIBS):
%: %.c
$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
+gup_bench: $(GUP_BENCH_OBJS) $(LIBS)
+ $(CC) $(CFLAGS) -o $@ $(GUP_BENCH_OBJS) $(LDFLAGS)
+
clean:
- $(RM) page-types slabinfo page_owner_sort thp_swap_allocator_test
+ $(RM) page-types slabinfo page_owner_sort thp_swap_allocator_test gup_bench
make -C $(LIB_DIR) clean
sbindir ?= /usr/sbin
diff --git a/tools/mm/gup_bench.c b/tools/mm/gup_bench.c
new file mode 100644
index 000000000000..50faff4527e5
--- /dev/null
+++ b/tools/mm/gup_bench.c
@@ -0,0 +1,390 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Microbenchmark for get_user_pages (GUP) kernel interfaces.
+ *
+ * Exercises GUP_FAST_BENCHMARK, PIN_FAST_BENCHMARK, and
+ * PIN_LONGTERM_BENCHMARK via the CONFIG_GUP_TEST debugfs interface.
+ *
+ * Example use:
+ * # Run the full matrix (all commands, access modes, page counts):
+ * ./gup_bench
+ *
+ * # Single run: pin_user_pages_fast, 512 pages, write access, hugetlb:
+ * ./gup_bench -a -n 512 -w -H
+ *
+ * Requires CONFIG_GUP_TEST=y and debugfs mounted at /sys/kernel/debug.
+ * Must be run as root.
+ */
+
+#define __SANE_USERSPACE_TYPES__ // Use ll64
+#include <fcntl.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <pthread.h>
+#include <stdbool.h>
+#include <stdatomic.h>
+#include <stdint.h>
+#include <limits.h>
+#include <string.h>
+#include <mm/gup_test.h>
+#include <mm/hugepage_settings.h>
+
+#define MB (1UL << 20)
+
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+#endif
+
+/* Just the flags we need, copied from the kernel internals. */
+#define FOLL_WRITE 0x01 /* check pte is writable */
+
+#define GUP_TEST_FILE "/sys/kernel/debug/gup_test"
+
+static unsigned int psize(void)
+{
+ static unsigned int __page_size;
+
+ if (!__page_size)
+ __page_size = sysconf(_SC_PAGESIZE);
+ return __page_size;
+}
+
+static unsigned long cmd;
+static const char *bench_label;
+static int gup_fd, repeats = 1;
+static unsigned long size = 128 * MB;
+static atomic_int bench_error;
+/* Serialize prints */
+static pthread_mutex_t print_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+static const unsigned long bench_cmds[] = {
+ GUP_FAST_BENCHMARK,
+ PIN_FAST_BENCHMARK,
+ PIN_LONGTERM_BENCHMARK,
+};
+static const int bench_thp_modes[] = { 1, 0 }; /* on, off */
+static const int bench_nr_pages_list[] = { 1, 512, 123, -1 };
+
+static const char *cmd_to_str(unsigned long cmd)
+{
+ switch (cmd) {
+ case GUP_FAST_BENCHMARK:
+ return "GUP_FAST_BENCHMARK";
+ case PIN_FAST_BENCHMARK:
+ return "PIN_FAST_BENCHMARK";
+ case PIN_LONGTERM_BENCHMARK:
+ return "PIN_LONGTERM_BENCHMARK";
+ }
+ return "Unknown command";
+}
+
+struct bench_run {
+ unsigned long cmd;
+ int thp; /* -1: default, 0: off, 1: on */
+ bool hugetlb;
+ bool write;
+ bool shared;
+ int nr_pages; /* -1 means all pages (size / psize()) */
+ unsigned long size;
+ char *file;
+ int nthreads;
+ unsigned int gup_flags;
+};
+
+void *gup_thread(void *data)
+{
+ struct gup_test gup = *(struct gup_test *)data;
+ int i, status;
+
+ for (i = 0; i < repeats; i++) {
+ gup.size = size;
+ status = ioctl(gup_fd, cmd, &gup);
+ if (status) {
+ bench_error = 1;
+ break;
+ }
+
+ pthread_mutex_lock(&print_mutex);
+ printf("%s time: get:%lld put:%lld us",
+ bench_label, gup.get_delta_usec,
+ gup.put_delta_usec);
+ if (gup.size != size)
+ printf(", truncated (size: %lld)", gup.size);
+ printf("\n");
+ pthread_mutex_unlock(&print_mutex);
+ }
+
+ return NULL;
+}
+
+static int run_bench(struct bench_run *run)
+{
+ struct gup_test gup = { 0 };
+ int zero_fd, i, ret, started_threads = 0;
+ int flags = MAP_PRIVATE;
+ pthread_t *tid;
+ char label[128];
+ char *p;
+
+ /* Set globals consumed by gup_thread */
+ cmd = run->cmd;
+ size = run->size;
+ bench_error = 0;
+
+ if (run->hugetlb) {
+ unsigned long hp_size = default_huge_page_size();
+
+ if (!hp_size) {
+ fprintf(stderr, "Could not determine huge page size\n");
+ return 1;
+ }
+ size = (size + hp_size - 1) & ~(hp_size - 1);
+ if (!hugetlb_setup_default(size / hp_size)) {
+ fprintf(stderr, "Not enough huge pages\n");
+ return 1;
+ }
+ flags |= (MAP_HUGETLB | MAP_ANONYMOUS);
+ }
+
+ if (run->shared) {
+ flags &= ~MAP_PRIVATE;
+ flags |= MAP_SHARED;
+ }
+
+ gup.nr_pages_per_call = run->nr_pages < 0 ? size / psize() :
+ (unsigned long)run->nr_pages;
+
+ gup.gup_flags = run->gup_flags;
+ if (run->write)
+ gup.gup_flags |= FOLL_WRITE;
+
+ snprintf(label, sizeof(label), "%s (nr_pages=%-4u %s %s %s %s)",
+ cmd_to_str(run->cmd),
+ gup.nr_pages_per_call,
+ run->write ? "write" : "read",
+ run->shared ? "shared" : "private",
+ run->hugetlb ? "hugetlb=on" : "hugetlb=off",
+ run->hugetlb ? "thp=off" :
+ (run->thp == 1 ? "thp=on" :
+ (run->thp == 0 ? "thp=off" : "thp=default")));
+ bench_label = label;
+
+ zero_fd = open(run->file, O_RDWR);
+ if (zero_fd < 0) {
+ fprintf(stderr, "Unable to open %s: %s\n", run->file, strerror(errno));
+ return 1;
+ }
+
+ p = mmap(NULL, size, PROT_READ | PROT_WRITE, flags, zero_fd, 0);
+ close(zero_fd);
+ if (p == MAP_FAILED) {
+ fprintf(stderr, "mmap: %s\n", strerror(errno));
+ return 1;
+ }
+ gup.addr = (unsigned long)p;
+
+ if (run->thp == 1)
+ madvise(p, size, MADV_HUGEPAGE);
+ else if (run->thp == 0)
+ madvise(p, size, MADV_NOHUGEPAGE);
+
+ /* Fault them in here, from user space. */
+ for (; (unsigned long)p < gup.addr + size; p += psize())
+ p[0] = 0;
+
+ tid = malloc(sizeof(pthread_t) * run->nthreads);
+ if (!tid) {
+ fprintf(stderr, "Failed to allocate %d threads: %s\n",
+ run->nthreads, strerror(errno));
+ munmap((void *)gup.addr, size);
+ return 1;
+ }
+
+ for (i = 0; i < run->nthreads; i++) {
+ ret = pthread_create(&tid[i], NULL, gup_thread, &gup);
+ if (ret) {
+ fprintf(stderr, "pthread_create failed: %s\n", strerror(ret));
+ bench_error = 1;
+ break;
+ }
+ started_threads++;
+ }
+ for (i = 0; i < started_threads; i++) {
+ ret = pthread_join(tid[i], NULL);
+ if (ret) {
+ fprintf(stderr, "pthread_join failed: %s\n", strerror(ret));
+ bench_error = 1;
+ }
+ }
+
+ free(tid);
+ munmap((void *)gup.addr, size);
+
+ return bench_error ? 1 : 0;
+}
+
+static int run_matrix(void)
+{
+ unsigned int c, t, w, s, n;
+ int ret = 0;
+
+ for (c = 0; c < ARRAY_SIZE(bench_cmds); c++) {
+ for (w = 0; w <= 1; w++) {
+ for (s = 0; s <= 1; s++) {
+ for (t = 0; t < ARRAY_SIZE(bench_thp_modes); t++) {
+ for (n = 0; n < ARRAY_SIZE(bench_nr_pages_list); n++) {
+ struct bench_run run = {
+ .cmd = bench_cmds[c],
+ .thp = bench_thp_modes[t],
+ .hugetlb = false,
+ .write = w,
+ .shared = s,
+ .nr_pages = bench_nr_pages_list[n],
+ .size = 128 * MB,
+ .file = "/dev/zero",
+ .nthreads = 1,
+ };
+ ret |= run_bench(&run);
+ }
+ }
+ /* hugetlb: 256M to match run_gup_matrix() in run_vmtests.sh */
+ for (n = 0; n < ARRAY_SIZE(bench_nr_pages_list); n++) {
+ struct bench_run run = {
+ .cmd = bench_cmds[c],
+ .thp = -1,
+ .hugetlb = true,
+ .write = w,
+ .shared = s,
+ .nr_pages = bench_nr_pages_list[n],
+ .size = 256 * MB,
+ .file = "/dev/zero",
+ .nthreads = 1,
+ };
+ ret |= run_bench(&run);
+ }
+ }
+ }
+ }
+ return ret;
+}
+
+int main(int argc, char **argv)
+{
+ struct bench_run run = {
+ .cmd = GUP_FAST_BENCHMARK,
+ .thp = -1,
+ .hugetlb = false,
+ .write = true,
+ .shared = false,
+ .nr_pages = 1,
+ .size = 128 * MB,
+ .file = "/dev/zero",
+ .nthreads = 1,
+ };
+ int opt, result;
+
+ while ((opt = getopt(argc, argv, "m:r:n:F:f:aj:tTLuwWSH")) != -1) {
+ switch (opt) {
+
+ /* Command selection */
+ case 'u':
+ run.cmd = GUP_FAST_BENCHMARK;
+ break;
+ case 'a':
+ run.cmd = PIN_FAST_BENCHMARK;
+ break;
+ case 'L':
+ run.cmd = PIN_LONGTERM_BENCHMARK;
+ break;
+
+ /* Memory type */
+ case 'H':
+ run.hugetlb = true;
+ break;
+ case 't':
+ run.thp = 1;
+ break;
+ case 'T':
+ run.thp = 0;
+ break;
+
+ /* Access mode */
+ case 'w':
+ run.write = true;
+ break;
+ case 'W':
+ run.write = false;
+ break;
+ case 'S':
+ run.shared = true;
+ break;
+
+ /* Mapping */
+ case 'f':
+ run.file = optarg;
+ break;
+
+ /* Sizing and iteration */
+ case 'm':
+ run.size = atoi(optarg) * MB;
+ break;
+ case 'n':
+ run.nr_pages = atoi(optarg);
+ break;
+ case 'r':
+ repeats = atoi(optarg);
+ break;
+ case 'j': {
+ char *end;
+ long val;
+
+ errno = 0;
+ val = strtol(optarg, &end, 10);
+ if (errno || end == optarg || *end != '\0' || val < 1 ||
+ val > INT_MAX ||
+ (size_t)val > SIZE_MAX / sizeof(pthread_t)) {
+ fprintf(stderr, "Invalid thread count '%s'\n", optarg);
+ exit(1);
+ }
+ run.nthreads = val;
+ break;
+ }
+
+ /* Advanced */
+ case 'F':
+ /* strtol, so you can pass flags in hex form */
+ run.gup_flags = strtol(optarg, 0, 0);
+ break;
+
+ default:
+ fprintf(stderr, "Wrong argument\n");
+ exit(1);
+ }
+ }
+
+ gup_fd = open(GUP_TEST_FILE, O_RDWR);
+ if (gup_fd == -1) {
+ if (errno == EACCES) {
+ fprintf(stderr, "Please run as root\n");
+ } else if (errno == ENOENT) {
+ if (opendir("/sys/kernel/debug") == NULL)
+ fprintf(stderr, "Mount debugfs at /sys/kernel/debug\n");
+ else
+ fprintf(stderr, "Check CONFIG_GUP_TEST in kernel config\n");
+ } else {
+ fprintf(stderr, "Failed to open %s: %s\n", GUP_TEST_FILE,
+ strerror(errno));
+ }
+ exit(1);
+ }
+
+ result = (argc == 1) ? run_matrix() : run_bench(&run);
+ close(gup_fd);
+ return result;
+}
--
2.39.5
^ permalink raw reply related
* [PATCH v3 2/4] tools/lib/mm: move hugepage_settings out of selftests
From: Sarthak Sharma @ 2026-05-21 11:17 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand
Cc: Jonathan Corbet, Lorenzo Stoakes, Liam R . Howlett,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
Shuah Khan, Shuah Khan, Jason Gunthorpe, John Hubbard, Peter Xu,
Leon Romanovsky, Zi Yan, Baolin Wang, Nico Pache, Ryan Roberts,
Dev Jain, Barry Song, Lance Yang, Mark Brown, linux-kernel,
linux-mm, linux-kselftest, linux-doc, Sarthak Sharma
In-Reply-To: <20260521111801.173019-1-sarthak.sharma@arm.com>
Move hugepage_settings.[ch] from tools/testing/selftests/mm/ to
tools/lib/mm/ so the THP and HugeTLB helpers can be shared more easily
between selftests and other tools.
Update the mm selftest users to include the header from tools/lib/mm/
and adjust the selftests/mm build to compile the moved implementation
from its new location.
Remove the remaining kselftest dependency from hugepage_settings.c by
replacing ksft_print_msg() calls with plain fprintf() calls. Drop the
non-fatal hugetlb informational prints from the shared helper, so it
does not emit unwanted output during selftest runs.
Signed-off-by: Sarthak Sharma <sarthak.sharma@arm.com>
---
.../selftests => lib}/mm/hugepage_settings.c | 15 +++++++++------
.../selftests => lib}/mm/hugepage_settings.h | 0
tools/testing/selftests/mm/Makefile | 6 ++++--
tools/testing/selftests/mm/compaction_test.c | 2 +-
tools/testing/selftests/mm/cow.c | 2 +-
.../testing/selftests/mm/folio_split_race_test.c | 3 ++-
tools/testing/selftests/mm/guard-regions.c | 3 ++-
tools/testing/selftests/mm/gup_longterm.c | 2 +-
tools/testing/selftests/mm/gup_test.c | 3 ++-
tools/testing/selftests/mm/hmm-tests.c | 6 +++---
tools/testing/selftests/mm/hugetlb-madvise.c | 3 ++-
tools/testing/selftests/mm/hugetlb-mmap.c | 3 ++-
tools/testing/selftests/mm/hugetlb-mremap.c | 3 ++-
tools/testing/selftests/mm/hugetlb-shm.c | 2 +-
tools/testing/selftests/mm/hugetlb-soft-offline.c | 2 +-
tools/testing/selftests/mm/hugetlb-vmemmap.c | 3 ++-
tools/testing/selftests/mm/hugetlb_dio.c | 3 ++-
.../selftests/mm/hugetlb_fault_after_madv.c | 2 +-
tools/testing/selftests/mm/hugetlb_madv_vs_map.c | 2 +-
tools/testing/selftests/mm/khugepaged.c | 2 +-
tools/testing/selftests/mm/ksm_tests.c | 2 +-
tools/testing/selftests/mm/migration.c | 6 +++---
tools/testing/selftests/mm/pagemap_ioctl.c | 2 +-
tools/testing/selftests/mm/prctl_thp_disable.c | 2 +-
tools/testing/selftests/mm/protection_keys.c | 2 +-
tools/testing/selftests/mm/soft-dirty.c | 2 +-
tools/testing/selftests/mm/split_huge_page_test.c | 2 +-
tools/testing/selftests/mm/thuge-gen.c | 3 ++-
tools/testing/selftests/mm/transhuge-stress.c | 3 ++-
tools/testing/selftests/mm/uffd-common.h | 2 +-
tools/testing/selftests/mm/uffd-wp-mremap.c | 3 ++-
tools/testing/selftests/mm/va_high_addr_switch.c | 2 +-
32 files changed, 57 insertions(+), 41 deletions(-)
rename tools/{testing/selftests => lib}/mm/hugepage_settings.c (98%)
rename tools/{testing/selftests => lib}/mm/hugepage_settings.h (100%)
diff --git a/tools/testing/selftests/mm/hugepage_settings.c b/tools/lib/mm/hugepage_settings.c
similarity index 98%
rename from tools/testing/selftests/mm/hugepage_settings.c
rename to tools/lib/mm/hugepage_settings.c
index 5e947abb7425..b08b27776fc5 100644
--- a/tools/testing/selftests/mm/hugepage_settings.c
+++ b/tools/lib/mm/hugepage_settings.c
@@ -8,13 +8,17 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <mm/file_utils.h>
-#include "kselftest.h"
+#include "file_utils.h"
#include "hugepage_settings.h"
#define THP_SYSFS "/sys/kernel/mm/transparent_hugepage/"
#define MAX_SETTINGS_DEPTH 4
+
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+#endif
+
static struct thp_settings settings_stack[MAX_SETTINGS_DEPTH];
static int settings_index;
static struct thp_settings saved_settings;
@@ -383,8 +387,6 @@ int detect_hugetlb_page_sizes(unsigned long sizes[], int max)
if (sscanf(entry->d_name, "hugepages-%zukB", &kb) != 1)
continue;
sizes[count++] = kb * 1024;
- ksft_print_msg("[INFO] detected hugetlb page size: %zu KiB\n",
- kb);
}
closedir(dir);
return count;
@@ -503,7 +505,6 @@ unsigned long hugetlb_setup(unsigned long nr, unsigned long sizes[],
return 0;
if (nr_enabled > max) {
- ksft_print_msg("detected %d huge page sizes, will only test %d\n", nr_enabled, max);
nr_enabled = max;
}
@@ -575,8 +576,10 @@ static void hugepage_restore_settings_atexit(void)
static void hugepage_restore_settings_sighandler(int sig)
{
+ (void)sig;
+
/* exit() will invoke the hugepage_restore_settings_atexit handler. */
- exit(KSFT_FAIL);
+ exit(EXIT_FAILURE);
}
void hugepage_save_settings(bool thp, bool hugetlb)
diff --git a/tools/testing/selftests/mm/hugepage_settings.h b/tools/lib/mm/hugepage_settings.h
similarity index 100%
rename from tools/testing/selftests/mm/hugepage_settings.h
rename to tools/lib/mm/hugepage_settings.h
diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/mm/Makefile
index b5fb4b6ab31b..8a307b777630 100644
--- a/tools/testing/selftests/mm/Makefile
+++ b/tools/testing/selftests/mm/Makefile
@@ -187,8 +187,10 @@ TEST_FILES += write_hugetlb_memory.sh
include ../lib.mk
-$(TEST_GEN_PROGS): vm_util.c hugepage_settings.c $(top_srcdir)/tools/lib/mm/file_utils.c
-$(TEST_GEN_FILES): vm_util.c hugepage_settings.c $(top_srcdir)/tools/lib/mm/file_utils.c
+$(TEST_GEN_PROGS): vm_util.c $(top_srcdir)/tools/lib/mm/hugepage_settings.c \
+ $(top_srcdir)/tools/lib/mm/file_utils.c
+$(TEST_GEN_FILES): vm_util.c $(top_srcdir)/tools/lib/mm/hugepage_settings.c \
+ $(top_srcdir)/tools/lib/mm/file_utils.c
$(OUTPUT)/uffd-stress: uffd-common.c
$(OUTPUT)/uffd-unit-tests: uffd-common.c
diff --git a/tools/testing/selftests/mm/compaction_test.c b/tools/testing/selftests/mm/compaction_test.c
index de0633f9a7e5..7c58506c0aa7 100644
--- a/tools/testing/selftests/mm/compaction_test.c
+++ b/tools/testing/selftests/mm/compaction_test.c
@@ -15,9 +15,9 @@
#include <errno.h>
#include <unistd.h>
#include <string.h>
+#include <mm/hugepage_settings.h>
#include "kselftest.h"
-#include "hugepage_settings.h"
#define MAP_SIZE_MB 100
#define MAP_SIZE (MAP_SIZE_MB * 1024 * 1024)
diff --git a/tools/testing/selftests/mm/cow.c b/tools/testing/selftests/mm/cow.c
index 0c627ea89ff7..7c29d3d2d887 100644
--- a/tools/testing/selftests/mm/cow.c
+++ b/tools/testing/selftests/mm/cow.c
@@ -20,6 +20,7 @@
#include <sys/ioctl.h>
#include <sys/wait.h>
#include <linux/memfd.h>
+#include <mm/hugepage_settings.h>
#include "local_config.h"
#ifdef LOCAL_CONFIG_HAVE_LIBURING
@@ -29,7 +30,6 @@
#include "../../../../mm/gup_test.h"
#include "kselftest.h"
#include "vm_util.h"
-#include "hugepage_settings.h"
static size_t pagesize;
static int pagemap_fd;
diff --git a/tools/testing/selftests/mm/folio_split_race_test.c b/tools/testing/selftests/mm/folio_split_race_test.c
index 6329e37fff4c..ca9b95c39c16 100644
--- a/tools/testing/selftests/mm/folio_split_race_test.c
+++ b/tools/testing/selftests/mm/folio_split_race_test.c
@@ -23,9 +23,10 @@
#include <sys/mman.h>
#include <signal.h>
#include <unistd.h>
+#include <mm/hugepage_settings.h>
+
#include "vm_util.h"
#include "kselftest.h"
-#include "hugepage_settings.h"
uint64_t page_size;
uint64_t pmd_pagesize;
diff --git a/tools/testing/selftests/mm/guard-regions.c b/tools/testing/selftests/mm/guard-regions.c
index b21df3040b1c..ccca432c8802 100644
--- a/tools/testing/selftests/mm/guard-regions.c
+++ b/tools/testing/selftests/mm/guard-regions.c
@@ -20,8 +20,9 @@
#include <sys/syscall.h>
#include <sys/uio.h>
#include <unistd.h>
+#include <mm/hugepage_settings.h>
+
#include "vm_util.h"
-#include "hugepage_settings.h"
#include "../pidfd/pidfd.h"
diff --git a/tools/testing/selftests/mm/gup_longterm.c b/tools/testing/selftests/mm/gup_longterm.c
index eb8963e9d98f..0cfc67fc5c8f 100644
--- a/tools/testing/selftests/mm/gup_longterm.c
+++ b/tools/testing/selftests/mm/gup_longterm.c
@@ -20,6 +20,7 @@
#include <sys/vfs.h>
#include <linux/magic.h>
#include <linux/memfd.h>
+#include <mm/hugepage_settings.h>
#include "local_config.h"
#ifdef LOCAL_CONFIG_HAVE_LIBURING
@@ -29,7 +30,6 @@
#include "../../../../mm/gup_test.h"
#include "kselftest.h"
#include "vm_util.h"
-#include "hugepage_settings.h"
static size_t pagesize;
static int nr_hugetlbsizes;
diff --git a/tools/testing/selftests/mm/gup_test.c b/tools/testing/selftests/mm/gup_test.c
index 3f841a96f870..803ab829a841 100644
--- a/tools/testing/selftests/mm/gup_test.c
+++ b/tools/testing/selftests/mm/gup_test.c
@@ -12,9 +12,10 @@
#include <pthread.h>
#include <assert.h>
#include <mm/gup_test.h>
+#include <mm/hugepage_settings.h>
+
#include "kselftest.h"
#include "vm_util.h"
-#include "hugepage_settings.h"
#define MB (1UL << 20)
diff --git a/tools/testing/selftests/mm/hmm-tests.c b/tools/testing/selftests/mm/hmm-tests.c
index e1c8a679a4cf..b7f85a144f03 100644
--- a/tools/testing/selftests/mm/hmm-tests.c
+++ b/tools/testing/selftests/mm/hmm-tests.c
@@ -10,9 +10,6 @@
* bugs.
*/
-#include "kselftest_harness.h"
-#include "hugepage_settings.h"
-
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
@@ -27,6 +24,9 @@
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <sys/time.h>
+#include <mm/hugepage_settings.h>
+
+#include "kselftest_harness.h"
/*
* This is a private UAPI to the kernel test module so it isn't exported
diff --git a/tools/testing/selftests/mm/hugetlb-madvise.c b/tools/testing/selftests/mm/hugetlb-madvise.c
index 555b4b3d1430..8e18b5027904 100644
--- a/tools/testing/selftests/mm/hugetlb-madvise.c
+++ b/tools/testing/selftests/mm/hugetlb-madvise.c
@@ -12,9 +12,10 @@
#include <unistd.h>
#include <sys/mman.h>
#include <fcntl.h>
+#include <mm/hugepage_settings.h>
+
#include "vm_util.h"
#include "kselftest.h"
-#include "hugepage_settings.h"
#define MIN_FREE_PAGES 20
#define NR_HUGE_PAGES 10 /* common number of pages to map/allocate */
diff --git a/tools/testing/selftests/mm/hugetlb-mmap.c b/tools/testing/selftests/mm/hugetlb-mmap.c
index 0f2aad1b7dbd..12184c1889ad 100644
--- a/tools/testing/selftests/mm/hugetlb-mmap.c
+++ b/tools/testing/selftests/mm/hugetlb-mmap.c
@@ -16,9 +16,10 @@
#include <sys/mman.h>
#include <fcntl.h>
#include <linux/memfd.h>
+#include <mm/hugepage_settings.h>
+
#include "vm_util.h"
#include "kselftest.h"
-#include "hugepage_settings.h"
#define LENGTH (256UL*1024*1024)
#define PROTECTION (PROT_READ | PROT_WRITE)
diff --git a/tools/testing/selftests/mm/hugetlb-mremap.c b/tools/testing/selftests/mm/hugetlb-mremap.c
index d239905790dd..0b1a1fc9e766 100644
--- a/tools/testing/selftests/mm/hugetlb-mremap.c
+++ b/tools/testing/selftests/mm/hugetlb-mremap.c
@@ -24,9 +24,10 @@
#include <sys/ioctl.h>
#include <string.h>
#include <stdbool.h>
+#include <mm/hugepage_settings.h>
+
#include "kselftest.h"
#include "vm_util.h"
-#include "hugepage_settings.h"
#define DEFAULT_LENGTH_MB 10UL
#define MB_TO_BYTES(x) (x * 1024 * 1024)
diff --git a/tools/testing/selftests/mm/hugetlb-shm.c b/tools/testing/selftests/mm/hugetlb-shm.c
index 3ff7f062b7eb..25988f97057a 100644
--- a/tools/testing/selftests/mm/hugetlb-shm.c
+++ b/tools/testing/selftests/mm/hugetlb-shm.c
@@ -27,9 +27,9 @@
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/mman.h>
+#include <mm/hugepage_settings.h>
#include "vm_util.h"
-#include "hugepage_settings.h"
#define LENGTH (256UL*1024*1024)
diff --git a/tools/testing/selftests/mm/hugetlb-soft-offline.c b/tools/testing/selftests/mm/hugetlb-soft-offline.c
index bc202e4ed2bd..20864e7d4e0c 100644
--- a/tools/testing/selftests/mm/hugetlb-soft-offline.c
+++ b/tools/testing/selftests/mm/hugetlb-soft-offline.c
@@ -21,9 +21,9 @@
#include <sys/mman.h>
#include <sys/statfs.h>
#include <sys/types.h>
+#include <mm/hugepage_settings.h>
#include "kselftest.h"
-#include "hugepage_settings.h"
#ifndef MADV_SOFT_OFFLINE
#define MADV_SOFT_OFFLINE 101
diff --git a/tools/testing/selftests/mm/hugetlb-vmemmap.c b/tools/testing/selftests/mm/hugetlb-vmemmap.c
index 507df78a158d..ffecea89ffa1 100644
--- a/tools/testing/selftests/mm/hugetlb-vmemmap.c
+++ b/tools/testing/selftests/mm/hugetlb-vmemmap.c
@@ -10,8 +10,9 @@
#include <unistd.h>
#include <sys/mman.h>
#include <fcntl.h>
+#include <mm/hugepage_settings.h>
+
#include "vm_util.h"
-#include "hugepage_settings.h"
#define PAGE_COMPOUND_HEAD (1UL << 15)
#define PAGE_COMPOUND_TAIL (1UL << 16)
diff --git a/tools/testing/selftests/mm/hugetlb_dio.c b/tools/testing/selftests/mm/hugetlb_dio.c
index fb4600570e13..896c6e3c09da 100644
--- a/tools/testing/selftests/mm/hugetlb_dio.c
+++ b/tools/testing/selftests/mm/hugetlb_dio.c
@@ -18,9 +18,10 @@
#include <string.h>
#include <sys/mman.h>
#include <sys/syscall.h>
+#include <mm/hugepage_settings.h>
+
#include "vm_util.h"
#include "kselftest.h"
-#include "hugepage_settings.h"
#ifndef STATX_DIOALIGN
#define STATX_DIOALIGN 0x00002000U
diff --git a/tools/testing/selftests/mm/hugetlb_fault_after_madv.c b/tools/testing/selftests/mm/hugetlb_fault_after_madv.c
index 2dc158054f66..70e685f0b510 100644
--- a/tools/testing/selftests/mm/hugetlb_fault_after_madv.c
+++ b/tools/testing/selftests/mm/hugetlb_fault_after_madv.c
@@ -7,10 +7,10 @@
#include <unistd.h>
#include <setjmp.h>
#include <signal.h>
+#include <mm/hugepage_settings.h>
#include "vm_util.h"
#include "kselftest.h"
-#include "hugepage_settings.h"
#define INLOOP_ITER 100
diff --git a/tools/testing/selftests/mm/hugetlb_madv_vs_map.c b/tools/testing/selftests/mm/hugetlb_madv_vs_map.c
index f94549efcc6f..c8f6414e8a77 100644
--- a/tools/testing/selftests/mm/hugetlb_madv_vs_map.c
+++ b/tools/testing/selftests/mm/hugetlb_madv_vs_map.c
@@ -23,9 +23,9 @@
#include <sys/mman.h>
#include <sys/types.h>
#include <unistd.h>
+#include <mm/hugepage_settings.h>
#include "vm_util.h"
-#include "hugepage_settings.h"
#define INLOOP_ITER 100
diff --git a/tools/testing/selftests/mm/khugepaged.c b/tools/testing/selftests/mm/khugepaged.c
index ae5945e2bfac..9bf1f8744431 100644
--- a/tools/testing/selftests/mm/khugepaged.c
+++ b/tools/testing/selftests/mm/khugepaged.c
@@ -19,11 +19,11 @@
#include <sys/sysmacros.h>
#include <sys/vfs.h>
#include <mm/file_utils.h>
+#include <mm/hugepage_settings.h>
#include "linux/magic.h"
#include "vm_util.h"
-#include "hugepage_settings.h"
#define BASE_ADDR ((void *)(1UL << 30))
static unsigned long hpage_pmd_size;
diff --git a/tools/testing/selftests/mm/ksm_tests.c b/tools/testing/selftests/mm/ksm_tests.c
index a050f4840cfa..4fda799a148d 100644
--- a/tools/testing/selftests/mm/ksm_tests.c
+++ b/tools/testing/selftests/mm/ksm_tests.c
@@ -11,11 +11,11 @@
#include <fcntl.h>
#include <stdint.h>
#include <err.h>
+#include <mm/hugepage_settings.h>
#include "kselftest.h"
#include <include/vdso/time64.h>
#include "vm_util.h"
-#include "hugepage_settings.h"
#define KSM_SYSFS_PATH "/sys/kernel/mm/ksm/"
#define KSM_FP(s) (KSM_SYSFS_PATH s)
diff --git a/tools/testing/selftests/mm/migration.c b/tools/testing/selftests/mm/migration.c
index 29f7492453d4..c3e60ddcefa7 100644
--- a/tools/testing/selftests/mm/migration.c
+++ b/tools/testing/selftests/mm/migration.c
@@ -4,9 +4,6 @@
* paths in the kernel.
*/
-#include "kselftest_harness.h"
-#include "hugepage_settings.h"
-
#include <strings.h>
#include <pthread.h>
#include <numa.h>
@@ -16,6 +13,9 @@
#include <sys/types.h>
#include <signal.h>
#include <time.h>
+#include <mm/hugepage_settings.h>
+
+#include "kselftest_harness.h"
#include "vm_util.h"
#define TWOMEG (2<<20)
diff --git a/tools/testing/selftests/mm/pagemap_ioctl.c b/tools/testing/selftests/mm/pagemap_ioctl.c
index 762306177ad8..924308ead037 100644
--- a/tools/testing/selftests/mm/pagemap_ioctl.c
+++ b/tools/testing/selftests/mm/pagemap_ioctl.c
@@ -20,10 +20,10 @@
#include <assert.h>
#include <sys/ipc.h>
#include <sys/shm.h>
+#include <mm/hugepage_settings.h>
#include "vm_util.h"
#include "kselftest.h"
-#include "hugepage_settings.h"
#define PAGEMAP_BITS_ALL (PAGE_IS_WPALLOWED | PAGE_IS_WRITTEN | \
PAGE_IS_FILE | PAGE_IS_PRESENT | \
diff --git a/tools/testing/selftests/mm/prctl_thp_disable.c b/tools/testing/selftests/mm/prctl_thp_disable.c
index d8d9d1de57b8..db1807adf72e 100644
--- a/tools/testing/selftests/mm/prctl_thp_disable.c
+++ b/tools/testing/selftests/mm/prctl_thp_disable.c
@@ -12,9 +12,9 @@
#include <linux/mman.h>
#include <sys/prctl.h>
#include <sys/wait.h>
+#include <mm/hugepage_settings.h>
#include "kselftest_harness.h"
-#include "hugepage_settings.h"
#include "vm_util.h"
#ifndef PR_THP_DISABLE_EXCEPT_ADVISED
diff --git a/tools/testing/selftests/mm/protection_keys.c b/tools/testing/selftests/mm/protection_keys.c
index 9a6d954ee371..5ba2033e8a09 100644
--- a/tools/testing/selftests/mm/protection_keys.c
+++ b/tools/testing/selftests/mm/protection_keys.c
@@ -45,8 +45,8 @@
#include <unistd.h>
#include <sys/ptrace.h>
#include <setjmp.h>
+#include <mm/hugepage_settings.h>
-#include "hugepage_settings.h"
#include "pkey-helpers.h"
int iteration_nr = 1;
diff --git a/tools/testing/selftests/mm/soft-dirty.c b/tools/testing/selftests/mm/soft-dirty.c
index fb1864a68e1c..852cc0a9743f 100644
--- a/tools/testing/selftests/mm/soft-dirty.c
+++ b/tools/testing/selftests/mm/soft-dirty.c
@@ -6,10 +6,10 @@
#include <stdint.h>
#include <malloc.h>
#include <sys/mman.h>
+#include <mm/hugepage_settings.h>
#include "kselftest.h"
#include "vm_util.h"
-#include "hugepage_settings.h"
#define PAGEMAP_FILE_PATH "/proc/self/pagemap"
#define TEST_ITERATIONS 10000
diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c
index 4a2ccc055c8b..b4ff8ed0b446 100644
--- a/tools/testing/selftests/mm/split_huge_page_test.c
+++ b/tools/testing/selftests/mm/split_huge_page_test.c
@@ -20,10 +20,10 @@
#include <stdbool.h>
#include <time.h>
#include <mm/file_utils.h>
+#include <mm/hugepage_settings.h>
#include "vm_util.h"
#include "kselftest.h"
-#include "hugepage_settings.h"
uint64_t pagesize;
unsigned int pageshift;
diff --git a/tools/testing/selftests/mm/thuge-gen.c b/tools/testing/selftests/mm/thuge-gen.c
index 22b9c2f1c35d..5556a1b89393 100644
--- a/tools/testing/selftests/mm/thuge-gen.c
+++ b/tools/testing/selftests/mm/thuge-gen.c
@@ -12,9 +12,10 @@
#include <unistd.h>
#include <stdarg.h>
#include <string.h>
+#include <mm/hugepage_settings.h>
+
#include "vm_util.h"
#include "kselftest.h"
-#include "hugepage_settings.h"
#if !defined(MAP_HUGETLB)
#define MAP_HUGETLB 0x40000
diff --git a/tools/testing/selftests/mm/transhuge-stress.c b/tools/testing/selftests/mm/transhuge-stress.c
index 8eb0c5630e7e..ed78b2142ac1 100644
--- a/tools/testing/selftests/mm/transhuge-stress.c
+++ b/tools/testing/selftests/mm/transhuge-stress.c
@@ -15,9 +15,10 @@
#include <fcntl.h>
#include <string.h>
#include <sys/mman.h>
+#include <mm/hugepage_settings.h>
+
#include "vm_util.h"
#include "kselftest.h"
-#include "hugepage_settings.h"
int backing_fd = -1;
int mmap_flags = MAP_ANONYMOUS | MAP_NORESERVE | MAP_PRIVATE;
diff --git a/tools/testing/selftests/mm/uffd-common.h b/tools/testing/selftests/mm/uffd-common.h
index 92a21b97f745..b8e25a96381d 100644
--- a/tools/testing/selftests/mm/uffd-common.h
+++ b/tools/testing/selftests/mm/uffd-common.h
@@ -34,10 +34,10 @@
#include <stdint.h>
#include <sys/random.h>
#include <stdatomic.h>
+#include <mm/hugepage_settings.h>
#include "kselftest.h"
#include "vm_util.h"
-#include "hugepage_settings.h"
#define UFFD_FLAGS (O_CLOEXEC | O_NONBLOCK | UFFD_USER_MODE_ONLY)
diff --git a/tools/testing/selftests/mm/uffd-wp-mremap.c b/tools/testing/selftests/mm/uffd-wp-mremap.c
index 90ac410c6c6f..dcd7ac35deba 100644
--- a/tools/testing/selftests/mm/uffd-wp-mremap.c
+++ b/tools/testing/selftests/mm/uffd-wp-mremap.c
@@ -7,8 +7,9 @@
#include <assert.h>
#include <linux/mman.h>
#include <sys/mman.h>
+#include <mm/hugepage_settings.h>
+
#include "kselftest.h"
-#include "hugepage_settings.h"
#include "uffd-common.h"
static int pagemap_fd;
diff --git a/tools/testing/selftests/mm/va_high_addr_switch.c b/tools/testing/selftests/mm/va_high_addr_switch.c
index e24d7ba00b44..07fcb03316cc 100644
--- a/tools/testing/selftests/mm/va_high_addr_switch.c
+++ b/tools/testing/selftests/mm/va_high_addr_switch.c
@@ -8,10 +8,10 @@
#include <stdio.h>
#include <sys/mman.h>
#include <string.h>
+#include <mm/hugepage_settings.h>
#include "vm_util.h"
#include "kselftest.h"
-#include "hugepage_settings.h"
/*
* The hint addr value is used to allocate addresses
--
2.39.5
^ permalink raw reply related
* [PATCH v3 1/4] tools/lib/mm: add shared file helpers
From: Sarthak Sharma @ 2026-05-21 11:17 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand
Cc: Jonathan Corbet, Lorenzo Stoakes, Liam R . Howlett,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
Shuah Khan, Shuah Khan, Jason Gunthorpe, John Hubbard, Peter Xu,
Leon Romanovsky, Zi Yan, Baolin Wang, Nico Pache, Ryan Roberts,
Dev Jain, Barry Song, Lance Yang, Mark Brown, linux-kernel,
linux-mm, linux-kselftest, linux-doc, Sarthak Sharma
In-Reply-To: <20260521111801.173019-1-sarthak.sharma@arm.com>
Move read_file(), write_file(), read_num(), and write_num() out of
tools/testing/selftests/mm/vm_util.c into a new shared helper under
tools/lib/mm/.
These helpers are used by mm selftests today and will also be needed by
shared hugepage helpers in subsequent patches. Move them to a generic
location and drop the kselftest-specific dependency from their
implementation so they can be reused outside selftests as well.
Update the current mm selftest users to include the new header directly,
and link the new helper into the selftests/mm build.
Add tools/lib/mm/ to the MEMORY MANAGEMENT - MISC entry in MAINTAINERS.
Signed-off-by: Sarthak Sharma <sarthak.sharma@arm.com>
---
MAINTAINERS | 1 +
tools/lib/mm/file_utils.c | 83 +++++++++++++++++++
tools/lib/mm/file_utils.h | 12 +++
tools/testing/selftests/mm/Makefile | 6 +-
.../testing/selftests/mm/hugepage_settings.c | 3 +-
tools/testing/selftests/mm/khugepaged.c | 1 +
.../selftests/mm/split_huge_page_test.c | 2 +
tools/testing/selftests/mm/vm_util.c | 65 +--------------
tools/testing/selftests/mm/vm_util.h | 5 --
9 files changed, 106 insertions(+), 72 deletions(-)
create mode 100644 tools/lib/mm/file_utils.c
create mode 100644 tools/lib/mm/file_utils.h
diff --git a/MAINTAINERS b/MAINTAINERS
index 46ed0f0e76d8..7887a3263373 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -16936,6 +16936,7 @@ F: mm/memory-tiers.c
F: mm/page_idle.c
F: mm/pgalloc-track.h
F: mm/process_vm_access.c
+F: tools/lib/mm/
F: tools/testing/selftests/mm/
MEMORY MANAGEMENT - NUMA MEMBLOCKS AND NUMA EMULATION
diff --git a/tools/lib/mm/file_utils.c b/tools/lib/mm/file_utils.c
new file mode 100644
index 000000000000..0f9322f2cf41
--- /dev/null
+++ b/tools/lib/mm/file_utils.c
@@ -0,0 +1,83 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "file_utils.h"
+
+int read_file(const char *path, char *buf, size_t buflen)
+{
+ int fd;
+ ssize_t numread;
+
+ fd = open(path, O_RDONLY);
+ if (fd == -1)
+ return 0;
+
+ numread = read(fd, buf, buflen - 1);
+ if (numread < 1) {
+ close(fd);
+ return 0;
+ }
+
+ buf[numread] = '\0';
+ close(fd);
+
+ return (unsigned int)numread;
+}
+
+void write_file(const char *path, const char *buf, size_t buflen)
+{
+ int fd, saved_errno;
+ ssize_t numwritten;
+
+ if (buflen < 2) {
+ fprintf(stderr, "Incorrect buffer len: %zu\n", buflen);
+ exit(EXIT_FAILURE);
+ }
+
+ fd = open(path, O_WRONLY);
+ if (fd == -1) {
+ fprintf(stderr, "%s open failed: %s\n", path, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ numwritten = write(fd, buf, buflen - 1);
+ saved_errno = errno;
+ close(fd);
+ errno = saved_errno;
+ if (numwritten < 0) {
+ fprintf(stderr, "%s write(%.*s) failed: %s\n",
+ path, (int)(buflen - 1), buf, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+ if (numwritten != (ssize_t)(buflen - 1)) {
+ fprintf(stderr,
+ "%s write(%.*s) is truncated, expected %zu bytes, got %zd bytes\n",
+ path, (int)(buflen - 1), buf, buflen - 1, numwritten);
+ exit(EXIT_FAILURE);
+ }
+}
+
+unsigned long read_num(const char *path)
+{
+ char buf[21];
+
+ if (read_file(path, buf, sizeof(buf)) < 0) {
+ perror("read_file()");
+ exit(EXIT_FAILURE);
+ }
+
+ return strtoul(buf, NULL, 10);
+}
+
+void write_num(const char *path, unsigned long num)
+{
+ char buf[21];
+
+ snprintf(buf, sizeof(buf), "%lu", num);
+ write_file(path, buf, strlen(buf) + 1);
+}
diff --git a/tools/lib/mm/file_utils.h b/tools/lib/mm/file_utils.h
new file mode 100644
index 000000000000..060a84725c9d
--- /dev/null
+++ b/tools/lib/mm/file_utils.h
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __MM_FILE_UTILS_H__
+#define __MM_FILE_UTILS_H__
+
+#include <stddef.h>
+
+int read_file(const char *path, char *buf, size_t buflen);
+void write_file(const char *path, const char *buf, size_t buflen);
+unsigned long read_num(const char *path);
+void write_num(const char *path, unsigned long num);
+
+#endif
diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/mm/Makefile
index e6df968f0971..b5fb4b6ab31b 100644
--- a/tools/testing/selftests/mm/Makefile
+++ b/tools/testing/selftests/mm/Makefile
@@ -37,7 +37,7 @@ endif
# LDLIBS.
MAKEFLAGS += --no-builtin-rules
-CFLAGS = -Wall -O2 -I $(top_srcdir) $(EXTRA_CFLAGS) $(KHDR_INCLUDES) $(TOOLS_INCLUDES)
+CFLAGS = -Wall -O2 -I $(top_srcdir) -I $(top_srcdir)/tools/lib $(EXTRA_CFLAGS) $(KHDR_INCLUDES) $(TOOLS_INCLUDES)
CFLAGS += -Wunreachable-code
LDLIBS = -lrt -lpthread -lm
@@ -187,8 +187,8 @@ TEST_FILES += write_hugetlb_memory.sh
include ../lib.mk
-$(TEST_GEN_PROGS): vm_util.c hugepage_settings.c
-$(TEST_GEN_FILES): vm_util.c hugepage_settings.c
+$(TEST_GEN_PROGS): vm_util.c hugepage_settings.c $(top_srcdir)/tools/lib/mm/file_utils.c
+$(TEST_GEN_FILES): vm_util.c hugepage_settings.c $(top_srcdir)/tools/lib/mm/file_utils.c
$(OUTPUT)/uffd-stress: uffd-common.c
$(OUTPUT)/uffd-unit-tests: uffd-common.c
diff --git a/tools/testing/selftests/mm/hugepage_settings.c b/tools/testing/selftests/mm/hugepage_settings.c
index 2eab2110ac6a..5e947abb7425 100644
--- a/tools/testing/selftests/mm/hugepage_settings.c
+++ b/tools/testing/selftests/mm/hugepage_settings.c
@@ -8,8 +8,9 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <mm/file_utils.h>
-#include "vm_util.h"
+#include "kselftest.h"
#include "hugepage_settings.h"
#define THP_SYSFS "/sys/kernel/mm/transparent_hugepage/"
diff --git a/tools/testing/selftests/mm/khugepaged.c b/tools/testing/selftests/mm/khugepaged.c
index 10e8dedcb087..ae5945e2bfac 100644
--- a/tools/testing/selftests/mm/khugepaged.c
+++ b/tools/testing/selftests/mm/khugepaged.c
@@ -18,6 +18,7 @@
#include <sys/stat.h>
#include <sys/sysmacros.h>
#include <sys/vfs.h>
+#include <mm/file_utils.h>
#include "linux/magic.h"
diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c
index 50c80ceb4988..4a2ccc055c8b 100644
--- a/tools/testing/selftests/mm/split_huge_page_test.c
+++ b/tools/testing/selftests/mm/split_huge_page_test.c
@@ -19,6 +19,8 @@
#include <malloc.h>
#include <stdbool.h>
#include <time.h>
+#include <mm/file_utils.h>
+
#include "vm_util.h"
#include "kselftest.h"
#include "hugepage_settings.h"
diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c
index 311fc5b4513e..631dc2baff97 100644
--- a/tools/testing/selftests/mm/vm_util.c
+++ b/tools/testing/selftests/mm/vm_util.c
@@ -8,6 +8,8 @@
#include <linux/fs.h>
#include <sys/syscall.h>
#include <unistd.h>
+#include <mm/file_utils.h>
+
#include "kselftest.h"
#include "vm_util.h"
@@ -698,69 +700,6 @@ int unpoison_memory(unsigned long pfn)
return ret > 0 ? 0 : -errno;
}
-int read_file(const char *path, char *buf, size_t buflen)
-{
- int fd;
- ssize_t numread;
-
- fd = open(path, O_RDONLY);
- if (fd == -1)
- return 0;
-
- numread = read(fd, buf, buflen - 1);
- if (numread < 1) {
- close(fd);
- return 0;
- }
-
- buf[numread] = '\0';
- close(fd);
-
- return (unsigned int) numread;
-}
-
-void write_file(const char *path, const char *buf, size_t buflen)
-{
- int fd, saved_errno;
- ssize_t numwritten;
-
- if (buflen < 2)
- ksft_exit_fail_msg("Incorrect buffer len: %zu\n", buflen);
-
- fd = open(path, O_WRONLY);
- if (fd == -1)
- ksft_exit_fail_msg("%s open failed: %s\n", path, strerror(errno));
-
- numwritten = write(fd, buf, buflen - 1);
- saved_errno = errno;
- close(fd);
- errno = saved_errno;
- if (numwritten < 0)
- ksft_exit_fail_msg("%s write(%.*s) failed: %s\n", path, (int)(buflen - 1),
- buf, strerror(errno));
- if (numwritten != buflen - 1)
- ksft_exit_fail_msg("%s write(%.*s) is truncated, expected %zu bytes, got %zd bytes\n",
- path, (int)(buflen - 1), buf, buflen - 1, numwritten);
-}
-
-unsigned long read_num(const char *path)
-{
- char buf[21];
-
- if (read_file(path, buf, sizeof(buf)) < 0)
- ksft_exit_fail_perror("read_file()");
-
- return strtoul(buf, NULL, 10);
-}
-
-void write_num(const char *path, unsigned long num)
-{
- char buf[21];
-
- sprintf(buf, "%lu", num);
- write_file(path, buf, strlen(buf) + 1);
-}
-
static unsigned long shmall, shmmax;
void __shm_limits_restore(void)
diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h
index ea8fc8fdf0eb..d0932cdd9a34 100644
--- a/tools/testing/selftests/mm/vm_util.h
+++ b/tools/testing/selftests/mm/vm_util.h
@@ -164,11 +164,6 @@ int unpoison_memory(unsigned long pfn);
#define PAGEMAP_PRESENT(ent) (((ent) & (1ull << 63)) != 0)
#define PAGEMAP_PFN(ent) ((ent) & ((1ull << 55) - 1))
-void write_file(const char *path, const char *buf, size_t buflen);
-int read_file(const char *path, char *buf, size_t buflen);
-unsigned long read_num(const char *path);
-void write_num(const char *path, unsigned long num);
-
void shm_limits_prepare(unsigned long length);
void __shm_limits_restore(void);
--
2.39.5
^ permalink raw reply related
* [PATCH v3 0/4] selftests/mm: separate GUP microbenchmarking from functional testing
From: Sarthak Sharma @ 2026-05-21 11:17 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand
Cc: Jonathan Corbet, Lorenzo Stoakes, Liam R . Howlett,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
Shuah Khan, Shuah Khan, Jason Gunthorpe, John Hubbard, Peter Xu,
Leon Romanovsky, Zi Yan, Baolin Wang, Nico Pache, Ryan Roberts,
Dev Jain, Barry Song, Lance Yang, Mark Brown, linux-kernel,
linux-mm, linux-kselftest, linux-doc, Sarthak Sharma
gup_test.c currently serves two distinct purposes: microbenchmarking
(GUP_FAST_BENCHMARK, PIN_FAST_BENCHMARK, PIN_LONGTERM_BENCHMARK) and
functional correctness testing (GUP_BASIC_TEST, PIN_BASIC_TEST,
DUMP_USER_PAGES_TEST). Mixing these in a single binary means functional
tests cannot be run or reported individually and run_vmtests.sh must
invoke the binary multiple times with different flag combinations to
cover all configurations.
This patch series separates the two concerns: tools/mm/gup_bench for
benchmarking and tools/testing/selftests/mm/gup_test for functional
testing. To avoid duplicating HugeTLB and related file helpers, the
series first moves the common helper code to tools/lib/mm/ so it can be
shared by both selftests and tools/mm.
Patch 1 adds tools/lib/mm/file_utils.[ch], moving read_file(),
write_file(), read_num() and write_num() out of vm_util.c into a shared
helper without a kselftest dependency. It also adds tools/lib/mm/ to the
MEMORY MANAGEMENT - MISC entry in MAINTAINERS.
Patch 2 moves hugepage_settings.[ch] from selftests/mm to tools/lib/mm/,
updates the selftests/mm users to include it from there and removes the
remaining kselftest dependency from the implementation while dropping
non-fatal hugetlb informational prints from the shared helper.
Patch 3 adds tools/mm/gup_bench.c, a standalone microbenchmark for
GUP_FAST, PIN_FAST and PIN_LONGTERM via the CONFIG_GUP_TEST debugfs
interface. It runs the same matrix of configurations as the old
run_gup_matrix() shell function (all three commands, read/write,
private/shared, four page counts, THP on/off, hugetlb), but as a
standalone C program under tools/mm using the shared tools/lib/mm
helpers.
Patch 4 rewrites gup_test.c as a kselftest harness-based selftest. It
covers all five GUP kernel functions (get_user_pages, get_user_pages_fast,
pin_user_pages, pin_user_pages_fast, pin_user_pages with FOLL_LONGTERM)
plus DUMP_USER_PAGES_TEST, across 12 mapping configurations (THP on,
THP off and hugetlb, each across private/shared and read/write variants)
and four batch sizes (1, 512, 123, all pages). It also preserves the old
sparse dump coverage for pages 0, 19 and 0x1000. Results are reported as
standard TAP output with no command-line arguments required.
---
These patches apply on top of mm/mm-new.
Changes in v3:
- Address v2 feedback from Sashiko
- Add shared file_utils helpers under tools/lib/mm
- Move hugepage_settings out of selftests and into tools/lib/mm
- Convert gup_bench to use the shared tools/lib/mm helpers
- Guard against invalid thread counts in gup_bench
- Handle thread-array allocation failure cleanly in gup_bench
- Restore hugetlb settings on setup failure in gup_test
- Add sparse DUMP_USER_PAGES_TEST coverage for pages 0, 19 and 0x1000 in gup_test
Changes in v2:
- Address v1 feedback from Sashiko
- Add fast and longterm GUP/PUP coverage
- Sweep nr_pages_per_call over 1, 512, 123 and all pages
- Call madvise(MADV_NOHUGEPAGE) in non-THP variants
- Use 256 MB for hugetlb fixtures
- Use hugetlb_restore_settings() in FIXTURE_TEARDOWN instead of atexit()
- Add TH_LOG to report nr_pages_per_call for each iteration
- Update Documentation/core-api/pin_user_pages.rst unit testing section
Previous versions:
v2: https://lore.kernel.org/all/20260519120506.184512-1-sarthak.sharma@arm.com/
v1: https://lore.kernel.org/all/20260515084840.174652-1-sarthak.sharma@arm.com/
---
Sarthak Sharma (4):
tools/lib/mm: add shared file helpers
tools/lib/mm: move hugepage_settings out of selftests
tools/mm: add a standalone GUP microbenchmark
selftests/mm: rewrite gup_test as a standalone harness-based selftest
Documentation/core-api/pin_user_pages.rst | 12 +-
MAINTAINERS | 2 +
tools/lib/mm/file_utils.c | 83 +++
tools/lib/mm/file_utils.h | 12 +
.../selftests => lib}/mm/hugepage_settings.c | 14 +-
.../selftests => lib}/mm/hugepage_settings.h | 0
tools/mm/.gitignore | 2 +
tools/mm/Makefile | 10 +-
tools/mm/gup_bench.c | 390 ++++++++++++
tools/testing/selftests/mm/Makefile | 8 +-
tools/testing/selftests/mm/compaction_test.c | 2 +-
tools/testing/selftests/mm/cow.c | 2 +-
.../selftests/mm/folio_split_race_test.c | 3 +-
tools/testing/selftests/mm/guard-regions.c | 3 +-
tools/testing/selftests/mm/gup_longterm.c | 2 +-
tools/testing/selftests/mm/gup_test.c | 587 +++++++++++-------
tools/testing/selftests/mm/hmm-tests.c | 6 +-
tools/testing/selftests/mm/hugetlb-madvise.c | 3 +-
tools/testing/selftests/mm/hugetlb-mmap.c | 3 +-
tools/testing/selftests/mm/hugetlb-mremap.c | 3 +-
tools/testing/selftests/mm/hugetlb-shm.c | 2 +-
.../selftests/mm/hugetlb-soft-offline.c | 2 +-
tools/testing/selftests/mm/hugetlb-vmemmap.c | 3 +-
tools/testing/selftests/mm/hugetlb_dio.c | 3 +-
.../selftests/mm/hugetlb_fault_after_madv.c | 2 +-
.../selftests/mm/hugetlb_madv_vs_map.c | 2 +-
tools/testing/selftests/mm/khugepaged.c | 3 +-
tools/testing/selftests/mm/ksm_tests.c | 2 +-
tools/testing/selftests/mm/migration.c | 6 +-
tools/testing/selftests/mm/pagemap_ioctl.c | 2 +-
.../testing/selftests/mm/prctl_thp_disable.c | 2 +-
tools/testing/selftests/mm/protection_keys.c | 2 +-
tools/testing/selftests/mm/run_vmtests.sh | 37 +-
tools/testing/selftests/mm/soft-dirty.c | 2 +-
.../selftests/mm/split_huge_page_test.c | 4 +-
tools/testing/selftests/mm/thuge-gen.c | 3 +-
tools/testing/selftests/mm/transhuge-stress.c | 3 +-
tools/testing/selftests/mm/uffd-common.h | 2 +-
tools/testing/selftests/mm/uffd-wp-mremap.c | 3 +-
.../selftests/mm/va_high_addr_switch.c | 2 +-
tools/testing/selftests/mm/vm_util.c | 65 +-
tools/testing/selftests/mm/vm_util.h | 5 -
42 files changed, 935 insertions(+), 369 deletions(-)
create mode 100644 tools/lib/mm/file_utils.c
create mode 100644 tools/lib/mm/file_utils.h
rename tools/{testing/selftests => lib}/mm/hugepage_settings.c (98%)
rename tools/{testing/selftests => lib}/mm/hugepage_settings.h (100%)
create mode 100644 tools/mm/gup_bench.c
base-commit: 4c6512d033e5e9469cc76d07512c24a0ee0ac207
--
2.39.5
^ permalink raw reply
* [PATCH v7 7/8] docs/zh_CN: Add usbmon.rst translation
From: Kefan Bai @ 2026-05-21 9:55 UTC (permalink / raw)
To: linux-usb, si.yanteng
Cc: gregkh, seakeel, alexs, dzm91, corbet, skhan, linux-doc, doubled
In-Reply-To: <cover.1779355170.git.baikefan@leap-io-kernel.com>
Translate .../usb/usbmon.rst into Chinese
Update the translation through commit 788183a6e8b0
("docs: usb: fix literal block marker in usbmon verification example")
Reviewed-by: Yanteng Si <siyanteng@cqsoftware.com.cn>
Signed-off-by: Kefan Bai <baikefan@leap-io-kernel.com>
---
.../translations/zh_CN/usb/index.rst | 2 +-
.../translations/zh_CN/usb/usbmon.rst | 427 ++++++++++++++++++
2 files changed, 428 insertions(+), 1 deletion(-)
create mode 100644 Documentation/translations/zh_CN/usb/usbmon.rst
diff --git a/Documentation/translations/zh_CN/usb/index.rst b/Documentation/translations/zh_CN/usb/index.rst
index 8c6b26912320..eb5aca0c13ec 100644
--- a/Documentation/translations/zh_CN/usb/index.rst
+++ b/Documentation/translations/zh_CN/usb/index.rst
@@ -22,10 +22,10 @@ USB 支持
chipidea
dwc3
ehci
+ usbmon
Todolist:
-* usbmon
* functionfs
* functionfs-desc
* gadget_configfs
diff --git a/Documentation/translations/zh_CN/usb/usbmon.rst b/Documentation/translations/zh_CN/usb/usbmon.rst
new file mode 100644
index 000000000000..11b6d5b59dce
--- /dev/null
+++ b/Documentation/translations/zh_CN/usb/usbmon.rst
@@ -0,0 +1,427 @@
+.. SPDX-License-Identifier: GPL-2.0
+.. include:: ../disclaimer-zh_CN.rst
+
+:Original: Documentation/usb/usbmon.rst
+
+:翻译:
+
+ 白钶凡 Kefan Bai <baikefan@leap-io-kernel.com>
+
+:校译:
+
+
+======
+usbmon
+======
+
+简介
+====
+小写形式的 ``usbmon`` 指的是内核中的一项功能,
+用于收集 USB 总线上的 I/O 跟踪信息。它类似于网络监控工具
+``tcpdump(1)`` 或 Ethereal 所使用的数据包套接字。
+类似地,人们希望使用 usbdump 或 USBMon
+(首字母大写)之类的工具来检查
+usbmon 生成的原始跟踪数据。
+
+usbmon 报告的是各个外设驱动
+向主机控制器驱动(HCD)发出的请求。
+因此,如果 HCD 本身有 bug,那么 usbmon 报告的跟踪信息
+可能无法精确对应实际的总线事务。
+这和 tcpdump 的情况是一样的。
+
+目前实现了两种 API: ``text`` 和 ``binary``。
+二进制 API 通过 ``/dev`` 命名空间中的字符设备提供,
+并且属于 ABI。文本 API 自内核 2.6.35 起已废弃,
+但为了方便仍然可用。
+
+如何使用 usbmon 收集原始文本跟踪信息
+====================================
+
+与数据包套接字不同,usbmon 提供了一种接口,
+可以输出文本格式的跟踪信息。这样做有两个目的:
+第一,在更完善的格式最终确定之前,
+它作为工具间通用的跟踪交换格式;
+第二,在不使用工具的情况下,人们也可以直接阅读这些信息。
+
+要收集原始文本跟踪信息,请按以下步骤进行操作。
+
+1. 准备
+-------
+
+挂载 debugfs(内核配置中必须启用它),并加载 usbmon 模块
+(如果它是作为模块构建的)。如果 usbmon 已经编入内核,
+那么第二步可以省略。
+
+命令示例::
+
+ # mount -t debugfs none_debugs /sys/kernel/debug
+ # modprobe usbmon
+ #
+
+确认总线套接字是否存在::
+
+ # ls /sys/kernel/debug/usb/usbmon
+ 0s 0u 1s 1t 1u 2s 2t 2u 3s 3t 3u 4s 4t 4u
+ #
+
+现在,你可以选择使用 ``0u`` 捕获所有总线上的数据包,
+并跳到第 3 步;
+也可以先按第 2 步找到目标设备所在的总线。
+这样可以过滤掉那些持续输出数据的烦人设备。
+
+2. 查找目标设备连接的是哪条总线
+-------------------------------
+
+运行 ``cat /sys/kernel/debug/usb/devices``,
+找到对应设备的 T 行。通常可以通过厂商字符串来查找。
+如果有许多类似设备,可以拔掉其中一个,
+再比较前后两次 ``/sys/kernel/debug/usb/devices``
+的输出。T 行里会包含总线编号。
+
+示例::
+
+ T: Bus=03 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 2 Spd=12 MxCh= 0
+ D: Ver= 1.10 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1
+ P: Vendor=0557 ProdID=2004 Rev= 1.00
+ S: Manufacturer=ATEN
+ S: Product=UC100KM V2.00
+
+``Bus=03`` 表示它位于 3 号总线上。或者,
+也可以查看 ``lsusb`` 的输出,并从对应行得到总线编号。
+
+示例如下::
+
+ Bus 003 Device 002: ID 0557:2004 ATEN UC100KM V2.00
+
+
+3. 启动 cat 命令
+----------------
+
+如果只监听单条总线,可执行::
+
+ # cat /sys/kernel/debug/usb/usbmon/3u > /tmp/1.mon.out
+
+否则,如果要监听所有总线,则执行::
+
+ # cat /sys/kernel/debug/usb/usbmon/0u > /tmp/1.mon.out
+
+此进程会一直读取,直到被终止。
+由于输出通常会很长,因此更推荐将输出重定向到某个位置。
+
+
+4. 在 USB 总线上执行期望的操作
+------------------------------
+
+此处需要执行一些会产生 USB 流量的动作,
+比如插入 U 盘、拷贝文件、操作摄像头等。
+
+
+5. 停止 cat
+-----------
+
+这一步通常通过键盘中断(Control-C)完成。
+
+此时输出文件(本例中为 ``/tmp/1.mon.out``)
+可以保存、通过电子邮件发送,或使用文本编辑器查看。
+如果使用最后一种方式,请确保文件不会大到编辑器无法打开。
+
+
+原始文本数据格式
+================
+
+目前支持两种格式:原始格式,也就是 ``1t`` 格式,
+以及 ``1u`` 格式。``1t`` 格式在内核 2.6.21 中已被废弃。
+``1u`` 格式增加了一些字段,例如 ISO 帧描述符、
+``interval`` 等。它生成的行会稍长一些,
+但在其他方面是 ``1t`` 格式的完整超集。
+
+如果程序需要区分上述两种格式,
+可以查看 ``address`` 字段(见下文)。
+如果其中有两个冒号,就是 ``1t`` 格式;
+否则是 ``1u`` 格式。
+
+任何文本格式的数据由一系列事件组成,
+如 URB 提交、URB 回调、提交错误等。
+每个事件对应单独的一行文本,
+由使用空白符间隔的若干字段组成。
+字段的数量与位置可能取决于事件类型,
+但以下字段对所有类型都通用:
+
+下面按从左到右的顺序列出这些共有字段:
+
+- URB Tag。用于标识 URB,通常是 URB 结构体在内核中的地址
+ (以十六进制表示),
+ 但也可能是序号或其他合理的唯一字符串。
+
+- 时间戳(微秒),十进制数字。
+ 时间戳的精度取决于可用时钟,
+ 因此可能远差于
+ 1 微秒(例如实现使用的是 jiffies)。
+
+- 事件类型。它表示的是事件的格式,而不是 URB 的类型。
+ 可用值为:``S`` 表示提交,``C`` 表示回调,``E`` 表示提交错误。
+
+- ``Address`` 字段(以前称作 ``pipe``)。
+ 它包含四个由冒号分隔的字段:
+ URB 类型及方向、总线号、设备地址和端点号。类型与方向的编码如下:
+
+ == == ==========================
+ Ci Co 控制输入和输出
+ Zi Zo 等时输入和输出
+ Ii Io 中断输入和输出
+ Bi Bo 批量输入和输出
+ == == ==========================
+
+ 总线号、设备地址和端点号使用十进制,但可能有前导零。
+
+- URB 状态字段。这个字段要么是一个字母,
+ 要么是几个由冒号分隔的数字:
+ URB 状态、``interval``、``start frame`` 和 ``error count``。
+ 与 ``address`` 字段不同,除了状态外,其余字段都是可选的。
+ ``interval`` 只会为中断和等时 URB 打印;``start frame`` 只会为
+ 等时 URB 打印;错误计数只会在等时回调事件中打印。
+
+ 状态字段是一个十进制数字,有时为负数,
+ 对应 URB 的 ``status`` 字段。
+ 对于提交事件,这个字段本身没有实际意义,
+ 但为了便于脚本解析,它仍然存在。
+ 当发生错误时,该字段包含错误码。
+
+ 在提交控制包时,这个字段包含的是 ``Setup Tag``,
+ 而不是一组数字。
+ 判断 ``Setup Tag`` 是否存在很容易,因为它从来不是数字。
+ 因此,如果脚本在这个字段里发现的是一组数字,
+ 就会继续读取数据长度(等时 URB 除外)。
+ 如果发现的是其他内容,比如一个字母,
+ 那么脚本会先读取 ``Setup`` 包,再读取数据长度或等时描述符。
+
+- ``Setup`` 包由 5 个字段组成:
+ ``bmRequestType``、``bRequest``、``wValue``、
+ ``wIndex`` 和 ``wLength``。这些字段由 USB 2.0 规范定义。
+ 如果 ``Setup Tag`` 为 ``s``,就可以安全地解码这些字段。
+ 否则,说明 Setup 包虽然存在,但并未被捕获,此时各字段中会填入占位内容。
+
+- 等时传输帧描述符的数量及其内容:
+ 如果一个等时传输事件带有一组描述符,首先打印该 URB 中描述符的总数,
+ 然后为每个描述符打印一个字段,最多打印 5 个字段。
+ 每个字段由三个用冒号分隔的十进制数字组成,
+ 分别表示状态(status)、偏移(offset)和长度(length)。
+ 对于提交(submission),报告的是初始长度;
+ 对于回调(callback),报告的是实际长度。
+
+- 数据长度:
+ 对于提交,表示请求的长度;对于回调,表示实际传输的长度。
+
+- 数据标签:
+ 即使数据长度非零,usbmon 也不一定会捕获数据。
+ 仅当标签为 ``=`` 时,才会有数据字段。
+
+- 数据字段:
+ 以大端十六进制格式显示。注意,这些并不是真正的机器字,
+ 而只是把字节流拆成若干“字”以便阅读。因此最后一个字可能只包含
+ 1 到 4 个字节。
+ 收集的数据长度是有限的,可能小于数据长度字段中报告的值。
+ 因为数据长度字段只统计实际接收到的字节,而数据字段包含整个传输缓冲区,
+ 所以,在等时输入(Zi)完成且缓冲区中接收到的数据稀疏的情况下,
+ 收集的数据长度可能大于数据长度字段的值。
+
+
+
+示例:
+
+获取端口状态的输入控制传输::
+
+ d5ea89a0 3575914555 S Ci:1:001:0 s a3 00 0000 0003 0004 4 <
+ d5ea89a0 3575914560 C Ci:1:001:0 0 4 = 01050000
+
+向地址为 5 的存储设备发送
+31 字节 Bulk 包装的 SCSI 命令 ``0x28``
+(``READ_10``)的输出批量传输::
+
+ dd65f0e8 4128379752 S Bo:1:005:2 -115 31 = 55534243 ad000000 00800000 80010a28 20000000 20000040 00000000 000000
+ dd65f0e8 4128379808 C Bo:1:005:2 0 31 >
+
+原始二进制格式与 API
+====================
+API 的整体架构与前文大体相同,只是事件以二进制格式传递。
+每个事件都通过下面的结构发送
+(这个名字是为了叙述方便而虚构的)::
+
+
+ struct usbmon_packet {
+ u64 id; /* 0: URB ID - 从提交到回调 */
+ unsigned char type; /* 8: 与文本相同;可扩展 */
+ unsigned char xfer_type; /* ISO (0)、中断、控制、批量 (3) */
+ unsigned char epnum; /* 端点号和传输方向 */
+ unsigned char devnum; /* 设备地址 */
+ u16 busnum; /* 12: 总线号 */
+ char flag_setup; /* 14: 与文本相同 */
+ char flag_data; /* 15: 与文本相同;二进制零也可 */
+ s64 ts_sec; /* 16: gettimeofday */
+ s32 ts_usec; /* 24: gettimeofday */
+ int status; /* 28: */
+ unsigned int length; /* 32: 数据长度(提交或实际) */
+ unsigned int len_cap; /* 36: 已捕获的数据长度 */
+ union { /* 40: */
+ unsigned char setup[SETUP_LEN]; /* 仅用于控制类 S 事件 */
+ struct iso_rec { /* 仅用于 ISO */
+ int error_count;
+ int numdesc;
+ } iso;
+ } s;
+ int interval; /* 48: 仅用于中断和 ISO */
+ int start_frame; /* 52: 仅用于 ISO */
+ unsigned int xfer_flags; /* 56: URB 的 transfer_flags 副本 */
+ unsigned int ndesc; /* 60: 实际 ISO 描述符数量 */
+ }; /* 64 总长度 */
+
+可以用 ``read(2)``、``ioctl(2)``,
+或者通过 ``mmap`` 访问缓冲区,
+从字符设备接收这些事件。
+不过,出于兼容性原因,``read(2)``
+只返回前 48 个字节。
+
+字符设备通常命名为 ``/dev/usbmonN``,
+其中 ``N`` 是 USB 总线号。
+编号为零的设备(``/dev/usbmon0``)比较特殊,
+表示“所有总线”。
+请注意,具体命名策略由 Linux 发行版决定。
+
+如果你手动创建 ``/dev/usbmon0``,
+请确保它归 root 所有,并且权限为 ``0600``。
+否则,非特权用户将能够窃听键盘流量。
+
+以下 ``MON_IOC_MAGIC`` 为 ``0x92`` 的 ioctl 调用可用:
+
+``MON_IOCQ_URB_LEN``,定义为 ``_IO(MON_IOC_MAGIC, 1)``
+
+该调用返回下一个事件的数据长度。
+注意大多数事件不包含数据,
+因此如果该调用返回零,并不意味着没有事件。
+
+``MON_IOCG_STATS``,定义为
+``_IOR(MON_IOC_MAGIC, 3, struct mon_bin_stats)``
+
+参数是指向以下结构的指针::
+
+ struct mon_bin_stats {
+ u32 queued;
+ u32 dropped;
+ };
+
+成员 ``queued`` 表示当前缓冲区中已经排队的事件数量,
+而不是自上次重置以来处理过的事件数量。
+
+成员 ``dropped`` 表示自上次调用
+``MON_IOCG_STATS`` 以来丢失的事件数量。
+
+``MON_IOCT_RING_SIZE``,定义为 ``_IO(MON_IOC_MAGIC, 4)``
+
+此调用设置缓冲区大小。参数为以字节为单位的缓冲区大小。
+大小可能会向下取整到下一个块(或页)。
+如果请求的大小超出该内核的 [未指定] 范围,
+则调用会失败并返回 ``-EINVAL``。
+
+``MON_IOCQ_RING_SIZE``,定义为 ``_IO(MON_IOC_MAGIC, 5)``
+
+该调用返回缓冲区当前大小(以字节为单位)。
+
+``MON_IOCX_GET``,定义为
+``_IOW(MON_IOC_MAGIC, 6, struct mon_get_arg)``
+``MON_IOCX_GETX``,定义为
+``_IOW(MON_IOC_MAGIC, 10, struct mon_get_arg)``
+
+如果内核缓冲区中没有事件,
+这些调用就会一直等待,直到有事件到达,
+然后返回第一个事件。
+参数是指向以下结构的指针::
+
+ struct mon_get_arg {
+ struct usbmon_packet *hdr;
+ void *data;
+ size_t alloc; /* 数据长度可以为零 */
+ };
+
+
+调用前,应填好 ``hdr``、``data`` 和 ``alloc``。
+调用返回后,``hdr`` 指向的区域中包含下一个事件的结构;
+如果存在数据,那么数据缓冲区中也会包含相应数据。
+该事件会从内核缓冲区中移除。
+
+``MON_IOCX_GET`` 会将 48 字节的数据复制到 ``hdr`` 区域,
+``MON_IOCX_GETX`` 会复制 64 字节。
+
+``MON_IOCX_MFETCH``,定义为
+``_IOWR(MON_IOC_MAGIC, 7, struct mon_mfetch_arg)``
+
+当应用程序通过 ``mmap(2)`` 访问缓冲区时,
+主要使用这个 ioctl。
+其参数是指向以下结构的指针::
+
+ struct mon_mfetch_arg {
+ uint32_t *offvec; /* 获取的事件偏移向量 */
+ uint32_t nfetch; /* 要获取的事件数量(输出:已获取) */
+ uint32_t nflush; /* 要刷新的事件数量 */
+ };
+
+
+该 ioctl 的操作分为三个阶段:
+
+首先,从内核缓冲区移除并丢弃最多 ``nflush`` 个事件。
+实际丢弃的事件数量会写回 ``nflush``。
+
+其次,除非伪设备以 ``O_NONBLOCK`` 打开,否则会一直等待,
+直到缓冲区中出现事件。
+
+第三,将最多 ``nfetch`` 个偏移量提取到 mmap
+缓冲区,并存入 ``offvec`` 中。
+实际提取到的事件偏移数量会存回 ``nfetch``。
+
+``MON_IOCH_MFLUSH``,定义为 ``_IO(MON_IOC_MAGIC, 8)``
+
+此调用从内核缓冲区移除若干事件。
+其参数为要移除的事件数量。
+如果缓冲区中的事件少于请求数量,
+则移除所有事件,且不报告错误。
+当没有事件时也可使用。
+
+``FIONBIO``
+
+如果有需要,将来可能会实现 ``FIONBIO`` ioctl。
+
+除了 ``ioctl(2)`` 和 ``read(2)`` 之外,
+二进制 API 的特殊文件也可以用 ``select(2)`` 和
+``poll(2)`` 轮询。
+但 ``lseek(2)`` 不起作用。
+
+* 二进制 API 的内核缓冲区内存映射访问
+
+基本思想很简单:
+
+准备时,先获取当前大小,再用 ``mmap(2)`` 映射缓冲区。
+然后执行类似下面伪代码的循环::
+
+ struct mon_mfetch_arg fetch;
+ struct usbmon_packet *hdr;
+ int nflush = 0;
+ for (;;) {
+ fetch.offvec = vec; // 有 N 个 32 位字
+ fetch.nfetch = N; // 或者少于 N
+ fetch.nflush = nflush;
+ ioctl(fd, MON_IOCX_MFETCH, &fetch); // 同时处理错误
+ nflush = fetch.nfetch; // 完成后要刷新这么多包
+ for (i = 0; i < nflush; i++) {
+ hdr = (struct ubsmon_packet *) &mmap_area[vec[i]];
+ if (hdr->type == '@') // 填充包
+ continue;
+ caddr_t data = &mmap_area[vec[i]] + 64;
+ process_packet(hdr, data);
+ }
+ }
+
+
+
+因此,主要思想是每 N 个事件只执行一次 ioctl。
+
+虽然缓冲区是环形的,但返回的头和数据不会跨越缓冲区末端,
+因此上面的伪代码无需任何合并操作。
--
2.54.0
^ permalink raw reply related
* [PATCH v7 2/8] docs/zh_CN: Add acm.rst translation
From: Kefan Bai @ 2026-05-21 9:55 UTC (permalink / raw)
To: linux-usb, si.yanteng
Cc: gregkh, seakeel, alexs, dzm91, corbet, skhan, linux-doc, doubled
In-Reply-To: <cover.1779355170.git.baikefan@leap-io-kernel.com>
Translate .../usb/acm.rst into Chinese
Update the translation through commit ecefae6db042
("docs: usb: rename files to .rst and add them to drivers-api")
Reviewed-by: Yanteng Si <siyanteng@cqsoftware.com.cn>
Signed-off-by: Kefan Bai <baikefan@leap-io-kernel.com>
---
Documentation/translations/zh_CN/usb/acm.rst | 147 ++++++++++++++++++
.../translations/zh_CN/usb/index.rst | 2 +-
2 files changed, 148 insertions(+), 1 deletion(-)
create mode 100644 Documentation/translations/zh_CN/usb/acm.rst
diff --git a/Documentation/translations/zh_CN/usb/acm.rst b/Documentation/translations/zh_CN/usb/acm.rst
new file mode 100644
index 000000000000..51d6eb8f5660
--- /dev/null
+++ b/Documentation/translations/zh_CN/usb/acm.rst
@@ -0,0 +1,147 @@
+.. SPDX-License-Identifier: GPL-2.0
+.. include:: ../disclaimer-zh_CN.rst
+
+:Original: Documentation/usb/acm.rst
+
+:翻译:
+
+ 白钶凡 Kefan Bai <baikefan@leap-io-kernel.com>
+
+:校译:
+
+
+====================
+Linux ACM 驱动 v0.16
+====================
+
+版权所有 (c) 1999 Vojtech Pavlik <vojtech@suse.cz>
+
+由 SuSE 赞助
+
+0. 免责声明
+~~~~~~~~~~~
+本程序是自由软件;你可以在自由软件基金会发布的
+GNU 通用公共许可证第 2 版,或者(按你的选择)
+任何后续版本的条款下重新发布和/或修改它。
+
+发布本程序是希望它能发挥作用,但它不附带任何担保;
+甚至不包括对适销性或特定用途适用性的默示担保。
+详情见 GNU 通用公共许可证。
+
+你应该已经随本程序收到了 GNU 通用公共许可证的副本;
+如果没有,请致信:Free Software Foundation, Inc., 59
+Temple Place, Suite 330, Boston, MA 02111-1307 USA。
+
+如需联系作者,可发送电子邮件至 vojtech@suse.cz,
+或邮寄至:
+Vojtech Pavlik, Ucitelska 1576, Prague 8,
+182 00, Czech Republic。
+
+为方便起见,软件包中已附带 GNU 通用公共许可证
+第 2 版:见 COPYING 文件。
+
+1. 使用方法
+~~~~~~~~~~~
+``drivers/usb/class/cdc-acm.c`` 驱动可用于符合 USB
+通信设备类抽象控制模型(USB CDC ACM)规范的
+USB 调制解调器和 USB ISDN 终端适配器。
+
+许多调制解调器支持此驱动,以下是我所知道的一些型号:
+
+ - 3Com OfficeConnect 56k
+ - 3Com Voice FaxModem Pro
+ - 3Com Sportster
+ - MultiTech MultiModem 56k
+ - Zoom 2986L FaxModem
+ - Compaq 56k FaxModem
+ - ELSA Microlink 56k
+
+我知道有一款 ISDN 终端适配器可以与 ACM 驱动一起使用:
+
+ - 3Com USR ISDN Pro TA
+
+一些手机也可以通过 USB 连接。
+我知道以下机型可以正常工作:
+
+ - SonyEricsson K800i
+
+遗憾的是,许多调制解调器和大多数 ISDN TA
+都使用专有接口,因此无法与此驱动配合工作。
+购买前请先确认设备是否符合 ACM 规范。
+
+要使用这些调制解调器,需要加载以下模块::
+
+ usbcore.ko
+ uhci-hcd.ko ohci-hcd.ko or ehci-hcd.ko
+ cdc-acm.ko
+
+之后就应该可以访问这些调制解调器了。
+应当可以使用 ``minicom``、``ppp`` 和 ``mgetty``
+与它们通信。
+
+2. 验证驱动是否正常工作
+~~~~~~~~~~~~~~~~~~~~~~~
+
+第一步是检查 ``/sys/kernel/debug/usb/devices``,
+其内容应该类似如下::
+
+ T: Bus=01 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=12 MxCh= 2
+ B: Alloc= 0/900 us ( 0%), #Int= 0, #Iso= 0
+ D: Ver= 1.00 Cls=09(hub ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1
+ P: Vendor=0000 ProdID=0000 Rev= 0.00
+ S: Product=USB UHCI Root Hub
+ S: SerialNumber=6800
+ C:* #Ifs= 1 Cfg#= 1 Atr=40 MxPwr= 0mA
+ I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub
+ E: Ad=81(I) Atr=03(Int.) MxPS= 8 Ivl=255ms
+ T: Bus=01 Lev=01 Prnt=01 Port=01 Cnt=01 Dev#= 2 Spd=12 MxCh= 0
+ D: Ver= 1.00 Cls=02(comm.) Sub=00 Prot=00 MxPS= 8 #Cfgs= 2
+ P: Vendor=04c1 ProdID=008f Rev= 2.07
+ S: Manufacturer=3Com Inc.
+ S: Product=3Com U.S. Robotics Pro ISDN TA
+ S: SerialNumber=UFT53A49BVT7
+ C: #Ifs= 1 Cfg#= 1 Atr=60 MxPwr= 0mA
+ I: If#= 0 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=ff Driver=acm
+ E: Ad=85(I) Atr=02(Bulk) MxPS= 64 Ivl= 0ms
+ E: Ad=04(O) Atr=02(Bulk) MxPS= 64 Ivl= 0ms
+ E: Ad=81(I) Atr=03(Int.) MxPS= 16 Ivl=128ms
+ C:* #Ifs= 2 Cfg#= 2 Atr=60 MxPwr= 0mA
+ I: If#= 0 Alt= 0 #EPs= 1 Cls=02(comm.) Sub=02 Prot=01 Driver=acm
+ E: Ad=81(I) Atr=03(Int.) MxPS= 16 Ivl=128ms
+ I: If#= 1 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=acm
+ E: Ad=85(I) Atr=02(Bulk) MxPS= 64 Ivl= 0ms
+ E: Ad=04(O) Atr=02(Bulk) MxPS= 64 Ivl= 0ms
+
+这三行的存在很关键(以及 ``Cls=`` 字段里出现的
+``comm`` 和 ``data`` 类);它说明这是一个 ACM
+设备。``Driver=acm`` 表示该设备正在使用 acm 驱动。
+如果只看到 ``Cls=ff(vend.)``,那就无能为力了:
+这说明你手上的设备使用的是厂商专有接口::
+
+ D: Ver= 1.00 Cls=02(comm.) Sub=00 Prot=00 MxPS= 8 #Cfgs= 2
+ I: If#= 0 Alt= 0 #EPs= 1 Cls=02(comm.) Sub=02 Prot=01 Driver=acm
+ I: If#= 1 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=acm
+
+在系统日志中应该可以看到::
+
+ usb.c: USB new device connect, assigned device number 2
+ usb.c: kmalloc IF c7691fa0, numif 1
+ usb.c: kmalloc IF c7b5f3e0, numif 2
+ usb.c: skipped 4 class/vendor specific interface descriptors
+ usb.c: new device strings: Mfr=1, Product=2, SerialNumber=3
+ usb.c: USB device number 2 default language ID 0x409
+ Manufacturer: 3Com Inc.
+ Product: 3Com U.S. Robotics Pro ISDN TA
+ SerialNumber: UFT53A49BVT7
+ acm.c: probing config 1
+ acm.c: probing config 2
+ ttyACM0: USB ACM device
+ acm.c: acm_control_msg: rq: 0x22 val: 0x0 len: 0x0 result: 0
+ acm.c: acm_control_msg: rq: 0x20 val: 0x0 len: 0x7 result: 7
+ usb.c: acm driver claimed interface c7b5f3e0
+ usb.c: acm driver claimed interface c7b5f3f8
+ usb.c: acm driver claimed interface c7691fa0
+
+如果以上都正常,请启动 ``minicom``,
+把它配置为连接 ``ttyACM`` 设备,然后
+尝试输入 ``at``。如果返回 ``OK``,说明一切工作正常。
diff --git a/Documentation/translations/zh_CN/usb/index.rst b/Documentation/translations/zh_CN/usb/index.rst
index b4cb0ccaa39b..686e5b0a9384 100644
--- a/Documentation/translations/zh_CN/usb/index.rst
+++ b/Documentation/translations/zh_CN/usb/index.rst
@@ -17,10 +17,10 @@ USB 支持
.. toctree::
:maxdepth: 1
+ acm
Todolist:
-* acm
* authorization
* chipidea
* dwc3
--
2.54.0
^ permalink raw reply related
* [PATCH v7 0/8] Add Chinese translation for USB subsystem
From: Kefan Bai @ 2026-05-21 9:55 UTC (permalink / raw)
To: linux-usb, si.yanteng
Cc: gregkh, seakeel, alexs, dzm91, corbet, skhan, linux-doc, doubled
This patch set adds Chinese translations for the USB documentation.
This patch set adds Chinese translations for the USB documentation.
Many thanks to Alex Shi for the careful review and suggestions, and
apologies for the delay in sending this updated version.
Changes in v7:
- Applied the formatting cleanup suggested by Alex Shi across the
whole series.
- Reflowed the translated text for cleaner line alignment and
adjusted title/section adornments for consistency.
- No content changes beyond formatting cleanup.
Changes in v6:
- Rebased the series onto the latest docs-next branch in Jon's tree
(git://git.lwn.net/linux.git), as suggested by Alex Shi.
- Added the USB maintainers to the Cc list.
- Rechecked and polished the Chinese translations throughout the series.
- Link to v6: https://lore.kernel.org/linux-usb/cover.1778415392.git.baikefan@leap-io-kernel.com/
Changes in v5:
- Moved the index.rst entries for acm, authorization, chipidea, dwc3,
ehci, and usbmon into the corresponding patches so the series builds
cleanly when applied patch by patch.
- Removed extra spaces in chipidea.rst.
- Sent the series to linux-usb@vger.kernel.org for review by
Chinese-speaking developers, as suggested by Alex Shi and Yanteng Si.
- Link to v5: https://lore.kernel.org/linux-usb/cover.1765180570.git.baikefan@leap-io-kernel.com/
Changes in v4:
- Shortened overlong title underline and overline markers.
- Removed the CREDITS entry from index.rst.
- Link to v4: https://lore.kernel.org/all/cover.1764674650.git.baikefan@leap-io-kernel.com/
Changes in v3:
- Updated my sign-off to use my full legal name, as requested by
Jonathan Corbet.
- Reviewed and fixed the RST syntax issues noted by Alex Shi.
- Kept the number of translated files to eight to make submission and
review more manageable.
- Link to v3: https://lore.kernel.org/all/cover.1763984424.git.baikefan@leap-io-kernel.com/
Changes in v2:
- Updated [PATCH 01/25] docs/zh_CN: Add index.rst translation to include
the corresponding changes to
Documentation/translations/zh_CN/subsystem-apis.rst.
- Link to v2: https://lore.kernel.org/all/cover.1763897036.git.baikefan@leap-io-kernel.com/
v1:
- Link: https://lore.kernel.org/all/20251123074540.34161-1-baikefan@leap-io-kernel.com/
Kefan Bai (8):
docs/zh_CN: Add index.rst translation
docs/zh_CN: Add acm.rst translation
docs/zh_CN: Add authorization.rst translation
docs/zh_CN: Add chipidea.rst translation
docs/zh_CN: Add dwc3.rst translation
docs/zh_CN: Add ehci.rst translation
docs/zh_CN: Add usbmon.rst translation
docs/zh_CN: Add CREDITS translation
.../translations/zh_CN/subsystem-apis.rst | 2 +-
Documentation/translations/zh_CN/usb/CREDITS | 163 +++++++
Documentation/translations/zh_CN/usb/acm.rst | 147 ++++++
.../translations/zh_CN/usb/authorization.rst | 139 ++++++
.../translations/zh_CN/usb/chipidea.rst | 150 ++++++
Documentation/translations/zh_CN/usb/dwc3.rst | 63 +++
Documentation/translations/zh_CN/usb/ehci.rst | 261 +++++++++++
.../translations/zh_CN/usb/index.rst | 54 +++
.../translations/zh_CN/usb/usbmon.rst | 427 ++++++++++++++++++
9 files changed, 1405 insertions(+), 1 deletion(-)
create mode 100644 Documentation/translations/zh_CN/usb/CREDITS
create mode 100644 Documentation/translations/zh_CN/usb/acm.rst
create mode 100644 Documentation/translations/zh_CN/usb/authorization.rst
create mode 100644 Documentation/translations/zh_CN/usb/chipidea.rst
create mode 100644 Documentation/translations/zh_CN/usb/dwc3.rst
create mode 100644 Documentation/translations/zh_CN/usb/ehci.rst
create mode 100644 Documentation/translations/zh_CN/usb/index.rst
create mode 100644 Documentation/translations/zh_CN/usb/usbmon.rst
--
2.54.0
^ permalink raw reply
* Re: [PATCH v2] Fail the build on RUST=y and RUST_IS_AVAILABLE=n
From: Neal Gompa @ 2026-05-21 10:14 UTC (permalink / raw)
To: Sasha Finkelstein
Cc: Alice Ryhl, Andreas Hindborg, Benno Lossin, Björn Roy Baron,
Boqun Feng, Danilo Krummrich, Gary Guo, Jonathan Corbet,
Miguel Ojeda, Shuah Khan, Trevor Gross, linux-doc, linux-kernel,
rust-for-linux
In-Reply-To: <20260521-evolve-to-crab-v2-1-c18e0e98fc54@chaosmail.tech>
On Thu, May 21, 2026 at 4:32 AM Sasha Finkelstein <k@chaosmail.tech> wrote:
>
> The current approach of silently disabling all rust drivers if the
> toolchain is missing results in users that try to compile their own
> kernels getting a "successful" build and then being confused about where
> did their drivers go. In comparison, missing openssl results in a build
> failure, not a disappearance of everything that depends on it.
>
> This also means that allyesconfig will depend on rust, but since the
> rust experiment concluded with "rust is here to stay", i believe that
> allyesconfig should be building rust drivers too.
>
> Signed-off-by: Sasha Finkelstein <k@chaosmail.tech>
> ---
> Changes in v2:
> - No longer a RFC, let's make it happen.
> - Update the docs.
> - Link to v1: https://patch.msgid.link/20260510-evolve-to-crab-v1-1-208df84e67be@chaosmail.tech
> ---
> Documentation/rust/quick-start.rst | 6 +++---
> init/Kconfig | 1 -
> 2 files changed, 3 insertions(+), 4 deletions(-)
>
At this point, yes, we should just go ahead and do this.
Reviewed-by: Neal Gompa <neal@gompa.dev>
--
真実はいつも一つ!/ Always, there's only one truth!
^ permalink raw reply
* [PATCH v7 4/8] docs/zh_CN: Add chipidea.rst translation
From: Kefan Bai @ 2026-05-21 9:55 UTC (permalink / raw)
To: linux-usb, si.yanteng
Cc: gregkh, seakeel, alexs, dzm91, corbet, skhan, linux-doc, doubled
In-Reply-To: <cover.1779355170.git.baikefan@leap-io-kernel.com>
Translate .../usb/chipidea.rst into Chinese
Update the translation through commit e4157519ad46
("Documentation: usb: correct spelling")
Reviewed-by: Yanteng Si <siyanteng@cqsoftware.com.cn>
Signed-off-by: Kefan Bai <baikefan@leap-io-kernel.com>
---
.../translations/zh_CN/usb/chipidea.rst | 150 ++++++++++++++++++
.../translations/zh_CN/usb/index.rst | 2 +-
2 files changed, 151 insertions(+), 1 deletion(-)
create mode 100644 Documentation/translations/zh_CN/usb/chipidea.rst
diff --git a/Documentation/translations/zh_CN/usb/chipidea.rst b/Documentation/translations/zh_CN/usb/chipidea.rst
new file mode 100644
index 000000000000..ea0dc3043189
--- /dev/null
+++ b/Documentation/translations/zh_CN/usb/chipidea.rst
@@ -0,0 +1,150 @@
+.. SPDX-License-Identifier: GPL-2.0
+.. include:: ../disclaimer-zh_CN.rst
+
+:Original: Documentation/usb/chipidea.rst
+
+:翻译:
+
+ 白钶凡 Kefan Bai <baikefan@leap-io-kernel.com>
+
+:校译:
+
+
+=============================
+ChipIdea 高速双角色控制器驱动
+=============================
+
+1. 如何测试 OTG FSM(HNP 和 SRP)
+---------------------------------
+
+下面以两块 Freescale i.MX6Q Sabre SD 开发板为例,
+说明如何通过 sysfs 输入文件演示 OTG 的 HNP 和 SRP 功能。
+
+1.1 如何使能 OTG FSM
+--------------------
+
+1.1.1 在 ``menuconfig`` 中选择 ``CONFIG_USB_OTG_FSM``,并重新编译内核
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+重新构建内核镜像和模块。如果想查看 OTG FSM 的
+一些内部变量,可以挂载 ``debugfs``;其中有两个文件
+可以显示 OTG FSM 变量以及部分控制器寄存器的值::
+
+ cat /sys/kernel/debug/ci_hdrc.0/otg
+ cat /sys/kernel/debug/ci_hdrc.0/registers
+
+1.1.2 在控制器节点对应的 ``dts`` 文件中添加以下条目
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+::
+
+ otg-rev = <0x0200>;
+ adp-disable;
+
+1.2 测试步骤
+------------
+
+1) 给两块 Freescale i.MX6Q Sabre SD 开发板上电,
+ 并加载 gadget 类驱动(例如 ``g_mass_storage``)。
+
+2) 用 USB 线连接两块开发板:
+ 一端是 micro A 插头,另一端是 micro B 插头。
+
+ 插入 micro A 插头的一端是 A 设备,它应枚举另一端的 B 设备。
+
+3) 角色切换
+
+ 在 B 设备上执行::
+
+ echo 1 > /sys/bus/platform/devices/ci_hdrc.0/inputs/b_bus_req
+
+ B 设备应接管主机角色并枚举 A 设备。
+
+4) A 设备切回主机角色
+
+ 在 B 设备上执行::
+
+ echo 0 > /sys/bus/platform/devices/ci_hdrc.0/inputs/b_bus_req
+
+ 或者,通过引入 HNP 轮询,B 端主机可以知道
+ A 端外设希望切换为主机角色,因此这次角色切换
+ 也可以通过 A 端外设响应 B 端主机的轮询,
+ 在 A 侧触发。
+ 这可以通过在 A 设备上执行下面的命令来完成::
+
+ echo 1 > /sys/bus/platform/devices/ci_hdrc.0/inputs/a_bus_req
+
+ A 设备应切回主机角色并枚举 B 设备。
+
+5) 拔掉 B 设备(拔掉 micro B 插头),
+ 并在 10 秒内重新插入;
+ A 设备应重新枚举 B 设备。
+
+6) 拔掉 B 设备(拔掉 micro B 插头),
+ 并在 10 秒后重新插入;
+ A 设备不应重新枚举 B 设备。
+
+ 如果 A 设备希望使用总线:
+
+ 在 A 设备上执行::
+
+ echo 0 > /sys/bus/platform/devices/ci_hdrc.0/inputs/a_bus_drop
+ echo 1 > /sys/bus/platform/devices/ci_hdrc.0/inputs/a_bus_req
+
+ 如果 B 设备希望使用总线:
+
+ 在 B 设备上执行::
+
+ echo 1 > /sys/bus/platform/devices/ci_hdrc.0/inputs/b_bus_req
+
+7) A 设备关闭总线供电
+
+ 在 A 设备上执行::
+
+ echo 1 > /sys/bus/platform/devices/ci_hdrc.0/inputs/a_bus_drop
+
+ A 设备应断开与 B 设备的连接,并关闭总线供电。
+
+8) B 设备发出 SRP 数据脉冲
+
+ 在 B 设备上执行::
+
+ echo 1 > /sys/bus/platform/devices/ci_hdrc.0/inputs/b_bus_req
+
+ A 设备应恢复 USB 总线并枚举 B 设备。
+
+1.3 参考文档
+------------
+《On-The-Go and Embedded Host Supplement
+to the USB Revision 2.0 Specification
+July 27, 2012 Revision 2.0 version 1.1a》
+
+2. 如何将 USB 用作系统唤醒源
+----------------------------
+下面是在 i.MX6 平台上把 USB 用作系统唤醒源的示例。
+
+2.1 使能核心控制器的唤醒功能::
+
+ echo enabled > /sys/bus/platform/devices/ci_hdrc.0/power/wakeup
+
+2.2 使能 glue 层的唤醒功能::
+
+ echo enabled > /sys/bus/platform/devices/2184000.usb/power/wakeup
+
+2.3 使能 PHY 的唤醒功能(可选)::
+
+ echo enabled > /sys/bus/platform/devices/20c9000.usbphy/power/wakeup
+
+2.4 使能根集线器的唤醒功能::
+
+ echo enabled > /sys/bus/usb/devices/usb1/power/wakeup
+
+2.5 使能相关设备的唤醒功能::
+
+ echo enabled > /sys/bus/usb/devices/1-1/power/wakeup
+
+如果系统只有一个 USB 端口,
+而你希望在该端口上启用 USB 唤醒功能,
+可以使用下面的脚本::
+
+ for i in $(find /sys -name wakeup | grep usb);do echo enabled > $i;done;
diff --git a/Documentation/translations/zh_CN/usb/index.rst b/Documentation/translations/zh_CN/usb/index.rst
index 3480966fee19..e6d0a4fceff7 100644
--- a/Documentation/translations/zh_CN/usb/index.rst
+++ b/Documentation/translations/zh_CN/usb/index.rst
@@ -19,10 +19,10 @@ USB 支持
acm
authorization
+ chipidea
Todolist:
-* chipidea
* dwc3
* ehci
* usbmon
--
2.54.0
^ permalink raw reply related
* Re: [PATCH net-next v3 03/14] libeth: allow to create fill queues without NAPI
From: Larysa Zaremba @ 2026-05-21 10:07 UTC (permalink / raw)
To: Jakub Kicinski
Cc: Tony Nguyen, davem, pabeni, edumazet, andrew+netdev, netdev,
Pavan Kumar Linga, przemyslaw.kitszel, aleksander.lobakin,
sridhar.samudrala, anjali.singhai, michal.swiatkowski,
maciej.fijalkowski, emil.s.tantilov, joshua.a.hay, jacob.e.keller,
jayaprakash.shanmugam, jiri, horms, corbet, richardcochran,
linux-doc, Bharath R, Samuel Salin
In-Reply-To: <20260520184922.34c36c74@kernel.org>
On Wed, May 20, 2026 at 06:49:22PM -0700, Jakub Kicinski wrote:
> On Fri, 15 May 2026 15:44:27 -0700 Tony Nguyen wrote:
> > +int libeth_rx_fq_create(struct libeth_fq *fq, void *napi_dev)
>
> Why do you have to pass an opaque void pointer?
> Just add another arg for dev.
I agree that having type safety would be nice. But firstly, napi and dev are
mutually exclusive, and secondly, call sites would look pretty ugly, unless we
add a macro on top.
>
> int libeth_rx_fq_create(struct libeth_fq *fq, struct napi_struct *napi,
> struct device *dev)
> {
> struct page_pool_params pp = {
> .flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV,
> .order = LIBETH_RX_PAGE_ORDER,
> .pool_size = fq->count,
> .nid = fq->nid,
> - .dev = napi->dev->dev.parent,
> - .netdev = napi->dev,
> + .dev = dev ? dev : napi->dev->dev.parent,
> + .netdev = napi ? napi->dev : NULL,
^ permalink raw reply
* [PATCH v7 6/8] docs/zh_CN: Add ehci.rst translation
From: Kefan Bai @ 2026-05-21 9:55 UTC (permalink / raw)
To: linux-usb, si.yanteng
Cc: gregkh, seakeel, alexs, dzm91, corbet, skhan, linux-doc, doubled
In-Reply-To: <cover.1779355170.git.baikefan@leap-io-kernel.com>
Translate .../usb/ehci.rst into Chinese
Update the translation through commit 570eb861243c
("docs: usb: replace some characters")
Reviewed-by: Yanteng Si <siyanteng@cqsoftware.com.cn>
Signed-off-by: Kefan Bai <baikefan@leap-io-kernel.com>
---
Documentation/translations/zh_CN/usb/ehci.rst | 261 ++++++++++++++++++
.../translations/zh_CN/usb/index.rst | 2 +-
2 files changed, 262 insertions(+), 1 deletion(-)
create mode 100644 Documentation/translations/zh_CN/usb/ehci.rst
diff --git a/Documentation/translations/zh_CN/usb/ehci.rst b/Documentation/translations/zh_CN/usb/ehci.rst
new file mode 100644
index 000000000000..e05e493a30d3
--- /dev/null
+++ b/Documentation/translations/zh_CN/usb/ehci.rst
@@ -0,0 +1,261 @@
+.. SPDX-License-Identifier: GPL-2.0
+.. include:: ../disclaimer-zh_CN.rst
+
+:Original: Documentation/usb/ehci.rst
+
+:翻译:
+
+ 白钶凡 Kefan Bai <baikefan@leap-io-kernel.com>
+
+:校译:
+
+
+=========
+EHCI 驱动
+=========
+
+2002年12月27日
+
+EHCI 驱动用于通过支持 USB 2.0 的主机控制器
+硬件与高速 USB 2.0 设备通信。USB 2.0 兼容
+USB 1.1 标准,它定义了三种传输速率:
+
+ - “高速”(High Speed)480 Mbit/sec(60 MByte/sec)
+ - “全速”(Full Speed)12 Mbit/sec(1.5 MByte/sec)
+ - “低速”(Low Speed)1.5 Mbit/sec
+
+USB 1.1 仅支持全速与低速。
+高速设备可以在 USB 1.1 系统上使用,
+但速度会降到 USB 1.1 的速率。
+
+USB 1.1 设备也可以在 USB 2.0 系统上使用。当它们
+插入 EHCI 控制器时,会被交由 USB 1.1 的伴随
+(companion)控制器处理,该控制器通常是 OHCI 或 UHCI。
+
+当 USB 1.1 设备插入 USB 2.0 集线器时,它们通过
+集线器中的事务转换器(Transaction Translator,TT)
+与 EHCI 控制器交互,该转换器将低速或全速事务转换为
+高速分割事务,从而避免浪费传输带宽。
+
+截至本文撰写时,该驱动已在以下 EHCI 实现上成功运行
+(按字母顺序):Intel、NEC、Philips 和 VIA。
+其他供应商的 EHCI 实现正在陆续问世;
+预计该驱动在这些实现上也可正常运行。
+
+自 2001 年年中起,usb-storage 设备就已可用
+(在 2.4 版该驱动上速度相当不错),
+集线器则直到 2001 年底才开始可用,而其他类型的高速设备
+似乎要等到更多系统内置 USB 2.0 后才会出现。
+这类新系统从 2002 年初开始上市,
+并在 2002 年下半年变得更加常见。
+
+注意,USB 2.0 支持并不只是 EHCI 本身。
+它还需要对 Linux-USB 核心 API 作出其他修改,
+包括 hub 驱动;不过这些修改并不需要真正改变
+暴露给 USB 设备驱动的基本 ``usbcore`` API。
+
+- David Brownell
+ <dbrownell@users.sourceforge.net>
+
+
+功能
+====
+
+该驱动会定期在 x86 硬件上进行测试,
+也已在 PPC 硬件上使用,因此大小端问题应当已经解决。
+因此可以认为,它已经处理好了所有必要的 PCI 细节,
+所以即便在 DMA 映射有些特殊的系统上,
+I/O 也应能正常运行。
+
+传输类型
+--------
+
+截至本文撰写时,该驱动应当已经能够很好地处理
+所有控制传输、批量传输和中断传输,
+包括通过 USB 2.0 集线器中的事务转换器
+与 USB 1.1 设备通信;但仍可能存在 bug。
+
+高速等时(ISO)传输支持也已可用,但截至本文撰写时,
+还没有 Linux 驱动使用这项支持。
+
+目前尚不支持通过事务转换器实现全速等时传输。
+需要注意,ISO 传输的 split transaction 支持
+与高速 ISO 传输几乎无法共用代码,
+因为 EHCI 用不同的数据结构表示它们。
+因此,目前大多数 USB 音频和视频设备
+还不能通过高速总线连接使用。
+
+驱动行为
+--------
+
+所有类型的传输都可以排队。
+这意味着来自一个接口驱动的控制传输
+(或通过 usbfs 发出的控制传输)不会干扰
+另一个驱动的控制传输,而且中断传输可以使用 1 帧的周期,
+而不必担心中断处理开销导致的数据丢失。
+
+
+EHCI 根集线器代码会将 USB 1.1 设备移交给其伴随控制器。
+该驱动不需要了解那些驱动的任何细节;
+一个原本就能正常工作的 OHCI 或 UHCI 驱动,
+并不会因为 EHCI 驱动也存在而需要更改。
+
+电源管理方面还有一些问题;
+当前挂起/恢复的行为还不完全正确。
+
+此外,在调度周期性事务
+(中断和等时传输)时还采取了一些简化处理。
+这些简化会限制可调度的周期性事务数量,
+并且无法使用小于一帧的轮询间隔。
+
+使用方式
+========
+
+假设有一个 EHCI 控制器(位于 PCI 卡或主板上),
+并且已将此驱动编译为模块,可这样加载::
+
+ # modprobe ehci-hcd
+
+卸载方式::
+
+ # rmmod ehci-hcd
+
+还应加载一个伴随控制器驱动,
+例如 ``ohci-hcd`` 或 ``uhci-hcd``。
+如果 EHCI 驱动出现任何问题,只需卸载它的模块,
+随后该伴随控制器驱动就会接手
+此前由 EHCI 驱动处理的所有设备
+(但速度会降低)。
+
+模块参数(传给 ``modprobe``)包括:
+
+ log2_irq_thresh(默认值 0):
+ 默认中断延迟的 log2 值,单位是微帧。默认值 0 表示 1 个微帧
+ (125 微秒)。最大值 6 表示 2^6 = 64 个微帧。
+ 该值控制 EHCI 控制器发出中断的频率。
+
+如果在 2.5 内核上使用此驱动,并且启用了 USB 调试支持,
+则会在任一 EHCI 控制器的 ``sysfs`` 目录中看到三个文件:
+
+ ``async``
+ 转储异步调度,用于控制传输和批量传输。它会显示每个活动的 ``qh``
+ 以及待处理的 ``qtd``,通常每个 ``urb`` 对应一个 ``qtd``。
+ (可以在 ``usb-storage`` 做磁盘 I/O 时看它;顺便观察请求队列!)
+
+ ``periodic``
+ 转储周期性调度,用于中断传输和等时传输。不显示 ``qtd``。
+
+ ``registers``
+ 显示控制器寄存器状态。
+
+这些文件的内容有助于定位驱动问题。
+
+
+设备驱动通常不需要关心自己是否运行在 EHCI 之上,
+但它们可能想检查
+``usb_device->speed == USB_SPEED_HIGH``。
+高速设备能做到全速(或低速)设备做不到的事,
+例如高带宽的周期性传输(中断或 ISO 传输)。
+另外,设备描述符中的某些值
+(例如周期性传输的轮询间隔)
+在高速模式下使用不同的编码方式。
+
+不过,一定要让设备驱动经过 USB 2.0 集线器的测试。
+当使用事务转换器时,这些集线器报告某些故障
+(例如断开连接)的方式会不同;
+已经见过一些驱动在遇到与 OHCI 或 UHCI
+所报告的不同故障时表现不佳。
+
+性能
+====
+
+USB 2.0 吞吐量主要受两个因素制约:
+主机控制器处理请求的速度,以及设备响应这些请求的速度。
+480 Mbit/sec 的“原始传输率”对所有设备都成立,
+但总吞吐量还会受到诸如单个高速包之间的延迟、
+驱动是否足够聪明,以及系统整体负载等因素的影响。
+延迟也是性能考量因素。
+
+批量传输最常用于关注吞吐量的场景。
+需要记住的是,批量传输总是以 512 字节包为单位,
+而一个 USB 2.0 微帧中最多只能容纳 13 个这样的包。
+8 个 USB 2.0 微帧构成一个 USB 1.1 帧;
+一个微帧的时长是 1 毫秒 / 8 = 125 微秒。
+
+因此,只要硬件和设备驱动软件都允许,
+批量传输可提供超过 50 MByte/sec 的带宽。
+周期性传输模式(等时和中断)允许使用更大的包大小,
+从而可以逼近所宣称的 480 Mbit/sec 传输率。
+
+硬件性能
+--------
+
+截至本文撰写时,单个 USB 2.0 设备的最大传输速率
+通常约为 20 MByte/sec。
+这当然会随着时间改变:一些设备现在更快,一些更慢。
+
+第一代 NEC EHCI 实现似乎存在
+大约 28 MByte/sec 的硬件瓶颈。
+虽然这对单个 20 MByte/sec 的设备显然已经够用,
+但把三个这样的设备挂到同一总线上,
+并不能得到 60 MByte/sec。
+问题似乎在于控制器硬件无法并发进行 USB 与 PCI 访问,
+因此它每个微帧只会尝试 6 次(也许是 7 次)
+USB 事务,而不是 13 次。
+(对一个比其他产品早上市一年的芯片来说,
+这是个合理的妥协!)
+
+
+预计较新的实现会在这方面做得更好,
+通过投入更多芯片面积来解决这个问题,
+使新的主板芯片组更接近 60 MByte/sec 的目标。
+这既包括 NEC 的更新实现,也包括其他厂商的芯片。
+
+
+主机从 EHCI 控制器收到“请求已完成”中断的最小延迟
+为一个微帧(125 微秒)。该延迟可以调节;
+驱动提供了一个模块选项。默认情况下,
+``ehci-hcd`` 使用最小延迟,这意味着当发出一个控制
+或批量请求时,通常可以在不到 250 微秒内得知它已完成
+(具体取决于传输大小)。
+
+软件性能
+--------
+
+即便只是要达到 20 MByte/sec 的传输速率,
+Linux-USB 设备驱动也必须让 EHCI 队列始终保持满载。
+这意味着要发出较大的请求,
+或者在需要发出一连串小请求时使用批量请求排队。
+如果驱动未做到这一点,那么会直接从性能结果上表现出来。
+
+
+在典型情况下,使用 ``usb_bulk_msg()``
+以 4 KB 块循环写出,
+会浪费超过一半的 USB 2.0 带宽。
+I/O 完成与驱动发出下一次请求之间的延迟,
+通常会比一次 I/O 本身耗时更长。
+如果同样的循环改用 16 KB 块,会好一些;
+若使用一连串 128 KB 块,则浪费会少得多。
+
+
+但与其依赖这么大的 I/O 缓冲区来让同步 I/O 高效,
+不如直接向主机控制器排入多个(批量)请求,
+然后等待它们全部完成(或在出错时取消)。
+这种 URB 排队方式对所有 USB 1.1
+主机控制器驱动也同样适用。
+
+
+在 Linux 2.5 内核中,定义了新的 ``usb_sg_*()`` API;
+它们会把 scatterlist 中的所有缓冲区都排入队列。
+它们还使用 scatterlist 的 DMA 映射
+(其中可能应用 IOMMU)并减少中断次数,
+这些都有助于让高速传输尽可能快地运行。
+
+待办:
+ 中断传输和等时(ISO)传输的性能问题。
+ 这些周期性传输都是完全调度的,因此,主要问题可能在于如何触发高带宽模式。
+
+待办:
+ 通过 ``sysfs`` 中的 ``uframe_periodic_max`` 参数,
+ 可以分配超过标准 80% 的周期性带宽。
+ 后续将对此进行说明。
diff --git a/Documentation/translations/zh_CN/usb/index.rst b/Documentation/translations/zh_CN/usb/index.rst
index 7c739627077b..8c6b26912320 100644
--- a/Documentation/translations/zh_CN/usb/index.rst
+++ b/Documentation/translations/zh_CN/usb/index.rst
@@ -21,10 +21,10 @@ USB 支持
authorization
chipidea
dwc3
+ ehci
Todolist:
-* ehci
* usbmon
* functionfs
* functionfs-desc
--
2.54.0
^ permalink raw reply related
* [PATCH v7 8/8] docs/zh_CN: Add CREDITS translation
From: Kefan Bai @ 2026-05-21 9:55 UTC (permalink / raw)
To: linux-usb, si.yanteng
Cc: gregkh, seakeel, alexs, dzm91, corbet, skhan, linux-doc, doubled
In-Reply-To: <cover.1779355170.git.baikefan@leap-io-kernel.com>
Translate .../usb/CREDITS into Chinese
Update the translation through commit 7b2328c5a009
("docs: Fix typo in usb/CREDITS")
Reviewed-by: Yanteng Si <siyanteng@cqsoftware.com.cn>
Signed-off-by: Kefan Bai <baikefan@leap-io-kernel.com>
---
Documentation/translations/zh_CN/usb/CREDITS | 163 +++++++++++++++++++
1 file changed, 163 insertions(+)
create mode 100644 Documentation/translations/zh_CN/usb/CREDITS
diff --git a/Documentation/translations/zh_CN/usb/CREDITS b/Documentation/translations/zh_CN/usb/CREDITS
new file mode 100644
index 000000000000..c133b1a5daff
--- /dev/null
+++ b/Documentation/translations/zh_CN/usb/CREDITS
@@ -0,0 +1,163 @@
+.. SPDX-License-Identifier: GPL-2.0
+.. include:: ../disclaimer-zh_CN.rst
+
+:Original: Documentation/usb/CREDITS
+
+:翻译:
+
+ 白钶凡 Kefan Bai <baikefan@leap-io-kernel.com>
+
+:校译:
+
+
+简易 Linux USB 驱动的致谢名单:
+
+以下人员都为 Linux USB 驱动代码作出了贡献
+(按姓氏字母顺序排列)。我相信这份名单本应
+更长一些,但确实不容易维护。
+如需将自己加入名单,请提交补丁。
+
+ Georg Acher <acher@informatik.tu-muenchen.de>
+ David Brownell <dbrownell@users.sourceforge.net>
+ Alan Cox <alan@lxorguk.ukuu.org.uk>
+ Randy Dunlap <randy.dunlap@intel.com>
+ Johannes Erdfelt <johannes@erdfelt.com>
+ Deti Fliegl <deti@fliegl.de>
+ ham <ham@unsuave.com>
+ Bradley M Keryan <keryan@andrew.cmu.edu>
+ Greg Kroah-Hartman <greg@kroah.com>
+ Pavel Machek <pavel@suse.cz>
+ Paul Mackerras <paulus@cs.anu.edu.au>
+ Petko Manlolov <petkan@dce.bg>
+ David E. Nelson <dnelson@jump.net>
+ Vojtech Pavlik <vojtech@suse.cz>
+ Bill Ryder <bryder@sgi.com>
+ Thomas Sailer <sailer@ife.ee.ethz.ch>
+ Gregory P. Smith <greg@electricrain.com>
+ Linus Torvalds <torvalds@linux-foundation.org>
+ Roman Weissgaerber <weissg@vienna.at>
+ <Kazuki.Yasumatsu@fujixerox.co.jp>
+
+特别感谢:
+
+ Inaky Perez Gonzalez <inaky@peloncho.fis.ucm.es>
+ 感谢他发起了 Linux USB 驱动开发工作,并编写了体量较大的 uusbd
+ 驱动中的大部分代码。我们从那项工作中学到了很多。
+
+ NetBSD 和 FreeBSD 的 USB 开发者们
+ 感谢他们加入 Linux USB 邮件列表,提供建议并分享实现经验。
+
+附加感谢:
+ 还要感谢以下公司与个人在硬件、支持、时间投入和开发方面提供的捐赠与帮助
+ (摘自 Inaky 驱动原始的 THANKS 文件):
+
+ 以下公司曾帮助我们开发 Linux USB / UUSBD:
+
+ - 3Com GmbH 捐赠了一台 ISDN Pro TA,并在技术问题和测试设备方面为我
+ 提供支持。没想到能得到这么大的帮助。
+
+ - USAR Systems 向我们提供了他们出色的 USB 评估套件,
+ 使我们能够测试 Linux USB 驱动对最新 USB 规范的符合性。
+ USAR Systems 认识到保持开放操作系统与时俱进的重要性,
+ 并以硬件支持这个项目。感谢!
+
+ - 感谢英特尔提供的宝贵帮助。
+
+ - 我们与 Cherry 合作,使 Linux 成为首个内置 USB 支持的操作系统。
+ Cherry 是全球最大的键盘制造商之一。
+
+ - CMD Technology, Inc. 慷慨捐赠了一块 CSA-6700 PCI-to-USB
+ 控制卡,用于测试 OHCI 实现。
+
+ - 由于他们对我们的支持,Keytronic 可以放心,
+ 他们的键盘能卖给至少 300 万 Linux 用户中的一部分。
+
+ - ing büro h doran [http://www.ibhdoran.com]!
+ 在欧洲,想给主板买一个 PC 背板 USB 连接器几乎是不可能的
+ (我自己做的那个相当糟糕 :))。现在我知道该去哪里买漂亮的 USB
+ 配件了!
+
+ - Genius Germany 捐赠了一只 USB 鼠标,用于测试鼠标启动协议;
+ 他们还捐赠了 F-23 数字摇杆和 NetMouse Pro。感谢!
+
+ - AVM GmbH Berlin 支持我们开发 Linux 下的 AVM ISDN Controller B1 USB 驱动。
+ AVM 是领先的 ISDN 控制器制造商,其主动式设计对包括 Linux 在内的
+ 所有操作系统平台开放。
+
+ - 非常感谢 Y-E Data, Inc 捐赠的 FlashBuster-U USB 软驱,
+ 使我们能够测试批量传输代码。
+
+ - 感谢 Logitech 捐赠了一只三轴 USB 鼠标。
+
+ Logitech 负责设计、制造并销售各种人机接口设备,
+ 在键盘、鼠标、轨迹球、摄像头、扬声器,以及面向游戏和专业用途的
+ 控制设备方面拥有悠久历史和丰富经验。
+
+ 作为这些设备广为人知的供应商和销售商,他们捐赠了 USB 鼠标、
+ 摇杆和扫描仪,以表明 Linux 的重要性,也让 Logitech 的客户
+ 能在自己喜欢的操作系统上获得支持,并让所有 Linux 用户都能使用
+ Logitech 以及其他 USB 硬件。
+
+ Logitech 也是 1999 年 2 月 11 日维也纳 Linux 大会的官方赞助商,
+ 我们将在会上展示 Linux USB 工作的最新进展。
+
+ - 感谢 CATC 提供 USB Inspector,帮助我们揭开 UHCI 内部实现中
+ 那些不为人知的角落。
+
+ - 感谢 Entrega 为开发工作提供 PCI 转 USB 卡、集线器和转换器产品。
+
+ - 感谢 ConnectTech 提供 WhiteHEAT USB 转串口转换器以及相关文档,
+ 让这个驱动得以写成。
+
+ - 感谢 ADMtek 提供 Pegasus 和 Pegasus II 评估板、规格说明,
+ 以及驱动开发过程中的宝贵建议。
+
+ 另外还要感谢以下个人(嘿,顺序不分先后 :))
+
+ - Oren Tirosh <orenti@hishome.net>,
+ 他非常耐心地听我唠叨各种 USB 疑问,还给了很多很酷的想法。
+
+ - Jochen Karrer <karrer@wpfd25.physik.uni-wuerzburg.de>,
+ 指出了致命 bug,并给出了宝贵建议。
+
+ - Edmund Humemberger <ed@atnet.at>,他在公共关系与项目管理方面
+ 为 Linux-USB 项目付出了巨大的努力。
+
+ - Alberto Menegazzi <flash@flash.iol.it> 正在着手编写 UUSBD 文档,加油!
+
+ - Ric Klaren <ia_ric@cs.utwente.nl> 编写了很好的入门文档,
+ 与 Alberto 的作品形成良性竞争:)。
+
+ - Christian Groessler <cpg@aladdin.de>,感谢他在那些棘手细节上的帮助。
+
+ - Paul MacKerras 改进了 OHCI 实现,推动了对 iMac 的支持,
+ 并提供了大量的改进意见。
+
+ - Fernando Herrera <fherrera@eurielec.etsit.upm.es>
+ 负责撰写、维护并不断补充那份期待已久、独一无二又精彩的
+ UUSBD FAQ!太棒了!
+
+ - Rasca Gmelch <thron@gmx.de> 重新启用了 raw 驱动,
+ 指出了一些错误,并启动了 uusbd-utils 软件包。
+
+ - Peter Dettori <dettori@ozy.dec.com>,像疯了一样挖掘 bug,
+ 还提出了很多很酷的建议,太棒了!
+
+ - 自由软件与 Linux 社区的所有成员,包括 FSF、GNU 项目、
+ MIT X 联盟、TeX 社区等等,谢谢你们!
+
+ - 特别感谢 Richard Stallman 创造了 Emacs!
+
+ - 感谢 linux-usb 邮件列表的所有成员,读了那么多邮件——不开玩笑了,
+ 感谢你们提出的所有建议!
+
+ - 感谢 USB Implementers Forum 成员们的帮助与支持。
+
+ - Nathan Myers <ncm@cantrip.org>,感谢他的建议!
+ (希望你喜欢 Cibeles 的派对。)
+
+ - 感谢 Linus Torvalds 创建、开发并管理 Linux。
+
+ - Mike Smith、Craig Keithley、Thierry Giron 和 Janet Schank
+ 感谢他们让我认识到标准 USB 集线器其实也没那么“标准”,
+ 这有助于我们在标准集线器驱动中加入厂商特定的特殊处理。
--
2.54.0
^ permalink raw reply related
* [PATCH v7 5/8] docs/zh_CN: Add dwc3.rst translation
From: Kefan Bai @ 2026-05-21 9:55 UTC (permalink / raw)
To: linux-usb, si.yanteng
Cc: gregkh, seakeel, alexs, dzm91, corbet, skhan, linux-doc, doubled
In-Reply-To: <cover.1779355170.git.baikefan@leap-io-kernel.com>
Translate .../usb/dwc3.rst into Chinese
Update the translation through commit ecefae6db042
("docs: usb: rename files to .rst and add them to drivers-api")
Reviewed-by: Yanteng Si <siyanteng@cqsoftware.com.cn>
Signed-off-by: Kefan Bai <baikefan@leap-io-kernel.com>
---
Documentation/translations/zh_CN/usb/dwc3.rst | 63 +++++++++++++++++++
.../translations/zh_CN/usb/index.rst | 2 +-
2 files changed, 64 insertions(+), 1 deletion(-)
create mode 100644 Documentation/translations/zh_CN/usb/dwc3.rst
diff --git a/Documentation/translations/zh_CN/usb/dwc3.rst b/Documentation/translations/zh_CN/usb/dwc3.rst
new file mode 100644
index 000000000000..3468ce50c5ba
--- /dev/null
+++ b/Documentation/translations/zh_CN/usb/dwc3.rst
@@ -0,0 +1,63 @@
+.. SPDX-License-Identifier: GPL-2.0
+.. include:: ../disclaimer-zh_CN.rst
+
+:Original: Documentation/usb/dwc3.rst
+
+:翻译:
+
+ 白钶凡 Kefan Bai <baikefan@leap-io-kernel.com>
+
+:校译:
+
+
+=========
+DWC3 驱动
+=========
+
+
+待办
+~~~~
+
+阅读时如果想顺手认领点任务,可以从下面挑一项 :)
+
+- 将中断处理程序改为每个端点各自使用线程化 IRQ
+
+ 事实证明,有些 DWC3 命令大约需要 ``~1 ms`` 才能完成。
+ 当前代码会一直自旋等待命令完成,这种设计并不好。
+
+ 实现思路:
+
+ - DWC 核心实现了一个按端点对中断进行解复用的 IRQ 控制器。
+ 中断号在探测(``probe``)阶段分配,并归属于该设备。
+ 如果硬件通过 ``MSI`` 为每个端点提供独立中断,
+ 那么这个“虚拟”IRQ 控制器就可以被真实的端点中断取代。
+
+ - 在调用 ``usb_ep_enable()`` 时请求并分配中断资源,
+ 在调用 ``usb_ep_disable()`` 时释放中断资源。
+ 最坏情况下需要 32 个中断,最少是 ``ep0/1`` 的两个中断。
+ - ``dwc3_send_gadget_ep_cmd()`` 将在 ``wait_for_completion_timeout()``
+ 中休眠,直到命令完成。
+ - 中断处理程序分为以下几个部分:
+
+ - 设备级主中断处理程序
+ 遍历每个事件,并对其调用 ``generic_handle_irq()``。
+ 从 ``generic_handle_irq()`` 返回后,确认事件计数器,使中断最终消失。
+
+ - 设备级线程化处理程序
+ 无。
+
+ - 端点中断的主处理程序
+ 读取事件并尽量处理它。凡是需要睡眠的操作都交给线程处理。
+ 事件保存在每个端点的数据结构中。
+ 还要注意,一旦把某项工作交给线程处理,
+ 就不要再在主处理程序里处理它,
+ 以免出现优先级反转之类的问题。
+
+ - 端点中断的线程化处理程序
+ 处理剩余的端点工作,这些工作可能会睡眠,例如等待命令完成。
+
+ 延迟:
+
+ 不应增加延迟,因为中断线程具有较高优先级,
+ 会在普通用户态任务之前运行
+ (除非用户更改了调度优先级)。
diff --git a/Documentation/translations/zh_CN/usb/index.rst b/Documentation/translations/zh_CN/usb/index.rst
index e6d0a4fceff7..7c739627077b 100644
--- a/Documentation/translations/zh_CN/usb/index.rst
+++ b/Documentation/translations/zh_CN/usb/index.rst
@@ -20,10 +20,10 @@ USB 支持
acm
authorization
chipidea
+ dwc3
Todolist:
-* dwc3
* ehci
* usbmon
* functionfs
--
2.54.0
^ permalink raw reply related
* Re: [PATCH bpf-next v11 0/8] bpf: Extend the bpf_list family of APIs
From: patchwork-bot+netdevbpf @ 2026-05-21 10:00 UTC (permalink / raw)
To: Kaitao Cheng
Cc: ast, corbet, martin.lau, daniel, andrii, eddyz87, song,
yonghong.song, john.fastabend, kpsingh, sdf, haoluo, jolsa, shuah,
chengkaitao, skhan, memxor, bpf, linux-kernel, linux-doc, vmalik,
linux-kselftest
In-Reply-To: <20260521032306.97118-1-kaitao.cheng@linux.dev>
Hello:
This series was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:
On Thu, 21 May 2026 11:22:58 +0800 you wrote:
> In BPF, a list can only be used to implement a stack structure.
> Due to an incomplete API set, only FIFO or LIFO operations are
> supported. The patches enhance the BPF list API, making it more
> list-like.
>
> Five new kfuncs have been added:
> bpf_list_del: remove a node from the list
> bpf_list_add_impl: insert a node after a given list node
> bpf_list_is_first: check if a node is the first in the list
> bpf_list_is_last: check if a node is the last in the list
> bpf_list_empty: check if the list is empty
>
> [...]
Here is the summary with links:
- [bpf-next,v11,1/8] bpf: refactor __bpf_list_del to take list node pointer
https://git.kernel.org/bpf/bpf-next/c/cb339ac61d72
- [bpf-next,v11,2/8] bpf: clear list node owner and unlink before drop
https://git.kernel.org/bpf/bpf-next/c/cfa6afa4b931
- [bpf-next,v11,3/8] bpf: allow non-owning list-node args via __nonown_allowed
https://git.kernel.org/bpf/bpf-next/c/7c8c71591b76
- [bpf-next,v11,4/8] bpf: Introduce the bpf_list_del kfunc.
https://git.kernel.org/bpf/bpf-next/c/187baa10963a
- [bpf-next,v11,5/8] bpf: refactor __bpf_list_add to take insertion point via **prev_ptr
https://git.kernel.org/bpf/bpf-next/c/e6919ff67c1e
- [bpf-next,v11,6/8] bpf: Add bpf_list_add to insert node after a given list node
https://git.kernel.org/bpf/bpf-next/c/a3493ca504f1
- [bpf-next,v11,7/8] bpf: add bpf_list_is_first/last/empty kfuncs
https://git.kernel.org/bpf/bpf-next/c/745515d386eb
- [bpf-next,v11,8/8] selftests/bpf: Add test cases for bpf_list_del/add/is_first/is_last/empty
https://git.kernel.org/bpf/bpf-next/c/ba3dc064f406
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply
* Re: [PATCH v6 21/43] KVM: SEV: Make 'uaddr' parameter optional for KVM_SEV_SNP_LAUNCH_UPDATE
From: Fuad Tabba @ 2026-05-21 9:55 UTC (permalink / raw)
To: ackerleytng
Cc: aik, andrew.jones, binbin.wu, brauner, chao.p.peng, david,
ira.weiny, jmattson, jthoughton, michael.roth, oupton,
pankaj.gupta, qperret, rick.p.edgecombe, rientjes, shivankg,
steven.price, willy, wyihan, yan.y.zhao, forkloop, pratyush,
suzuki.poulose, aneesh.kumar, liam, Paolo Bonzini,
Sean Christopherson, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin, Steven Rostedt,
Masami Hiramatsu, Mathieu Desnoyers, Jonathan Corbet, Shuah Khan,
Shuah Khan, Vishal Annapurve, Andrew Morton, Chris Li,
Kairui Song, Kemeng Shi, Nhat Pham, Baoquan He, Barry Song,
Axel Rasmussen, Yuanchu Xie, Wei Xu, Youngjun Park, Qi Zheng,
Shakeel Butt, Kiryl Shutsemau, Jason Gunthorpe, Vlastimil Babka,
kvm, linux-kernel, linux-trace-kernel, linux-doc, linux-kselftest,
linux-mm, linux-coco
In-Reply-To: <20260507-gmem-inplace-conversion-v6-21-91ab5a8b19a4@google.com>
Hi,
On Thu, 7 May 2026 at 21:22, Ackerley Tng via B4 Relay
<devnull+ackerleytng.google.com@kernel.org> wrote:
>
> From: Michael Roth <michael.roth@amd.com>
>
> For vm_memory_attributes=1, in-place conversion/population is not
> supported, so the initial contents necessarily must need to come
> from a separate src address, which is enforced by the current
> implementation. However, for vm_memory_attributes=0, it is possible for
> guest memory to be initialized directly from userspace by mmap()'ing the
> guest_memfd and writing to it while the corresponding GPA ranges are in
> a 'shared' state before converting them to the 'private' state expected
> by KVM_SEV_SNP_LAUNCH_UPDATE.
>
> Update the handling/documentation for KVM_SEV_SNP_LAUNCH_UPDATE to allow
> for 'uaddr' to be set to NULL when vm_memory_attributes=0, which
> SNP_LAUNCH_UPDATE will then use to determine when it should/shouldn't
> copy in data from a separate memory location. Continue to enforce
> non-NULL for the original vm_memory_attributes=1 case.
>
> Signed-off-by: Michael Roth <michael.roth@amd.com>
> [Added src_page check in error handling path when the firmware command fails]
> [Dropped ifdef CONFIG_KVM_VM_MEMORY_ATTRIBUTES]
> Signed-off-by: Ackerley Tng <ackerleytng@google.com>
I'm not very familiar with the SEV-SNP populate flows, but it looks
like Sashiko is on to something:
https://sashiko.dev/#/patchset/20260507-gmem-inplace-conversion-v6-0-91ab5a8b19a4%40google.com?part=21
- a potential read-only page overwrite, because src_page is acquired
via get_user_pages_fast() without the FOLL_WRITE flag, but is then
overwritten via memcpy
- an ordering violation with the kunmap_local() calls
These predate this patch series and are just being touched by the
'src_page' addition, but if Sashiko's right, these should probably be
fixed sooner rather than later.
Cheers,
/fuad
> ---
> Documentation/virt/kvm/x86/amd-memory-encryption.rst | 15 +++++++++++----
> arch/x86/kvm/svm/sev.c | 18 +++++++++++++-----
> virt/kvm/kvm_main.c | 1 +
> 3 files changed, 25 insertions(+), 9 deletions(-)
>
> diff --git a/Documentation/virt/kvm/x86/amd-memory-encryption.rst b/Documentation/virt/kvm/x86/amd-memory-encryption.rst
> index b2395dd4769de..43085f65b2d85 100644
> --- a/Documentation/virt/kvm/x86/amd-memory-encryption.rst
> +++ b/Documentation/virt/kvm/x86/amd-memory-encryption.rst
> @@ -503,7 +503,8 @@ secrets.
>
> It is required that the GPA ranges initialized by this command have had the
> KVM_MEMORY_ATTRIBUTE_PRIVATE attribute set in advance. See the documentation
> -for KVM_SET_MEMORY_ATTRIBUTES for more details on this aspect.
> +for KVM_SET_MEMORY_ATTRIBUTES/KVM_SET_MEMORY_ATTRIBUTES2 for more details on
> +this aspect.
>
> Upon success, this command is not guaranteed to have processed the entire
> range requested. Instead, the ``gfn_start``, ``uaddr``, and ``len`` fields of
> @@ -511,9 +512,15 @@ range requested. Instead, the ``gfn_start``, ``uaddr``, and ``len`` fields of
> remaining range that has yet to be processed. The caller should continue
> calling this command until those fields indicate the entire range has been
> processed, e.g. ``len`` is 0, ``gfn_start`` is equal to the last GFN in the
> -range plus 1, and ``uaddr`` is the last byte of the userspace-provided source
> -buffer address plus 1. In the case where ``type`` is KVM_SEV_SNP_PAGE_TYPE_ZERO,
> -``uaddr`` will be ignored completely.
> +range plus 1, and ``uaddr`` (if specified) is the last byte of the
> +userspace-provided source buffer address plus 1.
> +
> +In the case where ``type`` is KVM_SEV_SNP_PAGE_TYPE_ZERO, ``uaddr`` will be
> +ignored completely. Otherwise, ``uaddr`` is required if
> +kvm.vm_memory_attributes=1 and optional if kvm.vm_memory_attributes=0, since
> +in the latter case guest memory can be initialized directly from userspace
> +prior to converting it to private and passing the GPA range on to this
> +interface.
>
> Parameters (in): struct kvm_sev_snp_launch_update
>
> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> index c2126b3c30724..bf10d24907a00 100644
> --- a/arch/x86/kvm/svm/sev.c
> +++ b/arch/x86/kvm/svm/sev.c
> @@ -2343,7 +2343,15 @@ static int sev_gmem_post_populate(struct kvm *kvm, gfn_t gfn, kvm_pfn_t pfn,
> int level;
> int ret;
>
> - if (WARN_ON_ONCE(sev_populate_args->type != KVM_SEV_SNP_PAGE_TYPE_ZERO && !src_page))
> + /*
> + * For vm_memory_attributes=1, in-place conversion/population is not
> + * supported, so the initial contents necessarily need to come from a
> + * separate src address. For vm_memory_attributes=0, this isn't
> + * necessarily the case, since the pages may have been populated
> + * directly from userspace before calling KVM_SEV_SNP_LAUNCH_UPDATE.
> + */
> + if (vm_memory_attributes &&
> + sev_populate_args->type != KVM_SEV_SNP_PAGE_TYPE_ZERO && !src_page)
> return -EINVAL;
>
> ret = snp_lookup_rmpentry((u64)pfn, &assigned, &level);
> @@ -2390,7 +2398,7 @@ static int sev_gmem_post_populate(struct kvm *kvm, gfn_t gfn, kvm_pfn_t pfn,
> */
> if (ret && !snp_page_reclaim(kvm, pfn) &&
> sev_populate_args->type == KVM_SEV_SNP_PAGE_TYPE_CPUID &&
> - sev_populate_args->fw_error == SEV_RET_INVALID_PARAM) {
> + sev_populate_args->fw_error == SEV_RET_INVALID_PARAM && src_page) {
> void *src_vaddr = kmap_local_page(src_page);
> void *dst_vaddr = kmap_local_pfn(pfn);
>
> @@ -2422,8 +2430,8 @@ static int snp_launch_update(struct kvm *kvm, struct kvm_sev_cmd *argp)
> if (copy_from_user(¶ms, u64_to_user_ptr(argp->data), sizeof(params)))
> return -EFAULT;
>
> - pr_debug("%s: GFN start 0x%llx length 0x%llx type %d flags %d\n", __func__,
> - params.gfn_start, params.len, params.type, params.flags);
> + pr_debug("%s: GFN start 0x%llx length 0x%llx type %d flags %d src %llx\n", __func__,
> + params.gfn_start, params.len, params.type, params.flags, params.uaddr);
>
> if (!params.len || !PAGE_ALIGNED(params.len) || params.flags ||
> (params.type != KVM_SEV_SNP_PAGE_TYPE_NORMAL &&
> @@ -2479,7 +2487,7 @@ static int snp_launch_update(struct kvm *kvm, struct kvm_sev_cmd *argp)
>
> params.gfn_start += count;
> params.len -= count * PAGE_SIZE;
> - if (params.type != KVM_SEV_SNP_PAGE_TYPE_ZERO)
> + if (src && params.type != KVM_SEV_SNP_PAGE_TYPE_ZERO)
> params.uaddr += count * PAGE_SIZE;
>
> if (copy_to_user(u64_to_user_ptr(argp->data), ¶ms, sizeof(params)))
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index ba195bb239aaa..3bf212fd99193 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -105,6 +105,7 @@ module_param(allow_unsafe_mappings, bool, 0444);
> #ifdef CONFIG_KVM_VM_MEMORY_ATTRIBUTES
> bool vm_memory_attributes = true;
> module_param(vm_memory_attributes, bool, 0444);
> +EXPORT_SYMBOL_FOR_KVM_INTERNAL(vm_memory_attributes);
> #endif
> DEFINE_STATIC_CALL_RET0(__kvm_get_memory_attributes, kvm_get_memory_attributes_t);
> EXPORT_SYMBOL_FOR_KVM_INTERNAL(STATIC_CALL_KEY(__kvm_get_memory_attributes));
>
> --
> 2.54.0.563.g4f69b47b94-goog
>
>
^ permalink raw reply
* [PATCH v7 1/8] docs/zh_CN: Add index.rst translation
From: Kefan Bai @ 2026-05-21 9:55 UTC (permalink / raw)
To: linux-usb, si.yanteng
Cc: gregkh, seakeel, alexs, dzm91, corbet, skhan, linux-doc, doubled
In-Reply-To: <cover.1779355170.git.baikefan@leap-io-kernel.com>
Translate .../usb/index.rst into Chinese and update subsystem-apis.rst
Update the translation through commit a592a36e4937
("Documentation: use a source-read extension for the index link boilerplate")
Reviewed-by: Yanteng Si <siyanteng@cqsoftware.com.cn>
Signed-off-by: Kefan Bai <baikefan@leap-io-kernel.com>
---
.../translations/zh_CN/subsystem-apis.rst | 2 +-
.../translations/zh_CN/usb/index.rst | 54 +++++++++++++++++++
2 files changed, 55 insertions(+), 1 deletion(-)
create mode 100644 Documentation/translations/zh_CN/usb/index.rst
diff --git a/Documentation/translations/zh_CN/subsystem-apis.rst b/Documentation/translations/zh_CN/subsystem-apis.rst
index 830217140fb6..b52e1feb0167 100644
--- a/Documentation/translations/zh_CN/subsystem-apis.rst
+++ b/Documentation/translations/zh_CN/subsystem-apis.rst
@@ -90,6 +90,7 @@ TODOList:
security/index
PCI/index
peci/index
+ usb/index
TODOList:
@@ -104,6 +105,5 @@ TODOList:
* accel/index
* crypto/index
* bpf/index
-* usb/index
* misc-devices/index
* wmi/index
diff --git a/Documentation/translations/zh_CN/usb/index.rst b/Documentation/translations/zh_CN/usb/index.rst
new file mode 100644
index 000000000000..b4cb0ccaa39b
--- /dev/null
+++ b/Documentation/translations/zh_CN/usb/index.rst
@@ -0,0 +1,54 @@
+.. SPDX-License-Identifier: GPL-2.0
+.. include:: ../disclaimer-zh_CN.rst
+
+:Original: Documentation/usb/index.rst
+
+:翻译:
+
+ 白钶凡 Kefan Bai <baikefan@leap-io-kernel.com>
+
+:校译:
+
+
+========
+USB 支持
+========
+
+.. toctree::
+ :maxdepth: 1
+
+
+Todolist:
+
+* acm
+* authorization
+* chipidea
+* dwc3
+* ehci
+* usbmon
+* functionfs
+* functionfs-desc
+* gadget_configfs
+* gadget_hid
+* gadget_multi
+* gadget_printer
+* gadget_serial
+* gadget_uvc
+* gadget-testing
+* iuu_phoenix
+* mass-storage
+* misc_usbsevseg
+* mtouchusb
+* ohci
+* raw-gadget
+* usbip_protocol
+* usb-serial
+* usb-help
+* text_files
+
+.. only:: subproject and html
+
+ 索引
+ ====
+
+ * :ref:`genindex`
--
2.54.0
^ permalink raw reply related
* Re: [PATCH net-next v3 01/14] virtchnl: create 'include/linux/intel' and move necessary header files
From: Larysa Zaremba @ 2026-05-21 9:28 UTC (permalink / raw)
To: Jakub Kicinski
Cc: Tony Nguyen, davem, pabeni, edumazet, andrew+netdev, netdev,
przemyslaw.kitszel, aleksander.lobakin, sridhar.samudrala,
anjali.singhai, michal.swiatkowski, maciej.fijalkowski,
emil.s.tantilov, madhu.chittim, joshua.a.hay, jacob.e.keller,
jayaprakash.shanmugam, jiri, horms, corbet, richardcochran,
linux-doc, tatyana.e.nikolova, krzysztof.czurylo, jgg, leon,
linux-rdma, Samuel Salin, Aleksandr Loktionov
In-Reply-To: <20260520175201.72f83c4a@kernel.org>
On Wed, May 20, 2026 at 05:52:01PM -0700, Jakub Kicinski wrote:
> On Fri, 15 May 2026 15:44:25 -0700 Tony Nguyen wrote:
> > include/linux/intel is vacant
>
> I don't see any other vendor directory under include/linux
There are at least
include/linux/mlx4, include/linux/mlx5 and include/linux/bnxt.
Those are per-driver and not per-vendor, but intel ethernet has too many drivers
to have separate folders for them.
I just do not think this creates a precedent neccessarily.
Folder structure is for you to decide as a maintainer, but it would be nice to
have known about such doubts earlier.
> and TBH I don't want to be the maintainer making a precedent
> for this sort of stuff. include/net/intel is a better choice.
> Or rather, at least its in "our" section of the tree so nobody
> will complain.
>
^ permalink raw reply
* Re: [PATCH v3] killswitch: add per-function short-circuit mitigation primitive
From: Daniel Borkmann @ 2026-05-21 9:11 UTC (permalink / raw)
To: Sasha Levin
Cc: Song Liu, linux-kernel, linux-doc, linux-kselftest, bpf,
live-patching, Greg Kroah-Hartman, Andrew Morton, Jonathan Corbet,
Mathieu Desnoyers, Joshua Peisach, Florian Weimer, Breno Leitao,
Anthony Iliopoulos, Michal Hocko, Jiri Olsa, John Fastabend,
Christian Brauner, KP Singh
In-Reply-To: <agzAwjKhOhuANz_P@laps>
On 5/19/26 9:57 PM, Sasha Levin wrote:
> On Tue, May 19, 2026 at 02:13:26PM +0200, Daniel Borkmann wrote:
>> On 5/19/26 1:59 AM, Song Liu wrote:
>>> On Mon, May 18, 2026 at 6:33 AM Sasha Levin <sashal@kernel.org> wrote:
>>>> On Sun, May 17, 2026 at 11:37:36PM -0700, Song Liu wrote:
>>>>> On Sun, May 17, 2026 at 6:49 AM Sasha Levin <sashal@kernel.org> wrote:
>>>>>> * fail_function (CONFIG_FUNCTION_ERROR_INJECTION) is disabled in
>>>>>> most production kernels. Even where enabled, it only works on
>>>>>> functions pre-annotated with ALLOW_ERROR_INJECTION() in source -
>>>>>> no help for a freshly-disclosed CVE. The debugfs UI is blocked by
>>>>>> lockdown=integrity and the override is probabilistic.
>>>>>>
>>>>>> * BPF override (bpf_override_return) honors the same
>>>>>> ALLOW_ERROR_INJECTION() whitelist, and BPF itself is off in many
>>>>>> production kernels. Even where on, the operator interface is
>>>>>> "load a verified BPF program," not a one-line write.
>>>>>
>>>>> If it is OK for killswitch to attach to any kernel functions, do we still
>>>>> need ALLOW_ERROR_INJECTION() for fail_function and BPF
>>>>> override? Shall we instead also allow fail_function and BPF override
>>>>> to attach to any kernel functions?
>>>>
>>>> I don't think so. ALLOW_ERROR_INJECTION is not a security mechanism, it's an
>>>> integrity/safety mechanism for both bpf and fault injection.
>>>>
>>>> It protects against a "developer or CI script doing legitimate fault injection
>>>> accidentally panics the box" scenario, not an "attacker gets in" one.
>>>
>>> There really isn't a clear boundary between "security mechanism" and
>>> "non-security mechanism". As we are making killswitch available
>>> everywhere under root, users will soon learn to use it to do fault injection,
>>> and potentially much more scary things. (Think about agents with sudo
>>> access).
>>
>> Fully agree with Song here that there is no clear boundary, and that the
>> killswitch could lead to arbitrary, hard to debug breakage if applied to
>> the wrong function.. introducing worse bugs than the one being mitigated
>> or even /short-circuit LSM enforcement/ (engage security_file_open 0,
>> engage cap_capable 0, engage apparmor_* etc).
>
> This is similar to livepatch, right? Do we need guardrails there too?
>
> Or do we just trust root to do the right thing for it's systems without needing
> to be it's babysitter?
[See Song's reply.]
>> The ALLOW_ERROR_INJECTION() provides a curated white-list where you may
>> return with an error without causing more severe damage (assuming the
>> error handling code is right). The right thing would be to more widely
>> apply ALLOW_ERROR_INJECTION() or to figure out a better way to safely
>> enable the latter without explicit function annotation.
>
> Sure, this would also work. How do you see this happening? Can we let a certain
> user/pid/etc disable the allowlist if they choose to?
I don't think we should, given then we're back to square one where root
or some other user would be able to just override/bypass an LSM.
[...]
> How do you see this working with the allowlist?
We should look at the underlying areas where most of the CVE-like fixes
took place (these days should be more easily doable given Claude and friends)
and based on that either extend ALLOW_ERROR_INJECTION() or (better) create
new hooks which BPF LSM can consume where you can then have a policy to reject
requests and tighten the attack surface. For example, the AF_ALG stuff you
can already easily cover today ...
#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#define AF_ALG 38
#define EPERM 1
char _license[] SEC("license") = "Dual BSD/GPL";
SEC("lsm/socket_create")
int BPF_PROG(block_af_alg, int family, int type, int protocol, int kern)
{
if (family == AF_ALG)
return -EPERM;
return 0;
}
... the problem is that distros enable and pull in all sort of crap which
then non-root could pull in via request_module() as an example; similarly
for netlink we want to have a BPF LSM policy to parse into netlink requests
and then reject based on certain attribute matching (both on our todo list)
which would have helped in case of exotic tc cls/act/qdisc modules to prevent
them to be pulled from userns. I bet there are a ton more examples once we
look further into the data.
Thanks,
Daniel
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox