Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2168919yba; Mon, 15 Apr 2019 06:26:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqwXyot9dBIadDwl5ezfYji73GTr3FknDtTShiys0rKL2c0s+aDq+hEV09tDFRpXo09K/ez8 X-Received: by 2002:a17:902:758e:: with SMTP id j14mr33471526pll.286.1555334762307; Mon, 15 Apr 2019 06:26:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555334762; cv=none; d=google.com; s=arc-20160816; b=UrBicTYo7bfz9OFWTEGwx31jAC1Z3554c0ktt5I9hYlYJcEAPFQC3uDYT3KwFfL2AD goUvvLLowJyqsLJxxQ/yVsYV26jNh9UaqCJgiZAlTQNcVwySDtslLk+mL7hrDf7KPJ4h FrJrtQnTLqeOn93WouElwvxQwZ+i0/VWP6UdCIQtTJn97FglhfTI6DMd1sYMb81Unnwz WriMsglipPk59zicYpbN5TilPEG5qJbdVyngxFN6toApCmcJIvugl9zkBem5yW+6u8ca m7F02QER6VoJhm2QXJTsMIDZMVhJztU7os2mQiGkqQQATEPam3gTiXVgnsuKomlTYa/l qjRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=eXhSjLM4tCTBGmRNgiWS9hGWPxM25NKXgh0R+I83O40=; b=qO6UYxosbHcMq/D8wqXmJpj+mALANQj4TNN4J83SWgfVG1ZJJc/tCspSrG+HGkskbF ziDDWZZpFxNVOnuOXGtrBIBVYBr3D1++5PyiayVAA1pKBDLh/LC0HQXA75K9IGwQMisa lr7c9xJjo/fvXmLJ4PJo1G/h/DL0nZ2JwyeLXxcP8PLZhrFqmOdL+ci8/YIYlQRXbNl0 IbuuwBT5Y3rryIY+w0PKIcomKXHbgvJZwf9MO4PwAGAMeCZ09FHktP3uSWdq/mTvV8gh +g2Ub+XepU9PMcwZIiwMoyMs6imb5/aHG+pq1ir/mlpxAMxLnQ+/p6i6/09T2cFabzga Xs8Q== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f1si28958912pff.158.2019.04.15.06.25.44; Mon, 15 Apr 2019 06:26:02 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727412AbfDONY3 (ORCPT + 99 others); Mon, 15 Apr 2019 09:24:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55934 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727213AbfDONY3 (ORCPT ); Mon, 15 Apr 2019 09:24:29 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 08A4C307EA89; Mon, 15 Apr 2019 13:24:23 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.43.17.38]) by smtp.corp.redhat.com (Postfix) with SMTP id 8905360C43; Mon, 15 Apr 2019 13:24:17 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Mon, 15 Apr 2019 15:24:22 +0200 (CEST) Date: Mon, 15 Apr 2019 15:24:16 +0200 From: Oleg Nesterov To: Christian Brauner Cc: torvalds@linux-foundation.org, viro@zeniv.linux.org.uk, jannh@google.com, dhowells@redhat.com, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, serge@hallyn.com, luto@kernel.org, arnd@arndb.de, ebiederm@xmission.com, keescook@chromium.org, tglx@linutronix.de, mtk.manpages@gmail.com, akpm@linux-foundation.org, cyphar@cyphar.com, joel@joelfernandes.org, dancol@google.com Subject: Re: [PATCH 2/4] clone: add CLONE_PIDFD Message-ID: <20190415132416.GB22204@redhat.com> References: <20190414201436.19502-1-christian@brauner.io> <20190414201436.19502-3-christian@brauner.io> <20190415105209.GA22204@redhat.com> <20190415114204.ydczeuwmi74wfsuv@brauner.io> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190415114204.ydczeuwmi74wfsuv@brauner.io> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Mon, 15 Apr 2019 13:24:29 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/15, Christian Brauner wrote: > > > CLONE_PARENT_SETTID doesn't look very usefule, so what if we add > > > > if ((clone_flags & (CLONE_PIDFD|CLONE_PARENT_SETTID)) == > > (CLONE_PIDFD|CLONE_PARENT_SETTID)) > > return ERR_PTR(-EINVAL); > > > > at the start of copy_process() ? > > > > Then it can do > > > > if (clone_flags & CLONE_PIDFD) { > > retval = pidfd_create(pid, &pidfdf); > > if (retval < 0) > > goto bad_fork_free_pid; > > retval = put_user(retval, parent_tidptr) > > if (retval < 0) > > goto bad_fork_free_pid; > > } > > Uhhh Oleg, that is nifty. I have to say I like that a lot. This would > let us return the pid and the pidfd in one go and we can also start > pidfd numbering at 0. Christian, sorry if it was already discussed, but I can't force myself to read all the previous discussions ;) If we forget about CONFIG_PROC_FS, why do we really want to create a file? Suppose we add a global u64 counter incremented by copy_process and reported in /proc/$pid/status. Suppose that clone(CLONE_PIDFD) writes this counter to *parent_tidptr. Let's denote this counter as UNIQ_PID. Now, if you want to (say) safely kill a task and you have its UNIQ_PID, you can do kill_by_pid_uniq(int pid, u64 uniq_pid) { pidfd = open("/proc/$pid", O_DIRECTORY); status = openat(pidfd, "status"); u64 this_uniq_pid = ... read UNIQ_PID from status ...; if (uniq_pid != this_uniq_pid) return; pidfd_send_signal(pidfd); } Why else do we want pidfd? Oleg.