From nobody Fri Apr 3 11:10:50 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B5D6402457 for ; Tue, 24 Mar 2026 15:19:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774365556; cv=none; b=jX+7HrfBWCoQdFaE6lM6/TDtY9DQ58h83qHRgGVIc2IU7oAR6CGakXY5AS6PGMuqxVtLVZG3zDrud9j0oajCwnzJ9sWDowLLfgmFs/zpSSUNHd3avltfCwDt7MMWVKLjkoEN1ahm4ZsSn5APhAHvo+504N3TEGDF27J0iTs8hKc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774365556; c=relaxed/simple; bh=Wx3rCjft+f2xsQztl0u/tUkCuC3NJhEmQV+HjeE0iDk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iaS9uCkq4xdTrBmOsbuZIN/8x5XYPGbRnQoBOoDvnKSgXu7MdrH8YmToszW5bmBetcF/92k8WVLSQCYYi5XvZbt+le/RNzSOAro90n2F3Jlzb5lNdpup5eSMUZu07lkSA8HiC9+jlR/HhaE5O9p7KQy5yYx/MiCI2RG6OPcKNHY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=LQZhrDx0; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="LQZhrDx0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774365553; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NM71jEPy1P0WHGHdPzJuToYXqWbTBefaY9NqYpg0IOU=; b=LQZhrDx0MQTANlb3IympBwc040b0yArGX/3vmTmU7fX5F3WdR6tsmO2IWNr0NszYJXq4LZ i9nfdFQDZ9Y0wS+eulozIA1mE+WsN4HkpMCUok5zbRuqqRVnFDhtf66POwMcqvLRD8TuDF vLGwjXTk5sM5um+HpIFBKl8tVV9JU1Q= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-352-M9C8THMbPsyL3eIxAPqsKA-1; Tue, 24 Mar 2026 11:19:07 -0400 X-MC-Unique: M9C8THMbPsyL3eIxAPqsKA-1 X-Mimecast-MFC-AGG-ID: M9C8THMbPsyL3eIxAPqsKA_1774365545 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 363C61944DCB; Tue, 24 Mar 2026 15:19:04 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.22.65.192]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A712D18001FE; Tue, 24 Mar 2026 15:18:57 +0000 (UTC) From: Waiman Long To: Simon Horman , Julian Anastasov , "David S. Miller" , David Ahern , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Pablo Neira Ayuso , Florian Westphal , Phil Sutter , Frederic Weisbecker , Chen Ridong , Phil Auld Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, lvs-devel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, sheviks , Waiman Long Subject: [PATCH 1/2] sched/isolation: Make HK_TYPE_KTHREAD an alias of HK_TYPE_DOMAIN Date: Tue, 24 Mar 2026 11:18:26 -0400 Message-ID: <20260324151827.2006656-2-longman@redhat.com> In-Reply-To: <20260324151827.2006656-1-longman@redhat.com> References: <20260324151827.2006656-1-longman@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Since commit 041ee6f3727a ("kthread: Rely on HK_TYPE_DOMAIN for preferred affinity management"), kthreads default to use the HK_TYPE_DOMAIN cpumask. IOW, it is no longer affected by the setting of the nohz_full boot kernel parameter. That means HK_TYPE_KTHREAD should now be an alias of HK_TYPE_DOMAIN instead of HK_TYPE_KERNEL_NOISE to correctly reflect the current kthread behavior. Make the change as HK_TYPE_KTHREAD is still being used in some networking code. Fixes: 041ee6f3727a ("kthread: Rely on HK_TYPE_DOMAIN for preferred affinit= y management") Signed-off-by: Waiman Long Reviewed-by: David Dull --- include/linux/sched/isolation.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/linux/sched/isolation.h b/include/linux/sched/isolatio= n.h index dc3975ff1b2e..cf0fd03dd7a2 100644 --- a/include/linux/sched/isolation.h +++ b/include/linux/sched/isolation.h @@ -20,6 +20,11 @@ enum hk_type { HK_TYPE_KERNEL_NOISE, HK_TYPE_MAX, =20 + /* + * HK_TYPE_KTHREAD is now an alias of HK_TYPE_DOMAIN + */ + HK_TYPE_KTHREAD =3D HK_TYPE_DOMAIN, + /* * The following housekeeping types are only set by the nohz_full * boot commandline option. So they can share the same value. @@ -29,7 +34,6 @@ enum hk_type { HK_TYPE_RCU =3D HK_TYPE_KERNEL_NOISE, HK_TYPE_MISC =3D HK_TYPE_KERNEL_NOISE, HK_TYPE_WQ =3D HK_TYPE_KERNEL_NOISE, - HK_TYPE_KTHREAD =3D HK_TYPE_KERNEL_NOISE }; =20 #ifdef CONFIG_CPU_ISOLATION --=20 2.53.0 From nobody Fri Apr 3 11:10:50 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1522D3FF880 for ; Tue, 24 Mar 2026 15:19:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774365560; cv=none; b=kTUE+AdK1Sk2KyMD3MXpNjUf7dWEOoLa1bURLZ9XuTIxoQ0QRURsRazHwR0iJYN16sGppNR1TX1Vl0LtpzIRVUt8CwErEym/HpBELKUEPqRPtta/oHyBtPwV4+yEiy3GL1V2EbMLgdZc3x8tFCGvlyZ0GYy26zlJo4Xu199OOEE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774365560; c=relaxed/simple; bh=yQu+yg14FNYHLy+s+BbhOlgj6hTn6x3xR7kw0ed5ygA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QsrAQzEjAkD7XRpdCaIgIJU3rt55wQFWxImC4QieoR9mo2P/1YkDDnPZGKhUDiqbIFoR+4VgxqbOL10W8HgeI8Ki7VWZnq7HJi64rLJz/alXybP8t3rVmOHySxfBkrF8Qjrr5goJlpzaNGgXgt61BIAsVvCoxsZBqwKNwR2RwK8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=DgZTSMk8; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DgZTSMk8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774365555; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=47K4ukq6ERapPLsJPgxXf1k9UvvwaRytR4+a7cgPSYw=; b=DgZTSMk8MUQwgAX1/wPeE5pBySz9IhkNrmfu9Y4t/noRwZpAVR6aLBqAXGB7IbAk18j2xh s3T0csefPxFehSgU5jxtVKMGFWyuZiQ9zM8yqdceQJHasgxVVqehcjQ/zJHp87VjyCTBuL agYBmver4BNqwR4PlFNqNff3xxHMTYA= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-265-fwC_8vFtNWuKSKRWqW9RmQ-1; Tue, 24 Mar 2026 11:19:11 -0400 X-MC-Unique: fwC_8vFtNWuKSKRWqW9RmQ-1 X-Mimecast-MFC-AGG-ID: fwC_8vFtNWuKSKRWqW9RmQ_1774365549 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E95361956046; Tue, 24 Mar 2026 15:19:08 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.22.65.192]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8BBCA1800764; Tue, 24 Mar 2026 15:19:04 +0000 (UTC) From: Waiman Long To: Simon Horman , Julian Anastasov , "David S. Miller" , David Ahern , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Pablo Neira Ayuso , Florian Westphal , Phil Sutter , Frederic Weisbecker , Chen Ridong , Phil Auld Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, lvs-devel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, sheviks , Waiman Long Subject: [PATCH 2/2] ipvs: Guard access of HK_TYPE_KTHREAD cpumask with RCU Date: Tue, 24 Mar 2026 11:18:27 -0400 Message-ID: <20260324151827.2006656-3-longman@redhat.com> In-Reply-To: <20260324151827.2006656-1-longman@redhat.com> References: <20260324151827.2006656-1-longman@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" The ip_vs_ctl.c file and the associated ip_vs.h file are the only places in the kernel where HK_TYPE_KTHREAD cpumask is being retrieved and used. Now that HK_TYPE_KTHREAD/HK_TYPE_DOMAIN cpumask can be changed at run time. We need to use RCU to guard access to this cpumask to avoid a potential UAF problem as the returned cpumask may be freed before it is being used. Signed-off-by: Waiman Long --- include/net/ip_vs.h | 20 ++++++++++++++++---- net/netfilter/ipvs/ip_vs_ctl.c | 13 ++++++++----- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h index 29a36709e7f3..17c85a575ef4 100644 --- a/include/net/ip_vs.h +++ b/include/net/ip_vs.h @@ -1155,7 +1155,7 @@ static inline int sysctl_run_estimation(struct netns_= ipvs *ipvs) return ipvs->sysctl_run_estimation; } =20 -static inline const struct cpumask *sysctl_est_cpulist(struct netns_ipvs *= ipvs) +static inline const struct cpumask *__sysctl_est_cpulist(struct netns_ipvs= *ipvs) { if (ipvs->est_cpulist_valid) return ipvs->sysctl_est_cpulist; @@ -1273,7 +1273,7 @@ static inline int sysctl_run_estimation(struct netns_= ipvs *ipvs) return 1; } =20 -static inline const struct cpumask *sysctl_est_cpulist(struct netns_ipvs *= ipvs) +static inline const struct cpumask *__sysctl_est_cpulist(struct netns_ipvs= *ipvs) { return housekeeping_cpumask(HK_TYPE_KTHREAD); } @@ -1290,6 +1290,18 @@ static inline int sysctl_est_nice(struct netns_ipvs = *ipvs) =20 #endif =20 +static inline bool sysctl_est_cpulist_empty(struct netns_ipvs *ipvs) +{ + guard(rcu)(); + return cpumask_empty(__sysctl_est_cpulist(ipvs)); +} + +static inline unsigned int sysctl_est_cpulist_weight(struct netns_ipvs *ip= vs) +{ + guard(rcu)(); + return cpumask_weight(__sysctl_est_cpulist(ipvs)); +} + /* IPVS core functions * (from ip_vs_core.c) */ @@ -1604,7 +1616,7 @@ static inline void ip_vs_est_stopped_recalc(struct ne= tns_ipvs *ipvs) /* Stop tasks while cpulist is empty or if disabled with flag */ ipvs->est_stopped =3D !sysctl_run_estimation(ipvs) || (ipvs->est_cpulist_valid && - cpumask_empty(sysctl_est_cpulist(ipvs))); + sysctl_est_cpulist_empty(ipvs)); #endif } =20 @@ -1620,7 +1632,7 @@ static inline bool ip_vs_est_stopped(struct netns_ipv= s *ipvs) static inline int ip_vs_est_max_threads(struct netns_ipvs *ipvs) { unsigned int limit =3D IPVS_EST_CPU_KTHREADS * - cpumask_weight(sysctl_est_cpulist(ipvs)); + sysctl_est_cpulist_weight(ipvs); =20 return max(1U, limit); } diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c index 35642de2a0fe..f38a2e2a9dc5 100644 --- a/net/netfilter/ipvs/ip_vs_ctl.c +++ b/net/netfilter/ipvs/ip_vs_ctl.c @@ -1973,11 +1973,14 @@ static int ipvs_proc_est_cpumask_get(const struct c= tl_table *table, =20 mutex_lock(&ipvs->est_mutex); =20 - if (ipvs->est_cpulist_valid) - mask =3D *valp; - else - mask =3D (struct cpumask *)housekeeping_cpumask(HK_TYPE_KTHREAD); - ret =3D scnprintf(buffer, size, "%*pbl\n", cpumask_pr_args(mask)); + /* HK_TYPE_KTHREAD cpumask needs RCU protection */ + scoped_guard(rcu) { + if (ipvs->est_cpulist_valid) + mask =3D *valp; + else + mask =3D (struct cpumask *)housekeeping_cpumask(HK_TYPE_KTHREAD); + ret =3D scnprintf(buffer, size, "%*pbl\n", cpumask_pr_args(mask)); + } =20 mutex_unlock(&ipvs->est_mutex); =20 --=20 2.53.0