Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp1914635lqz; Tue, 2 Apr 2024 01:12:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXnBtc/Pyh/bGdqVOCsPTp86J86x5VqzHyxLgfl4U8+rb4toFskCxFQFODWRewQzsPAgoa92Wav7lkcecehvdlc5/1gtRBTymP4PFFyMA== X-Google-Smtp-Source: AGHT+IF3X1FtT3UEvQxWB4al3Wvtim/msTwDh+UhwEy9KeoQb1AJ1mgeBWg/PRGTugltAxmsyVf7 X-Received: by 2002:a05:6402:520f:b0:56d:f3f3:f61f with SMTP id s15-20020a056402520f00b0056df3f3f61fmr432080edd.9.1712045567910; Tue, 02 Apr 2024 01:12:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712045567; cv=pass; d=google.com; s=arc-20160816; b=EmF8K3EKoDM97REND3u0gSnA2Z1Y+ib1lw8zRgZz//njqz//QCMYDp7EY+Juuf7Z0f JcRKZ6R+SmnVinWS+wcKYlB6Am64t/xQz7R3VikZ3zGg526JEWj9aNyOt/30ouCyjyJs W1nvt1Zo5t7/qRWbj3waUOTPubo93QXmLnOEvm21xnzOCbFyuW5vOiLwcDr5YEgZyx31 sa0/8UXnkDXFzBMxIRVUbY5sr/QAEp01sVJ5+G/TDHBbW1laclHdPWKlDUhUB5OIAb75 T1Pf6pApO1yi3TUz5TofyIWR6NGc8EeEANefLsQJ488w95wx8Q3tH0QHfn2WsOj83e8L t69A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=d4nRvJ0c59zUyR8ezgAHKzFD+7G8QnVomCEdYphyOZA=; fh=qRXECnOTLBpYuqQbGuC11UOFFx9QcWlv9ipjLq7AJfY=; b=0+2iek7VGH+iHPDKIB0Mk/f96XuDEMGOUeKiabVrlExyNM/hh6T4gsYxRE57mkH+aP ihRzsv9777YUi4zy984TXzAG9I6mHcrnyaCgHiGdhjU5UnfwBVkUDqNHf3pFroQR+KTI yGyw38loTKyVqIo0M+qsrZjPHXwG4YQL3QemfzToN1MPBPFsGet+f/DEFCz2z5o0a+7Z gBfPogpHmuc17XqtdLrx3kz6RJWWExMAgqP6w8nFviEAcNzuiVFMnOxmNwNSofWhSYbZ y7SsCrSWDbi/OAVXxlMG3o/q+tkqUGoiBBSN9KJAac7sh39UpAvsE88fLpMrIxMfdXEz Jt2g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=O88CmPZU; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-127529-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-127529-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id fd23-20020a056402389700b0056bafe03017si5601149edb.617.2024.04.02.01.12.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Apr 2024 01:12:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-127529-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=O88CmPZU; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-127529-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-127529-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.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 am.mirrors.kernel.org (Postfix) with ESMTPS id 067791F2293D for ; Tue, 2 Apr 2024 08:12:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3695E3D969; Tue, 2 Apr 2024 08:12:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="O88CmPZU" Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) (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 E3C5945007 for ; Tue, 2 Apr 2024 08:12:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.61.82.184 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712045560; cv=none; b=u2N1ktF4ybuSKQ35R1Cux2lgNCCuUMCx1x2r93uhRlyjEPeJ5bYcS/qSZaiyWJPxLTlA0FIe+agIbC6u00c40DEoVQ7sh2b+OnznusrrMO023x2t6g7JJSA936ssjO627762BPKbQQmWENqyKenz6S/xwjshcK17QwcV/M5TVnA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712045560; c=relaxed/simple; bh=5lhu8bkA4ICih9Qc8yz1RpFgwQC1a6ZaDAdiBJ/ytt4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EMjewVja1GE7EW8N4xKlnEmEg7HlunIGFPdqG8HDe+37YGXmCpOoIMR14k6sxe6EaYBmx6wa4tTZ03UqSgUX9FPD4JMtvs1WFBVdlRgU5bikuIH5CloNyeVpBKjxESYoZ7btzUJ2TpRll7uGQM4ei2eRZ92pQhNtzKHYL5bd0o8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=O88CmPZU; arc=none smtp.client-ip=210.61.82.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: bde17668f0c811ee935d6952f98a51a9-20240402 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=d4nRvJ0c59zUyR8ezgAHKzFD+7G8QnVomCEdYphyOZA=; b=O88CmPZUqkw0d5Ku+niN01bdy5m91N9rFlOXocdLkbhoWEzGPET0ZydKqWl3YBaa7clFW5oK0+/HO32jEveKw9E4GXxCb81AUfWjlca6DX6Z2EhfIAin8hKofh90+UxkIIYGyNghGMaAQ5kaKwgdbN5iX1PoFj54+lRo3avLZHg=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.37,REQID:eee8753e-3c77-4049-a53d-ee9db0624979,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:6f543d0,CLOUDID:d8331f91-e2c0-40b0-a8fe-7c7e47299109,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: bde17668f0c811ee935d6952f98a51a9-20240402 Received: from mtkmbs14n1.mediatek.inc [(172.21.101.75)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1646343256; Tue, 02 Apr 2024 16:12:26 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Tue, 2 Apr 2024 16:12:25 +0800 Received: from mbjsdccf07.gcn.mediatek.inc (10.15.20.246) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Tue, 2 Apr 2024 16:12:24 +0800 From: Guoyong Wang To: "Jason A . Donenfeld" , Theodore Ts'o , Tejun Heo , Lai Jiangshan , "Matthias Brugger" , AngeloGioacchino Del Regno CC: , , , , "Guoyong Wang" Subject: Re: [PATCH] random: Fix the issue of '_might_sleep' function running in an atomic contex Date: Tue, 2 Apr 2024 16:12:14 +0800 Message-ID: <20240402081214.2723-1-guoyong.wang@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20240320090242.10318-1-guoyong.wang@mediatek.com> References: <20240320090242.10318-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 X-TM-AS-Product-Ver: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-AS-Result: No-10--11.181500-8.000000 X-TMASE-MatchedRID: VfovoVrt/oZq0U6EhO9EEya1MaKuob8PC/ExpXrHizyo+b+yOP0oGAAt 9g7dvMC1IKdjJZRyIZmrMtdnoedbNxHzG0HT5tBb/1aBDnIV4ikWTveLitVUgcwHSQ+yXjTD/VQ G3oVfx34Pu+MfgwheR2w5+V5bC8rHsEBAuoaUqK8QNC45RlqcS167veYUroY0yWCL+8tLbvaPdB sWkfHN7SQPHPUuX+yXwFVmU96WjVi8f06ZoOZQY0KcYi5Qw/RVQrO4XR6BRQNgg+UjPGL1RUTNC ucTZFZapt+BKnbPggH9KP9acIz8sx8TzIzimOwPVnRXm1iHN1bEQdG7H66TyH4gKq42LRYkIxUs k7Y5zqotD17eyPoKssqg3Bx5SzilnGVR9vPBa4t+3BndfXUhXQ== X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--11.181500-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: 06C58068D73256DA76C0B51F75B979DDFF4EDD0C74A25AEFEA31C055BBFF53672000:8 X-MTK: N On Web, 20 Mar 2024 02:09:21 +0100, Jason A. Donenfeld wrote: >> Hi Jason, >> >> Thanks for your suggestions. >> >> I am inclined to accept your second suggestion. My reluctance to accept >> the first is due to the concern that "&& !in_atomic()" could potentially >> alter the original meaning of the 'execute_in_process_context' interface. >> Regarding the third suggestion, modifying the logic associated with 'input' >> is not recommended. > > Doesn't something like the below seem simplest? Just move the call out > of the spinlock and we're done. > > diff --git a/drivers/input/input-core-private.h b/drivers/input/input-core-private.h > index 116834cf8868..717f239e28d0 100644 > --- a/drivers/input/input-core-private.h > +++ b/drivers/input/input-core-private.h > @@ -10,7 +10,7 @@ > struct input_dev; > > void input_mt_release_slots(struct input_dev *dev); > -void input_handle_event(struct input_dev *dev, > +bool input_handle_event(struct input_dev *dev, > unsigned int type, unsigned int code, int value); > > #endif /* _INPUT_CORE_PRIVATE_H */ > diff --git a/drivers/input/input.c b/drivers/input/input.c > index f71ea4fb173f..2faf46218c66 100644 > --- a/drivers/input/input.c > +++ b/drivers/input/input.c > @@ -391,20 +391,22 @@ static void input_event_dispose(struct input_dev *dev, int disposition, > } > } > > -void input_handle_event(struct input_dev *dev, > +bool input_handle_event(struct input_dev *dev, > unsigned int type, unsigned int code, int value) > { > int disposition; > +bool should_contribute_to_rng = false; > > lockdep_assert_held(&dev->event_lock); > > disposition = input_get_disposition(dev, type, code, &value); > if (disposition != INPUT_IGNORE_EVENT) { > if (type != EV_SYN) > -add_input_randomness(type, code, value); > +should_contribute_to_rng = true; > > input_event_dispose(dev, disposition, type, code, value); > } > +return should_contribute_to_rng; > } > > /** > @@ -428,12 +430,15 @@ void input_event(struct input_dev *dev, > unsigned int type, unsigned int code, int value) > { > unsigned long flags; > +bool should_contribute_to_rng; > > if (is_event_supported(type, dev->evbit, EV_MAX)) { > > spin_lock_irqsave(&dev->event_lock, flags); > -input_handle_event(dev, type, code, value); > +should_contribute_to_rng = input_handle_event(dev, type, code, value); > spin_unlock_irqrestore(&dev->event_lock, flags); > +if (should_contribute_to_rng) > +add_input_randomness(type, code, value); > } > } > EXPORT_SYMBOL(input_event); Hi Jason, As I mentioned last time: Your solution may not be applicable when 'input_event' is executed in users spinlock. What are you thoughts on this? I'm looking forward to your suggestions so we can reach an agreement and expedite the upstream process, Thanks!