Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp1874924ybc; Wed, 13 Nov 2019 05:45:45 -0800 (PST) X-Google-Smtp-Source: APXvYqwCXYeeGsq3RxxHGnc4Es3DvoYB5lfrYcGWrDdCwXWH6SRxy8bf5nxxjVVroeeSVcKwo73Q X-Received: by 2002:aa7:c65a:: with SMTP id z26mr3652245edr.261.1573652745392; Wed, 13 Nov 2019 05:45:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573652745; cv=none; d=google.com; s=arc-20160816; b=Z2RuRyO8KfHIWdQ5nvkA34/4HA6V9lC7QBMhRe3Us+AWg2BdyitYD165pcDo7XFFCE 80ipEldw3Q18F+3RsVgn9MeKYQ/aTA9bEScehwMmPG8bDRo64jud1E4YPl4G3RhCIVye dCJw5Ej1aTyRU2gXEHXHJdDeKt98kh1IqYqVQK0zcGA3vwBE+lXMWez3eaL8V2W+9Kyz W6M2If9lCMppLTSj7B9KLjn1RSQZ5eu3blg4JocJjd7ksmAGAwFhK3hlr2bcQaeD9dDr l73YXhE2KLp2xfGesGy3WRQP/QPQWMVh/Pv6mGDArCdcqiRGahbY0KiwDaN7w/ET5hfo lCBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:user-agent:in-reply-to:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=JgU2e8RT59hEaQw/a6iawkjHzbdgc0u0v1JZhhfT5kU=; b=zzu3+bjzBqQvJMHG9D8gJB8ybdSAJiALeLaaOkdJ0ZpIqKdLPPYyotZS9OyaWc+Oow C7JhDQYJs+wX/Y4Q7DkxpGE4X7BsWRu1xYQLPafo2KxYmQ2RNBLEGZ6yHXVtSWOsbJJT 0Yn9+JiZCCjk1yr8LAOPbjD9jMn6UOKWNzj7ZK1zBIy5NGgSb2DN0UPc+yaMc8Nr+tpP FPCFl13TPIu+IU8tcgTX5aPfd3zT43SH9Gpj08y0QJ+p37/6kSzIjzetGiOcvgdYwTyI dxrAVgw8wjD5r6trNzK090VPVj4zQM1dErIFCqpxug/ch87ohXG/CDDVPxsKBytf3UNJ xPMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=U1bRV0hG; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 4si1504373edc.4.2019.11.13.05.45.20; Wed, 13 Nov 2019 05:45:45 -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=@redhat.com header.s=mimecast20190719 header.b=U1bRV0hG; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727485AbfKMNmT (ORCPT + 99 others); Wed, 13 Nov 2019 08:42:19 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:20321 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726434AbfKMNmS (ORCPT ); Wed, 13 Nov 2019 08:42:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573652536; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JgU2e8RT59hEaQw/a6iawkjHzbdgc0u0v1JZhhfT5kU=; b=U1bRV0hGlhzyn7KIa2MD0bWHh1j91mybyLpqcIIFndulbD3A4AEbf1yDiuyM6FUfdejAsw mPa/quPq2dzOQtcJFyNnByi1IND5L/ESWTOiRm6bfK6iwfh+0+AfOFhqN0mHXGFm9V1ftV jDl7+cHeo1QjKfMMIL6rWFmhB9ouUvU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-231-nY7xI--DNa61pN8DDiLq6g-1; Wed, 13 Nov 2019 08:42:13 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D08391852E20; Wed, 13 Nov 2019 13:42:10 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.43.17.44]) by smtp.corp.redhat.com (Postfix) with SMTP id BD3972B7C5; Wed, 13 Nov 2019 13:42:08 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Wed, 13 Nov 2019 14:42:09 +0100 (CET) Date: Wed, 13 Nov 2019 14:42:06 +0100 From: Oleg Nesterov To: Adrian Reber Cc: Christian Brauner , Eric Biederman , Pavel Emelyanov , Jann Horn , Dmitry Safonov <0x7f454c46@gmail.com>, Rasmus Villemoes , linux-kernel@vger.kernel.org, Andrei Vagin , Mike Rapoport , Radostin Stoyanov Subject: Re: [PATCH v8 1/2] fork: extend clone3() to support setting a PID Message-ID: <20191113134206.GA4320@redhat.com> References: <20191113080301.1197762-1-areber@redhat.com> MIME-Version: 1.0 In-Reply-To: <20191113080301.1197762-1-areber@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: nY7xI--DNa61pN8DDiLq6g-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/13, Adrian Reber wrote: > > @@ -175,23 +187,47 @@ struct pid *alloc_pid(struct pid_namespace *ns) > =20 > =09for (i =3D ns->level; i >=3D 0; i--) { > =09=09int pid_min =3D 1; Well, this is really minor but again, pid_min is only used in the "else" branch below, you can move this declaration there. > + > +=09=09if (set_tid_size) { > +=09=09=09tid =3D set_tid[ns->level - i]; > +=09=09=09if (tid < 1 || tid >=3D pid_max) > +=09=09=09=09return ERR_PTR(-EINVAL); > +=09=09=09/* Also fail if a PID !=3D 1 is requested and no PID 1 exists *= / > +=09=09=09if (tid !=3D 1 && !tmp->child_reaper) > +=09=09=09=09return ERR_PTR(-EINVAL); > +=09=09=09if (!ns_capable(tmp->user_ns, CAP_SYS_ADMIN)) > +=09=09=09=09return ERR_PTR(-EPERM); > +=09=09} > =20 > =09=09idr_preload(GFP_KERNEL); > =09=09spin_lock_irq(&pidmap_lock); > =20 > -=09=09/* > -=09=09 * init really needs pid 1, but after reaching the maximum > -=09=09 * wrap back to RESERVED_PIDS > -=09=09 */ > -=09=09if (idr_get_cursor(&tmp->idr) > RESERVED_PIDS) > -=09=09=09pid_min =3D RESERVED_PIDS; > - > -=09=09/* > -=09=09 * Store a null pointer so find_pid_ns does not find > -=09=09 * a partially initialized PID (see below). > -=09=09 */ > -=09=09nr =3D idr_alloc_cyclic(&tmp->idr, NULL, pid_min, > -=09=09=09=09 pid_max, GFP_ATOMIC); > +=09=09if (tid) { > +=09=09=09nr =3D idr_alloc(&tmp->idr, NULL, tid, > +=09=09=09=09 tid + 1, GFP_ATOMIC); > +=09=09=09/* > +=09=09=09 * If ENOSPC is returned it means that the PID is > +=09=09=09 * alreay in use. Return EEXIST in that case. > +=09=09=09 */ > +=09=09=09if (nr =3D=3D -ENOSPC) > +=09=09=09=09nr =3D -EEXIST; > +=09=09=09set_tid_size--; ^^^^^^^^^^^^^^^ May I ask you to move this decrement into the "if (set_tid_size)" block abo= ve? Oleg.