From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org, Tejun Heo <tj@kernel.org>,
"Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com>
Subject: [PATCH 4.14 075/101] cgroup: fix CSS_TASK_ITER_PROCS
Date: Mon, 7 Jan 2019 13:33:03 +0100 [thread overview]
Message-ID: <20190107105337.073441015@linuxfoundation.org> (raw)
In-Reply-To: <20190107105330.372621917@linuxfoundation.org>
4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tejun Heo <tj@kernel.org>
commit e9d81a1bc2c48ea9782e3e8b53875f419766ef47 upstream.
CSS_TASK_ITER_PROCS implements process-only iteration by making
css_task_iter_advance() skip tasks which aren't threadgroup leaders;
however, when an iteration is started css_task_iter_start() calls the
inner helper function css_task_iter_advance_css_set() instead of
css_task_iter_advance(). As the helper doesn't have the skip logic,
when the first task to visit is a non-leader thread, it doesn't get
skipped correctly as shown in the following example.
# ps -L 2030
PID LWP TTY STAT TIME COMMAND
2030 2030 pts/0 Sl+ 0:00 ./test-thread
2030 2031 pts/0 Sl+ 0:00 ./test-thread
# mkdir -p /sys/fs/cgroup/x/a/b
# echo threaded > /sys/fs/cgroup/x/a/cgroup.type
# echo threaded > /sys/fs/cgroup/x/a/b/cgroup.type
# echo 2030 > /sys/fs/cgroup/x/a/cgroup.procs
# cat /sys/fs/cgroup/x/a/cgroup.threads
2030
2031
# cat /sys/fs/cgroup/x/cgroup.procs
2030
# echo 2030 > /sys/fs/cgroup/x/a/b/cgroup.threads
# cat /sys/fs/cgroup/x/cgroup.procs
2031
2030
The last read of cgroup.procs is incorrectly showing non-leader 2031
in cgroup.procs output.
This can be fixed by updating css_task_iter_advance() to handle the
first advance and css_task_iters_tart() to call
css_task_iter_advance() instead of the inner helper. After the fix,
the same commands result in the following (correct) result:
# ps -L 2062
PID LWP TTY STAT TIME COMMAND
2062 2062 pts/0 Sl+ 0:00 ./test-thread
2062 2063 pts/0 Sl+ 0:00 ./test-thread
# mkdir -p /sys/fs/cgroup/x/a/b
# echo threaded > /sys/fs/cgroup/x/a/cgroup.type
# echo threaded > /sys/fs/cgroup/x/a/b/cgroup.type
# echo 2062 > /sys/fs/cgroup/x/a/cgroup.procs
# cat /sys/fs/cgroup/x/a/cgroup.threads
2062
2063
# cat /sys/fs/cgroup/x/cgroup.procs
2062
# echo 2062 > /sys/fs/cgroup/x/a/b/cgroup.threads
# cat /sys/fs/cgroup/x/cgroup.procs
2062
Signed-off-by: Tejun Heo <tj@kernel.org>
Reported-by: "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com>
Fixes: 8cfd8147df67 ("cgroup: implement cgroup v2 thread support")
Cc: stable@vger.kernel.org # v4.14+
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
kernel/cgroup/cgroup.c | 33 +++++++++++++++++++--------------
1 file changed, 19 insertions(+), 14 deletions(-)
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -4080,20 +4080,25 @@ static void css_task_iter_advance(struct
lockdep_assert_held(&css_set_lock);
repeat:
- /*
- * Advance iterator to find next entry. cset->tasks is consumed
- * first and then ->mg_tasks. After ->mg_tasks, we move onto the
- * next cset.
- */
- next = it->task_pos->next;
-
- if (next == it->tasks_head)
- next = it->mg_tasks_head->next;
-
- if (next == it->mg_tasks_head)
+ if (it->task_pos) {
+ /*
+ * Advance iterator to find next entry. cset->tasks is
+ * consumed first and then ->mg_tasks. After ->mg_tasks,
+ * we move onto the next cset.
+ */
+ next = it->task_pos->next;
+
+ if (next == it->tasks_head)
+ next = it->mg_tasks_head->next;
+
+ if (next == it->mg_tasks_head)
+ css_task_iter_advance_css_set(it);
+ else
+ it->task_pos = next;
+ } else {
+ /* called from start, proceed to the first cset */
css_task_iter_advance_css_set(it);
- else
- it->task_pos = next;
+ }
/* if PROCS, skip over tasks which aren't group leaders */
if ((it->flags & CSS_TASK_ITER_PROCS) && it->task_pos &&
@@ -4133,7 +4138,7 @@ void css_task_iter_start(struct cgroup_s
it->cset_head = it->cset_pos;
- css_task_iter_advance_css_set(it);
+ css_task_iter_advance(it);
spin_unlock_irq(&css_set_lock);
}
next prev parent reply other threads:[~2019-01-07 13:13 UTC|newest]
Thread overview: 130+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-07 12:31 [PATCH 4.14 000/101] 4.14.92-stable review Greg Kroah-Hartman
2019-01-07 12:31 ` [PATCH 4.14 001/101] phonet: af_phonet: Fix Spectre v1 vulnerability Greg Kroah-Hartman
2019-01-07 21:11 ` Sudip Mukherjee
2019-01-08 0:36 ` David Miller
2019-01-08 7:44 ` Greg KH
2019-01-07 12:31 ` [PATCH 4.14 002/101] net: core: " Greg Kroah-Hartman
2019-01-07 21:13 ` Sudip Mukherjee
2019-01-08 0:36 ` David Miller
2019-01-08 7:44 ` Greg KH
2019-01-07 12:31 ` [PATCH 4.14 003/101] ipv4: Fix potential " Greg Kroah-Hartman
2019-01-07 12:31 ` [PATCH 4.14 004/101] ip6mr: " Greg Kroah-Hartman
2019-01-07 12:31 ` [PATCH 4.14 005/101] ax25: fix a use-after-free in ax25_fillin_cb() Greg Kroah-Hartman
2019-01-07 12:31 ` [PATCH 4.14 006/101] gro_cell: add napi_disable in gro_cells_destroy Greg Kroah-Hartman
2019-01-07 12:31 ` [PATCH 4.14 007/101] ibmveth: fix DMA unmap error in ibmveth_xmit_start error path Greg Kroah-Hartman
2019-01-07 12:31 ` [PATCH 4.14 008/101] ieee802154: lowpan_header_create check must check daddr Greg Kroah-Hartman
2019-01-07 12:31 ` [PATCH 4.14 009/101] ipv6: explicitly initialize udp6_addr in udp_sock_create6() Greg Kroah-Hartman
2019-01-07 12:31 ` [PATCH 4.14 010/101] ipv6: tunnels: fix two use-after-free Greg Kroah-Hartman
2019-01-07 12:31 ` [PATCH 4.14 011/101] isdn: fix kernel-infoleak in capi_unlocked_ioctl Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 012/101] net: ipv4: do not handle duplicate fragments as overlapping Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 013/101] net: macb: restart tx after tx used bit read Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 014/101] net: phy: Fix the issue that netif always links up after resuming Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 015/101] netrom: fix locking in nr_find_socket() Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 016/101] net/wan: fix a double free in x25_asy_open_tty() Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 017/101] packet: validate address length Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 018/101] packet: validate address length if non-zero Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 019/101] ptr_ring: wrap back ->producer in __ptr_ring_swap_queue() Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 020/101] qmi_wwan: Added support for Telit LN940 series Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 021/101] sctp: initialize sin6_flowinfo for ipv6 addrs in sctp_inet6addr_event Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 022/101] tcp: fix a race in inet_diag_dump_icsk() Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 023/101] tipc: fix a double kfree_skb() Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 024/101] vhost: make sure used idx is seen before log in vhost_add_used_n() Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 025/101] VSOCK: Send reset control packet when socket is partially bound Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 026/101] xen/netfront: tolerate frags with no data Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 027/101] net/mlx5: Typo fix in del_sw_hw_rule Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 028/101] net/mlx5e: RX, Fix wrong early return in receive queue poll Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 029/101] mlxsw: core: Increase timeout during firmware flash process Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 030/101] net/mlx5e: Remove the false indication of software timestamping support Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 031/101] tipc: use lock_sock() in tipc_sk_reinit() Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 032/101] tipc: compare remote and local protocols in tipc_udp_enable() Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 033/101] qmi_wwan: Added support for Fibocom NL668 series Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 034/101] qmi_wwan: Add support for Fibocom NL678 series Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 035/101] net/smc: fix TCP fallback socket release Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 036/101] sock: Make sock->sk_stamp thread-safe Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 037/101] IB/hfi1: Incorrect sizing of sge for PIO will OOPs Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 038/101] ALSA: rme9652: Fix potential Spectre v1 vulnerability Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 039/101] ALSA: emu10k1: Fix potential Spectre v1 vulnerabilities Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 040/101] ALSA: pcm: Fix potential Spectre v1 vulnerability Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 041/101] ALSA: emux: Fix potential Spectre v1 vulnerabilities Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 042/101] mtd: atmel-quadspi: disallow building on ebsa110 Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 043/101] ALSA: hda: add mute LED support for HP EliteBook 840 G4 Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 044/101] ALSA: fireface: fix for state to fetch PCM frames Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 045/101] ALSA: firewire-lib: fix wrong handling payload_length as payload_quadlet Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 046/101] ALSA: firewire-lib: fix wrong assignment for out_packet_without_header tracepoint Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 047/101] ALSA: firewire-lib: use the same print format for without_header tracepoints Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 048/101] ALSA: hda/tegra: clear pending irq handlers Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 049/101] USB: serial: pl2303: add ids for Hewlett-Packard HP POS pole displays Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 050/101] USB: serial: option: add Fibocom NL678 series Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 051/101] usb: r8a66597: Fix a possible concurrency use-after-free bug in r8a66597_endpoint_disable() Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 052/101] staging: wilc1000: fix missing read_write setting when reading data Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 053/101] qmi_wwan: apply SET_DTR quirk to the SIMCOM shared device ID Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 054/101] s390/pci: fix sleeping in atomic during hotplug Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 055/101] Input: elan_i2c - add ACPI ID for touchpad in ASUS Aspire F5-573G Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 056/101] x86/speculation/l1tf: Drop the swap storage limit restriction when l1tf=off Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 057/101] x86/mm: Drop usage of __flush_tlb_all() in kernel_physical_mapping_init() Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 058/101] KVM: x86: Use jmp to invoke kvm_spurious_fault() from .fixup Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 059/101] KVM: nVMX: Free the VMREAD/VMWRITE bitmaps if alloc_kvm_area() fails Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 060/101] platform-msi: Free descriptors in platform_msi_domain_free() Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 061/101] perf pmu: Suppress potential format-truncation warning Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 062/101] ext4: add ext4_sb_bread() to disambiguate ENOMEM cases Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 063/101] ext4: fix possible use after free in ext4_quota_enable Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 064/101] ext4: missing unlock/put_page() in ext4_try_to_write_inline_data() Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 065/101] ext4: fix EXT4_IOC_GROUP_ADD ioctl Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 066/101] ext4: include terminating u32 in size of xattr entries when expanding inodes Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 067/101] ext4: force inode writes when nfsd calls commit_metadata() Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 068/101] ext4: check for shutdown and r/o file system in ext4_write_inode() Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 069/101] spi: bcm2835: Fix race on DMA termination Greg Kroah-Hartman
2019-01-07 21:15 ` Sudip Mukherjee
2019-01-08 7:37 ` Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 070/101] spi: bcm2835: Fix book-keeping of " Greg Kroah-Hartman
2019-01-07 12:32 ` [PATCH 4.14 071/101] spi: bcm2835: Avoid finishing transfer prematurely in IRQ mode Greg Kroah-Hartman
2019-01-07 12:33 ` [PATCH 4.14 072/101] clk: rockchip: fix typo in rk3188 spdif_frac parent Greg Kroah-Hartman
2019-01-07 12:33 ` [PATCH 4.14 073/101] crypto: cavium/nitrox - fix a DMA pool free failure Greg Kroah-Hartman
2019-01-07 12:33 ` [PATCH 4.14 074/101] crypto: testmgr - add AES-CFB tests Greg Kroah-Hartman
2019-01-07 12:33 ` Greg Kroah-Hartman [this message]
2019-01-07 12:33 ` [PATCH 4.14 076/101] cdc-acm: fix abnormal DATA RX issue for Mediatek Preloader Greg Kroah-Hartman
2019-01-07 12:33 ` [PATCH 4.14 077/101] Btrfs: fix fsync of files with multiple hard links in new directories Greg Kroah-Hartman
2019-01-07 12:33 ` [PATCH 4.14 078/101] btrfs: run delayed items before dropping the snapshot Greg Kroah-Hartman
2019-01-07 12:33 ` [PATCH 4.14 079/101] powerpc/tm: Set MSR[TS] just prior to recheckpoint Greg Kroah-Hartman
2019-01-07 12:33 ` [PATCH 4.14 080/101] netfilter: xt_connlimit: dont store address in the conn nodes Greg Kroah-Hartman
2019-01-07 12:33 ` [PATCH 4.14 081/101] netfilter: nf_conncount: expose connection list interface Greg Kroah-Hartman
2019-01-07 12:33 ` [PATCH 4.14 082/101] netfilter: nf_conncount: Fix garbage collection with zones Greg Kroah-Hartman
2019-01-07 12:33 ` [PATCH 4.14 083/101] netfilter: nf_conncount: fix garbage collection confirm race Greg Kroah-Hartman
2019-01-07 12:33 ` [PATCH 4.14 084/101] netfilter: nf_conncount: dont skip eviction when age is negative Greg Kroah-Hartman
2019-01-07 12:33 ` [PATCH 4.14 085/101] f2fs: fix validation of the block count in sanity_check_raw_super Greg Kroah-Hartman
2019-01-07 12:33 ` [PATCH 4.14 086/101] serial: uartps: Fix interrupt mask issue to handle the RX interrupts properly Greg Kroah-Hartman
2019-01-07 12:33 ` [PATCH 4.14 087/101] media: vivid: free bitmap_cap when updating std/timings/etc Greg Kroah-Hartman
2019-01-07 12:33 ` [PATCH 4.14 088/101] media: v4l2-tpg: array index could become negative Greg Kroah-Hartman
2019-01-07 12:33 ` [PATCH 4.14 089/101] MIPS: math-emu: Write-protect delay slot emulation pages Greg Kroah-Hartman
2019-01-07 12:33 ` [PATCH 4.14 090/101] MIPS: c-r4k: Add r4k_blast_scache_node for Loongson-3 Greg Kroah-Hartman
2019-01-07 21:17 ` Sudip Mukherjee
2019-01-08 7:38 ` Greg Kroah-Hartman
2019-01-08 9:54 ` Sudip Mukherjee
2019-01-08 12:03 ` Greg Kroah-Hartman
2019-01-07 12:33 ` [PATCH 4.14 091/101] MIPS: Ensure pmd_present() returns false after pmd_mknotpresent() Greg Kroah-Hartman
2019-01-07 12:33 ` [PATCH 4.14 092/101] MIPS: Align kernel load address to 64KB Greg Kroah-Hartman
2019-01-07 12:33 ` [PATCH 4.14 093/101] MIPS: Expand MIPS32 ASIDs to 64 bits Greg Kroah-Hartman
2019-01-07 12:33 ` [PATCH 4.14 094/101] MIPS: OCTEON: mark RGMII interface disabled on OCTEON III Greg Kroah-Hartman
2019-01-07 12:33 ` [PATCH 4.14 095/101] CIFS: Fix error mapping for SMB2_LOCK command which caused OFD lock problem Greg Kroah-Hartman
2019-01-07 12:33 ` [PATCH 4.14 096/101] arm64: KVM: Avoid setting the upper 32 bits of VTCR_EL2 to 1 Greg Kroah-Hartman
2019-01-07 12:33 ` [PATCH 4.14 097/101] arm/arm64: KVM: vgic: Force VM halt when changing the active state of GICv3 PPIs/SGIs Greg Kroah-Hartman
2019-01-07 12:33 ` [PATCH 4.14 098/101] rtc: m41t80: Correct alarm month range with RTC reads Greg Kroah-Hartman
2019-01-07 12:33 ` [PATCH 4.14 099/101] tpm: tpm_try_transmit() refactor error flow Greg Kroah-Hartman
2019-01-07 12:33 ` [PATCH 4.14 100/101] tpm: tpm_i2c_nuvoton: use correct command duration for TPM 2.x Greg Kroah-Hartman
2019-01-07 12:33 ` [PATCH 4.14 101/101] ARM: dts: exynos: Specify I2S assigned clocks in proper node Greg Kroah-Hartman
2019-01-07 14:39 ` [PATCH 4.14 000/101] 4.14.92-stable review Daniel Díaz
2019-01-07 14:47 ` Greg Kroah-Hartman
2019-01-07 14:51 ` Greg Kroah-Hartman
2019-01-07 14:52 ` Greg Kroah-Hartman
2019-01-08 9:20 ` Naresh Kamboju
2019-01-07 22:34 ` shuah
2019-01-07 22:38 ` shuah
2019-01-08 4:59 ` Guenter Roeck
2019-01-08 12:25 ` Greg Kroah-Hartman
2019-01-09 11:40 ` Jinpu Wang
2019-01-09 14:46 ` Greg Kroah-Hartman
2019-01-09 15:47 ` Guenter Roeck
2019-01-08 12:19 ` Greg Kroah-Hartman
2019-01-09 10:47 ` Jon Hunter
2019-01-09 14:40 ` Greg Kroah-Hartman
2019-01-08 23:05 ` Guenter Roeck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190107105337.073441015@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mtk.manpages@gmail.com \
--cc=stable@vger.kernel.org \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome