From owner-freebsd-current@freebsd.org Fri Mar 17 13:53:50 2017 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 85526D10810 for ; Fri, 17 Mar 2017 13:53:50 +0000 (UTC) (envelope-from rmacklem@uoguelph.ca) Received: from CAN01-QB1-obe.outbound.protection.outlook.com (mail-eopbgr660049.outbound.protection.outlook.com [40.107.66.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (Client CN "mail.protection.outlook.com", Issuer "Microsoft IT SSL SHA2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 18D631D32; Fri, 17 Mar 2017 13:53:49 +0000 (UTC) (envelope-from rmacklem@uoguelph.ca) Received: from YTXPR01MB0189.CANPRD01.PROD.OUTLOOK.COM (10.165.218.133) by YTXPR01MB0191.CANPRD01.PROD.OUTLOOK.COM (10.165.218.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.961.17; Fri, 17 Mar 2017 13:53:47 +0000 Received: from YTXPR01MB0189.CANPRD01.PROD.OUTLOOK.COM ([10.165.218.133]) by YTXPR01MB0189.CANPRD01.PROD.OUTLOOK.COM ([10.165.218.133]) with mapi id 15.01.0961.022; Fri, 17 Mar 2017 13:53:47 +0000 From: Rick Macklem To: Konstantin Belousov CC: Dimitry Andric , Ian Lepore , "Gergely Czuczy" , FreeBSD Current Subject: Re: process killed: text file modification Thread-Topic: process killed: text file modification Thread-Index: AQHSnqPLfXcZwdtVHkecT5jK6Yv9dKGYQJIXgAAZ/baAAFsxgIAAVqF+ Date: Fri, 17 Mar 2017 13:53:46 +0000 Message-ID: References: <646c1395-9482-b214-118c-01573243ae5a@harmless.hu> <45436522-77df-f894-0569-737a6a74958f@harmless.hu> <55189643.aaZPuY77s8@ralph.baldwin.cx> <3ed3e4a3-23af-7267-39f1-9090093c9c1e@harmless.hu> <5ac94b9a-7ced-9eff-d746-7dddaaeca516@harmless.hu> <1489340839.40576.82.camel@freebsd.org> , <20170317083605.GQ16105@kib.kiev.ua> In-Reply-To: <20170317083605.GQ16105@kib.kiev.ua> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: yes X-MS-TNEF-Correlator: authentication-results: gmail.com; dkim=none (message not signed) header.d=none;gmail.com; dmarc=none action=none header.from=uoguelph.ca; x-ms-office365-filtering-correlation-id: 48211e51-80e4-4117-a36c-08d46d3d0892 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:YTXPR01MB0191; x-microsoft-exchange-diagnostics: 1; YTXPR01MB0191; 7:ZQM7FDUkJSMu4Pkh1rNjxps07q/vo6xEYONgNyQ4kpKIRs6Ep8Jw8vIWmN0iSKPC/pbJDm9XipiEPxCvgTA/q17WqYwqd/Bk97srKJ6uLQg3FdMvq3Fzaq45GDUM4I+AbqNDYTOIb2amZwMk1ThlX7NMpLFX9bI9wP34H5+LNU0GfiMd8Ukj05DWHBQmDgAirL0qaiQjRErYGivewCbhtGZy8OE9HyawhtUnq90IMhkfySf6Q7IHicwf2+Q3b6DsM471h9RUhH682w49Jjc/Y8s0Cp658imAvJgaei2Tdn/z2bQecxJdU4SowC55gxVDTNXLmpAAORFCnJxgI8wr7A== x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(158342451672863)(75325880899374); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(102415395)(6040375)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6041248)(20161123562025)(20161123564025)(20161123560025)(20161123558025)(20161123555025)(6072148); SRVR:YTXPR01MB0191; BCL:0; PCL:0; RULEID:; SRVR:YTXPR01MB0191; x-forefront-prvs: 0249EFCB0B x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(39450400003)(39830400002)(39410400002)(377454003)(43234003)(51444003)(24454002)(229853002)(86362001)(77096006)(6506006)(4326008)(5660300001)(102836003)(5890100001)(1411001)(93886004)(122556002)(39060400002)(53936002)(99936001)(6306002)(9686003)(3280700002)(74316002)(50986999)(189998001)(53546008)(76176999)(54356999)(2906002)(6916009)(305945005)(2950100002)(81156014)(8676002)(81166006)(966004)(74482002)(6436002)(38730400002)(6246003)(2900100001)(110136004)(7696004)(55016002)(8936002)(54906002)(33656002)(3660700001); DIR:OUT; SFP:1101; SCL:1; SRVR:YTXPR01MB0191; H:YTXPR01MB0189.CANPRD01.PROD.OUTLOOK.COM; FPR:; SPF:None; MLV:ovrnspm; PTR:InfoNoRecords; LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: multipart/mixed; boundary="_002_YTXPR01MB0189F7147A7C5C5F8C56B2F1DD390YTXPR01MB0189CANP_" MIME-Version: 1.0 X-OriginatorOrg: uoguelph.ca X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Mar 2017 13:53:46.9092 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: be62a12b-2cad-49a1-a5fa-85f4f3156a7d X-MS-Exchange-Transport-CrossTenantHeadersStamped: YTXPR01MB0191 X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Mar 2017 13:53:50 -0000 --_002_YTXPR01MB0189F7147A7C5C5F8C56B2F1DD390YTXPR01MB0189CANP_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Well, I don't mind adding ncl_flush(), but it shouldn't be necessary. I actually had it in the first rendition of the patch, but took it out because it should happen on the VOP_CLOSE() if any writing to the buffer cache happened and that code hasn't changed in many years. What the patch was missing was updating n_mtime after the dirty page flush. Btw, a flush without OBJPC_SYNC happens when the file is VOP_CLOSE()'d unless the default value of vfs.nfs.clean_[ages_on_close is changed, which I think is why the 1sec resolution always seemed to work, at least for the example where there was an munmap before close. Attached is an updated version with that in it, rick ________________________________________ From: owner-freebsd-current@freebsd.org = on behalf of Konstantin Belousov Sent: Friday, March 17, 2017 4:36:05 AM To: Rick Macklem Cc: Dimitry Andric; Ian Lepore; Gergely Czuczy; FreeBSD Current Subject: Re: process killed: text file modification On Fri, Mar 17, 2017 at 03:10:57AM +0000, Rick Macklem wrote: > Hope you don't mind a top post... > Attached is a little patch you could test maybe? > > rick > ________________________________________ > From: owner-freebsd-current@freebsd.org on behalf of Rick Macklem > Sent: Thursday, March 16, 2017 9:57:23 PM > To: Dimitry Andric; Ian Lepore > Cc: Gergely Czuczy; FreeBSD Current > Subject: Re: process killed: text file modification > > Dimitry Andric wrote: > [lots of stuff snipped] > > I'm also running into this problem, but while using lld. I must set > > vfs.timestamp_precision to 1 (e.g. sec + ns accurate to 1/HZ) on both > > the client and the server, to make it work. > > > > Instead of GNU ld, lld uses mmap to write to the output executable. If > > this executable is more than one page, and resides on an NFS share, > > running it will almost always result in "text file modification", if > > vfs_timestamp_precision >=3D 2. > > > > A small test case: http://www.andric.com/freebsd/test-mmap-write.c, > > which writes a simple "hello world" i386-freebsd executable file, using > > the sequence: open() -> ftruncate() -> mmap() -> memcpy() -> munmap() -= > > > close(). > Hopefully Kostik will correct me if I have this wrong, but I don't believ= e any > of the above syscalls guarantee that dirty pages have been flushed. > At least for cases without munmap(), the writes of dirty pages can occur = after > the file descriptor is closed. I run into this in NFSv4, where there is a= Close (NFSv4 one) > that can't be done until VOP_INACTIVE(). > If you look in the NFS VOP_INACTIVE() { called ncl_inactive() } you'll se= e: > if (NFS_ISV4(vp) && vp->v_type =3D=3D VREG) { > 237 /* > 238 * Since mmap()'d files do I/O after VOP_CLOSE(),= the NFSv4 > 239 * Close operations are delayed until now. Any di= rty > 240 * buffers/pages must be flushed before the close= , so that the > 241 * stateid is available for the writes. > 242 */ > 243 if (vp->v_object !=3D NULL) { > 244 VM_OBJECT_WLOCK(vp->v_object); > 245 retv =3D vm_object_page_clean(vp->v_objec= t, 0, 0, > 246 OBJPC_SYNC); > 247 VM_OBJECT_WUNLOCK(vp->v_object); > 248 } else > 249 retv =3D TRUE; > 250 if (retv =3D=3D TRUE) { > 251 (void)ncl_flush(vp, MNT_WAIT, NULL, ap->a= _td, 1, 0); > 252 (void)nfsrpc_close(vp, 1, ap->a_td); > 253 } > 254 } > Note that nothing like this is done for NFSv3. > What might work is implementing a VOP_SET_TEXT() vnode op for the NFS > client that does most of the above (except for nfsrpc_close()) and then s= ets > VV_TEXT. > --> That way, all the dirty pages will be flushed to the server before th= e executable > starts executing. > > > Running this on an NFS share, and then attempting to run the resulting > > 'helloworld' executable will result in the "text file modification" > > error, and it will be killed. But if you simply copy the executable to > > something else, then it runs fine, even if you use -p to retain the > > properties! > > > > IMHO this is a rather surprising problem with the NFS code, and Kostik > > remarked that the problem seems to be that the VV_TEXT flag is set too > > early, before the nfs cache is invalidated. Rick, do you have any idea= s > > about this? > I don't think it is the "nfs cache" that needs invalidation, but the dirt= y > pages written by the mmap'd file need to be flushed, before the VV_TEXT > is set, I think? > > If Kostik meant "attribute cache" when he said "nfs cache", I'll note tha= t the > cached attributes (including mtime) are updated by the reply to every wri= te. > (As such, I think it is the writes that must be done before setting VV_TE= XT > that is needed.) > > It is a fairly simple patch to create. I'll post one to this thread in a = day or so > unless Kostik thinks this isn't correct and not worth trying. > I think that the patch is in right direction, but I am not convinced that it is enough. What we need is to ensure that mtime on server does not change after VV_TEXT is set. Dirty pages indeed would cause the mtime update on flush, but wouldn't dirty buffers writes cause the same issue ? In other words, I think that enchanced VOP_SET_TEXT() for nfs must flush everything to ensure that mtime on server would not change due to further actions by this machine' nfs client. _______________________________________________ freebsd-current@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/freebsd-current To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org" --_002_YTXPR01MB0189F7147A7C5C5F8C56B2F1DD390YTXPR01MB0189CANP_ Content-Type: application/octet-stream; name="textmod.patch" Content-Description: textmod.patch Content-Disposition: attachment; filename="textmod.patch"; size=1343; creation-date="Fri, 17 Mar 2017 13:49:47 GMT"; modification-date="Fri, 17 Mar 2017 13:49:47 GMT" Content-Transfer-Encoding: base64 LS0tIGZzL25mc2NsaWVudC9uZnNfY2x2bm9wcy5jLnRleHQJMjAxNy0wMy0xNiAyMTo1NToxNi4y NjMzOTMwMDAgLTA0MDAKKysrIGZzL25mc2NsaWVudC9uZnNfY2x2bm9wcy5jCTIwMTctMDMtMTcg MDk6MzE6MjMuNjMyODE0MDAwIC0wNDAwCkBAIC0xNDAsNiArMTQwLDcgQEAgc3RhdGljIHZvcF9h ZHZsb2NrX3QJbmZzX2FkdmxvY2s7CiBzdGF0aWMgdm9wX2FkdmxvY2thc3luY190IG5mc19hZHZs b2NrYXN5bmM7CiBzdGF0aWMgdm9wX2dldGFjbF90IG5mc19nZXRhY2w7CiBzdGF0aWMgdm9wX3Nl dGFjbF90IG5mc19zZXRhY2w7CitzdGF0aWMgdm9wX3NldF90ZXh0X3QgbmZzX3NldF90ZXh0Owog CiAvKgogICogR2xvYmFsIHZmcyBkYXRhIHN0cnVjdHVyZXMgZm9yIG5mcwpAQCAtMTc2LDYgKzE3 Nyw3IEBAIHN0cnVjdCB2b3BfdmVjdG9yIG5ld25mc192bm9kZW9wcyA9IHsKIAkudm9wX3dyaXRl ID0JCW5jbF93cml0ZSwKIAkudm9wX2dldGFjbCA9CQluZnNfZ2V0YWNsLAogCS52b3Bfc2V0YWNs ID0JCW5mc19zZXRhY2wsCisJLnZvcF9zZXRfdGV4dCA9CQluZnNfc2V0X3RleHQsCiB9OwogCiBz dHJ1Y3Qgdm9wX3ZlY3RvciBuZXduZnNfZmlmb29wcyA9IHsKQEAgLTMzNzMsNiArMzM3NSwyOSBA QCBuZnNfc2V0YWNsKHN0cnVjdCB2b3Bfc2V0YWNsX2FyZ3MgKmFwKQogCXJldHVybiAoZXJyb3Ip OwogfQogCitzdGF0aWMg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