Received: by 10.223.185.116 with SMTP id b49csp1767569wrg; Thu, 22 Feb 2018 02:48:09 -0800 (PST) X-Google-Smtp-Source: AH8x2266pyIhW6OP5QaxfWWyTfRM2y6LHKKthsqDRmQ2clN+mGcci3cIy8jDcgY9hKYVbZIBxxWk X-Received: by 2002:a17:902:d682:: with SMTP id v2-v6mr1712443ply.348.1519296489662; Thu, 22 Feb 2018 02:48:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519296489; cv=none; d=google.com; s=arc-20160816; b=XvfaUU5HEkHT+RNm861HjnHuS4QpHIvMXxUB0uB1LM0AYwFL0tZ7xgJJhdZcKgv2k5 Fai774cwSCgXFfhqRvagZsF9uO5KWGVN+5prcKIj+KfCSVVzx6FPFcb4McrM2JZ4F3Nu 5Sr0geYYnHJa9a6uSSXnq5w46GUaFjLw1br4Q/GzM2SnzdS7BsEqE9iubIGJ1Mr653C4 oHUiLeuP9CWZzuLsP9Sg4kC36TU6kvqiEMM0kFE1KU0sL26WUfc8ONFeJTMerhkf+llY kTihakq5nHDX6Sttc+ydbOHALqHsAbcf1/0RtCi2qy63lXhVxbsz+pi456XZzXBpRyT5 r++w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:cms-type :content-transfer-encoding:date:message-id:in-reply-to:cc:to:from :reply-to:subject:mime-version:dkim-signature:dkim-filter :arc-authentication-results; bh=7wsizaohuh4EUGOJmG7VuVyetm91yGSf+KUvEAxFzOA=; b=LPtTZJYz0wz0DbW9wV4uasAH6Xo/dzUhzMlCiVsVVbYw/dhc8loIrQRlsjsjMrYWPd kjlQ7gEsipudiOhsQ8s/aGS4qyyX4LRbO29MLXk/eon6b1glhaBVRqewerbTbarBu4Cr gKrk+hOWyky3Ibma5YUCE1HI8AxnLUlAKJlWH3NChN/7leCee4k6UmF2CswLeP1ilDWa sFEiUz/q2ysklY/3Aohhfe3PKTd/2uGzrLyvXX4AkBeqpHa0xILsZ3T9UdR20aQiZjj0 basWhOml+Me1buLjU7rK7HOYEdY7uCb1OSMF0+I+csS8R2NzdE/L6Ud/qZ8MiHiMBLLt xjIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=ZidrptRA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a7-v6si2508287pll.581.2018.02.22.02.47.54; Thu, 22 Feb 2018 02:48:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=ZidrptRA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753488AbeBVKqi (ORCPT + 99 others); Thu, 22 Feb 2018 05:46:38 -0500 Received: from mailout1.samsung.com ([203.254.224.24]:52638 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753348AbeBVKqg (ORCPT ); Thu, 22 Feb 2018 05:46:36 -0500 Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20180222104634epoutp01d53b700960555b4ecbec4ebe8b9782fb~VoAV8iw1r1622816228epoutp01S for ; Thu, 22 Feb 2018 10:46:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20180222104634epoutp01d53b700960555b4ecbec4ebe8b9782fb~VoAV8iw1r1622816228epoutp01S DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1519296394; bh=7wsizaohuh4EUGOJmG7VuVyetm91yGSf+KUvEAxFzOA=; h=Subject:Reply-To:From:To:CC:In-Reply-To:Date:References:From; b=ZidrptRA75eMTIZRjcxHvbYYUT65y/Uh5VwJpbmCIpTaYsBZZhtYzmG/Z96oUlCNj DYuHc0l955JrR09ztqLCu3N6Kt5l4II3zaEISrkin4kOUb1K0gJG1lEzs5rJVybHEj GMIByYrpunhqxzSihMQiYTkCQuupPkJ6H/PNFyL0= Received: from epsmges5p3new.samsung.com (unknown [182.195.42.75]) by epcas5p4.samsung.com (KnoxPortal) with ESMTP id 20180222104634epcas5p4391ce1fdeb0c1a03ffac2327046c5dea~VoAVsA-nz1175811758epcas5p4_; Thu, 22 Feb 2018 10:46:34 +0000 (GMT) X-AuditID: b6c32a4b-cb9ff70000001126-81-5a8e9f8a14e2 Received: from epcas5p1.samsung.com ( [182.195.41.39]) by epsmges5p3new.samsung.com (Symantec Messaging Gateway) with SMTP id 1A.98.04390.A8F9E8A5; Thu, 22 Feb 2018 19:46:34 +0900 (KST) Mime-Version: 1.0 Subject: RE: Re: [PATCH] fanotify: allow freeze on suspend when waiting for response from userspace Reply-To: k.shubham@samsung.com From: Kunal Shubham To: "jack@suse.cz" CC: VIVEK TRIVEDI , "amir73il@gmail.com" , "linux-fsdevel@vger.kernel.org" , "linux-kernel@vger.kernel.org" , PANKAJ MISHRA , Kunal Shubham X-Priority: 3 X-Content-Kind-Code: NORMAL In-Reply-To: <20180216102913.jcgvc5rhjqtzlkb6@quack2.suse.cz> X-Drm-Type: Y,confirm X-Msg-Generator: Mail X-Msg-Type: PERSONAL X-Reply-Demand: N Message-ID: <20180222094454epcms5p15e3538bdba8bcbc036dc379583bc3a55@epcms5p1> Date: Thu, 22 Feb 2018 15:14:54 +0530 X-CMS-MailID: 20180222094454epcms5p15e3538bdba8bcbc036dc379583bc3a55 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: REQ_APPROVE X-MTR: 20180222094454epcms5p15e3538bdba8bcbc036dc379583bc3a55 CMS-TYPE: 105P X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprGKsWRmVeSWpSXmKPExsWy7bCmum7X/L4og6dbpSwurFvNaDF7ejOT xcFlM5kt9uw9yWJxedccNot7b7YyWbzs28jmwO6xc9Zddo++LasYPc4sOMLu8XmTXABLFJdN SmpOZllqkb5dAlfGhgvv2QtW2Fcs2cHZwLjMqouRk0NCwETi/fTF7F2MXBxCArsZJY5O3MXY xcjBwSsgKPF3hzBIjbBAqsTrzTcYQWwhAXmJT4tvMkPEdSVaJqwEi7MJaEvMXbKfFcQWEVCU uLvzPCvITGaB5UwSu99OY4NYxisxo/0pC4QtLbF9+VawZk4BW4kXLxdBxUUl/jQ8hbPfH5vP CGGLSLTeO8sMYQtKPPi5GyouI7HywjkWkGUSAs2MEusOHGeCcHoYJR583QS12Vzi/Mn5YN28 Ar4Saw/+YQKxWQRUJdqO9EDVuEhM7ZoP9gIz0DvLFr5mBoUEs4CmxPpd+hAlshJTT61jAglL AB198I4PRDWfRO/vJ0wwP+6YB2MrS6xqu8oKYUtKXLrazgjR6iHR+ih1AqPSLERIz0KydhbC 2gWMzKsYJVMLinPTU4tNC4zzUsv1ihNzi0vz0vWS83M3MYJTi5b3DsZN53wOMQpwMCrx8EaU 9EYJsSaWFVfmHmKU4GBWEuFdGtoXJcSbklhZlVqUH19UmpNafIhRmoNFSZzXMdAlSkggPbEk NTs1tSC1CCbLxMEp1cCYFXyfv1nutqzBCx8xLsvFqlb/DfLqLLd3c7nZcJqop2gt3rpe9PYS u/74bwLhdrPcm7bo+l3l+Vxta9VfOknK2bapYnvZk5urrE+yfpw5e6GdRNWf9IjpR8vMf609 t05H0qVeZd/iF412WVl8n069bPaXu1X3Zkc8c7O763v2isutb63ZtZVYijMSDbWYi4oTAeSS Oq0pAwAA X-CMS-RootMailID: 20180216094525epcas5p1e52ea815ed7dfb7516578384dedcf5ae X-RootMTR: 20180216094525epcas5p1e52ea815ed7dfb7516578384dedcf5ae References: <20180216102913.jcgvc5rhjqtzlkb6@quack2.suse.cz> <1518774280-38090-1-git-send-email-t.vivek@samsung.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org >> On Fri 16-02-18 15:14:40, t.vivek=40samsung.com wrote: >> From: Vivek Trivedi >>=20 >> If fanotify userspace response server thread is frozen first, >> it may fail to send response from userspace to kernel space listener. >> In this scenario, fanotify response listener will never get response >> from userepace and fail to suspend. >>=20 >> Use freeze-friendly wait API to handle this issue. >>=20 >> Same problem was reported here: >> https://bbs.archlinux.org/viewtopic.php?id=3D232270 >>=20 >> Freezing of tasks failed after 20.005 seconds >> (1 tasks refusing to freeze, wq_busy=3D0) >>=20 >> Backtrace: >> =5B=5D (__schedule) from =5B=5D (schedule+0x4c/0xa4) >> =5B=5D (schedule) from =5B=5D (fanotify_handle_event= +0x1c8/0x218) >> =5B=5D (fanotify_handle_event) from =5B=5D (fsnotify= +0x17c/0x38c) >> =5B=5D (fsnotify) from =5B=5D (security_file_open+0x= 88/0x8c) >> =5B=5D (security_file_open) from =5B=5D (do_dentry_o= pen+0xc0/0x338) >> =5B=5D (do_dentry_open) from =5B=5D (vfs_open+0x54/0= x58) >> =5B=5D (vfs_open) from =5B=5D (do_last.isra.10+0x45c= /0xcf8) >> =5B=5D (do_last.isra.10) from =5B=5D (path_openat+0x= 424/0x600) >> =5B=5D (path_openat) from =5B=5D (do_filp_open+0x3c/= 0x98) >> =5B=5D (do_filp_open) from =5B=5D (do_sys_open+0x120= /0x1e4) >> =5B=5D (do_sys_open) from =5B=5D (SyS_open+0x28/0x2c= ) >> =5B=5D (SyS_open) from =5B=5D (__sys_trace_return+0x= 0/0x20) > > Yeah, good catch. > >> =40=40 -63,7 +64,9 =40=40 static int fanotify_get_response(struct fsnoti= fy_group *group, >> =20 >> pr_debug(=22%s: group=3D%p event=3D%p=5Cn=22, __func__, group, event); >> =20 >> - wait_event(group->fanotify_data.access_waitq, event->response); >> + while (=21event->response) >> + wait_event_freezable(group->fanotify_data.access_waitq, >> + event->response); > > But if the process gets a signal while waiting, we will just livelock the > kernel in this loop as wait_event_freezable() will keep returning > ERESTARTSYS. So you need to be a bit more clever here... Hi Jack, Thanks for the quick review. To avoid livelock issue, is it fine to use below change?=20 If agree, I will send v2 patch. =40=40 -63,7 +64,11 =40=40 static int fanotify_get_response(struct fsnotify= _group *group, pr_debug(=22%s: group=3D%p event=3D%p=5Cn=22, __func__, group, even= t); - wait_event(group->fanotify_data.access_waitq, event->response); + while (=21event->response) =7B + if (wait_event_freezable(group->fanotify_data.access_waitq, + event->response)) + flush_signals(current); + =7D Thanks =C2=A0=0D=0A---------=20Original=20Message=20---------=0D=0ASender=20:=20Ja= n=20Kara=C2=A0=0D=0ADate=20=20=20:=202018-02-16=2015:59=20(= GMT+5:30)=0D=0ATitle=20=20:=20Re:=20=5BPATCH=5D=20fanotify:=20allow=20freez= e=20on=20suspend=20when=20waiting=20for=20response=20from=20userspace=0D=0A= To=20:=20VIVEK=20TRIVEDI=0D=0ACC=20:=20jack=40suse.c= z,=20amir73il=40gmail.com,=20linux-fsdevel=40vger.kernel.org,=20linux-kerne= l=40vger.kernel.org,=20PANKAJ=20MISHRA,=20Kunal=20S= hubham=0D=0A=C2=A0=0D=0AOn=C2=A0Fri=C2=A016-02-18= =C2=A015:14:40,=C2=A0t.vivek=40samsung.com=C2=A0wrote:=0D=0A>=C2=A0From:=C2= =A0Vivek=C2=A0Trivedi=C2=A0=0D=0A>=C2=A0=0D=0A>=C2= =A0If=C2=A0fanotify=C2=A0userspace=C2=A0response=C2=A0server=C2=A0thread=C2= =A0is=C2=A0frozen=C2=A0first,=0D=0A>=C2=A0it=C2=A0may=C2=A0fail=C2=A0to=C2= =A0send=C2=A0response=C2=A0from=C2=A0userspace=C2=A0to=C2=A0kernel=C2=A0spa= ce=C2=A0listener.=0D=0A>=C2=A0In=C2=A0this=C2=A0scenario,=C2=A0fanotify=C2= =A0response=C2=A0listener=C2=A0will=C2=A0never=C2=A0get=C2=A0response=0D=0A= >=C2=A0from=C2=A0userepace=C2=A0and=C2=A0fail=C2=A0to=C2=A0suspend.=0D=0A>= =C2=A0=0D=0A>=C2=A0Use=C2=A0freeze-friendly=C2=A0wait=C2=A0API=C2=A0to=C2= =A0handle=C2=A0this=C2=A0issue.=0D=0A>=C2=A0=0D=0A>=C2=A0Same=C2=A0problem= =C2=A0was=C2=A0reported=C2=A0here:=0D=0A>=C2=A0https://bbs.archlinux.org/vi= ewtopic.php?id=3D232270=0D=0A>=C2=A0=0D=0A>=C2=A0Freezing=C2=A0of=C2=A0task= s=C2=A0failed=C2=A0after=C2=A020.005=C2=A0seconds=0D=0A>=C2=A0(1=C2=A0tasks= =C2=A0refusing=C2=A0to=C2=A0freeze,=C2=A0wq_busy=3D0)=0D=0A>=C2=A0=0D=0A>= =C2=A0Backtrace:=0D=0A>=C2=A0=5B=5D=C2=A0(__schedule)=C2=A0from= =C2=A0=5B=5D=C2=A0(schedule+0x4c/0xa4)=0D=0A>=C2=A0=5B= =5D=C2=A0(schedule)=C2=A0from=C2=A0=5B=5D=C2=A0(fanotify_handle_e= vent+0x1c8/0x218)=0D=0A>=C2=A0=5B=5D=C2=A0(fanotify_handle_event)= =C2=A0from=C2=A0=5B=5D=C2=A0(fsnotify+0x17c/0x38c)=0D=0A>=C2=A0= =5B=5D=C2=A0(fsnotify)=C2=A0from=C2=A0=5B=5D=C2=A0(secu= rity_file_open+0x88/0x8c)=0D=0A>=C2=A0=5B=5D=C2=A0(security_file_= open)=C2=A0from=C2=A0=5B=5D=C2=A0(do_dentry_open+0xc0/0x338)=0D= =0A>=C2=A0=5B=5D=C2=A0(do_dentry_open)=C2=A0from=C2=A0=5B=5D=C2=A0(vfs_open+0x54/0x58)=0D=0A>=C2=A0=5B=5D=C2=A0(vfs_open= )=C2=A0from=C2=A0=5B=5D=C2=A0(do_last.isra.10+0x45c/0xcf8)=0D=0A>= =C2=A0=5B=5D=C2=A0(do_last.isra.10)=C2=A0from=C2=A0=5B= =5D=C2=A0(path_openat+0x424/0x600)=0D=0A>=C2=A0=5B=5D=C2=A0(path_= openat)=C2=A0from=C2=A0=5B=5D=C2=A0(do_filp_open+0x3c/0x98)=0D=0A= >=C2=A0=5B=5D=C2=A0(do_filp_open)=C2=A0from=C2=A0=5B=5D= =C2=A0(do_sys_open+0x120/0x1e4)=0D=0A>=C2=A0=5B=5D=C2=A0(do_sys_o= pen)=C2=A0from=C2=A0=5B=5D=C2=A0(SyS_open+0x28/0x2c)=0D=0A>=C2=A0= =5B=5D=C2=A0(SyS_open)=C2=A0from=C2=A0=5B=5D=C2=A0(__sy= s_trace_return+0x0/0x20)=0D=0A=C2=A0=0D=0AYeah,=C2=A0good=C2=A0catch.=0D=0A= =C2=A0=0D=0A>=C2=A0=40=40=C2=A0-63,7=C2=A0+64,9=C2=A0=40=40=C2=A0static=C2= =A0int=C2=A0fanotify_get_response(struct=C2=A0fsnotify_group=C2=A0*group,= =0D=0A>=C2=A0=C2=A0=0D=0A>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0pr_debug(=22%s:=C2=A0group=3D%p=C2=A0event=3D%p=5Cn=22,=C2=A0__= func__,=C2=A0group,=C2=A0event);=0D=0A>=C2=A0=C2=A0=0D=0A>=C2=A0-=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0wait_event(group->fanotify_data.acce= ss_waitq,=C2=A0event->response);=0D=0A>=C2=A0+=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0while=C2=A0(=21event->response)=0D=0A>=C2=A0+=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0wait_event_freezable(group->fanotify_data.access_waitq,=0D=0A>= =C2=A0+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0event->response);=0D=0A=C2=A0=0D=0ABut=C2=A0if=C2=A0the=C2=A0process= =C2=A0gets=C2=A0a=C2=A0signal=C2=A0while=C2=A0waiting,=C2=A0we=C2=A0will=C2= =A0just=C2=A0livelock=C2=A0the=0D=0Akernel=C2=A0in=C2=A0this=C2=A0loop=C2= =A0as=C2=A0wait_event_freezable()=C2=A0will=C2=A0keep=C2=A0returning=0D=0AE= RESTARTSYS.=C2=A0So=C2=A0you=C2=A0need=C2=A0to=C2=A0be=C2=A0a=C2=A0bit=C2= =A0more=C2=A0clever=C2=A0here...=0D=0A=C2=A0=0D=0A=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Honza=0D=0A--= =C2=A0=0D=0AJan=C2=A0Kara=C2=A0=0D=0ASUSE=C2=A0Labs,=C2=A0= CR=0D=0A=C2=A0=0D=0A=C2=A0