Commit 11b91485 authored by Alexei Starovoitov's avatar Alexei Starovoitov
Browse files

Merge branch 'Add BPF-helper for accessing CLOCK_TAI'

Kurt Kanzenbach says:

====================

Hi,

add a BPF-helper for accessing CLOCK_TAI. Use cases for such a BPF helper
include functionalities such as Tx launch time (e.g. ETF and TAPRIO Qdiscs),
timestamping and policing.

Patch #1 - Introduce BPF helper
Patch #2 - Add test case (skb based)

Changes since v1:

 * Update changelog (Alexei Starovoitov)
 * Add test case (Alexei Starovoitov, Andrii Nakryiko)
 * Add missing function prototype (netdev ci)

Previous versions:

 * v1: https://lore.kernel.org/r/20220606103734.92423-1-kurt@linutronix.de/



Jesper Dangaard Brouer (1):
  bpf: Add BPF-helper for accessing CLOCK_TAI
====================

Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parents b2d8ef19 64e15820
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -2349,6 +2349,7 @@ extern const struct bpf_func_proto bpf_get_numa_node_id_proto;
extern const struct bpf_func_proto bpf_tail_call_proto;
extern const struct bpf_func_proto bpf_ktime_get_ns_proto;
extern const struct bpf_func_proto bpf_ktime_get_boot_ns_proto;
extern const struct bpf_func_proto bpf_ktime_get_tai_ns_proto;
extern const struct bpf_func_proto bpf_get_current_pid_tgid_proto;
extern const struct bpf_func_proto bpf_get_current_uid_gid_proto;
extern const struct bpf_func_proto bpf_get_current_comm_proto;
+13 −0
Original line number Diff line number Diff line
@@ -5341,6 +5341,18 @@ union bpf_attr {
 *		**-EACCES** if the SYN cookie is not valid.
 *
 *		**-EPROTONOSUPPORT** if CONFIG_IPV6 is not builtin.
 *
 * u64 bpf_ktime_get_tai_ns(void)
 *	Description
 *		A nonsettable system-wide clock derived from wall-clock time but
 *		ignoring leap seconds.  This clock does not experience
 *		discontinuities and backwards jumps caused by NTP inserting leap
 *		seconds as CLOCK_REALTIME does.
 *
 *		See: **clock_gettime**\ (**CLOCK_TAI**)
 *	Return
 *		Current *ktime*.
 *
 */
#define __BPF_FUNC_MAPPER(FN)		\
	FN(unspec),			\
@@ -5551,6 +5563,7 @@ union bpf_attr {
	FN(tcp_raw_gen_syncookie_ipv6),	\
	FN(tcp_raw_check_syncookie_ipv4),	\
	FN(tcp_raw_check_syncookie_ipv6),	\
	FN(ktime_get_tai_ns),		\
	/* */

/* integer value in 'imm' field of BPF_CALL instruction selects which helper
+1 −0
Original line number Diff line number Diff line
@@ -2623,6 +2623,7 @@ const struct bpf_func_proto bpf_get_numa_node_id_proto __weak;
const struct bpf_func_proto bpf_ktime_get_ns_proto __weak;
const struct bpf_func_proto bpf_ktime_get_boot_ns_proto __weak;
const struct bpf_func_proto bpf_ktime_get_coarse_ns_proto __weak;
const struct bpf_func_proto bpf_ktime_get_tai_ns_proto __weak;

const struct bpf_func_proto bpf_get_current_pid_tgid_proto __weak;
const struct bpf_func_proto bpf_get_current_uid_gid_proto __weak;
+14 −0
Original line number Diff line number Diff line
@@ -198,6 +198,18 @@ const struct bpf_func_proto bpf_ktime_get_coarse_ns_proto = {
	.ret_type	= RET_INTEGER,
};

BPF_CALL_0(bpf_ktime_get_tai_ns)
{
	/* NMI safe access to clock tai */
	return ktime_get_tai_fast_ns();
}

const struct bpf_func_proto bpf_ktime_get_tai_ns_proto = {
	.func		= bpf_ktime_get_tai_ns,
	.gpl_only	= false,
	.ret_type	= RET_INTEGER,
};

BPF_CALL_0(bpf_get_current_pid_tgid)
{
	struct task_struct *task = current;
@@ -1617,6 +1629,8 @@ bpf_base_func_proto(enum bpf_func_id func_id)
		return &bpf_ktime_get_ns_proto;
	case BPF_FUNC_ktime_get_boot_ns:
		return &bpf_ktime_get_boot_ns_proto;
	case BPF_FUNC_ktime_get_tai_ns:
		return &bpf_ktime_get_tai_ns_proto;
	case BPF_FUNC_ringbuf_output:
		return &bpf_ringbuf_output_proto;
	case BPF_FUNC_ringbuf_reserve:
+13 −0
Original line number Diff line number Diff line
@@ -5341,6 +5341,18 @@ union bpf_attr {
 *		**-EACCES** if the SYN cookie is not valid.
 *
 *		**-EPROTONOSUPPORT** if CONFIG_IPV6 is not builtin.
 *
 * u64 bpf_ktime_get_tai_ns(void)
 *	Description
 *		A nonsettable system-wide clock derived from wall-clock time but
 *		ignoring leap seconds.  This clock does not experience
 *		discontinuities and backwards jumps caused by NTP inserting leap
 *		seconds as CLOCK_REALTIME does.
 *
 *		See: **clock_gettime**\ (**CLOCK_TAI**)
 *	Return
 *		Current *ktime*.
 *
 */
#define __BPF_FUNC_MAPPER(FN)		\
	FN(unspec),			\
@@ -5551,6 +5563,7 @@ union bpf_attr {
	FN(tcp_raw_gen_syncookie_ipv6),	\
	FN(tcp_raw_check_syncookie_ipv4),	\
	FN(tcp_raw_check_syncookie_ipv6),	\
	FN(ktime_get_tai_ns),		\
	/* */

/* integer value in 'imm' field of BPF_CALL instruction selects which helper
Loading