public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Zhang Qiao <zhangqiao22@huawei.com>
Cc: "Michal Koutný" <mkoutny@suse.com>,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	"Zhao Gongyi" <zhaogongyi@huawei.com>,
	"Waiman Long" <longman@redhat.com>, "Tejun Heo" <tj@kernel.org>,
	"Juri Lelli" <juri.lelli@redhat.com>
Subject: Re: [PATCH 4.19 01/34] cgroup/cpuset: Fix a race between cpuset_attach() and cpu hotplug
Date: Thu, 17 Mar 2022 11:24:31 +0100	[thread overview]
Message-ID: <YjMMX7jSU8ynwgON@kroah.com> (raw)
In-Reply-To: <1ea13066-aa98-ead2-f50f-f62d030ce3c5@huawei.com>

On Thu, Mar 17, 2022 at 10:41:57AM +0800, Zhang Qiao wrote:
> 
> 
> 在 2022/3/16 22:27, Greg Kroah-Hartman 写道:
> > On Mon, Mar 14, 2022 at 12:19:41PM +0100, Michal Koutný wrote:
> >> Hello.
> >>
> >> In my opinion there are two approaches:
> >> a) drop this backport (given other races present),
> > 
> > I have no problem with that, want to send a revert patch?
> > 
> >> b) swap the locks compatible with v4.19 as this patch proposes.
> >>
> >> On Mon, Mar 14, 2022 at 05:11:50PM +0800, Zhang Qiao <zhangqiao22@huawei.com> wrote:
> >>> +       /*
> >>> +        * It should hold cpus lock because a cpu offline event can
> >>> +        * cause set_cpus_allowed_ptr() failed.
> >>> +        */
> >>> +       cpus_read_lock();
> >>
> >> Maybe just a nit, the old kernels before commit c5c63b9a6a2e ("cgroup:
> >> Replace deprecated CPU-hotplug functions.") v5.15-rc1~159^2~5
> >> would be more consistent with get_online_cpus() here (but they're
> >> equivalent functionally so the locking order is correct).
> > 
> > A fixed up patch would also be appreciated :)
> > 
> 
> Fixed up patch as follows, replace cpus_read_lock() with get_online_cpus().
> 
> thanks.
> 
> --------
> 
> 
> [PATCH] cpuset: Fix unsafe lock order between cpuset lock and cpuslock
> 
> The backport commit 4eec5fe1c680a ("cgroup/cpuset: Fix a race
> between cpuset_attach() and cpu hotplug") looks suspicious since
> it comes before commit d74b27d63a8b ("cgroup/cpuset: Change
> cpuset_rwsem and hotplug lock order") v5.4-rc1~176^2~30 when
> the locking order was: cpuset lock, cpus lock.
> 
> Fix it with the correct locking order and reduce the cpus locking
> range because only set_cpus_allowed_ptr() needs the protection of
> cpus lock.
> 
> Fixes: 4eec5fe1c680a ("cgroup/cpuset: Fix a race between cpuset_attach() and cpu hotplug")
> Reported-by: Michal Koutný <mkoutny@suse.com>
> Signed-off-by: Zhang Qiao <zhangqiao22@huawei.com>
> ---
>  kernel/cgroup/cpuset.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index d43d25acc..4e1c4232e 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -1528,9 +1528,13 @@ static void cpuset_attach(struct cgroup_taskset *tset)
>         cgroup_taskset_first(tset, &css);
>         cs = css_cs(css);
> 
> -       cpus_read_lock();
>         mutex_lock(&cpuset_mutex);
> 
> +       /*
> +        * It should hold cpus lock because a cpu offline event can
> +        * cause set_cpus_allowed_ptr() failed.
> +        */
> +       get_online_cpus();
>         /* prepare for attach */
>         if (cs == &top_cpuset)
>                 cpumask_copy(cpus_attach, cpu_possible_mask);
> @@ -1549,6 +1553,7 @@ static void cpuset_attach(struct cgroup_taskset *tset)
>                 cpuset_change_task_nodemask(task, &cpuset_attach_nodemask_to);
>                 cpuset_update_task_spread_flag(cs, task);
>         }
> +       put_online_cpus();
> 
>         /*
>          * Change mm for all threadgroup leaders. This is expensive and may
> @@ -1584,7 +1589,6 @@ static void cpuset_attach(struct cgroup_taskset *tset)
>                 wake_up(&cpuset_attach_wq);
> 
>         mutex_unlock(&cpuset_mutex);
> -       cpus_read_unlock();
>  }
> 
>  /* The various types of files and directories in a cpuset file system */
> --
> 2.18.0
> 
> 

Argh, whitespace was corrupted :(

I've fixed this up by hand and queued it up...

greg k-h

  reply	other threads:[~2022-03-17 10:24 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-28 17:24 [PATCH 4.19 00/34] 4.19.232-rc1 review Greg Kroah-Hartman
2022-02-28 17:24 ` [PATCH 4.19 01/34] cgroup/cpuset: Fix a race between cpuset_attach() and cpu hotplug Greg Kroah-Hartman
2022-03-08 15:12   ` Michal Koutný
2022-03-14  8:06     ` Greg Kroah-Hartman
2022-03-14  9:11       ` Zhang Qiao
2022-03-14 11:19         ` Michal Koutný
2022-03-16 14:27           ` Greg Kroah-Hartman
2022-03-17  2:41             ` Zhang Qiao
2022-03-17 10:24               ` Greg Kroah-Hartman [this message]
2022-02-28 17:24 ` [PATCH 4.19 02/34] vhost/vsock: dont check owner in vhost_vsock_stop() while releasing Greg Kroah-Hartman
2022-02-28 17:24 ` [PATCH 4.19 03/34] parisc/unaligned: Fix fldd and fstd unaligned handlers on 32-bit kernel Greg Kroah-Hartman
2022-02-28 17:24 ` [PATCH 4.19 04/34] parisc/unaligned: Fix ldw() and stw() unalignment handlers Greg Kroah-Hartman
2022-02-28 17:24 ` [PATCH 4.19 05/34] sr9700: sanity check for packet length Greg Kroah-Hartman
2022-02-28 17:24 ` [PATCH 4.19 06/34] USB: zaurus: support another broken Zaurus Greg Kroah-Hartman
2022-02-28 17:24 ` [PATCH 4.19 07/34] ping: remove pr_err from ping_lookup Greg Kroah-Hartman
2022-02-28 17:24 ` [PATCH 4.19 08/34] net: __pskb_pull_tail() & pskb_carve_frag_list() drop_monitor friends Greg Kroah-Hartman
2022-02-28 17:24 ` [PATCH 4.19 09/34] tipc: Fix end of loop tests for list_for_each_entry() Greg Kroah-Hartman
2022-02-28 17:24 ` [PATCH 4.19 10/34] gso: do not skip outer ip header in case of ipip and net_failover Greg Kroah-Hartman
2022-02-28 17:24 ` [PATCH 4.19 11/34] openvswitch: Fix setting ipv6 fields causing hw csum failure Greg Kroah-Hartman
2022-02-28 17:24 ` [PATCH 4.19 12/34] drm/edid: Always set RGB444 Greg Kroah-Hartman
2022-02-28 17:24 ` [PATCH 4.19 13/34] net/mlx5e: Fix wrong return value on ioctl EEPROM query failure Greg Kroah-Hartman
2022-02-28 17:24 ` [PATCH 4.19 14/34] configfs: fix a race in configfs_{,un}register_subsystem() Greg Kroah-Hartman
2022-02-28 17:24 ` [PATCH 4.19 15/34] RDMA/ib_srp: Fix a deadlock Greg Kroah-Hartman
2022-02-28 17:24 ` [PATCH 4.19 16/34] tty: n_gsm: fix proper link termination after failed open Greg Kroah-Hartman
2022-02-28 17:24 ` [PATCH 4.19 17/34] gpio: tegra186: Fix chip_data type confusion Greg Kroah-Hartman
2022-02-28 17:24 ` [PATCH 4.19 18/34] Revert "drm/nouveau/pmu/gm200-: avoid touching PMU outside of DEVINIT/PREOS/ACR" Greg Kroah-Hartman
2022-02-28 17:24 ` [PATCH 4.19 19/34] memblock: use kfree() to release kmalloced memblock regions Greg Kroah-Hartman
2022-02-28 17:24 ` [PATCH 4.19 20/34] fget: clarify and improve __fget_files() implementation Greg Kroah-Hartman
2022-02-28 17:24 ` [PATCH 4.19 21/34] tracing: Have traceon and traceoff trigger honor the instance Greg Kroah-Hartman
2022-02-28 17:24 ` [PATCH 4.19 22/34] iio: adc: men_z188_adc: Fix a resource leak in an error handling path Greg Kroah-Hartman
2022-02-28 17:24 ` [PATCH 4.19 23/34] ata: pata_hpt37x: disable primary channel on HPT371 Greg Kroah-Hartman
2022-02-28 17:24 ` [PATCH 4.19 24/34] Revert "USB: serial: ch341: add new Product ID for CH341A" Greg Kroah-Hartman
2022-02-28 17:24 ` [PATCH 4.19 25/34] usb: gadget: rndis: add spinlock for rndis response list Greg Kroah-Hartman
2022-02-28 17:24 ` [PATCH 4.19 26/34] USB: gadget: validate endpoint index for xilinx udc Greg Kroah-Hartman
2022-02-28 17:24 ` [PATCH 4.19 27/34] tracefs: Set the group ownership in apply_options() not parse_options() Greg Kroah-Hartman
2022-02-28 17:24 ` [PATCH 4.19 28/34] USB: serial: option: add support for DW5829e Greg Kroah-Hartman
2022-02-28 17:24 ` [PATCH 4.19 29/34] USB: serial: option: add Telit LE910R1 compositions Greg Kroah-Hartman
2022-02-28 17:24 ` [PATCH 4.19 30/34] usb: dwc3: pci: Fix Bay Trail phy GPIO mappings Greg Kroah-Hartman
2022-02-28 17:24 ` [PATCH 4.19 31/34] usb: dwc3: gadget: Let the interrupt handler disable bottom halves Greg Kroah-Hartman
2022-02-28 17:24 ` [PATCH 4.19 32/34] xhci: re-initialize the HC during resume if HCE was set Greg Kroah-Hartman
2022-02-28 17:24 ` [PATCH 4.19 33/34] xhci: Prevent futile URB re-submissions due to incorrect return value Greg Kroah-Hartman
2022-02-28 17:24 ` [PATCH 4.19 34/34] tty: n_gsm: fix encoding of control signal octet bit DV Greg Kroah-Hartman
2022-02-28 21:21 ` [PATCH 4.19 00/34] 4.19.232-rc1 review Pavel Machek
2022-02-28 21:42 ` Shuah Khan
2022-03-01 11:32 ` Sudip Mukherjee
2022-03-01 16:37 ` Naresh Kamboju
2022-03-01 18:23 ` Jeffrin Thalakkottoor
2022-03-01 19:10 ` Guenter Roeck
2022-03-01 19:36 ` Slade Watkins

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=YjMMX7jSU8ynwgON@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mkoutny@suse.com \
    --cc=stable@vger.kernel.org \
    --cc=tj@kernel.org \
    --cc=zhangqiao22@huawei.com \
    --cc=zhaogongyi@huawei.com \
    /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