Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp463052lqt; Mon, 18 Mar 2024 13:00:54 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUzvQ8wHWzO43YerV7hiW4T1dJiYHG237mmCfe3gzljMNLhE1m2D88leJDnYa7GKuEtzvWYZNLxYffWM1KDpAonBx74+TDt5iilkkayEw== X-Google-Smtp-Source: AGHT+IFmxV95lEfmrDZfioC3Hqrko+8xmJVyUQSrwvbgPOc5LkkLYnOn/1Yr6JWi4vb22AW2uMFH X-Received: by 2002:a05:620a:1358:b0:789:ed17:507f with SMTP id c24-20020a05620a135800b00789ed17507fmr8484028qkl.36.1710792054473; Mon, 18 Mar 2024 13:00:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710792054; cv=pass; d=google.com; s=arc-20160816; b=uto1yGRBFip1AsC5IuJ5VarCOJwfXbUmqrXA0vy31DZrt5HKwsO/bW9gCcfKjDWVuX T6WqdJI0anoKbQ3JcA1phtkBADFHl3Zc6yuuC+IwOcfqSWNXrWrGmdepJeD+EOjWIjUr eabX3fwYQEq7I5qO8CYV6zaSN1vqkr+tOtINWIXQNOCzVM9JKLaFQVxAp+5Zhmrt6+IA OWMhq2aXzjzT4kcukr8eRUv8PoCA3hemr8GuBO0m0OSJk7tfWa85+fFfhnaslYIGVo9q DttWPFUM5zMS2wc2R/7NyI6KhImc/Byx4IAl+COxPDW9WdLZH3djEJgqSm8h/tGtYwG3 2Xag== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=x/ouslTaGHLCxb1m+bGhdTdK1PrUUCc7ZDIw9C0aeXY=; fh=k9mYeTSFf0HcQrgJuFP7xrG3Pg6aOcvLT1Pu6TDt6Bs=; b=IXWwRPfKXeqX9DF1F4nnsOzBUoOKb/jaSOlDi42mkGx3KMbxCpojT5To+/qhZnYc8v YzDaeF7QxtJKV4PmKZDveZWr1f39y8SWCJg5TC7yL+zB7AQ/iQE8kE7/nGTCGEd04sj/ 3e1pUY9tNdtyJ+Tx/WT4zrrJFuV6sc8pZp5v+BnoWAzENeL7iSRXsH4Hf+Ooe1skBi3F kCiz7jJxLhWaIZOBZyqQXaanaoRqCFxFfWlR+9aDhP7fcN1PgYYV57gr1iZGFr0rRZNY rofJ6Yc0TGSVMHWRVuzW6kY9JL6arTWAoMmFWnQj3fJTEz+BPWVO8A/yiy4ORI5SEtti UJqQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=ceug2BPQ; arc=pass (i=1 dkim=pass dkdomain=zx2c4.com); spf=pass (google.com: domain of linux-kernel+bounces-106590-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-106590-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=zx2c4.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id xz20-20020a05620a5e1400b00789e8f9c85esi6701547qkn.47.2024.03.18.13.00.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 13:00:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-106590-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=ceug2BPQ; arc=pass (i=1 dkim=pass dkdomain=zx2c4.com); spf=pass (google.com: domain of linux-kernel+bounces-106590-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-106590-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=zx2c4.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 2D6D31C21C7C for ; Mon, 18 Mar 2024 20:00:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A11BC57865; Mon, 18 Mar 2024 20:00:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="ceug2BPQ" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6DA9155C14 for ; Mon, 18 Mar 2024 20:00:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710792048; cv=none; b=GuDzhRwGuh0kuN9riZlXYZML6wCfho5Hr5WZ9XO/ZWPpJbA2DZHnFbuA3032uaSpz8VYkhRKjuhXJxjLcgIfw26T6dWbeL5Gpdbz/dRHkJutEdcHJ9JuxNLwyXk+hXQ9Y1SiZsZWo/ArqJxi6012p2D8t9EcfYMj0oeZkJcmEJQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710792048; c=relaxed/simple; bh=el0HPdAPF4mHn0BlNYeNhSj/Fplf86ilRk12/hHw6cg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HDa2MmxcDS3I1zDO5i4Avii0hm9D7QXkY4LA0zkH0NUlDv2n7ednckwDzzBiPWMjQlVN9vi58equIxr0OQMgdGT9FRa8xctwEbkeOevziZvHQVTHCg/+iMvZPNxTQjJ18UtDycRhgFKv5TZSALHDbq2uL+jhlpyCkvwW4sEFUc8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b=ceug2BPQ; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE556C433C7; Mon, 18 Mar 2024 20:00:46 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="ceug2BPQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1710792045; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=x/ouslTaGHLCxb1m+bGhdTdK1PrUUCc7ZDIw9C0aeXY=; b=ceug2BPQdk5IAlFjKlflM+G9KtwVWLB93z8vnCZtBAbfbqZIn5P8Hv+q61AMG9xV1Kulz8 P7fnBvzrGFm9KRmIKizhg0LM5oOUlWn5xbnKQuSRVTmy9fd8T+1hhQWeNEX2CYzE1Sk7w8 jD/XacaQSEOhyjssoqUtuaXsFyM35UY= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id b4eb4cb4 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 18 Mar 2024 20:00:44 +0000 (UTC) Date: Mon, 18 Mar 2024 21:00:42 +0100 From: "Jason A. Donenfeld" To: Guoyong Wang Cc: Theodore Ts'o , Tejun Heo , Lai Jiangshan , Matthias Brugger , AngeloGioacchino Del Regno , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, wsd_upstream@mediatek.com Subject: Re: [PATCH] random: Fix the issue of '_might_sleep' function running in an atomic contex Message-ID: References: <20240318075327.26318-1-guoyong.wang@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20240318075327.26318-1-guoyong.wang@mediatek.com> Hi Guoyong, On Mon, Mar 18, 2024 at 03:53:27PM +0800, Guoyong Wang wrote: > 'input_handle_event' runs in an atomic context > (spinlock). In rare instances, it may call > the '_might_sleep' function, which could trigger > a kernel exception. > > Backtrace: > [] die+0xa8/0x2fc > [] bug_handler+0x44/0xec > [] brk_handler+0x90/0x144 > [] do_debug_exception+0xa0/0x148 > [] el1_dbg+0x60/0x7c > [] el1h_64_sync_handler+0x38/0x90 > [] el1h_64_sync+0x64/0x6c > [] __might_resched+0x1fc/0x2e8 > [] __might_sleep+0x44/0x7c > [] cpus_read_lock+0x1c/0xec > [] static_key_enable+0x14/0x38 > [] crng_set_ready+0x14/0x28 > [] execute_in_process_context+0xb8/0xf8 > [] _credit_init_bits+0x118/0x1dc > [] add_timer_randomness+0x264/0x270 > [] add_input_randomness+0x38/0x48 > [] input_handle_event+0x2b8/0x490 > [] input_event+0x6c/0x98 Thanks for reporting this. I'm wondering, though, rather than introducing a second function, maybe execute_in_process_context() should just gain a `&& !in_atomic()`. That'd make things a bit simpler. However, I'm pretty sure in_atomic() isn't actually a reliable way of determining that, depending on config. So maybe this should just call the worker always (if system_wq isn't null). Alternatively, any chance the call to add_input_randomness() could be moved outside the spinlock, or does this not look possible? Jason