From patchwork Tue Nov 19 15:34:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Schneider X-Patchwork-Id: 13880130 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4CDB9D44167 for ; Tue, 19 Nov 2024 15:37:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D41566B00AD; Tue, 19 Nov 2024 10:37:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D18FA6B00AF; Tue, 19 Nov 2024 10:37:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BB87B6B00B0; Tue, 19 Nov 2024 10:37:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id A0BF86B00AD for ; Tue, 19 Nov 2024 10:37:08 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 4A3A2C0567 for ; Tue, 19 Nov 2024 15:37:08 +0000 (UTC) X-FDA: 82803246540.10.E361367 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf06.hostedemail.com (Postfix) with ESMTP id C1A38180015 for ; Tue, 19 Nov 2024 15:36:30 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IZ1ztEqy; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf06.hostedemail.com: domain of vschneid@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=vschneid@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732030535; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=9/zjMAAzjZ63CvtK65oto4Glzya8ix3n4q04/5M16qM=; b=O6SsdwvHIMpVJ3xJiAwm1VV31UzBzvxOknsHA+ldp32wPEWWpXU7KNfuOmBW1XFw1yrVDw yt8pTfrYVW96FxS1Ai93rTK3d2ax7qOBc5F7aFEsQGLgTE+aMG9R4hF0/pdnlmEwgBsPq4 6MphdTZuS/ioSpEwtfmwTxN4Uo5lHdg= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IZ1ztEqy; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf06.hostedemail.com: domain of vschneid@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=vschneid@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732030535; a=rsa-sha256; cv=none; b=Janc5yxdAYwJA/C/Pm46GIL6VYBtw4haCuUIk7dI9dKSR8HExpLvS05SXjw1ewRqadyp+w pkweQiPzXL9sM2P3FiDtBQZAfW3zqpXem3H3QVPbmSBjBPiCiv//Iy9XdfXRHMC/RE84KO DDVNWwrtCpFWgvUht0YedHfjio3KNOs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732030625; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9/zjMAAzjZ63CvtK65oto4Glzya8ix3n4q04/5M16qM=; b=IZ1ztEqy7+gIO7UlsThLnZzckIHQzW4ij0sGD8snjOkq5709KKOoREf4Y3ra8vp0SopQTd ma7gXv7s5aYpnqYG9BkKoZrGqHcAonBU7I60sYSox9nKfbflMHT3TBC0mN1EWRXl/MYSfO SvL4sJIfO7cbueQDKp6Y35bMdITl7uw= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-668-nbrc9rTzMP-Bp1uCFPcarg-1; Tue, 19 Nov 2024 10:37:04 -0500 X-MC-Unique: nbrc9rTzMP-Bp1uCFPcarg-1 X-Mimecast-MFC-AGG-ID: nbrc9rTzMP-Bp1uCFPcarg Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C4EB41952D0D; Tue, 19 Nov 2024 15:36:56 +0000 (UTC) Received: from vschneid-thinkpadt14sgen2i.remote.csb (unknown [10.39.194.94]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EC7F330001A2; Tue, 19 Nov 2024 15:36:40 +0000 (UTC) From: Valentin Schneider To: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, kvm@vger.kernel.org, linux-mm@kvack.org, bpf@vger.kernel.org, x86@kernel.org, rcu@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: "Paul E . McKenney" , Steven Rostedt , Masami Hiramatsu , Jonathan Corbet , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Paolo Bonzini , Wanpeng Li , Vitaly Kuznetsov , Andy Lutomirski , Peter Zijlstra , Frederic Weisbecker , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Andrew Morton , Uladzislau Rezki , Christoph Hellwig , Lorenzo Stoakes , Josh Poimboeuf , Jason Baron , Kees Cook , Sami Tolvanen , Ard Biesheuvel , Nicholas Piggin , Juerg Haefliger , Nicolas Saenz Julienne , "Kirill A. Shutemov" , Nadav Amit , Dan Carpenter , Chuang Wang , Yang Jihong , Petr Mladek , "Jason A. Donenfeld" , Song Liu , Julian Pidancet , Tom Lendacky , Dionna Glaze , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Juri Lelli , Marcelo Tosatti , Yair Podemsky , Daniel Wagner , Petr Tesarik Subject: [RFC PATCH v3 04/15] rcu: Add a small-width RCU watching counter debug option Date: Tue, 19 Nov 2024 16:34:51 +0100 Message-ID: <20241119153502.41361-5-vschneid@redhat.com> In-Reply-To: <20241119153502.41361-1-vschneid@redhat.com> References: <20241119153502.41361-1-vschneid@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: C1A38180015 X-Stat-Signature: 8m3d85wzgkmxjpf7x583qb855ttz9tj9 X-HE-Tag: 1732030590-523650 X-HE-Meta: U2FsdGVkX19NWeBQfZV70TxeNZFSChNyEe4RsN3XkSr3kP4ilqLjXhAfZqPGyNqD3T19csFUk14ABzL2DTPS+n0llXVzGKs9uUX3E9+6oF8eAsLx/2nSdVhvlodcJKfoxUupMFGd0s6rhezxBIJvyJofRbjaI3hm1QQ4MelPC0iEM0ZFpmdLKgmkK4GPhjuXIeJT1TpCCLN3uTqmY01A//juTZtzdUbzCy2Xp0V4pJZYgh7A+rHFrbXbBw+xqYQXWua1C9RY4os6yp8edsQSthUMntn86g2dXwJDVsVvnTkFUciORdNmz5gi9sn3G52oDUtrRZxnRNxgcznhe2Wz+Y1EYxjTf55A7ODTa3vG4eWj3yisiDw/ebvBaeExzfTTgNt8+XZO9fL1upx3TU7bHJVEQBn18dJkSd4wV+Z6ncAHQktt2cnPevRasifEThnmBsJXazFd0fpAhZGFtKR7mysjDY5e6Xl1C1GC1PCCNkpikI7kDePwKE70z+L8sJ1XVKnaYmLWU2eN2T10irlsm/8kNRwl4951cVM1yH5AdsJbbB9P95yRTyM4DtX7lAR5ArW/X9HJjO0gtU1d5oIV1/YlqWDZcppUKVxa1ARD/svPZD66YO0Ep4dAfi87AUIuLSsgkqMuJtr/+L/ePrZlzLqaI/M2z4pc/zNgt7CQPhSEeM6syG2tgTv+RXcqYA4QAkI3JcqSOk7bogjvoiqq5br1389Oimva/tMxR+6fGYo2zllkvAL3rLzd9HICVcceHGzPryqt1fR8+u13RNjX4WJDgRp8zXeSnQwUjD8vXI/oKS/eC+dBjpBLr4bN3xR8I7hNpYMVbviJkvQatW1CkgqL+Qhe4ToMHgVVQC2SUkuhC+Z5UfPFp3+IJpb0ktBG273VPBP5mstabAaFTLagKwwRs+mQ5kDlNjlX/yjMSM5nL7OSr5egSADp+jST9dcDvSGIrXnZ1EKvBNKIAIm DdQLZDpm LFH0rhE4Fb5qdmMfldTysG0oUevvK4m4bEaTuoJh4+7iua6wOrG9Bh1onCKYqeV96eGP5feFP/hGNN9+XYveUgzUkT9hkqd/CnoAUMkQ7t3005NARtBsoS3nKHkk0RhG89HbilqTSSXy5xrWeF8Pw6YOZcunrRJAEjqOVKu4e0QKDhK1NKb3wt3N0fJhaEpCutfblrKugrzZXKa1hYCph7Y4ESwNeoOx9x66vCJaZbBwBqTo6Cl3W03CW4+6RUDM0cqvXa4+UPPM0pRa5EZazK4hapwIvL1PoZ1hwN3P1sFq5x/FVPLAOvmspcyPPKGtvkpzRT1nUVNm7y11Ei3EpQbQdkYqHdYEGqTFGgPWfnmG6y3MJqcYFpDKr5C25/wmL9HXIobThdc99qZ/hJzVSJ+C2C46rWSc46d8u96M7IyI4iAy0+WcqO40tO6WiA6esPoOZ X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: A later commit will reduce the size of the RCU watching counter to free up some bits for another purpose. Paul suggested adding a config option to test the extreme case where the counter is reduced to its minimum usable width for rcutorture to poke at, so do that. Make it only configurable under RCU_EXPERT. While at it, add a comment to explain the layout of context_tracking->state. Link: http://lore.kernel.org/r/4c2cb573-168f-4806-b1d9-164e8276e66a@paulmck-laptop Suggested-by: Paul E. McKenney Signed-off-by: Valentin Schneider --- include/linux/context_tracking_state.h | 44 ++++++++++++++++++++++---- kernel/rcu/Kconfig.debug | 14 ++++++++ 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/include/linux/context_tracking_state.h b/include/linux/context_tracking_state.h index 7b8433d5a8efe..0b81248aa03e2 100644 --- a/include/linux/context_tracking_state.h +++ b/include/linux/context_tracking_state.h @@ -18,12 +18,6 @@ enum ctx_state { CT_STATE_MAX = 4, }; -/* Odd value for watching, else even. */ -#define CT_RCU_WATCHING CT_STATE_MAX - -#define CT_STATE_MASK (CT_STATE_MAX - 1) -#define CT_RCU_WATCHING_MASK (~CT_STATE_MASK) - struct context_tracking { #ifdef CONFIG_CONTEXT_TRACKING_USER /* @@ -44,9 +38,45 @@ struct context_tracking { #endif }; +/* + * We cram two different things within the same atomic variable: + * + * CT_RCU_WATCHING_START CT_STATE_START + * | | + * v v + * MSB [ RCU watching counter ][ context_state ] LSB + * ^ ^ + * | | + * CT_RCU_WATCHING_END CT_STATE_END + * + * Bits are used from the LSB upwards, so unused bits (if any) will always be in + * upper bits of the variable. + */ #ifdef CONFIG_CONTEXT_TRACKING +#define CT_SIZE (sizeof(((struct context_tracking *)0)->state) * BITS_PER_BYTE) + +#define CT_STATE_WIDTH bits_per(CT_STATE_MAX - 1) +#define CT_STATE_START 0 +#define CT_STATE_END (CT_STATE_START + CT_STATE_WIDTH - 1) + +#define CT_RCU_WATCHING_MAX_WIDTH (CT_SIZE - CT_STATE_WIDTH) +#define CT_RCU_WATCHING_WIDTH (IS_ENABLED(CONFIG_RCU_DYNTICKS_TORTURE) ? 2 : CT_RCU_WATCHING_MAX_WIDTH) +#define CT_RCU_WATCHING_START (CT_STATE_END + 1) +#define CT_RCU_WATCHING_END (CT_RCU_WATCHING_START + CT_RCU_WATCHING_WIDTH - 1) +#define CT_RCU_WATCHING BIT(CT_RCU_WATCHING_START) + +#define CT_STATE_MASK GENMASK(CT_STATE_END, CT_STATE_START) +#define CT_RCU_WATCHING_MASK GENMASK(CT_RCU_WATCHING_END, CT_RCU_WATCHING_START) + +#define CT_UNUSED_WIDTH (CT_RCU_WATCHING_MAX_WIDTH - CT_RCU_WATCHING_WIDTH) + +static_assert(CT_STATE_WIDTH + + CT_RCU_WATCHING_WIDTH + + CT_UNUSED_WIDTH == + CT_SIZE); + DECLARE_PER_CPU(struct context_tracking, context_tracking); -#endif +#endif /* CONFIG_CONTEXT_TRACKING */ #ifdef CONFIG_CONTEXT_TRACKING_USER static __always_inline int __ct_state(void) diff --git a/kernel/rcu/Kconfig.debug b/kernel/rcu/Kconfig.debug index 9b0b52e1836fa..8dc505d841f8d 100644 --- a/kernel/rcu/Kconfig.debug +++ b/kernel/rcu/Kconfig.debug @@ -168,4 +168,18 @@ config RCU_STRICT_GRACE_PERIOD when looking for certain types of RCU usage bugs, for example, too-short RCU read-side critical sections. + +config RCU_DYNTICKS_TORTURE + bool "Minimize RCU dynticks counter size" + depends on RCU_EXPERT + default n + help + This option controls the width of the dynticks counter. + + Lower values will make overflows more frequent, which will increase + the likelihood of extending grace-periods. This option sets the width + to its minimum usable value. + + This has no value for production and is only for testing. + endmenu # "RCU Debugging"