--- /dev/null
+From 673004821ab98c6645bd21af56a290854e88f533 Mon Sep 17 00:00:00 2001
+From: Matthieu Baerts <matthieu.baerts@tessares.net>
+Date: Thu, 8 Jun 2023 18:38:43 +0200
+Subject: selftests: mptcp: lib: skip if missing symbol
+
+From: Matthieu Baerts <matthieu.baerts@tessares.net>
+
+commit 673004821ab98c6645bd21af56a290854e88f533 upstream.
+
+Selftests are supposed to run on any kernels, including the old ones not
+supporting all MPTCP features.
+
+New functions are now available to easily detect if a certain feature is
+missing by looking at kallsyms.
+
+These new helpers are going to be used in the following commits. In
+order to ease the backport of such future patches, it would be good if
+this patch is backported up to the introduction of MPTCP selftests,
+hence the Fixes tag below: this type of check was supposed to be done
+from the beginning.
+
+Link: https://github.com/multipath-tcp/mptcp_net-next/issues/368
+Fixes: 048d19d444be ("mptcp: add basic kselftest for mptcp")
+Cc: stable@vger.kernel.org
+Signed-off-by: Matthieu Baerts <matthieu.baerts@tessares.net>
+Signed-off-by: Jakub Kicinski <kuba@kernel.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ tools/testing/selftests/net/mptcp/config | 1
+ tools/testing/selftests/net/mptcp/mptcp_lib.sh | 38 +++++++++++++++++++++++++
+ 2 files changed, 39 insertions(+)
+
+--- a/tools/testing/selftests/net/mptcp/config
++++ b/tools/testing/selftests/net/mptcp/config
+@@ -1,3 +1,4 @@
++CONFIG_KALLSYMS=y
+ CONFIG_MPTCP=y
+ CONFIG_IPV6=y
+ CONFIG_MPTCP_IPV6=y
+--- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh
++++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
+@@ -38,3 +38,41 @@ mptcp_lib_check_mptcp() {
+ exit ${KSFT_SKIP}
+ fi
+ }
++
++mptcp_lib_check_kallsyms() {
++ if ! mptcp_lib_has_file "/proc/kallsyms"; then
++ echo "SKIP: CONFIG_KALLSYMS is missing"
++ exit ${KSFT_SKIP}
++ fi
++}
++
++# Internal: use mptcp_lib_kallsyms_has() instead
++__mptcp_lib_kallsyms_has() {
++ local sym="${1}"
++
++ mptcp_lib_check_kallsyms
++
++ grep -q " ${sym}" /proc/kallsyms
++}
++
++# $1: part of a symbol to look at, add '$' at the end for full name
++mptcp_lib_kallsyms_has() {
++ local sym="${1}"
++
++ if __mptcp_lib_kallsyms_has "${sym}"; then
++ return 0
++ fi
++
++ mptcp_lib_fail_if_expected_feature "${sym} symbol not found"
++}
++
++# $1: part of a symbol to look at, add '$' at the end for full name
++mptcp_lib_kallsyms_doesnt_have() {
++ local sym="${1}"
++
++ if ! __mptcp_lib_kallsyms_has "${sym}"; then
++ return 0
++ fi
++
++ mptcp_lib_fail_if_expected_feature "${sym} symbol has been found"
++}
--- /dev/null
+From b1a6a38ab8a633546cefae890da842f19e006c74 Mon Sep 17 00:00:00 2001
+From: Matthieu Baerts <matthieu.baerts@tessares.net>
+Date: Sat, 10 Jun 2023 18:11:36 +0200
+Subject: selftests: mptcp: lib: skip if not below kernel version
+
+From: Matthieu Baerts <matthieu.baerts@tessares.net>
+
+commit b1a6a38ab8a633546cefae890da842f19e006c74 upstream.
+
+Selftests are supposed to run on any kernels, including the old ones not
+supporting all MPTCP features.
+
+A new function is now available to easily detect if a feature is
+missing by looking at the kernel version. That's clearly not ideal and
+this kind of check should be avoided as soon as possible. But sometimes,
+there are no external sign that a "feature" is available or not:
+internal behaviours can change without modifying the uAPI and these
+selftests are verifying the internal behaviours. Sometimes, the only
+(easy) way to verify if the feature is present is to run the test but
+then the validation cannot determine if there is a failure with the
+feature or if the feature is missing. Then it looks better to check the
+kernel version instead of having tests that can never fail. In any case,
+we need a solution not to have a whole selftest being marked as failed
+just because one sub-test has failed.
+
+Note that this env var car be set to 1 not to do such check and run the
+linked sub-test: SELFTESTS_MPTCP_LIB_NO_KVERSION_CHECK.
+
+This new helper is going to be used in the following commits. In order
+to ease the backport of such future patches, it would be good if this
+patch is backported up to the introduction of MPTCP selftests, hence the
+Fixes tag below: this type of check was supposed to be done from the
+beginning.
+
+Link: https://github.com/multipath-tcp/mptcp_net-next/issues/368
+Fixes: 048d19d444be ("mptcp: add basic kselftest for mptcp")
+Cc: stable@vger.kernel.org
+Signed-off-by: Matthieu Baerts <matthieu.baerts@tessares.net>
+Signed-off-by: Jakub Kicinski <kuba@kernel.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ tools/testing/selftests/net/mptcp/mptcp_lib.sh | 26 +++++++++++++++++++++++++
+ 1 file changed, 26 insertions(+)
+
+--- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh
++++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
+@@ -76,3 +76,29 @@ mptcp_lib_kallsyms_doesnt_have() {
+
+ mptcp_lib_fail_if_expected_feature "${sym} symbol has been found"
+ }
++
++# !!!AVOID USING THIS!!!
++# Features might not land in the expected version and features can be backported
++#
++# $1: kernel version, e.g. 6.3
++mptcp_lib_kversion_ge() {
++ local exp_maj="${1%.*}"
++ local exp_min="${1#*.}"
++ local v maj min
++
++ # If the kernel has backported features, set this env var to 1:
++ if [ "${SELFTESTS_MPTCP_LIB_NO_KVERSION_CHECK:-}" = "1" ]; then
++ return 0
++ fi
++
++ v=$(uname -r | cut -d'.' -f1,2)
++ maj=${v%.*}
++ min=${v#*.}
++
++ if [ "${maj}" -gt "${exp_maj}" ] ||
++ { [ "${maj}" -eq "${exp_maj}" ] && [ "${min}" -ge "${exp_min}" ]; }; then
++ return 0
++ fi
++
++ mptcp_lib_fail_if_expected_feature "kernel version ${1} lower than ${v}"
++}