Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp23746pxb; Wed, 24 Feb 2021 17:03:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJzuutbpNs2LMgnqVUj/QXsEdaJaxVCRIxt8l32EmMX+rYCTA8gIjjmkbEooL4tpzetEbUBS X-Received: by 2002:a05:6402:3071:: with SMTP id bs17mr527707edb.19.1614215027552; Wed, 24 Feb 2021 17:03:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614215027; cv=none; d=google.com; s=arc-20160816; b=S0baAskKNvMYI5/DQ/wdGWOhtIb2FhL+yhqgF52P8wcIR8HMulPa10Jsh3C+ogurrs WToImdlQrhcq+HbUeU0Tmf81QzsaDdIZRZUMHW99haMqW6TUcbJD/gS6geFPw8aPokLa ffymWhURpDs4KmNJ9s/vGu1HNpGoeawf9E/woYrWEb05ApXawuQIP1r3VUWNI2felPwc 0UN1YFt/kwH6NTiwU6aKybFPSgd+sc/z3gwKH5V0/9nj+wg6ON/3daKz8jBu9jwTfpnr 9DJH+2UQBb10XXOjEtfcbuh2AfpquAsz39JESoqJvKU3CggCFgU1fnSdz8oDcI5ToA8/ 2qzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:in-reply-to:cc:references:message-id:date :subject:mime-version:from:content-transfer-encoding:dkim-signature; bh=lteuOHvfo4K4/+NJPA032TcNQF+JRBgKzkoDcHJYOeU=; b=PKAhlUVaC5FfFZk7Yc8obzyKTNzf3Pht7gfv76E2j6IpWDH46jIq1ixA4FRYtKS6Ab a6poy6Tz/P90dEhTH8q20BNUk6CwYPz71NjH6GsubB95Q9L4FuAlOn+P/rHZEfzeDafz OZAKEwkORwUDbuFHC9veJcMnT4y99xnHhpzImykhQ/qSedgLgBVreTuYpt+nOVDzDewf SPgIUnzmnZ8Sc1EF46x6dgbQ6FEU/QmrGwPkBqqXRprOBxP+stmscALXbvtotWTuU9R+ N1JhruOXipKwSl6oCwLWujq3DZITCkTJBK5/PdUuit5F6rns9SFgdDQGx0xknQT9rASL b9ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=uCCBhDCi; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o22si2332673edr.539.2021.02.24.17.03.23; Wed, 24 Feb 2021 17:03:47 -0800 (PST) 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=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=uCCBhDCi; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231881AbhBXQVA (ORCPT + 99 others); Wed, 24 Feb 2021 11:21:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232578AbhBXQTU (ORCPT ); Wed, 24 Feb 2021 11:19:20 -0500 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 466D8C061786 for ; Wed, 24 Feb 2021 08:18:39 -0800 (PST) Received: by mail-pf1-x42c.google.com with SMTP id u26so1630712pfn.6 for ; Wed, 24 Feb 2021 08:18:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amacapital-net.20150623.gappssmtp.com; s=20150623; h=content-transfer-encoding:from:mime-version:subject:date:message-id :references:cc:in-reply-to:to; bh=lteuOHvfo4K4/+NJPA032TcNQF+JRBgKzkoDcHJYOeU=; b=uCCBhDCiEOSzFvDq8hugaWh/4pBpmUkUgVRmolQ8lW0uFuHMzJvGIgmPL4r8kj3n2l 01nDGBc4uXPWXEBYFUYjKC5zR2diGc96pCYSa0TJ7bJo3Ll38Y0hEMSXhUYacQW9v9Xx am3Z3d5h+oL9sffF9MC+Op2fdaEek0PJThOjiCXJf1hng3UAcrancae4fy52JJP46G5L J4eofy0ONPNKGBqSVa4T8n11S/TvXgpMsVDaxDBMnt/6ykECd71r5+E+Ku4bkyvdDKyY 3MifsS3qqXObyJaomc97p6GiRN+AdOg1lMBqiURpgnS0szSIBhq4vkR6lu00kdBWQitB Yliw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:content-transfer-encoding:from:mime-version :subject:date:message-id:references:cc:in-reply-to:to; bh=lteuOHvfo4K4/+NJPA032TcNQF+JRBgKzkoDcHJYOeU=; b=dSniu/Hgto2jyB8j3/DZ2b6MSN80R6tHiaMqMfPjQe53Gs89y3yM0pbHwTm33tLKfa B9cS+BZfHpLpz627a8TvwYL/K4rttMRhN/IUvzHWh/EVUEma5+wY8kJg7VXgMndz8Rpw JqMfiP/7PpCo2bd/HjQ1W1KXioJbe+9D/N7nyisJZL0jkU3oLiSOHXqKqgxqnNDu2iup ICOdV5O1Zg281WP7mcnuapsP6PW9JufNWt9VFJHHX0ooYnUgBC9XM4L54BCAgT5zbPOE npJNjDDoFPU1qAaxmWmZZak/qAKdLGpB/LhcEfxl1lOSgHtfZct3ouII4Eh6irHjGUyP SMdQ== X-Gm-Message-State: AOAM532E0dHPC7oy60dDkw+vSsYTgKr6b/64gfUCpH164LK9PM34UzFF waq+0afWI5zeE4wXoIBenl9/ag== X-Received: by 2002:a63:db08:: with SMTP id e8mr29626323pgg.261.1614183518749; Wed, 24 Feb 2021 08:18:38 -0800 (PST) Received: from ?IPv6:2601:646:c200:1ef2:f023:34a9:302a:60b6? ([2601:646:c200:1ef2:f023:34a9:302a:60b6]) by smtp.gmail.com with ESMTPSA id v4sm3283538pjo.32.2021.02.24.08.18.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 24 Feb 2021 08:18:37 -0800 (PST) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: Andy Lutomirski Mime-Version: 1.0 (1.0) Subject: Re: [PATCH v3] seccomp: Improve performace by optimizing rmb() Date: Wed, 24 Feb 2021 08:18:36 -0800 Message-Id: <638D44BA-0ACA-4041-8213-217233656A70@amacapital.net> References: <1614156585-18842-1-git-send-email-wanghongzhe@huawei.com> Cc: keescook@chromium.org, andrii@kernel.org, ast@kernel.org, bpf@vger.kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, kafai@fb.com, kpsingh@kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, songliubraving@fb.com, wad@chromium.org, yhs@fb.com, tongxiaomeng@huawei.com In-Reply-To: <1614156585-18842-1-git-send-email-wanghongzhe@huawei.com> To: wanghongzhe X-Mailer: iPhone Mail (18D52) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Feb 24, 2021, at 12:03 AM, wanghongzhe wrote: >=20 > =EF=BB=BFAs Kees haved accepted the v2 patch at a381b70a1 which just > replaced rmb() with smp_rmb(), this patch will base on that and just adjus= t > the smp_rmb() to the correct position. >=20 > As the original comment shown (and indeed it should be): > /* > * Make sure that any changes to mode from another thread have > * been seen after SYSCALL_WORK_SECCOMP was seen. > */ > the smp_rmb() should be put between reading SYSCALL_WORK_SECCOMP and readi= ng > seccomp.mode to make sure that any changes to mode from another thread hav= e > been seen after SYSCALL_WORK_SECCOMP was seen, for TSYNC situation. Howeve= r, > it is misplaced between reading seccomp.mode and seccomp->filter. This iss= ue > seems to be misintroduced at 13aa72f0fd0a9f98a41cefb662487269e2f1ad65 whic= h > aims to refactor the filter callback and the API. So let's just adjust the= > smp_rmb() to the correct position. >=20 > A next optimization patch will be provided if this ajustment is appropriat= e. Would it be better to make the syscall work read be smp_load_acquire()? >=20 > v2 -> v3: > - move the smp_rmb() to the correct position >=20 > v1 -> v2: > - only replace rmb() with smp_rmb() > - provide the performance test number >=20 > RFC -> v1: > - replace rmb() with smp_rmb() > - move the smp_rmb() logic to the middle between TIF_SECCOMP and mode >=20 > Signed-off-by: wanghongzhe > --- > kernel/seccomp.c | 15 +++++++-------- > 1 file changed, 7 insertions(+), 8 deletions(-) >=20 > diff --git a/kernel/seccomp.c b/kernel/seccomp.c > index 1d60fc2c9987..64b236cb8a7f 100644 > --- a/kernel/seccomp.c > +++ b/kernel/seccomp.c > @@ -1160,12 +1160,6 @@ static int __seccomp_filter(int this_syscall, const= struct seccomp_data *sd, > int data; > struct seccomp_data sd_local; >=20 > - /* > - * Make sure that any changes to mode from another thread have > - * been seen after SYSCALL_WORK_SECCOMP was seen. > - */ > - smp_rmb(); > - > if (!sd) { > populate_seccomp_data(&sd_local); > sd =3D &sd_local; > @@ -1291,7 +1285,6 @@ static int __seccomp_filter(int this_syscall, const s= truct seccomp_data *sd, >=20 > int __secure_computing(const struct seccomp_data *sd) > { > - int mode =3D current->seccomp.mode; > int this_syscall; >=20 > if (IS_ENABLED(CONFIG_CHECKPOINT_RESTORE) && > @@ -1301,7 +1294,13 @@ int __secure_computing(const struct seccomp_data *s= d) > this_syscall =3D sd ? sd->nr : > syscall_get_nr(current, current_pt_regs()); >=20 > - switch (mode) { > + /*=20 > + * Make sure that any changes to mode from another thread have > + * been seen after SYSCALL_WORK_SECCOMP was seen. > + */ > + smp_rmb(); > + > + switch (current->seccomp.mode) { > case SECCOMP_MODE_STRICT: > __secure_computing_strict(this_syscall); /* may call do_exit */ > return 0; > --=20 > 2.19.1 >=20