Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

asamy
Copy link
Contributor

@asamy asamy commented Aug 24, 2012

No description provided.

mturquette pushed a commit to mturquette/linux that referenced this pull request Aug 25, 2012
…d reasons

We've had some reports of a deadlock where rpciod ends up with a stack
trace like this:

    PID: 2507   TASK: ffff88103691ab40  CPU: 14  COMMAND: "rpciod/14"
     #0 [ffff8810343bf2f0] schedule at ffffffff814dabd9
     #1 [ffff8810343bf3b8] nfs_wait_bit_killable at ffffffffa038fc04 [nfs]
     #2 [ffff8810343bf3c8] __wait_on_bit at ffffffff814dbc2f
     #3 [ffff8810343bf418] out_of_line_wait_on_bit at ffffffff814dbcd8
     #4 [ffff8810343bf488] nfs_commit_inode at ffffffffa039e0c1 [nfs]
     #5 [ffff8810343bf4f8] nfs_release_page at ffffffffa038bef6 [nfs]
     torvalds#6 [ffff8810343bf528] try_to_release_page at ffffffff8110c670
     torvalds#7 [ffff8810343bf538] shrink_page_list.clone.0 at ffffffff81126271
     torvalds#8 [ffff8810343bf668] shrink_inactive_list at ffffffff81126638
     torvalds#9 [ffff8810343bf818] shrink_zone at ffffffff8112788f
    torvalds#10 [ffff8810343bf8c8] do_try_to_free_pages at ffffffff81127b1e
    torvalds#11 [ffff8810343bf958] try_to_free_pages at ffffffff8112812f
    torvalds#12 [ffff8810343bfa08] __alloc_pages_nodemask at ffffffff8111fdad
    torvalds#13 [ffff8810343bfb28] kmem_getpages at ffffffff81159942
    torvalds#14 [ffff8810343bfb58] fallback_alloc at ffffffff8115a55a
    torvalds#15 [ffff8810343bfbd8] ____cache_alloc_node at ffffffff8115a2d9
    torvalds#16 [ffff8810343bfc38] kmem_cache_alloc at ffffffff8115b09b
    torvalds#17 [ffff8810343bfc78] sk_prot_alloc at ffffffff81411808
    torvalds#18 [ffff8810343bfcb8] sk_alloc at ffffffff8141197c
    torvalds#19 [ffff8810343bfce8] inet_create at ffffffff81483ba6
    torvalds#20 [ffff8810343bfd38] __sock_create at ffffffff8140b4a7
    torvalds#21 [ffff8810343bfd98] xs_create_sock at ffffffffa01f649b [sunrpc]
    torvalds#22 [ffff8810343bfdd8] xs_tcp_setup_socket at ffffffffa01f6965 [sunrpc]
    torvalds#23 [ffff8810343bfe38] worker_thread at ffffffff810887d0
    torvalds#24 [ffff8810343bfee8] kthread at ffffffff8108dd96
    torvalds#25 [ffff8810343bff48] kernel_thread at ffffffff8100c1ca

rpciod is trying to allocate memory for a new socket to talk to the
server. The VM ends up calling ->releasepage to get more memory, and it
tries to do a blocking commit. That commit can't succeed however without
a connected socket, so we deadlock.

Fix this by setting PF_FSTRANS on the workqueue task prior to doing the
socket allocation, and having nfs_release_page check for that flag when
deciding whether to do a commit call. Also, set PF_FSTRANS
unconditionally in rpc_async_schedule since that function can also do
allocations sometimes.

Signed-off-by: Jeff Layton <[email protected]>
Signed-off-by: Trond Myklebust <[email protected]>
Cc: [email protected]
bootc pushed a commit to bootc/linux that referenced this pull request Aug 25, 2012
…d reasons

commit 5cf02d0 upstream.

We've had some reports of a deadlock where rpciod ends up with a stack
trace like this:

    PID: 2507   TASK: ffff88103691ab40  CPU: 14  COMMAND: "rpciod/14"
     #0 [ffff8810343bf2f0] schedule at ffffffff814dabd9
     #1 [ffff8810343bf3b8] nfs_wait_bit_killable at ffffffffa038fc04 [nfs]
     #2 [ffff8810343bf3c8] __wait_on_bit at ffffffff814dbc2f
     #3 [ffff8810343bf418] out_of_line_wait_on_bit at ffffffff814dbcd8
     #4 [ffff8810343bf488] nfs_commit_inode at ffffffffa039e0c1 [nfs]
     #5 [ffff8810343bf4f8] nfs_release_page at ffffffffa038bef6 [nfs]
     #6 [ffff8810343bf528] try_to_release_page at ffffffff8110c670
     #7 [ffff8810343bf538] shrink_page_list.clone.0 at ffffffff81126271
     torvalds#8 [ffff8810343bf668] shrink_inactive_list at ffffffff81126638
     torvalds#9 [ffff8810343bf818] shrink_zone at ffffffff8112788f
    torvalds#10 [ffff8810343bf8c8] do_try_to_free_pages at ffffffff81127b1e
    torvalds#11 [ffff8810343bf958] try_to_free_pages at ffffffff8112812f
    torvalds#12 [ffff8810343bfa08] __alloc_pages_nodemask at ffffffff8111fdad
    torvalds#13 [ffff8810343bfb28] kmem_getpages at ffffffff81159942
    torvalds#14 [ffff8810343bfb58] fallback_alloc at ffffffff8115a55a
    torvalds#15 [ffff8810343bfbd8] ____cache_alloc_node at ffffffff8115a2d9
    torvalds#16 [ffff8810343bfc38] kmem_cache_alloc at ffffffff8115b09b
    torvalds#17 [ffff8810343bfc78] sk_prot_alloc at ffffffff81411808
    torvalds#18 [ffff8810343bfcb8] sk_alloc at ffffffff8141197c
    torvalds#19 [ffff8810343bfce8] inet_create at ffffffff81483ba6
    torvalds#20 [ffff8810343bfd38] __sock_create at ffffffff8140b4a7
    torvalds#21 [ffff8810343bfd98] xs_create_sock at ffffffffa01f649b [sunrpc]
    torvalds#22 [ffff8810343bfdd8] xs_tcp_setup_socket at ffffffffa01f6965 [sunrpc]
    torvalds#23 [ffff8810343bfe38] worker_thread at ffffffff810887d0
    torvalds#24 [ffff8810343bfee8] kthread at ffffffff8108dd96
    torvalds#25 [ffff8810343bff48] kernel_thread at ffffffff8100c1ca

rpciod is trying to allocate memory for a new socket to talk to the
server. The VM ends up calling ->releasepage to get more memory, and it
tries to do a blocking commit. That commit can't succeed however without
a connected socket, so we deadlock.

Fix this by setting PF_FSTRANS on the workqueue task prior to doing the
socket allocation, and having nfs_release_page check for that flag when
deciding whether to do a commit call. Also, set PF_FSTRANS
unconditionally in rpc_async_schedule since that function can also do
allocations sometimes.

Signed-off-by: Jeff Layton <[email protected]>
Signed-off-by: Trond Myklebust <[email protected]>
Signed-off-by: Ben Hutchings <[email protected]>
@asamy asamy closed this Aug 25, 2012
liubogithub pushed a commit to liubogithub/btrfs-work that referenced this pull request Aug 29, 2012
When hot-adding a CPU, the system outputs following messages
since node_to_cpumask_map[2] was not allocated memory.

Booting Node 2 Processor 32 APIC 0xc0
node_to_cpumask_map[2] NULL
Pid: 0, comm: swapper/32 Tainted: G       A     3.3.5-acd torvalds#21
Call Trace:
 [<ffffffff81048845>] debug_cpumask_set_cpu+0x155/0x160
 [<ffffffff8105e28a>] ? add_timer_on+0xaa/0x120
 [<ffffffff8150665f>] numa_add_cpu+0x1e/0x22
 [<ffffffff815020bb>] identify_cpu+0x1df/0x1e4
 [<ffffffff815020d6>] identify_econdary_cpu+0x16/0x1d
 [<ffffffff81504614>] smp_store_cpu_info+0x3c/0x3e
 [<ffffffff81505263>] smp_callin+0x139/0x1be
 [<ffffffff815052fb>] start_secondary+0x13/0xeb

The reason is that the bit of node 2 was not set at
numa_nodes_parsed. numa_nodes_parsed is set by only
acpi_numa_processor_affinity_init /
acpi_numa_x2apic_affinity_init. Thus even if hot-added memory
which is same PXM as hot-added CPU is written in ACPI SRAT
Table, if the hot-added CPU is not written in ACPI SRAT table,
numa_nodes_parsed is not set.

But according to ACPI Spec Rev 5.0, it says about ACPI SRAT
table as follows: This optional table provides information that
allows OSPM to associate processors and memory ranges, including
ranges of memory provided by hot-added memory devices, with
system localities / proximity domains and clock domains.

It means that ACPI SRAT table only provides information for CPUs
present at boot time and for memory including hot-added memory.
So hot-added memory is written in ACPI SRAT table, but hot-added
CPU is not written in it. Thus numa_nodes_parsed should be set
by not only acpi_numa_processor_affinity_init /
acpi_numa_x2apic_affinity_init but also
acpi_numa_memory_affinity_init for the case.

Additionally, if system has cpuless memory node,
acpi_numa_processor_affinity_init /
acpi_numa_x2apic_affinity_init cannot set numa_nodes_parseds
since these functions cannot find cpu description for the node.
In this case, numa_nodes_parsed needs to be set by
acpi_numa_memory_affinity_init.

Signed-off-by: Yasuaki Ishimatsu <[email protected]>
Acked-by: David Rientjes <[email protected]>
Acked-by: KOSAKI Motohiro <[email protected]>
Cc: [email protected]
Cc: [email protected]
Link: http://lkml.kernel.org/r/[email protected]
[ merged it ]
Signed-off-by: Ingo Molnar <[email protected]>
liubogithub pushed a commit to liubogithub/btrfs-work that referenced this pull request Aug 29, 2012
The warning below triggers on AMD MCM packages because physical package
IDs on the cores of a _physical_ socket are the same. I.e., this field
says which CPUs belong to the same physical package.

However, the same two CPUs belong to two different internal, i.e.
"logical" nodes in the same physical socket which is reflected in the
CPU-to-node map on x86 with NUMA.

Which makes this check wrong on the above topologies so circumvent it.

[    0.444413] Booting Node   0, Processors  #1 #2 #3 #4 #5 Ok.
[    0.461388] ------------[ cut here ]------------
[    0.465997] WARNING: at arch/x86/kernel/smpboot.c:310 topology_sane.clone.1+0x6e/0x81()
[    0.473960] Hardware name: Dinar
[    0.477170] sched: CPU torvalds#6's mc-sibling CPU #0 is not on the same node! [node: 1 != 0]. Ignoring dependency.
[    0.486860] Booting Node   1, Processors  torvalds#6
[    0.491104] Modules linked in:
[    0.494141] Pid: 0, comm: swapper/6 Not tainted 3.4.0+ #1
[    0.499510] Call Trace:
[    0.501946]  [<ffffffff8144bf92>] ? topology_sane.clone.1+0x6e/0x81
[    0.508185]  [<ffffffff8102f1fc>] warn_slowpath_common+0x85/0x9d
[    0.514163]  [<ffffffff8102f2b7>] warn_slowpath_fmt+0x46/0x48
[    0.519881]  [<ffffffff8144bf92>] topology_sane.clone.1+0x6e/0x81
[    0.525943]  [<ffffffff8144c234>] set_cpu_sibling_map+0x251/0x371
[    0.532004]  [<ffffffff8144c4ee>] start_secondary+0x19a/0x218
[    0.537729] ---[ end trace 4eaa2a86a8e2da22 ]---
[    0.628197]  torvalds#7 torvalds#8 torvalds#9 torvalds#10 torvalds#11 Ok.
[    0.807108] Booting Node   3, Processors  torvalds#12 torvalds#13 torvalds#14 torvalds#15 torvalds#16 torvalds#17 Ok.
[    0.897587] Booting Node   2, Processors  torvalds#18 torvalds#19 torvalds#20 torvalds#21 torvalds#22 torvalds#23 Ok.
[    0.917443] Brought up 24 CPUs

We ran a topology sanity check test we have here on it and
it all looks ok... hopefully :).

Signed-off-by: Borislav Petkov <[email protected]>
Cc: Andreas Herrmann <[email protected]>
Signed-off-by: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
jbrandeb pushed a commit to jbrandeb/linux that referenced this pull request Aug 29, 2012
…d reasons

commit 5cf02d0 upstream.

We've had some reports of a deadlock where rpciod ends up with a stack
trace like this:

    PID: 2507   TASK: ffff88103691ab40  CPU: 14  COMMAND: "rpciod/14"
     #0 [ffff8810343bf2f0] schedule at ffffffff814dabd9
     #1 [ffff8810343bf3b8] nfs_wait_bit_killable at ffffffffa038fc04 [nfs]
     #2 [ffff8810343bf3c8] __wait_on_bit at ffffffff814dbc2f
     #3 [ffff8810343bf418] out_of_line_wait_on_bit at ffffffff814dbcd8
     #4 [ffff8810343bf488] nfs_commit_inode at ffffffffa039e0c1 [nfs]
     #5 [ffff8810343bf4f8] nfs_release_page at ffffffffa038bef6 [nfs]
     torvalds#6 [ffff8810343bf528] try_to_release_page at ffffffff8110c670
     torvalds#7 [ffff8810343bf538] shrink_page_list.clone.0 at ffffffff81126271
     torvalds#8 [ffff8810343bf668] shrink_inactive_list at ffffffff81126638
     torvalds#9 [ffff8810343bf818] shrink_zone at ffffffff8112788f
    torvalds#10 [ffff8810343bf8c8] do_try_to_free_pages at ffffffff81127b1e
    torvalds#11 [ffff8810343bf958] try_to_free_pages at ffffffff8112812f
    torvalds#12 [ffff8810343bfa08] __alloc_pages_nodemask at ffffffff8111fdad
    torvalds#13 [ffff8810343bfb28] kmem_getpages at ffffffff81159942
    torvalds#14 [ffff8810343bfb58] fallback_alloc at ffffffff8115a55a
    torvalds#15 [ffff8810343bfbd8] ____cache_alloc_node at ffffffff8115a2d9
    torvalds#16 [ffff8810343bfc38] kmem_cache_alloc at ffffffff8115b09b
    torvalds#17 [ffff8810343bfc78] sk_prot_alloc at ffffffff81411808
    torvalds#18 [ffff8810343bfcb8] sk_alloc at ffffffff8141197c
    torvalds#19 [ffff8810343bfce8] inet_create at ffffffff81483ba6
    torvalds#20 [ffff8810343bfd38] __sock_create at ffffffff8140b4a7
    torvalds#21 [ffff8810343bfd98] xs_create_sock at ffffffffa01f649b [sunrpc]
    torvalds#22 [ffff8810343bfdd8] xs_tcp_setup_socket at ffffffffa01f6965 [sunrpc]
    torvalds#23 [ffff8810343bfe38] worker_thread at ffffffff810887d0
    torvalds#24 [ffff8810343bfee8] kthread at ffffffff8108dd96
    torvalds#25 [ffff8810343bff48] kernel_thread at ffffffff8100c1ca

rpciod is trying to allocate memory for a new socket to talk to the
server. The VM ends up calling ->releasepage to get more memory, and it
tries to do a blocking commit. That commit can't succeed however without
a connected socket, so we deadlock.

Fix this by setting PF_FSTRANS on the workqueue task prior to doing the
socket allocation, and having nfs_release_page check for that flag when
deciding whether to do a commit call. Also, set PF_FSTRANS
unconditionally in rpc_async_schedule since that function can also do
allocations sometimes.

Signed-off-by: Jeff Layton <[email protected]>
Signed-off-by: Trond Myklebust <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
shr-project pushed a commit to shr-distribution/linux that referenced this pull request Aug 30, 2012
…d reasons

commit 5cf02d0 upstream.

We've had some reports of a deadlock where rpciod ends up with a stack
trace like this:

    PID: 2507   TASK: ffff88103691ab40  CPU: 14  COMMAND: "rpciod/14"
     #0 [ffff8810343bf2f0] schedule at ffffffff814dabd9
     #1 [ffff8810343bf3b8] nfs_wait_bit_killable at ffffffffa038fc04 [nfs]
     #2 [ffff8810343bf3c8] __wait_on_bit at ffffffff814dbc2f
     #3 [ffff8810343bf418] out_of_line_wait_on_bit at ffffffff814dbcd8
     #4 [ffff8810343bf488] nfs_commit_inode at ffffffffa039e0c1 [nfs]
     #5 [ffff8810343bf4f8] nfs_release_page at ffffffffa038bef6 [nfs]
     #6 [ffff8810343bf528] try_to_release_page at ffffffff8110c670
     #7 [ffff8810343bf538] shrink_page_list.clone.0 at ffffffff81126271
     #8 [ffff8810343bf668] shrink_inactive_list at ffffffff81126638
     #9 [ffff8810343bf818] shrink_zone at ffffffff8112788f
    #10 [ffff8810343bf8c8] do_try_to_free_pages at ffffffff81127b1e
    #11 [ffff8810343bf958] try_to_free_pages at ffffffff8112812f
    torvalds#12 [ffff8810343bfa08] __alloc_pages_nodemask at ffffffff8111fdad
    torvalds#13 [ffff8810343bfb28] kmem_getpages at ffffffff81159942
    torvalds#14 [ffff8810343bfb58] fallback_alloc at ffffffff8115a55a
    torvalds#15 [ffff8810343bfbd8] ____cache_alloc_node at ffffffff8115a2d9
    torvalds#16 [ffff8810343bfc38] kmem_cache_alloc at ffffffff8115b09b
    torvalds#17 [ffff8810343bfc78] sk_prot_alloc at ffffffff81411808
    torvalds#18 [ffff8810343bfcb8] sk_alloc at ffffffff8141197c
    torvalds#19 [ffff8810343bfce8] inet_create at ffffffff81483ba6
    torvalds#20 [ffff8810343bfd38] __sock_create at ffffffff8140b4a7
    torvalds#21 [ffff8810343bfd98] xs_create_sock at ffffffffa01f649b [sunrpc]
    torvalds#22 [ffff8810343bfdd8] xs_tcp_setup_socket at ffffffffa01f6965 [sunrpc]
    torvalds#23 [ffff8810343bfe38] worker_thread at ffffffff810887d0
    torvalds#24 [ffff8810343bfee8] kthread at ffffffff8108dd96
    torvalds#25 [ffff8810343bff48] kernel_thread at ffffffff8100c1ca

rpciod is trying to allocate memory for a new socket to talk to the
server. The VM ends up calling ->releasepage to get more memory, and it
tries to do a blocking commit. That commit can't succeed however without
a connected socket, so we deadlock.

Fix this by setting PF_FSTRANS on the workqueue task prior to doing the
socket allocation, and having nfs_release_page check for that flag when
deciding whether to do a commit call. Also, set PF_FSTRANS
unconditionally in rpc_async_schedule since that function can also do
allocations sometimes.

Signed-off-by: Jeff Layton <[email protected]>
Signed-off-by: Trond Myklebust <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
RobertCNelson pushed a commit to RobertCNelson/linux that referenced this pull request Aug 30, 2012
…d reasons

commit 5cf02d0 upstream.

We've had some reports of a deadlock where rpciod ends up with a stack
trace like this:

    PID: 2507   TASK: ffff88103691ab40  CPU: 14  COMMAND: "rpciod/14"
     #0 [ffff8810343bf2f0] schedule at ffffffff814dabd9
     #1 [ffff8810343bf3b8] nfs_wait_bit_killable at ffffffffa038fc04 [nfs]
     #2 [ffff8810343bf3c8] __wait_on_bit at ffffffff814dbc2f
     #3 [ffff8810343bf418] out_of_line_wait_on_bit at ffffffff814dbcd8
     #4 [ffff8810343bf488] nfs_commit_inode at ffffffffa039e0c1 [nfs]
     #5 [ffff8810343bf4f8] nfs_release_page at ffffffffa038bef6 [nfs]
     torvalds#6 [ffff8810343bf528] try_to_release_page at ffffffff8110c670
     torvalds#7 [ffff8810343bf538] shrink_page_list.clone.0 at ffffffff81126271
     torvalds#8 [ffff8810343bf668] shrink_inactive_list at ffffffff81126638
     torvalds#9 [ffff8810343bf818] shrink_zone at ffffffff8112788f
    torvalds#10 [ffff8810343bf8c8] do_try_to_free_pages at ffffffff81127b1e
    torvalds#11 [ffff8810343bf958] try_to_free_pages at ffffffff8112812f
    torvalds#12 [ffff8810343bfa08] __alloc_pages_nodemask at ffffffff8111fdad
    torvalds#13 [ffff8810343bfb28] kmem_getpages at ffffffff81159942
    torvalds#14 [ffff8810343bfb58] fallback_alloc at ffffffff8115a55a
    torvalds#15 [ffff8810343bfbd8] ____cache_alloc_node at ffffffff8115a2d9
    torvalds#16 [ffff8810343bfc38] kmem_cache_alloc at ffffffff8115b09b
    torvalds#17 [ffff8810343bfc78] sk_prot_alloc at ffffffff81411808
    torvalds#18 [ffff8810343bfcb8] sk_alloc at ffffffff8141197c
    torvalds#19 [ffff8810343bfce8] inet_create at ffffffff81483ba6
    torvalds#20 [ffff8810343bfd38] __sock_create at ffffffff8140b4a7
    torvalds#21 [ffff8810343bfd98] xs_create_sock at ffffffffa01f649b [sunrpc]
    torvalds#22 [ffff8810343bfdd8] xs_tcp_setup_socket at ffffffffa01f6965 [sunrpc]
    torvalds#23 [ffff8810343bfe38] worker_thread at ffffffff810887d0
    torvalds#24 [ffff8810343bfee8] kthread at ffffffff8108dd96
    torvalds#25 [ffff8810343bff48] kernel_thread at ffffffff8100c1ca

rpciod is trying to allocate memory for a new socket to talk to the
server. The VM ends up calling ->releasepage to get more memory, and it
tries to do a blocking commit. That commit can't succeed however without
a connected socket, so we deadlock.

Fix this by setting PF_FSTRANS on the workqueue task prior to doing the
socket allocation, and having nfs_release_page check for that flag when
deciding whether to do a commit call. Also, set PF_FSTRANS
unconditionally in rpc_async_schedule since that function can also do
allocations sometimes.

Signed-off-by: Jeff Layton <jlayton at redhat.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust at netapp.com>
Signed-off-by: Ben Hutchings <ben at decadent.org.uk>
Quarx2k pushed a commit to Quarx2k/linux-allwinner that referenced this pull request Sep 9, 2012
…d reasons

commit 5cf02d0 upstream.

We've had some reports of a deadlock where rpciod ends up with a stack
trace like this:

    PID: 2507   TASK: ffff88103691ab40  CPU: 14  COMMAND: "rpciod/14"
     #0 [ffff8810343bf2f0] schedule at ffffffff814dabd9
     #1 [ffff8810343bf3b8] nfs_wait_bit_killable at ffffffffa038fc04 [nfs]
     #2 [ffff8810343bf3c8] __wait_on_bit at ffffffff814dbc2f
     #3 [ffff8810343bf418] out_of_line_wait_on_bit at ffffffff814dbcd8
     #4 [ffff8810343bf488] nfs_commit_inode at ffffffffa039e0c1 [nfs]
     #5 [ffff8810343bf4f8] nfs_release_page at ffffffffa038bef6 [nfs]
     torvalds#6 [ffff8810343bf528] try_to_release_page at ffffffff8110c670
     torvalds#7 [ffff8810343bf538] shrink_page_list.clone.0 at ffffffff81126271
     torvalds#8 [ffff8810343bf668] shrink_inactive_list at ffffffff81126638
     torvalds#9 [ffff8810343bf818] shrink_zone at ffffffff8112788f
    torvalds#10 [ffff8810343bf8c8] do_try_to_free_pages at ffffffff81127b1e
    torvalds#11 [ffff8810343bf958] try_to_free_pages at ffffffff8112812f
    torvalds#12 [ffff8810343bfa08] __alloc_pages_nodemask at ffffffff8111fdad
    torvalds#13 [ffff8810343bfb28] kmem_getpages at ffffffff81159942
    torvalds#14 [ffff8810343bfb58] fallback_alloc at ffffffff8115a55a
    torvalds#15 [ffff8810343bfbd8] ____cache_alloc_node at ffffffff8115a2d9
    torvalds#16 [ffff8810343bfc38] kmem_cache_alloc at ffffffff8115b09b
    torvalds#17 [ffff8810343bfc78] sk_prot_alloc at ffffffff81411808
    torvalds#18 [ffff8810343bfcb8] sk_alloc at ffffffff8141197c
    torvalds#19 [ffff8810343bfce8] inet_create at ffffffff81483ba6
    torvalds#20 [ffff8810343bfd38] __sock_create at ffffffff8140b4a7
    torvalds#21 [ffff8810343bfd98] xs_create_sock at ffffffffa01f649b [sunrpc]
    torvalds#22 [ffff8810343bfdd8] xs_tcp_setup_socket at ffffffffa01f6965 [sunrpc]
    torvalds#23 [ffff8810343bfe38] worker_thread at ffffffff810887d0
    torvalds#24 [ffff8810343bfee8] kthread at ffffffff8108dd96
    torvalds#25 [ffff8810343bff48] kernel_thread at ffffffff8100c1ca

rpciod is trying to allocate memory for a new socket to talk to the
server. The VM ends up calling ->releasepage to get more memory, and it
tries to do a blocking commit. That commit can't succeed however without
a connected socket, so we deadlock.

Fix this by setting PF_FSTRANS on the workqueue task prior to doing the
socket allocation, and having nfs_release_page check for that flag when
deciding whether to do a commit call. Also, set PF_FSTRANS
unconditionally in rpc_async_schedule since that function can also do
allocations sometimes.

Signed-off-by: Jeff Layton <[email protected]>
Signed-off-by: Trond Myklebust <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
koenkooi pushed a commit to koenkooi/linux that referenced this pull request Sep 11, 2012
…d reasons

commit 5cf02d0 upstream.

We've had some reports of a deadlock where rpciod ends up with a stack
trace like this:

    PID: 2507   TASK: ffff88103691ab40  CPU: 14  COMMAND: "rpciod/14"
     #0 [ffff8810343bf2f0] schedule at ffffffff814dabd9
     #1 [ffff8810343bf3b8] nfs_wait_bit_killable at ffffffffa038fc04 [nfs]
     #2 [ffff8810343bf3c8] __wait_on_bit at ffffffff814dbc2f
     #3 [ffff8810343bf418] out_of_line_wait_on_bit at ffffffff814dbcd8
     #4 [ffff8810343bf488] nfs_commit_inode at ffffffffa039e0c1 [nfs]
     #5 [ffff8810343bf4f8] nfs_release_page at ffffffffa038bef6 [nfs]
     #6 [ffff8810343bf528] try_to_release_page at ffffffff8110c670
     #7 [ffff8810343bf538] shrink_page_list.clone.0 at ffffffff81126271
     #8 [ffff8810343bf668] shrink_inactive_list at ffffffff81126638
     #9 [ffff8810343bf818] shrink_zone at ffffffff8112788f
    torvalds#10 [ffff8810343bf8c8] do_try_to_free_pages at ffffffff81127b1e
    torvalds#11 [ffff8810343bf958] try_to_free_pages at ffffffff8112812f
    torvalds#12 [ffff8810343bfa08] __alloc_pages_nodemask at ffffffff8111fdad
    torvalds#13 [ffff8810343bfb28] kmem_getpages at ffffffff81159942
    torvalds#14 [ffff8810343bfb58] fallback_alloc at ffffffff8115a55a
    torvalds#15 [ffff8810343bfbd8] ____cache_alloc_node at ffffffff8115a2d9
    torvalds#16 [ffff8810343bfc38] kmem_cache_alloc at ffffffff8115b09b
    torvalds#17 [ffff8810343bfc78] sk_prot_alloc at ffffffff81411808
    torvalds#18 [ffff8810343bfcb8] sk_alloc at ffffffff8141197c
    torvalds#19 [ffff8810343bfce8] inet_create at ffffffff81483ba6
    torvalds#20 [ffff8810343bfd38] __sock_create at ffffffff8140b4a7
    torvalds#21 [ffff8810343bfd98] xs_create_sock at ffffffffa01f649b [sunrpc]
    torvalds#22 [ffff8810343bfdd8] xs_tcp_setup_socket at ffffffffa01f6965 [sunrpc]
    torvalds#23 [ffff8810343bfe38] worker_thread at ffffffff810887d0
    torvalds#24 [ffff8810343bfee8] kthread at ffffffff8108dd96
    torvalds#25 [ffff8810343bff48] kernel_thread at ffffffff8100c1ca

rpciod is trying to allocate memory for a new socket to talk to the
server. The VM ends up calling ->releasepage to get more memory, and it
tries to do a blocking commit. That commit can't succeed however without
a connected socket, so we deadlock.

Fix this by setting PF_FSTRANS on the workqueue task prior to doing the
socket allocation, and having nfs_release_page check for that flag when
deciding whether to do a commit call. Also, set PF_FSTRANS
unconditionally in rpc_async_schedule since that function can also do
allocations sometimes.

Signed-off-by: Jeff Layton <[email protected]>
Signed-off-by: Trond Myklebust <[email protected]>
Signed-off-by: Ben Hutchings <[email protected]>
baerwolf pushed a commit to baerwolf/linux-stephan that referenced this pull request Sep 12, 2012
commit a3f83ab upstream.

At a boot time I observed following bug:

 BUG: unable to handle kernel paging request at ffff8800a4244000
 IP: [<ffffffff81275b5b>] memcpy+0xb/0x120
 PGD 1816063 PUD 1fe7d067 PMD 1ff9f067 PTE 80000000a4244160
 Oops: 0000 [#1] SMP DEBUG_PAGEALLOC
 CPU 0
 Modules linked in: btusb bluetooth brcmsmac brcmutil crc8 cordic b43 radeon(+)
  mac80211 cfg80211 ttm ohci_hcd drm_kms_helper rfkill drm ssb agpgart mmc_core
  sp5100_tco video battery ac thermal processor rtc_cmos thermal_sys snd_hda_codec_hdmi
  joydev snd_hda_codec_conexant button bcma pcmcia snd_hda_intel snd_hda_codec
  snd_hwdep snd_pcm shpchp pcmcia_core k8temp snd_timer atl1c snd psmouse hwmon
  i2c_piix4 i2c_algo_bit soundcore evdev i2c_core ehci_hcd sg serio_raw snd_page_alloc
  loop btrfs

 Pid: 1008, comm: modprobe Not tainted 3.3.0-rc1 torvalds#21 LENOVO 20046                           /AMD CRB
 RIP: 0010:[<ffffffff81275b5b>]  [<ffffffff81275b5b>] memcpy+0xb/0x120
 RSP: 0018:ffff8800aa72db00  EFLAGS: 00010246
 RAX: ffff8800a4150000 RBX: 0000000000001000 RCX: 0000000000000087
 RDX: 0000000000000000 RSI: ffff8800a4244000 RDI: ffff8800a4150bc8
 RBP: ffff8800aa72db78 R08: 0000000000000010 R09: ffffffff8174bbec
 R10: ffffffff812ee010 R11: 0000000000000001 R12: 0000000000001000
 R13: 0000000000010000 R14: ffff8800a4140000 R15: ffff8800aaba1800
 FS:  00007ff9a3bd4720(0000) GS:ffff8800afa00000(0000) knlGS:0000000000000000
 CS:  0010 DS: 0000 ES: 0000 CR0: 000000008005003b
 CR2: ffff8800a4244000 CR3: 00000000a9c18000 CR4: 00000000000006f0
 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
 DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
 Process modprobe (pid: 1008, threadinfo ffff8800aa72c000, task ffff8800aa0e4000)
 Stack:
  ffffffffa04e7c7b 0000000000000001 0000000000010000 ffff8800aa72db28
  ffffffff00000001 0000000000001000 ffffffff8113cbef 0000000000000020
  ffff8800a4243420 ffff880000000002 ffff8800aa72db08 ffff8800a9d42000
 Call Trace:
  [<ffffffffa04e7c7b>] ? radeon_atrm_get_bios_chunk+0x8b/0xd0 [radeon]
  [<ffffffff8113cbef>] ? kmalloc_order_trace+0x3f/0xb0
  [<ffffffffa04a9298>] radeon_get_bios+0x68/0x2f0 [radeon]
  [<ffffffffa04c7a30>] rv770_init+0x40/0x280 [radeon]
  [<ffffffffa047d740>] radeon_device_init+0x560/0x600 [radeon]
  [<ffffffffa047ef4f>] radeon_driver_load_kms+0xaf/0x170 [radeon]
  [<ffffffffa043cdde>] drm_get_pci_dev+0x18e/0x2c0 [drm]
  [<ffffffffa04e7e95>] radeon_pci_probe+0xad/0xb5 [radeon]
  [<ffffffff81296c5f>] local_pci_probe+0x5f/0xd0
  [<ffffffff81297418>] pci_device_probe+0x88/0xb0
  [<ffffffff813417aa>] ? driver_sysfs_add+0x7a/0xb0
  [<ffffffff813418d8>] really_probe+0x68/0x180
  [<ffffffff81341be5>] driver_probe_device+0x45/0x70
  [<ffffffff81341cb3>] __driver_attach+0xa3/0xb0
  [<ffffffff81341c10>] ? driver_probe_device+0x70/0x70
  [<ffffffff813400ce>] bus_for_each_dev+0x5e/0x90
  [<ffffffff8134172e>] driver_attach+0x1e/0x20
  [<ffffffff81341298>] bus_add_driver+0xc8/0x280
  [<ffffffff813422c6>] driver_register+0x76/0x140
  [<ffffffff812976d6>] __pci_register_driver+0x66/0xe0
  [<ffffffffa043d021>] drm_pci_init+0x111/0x120 [drm]
  [<ffffffff8133c67a>] ? vga_switcheroo_register_handler+0x3a/0x60
  [<ffffffffa0229000>] ? 0xffffffffa0228fff
  [<ffffffffa02290ec>] radeon_init+0xec/0xee [radeon]
  [<ffffffff810002f2>] do_one_initcall+0x42/0x180
  [<ffffffff8109d8d2>] sys_init_module+0x92/0x1e0
  [<ffffffff815407a9>] system_call_fastpath+0x16/0x1b
 Code: 58 2a 43 50 88 43 4e 48 83 c4 08 5b c9 c3 66 90 e8 cb fd ff ff eb
  e6 90 90 90 90 90 90 90 90 90 48 89 f8 89 d1 c1 e9 03 83 e2 07 <f3> 48
  a5 89 d1 f3 a4 c3 20 48 83 ea 20 4c 8b 06 4c 8b 4e 08 4c
 RIP  [<ffffffff81275b5b>] memcpy+0xb/0x120
  RSP <ffff8800aa72db00>
 CR2: ffff8800a4244000
 ---[ end trace fcffa1599cf56382 ]---

Call to acpi_evaluate_object() not always returns 4096 bytes chunks,
on my system it can return 2048 bytes chunk, so pass the length of
retrieved chunk to memcpy(), not the length of the recieving buffer.

Signed-off-by: Igor Murzov <[email protected]>
Reviewed-by: Alex Deucher <[email protected]>
Signed-off-by: Dave Airlie <[email protected]>
Signed-off-by: Ben Hutchings <[email protected]>
RobertCNelson pushed a commit to RobertCNelson/linux that referenced this pull request Sep 12, 2012
commit a3f83ab upstream.

At a boot time I observed following bug:

 BUG: unable to handle kernel paging request at ffff8800a4244000
 IP: [<ffffffff81275b5b>] memcpy+0xb/0x120
 PGD 1816063 PUD 1fe7d067 PMD 1ff9f067 PTE 80000000a4244160
 Oops: 0000 [#1] SMP DEBUG_PAGEALLOC
 CPU 0
 Modules linked in: btusb bluetooth brcmsmac brcmutil crc8 cordic b43 radeon(+)
  mac80211 cfg80211 ttm ohci_hcd drm_kms_helper rfkill drm ssb agpgart mmc_core
  sp5100_tco video battery ac thermal processor rtc_cmos thermal_sys snd_hda_codec_hdmi
  joydev snd_hda_codec_conexant button bcma pcmcia snd_hda_intel snd_hda_codec
  snd_hwdep snd_pcm shpchp pcmcia_core k8temp snd_timer atl1c snd psmouse hwmon
  i2c_piix4 i2c_algo_bit soundcore evdev i2c_core ehci_hcd sg serio_raw snd_page_alloc
  loop btrfs

 Pid: 1008, comm: modprobe Not tainted 3.3.0-rc1 torvalds#21 LENOVO 20046                           /AMD CRB
 RIP: 0010:[<ffffffff81275b5b>]  [<ffffffff81275b5b>] memcpy+0xb/0x120
 RSP: 0018:ffff8800aa72db00  EFLAGS: 00010246
 RAX: ffff8800a4150000 RBX: 0000000000001000 RCX: 0000000000000087
 RDX: 0000000000000000 RSI: ffff8800a4244000 RDI: ffff8800a4150bc8
 RBP: ffff8800aa72db78 R08: 0000000000000010 R09: ffffffff8174bbec
 R10: ffffffff812ee010 R11: 0000000000000001 R12: 0000000000001000
 R13: 0000000000010000 R14: ffff8800a4140000 R15: ffff8800aaba1800
 FS:  00007ff9a3bd4720(0000) GS:ffff8800afa00000(0000) knlGS:0000000000000000
 CS:  0010 DS: 0000 ES: 0000 CR0: 000000008005003b
 CR2: ffff8800a4244000 CR3: 00000000a9c18000 CR4: 00000000000006f0
 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
 DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
 Process modprobe (pid: 1008, threadinfo ffff8800aa72c000, task ffff8800aa0e4000)
 Stack:
  ffffffffa04e7c7b 0000000000000001 0000000000010000 ffff8800aa72db28
  ffffffff00000001 0000000000001000 ffffffff8113cbef 0000000000000020
  ffff8800a4243420 ffff880000000002 ffff8800aa72db08 ffff8800a9d42000
 Call Trace:
  [<ffffffffa04e7c7b>] ? radeon_atrm_get_bios_chunk+0x8b/0xd0 [radeon]
  [<ffffffff8113cbef>] ? kmalloc_order_trace+0x3f/0xb0
  [<ffffffffa04a9298>] radeon_get_bios+0x68/0x2f0 [radeon]
  [<ffffffffa04c7a30>] rv770_init+0x40/0x280 [radeon]
  [<ffffffffa047d740>] radeon_device_init+0x560/0x600 [radeon]
  [<ffffffffa047ef4f>] radeon_driver_load_kms+0xaf/0x170 [radeon]
  [<ffffffffa043cdde>] drm_get_pci_dev+0x18e/0x2c0 [drm]
  [<ffffffffa04e7e95>] radeon_pci_probe+0xad/0xb5 [radeon]
  [<ffffffff81296c5f>] local_pci_probe+0x5f/0xd0
  [<ffffffff81297418>] pci_device_probe+0x88/0xb0
  [<ffffffff813417aa>] ? driver_sysfs_add+0x7a/0xb0
  [<ffffffff813418d8>] really_probe+0x68/0x180
  [<ffffffff81341be5>] driver_probe_device+0x45/0x70
  [<ffffffff81341cb3>] __driver_attach+0xa3/0xb0
  [<ffffffff81341c10>] ? driver_probe_device+0x70/0x70
  [<ffffffff813400ce>] bus_for_each_dev+0x5e/0x90
  [<ffffffff8134172e>] driver_attach+0x1e/0x20
  [<ffffffff81341298>] bus_add_driver+0xc8/0x280
  [<ffffffff813422c6>] driver_register+0x76/0x140
  [<ffffffff812976d6>] __pci_register_driver+0x66/0xe0
  [<ffffffffa043d021>] drm_pci_init+0x111/0x120 [drm]
  [<ffffffff8133c67a>] ? vga_switcheroo_register_handler+0x3a/0x60
  [<ffffffffa0229000>] ? 0xffffffffa0228fff
  [<ffffffffa02290ec>] radeon_init+0xec/0xee [radeon]
  [<ffffffff810002f2>] do_one_initcall+0x42/0x180
  [<ffffffff8109d8d2>] sys_init_module+0x92/0x1e0
  [<ffffffff815407a9>] system_call_fastpath+0x16/0x1b
 Code: 58 2a 43 50 88 43 4e 48 83 c4 08 5b c9 c3 66 90 e8 cb fd ff ff eb
  e6 90 90 90 90 90 90 90 90 90 48 89 f8 89 d1 c1 e9 03 83 e2 07 <f3> 48
  a5 89 d1 f3 a4 c3 20 48 83 ea 20 4c 8b 06 4c 8b 4e 08 4c
 RIP  [<ffffffff81275b5b>] memcpy+0xb/0x120
  RSP <ffff8800aa72db00>
 CR2: ffff8800a4244000
 ---[ end trace fcffa1599cf56382 ]---

Call to acpi_evaluate_object() not always returns 4096 bytes chunks,
on my system it can return 2048 bytes chunk, so pass the length of
retrieved chunk to memcpy(), not the length of the recieving buffer.

Signed-off-by: Igor Murzov <[email protected]>
Reviewed-by: Alex Deucher <[email protected]>
Signed-off-by: Dave Airlie <[email protected]>
Signed-off-by: Ben Hutchings <[email protected]>
hno pushed a commit to hno/linux that referenced this pull request Sep 12, 2012
Fixes issue torvalds#21 on amery/linux-allwinner
hno pushed a commit to hno/linux that referenced this pull request Sep 12, 2012
Fix build using O= (issue torvalds#21) and inline build on CM9
koenkooi pushed a commit to koenkooi/linux that referenced this pull request Oct 2, 2012
…d reasons

commit 5cf02d0 upstream.

We've had some reports of a deadlock where rpciod ends up with a stack
trace like this:

    PID: 2507   TASK: ffff88103691ab40  CPU: 14  COMMAND: "rpciod/14"
     #0 [ffff8810343bf2f0] schedule at ffffffff814dabd9
     #1 [ffff8810343bf3b8] nfs_wait_bit_killable at ffffffffa038fc04 [nfs]
     #2 [ffff8810343bf3c8] __wait_on_bit at ffffffff814dbc2f
     #3 [ffff8810343bf418] out_of_line_wait_on_bit at ffffffff814dbcd8
     #4 [ffff8810343bf488] nfs_commit_inode at ffffffffa039e0c1 [nfs]
     #5 [ffff8810343bf4f8] nfs_release_page at ffffffffa038bef6 [nfs]
     #6 [ffff8810343bf528] try_to_release_page at ffffffff8110c670
     #7 [ffff8810343bf538] shrink_page_list.clone.0 at ffffffff81126271
     #8 [ffff8810343bf668] shrink_inactive_list at ffffffff81126638
     #9 [ffff8810343bf818] shrink_zone at ffffffff8112788f
    torvalds#10 [ffff8810343bf8c8] do_try_to_free_pages at ffffffff81127b1e
    torvalds#11 [ffff8810343bf958] try_to_free_pages at ffffffff8112812f
    torvalds#12 [ffff8810343bfa08] __alloc_pages_nodemask at ffffffff8111fdad
    torvalds#13 [ffff8810343bfb28] kmem_getpages at ffffffff81159942
    torvalds#14 [ffff8810343bfb58] fallback_alloc at ffffffff8115a55a
    torvalds#15 [ffff8810343bfbd8] ____cache_alloc_node at ffffffff8115a2d9
    torvalds#16 [ffff8810343bfc38] kmem_cache_alloc at ffffffff8115b09b
    torvalds#17 [ffff8810343bfc78] sk_prot_alloc at ffffffff81411808
    torvalds#18 [ffff8810343bfcb8] sk_alloc at ffffffff8141197c
    torvalds#19 [ffff8810343bfce8] inet_create at ffffffff81483ba6
    torvalds#20 [ffff8810343bfd38] __sock_create at ffffffff8140b4a7
    torvalds#21 [ffff8810343bfd98] xs_create_sock at ffffffffa01f649b [sunrpc]
    torvalds#22 [ffff8810343bfdd8] xs_tcp_setup_socket at ffffffffa01f6965 [sunrpc]
    torvalds#23 [ffff8810343bfe38] worker_thread at ffffffff810887d0
    torvalds#24 [ffff8810343bfee8] kthread at ffffffff8108dd96
    torvalds#25 [ffff8810343bff48] kernel_thread at ffffffff8100c1ca

rpciod is trying to allocate memory for a new socket to talk to the
server. The VM ends up calling ->releasepage to get more memory, and it
tries to do a blocking commit. That commit can't succeed however without
a connected socket, so we deadlock.

Fix this by setting PF_FSTRANS on the workqueue task prior to doing the
socket allocation, and having nfs_release_page check for that flag when
deciding whether to do a commit call. Also, set PF_FSTRANS
unconditionally in rpc_async_schedule since that function can also do
allocations sometimes.

Signed-off-by: Jeff Layton <[email protected]>
Signed-off-by: Trond Myklebust <[email protected]>
Signed-off-by: Ben Hutchings <[email protected]>
koenkooi pushed a commit to koenkooi/linux that referenced this pull request Oct 2, 2012
commit a3f83ab upstream.

At a boot time I observed following bug:

 BUG: unable to handle kernel paging request at ffff8800a4244000
 IP: [<ffffffff81275b5b>] memcpy+0xb/0x120
 PGD 1816063 PUD 1fe7d067 PMD 1ff9f067 PTE 80000000a4244160
 Oops: 0000 [#1] SMP DEBUG_PAGEALLOC
 CPU 0
 Modules linked in: btusb bluetooth brcmsmac brcmutil crc8 cordic b43 radeon(+)
  mac80211 cfg80211 ttm ohci_hcd drm_kms_helper rfkill drm ssb agpgart mmc_core
  sp5100_tco video battery ac thermal processor rtc_cmos thermal_sys snd_hda_codec_hdmi
  joydev snd_hda_codec_conexant button bcma pcmcia snd_hda_intel snd_hda_codec
  snd_hwdep snd_pcm shpchp pcmcia_core k8temp snd_timer atl1c snd psmouse hwmon
  i2c_piix4 i2c_algo_bit soundcore evdev i2c_core ehci_hcd sg serio_raw snd_page_alloc
  loop btrfs

 Pid: 1008, comm: modprobe Not tainted 3.3.0-rc1 torvalds#21 LENOVO 20046                           /AMD CRB
 RIP: 0010:[<ffffffff81275b5b>]  [<ffffffff81275b5b>] memcpy+0xb/0x120
 RSP: 0018:ffff8800aa72db00  EFLAGS: 00010246
 RAX: ffff8800a4150000 RBX: 0000000000001000 RCX: 0000000000000087
 RDX: 0000000000000000 RSI: ffff8800a4244000 RDI: ffff8800a4150bc8
 RBP: ffff8800aa72db78 R08: 0000000000000010 R09: ffffffff8174bbec
 R10: ffffffff812ee010 R11: 0000000000000001 R12: 0000000000001000
 R13: 0000000000010000 R14: ffff8800a4140000 R15: ffff8800aaba1800
 FS:  00007ff9a3bd4720(0000) GS:ffff8800afa00000(0000) knlGS:0000000000000000
 CS:  0010 DS: 0000 ES: 0000 CR0: 000000008005003b
 CR2: ffff8800a4244000 CR3: 00000000a9c18000 CR4: 00000000000006f0
 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
 DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
 Process modprobe (pid: 1008, threadinfo ffff8800aa72c000, task ffff8800aa0e4000)
 Stack:
  ffffffffa04e7c7b 0000000000000001 0000000000010000 ffff8800aa72db28
  ffffffff00000001 0000000000001000 ffffffff8113cbef 0000000000000020
  ffff8800a4243420 ffff880000000002 ffff8800aa72db08 ffff8800a9d42000
 Call Trace:
  [<ffffffffa04e7c7b>] ? radeon_atrm_get_bios_chunk+0x8b/0xd0 [radeon]
  [<ffffffff8113cbef>] ? kmalloc_order_trace+0x3f/0xb0
  [<ffffffffa04a9298>] radeon_get_bios+0x68/0x2f0 [radeon]
  [<ffffffffa04c7a30>] rv770_init+0x40/0x280 [radeon]
  [<ffffffffa047d740>] radeon_device_init+0x560/0x600 [radeon]
  [<ffffffffa047ef4f>] radeon_driver_load_kms+0xaf/0x170 [radeon]
  [<ffffffffa043cdde>] drm_get_pci_dev+0x18e/0x2c0 [drm]
  [<ffffffffa04e7e95>] radeon_pci_probe+0xad/0xb5 [radeon]
  [<ffffffff81296c5f>] local_pci_probe+0x5f/0xd0
  [<ffffffff81297418>] pci_device_probe+0x88/0xb0
  [<ffffffff813417aa>] ? driver_sysfs_add+0x7a/0xb0
  [<ffffffff813418d8>] really_probe+0x68/0x180
  [<ffffffff81341be5>] driver_probe_device+0x45/0x70
  [<ffffffff81341cb3>] __driver_attach+0xa3/0xb0
  [<ffffffff81341c10>] ? driver_probe_device+0x70/0x70
  [<ffffffff813400ce>] bus_for_each_dev+0x5e/0x90
  [<ffffffff8134172e>] driver_attach+0x1e/0x20
  [<ffffffff81341298>] bus_add_driver+0xc8/0x280
  [<ffffffff813422c6>] driver_register+0x76/0x140
  [<ffffffff812976d6>] __pci_register_driver+0x66/0xe0
  [<ffffffffa043d021>] drm_pci_init+0x111/0x120 [drm]
  [<ffffffff8133c67a>] ? vga_switcheroo_register_handler+0x3a/0x60
  [<ffffffffa0229000>] ? 0xffffffffa0228fff
  [<ffffffffa02290ec>] radeon_init+0xec/0xee [radeon]
  [<ffffffff810002f2>] do_one_initcall+0x42/0x180
  [<ffffffff8109d8d2>] sys_init_module+0x92/0x1e0
  [<ffffffff815407a9>] system_call_fastpath+0x16/0x1b
 Code: 58 2a 43 50 88 43 4e 48 83 c4 08 5b c9 c3 66 90 e8 cb fd ff ff eb
  e6 90 90 90 90 90 90 90 90 90 48 89 f8 89 d1 c1 e9 03 83 e2 07 <f3> 48
  a5 89 d1 f3 a4 c3 20 48 83 ea 20 4c 8b 06 4c 8b 4e 08 4c
 RIP  [<ffffffff81275b5b>] memcpy+0xb/0x120
  RSP <ffff8800aa72db00>
 CR2: ffff8800a4244000
 ---[ end trace fcffa1599cf56382 ]---

Call to acpi_evaluate_object() not always returns 4096 bytes chunks,
on my system it can return 2048 bytes chunk, so pass the length of
retrieved chunk to memcpy(), not the length of the recieving buffer.

Signed-off-by: Igor Murzov <[email protected]>
Reviewed-by: Alex Deucher <[email protected]>
Signed-off-by: Dave Airlie <[email protected]>
Signed-off-by: Ben Hutchings <[email protected]>
koenkooi pushed a commit to koenkooi/linux that referenced this pull request Oct 4, 2012
…d reasons

commit 5cf02d0 upstream.

We've had some reports of a deadlock where rpciod ends up with a stack
trace like this:

    PID: 2507   TASK: ffff88103691ab40  CPU: 14  COMMAND: "rpciod/14"
     #0 [ffff8810343bf2f0] schedule at ffffffff814dabd9
     #1 [ffff8810343bf3b8] nfs_wait_bit_killable at ffffffffa038fc04 [nfs]
     #2 [ffff8810343bf3c8] __wait_on_bit at ffffffff814dbc2f
     #3 [ffff8810343bf418] out_of_line_wait_on_bit at ffffffff814dbcd8
     #4 [ffff8810343bf488] nfs_commit_inode at ffffffffa039e0c1 [nfs]
     #5 [ffff8810343bf4f8] nfs_release_page at ffffffffa038bef6 [nfs]
     #6 [ffff8810343bf528] try_to_release_page at ffffffff8110c670
     #7 [ffff8810343bf538] shrink_page_list.clone.0 at ffffffff81126271
     #8 [ffff8810343bf668] shrink_inactive_list at ffffffff81126638
     #9 [ffff8810343bf818] shrink_zone at ffffffff8112788f
    torvalds#10 [ffff8810343bf8c8] do_try_to_free_pages at ffffffff81127b1e
    torvalds#11 [ffff8810343bf958] try_to_free_pages at ffffffff8112812f
    torvalds#12 [ffff8810343bfa08] __alloc_pages_nodemask at ffffffff8111fdad
    torvalds#13 [ffff8810343bfb28] kmem_getpages at ffffffff81159942
    torvalds#14 [ffff8810343bfb58] fallback_alloc at ffffffff8115a55a
    torvalds#15 [ffff8810343bfbd8] ____cache_alloc_node at ffffffff8115a2d9
    torvalds#16 [ffff8810343bfc38] kmem_cache_alloc at ffffffff8115b09b
    torvalds#17 [ffff8810343bfc78] sk_prot_alloc at ffffffff81411808
    torvalds#18 [ffff8810343bfcb8] sk_alloc at ffffffff8141197c
    torvalds#19 [ffff8810343bfce8] inet_create at ffffffff81483ba6
    torvalds#20 [ffff8810343bfd38] __sock_create at ffffffff8140b4a7
    torvalds#21 [ffff8810343bfd98] xs_create_sock at ffffffffa01f649b [sunrpc]
    torvalds#22 [ffff8810343bfdd8] xs_tcp_setup_socket at ffffffffa01f6965 [sunrpc]
    torvalds#23 [ffff8810343bfe38] worker_thread at ffffffff810887d0
    torvalds#24 [ffff8810343bfee8] kthread at ffffffff8108dd96
    torvalds#25 [ffff8810343bff48] kernel_thread at ffffffff8100c1ca

rpciod is trying to allocate memory for a new socket to talk to the
server. The VM ends up calling ->releasepage to get more memory, and it
tries to do a blocking commit. That commit can't succeed however without
a connected socket, so we deadlock.

Fix this by setting PF_FSTRANS on the workqueue task prior to doing the
socket allocation, and having nfs_release_page check for that flag when
deciding whether to do a commit call. Also, set PF_FSTRANS
unconditionally in rpc_async_schedule since that function can also do
allocations sometimes.

Signed-off-by: Jeff Layton <[email protected]>
Signed-off-by: Trond Myklebust <[email protected]>
Signed-off-by: Ben Hutchings <[email protected]>
koenkooi pushed a commit to koenkooi/linux that referenced this pull request Oct 4, 2012
commit a3f83ab upstream.

At a boot time I observed following bug:

 BUG: unable to handle kernel paging request at ffff8800a4244000
 IP: [<ffffffff81275b5b>] memcpy+0xb/0x120
 PGD 1816063 PUD 1fe7d067 PMD 1ff9f067 PTE 80000000a4244160
 Oops: 0000 [#1] SMP DEBUG_PAGEALLOC
 CPU 0
 Modules linked in: btusb bluetooth brcmsmac brcmutil crc8 cordic b43 radeon(+)
  mac80211 cfg80211 ttm ohci_hcd drm_kms_helper rfkill drm ssb agpgart mmc_core
  sp5100_tco video battery ac thermal processor rtc_cmos thermal_sys snd_hda_codec_hdmi
  joydev snd_hda_codec_conexant button bcma pcmcia snd_hda_intel snd_hda_codec
  snd_hwdep snd_pcm shpchp pcmcia_core k8temp snd_timer atl1c snd psmouse hwmon
  i2c_piix4 i2c_algo_bit soundcore evdev i2c_core ehci_hcd sg serio_raw snd_page_alloc
  loop btrfs

 Pid: 1008, comm: modprobe Not tainted 3.3.0-rc1 torvalds#21 LENOVO 20046                           /AMD CRB
 RIP: 0010:[<ffffffff81275b5b>]  [<ffffffff81275b5b>] memcpy+0xb/0x120
 RSP: 0018:ffff8800aa72db00  EFLAGS: 00010246
 RAX: ffff8800a4150000 RBX: 0000000000001000 RCX: 0000000000000087
 RDX: 0000000000000000 RSI: ffff8800a4244000 RDI: ffff8800a4150bc8
 RBP: ffff8800aa72db78 R08: 0000000000000010 R09: ffffffff8174bbec
 R10: ffffffff812ee010 R11: 0000000000000001 R12: 0000000000001000
 R13: 0000000000010000 R14: ffff8800a4140000 R15: ffff8800aaba1800
 FS:  00007ff9a3bd4720(0000) GS:ffff8800afa00000(0000) knlGS:0000000000000000
 CS:  0010 DS: 0000 ES: 0000 CR0: 000000008005003b
 CR2: ffff8800a4244000 CR3: 00000000a9c18000 CR4: 00000000000006f0
 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
 DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
 Process modprobe (pid: 1008, threadinfo ffff8800aa72c000, task ffff8800aa0e4000)
 Stack:
  ffffffffa04e7c7b 0000000000000001 0000000000010000 ffff8800aa72db28
  ffffffff00000001 0000000000001000 ffffffff8113cbef 0000000000000020
  ffff8800a4243420 ffff880000000002 ffff8800aa72db08 ffff8800a9d42000
 Call Trace:
  [<ffffffffa04e7c7b>] ? radeon_atrm_get_bios_chunk+0x8b/0xd0 [radeon]
  [<ffffffff8113cbef>] ? kmalloc_order_trace+0x3f/0xb0
  [<ffffffffa04a9298>] radeon_get_bios+0x68/0x2f0 [radeon]
  [<ffffffffa04c7a30>] rv770_init+0x40/0x280 [radeon]
  [<ffffffffa047d740>] radeon_device_init+0x560/0x600 [radeon]
  [<ffffffffa047ef4f>] radeon_driver_load_kms+0xaf/0x170 [radeon]
  [<ffffffffa043cdde>] drm_get_pci_dev+0x18e/0x2c0 [drm]
  [<ffffffffa04e7e95>] radeon_pci_probe+0xad/0xb5 [radeon]
  [<ffffffff81296c5f>] local_pci_probe+0x5f/0xd0
  [<ffffffff81297418>] pci_device_probe+0x88/0xb0
  [<ffffffff813417aa>] ? driver_sysfs_add+0x7a/0xb0
  [<ffffffff813418d8>] really_probe+0x68/0x180
  [<ffffffff81341be5>] driver_probe_device+0x45/0x70
  [<ffffffff81341cb3>] __driver_attach+0xa3/0xb0
  [<ffffffff81341c10>] ? driver_probe_device+0x70/0x70
  [<ffffffff813400ce>] bus_for_each_dev+0x5e/0x90
  [<ffffffff8134172e>] driver_attach+0x1e/0x20
  [<ffffffff81341298>] bus_add_driver+0xc8/0x280
  [<ffffffff813422c6>] driver_register+0x76/0x140
  [<ffffffff812976d6>] __pci_register_driver+0x66/0xe0
  [<ffffffffa043d021>] drm_pci_init+0x111/0x120 [drm]
  [<ffffffff8133c67a>] ? vga_switcheroo_register_handler+0x3a/0x60
  [<ffffffffa0229000>] ? 0xffffffffa0228fff
  [<ffffffffa02290ec>] radeon_init+0xec/0xee [radeon]
  [<ffffffff810002f2>] do_one_initcall+0x42/0x180
  [<ffffffff8109d8d2>] sys_init_module+0x92/0x1e0
  [<ffffffff815407a9>] system_call_fastpath+0x16/0x1b
 Code: 58 2a 43 50 88 43 4e 48 83 c4 08 5b c9 c3 66 90 e8 cb fd ff ff eb
  e6 90 90 90 90 90 90 90 90 90 48 89 f8 89 d1 c1 e9 03 83 e2 07 <f3> 48
  a5 89 d1 f3 a4 c3 20 48 83 ea 20 4c 8b 06 4c 8b 4e 08 4c
 RIP  [<ffffffff81275b5b>] memcpy+0xb/0x120
  RSP <ffff8800aa72db00>
 CR2: ffff8800a4244000
 ---[ end trace fcffa1599cf56382 ]---

Call to acpi_evaluate_object() not always returns 4096 bytes chunks,
on my system it can return 2048 bytes chunk, so pass the length of
retrieved chunk to memcpy(), not the length of the recieving buffer.

Signed-off-by: Igor Murzov <[email protected]>
Reviewed-by: Alex Deucher <[email protected]>
Signed-off-by: Dave Airlie <[email protected]>
Signed-off-by: Ben Hutchings <[email protected]>
noamc referenced this pull request in Mellanox/linux Oct 16, 2012
…rq() workaround for clockevent Timer

request_irq() for TIMER0 failing on CPU1

Ideally we want to use the request_percpu_irq( ) / enable_percpu_irq()
calls from GENERIC_IRQ framework, however that seems to be faltering
even on the boot cpu at the time of first interrupt.

Until that is resolved (with Thomas G), we need to pretend that
TIMER0 is IRQF_SHARED. This also requires yet another hack of explicitly
unmasking the IRQ on that CPU.

Query sent to Thomas Gleixner

======================>8====================================
In a SMP setup, each ARC700 CPU has a in-core TIMER, hooked up to
private IRQ 3 of respective CPU and would serve as the local
clock_event_device.

request_irq( ) for my first CPU which succeeds, looks roughly as
follows:

	void __cpuinit arc_clockevent_init(void)
	{
	    int rc;
	    unsigned int cpu = smp_processor_id();
	    struct clock_event_device *evt = &per_cpu(arc_clockevent_device,
							cpu);
	....
	    rc = request_irq(TIMER0_INT, timer_irq_handler,
        	    IRQF_TIMER | IRQF_DISABLED | IRQF_PERCPU,
	            "Timer0 (clock-evt-dev)", evt);
	....

The exact same call, when done from 2nd CPU fails, as it wants to see
IRQF_SHARED which is semantically not correct, since IRQ is not really
shared, it is a private instance (albeit same value), per cpu.

I figured that the right APIs for our case is the pair:
(request|enable)_percpu_irq to be called for both CPUs, with a prior one
time call to irq_set_percpu_devid().  Is that correct?

Assuming it is, the trouble now is that, even on the first CPU,
handle_level_irq( ) is bailing out w/o calling handle_irq_event()
because irqd_irq_disabled( ) is true. This in turn happens because,
irq_set_percpu_devid(), our much needed init routine, sets IRQ_NOAUTOEN
causing __setup_irq( ) to skip calling irq_startup() => irq_enable()
which would have cleared IRQD_IRQ_DISABLED.

While enable_percpu_irq( ), could have fixed this, it only seems to be
unmasking IRQ at device level, it is not clearing the above flag.

I tried calling enable_irq( ) right after, but that doesn't seem to help
either.
What API am I missing here, to enable the irqd machinery, or am I seeing
a bug where enable_percpu_irq( ) call-chain should somehow be doing it.

======================>8====================================

This needs to be reverted and replaced with right calls once ThomasG
responds to my query.

Signed-off-by: Vineet Gupta <[email protected]>
noamc referenced this pull request in Mellanox/linux Oct 16, 2012
…equest_irq() workaround for clockevent Timer"

This reverts commit 2985184.

Next commit uses the correct APIs, so we no longer need this hack
koenkooi pushed a commit to koenkooi/linux that referenced this pull request Oct 17, 2012
…d reasons

commit 5cf02d0 upstream.

We've had some reports of a deadlock where rpciod ends up with a stack
trace like this:

    PID: 2507   TASK: ffff88103691ab40  CPU: 14  COMMAND: "rpciod/14"
     #0 [ffff8810343bf2f0] schedule at ffffffff814dabd9
     #1 [ffff8810343bf3b8] nfs_wait_bit_killable at ffffffffa038fc04 [nfs]
     #2 [ffff8810343bf3c8] __wait_on_bit at ffffffff814dbc2f
     #3 [ffff8810343bf418] out_of_line_wait_on_bit at ffffffff814dbcd8
     #4 [ffff8810343bf488] nfs_commit_inode at ffffffffa039e0c1 [nfs]
     #5 [ffff8810343bf4f8] nfs_release_page at ffffffffa038bef6 [nfs]
     #6 [ffff8810343bf528] try_to_release_page at ffffffff8110c670
     #7 [ffff8810343bf538] shrink_page_list.clone.0 at ffffffff81126271
     #8 [ffff8810343bf668] shrink_inactive_list at ffffffff81126638
     #9 [ffff8810343bf818] shrink_zone at ffffffff8112788f
    torvalds#10 [ffff8810343bf8c8] do_try_to_free_pages at ffffffff81127b1e
    torvalds#11 [ffff8810343bf958] try_to_free_pages at ffffffff8112812f
    torvalds#12 [ffff8810343bfa08] __alloc_pages_nodemask at ffffffff8111fdad
    torvalds#13 [ffff8810343bfb28] kmem_getpages at ffffffff81159942
    torvalds#14 [ffff8810343bfb58] fallback_alloc at ffffffff8115a55a
    torvalds#15 [ffff8810343bfbd8] ____cache_alloc_node at ffffffff8115a2d9
    torvalds#16 [ffff8810343bfc38] kmem_cache_alloc at ffffffff8115b09b
    torvalds#17 [ffff8810343bfc78] sk_prot_alloc at ffffffff81411808
    torvalds#18 [ffff8810343bfcb8] sk_alloc at ffffffff8141197c
    torvalds#19 [ffff8810343bfce8] inet_create at ffffffff81483ba6
    torvalds#20 [ffff8810343bfd38] __sock_create at ffffffff8140b4a7
    torvalds#21 [ffff8810343bfd98] xs_create_sock at ffffffffa01f649b [sunrpc]
    torvalds#22 [ffff8810343bfdd8] xs_tcp_setup_socket at ffffffffa01f6965 [sunrpc]
    torvalds#23 [ffff8810343bfe38] worker_thread at ffffffff810887d0
    torvalds#24 [ffff8810343bfee8] kthread at ffffffff8108dd96
    torvalds#25 [ffff8810343bff48] kernel_thread at ffffffff8100c1ca

rpciod is trying to allocate memory for a new socket to talk to the
server. The VM ends up calling ->releasepage to get more memory, and it
tries to do a blocking commit. That commit can't succeed however without
a connected socket, so we deadlock.

Fix this by setting PF_FSTRANS on the workqueue task prior to doing the
socket allocation, and having nfs_release_page check for that flag when
deciding whether to do a commit call. Also, set PF_FSTRANS
unconditionally in rpc_async_schedule since that function can also do
allocations sometimes.

Signed-off-by: Jeff Layton <[email protected]>
Signed-off-by: Trond Myklebust <[email protected]>
Signed-off-by: Ben Hutchings <[email protected]>
koenkooi pushed a commit to koenkooi/linux that referenced this pull request Oct 17, 2012
commit a3f83ab upstream.

At a boot time I observed following bug:

 BUG: unable to handle kernel paging request at ffff8800a4244000
 IP: [<ffffffff81275b5b>] memcpy+0xb/0x120
 PGD 1816063 PUD 1fe7d067 PMD 1ff9f067 PTE 80000000a4244160
 Oops: 0000 [#1] SMP DEBUG_PAGEALLOC
 CPU 0
 Modules linked in: btusb bluetooth brcmsmac brcmutil crc8 cordic b43 radeon(+)
  mac80211 cfg80211 ttm ohci_hcd drm_kms_helper rfkill drm ssb agpgart mmc_core
  sp5100_tco video battery ac thermal processor rtc_cmos thermal_sys snd_hda_codec_hdmi
  joydev snd_hda_codec_conexant button bcma pcmcia snd_hda_intel snd_hda_codec
  snd_hwdep snd_pcm shpchp pcmcia_core k8temp snd_timer atl1c snd psmouse hwmon
  i2c_piix4 i2c_algo_bit soundcore evdev i2c_core ehci_hcd sg serio_raw snd_page_alloc
  loop btrfs

 Pid: 1008, comm: modprobe Not tainted 3.3.0-rc1 torvalds#21 LENOVO 20046                           /AMD CRB
 RIP: 0010:[<ffffffff81275b5b>]  [<ffffffff81275b5b>] memcpy+0xb/0x120
 RSP: 0018:ffff8800aa72db00  EFLAGS: 00010246
 RAX: ffff8800a4150000 RBX: 0000000000001000 RCX: 0000000000000087
 RDX: 0000000000000000 RSI: ffff8800a4244000 RDI: ffff8800a4150bc8
 RBP: ffff8800aa72db78 R08: 0000000000000010 R09: ffffffff8174bbec
 R10: ffffffff812ee010 R11: 0000000000000001 R12: 0000000000001000
 R13: 0000000000010000 R14: ffff8800a4140000 R15: ffff8800aaba1800
 FS:  00007ff9a3bd4720(0000) GS:ffff8800afa00000(0000) knlGS:0000000000000000
 CS:  0010 DS: 0000 ES: 0000 CR0: 000000008005003b
 CR2: ffff8800a4244000 CR3: 00000000a9c18000 CR4: 00000000000006f0
 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
 DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
 Process modprobe (pid: 1008, threadinfo ffff8800aa72c000, task ffff8800aa0e4000)
 Stack:
  ffffffffa04e7c7b 0000000000000001 0000000000010000 ffff8800aa72db28
  ffffffff00000001 0000000000001000 ffffffff8113cbef 0000000000000020
  ffff8800a4243420 ffff880000000002 ffff8800aa72db08 ffff8800a9d42000
 Call Trace:
  [<ffffffffa04e7c7b>] ? radeon_atrm_get_bios_chunk+0x8b/0xd0 [radeon]
  [<ffffffff8113cbef>] ? kmalloc_order_trace+0x3f/0xb0
  [<ffffffffa04a9298>] radeon_get_bios+0x68/0x2f0 [radeon]
  [<ffffffffa04c7a30>] rv770_init+0x40/0x280 [radeon]
  [<ffffffffa047d740>] radeon_device_init+0x560/0x600 [radeon]
  [<ffffffffa047ef4f>] radeon_driver_load_kms+0xaf/0x170 [radeon]
  [<ffffffffa043cdde>] drm_get_pci_dev+0x18e/0x2c0 [drm]
  [<ffffffffa04e7e95>] radeon_pci_probe+0xad/0xb5 [radeon]
  [<ffffffff81296c5f>] local_pci_probe+0x5f/0xd0
  [<ffffffff81297418>] pci_device_probe+0x88/0xb0
  [<ffffffff813417aa>] ? driver_sysfs_add+0x7a/0xb0
  [<ffffffff813418d8>] really_probe+0x68/0x180
  [<ffffffff81341be5>] driver_probe_device+0x45/0x70
  [<ffffffff81341cb3>] __driver_attach+0xa3/0xb0
  [<ffffffff81341c10>] ? driver_probe_device+0x70/0x70
  [<ffffffff813400ce>] bus_for_each_dev+0x5e/0x90
  [<ffffffff8134172e>] driver_attach+0x1e/0x20
  [<ffffffff81341298>] bus_add_driver+0xc8/0x280
  [<ffffffff813422c6>] driver_register+0x76/0x140
  [<ffffffff812976d6>] __pci_register_driver+0x66/0xe0
  [<ffffffffa043d021>] drm_pci_init+0x111/0x120 [drm]
  [<ffffffff8133c67a>] ? vga_switcheroo_register_handler+0x3a/0x60
  [<ffffffffa0229000>] ? 0xffffffffa0228fff
  [<ffffffffa02290ec>] radeon_init+0xec/0xee [radeon]
  [<ffffffff810002f2>] do_one_initcall+0x42/0x180
  [<ffffffff8109d8d2>] sys_init_module+0x92/0x1e0
  [<ffffffff815407a9>] system_call_fastpath+0x16/0x1b
 Code: 58 2a 43 50 88 43 4e 48 83 c4 08 5b c9 c3 66 90 e8 cb fd ff ff eb
  e6 90 90 90 90 90 90 90 90 90 48 89 f8 89 d1 c1 e9 03 83 e2 07 <f3> 48
  a5 89 d1 f3 a4 c3 20 48 83 ea 20 4c 8b 06 4c 8b 4e 08 4c
 RIP  [<ffffffff81275b5b>] memcpy+0xb/0x120
  RSP <ffff8800aa72db00>
 CR2: ffff8800a4244000
 ---[ end trace fcffa1599cf56382 ]---

Call to acpi_evaluate_object() not always returns 4096 bytes chunks,
on my system it can return 2048 bytes chunk, so pass the length of
retrieved chunk to memcpy(), not the length of the recieving buffer.

Signed-off-by: Igor Murzov <[email protected]>
Reviewed-by: Alex Deucher <[email protected]>
Signed-off-by: Dave Airlie <[email protected]>
Signed-off-by: Ben Hutchings <[email protected]>
hknkkn pushed a commit to hknkkn/linux-dynticks that referenced this pull request Oct 29, 2012
Printing the "start_ip" for every secondary cpu is very noisy on a large
system - and doesn't add any value. Drop this message.

Console log before:
Booting Node   0, Processors  #1
smpboot cpu 1: start_ip = 96000
 #2
smpboot cpu 2: start_ip = 96000
 #3
smpboot cpu 3: start_ip = 96000
 #4
smpboot cpu 4: start_ip = 96000
       ...
 torvalds#31
smpboot cpu 31: start_ip = 96000
Brought up 32 CPUs

Console log after:
Booting Node   0, Processors  #1 #2 #3 #4 #5 torvalds#6 torvalds#7 Ok.
Booting Node   1, Processors  torvalds#8 torvalds#9 torvalds#10 torvalds#11 torvalds#12 torvalds#13 torvalds#14 torvalds#15 Ok.
Booting Node   0, Processors  torvalds#16 torvalds#17 torvalds#18 torvalds#19 torvalds#20 torvalds#21 torvalds#22 torvalds#23 Ok.
Booting Node   1, Processors  torvalds#24 torvalds#25 torvalds#26 torvalds#27 torvalds#28 torvalds#29 torvalds#30 torvalds#31
Brought up 32 CPUs

Acked-by: Borislav Petkov <[email protected]>
Signed-off-by: Tony Luck <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: H. Peter Anvin <[email protected]>
koenkooi pushed a commit to koenkooi/linux that referenced this pull request Oct 31, 2012
…d reasons

commit 5cf02d0 upstream.

We've had some reports of a deadlock where rpciod ends up with a stack
trace like this:

    PID: 2507   TASK: ffff88103691ab40  CPU: 14  COMMAND: "rpciod/14"
     #0 [ffff8810343bf2f0] schedule at ffffffff814dabd9
     #1 [ffff8810343bf3b8] nfs_wait_bit_killable at ffffffffa038fc04 [nfs]
     #2 [ffff8810343bf3c8] __wait_on_bit at ffffffff814dbc2f
     #3 [ffff8810343bf418] out_of_line_wait_on_bit at ffffffff814dbcd8
     #4 [ffff8810343bf488] nfs_commit_inode at ffffffffa039e0c1 [nfs]
     #5 [ffff8810343bf4f8] nfs_release_page at ffffffffa038bef6 [nfs]
     #6 [ffff8810343bf528] try_to_release_page at ffffffff8110c670
     #7 [ffff8810343bf538] shrink_page_list.clone.0 at ffffffff81126271
     #8 [ffff8810343bf668] shrink_inactive_list at ffffffff81126638
     #9 [ffff8810343bf818] shrink_zone at ffffffff8112788f
    torvalds#10 [ffff8810343bf8c8] do_try_to_free_pages at ffffffff81127b1e
    torvalds#11 [ffff8810343bf958] try_to_free_pages at ffffffff8112812f
    torvalds#12 [ffff8810343bfa08] __alloc_pages_nodemask at ffffffff8111fdad
    torvalds#13 [ffff8810343bfb28] kmem_getpages at ffffffff81159942
    torvalds#14 [ffff8810343bfb58] fallback_alloc at ffffffff8115a55a
    torvalds#15 [ffff8810343bfbd8] ____cache_alloc_node at ffffffff8115a2d9
    torvalds#16 [ffff8810343bfc38] kmem_cache_alloc at ffffffff8115b09b
    torvalds#17 [ffff8810343bfc78] sk_prot_alloc at ffffffff81411808
    torvalds#18 [ffff8810343bfcb8] sk_alloc at ffffffff8141197c
    torvalds#19 [ffff8810343bfce8] inet_create at ffffffff81483ba6
    torvalds#20 [ffff8810343bfd38] __sock_create at ffffffff8140b4a7
    torvalds#21 [ffff8810343bfd98] xs_create_sock at ffffffffa01f649b [sunrpc]
    torvalds#22 [ffff8810343bfdd8] xs_tcp_setup_socket at ffffffffa01f6965 [sunrpc]
    torvalds#23 [ffff8810343bfe38] worker_thread at ffffffff810887d0
    torvalds#24 [ffff8810343bfee8] kthread at ffffffff8108dd96
    torvalds#25 [ffff8810343bff48] kernel_thread at ffffffff8100c1ca

rpciod is trying to allocate memory for a new socket to talk to the
server. The VM ends up calling ->releasepage to get more memory, and it
tries to do a blocking commit. That commit can't succeed however without
a connected socket, so we deadlock.

Fix this by setting PF_FSTRANS on the workqueue task prior to doing the
socket allocation, and having nfs_release_page check for that flag when
deciding whether to do a commit call. Also, set PF_FSTRANS
unconditionally in rpc_async_schedule since that function can also do
allocations sometimes.

Signed-off-by: Jeff Layton <[email protected]>
Signed-off-by: Trond Myklebust <[email protected]>
Signed-off-by: Ben Hutchings <[email protected]>
koenkooi pushed a commit to koenkooi/linux that referenced this pull request Oct 31, 2012
commit a3f83ab upstream.

At a boot time I observed following bug:

 BUG: unable to handle kernel paging request at ffff8800a4244000
 IP: [<ffffffff81275b5b>] memcpy+0xb/0x120
 PGD 1816063 PUD 1fe7d067 PMD 1ff9f067 PTE 80000000a4244160
 Oops: 0000 [#1] SMP DEBUG_PAGEALLOC
 CPU 0
 Modules linked in: btusb bluetooth brcmsmac brcmutil crc8 cordic b43 radeon(+)
  mac80211 cfg80211 ttm ohci_hcd drm_kms_helper rfkill drm ssb agpgart mmc_core
  sp5100_tco video battery ac thermal processor rtc_cmos thermal_sys snd_hda_codec_hdmi
  joydev snd_hda_codec_conexant button bcma pcmcia snd_hda_intel snd_hda_codec
  snd_hwdep snd_pcm shpchp pcmcia_core k8temp snd_timer atl1c snd psmouse hwmon
  i2c_piix4 i2c_algo_bit soundcore evdev i2c_core ehci_hcd sg serio_raw snd_page_alloc
  loop btrfs

 Pid: 1008, comm: modprobe Not tainted 3.3.0-rc1 torvalds#21 LENOVO 20046                           /AMD CRB
 RIP: 0010:[<ffffffff81275b5b>]  [<ffffffff81275b5b>] memcpy+0xb/0x120
 RSP: 0018:ffff8800aa72db00  EFLAGS: 00010246
 RAX: ffff8800a4150000 RBX: 0000000000001000 RCX: 0000000000000087
 RDX: 0000000000000000 RSI: ffff8800a4244000 RDI: ffff8800a4150bc8
 RBP: ffff8800aa72db78 R08: 0000000000000010 R09: ffffffff8174bbec
 R10: ffffffff812ee010 R11: 0000000000000001 R12: 0000000000001000
 R13: 0000000000010000 R14: ffff8800a4140000 R15: ffff8800aaba1800
 FS:  00007ff9a3bd4720(0000) GS:ffff8800afa00000(0000) knlGS:0000000000000000
 CS:  0010 DS: 0000 ES: 0000 CR0: 000000008005003b
 CR2: ffff8800a4244000 CR3: 00000000a9c18000 CR4: 00000000000006f0
 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
 DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
 Process modprobe (pid: 1008, threadinfo ffff8800aa72c000, task ffff8800aa0e4000)
 Stack:
  ffffffffa04e7c7b 0000000000000001 0000000000010000 ffff8800aa72db28
  ffffffff00000001 0000000000001000 ffffffff8113cbef 0000000000000020
  ffff8800a4243420 ffff880000000002 ffff8800aa72db08 ffff8800a9d42000
 Call Trace:
  [<ffffffffa04e7c7b>] ? radeon_atrm_get_bios_chunk+0x8b/0xd0 [radeon]
  [<ffffffff8113cbef>] ? kmalloc_order_trace+0x3f/0xb0
  [<ffffffffa04a9298>] radeon_get_bios+0x68/0x2f0 [radeon]
  [<ffffffffa04c7a30>] rv770_init+0x40/0x280 [radeon]
  [<ffffffffa047d740>] radeon_device_init+0x560/0x600 [radeon]
  [<ffffffffa047ef4f>] radeon_driver_load_kms+0xaf/0x170 [radeon]
  [<ffffffffa043cdde>] drm_get_pci_dev+0x18e/0x2c0 [drm]
  [<ffffffffa04e7e95>] radeon_pci_probe+0xad/0xb5 [radeon]
  [<ffffffff81296c5f>] local_pci_probe+0x5f/0xd0
  [<ffffffff81297418>] pci_device_probe+0x88/0xb0
  [<ffffffff813417aa>] ? driver_sysfs_add+0x7a/0xb0
  [<ffffffff813418d8>] really_probe+0x68/0x180
  [<ffffffff81341be5>] driver_probe_device+0x45/0x70
  [<ffffffff81341cb3>] __driver_attach+0xa3/0xb0
  [<ffffffff81341c10>] ? driver_probe_device+0x70/0x70
  [<ffffffff813400ce>] bus_for_each_dev+0x5e/0x90
  [<ffffffff8134172e>] driver_attach+0x1e/0x20
  [<ffffffff81341298>] bus_add_driver+0xc8/0x280
  [<ffffffff813422c6>] driver_register+0x76/0x140
  [<ffffffff812976d6>] __pci_register_driver+0x66/0xe0
  [<ffffffffa043d021>] drm_pci_init+0x111/0x120 [drm]
  [<ffffffff8133c67a>] ? vga_switcheroo_register_handler+0x3a/0x60
  [<ffffffffa0229000>] ? 0xffffffffa0228fff
  [<ffffffffa02290ec>] radeon_init+0xec/0xee [radeon]
  [<ffffffff810002f2>] do_one_initcall+0x42/0x180
  [<ffffffff8109d8d2>] sys_init_module+0x92/0x1e0
  [<ffffffff815407a9>] system_call_fastpath+0x16/0x1b
 Code: 58 2a 43 50 88 43 4e 48 83 c4 08 5b c9 c3 66 90 e8 cb fd ff ff eb
  e6 90 90 90 90 90 90 90 90 90 48 89 f8 89 d1 c1 e9 03 83 e2 07 <f3> 48
  a5 89 d1 f3 a4 c3 20 48 83 ea 20 4c 8b 06 4c 8b 4e 08 4c
 RIP  [<ffffffff81275b5b>] memcpy+0xb/0x120
  RSP <ffff8800aa72db00>
 CR2: ffff8800a4244000
 ---[ end trace fcffa1599cf56382 ]---

Call to acpi_evaluate_object() not always returns 4096 bytes chunks,
on my system it can return 2048 bytes chunk, so pass the length of
retrieved chunk to memcpy(), not the length of the recieving buffer.

Signed-off-by: Igor Murzov <[email protected]>
Reviewed-by: Alex Deucher <[email protected]>
Signed-off-by: Dave Airlie <[email protected]>
Signed-off-by: Ben Hutchings <[email protected]>
vineetgarc referenced this pull request in foss-for-synopsys-dwc-arc-processors/linux Oct 31, 2012
request_irq() for TIMER0 failing on CPU1

Ideally we want to use the request_percpu_irq( ) / enable_percpu_irq()
calls from GENERIC_IRQ framework, however that seems to be faltering
even on the boot cpu at the time of first interrupt.

Until that is resolved (with Thomas G), we need to pretend that
TIMER0 is IRQF_SHARED. This also requires yet another hack of explicitly
unmasking the IRQ on that CPU.

Query sent to Thomas Gleixner

======================>8====================================
In a SMP setup, each ARC700 CPU has a in-core TIMER, hooked up to
private IRQ 3 of respective CPU and would serve as the local
clock_event_device.

request_irq( ) for my first CPU which succeeds, looks roughly as
follows:

	void __cpuinit arc_clockevent_init(void)
	{
	    int rc;
	    unsigned int cpu = smp_processor_id();
	    struct clock_event_device *evt = &per_cpu(arc_clockevent_device,
							cpu);
	....
	    rc = request_irq(TIMER0_INT, timer_irq_handler,
        	    IRQF_TIMER | IRQF_DISABLED | IRQF_PERCPU,
	            "Timer0 (clock-evt-dev)", evt);
	....

The exact same call, when done from 2nd CPU fails, as it wants to see
IRQF_SHARED which is semantically not correct, since IRQ is not really
shared, it is a private instance (albeit same value), per cpu.

I figured that the right APIs for our case is the pair:
(request|enable)_percpu_irq to be called for both CPUs, with a prior one
time call to irq_set_percpu_devid().  Is that correct?

Assuming it is, the trouble now is that, even on the first CPU,
handle_level_irq( ) is bailing out w/o calling handle_irq_event()
because irqd_irq_disabled( ) is true. This in turn happens because,
irq_set_percpu_devid(), our much needed init routine, sets IRQ_NOAUTOEN
causing __setup_irq( ) to skip calling irq_startup() => irq_enable()
which would have cleared IRQD_IRQ_DISABLED.

While enable_percpu_irq( ), could have fixed this, it only seems to be
unmasking IRQ at device level, it is not clearing the above flag.

I tried calling enable_irq( ) right after, but that doesn't seem to help
either.
What API am I missing here, to enable the irqd machinery, or am I seeing
a bug where enable_percpu_irq( ) call-chain should somehow be doing it.

======================>8====================================

This needs to be reverted and replaced with right calls once ThomasG
responds to my query.

Signed-off-by: Vineet Gupta <[email protected]>
vineetgarc referenced this pull request in foss-for-synopsys-dwc-arc-processors/linux Oct 31, 2012
…nt Timer"

This reverts commit 2985184.

Next commit uses the correct APIs, so we no longer need this hack

Signed-off-by: Vineet Gupta <[email protected]>
jadonk pushed a commit to jadonk/linux that referenced this pull request Nov 13, 2012
At a boot time I observed following bug:

 BUG: unable to handle kernel paging request at ffff8800a4244000
 IP: [<ffffffff81275b5b>] memcpy+0xb/0x120
 PGD 1816063 PUD 1fe7d067 PMD 1ff9f067 PTE 80000000a4244160
 Oops: 0000 [#1] SMP DEBUG_PAGEALLOC
 CPU 0
 Modules linked in: btusb bluetooth brcmsmac brcmutil crc8 cordic b43 radeon(+)
  mac80211 cfg80211 ttm ohci_hcd drm_kms_helper rfkill drm ssb agpgart mmc_core
  sp5100_tco video battery ac thermal processor rtc_cmos thermal_sys snd_hda_codec_hdmi
  joydev snd_hda_codec_conexant button bcma pcmcia snd_hda_intel snd_hda_codec
  snd_hwdep snd_pcm shpchp pcmcia_core k8temp snd_timer atl1c snd psmouse hwmon
  i2c_piix4 i2c_algo_bit soundcore evdev i2c_core ehci_hcd sg serio_raw snd_page_alloc
  loop btrfs

 Pid: 1008, comm: modprobe Not tainted 3.3.0-rc1 torvalds#21 LENOVO 20046                           /AMD CRB
 RIP: 0010:[<ffffffff81275b5b>]  [<ffffffff81275b5b>] memcpy+0xb/0x120
 RSP: 0018:ffff8800aa72db00  EFLAGS: 00010246
 RAX: ffff8800a4150000 RBX: 0000000000001000 RCX: 0000000000000087
 RDX: 0000000000000000 RSI: ffff8800a4244000 RDI: ffff8800a4150bc8
 RBP: ffff8800aa72db78 R08: 0000000000000010 R09: ffffffff8174bbec
 R10: ffffffff812ee010 R11: 0000000000000001 R12: 0000000000001000
 R13: 0000000000010000 R14: ffff8800a4140000 R15: ffff8800aaba1800
 FS:  00007ff9a3bd4720(0000) GS:ffff8800afa00000(0000) knlGS:0000000000000000
 CS:  0010 DS: 0000 ES: 0000 CR0: 000000008005003b
 CR2: ffff8800a4244000 CR3: 00000000a9c18000 CR4: 00000000000006f0
 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
 DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
 Process modprobe (pid: 1008, threadinfo ffff8800aa72c000, task ffff8800aa0e4000)
 Stack:
  ffffffffa04e7c7b 0000000000000001 0000000000010000 ffff8800aa72db28
  ffffffff00000001 0000000000001000 ffffffff8113cbef 0000000000000020
  ffff8800a4243420 ffff880000000002 ffff8800aa72db08 ffff8800a9d42000
 Call Trace:
  [<ffffffffa04e7c7b>] ? radeon_atrm_get_bios_chunk+0x8b/0xd0 [radeon]
  [<ffffffff8113cbef>] ? kmalloc_order_trace+0x3f/0xb0
  [<ffffffffa04a9298>] radeon_get_bios+0x68/0x2f0 [radeon]
  [<ffffffffa04c7a30>] rv770_init+0x40/0x280 [radeon]
  [<ffffffffa047d740>] radeon_device_init+0x560/0x600 [radeon]
  [<ffffffffa047ef4f>] radeon_driver_load_kms+0xaf/0x170 [radeon]
  [<ffffffffa043cdde>] drm_get_pci_dev+0x18e/0x2c0 [drm]
  [<ffffffffa04e7e95>] radeon_pci_probe+0xad/0xb5 [radeon]
  [<ffffffff81296c5f>] local_pci_probe+0x5f/0xd0
  [<ffffffff81297418>] pci_device_probe+0x88/0xb0
  [<ffffffff813417aa>] ? driver_sysfs_add+0x7a/0xb0
  [<ffffffff813418d8>] really_probe+0x68/0x180
  [<ffffffff81341be5>] driver_probe_device+0x45/0x70
  [<ffffffff81341cb3>] __driver_attach+0xa3/0xb0
  [<ffffffff81341c10>] ? driver_probe_device+0x70/0x70
  [<ffffffff813400ce>] bus_for_each_dev+0x5e/0x90
  [<ffffffff8134172e>] driver_attach+0x1e/0x20
  [<ffffffff81341298>] bus_add_driver+0xc8/0x280
  [<ffffffff813422c6>] driver_register+0x76/0x140
  [<ffffffff812976d6>] __pci_register_driver+0x66/0xe0
  [<ffffffffa043d021>] drm_pci_init+0x111/0x120 [drm]
  [<ffffffff8133c67a>] ? vga_switcheroo_register_handler+0x3a/0x60
  [<ffffffffa0229000>] ? 0xffffffffa0228fff
  [<ffffffffa02290ec>] radeon_init+0xec/0xee [radeon]
  [<ffffffff810002f2>] do_one_initcall+0x42/0x180
  [<ffffffff8109d8d2>] sys_init_module+0x92/0x1e0
  [<ffffffff815407a9>] system_call_fastpath+0x16/0x1b
 Code: 58 2a 43 50 88 43 4e 48 83 c4 08 5b c9 c3 66 90 e8 cb fd ff ff eb
  e6 90 90 90 90 90 90 90 90 90 48 89 f8 89 d1 c1 e9 03 83 e2 07 <f3> 48
  a5 89 d1 f3 a4 c3 20 48 83 ea 20 4c 8b 06 4c 8b 4e 08 4c
 RIP  [<ffffffff81275b5b>] memcpy+0xb/0x120
  RSP <ffff8800aa72db00>
 CR2: ffff8800a4244000
 ---[ end trace fcffa1599cf56382 ]---

Call to acpi_evaluate_object() not always returns 4096 bytes chunks,
on my system it can return 2048 bytes chunk, so pass the length of
retrieved chunk to memcpy(), not the length of the recieving buffer.

Signed-off-by: Igor Murzov <[email protected]>
Reviewed-by: Alex Deucher <[email protected]>
Signed-off-by: Dave Airlie <[email protected]>
jadonk pushed a commit to jadonk/linux that referenced this pull request Nov 13, 2012
If the netdev is already in NETREG_UNREGISTERING/_UNREGISTERED state, do not
update the real num tx queues. netdev_queue_update_kobjects() is already
called via remove_queue_kobjects() at NETREG_UNREGISTERING time. So, when
upper layer driver, e.g., FCoE protocol stack is monitoring the netdev
event of NETDEV_UNREGISTER and calls back to LLD ndo_fcoe_disable() to remove
extra queues allocated for FCoE, the associated txq sysfs kobjects are already
removed, and trying to update the real num queues would cause something like
below:

...
PID: 25138  TASK: ffff88021e64c440  CPU: 3   COMMAND: "kworker/3:3"
 #0 [ffff88021f007760] machine_kexec at ffffffff810226d9
 #1 [ffff88021f0077d0] crash_kexec at ffffffff81089d2d
 #2 [ffff88021f0078a0] oops_end at ffffffff813bca78
 #3 [ffff88021f0078d0] no_context at ffffffff81029e72
 #4 [ffff88021f007920] __bad_area_nosemaphore at ffffffff8102a155
 #5 [ffff88021f0079f0] bad_area_nosemaphore at ffffffff8102a23e
 torvalds#6 [ffff88021f007a00] do_page_fault at ffffffff813bf32e
 torvalds#7 [ffff88021f007b10] page_fault at ffffffff813bc045
    [exception RIP: sysfs_find_dirent+17]
    RIP: ffffffff81178611  RSP: ffff88021f007bc0  RFLAGS: 00010246
    RAX: ffff88021e64c440  RBX: ffffffff8156cc63  RCX: 0000000000000004
    RDX: ffffffff8156cc63  RSI: 0000000000000000  RDI: 0000000000000000
    RBP: ffff88021f007be0   R8: 0000000000000004   R9: 0000000000000008
    R10: ffffffff816fed00  R11: 0000000000000004  R12: 0000000000000000
    R13: ffffffff8156cc63  R14: 0000000000000000  R15: ffff8802222a0000
    ORIG_RAX: ffffffffffffffff  CS: 0010  SS: 0018
 torvalds#8 [ffff88021f007be8] sysfs_get_dirent at ffffffff81178c07
 torvalds#9 [ffff88021f007c18] sysfs_remove_group at ffffffff8117ac27
torvalds#10 [ffff88021f007c48] netdev_queue_update_kobjects at ffffffff813178f9
torvalds#11 [ffff88021f007c88] netif_set_real_num_tx_queues at ffffffff81303e38
torvalds#12 [ffff88021f007cc8] ixgbe_set_num_queues at ffffffffa0249763 [ixgbe]
torvalds#13 [ffff88021f007cf8] ixgbe_init_interrupt_scheme at ffffffffa024ea89 [ixgbe]
torvalds#14 [ffff88021f007d48] ixgbe_fcoe_disable at ffffffffa0267113 [ixgbe]
torvalds#15 [ffff88021f007d68] vlan_dev_fcoe_disable at ffffffffa014fef5 [8021q]
torvalds#16 [ffff88021f007d78] fcoe_interface_cleanup at ffffffffa02b7dfd [fcoe]
torvalds#17 [ffff88021f007df8] fcoe_destroy_work at ffffffffa02b7f08 [fcoe]
torvalds#18 [ffff88021f007e18] process_one_work at ffffffff8105d7ca
torvalds#19 [ffff88021f007e68] worker_thread at ffffffff81060513
torvalds#20 [ffff88021f007ee8] kthread at ffffffff810648b6
torvalds#21 [ffff88021f007f48] kernel_thread_helper at ffffffff813c40f4

Signed-off-by: Yi Zou <[email protected]>
Tested-by: Ross Brattain <[email protected]>
Tested-by: Stephen Ko <[email protected]>
Signed-off-by: Jeff Kirsher <[email protected]>
guidosarducci added a commit to guidosarducci/linux that referenced this pull request Aug 5, 2025
Sequence of ctx checks and rewrites in real world:

1. Possible CO-RE rewrites of access size & offset, maybe breaking #2
2. Verifier env->ops->is_valid_access(), testing access size == sizeof(u64)
3. Verifier env->ops->convert_ctx_access(), rewrite size & offset

Position of access check above is strange, really only works on 64-bit and
likely unnoticed for lack of systematic 32-bit testing.

Test changing *is_valid_access() to always check size != sizeof(u64), but
on 32-bit systems also check size != sizeof(u32)

On 32-bit armhf, test_progs hits ~100 instances of failures such as:

(NOTE: this results from CO-RE relocation patching to u32 load size)

  libbpf: prog 'change_tcp_cc': -- BEGIN PROG LOAD LOG --
  0: R1=ctx() R10=fp0
  ; int change_tcp_cc(struct bpf_iter__tcp *ctx) @ bpf_iter_setsockopt.c:40
  0: (b4) w2 = 0                        ; R2_w=0
  ; if (!bpf_tcp_sk(ctx->sk_common)) @ bpf_iter_setsockopt.c:46
  1: (61) r1 = *(u32 *)(r1 +8)
  func 'bpf_iter_tcp' size 4 must be 8
  invalid bpf_context access off=8 size=4 is_valid_access=tracing_prog_is_valid_access
  processed 2 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
  -- END PROG LOAD LOG --
  libbpf: prog 'change_tcp_cc': failed to load: -EACCES
  libbpf: failed to load object 'bpf_iter_setsockopt'
  libbpf: failed to load BPF skeleton 'bpf_iter_setsockopt': -EACCES
  serial_test_bpf_iter_setsockopt:FAIL:iter_skel unexpected error: -13
  torvalds#21      bpf_iter_setsockopt:FAIL

(NOTE: no error for tests without CO-RE patching which have u64 load size)

This means *_is_valid_access() can't check ctx pointers simply using:

	if (size != sizeof(__u64))
		return false;
or
	if (size != sizeof(void *)
		return false;

And what's required instead is a combo like:

	if (size != sizeof(__u64) && size != sizeof(long))
		return false;

Implement above as convenience function and use in:

 - btf_ctx_access()
 - cg_sockopt_is_valid_access()
 - bpf_skb_is_valid_access()
 - sock_addr_is_valid_access()
 - sock_ops_is_valid_access()
 - sk_msg_is_valid_access()
 - flow_dissector_is_valid_access()

This eliminates all 'invalid bpf_context access" errors on 32-bit armhf
except one with nf_is_valid_access() which is fixed in the next patch.

Signed-off-by: Tony Ambardar <[email protected]>
guidosarducci added a commit to guidosarducci/linux that referenced this pull request Aug 9, 2025
Sequence of ctx checks and rewrites in real world:

1. Possible CO-RE rewrites of access size & offset, maybe breaking #2
2. Verifier env->ops->is_valid_access(), testing access size == sizeof(u64)
3. Verifier env->ops->convert_ctx_access(), rewrite size & offset

Position of access check above is strange, really only works on 64-bit and
likely unnoticed for lack of systematic 32-bit testing.

Test changing *is_valid_access() to always check size != sizeof(u64), but
on 32-bit systems also check size != sizeof(u32)

On 32-bit armhf, test_progs hits ~100 instances of failures such as:

(NOTE: this results from CO-RE relocation patching to u32 load size)

  libbpf: prog 'change_tcp_cc': -- BEGIN PROG LOAD LOG --
  0: R1=ctx() R10=fp0
  ; int change_tcp_cc(struct bpf_iter__tcp *ctx) @ bpf_iter_setsockopt.c:40
  0: (b4) w2 = 0                        ; R2_w=0
  ; if (!bpf_tcp_sk(ctx->sk_common)) @ bpf_iter_setsockopt.c:46
  1: (61) r1 = *(u32 *)(r1 +8)
  func 'bpf_iter_tcp' size 4 must be 8
  invalid bpf_context access off=8 size=4 is_valid_access=tracing_prog_is_valid_access
  processed 2 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
  -- END PROG LOAD LOG --
  libbpf: prog 'change_tcp_cc': failed to load: -EACCES
  libbpf: failed to load object 'bpf_iter_setsockopt'
  libbpf: failed to load BPF skeleton 'bpf_iter_setsockopt': -EACCES
  serial_test_bpf_iter_setsockopt:FAIL:iter_skel unexpected error: -13
  torvalds#21      bpf_iter_setsockopt:FAIL

(NOTE: no error for tests without CO-RE patching which have u64 load size)

This means *_is_valid_access() can't check ctx pointers simply using:

	if (size != sizeof(__u64))
		return false;
or
	if (size != sizeof(void *)
		return false;

And what's required instead is a combo like:

	if (size != sizeof(__u64) && size != sizeof(long))
		return false;

Implement above as convenience function and use in:

 - btf_ctx_access()
 - cg_sockopt_is_valid_access()
 - bpf_skb_is_valid_access()
 - sock_addr_is_valid_access()
 - sock_ops_is_valid_access()
 - sk_msg_is_valid_access()
 - flow_dissector_is_valid_access()

This eliminates all 'invalid bpf_context access" errors on 32-bit armhf
except one with nf_is_valid_access() which is fixed in the next patch.

Signed-off-by: Tony Ambardar <[email protected]>
guidosarducci added a commit to guidosarducci/linux that referenced this pull request Aug 13, 2025
Sequence of ctx checks and rewrites in real world:

1. Possible CO-RE rewrites of access size & offset, maybe breaking #2
2. Verifier env->ops->is_valid_access(), testing access size == sizeof(u64)
3. Verifier env->ops->convert_ctx_access(), rewrite size & offset

Position of access check above is strange, really only works on 64-bit and
likely unnoticed for lack of systematic 32-bit testing.

Test changing *is_valid_access() to always check size != sizeof(u64), but
on 32-bit systems also check size != sizeof(u32)

On 32-bit armhf, test_progs hits ~100 instances of failures such as:

(NOTE: this results from CO-RE relocation patching to u32 load size)

  libbpf: prog 'change_tcp_cc': -- BEGIN PROG LOAD LOG --
  0: R1=ctx() R10=fp0
  ; int change_tcp_cc(struct bpf_iter__tcp *ctx) @ bpf_iter_setsockopt.c:40
  0: (b4) w2 = 0                        ; R2_w=0
  ; if (!bpf_tcp_sk(ctx->sk_common)) @ bpf_iter_setsockopt.c:46
  1: (61) r1 = *(u32 *)(r1 +8)
  func 'bpf_iter_tcp' size 4 must be 8
  invalid bpf_context access off=8 size=4 is_valid_access=tracing_prog_is_valid_access
  processed 2 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
  -- END PROG LOAD LOG --
  libbpf: prog 'change_tcp_cc': failed to load: -EACCES
  libbpf: failed to load object 'bpf_iter_setsockopt'
  libbpf: failed to load BPF skeleton 'bpf_iter_setsockopt': -EACCES
  serial_test_bpf_iter_setsockopt:FAIL:iter_skel unexpected error: -13
  torvalds#21      bpf_iter_setsockopt:FAIL

(NOTE: no error for tests without CO-RE patching which have u64 load size)

This means *_is_valid_access() can't check ctx pointers simply using:

	if (size != sizeof(__u64))
		return false;
or
	if (size != sizeof(void *)
		return false;

And what's required instead is a combo like:

	if (size != sizeof(__u64) && size != sizeof(long))
		return false;

Implement above as convenience function and use in:

 - btf_ctx_access()
 - cg_sockopt_is_valid_access()
 - bpf_skb_is_valid_access()
 - sock_addr_is_valid_access()
 - sock_ops_is_valid_access()
 - sk_msg_is_valid_access()
 - flow_dissector_is_valid_access()

This eliminates all 'invalid bpf_context access" errors on 32-bit armhf
except one with nf_is_valid_access() which is fixed in the next patch.

Signed-off-by: Tony Ambardar <[email protected]>
guidosarducci added a commit to guidosarducci/linux that referenced this pull request Aug 14, 2025
Sequence of ctx checks and rewrites in real world:

1. Possible CO-RE rewrites of access size & offset, maybe breaking #2
2. Verifier env->ops->is_valid_access(), testing access size == sizeof(u64)
3. Verifier env->ops->convert_ctx_access(), rewrite size & offset

Position of access check above is strange, really only works on 64-bit and
likely unnoticed for lack of systematic 32-bit testing.

Test changing *is_valid_access() to always check size != sizeof(u64), but
on 32-bit systems also check size != sizeof(u32)

On 32-bit armhf, test_progs hits ~100 instances of failures such as:

(NOTE: this results from CO-RE relocation patching to u32 load size)

  libbpf: prog 'change_tcp_cc': -- BEGIN PROG LOAD LOG --
  0: R1=ctx() R10=fp0
  ; int change_tcp_cc(struct bpf_iter__tcp *ctx) @ bpf_iter_setsockopt.c:40
  0: (b4) w2 = 0                        ; R2_w=0
  ; if (!bpf_tcp_sk(ctx->sk_common)) @ bpf_iter_setsockopt.c:46
  1: (61) r1 = *(u32 *)(r1 +8)
  func 'bpf_iter_tcp' size 4 must be 8
  invalid bpf_context access off=8 size=4 is_valid_access=tracing_prog_is_valid_access
  processed 2 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
  -- END PROG LOAD LOG --
  libbpf: prog 'change_tcp_cc': failed to load: -EACCES
  libbpf: failed to load object 'bpf_iter_setsockopt'
  libbpf: failed to load BPF skeleton 'bpf_iter_setsockopt': -EACCES
  serial_test_bpf_iter_setsockopt:FAIL:iter_skel unexpected error: -13
  torvalds#21      bpf_iter_setsockopt:FAIL

(NOTE: no error for tests without CO-RE patching which have u64 load size)

This means *_is_valid_access() can't check ctx pointers simply using:

	if (size != sizeof(__u64))
		return false;
or
	if (size != sizeof(void *)
		return false;

And what's required instead is a combo like:

	if (size != sizeof(__u64) && size != sizeof(long))
		return false;

Implement above as convenience function and use in:

 - btf_ctx_access()
 - cg_sockopt_is_valid_access()
 - bpf_skb_is_valid_access()
 - sock_addr_is_valid_access()
 - sock_ops_is_valid_access()
 - sk_msg_is_valid_access()
 - flow_dissector_is_valid_access()

This eliminates all 'invalid bpf_context access" errors on 32-bit armhf
except one with nf_is_valid_access() which is fixed in the next patch.

Signed-off-by: Tony Ambardar <[email protected]>
guidosarducci added a commit to guidosarducci/linux that referenced this pull request Aug 17, 2025
Sequence of ctx checks and rewrites in real world:

1. Possible CO-RE rewrites of access size & offset, maybe breaking #2
2. Verifier env->ops->is_valid_access(), testing access size == sizeof(u64)
3. Verifier env->ops->convert_ctx_access(), rewrite size & offset

Position of access check above is strange, really only works on 64-bit and
likely unnoticed for lack of systematic 32-bit testing.

Test changing *is_valid_access() to always check size != sizeof(u64), but
on 32-bit systems also check size != sizeof(u32)

On 32-bit armhf, test_progs hits ~100 instances of failures such as:

(NOTE: this results from CO-RE relocation patching to u32 load size)

  libbpf: prog 'change_tcp_cc': -- BEGIN PROG LOAD LOG --
  0: R1=ctx() R10=fp0
  ; int change_tcp_cc(struct bpf_iter__tcp *ctx) @ bpf_iter_setsockopt.c:40
  0: (b4) w2 = 0                        ; R2_w=0
  ; if (!bpf_tcp_sk(ctx->sk_common)) @ bpf_iter_setsockopt.c:46
  1: (61) r1 = *(u32 *)(r1 +8)
  func 'bpf_iter_tcp' size 4 must be 8
  invalid bpf_context access off=8 size=4 is_valid_access=tracing_prog_is_valid_access
  processed 2 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
  -- END PROG LOAD LOG --
  libbpf: prog 'change_tcp_cc': failed to load: -EACCES
  libbpf: failed to load object 'bpf_iter_setsockopt'
  libbpf: failed to load BPF skeleton 'bpf_iter_setsockopt': -EACCES
  serial_test_bpf_iter_setsockopt:FAIL:iter_skel unexpected error: -13
  torvalds#21      bpf_iter_setsockopt:FAIL

(NOTE: no error for tests without CO-RE patching which have u64 load size)

This means *_is_valid_access() can't check ctx pointers simply using:

	if (size != sizeof(__u64))
		return false;
or
	if (size != sizeof(void *)
		return false;

And what's required instead is a combo like:

	if (size != sizeof(__u64) && size != sizeof(long))
		return false;

Implement above as convenience function and use in:

 - btf_ctx_access()
 - cg_sockopt_is_valid_access()
 - bpf_skb_is_valid_access()
 - sock_addr_is_valid_access()
 - sock_ops_is_valid_access()
 - sk_msg_is_valid_access()
 - flow_dissector_is_valid_access()

This eliminates all 'invalid bpf_context access" errors on 32-bit armhf
except one with nf_is_valid_access() which is fixed in the next patch.

Signed-off-by: Tony Ambardar <[email protected]>
guidosarducci added a commit to guidosarducci/linux that referenced this pull request Aug 19, 2025
Sequence of ctx checks and rewrites in real world:

1. Possible CO-RE rewrites of access size & offset, maybe breaking #2
2. Verifier env->ops->is_valid_access(), testing access size == sizeof(u64)
3. Verifier env->ops->convert_ctx_access(), rewrite size & offset

Position of access check above is strange, really only works on 64-bit and
likely unnoticed for lack of systematic 32-bit testing.

Test changing *is_valid_access() to always check size != sizeof(u64), but
on 32-bit systems also check size != sizeof(u32)

On 32-bit armhf, test_progs hits ~100 instances of failures such as:

(NOTE: this results from CO-RE relocation patching to u32 load size)

  libbpf: prog 'change_tcp_cc': -- BEGIN PROG LOAD LOG --
  0: R1=ctx() R10=fp0
  ; int change_tcp_cc(struct bpf_iter__tcp *ctx) @ bpf_iter_setsockopt.c:40
  0: (b4) w2 = 0                        ; R2_w=0
  ; if (!bpf_tcp_sk(ctx->sk_common)) @ bpf_iter_setsockopt.c:46
  1: (61) r1 = *(u32 *)(r1 +8)
  func 'bpf_iter_tcp' size 4 must be 8
  invalid bpf_context access off=8 size=4 is_valid_access=tracing_prog_is_valid_access
  processed 2 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
  -- END PROG LOAD LOG --
  libbpf: prog 'change_tcp_cc': failed to load: -EACCES
  libbpf: failed to load object 'bpf_iter_setsockopt'
  libbpf: failed to load BPF skeleton 'bpf_iter_setsockopt': -EACCES
  serial_test_bpf_iter_setsockopt:FAIL:iter_skel unexpected error: -13
  torvalds#21      bpf_iter_setsockopt:FAIL

(NOTE: no error for tests without CO-RE patching which have u64 load size)

This means *_is_valid_access() can't check ctx pointers simply using:

	if (size != sizeof(__u64))
		return false;
or
	if (size != sizeof(void *)
		return false;

And what's required instead is a combo like:

	if (size != sizeof(__u64) && size != sizeof(long))
		return false;

Implement above as convenience function and use in:

 - btf_ctx_access()
 - cg_sockopt_is_valid_access()
 - bpf_skb_is_valid_access()
 - sock_addr_is_valid_access()
 - sock_ops_is_valid_access()
 - sk_msg_is_valid_access()
 - flow_dissector_is_valid_access()

This eliminates all 'invalid bpf_context access" errors on 32-bit armhf
except one with nf_is_valid_access() which is fixed in the next patch.

Signed-off-by: Tony Ambardar <[email protected]>
guidosarducci added a commit to guidosarducci/linux that referenced this pull request Aug 21, 2025
Sequence of ctx checks and rewrites in real world:

1. Possible CO-RE rewrites of access size & offset, maybe breaking #2
2. Verifier env->ops->is_valid_access(), testing access size == sizeof(u64)
3. Verifier env->ops->convert_ctx_access(), rewrite size & offset

Position of access check above is strange, really only works on 64-bit and
likely unnoticed for lack of systematic 32-bit testing.

Test changing *is_valid_access() to always check size != sizeof(u64), but
on 32-bit systems also check size != sizeof(u32)

On 32-bit armhf, test_progs hits ~100 instances of failures such as:

(NOTE: this results from CO-RE relocation patching to u32 load size)

  libbpf: prog 'change_tcp_cc': -- BEGIN PROG LOAD LOG --
  0: R1=ctx() R10=fp0
  ; int change_tcp_cc(struct bpf_iter__tcp *ctx) @ bpf_iter_setsockopt.c:40
  0: (b4) w2 = 0                        ; R2_w=0
  ; if (!bpf_tcp_sk(ctx->sk_common)) @ bpf_iter_setsockopt.c:46
  1: (61) r1 = *(u32 *)(r1 +8)
  func 'bpf_iter_tcp' size 4 must be 8
  invalid bpf_context access off=8 size=4 is_valid_access=tracing_prog_is_valid_access
  processed 2 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
  -- END PROG LOAD LOG --
  libbpf: prog 'change_tcp_cc': failed to load: -EACCES
  libbpf: failed to load object 'bpf_iter_setsockopt'
  libbpf: failed to load BPF skeleton 'bpf_iter_setsockopt': -EACCES
  serial_test_bpf_iter_setsockopt:FAIL:iter_skel unexpected error: -13
  torvalds#21      bpf_iter_setsockopt:FAIL

(NOTE: no error for tests without CO-RE patching which have u64 load size)

This means *_is_valid_access() can't check ctx pointers simply using:

	if (size != sizeof(__u64))
		return false;
or
	if (size != sizeof(void *)
		return false;

And what's required instead is a combo like:

	if (size != sizeof(__u64) && size != sizeof(long))
		return false;

Implement above as convenience function and use in:

 - btf_ctx_access()
 - cg_sockopt_is_valid_access()
 - bpf_skb_is_valid_access()
 - sock_addr_is_valid_access()
 - sock_ops_is_valid_access()
 - sk_msg_is_valid_access()
 - flow_dissector_is_valid_access()

This eliminates all 'invalid bpf_context access" errors on 32-bit armhf
except one with nf_is_valid_access() which is fixed in the next patch.

Signed-off-by: Tony Ambardar <[email protected]>
guidosarducci added a commit to guidosarducci/linux that referenced this pull request Aug 23, 2025
Sequence of ctx checks and rewrites in real world:

1. Possible CO-RE rewrites of access size & offset, maybe breaking #2
2. Verifier env->ops->is_valid_access(), testing access size == sizeof(u64)
3. Verifier env->ops->convert_ctx_access(), rewrite size & offset

Position of access check above is strange, really only works on 64-bit and
likely unnoticed for lack of systematic 32-bit testing.

Test changing *is_valid_access() to always check size != sizeof(u64), but
on 32-bit systems also check size != sizeof(u32)

On 32-bit armhf, test_progs hits ~100 instances of failures such as:

(NOTE: this results from CO-RE relocation patching to u32 load size)

  libbpf: prog 'change_tcp_cc': -- BEGIN PROG LOAD LOG --
  0: R1=ctx() R10=fp0
  ; int change_tcp_cc(struct bpf_iter__tcp *ctx) @ bpf_iter_setsockopt.c:40
  0: (b4) w2 = 0                        ; R2_w=0
  ; if (!bpf_tcp_sk(ctx->sk_common)) @ bpf_iter_setsockopt.c:46
  1: (61) r1 = *(u32 *)(r1 +8)
  func 'bpf_iter_tcp' size 4 must be 8
  invalid bpf_context access off=8 size=4 is_valid_access=tracing_prog_is_valid_access
  processed 2 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
  -- END PROG LOAD LOG --
  libbpf: prog 'change_tcp_cc': failed to load: -EACCES
  libbpf: failed to load object 'bpf_iter_setsockopt'
  libbpf: failed to load BPF skeleton 'bpf_iter_setsockopt': -EACCES
  serial_test_bpf_iter_setsockopt:FAIL:iter_skel unexpected error: -13
  torvalds#21      bpf_iter_setsockopt:FAIL

(NOTE: no error for tests without CO-RE patching which have u64 load size)

This means *_is_valid_access() can't check ctx pointers simply using:

	if (size != sizeof(__u64))
		return false;
or
	if (size != sizeof(void *)
		return false;

And what's required instead is a combo like:

	if (size != sizeof(__u64) && size != sizeof(long))
		return false;

Implement above as convenience function and use in:

 - btf_ctx_access()
 - cg_sockopt_is_valid_access()
 - bpf_skb_is_valid_access()
 - sock_addr_is_valid_access()
 - sock_ops_is_valid_access()
 - sk_msg_is_valid_access()
 - flow_dissector_is_valid_access()

This eliminates all 'invalid bpf_context access" errors on 32-bit armhf
except one with nf_is_valid_access() which is fixed in the next patch.

Signed-off-by: Tony Ambardar <[email protected]>
guidosarducci added a commit to guidosarducci/linux that referenced this pull request Aug 28, 2025
Sequence of ctx checks and rewrites in real world:

1. Possible CO-RE rewrites of access size & offset, maybe breaking #2
2. Verifier env->ops->is_valid_access(), testing access size == sizeof(u64)
3. Verifier env->ops->convert_ctx_access(), rewrite size & offset

Position of access check above is strange, really only works on 64-bit and
likely unnoticed for lack of systematic 32-bit testing.

Test changing *is_valid_access() to always check size != sizeof(u64), but
on 32-bit systems also check size != sizeof(u32)

On 32-bit armhf, test_progs hits ~100 instances of failures such as:

(NOTE: this results from CO-RE relocation patching to u32 load size)

  libbpf: prog 'change_tcp_cc': -- BEGIN PROG LOAD LOG --
  0: R1=ctx() R10=fp0
  ; int change_tcp_cc(struct bpf_iter__tcp *ctx) @ bpf_iter_setsockopt.c:40
  0: (b4) w2 = 0                        ; R2_w=0
  ; if (!bpf_tcp_sk(ctx->sk_common)) @ bpf_iter_setsockopt.c:46
  1: (61) r1 = *(u32 *)(r1 +8)
  func 'bpf_iter_tcp' size 4 must be 8
  invalid bpf_context access off=8 size=4 is_valid_access=tracing_prog_is_valid_access
  processed 2 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
  -- END PROG LOAD LOG --
  libbpf: prog 'change_tcp_cc': failed to load: -EACCES
  libbpf: failed to load object 'bpf_iter_setsockopt'
  libbpf: failed to load BPF skeleton 'bpf_iter_setsockopt': -EACCES
  serial_test_bpf_iter_setsockopt:FAIL:iter_skel unexpected error: -13
  torvalds#21      bpf_iter_setsockopt:FAIL

(NOTE: no error for tests without CO-RE patching which have u64 load size)

This means *_is_valid_access() can't check ctx pointers simply using:

	if (size != sizeof(__u64))
		return false;
or
	if (size != sizeof(void *)
		return false;

And what's required instead is a combo like:

	if (size != sizeof(__u64) && size != sizeof(long))
		return false;

Implement above as convenience function and use in:

 - btf_ctx_access()
 - cg_sockopt_is_valid_access()
 - bpf_skb_is_valid_access()
 - sock_addr_is_valid_access()
 - sock_ops_is_valid_access()
 - sk_msg_is_valid_access()
 - flow_dissector_is_valid_access()

This eliminates all 'invalid bpf_context access" errors on 32-bit armhf
except one with nf_is_valid_access() which is fixed in the next patch.

Signed-off-by: Tony Ambardar <[email protected]>
guidosarducci added a commit to guidosarducci/linux that referenced this pull request Aug 29, 2025
Sequence of ctx checks and rewrites in real world:

1. Possible CO-RE rewrites of access size & offset, maybe breaking #2
2. Verifier env->ops->is_valid_access(), testing access size == sizeof(u64)
3. Verifier env->ops->convert_ctx_access(), rewrite size & offset

Position of access check above is strange, really only works on 64-bit and
likely unnoticed for lack of systematic 32-bit testing.

Test changing *is_valid_access() to always check size != sizeof(u64), but
on 32-bit systems also check size != sizeof(u32)

On 32-bit armhf, test_progs hits ~100 instances of failures such as:

(NOTE: this results from CO-RE relocation patching to u32 load size)

  libbpf: prog 'change_tcp_cc': -- BEGIN PROG LOAD LOG --
  0: R1=ctx() R10=fp0
  ; int change_tcp_cc(struct bpf_iter__tcp *ctx) @ bpf_iter_setsockopt.c:40
  0: (b4) w2 = 0                        ; R2_w=0
  ; if (!bpf_tcp_sk(ctx->sk_common)) @ bpf_iter_setsockopt.c:46
  1: (61) r1 = *(u32 *)(r1 +8)
  func 'bpf_iter_tcp' size 4 must be 8
  invalid bpf_context access off=8 size=4 is_valid_access=tracing_prog_is_valid_access
  processed 2 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
  -- END PROG LOAD LOG --
  libbpf: prog 'change_tcp_cc': failed to load: -EACCES
  libbpf: failed to load object 'bpf_iter_setsockopt'
  libbpf: failed to load BPF skeleton 'bpf_iter_setsockopt': -EACCES
  serial_test_bpf_iter_setsockopt:FAIL:iter_skel unexpected error: -13
  torvalds#21      bpf_iter_setsockopt:FAIL

(NOTE: no error for tests without CO-RE patching which have u64 load size)

This means *_is_valid_access() can't check ctx pointers simply using:

	if (size != sizeof(__u64))
		return false;
or
	if (size != sizeof(void *)
		return false;

And what's required instead is a combo like:

	if (size != sizeof(__u64) && size != sizeof(long))
		return false;

Implement above as convenience function and use in:

 - btf_ctx_access()
 - cg_sockopt_is_valid_access()
 - bpf_skb_is_valid_access()
 - sock_addr_is_valid_access()
 - sock_ops_is_valid_access()
 - sk_msg_is_valid_access()
 - flow_dissector_is_valid_access()

This eliminates all 'invalid bpf_context access" errors on 32-bit armhf
except one with nf_is_valid_access() which is fixed in the next patch.

Signed-off-by: Tony Ambardar <[email protected]>
hbiyik pushed a commit to hbiyik/linux that referenced this pull request Aug 30, 2025
The vcstate for the splice vp may be NULL if this
vp not registered as a crtc, this may trigger a null
pointer access in the 8K mode:

[   84.267856] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000040
[   84.344984] Mem abort info:
[   84.347778]   ESR = 0x0000000096000005
[   84.392721] Internal error: Oops: 0000000096000005 [#1] SMP
[   84.398289] Modules linked in:
[   84.401347] CPU: 6 PID: 779 Comm: weston Not tainted 6.1.99 torvalds#21
[   84.407263] Hardware name: IP11HH-8K-104 V0.4 (DT)
[   84.412048] pstate: 60400009 (nZCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
[   84.419005] pc : vop2_setup_dly_for_vp+0x1c/0x270
[   84.423705] lr : vop2_crtc_atomic_begin+0xe90/0x2bb0
[   84.428667] sp : ffffffc00c8db850
[   84.431974] x29: ffffffc00c8db850 x28: 0000000000000001 x27:0000000000000000
[   84.439101] x26: ffffff8005960080 x25: ffffff8006ae9600 x24:ffffff8005961458
[   84.446226] x23: ffffffc009842850 x22: ffffff80059600f8 x21:ffffffc009823410
[   84.453355] x20: ffffff8006ae9500 x19: ffffff8002054800 x18:0000000000000030
[   84.460485] x17: 393431313a632e32 x16: 706f765f6d72645f x15:ffffffffffffffff
[   84.467614] x14: 0000000000000000 x13: 30393431313a632e x12:32706f765f6d7264
[   84.474738] x11: 5f706968636b636f x10: ffffffc00a2438d8 x9 :ffffffc008813420
[   84.481865] x8 : 0000000000000000 x7 : ffffffc00a2438d8 x6 :ffffff8005960080
[   84.488989] x5 : 0000000000017ff4 x4 : ffffffc009418f68 x3 :0000000000000000
[   84.496118] x2 : 0000000000000001 x1 : ffffff80072cd280 x0 :ffffff8005961458
[   84.503246] Call trace:
[   84.505693]  vop2_setup_dly_for_vp+0x1c/0x270
[   84.510051]  drm_atomic_helper_commit_planes+0x80/0x210
[   84.515274]  rockchip_drm_atomic_helper_commit_tail_rpm+0x19c/0x2fc
[   84.521540]  commit_tail+0xa4/0x180
[   84.525022]  drm_atomic_helper_commit+0x16c/0x190
[   84.529725]  drm_atomic_commit+0xac/0xe0
[   84.533652]  drm_atomic_helper_set_config+0xd8/0x110
[   84.538609]  drm_mode_setcrtc+0x1b4/0x690
[   84.542617]  drm_ioctl_kernel+0xb4/0x100
[   84.546542]  drm_ioctl+0x208/0x440
[   84.549947]  __arm64_sys_ioctl+0xb4/0xdc
[   84.553869]  invoke_syscall+0x4c/0x114
[   84.557617]  el0_svc_common.constprop.0+0x54/0x180
[   84.562407]  do_el0_svc+0x20/0x2c
[   84.565724]  el0_svc+0x14/0x80
[   84.568784]  el0t_64_sync_handler+0xb0/0xb4
[   84.572961]  el0t_64_sync+0x158/0x15c

Change-Id: Ic654f121cc180fb3f57834774eca856c3b87ecc1
Signed-off-by: Andy Yan <[email protected]>
guidosarducci added a commit to guidosarducci/linux that referenced this pull request Sep 2, 2025
Sequence of ctx checks and rewrites in real world:

1. Possible CO-RE rewrites of access size & offset, maybe breaking #2
2. Verifier env->ops->is_valid_access(), testing access size == sizeof(u64)
3. Verifier env->ops->convert_ctx_access(), rewrite size & offset

Position of access check above is strange, really only works on 64-bit and
likely unnoticed for lack of systematic 32-bit testing.

Test changing *is_valid_access() to always check size != sizeof(u64), but
on 32-bit systems also check size != sizeof(u32)

On 32-bit armhf, test_progs hits ~100 instances of failures such as:

(NOTE: this results from CO-RE relocation patching to u32 load size)

  libbpf: prog 'change_tcp_cc': -- BEGIN PROG LOAD LOG --
  0: R1=ctx() R10=fp0
  ; int change_tcp_cc(struct bpf_iter__tcp *ctx) @ bpf_iter_setsockopt.c:40
  0: (b4) w2 = 0                        ; R2_w=0
  ; if (!bpf_tcp_sk(ctx->sk_common)) @ bpf_iter_setsockopt.c:46
  1: (61) r1 = *(u32 *)(r1 +8)
  func 'bpf_iter_tcp' size 4 must be 8
  invalid bpf_context access off=8 size=4 is_valid_access=tracing_prog_is_valid_access
  processed 2 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
  -- END PROG LOAD LOG --
  libbpf: prog 'change_tcp_cc': failed to load: -EACCES
  libbpf: failed to load object 'bpf_iter_setsockopt'
  libbpf: failed to load BPF skeleton 'bpf_iter_setsockopt': -EACCES
  serial_test_bpf_iter_setsockopt:FAIL:iter_skel unexpected error: -13
  torvalds#21      bpf_iter_setsockopt:FAIL

(NOTE: no error for tests without CO-RE patching which have u64 load size)

This means *_is_valid_access() can't check ctx pointers simply using:

	if (size != sizeof(__u64))
		return false;
or
	if (size != sizeof(void *)
		return false;

And what's required instead is a combo like:

	if (size != sizeof(__u64) && size != sizeof(long))
		return false;

Implement above as convenience function and use in:

 - btf_ctx_access()
 - cg_sockopt_is_valid_access()
 - bpf_skb_is_valid_access()
 - sock_addr_is_valid_access()
 - sock_ops_is_valid_access()
 - sk_msg_is_valid_access()
 - flow_dissector_is_valid_access()

This eliminates all 'invalid bpf_context access" errors on 32-bit armhf
except one with nf_is_valid_access() which is fixed in the next patch.

Signed-off-by: Tony Ambardar <[email protected]>
vincent-mailhol added a commit to vincent-mailhol/linux that referenced this pull request Sep 3, 2025
In November last year, I sent an RFC to introduce CAN XL [1]. That
RFC, despite positive feedback, was put on hold due to some unanswered
question concerning the PWM encoding [2].

While stuck, some small preparation work was done in parallel in [3]
by refactoring the struct can_priv and doing some trivial clean-up and
renaming. [3] received zero feedback but was eventually merged after
splitting it in smaller parts and resending it.

Finally, in July this year, we clarified the remaining mysteries about
PWM calculation, thus unlocking the series. Summer being a bit busy
because of some personal matters brings us to now.

After doing all the refactoring and adding all the CAN XL features,
the final result is roughly 30 patches, probably too much for a single
series. So I am splitting it in two:

  - preparation (this series)
  - CAN XL

And so, this series continues and finishes the preparation work done
in [3]. It contains all the refactoring needed to smoothly introduce
CAN XL. The goal is to:

  - split the function in smaller pieces: CAN XL will introduce a fair
    amount of code. And some functions which are already fairly long
    (86 lines for can_validate(), 216 lines for can_changelink())
    would grow to disproportionate sizes if the CAN XL logic were to
    be inlined in those functions.

  - repurpose the existing code to handle both CAN FD and CAN XL: a
    huge part of CAN XL simply reuses the CAN FD logic. All the
    existing CAN FD logic is made more generic to handle both CAN FD
    and XL.

In more details:

  - Patch #1 moves struct data_bittiming_params from dev.h to
    bittiming.h and patch #2 makes can_get_relative_tdco() FD agnostic
    before also moving it to bittiming.h.

  - Patch #3 adds some comments to netlink.h tagging which IFLA
    symbols are FD specific.

  - Patch #4 to torvalds#7 are refactoring can_validate() and
    can_validate_bittiming().

  - Patch torvalds#8 to torvalds#12 are refactoring can_changelink() and
    can_tdc_changelink().

  - Patch torvalds#13 and torvalds#14 are refactoring can_get_size() and
    can_tdc_get_size().

  - Patch torvalds#15 to torvalds#18 are refactoring can_fill_info() and
    can_tdc_fill_info().

  - Patch torvalds#19 makes can_calc_tdco() FD agnostic.

  - Patch torvalds#20 adds can_get_ctrlmode_str() which converts control mode
    flags into strings. This is done in preparation of patch torvalds#20.

  - Patch torvalds#21 is the final patch and improves the user experience by
    providing detailed error messages whenever invalid parameters are
    provided. All those error messages came into handy when debugging
    the upcoming CAN XL patches.

Aside from the last patch, the other changes do not impact any of the
existing functionalities.

The follow up series which introduces CAN XL is nearly completed but
will be sent only once this one is approved: one thing at a time, I do
not want to overwhelm people (including myself).

[1] https://lore.kernel.org/linux-can/[email protected]/
[2] https://lore.kernel.org/linux-can/[email protected]/
[3] https://lore.kernel.org/linux-can/[email protected]/

To: Marc Kleine-Budde <[email protected]>
To: Oliver Hartkopp <[email protected]>
Cc: Vincent Mailhol <[email protected]>
Cc: Stéphane Grosjean <[email protected]>
Cc: Robert Nawrath <[email protected]>
Cc: Minh Le <[email protected]>
Cc: Duy Nguyen <[email protected]>
Cc: [email protected]
Cc: [email protected]

Signed-off-by: Vincent Mailhol <[email protected]>

---
Changes in v2:
- EDITME: describe what is new in this series revision.
- EDITME: use bulletpoints and terse descriptions.
- Link to v1: https://lore.kernel.org/r/[email protected]



--- b4-submit-tracking ---
# This section is used internally by b4 prep for tracking purposes.
{
  "series": {
    "revision": 2,
    "change-id": "20250831-canxl-netlink-prep-9dbf8498fd9d",
    "prefixes": [],
    "prerequisites": [
      "base-commit: net-next/main"
    ],
    "history": {
      "v1": [
        "[email protected]"
      ]
    }
  }
}
guidosarducci added a commit to guidosarducci/linux that referenced this pull request Sep 5, 2025
Sequence of ctx checks and rewrites in real world:

1. Possible CO-RE rewrites of access size & offset, maybe breaking #2
2. Verifier env->ops->is_valid_access(), testing access size == sizeof(u64)
3. Verifier env->ops->convert_ctx_access(), rewrite size & offset

Position of access check above is strange, really only works on 64-bit and
likely unnoticed for lack of systematic 32-bit testing.

Test changing *is_valid_access() to always check size != sizeof(u64), but
on 32-bit systems also check size != sizeof(u32)

On 32-bit armhf, test_progs hits ~100 instances of failures such as:

(NOTE: this results from CO-RE relocation patching to u32 load size)

  libbpf: prog 'change_tcp_cc': -- BEGIN PROG LOAD LOG --
  0: R1=ctx() R10=fp0
  ; int change_tcp_cc(struct bpf_iter__tcp *ctx) @ bpf_iter_setsockopt.c:40
  0: (b4) w2 = 0                        ; R2_w=0
  ; if (!bpf_tcp_sk(ctx->sk_common)) @ bpf_iter_setsockopt.c:46
  1: (61) r1 = *(u32 *)(r1 +8)
  func 'bpf_iter_tcp' size 4 must be 8
  invalid bpf_context access off=8 size=4 is_valid_access=tracing_prog_is_valid_access
  processed 2 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
  -- END PROG LOAD LOG --
  libbpf: prog 'change_tcp_cc': failed to load: -EACCES
  libbpf: failed to load object 'bpf_iter_setsockopt'
  libbpf: failed to load BPF skeleton 'bpf_iter_setsockopt': -EACCES
  serial_test_bpf_iter_setsockopt:FAIL:iter_skel unexpected error: -13
  torvalds#21      bpf_iter_setsockopt:FAIL

(NOTE: no error for tests without CO-RE patching which have u64 load size)

This means *_is_valid_access() can't check ctx pointers simply using:

	if (size != sizeof(__u64))
		return false;
or
	if (size != sizeof(void *)
		return false;

And what's required instead is a combo like:

	if (size != sizeof(__u64) && size != sizeof(long))
		return false;

Implement above as convenience function and use in:

 - btf_ctx_access()
 - cg_sockopt_is_valid_access()
 - bpf_skb_is_valid_access()
 - sock_addr_is_valid_access()
 - sock_ops_is_valid_access()
 - sk_msg_is_valid_access()
 - flow_dissector_is_valid_access()

This eliminates all 'invalid bpf_context access" errors on 32-bit armhf
except one with nf_is_valid_access() which is fixed in the next patch.

Signed-off-by: Tony Ambardar <[email protected]>
guidosarducci added a commit to guidosarducci/linux that referenced this pull request Sep 8, 2025
Sequence of ctx checks and rewrites in real world:

1. Possible CO-RE rewrites of access size & offset, maybe breaking #2
2. Verifier env->ops->is_valid_access(), testing access size == sizeof(u64)
3. Verifier env->ops->convert_ctx_access(), rewrite size & offset

Position of access check above is strange, really only works on 64-bit and
likely unnoticed for lack of systematic 32-bit testing.

Test changing *is_valid_access() to always check size != sizeof(u64), but
on 32-bit systems also check size != sizeof(u32)

On 32-bit armhf, test_progs hits ~100 instances of failures such as:

(NOTE: this results from CO-RE relocation patching to u32 load size)

  libbpf: prog 'change_tcp_cc': -- BEGIN PROG LOAD LOG --
  0: R1=ctx() R10=fp0
  ; int change_tcp_cc(struct bpf_iter__tcp *ctx) @ bpf_iter_setsockopt.c:40
  0: (b4) w2 = 0                        ; R2_w=0
  ; if (!bpf_tcp_sk(ctx->sk_common)) @ bpf_iter_setsockopt.c:46
  1: (61) r1 = *(u32 *)(r1 +8)
  func 'bpf_iter_tcp' size 4 must be 8
  invalid bpf_context access off=8 size=4 is_valid_access=tracing_prog_is_valid_access
  processed 2 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
  -- END PROG LOAD LOG --
  libbpf: prog 'change_tcp_cc': failed to load: -EACCES
  libbpf: failed to load object 'bpf_iter_setsockopt'
  libbpf: failed to load BPF skeleton 'bpf_iter_setsockopt': -EACCES
  serial_test_bpf_iter_setsockopt:FAIL:iter_skel unexpected error: -13
  torvalds#21      bpf_iter_setsockopt:FAIL

(NOTE: no error for tests without CO-RE patching which have u64 load size)

This means *_is_valid_access() can't check ctx pointers simply using:

	if (size != sizeof(__u64))
		return false;
or
	if (size != sizeof(void *)
		return false;

And what's required instead is a combo like:

	if (size != sizeof(__u64) && size != sizeof(long))
		return false;

Implement above as convenience function and use in:

 - btf_ctx_access()
 - cg_sockopt_is_valid_access()
 - bpf_skb_is_valid_access()
 - sock_addr_is_valid_access()
 - sock_ops_is_valid_access()
 - sk_msg_is_valid_access()
 - flow_dissector_is_valid_access()

This eliminates all 'invalid bpf_context access" errors on 32-bit armhf
except one with nf_is_valid_access() which is fixed in the next patch.

Signed-off-by: Tony Ambardar <[email protected]>
guidosarducci added a commit to guidosarducci/linux that referenced this pull request Sep 10, 2025
Sequence of ctx checks and rewrites in real world:

1. Possible CO-RE rewrites of access size & offset, maybe breaking #2
2. Verifier env->ops->is_valid_access(), testing access size == sizeof(u64)
3. Verifier env->ops->convert_ctx_access(), rewrite size & offset

Position of access check above is strange, really only works on 64-bit and
likely unnoticed for lack of systematic 32-bit testing.

Test changing *is_valid_access() to always check size != sizeof(u64), but
on 32-bit systems also check size != sizeof(u32)

On 32-bit armhf, test_progs hits ~100 instances of failures such as:

(NOTE: this results from CO-RE relocation patching to u32 load size)

  libbpf: prog 'change_tcp_cc': -- BEGIN PROG LOAD LOG --
  0: R1=ctx() R10=fp0
  ; int change_tcp_cc(struct bpf_iter__tcp *ctx) @ bpf_iter_setsockopt.c:40
  0: (b4) w2 = 0                        ; R2_w=0
  ; if (!bpf_tcp_sk(ctx->sk_common)) @ bpf_iter_setsockopt.c:46
  1: (61) r1 = *(u32 *)(r1 +8)
  func 'bpf_iter_tcp' size 4 must be 8
  invalid bpf_context access off=8 size=4 is_valid_access=tracing_prog_is_valid_access
  processed 2 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
  -- END PROG LOAD LOG --
  libbpf: prog 'change_tcp_cc': failed to load: -EACCES
  libbpf: failed to load object 'bpf_iter_setsockopt'
  libbpf: failed to load BPF skeleton 'bpf_iter_setsockopt': -EACCES
  serial_test_bpf_iter_setsockopt:FAIL:iter_skel unexpected error: -13
  torvalds#21      bpf_iter_setsockopt:FAIL

(NOTE: no error for tests without CO-RE patching which have u64 load size)

This means *_is_valid_access() can't check ctx pointers simply using:

	if (size != sizeof(__u64))
		return false;
or
	if (size != sizeof(void *)
		return false;

And what's required instead is a combo like:

	if (size != sizeof(__u64) && size != sizeof(long))
		return false;

Implement above as convenience function and use in:

 - btf_ctx_access()
 - cg_sockopt_is_valid_access()
 - bpf_skb_is_valid_access()
 - sock_addr_is_valid_access()
 - sock_ops_is_valid_access()
 - sk_msg_is_valid_access()
 - flow_dissector_is_valid_access()

This eliminates all 'invalid bpf_context access" errors on 32-bit armhf
except one with nf_is_valid_access() which is fixed in the next patch.

Signed-off-by: Tony Ambardar <[email protected]>
intel-lab-lkp pushed a commit to intel-lab-lkp/linux that referenced this pull request Sep 10, 2025
The CMT do runtime PM and call clk_enable()/clk_disable() when a new
clock event is register and the CMT is not already started. This is not
always possible as a spinlock is also needed to sync the internals of
the CMT. Running with PROVE_LOCKING uncovers one such issue.

    =============================
    [ BUG: Invalid wait context ]
    6.17.0-rc3-arm64-renesas-03071-gb3c4f4122b28-dirty torvalds#21 Not tainted
    -----------------------------
    swapper/1/0 is trying to lock:
    ffff00000898d180 (&dev->power.lock){-...}-{3:3}, at: __pm_runtime_resume+0x38/0x88
    ccree e6601000.crypto: ARM CryptoCell 630P Driver: HW version 0xAF400001/0xDCC63000, Driver version 5.0
    other info that might help us debug this:
    ccree e6601000.crypto: ARM ccree device initialized
    context-{5:5}
    2 locks held by swapper/1/0:
     #0: ffff80008173c298 (tick_broadcast_lock){-...}-{2:2}, at: __tick_broadcast_oneshot_control+0xa4/0x3a8
     #1: ffff0000089a5858 (&ch->lock){....}-{2:2}
    usbcore: registered new interface driver usbhid
    , at: sh_cmt_start+0x30/0x364
    stack backtrace:
    CPU: 1 UID: 0 PID: 0 Comm: swapper/1 Not tainted 6.17.0-rc3-arm64-renesas-03071-gb3c4f4122b28-dirty torvalds#21 PREEMPT
    Hardware name: Renesas Salvator-X 2nd version board based on r8a77965 (DT)
    Call trace:
     show_stack+0x14/0x1c (C)
     dump_stack_lvl+0x6c/0x90
     dump_stack+0x14/0x1c
     __lock_acquire+0x904/0x1584
     lock_acquire+0x220/0x34c
     _raw_spin_lock_irqsave+0x58/0x80
     __pm_runtime_resume+0x38/0x88
     sh_cmt_start+0x54/0x364
     sh_cmt_clock_event_set_oneshot+0x64/0xb8
     clockevents_switch_state+0xfc/0x13c
     tick_broadcast_set_event+0x30/0xa4
     __tick_broadcast_oneshot_control+0x1e0/0x3a8
     tick_broadcast_oneshot_control+0x30/0x40
     cpuidle_enter_state+0x40c/0x680
     cpuidle_enter+0x30/0x40
     do_idle+0x1f4/0x26c
     cpu_startup_entry+0x34/0x40
     secondary_start_kernel+0x11c/0x13c
     __secondary_switched+0x74/0x78

Fix this by unconditionally powering on and enabling the needed clocks
for all CMT channels which are used for clock events. Do this before
registering any clock source or event to avid having to take the
spin lock at probe time.

Signed-off-by: Niklas Söderlund <[email protected]>
guidosarducci added a commit to guidosarducci/linux that referenced this pull request Sep 11, 2025
Sequence of ctx checks and rewrites in real world:

1. Possible CO-RE rewrites of access size & offset, maybe breaking #2
2. Verifier env->ops->is_valid_access(), testing access size == sizeof(u64)
3. Verifier env->ops->convert_ctx_access(), rewrite size & offset

Position of access check above is strange, really only works on 64-bit and
likely unnoticed for lack of systematic 32-bit testing.

Test changing *is_valid_access() to always check size != sizeof(u64), but
on 32-bit systems also check size != sizeof(u32)

On 32-bit armhf, test_progs hits ~100 instances of failures such as:

(NOTE: this results from CO-RE relocation patching to u32 load size)

  libbpf: prog 'change_tcp_cc': -- BEGIN PROG LOAD LOG --
  0: R1=ctx() R10=fp0
  ; int change_tcp_cc(struct bpf_iter__tcp *ctx) @ bpf_iter_setsockopt.c:40
  0: (b4) w2 = 0                        ; R2_w=0
  ; if (!bpf_tcp_sk(ctx->sk_common)) @ bpf_iter_setsockopt.c:46
  1: (61) r1 = *(u32 *)(r1 +8)
  func 'bpf_iter_tcp' size 4 must be 8
  invalid bpf_context access off=8 size=4 is_valid_access=tracing_prog_is_valid_access
  processed 2 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
  -- END PROG LOAD LOG --
  libbpf: prog 'change_tcp_cc': failed to load: -EACCES
  libbpf: failed to load object 'bpf_iter_setsockopt'
  libbpf: failed to load BPF skeleton 'bpf_iter_setsockopt': -EACCES
  serial_test_bpf_iter_setsockopt:FAIL:iter_skel unexpected error: -13
  torvalds#21      bpf_iter_setsockopt:FAIL

(NOTE: no error for tests without CO-RE patching which have u64 load size)

This means *_is_valid_access() can't check ctx pointers simply using:

	if (size != sizeof(__u64))
		return false;
or
	if (size != sizeof(void *)
		return false;

And what's required instead is a combo like:

	if (size != sizeof(__u64) && size != sizeof(long))
		return false;

Implement above as convenience function and use in:

 - btf_ctx_access()
 - cg_sockopt_is_valid_access()
 - bpf_skb_is_valid_access()
 - sock_addr_is_valid_access()
 - sock_ops_is_valid_access()
 - sk_msg_is_valid_access()
 - flow_dissector_is_valid_access()

This eliminates all 'invalid bpf_context access" errors on 32-bit armhf
except one with nf_is_valid_access() which is fixed in the next patch.

Signed-off-by: Tony Ambardar <[email protected]>
guidosarducci added a commit to guidosarducci/linux that referenced this pull request Sep 13, 2025
Sequence of ctx checks and rewrites in real world:

1. Possible CO-RE rewrites of access size & offset, maybe breaking #2
2. Verifier env->ops->is_valid_access(), testing access size == sizeof(u64)
3. Verifier env->ops->convert_ctx_access(), rewrite size & offset

Position of access check above is strange, really only works on 64-bit and
likely unnoticed for lack of systematic 32-bit testing.

Test changing *is_valid_access() to always check size != sizeof(u64), but
on 32-bit systems also check size != sizeof(u32)

On 32-bit armhf, test_progs hits ~100 instances of failures such as:

(NOTE: this results from CO-RE relocation patching to u32 load size)

  libbpf: prog 'change_tcp_cc': -- BEGIN PROG LOAD LOG --
  0: R1=ctx() R10=fp0
  ; int change_tcp_cc(struct bpf_iter__tcp *ctx) @ bpf_iter_setsockopt.c:40
  0: (b4) w2 = 0                        ; R2_w=0
  ; if (!bpf_tcp_sk(ctx->sk_common)) @ bpf_iter_setsockopt.c:46
  1: (61) r1 = *(u32 *)(r1 +8)
  func 'bpf_iter_tcp' size 4 must be 8
  invalid bpf_context access off=8 size=4 is_valid_access=tracing_prog_is_valid_access
  processed 2 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
  -- END PROG LOAD LOG --
  libbpf: prog 'change_tcp_cc': failed to load: -EACCES
  libbpf: failed to load object 'bpf_iter_setsockopt'
  libbpf: failed to load BPF skeleton 'bpf_iter_setsockopt': -EACCES
  serial_test_bpf_iter_setsockopt:FAIL:iter_skel unexpected error: -13
  torvalds#21      bpf_iter_setsockopt:FAIL

(NOTE: no error for tests without CO-RE patching which have u64 load size)

This means *_is_valid_access() can't check ctx pointers simply using:

	if (size != sizeof(__u64))
		return false;
or
	if (size != sizeof(void *)
		return false;

And what's required instead is a combo like:

	if (size != sizeof(__u64) && size != sizeof(long))
		return false;

Implement above as convenience function and use in:

 - btf_ctx_access()
 - cg_sockopt_is_valid_access()
 - bpf_skb_is_valid_access()
 - sock_addr_is_valid_access()
 - sock_ops_is_valid_access()
 - sk_msg_is_valid_access()
 - flow_dissector_is_valid_access()

This eliminates all 'invalid bpf_context access" errors on 32-bit armhf
except one with nf_is_valid_access() which is fixed in the next patch.

Signed-off-by: Tony Ambardar <[email protected]>
guidosarducci added a commit to guidosarducci/linux that referenced this pull request Sep 16, 2025
Sequence of ctx checks and rewrites in real world:

1. Possible CO-RE rewrites of access size & offset, maybe breaking #2
2. Verifier env->ops->is_valid_access(), testing access size == sizeof(u64)
3. Verifier env->ops->convert_ctx_access(), rewrite size & offset

Position of access check above is strange, really only works on 64-bit and
likely unnoticed for lack of systematic 32-bit testing.

Test changing *is_valid_access() to always check size != sizeof(u64), but
on 32-bit systems also check size != sizeof(u32)

On 32-bit armhf, test_progs hits ~100 instances of failures such as:

(NOTE: this results from CO-RE relocation patching to u32 load size)

  libbpf: prog 'change_tcp_cc': -- BEGIN PROG LOAD LOG --
  0: R1=ctx() R10=fp0
  ; int change_tcp_cc(struct bpf_iter__tcp *ctx) @ bpf_iter_setsockopt.c:40
  0: (b4) w2 = 0                        ; R2_w=0
  ; if (!bpf_tcp_sk(ctx->sk_common)) @ bpf_iter_setsockopt.c:46
  1: (61) r1 = *(u32 *)(r1 +8)
  func 'bpf_iter_tcp' size 4 must be 8
  invalid bpf_context access off=8 size=4 is_valid_access=tracing_prog_is_valid_access
  processed 2 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
  -- END PROG LOAD LOG --
  libbpf: prog 'change_tcp_cc': failed to load: -EACCES
  libbpf: failed to load object 'bpf_iter_setsockopt'
  libbpf: failed to load BPF skeleton 'bpf_iter_setsockopt': -EACCES
  serial_test_bpf_iter_setsockopt:FAIL:iter_skel unexpected error: -13
  torvalds#21      bpf_iter_setsockopt:FAIL

(NOTE: no error for tests without CO-RE patching which have u64 load size)

This means *_is_valid_access() can't check ctx pointers simply using:

	if (size != sizeof(__u64))
		return false;
or
	if (size != sizeof(void *)
		return false;

And what's required instead is a combo like:

	if (size != sizeof(__u64) && size != sizeof(long))
		return false;

Implement above as convenience function and use in:

 - btf_ctx_access()
 - cg_sockopt_is_valid_access()
 - bpf_skb_is_valid_access()
 - sock_addr_is_valid_access()
 - sock_ops_is_valid_access()
 - sk_msg_is_valid_access()
 - flow_dissector_is_valid_access()

This eliminates all 'invalid bpf_context access" errors on 32-bit armhf
except one with nf_is_valid_access() which is fixed in the next patch.

Signed-off-by: Tony Ambardar <[email protected]>
guidosarducci added a commit to guidosarducci/linux that referenced this pull request Sep 17, 2025
Sequence of ctx checks and rewrites in real world:

1. Possible CO-RE rewrites of access size & offset, maybe breaking #2
2. Verifier env->ops->is_valid_access(), testing access size == sizeof(u64)
3. Verifier env->ops->convert_ctx_access(), rewrite size & offset

Position of access check above is strange, really only works on 64-bit and
likely unnoticed for lack of systematic 32-bit testing.

Test changing *is_valid_access() to always check size != sizeof(u64), but
on 32-bit systems also check size != sizeof(u32)

On 32-bit armhf, test_progs hits ~100 instances of failures such as:

(NOTE: this results from CO-RE relocation patching to u32 load size)

  libbpf: prog 'change_tcp_cc': -- BEGIN PROG LOAD LOG --
  0: R1=ctx() R10=fp0
  ; int change_tcp_cc(struct bpf_iter__tcp *ctx) @ bpf_iter_setsockopt.c:40
  0: (b4) w2 = 0                        ; R2_w=0
  ; if (!bpf_tcp_sk(ctx->sk_common)) @ bpf_iter_setsockopt.c:46
  1: (61) r1 = *(u32 *)(r1 +8)
  func 'bpf_iter_tcp' size 4 must be 8
  invalid bpf_context access off=8 size=4 is_valid_access=tracing_prog_is_valid_access
  processed 2 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
  -- END PROG LOAD LOG --
  libbpf: prog 'change_tcp_cc': failed to load: -EACCES
  libbpf: failed to load object 'bpf_iter_setsockopt'
  libbpf: failed to load BPF skeleton 'bpf_iter_setsockopt': -EACCES
  serial_test_bpf_iter_setsockopt:FAIL:iter_skel unexpected error: -13
  torvalds#21      bpf_iter_setsockopt:FAIL

(NOTE: no error for tests without CO-RE patching which have u64 load size)

This means *_is_valid_access() can't check ctx pointers simply using:

	if (size != sizeof(__u64))
		return false;
or
	if (size != sizeof(void *)
		return false;

And what's required instead is a combo like:

	if (size != sizeof(__u64) && size != sizeof(long))
		return false;

Implement above as convenience function and use in:

 - btf_ctx_access()
 - cg_sockopt_is_valid_access()
 - bpf_skb_is_valid_access()
 - sock_addr_is_valid_access()
 - sock_ops_is_valid_access()
 - sk_msg_is_valid_access()
 - flow_dissector_is_valid_access()

This eliminates all 'invalid bpf_context access" errors on 32-bit armhf
except one with nf_is_valid_access() which is fixed in the next patch.

Signed-off-by: Tony Ambardar <[email protected]>
guidosarducci added a commit to guidosarducci/linux that referenced this pull request Sep 18, 2025
Sequence of ctx checks and rewrites in real world:

1. Possible CO-RE rewrites of access size & offset, maybe breaking #2
2. Verifier env->ops->is_valid_access(), testing access size == sizeof(u64)
3. Verifier env->ops->convert_ctx_access(), rewrite size & offset

Position of access check above is strange, really only works on 64-bit and
likely unnoticed for lack of systematic 32-bit testing.

Test changing *is_valid_access() to always check size != sizeof(u64), but
on 32-bit systems also check size != sizeof(u32)

On 32-bit armhf, test_progs hits ~100 instances of failures such as:

(NOTE: this results from CO-RE relocation patching to u32 load size)

  libbpf: prog 'change_tcp_cc': -- BEGIN PROG LOAD LOG --
  0: R1=ctx() R10=fp0
  ; int change_tcp_cc(struct bpf_iter__tcp *ctx) @ bpf_iter_setsockopt.c:40
  0: (b4) w2 = 0                        ; R2_w=0
  ; if (!bpf_tcp_sk(ctx->sk_common)) @ bpf_iter_setsockopt.c:46
  1: (61) r1 = *(u32 *)(r1 +8)
  func 'bpf_iter_tcp' size 4 must be 8
  invalid bpf_context access off=8 size=4 is_valid_access=tracing_prog_is_valid_access
  processed 2 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
  -- END PROG LOAD LOG --
  libbpf: prog 'change_tcp_cc': failed to load: -EACCES
  libbpf: failed to load object 'bpf_iter_setsockopt'
  libbpf: failed to load BPF skeleton 'bpf_iter_setsockopt': -EACCES
  serial_test_bpf_iter_setsockopt:FAIL:iter_skel unexpected error: -13
  torvalds#21      bpf_iter_setsockopt:FAIL

(NOTE: no error for tests without CO-RE patching which have u64 load size)

This means *_is_valid_access() can't check ctx pointers simply using:

	if (size != sizeof(__u64))
		return false;
or
	if (size != sizeof(void *)
		return false;

And what's required instead is a combo like:

	if (size != sizeof(__u64) && size != sizeof(long))
		return false;

Implement above as convenience function and use in:

 - btf_ctx_access()
 - cg_sockopt_is_valid_access()
 - bpf_skb_is_valid_access()
 - sock_addr_is_valid_access()
 - sock_ops_is_valid_access()
 - sk_msg_is_valid_access()
 - flow_dissector_is_valid_access()

This eliminates all 'invalid bpf_context access" errors on 32-bit armhf
except one with nf_is_valid_access() which is fixed in the next patch.

Signed-off-by: Tony Ambardar <[email protected]>
mj22226 pushed a commit to mj22226/linux that referenced this pull request Sep 18, 2025
The CMT do runtime PM and call clk_enable()/clk_disable() when a new
clock event is register and the CMT is not already started. This is not
always possible as a spinlock is also needed to sync the internals of
the CMT. Running with PROVE_LOCKING uncovers one such issue.

    =============================
    [ BUG: Invalid wait context ]
    6.17.0-rc3-arm64-renesas-03071-gb3c4f4122b28-dirty torvalds#21 Not tainted
    -----------------------------
    swapper/1/0 is trying to lock:
    ffff00000898d180 (&dev->power.lock){-...}-{3:3}, at: __pm_runtime_resume+0x38/0x88
    ccree e6601000.crypto: ARM CryptoCell 630P Driver: HW version 0xAF400001/0xDCC63000, Driver version 5.0
    other info that might help us debug this:
    ccree e6601000.crypto: ARM ccree device initialized
    context-{5:5}
    2 locks held by swapper/1/0:
     #0: ffff80008173c298 (tick_broadcast_lock){-...}-{2:2}, at: __tick_broadcast_oneshot_control+0xa4/0x3a8
     #1: ffff0000089a5858 (&ch->lock){....}-{2:2}
    usbcore: registered new interface driver usbhid
    , at: sh_cmt_start+0x30/0x364
    stack backtrace:
    CPU: 1 UID: 0 PID: 0 Comm: swapper/1 Not tainted 6.17.0-rc3-arm64-renesas-03071-gb3c4f4122b28-dirty torvalds#21 PREEMPT
    Hardware name: Renesas Salvator-X 2nd version board based on r8a77965 (DT)
    Call trace:
     show_stack+0x14/0x1c (C)
     dump_stack_lvl+0x6c/0x90
     dump_stack+0x14/0x1c
     __lock_acquire+0x904/0x1584
     lock_acquire+0x220/0x34c
     _raw_spin_lock_irqsave+0x58/0x80
     __pm_runtime_resume+0x38/0x88
     sh_cmt_start+0x54/0x364
     sh_cmt_clock_event_set_oneshot+0x64/0xb8
     clockevents_switch_state+0xfc/0x13c
     tick_broadcast_set_event+0x30/0xa4
     __tick_broadcast_oneshot_control+0x1e0/0x3a8
     tick_broadcast_oneshot_control+0x30/0x40
     cpuidle_enter_state+0x40c/0x680
     cpuidle_enter+0x30/0x40
     do_idle+0x1f4/0x26c
     cpu_startup_entry+0x34/0x40
     secondary_start_kernel+0x11c/0x13c
     __secondary_switched+0x74/0x78

Fix this by unconditionally powering on and enabling the needed clocks
for all CMT channels which are used for clock events. Do this before
registering any clock source or event to avid having to take the
spin lock at probe time.

Signed-off-by: Niklas Söderlund <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Daniel Lezcano <[email protected]>
guidosarducci added a commit to guidosarducci/linux that referenced this pull request Sep 19, 2025
Sequence of ctx checks and rewrites in real world:

1. Possible CO-RE rewrites of access size & offset, maybe breaking #2
2. Verifier env->ops->is_valid_access(), testing access size == sizeof(u64)
3. Verifier env->ops->convert_ctx_access(), rewrite size & offset

Position of access check above is strange, really only works on 64-bit and
likely unnoticed for lack of systematic 32-bit testing.

Test changing *is_valid_access() to always check size != sizeof(u64), but
on 32-bit systems also check size != sizeof(u32)

On 32-bit armhf, test_progs hits ~100 instances of failures such as:

(NOTE: this results from CO-RE relocation patching to u32 load size)

  libbpf: prog 'change_tcp_cc': -- BEGIN PROG LOAD LOG --
  0: R1=ctx() R10=fp0
  ; int change_tcp_cc(struct bpf_iter__tcp *ctx) @ bpf_iter_setsockopt.c:40
  0: (b4) w2 = 0                        ; R2_w=0
  ; if (!bpf_tcp_sk(ctx->sk_common)) @ bpf_iter_setsockopt.c:46
  1: (61) r1 = *(u32 *)(r1 +8)
  func 'bpf_iter_tcp' size 4 must be 8
  invalid bpf_context access off=8 size=4 is_valid_access=tracing_prog_is_valid_access
  processed 2 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
  -- END PROG LOAD LOG --
  libbpf: prog 'change_tcp_cc': failed to load: -EACCES
  libbpf: failed to load object 'bpf_iter_setsockopt'
  libbpf: failed to load BPF skeleton 'bpf_iter_setsockopt': -EACCES
  serial_test_bpf_iter_setsockopt:FAIL:iter_skel unexpected error: -13
  torvalds#21      bpf_iter_setsockopt:FAIL

(NOTE: no error for tests without CO-RE patching which have u64 load size)

This means *_is_valid_access() can't check ctx pointers simply using:

	if (size != sizeof(__u64))
		return false;
or
	if (size != sizeof(void *)
		return false;

And what's required instead is a combo like:

	if (size != sizeof(__u64) && size != sizeof(long))
		return false;

Implement above as convenience function and use in:

 - btf_ctx_access()
 - cg_sockopt_is_valid_access()
 - bpf_skb_is_valid_access()
 - sock_addr_is_valid_access()
 - sock_ops_is_valid_access()
 - sk_msg_is_valid_access()
 - flow_dissector_is_valid_access()

This eliminates all 'invalid bpf_context access" errors on 32-bit armhf
except one with nf_is_valid_access() which is fixed in the next patch.

Signed-off-by: Tony Ambardar <[email protected]>
guidosarducci added a commit to guidosarducci/linux that referenced this pull request Sep 20, 2025
Sequence of ctx checks and rewrites in real world:

1. Possible CO-RE rewrites of access size & offset, maybe breaking #2
2. Verifier env->ops->is_valid_access(), testing access size == sizeof(u64)
3. Verifier env->ops->convert_ctx_access(), rewrite size & offset

Position of access check above is strange, really only works on 64-bit and
likely unnoticed for lack of systematic 32-bit testing.

Test changing *is_valid_access() to always check size != sizeof(u64), but
on 32-bit systems also check size != sizeof(u32)

On 32-bit armhf, test_progs hits ~100 instances of failures such as:

(NOTE: this results from CO-RE relocation patching to u32 load size)

  libbpf: prog 'change_tcp_cc': -- BEGIN PROG LOAD LOG --
  0: R1=ctx() R10=fp0
  ; int change_tcp_cc(struct bpf_iter__tcp *ctx) @ bpf_iter_setsockopt.c:40
  0: (b4) w2 = 0                        ; R2_w=0
  ; if (!bpf_tcp_sk(ctx->sk_common)) @ bpf_iter_setsockopt.c:46
  1: (61) r1 = *(u32 *)(r1 +8)
  func 'bpf_iter_tcp' size 4 must be 8
  invalid bpf_context access off=8 size=4 is_valid_access=tracing_prog_is_valid_access
  processed 2 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
  -- END PROG LOAD LOG --
  libbpf: prog 'change_tcp_cc': failed to load: -EACCES
  libbpf: failed to load object 'bpf_iter_setsockopt'
  libbpf: failed to load BPF skeleton 'bpf_iter_setsockopt': -EACCES
  serial_test_bpf_iter_setsockopt:FAIL:iter_skel unexpected error: -13
  torvalds#21      bpf_iter_setsockopt:FAIL

(NOTE: no error for tests without CO-RE patching which have u64 load size)

This means *_is_valid_access() can't check ctx pointers simply using:

	if (size != sizeof(__u64))
		return false;
or
	if (size != sizeof(void *)
		return false;

And what's required instead is a combo like:

	if (size != sizeof(__u64) && size != sizeof(long))
		return false;

Implement above as convenience function and use in:

 - btf_ctx_access()
 - cg_sockopt_is_valid_access()
 - bpf_skb_is_valid_access()
 - sock_addr_is_valid_access()
 - sock_ops_is_valid_access()
 - sk_msg_is_valid_access()
 - flow_dissector_is_valid_access()

This eliminates all 'invalid bpf_context access" errors on 32-bit armhf
except one with nf_is_valid_access() which is fixed in the next patch.

Signed-off-by: Tony Ambardar <[email protected]>
guidosarducci added a commit to guidosarducci/linux that referenced this pull request Sep 21, 2025
Sequence of ctx checks and rewrites in real world:

1. Possible CO-RE rewrites of access size & offset, maybe breaking #2
2. Verifier env->ops->is_valid_access(), testing access size == sizeof(u64)
3. Verifier env->ops->convert_ctx_access(), rewrite size & offset

Position of access check above is strange, really only works on 64-bit and
likely unnoticed for lack of systematic 32-bit testing.

Test changing *is_valid_access() to always check size != sizeof(u64), but
on 32-bit systems also check size != sizeof(u32)

On 32-bit armhf, test_progs hits ~100 instances of failures such as:

(NOTE: this results from CO-RE relocation patching to u32 load size)

  libbpf: prog 'change_tcp_cc': -- BEGIN PROG LOAD LOG --
  0: R1=ctx() R10=fp0
  ; int change_tcp_cc(struct bpf_iter__tcp *ctx) @ bpf_iter_setsockopt.c:40
  0: (b4) w2 = 0                        ; R2_w=0
  ; if (!bpf_tcp_sk(ctx->sk_common)) @ bpf_iter_setsockopt.c:46
  1: (61) r1 = *(u32 *)(r1 +8)
  func 'bpf_iter_tcp' size 4 must be 8
  invalid bpf_context access off=8 size=4 is_valid_access=tracing_prog_is_valid_access
  processed 2 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
  -- END PROG LOAD LOG --
  libbpf: prog 'change_tcp_cc': failed to load: -EACCES
  libbpf: failed to load object 'bpf_iter_setsockopt'
  libbpf: failed to load BPF skeleton 'bpf_iter_setsockopt': -EACCES
  serial_test_bpf_iter_setsockopt:FAIL:iter_skel unexpected error: -13
  torvalds#21      bpf_iter_setsockopt:FAIL

(NOTE: no error for tests without CO-RE patching which have u64 load size)

This means *_is_valid_access() can't check ctx pointers simply using:

	if (size != sizeof(__u64))
		return false;
or
	if (size != sizeof(void *)
		return false;

And what's required instead is a combo like:

	if (size != sizeof(__u64) && size != sizeof(long))
		return false;

Implement above as convenience function and use in:

 - btf_ctx_access()
 - cg_sockopt_is_valid_access()
 - bpf_skb_is_valid_access()
 - sock_addr_is_valid_access()
 - sock_ops_is_valid_access()
 - sk_msg_is_valid_access()
 - flow_dissector_is_valid_access()

This eliminates all 'invalid bpf_context access" errors on 32-bit armhf
except one with nf_is_valid_access() which is fixed in the next patch.

Signed-off-by: Tony Ambardar <[email protected]>
guidosarducci added a commit to guidosarducci/linux that referenced this pull request Sep 23, 2025
Sequence of ctx checks and rewrites in real world:

1. Possible CO-RE rewrites of access size & offset, maybe breaking #2
2. Verifier env->ops->is_valid_access(), testing access size == sizeof(u64)
3. Verifier env->ops->convert_ctx_access(), rewrite size & offset

Position of access check above is strange, really only works on 64-bit and
likely unnoticed for lack of systematic 32-bit testing.

Test changing *is_valid_access() to always check size != sizeof(u64), but
on 32-bit systems also check size != sizeof(u32)

On 32-bit armhf, test_progs hits ~100 instances of failures such as:

(NOTE: this results from CO-RE relocation patching to u32 load size)

  libbpf: prog 'change_tcp_cc': -- BEGIN PROG LOAD LOG --
  0: R1=ctx() R10=fp0
  ; int change_tcp_cc(struct bpf_iter__tcp *ctx) @ bpf_iter_setsockopt.c:40
  0: (b4) w2 = 0                        ; R2_w=0
  ; if (!bpf_tcp_sk(ctx->sk_common)) @ bpf_iter_setsockopt.c:46
  1: (61) r1 = *(u32 *)(r1 +8)
  func 'bpf_iter_tcp' size 4 must be 8
  invalid bpf_context access off=8 size=4 is_valid_access=tracing_prog_is_valid_access
  processed 2 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
  -- END PROG LOAD LOG --
  libbpf: prog 'change_tcp_cc': failed to load: -EACCES
  libbpf: failed to load object 'bpf_iter_setsockopt'
  libbpf: failed to load BPF skeleton 'bpf_iter_setsockopt': -EACCES
  serial_test_bpf_iter_setsockopt:FAIL:iter_skel unexpected error: -13
  torvalds#21      bpf_iter_setsockopt:FAIL

(NOTE: no error for tests without CO-RE patching which have u64 load size)

This means *_is_valid_access() can't check ctx pointers simply using:

	if (size != sizeof(__u64))
		return false;
or
	if (size != sizeof(void *)
		return false;

And what's required instead is a combo like:

	if (size != sizeof(__u64) && size != sizeof(long))
		return false;

Implement above as convenience function and use in:

 - btf_ctx_access()
 - cg_sockopt_is_valid_access()
 - bpf_skb_is_valid_access()
 - sock_addr_is_valid_access()
 - sock_ops_is_valid_access()
 - sk_msg_is_valid_access()
 - flow_dissector_is_valid_access()

This eliminates all 'invalid bpf_context access" errors on 32-bit armhf
except one with nf_is_valid_access() which is fixed in the next patch.

Signed-off-by: Tony Ambardar <[email protected]>
guidosarducci added a commit to guidosarducci/linux that referenced this pull request Sep 23, 2025
Sequence of ctx checks and rewrites in real world:

1. Possible CO-RE rewrites of access size & offset, maybe breaking #2
2. Verifier env->ops->is_valid_access(), testing access size == sizeof(u64)
3. Verifier env->ops->convert_ctx_access(), rewrite size & offset

Position of access check above is strange, really only works on 64-bit and
likely unnoticed for lack of systematic 32-bit testing.

Test changing *is_valid_access() to always check size != sizeof(u64), but
on 32-bit systems also check size != sizeof(u32)

On 32-bit armhf, test_progs hits ~100 instances of failures such as:

(NOTE: this results from CO-RE relocation patching to u32 load size)

  libbpf: prog 'change_tcp_cc': -- BEGIN PROG LOAD LOG --
  0: R1=ctx() R10=fp0
  ; int change_tcp_cc(struct bpf_iter__tcp *ctx) @ bpf_iter_setsockopt.c:40
  0: (b4) w2 = 0                        ; R2_w=0
  ; if (!bpf_tcp_sk(ctx->sk_common)) @ bpf_iter_setsockopt.c:46
  1: (61) r1 = *(u32 *)(r1 +8)
  func 'bpf_iter_tcp' size 4 must be 8
  invalid bpf_context access off=8 size=4 is_valid_access=tracing_prog_is_valid_access
  processed 2 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
  -- END PROG LOAD LOG --
  libbpf: prog 'change_tcp_cc': failed to load: -EACCES
  libbpf: failed to load object 'bpf_iter_setsockopt'
  libbpf: failed to load BPF skeleton 'bpf_iter_setsockopt': -EACCES
  serial_test_bpf_iter_setsockopt:FAIL:iter_skel unexpected error: -13
  torvalds#21      bpf_iter_setsockopt:FAIL

(NOTE: no error for tests without CO-RE patching which have u64 load size)

This means *_is_valid_access() can't check ctx pointers simply using:

	if (size != sizeof(__u64))
		return false;
or
	if (size != sizeof(void *)
		return false;

And what's required instead is a combo like:

	if (size != sizeof(__u64) && size != sizeof(long))
		return false;

Implement above as convenience function and use in:

 - btf_ctx_access()
 - cg_sockopt_is_valid_access()
 - bpf_skb_is_valid_access()
 - sock_addr_is_valid_access()
 - sock_ops_is_valid_access()
 - sk_msg_is_valid_access()
 - flow_dissector_is_valid_access()

This eliminates all 'invalid bpf_context access" errors on 32-bit armhf
except one with nf_is_valid_access() which is fixed in the next patch.

Signed-off-by: Tony Ambardar <[email protected]>
guidosarducci added a commit to guidosarducci/linux that referenced this pull request Sep 23, 2025
Sequence of ctx checks and rewrites in real world:

1. Possible CO-RE rewrites of access size & offset, maybe breaking #2
2. Verifier env->ops->is_valid_access(), testing access size == sizeof(u64)
3. Verifier env->ops->convert_ctx_access(), rewrite size & offset

Position of access check above is strange, really only works on 64-bit and
likely unnoticed for lack of systematic 32-bit testing.

Test changing *is_valid_access() to always check size != sizeof(u64), but
on 32-bit systems also check size != sizeof(u32)

On 32-bit armhf, test_progs hits ~100 instances of failures such as:

(NOTE: this results from CO-RE relocation patching to u32 load size)

  libbpf: prog 'change_tcp_cc': -- BEGIN PROG LOAD LOG --
  0: R1=ctx() R10=fp0
  ; int change_tcp_cc(struct bpf_iter__tcp *ctx) @ bpf_iter_setsockopt.c:40
  0: (b4) w2 = 0                        ; R2_w=0
  ; if (!bpf_tcp_sk(ctx->sk_common)) @ bpf_iter_setsockopt.c:46
  1: (61) r1 = *(u32 *)(r1 +8)
  func 'bpf_iter_tcp' size 4 must be 8
  invalid bpf_context access off=8 size=4 is_valid_access=tracing_prog_is_valid_access
  processed 2 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
  -- END PROG LOAD LOG --
  libbpf: prog 'change_tcp_cc': failed to load: -EACCES
  libbpf: failed to load object 'bpf_iter_setsockopt'
  libbpf: failed to load BPF skeleton 'bpf_iter_setsockopt': -EACCES
  serial_test_bpf_iter_setsockopt:FAIL:iter_skel unexpected error: -13
  torvalds#21      bpf_iter_setsockopt:FAIL

(NOTE: no error for tests without CO-RE patching which have u64 load size)

This means *_is_valid_access() can't check ctx pointers simply using:

	if (size != sizeof(__u64))
		return false;
or
	if (size != sizeof(void *)
		return false;

And what's required instead is a combo like:

	if (size != sizeof(__u64) && size != sizeof(long))
		return false;

Implement above as convenience function and use in:

 - btf_ctx_access()
 - cg_sockopt_is_valid_access()
 - bpf_skb_is_valid_access()
 - sock_addr_is_valid_access()
 - sock_ops_is_valid_access()
 - sk_msg_is_valid_access()
 - flow_dissector_is_valid_access()

This eliminates all 'invalid bpf_context access" errors on 32-bit armhf
except one with nf_is_valid_access() which is fixed in the next patch.

Signed-off-by: Tony Ambardar <[email protected]>
guidosarducci added a commit to guidosarducci/linux that referenced this pull request Sep 23, 2025
Sequence of ctx checks and rewrites in real world:

1. Possible CO-RE rewrites of access size & offset, maybe breaking #2
2. Verifier env->ops->is_valid_access(), testing access size == sizeof(u64)
3. Verifier env->ops->convert_ctx_access(), rewrite size & offset

Position of access check above is strange, really only works on 64-bit and
likely unnoticed for lack of systematic 32-bit testing.

Test changing *is_valid_access() to always check size != sizeof(u64), but
on 32-bit systems also check size != sizeof(u32)

On 32-bit armhf, test_progs hits ~100 instances of failures such as:

(NOTE: this results from CO-RE relocation patching to u32 load size)

  libbpf: prog 'change_tcp_cc': -- BEGIN PROG LOAD LOG --
  0: R1=ctx() R10=fp0
  ; int change_tcp_cc(struct bpf_iter__tcp *ctx) @ bpf_iter_setsockopt.c:40
  0: (b4) w2 = 0                        ; R2_w=0
  ; if (!bpf_tcp_sk(ctx->sk_common)) @ bpf_iter_setsockopt.c:46
  1: (61) r1 = *(u32 *)(r1 +8)
  func 'bpf_iter_tcp' size 4 must be 8
  invalid bpf_context access off=8 size=4 is_valid_access=tracing_prog_is_valid_access
  processed 2 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
  -- END PROG LOAD LOG --
  libbpf: prog 'change_tcp_cc': failed to load: -EACCES
  libbpf: failed to load object 'bpf_iter_setsockopt'
  libbpf: failed to load BPF skeleton 'bpf_iter_setsockopt': -EACCES
  serial_test_bpf_iter_setsockopt:FAIL:iter_skel unexpected error: -13
  torvalds#21      bpf_iter_setsockopt:FAIL

(NOTE: no error for tests without CO-RE patching which have u64 load size)

This means *_is_valid_access() can't check ctx pointers simply using:

	if (size != sizeof(__u64))
		return false;
or
	if (size != sizeof(void *)
		return false;

And what's required instead is a combo like:

	if (size != sizeof(__u64) && size != sizeof(long))
		return false;

Implement above as convenience function and use in:

 - btf_ctx_access()
 - cg_sockopt_is_valid_access()
 - bpf_skb_is_valid_access()
 - sock_addr_is_valid_access()
 - sock_ops_is_valid_access()
 - sk_msg_is_valid_access()
 - flow_dissector_is_valid_access()

This eliminates all 'invalid bpf_context access" errors on 32-bit armhf
except one with nf_is_valid_access() which is fixed in the next patch.

Signed-off-by: Tony Ambardar <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant