From patchwork Mon Oct 24 10:44:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Wagner X-Patchwork-Id: 8331 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp376407wru; Mon, 24 Oct 2022 03:58:21 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5rTyJYwc8HSS3xVfPMG4KYx7WJ637gVIXizzJ+uc5xrf2QbVMM/GonVQJ0NkqM4iPhva7N X-Received: by 2002:a05:6402:4150:b0:44a:ec16:def4 with SMTP id x16-20020a056402415000b0044aec16def4mr30611106eda.21.1666609100882; Mon, 24 Oct 2022 03:58:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666609100; cv=none; d=google.com; s=arc-20160816; b=vddaCCIG8PzIlDEoS1fbvOSEofrsA623atSOb76g7tBmORFjcj9JhJ6Ot9J3G20FYn 5mJAM+uc21OwdEIutWMsf3EDH9P6HJg+VZw8XNXZbwAzGQMu210+nW4zpqYrp2elDHNV VpJhDyn2mHempGZAQ9EXZSV6/nNXdkq0ZDgBixrTMmuSzCoMsHKsE6em0FSWOYe7mnKe cmDuAhASNOm6kt62dU+DaA2mxGgA3CjPl9/9U7aRuTJGAZhRUuNpEg3kKXRTI2G2AAEY LrM3PN+ZyO6GeJSIPfRezCki0fRAuGXWFInXz1x+ukqaVno13FeYNCyvyL0GvjX2znXI Xq6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=OO8ivmGitwcKDyAkmI+pQE3XfdhYBWotXa3wVqMIHE4=; b=xiUOg4afcfyv+0NoCp6sC+PgRhtoRuAm3W4l+P9fbNu/ey/tFjsoBJ2VVrIv2hbztz spnLuRaqIpEVFRGZ8norKEGi8+HnYkQHUpk1++l3OVmT4+AEQ+36kNgVI+91ikApKrKG 4HS1tcbg3zUhOxekKQZSVgOIqb7cs5glH0/q/p2GVkUrYh6JUNDMP1+xtwcegXGdq2ZH KlVUjcskWxlppdrpF1ZPCvv5hyR/I3OYW4z/O3y/479uCT3rxtBqn3CFdyvGy56iWkbA P2FhVPko62R8R5XEnal2HpR0H8Pm48yk76OsyJaBTaJxJ9TI18OBRPAPmmLAzY3kyOdB OSQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@monom.org header.s=dkim header.b=OVscYbQB; 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=REJECT sp=REJECT dis=NONE) header.from=monom.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dm21-20020a170907949500b00787803711f9si29003388ejc.353.2022.10.24.03.57.57; Mon, 24 Oct 2022 03:58:20 -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=@monom.org header.s=dkim header.b=OVscYbQB; 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=REJECT sp=REJECT dis=NONE) header.from=monom.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229746AbiJXKzi (ORCPT + 99 others); Mon, 24 Oct 2022 06:55:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229912AbiJXKy6 (ORCPT ); Mon, 24 Oct 2022 06:54:58 -0400 Received: from mail.nearlyone.de (mail.nearlyone.de [46.163.114.145]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C8B613F34; Mon, 24 Oct 2022 03:54:38 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id D116061D78; Mon, 24 Oct 2022 12:44:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monom.org; s=dkim; t=1666608269; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=OO8ivmGitwcKDyAkmI+pQE3XfdhYBWotXa3wVqMIHE4=; b=OVscYbQBs3+pgCis9WTsKntYC4FUwkJhmodaQtdp/Ujq7AL2cze7YucRBBlPBRyWtk39FW skrs6X8tG7lzd6HPwuRtF/V0O5BCnvhjxWgYyjxaFz+TmiysVlBpxA+bqG7qGsR0m4jjJT 5CYIS8ae1T1it1DBGHa2736TDV94gwjMjETQqpabaH8MtlliOGOtJxkiW6dGqbvFtGeqHI L7qpzbzQ1qgw5ME9vi7reGiE4u/Q76PdL6TbVJFDdLg/Xr0IfG2MhfsfLdk4VSdYVoTBgr CgJ8bpBvW8TsRRj3asXaJpZflnO7hByW+Axx8VnTGUwNlTUMhAHtgcgfL/tNPg== From: Daniel Wagner To: LKML , linux-rt-users , Steven Rostedt , Thomas Gleixner , Carsten Emde , John Kacur , Sebastian Andrzej Siewior , Tom Zanussi , Clark Williams , Pavel Machek Cc: Daniel Wagner Subject: [PATCH RT 1/9] Revert "random: Use local locks for crng context access" Date: Mon, 24 Oct 2022 12:44:17 +0200 Message-Id: <20221024104425.16423-2-wagi@monom.org> In-Reply-To: <20221024104425.16423-1-wagi@monom.org> References: <20221024104425.16423-1-wagi@monom.org> MIME-Version: 1.0 X-Last-TLS-Session-Version: TLSv1.3 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747566304565031916?= X-GMAIL-MSGID: =?utf-8?q?1747566304565031916?= v4.19.255-rt114-rc1 stable review patch. If anyone has any objections, please let me know. ----------- This reverts commit af5469c6f4f85f60f3ecc9bd541adfb6bdbeaff2. --- drivers/char/random.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/char/random.c b/drivers/char/random.c index c06705a32246..2be38780a7f7 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -53,7 +53,6 @@ #include #include #include -#include #include #include #include @@ -235,7 +234,6 @@ struct crng { static DEFINE_PER_CPU(struct crng, crngs) = { .generation = ULONG_MAX }; -DEFINE_LOCAL_IRQ_LOCK(crngs_lock); /* Used by crng_reseed() and crng_make_state() to extract a new seed from the input pool. */ static void extract_entropy(void *buf, size_t len); @@ -364,7 +362,7 @@ static void crng_make_state(u32 chacha_state[CHACHA20_BLOCK_SIZE / sizeof(u32)], if (unlikely(crng_has_old_seed())) crng_reseed(); - local_lock_irqsave(crngs_lock, flags); + local_irq_save(flags); crng = raw_cpu_ptr(&crngs); /* @@ -389,7 +387,7 @@ static void crng_make_state(u32 chacha_state[CHACHA20_BLOCK_SIZE / sizeof(u32)], * should wind up here immediately. */ crng_fast_key_erasure(crng->key, chacha_state, random_data, random_data_len); - local_unlock_irqrestore(crngs_lock, flags); + local_irq_restore(flags); } static void _get_random_bytes(void *buf, size_t len) @@ -514,7 +512,6 @@ struct batch_ ##type { \ static DEFINE_PER_CPU(struct batch_ ##type, batched_entropy_ ##type) = { \ .position = UINT_MAX \ }; \ -static DEFINE_LOCAL_IRQ_LOCK(batched_entropy_lock_ ##type); \ \ type get_random_ ##type(void) \ { \ @@ -530,7 +527,7 @@ type get_random_ ##type(void) \ return ret; \ } \ \ - local_lock_irqsave(batched_entropy_lock_ ##type, flags); \ + local_irq_save(flags); \ batch = raw_cpu_ptr(&batched_entropy_##type); \ \ next_gen = READ_ONCE(base_crng.generation); \ @@ -544,7 +541,7 @@ type get_random_ ##type(void) \ ret = batch->entropy[batch->position]; \ batch->entropy[batch->position] = 0; \ ++batch->position; \ - local_unlock_irqrestore(batched_entropy_lock_ ##type, flags); \ + local_irq_restore(flags); \ return ret; \ } \ EXPORT_SYMBOL(get_random_ ##type); From patchwork Mon Oct 24 10:44:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Wagner X-Patchwork-Id: 8333 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp376730wru; Mon, 24 Oct 2022 03:59:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7eLX0RqedbzKxtUhoyP+mZe8XbMpZTYJjjAlBNVmauGkA7UBzkStv6OPjBNuC9ffaWUgSq X-Received: by 2002:a17:906:5d0d:b0:78d:ecd6:64c1 with SMTP id g13-20020a1709065d0d00b0078decd664c1mr26228326ejt.571.1666609169776; Mon, 24 Oct 2022 03:59:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666609169; cv=none; d=google.com; s=arc-20160816; b=imeUY3EP1sd3QjRRfEpT6rVmPeGkk/fUvgjrGjJTdpCrGbHYbm3YfmWATazaVmSiot A2z3NqLKi3dmoVHRD/sTDGfX00e1A0GxcXP4rIRAs9zpd36WOqhtVZ4YT7k057hnviDg +Bdzw0GB6YJlbvCw/URVDQyI/WRjA/PDncbVosjJfpZlX2efDdr8/lYnG7QowtOW/9Zk be86LJL3wbLCn6BHSbgZs9EdTVUkOCSB2iv3eQPDbleNXBdejUbYNEVhtp+avhDhU70Y S09waDOgIKSlfyZ3YK14Hczy01n2OVG11+J0TkWOq17IgCPeOpl+b3Ps/6POPbWheR2o XM3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3wa0f+zrOtFlna7a224EJfMKkCUy+rnhosyUNwJXajU=; b=YsC6fqMDOCS2+MTflqoDMyr4T4niUwb6OCxQjIweyEu0Um4InYdiuxGvOSuAjVu/CN PJ8D/XSSC9YzaLgTEyDTuCFYTPJckpm+jHiEDqzBKZ1QoncOpFRGogg5QGlDtELhVRMP T2tGy+Q9iht6IBMZG6pGB3WuXTha9a3bjxtnHPY4K8A6wtcZs2jDWvVSU/z/JhEZBUhi EG7XayowLVYOWDvoHrXkeXPR3zgDzIQXQMJHH58pFSd/Uv+IVATdOyvAV2iDBSUj+VoY Yf9Xl2NvVWzvqu8NJuJDDgEzr2hJpWX2ui3thsz8rkjFcGg/1rW7NaCLza4y0tGX9EtQ LJBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@monom.org header.s=dkim header.b=t6jrHgif; 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=REJECT sp=REJECT dis=NONE) header.from=monom.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f20-20020a056402161400b00461af57d736si3216614edv.278.2022.10.24.03.59.06; Mon, 24 Oct 2022 03:59:29 -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=@monom.org header.s=dkim header.b=t6jrHgif; 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=REJECT sp=REJECT dis=NONE) header.from=monom.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229721AbiJXKzr (ORCPT + 99 others); Mon, 24 Oct 2022 06:55:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229671AbiJXKzF (ORCPT ); Mon, 24 Oct 2022 06:55:05 -0400 Received: from mail.nearlyone.de (mail.nearlyone.de [46.163.114.145]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9A6C1B79B; Mon, 24 Oct 2022 03:54:41 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 7F6E061D77; Mon, 24 Oct 2022 12:44:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monom.org; s=dkim; t=1666608269; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=3wa0f+zrOtFlna7a224EJfMKkCUy+rnhosyUNwJXajU=; b=t6jrHgifm7euHqYxcpmUyTMRqj8Wj+Y7OApKKa7oEPARDPsxnQos35MzpkLtHAUiUuPWOf ggwoRrnup5iR1V8pw4reDw7zFAM7qhucPYJLW97ByT8TeqfDuvPhO5kP8pzKHbnmpveiZa 0AmqKeh1K/Wm7DwA0d4PPF9LbjNBmlKiVYXCgDFm8hvYPnOaKq/htN1Nj9fzgnE7F+61ZH 5UObSt24gzejAgZgrcUMiq7Bpj+Tl0y0L/Nwtkg47AbuZuHMfn5XHDqfUmMPmU7ihaq8ZU OvXC1RgQbfyB7Wh9DLoSiKRTywBapiSZ/fmo2M3DM1KEOFo/JN8D4VglxL9Vfg== From: Daniel Wagner To: LKML , linux-rt-users , Steven Rostedt , Thomas Gleixner , Carsten Emde , John Kacur , Sebastian Andrzej Siewior , Tom Zanussi , Clark Williams , Pavel Machek Cc: Daniel Wagner Subject: [PATCH RT 2/9] random: Bring back the local_locks Date: Mon, 24 Oct 2022 12:44:18 +0200 Message-Id: <20221024104425.16423-3-wagi@monom.org> In-Reply-To: <20221024104425.16423-1-wagi@monom.org> References: <20221024104425.16423-1-wagi@monom.org> MIME-Version: 1.0 X-Last-TLS-Session-Version: TLSv1.3 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747566376615227820?= X-GMAIL-MSGID: =?utf-8?q?1747566376615227820?= From: Sebastian Andrzej Siewior v4.19.255-rt114-rc1 stable review patch. If anyone has any objections, please let me know. ----------- As part of the backports the random code lost its local_lock_t type and the whole operation became a local_irq_{disable|enable}() simply because the older kernel did not provide those primitives. RT as of v4.9 has a slightly different variant of local_locks. Replace the local_irq_*() operations with matching local_lock_irq*() operations which were there as part of commit 77760fd7f7ae3 ("random: remove batched entropy locking") Signed-off-by: Sebastian Andrzej Siewior Link: https://lore.kernel.org/all/20220819092446.980320-2-bigeasy@linutronix.de/ Signed-off-by: Daniel Wagner --- drivers/char/random.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/char/random.c b/drivers/char/random.c index 2be38780a7f7..0fd0462054bd 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -53,6 +53,7 @@ #include #include #include +#include #include #include #include @@ -229,10 +230,12 @@ static struct { struct crng { u8 key[CHACHA20_KEY_SIZE]; unsigned long generation; + struct local_irq_lock lock; }; static DEFINE_PER_CPU(struct crng, crngs) = { - .generation = ULONG_MAX + .generation = ULONG_MAX, + .lock.lock = __SPIN_LOCK_UNLOCKED(crngs.lock.lock), }; /* Used by crng_reseed() and crng_make_state() to extract a new seed from the input pool. */ @@ -362,7 +365,7 @@ static void crng_make_state(u32 chacha_state[CHACHA20_BLOCK_SIZE / sizeof(u32)], if (unlikely(crng_has_old_seed())) crng_reseed(); - local_irq_save(flags); + local_lock_irqsave(crngs.lock, flags); crng = raw_cpu_ptr(&crngs); /* @@ -387,7 +390,7 @@ static void crng_make_state(u32 chacha_state[CHACHA20_BLOCK_SIZE / sizeof(u32)], * should wind up here immediately. */ crng_fast_key_erasure(crng->key, chacha_state, random_data, random_data_len); - local_irq_restore(flags); + local_unlock_irqrestore(crngs.lock, flags); } static void _get_random_bytes(void *buf, size_t len) @@ -505,11 +508,13 @@ struct batch_ ##type { \ * formula of (integer_blocks + 0.5) * CHACHA20_BLOCK_SIZE. \ */ \ type entropy[CHACHA20_BLOCK_SIZE * 3 / (2 * sizeof(type))]; \ + struct local_irq_lock lock; \ unsigned long generation; \ unsigned int position; \ }; \ \ static DEFINE_PER_CPU(struct batch_ ##type, batched_entropy_ ##type) = { \ + .lock.lock = __SPIN_LOCK_UNLOCKED(batched_entropy_ ##type.lock.lock), \ .position = UINT_MAX \ }; \ \ @@ -527,7 +532,7 @@ type get_random_ ##type(void) \ return ret; \ } \ \ - local_irq_save(flags); \ + local_lock_irqsave(batched_entropy_ ##type.lock, flags); \ batch = raw_cpu_ptr(&batched_entropy_##type); \ \ next_gen = READ_ONCE(base_crng.generation); \ @@ -541,7 +546,7 @@ type get_random_ ##type(void) \ ret = batch->entropy[batch->position]; \ batch->entropy[batch->position] = 0; \ ++batch->position; \ - local_irq_restore(flags); \ + local_unlock_irqrestore(batched_entropy_ ##type.lock, flags); \ return ret; \ } \ EXPORT_SYMBOL(get_random_ ##type); From patchwork Mon Oct 24 10:44:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Wagner X-Patchwork-Id: 8326 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp375901wru; Mon, 24 Oct 2022 03:56:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5mgO8lRZsfLTeYiLbUqW+y3hNF5/TKdhpWbPN1lhzY/pEWiY56ykjSSKDPYs3yiZ3fTBXi X-Received: by 2002:a17:907:7da6:b0:791:997e:58fc with SMTP id oz38-20020a1709077da600b00791997e58fcmr27805767ejc.385.1666609008519; Mon, 24 Oct 2022 03:56:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666609008; cv=none; d=google.com; s=arc-20160816; b=arc4DxlxEtA9rydD4bfoF0VVtC/VLMSmOgy3LlyLsZ/qwh199t0eHWYyp4QapClnju Pwjkk6MlIOgnNEb2H7Vujk8XV6hyRYcpWdsu9HgiRpaUXTiahaB2QjNG4A3+HuzT93JN 54WkFc580iGiOs5jVEYekBtSMzmtpadQeIBSTFX6SeZ477fnFaZSJg9qYdQTWSMFA52n RF/J2lr8Muw6WAw/96Ola/4o5n+bToCWKR0oEyuYNg1t1B/uoqiZs74xVC8dsNOOUhIt BjT8grinJdt7MWRMxK4ygre9pxpeuueVNs7H9JL1JqCvkJhB1YN7kYDvg4LjEUUhOS+1 B+uA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ScROC3sGA4GWsZP9jfPmNdGSmAv/ip4dlZ5Qh/Mh1f4=; b=roWZcR8Mc2iyj16QiqsZAsbT9w/SJSCMWK1S1eqRV3g3tHSf7rQFyTyxFp4vYGdrgY XABBrrOdidtH0llDIWhJDbk4iUYyfvlbSHCCWXWgQEzNiJRcf5/MJOCz4uqQwCRs7MVi HWVSqgIitchP6iqi6DsAwZpXXylOut0CX9P2WtkPaebrB4014iTK2Zqy8lQtyLrDjF+s hjriiOYz3OwvU3hZjn153iAxA/rvupPeC8aQNeOL9sCAEv8Z+nlrbR+wgpTZZcPn68Vz fn8vEueEtdYoE2vg1hV6eLtUlor4yzf2Plf7mpIorq/ClbXCnF8awusfHV2oGybz6cVi 3sdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@monom.org header.s=dkim header.b=yKdjvmL0; 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=REJECT sp=REJECT dis=NONE) header.from=monom.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bf26-20020a0564021a5a00b0045c83fb19d4si25327740edb.578.2022.10.24.03.56.24; Mon, 24 Oct 2022 03:56:48 -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=@monom.org header.s=dkim header.b=yKdjvmL0; 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=REJECT sp=REJECT dis=NONE) header.from=monom.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229786AbiJXKzK (ORCPT + 99 others); Mon, 24 Oct 2022 06:55:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229742AbiJXKyk (ORCPT ); Mon, 24 Oct 2022 06:54:40 -0400 Received: from mail.nearlyone.de (mail.nearlyone.de [46.163.114.145]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39516B7CD; Mon, 24 Oct 2022 03:54:31 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 82E1B61D7C; Mon, 24 Oct 2022 12:44:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monom.org; s=dkim; t=1666608270; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=ScROC3sGA4GWsZP9jfPmNdGSmAv/ip4dlZ5Qh/Mh1f4=; b=yKdjvmL0NaVsQKuw4uS6ES5CgxzRLTabK1AaP+a2OzH/14AW0ZofPSNn5zT0hgv4hbi51D Z//IK1Kc1oeoBrgkGvsMZ7rbfn6p1tvDY+qKEqbM9VgxEPSMLsHvNV4swoHLlQY6pmi60a bh54YY162QKwbNpbul750XTDSFu99iAlejmGfI/otbTzjcf8QVLJh92A618XNbdfTLtfnN NoA/CrtYXha+JjJ7e0hZKg+4PVkzyqFM5G7AfI65cj2FGM2RtVyi425jye2h7HK9BG+7Dc k25egpUEaorjGV69IL0vEOoVcf+j5FufnKi7J+0byextGew23S9LllviW5VPFQ== From: Daniel Wagner To: LKML , linux-rt-users , Steven Rostedt , Thomas Gleixner , Carsten Emde , John Kacur , Sebastian Andrzej Siewior , Tom Zanussi , Clark Williams , Pavel Machek Cc: Daniel Wagner Subject: [PATCH RT 3/9] local_lock: Provide INIT_LOCAL_LOCK(). Date: Mon, 24 Oct 2022 12:44:19 +0200 Message-Id: <20221024104425.16423-4-wagi@monom.org> In-Reply-To: <20221024104425.16423-1-wagi@monom.org> References: <20221024104425.16423-1-wagi@monom.org> MIME-Version: 1.0 X-Last-TLS-Session-Version: TLSv1.3 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747566207655881759?= X-GMAIL-MSGID: =?utf-8?q?1747566207655881759?= From: Sebastian Andrzej Siewior v4.19.255-rt114-rc1 stable review patch. If anyone has any objections, please let me know. ----------- The original code was using INIT_LOCAL_LOCK() and I tried to sneak around it and forgot that this code also needs to compile on !RT platforms. Provide INIT_LOCAL_LOCK() to initialize properly on RT and do nothing on !RT. Let random.c use which is the only user so far and oes not compile on !RT otherwise. Signed-off-by: Sebastian Andrzej Siewior Link: https://lore.kernel.org/all/YzcEIU17EIZ7ZIF5@linutronix.de/ Signed-off-by: Daniel Wagner --- drivers/char/random.c | 4 ++-- include/linux/locallock.h | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/char/random.c b/drivers/char/random.c index 0fd0462054bd..a7b345c47d1f 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -235,7 +235,7 @@ struct crng { static DEFINE_PER_CPU(struct crng, crngs) = { .generation = ULONG_MAX, - .lock.lock = __SPIN_LOCK_UNLOCKED(crngs.lock.lock), + .lock = INIT_LOCAL_LOCK(crngs.lock), }; /* Used by crng_reseed() and crng_make_state() to extract a new seed from the input pool. */ @@ -514,7 +514,7 @@ struct batch_ ##type { \ }; \ \ static DEFINE_PER_CPU(struct batch_ ##type, batched_entropy_ ##type) = { \ - .lock.lock = __SPIN_LOCK_UNLOCKED(batched_entropy_ ##type.lock.lock), \ + .lock = INIT_LOCAL_LOCK(batched_entropy_ ##type.lock), \ .position = UINT_MAX \ }; \ \ diff --git a/include/linux/locallock.h b/include/linux/locallock.h index 81c89d87723b..7964ee6b998c 100644 --- a/include/linux/locallock.h +++ b/include/linux/locallock.h @@ -23,6 +23,8 @@ struct local_irq_lock { unsigned long flags; }; +#define INIT_LOCAL_LOCK(lvar) { .lock = __SPIN_LOCK_UNLOCKED((lvar).lock.lock) } + #define DEFINE_LOCAL_IRQ_LOCK(lvar) \ DEFINE_PER_CPU(struct local_irq_lock, lvar) = { \ .lock = __SPIN_LOCK_UNLOCKED((lvar).lock) } @@ -241,6 +243,9 @@ static inline int __local_unlock_irqrestore(struct local_irq_lock *lv, #else /* PREEMPT_RT_BASE */ +struct local_irq_lock { }; +#define INIT_LOCAL_LOCK(lvar) { } + #define DEFINE_LOCAL_IRQ_LOCK(lvar) __typeof__(const int) lvar #define DECLARE_LOCAL_IRQ_LOCK(lvar) extern __typeof__(const int) lvar From patchwork Mon Oct 24 10:44:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Wagner X-Patchwork-Id: 8325 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp375884wru; Mon, 24 Oct 2022 03:56:46 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5qpnbONLC7ZqSnxP29kz1ag+dgO2JkP++rRhUz2PcH1UbxPFUxz+xyL1BvwQCNGdBsIWyV X-Received: by 2002:a17:906:6a27:b0:7a6:c537:ba4 with SMTP id qw39-20020a1709066a2700b007a6c5370ba4mr4687637ejc.517.1666609005819; Mon, 24 Oct 2022 03:56:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666609005; cv=none; d=google.com; s=arc-20160816; b=AbIHK36crZqPB0OVtqwWW0LWOzMP3gO5udqQUE5mgtB9BvgVA+Ocfgh0jhf7LJK74X QYE6HQLjyGiOvgBet/dHHUCLBcdMxYLuFR/0dKWTfKHreqnXj5oSY46QnGWZs1GUqjR0 D6ticfX5yMLwWKh9TVyOOcEFySR3jEEwTOQ8NkiWCRLcgTT33OnB4dT+18tUCyreCOOe yf5zOER1CKYENDq71BGX6y9/nJfJIVw4GH42eSBq+SMoI9zCRgNx+bF389WnI+1wC7I3 0Xe3p9y1REX+RkU8L2C5Mc/PkRFq24LnoVhxgzcAunmRRgFuL0NcHopk8jxmuenXinjf o/sA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=s6+zpCqS6FPxz8ZLKaj1J443b3jYNWuEs6pNuizXfBs=; b=Ms57uD+C0tVhDZ59Ltncu0zJ2xyYlxm1Qm1SPPEKZZyQZJhvBZKdCY7St1NxfPtJ7X JsGgsdbMiR5J2Az5145Yk6MlNRU1RpptQspQRgMvZ2ckl8FD0q0SREvr3UjhzwmIej7r A30bur5uDvAzbfG3qahcZZANzlKBICpU0z9N6FDM432AEEfu4ZIO2Vx0SiIf3HQ/I5g5 2s669E2N1Gdb+5VyCtopilwZNArCMjNTFohpzWUOqqBAiUlTeg7KHCvvEmhFXA/0R9k2 ve7KjtAmCn9w+IYsKc5ZMO7ZTgB98Vnt+fZR7ZHP5I3lw3DPG/aoSzRC10kFhDHEbsdC jmPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@monom.org header.s=dkim header.b=cLi1hzzF; 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=REJECT sp=REJECT dis=NONE) header.from=monom.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w13-20020a05640234cd00b00459f9c3d02bsi32755059edc.22.2022.10.24.03.56.21; Mon, 24 Oct 2022 03:56:45 -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=@monom.org header.s=dkim header.b=cLi1hzzF; 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=REJECT sp=REJECT dis=NONE) header.from=monom.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229949AbiJXKzD (ORCPT + 99 others); Mon, 24 Oct 2022 06:55:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229871AbiJXKyk (ORCPT ); Mon, 24 Oct 2022 06:54:40 -0400 Received: from mail.nearlyone.de (mail.nearlyone.de [46.163.114.145]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCB40CE0E; Mon, 24 Oct 2022 03:54:31 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id F0CAF61D7A; Mon, 24 Oct 2022 12:44:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monom.org; s=dkim; t=1666608272; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=s6+zpCqS6FPxz8ZLKaj1J443b3jYNWuEs6pNuizXfBs=; b=cLi1hzzFHj8dNkBW0yrnn+LRsRdGoWuCmaLSI+VBf2/mX7lC78Gmie4gPpJH1URSSet0TW Un8fW2WYnNd2MfYt8nPZwl56cNZSBWJfaXaIXLC0dsHQaXefyftS5cTmUf+95gdot1Et6p 4u1TipPziBcE6dw4QlQ2YPSekpcidzfFDtNF2n7ggsPHF7gpgZjvBq/wlRpvdFaY9DfrUw gVW37QGelHsXHePuKfGb6OIEq/pWRP4XJ3WeMBcUO7IyFblXtW4fCNSZdWxupzVduwLZpu E3P3Md1gbUfo+moCh7DDDnaxhZUQllbRiRZ3BL2WWzS0g78pE5ScnNROjc0uAg== From: Daniel Wagner To: LKML , linux-rt-users , Steven Rostedt , Thomas Gleixner , Carsten Emde , John Kacur , Sebastian Andrzej Siewior , Tom Zanussi , Clark Williams , Pavel Machek Cc: Daniel Wagner Subject: [PATCH RT 4/9] Revert "workqueue: Use local irq lock instead of irq disable regions" Date: Mon, 24 Oct 2022 12:44:20 +0200 Message-Id: <20221024104425.16423-5-wagi@monom.org> In-Reply-To: <20221024104425.16423-1-wagi@monom.org> References: <20221024104425.16423-1-wagi@monom.org> MIME-Version: 1.0 X-Last-TLS-Session-Version: TLSv1.3 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747566205118195216?= X-GMAIL-MSGID: =?utf-8?q?1747566205118195216?= From: Sebastian Andrzej Siewior v4.19.255-rt114-rc1 stable review patch. If anyone has any objections, please let me know. ----------- This reverts the PREEMPT_RT related changes to workqueue. It reverts the usage of local_locks() and cpu_chill(). This is a preparation to pull in the PREEMPT_RT related changes which were merged upstream. Signed-off-by: Sebastian Andrzej Siewior [wagi: 827b6f6962da ("workqueue: rework") already reverted most of the changes, except the missing update in put_pwq_unlocked.] Signed-off-by: Daniel Wagner --- kernel/workqueue.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 4ed22776b2ee..d97c2ad8dc08 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -1496,11 +1496,9 @@ EXPORT_SYMBOL(queue_work_on); void delayed_work_timer_fn(struct timer_list *t) { struct delayed_work *dwork = from_timer(dwork, t, timer); - unsigned long flags; - local_irq_save(flags); + /* should have been called from irqsafe timer with irq already off */ __queue_work(dwork->cpu, dwork->wq, &dwork->work); - local_irq_restore(flags); } EXPORT_SYMBOL(delayed_work_timer_fn); From patchwork Mon Oct 24 10:44:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Wagner X-Patchwork-Id: 8327 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp375992wru; Mon, 24 Oct 2022 03:57:06 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4i9kezifg186PGs3lNprpbVSWg4R02ErpTe95a3rMDi8W/sIGKOm0URcorDtyAguGCyt0/ X-Received: by 2002:a17:907:2d89:b0:78d:9c30:452b with SMTP id gt9-20020a1709072d8900b0078d9c30452bmr25544103ejc.533.1666609026015; Mon, 24 Oct 2022 03:57:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666609026; cv=none; d=google.com; s=arc-20160816; b=xhstNnTy0m1X/acQK8e4dIJhMf+kTqSoTpn1YI5zvSQRycNTQ0vOTLTyJJK8f3eu94 VpvmSj6/dy+S0ZuFSHkNyN2z0aTbB5e4jzfYh9/+LOl0k9nX0yFsYcw7LmWKhMZPxoq1 eJODw9lykzKcsV9zcgM8cKlpE4f/XmjCOQ11bIbg+JSr1YH7+1OM/tEBZVtzO7g/lZZX 0VapdZ/kc5+A+2U6YW+NP7J4Ehx5I0hgq4DAa07Yf5MDaU2rR7+c2bghv6QUjASFNjBV EE2ZIC0H4DuQ2oqyOALPwYXAkeeT5QlSh6IFVupdbdUmsdEqOSJah+liSt7RcEUmIbVB uimQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Ewd7YIr3/bEdlcKC7v2uy0s+SHWdjFr5K1Yi5NyIu0o=; b=eHpNQK1cRy9vc4QvAvQ7adh0B6pTysqkrdMNZWjLT6nYo5fBxDmkz9kLy0zKY7aGOh CSxNvjnl03eFmWS7JndXoPhP7nasmJVcCEEJ+dUiH51ItZAGcCo9hS1paaPrWHrLcCO2 o9kEVa90Nfz0ToCoVKBsrmcBzVtteY9KvgFv5Y1OFfKkwkGwmM60yqMwddRI8kmdrLaM Syc/mprhVEv+r3shjuERmbo9eCOONTfclkRFYdMtaUppgNLYs4T34aDUgKTvqu6oOP66 0nECKRhzNHQ6TrDstVPIdD7YxEP7x+QaDfKm9UtKcmduBLtT5T+Z3Dixs91I3IHhj+3A 2TMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@monom.org header.s=dkim header.b=C4+RmTg5; 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=REJECT sp=REJECT dis=NONE) header.from=monom.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b9-20020aa7dc09000000b00456964d3369si23478283edu.230.2022.10.24.03.56.42; Mon, 24 Oct 2022 03:57:06 -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=@monom.org header.s=dkim header.b=C4+RmTg5; 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=REJECT sp=REJECT dis=NONE) header.from=monom.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230085AbiJXKzb (ORCPT + 99 others); Mon, 24 Oct 2022 06:55:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229851AbiJXKy6 (ORCPT ); Mon, 24 Oct 2022 06:54:58 -0400 Received: from mail.nearlyone.de (mail.nearlyone.de [46.163.114.145]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C78D13F0E; Mon, 24 Oct 2022 03:54:38 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 9CD8E61D7D; Mon, 24 Oct 2022 12:44:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monom.org; s=dkim; t=1666608272; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=Ewd7YIr3/bEdlcKC7v2uy0s+SHWdjFr5K1Yi5NyIu0o=; b=C4+RmTg5hzIEjuwHdWs8SjfZlMU3wo4WAXs4hFa2XAeFvu7j/5Ex526Dr8JBA/Rpd8240j Lvl25pbIOnbMYiQ5Q63Zn9n+AiEZNa8+hsqjOdes0N1hWylcOuqwZqclS7EoN9ydqC1XCE C71lqELBsDMUJrw5ZSB8NzDLSXqMCnEuaGiCzQU+lFylRPG5OBNSQKEYHaDfJ8Ni2Nfirs sfim8pizNBl+Hcuy1Nz4M+DraDhnpArs/5hMlNI5ZejIYJqtdLdTW1CBuIXthe1cp1LycB FeVnF3jK7IQeCZiETOlo/kkfmj+S7+V+oiDu1bqT2W0G1/OU3CpgdiWN02iWiw== From: Daniel Wagner To: LKML , linux-rt-users , Steven Rostedt , Thomas Gleixner , Carsten Emde , John Kacur , Sebastian Andrzej Siewior , Tom Zanussi , Clark Williams , Pavel Machek Cc: Daniel Wagner Subject: [PATCH RT 5/9] timers: Keep interrupts disabled for TIMER_IRQSAFE timer. Date: Mon, 24 Oct 2022 12:44:21 +0200 Message-Id: <20221024104425.16423-6-wagi@monom.org> In-Reply-To: <20221024104425.16423-1-wagi@monom.org> References: <20221024104425.16423-1-wagi@monom.org> MIME-Version: 1.0 X-Last-TLS-Session-Version: TLSv1.3 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747566225942749226?= X-GMAIL-MSGID: =?utf-8?q?1747566225942749226?= From: Sebastian Andrzej Siewior v4.19.255-rt114-rc1 stable review patch. If anyone has any objections, please let me know. ----------- Keep interrupts disabled across callback invocation for the TIMER_IRQSAFE as expected. This is required for the timer used by workqueue after the upcomming rework. Signed-off-by: Sebastian Andrzej Siewior Signed-off-by: Daniel Wagner --- kernel/time/timer.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kernel/time/timer.c b/kernel/time/timer.c index a2be2277506d..3e2c0bd03004 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1397,8 +1397,7 @@ static void expire_timers(struct timer_base *base, struct hlist_head *head) fn = timer->function; - if (!IS_ENABLED(CONFIG_PREEMPT_RT_FULL) && - timer->flags & TIMER_IRQSAFE) { + if (timer->flags & TIMER_IRQSAFE) { raw_spin_unlock(&base->lock); call_timer_fn(timer, fn); base->running_timer = NULL; From patchwork Mon Oct 24 10:44:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Wagner X-Patchwork-Id: 8328 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp376099wru; Mon, 24 Oct 2022 03:57:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6khfwv4rw0n7YjgzxPZDtvxRKmtZfF8W4IMxswwtPRgWik5q8cX7mMiEI8dLcPDiya6YCQ X-Received: by 2002:a17:906:cc5a:b0:78d:c3cf:6ff7 with SMTP id mm26-20020a170906cc5a00b0078dc3cf6ff7mr27374347ejb.383.1666609033813; Mon, 24 Oct 2022 03:57:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666609033; cv=none; d=google.com; s=arc-20160816; b=PlDsaxupgcayCfsdFOUJPxxBWlGjlJ5P0O9qgVlyzcdBdUBbIRN0WQPaxWsFaC5xFc omaOlR3XwlnSw2m7YcZnWHYEdNkatTKMQq41Rkky4xJ1UbpZZtYHebHbZ1y1p5TUa23R QjMv0ZfkpXrMAkakmxGW5rMegjYufStFTWT7YWR6D0jV+5NKyRmhoJqN7G0GvJ8L4gIQ v0ab4Yf7p/5EufPEAOmEfgtDGOoW40rFWnjmMQvBuXWRYZ3pm+H8762k424jDsgU+z8P v6t6oMAmTL6aSA7eWdg8UFzEJI1dAFpuFvYWdSrrJerPp+yZ4lsr8FXoDnnE5hsMGLBS eJCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=BOoIY9WJFmBt1PSHlkPpnZQdqGiT4O4onH5CW/obUpI=; b=L0kpBhHQJfQ3MSu+TqjSrAOFYcR5rNMjMeEVm6VoaJ7HIfXYsb5R9jhbL0PeADGntO r/y9MmmJWq9x+f1+4I85beex2QkjiSgv8gY4p+MrKors36iaD3qgzQQcxRruxkkLBUsn 65zmMdqwSGkRsd2yRPBaAhwb/tdATbym08jBz7RbyFnR9pbbMi6N903OyufurHL09uLR AOj9yP5SWs19eGu88cNXu1OOdxS0t51aSRhTlPlPOx4iUG3NyrIcnWAW+aJeaT4pU0tZ 0DUFCLDxmURTi97SSiqSsy4veySUum+mmAQJR8NkKhuuR1yoAWOw6Gjy3MjgGFDvIgnG ysPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@monom.org header.s=dkim header.b=aO0uZ3v9; 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=REJECT sp=REJECT dis=NONE) header.from=monom.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q15-20020a056402032f00b00461606e36dbsi7006423edw.131.2022.10.24.03.56.48; Mon, 24 Oct 2022 03:57:13 -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=@monom.org header.s=dkim header.b=aO0uZ3v9; 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=REJECT sp=REJECT dis=NONE) header.from=monom.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229773AbiJXKyk (ORCPT + 99 others); Mon, 24 Oct 2022 06:54:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229865AbiJXKyg (ORCPT ); Mon, 24 Oct 2022 06:54:36 -0400 Received: from mail.nearlyone.de (mail.nearlyone.de [46.163.114.145]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7378C65D5; Mon, 24 Oct 2022 03:54:31 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 4C9E561D80; Mon, 24 Oct 2022 12:44:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monom.org; s=dkim; t=1666608273; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=BOoIY9WJFmBt1PSHlkPpnZQdqGiT4O4onH5CW/obUpI=; b=aO0uZ3v90bbg6mi3ImXFlkzhdHX/g0FQCi0pycvauxRpctXYkmPO+cOdvY0LbEcCXZLkUr N1k7H6QO3ImFEEKEkU5ghTkU6tbR/35k1X9QQV1e84adehoMye5oeTX9kxZoatKYbcSGNm D4teRsHUUeE7lzcA4nVfOSJwEisS1Qz3AqbJCYaF6Q43b6E2GoKjcAKa7V1/7/0DsSlxad moM8HgLNk2F63w+h80FgwXG66xSu15BqOxhktjyb7sqhBwJRh0bhvDo+skJfp4vPMKhQHS jsVBy+gfqOonqQGMg8wexjfk+tMuWi7380sqd13iw/QmD5V8OBf8yecVVUYhuQ== From: Daniel Wagner To: LKML , linux-rt-users , Steven Rostedt , Thomas Gleixner , Carsten Emde , John Kacur , Sebastian Andrzej Siewior , Tom Zanussi , Clark Williams , Pavel Machek Cc: Mike Galbraith , Daniel Wagner Subject: [PATCH RT 6/9] timers: Don't block on ->expiry_lock for TIMER_IRQSAFE timers Date: Mon, 24 Oct 2022 12:44:22 +0200 Message-Id: <20221024104425.16423-7-wagi@monom.org> In-Reply-To: <20221024104425.16423-1-wagi@monom.org> References: <20221024104425.16423-1-wagi@monom.org> MIME-Version: 1.0 X-Last-TLS-Session-Version: TLSv1.3 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747566234440585172?= X-GMAIL-MSGID: =?utf-8?q?1747566234440585172?= From: Sebastian Andrzej Siewior v4.19.255-rt114-rc1 stable review patch. If anyone has any objections, please let me know. ----------- Upstream commit c725dafc95f1b37027840aaeaa8b7e4e9cd20516 PREEMPT_RT does not spin and wait until a running timer completes its callback but instead it blocks on a sleeping lock to prevent a livelock in the case that the task waiting for the callback completion preempted the callback. This cannot be done for timers flagged with TIMER_IRQSAFE. These timers can be canceled from an interrupt disabled context even on RT kernels. The expiry callback of such timers is invoked with interrupts disabled so there is no need to use the expiry lock mechanism because obviously the callback cannot be preempted even on RT kernels. Do not use the timer_base::expiry_lock mechanism when waiting for a running callback to complete if the timer is flagged with TIMER_IRQSAFE. Also add a lockdep assertion for RT kernels to validate that the expiry lock mechanism is always invoked in preemptible context. Reported-by: Mike Galbraith Signed-off-by: Sebastian Andrzej Siewior Signed-off-by: Thomas Gleixner Link: https://lore.kernel.org/r/20201103190937.hga67rqhvknki3tp@linutronix.de [bigeasy: The logic in v4.19 is slightly different but the outcome is the same as we must not sleep while waiting for the irqsafe timer to complete. The IRQSAFE timer can not be preempted. The "lockdep annotation" is not available and has been replaced with might_sleep()] Signed-off-by: Sebastian Andrzej Siewior Signed-off-by: Daniel Wagner --- kernel/time/timer.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/kernel/time/timer.c b/kernel/time/timer.c index 3e2c0bd03004..0a6d60b3e67c 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1272,6 +1272,9 @@ static int __del_timer_sync(struct timer_list *timer) if (ret >= 0) return ret; + if (READ_ONCE(timer->flags) & TIMER_IRQSAFE) + continue; + /* * When accessing the lock, timers of base are no longer expired * and so timer is no longer running. @@ -1336,6 +1339,12 @@ int del_timer_sync(struct timer_list *timer) * could lead to deadlock. */ WARN_ON(in_irq() && !(timer->flags & TIMER_IRQSAFE)); + /* + * Must be able to sleep on PREEMPT_RT because of the slowpath in + * __del_timer_sync(). + */ + if (IS_ENABLED(CONFIG_PREEMPT_RT) && !(timer->flags & TIMER_IRQSAFE)) + might_sleep(); return __del_timer_sync(timer); } From patchwork Mon Oct 24 10:44:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Wagner X-Patchwork-Id: 8332 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp376713wru; Mon, 24 Oct 2022 03:59:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4ZONBgByPwA1InuupBiQWZpTbrmapbLzFISyd6v+Wf14005ZWvM2dIdMRbWmm7fiy7q77J X-Received: by 2002:a17:907:9618:b0:78d:fa75:e2b8 with SMTP id gb24-20020a170907961800b0078dfa75e2b8mr27768105ejc.65.1666609164344; Mon, 24 Oct 2022 03:59:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666609164; cv=none; d=google.com; s=arc-20160816; b=ytZ7qXgFAe8YUsw3eIlQ1EsYicDkbbjQJq6mUPix9tzoNpbaO9DgmujeaVtBpIERdf wtD0J1tLzX4gLUQMjx6bdKupLfktD23XZx7rFNNkHWzNshk7yfq21YCI8Uu5BPyK7DpB eZCaUFWeQVVhNOyKWUX8GO/b9aEzNnkJN+PC9WODSMr633NoTmQ0+k9293M8FPNG+wYU AE01PiWOYqHDKS2NDMFoJIcG90NmfIPMmLoeLemEpcvl0trW4PZbUy+43CGLZAKFQ3+A X9S7WA+O0pWUJ102rICgvfzOj27O4hmXo9T+oPGO9qlU/MABJQEhc/06Eb7HXfK+J4Q1 5ZBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3ybaud1kyiVS7GuVr4/KkcFRcnBUsmRucVe0CCHGVXw=; b=qZLJJzIfhEbUwJkNAMoeXT3z3YZDl5GUX0m5T+91COEbtePQbISHTE/M4SRQFPS1ne GsiJUd9COQy8ELnbVKhiv/ORRnihBUDRLLPbJGV/JmkpCWIqDlJ01lFpU8j+5lUs6dzT jAAoglgAjRa1TmGg/WdSGeRrc84s4ZNucTZesfaeQy3NGdNPAQALtwnKq8/O4p7vvYBr NrNniTP8GVOEgohA0iaheXVf6ENEKF7L8qxD9HuIz1+3Z/VLXfn6YeOh1J1Y1+9zLLO6 rhIhqFUolObwjMR4REaxnxVJ1rwsOFQKQ2gY6u4YqiuaQ3rMN6DmKrsf/4oQEueIVpRf SQ1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@monom.org header.s=dkim header.b=PdGcuYXB; 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=REJECT sp=REJECT dis=NONE) header.from=monom.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q13-20020a170906388d00b0078d4b9428cdsi23119252ejd.389.2022.10.24.03.59.00; Mon, 24 Oct 2022 03:59:24 -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=@monom.org header.s=dkim header.b=PdGcuYXB; 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=REJECT sp=REJECT dis=NONE) header.from=monom.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229841AbiJXKzo (ORCPT + 99 others); Mon, 24 Oct 2022 06:55:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229940AbiJXKy6 (ORCPT ); Mon, 24 Oct 2022 06:54:58 -0400 Received: from mail.nearlyone.de (mail.nearlyone.de [46.163.114.145]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56582175B7; Mon, 24 Oct 2022 03:54:38 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 3C5B261D82; Mon, 24 Oct 2022 12:44:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monom.org; s=dkim; t=1666608274; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=3ybaud1kyiVS7GuVr4/KkcFRcnBUsmRucVe0CCHGVXw=; b=PdGcuYXB2KhNfeE3P/LI4rjJHS+bNnyqguGy7XMp4h5tqjtGaxZ3C9jidrABfnn20gGxCa x8U0SibXgJ9SFLlbRdWM4+HwTCMlX+m3R9LGhBH/Ez6dnJp9cXCESaGa4aU9QDM55elTsW W921MugGlOUr0iXeSnVA3OmIqxwun4I/yK5aYGSrxtPHYibQeYnqgB8HKFt7/VEp7nouNX URuxTo573KswFnmbqoDWiv0taHBQD9CsLokceD4uAKc6lYXCFJbihfIV5+U4V5EnzCkXLs k2wi8nAbGQL5LGwQVH6afxnA59Uw8TpNAYWVkBjfZewPWzF5mXUBLSDDhUABRQ== From: Daniel Wagner To: LKML , linux-rt-users , Steven Rostedt , Thomas Gleixner , Carsten Emde , John Kacur , Sebastian Andrzej Siewior , Tom Zanussi , Clark Williams , Pavel Machek Cc: Daniel Wagner Subject: [PATCH RT 7/9] rcu: Update rcuwait Date: Mon, 24 Oct 2022 12:44:23 +0200 Message-Id: <20221024104425.16423-8-wagi@monom.org> In-Reply-To: <20221024104425.16423-1-wagi@monom.org> References: <20221024104425.16423-1-wagi@monom.org> MIME-Version: 1.0 X-Last-TLS-Session-Version: TLSv1.3 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747566371407586883?= X-GMAIL-MSGID: =?utf-8?q?1747566371407586883?= v4.19.255-rt114-rc1 stable review patch. If anyone has any objections, please let me know. ----------- This is an all in one commit backporting updates for rcuwait: - 03f4b48edae7 ("rcuwait: Annotate task_struct with __rcu") - 191a43be61d6 ("rcuwait: Introduce rcuwait_active()") - 5c21f7b322cb ("rcuwait: Introduce prepare_to and finish_rcuwait") - 80fbaf1c3f29 ("rcuwait: Add @state argument to rcuwait_wait_event()") - 9d9a6ebfea32 ("rcuwait: Let rcuwait_wake_up() return whether or not a task was awoken") - 58d4292bd037 ("rcu: Uninline multi-use function: finish_rcuwait()") Signed-off-by: Daniel Wagner --- include/linux/rcuwait.h | 42 +++++++++++++++++++++++++++-------- kernel/exit.c | 7 ++++-- kernel/locking/percpu-rwsem.c | 2 +- kernel/rcu/update.c | 8 +++++++ 4 files changed, 47 insertions(+), 12 deletions(-) diff --git a/include/linux/rcuwait.h b/include/linux/rcuwait.h index 90bfa3279a01..4fe9ecd56aac 100644 --- a/include/linux/rcuwait.h +++ b/include/linux/rcuwait.h @@ -3,6 +3,7 @@ #define _LINUX_RCUWAIT_H_ #include +#include /* * rcuwait provides a way of blocking and waking up a single @@ -18,7 +19,7 @@ * awoken. */ struct rcuwait { - struct task_struct *task; + struct task_struct __rcu *task; }; #define __RCUWAIT_INITIALIZER(name) \ @@ -29,14 +30,33 @@ static inline void rcuwait_init(struct rcuwait *w) w->task = NULL; } -extern void rcuwait_wake_up(struct rcuwait *w); +extern int rcuwait_wake_up(struct rcuwait *w); + +/* + * Note: this provides no serialization and, just as with waitqueues, + * requires care to estimate as to whether or not the wait is active. + */ +static inline int rcuwait_active(struct rcuwait *w) +{ + return !!rcu_access_pointer(w->task); +} /* * The caller is responsible for locking around rcuwait_wait_event(), - * such that writes to @task are properly serialized. + * and [prepare_to/finish]_rcuwait() such that writes to @task are + * properly serialized. */ -#define rcuwait_wait_event(w, condition) \ + +static inline void prepare_to_rcuwait(struct rcuwait *w) +{ + rcu_assign_pointer(w->task, current); +} + +extern void finish_rcuwait(struct rcuwait *w); + +#define rcuwait_wait_event(w, condition, state) \ ({ \ + int __ret = 0; \ /* \ * Complain if we are called after do_exit()/exit_notify(), \ * as we cannot rely on the rcu critical region for the \ @@ -44,21 +64,25 @@ extern void rcuwait_wake_up(struct rcuwait *w); */ \ WARN_ON(current->exit_state); \ \ - rcu_assign_pointer((w)->task, current); \ + prepare_to_rcuwait(w); \ for (;;) { \ /* \ * Implicit barrier (A) pairs with (B) in \ * rcuwait_wake_up(). \ */ \ - set_current_state(TASK_UNINTERRUPTIBLE); \ + set_current_state(state); \ if (condition) \ break; \ \ + if (signal_pending_state(state, current)) { \ + __ret = -EINTR; \ + break; \ + } \ + \ schedule(); \ } \ - \ - WRITE_ONCE((w)->task, NULL); \ - __set_current_state(TASK_RUNNING); \ + finish_rcuwait(w); \ + __ret; \ }) #endif /* _LINUX_RCUWAIT_H_ */ diff --git a/kernel/exit.c b/kernel/exit.c index 2a414fc71b87..cf68896a94fa 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -291,8 +291,9 @@ struct task_struct *task_rcu_dereference(struct task_struct **ptask) return task; } -void rcuwait_wake_up(struct rcuwait *w) +int rcuwait_wake_up(struct rcuwait *w) { + int ret = 0; struct task_struct *task; rcu_read_lock(); @@ -316,8 +317,10 @@ void rcuwait_wake_up(struct rcuwait *w) */ task = rcu_dereference(w->task); if (task) - wake_up_process(task); + ret = wake_up_process(task); rcu_read_unlock(); + + return ret; } /* diff --git a/kernel/locking/percpu-rwsem.c b/kernel/locking/percpu-rwsem.c index 883cf1b92d90..41787e80dbde 100644 --- a/kernel/locking/percpu-rwsem.c +++ b/kernel/locking/percpu-rwsem.c @@ -159,7 +159,7 @@ void percpu_down_write(struct percpu_rw_semaphore *sem) */ /* Wait for all now active readers to complete. */ - rcuwait_wait_event(&sem->writer, readers_active_check(sem)); + rcuwait_wait_event(&sem->writer, readers_active_check(sem), TASK_UNINTERRUPTIBLE); } EXPORT_SYMBOL_GPL(percpu_down_write); diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c index ed75addd3ccd..4b2ce6bb94a4 100644 --- a/kernel/rcu/update.c +++ b/kernel/rcu/update.c @@ -53,6 +53,7 @@ #include #include #include +#include #define CREATE_TRACE_POINTS @@ -375,6 +376,13 @@ void __wait_rcu_gp(bool checktiny, int n, call_rcu_func_t *crcu_array, } EXPORT_SYMBOL_GPL(__wait_rcu_gp); +void finish_rcuwait(struct rcuwait *w) +{ + rcu_assign_pointer(w->task, NULL); + __set_current_state(TASK_RUNNING); +} +EXPORT_SYMBOL_GPL(finish_rcuwait); + #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD void init_rcu_head(struct rcu_head *head) { From patchwork Mon Oct 24 10:44:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Wagner X-Patchwork-Id: 8329 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp376243wru; Mon, 24 Oct 2022 03:57:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM42UE21B4s79Eb7VUbuLu8s1e+WjnKChNFlAEqYtQjNJx3sBiGFAxrfmjLdfYl3kNwGmCuZ X-Received: by 2002:a17:907:2c59:b0:7a9:1134:db02 with SMTP id hf25-20020a1709072c5900b007a91134db02mr2675144ejc.508.1666609076979; Mon, 24 Oct 2022 03:57:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666609076; cv=none; d=google.com; s=arc-20160816; b=ehbmW/r2c5JCm2DsEO72/yKI8BGPVOcTaCWIkOKwyaGDtRbK5+skQ7PqegmuRazmVJ YV3MqNELmUNZab3nR/Qgn3qvQou+AJaV2OjbgMvdIfs6gujKhUHjIbggpvW9fbl716Tg F3ZTA2HzjMP2j7mPOzxji4dXCaLQcAInX1+UgHUzrEN+PsTwQnMUR4nqVpTeSmj5NQ4t 7Ir8NYLY4qvTFyEK/QNG1BBCLcStLIh6UdSSIgaHV4RQRxXPIpk1HJP3s6aXRxfeQBzL F6AwZt3cLtx/EIeSRMKo5RG5S66TPNv+Jv460FiUcwN99Xkot0umrBY4yNfTcJXE38+2 Bw3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=wKMtxoQSqU1ebaoGnDGb+/Jm2lZqqN7MOioiczni8Q4=; b=Wp+TF/wj7KXayz+uuOLl5ZdYeVscPORV+x6lQr/zjKY/V7lR8ojfQ71bO39Bnskz1Y z8oME67d1Qyo2M1icXxlJvnEU/RIxkdSodIm18rKh1OdqydEMuPGH7Ti7ZG3T1fjAEVW S02Sdm4fSfaGoor2Psq7SaczSoa2PITzCokD+Wx28kmQa3UKHRDxqgfd/brrLZkT3wzr 417Rz8MiRDshJ7LyJX5NdS7i7UwUe2hv6PKrnQJq3arI9s/koAGf0vbwmH4Zu5i3cdGQ REpwC9ho8hCsAeTNCrma/iJy4vlAFBLtVL+2MkjHevLUsxYAq3D/qHntf8t8NJehs2ON dH3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@monom.org header.s=dkim header.b=Gv8xGyN4; 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=REJECT sp=REJECT dis=NONE) header.from=monom.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a21-20020a1709066d5500b00782933fe436si23614756ejt.965.2022.10.24.03.57.32; Mon, 24 Oct 2022 03:57:56 -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=@monom.org header.s=dkim header.b=Gv8xGyN4; 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=REJECT sp=REJECT dis=NONE) header.from=monom.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229999AbiJXKzY (ORCPT + 99 others); Mon, 24 Oct 2022 06:55:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229905AbiJXKy6 (ORCPT ); Mon, 24 Oct 2022 06:54:58 -0400 Received: from mail.nearlyone.de (mail.nearlyone.de [46.163.114.145]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 400D513EAB; Mon, 24 Oct 2022 03:54:38 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id DB1BE61D87; Mon, 24 Oct 2022 12:44:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monom.org; s=dkim; t=1666608275; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=wKMtxoQSqU1ebaoGnDGb+/Jm2lZqqN7MOioiczni8Q4=; b=Gv8xGyN41xfixWyk3MSUHYHC7pQsBIjt/5gQfFsrP+8A+mdStUayYM0dMm4r9Tq3xa3+RG XLgriCxoVzZ/UnXb7hvMiJl2uZJiKEYCl5QwMi7DuHVlGZouJ2jkOXFGMMvzURJ9rfwaxF QM9M59BVerI6FHPuqCK/nretNaZAtZaPo32eY0uMJsxs6RJhRwClq4IoVgexxFR96mz9L/ Ud/SeXsu/XDhW9RibK7QU8l/8DiTQxiKUxrhlRiFGSzrDpFf32JxwQLNQeiWwB114jtKs7 oJm2a1X1GKTlfDqmrwXrkPkLZcbg/InzJPn1FqI5iAWS/oorsTkZckHxJ6jQZA== From: Daniel Wagner To: LKML , linux-rt-users , Steven Rostedt , Thomas Gleixner , Carsten Emde , John Kacur , Sebastian Andrzej Siewior , Tom Zanussi , Clark Williams , Pavel Machek Cc: Tejun Heo , Daniel Wagner Subject: [PATCH RT 8/9] workqueue: Use rcuwait for wq_manager_wait Date: Mon, 24 Oct 2022 12:44:24 +0200 Message-Id: <20221024104425.16423-9-wagi@monom.org> In-Reply-To: <20221024104425.16423-1-wagi@monom.org> References: <20221024104425.16423-1-wagi@monom.org> MIME-Version: 1.0 X-Last-TLS-Session-Version: TLSv1.3 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747566279774627938?= X-GMAIL-MSGID: =?utf-8?q?1747566279774627938?= From: Sebastian Andrzej Siewior v4.19.255-rt114-rc1 stable review patch. If anyone has any objections, please let me know. ----------- Upstream commit d8bb65ab70f702531aaaa11d9710f9450078e295 The workqueue code has it's internal spinlock (pool::lock) and also implicit spinlock usage in the wq_manager waitqueue. These spinlocks are converted to 'sleeping' spinlocks on a RT-kernel. Workqueue functions can be invoked from contexts which are truly atomic even on a PREEMPT_RT enabled kernel. Taking sleeping locks from such contexts is forbidden. pool::lock can be converted to a raw spinlock as the lock held times are short. But the workqueue manager waitqueue is handled inside of pool::lock held regions which again violates the lock nesting rules of raw and regular spinlocks. The manager waitqueue has no special requirements like custom wakeup callbacks or mass wakeups. While it does not use exclusive wait mode explicitly there is no strict requirement to queue the waiters in a particular order as there is only one waiter at a time. This allows to replace the waitqueue with rcuwait which solves the locking problem because rcuwait relies on existing locking. Signed-off-by: Sebastian Andrzej Siewior Signed-off-by: Tejun Heo Signed-off-by: Sebastian Andrzej Siewior [wagi: Updated context as v4.19-rt was using swait] Signed-off-by: Daniel Wagner --- kernel/workqueue.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index d97c2ad8dc08..a3777fe1e224 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -50,6 +50,7 @@ #include #include #include +#include #include "workqueue_internal.h" @@ -299,7 +300,8 @@ static struct workqueue_attrs *wq_update_unbound_numa_attrs_buf; static DEFINE_MUTEX(wq_pool_mutex); /* protects pools and workqueues list */ static DEFINE_MUTEX(wq_pool_attach_mutex); /* protects worker attach/detach */ static DEFINE_RAW_SPINLOCK(wq_mayday_lock); /* protects wq->maydays list */ -static DECLARE_SWAIT_QUEUE_HEAD(wq_manager_wait); /* wait for manager to go away */ +/* wait for manager to go away */ +static struct rcuwait manager_wait = __RCUWAIT_INITIALIZER(manager_wait); static LIST_HEAD(workqueues); /* PR: list of all workqueues */ static bool workqueue_freezing; /* PL: have wqs started freezing? */ @@ -2023,7 +2025,7 @@ static bool manage_workers(struct worker *worker) pool->manager = NULL; pool->flags &= ~POOL_MANAGER_ACTIVE; - swake_up_one(&wq_manager_wait); + rcuwait_wake_up(&manager_wait); return true; } @@ -3344,6 +3346,18 @@ static void rcu_free_pool(struct rcu_head *rcu) kfree(pool); } +/* This returns with the lock held on success (pool manager is inactive). */ +static bool wq_manager_inactive(struct worker_pool *pool) +{ + raw_spin_lock_irq(&pool->lock); + + if (pool->flags & POOL_MANAGER_ACTIVE) { + raw_spin_unlock_irq(&pool->lock); + return false; + } + return true; +} + /** * put_unbound_pool - put a worker_pool * @pool: worker_pool to put @@ -3379,10 +3393,12 @@ static void put_unbound_pool(struct worker_pool *pool) * Become the manager and destroy all workers. This prevents * @pool's workers from blocking on attach_mutex. We're the last * manager and @pool gets freed with the flag set. + * Because of how wq_manager_inactive() works, we will hold the + * spinlock after a successful wait. */ raw_spin_lock_irq(&pool->lock); - swait_event_lock_irq(wq_manager_wait, - !(pool->flags & POOL_MANAGER_ACTIVE), pool->lock); + rcuwait_wait_event(&manager_wait, wq_manager_inactive(pool), + TASK_UNINTERRUPTIBLE); pool->flags |= POOL_MANAGER_ACTIVE; while ((worker = first_idle_worker(pool))) From patchwork Mon Oct 24 10:44:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Wagner X-Patchwork-Id: 8330 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp376272wru; Mon, 24 Oct 2022 03:58:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM40VpuuryXbcfpEarkr91tVV3h2a/oxYjc0jZb8aSLS0HVZ+XkEFq86LcSSJBdZeU+vU6I7 X-Received: by 2002:a05:6402:1f06:b0:457:149d:beaa with SMTP id b6-20020a0564021f0600b00457149dbeaamr29844632edb.238.1666609080884; Mon, 24 Oct 2022 03:58:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666609080; cv=none; d=google.com; s=arc-20160816; b=w9zJBLNuja4W+PGtP8/MTn6FwXdDAmnZGIga2MtUnllpKSvwqD/hbxkR0MleHfu1aJ hYqPxpTruh1g6cFnwkO2I2CfaxZ8ucSYGlhE2zPLI++l2s7a5yiQUJiEi6yNrNSL17Ez 8CJtrRxrF3QRKWwHbky7SXP1bPzAcQpjbF6NqsxN1Y1z6JYnvIwOtC4DtJqcESAZiWSp 0l7FNzp8wvkUW2STUQN63MrU9nxOJxymt7OuaC1y6pPT4IXAMxv/n1jdaXy60MJ1BKjU pFaz0Xjanjivczv0IdluCGLh86nyXmEwhyS90dDRPpZRU+xJisDnW0kpeW4QvRDAnATU dyeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Vx66ENX8B8kIe6BX2BaW+D/YVu0rgeih4x2rY/yzaTY=; b=e6jw+fZewWYvzD5Ru+3wVMRXAWT/ViIrcDEjr6ub+1/N7/9uSuUFLLSEcdSvAcpOpv TYoCGuDtQSvP50soV/PK6zzcMCuFj1snofpGMen+/9QoWuAAQ6l/d1cj38hIciYrT8U4 m9J9Th9N0G0DuMEFD9/y1or5lkJKYqtVuLoiJlyGJV5mlIRzYfEVgIIxfMK7oxq1gs7v qTqIO1TLkNWZhLrCmpSRjmHk4xFvm4eJkCLvrpeX0rtIjv7druxfhPcS6cQbrqxxRyWs CO+qoeLOVGCzyKw40sEbZONS2oMy5/tBhsIp2Hm5OT5j317IcMVFIgL15V3zxnqgV7ug SC9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@monom.org header.s=dkim header.b=YcpYO+CE; 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=REJECT sp=REJECT dis=NONE) header.from=monom.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g20-20020a1709065d1400b007a66031d2dbsi3573623ejt.718.2022.10.24.03.57.37; Mon, 24 Oct 2022 03:58:00 -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=@monom.org header.s=dkim header.b=YcpYO+CE; 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=REJECT sp=REJECT dis=NONE) header.from=monom.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229651AbiJXKyo (ORCPT + 99 others); Mon, 24 Oct 2022 06:54:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229872AbiJXKyg (ORCPT ); Mon, 24 Oct 2022 06:54:36 -0400 Received: from mail.nearlyone.de (mail.nearlyone.de [46.163.114.145]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72D5065BD; Mon, 24 Oct 2022 03:54:31 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id A6EBD61D84; Mon, 24 Oct 2022 12:44:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monom.org; s=dkim; t=1666608275; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=Vx66ENX8B8kIe6BX2BaW+D/YVu0rgeih4x2rY/yzaTY=; b=YcpYO+CEYFZTRhRE8s5SjUiovlo5vMf0gUXngSmImmJGmzRemBlG4OOa28kRxv7BUfiyNd iU5cOLCZALME1hSLbi/gCXFssfBMKo9VsJehpFVW4OV/i7lShR2MsR1fqJVNPawQu1nuIZ kScFNk0YU5BORixjkdUDHQjrT6QY/q6gTu266LdQJr88lJXN6497RPplGZRBwyVvjRgz3x I8zPwWjTASRAvE+675FMAx4s4M5Xsu0+SGWU3wr+5LUxrcLMHBcSoWLkSSSwvIDEQMOZ80 ybC/MMh4s7q0n1bw92Uf8faQ5PP4weqVJiwNBbOmSz2TRLHFrmr1dHzhWqBoKA== From: Daniel Wagner To: LKML , linux-rt-users , Steven Rostedt , Thomas Gleixner , Carsten Emde , John Kacur , Sebastian Andrzej Siewior , Tom Zanussi , Clark Williams , Pavel Machek Cc: Daniel Wagner Subject: [PATCH RT 9/9] Linux 4.19.255-rt114-rc1 Date: Mon, 24 Oct 2022 12:44:25 +0200 Message-Id: <20221024104425.16423-10-wagi@monom.org> In-Reply-To: <20221024104425.16423-1-wagi@monom.org> References: <20221024104425.16423-1-wagi@monom.org> MIME-Version: 1.0 X-Last-TLS-Session-Version: TLSv1.3 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747566283816861010?= X-GMAIL-MSGID: =?utf-8?q?1747566283816861010?= v4.19.255-rt114-rc1 stable review patch. If anyone has any objections, please let me know. ----------- Signed-off-by: Daniel Wagner --- localversion-rt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/localversion-rt b/localversion-rt index fdcd9167ca0b..2ae39973e9f8 100644 --- a/localversion-rt +++ b/localversion-rt @@ -1 +1 @@ --rt113 +-rt114-rc1