Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp2747413pxb; Mon, 31 Jan 2022 03:31:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJyFy1dj+rQodwsmov1XfPt7/j4GtBt9EvVgOGLQdxYYZrB2pHR051H+IN+5PzrXzSsoQKCc X-Received: by 2002:a17:90b:3447:: with SMTP id lj7mr23872777pjb.39.1643628663768; Mon, 31 Jan 2022 03:31:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643628663; cv=none; d=google.com; s=arc-20160816; b=h5kQBp7zogpmcVE+E7wAdz6zvY1NYe5wi2j2JwNhQFXTyRcB37bJYPB0gVn7eWBZf3 wBEVptVD9p1Jw9/23fAYREjOzgzFYslclkTLez9YnM3qE0krMUDSw+Yuxlaf99l9cR1L +lgXKsqYC6njJeinH8SjZbbAppwP78hdhuDWuveJk+CI/Uo/qeXnsWzvJ5HuXnMVgnWP AZAvkitkOyzqMMrJBo9TJy1bOnNvEmJ7OY0K+4s4ioCRJ4hZ1DiKc79+oPZ4nSSYUWVR no1NneO/W2OPQdBm8u3V2YrzIpaJWy5BlrfM1GpWqQMH9mTd9PwVkcH+tNYmDDp/l07w eK7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=3eJ4roU6+z1xVvJm915h/1usfy+Lk/4syU09UHRxkp4=; b=nu8TZFFnMpRfd6b6ZN6sGsKlxlD7Ma+1q35g1bPE3PTjaI4k3uKXarcu5OGLqTjEGN 5UECcj6Widq0+YTNWMOvpOMHeq7XzqCSDjmAlennulPM1c4S5patXRmLu4OdcO+kzx68 iKKXK2z2ba9HfYef/3lnHmYKX8dgU9qmv0Qnv41lpXdYRK/tzMrSROCtWiwrZHCeflQ5 sRPOre0ZNEq+rMFMwo2E8O5zHs6C3egiWxmF7n3QtRfaSd4lWjyszR02atJ3RRrQuzyh YqMjXjyiaOD4xbHXM2qTM3L4zR6/3uloQChe0DrePKWyvCsXJLXV2kXX87yszbpSrpWi giGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.net header.s=badeba3b8450 header.b=h0NBAwfP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmx.net Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 16si13676599pfm.354.2022.01.31.03.30.52; Mon, 31 Jan 2022 03:31:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.net header.s=badeba3b8450 header.b=h0NBAwfP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmx.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350186AbiA1SFj (ORCPT + 99 others); Fri, 28 Jan 2022 13:05:39 -0500 Received: from mout.gmx.net ([212.227.17.20]:56351 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349942AbiA1SFi (ORCPT ); Fri, 28 Jan 2022 13:05:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1643393109; bh=iRFt1KYMfjxrsMdt+zhDL0zzqnVvCTO/KxVzMNkb37Y=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:References:In-Reply-To; b=h0NBAwfPe525EStPtOQSPoVTQtrKjEHtGFPL4e0qFZaOo/17BBxl3TQxwJJjSI1yf Xyj2x6Jq/b/nffgU6moyZ2vxxZd6xdOPiV0l/P+GA0bC22xJ4uRIVkuA/g4H3RaWbx TvuFh86tiIMNJAv4TS8CcojkP8m5UzCXYsp+LRMI= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from longitude ([5.146.194.160]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MbRfl-1mgvxU1Eoz-00bpvj; Fri, 28 Jan 2022 19:05:09 +0100 Date: Fri, 28 Jan 2022 19:05:06 +0100 From: Jonathan =?utf-8?Q?Neusch=C3=A4fer?= To: "Jason A. Donenfeld" Cc: Andy Lutomirski , Jonathan =?utf-8?Q?Neusch=C3=A4fer?= , Theodore Ts'o , linux-kernel@vger.kernel.org, Sebastian Andrzej Siewior , Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long , Boqun Feng , Andy Lutomirski , stable@vger.kernel.org Subject: Re: [PATCH] random: remove batched entropy locking Message-ID: References: <20220128153344.34211-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="A6vXYDstX4zHSKyS" Content-Disposition: inline In-Reply-To: <20220128153344.34211-1-Jason@zx2c4.com> X-Provags-ID: V03:K1:Jhr2awT3cVJ7/eSIUG9/WCfAfuc1z9OpNH/Arnzirp3sObV29Yf ely1xPuoPvdbBHHI174GL7Br5di++9BxlflHCDXaFxsacJiBwyD67mOCihryUbVSsKtMQMk THcVx0Cbn2rbI03P8WNfRK7on+01Jt24Pzlx4jAmxLVQULMzRgnxNrjWEixjSV6i7PTTfDN xA/t3AUWyndP5eZHvnr9w== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:EQeQOkdOfwc=:KvDIMuABLM1L7ZUn3XdGgp ac+TTLtI8nJ6z3rCugjB0li/3WNbrjGTVP8CuHFaMy1WGn0qfktLERcvrKmR7HiLYGYEjviLu MzK2+SnQRW2XfImwtUWmi+DUZmBl+KhbgasXUcy7PTKQ45VzpByfLYFvvXKiYsGJrq7zFWCHY OAUwpEOxAxYW/V9dMW3RbWam77G9WqswM/lTrxaF8AYLPZ4HIeIejaul94rZcb09g9GA+9ibB +IzBg3Bj9jLsrR2Nrw/hhenEiG+6r/rqkMq4CVDXLwVzGSHjYetr1OK92pFscNCgyawLuj37s H2So6Z6AQ6O/GLiRj3dkmGP8B+xXuEmXzp80lqLN6FCSXSHGyF+tzmsBv9stUDrm4ZW7btBU+ YSpS/erA3+QfjyM/4SqnqUbxnrJxt6zv7dVV8AbBvhcVejSDgb23WwsSRhXEySz4JcGfn3IRk jYl4eBJvnLoPfc+Pq6h5UGqy5EyauToL58HukOkA3r+MlTPVbxQspxI1QhchffMTvE84y4+B0 yaIoy9WthVf/EvyPD+CKUSHE6WTS3Beu5emq3OhJis7NdLoOe2+HSD5aqsLBgd4HOyc9dKUOX 2NsPSpeGY7Ad+HuVfu+9lkB9X3rY2JP+bk1odn0KGNL5H1VGyAFOe/NDJCHjUUajDSnhl+Raq 5oK7LYmSGdm1BV2SjKSeyS+WaB2HdBLEfMUtpbI8HPu2zGlpoYTyyhFUdEOwJ4O4QrEbI5rM7 3/7O2cuoEmxEGcI37hHU/3l3WfoYzZRZUKZp5oasuQRuIeQU91rzpVE7Hs/OD0acNya8qB8zw 3s0zeD9YcggmrlyZWCl/QkASruLrGOsbm2WSMUyaytbIddZ0dT5md8+e26mAttwPYDybT9KzP qXt2VuueTalKp0VMSH/nUNjt+1rvx5t6CKp7qxYWg8z5MJgA4GHoOmArv3eIPEq5yADy5HRZR CqvuT16nGP3MAmkNYNARC8Egd1qpg1QtjO0lR2G27qx8gmPKHoGTYHdU0GWl023cbbt/bRlyS FzDumjdyEoaSvSwXOum2o88WzdszpPGo8/YoE/yPz68O1bIkrfzbDwEcMm+3mdwq2d1DhN/AO wDiw7+hhrLej3k= Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --A6vXYDstX4zHSKyS Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jan 28, 2022 at 04:33:44PM +0100, Jason A. Donenfeld wrote: > From: Andy Lutomirski >=20 > We don't need spinlocks to protect batched entropy -- all we need > is a little bit of care. This should fix up the following splat that > Jonathan received with a PROVE_LOCKING=3Dy/PROVE_RAW_LOCK_NESTING=3Dy > kernel: >=20 > [ 2.500000] [ BUG: Invalid wait context ] > [ 2.500000] 5.17.0-rc1 #563 Not tainted > [ 2.500000] ----------------------------- > [ 2.500000] swapper/1 is trying to lock: > [ 2.500000] c0b0e9cc (batched_entropy_u32.lock){....}-{3:3}, at: inval= idate_batched_entropy+0x18/0x4c > [ 2.500000] other info that might help us debug this: > [ 2.500000] context-{2:2} > [ 2.500000] 3 locks held by swapper/1: > [ 2.500000] #0: c0ae86ac (event_mutex){+.+.}-{4:4}, at: event_trace_i= nit+0x4c/0xd8 > [ 2.500000] #1: c0ae81b8 (trace_event_sem){+.+.}-{4:4}, at: event_tra= ce_init+0x68/0xd8 > [ 2.500000] #2: c19b05cc (&sb->s_type->i_mutex_key#2){+.+.}-{4:4}, at= : start_creating+0x40/0xc4 > [ 2.500000] stack backtrace: > [ 2.500000] CPU: 0 PID: 1 Comm: swapper Not tainted 5.17.0-rc1 #563 > [ 2.500000] Hardware name: WPCM450 chip > [ 2.500000] [] (unwind_backtrace) from [] (show_st= ack+0x10/0x14) > [ 2.500000] [] (show_stack) from [] (__lock_acquir= e+0x3f0/0x189c) > [ 2.500000] [] (__lock_acquire) from [] (lock_acqu= ire+0x2b8/0x354) > [ 2.500000] [] (lock_acquire) from [] (_raw_spin_l= ock_irqsave+0x60/0x74) > [ 2.500000] [] (_raw_spin_lock_irqsave) from [] (i= nvalidate_batched_entropy+0x18/0x4c) > [ 2.500000] [] (invalidate_batched_entropy) from [= ] (crng_fast_load+0xf0/0x110) > [ 2.500000] [] (crng_fast_load) from [] (add_inter= rupt_randomness+0x138/0x200) > [ 2.500000] [] (add_interrupt_randomness) from [] = (handle_irq_event_percpu+0x18/0x38) > [ 2.500000] [] (handle_irq_event_percpu) from [] (= handle_irq_event+0x38/0x5c) > [ 2.500000] [] (handle_irq_event) from [] (handle_= fasteoi_irq+0x9c/0x114) > [ 2.500000] [] (handle_fasteoi_irq) from [] (handl= e_irq_desc+0x24/0x34) > [ 2.500000] [] (handle_irq_desc) from [] (generic_= handle_arch_irq+0x28/0x3c) > [ 2.500000] [] (generic_handle_arch_irq) from [] (= __irq_svc+0x54/0x80) > [ 2.500000] Exception stack(0xc1485d48 to 0xc1485d90) > [ 2.500000] 5d40: 9780e804 00000001 c09413d4 200000d= 3 60000053 c016af54 > [ 2.500000] 5d60: 00000000 c0afa5b8 c14194e0 c19a1d48 c0789ce0 0000000= 0 c1490480 c1485d98 > [ 2.500000] 5d80: c0168970 c0168984 20000053 ffffffff > [ 2.500000] [] (__irq_svc) from [] (read_seqbegin.= constprop.0+0x6c/0x90) > [ 2.500000] [] (read_seqbegin.constprop.0) from []= (d_lookup+0x14/0x40) > [ 2.500000] [] (d_lookup) from [] (lookup_dcache+0= x18/0x50) > [ 2.500000] [] (lookup_dcache) from [] (lookup_one= _len+0x90/0xe0) > [ 2.500000] [] (lookup_one_len) from [] (start_cre= ating+0x68/0xc4) > [ 2.500000] [] (start_creating) from [] (tracefs_c= reate_file+0x30/0x11c) > [ 2.500000] [] (tracefs_create_file) from [] (trac= e_create_file+0x14/0x38) > [ 2.500000] [] (trace_create_file) from [] (event_= create_dir+0x310/0x420) > [ 2.500000] [] (event_create_dir) from [] (__trace= _early_add_event_dirs+0x28/0x50) > [ 2.500000] [] (__trace_early_add_event_dirs) from [] (event_trace_init+0x70/0xd8) > [ 2.500000] [] (event_trace_init) from [] (tracer_= init_tracefs+0x14/0x284) > [ 2.500000] [] (tracer_init_tracefs) from [] (do_o= ne_initcall+0xdc/0x288) > [ 2.500000] [] (do_one_initcall) from [] (kernel_i= nit_freeable+0x1c4/0x20c) > [ 2.500000] [] (kernel_init_freeable) from [] (ker= nel_init+0x10/0x110) > [ 2.500000] [] (kernel_init) from [] (ret_from_for= k+0x14/0x3c) > [ 2.500000] Exception stack(0xc1485fb0 to 0xc1485ff8) > [ 2.500000] 5fa0: 00000000 0000000= 0 00000000 00000000 > [ 2.500000] 5fc0: 00000000 00000000 00000000 00000000 00000000 0000000= 0 00000000 00000000 > [ 2.500000] 5fe0: 00000000 00000000 00000000 00000000 00000013 00000000 >=20 > Signed-off-by: Andy Lutomirski > [Jason: I extracted this from a larger in-progress series of Andy's that > also unifies the two batches into one and does other performance > things. Since that's still under development, but because we need this > part to fix the CONFIG_PROVE_RAW_LOCK_NESTING issue, I've extracted it > out and applied it to the current setup. This will also make it easier > to backport to old kernels that also need the fix. I've also amended > Andy's original commit message.] > Reported-by: Jonathan Neusch=C3=A4fer > Link: https://lore.kernel.org/lkml/YfMa0QgsjCVdRAvJ@latitude/ > Fixes: b7d5dc21072c ("random: add a spinlock_t to struct batched_entropy") > Cc: Sebastian Andrzej Siewior > Cc: stable@vger.kernel.org > Signed-off-by: Jason A. Donenfeld > --- > Andy - could you take a look at this and let me know if it's still > correct after I've ported it out of your series and into a standalone > thing here? I'd prefer to hold off on moving forward on this until I > receive our green light. I'm also still a bit uncertain about your NB: > comment regarding the acceptable race. If you could elaborate on that > argument, it might save me a few cycles with my thinking cap on. >=20 > drivers/char/random.c | 57 ++++++++++++++++++++++++------------------- > 1 file changed, 32 insertions(+), 25 deletions(-) FWIW, this does fix the splat on my machine. Tested-by: Jonathan Neusch=C3=A4fer Thanks everyone, Jonathan --A6vXYDstX4zHSKyS Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEvHAHGBBjQPVy+qvDCDBEmo7zX9sFAmH0MDEACgkQCDBEmo7z X9tbKQ/8CxYH4spoiEoNY8v6/3PnyLR2TJQ2rfaUAXnij/S4JsaFH5oXZ/58nqug N5i0jEdqju0gaKNyZ9uUk+4uGt94CeYyYj3idkYl6GxVgTGvtv+ori/q78+LOU8y IoNKaQE+nJj7/j2oecbkYgazoIAPNCnyy33y4nVUKgU4hO4sUT1M2uDNegU8lk51 RfTGIOb8Dyk/311wuDe030bJv0N+p68Pwk/m2nUv9dgbE17r2iyG+FCm2Ej/Tw3t gTQuYm1qgv52BAMCBkARC19Vp4GJApJ9oDW/Y5/eG8Y+fIJYe8QZwbL5sGDx8IQz JjWzmwj36K9CFGZTH8LhxFHSr/YUn4vqP/wI6N9MR90L6hOPXcYqA1K9oawKlP1V seNd2BMxqBG9x5x7PCDQc/xBbhwjDqS4jdK9s5qHRxLuLo99XESlrxY0iJKxKTxT yt+/0BrPwSGexf/EBQDXMy8cmADdsp4yfLYVlQfQVdKrOfKxFPFaB2mMtOnC9DO/ rPsp7CE4GpnJSGnV5gqz0KZnhtSzWRAKzPsT+DW9vBgp7z9HFf+XDKeAeYFLtnRf UWxArDDxjGqxaw/Nq064iovXog/TbIR/jTLI1mEiLBJMah+xfaDa4zSsNmtHzEdq jQCT/Ivf0a8QrGf8HIxCm+gxeugCyNQo7RteDkUyXA6X3M57Fb0= =ESBe -----END PGP SIGNATURE----- --A6vXYDstX4zHSKyS--