Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1965173pxk; Sat, 26 Sep 2020 11:13:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFOzebqY+r54zer0LK0Gyzn9U4xljPW5xD4b5jCEJgikWLarztfit0XSAF2T/8eNUjs4QN X-Received: by 2002:a05:6402:1acf:: with SMTP id ba15mr7983420edb.305.1601144003007; Sat, 26 Sep 2020 11:13:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601144003; cv=none; d=google.com; s=arc-20160816; b=A+0BCqL8POKYZDQIm9pgAAl7hQwNn/GMwK2oyFc/hoyZpBmoyRWn9xJ9KxluL71LeZ df3rV5B3rTk7fLkOCVLaxKgDvWI5hutL7FcV/h6WEPyp6nCFCK/ZnyOi5jx6cke6kqZP dKl9qR/1IgVJCLURBIzpShbvSNTpOM7fkt17FnW4Jrrunj0H8ymcHD8/BQ3DFumYBSSE /zvbTyENyNGz/CsWEuD0I0NFA367yN5Mc0/Wj+3/vp+0sW3zEJl+EPWIJ4QPZv0erH+G CX7mIVkMWjsQTAp4qcpd6c8kbRJexQTgjMJCbXZLpbBsjCUrXecugacsS9YmXpRKmVrq PUtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=KowdFI99SvwAHlmnquISweYZPA2kNBZ4Vy+1Sm1Ru5Y=; b=n//r1cr/M3xJ+CCPxFRVyxgTJSaLDdZH32Y+9n4uovPP1KC1n91EnaGeHKeDnI3qwX sX5VNPhRQYUdJMdZZOu0W0hBCo5XMewGYZY4SAWW0XziUz53UprgYbX8knnxc0ffAjuo JQlwaq8cgaN6IpjvdAalqXdrcSp/gBCvfMNOfrN9ENLmGcM7roDoaxHjIE0p9ghgNl4+ eeT45UQLkuQ8qVW/iimDUMcjQ2Vnsr6y3xBGm3b4dRnhoB4v8ei3JFsYdmEuS378ZlMz wrqel7r4RK2GNe5OnYBWh0RGhuGwkmpreRjuSkZVdRR0skMQ4Czr1lp7HPYQpoTCiCK9 m3tA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=syrFF3GZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f21si4523392edq.84.2020.09.26.11.12.59; Sat, 26 Sep 2020 11:13:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=syrFF3GZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729443AbgIZSMD (ORCPT + 99 others); Sat, 26 Sep 2020 14:12:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726183AbgIZSMC (ORCPT ); Sat, 26 Sep 2020 14:12:02 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AC5CC0613CE; Sat, 26 Sep 2020 11:12:02 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id 197so4971108pge.8; Sat, 26 Sep 2020 11:12:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=KowdFI99SvwAHlmnquISweYZPA2kNBZ4Vy+1Sm1Ru5Y=; b=syrFF3GZ4vwOCTVvGBzGuHJ4tcSsvCEY7VnZU5FZQtDjapU5yYWoTukg/YbFCvyOJg 1R7CkOr3meO9mL0s1bMniClEFzIlmODRBjafTC6oXho0L9KbcuKtKcSgsuuIbEOvHeXl O5h/Xqfj+cLXNLXaF79JK62/N9SjeS8W5mQw2r0Tuu+rfkfifKplqReHttHgGNDSlsic HAOssh01hbBRJI4TX+cbsO+bYKpU9wQblx3JlaoIkkKSgaDYgfIbe5UQJOxNuBcdTYAn dtMhzMWv6i+0HWW2pwD3bGOM/+eqS8iF1KLeTKLkYLQyqsK3w9bCIDV4aeG+10gzxV84 s38g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=KowdFI99SvwAHlmnquISweYZPA2kNBZ4Vy+1Sm1Ru5Y=; b=YdQ04BB5yVRZdG1kp3wGYCzghHQMDWVlYrbEqZlez53cr6FNFKaIxB9qLDMy6Uv4kN zzHRqLikdx4DQ9Dci5pTvkONzehUMTdp9sjT663Ubp9Fu5DVcp3PaZty/f6nmJtQ25ma /cBU7YgM92/Lma4xmcwjhYjZHFZW4ym5n11bWSYCN4rqvxdK0ixdW0vdpCC9ESFzZTpS TxhiX6mHHoFoPGt5h6vjBMMvISb7K9WegR5dyywKRiO152vffDXNUeex5nuuV8UTo3QW gMHrnuLQYgrcXM5zn6XA6bOyo9ucFYsg6shVr5zPBsFKIZFy6w8BUPHbqPWtgPUNoT4u o8FQ== X-Gm-Message-State: AOAM531fBz6oGJd84Fb2s92XxaartqmYQ+1Cc3np8duGytA83IUOekV6 5WOYv4mm7sgdJtPgDCTkln2NWYZfPrXhh/TBazA= X-Received: by 2002:a63:906:: with SMTP id 6mr3490414pgj.66.1601143922050; Sat, 26 Sep 2020 11:12:02 -0700 (PDT) MIME-Version: 1.0 References: <20200923232923.3142503-1-keescook@chromium.org> <43039bb6-9d9f-b347-fa92-ea34ccc21d3d@rasmusvillemoes.dk> <27b4ef86-fee5-fc35-993b-3352ce504c73@rasmusvillemoes.dk> In-Reply-To: From: YiFei Zhu Date: Sat, 26 Sep 2020 13:11:50 -0500 Message-ID: Subject: Re: [PATCH v1 0/6] seccomp: Implement constant action bitmaps To: Rasmus Villemoes Cc: Kees Cook , YiFei Zhu , Andrea Arcangeli , Giuseppe Scrivano , Will Drewry , bpf , Jann Horn , Linux API , Linux Containers , Tobin Feldman-Fitzthum , Hubertus Franke , Andy Lutomirski , Valentin Rothberg , Dimitrios Skarlatos , Jack Chen , Josep Torrellas , Tianyin Xu , kernel list Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 25, 2020 at 2:07 AM YiFei Zhu wrote: > I'll try to profile the latter later on my qemu-kvm, with a recent > libsecomp with binary tree and docker's profile, probably both direct > filter attaches and filter attaches with fork(). I'm guessing if I > have fork() the cost of fork() will overshadow seccomp() though. I'm surprised. That is not the case as far as I can tell. I wrote a benchmark [1] that would fork() and in the child attach a seccomp filter, look at the CLOCK_MONOTONIC difference, then add it to a struct timespec shared with the parent. It checks the difference with the timespec before prctl and before fork. CLOCK_MONOTONIC instead of CLOCK_PROCESS_CPUTIME_ID because of fork. I ran `./seccomp_emu_bench 100000` in my qemu-kvm and here are the results: without emulator: Benchmarking 100000 syscalls... 19799663603 (19.8s) seecomp attach without fork: 197996 ns 33911173847 (33.9s) seecomp attach with fork: 339111 ns with emulator: Benchmarking 100000 syscalls... 54428289147 (54.4s) seecomp attach without fork: 544282 ns 69494235408 (69.5s) seecomp attach with fork: 694942 ns fork seems to take around 150us, seccomp attach takes around 200us, and the filter emulation overhead is around 350us. I had no idea that fork was this fast. If I wrote my benchmark badly please criticise. Given that we are doubling the time to fork() + seccomp attach filter, I think yeah running the emulator on the first instance of a syscall, holding a lock, is a much better idea. If I naively divide 350us by the number of syscall + arch pairs emulated the overhead is less than 1 us and that should be okay since it only happens for the first invocation of the particular syscall. [1] https://gist.github.com/zhuyifei1999/d7bee62bea14187e150fef59db8e30b1 YiFei Zhu