From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751828AbdB0WrD (ORCPT ); Mon, 27 Feb 2017 17:47:03 -0500 Received: from mail-ve1eur01on0103.outbound.protection.outlook.com ([104.47.1.103]:16608 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751630AbdB0WrA (ORCPT ); Mon, 27 Feb 2017 17:47:00 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=avagin@virtuozzo.com; Date: Mon, 27 Feb 2017 14:43:47 -0800 From: Andrei Vagin To: Cyrill Gorcunov CC: , , , , , , , , , , Andrey Vagin Subject: Re: [RFC 2/3] kcmp: Add KCMP_EPOLL_TFD mode to compare epoll target files Message-ID: <20170227224346.GA7101@outlook.office365.com> References: <20170221171255.023016858@openvz.org> MIME-Version: 1.0 Content-Type: text/plain; charset="koi8-r" Content-Disposition: inline In-Reply-To: <20170221171255.023016858@openvz.org> User-Agent: Mutt/1.7.1 (2016-10-04) X-Originating-IP: [162.246.95.100] X-ClientProxiedBy: BN6PR03CA0004.namprd03.prod.outlook.com (10.168.230.142) To VI1PR0801MB1982.eurprd08.prod.outlook.com (10.173.74.15) X-MS-Office365-Filtering-Correlation-Id: aba0eea8-ea20-456b-e40f-08d45f6221ac X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:VI1PR0801MB1982; X-Microsoft-Exchange-Diagnostics: 1;VI1PR0801MB1982;3:/SjWlydOkk4mDvOblf2H+hzQIL/LgWfBq+aHQ+CcnxC6V4VcD7htEOU7rKHg9XmDpDNnFUTxzaJDx+cDGEwYLG9o68L55nuj8eXqrYsYqViHYjjLdz72daqrtHGlBRb5CehnljAtHvMR9b+XQKSfYAYoe5a8gVmd4y8U+zZvRufAF37P0BdEzsx+jJmJEgPyu2PDAJtntBoEDYj4Aqr10tWEO73owgFHDFpw7IrlCaN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qsdXc0AD1yVk9M30lmp8KN32mIaRGraptgz+aWqQAK3HRQfafhkpYbw3INFECFDswPoZfl9tsjyiM5hw7gmKR/vToWK4kW2UD/3zLaBGT6ZxiDq8tbcPmwZtjR8ynOo104dAU9d3BlhrrGZXP+2g0fR8= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(17755550239193); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6041248)(20161123558025)(20161123564025)(20161123562025)(20161123555025)(20161123560025)(6072148);SRVR:VI1PR0801MB1982;BCL:0;PCL:0;RULEID:;SRVR:VI1PR0801MB1982; X-Microsoft-Exchange-Diagnostics: 1;VI1PR0801MB1982;4:rcY+x2pauOdtbq6bP+j//Z/IRdix1bXhrGvyUuKbZlSdR7h/UgCgcDmcj9tCQ7bjF4wy21bL95dD/kkhoYzG4EOx4qt3IKBCZzHw9QNkUJ5vU171GphhUBSf6ufDKwP2grRYxI8r8Qt/3qYK5fsyUjtf/2U3Or9Y3T9ifrSW+9kZ7V18++yZjKGIKYrfuj70dT1Rw2iYRHoKYPtx447CRFyRrFRTW0LGem7p+zNJkIb9DgocPdRUDYduq8NIITdYUhfEVU8mkzxU2QljdW3+UqO/26rWzwLXpfRw7y17zHPlEfWxgOAWkXow9GxxXogfmoZVtoUzQ3766hfcMWohnlgO1azZmVqL+Hb6Iut7xfxj4kPbVzX9P9mhIpYq9zuFacBFRtxvi21XTTDaVaeML+WDliMjQA/Cawzsyu60Eo1pFrtddxSROot5D7D6n+Ha9F7PX7dxep92IsoLsKUd/71/vVRZNDl9Y1tIucvrG9J8N0KeJWNl9h+Iuj+pSGiv7G5GFqDz7M9fjFnJxyvfd+QArLefLQTQs8slLB/RMeBVz2t3cFsdcTIBbaC88TPWVs5qm2LiuOLAPGtNiDblHsGf5BLgrgZi41jbuH+RcZxW1nG+KAqh3pDyA/0wuOz2L9TQhQaZInk7oLeWihWzuA== X-Forefront-PRVS: 02318D10FB X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(7916002)(39450400003)(189002)(24454002)(199003)(101416001)(5660300001)(92566002)(53936002)(2906002)(305945005)(23686003)(7736002)(4326007)(97736004)(4001350100001)(68736007)(86362001)(189998001)(6666003)(105586002)(2950100002)(106356001)(229853002)(81166006)(81156014)(8676002)(50466002)(53416004)(42186005)(50986999)(6862004)(25786008)(47776003)(66066001)(69596002)(9686003)(6246003)(54906002)(110136004)(54356999)(33656002)(55016002)(76176999)(107886003)(38730400002)(6506006)(6116002)(83506001)(3846002)(1076002)(7099028)(18370500001)(26326002);DIR:OUT;SFP:1102;SCL:1;SRVR:VI1PR0801MB1982;H:outlook.office365.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?koi8-r?Q?1;VI1PR0801MB1982;23:2xr6zTuHfkMtRVilnDQMkYFtjJpS/ifyiG3GJxm3m?= =?koi8-r?Q?BAjAgrutrw1cLNd3odQOIjSVFw7bFWP8ZbqXcgZcJl4At1s7Hky6gfmrDFqCqR?= =?koi8-r?Q?X5BvIpTO8zLcIwg/9kAKtxEw9ta/t3ZP6VoCroxFZstoLI/5z3mSy0p1DXOzGE?= =?koi8-r?Q?V53qAt936lCd20mw7KIHtzBOXXjs9CQ4SEuMOC16HBh1kwpjRjiTNUmmlRNIjS?= =?koi8-r?Q?monVHmGZMvBKOxqJpc2sbJgvcrdLU27nFOscgf+iLPqPo650+KgGoCF8+MkHJd?= =?koi8-r?Q?banIhjYepWn7JIRIAI4ew3Hi1fZZj/7EfmNCmUyQuDwlTPebJgfU0vh+KqyHiT?= =?koi8-r?Q?DVus66SJu1ZgXGL607ly3s2AMH8sITProdeM6rqQZpJQkZ9Qp29wP7v8jE7oGR?= =?koi8-r?Q?Qy9MuD5dgJUeNuQu8Jo9oVPIjVfsTL8NcXUAknClh1sbERSO9j024D6ml4Ndkc?= =?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exchange-Diagnostics: 1;VI1PR0801MB1982;6:dpJP/6CH+ReyBHQQG/UxfwFcRoO5YfFFWkgSPF4eXFWD022W1JKbcfSP83PK1fNCXFqVRyaxCivZvM+T7VnBmuHGWHbxDcdthf/VdtrFhBMYezRBYFq7n7O6c5pZD8V5p1I/7yBbPmfQGr5kzE0/crKxE6lllfNQYCYsTe6XwunCeP4pCJdCY3Tk7F39IMqcad88uijtuXcdu9TY79j+rv2FHx2uv05B5TXTnOdb0vdJL/FLBsiAkr92Ih3zyqjlFwyG9ciTXkpVFIv40VwYAVKVZTEInnLqNpv4fwuM6MaN39ofFlTKMPExsbXwBa3pM5yQg1Q8od+RzLgxtMd6Jjpn3OThE4uZqyQ3/7n700GCl1OZa7XPx/3T0615u8BbIFWBApOnVrarwXKqTeSbug==;5:Y/W2q4CB0N0uZ4WHiH81sr5ZNxZzdJu4G9EtY00vnagMk8CQmQoUs3NhypEXcRSdptpvqg+cTseg/aeNSfwXeI1xTYaJD4jKd8D7oZV6lD3MvI/dmYttpcet9JncPLnE0sKUs38YKP3OQd0EGJmbig==;24:1oYuSs+guP7Mxn8ujKKx3PS11FVOuxs9+CZeBSEKWAi22cQXIy2Kyv7922fer9gMknirtAcWaS6l4/zu0SOUDn6kJL0Z8rixaAh+cuovPe8= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;VI1PR0801MB1982;7:RSYjJQODbt5MesaHBGGnjG0NUUbfox+TmnuihSh+Uv58qZOhxKWKaxMQMV6AKiR1uiyW9gSByLv1+/s14SwnkbRcJudJZIvVyAUXBdyFeVfKJh6SAeFv7XRNYuRtEoZgxbf+fw9UXgmGT1h/pYVB7+wT2dQmlo7RwmD8Nr7ghMVm9b9BNdHw+KeUwT/szmGhlyycriEkV2C4A/seDWZpPwxtyD1nRUulFYtA4RVqOy8hehRVOwP8rVj7Cx1wxVkpE59+3FZLMMJLKCu5A+/LVUfC2uNUfQvZ3Y7jNytb2QYUWx0uN/3u8Tfx4KOQ8dcqPdMKIPChuEzkPS9VF2tlhA==;20:KicFji0H9Af8KN5z55SBazqGDBxWTgr19IEr5NgxmQA/bbjSQwXVwONlGjE8smJ+EFvAT+qxQTSKeX5Sv4ETKP9723l329GSRvCkExcEOFy/BfdLn1d6KCDCc9xhn8HIoy4ye4AYyIvq4XOehOH+PlGka97ep8UYiYmoYzSIp0k= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Feb 2017 22:44:01.5962 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB1982 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 21, 2017 at 07:59:46PM +0300, Cyrill Gorcunov wrote: > With current epoll architecture target files are addressed > with file_struct and file descriptor number, where the last > is not unique. Moreover files can be transferred from another > process via unix socket, added into queue and closed then > so we won't find this descriptor in the task fdinfo list. > > Thus to checkpoint and restore such processes CRIU needs to > find out where exactly target file is present to add it into > the epoll queue. For this sake one can use kcmp call where > some particular target file from the queue is compared with > arbitrary file passed as an argument. > > Because epoll target files can have same file descriptor > number but different file_struct a caller should explicitly > specify the offset within such entries. > > To test if some particular file is matching entry inside > epoll one have to > > - fill kcmp_epoll_slot structure with epoll file descriptor, > target file number and target file offset (in case if only > one target is present then it should be 0) > > - call kcmp as kcmp(pid1, pid2, KCMP_EPOLL_TFD, fd, &kcmp_epoll_slot) > - the kernel fetch file pointer matching file descriptor @fd of pid1 > - lookups for file struct in epoll queue of pid2 and returns traditional > 0,1,2 result for sorting purpose > > Signed-off-by: Cyrill Gorcunov > CC: Al Viro > CC: Andrew Morton > CC: Andrey Vagin > CC: Pavel Emelyanov > CC: Michael Kerrisk > CC: Kir Kolyshkin > CC: Jason Baron > CC: Andy Lutomirski > --- > fs/eventpoll.c | 42 ++++++++++++++++++++++++++++++++++++++++++ > include/linux/eventpoll.h | 3 +++ > include/uapi/linux/kcmp.h | 10 ++++++++++ > kernel/kcmp.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ > 4 files changed, 99 insertions(+) > > Index: linux-ml.git/fs/eventpoll.c > =================================================================== > --- linux-ml.git.orig/fs/eventpoll.c > +++ linux-ml.git/fs/eventpoll.c > @@ -1000,6 +1000,48 @@ static struct epitem *ep_find(struct eve > return epir; > } > > +static struct epitem *ep_find_tfd(struct eventpoll *ep, int tfd, unsigned long toff) > +{ > + struct rb_node *rbp; > + struct epitem *epi; > + > + for (rbp = rb_first(&ep->rbr); rbp; rbp = rb_next(rbp)) { > + epi = rb_entry(rbp, struct epitem, rbn); > + if (epi->ffd.fd == tfd) { > + if (toff == 0) > + return epi; > + else > + toff--; > + } > + cond_resched(); > + } > + > + return NULL; > +} > + > +struct file *get_epoll_tfile_raw_ptr(struct file *file, int tfd, > + unsigned long toff) > +{ > + struct file *file_raw; > + struct eventpoll *ep; > + struct epitem *epi; > + > + if (!is_file_epoll(file)) > + return ERR_PTR(-EINVAL); > + > + ep = file->private_data; > + > + mutex_lock(&ep->mtx); > + epi = ep_find_tfd(ep, tfd, toff); > + if (epi) > + file_raw = epi->ffd.file; > + else > + file_raw = ERR_PTR(-ENOENT); > + mutex_unlock(&ep->mtx); > + > + return file_raw; > +} > + > /* > * This is the callback that is passed to the wait queue wakeup > * mechanism. It is called by the stored file descriptors when they > Index: linux-ml.git/include/linux/eventpoll.h > =================================================================== > --- linux-ml.git.orig/include/linux/eventpoll.h > +++ linux-ml.git/include/linux/eventpoll.h > @@ -14,6 +14,7 @@ > #define _LINUX_EVENTPOLL_H > > #include > +#include > > > /* Forward declarations to avoid compiler errors */ > @@ -22,6 +23,8 @@ struct file; > > #ifdef CONFIG_EPOLL > > +struct file *get_epoll_tfile_raw_ptr(struct file *file, int tfd, unsigned long toff); > + > /* Used to initialize the epoll bits inside the "struct file" */ > static inline void eventpoll_init_file(struct file *file) > { > Index: linux-ml.git/include/uapi/linux/kcmp.h > =================================================================== > --- linux-ml.git.orig/include/uapi/linux/kcmp.h > +++ linux-ml.git/include/uapi/linux/kcmp.h > @@ -1,6 +1,8 @@ > #ifndef _UAPI_LINUX_KCMP_H > #define _UAPI_LINUX_KCMP_H > > +#include > + > /* Comparison type */ > enum kcmp_type { > KCMP_FILE, > @@ -10,8 +12,16 @@ enum kcmp_type { > KCMP_SIGHAND, > KCMP_IO, > KCMP_SYSVSEM, > + KCMP_EPOLL_TFD, > > KCMP_TYPES, > }; > > +/* Slot for KCMP_EPOLL_TFD */ > +struct kcmp_epoll_slot { > + __u32 efd; /* epoll file descriptor */ > + __u32 tfd; /* target file number */ > + __u64 toff; /* target offset within same numbered sequence */ > +}; > + > #endif /* _UAPI_LINUX_KCMP_H */ > Index: linux-ml.git/kernel/kcmp.c > =================================================================== > --- linux-ml.git.orig/kernel/kcmp.c > +++ linux-ml.git/kernel/kcmp.c > @@ -11,6 +11,10 @@ > #include > #include > #include > +#include > +#include > +#include > +#include > > #include > > @@ -165,6 +169,46 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t > ret = -EOPNOTSUPP; > #endif > break; > + case KCMP_EPOLL_TFD: { > +#ifdef CONFIG_EPOLL > + struct file *filp1, *filp_epoll, *filp_tgt; > + struct kcmp_epoll_slot slot; > + struct files_struct *files; > + > + if (copy_from_user(&slot, (void *)idx2, sizeof(slot))) { > + ret = -EFAULT; > + goto err_unlock; > + } > + > + filp1 = get_file_raw_ptr(task1, idx1); > + > + files = get_files_struct(task2); > + if (files) { > + spin_lock(&files->file_lock); > + filp_epoll = fcheck_files(files, slot.efd); > + if (filp_epoll) > + get_file(filp_epoll); > + spin_unlock(&files->file_lock); > + put_files_struct(files); > + } else > + filp_epoll = NULL; > + > + if (filp1 && filp_epoll) { > + filp_tgt = get_epoll_tfile_raw_ptr(filp_epoll, slot.tfd, slot.toff); > + if (IS_ERR(filp_tgt)) > + ret = PTR_ERR(filp_tgt); > + else > + ret = kcmp_ptr(filp1, filp_tgt, KCMP_EPOLL_TFD); I think KCMP_FILE has to be used here ^^^^, because we compare files. We have to use the same function for all files to be able to sort them, don't we? > + } else > + ret = -EBADF; > + > + if (filp_epoll) > + fput(filp_epoll); > +#else > + ret = -EOPNOTSUPP; > +#endif > + break; > + } > default: > ret = -EINVAL; > break; >