Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp3049780ioo; Tue, 24 May 2022 11:49:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyKzHDczIZd5NLzVxSVck3TD8BDV+RUG94bNUgN9O0NCLhXHgTnIjL7QEQwdg2MovL8VGEc X-Received: by 2002:a17:903:2cb:b0:14f:4fb6:2fb0 with SMTP id s11-20020a17090302cb00b0014f4fb62fb0mr28379444plk.172.1653418147565; Tue, 24 May 2022 11:49:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653418147; cv=none; d=google.com; s=arc-20160816; b=b/N/5au8O7V1RwJ9enkHu3ypHtrB4d+jTVfP9xC8C9Co2Gf4cQ5DOjjI4TBaXPYUCv zzYPhMI+W2ZIwVCuJo3MCUsMrxIeV3CP9+z+F9QWxmEq7vAyCmP/mc7H8hDsi5E3NdFy 5rkZiRieyFzzasQd+js4glWiMxYZENgpKLQdaCv22QnQbVDeaNPdleyr7lNstbeGaZTb 7IYonalCpFl38ehbXJRwU7Hdle98iL4Ff2ORloP0ZzIzKXVQxJyRRsye7qenFOxJVwRe oKAmjM9CMV1D92m8bivT+3OMPzo6OZYVprXeKWHJpv8ULNyF3/V6mlZEcDjZs7HFw2Ow ZEGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=ofqhF7B0Lhr9XDJpCI5NspBe7jXyy3A5iExBePEO86M=; b=PtKBN4cMc6g/fxYXamoeSV7ZEiiYsHjSWonCHv+5X+3cEH65VeXnwjjyvJbld21nuZ fgwOqeL0sz3QxLF692NntxEXC0JRCEsW6cEHdsjk2W9kUE3Hj9xcM4OvNsFD4lPVtgKG d8Dl6/7V6yfc3ri+5zSr1kFyhzXd875D7BZ14v9yV9tri4ZYlQyNOmEUKLYixZoizWeM 9EFXNxpfVFrgWAa77Tj6SslFdBOzKQWDLTrlIR4d1UvSlFsPcMEgj3GBVXzutHs/OIzD sv5uO9fXWr/Wzq6CnLTh3r/pDBmjSFHvPYCz0Pgj41cI7/xPo9nptxIkZf7fCWT98epn LAaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hWN9iqCP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l11-20020a65680b000000b003ab1b4e88f1si14722730pgt.87.2022.05.24.11.48.54; Tue, 24 May 2022 11:49:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hWN9iqCP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238692AbiEXPMG (ORCPT + 99 others); Tue, 24 May 2022 11:12:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238872AbiEXPMD (ORCPT ); Tue, 24 May 2022 11:12:03 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0B98F3D4BB for ; Tue, 24 May 2022 08:12:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653405121; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ofqhF7B0Lhr9XDJpCI5NspBe7jXyy3A5iExBePEO86M=; b=hWN9iqCPVXBmCJ0YMMvLsB3VW+sjxTObcrcS642M4fkbZxk1Mhm7HkRuD13H5SUnLZ77EO qcIp5IRj0ktw9Jv7FvbtyjKClEt4JRcA4twu6KjY6aQ+UEpSnshUVAntCmJUzvsaB+K0Gm iTYop9+vHW+dz9Hh5BpIDEKeM6TEwww= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-368-ORQeLfTsMK6bE3vVpY43bw-1; Tue, 24 May 2022 11:11:54 -0400 X-MC-Unique: ORQeLfTsMK6bE3vVpY43bw-1 Received: by mail-wr1-f69.google.com with SMTP id e17-20020adfe391000000b0020e64e7dd15so4399432wrm.4 for ; Tue, 24 May 2022 08:11:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=ofqhF7B0Lhr9XDJpCI5NspBe7jXyy3A5iExBePEO86M=; b=RTMX77vBkxYYgKlsGyM8qeVkCpGdkHtFkjlMoTfePhPaZmFxlNUhxeL9p9zb81lGl+ tIvKkvWEwftZeYqunHJ8AMe2A0EdzcBx8fDAJSIUjEaJG+H40pTeb6XxMowbKTp+8DUB X4XAAWQNCF1b5jHmOvyNRnMnyy4RRexM8A3hh2BC2OkWg3okqPCaBaWAV1ehJYjtsHyy eOqsz0bEOYHyW78ZsnYdEowDgbxAz9++CgqAfG3XCkm0vOVZ2McCbX5yDNxaQtVXhsNg 8XBYV6Q5QSLrfig3XxzoiNKMrxzjJRQgw0O/vzEXndBv/YwMrbh1A8peLuecp4HG7FcO 59eQ== X-Gm-Message-State: AOAM530ShI+wZ9rka/df3f6ltZRbNR26aZ1q+Mo4k2yGQ22Z0OMthMM1 tlJnSqz59EIyig6EF9ZLvSqtamQMcA2ZM+i+tcnHkv+wnA82nzzRHjdqL+SVLNzG/YySz0E1X00 Bdwlp6REB0Rn7rhXb/5Vwg2x+ X-Received: by 2002:a05:600c:354a:b0:394:8fa4:73bc with SMTP id i10-20020a05600c354a00b003948fa473bcmr4204448wmq.37.1653405112862; Tue, 24 May 2022 08:11:52 -0700 (PDT) X-Received: by 2002:a05:600c:354a:b0:394:8fa4:73bc with SMTP id i10-20020a05600c354a00b003948fa473bcmr4204425wmq.37.1653405112626; Tue, 24 May 2022 08:11:52 -0700 (PDT) Received: from vschneid.remote.csb ([185.11.37.247]) by smtp.gmail.com with ESMTPSA id m6-20020adfa3c6000000b0020fc4cd81f6sm10619841wrb.60.2022.05.24.08.11.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 May 2022 08:11:52 -0700 (PDT) From: Valentin Schneider To: Phil Auld , linux-kernel@vger.kernel.org Cc: Thomas Gleixner , Peter Zijlstra Subject: Re: [PATCH] cpuhp: make target_store() a nop when target == state In-Reply-To: <20220523144728.32414-1-pauld@redhat.com> References: <20220523144728.32414-1-pauld@redhat.com> Date: Tue, 24 May 2022 16:11:51 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 23/05/22 10:47, Phil Auld wrote: > writing the current state back into hotplug/target calls cpu_down() > which will set cpu dying even when it isn't and then nothing will > ever clear it. A stress test that reads values and writes them back > for all cpu device files in sysfs will trigger the BUG() in > select_fallback_rq once all cpus are marked as dying. > > kernel/cpu.c::target_store() > ... > if (st->state < target) > ret = cpu_up(dev->id, target); > else > ret = cpu_down(dev->id, target); > > cpu_down() -> cpu_set_state() > bool bringup = st->state < target; > ... > if (cpu_dying(cpu) != !bringup) > set_cpu_dying(cpu, !bringup); > > Make this safe by catching the case where target == state > and bailing early. > > Signed-off-by: Phil Auld > --- > > Yeah, I know... don't do that. But it's still messy. > > !< != > > > kernel/cpu.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/kernel/cpu.c b/kernel/cpu.c > index d0a9aa0b42e8..8a71b1149c60 100644 > --- a/kernel/cpu.c > +++ b/kernel/cpu.c > @@ -2302,6 +2302,9 @@ static ssize_t target_store(struct device *dev, struct device_attribute *attr, > return -EINVAL; > #endif > > + if (target == st->state) > + return count; > + The current checks are against static boundaries, this has to compare against st->state - AFAICT this could race with another hotplug operation to the same CPU, e.g. CPU42.cpuhp_state ->state == CPUHP_AP_SCHED_STARTING ->target == CPUHP_ONLINE CPU42.cpuhp_state == CPUHP_ONLINE _cpu_up() has: /* * The caller of cpu_up() might have raced with another * caller. Nothing to do. */ if (st->state >= target) goto out; Looks like we want an equivalent in _cpu_down(), what do you think? > ret = lock_device_hotplug_sysfs(); > if (ret) > return ret; > -- > 2.18.0