/* * Copyright (C) 2015 Microchip Technology * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . */ #ifndef _MICROCHIPPHY_H #define _MICROCHIPPHY_H #define LAN88XX_INT_MASK (0x19) #define LAN88XX_INT_MASK_MDINTPIN_EN_ (0x8000) #define LAN88XX_INT_MASK_SPEED_CHANGE_ (0x4000) #define LAN88XX_INT_MASK_LINK_CHANGE_ (0x2000) #define LAN88XX_INT_MASK_FDX_CHANGE_ (0x1000) #define LAN88XX_INT_MASK_AUTONEG_ERR_ (0x0800) #define LAN88XX_INT_MASK_AUTONEG_DONE_ (0x0400) #define LAN88XX_INT_MASK_POE_DETECT_ (0x0200) #define LAN88XX_INT_MASK_SYMBOL_ERR_ (0x0100) #define LAN88XX_INT_MASK_FAST_LINK_FAIL_ (0x0080) #define LAN88XX_INT_MASK_WOL_EVENT_ (0x0040) #define LAN88XX_INT_MASK_EXTENDED_INT_ (0x0020) #define LAN88XX_INT_MASK_RESERVED_ (0x0010) #define LAN88XX_INT_MASK_FALSE_CARRIER_ (0x0008) #define LAN88XX_INT_MASK_LINK_SPEED_DS_ (0x0004) #define LAN88XX_INT_MASK_MASTER_SLAVE_DONE_ (0x0002) #define LAN88XX_INT_MASK_RX__ER_ (0x0001) #define LAN88XX_INT_STS (0x1A) #define LAN88XX_INT_STS_INT_ACTIVE_ (0x8000) #define LAN88XX_INT_STS_SPEED_CHANGE_ (0x4000) #define LAN88XX_INT_STS_LINK_CHANGE_ (0x2000) #define LAN88XX_INT_STS_FDX_CHANGE_ (0x1000) #define LAN88XX_INT_STS_AUTONEG_ERR_ (0x0800) #define LAN88XX_INT_STS_AUTONEG_DONE_ (0x0400) #define LAN88XX_INT_STS_POE_DETECT_ (0x0200) #define LAN88XX_INT_STS_SYMBOL_ERR_ (0x0100) #define LAN88XX_INT_STS_FAST_LINK_FAIL_ (0x0080) #define LAN88XX_INT_STS_WOL_EVENT_ (0x0040) #define LAN88XX_INT_STS_EXTENDED_INT_ (0x0020) #define LAN88XX_INT_STS_RESERVED_ (0x0010) #define LAN88XX_INT_STS_FALSE_CARRIER_ (0x0008) #define LAN88XX_INT_STS_LINK_SPEED_DS_ (0x0004) #define LAN88XX_INT_STS_MASTER_SLAVE_DONE_ (0x0002) #define LAN88XX_INT_STS_RX_ER_ (0x0001) #define LAN88XX_EXT_PAGE_ACCESS (0x1F) #define LAN88XX_EXT_PAGE_SPACE_0 (0x0000) #define LAN88XX_EXT_PAGE_SPACE_1 (0x0001) #define LAN88XX_EXT_PAGE_SPACE_2 (0x0002) /* Extended Register Page 1 space */ #define LAN88XX_EXT_MODE_CTRL (0x13) #define LAN88XX_EXT_MODE_CTRL_MDIX_MASK_ (0x000C) #define LAN88XX_EXT_MODE_CTRL_AUTO_MDIX_ (0x0000) #define LAN88XX_EXT_MODE_CTRL_MDI_ (0x0008) #define LAN88XX_EXT_MODE_CTRL_MDI_X_ (0x000C) /* MMD 3 Registers */ #define LAN88XX_MMD3_CHIP_ID (32877) #define LAN88XX_MMD3_CHIP_REV (32878) /* Registers specific to the LAN7800/LAN7850 embedded phy */ #define LAN78XX_PHY_LED_MODE_SELECT (0x1D) /* DSP registers */ #define PHY_ARDENNES_MMD_DEV_3_PHY_CFG (0x806A) #define PHY_ARDENNES_MMD_DEV_3_PHY_CFG_ZD_DLY_EN_ (0x2000) #define LAN88XX_EXT_PAGE_ACCESS_TR (0x52B5) #define LAN88XX_EXT_PAGE_TR_CR 16 #define LAN88XX_EXT_PAGE_TR_LOW_DATA 17 #define LAN88XX_EXT_PAGE_TR_HIGH_DATA 18 #endif /* _MICROCHIPPHY_H */ e'/> urn:sha1:91c96842ab1e9159c8129ab5ddfeb7dd97bf840e Test stashing both referenced kptr and local kptr into local kptrs. Then, test unstashing them. Acked-by: Martin KaFai Lau <martin.lau@kernel.org> Acked-by: Hou Tao <houtao1@huawei.com> Signed-off-by: Dave Marchevsky <davemarchevsky@fb.com> Signed-off-by: Amery Hung <amery.hung@bytedance.com> Link: https://lore.kernel.org/r/20240813212424.2871455-6-amery.hung@bytedance.com Signed-off-by: Alexei Starovoitov <ast@kernel.org> selftests/bpf: Add CO-RE relocs kfunc flavors tests 2023-08-18T16:12:59Z Dave Marchevsky davemarchevsky@fb.com 2023-08-17T22:53:53Z urn:sha1:63ae8eb2c5b1388eeda39bc95e89e4ad906fa336 This patch adds selftests that exercise kfunc flavor relocation functionality added in the previous patch. The actual kfunc defined in kernel/bpf/helpers.c is: struct task_struct *bpf_task_acquire(struct task_struct *p) The following relocation behaviors are checked: struct task_struct *bpf_task_acquire___one(struct task_struct *name) * Should succeed despite differing param name struct task_struct *bpf_task_acquire___two(struct task_struct *p, void *ctx) * Should fail because there is no two-param bpf_task_acquire struct task_struct *bpf_task_acquire___three(void *ctx) * Should fail because, despite vmlinux's bpf_task_acquire having one param, the types don't match Signed-off-by: Dave Marchevsky <davemarchevsky@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: David Vernet <void@manifault.com> Link: https://lore.kernel.org/bpf/20230817225353.2570845-2-davemarchevsky@fb.com bpf: Remove now-defunct task kfuncs 2023-04-01T16:07:20Z David Vernet void@manifault.com 2023-03-31T19:57:32Z urn:sha1:f85671c6ef46d490a90dac719e0c0e0adbacfd9b In commit 22df776a9a86 ("tasks: Extract rcu_users out of union"), the 'refcount_t rcu_users' field was extracted out of a union with the 'struct rcu_head rcu' field. This allows us to safely perform a refcount_inc_not_zero() on task->rcu_users when acquiring a reference on a task struct. A prior patch leveraged this by making struct task_struct an RCU-protected object in the verifier, and by bpf_task_acquire() to use the task->rcu_users field for synchronization. Now that we can use RCU to protect tasks, we no longer need bpf_task_kptr_get(), or bpf_task_acquire_not_zero(). bpf_task_kptr_get() is truly completely unnecessary, as we can just use RCU to get the object. bpf_task_acquire_not_zero() is now equivalent to bpf_task_acquire(). In addition to these changes, this patch also updates the associated selftests to no longer use these kfuncs. Signed-off-by: David Vernet <void@manifault.com> Link: https://lore.kernel.org/r/20230331195733.699708-3-void@manifault.com Signed-off-by: Alexei Starovoitov <ast@kernel.org> bpf: Make struct task_struct an RCU-safe type 2023-04-01T16:07:20Z David Vernet void@manifault.com 2023-03-31T19:57:31Z urn:sha1:d02c48fa113953aba0b330ec6c35f50c7d1d7986 struct task_struct objects are a bit interesting in terms of how their lifetime is protected by refcounts. task structs have two refcount fields: 1. refcount_t usage: Protects the memory backing the task struct. When this refcount drops to 0, the task is immediately freed, without waiting for an RCU grace period to elapse. This is the field that most callers in the kernel currently use to ensure that a task remains valid while it's being referenced, and is what's currently tracked with bpf_task_acquire() and bpf_task_release(). 2. refcount_t rcu_users: A refcount field which, when it drops to 0, schedules an RCU callback that drops a reference held on the 'usage' field above (which is acquired when the task is first created). This field therefore provides a form of RCU protection on the task by ensuring that at least one 'usage' refcount will be held until an RCU grace period has elapsed. The qualifier "a form of" is important here, as a task can remain valid after task->rcu_users has dropped to 0 and the subsequent RCU gp has elapsed. In terms of BPF, we want to use task->rcu_users to protect tasks that function as referenced kptrs, and to allow tasks stored as referenced kptrs in maps to be accessed with RCU protection. Let's first determine whether we can safely use task->rcu_users to protect tasks stored in maps. All of the bpf_task* kfuncs can only be called from tracepoint, struct_ops, or BPF_PROG_TYPE_SCHED_CLS, program types. For tracepoint and struct_ops programs, the struct task_struct passed to a program handler will always be trusted, so it will always be safe to call bpf_task_acquire() with any task passed to a program. Note, however, that we must update bpf_task_acquire() to be KF_RET_NULL, as it is possible that the task has exited by the time the program is invoked, even if the pointer is still currently valid because the main kernel holds a task->usage refcount. For BPF_PROG_TYPE_SCHED_CLS, tasks should never be passed as an argument to the any program handlers, so it should not be relevant. The second question is whether it's safe to use RCU to access a task that was acquired with bpf_task_acquire(), and stored in a map. Because bpf_task_acquire() now uses task->rcu_users, it follows that if the task is present in the map, that it must have had at least one task->rcu_users refcount by the time the current RCU cs was started. Therefore, it's safe to access that task until the end of the current RCU cs. With all that said, this patch makes struct task_struct is an RCU-protected object. In doing so, we also change bpf_task_acquire() to be KF_ACQUIRE | KF_RCU | KF_RET_NULL, and adjust any selftests as necessary. A subsequent patch will remove bpf_task_kptr_get(), and bpf_task_acquire_not_zero() respectively. Signed-off-by: David Vernet <void@manifault.com> Link: https://lore.kernel.org/r/20230331195733.699708-2-void@manifault.com Signed-off-by: Alexei Starovoitov <ast@kernel.org> selftests/bpf: Add test for bpf_ksym_exists(). 2023-03-17T22:46:02Z Alexei Starovoitov ast@kernel.org 2023-03-17T20:19:20Z urn:sha1:95fdf6e313a981b0729886f86916190cb418b04c Add load and run time test for bpf_ksym_exists() and check that the verifier performs dead code elimination for non-existing kfunc. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Reviewed-by: Martin KaFai Lau <martin.lau@kernel.org> Reviewed-by: Toke Høiland-Jørgensen <toke@redhat.com> Acked-by: John Fastabend <john.fastabend@gmail.com> Link: https://lore.kernel.org/bpf/20230317201920.62030-5-alexei.starovoitov@gmail.com selftests/bpf: Add various tests to check helper access into ptr_to_btf_id. 2023-03-14T06:08:21Z Alexei Starovoitov ast@kernel.org 2023-03-13T23:58:45Z urn:sha1:f25fd6088216bd257902e5c212177cddcb291218 Add various tests to check helper access into ptr_to_btf_id. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: David Vernet <void@manifault.com> Link: https://lore.kernel.org/r/20230313235845.61029-4-alexei.starovoitov@gmail.com Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org> selftests/bpf: fix lots of silly mistakes pointed out by compiler 2023-03-10T16:14:08Z Andrii Nakryiko andrii@kernel.org 2023-03-09T05:40:14Z urn:sha1:c8ed66859397237c649998c58a68a86b8ea5f417 Once we enable -Wall for BPF sources, compiler will complain about lots of unused variables, variables that are set but never read, etc. Fix all these issues first before enabling -Wall in Makefile. Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/r/20230309054015.4068562-4-andrii@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>