From patchwork Fri Nov 1 19:54:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boqun Feng X-Patchwork-Id: 13859728 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 25ECBE6F085 for ; Fri, 1 Nov 2024 19:56:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7EF686B0099; Fri, 1 Nov 2024 15:56:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 79FCF6B009A; Fri, 1 Nov 2024 15:56:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 618FC6B009B; Fri, 1 Nov 2024 15:56:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 4337B6B0099 for ; Fri, 1 Nov 2024 15:56:02 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 00A7D80E43 for ; Fri, 1 Nov 2024 19:56:01 +0000 (UTC) X-FDA: 82738580736.03.F042279 Received: from mail-qv1-f49.google.com (mail-qv1-f49.google.com [209.85.219.49]) by imf21.hostedemail.com (Postfix) with ESMTP id 808C81C000A for ; Fri, 1 Nov 2024 19:55:05 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="mi/ndHGU"; spf=pass (imf21.hostedemail.com: domain of boqun.feng@gmail.com designates 209.85.219.49 as permitted sender) smtp.mailfrom=boqun.feng@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730490877; 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=V/wo6tn5xum2AVMECmALlIc/sY7DW4M/ZUa/SRoull4=; b=sXTWCsK8I7A8KGQH5sr4cpfvBOcv0l//15YWkWXeILWWIB1UJaBgX4UTsOSBcU6mRYf/xg Q/kyUBjjnSFcpVe+5U1jlj0jlv9QJ0+4/vNemYenShNcwXhtoKDaL+sDT+3H6xpnmrHRQb rS3Iw8u3SqnaqDCeupaRpLZNBQ6/EGY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730490877; a=rsa-sha256; cv=none; b=448tjePVgMmG6CeN6LzkSEBB/NzCqq240DIZUipq3RyH9ks2qph0JcWAqk/N84ODxizgWh xDwcC31SrsG6BmkMfRz5kPPHMZNAmCN510HR91gaHl1gRz/zAhiBmT28f0tw0/lUkLX6kQ LZ+Gd4JuXLPfQi1Prr+shMVSlkGj4RI= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="mi/ndHGU"; spf=pass (imf21.hostedemail.com: domain of boqun.feng@gmail.com designates 209.85.219.49 as permitted sender) smtp.mailfrom=boqun.feng@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-qv1-f49.google.com with SMTP id 6a1803df08f44-6cbce8d830dso14238766d6.1 for ; Fri, 01 Nov 2024 12:55:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730490959; x=1731095759; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:from:to:cc:subject :date:message-id:reply-to; bh=V/wo6tn5xum2AVMECmALlIc/sY7DW4M/ZUa/SRoull4=; b=mi/ndHGUw0/J07GzwSAc6BMy2dqa8+bwtlxJb05QHN2YMY2fUMoFO5PYQadzoAh6K1 3tgufxeEdMZ2BdmUZEVcQxRdXXyPP4Clt+ZLY/0unON8IcnOiJIBjS5GrmmMrzUYQaTK neWItRYS1eEtN9proY1eJHDXeqlKGHzosEuPsIIMPDs2IxXGo1I2Lll9W2b6++xhGFII qkDTtnii3842MUrLd4u7GNRgiZ3JMHYC4v+p9FBGP1jItBgPhEMDDgohes9Z4gsfCtgg ZXspB2jHkGLNQThM7BjReb52kxAXJY/RrJFMhS/LE6XBj51emHEpXj8RDLqaPmtTQx5v 6BVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730490959; x=1731095759; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=V/wo6tn5xum2AVMECmALlIc/sY7DW4M/ZUa/SRoull4=; b=fMJtB3L6ryHBbBZbPDWik8McP1YmFGBV5wKGKomk54L29HO7VmAh0wYdQgPQpydHYg 4HQwtGvE+U4kmCQRUGIhU87kBRg2vJej+0U9NdMVoDRvNiNgkV3bPsOSxbjm/AG30HPx aaIBZ2LsH6m0XCk5ylCCgsqHXUIVSqySa12cf++x/rcwWBqspAXovYNS7pmzzCsKIYEU 1mxsNGpx5Dn93LItQj9aykzDrwOeiN+pI5UZqCo4vwSUT5xxAgMEvzG686d242mYNTB0 zlx9qahHJgqBh/j8XMPn/OnFy+2RorlTysH9uD+3FCc27JFpha07EmRAPeAIE7+bxbDV 59Iw== X-Forwarded-Encrypted: i=1; AJvYcCXHYk92u9Z8F+4QlBF+amDhscNkH41h8UEk7dsx5lwh/hsRpPxt2phecvIRB6dkr58OOxiMsvmhnQ==@kvack.org X-Gm-Message-State: AOJu0YzWOLJaXigM7oVPNCLSe6yCJdfdBfnQ++BSIq2q5hWeijqpVq+Q DaAeDnQI/+IAkoSce8yi5u3qSGNt/MQjOVRyUnKzSfCxQvPaRF3s X-Google-Smtp-Source: AGHT+IFPagyvh5cj1suOH5cWI+VLHf+AeDKM7KQP+P4BRYdYB9fU3T/yM3NaTN4fYGjak0m3mhjnvQ== X-Received: by 2002:a05:6214:5d86:b0:6cb:e52c:c8dd with SMTP id 6a1803df08f44-6d35c1aeed4mr49651226d6.53.1730490958752; Fri, 01 Nov 2024 12:55:58 -0700 (PDT) Received: from fauth-a2-smtp.messagingengine.com (fauth-a2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d353f9e057sm22585066d6.1.2024.11.01.12.55.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Nov 2024 12:55:58 -0700 (PDT) Received: from phl-compute-10.internal (phl-compute-10.phl.internal [10.202.2.50]) by mailfauth.phl.internal (Postfix) with ESMTP id BFA231200043; Fri, 1 Nov 2024 15:55:57 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-10.internal (MEProxy); Fri, 01 Nov 2024 15:55:57 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdekledguddvlecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddt necuhfhrohhmpeeuohhquhhnucfhvghnghcuoegsohhquhhnrdhfvghnghesghhmrghilh drtghomheqnecuggftrfgrthhtvghrnhepgffhffevhffhvdfgjefgkedvlefgkeegveeu heelhfeivdegffejgfetuefgheeinecuffhomhgrihhnpehkvghrnhgvlhdrohhrghenuc evlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegsohhquhhn odhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdeiledvgeehtdeigedqudejje ekheehhedvqdgsohhquhhnrdhfvghngheppehgmhgrihhlrdgtohhmsehfihigmhgvrdhn rghmvgdpnhgspghrtghpthhtohepudekpdhmohguvgepshhmthhpohhuthdprhgtphhtth hopehprghulhhmtghksehkvghrnhgvlhdrohhrghdprhgtphhtthhopegsihhgvggrshih sehlihhnuhhtrhhonhhigidruggvpdhrtghpthhtohepvhgsrggskhgrsehsuhhsvgdrtg iipdhrtghpthhtohepvghlvhgvrhesghhoohhglhgvrdgtohhmpdhrtghpthhtoheplhhi nhhugidqnhgvgihtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinh hugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepkhgr shgrnhdquggvvhesghhoohhglhgvghhrohhuphhsrdgtohhmpdhrtghpthhtoheplhhinh hugidqmhhmsehkvhgrtghkrdhorhhgpdhrtghpthhtohepshhfrhestggrnhgsrdgruhhu ghdrohhrghdrrghu X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 1 Nov 2024 15:55:57 -0400 (EDT) From: Boqun Feng To: paulmck@kernel.org Cc: Sebastian Andrzej Siewior , Vlastimil Babka , Marco Elver , linux-next@vger.kernel.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, sfr@canb.auug.org.au, longman@redhat.com, cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, Thomas Gleixner , Peter Zijlstra , Boqun Feng Subject: [PATCH] scftorture: Use workqueue to free scf_check Date: Fri, 1 Nov 2024 12:54:38 -0700 Message-ID: <20241101195438.1658633-1-boqun.feng@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Stat-Signature: tt37my1x8uwhrp5or8np7hs3q1nqdyoi X-Rspamd-Queue-Id: 808C81C000A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NrvlI5rFSC34hdSkaXuFxGuWI1pi9rmnyckFiMyVZ8M8Y0BuGT3weI/kVmbvYIBksG4X3gl5Bp8NqZqeiO5btmmPW/UapLS4+ax12drnroOipxVCYw3VcZGwKR5JKBayUtYnztkq87qh4VW5EVwnALxXPNUSARkL/emZZz8knXgPav/rDIqwnYXprkZ3YQouUSL1vsSOi0AkBdHXnC2Kj1yZHfKZ2VZLY6QwTntIpJ/bA6DTK0C7q8G9I+Ismc7lzdCKVZdsZeqyGXRFfEOHVJ/pt7jP8rIGYscEiRqZR5/NAadmu5yMhWkinaNDSYCI/IWirLIAHQr9V706sfU5b/RVkK1vRriHNL32KigeQKqYyKgvmWImw7N3N6b8G2cxDFo9Lb0aT/MGdBFYXdVuFzVpBj/30yPon6m6ESRdZf1MnEqc9eKgRbzp0LzENR4APgOARzTOgtJ7yIRRSS2b8Hl77kQdIHGX0MM5Q== 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: Paul reported an invalid wait context issue in scftorture catched by lockdep, and the cause of the issue is because scf_handler() may call kfree() to free the struct scf_check: static void scf_handler(void *scfc_in) { [...] } else { kfree(scfcp); } } (call chain anlysis from Marco Elver) This is problematic because smp_call_function() uses non-threaded interrupt and kfree() may acquire a local_lock which is a sleepable lock on RT. The general rule is: do not alloc or free memory in non-threaded interrupt conntexts. A quick fix is to use workqueue to defer the kfree(). However, this is OK only because scftorture is test code. In general the users of interrupts should avoid giving interrupt handlers the ownership of objects, that is, users should handle the lifetime of objects outside and interrupt handlers should only hold references to objects. Reported-by: "Paul E. McKenney" Link: https://lore.kernel.org/lkml/41619255-cdc2-4573-a360-7794fc3614f7@paulmck-laptop/ Signed-off-by: Boqun Feng --- kernel/scftorture.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/kernel/scftorture.c b/kernel/scftorture.c index 44e83a646264..ab6dcc7c0116 100644 --- a/kernel/scftorture.c +++ b/kernel/scftorture.c @@ -127,6 +127,7 @@ static unsigned long scf_sel_totweight; // Communicate between caller and handler. struct scf_check { + struct work_struct work; bool scfc_in; bool scfc_out; int scfc_cpu; // -1 for not _single(). @@ -252,6 +253,13 @@ static struct scf_selector *scf_sel_rand(struct torture_random_state *trsp) return &scf_sel_array[0]; } +static void kfree_scf_check_work(struct work_struct *w) +{ + struct scf_check *scfcp = container_of(w, struct scf_check, work); + + kfree(scfcp); +} + // Update statistics and occasionally burn up mass quantities of CPU time, // if told to do so via scftorture.longwait. Otherwise, occasionally burn // a little bit. @@ -296,7 +304,10 @@ static void scf_handler(void *scfc_in) if (scfcp->scfc_rpc) complete(&scfcp->scfc_completion); } else { - kfree(scfcp); + // Cannot call kfree() directly, pass it to workqueue. It's OK + // only because this is test code, avoid this in real world + // usage. + queue_work(system_wq, &scfcp->work); } } @@ -335,6 +346,7 @@ static void scftorture_invoke_one(struct scf_statistics *scfp, struct torture_ra scfcp->scfc_wait = scfsp->scfs_wait; scfcp->scfc_out = false; scfcp->scfc_rpc = false; + INIT_WORK(&scfcp->work, kfree_scf_check_work); } } switch (scfsp->scfs_prim) {