Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5904820ybi; Tue, 4 Jun 2019 14:30:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqzaNsCiOmEdY/GGAUhmK2znW9Q3BrijRaWWQCLgbUgtzVlXRTZzC8A75YxWKct4d2dp6Nw1 X-Received: by 2002:a17:90a:2190:: with SMTP id q16mr3407899pjc.23.1559683857535; Tue, 04 Jun 2019 14:30:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559683857; cv=none; d=google.com; s=arc-20160816; b=ghi/pzXrQ9Q4r3t+dLo6SNw+02kYaiXvPc8Oxly4qoa/Fj7L1smVe0i9Jn2nJACkFN s3PSnRv+aWDdjiPTWZT8i/yRbLe2N3TkJAySsiPuW3hJAP2Fh65WIqMy9RmvY9U39HOV eLYMBf1tk1cwfPR7yN9lL0X04LOlqS30u4wj5diXf7IGyDqaZBP3MDfXPxddiM7Y3xlT s+HcusNkiEEwWgQynYMx0W/09Guz3y2+0Nfbeu/qlr5sWLIK2ooVe2g09BRNMtzv4tx+ 6AlAdimuyVrLSbQE5WHGUgUjjAfux74Ea7SZ4BeOArvlxRdviorSSLTCUwZkoQQJa8BW olqA== 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:dkim-signature; bh=JZJYTNyCIjCtE1t89164f4VdEMlbutgxwjEunlEpUIs=; b=SSnAFB3QcZtVwY5/3Fm0J5ZX6PR12lSFzJjsNSh7n3d61yVylPUugs6cTRGZ/SeuTU hbEfyKkhmp95wNE+N6Qvw4jhxYP14pvmoiJLfNxLBf2oiuBvvBsNSHeNXYKUlnzObuEk ZCcxTrx8vRltlZXP8dGS6y4a4ti+DKxP1Q76IipyEzfnglax5N23P+55/llExSivwouh YHvQHmKdVUi4sjlL12EYnxLSEJWGnMsAwRuPPc4s1Zikjebv8Hf9CUNdtX9/vh9vXidc Z6MVQbaE7kXs3pR4K7xHphxhIieYuCj9FYSCi5ZKzNNgqynUcobUgh5/WFp+snXYxnHu Wxyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brauner.io header.s=google header.b=WZ9Fg9dd; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j16si25541088pfn.225.2019.06.04.14.30.41; Tue, 04 Jun 2019 14:30:57 -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; dkim=pass header.i=@brauner.io header.s=google header.b=WZ9Fg9dd; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726690AbfFDV3h (ORCPT + 99 others); Tue, 4 Jun 2019 17:29:37 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:33630 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726033AbfFDV3f (ORCPT ); Tue, 4 Jun 2019 17:29:35 -0400 Received: by mail-wm1-f66.google.com with SMTP id v19so349192wmh.0 for ; Tue, 04 Jun 2019 14:29:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brauner.io; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=JZJYTNyCIjCtE1t89164f4VdEMlbutgxwjEunlEpUIs=; b=WZ9Fg9ddza4LB6asPBDF7sIrW37u5T5YUWWbvHtVVmMwyWIDe8KCQCJoLw4YFIRNvR PBDGPZ3P2cHPq6pwX/Dssuy8C+eM/vg9nT6qAQeAiZ0gXshdzz+2nYzur5jVPDMZAbKT dT66uq6ltvKrEviKKbhQBrERGzP8jJWUGZMLaGxWcWXxmoWSy/xGP8vA4oo0yTFWGXhK HjksfSXEcnmpLhrf/hle3rBr7DxBHcFJT78iI8p61BBgSX2SsMBdx9+39JdBrI8451qL u2HvXTEOdcLVa5Pq5zvrZWVCMuR6mpvm0983zyu6+oQfxTvbm4yb09moe03txqhc5aHQ VJZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=JZJYTNyCIjCtE1t89164f4VdEMlbutgxwjEunlEpUIs=; b=Vg8syvlA0pLxrOcR2NiegM+n/lB62kr7kCZAMayLkVuKMB36ruON4wvFmfa1uNb5sT X/tiyX3KchHYaPOI0oi/AX64byy7/vjJMAQarW/fHiuW5Fco7EYpIjoc9kbsKoIr0B3G ULIVBfxYmyEkshhugFctfbaHbllI0rRlRU2T/inXaPKJgfhTAw85/2wQxVDt3pH8AUHo BCFnZeg8csIvNePdaeC+7F4xc9FrRaIxiN7wE+diS4r77zjjPj7nma68eveU9TgBQ5AD XfqPSX7cArVSTAfYtrNfIoNMyHjd6YdWkezRMgCLn1MZ64CTr5Dve1Pk5aQI93ldCLpW T3xA== X-Gm-Message-State: APjAAAXj4Cge4qp1MGGoIFqTres7VhAU/UOpwktN3ZmqGjK3QYpGPJ36 Fis4JlyzdVl6dYt7WXyXdxxILQ== X-Received: by 2002:a1c:ef0c:: with SMTP id n12mr8157160wmh.132.1559683773365; Tue, 04 Jun 2019 14:29:33 -0700 (PDT) Received: from brauner.io ([212.91.227.56]) by smtp.gmail.com with ESMTPSA id x11sm14812487wmg.23.2019.06.04.14.29.32 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 04 Jun 2019 14:29:32 -0700 (PDT) Date: Tue, 4 Jun 2019 23:29:31 +0200 From: Christian Brauner To: Arnd Bergmann Cc: Al Viro , Linux Kernel Mailing List , Linus Torvalds , Jann Horn , Kees Cook , Florian Weimer , Oleg Nesterov , David Howells , Andrew Morton , Adrian Reber , Linux API , linux-arch , the arch/x86 maintainers Subject: Re: [PATCH v3 2/2] arch: wire-up clone3() syscall Message-ID: <20190604212930.jaaztvkent32b7d3@brauner.io> References: <20190604160944.4058-1-christian@brauner.io> <20190604160944.4058-2-christian@brauner.io> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 04, 2019 at 08:40:01PM +0200, Arnd Bergmann wrote: > On Tue, Jun 4, 2019 at 6:09 PM Christian Brauner wrote: > > > > Wire up the clone3() call on all arches that don't require hand-rolled > > assembly. > > > > Some of the arches look like they need special assembly massaging and it is > > probably smarter if the appropriate arch maintainers would do the actual > > wiring. Arches that are wired-up are: > > - x86{_32,64} > > - arm{64} > > - xtensa > > The ones you did look good to me. I would hope that we can do all other > architectures the same way, even if they have special assembly wrappers > for the old clone(). The most interesting cases appear to be ia64, alpha, > m68k and sparc, so it would be good if their maintainers could take a > look. Yes, agreed. They can sort this out even after this lands. > > What do you use for testing? Would it be possible to override the > internal clone() function in glibc with an LD_PRELOAD library > to quickly test one of the other architectures for regressions? I have a test program that is rather horrendously ugly and I compiled kernels for x86 and the arms and tested in qemu. The program basically looks like [1]. Christian [1]: #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static pid_t raw_clone(struct clone_args *args) { return syscall(__NR_clone3, args, sizeof(struct clone_args)); } static pid_t raw_clone_legacy(int *pidfd, unsigned int flags) { return syscall(__NR_clone, flags, 0, pidfd, 0, 0); } static int wait_for_pid(pid_t pid) { int status, ret; again: ret = waitpid(pid, &status, 0); if (ret == -1) { if (errno == EINTR) goto again; return -1; } if (ret != pid) goto again; if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) return -1; return 0; } #define ptr_to_u64(ptr) ((__u64)((uintptr_t)(ptr))) #define u64_to_ptr(n) ((uintptr_t)((__u64)(n))) int main(int argc, char *argv[]) { int pidfd = -1; pid_t parent_tid = -1, pid = -1; struct clone_args args = {0}; args.parent_tid = ptr_to_u64(&parent_tid); args.pidfd = ptr_to_u64(&pidfd); args.flags = CLONE_PIDFD | CLONE_PARENT_SETTID; args.exit_signal = SIGCHLD; pid = raw_clone(&args); if (pid < 0) { fprintf(stderr, "%s - Failed to create new process\n", strerror(errno)); exit(EXIT_FAILURE); } if (pid == 0) { printf("I am the child with pid %d\n", getpid()); exit(EXIT_SUCCESS); } printf("raw_clone: I am the parent. My child's pid is %d\n", pid); printf("raw_clone: I am the parent. My child's pidfd is %d\n", *(int *)args.pidfd); printf("raw_clone: I am the parent. My child's paren_tid value is %d\n", *(pid_t *)args.parent_tid); if (wait_for_pid(pid)) exit(EXIT_FAILURE); if (pid != *(pid_t *)args.parent_tid) exit(EXIT_FAILURE); close(pidfd); printf("\n\n"); pidfd = -1; pid = raw_clone_legacy(&pidfd, CLONE_PIDFD | SIGCHLD); if (pid < 0) { fprintf(stderr, "%s - Failed to create new process\n", strerror(errno)); exit(EXIT_FAILURE); } if (pid == 0) { printf("I am the child with pid %d\n", getpid()); exit(EXIT_SUCCESS); } printf("raw_clone_legacy: I am the parent. My child's pid is %d\n", pid); printf("raw_clone_legacy: I am the parent. My child's pidfd is %d\n", pidfd); if (wait_for_pid(pid)) exit(EXIT_FAILURE); if (pid != *(pid_t *)args.parent_tid) exit(EXIT_FAILURE); return 0; }