Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp359283pxb; Wed, 14 Apr 2021 17:47:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwGhUJ1colJGEkIKv2K/W6CitSo+Es0VAFyrdYw+b1pU+nbgcdEcHKShb5WZBQ5Lk2LQ6Gi X-Received: by 2002:a17:90b:e0b:: with SMTP id ge11mr877982pjb.127.1618447638100; Wed, 14 Apr 2021 17:47:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618447638; cv=none; d=google.com; s=arc-20160816; b=HGLgwUQNtxrc7ExIeUWaG0b0OihtwfPO+AIT1dUtwoIWvmPu5iYo9/BU0taIp9P5jy oQ5kSjKqlejVc1RWoR8vCdPnyaq+iWWiRYHW08QJRckkqbeSeycc2lTCIJnKIC6NfbZ5 MxFU301H6T9hOgwWSd9vMFg3Ytr9tni1dDx30oWoCtNbvDu1+7S/HJpfha4/7bb6jiCF Wh4qC9V/n1M2TCUlib+zZP+T/SNTnPBxvyt0tcFbXhk/GZHpKHikiSKuv0U2MkO9mZdk enHaiHkiCcGQgilsTu58CinKtp/DDAnEKdGFSEcyWVaaKPijG5ERQKFMqkOsiEJgz26e tjbg== 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=xd3Z5U0VOmuFth27DsrDTu5x4gcSsdYJKxKpDn5Q/g0=; b=U3gvRJe6OrWO2vV1DJmdZ77PmyIVSHIHanLiTVj8grc8Ug5+ljdn7V5NqvWpEwAJou V1qomNOSLXph/7rSUKrRfc9Iz/M3r5pshu+sgVEUCzhtAaLUUkJfgp4Jr3kmIx56EaVA 1fQnxPoeD1vlnJJPQ/INHfRu+eYfxM8nbJIgdmExE31R95j/pQ/xar2knRrl+QjIiT1H Yqyri0KGR6YkYmYO04Y0CBgPaP/ovHzOH2q4VGellvlj5oYuBcegZ2rbC9Btg0m9z++1 ItqjRcLbHxBizY2/+BTn41TxSR6ZqOQtnzo0w97MKkQMrovRf5OpKJKXGpsM0nPA1RQp 7IhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=alDkMo8l; 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 p21si1224338pfn.77.2021.04.14.17.47.06; Wed, 14 Apr 2021 17:47:18 -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=alDkMo8l; 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 S1349055AbhDNU0B (ORCPT + 99 others); Wed, 14 Apr 2021 16:26:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348700AbhDNUZ6 (ORCPT ); Wed, 14 Apr 2021 16:25:58 -0400 Received: from mail-yb1-xb2c.google.com (mail-yb1-xb2c.google.com [IPv6:2607:f8b0:4864:20::b2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D927C061574 for ; Wed, 14 Apr 2021 13:25:36 -0700 (PDT) Received: by mail-yb1-xb2c.google.com with SMTP id y2so21489627ybq.13 for ; Wed, 14 Apr 2021 13:25:36 -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=xd3Z5U0VOmuFth27DsrDTu5x4gcSsdYJKxKpDn5Q/g0=; b=alDkMo8lWFm5QA6bTxZWTxMZ7PCvrZynkWcqw3HYZF9eKF7D6MugQuDETkG0/ekWQS rfJQjPe0P+0hUxh5CqHgH9zYzLyfHfRz+DD09Zk6XJjbk1CoE/kSDY4dMClxRQNa4iQX A/PcS+DCBNTmdfurl9hzq+VhrKcFX3QLrpSbtkFSdCBq9CPWJY57eESmL7ubf0sHEdzT gDXBsqYi+zGiNQxi5o6MoVgizjdpWJTeJPv++29Lfd6g0xyoOMHIoMuNLEodYXZMWoGr 43aPKPrTR4TqdaBklRx9UX1SgaKWmspUjqaYLF24QMQbsV9cwGOIrqfOq1ibewVkJBKB bbZA== 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=xd3Z5U0VOmuFth27DsrDTu5x4gcSsdYJKxKpDn5Q/g0=; b=hib0dgoU28q9Blat9mcLo2RiqxQnKrcX/c9QNY5inL/5QdErZnxBkh6QQNWTEPUFKT vaM03/Xa45ao7fV6G5fZjqPKdD+0gl/mgWg1W+Ziw/BW+UoRLqiD7VC9xLmdDpNa1Jjx IR4FUp3IkchLL3zCi0zx1XnrkhJ18cooXvmYazHEFwLeiBtki6LIifsLgWtgU7Iu4Wqg De6xQpPU8vcRl4RBFRtMKrA188UEXrtNWIAypC2Xl5BSe5GuDAvL0NEZkiWxtrmPVc6A hkVn9Bj06GQQd8+XbXBB/XToeT2eVwJRpxvPuu1nlCWd63EfwErW73xnbpyYT//AMlFW kkRg== X-Gm-Message-State: AOAM5338QNnrf3HoRHz/tYxr9/hifXw3sCCMuQpQLdyEx2HS0Cuqglm2 fMkCrGfpHigJezx3KqIGvdRCaoMUGPCuz2k8c/ysMg== X-Received: by 2002:a25:850b:: with SMTP id w11mr55494733ybk.518.1618431935033; Wed, 14 Apr 2021 13:25:35 -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: Eric Dumazet Date: Wed, 14 Apr 2021 22:25:23 +0200 Message-ID: Subject: Re: [PATCH v2 3/3] rseq: optimise rseq_get_rseq_cs() and clear_rseq_cs() To: Arjun Roy 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:15 PM Arjun Roy wrote: > > 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. I was suggesting only using unsafe_get_user() and unsafe_put_user(), and one surrounding stac/clac Basically what we had (partially) in our old Google kernels, before commit 8f2817701492 ("rseq: Use get_user/put_user rather than __get_user/__put_user") but with all the needed modern stuff.