Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp358460pxb; Wed, 14 Apr 2021 17:45:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwDFshWYzY+9oFKTeoYye2mVbqM4JEFYWuhWy+7iCrYLgBt9rLOGIvEvFS0wlM2MYZzyL7u X-Received: by 2002:a63:164a:: with SMTP id 10mr1035593pgw.186.1618447539510; Wed, 14 Apr 2021 17:45:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618447539; cv=none; d=google.com; s=arc-20160816; b=uoSdKooc5JMpms0qNzlwgkaKydJoV8yCXt/LmsVJNkbUl4VMcsKX82G3t6vhlXbmJu Oo+AAJ95BZDcquUGvwncTttr5ShR7sxnH4Lnpjwn6wR4WZSCJqefTkYKLhF4vJYwCMMM tYfOA6/nohuFpgRgReh6ne5KS0fd88B64KMBlknH42rXdG/qdDcmN6M5IUGINjZAdSzB 6886XrErSceMwqLXP2imvzCKFd35DdqD09WVAVeYtA7Ij25zqvwDKzmT0hpJqt065tIg MAJcRkhquq9lmlXqZG9/8BcWoi8riLd2XCBa0F2nrTSIsYncSgkArBvK/SS35RaOvH7A zsHw== 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=LMn4fRwscQ/SJvwZ2LjbT42lX4Wost4d9Na2ULpirlU=; b=rSaPT548Dvn2qgpzGluWtHaPFgfptXKAY65d/6/cID1vZz484mTEH3i0R/rV76wANX 03OIlytsMl7CMpirVB9l42/jhIYSkL0Iuh2op8YUSIRzPhx03VTr8sVE0sv+SjLtXZXT x5i6cw3vSvxan8+YOJbK13rh8SHNMomew9uuhnq5MeZG7ujUPnYqyZdic2vXRX5XyavO 1rQ+NvX7Y+YHA4Xbrpo3bZonUnGJZlPT5/93/Yd0OYo/TyzrLmvwpwc1u2yvUD1DhT0j oOr/ZT67VzDGhv0Tf19cxMCn/v7AzMrUxJzRxproO/RC6EvxMw58YslY1wFPwQgaMgmF ZVbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=TqH0puN1; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h2si1083305pfc.321.2021.04.14.17.45.27; Wed, 14 Apr 2021 17:45:39 -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=@google.com header.s=20161025 header.b=TqH0puN1; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244620AbhDNUPm (ORCPT + 99 others); Wed, 14 Apr 2021 16:15:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233973AbhDNUPl (ORCPT ); Wed, 14 Apr 2021 16:15:41 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAEABC061574 for ; Wed, 14 Apr 2021 13:15:19 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id m18so8568069plc.13 for ; Wed, 14 Apr 2021 13:15:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=LMn4fRwscQ/SJvwZ2LjbT42lX4Wost4d9Na2ULpirlU=; b=TqH0puN1wxvV9PRIQzZzH+0TMRpojPhI54y5C12M9KuJRQVjtTXxetefGc2E0238zC t6QRQN57CMW9wqEdxIKdLLLFZUQRYGNaUlZMbgAcueEikTnS+nQirDXZXrSbb/8Ye/Zv Yr+vhKv3RUfE7PYz0A3THFwX+EDGV2hMWP+QFEYQYwlmv5l2kOcn3DAGB0xzEf75EhIH glhYz87YtCc2ShAz5u17L7LUizjhAsfutRjj+7YHnrkZJ8mCiEAhpC7prFZafU8ALfQl qGYy252nuL8bPV4QAweOnpasQvQQ7+qDXiXRBJirZdRIUIlaBYpxxejIZhZD98LYdzGg CfOA== 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=LMn4fRwscQ/SJvwZ2LjbT42lX4Wost4d9Na2ULpirlU=; b=A94Xr3tUO888FyF49fgU0JVJ1x4oxS7eNJ8l57GlQS0Bk9F6AddniH9MfsGc3BBNgr qqZ9AetxH37W+f87IdydDtNMt5KYCEsL2cIS2aALJR2OppOY97EY7G58uXXR5rq8ulU/ +M4jfVEPBjqlL1dcP3TcmmUp615Z866xDkSV/8pkzcwHB8E7HQMEuFX0GCb+SBEaQV3/ ZC5H+TaDwCyPVnHrueQIizzm5eLBCo/A1CXqj2KyuA5wcwSPVoU1dxk6UwbAf43LYuzA MeY3FfGEDPStB0rnRtUFtp1GKFp5Fx9sYAU3/LgiZ+lBjg0IOQAIvNos6Gx5VdMkPnGS hF8g== X-Gm-Message-State: AOAM531f/5MG90G+9Yf+vkJHBoCQ45tgLByVnnSa/cr/YszfID0EQfVt 6S8RmyJMH6una/W95vzJWdZxu4Erm6ZaGvrHUyzD0w== X-Received: by 2002:a17:90a:ce8d:: with SMTP id g13mr5311217pju.85.1618431319245; Wed, 14 Apr 2021 13:15:19 -0700 (PDT) MIME-Version: 1.0 References: <20210413162240.3131033-1-eric.dumazet@gmail.com> <20210413162240.3131033-4-eric.dumazet@gmail.com> <567941475.72456.1618332885342.JavaMail.zimbra@efficios.com> <989543379.72506.1618334454075.JavaMail.zimbra@efficios.com> <1347243835.72576.1618336812739.JavaMail.zimbra@efficios.com> <2c6885b0241d4127b8cb7e38abbbe1e5@AcuMS.aculab.com> <1e5576a1a5b24cb0b1d53b9bb22d528e@AcuMS.aculab.com> In-Reply-To: From: Arjun Roy Date: Wed, 14 Apr 2021 13:15:08 -0700 Message-ID: Subject: Re: [PATCH v2 3/3] rseq: optimise rseq_get_rseq_cs() and clear_rseq_cs() To: Eric Dumazet Cc: David Laight , Mathieu Desnoyers , Eric Dumazet , Ingo Molnar , Peter Zijlstra , paulmck , Boqun Feng , linux-kernel Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 14, 2021 at 10:35 AM Eric Dumazet wrote: > > On Wed, Apr 14, 2021 at 7:15 PM Arjun Roy wrote: > > > > On Wed, Apr 14, 2021 at 9:10 AM Eric Dumazet wrote: > > > > > > On Wed, Apr 14, 2021 at 6:08 PM David Laight wrote: > > > > > > > > From: Eric Dumazet > > > > > Sent: 14 April 2021 17:00 > > > > ... > > > > > > Repeated unsafe_get_user() calls are crying out for an optimisation. > > > > > > You get something like: > > > > > > failed = 0; > > > > > > copy(); > > > > > > if (failed) goto error; > > > > > > copy(); > > > > > > if (failed) goto error; > > > > > > Where 'failed' is set by the fault handler. > > > > > > > > > > > > This could be optimised to: > > > > > > failed = 0; > > > > > > copy(); > > > > > > copy(); > > > > > > if (failed) goto error; > > > > > > Even if it faults on every invalid address it probably > > > > > > doesn't matter - no one cares about that path. > > > > > > > > > > > > > > > On which arch are you looking at ? > > > > > > > > > > On x86_64 at least, code generation is just perfect. > > > > > Not even a conditional jmp, it is all handled by exceptions (if any) > > > > > > > > > > stac > > > > > copy(); > > > > > copy(); > > > > > clac > > > > > > > > > > > > > > > > > > > > efault_end: do error recovery. > > > > > > > > It will be x86_64. > > > > I'm definitely seeing repeated tests of (IIRC) %rdx. > > > > > > > > It may well be because the compiler isn't very new. > > > > Will be an Ubuntu build of 9.3.0. > > > > Does that support 'asm goto with outputs' - which > > > > may be the difference. > > > > > > > > > > Yep, probably. I am using some recent clang version. > > > > > > > On x86-64 I can confirm, for me it (4 x unsafe_get_user()) compiles > > down to stac + lfence + 8 x mov + clac as straight line code. And > > results in roughly a 5%-10% speedup over copy_from_user(). > > > > But rseq_get_rseq_cs() would still need three different copies, > with 3 stac+lfence+clac sequences. > > Maybe we need to enclose all __rseq_handle_notify_resume() operations > in a single section. > > To provide a bit of further exposition on this point, if you do 4x unsafe_get_user() recall I mentioned a 5-10% improvement. On the other hand, 4x normal get_user() I saw something like a 100% (ie. doubling of sys time measured) regression. I assume that's the fault of multiple stac+clac. -Arjun > > > > > > > -Arjun > > > > > > > > David > > > > > > > > - > > > > Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK > > > > Registration No: 1397386 (Wales)